#include<bits/stdc++.h>
#define lli long long int
using namespace std;
int sum[109],arr[109];
int main()
{
   lli n,m,ans=0;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        cin>>arr[i];
        sum[i]=sum[i-1]+arr[i];
    }
    while(m--)
    {
        lli l,r,a;
        cin>>l>>r;
        a=sum[r]-sum[l-1];
        if(a>0)
            ans+=a;
    }
    cout<<ans<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int f[200],sumac[200],a[200],n,m;

int main(){
  cin>>n>>m;
  for(int i = 1 ; i <= n ; ++i){
    cin>>a[i];
    sumac[i] = sumac[i-1]+a[i];
  }
  int l,r;
  while(m--){
    cin>>l>>r;
    if((sumac[r] - sumac[l-1]) > 0){
      for(int i = l ; i <= r ; ++i) f[i]++;
    }
  }
  int ans = 0;
  for(int i = 1 ; i <= n ; ++i){
    ans += f[i]*a[i];
  }
  cout << ans << '\n';
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int ft[200],sumac[200],a[200],n,m;

int query(int pos){
  int r = 0;
  for(int i = pos ; i ; i -= (i&(-i))) r += ft[i];
  return r;
}

void update(int pos, int value){
  for(int i = pos ; i <= n ; i+= (i&(-i))) ft[i]+= value;
}

int main(){
  cin>>n>>m;
  for(int i = 1 ; i <= n ; ++i){
    cin>>a[i]; ft[i] = 0;
    sumac[i] = sumac[i-1]+a[i];
  }
  int l,r;
  while(m--){
    cin>>l>>r;
    if((sumac[r] - sumac[l-1]) > 0){
      update(l,1);
      update(r+1,-1);
    }
  }
  int ans = 0;
  int ant = 0;
  for(int i = 1 ; i <= n ; ++i){
    int k  = -ant;
    ant = query(i);
    k += ant;
    ans += query(i)*a[i];
  }
  cout << ans << '\n';
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int a[600], n, k;
int d[600];

int main()
{
    //freopen("inp.txr", "r", stdin);
    memset(d, 0, sizeof(d));
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = 1; i <= k; i ++)
    {
        int l, r;
        cin >> l >> r;
        for (int j = l; j <= r; j++)
            d[i] += a[j];
    }
    int maxx = 0;
    for (int i = 1; i <= n; i++)
        if (d[i] > 0)
            maxx += d[i];
    if (maxx < 0)
        cout << 0;
    else cout << maxx;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int a[600], n, k;
int d[600];

int main()
{
    //freopen("inp.txr", "r", stdin);
    memset(d, 0, sizeof(d));
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = 1; i <= k; i ++)
    {
        int l, r;
        cin >> l >> r;
        for (int j = l; j <= r; j++)
            d[i] += a[j];
    }
    int maxx = 0;
    int dx = 0;
    for (int i = 1; i <= n; i++)
    {
        dx += d[i];
        if (dx < 0)
            dx = 0;
        maxx = max(dx, maxx);
    }
    cout << maxx;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int a[600], n, k;
int d[600];

int main()
{
   //  freopen("inp.txr", "r", stdin);
    memset(d, 0, sizeof(d));
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = 1; i <= k; i ++)
    {
        int l, r;
        cin >> l >> r;
        for (int j = l; j <= r; j++)
            d[i] += a[j];
    }
    int maxx = 0;
    for (int i = 1; i <= n; i++)
        if (d[i] > 0)
            maxx += d[i];
    cout << maxx;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int a[600], n, k;
int d[600];

int main()
{
    memset(d, 0, sizeof(d));
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = 1; i <= k; i ++)
    {
        int l, r;
        cin >> l >> r;
        for (int j = l; j <= r; j++)
            d[i] += a[j];
    }
    int maxx = 0;
    for (int i = 1; i <= k; i++)
        if (d[i] > 0)
            maxx += d[i];
    cout << maxx;
    return 0;
}


#include <cstdio>
#include <algorithm>
using namespace std;

const int SIZE = 100+10;
int pre[SIZE];
int tmp[SIZE];

int main(void)
{
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;i++){
		int x;
		scanf("%d",&x);
		pre[i] = pre[i-1] + x;
	}

	for(int i=1;i<=m;i++){
		int l,r;
		scanf("%d %d",&l,&r);
		tmp[i] = pre[r] - pre[l-1];
	}
	int ans = 0;
	int c = 0;
	for(int i=1;i<=m;i++){
		c += tmp[i];
		ans = max(ans,c);
		if( c<0 ) c = 0;
	}
	printf("%d\n",max(0,ans) );

	return 0;
}


#include <cstdio>
#include <algorithm>
using namespace std;

const int SIZE = 100+10;
int A[SIZE];
int pre[SIZE];
int tmp[SIZE];

int main(void)
{
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%d",A+i);
		pre[i] = pre[i-1] + A[i];
	}

	for(int i=1;i<=m;i++){
		int l,r;
		scanf("%d %d",&l,&r);
		tmp[i] = pre[r] - pre[l-1];
	}
	int ans = tmp[1];
	int c = tmp[1];
	for(int i=2;i<=m;i++){
		c += tmp[i];
		ans = max(ans,c);
		if( c<0 ) c = 0;
	}
	printf("%d\n",max(0,ans) );

	return 0;
}


#include <cstdio>
#include <algorithm>
using namespace std;

const int SIZE = 100+10;
int pre[SIZE];
int tmp[SIZE];

int main(void)
{
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;i++){
		int x;
		scanf("%d",&x);
		pre[i] = pre[i-1] + x;
	}

	for(int i=1;i<=m;i++){
		int l,r;
		scanf("%d %d",&l,&r);
		tmp[i] = pre[r] - pre[l-1];
	}
	int ans = 0;
	for(int i=1;i<=m;i++)
		if( tmp[i] > 0)
			ans += tmp[i];
	printf("%d\n",ans );

	return 0;
}


#include <iostream>
using namespace std;

int main()
{
   int l,m;
   cin>>l>>m;
   int arr[l];
   for(int y=0;y<l;y++)
   {
       scanf("%d",&arr[y]);
       //cin>>arr[y];

   }
   for(int y=0;y<l;y++)
   {
       cout<<arr[y];

   }
   int arr1[m][2];
   int k=0;
   int sum=0;
    for(int y=0;y<m;y++)
   {
       scanf("%d%d",&arr1[y][0],&arr1[y][1]);
     // cin>>arr1[y][0]>>arr1[y][1];
   }
   for(int y=0;y<m;y++)
   {
       for(int s=arr1[y][0];s<=arr1[y][1];s++)
       {
           k=k+arr[s-1];
       }
       if (k>=0 )
       sum=sum+k;

       //cin>>arr1[y][0]>>arr1[y][1];
   }
   cout<<sum;

    return 0;
}


#include <iostream>
using namespace std;

int main()
{
   int l,m;
   cin>>l>>m;
   int arr[l];
   for(int y=0;y<l;y++)
   {
       cin>>arr[y];
   }
   int arr1[m][2];
   int k=0;
   int sum=0;
    for(int y=0;y<m;y++)
   {
      cin>>arr1[y][0]>>arr1[y][1];
   }
   for(int y=0;y<m;y++)
   {
       for(int s=arr1[y][0];s<=arr1[y][1];s++)
       {
           k=k+arr[s-1];
       }
      // cout<<k<<sum<<"\n";
       if (k>0)

      { sum=sum+k;
         k=0;

      }
      k=0;
  // cout<<sum;
       //cin>>arr1[y][0]>>arr1[y][1];
   }
   cout<<sum;

    return 0;
}


#include <iostream>
using namespace std;

int main()
{
   int l,m;
   cin>>l>>m;
   int arr[l];
   for(int y=0;y<l;y++)
   {
       cin>>arr[y];

   }

   int arr1[m][2];
   int k=0;
   int sum=0;
    for(int y=0;y<m;y++)
   {
      cin>>arr1[y][0]>>arr1[y][1];
   }
   for(int y=0;y<m;y++)
   {
       for(int s=arr1[y][0];s<=arr1[y][1];s++)
       {
           k=k+arr[s-1];
       }
      // cout<<k<<sum<<"\n";
       if (k>=0)

      { sum=sum+k;
          k=0;
      }

       //cin>>arr1[y][0]>>arr1[y][1];
   }
   cout<<sum;

    return 0;
}


#include <iostream>
using namespace std;

int main()
{
   int l,m;
   cin>>l>>m;
   int arr[l];
   for(int y=0;y<l;y++)
   {
       cin>>arr[y];

   }

   int arr1[m][2];
   int k=0;
   int sum=0;
    for(int y=0;y<m;y++)
   {
      cin>>arr1[y][0]>>arr1[y][1];
   }
   for(int y=0;y<m;y++)
   {
       for(int s=arr1[y][0];s<=arr1[y][1];s++)
       {
           k=k+arr[s-1];
       }
       if (k>=0 )
       sum=sum+k;

       //cin>>arr1[y][0]>>arr1[y][1];
   }
   cout<<sum;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,m,x,y;
cin>>n>>m;
int a[n];
int i;
int count1=0,count2=0;
vector<int>k;

for(i=0;i<n;i++)
cin>>a[i];
vector< pair<int,int> >b;
for(i=0;i<m;i++)
{cin>>x>>y;
b.push_back(make_pair(x,y));
	}

for(i=0;i<m;i++)
{
for(int j=b[i].first;j<=b[i].second;j++)
{
	if(a[j-1]>0)
	count1++;
	if(a[j-1]<0)
	count2++;
}
if(count1>count2)
k.push_back(i);
}

int c[n];
for(i=0;i<n;i++)
c[i]=0;
/*
for(i=0;i<n;i++)
cout<<c[i]<<" ";
*/

for(i=0;i<k.size();i++)
{

for(int j=b[k[i]].first;j<=b[k[i]].second;j++)
{
c[j-1]++;

}

}
int sum=0;
for(i=0;i<n;i++)
{
sum+=c[i]*a[i];
}

cout<<sum<<endl;
return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,m,x,y;
cin>>n>>m;
int a[n];
int i;
int count1=0,count2=0;
vector<int>k;

for(i=0;i<n;i++)
cin>>a[i];
vector< pair<int,int> >b;
for(i=0;i<m;i++)
{cin>>x>>y;
b.push_back(make_pair(x,y));
	}
//cout<<"________"<<endl;
for(i=0;i<m;i++)
{
//cout<<b[i].first<<" "<<b[i].second<<endl;
count1=0;
count2=0;
for(int j=b[i].first;j<=b[i].second;j++)
{

	if(a[j-1]>0)
	count1+=a[j-1];
else	if(a[j-1]<0)
	count2+=a[j-1];
}
//cout<<"count"<<count1<<" "<<count2<<endl;
int count=count1+count2;
if(count>0)
 {
 k.push_back(i);
 //cout<<"herre"<<endl;
}
}

int c[n];
for(i=0;i<n;i++)
c[i]=0;

for(i=0;i<k.size();i++)
{

for(int j=b[k[i]].first;j<=b[k[i]].second;j++)
{
c[j-1]++;

}

}
int sum=0;
for(i=0;i<n;i++)
{
sum+=c[i]*a[i];
}

cout<<sum<<endl;

return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,m,x,y;
cin>>n>>m;
int a[n];
int i;
int count1=0,count2=0;
vector<int>k;

for(i=0;i<n;i++)
cin>>a[i];
vector< pair<int,int> >b;
for(i=0;i<m;i++)
{cin>>x>>y;
b.push_back(make_pair(x,y));
	}
//cout<<"________"<<endl;
for(i=0;i<m;i++)
{
//cout<<b[i].first<<" "<<b[i].second<<endl;
count1=0;
count2=0;
for(int j=b[i].first;j<=b[i].second;j++)
{

	if(a[j-1]>0)
	count1++;
	if(a[j-1]<0)
	count2++;
}
//cout<<count1<<" "<<count2<<endl;
if(count1>count2)
k.push_back(i);
}

int c[n];
for(i=0;i<n;i++)
c[i]=0;
/*
for(i=0;i<k.size();i++)
cout<<k[i]<<" ";
*/

for(i=0;i<k.size();i++)
{

for(int j=b[k[i]].first;j<=b[k[i]].second;j++)
{
c[j-1]++;

}

}
int sum=0;
for(i=0;i<n;i++)
{
sum+=c[i]*a[i];
}
cout<<sum<<endl;
return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll A[500];
ll maxn = 0;

ll N,M;
ll x,y;

int main(){
    cin >> N >> M;
    for(ll i = 1; i <= N; i++){
        cin >> A[i];
    }
    int cnt = 0;
    for(ll i = 1; i <= M; i++){
        ll total = 0;
        cin >> x >> y;
        for(ll j = x; j <= y; j++){
            total += A[j];
        }
        if( total > 0 ){
            cnt+=total;
        }
    }
    cout << cnt << endl;
}


#include <bits/stdc++.h>
using namespace std;
int N,M,x,y,cnt = 0;
int main(){
    cin >> N >> M;
    for(int i = 1; i <= N; i++){
        cin >> A[i];
    }
    for(int i = 1; i <= M; i++){
        int total = 0;
        cin >> x >> y;
        for(int j = x; j <= y; j++){
            total += A[j];
        }
        cnt += (total > 0 ? total:0)
    }
    cout << cnt << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll A[500];
ll maxn = 0;

ll N,M;
ll x,y;

struct Node{
    ll a,b;
    ll total;
}No[150];

void dfs(ll t,ll cnt){
    ll total = 0;
    total += cnt;
    for(ll i = t+1; i <= M; i++){
        total += No[i].total;
        maxn = max( maxn,total );
        dfs(i,total);
    }
}

bool cmp(Node a,Node b){
    if( a.a != b.a ){
        return a.a < b.a;
    }else{
        return a.b < b.b;
    }
}

int main(){
    cin >> N >> M;
    for(ll i = 1; i <= N; i++){
        cin >> A[i];
    }
    for(ll i = 1; i <= M; i++){
        ll total = 0;
        cin >> x >> y;
        for(ll j = x; j <= y; j++){
            total += A[j];
        }
        No[i].a = x;
        No[i].b = y;
        No[i].total = total;
        maxn = max(maxn,total);
    }
    sort( No+1,No+M+1,cmp );
    for(ll i = 1; i <= M; i++){
        maxn = max( No[i].total,maxn );
        dfs(i,No[i].total);
    }
    cout << maxn << endl;
}


#include<iostream>
using namespace std;
int main()
{
	int n,m,i,sum=0;
	cin>>n>>m;
	int a[n];
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	int [m]={0};
	for(i=0;i<m;i++)
	{
		int y,z;
		cin>>y>>z;
		for(int j=(y-1);j<z;j++)
		{
			b[i]=b[i]+a[j];
		}
		if(b[i]>0)
		{
			sum += b[i];
		}
	}
	cout<<sum;

}


#include<iostream>
using namespace std;
int main()
{
	int n,m,i,sum=0;
	cin>>n>>m;
	int a[n];
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	int b[m]={0};
	for(i=0;i<m;i++)
	{
		int y,z;
		cin>>y>>z;
		for(int j=(y-1);j<z;j++)
		{
			b[i]=b[i]+a[j];
		}
		if(b[i]>0)
		{
			sum += b[i];
		}
	}
	cout<<sum;

}


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

int main() {
	int n, m; cin >> n >> m;
	int moods[n];
	for (int i = 0; i < n; i++) {
		cin >> moods[i];
	}
	vector<int> num;
	for (int i = 0; i < m; i++) {
		int b, e; cin >> b >> e;
		int sum = 0;
		for (int j = b - 1; j < e; j++) {
			sum += moods[j];
		}
		num.push_back(sum);
	}
	int maxhere = 0, maxfinal = 0;

	for (int i = 0; i < num.size(); i++) {
		maxhere = max(0, maxhere + num[i]);
		maxfinal = max(maxhere, maxfinal);
	}

	cout << maxfinal << endl;
	system("pause");
}


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

int main() {
	int n, m; cin >> n >> m;
	int moods[n];
	for (int i = 0; i < n; i++) {
		cin >> moods[i];
	}
	vector<int> num;
	for (int i = 0; i < m; i++) {
		int b, e; cin >> b >> e;
		int sum = 0;
		for (int j = b - 1; j < e; j++) {
			sum += moods[j];
		}
		num.push_back(sum);
	}
	int maxhere = 0, maxfinal = 0;
	sort(num.begin(), num.end());
	for (int i = 0; i < num.size(); i++) {
		maxhere = max(0, maxhere + num[i]);
		maxfinal = max(maxhere, maxfinal);
	}

	cout << maxfinal << endl;
		//system("pause");
}


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

int main() {
	int n, m; cin >> n >> m;
	int moods[n];
	for (int i = 0; i < n; i++) {
		cin >> moods[i];
	}
	vector<int> num;
	for (int i = 0; i < m; i++) {
		int b, e; cin >> b >> e;
		int sum = 0;
		for (int i = b - 1; i < e; i++) {
			sum += moods[i];
		}
		num.push_back(sum);
	}
	int maxhere = 0, maxfinal = 0;

	for (int i = 0; i < num.size(); i++) {
		maxhere = max(0, maxhere + num[i]);
		maxfinal = max(maxhere, maxfinal);
	}

	cout << maxfinal << endl;
//	system("pause");
}


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

int main() {
	int n, m; cin >> n >> m;
	int moods[n];
	for (int i = 0; i < n; i++) {
		cin >> moods[i];
	}
	vector<int> num;
	for (int i = 0; i < m; i++) {
		int b, e; cin >> b >> e;
		int sum = 0;
		for (int j = b - 1; j < e; j++) {
			sum += moods[j];
		}
		num.push_back(sum);
	}
	int maxhere = 0, maxfinal = 0;

	for (int i = 0; i < num.size(); i++) {
		maxhere = max(0, maxhere + num[i]);
		maxfinal = max(maxhere, maxfinal);
	}

	cout << maxfinal << endl;
//	system("pause");
}


#include<bits/stdc++.h>

using namespace std;

typedef vector<int> vi;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, m;
	cin>>n>>m;
	vi V(n);
	for (int i=0;i<n;++i) {
		int aux;
		cin>>aux;
		if (i == 0) {
			V[0] = aux;
		} else {
			V[i] = aux + V[i-1];
		}
	}
	int count = 0;
	for (int i=0;i<m;++i) {
		int a, b;
		cin>>a>>b;
		a--, b--;
		if (a == 0) {
			if (V[b] > 0)
				count += V[b];
		} else if (V[b] - V[a-1]> 0) {
			count += V[b] - V[a-1];
		}
	}
	cout<<count<<"\n";
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef vector<int> vi;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, m;
	cin>>n>>m;
	vi V(n);
	for (int i=0;i<n;++i) {
		int aux;
		cin>>aux;
		if (i == 0) {
			V[0] = aux;
		} else {
			V[i] = aux + V[i-1];
		}
	}
	int count = 0;
	for (int i=0;i<m;++i) {
		int a, b;
		cin>>a>>b;
		a--, b--;
		if (a == 0 && V[b] > 0) {
			count += V[b];
		} else if (V[b] - V[a-1]> 0) {
			count += V[b] - V[a-1];
		}
	}
	cout<<count<<"\n";
	return 0;
}


# include <iostream>
# include <vector>
# include <deque>
# include <math.h>
# include <set>
# include <iomanip>
# include <time.h>
# include <list>
# include <stdio.h>
# include <queue>
# include <map>

# define ll long long
# define mk make_pair
# define sc second
# define fr first
# define pb push_back

using namespace std;

const long long N = (1e6 + 10);
const long long mod = (1e9 + 7);

map<long long,long long > mp[N];

long long  a[N];

 main () {
	long long  n,m;

	cin >> n >> m;

	for(long long  i = 1; i <= n; i ++){
        cin >> a[i];
	}

	for(long long  i = 1; i <= m; i ++){

        long long  x,y;
        cin >> x >> y;
        for(long long  j = x; j <= y; j ++){
            mp[i][j] =  1;
        }
	}

    long long  ans = 0,mx = 0;

	for(long long  i = 1; i <= m; i ++){

        for(long long  j = i; j <= m; j ++){

            for(long long  k = 1; k <= n; k ++){

                long long  p = 0;

                for(long long  q = i; q <= j; q ++){
                    if(mp[q][k])
                        p ++;
                }
                    ans += a[k] * p;
            }
            mx = max(mx,ans);

            ans = 0;
        }
	}

	cout << mx << endl;
}


# include <iostream>
# include <vector>
# include <deque>
# include <math.h>
# include <set>
# include <iomanip>
# include <time.h>
# include <list>
# include <stdio.h>
# include <queue>
# include <map>

# define ll long long
# define mk make_pair
# define sc second
# define fr first
# define pb push_back

using namespace std;

const int N = (1e6 + 10);
const int mod = (1e9 + 7);

map<long long,int > mp[N],used[N];

int  a[N],dp[N];
vector<pair<int ,int > > t;
 main () {
	int  n,m;

	cin >> n >> m;

	for(int  i = 1; i <= n; i ++){
        cin >> a[i];
	}
    int  cnt = 0;
	for(int  i = 1; i <= m; i ++){

        int  x,y;
        cin >> x >> y;
        if(used[x][y] == 0){
            for(int j = x; j <= y; j ++){
                dp[i] += a[j];
            }
            used[x][y] = 1;
        }
        else
            dp[i] = 0;
	}

	int sum = 0;
	for(int i = 1; i <= m; i ++){
        if(dp[i] > 0)
            sum += dp[i];
	}

	cout << max(0,sum) << endl;

}


# include <iostream>
# include <vector>
# include <deque>
# include <math.h>
# include <set>
# include <iomanip>
# include <time.h>
# include <list>
# include <stdio.h>
# include <queue>
# include <map>

# define ll long long
# define mk make_pair
# define sc second
# define fr first
# define pb push_back

using namespace std;

const long long N = (1e6 + 10);
const long long mod = (1e9 + 7);

map<long long,long long > mp[N],used[N];

long long  a[N];
vector<pair<long long ,long long > > t;
 main () {
	long long  n,m;

	cin >> n >> m;

	for(long long  i = 1; i <= n; i ++){
        cin >> a[i];
	}
    long long  cnt = 0;
	for(long long  i = 1; i <= m; i ++){

        long long  x,y;
        cin >> x >> y;
        t.pb(mk(x,y));
        if(used[x][y] == 1)
            cnt ++;
        else
            used[x][y] = 1;
	}
	m -= cnt;
	for(long long  i = 0; i < t.size(); i ++){
        for(long long  j = t[i].fr; j <= t[i].sc; j ++){
            mp[i + 1][j] = 1;
        }
	}

    long long  ans = 0,mx = 0;

	for(long long  i = 1; i <= m; i ++){

        for(long long  j = i; j <= m; j ++){

            for(long long  k = 1; k <= n; k ++){

                long long  p = 0;

                for(long long  q = i; q <= j; q ++){
                    if(mp[q][k])
                        p ++;
                }
                    ans += a[k] * p;
            }
            mx = max(mx,ans);

            ans = 0;
        }
	}

	cout << mx << endl;
}


# include <iostream>
# include <vector>
# include <deque>
# include <math.h>
# include <set>
# include <iomanip>
# include <time.h>
# include <list>
# include <stdio.h>
# include <queue>
# include <map>

# define ll long long
# define mk make_pair
# define sc second
# define fr first
# define pb push_back

using namespace std;

const long long N = (1e6 + 10);
const long long mod = (1e9 + 7);

map<long long ,long long > mp[N];

vector<long long > v[N];

long long  a[N];

 main () {
	long long  n,m;

	cin >> n >> m;

	for(long long  i = 1; i <= n; i ++){
        cin >> a[i];
	}

	for(long long  i = 1; i <= m; i ++){

        long long  x,y;
        cin >> x >> y;
        for(long long  j = x; j <= y; j ++){
            mp[i][j] =  1;
        }
	}

    long long  ans = 0,mx = -1e18;

	for(long long  i = 1; i <= m; i ++){
        for(long long  j = i; j <= m; j ++){
            for(long long  k = 1; k <= n; k ++){
                    long long  p = 0;
                for(long long  q = i; q <= j; q ++){
                    if(mp[q][k])
                        p ++;
                }

                if(p > 0){
                    ans += (a[k] * p);
                }
            }

            mx = max(mx,ans);
            ans = 0;
        }
	}

	cout << max(mx,0 * 1ll) << endl;
}


# include <iostream>
# include <vector>
# include <deque>
# include <math.h>
# include <set>
# include <iomanip>
# include <time.h>
# include <list>
# include <stdio.h>
# include <queue>
# include <map>

# define ll long long
# define mk make_pair
# define sc second
# define fr first
# define pb push_back

using namespace std;

const long long N = (1e6 + 10);
const long long mod = (1e9 + 7);

map<long long,long long > mp[N],used[N];

long long  a[N];
vector<pair<long long ,long long > > t;
 main () {
	long long  n,m;

	cin >> n >> m;

	for(long long  i = 1; i <= n; i ++){
        cin >> a[i];
	}
    long long  cnt = 0;
	for(long long  i = 1; i <= m; i ++){

        long long  x,y;
        cin >> x >> y;
        if(used[x][y] == 0){
            t.pb(mk(x,y));
            used[x][y] = 1;
        }
	}
	m = t.size();
    long long  ans = 0,mx = 0;

	for(long long  i = 0; i < m; i ++){

        for(long long  j = i; j < m; j ++){

            for(long long  k = 1; k <= n; k ++){

                long long  p = 0;

                for(long long  q = i; q <= j; q ++){
                    if(k >= t[q].fr && k <= t[q].sc)
                        p ++;
                }
                    ans += a[k] * p;
            }
            mx = max(mx,ans);

            ans = 0;
        }
	}

	cout << max(0 * 1ll,mx) << endl;
}


# include <iostream>
# include <vector>
# include <deque>
# include <math.h>
# include <set>
# include <iomanip>
# include <time.h>
# include <list>
# include <stdio.h>
# include <queue>
# include <map>

# define ll long long
# define mk make_pair
# define sc second
# define fr first
# define pb push_back

using namespace std;

const long long  N = (1e6 + 10);
const long long  mod = (1e9 + 7);

map<long long,long long  > mp[N],used[N];

long long   a[N],dp[N];
vector<pair<long long  ,long long  > > t;
 main () {
	long long   n,m;

	cin >> n >> m;

	for(long long   i = 1; i <= n; i ++){
        cin >> a[i];
	}
    long long   cnt = 0;
	for(long long   i = 1; i <= m; i ++){

        long long   x,y;
        cin >> x >> y;
        if(used[x][y] == 0){
            for(long long  j = x; j <= y; j ++){
                dp[i] += a[j];
            }
            used[x][y] = 1;
        }
        else
            dp[i] = -1;
	}

	long long  sum = 0;
	for(long long  i = 1; i <= m; i ++){
        dp[i] = max(dp[i - 1],dp[i] + dp[i - 1]);
	}

	cout << max(0 * 1ll,dp[m]) << endl;

}


# include <iostream>
# include <vector>
# include <deque>
# include <math.h>
# include <set>
# include <iomanip>
# include <time.h>
# include <list>
# include <stdio.h>
# include <queue>
# include <map>

# define ll long long
# define mk make_pair
# define sc second
# define fr first
# define pb push_back

using namespace std;

const long long  N = (1e6 + 10);
const long long  mod = (1e9 + 7);

map<long long,long long > used[N];

long long   a[N],dp[N];
 main () {
	long long   n,m;

	cin >> n >> m;

	for(long long   i = 1; i <= n; i ++)
        cin >> a[i];

	for(long long   i = 1; i <= m; i ++){

        long long   x,y;
        cin >> x >> y;

            for(long long  j = x; j <= y; j ++){

                dp[i] += a[j];
            }

	}

    long long mx = 0;
	for(long long  i = 1; i <= m; i ++){
        dp[i] = max(dp[i - 1],max(dp[i],dp[i] + dp[i - 1]));
        mx = max(mx,dp[i]);
	}

	cout << mx << endl;

}


# include <iostream>
# include <vector>
# include <deque>
# include <math.h>
# include <set>
# include <iomanip>
# include <time.h>
# include <list>
# include <stdio.h>
# include <queue>
# include <map>

# define ll long long
# define mk make_pair
# define sc second
# define fr first
# define pb push_back

using namespace std;

const int N = (1e6 + 10);
const int mod = (1e9 + 7);

map<long long,int > mp[N],used[N];

int  a[N];
vector<pair<int ,int > > t;
 main () {
	int  n,m;

	cin >> n >> m;

	for(int  i = 1; i <= n; i ++){
        cin >> a[i];
	}
    int  cnt = 0;
	for(int  i = 1; i <= m; i ++){

        int  x,y;
        cin >> x >> y;
        if(used[x][y] == 0){
            t.pb(mk(x,y));
            used[x][y] = 1;
        }
	}
	m = t.size();
    int  ans = 0,mx = 0;

	for(int  i = 0; i < m; i ++){

        for(int  j = i; j < m; j ++){

            for(int  k = 1; k <= n; k ++){

                int  p = 0;

                for(int  q = i; q <= j; q ++){
                    if(k >= t[q].fr && k <= t[q].sc)
                        p ++;
                }
                    ans += a[k] * p;
            }
            mx = max(mx,ans);

            ans = 0;
        }
	}

	cout << max(0 ,mx) << endl;
}


#include<bits/stdc++.h>
using namespace std;
int n,m;
int a[110],times[110];
int l,r,tmp,maxm=0;
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=1;i<=m;i++){
		cin>>l>>r;
		tmp=0;
		for(int j=l;j<=r;j++)tmp+=a[j];
		if(tmp>0)maxm+=tmp;
	}
	cout<<maxm<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int n,m;
int a[110],times[110];
struct {
	int l,r;
}b[110];
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=0;i<m;i++){
		scanf("%d%d",&b[i].l,&b[i].r);
	}
	long long maxm=0;
	for(int i=0;i<m;i++){
		for(int j=i+1;j<m;j++){
			long long tmp=0;
			memset(times,0,sizeof(times));
			for(int k=i;k<=j;k++)
				for(int u=b[k].l;u<=b[k].r;u++)
					times[u]++;
			for(int k=1;k<=n;k++)tmp+=(long long)a[k]*times[k];
			maxm=max(maxm,tmp);
		}
	}
	printf("%I64d\n",maxm);
}


#include<bits/stdc++.h>
using namespace std;
int n,m;
int a[110],times[110];
struct {
	int l,r;
}b[110];
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=1;i<=m;i++){
		scanf("%d%d",&b[i].l,&b[i].r);
	}
	long long maxm=-1e9+1;
	for(int i=0;i<=m;i++){
		for(int j=i;j<=m;j++){
			long long tmp=0;
			memset(times,0,sizeof(times));
			for(int k=i;k<=j;k++)
				for(int u=b[k].l;u<=b[k].r;u++)
					times[u]++;
			for(int k=1;k<=n;k++)tmp+=(long long)a[k]*times[k];
			maxm=max(maxm,tmp);
		}
	}
	printf("%I64d\n",maxm);
}


#include<bits/stdc++.h>
using namespace std;
int n,m;
int a[110],times[110];
struct {
	int l,r;
}b[110];
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=1;i<=m;i++){
		scanf("%d%d",&b[i].l,&b[i].r);
	}
	long long maxm=0;
	for(int i=1;i<=m;i++){
		for(int j=i;j<=m;j++){
			long long tmp=0;
			memset(times,0,sizeof(times));
			for(int k=i;k<=j;k++)
				for(int u=b[k].l;u<=b[k].r;u++)
					times[u]++;
			for(int k=1;k<=n;k++)tmp+=(long long)(a[k]*times[k]);
			maxm=max(maxm,tmp);
		}
	}
	printf("%I64d\n",maxm);
}


#include<bits/stdc++.h>
using namespace std;
int n,m;
int a[110],times[110];
struct {
	int l,r;
}b[110];
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=0;i<m;i++){
		scanf("%d%d",&b[i].l,&b[i].r);
	}
	long long maxm=-1e9+1;
	for(int i=0;i<m;i++){
		for(int j=i+1;j<m;j++){
			long long tmp=0;
			memset(times,0,sizeof(times));
			for(int k=i;k<=j;k++)
				for(int u=b[k].l;u<=b[k].r;u++)
					times[u]++;
			for(int k=1;k<=n;k++)tmp+=(long long)a[k]*times[k];
			maxm=max(maxm,tmp);
		}
	}
	printf("%I64d\n",maxm);
}


#include <iostream>
#include <math.h>
#include<string>
#include<vector>
#include<set>
#include<algorithm>
#include<unordered_set>

using namespace std;
#define fr(i,n) for (int i=0; i<n; i++)

//int a[200000][3];
//
//
//
//void quickSort( int left, int right) {
//	int i = left, j = right;
//	int tmp;
//	int pivot = a[(left + right) / 2][2];
//
//	/* partition */
//	while (i <= j) {
//		while (a[i][2] < pivot)
//			i++;
//		while (a[j][2] > pivot)
//			j--;
//		if (i <= j) {
//			tmp = a[i][0];
//			a[i][0] = a[j][0];
//			a[j][0] = tmp;
//
//			tmp = a[i][1];
//			a[i][1] = a[j][1];
//			a[j][1] = tmp;
//
//			tmp = a[i][2];
//			a[i][2] = a[j][2];
//			a[j][2] = tmp;
//			i++;
//			j--;
//		}
//	};
//
//	/* recursion */
//	if (left < j)
//		quickSort( left, j);
//	if (i < right)
//		quickSort(i, right);
//
//}

int a[100];

int f(int l, int r)
{
	int res = 0;
	for (int i = l; i <= r; i++)
		res += a[i];
	return res;
}

int main(){
int n, m;
cin >> n >> m;
fr(i, n) cin >> a[i];
int res = 0;
fr(i, m)
{
	int l, r;
	cin >> l >> r;
	int t = f(l-1, r-1);
	if (t > 0) res += t;
}
cout << res;

	//system("pause");

	return 0;
}


#include <iostream>
#include <math.h>
#include<string>
#include<vector>
#include<set>
#include<algorithm>
#include<unordered_set>

using namespace std;
#define fr(i,n) for (int i=0; i<n; i++)

//int a[200000][3];
//
//
//
//void quickSort( int left, int right) {
//	int i = left, j = right;
//	int tmp;
//	int pivot = a[(left + right) / 2][2];
//
//	/* partition */
//	while (i <= j) {
//		while (a[i][2] < pivot)
//			i++;
//		while (a[j][2] > pivot)
//			j--;
//		if (i <= j) {
//			tmp = a[i][0];
//			a[i][0] = a[j][0];
//			a[j][0] = tmp;
//
//			tmp = a[i][1];
//			a[i][1] = a[j][1];
//			a[j][1] = tmp;
//
//			tmp = a[i][2];
//			a[i][2] = a[j][2];
//			a[j][2] = tmp;
//			i++;
//			j--;
//		}
//	};
//
//	/* recursion */
//	if (left < j)
//		quickSort( left, j);
//	if (i < right)
//		quickSort(i, right);
//
//}

char a[4][4];

int main()
{
	long long n, a, b, c;
	cin >> n >> a >> b >> c;
	if (n % 4 == 0) { cout << 0; return 0; }
	if (n % 4 == 1) { cout<<min(3 * a, min(a + b, c)); }
	if (n % 4 == 2) { cout << min(2 * a, min(b, 2*c)); }
	if (n % 4 == 3) { cout << min(a, b + c); }

	//system("pause");

	return 0;
}


#include <cstdio>
#include <algorithm>
using namespace std;
int n, m, L[105], R[105], A[105];
int dp[105][2];
int dfs(int ite, int flag)
{
	if (ite == n + 1) {
		return 0;
	}
	int& ret = dp[ite][flag];
	if (ret != -2e9)return ret;
	ret = -1e9;
	if (flag == 0) {
		ret = dfs(ite + 1, 0);
		ret = max(ret, dfs(ite + 1, 1));
	}
	else {
		int key = 0;
		for (int i = L[ite]; i <= R[ite]; i++) {
			key += A[i];
		}
		ret = key + dfs(ite + 1, 0);
		ret = max(ret, key + dfs(ite + 1, 1));
	}
	return ret;
}
int main() {
	scanf("%d %d", &n, &m);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &A[i]);
		for (int j = 0; j < 2; j++)dp[i][j] = -2e9;
	}
	for (int i = 1; i <= m; i++) {
		scanf("%d %d", &L[i], &R[i]);
	}
	int ans = dfs(1, 0);
	ans = max(ans, dfs(1, 1));
	printf("%d", ans);

}


#include <cstdio>
#include <algorithm>
using namespace std;
int n, m, L[105], R[105], A[105];
int dp[105][2];
int dfs(int ite, int flag)
{
	if (ite == m + 1) {
		return 0;
	}
	int& ret = dp[ite][flag];
	if (ret != -2e9)return ret;
	ret = -1e9;
	if (flag == 0) {
		ret = dfs(ite + 1, 0);
		ret = max(ret, dfs(ite + 1, 1));
	}
	else {
		int key = 0;
		for (int i = L[ite]; i <= R[ite]; i++) {
			key += A[i];
		}
		ret = key + dfs(ite + 1, 0);
		ret = max(ret, key + dfs(ite + 1, 1));
	}
	return ret;
}
int main() {
	scanf("%d %d", &n, &m);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &A[i]);
	}
	for (int i = 1; i <= m; i++) {
		scanf("%d %d", &L[i], &R[i]);

		for (int j = 0; j < 2; j++)dp[i][j] = -2e9;
	}
	int ans = dfs(1, 0);
	ans = max(ans, dfs(1, 1));
	printf("%d", ans);

}


#include <iostream>

using namespace std;

int main()
{
   int n,m,b,s(0),B,i,j,k,bg,bd;
   unsigned int T[100];
   unsigned int Ts[200];
      cin>>n>>m;
   for(i=0;i<n;i++)
   {
       cin>>T[i];
   }
   for(i=0;i<2*m;i++)
   {
       cin>>Ts[i];

   }
k=0;
   while(k<2*m-1)
   {
       bg=Ts[k]-1;k++;bd=Ts[k]-1;k++;
      for(i=0;i<n;i++)
   {
       B=0;
     j=bg;b=bd;
     while(j<=b&&B!=1){if(T[i]==T[j]){s+=T[i];B=1;}j++;};

   }

   }
   if(s>=0){cout<<s;}
   else{cout<<0;}

}


#include <iostream>

using namespace std;

int main()
{
   int n,m,b,s(0),B,i,j,k,bg,bd;
   unsigned int T[100];
   unsigned int Ts[200];
      cin>>n>>m;
   for(i=0;i<n;i++)
   {
       cin>>T[i];
   }
   for(i=0;i<2*m;i++)
   {
       cin>>Ts[i];

   }
k=0;
   while(k<=2*m-2)
   {
       bg=Ts[k]-1;k++;bd=Ts[k]-1;k++;
      for(i=0;i<n;i++)
   {
       B=0;
     j=bg;b=bd;
     while(j<=b&&B!=1){if(T[i]==T[j]){s+=T[i];B=1;}j++;};

   }

   }
   if(s>=0){cout<<s;}
   else{cout<<0;}

}


#include <iostream>

using namespace std;
 int somme(int i,int j,int a[])
 {
     int s=0,k=0;
     for(k=i;k<=j;k++)
     {
         s+=a[k];
     }
     return s;
 }

int main()
{
    int n,m,s(0),i,tmp;
    int T[100];
    int Ts[200];
      cin>>n>>m;
   for(i=0;i<n;i++)
   {
       cin>>T[i];
   }
   for(i=0;i<2*m;i++)
   {
       cin>>Ts[i];

   }

  i=0;

       while(i<2*m)
       {
           tmp=somme(Ts[i]-1,Ts[i+1]-1,T);
           if(tmp>0){s+=tmp;}
           i+=2;
       }

   cout<<s;
}


#include <iostream>

using namespace std;
 int somme(int i,int j,int a[])
 {
     int s=0,k=0;
     for(k=i;k<=j;k++)
     {
         s+=a[k];
     }
     return s;
 }

int main()
{
    int n,m,s(0),i,j,tmp;
    int T[100];
    int Ts[200];
    int occ[100];
      cin>>n>>m;
   for(i=0;i<n;i++)
   {
       cin>>T[i];
   }
   for(i=0;i<2*m;i++)
   {
       cin>>Ts[i];

   }

  j=0;

       while(j<2*m)
       {
           tmp=somme(Ts[j]-1,Ts[j+1]-1,T);
           if(tmp>0){s+=tmp;}
           j+=2;
       }

   cout<<s;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll m,n,a,b,c,x,t;
    cin>>n>>a>>b>>c;
    if(n%4==0)
    {
        cout<<"0\n";
    }
    else if(n < 4)
    {
        x = 4 - n;
        if(x==1)
        {
            cout<<min(a,b+c);
        }
        else if(x==2)
        {
            cout<<min({a*2,b,c*2});
        }
        else if(x==3)
        {
            cout<<min({a*3,c,a+b});
        }
    }
    else if(n%4==1)
    {
        cout<<min(a,b+c);
    }
    else if(n%4==2)
    {
        cout<<min({a*2,b,c*2});
    }
    else if(n%4==3)
    {
        cout<<min({a*3,c,a+b});
    }

}


#include<cstdio>
using namespace std;
const int MAXN=110;
int n,m,a[MAXN],tree[MAXN],tag[MAXN],ans;
inline int lc(int p){return p<<1;}
inline int rc(int p){return p<<1|1;}
void push_up(int u)
{
	tree[u]=tree[lc(u)]+tree[rc(u)];
}
void lazy_tag(int u,int l,int r,int k)
{
	tag[u]+=k;
	tree[u]+=k;
}
void push_down(int u,int l,int r)
{
	int mid=(l+r)>>1;
	lazy_tag(lc(u),l,mid,tag[u]);
	lazy_tag(rc(u),mid+1,r,tag[u]);
	tag[u]=0;
}
void build(int u,int l,int r)
{
	if(l==r)
	{
		tree[u]=a[l];
		return;
	}
	int mid=(l+r)>>1;
	build(lc(u),l,mid);
	build(rc(u),mid+1,r);
	push_up(u);
}
int query(int u,int l,int r,int ln,int rn)
{
	int t=0;
	if(ln<=l&&r<=rn)
	{
		return tree[u];
	}
	push_down(u,l,r);
	int mid=(l+r)>>1;
	if(ln<=mid) t+=query(lc(u),l,mid,ln,rn);
	if(rn>mid) t+=query(rc(u),mid+1,r,ln,rn);
	return t;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(register int i=1;i<=n;i++) scanf("%d",&a[i]);
	build(1,1,n);
	while(m--)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		int now=query(1,1,n,x,y);
		if(now>0) ans+=now;
	}
	printf("%d\n",ans);
	return 0;
}


#include<cstdio>
using namespace std;
const int MAXN=110;
int n,m,a[MAXN],tree[MAXN],tag[MAXN],ans;
inline int lc(int p){return p<<1;}
inline int rc(int p){return p<<1|1;}
void push_up(int u)
{
	tree[u]=tree[lc(u)]+tree[rc(u)];
}
void lazy_tag(int u,int l,int r,int k)
{
	tag[u]+=k;
	tree[u]+=k*(r-l+1);
}
void push_down(int u,int l,int r)
{
	int mid=(l+r)>>1;
	lazy_tag(lc(u),l,mid,tag[u]);
	lazy_tag(rc(u),mid+1,r,tag[u]);
	tag[u]=0;
}
void build(int u,int l,int r)
{
	if(l==r)
	{
		tree[u]=a[l];
		return;
	}
	int mid=(l+r)>>1;
	build(lc(u),l,mid);
	build(rc(u),mid+1,r);
	push_up(u);
}
int query(int u,int l,int r,int ln,int rn)
{
	int t=0;
	if(ln<=l&&r<=rn)
	{
		return tree[u];
	}
	push_down(u,l,r);
	int mid=(l+r)>>1;
	if(ln<=mid) t+=query(lc(u),l,mid,ln,rn);
	if(rn>mid) t+=query(rc(u),mid+1,r,ln,rn);
	return t;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(register int i=1;i<=n;i++) scanf("%d",&a[i]);
	build(1,1,n);
	while(m--)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		int now=query(1,1,n,x,y);
		if(now>0) ans+=now;
	}
	printf("%d\n",ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[5001];
int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;++i)
	{
		cin>>a[i];
	}
	int sum=0;
	for(int i=1;i<=m;++i)
	{
		int ss=0;
		int s,e;
		cin>>s>>e;
		for(int i=s;i<=e;++i)
		{
			ss+=a[i];
		}
		if(ss>0) sum+=ss;
	}
	cout<<sum;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m,k=0;
	cin>>n>>m;
	int a[n+1],l[m+1],r[m+1];
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		if(a[i]<0)
			k++;
	}
	for(int i=1;i<=m;i++)
	{
		cin>>l[i]>>r[i];
	}
	if(k==n)
		cout<<0<<endl;
	return 0;
}


#include<bits/stdc++.h>
#include<cstring>
#define ll long long
#define ld long double
#define inf 0x7f7f7f7f
#define maxn 1000010
using namespace std;
int a[maxn];
int main()
{
	ios::sync_with_stdio(false);
	int n,m;
	cin >> n >> m;
	for(int i=1;i<=n;i++)
		cin >> a[i];
	int ans = 0;
	for(int i=1;i<=m;i++)
	{
		int l,r,sum=0;
		cin >> l >> r;
		for(int j=l;j<=r;j++)
			sum +=a[j];
		if(sum > 0)
			ans += sum;
	}
	cout << ans ;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int maxProfit(vector<int>& nums,vector<pair<int,int>>& q) {

        int n = nums.size();
        int m = q.size();
        if(n<2){return 0;}

        vector<int> prefix_sum(n,0);

        prefix_sum[0]=nums[0];
        for(int i=1;i<n;i++){
            prefix_sum[i]=prefix_sum[i-1]+nums[i]; // why this line is throwing error
        }

        long long int maxt=0;

        for(int i=0;i<m;i++){
        	int c = q[i].first-2;
        	int temp;
        	if(c>-1){
        		temp = prefix_sum[q[i].second-1]-prefix_sum[q[i].first-2];
        	}
        	else{
        		temp = prefix_sum[q[i].second-1];
        	}
        	// cout<<"temp:"<<temp<<endl;
        	if(temp>0){
        		maxt+=temp;
        	}

        }
        cout<<maxt<<endl;
        return maxt;
}

int main() {
	int n,m;
	cin>>n>>m;
	vector<int> a1(n,0);
	for(int i=0;i<n;i++){cin>>a1[i];}

	 vector<pair <int, int>> iArr(m);
	for(int i=0;i<m;i++){
		int t1 ,t2;
		cin>>t1>>t2;
		iArr[i]=make_pair(t1,t2);
	}
	maxProfit(a1,iArr);

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
void maxProfit(vector<int>& nums,vector<pair<int,int>>& q) {

        int n = nums.size();
        int m = q.size();

        vector<int> prefix_sum(n,0);

        prefix_sum[0]=nums[0];
        for(int i=1;i<n;i++){
            prefix_sum[i]=prefix_sum[i-1]+nums[i]; // why this line is throwing error
        }

        long long int maxt=0;

        for(int i=0;i<m;i++){
        	int c = q[i].first-2;
        	int temp;
        	if(c>-1){
        		temp = prefix_sum[q[i].second-1]-prefix_sum[q[i].first-2];
        	}
        	else{
        		temp = prefix_sum[q[i].second-1];
        	}
        	// cout<<"temp:"<<temp<<endl;
        	if(temp>0){
        		maxt+=temp;
        	}

        }
        cout<<maxt<<endl;
}

int main() {
	int n,m;
	cin>>n>>m;
	vector<int> a1(n,0);
	for(int i=0;i<n;i++){cin>>a1[i];}

	 vector<pair <int, int>> iArr(m);
	for(int i=0;i<m;i++){
		int t1 ,t2;
		cin>>t1>>t2;
		iArr[i]=make_pair(t1,t2);
	}
	maxProfit(a1,iArr);

	return 0;
}


/*
* @Author: robertking
* @Date:   2016-11-24 00:31:34
* @Last Modified by:   robertking
* @Last Modified time: 2016-11-24 01:45:36
*/

#include <cstdio>
#include <iostream>

using namespace std;

int a[108];
int sum[108];

int main(int argc, char const *argv[])
{
#ifdef RK
    freopen("in.txt", "r", stdin);
#endif
    int n, m;
    scanf("%d %d", &n, &m);
    for (int i = 0; i < n; ++i) {
        scanf("%d", a + i);
        sum[i + 1] = sum[i] + a[i];
    }
    int s = 0;
    for (int i = 0; i < m; ++i) {
        int x, y;
        scanf("%d %d", &x, &y);
        s = max(s, s + sum[y] - sum[x - 1]);
    }
    printf("%d\n", s);
    // for (int i = 0; i <= n; ++i)printf("%d\t", sum[i]);
    return 0;
}


/*
* @Author: robertking
* @Date:   2016-11-24 00:31:34
* @Last Modified by:   robertking
* @Last Modified time: 2016-11-24 21:22:54
*/

#include <cstdio>
#include <iostream>

using namespace std;

int sum[108];

int main(int argc, char const *argv[])
{
#ifdef RK
    freopen("in.txt", "r", stdin);
#endif
    int n, m;
    scanf("%d %d", &n, &m);
    for (int i = 0; i < n; ++i) {
        int x;
        scanf("%d", &x);
        sum[i + 1] = sum[i] + x;
    }
    int s = 0;
    for (int i = 0; i < m; ++i) {
        int x, y;
        scanf("%d %d", &x, &y);
        s = max(s, s + sum[y] - sum[x - 1]);
    }
    printf("%d\n", s);
    return 0;
}


/*
* @Author: robertking
* @Date:   2016-11-24 00:31:34
* @Last Modified by:   robertking
* @Last Modified time: 2016-11-24 01:40:58
*/

#include <cstdio>
#include <iostream>

using namespace std;

int a[108];
int sum[108];

int main(int argc, char const *argv[])
{
#ifdef RK
    freopen("in.txt", "r", stdin);
#endif
    int n, m;
    scanf("%d %d", &n, &m);
    for (int i = 0; i < n; ++i) {
        scanf("%d", a + i);
        sum[i + 1] = sum[i] + a[i];
    }
    int s = 0;
    for (int i = 0; i < m; ++i) {
        int x, y;
        scanf("%d %d", &x, &y);
        s = max(s, s + sum[y] - sum[x - 1]);
    }
    printf("%d\n", s);
    for (int i = 0; i <= n; ++i)printf("%d\t", sum[i]);
    return 0;
}


/*
* @Author: robertking
* @Date:   2016-11-24 00:31:34
* @Last Modified by:   robertking
* @Last Modified time: 2016-11-24 01:14:15
*/

#include <cstdio>
#include <iostream>
#include <algorithm>

using namespace std;

int main(int argc, char const *argv[])
{
#ifdef RK
    freopen("in.txt", "r", stdin);
#endif
    long long n, a, b, c;
    cin >> n >> a >> b >> c;
    long long mini = 0x7fffffffffffffff;
    // cout << mini;
    if (n % 4 == 0) {printf("0\n"); return 0;}
    for (int i = 0; i < 10; ++i) {
        for (int j = 0; j < 10; ++j) {
            for (int k = 0; k < 10; ++k) {
                if ((n + i + j + j + k + k + k) % 4 == 0) {
                    mini = min(mini, a * i + b * j + c * k);
                }
            }
        }
    }
    cout << mini << '\n';

    return 0;
}


#include <bits/stdc++.h>t
const ll mx=1e6+5,M=1e9+7;
using namespace std;
ll a[mx],b,d,ans[mx],res;
struct qwer{
	ll x,y;
};
qwer s[mx];
int main(){
	cin>>b>>d;
	for(int i=0;i<b;i++){
		cin>>a[i];
	}
	for(int i=0;i<d;i++){
		cin>>s[i].x>>s[i].y;
	}
	for(int i=0;i<d;i++){
		res=0;
		for(int j=s[i].x-1;j<s[i].y;j++){
			res+=a[j];
		}
		if(res>0){
			for(int j=s[i].x-1;j<s[i].y;j++){
				ans[j]++;
			}
		}
	}
	res=0;
	for(int i=0;i<b;i++){
		res+=(a[i]*ans[i]);
	}
	cout<<res;
	return 0;
}


#include <bits/stdc++.h>
const ll mx=1e6+5,M=1e9+7;
using namespace std;
ll a[mx],b,d,ans[mx],res;
struct qwer{
	ll x,y;
};
qwer s[mx];
int main(){
	cin>>b>>d;
	for(int i=0;i<b;i++){
		cin>>a[i];
	}
	for(int i=0;i<d;i++){
		cin>>s[i].x>>s[i].y;
	}
	for(int i=0;i<d;i++){
		res=0;
		for(int j=s[i].x-1;j<s[i].y;j++){
			res+=a[j];
		}
		if(res>0){
			for(int j=s[i].x-1;j<s[i].y;j++){
				ans[j]++;
			}
		}
	}
	res=0;
	for(int i=0;i<b;i++){
		res+=(a[i]*ans[i]);
	}
	cout<<res;
	return 0;
}


#include <bits/stdc++.h>
#define ll long long int
const ll mx=1e6+5,M=1e9+7;
using namespace std;
ll a[mx],b,d,ans[mx],res;
struct qwer{
	ll x,y;
};
qwer s[mx];
int main(){
	cin>>b>>d;
	for(int i=0;i<b;i++){
		cin>>a[i];
	}
	for(int i=0;i<d;i++){
		cin>>s[i].x>>s[i].y;
	}
	for(int i=0;i<d;i++){
		res=0;
		for(int j=s[i].x-1;j<s[i].y;j++){
			res+=a[j];
		}
		if(res>0){
			for(int j=s[i].x-1;j<s[i].y;j++){
				ans[j]++;
			}
		}
	}
	res=0;
	for(int i=0;i<b;i++){
		res+=(a[i]*ans[i]);
	}
	cout<<res;
	return 0;
}


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

template <class T> int size(const T &x) {return x.size();}
template <class T> T mod(T a, T b) { return (b + (a % b)) % b;}

#define F first
#define S second
#define PB push_back
#define endl '\n'
#define rep(i, a, b) for(__typeof(a) i=a; i<(b); i++)
#define iter(it, c) for(__typeof((c).begin()) it=(c).begin(); \
 it != (c).end(); it++)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef set<int> si;

const int INF = ~(1 << 31);
const double EPS = 1e-9;
const double PI = acos(-1);

int eval(map<int, int> &dic) {
    int sum = 0;
    iter(it, dic)
        sum += (*it).F * (*it).S;
    return sum;
}

int main() {
    int n, m, answ;
    cin >> n >> m;
    vi A(n); vii B(m);
    for(int &i : A) cin >> i;
    for(ii &i : B) {
        cin >> i.F >> i.S;

        int sm = 0;
        rep(a, i.F - 1, i.S)
            sm += A[a];
        if(sm > 0) answ += sm;
    }

    cout << answ << endl;
    return 0;
}


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

template <class T> int size(const T &x) {return x.size();}
template <class T> T mod(T a, T b) { return (b + (a % b)) % b;}

#define F first
#define S second
#define PB push_back
#define endl '\n'
#define rep(i, a, b) for(__typeof(a) i=a; i<(b); i++)
#define iter(it, c) for(__typeof((c).begin()) it=(c).begin(); \
 it != (c).end(); it++)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef set<int> si;

const int INF = ~(1 << 31);
const double EPS = 1e-9;
const double PI = acos(-1);

int eval(map<int, int> &dic) {
    int sum = 0;
    iter(it, dic)
        sum += (*it).F * (*it).S;
    return sum;
}

int main() {
    int n, m;
    cin >> n >> m;
    vi A(n); vii B(m);
    map<int, int> dic;
    for(int &i : A) cin >> i;
    for(ii &i : B) {
        cin >> i.F >> i.S;
        rep(a, i.F - 1, i.S)
            dic[A[a]]++;
    }

    int mx = eval(dic);
    rep(i, 0, size(B)) {
        // Se quita i
        rep(a, B[i].F - 1, B[i].S)
            dic[A[a]]--;

        mx = max(mx, eval(dic));

        rep(j, i + 1, size(B)) {
            // Se quita [j, k]
            rep(k, j, size(B)) {
                rep(a, B[k].F - 1, B[k].S)
                    dic[A[a]]--;
                mx = max(mx, eval(dic));
            }
            // Se pone [j, k]
            rep(k, j, size(B)) {
                rep(a, B[k].F, B[k].S)
                    dic[A[a]]++;
                mx = max(mx, eval(dic));
            }

            mx = max(mx, eval(dic));
        }
        // Se pone i
        rep(a, B[i].F - 1, B[i].S)
            dic[A[a]]++;
    }

    cout << mx << endl;
    return 0;
}


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

template <class T> int size(const T &x) {return x.size();}
template <class T> T mod(T a, T b) { return (b + (a % b)) % b;}

#define F first
#define S second
#define PB push_back
#define endl '\n'
#define rep(i, a, b) for(__typeof(a) i=a; i<(b); i++)
#define iter(it, c) for(__typeof((c).begin()) it=(c).begin(); \
 it != (c).end(); it++)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef set<int> si;

const int INF = ~(1 << 31);
const double EPS = 1e-9;
const double PI = acos(-1);

int eval(map<int, int> &dic) {
    int sum = 0;
    iter(it, dic)
        sum += (*it).F * (*it).S;
    return sum;
}

int main() {
    int n, m;
    cin >> n >> m;
    vi A(n); vii B(m);
    map<int, int> dic;
    for(int &i : A) cin >> i;
    for(ii &i : B) {
        cin >> i.F >> i.S;
        rep(a, i.F - 1, i.S)
            dic[A[a]]++;
    }

    int mx = eval(dic);
    rep(i, 0, size(B)) {
        // Se quita i
        rep(a, B[i].F - 1, B[i].S)
            dic[A[a]]--;

        rep(j, i + 1, size(B)) {
            // Se quita [j, k]
            rep(k, j, size(B)) {
                rep(a, B[k].F - 1, B[k].S)
                    dic[A[a]]--;
                mx = max(mx, eval(dic));
            }
            // Se pone [j, k]
            rep(k, j, size(B)) {
                rep(a, B[k].F, B[k].S)
                    dic[A[a]]++;
                mx = max(mx, eval(dic));
            }

            mx = max(mx, eval(dic));
        }
        // Se pone i
        rep(a, B[i].F - 1, B[i].S)
            dic[A[a]]++;
    }

    cout << mx << endl;
    return 0;
}


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

template <class T> int size(const T &x) {return x.size();}
template <class T> T mod(T a, T b) { return (b + (a % b)) % b;}

#define F first
#define S second
#define PB push_back
#define endl '\n'
#define rep(i, a, b) for(__typeof(a) i=a; i<(b); i++)
#define iter(it, c) for(__typeof((c).begin()) it=(c).begin(); \
 it != (c).end(); it++)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef set<int> si;

const int INF = ~(1 << 31);
const double EPS = 1e-9;
const double PI = acos(-1);

int eval(map<int, int> &dic) {
    int sum = 0;
    iter(it, dic)
        sum += (*it).F * (*it).S;
    return sum;
}

int main() {
    int n, m, answ = 0;
    cin >> n >> m;
    vi A(n); vii B(m);
    for(int &i : A) cin >> i;
    for(ii &i : B) {
        cin >> i.F >> i.S;

        int sm = 0;
        rep(a, i.F - 1, i.S)
            sm += A[a];
        if(sm > 0) answ += sm;
    }

    cout << answ << endl;
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
using namespace std ;
// big mode
ll power(ll n, ll p, ll mod)
{
    if(p == 0)return 1 ;
    if(p%2 == 0)
    {
        ll c = power(n,p/2,mod);
        return (c%mod * c%mod) % mod ;
    }
    return (n%mod * power(n,p - 1,mod)%mod) % mod;
}

ull gcd(ull a, ull b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

int n , i , m ;

int arr[102] , a[102] , l , r ;

int dp[102][30000];

int solve(int index , int num)
{
    if(index == m)return 0 ;
    int &ret = dp[index][num] ;
    if(ret != -1)return ret ;
    int c1 = solve(index + 1 , num);
    int c2 = solve(index + 1 , a[index]) + a[index];
    return ret = max(c1,c2);
}

int main()
{
    ios_base::sync_with_stdio(0);

    memset(dp , -1 , sizeof dp);

    cin >> n >> m ;

    rep(i,n)cin >> arr[i] ;

    rep(i,m)
    {
        int sum = 0;
        cin >> l >> r ;
        for(int j=l-1;j<r;j++)sum += arr[j];
        a[i] = sum ;
    }
    cout << solve(0,0);
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
using namespace std ;
// big mode
ll power(ll n, ll p, ll mod)
{
    if(p == 0)return 1 ;
    if(p%2 == 0)
    {
        ll c = power(n,p/2,mod);
        return (c%mod * c%mod) % mod ;
    }
    return (n%mod * power(n,p - 1,mod)%mod) % mod;
}

ull gcd(ull a, ull b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

int n , i , m ;

int arr[102] , a[102] , l , r ;

int dp[102][20005];

int solve(int index , int num)
{
    if(index == m)return 0 ;
    int &ret = dp[index][num + 10000] ;
    if(ret != -1)return ret ;
    int c1 = solve(index + 1 , num);
    int c2 = solve(index + 1 , num) + a[index];
    return ret = max(c1,c2);
}

int main()
{
    ios_base::sync_with_stdio(0);

    memset(dp , -1 , sizeof dp);

    cin >> n >> m ;

    rep(i,n)cin >> arr[i] ;

    rep(i,m)
    {
        int sum = 0;
        cin >> l >> r ;
        for(int j=l-1;j<r;j++)sum += arr[j];
        a[i] = sum ;
    }
    cout << solve(0,0);
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
using namespace std ;
// big mode
ll power(ll n, ll p, ll mod)
{
    if(p == 0)return 1 ;
    if(p%2 == 0)
    {
        ll c = power(n,p/2,mod);
        return (c%mod * c%mod) % mod ;
    }
    return (n%mod * power(n,p - 1,mod)%mod) % mod;
}

ull gcd(ull a, ull b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

int n , i , m ;

int arr[102] , a[102] , l , r ;

int dp[102][20005];

int solve(int index , int sum)
{
    if(index == m)return 0 ;
    int &ret = dp[index][sum] ;
    if(ret != -1)return ret ;
    int c1 = solve(index + 1 , sum);
    int c2 = solve(index + 1 , sum + a[index]) + a[index];
    return ret = max(c1,c2);
}

int main()
{
    ios_base::sync_with_stdio(0);

    memset(dp , -1 , sizeof dp);

    cin >> n >> m ;

    rep(i,n)cin >> arr[i] ;

    rep(i,m)
    {
        int sum = 0;
        cin >> l >> r ;
        for(int j=l-1;j<r;j++)sum += arr[j];
        a[i] = sum ;
    }
    cout << solve(0,0);
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
using namespace std ;
// big mode
ll power(ll n, ll p, ll mod)
{
    if(p == 0)return 1 ;
    if(p%2 == 0)
    {
        ll c = power(n,p/2,mod);
        return (c%mod * c%mod) % mod ;
    }
    return (n%mod * power(n,p - 1,mod)%mod) % mod;
}

ull gcd(ull a, ull b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

int n , i , m ;

int arr[102] , a[102] , l , r ;

int dp[102][300];

int solve(int index , int num)
{
    if(index == m)return 0 ;
    int &ret = dp[index][num+100] ;
    if(ret != -1)return ret ;
    int c1 = solve(index + 1 , num);
    int c2 = solve(index + 1 , a[index]) + a[index];
    return ret = max(c1,c2);
}

int main()
{
    ios_base::sync_with_stdio(0);

    memset(dp , -1 , sizeof dp);

    cin >> n >> m ;

    rep(i,n)cin >> arr[i] ;

    rep(i,m)
    {
        int sum = 0;
        cin >> l >> r ;
        for(int j=l-1;j<r;j++)sum += arr[j];
        a[i] = sum ;
    }
    cout << solve(0,0);
    return 0;
}


#include <iostream>
#include <cstdio>

using namespace std;

int A[200];
int pre[200];
int main()
{
    int n,m;
    cin>>n>>m;
    pre[0] = 0;
    for(int i = 0 ;i <n ;i++ )
    {
        cin>>A[i];
        pre[i+1] = pre[i] + A[i];
    }
    int l , r;
    int sum = -1 , ans = 0;
    for(int i = 0 ; i<m ; i++)
    {
        cin>>l>>r;
        sum = pre[r] - pre[l-1];
        if(sum>0)
        {
            ans+=sum;
        }
    }
    cout<<ans<<endl;
}


#include <iostream>
#include <cstdio>
#include <algorithm>

typedef long long ll;
using namespace std;

int main()
{
    ll n,a,b,c;

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

    ll m = n%4;

    if(m==0)
    {
        cout<<0<<endl;
        return 0;
    }
    else if(m == 3)
    {
        ll ans = a;
        ans = min(ans,3*c);
        ans = min(ans,c+b);
        cout<<ans<<endl;
    }
    else if(m == 2)
    {
        ll ans = b;
        ans = min(ans,2*a);
        ans = min(ans,2*c);
        cout<<ans<<endl;
    }
    else if(m == 1)
    {
        ll ans = c;
        ans = min(ans,3*a);
        ans = min(a+b,ans);
        cout<<ans<<endl;
    }
    return 0 ;
}


//Handle: creed13605

#include<bits/stdc++.h>

using namespace std;

#define PRINT(X) cout << X << endl;
#define READ(X) cin << X;
#define FOR(i,N) for(int i=0;i<N;i++)
#define FORR(i,a,b) for(int i=a;i<b;i++)
#define ALL(x) (x.begin(),x.end())

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

const int MAXN = 1234567;
const int MOD = 1e9 + 7;
int arr[123];
int L[123];
int R[123];
int mood[123];
int main()
 {

 //freopen("input.txt", "r", stdin);
 //freopen("out.txt", "w", stdout);

 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
 cout.tie ( 0 );

 int N, M;
 cin >> N >> M;
 for ( int i = 0; i < N; i++ ) cin >> arr[i];

 for ( int i = 0; i < M; i++ ) cin >> L[i] >> R[i];

 for ( int i = 0; i < M; i++ ) {
   int sum = 0;
   for ( int j = L[i] - 1; j < R[i]; j++ ) {
     sum += arr[j];
     }
   mood[i] = sum;
   }
 int ans = 0;
 for ( int i = 0; i < M; i++ ) {
   if ( mood[i] > 0 )
    ans += mood[i];
   }
 cout << ans << endl;

 return 0;
 }


//Handle: creed13605

#include<bits/stdc++.h>

using namespace std;

#define PRINT(X) cout << X << endl;
#define READ(X) cin << X;
#define FOR(i,N) for(int i=0;i<N;i++)
#define FORR(i,a,b) for(int i=a;i<b;i++)
#define ALL(x) (x.begin(),x.end())

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

const int MAXN = 1234567;
const int MOD = 1e9 + 7;
int arr[123];
int L[123];
int R[123];
int mood[123];
int main()
 {

 //freopen("input.txt", "r", stdin);
 //freopen("out.txt", "w", stdout);

 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
 cout.tie ( 0 );

 int N, M;
 cin >> N >> M;
 for ( int i = 0; i < N; i++ ) cin >> arr[i];

 for ( int i = 0; i < M; i++ ) cin >> L[i] >> R[i];

 for ( int i = 0; i < M; i++ ) {
   int sum = 0;
   for ( int j = L[i] - 1; j < R[i]; j++ ) {
     sum += arr[j];
     }
   mood[i] = sum;
   }
 int ans = 0;
 for ( int i = 0; i < N; i++ ) {
   if ( mood[i] > 0 )
    ans += mood[i];
   }
 cout << ans << endl;

 return 0;
 }


#include <iostream>

using namespace std;

long long n,k,i,a[501],s[501],x,st,d,sc,smax;

int main()
{
    cin>>n>>k;
    for(i=1;i<=n;i++)
    {
        cin>>x;
        s[i]=s[i-1]+x;
    }
    for(i=1;i<=k;i++)
    {
        cin>>st>>d;
        a[i]=s[d]-s[st-1];
    }
    for(i=1;i<=k;i++)
    {
        sc+=a[i];
        if(sc<0)sc=0;
        smax=max(smax,sc);
    }
    cout<<smax;
    return 0;
}


#include <iostream>

using namespace std;

long long n,k,i,a[501],s[501],x,st,d,sc,smax;

int main()
{
    cin>>n>>k;
    for(i=1;i<=n;i++)
    {
        cin>>x;
        s[i]=s[i-1]+x;
    }
    for(i=1;i<=k;i++)
    {
        cin>>st>>d;
        a[i]=s[d]-s[st-1];
    }
    for(i=1;i<=k;i++)
    {
        if(a[i]<0)sc+=a[i];
    }
    cout<<sc;
    return 0;
}


#include <iostream>

using namespace std;

long long n,k,i,a[501],s[501],x,st,d,sc,smax;

int main()
{
    cin>>n>>k;
    for(i=1;i<=n;i++)
    {
        cin>>x;
        s[i]=s[i-1]+x;
    }
    for(i=1;i<=k;i++)
    {
        cin>>st>>d;
        a[i]=s[d]-s[st-1];
    }
    for(i=1;i<=k;i++)
    {
        sc+=a[i];
        smax=max(smax,sc);
        if(sc<0)sc=0;
    }
    cout<<smax;
    return 0;
}


#include <iostream>

using namespace std;

long long n,k,i,a[501],s[501],x,st,d,sc,smax;

int main()
{
    cin>>n>>k;
    for(i=1;i<=n;i++)
    {
        cin>>x;
        s[i]=s[i-1]+x;
    }
    for(i=1;i<=k;i++)
    {
        cin>>st>>d;
        a[i]=s[d]-s[st-1];
    }
    for(i=1;i<=k;i++)
    {
        if(a[i]>0)sc+=a[i];
    }
    cout<<sc;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(){

    int n,m,x,y,c = 0,d = 0;

    cin >> n >> m;

    vector<int> arr(n);

    for(int i = 0;i < n;i++){
        cin >> arr[i];
    }
    for(int i = 0;i < m;i++){
        cin >> x >> y;
        for(int j = x-1;j <= y-1;j++){
            c += arr[j];
        }
        if(c > 0)
            d += c;
        c = 0;
    }
    cout << d;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(){
    int n,m;

    cin >> n >> m;

    vector < vector <int> > arr(n)(m);

    for(int i = 0;i < n;i++){
        for(int j = 0;j < m;j++){
            cin >> arr[i][j];
        }
    }
    return 0;
}


#include<iostream>
using namespace std;
long long a[200], b[200]={0};
int main(){
    int n, m, i, j, x, y;
    cin>>n>>m;
    for(i=1; i<=n; i++)
        cin>>a[i];
    for(i=1; i<=m; i++){
        cin>>x>>y;
        long long v=0;
        for(j=x; j<=y; j++){
            v+=a[j];
        }
        if(v>0){
//            cout<<x<<" "<<y<<endl;
            for(j=x; j<=y; j++){
                b[j]++;
            }
        }
    }
    long long s=0;
    for(i=1; i<=n; i++){
        s+=(a[i]*b[i]);
    }
    cout<<s;
}


#include<iostream>
using namespace std;
long long a[200], b[200]={0};
int main(){
    int n, m, i, j, x, y;
    cin>>n>>m;
    for(i=1; i<=n; i++)
        cin>>a[i];
    for(i=1; i<=m; i++){
        cin>>x>>y;
        for(j=x; j<=y; j++){
            b[a[j]]++;
        }
    }
    long long s=0;
    for(i=1; i<=n; i++){
        s+=(a[i]*b[i]);
    }
    cout<<s;
}


#include<iostream>
using namespace std;
long long a[200], b[200]={0};
int main(){
    int n, m, i, j, x, y;
    cin>>n>>m;
    for(i=1; i<=n; i++)
        cin>>a[i];
    for(i=1; i<=m; i++){
        cin>>x>>y;
        for(j=x; j<=y; j++){
            b[a[j]]++;
        }
    }
    long long s=0;
    for(i=1; i<=n; i++){
        if(a[i]>0)
            s+=(a[i]*b[i]);
    }
    cout<<s;
}


#include<stdio.h>
using namespace std;
int a[105];
int main(){
    int n,m,i,ans=0,l,r;
    scanf("%d%d",&n,&m);
    for(i=1;i<=n;i++){
    	scanf("%d",&a[i]);
    	a[i]+=a[i-1];
	}
    for(i=1;i<=m;i++){
        scanf("%d%d",&l,&r);
        if(a[r]-a[l-1]>0){
        	ans=ans+a[r]-a[l-1];
		}
    }
    printf("%d",ans);
    return 0;
}


#include<stdio.h>
#include<cstring>
#include<algorithm>
#define HardBoy main()
#define ForMyLove return 0;
using namespace std;
const int MYDD = 1103;

int HardBoy {
	int n, m, a[MYDD], sum[MYDD];
	scanf("%d %d", &n, &m);
	sum[0] = 0;
	for(int j = 1; j <= n; j++) {
		scanf("%d", &a[j]);
		sum[j] = a[j] +sum[j-1];
	}

	int ans = 0;
	while(m--) {
		int u, v;
		scanf("%d %d", &u, &v);
		int tmp = sum[v] - sum[u-1];
		if(tmp > 0)	ans += tmp;
	}
	printf("%d\n", ans);
    return 0;
}


#include <iostream>

using namespace std;

const int MAX_N = 1000;

int main()
{
    int n, m;
    cin >> n >> m;

    int flowers[MAX_N];
    for (int i = 0; i < n; i++)
    {
        cin >> flowers[i];
    }

    pair<int, int> happiness[MAX_N];
    for (int i = 0; i < m; i++)
    {
        int l, r;
        cin >> l >> r;
        happiness[i] = {l - 1, r};
    }

    int flowers_left_sum[MAX_N];
    flowers_left_sum[0] = 0;
    for (int i = 0; i < n; i++)
    {
        flowers_left_sum[i + 1] = flowers_left_sum[i] + flowers[i];
    }

    long answer = 0;
    for (int i = 0; i < m; i++)
    {
        pair<int, int> subarray = happiness[i];
        int l = subarray.first, r = subarray.second;
        long subarray_sum = flowers_left_sum[r] - flowers_left_sum[l];

        if (subarray_sum > 0) answer += subarray_sum;
    }

    cout << answer;

    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;

    int flowers[100];
    for (int i = 0; i < n; i++)
    {
        cin >> flowers[i];
    }

    pair<int, int> happiness[100];
    for (int i = 0; i < m; i++)
    {
        int l, r;
        cin >> l >> r;
        happiness[i] = {l - 1, r};
    }

    int flowers_left_sum[100];
    flowers_left_sum[0] = 0;
    for (int i = 0; i < n; i++)
    {
        flowers_left_sum[i + 1] = flowers_left_sum[i] + flowers[i];
    }

    long answer = 0;
    for (int i = 0; i < m; i++)
    {
        pair<int, int> subarray = happiness[i];
        int l = subarray.first, r = subarray.second;
        long subarray_sum = flowers_left_sum[r] - flowers_left_sum[l];

        if (subarray_sum > 0) answer += subarray_sum;
    }

    cout << answer;

    return 0;
}


#include<iostream>
using namespace std;

int n,m,i,j,s,t,a,b;
int x[105];

int main()
{cin>>n>>m;
 for(i=0;i<n;i++)
   cin>>x[i];
 for(i=0;i<m;i++){
   cin>>a>>b;
   for(j=a;j<=b;j++)
     s+=x[a];
   if(s>0)
     t+=s;
 }
 cout<<s<<endl;
 return 0;
}


#include<iostream>
using namespace std;

int n,m,i,j,s,t,a,b;
int x[105];

int main()
{cin>>n>>m;
 for(i=0;i<n;i++)
   cin>>x[i];
 for(i=0;i<m;i++){
   cin>>a>>b;
   for(j=a;j<=b;j++)
     s+=y[a];
   if(s>0)
     t+=s;
 }
 cout<<s<<endl;
 return 0;
}


#include<iostream>
using namespace std;

int n,m,i,j,s,t,a,b;
int x[105];

int main()
{cin>>n>>m;
 for(i=1;i<=n;i++)
   cin>>x[i];
 for(i=1;i<=m;i++){
   s=0;
   cin>>a>>b;
   for(j=a;j<=b;j++)
     s+=x[j];
   if(s>0)
     t+=s;
 }
 cout<<t<<endl;
 return 0;
}


def ans(n,k):
    count=0
    sum=0
    s=''
    s2=''
    x=97
    for i in range(x,x+k,1):
        s+=chr(i)
    for i in range(0,n//2,1):
        s2+=s
    print(s2[0:n])

t=int(input())
while(t>0):
    n,k=map(int,input().split())
    ans(n,k)
    t-=1


def ans(n,k):
    count=0
    sum=0
    s=''
    s2=''
    x=97
    for i in range(x,x+k,1):
        s+=chr(i)
    for i in range(0,n//2 +1,1):
        s2+=s
    print(s2[0:n])

t=int(input())
while(t>0):
    s=''
    n,k=map(int,input().split())
    if(k==1):
        for i in range(0,n,1):
            s+='a'
        print(s)
    else:
        ans(n,k)
    t-=1


in=int(input())
for j in range(in):
       l,no=list(map(int,input().split()))
       sp=""
       for i in range(l):
              sp+=chr(i%no+97)
       l=list(sp)
       l.sort(reverse=True)
       sp="".join(l)
       print(sp)


l=int(input())

s=list(map(int,input().split()))
s.sort()
c=0
d=0
for i in range(0,l,2):
    c=c+s[i]
for i in range(1,l,2):
    d=d+s[i]
print(d-c)


n1=int(input())
st="abcdefghijklmnopqrstuvwxyz"
for i in range(n1):
    num,k=[int(i) for i in input().split()]
    q=1
    r=1
    while(q<=num):
        if r>k:
            r=1
        print(st[r],end="")
        r+=1
        q+=1
    print()


inp=int(input())
for j in range(inp):
       l,no=list(map(int,input().split()))
       sp=""
       for i in range(l):
              sp+=chr(i%no+97)
       l=list(sp)
       l.sort(reverse=True)
       sp="".join(l)
       print(sp)


in=int(input())
for k in range(in):
       li,no=list(map(int,input().split()))
       sp=""
       for i in range(li):
              sp+=chr(i%no+97)
       li=list(sp)
       li.sort(reverse=True)
       sp="".join(li)
       print(sp)


n1 = int(input())
for _ in range (n1):
	n, k = map(int,input().split())
	mpmf, s = int(n/k), ''
	for i in range(0,k):
		if i==k-1:
			s += chr(97+i)*(n-len(s))
		else:
			s += chr(97+i)*mpmf
	print(s)


n1 = int(input())
for _ in range (n1):
	n, k = map(int,input().split())
	mpmf, s = int(n/k), ''
	for i in range(0,k):
		if i==k-1:
			print(101, n-len(s))
			s += chr(97+i)*(n-len(s))
		else:
			s += chr(97+i)*mpmf
	print(s)


for i in range(int(input())):
    a,b=map(int,input().split())
    s=''
    i=0
    for _ in range(b):
        s+=str(chr(i+97))
        i+=1
    p=a//b
    d=''
    for i in range(p):
        if i%2==0:
            d+=s
        else:
            d+=s[::-1]
    print(''.join(str(i) for i in sorted(d[:a])[::-1]))


z=input;
from math import *
for _ in range(int(z())):

    a,b=list(map(int,z().split()))
    s=''
    for i in range(97,97+b):
        s+=chr(i)
    t=''
    for i in range(ceil(a/len(s))):
        t+=s
    print(t[:a])


for i in range(int(input())):
    a,b=map(int,input().split())
    s=''
    i=0
    for _ in range(b):
        s+=str(chr(i+97))
        i+=1
    p=a//b
    d=''
    for i in range(p):
        if i%2==0:
            d+=s
        else:
            d+=s[::-1]
    print(''.join(str(i) for i in sorted(d[:a])))


for i in range(int(input())):
    a,b=map(int,input().split())
    s=''
    i=0
    for _ in range(b):
        s+=str(chr(i+97))
        i+=1
    p=a//b
    d=''
    for i in range(p):
        if i%2==0:
            d+=s
        else:
            d+=s[::-1]
    print(d[:a])


n=int(input())
for i in range(n):
    n,k=map(int,input().split())
    p=[chr(j) for j in range(97,k+97)]
    # print(p)
    q=n//k
    for i in range(len(p)):
        p[i]=p[i]*q
    if n%k!=0:
        p.append("a")
    print(*p,sep="")


t=int(input())
for i in range(t):
    w=""
    n,k=map(int,input().split())
    for i in range(97,97+k):
        w+=chr(i)*(n//k)
    r=n%k
    for i in range(97,97+r):
        w+=chr(i)
    print(w)


t = int(input())
kod = 97

for i in range(t):
    n, k = map(int, input().split())
    s  = ''
    for j in range(n):
        s += str(chr(kod))
        kod += 1
        if kod == 97 + k:
            kod = 97
    print(s)


t = int(input())
kod = 97

for i in range(t):
    n, k = map(int, input().split())
    s  = ''
    for j in range(n):
        s += chr(j % k + 97)
    print(s)


t = int(input())
kod = 97

for i in range(t):
    n, k = map(int, input().split())
    s  = ''
    for j in range(n):
        s += chr(j % n + 97)
    print(s)


for i in range(int(input())):
    a, b = map(int, input().split())
    s = str()
    j = 97
    while len(s) < a:
        s += chr(j)
        j += 1
        if j == 97+b:
            j = 97
    print(s)


for i in range(int(input())):
    a, b = map(int, input().split())
    s = str()
    for j in range(97, 97+b):
        s += chr(j)
    for k in range(a-b):
        s += 'a'
    print(s)


t = int(input())
alphabet = "abcdefghijklmnopqrstuvwxyz"

while t > 0:
    s = ''
    n, k = map(int, input().split())
    freq = int(n/k)

    extra = n - freq*k

    for i in range(k):
        s += alphabet[i] * freq

    s += alphabet[0] * extra
    print(s)

    t -= 1


t = int(input())
while t>0:
    n, k = map(int, input().split())
    for i in range(n):
        print(chr(97 + i%k), end = "")
    t -= 1


t = int(input())
while t>0:
    n, k = map(int, input().split())
    for i in range(n):
        print(chr(97 + i%k), end = "")
    print()
    t -= 1


for i in range(int(input())):
	n , k = map(int,input().split())
	l = []
	m = n//k
	for j in range(97,97+k):
		l.append(chr(j)*m)
	# print(l)
	y = "".join(l)
	print(y)


for i in range(int(input())):
	n , k = map(int,input().split())
	l = []
	m = n//k
	for j in range(97,97+k):
		l.append(chr(j)*m)
	# print(l)
	# y = "".join(l)
	# print(y)
	# print(len(l),m*k)
	if n>m*k:
		l.append(chr(j)*(n-(m*k)))
		y = "".join(l)
	else:
		y = "".join(l)
	print(y)


for i in range(int(input())):
	n,k=map(int,input().split())
	a=n//k
	for i in range(n):
	 print(chr(97+i%k),end='')


for i in range(int(input())):
	n,k=map(int,input().split())
	a=n//k
	for i in range(n):
		print(chr(97+i%k),end='')
	print()


t = int(input())
while(t):
    n, l = list(map(int,input().split()))
    d = n//l
    s = ""
    sum = n
    for i in range(97,97+n):
        if len(s)>=n or sum<d:
            break
        elif len(s)!=n:
            s = s + chr(i)*d
            sum = sum - d
    s = s + s[-1]*(n - len(s))
    print(s)
    t = t - 1


t = int(input())
while(t):
    n, l = list(map(int,input().split()))
    d = n//l
    s = ""
    sum = n
    for i in range(97,97+l):
        if len(s)>=n or sum<d:
            break
        elif len(s)!=n:
            s = s + chr(i%123)*d
            sum = sum - d
    s = s + s[-1]*(n - len(s))
    print(s)
    t = t - 1


t = int(input())
while(t):
    n, l = list(map(int,input().split()))
    d = n//l
    s = ""
    sum = n
    for i in range(97,97+l):
        if len(s)>=n or sum<d:
            break
        elif len(s)!=n:
            s = s + chr(i%122)*d
            sum = sum - d
    s = s + s[-1]*(n - len(s))
    print(s)
    t = t - 1


# import sys
# sys.stdin=open("input1.in","r")
# sys.stdout=ope
# n("output1.out","w")
T=int(input())
while T:
	N,K=map(int,input().split())
	X=""
	for i in range(K):
		X=X+chr(97+i)
	print(X*int(N/K),end='')
	for i in range(N%K):
		print(X[i],end='')
	print()
	T-=1


# import sys
# sys.stdin=open("input1.in","r")
# sys.stdout=open("output1.out","w")
N,K=map(int,input().split())
X=""
for i in range(K):
	X=X+chr(97+i)
print(X*int(N/K)+X[(N%K)-1])


# import sys
# sys.stdin=open("input1.in","r")
# sys.stdout=open("output1.out","w")
T=int(input())
while T:
	N,K=map(int,input().split())
	X=""
	for i in range(K):
		X=X+chr(97+i)
	print(X*int(N/K)+X[(N%K)-1])
	T-=1


import string
t=int(input())
while(t>0):
    t-=1
    len_str,num=(map(int,input().split()))
    s=string.ascii_lowercase[:num]
    while(len(s)<len_str):
        s=s*2
    print(s[:len_str])


import string
m=int(input())
while(m>0):
    t-=1
    len,n=(map(int,input().split()))
    p=string.ascii_lowercase[:n]
    while(len(s)<len):
        p=p*2
    print(p[:len])


import string
m=int(input())
while(m>0):
    m-=1
    len,n=(map(int,input().split()))
    p=string.ascii_lowercase[:n]
    while(len(s)<len):
        p=p*2
    print(p[:len])


import string
p=int(input())
while(t>0):
    t-=1
    len,n=(map(int,input().split()))
    p=string.ascii_lowercase[:n]
    while(len(s)<len):
        p=p*2
    print(p[:len])


n=int(input())
l=list(map(int,input().split()))
l.sort()
sum_at_even=(sum(l[0::2]))
sum_at_odd=(sum(l[1::2]))
print(abs(sum_at_even-sum_at_odd))


import string
p=int(input())
while(t>0):
    t-=1
    len,n=(map(int,input().split()))
    s=string.ascii_lowercase[:n]
    while(len(s)<len):
        p=p*2
    print(p[:len])


for _ in range(int(input())):
  n, k = map(int, input().split())
  alphabets = "abcdefghijklmnopqrstuvwxyz"

  string = alphabets[:k]
  if n % 2 == 0:
    print(string*(n//k))
  else:
    print(string*(n//k)+alphabets[0])


for _ in range(int(input())):
  n, k = map(int, input().split())
  alphabets = "abcdefghijklmnopqrstuvwxyz"

  string = ""
  while len(string) != n:
    for i in range(k):
      string += alphabets[i]
  print(string)


for _ in range(int(input())):
  n, k = map(int, input().split())
  alphabets = "abcdefghijklmnopqrstuvwxyz"

  string = ""
  while True:
    for i in range(k):
      string += alphabets[i]
      if len(string) == n:
        break
    if len(string) == n:
      break
  print(string)


for _ in range(int(input())):
  n, k = map(int, input().split())
  alphabets = "abcdefghijklmnopqrstuvwxyz"

  string = alphabets[:k-1]
  if n % 2 == 0:
    print(string*(n//k))
  else:
    print(string*(n//k)+alphabets[0])


import string
t = int(input())
s1 = list(string.ascii_lowercase)
while(t>0):
    s = ''
    n,k = map(int,input().split())
    while(len(s)<n):
        for i in range(0,k):
            if(len(s) == n):
                break
            s += s1[i]
    print(s)
    t-=1


import string
t = int(input())
while(t>0):
    s = list(string.ascii_lowercase)
    n,k = map(int,input().split())
    if(n==k):
        x=n
        s1 = s[0:x]
        a = ''.join(map(str,s1))
        a = a*1
    else:
        x = k
        s1 = s[0:x]
        a = ''.join(map(str,s1))
        if(n%k==0):
            a = a*x
        else:
            a = a*(n//k)
    if(len(a) == n):
        print(a)
    else:
        for i in range(0,k):
            if(len(a)==n):
                break
            else:
                a = a + s[i]
        print(a)
    t-=1


import string
t = int(input())
s = list(string.ascii_lowercase)
while(t>0):

    n,k = map(int,input().split())
    if(n==k):
        x=n
        s1 = s[0:x]
        a = ''.join(map(str,s1))
        a = a*1
    else:
        x = k
        s1 = s[0:x]
        a = ''.join(map(str,s1))
        if(n%k==0):
            a = a*x
        else:
            a = a*(n//k)
    if(len(a) == n):
        print(a)
    else:
        for i in range(0,k):
            if(len(a)==n):
                break
            else:
                a = a + s[i]
        print(a)
    t-=1


t = int(input())
ans = ""
for i in range(t):
    n,k = map(int,input().split())
    for j in range(1,n+1):
        ans += chr(96+j)
    print(ans)
    ans = ""


t = int(input())
for i in range(t):
    n,k = map(int,input().split())
    for i in range(n):
        print(chr(97+i%k),end="")
    print()


j = int(input())
ans = ""
for i in range():
    n,k = map(int,input().split())
    for i in range(1,n):
        if i % 2 != 0:
            ans += "a"
        else:
            ans += "b"
    print(ans + chr(k + 96))
    ans = ""


j = int(input())
ans = ""
for i in range(j):
    n,k = map(int,input().split())
    for i in range(1,n):
        if i % 2 != 0:
            ans += "a"
        else:
            ans += "b"
    print(ans + chr(k + 96))
    ans = ""


a = int(input())
b = [int(x) for x in input().split()]
c = 0
b.sort()
for i in range(int(a/2)):
    c += int(max(b[i], b[i+1]) - min(b[i], b[i+1]))
print(c)


a = int(input())
b = []
col = 'abcdefghijklmnopqrstuvwxyz'
for i in range(a):
    c = [int(x) for x in input().split()]
    b.append(c)
for i in b:
    x = i[0]
    y = i[1]
    print(col[:y] * (x // y) + col[:(x%y)])


t=int(input())
print(ord("a"))
print(chr(97))
for i in range (t):
	l,n=map(int,input().split())
	alp=[97+i for i in range (n)]

	while l!=0:
		for i in alp :
			if l<=0:
				break
			print(chr(i),end=" ")
			l-=1
	print()


t=int(input())
for i in range (t):
	l,n=map(int,input().split())
	alp=[97+i for i in range (n)]

	while l!=0:
		for i in alp :
			if l<=0:
				break
			print(chr(i),end="")
			l-=1
	print()


t=int(input())
print(ord("a"))
print(chr(97))
for i in range (t):
	l,n=map(int,input().split())
	alp=[97+i for i in range (n)]

	while l!=0:
		for i in alp :
			if l<=0:
				break
			print(chr(i),end="")
			l-=1
	print()


t = int(input())
for i in range(t):
    a = list(map(int, input.split()))
    n, k = a[0], a[1]
    c = 0
    s = ''
    for j in range(n):
        s += str(chr(97+c))
        c += 1
        if c >= k:
            c = 0
    print(s)


import sys
t = int(sys.stdin.readline())
for i in range(t):
    a = list(map(int, sys.stdin.readline()))
    n, k = a[0], a[1]
    c = 0
    s = ''
    for j in range(n):
        s += str(chr(97+c))
        c += 1
        if c >= k:
            c = 0
    print(s)


import sys
t = int(sys.stdin.readline())
for i in range(t):
    a = list(map(int, sys.stdin.readline().split()))
    n, k = a[0], a[1]
    c = 0
    s = ''
    for j in range(n):
        s += str(chr(97+c))
        c += 1
        if c >= k:
            c = 0
    print(s)


from random import randint
a=int(input())
b=[]
c=0
d=[]
e=0
f='abcdefghijklmnopqrstuvwxyz'
for i in range(a):
    n,k=map(int,input().split())
    for i in range(n):
        print(f[e],end='')
        e+=1
    e=0
    print()


a=int(input())
b=[]
c=0
d=[]
e=0
f='abcdefghijklmnopqrstuvwxyz'
g=''
for i in range(a):
    n,k=map(int,input().split())
    for i in range(n):
        if k>1:
            g+=f[e]
            e+=1
            if e==k:
                e=0
        else:
            g+=f[0]
    e=0
    d.append(g)
    g=''
for i in d:
    print(i)


from random import randint
a=int(input())
b=[]
c=0
d=[]
e=0
f='abcdefghijklmnopqrstuvwxyz'
for i in range(a):
    n,k=map(int,input().split())
    for i in range(n):
        print(f[e],end='')
        e+=1
        if e==k:
            e=0
    print()


a=int(input())
b=[]
c=0
d=[]
e=0
f='abcdefghijklmnopqrstuvwxyz'
for i in range(a):
    n,k=map(int,input().split())
    for i in range(n):
        if k>1:
            print(f[e],end='')
            e+=1
            if e==k:
                e=0
        else:
            print(f[0],end='')
    print()


t=int(input())
for i in range(t):
	n,k=list(map(int,input().split()))
	for i in range(n):
		print(''.join(chr(i%k+97))


t=int(input())
for i in range(t):
	n,k=list(map(int,input().split()))
		for i in range(n):
			print(''.join(chr(i%k+97))


t=int(input())
for i in range(t):
	n,k=list(map(int,input().split()))
	for i in range(n):
		print(''.join(chr(i%k+97)))


t=int(input())
for i in range(t):
	n,k=map(int,input().split())
	print(''.join(chr(i%k+97) for i in range(n)))


for _ in range(int(input))):
    n, k = map(int, input().split())
    print("".join(map(lambda x: chr(ord('a')+i%k), range(n))))


for _ in range(int(input())):
    n, k = map(int, input().split())
    print("".join(map(lambda x: chr(ord('a')+i%k), range(n))))


for _ in range(int(input())):
    n, k = map(int, input().split())
    print("".join(map(lambda i: chr(ord('a')+i%k), range(n))))


from string import ascii_letters

def solve(n, k):
   return ascii_letters[:k]*(n//k) + ascii_letters[:(n % k)]

def main():
    for _ in range(int(input())):
        n, k = list(map(int, input().split()))
        print(solve(n, k))

main()


from string import ascii_letters

def solve(n, k):
    s = ''
    for i in range(n):
        s += ascii_letters[i % k]
    return s

def main():
    for _ in range(int(input())):
        n, k = list(map(int, input().split()))
        print(solve(n, k))

main()


t = int(input())
for i in range(t):
	n, k = map(int, input().split())
	for i in range(n):
		print(chr(ord('a') + i % k), end = '')


t = int(input())
for i in range(t):
	n, k = map(int, input().split())
	for j in range(n):
		print(chr(ord('a') + j % k), end = '')


t = int(input())
for i in range(t):
	n, k = map(int, input().split())
	for j in range(n):
		print(chr(ord('a') + j % k), end = '')
	print()


#print(" ".join(map(str, r)))

n = int(input())

a = "abcdefghijklmnopqrstuvwxyz"
b = " "
for j in range(n):
    m, k = map(int, input().split())
    for i in range(0, k):
        b += a[i] * (m//k)
    print(b)
    b = " "


#print(" ".join(map(str, r)))

n = int(input())
alf = "-abcdefghijklmnopqrstuvwxyz"

b = ""
for j in range(n):
    m, k = map(int, input().split())
    for i in range(1, k+1):
         b+=(alf[i]*(m//k))
    if m % 2 == 0:
        print(b)
    else:
        print(b + "a")
    b = ""


#print(" ".join(map(str, r)))

n = int(input())

a = "abcdefghijklmnopqrstuvwxyz"
b = ""
for j in range(n):
    m, k = map(int, input().split())
    for i in range(0, k):
        b += a[i] * (m//k)
    print(b)
    b = ""


#print(" ".join(map(str, r)))

n = int(input())
alf = "-abcdefghijklmnopqrstuvwxyz"

b = ""
c = ""
for j in range(n):
    m, k = map(int, input().split())
    for i in range(1, k+1):
         b+=(alf[i]*(m//k))
    if m % k == 0:
        print(b)
    else:
        for i in range(1, (m % k)+1):
            c+=alf[i]
        print(b + c)
    b = ""
    c = ""


#print(" ".join(map(str, r)))

n = int(input())

a = "abcdefghijklmnopqrstuvwxyz"
b = ""
for j in range(n):
    m, k = map(int, input().split())
    if m % k == 0:
        for i in range(0, k):
             b += a[i] * (m//k)
        print(b)
        b = ""
    else:
        for i in range(0, k):
            b += a[i] * (m//k)
        b += a[i]
        print(b)
        b = ""


#print(" ".join(map(str, r)))

n = int(input())
alf = "-abcdefghijklmnopqrstuvwxyz"

b = ""
c = ""
for j in range(n):
    m, k = map(int, input().split())
    for i in range(1, k+1):
         b+=(alf[i]*(m//k))
    if m % 2 == 0:
        print(b)
    else:
        for i in range(1, len(m % k)+1):
            c+=alf[i]

        print(b + c)
    b = ""
    c = ''


#print(" ".join(map(str, r)))

n = int(input())

a = "abcdefghijklmnopqrstuvwxyz"
b = ""
for j in range(n):
    m, k = map(int, input().split())
    if m % k == 0:
        for i in range(0, k):
             b += a[i] * (m//k)
        print(b)
    else:
        for i in range(0, k):
            b += a[i] * (m//k)
        b += a[i]
        print(b)


#print(" ".join(map(str, r)))

n = int(input())
alf = "-abcdefghijklmnopqrstuvwxyz"

b = ""
for j in range(n):
    m, k = map(int, input().split())
    for i in range(1, k+1):
         b+=(alf[i]*(m//k))
    if m % 2 == 0:
        print(b)
    else:
        print(b + "a")


x=int(input())
s="abcdefghijklmnopqrstuvwxyz"
for i in range(x):
                 a,b=[int(i) for i in input().split()]
                 y=1
                 z=1
                 while(y<=a):
                                  if(z>b):
                                                   z=1
                                  print(s[z],end=" ")
                                  z=z+1
                                  y=y+1
                 print()


x=int(input())
s="abcdefghijklmnopqrstuvwxyz"
for i in range(x):
                 a,b=[int(i) for i in input().split()]
                 y=z=1
                 while(y<=z):
                                  if(z>b):
                                                   z=1
                                  print(s[z],end=" ")
                                  z=z+1
                                  y=y+1
                 print()


x=int(input())
s="abcdefghijklmnopqrstuvwxyz"
for i in range(x):
                 a,b=[int(i) for i in input().split()]
                 y=1
                 z=1
                 while(y<=a):
                                  if(z>b):
                                                   z=1
                                  print(s[z],end="")
                                  z=z+1
                                  y=y+1
                 print()


x=int(input())
s="abcdefghijklmnopqrstuvwxyz"
for i in range(x):
                 a,b=[int(i) for i in input().split()]
                 y=1
                 z=1
                 while(y<=a):
                          if(z>b):
                                   z=1
                          print(s[z-1],end="")
                          z+=1
                          y+=1
                 print()


x=int(input())
s="abcdefghijklmnopqrstuvwxyz"
for i in range(x):
                 a,b=[int(i) for i in input().split()]
                 y=1
                 z=1
                 while(y<=a):
                          if(z>b):
                                   z=1
                          print(s[z],end="")
                          z+=1
                          y+=1
                 print()


t=int(input())
for q in range(0,t):
    n,k=input().split()
    n,k=[int(n),int(k)]
    a=[]
    l='a'
    ans=n//k
    i=0
    if n%2!=0 and n>=k:
        n-=1
        a.append(l)
    if n<k:
        while i<n:
            a.append(l)
            l=chr(ord(l)+1)
            i+=1
    else:
        while i < n:
            for j in range(0, ans):
                a.append(l)
                i += 1
                if i >= n:
                    break
            l = chr(ord(l) + 1)
    print(*a,sep="")


t=int(input())
for q in range(0,t):
    n,k=input().split()
    n,k=[int(n),int(k)]
    a=[]
    l='a'
    ans=n//k
    i=0
    if n%2!=0 and n>=k:
        n-=1
        a.append(l)
    if n<k:
        while i<n:
            a.append(l)
            l=chr(ord(l)+1)
            i+=1
    else:
        while i < n:
            for j in range(0, ans):
                a.append(l)
                i += 1
                if i >= n:
                    break
            if l=='z':
                l='a'
            else:
                l = chr(ord(l) + 1)
    print(*a,sep="")


t=int(input())
for q in range(0,t):
    n,k=input().split()
    n,k=[int(n),int(k)]
    a=[]
    l='a'
    ans=n//k
    i=0
    if n%2!=0:
        n-=1
        a.append(l)
    while i<n:
        for j in range(0,ans):
            a.append(l)
            i+=1
            if i>=n:
                break
        l=chr(ord(l)+1)
    print(*a,sep="")


#include<iostream>
#include<algorithm>
#include<vector>
//#include<cstdio>

using namespace std;

struct point{
    int x; int y;
};

struct paired{
    point p1; point p2;
};

int vprod(paired a, paired b){
    int dxa = a.p2.x - a.p1.x;
    int dyb = b.p2.y - b.p1.y;
    int dya = a.p2.y - a.p1.y;
    int dxb = b.p2.x - b.p1.x;
    return dxa*dyb - dya*dxb;
}

bool same(paired a, paired b){
    paired nb;
    nb.p1 = a.p1; nb.p2 = b.p1;
    return (vprod(a, b) == 0 ) && (vprod(a, nb) == 0);
}

paired ordered(paired a){
    point c;
    int dx = a.p2.x - a.p1.x;
    int dy = a.p2.y - a.p1.y;
    if ((dy < 0) || ((dy == 0) && (dx < 0))){
        c = a.p1; a.p1 = a.p2; a.p2 = c;
    }
    return a;
}

bool rotation_order (paired a, paired b){
    return vprod(ordered(a), ordered(b)) > 0;
}

struct shift_order {
        int DX, DY;
        shift_order(paired resp) {
            this -> DX = resp.p2.y - resp.p1.y;
            this -> DY = - (resp.p2.x - resp.p1.x); };
        bool operator () (paired a, paired b){
            int dx = b.p2.x - a.p2.x;
            int dy = b.p2.y - a.p2.y;
            return dx * DX + dy * DY > 0;
        }
};

int main(){

 //   freopen("in.txt", "r", stdin);
    unsigned long int n;
    cin >> n;
    unsigned long int tot = (n*(n - 1)*(n - 2))/6;

    vector<point> p;
    point t;
    for (int i = 0; i < n; i++){
        cin >> t.x >> t.y;
        p.push_back(t);
    }

    vector<paired> a;
    paired t2;
    for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++){
        t2.p1 = p[i];
        t2.p2 = p[j];
        a.push_back(t2);
    }
    sort(a.begin(), a.end(), rotation_order);

    vector<paired>::iterator a_it = a.begin();
    int i;
    unsigned long int cnt, dcnt;

    while (a_it < a.end()){

        paired tmp = *a_it;
        vector<paired> d;
        while ((a_it < a.end()) && (vprod(*a_it, tmp) == 0)) {
            d.push_back(*a_it); a_it++;
        };
        sort(d.begin(), d.end(), shift_order(tmp));
        i = 0;
        while (i < d.size()){
            cnt = 1;
            while ((i < d.size() - 1) && same(d[i], d[i+1])) {
                cnt++;
                i++;
            }
            dcnt = ((sqrt(1+8*cnt)-3)*cnt)/6;
            tot -= dcnt;
            i++;
        }
    }
    cout << tot;
    return 0;

}


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

struct point{ int x; int y; };
struct points_pair{ point p1; point p2; };

struct resp_comp {
        resp_comp(points_pair resp) {
            this -> DX = resp.p2.y - resp.p1.y;
            this -> DY = - (resp.p2.x - resp.p1.x);
        }
        bool operator () (points_pair a, points_pair b){
            int dx = b.p2.x - a.p2.x;
            int dy = b.p2.y - a.p2.y;
            return dx * DX + dy * DY > 0;
        }
        int DX, DY;
    };

int dphi(points_pair a, points_pair b){
    return (a.p2.x - a.p1.x)*(b.p2.y - b.p1.y) - (a.p2.y - a.p1.y)*(b.p2.x - b.p1.x);
}

int dphi2(points_pair a, points_pair b){
    points_pair na, nb;
    na.p1 = a.p1; na.p2 = b.p2;
    nb.p1 = b.p1; nb.p2 = a.p2;
    return dphi(na, nb);
}

bool comp(points_pair a, points_pair b){
    if (dphi(a, b) > 0) return true;
    else return false;
};

int main(){
    unsigned long int n;
    vector<point> p;
    vector<points_pair> a;
    point t;
    points_pair t2;

//    freopen("in.txt", "r", stdin);
    cin >> n;
    unsigned long int tot = n*(n - 1)*(n - 2)/6;

    for (int i = 0; i < n; i++){
        cin >> t.x >> t.y;
        p.push_back(t);
    }

    for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++){
        t2.p1 = p[i];
        t2.p2 = p[j];
        a.push_back(t2);
    }

    sort(a.begin(), a.end(), comp);

    vector<points_pair>::iterator a_it = a.begin();
    int i;
    unsigned long int cnt;
    while (a_it < a.end()){
        points_pair tmp = *a_it;
        vector<points_pair> d;

        while ((a_it < a.end()) && (dphi(*a_it, tmp) == 0)) {
            d.push_back(*a_it); a_it++;
        };

        sort(d.begin(), d.end(), resp_comp(tmp));

        i = 1;
        while (i < d.size()){
            cnt = 1;
            while ((i < d.size()) && (dphi2(d[i], d[i-1]) == 0)) {i++; cnt++; }
            tot -= ((sqrt(1+8*cnt)-3)/6)*cnt;
            i++;
        }
    }

    cout << tot;
    return 0;
}


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

struct point{ int x; int y; };
struct points_pair{ point p1; point p2; };

struct resp_comp {
        resp_comp(points_pair resp) { this->resp = resp; }
        bool operator () (points_pair a, points_pair b){
            return true;
        }
        points_pair resp;
    };

int dphi(points_pair a, points_pair b){
    return (a.p2.x - a.p1.x)*(b.p2.y - b.p1.y) - (a.p2.y - a.p1.y)*(b.p2.x - b.p1.x);
}

int dphi2(points_pair a, points_pair b){
    points_pair na, nb;
    na.p1 = a.p1; na.p2 = b.p2;
    nb.p1 = b.p1; nb.p2 = a.p2;
    return dphi(na, nb);
}

bool comp(points_pair a, points_pair b){
    if (dphi(a, b) > 0) return true;
    else return false;
};

int main(){
    int n;
    vector<point> p;
    vector<points_pair> a;
    point t;
    points_pair t2;

//    freopen("in.txt", "r", stdin);
    cin >> n;
    int tot = n*(n - 1)*(n - 2)/6;

    for (int i = 0; i < n; i++){
        cin >> t.x >> t.y;
        p.push_back(t);
    }

    for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++){
        t2.p1 = p[i];
        t2.p2 = p[j];
        a.push_back(t2);
    }

    sort(a.begin(), a.end(), comp);
    vector<points_pair>::iterator a_it = a.begin();

    int i, cnt;
    while (a_it < a.end()){
        points_pair tmp = *a_it;
        resp_comp order(tmp);
        vector<points_pair> d;

        while ((a_it < a.end()) && (dphi(*a_it, tmp) == 0)) {
            d.push_back(*a_it); a_it++;
        };

        sort(d.begin(), d.end(), order);
        i = 1; cnt = 1;
        while (i < d.size()){
            while ((i < d.size()) && (dphi2(d[i], d[i-1]) == 0)) {i++; cnt++; }
            tot -= (sqrt(1+8*cnt)-3)*cnt/6;
        }
    }

    cout << tot;
    return 0;
}


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

struct point{ int x; int y; };
struct points_pair{ point p1; point p2; };

struct resp_comp {
        resp_comp(points_pair resp) {
            this -> DX = resp.p2.y - resp.p1.y;
            this -> DY = - (resp.p2.x - resp.p1.x);
        }
        bool operator () (points_pair a, points_pair b){
            int dx = b.p2.x - a.p2.x;
            int dy = b.p2.y - a.p2.y;
            return dx * DX + dy * DY > 0;
        }
        int DX, DY;
    };

int dphi(points_pair a, points_pair b){
    return (a.p2.x - a.p1.x)*(b.p2.y - b.p1.y) - (a.p2.y - a.p1.y)*(b.p2.x - b.p1.x);
}

int dphi2(points_pair a, points_pair b){
    points_pair na, nb;
    na.p1 = a.p1; na.p2 = b.p2;
    nb.p1 = b.p1; nb.p2 = a.p2;
    return dphi(na, nb);
}

bool comp(points_pair a, points_pair b){
    if (dphi(a, b) > 0) return true;
    else return false;
};

int main(){
    long int n;
    vector<point> p;
    vector<points_pair> a;
    point t;
    points_pair t2;

//    freopen("in.txt", "r", stdin);
    cin >> n;
    long int tot = n*(n - 1)*(n - 2)/6;

    for (int i = 0; i < n; i++){
        cin >> t.x >> t.y;
        p.push_back(t);
    }

    for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++){
        t2.p1 = p[i];
        t2.p2 = p[j];
        a.push_back(t2);
    }

    sort(a.begin(), a.end(), comp);
    vector<points_pair>::iterator a_it = a.begin();
    int i;
    long int cnt;
    while (a_it < a.end()){
        points_pair tmp = *a_it;
        vector<points_pair> d;

        while ((a_it < a.end()) && (dphi(*a_it, tmp) == 0)) {
            d.push_back(*a_it); a_it++;
        };

        sort(d.begin(), d.end(), resp_comp(tmp));

        i = 1;
        while (i < d.size()){
            cnt = 1;
            while ((i < d.size()) && (dphi2(d[i], d[i-1]) == 0)) {i++; cnt++; }
            tot -= (sqrt(1+8*cnt)-3)*cnt/6;
            i++;
        }
    }

    cout << tot;
    return 0;
}


// O(n^2 log(n) solution)
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

struct point{
    int x; int y;
};

struct paired{
    point p1; point p2;
};

int vprod(paired a, paired b){
    int dxa = a.p2.x - a.p1.x;
    int dyb = b.p2.y - b.p1.y;
    int dya = a.p2.y - a.p1.y;
    int dxb = b.p2.x - b.p1.x;
    return dxa*dyb - dya*dxb;
}

bool same(paired a, paired b){
    paired nb;
    nb.p1 = a.p1; nb.p2 = b.p1;
    return (vprod(a, b) == 0) && (vprod(a, nb) == 0);
}

paired ordered(paired a){
    point c;
    int dx = a.p2.x - a.p1.x;
    int dy = a.p2.y - a.p1.y;
    if ((dy < 0) || ((dy == 0) && (dx < 0))){
        c = a.p1; a.p1 = a.p2; a.p2 = c;
    }
    return a;
}

bool rotation_order (paired a, paired b){
    return vprod(ordered(a), ordered(b)) > 0;
}

struct shift_order {
        int DX, DY;
        shift_order(paired resp) {
            this -> DX = resp.p2.y - resp.p1.y;
            this -> DY = - (resp.p2.x - resp.p1.x); };
        bool operator () (paired a, paired b){
            int dx = b.p2.x - a.p2.x;
            int dy = b.p2.y - a.p2.y;
            return dx * DX + dy * DY > 0;
        }
};

int main(){

    long long int n;
    vector<point> p;
    point t;

    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> t.x >> t.y;
        p.push_back(t);
    }

    long long int tot = (n*(n - 1)*(n - 2))/6;
    vector<paired> a;
    paired t2;
    for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++){
        t2.p1 = p[i];
        t2.p2 = p[j];
        a.push_back(t2);
    }
    sort(a.begin(), a.end(), rotation_order);

    vector<paired>::iterator a_it = a.begin();
    int i;
    long long int cnt, dcnt;
    while (a_it < a.end()){
        paired tmp = *a_it;
        vector<paired> d;
        while ((a_it < a.end()) && (vprod(*a_it, tmp) == 0)) {
            d.push_back(*a_it); a_it++;
        };
        sort(d.begin(), d.end(), shift_order(tmp));
        i = 0;
        while (i < d.size()){
            cnt = 1;
            while ((i < d.size() - 1) && same(d[i], d[i+1])) {
                cnt++;
                i++;
            }
            dcnt = ((sqrt(1+8*cnt)-3)*cnt)/6;
            tot -= dcnt;
            i++;
        }
    }
    cout << tot;
    return 0;

}


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

struct point{ int x; int y; };
struct points_pair{ point p1; point p2; };

struct resp_comp {
        resp_comp(points_pair resp) {
            this -> DX = resp.p2.y - resp.p1.y;
            this -> DY = - (resp.p2.x - resp.p1.x);
        }
        bool operator () (points_pair a, points_pair b){
            int dx = b.p2.x - a.p2.x;
            int dy = b.p2.y - a.p2.y;
            return dx * DX + dy * DY > 0;
        }
        int DX, DY;
    };

int dphi(points_pair a, points_pair b){
    return (a.p2.x - a.p1.x)*(b.p2.y - b.p1.y) - (a.p2.y - a.p1.y)*(b.p2.x - b.p1.x);
}

int dphi2(points_pair a, points_pair b){
    points_pair na, nb;
    na.p1 = a.p1; na.p2 = b.p2;
    nb.p1 = b.p1; nb.p2 = a.p2;
    return dphi(na, nb);
}

bool comp(points_pair a, points_pair b){
    if (dphi(a, b) > 0) return true;
    else return false;
};

int main(){
    int n;
    vector<point> p;
    vector<points_pair> a;
    point t;
    points_pair t2;

    cin >> n;
    int tot = n*(n - 1)*(n - 2)/6;

    for (int i = 0; i < n; i++){
        cin >> t.x >> t.y;
        p.push_back(t);
    }

    for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++){
        t2.p1 = p[i];
        t2.p2 = p[j];
        a.push_back(t2);
    }

    sort(a.begin(), a.end(), comp);
    vector<points_pair>::iterator a_it = a.begin();
    int i, cnt;
    while (a_it < a.end()){
        points_pair tmp = *a_it;
        vector<points_pair> d;

        while ((a_it < a.end()) && (dphi(*a_it, tmp) == 0)) {
            d.push_back(*a_it); a_it++;
        };

        sort(d.begin(), d.end(), resp_comp(tmp));

        i = 1; cnt = 1;
        while (i < d.size()){
            while ((i < d.size()) && (dphi2(d[i], d[i-1]) == 0)) {i++; cnt++; }
            i++; tot -= (sqrt(1+8*cnt)-3)*cnt/6;
        }
    }

    cout << tot;
    return 0;
}