#include <bits/stdc++.h>
#define x first
#define y second

using namespace std;

typedef long long INT;
typedef pair<int,int> pii;

const int NN=100010;
const int inf=0x3f3f3f3f;

int a[NN],b[NN];

main(){
#ifndef ONLINE_JUDGE
freopen("in.in","r",stdin);
#endif
	int t,n; cin>>t;
	while(t--){
		cin>>n;
		for(int i=0;i<n;i++)scanf("%d",a+i);
		for(int i=0;i<n;i++)scanf("%d",b+i);
		if(a[0]!=b[0]){
			puts("NO");
			continue;
		}
		int ne=n,po=n;
		for(int i=0;i<n;i++){
			if(a[i]==-1)ne=min(ne,i);
			if(a[i]==1)po=min(po,i);
		}
		int f=1;
		for(int i=n-1;i>=1;i--){
			if(b[i]-a[i]==0)continue;
			if(b[i]-a[i]>0 && po<i)continue;
			if(b[i]-a[i]<0 && ne<i)continue;
			f=0; puts("NO"); break;
		}
		if(f)puts("YES");
	}

	return 0;
}


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

int a[NN], b[NN];

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	int test;
	scanf("%d", &test);
	while(test--){
		int n;
		scanf("%d", &n);
		for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
		for(int i = 1; i <= n; i++) scanf("%d", &b[i]);

		int ct1= 0, ct2 = 0;
		int flag = 1;
		for(int i = 1; i <= n; i++){
			if(b[i] > a[i] && ct1 == 0) {
				flag  = 0;
				break;
			}
			if(b[i] < a[i] && ct2 == 0) {
				flag  = 0;
				break;
			}
			if(a[i] == 1) ct1 = 1;
			if(a[i] == -1) ct2 = 1;
		}
		if(flag) puts("YES");
		else puts("NO");
	}
	return 0;
}


#include<bits/stdc++.h>

#define NN 100100

using namespace std;

typedef long long INT;

int a[NN],b[NN];

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		for(int i=1;i<=n;i++)scanf("%d",&a[i]);
		for(int i=1;i<=n;i++)scanf("%d",&b[i]);
		int f1=0,f2=0;
		for(int i=1;i<=n;i++){
			if(a[i]==1){
				if(!f1){
					f1=i;
				}
			}
			if(a[i]==-1){
				if(!f2){
					f2=i;
				}
			}
		}
		int flag=0;
		for(int i=1;i<=n;i++){
			if(b[i]>a[i]){
				if(i<=f1){
					flag=1;
					break;
				}
			}
			if(b[i]<a[i]){
				if(i<=f2){
					flag=1;
					break;
				}
			}
		}
		if(flag)puts("NO");
		else puts("YES");
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define NN 100010
int n;
int a[NN], b[NN], pos[NN], neg[NN];
int t;

int solve() {
	scanf("%d", &n);
	for (int i=1; i<=n; i++) scanf("%d", &a[i]);
	for (int i=1; i<=n; i++) scanf("%d", &b[i]);
	for (int i=1; i<=n; i++) if (a[i]==1) {for (int j=i+1; j<=n; j++) pos[j]=1; break;}
	for (int i=1; i<=n; i++) if (a[i]==-1) {for (int j=i+1; j<=n; j++) neg[j]=1; break;}
	int flag=1;
	for (int i=1; i<=n; i++) {
		if (a[i]==b[i]) continue;
		int val=b[i]-a[i];
		if (val<0) {
			if (!neg[i]) {flag=0; break;}
		}
		if (val>0) {
			if (!pos[i]) {flag=0; break;}
		}
	}
	puts(flag ? "YES" : "NO");
	for (int i=1; i<=n; i++) pos[i]=neg[i]=0;
}
int main() {
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	for (scanf("%d", &t); t--;) solve();

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long INT;
int a[100010],b[100010];
int f[5];
int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int t;
	cin>>t;
	int n;
	while(t--){
		scanf("%d",&n);
		for(int i=1;i<=n;i++)scanf("%d",a+i);
		for(int i=1;i<=n;i++)scanf("%d",b+i);
		for(int i=1;i<=3;i++)f[i]=0;
		if(a[1]==-1)f[1]=1;
		if(a[1]==0)f[2]=1;
		if(a[1]==1)f[3]=1;
		if(a[1]!=b[1]) {cout<<"NO"<<endl;continue;}
		int ff=0;
		for(int i=2;i<=n;i++){
			 if(b[i]<a[i]){
			 	if(!f[1]){ff=1;}
			 }
			 else if(b[i]>a[i]){
			 	if(!f[3]){ff=1;}
			 }
//			 cout<<f[1]<<' '<<f[2]<<' '<<f[3]<<' '<<ff<<endl;
			 f[a[i]+2]=1;
			 if(ff==1)break;

		}
		if(ff)cout<<"NO"<<endl;
		else cout<<"YES"<<endl;
	}

	return 0;
}


#include<bits/stdc++.h>

#define NN 100100
#define inf 1e9
using namespace std;

typedef long long INT;

int a[NN],b[NN];

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		for(int i=1;i<=n;i++)scanf("%d",&a[i]);
		for(int i=1;i<=n;i++)scanf("%d",&b[i]);
		int f1=inf,f2=inf;
		for(int i=1;i<=n;i++){
			if(a[i]==1){
				if(f1==inf){
					f1=i;
				}
			}
			if(a[i]==-1){
				if(f2==inf){
					f2=i;
				}
			}
		}
		int flag=0;
		for(int i=1;i<=n;i++){
			if(b[i]>a[i]){
				if(i<=f1){
					flag=1;
					break;
				}
			}
			if(b[i]<a[i]){
				if(i<=f2){
					flag=1;
					break;
				}
			}
		}
		if(flag)puts("NO");
		else puts("YES");
	}

	return 0;
}


#include<bits/stdc++.h>

#define NN 100100

using namespace std;

typedef long long INT;

int a[NN],b[NN];

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		for(int i=1;i<=n;i++)scanf("%d",&a[i]);
		for(int i=1;i<=n;i++)scanf("%d",&b[i]);
		int f1=1e9,f2=1e9;
		for(int i=1;i<=n;i++){
			if(a[i]==1){
				if(!f1){
					f1=i;
				}
			}
			if(a[i]==-1){
				if(!f2){
					f2=i;
				}
			}
		}
		int flag=0;
		for(int i=1;i<=n;i++){
			if(b[i]>a[i]){
				if(i<=f1){
					flag=1;
					break;
				}
			}
			if(b[i]<a[i]){
				if(i<=f2){
					flag=1;
					break;
				}
			}
		}
		if(flag)puts("NO");
		else puts("YES");
	}

	return 0;
}


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

int main(){

int t = 0, n = 0, aux = 0;
cin >> t;

while(t--){
    cin >> n;

    vector<int>a(3,0);
    vector<int>pos(n,0);
    vector<int>b(n,0);
    bool posible = true;

    for(int i = 0; i < n; i++){
        cin >> aux;
        a[aux+1]++;
        pos[i] = aux;
    }
    for(int i = 0; i < n; i++){
        cin >> aux;
        b[i] = aux;
    }

    for(int i = n-1; i >= 0; i--){
        a[pos[i]+1]--;

        if(b[i] != pos[i]){
            if(b[i] < 0){  //si es negativo, se necesita: -1
                if(a[0] == 0){
                    posible = false;
                    break;
                }
            }
            else if(b[i] == 0){
                if(a[0] == 0 && a[2] == 0){
                    posible = false;
                    break;
                }
            }
            else if(b[i] > 0){  //si es positivo, se necesita:  1
                if(a[2] == 0){
                    posible = false;
                    break;
                }
            }
        }
}

    if(posible){
        cout << "YES\n";
    }
    else{
        cout << "NO\n";
    }

}

return 0;
}


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

int main(){

int t = 0, n = 0, aux = 0;
cin >> t;

while(t--){
    cin >> n;

    vector<int>a,b;
    vector<int>pos(2,0);
    bool posible = true;

    for(int i = 0; i < n; i++){
        cin >> aux;
        a.push_back(aux);
    }
    for(int i = 0; i < n; i++){
        cin >> aux;
        b.push_back(aux);
    }

    for(int i = 0; i < n; i++){  // 0: -1     1: 1
        if(b[i] != a[i]){
            if(b[i] < 0){  //si es negativo, se necesita: -1
                if(pos[0] == 0){
                    posible = false;
                    break;
                }
            }
            else if(b[i] == 0){
                if(pos[0] == 0 && pos[1] == 0){
                    posible = false;
                    break;
                }
            }
            else if(b[i] > 0){  //si es positivo, se necesita:  1
                if(pos[1] == 0){
                    posible = false;
                    break;
                }
            }
        }

        if(a[i] == -1){
            pos[0]++;
        }
        else if(a[i] == 1){
            pos[1]++;
        }
}

    if(posible){
        cout << "YES\n";
    }
    else{
        cout << "NO\n";
    }

}

return 0;
}


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

int main(){

int t = 0, n = 0, aux = 0;
cin >> t;

while(t--){
    cin >> n;

    vector<int>a(3,0);
    vector<int>pos(n,0);
    vector<int>b(n,0);
    bool posible = true;

    for(int i = 0; i < n; i++){
        cin >> aux;
        a[aux+1]++;
        pos[i] = aux;
    }
    for(int i = 0; i < n; i++){
        cin >> aux;
        b[i] = aux;
    }

    for(int i = n-1; i >= 0; i--){  // 0: -1     1: 0     2: 1
        a[pos[i]+1]--;

        if(b[i] != pos[i]){
            if(b[i] < 0){  //si es negativo, se necesita: -1
                if(a[0] == 0){
                    posible = false;
                    break;
                }
            }
            else if(b[i] == 0){
                a[pos[i]+1]++;
                if(a[0] == 0 && a[2] == 0){
                    posible = false;
                    break;
                }
                a[pos[i]+1]--;
            }
            else if(b[i] > 0){  //si es positivo, se necesita:  1
                if(a[2] == 0){
                    posible = false;
                    break;
                }
            }
        }
}

    if(posible){
        cout << "YES\n";
    }
    else{
        cout << "NO\n";
    }

}

return 0;
}


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

int main(){

int t = 0, n = 0, aux = 0;
cin >> t;

while(t--){
    cin >> n;

    vector<int>a,b;
    vector<int>pos(2,0);
    bool posible = true;

    for(int i = 0; i < n; i++){
        cin >> aux;
        a.push_back(aux);
    }
    for(int i = 0; i < n; i++){
        cin >> aux;
        b.push_back(aux);
    }

    for(int i = 0; i < n; i++){  // 0: -1     1: 1
        if(b[i]<a[i] && pos[0] == 0){
            posible = false;
            break;
        }
        if(b[i]>a[i] && pos[1] == 0){
            posible = false;
            break;
        }

        if(a[i] == -1){
            pos[0]++;
        }
        else if(a[i] == 1){
            pos[1]++;
        }

}

    if(posible){
        cout << "YES\n";
    }
    else{
        cout << "NO\n";
    }
}

return 0;
}


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

int main(){

int t = 0, n = 0, aux = 0;
cin >> t;

while(t--){
    cin >> n;

    vector<int>a,b;
    vector<int>pos(2,0);
    bool posible = true;

    for(int i = 0; i < n; i++){
        cin >> aux;
        a.push_back(aux);
    }
    for(int i = 0; i < n; i++){
        cin >> aux;
        b.push_back(aux);
    }

    for(int i = 0; i < n; i++){  // 0: -1     1: 1
        if(b[i] != a[i]){
            if(b[i] < 0){  //si es negativo, se necesita: -1
                if(pos[0] == 0){
                    posible = false;
                    break;
                }
            }
            else if(b[i] == 0){
                if((pos[0] < 1) || (pos[1] < 1)){
                    posible = false;
                    break;
                }
            }
            else if(b[i] > 0){  //si es positivo, se necesita:  1
                if(pos[1] == 0){
                    posible = false;
                    break;
                }
            }
        }

        if(a[i] == -1){
            pos[0]++;
        }
        else if(a[i] == 1){
            pos[1]++;
        }
}

    if(posible){
        cout << "YES\n";
    }
    else{
        cout << "NO\n";
    }

}

return 0;
}


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

int main(){

int t = 0, n = 0, aux = 0;
cin >> t;

while(t--){
    cin >> n;

    vector<int>a,b;
    vector<int>pos(2,0);
    bool posible = true;

    for(int i = 0; i < n; i++){
        cin >> aux;
        a.push_back(aux);
    }
    for(int i = 0; i < n; i++){
        cin >> aux;
        b.push_back(aux);
    }

    for(int i = 0; i < n; i++){  // 0: -1     1: 1
        if(b[i] != a[i]){
            if(b[i] < 0){  //si es negativo, se necesita: -1
                if(pos[0] == 0){
                    posible = false;
                    break;
                }
            }
            else if(b[i] > 0){  //si es positivo, se necesita:  1
                if(pos[1] == 0){
                    posible = false;
                    break;
                }
            }
        }

        if(a[i] == -1){
            pos[0]++;
        }
        else if(a[i] == 1){
            pos[1]++;
        }
}

    if(posible){
        cout << "YES\n";
    }
    else{
        cout << "NO\n";
    }

}

return 0;
}


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

int main(){

int t = 0, n = 0, aux = 0;
cin >> t;

while(t--){
    cin >> n;

    vector<int>a,b;
    vector<int>pos(2,0);
    bool posible = true;

    for(int i = 0; i < n; i++){
        cin >> aux;
        a.push_back(aux);
    }
    for(int i = 0; i < n; i++){
        cin >> aux;
        b.push_back(aux);
    }

    for(int i = 0; i < n; i++){  // 0: -1     1: 1
        if(b[i] != a[i]){
            if(b[i] < 0){  //si es negativo, se necesita: -1
                if(pos[0] == 0){
                    posible = false;
                    break;
                }
            }
            else if(b[i] == 0){
                if((a[i] == -1) && (pos[1] == 0)){
                    posible = false;
                    break;
                }
                if((a[i] == 1) && (pos[0] == 0)){
                    posible = false;
                    break;
                }
                a[i]--;
            }
            else if(b[i] > 0){  //si es positivo, se necesita:  1
                if(pos[1] == 0){
                    posible = false;
                    break;
                }
            }
        }

        if(a[i] == -1){
            pos[0]++;
        }
        else if(a[i] == 1){
            pos[1]++;
        }
}

    if(posible){
        cout << "YES\n";
    }
    else{
        cout << "NO\n";
    }

}

return 0;
}


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

int main(){

int t = 0, n = 0, aux = 0;
cin >> t;

while(t--){
    cin >> n;

    vector<int>a,b;
    vector<int>pos(2,0);
    bool posible = true;

    for(int i = 0; i < n; i++){
        cin >> aux;
        a.push_back(aux);
    }
    for(int i = 0; i < n; i++){
        cin >> aux;
        b.push_back(aux);
    }

    for(int i = 0; i < n; i++){  // 0: -1     1: 1
        if(b[i] != a[i]){
            if(b[i] < 0){  //si es negativo, se necesita: -1
                if(pos[0] == 0){
                    posible = false;
                    break;
                }
            }
            else if(b[i] > 0){  //si es positivo, se necesita:  1
                if(pos[1] == 0){
                    posible = false;
                    break;
                }
            }
            else if(b[i] == 0){
                if(pos[0] == 0 && pos[1] == 0){
                    posible = false;
                    break;
                }
            }
        }

        if(a[i] == -1){
            pos[0]++;
        }
        else if(a[i] == 1){
            pos[1]++;
        }
}

    if(posible){
        cout << "YES\n";
    }
    else{
        cout << "NO\n";
    }

}

return 0;
}


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

int main(){

int t = 0, n = 0, aux = 0;
cin >> t;

while(t--){
    cin >> n;

    vector<int>a,b;
    vector<int>pos(2,0);
    bool posible = true;

    for(int i = 0; i < n; i++){
        cin >> aux;
        a.push_back(aux);
    }
    for(int i = 0; i < n; i++){
        cin >> aux;
        b.push_back(aux);
    }

    for(int i = 0; i < n; i++){  // 0: -1     1: 1
        if(b[i] != a[i]){
            if(b[i] < a[i]){  //si es menor, se necesita: -1
                if(pos[0] == 0){
                    posible = false;
                    break;
                }
            }
            else if(b[i] > a[i]){  //si es mayor, se necesita:  1
                if(pos[1] == 0){
                    posible = false;
                    break;
                }
         }
        }

        if(a[i] == -1){
            pos[0]++;
        }
        else if(a[i] == 1){
            pos[1]++;
        }
}

    if(posible){
        cout << "YES\n";
    }
    else{
        cout << "NO\n";
    }

}

return 0;
}


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

int main(){

int t = 0, n = 0, aux = 0;
cin >> t;

while(t--){
    cin >> n;

    vector<int>a,b;
    vector<int>pos(2,0);
    bool posible = true;

    for(int i = 0; i < n; i++){
        cin >> aux;
        a.push_back(aux);
    }
    for(int i = 0; i < n; i++){
        cin >> aux;
        b.push_back(aux);
    }

    for(int i = 0; i < n; i++){  // 0: -1     1: 1
        if(b[i] != a[i]){
            if(b[i] < 0){  //si es negativo, se necesita: -1
                if(pos[0] == 0){
                    posible = false;
                    break;
                }
            }
            else if(b[i] > 0){  //si es positivo, se necesita:  1
                if(pos[1] == 0){
                    posible = false;
                    break;
                }
            }
            else if(b[i] == 0){
                if(pos[0] == 0 && pos[i] == 0){
                    posible = false;
                    break;
                }
            }
        }

        if(a[i] == -1){
            pos[0]++;
        }
        else if(a[i] == 1){
            pos[1]++;
        }
}

    if(posible){
        cout << "YES\n";
    }
    else{
        cout << "NO\n";
    }

}

return 0;
}


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

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

	while(t--)
	{
		int n;
		cin>>n;

		long long int arr[n], brr[n];
		for(int i = 0; i < n; i++) cin>>arr[i];
		for(int i = 0; i < n; i++) cin>>brr[i];

		int pos = -1, neg = -1;

		for(int i = 0; i < n; i++)
		{
			if(arr[i]==-1 && neg == -1) neg = i;
			if(arr[i]==1 && pos == -1) pos = i;
		}

		bool ans =true;

		if(brr[0]!=arr[0]) ans = false;

		for(int i = n-1; i > 0; i--)
		{
			if(brr[i]==arr[i]) continue;
			else if(arr[i]<brr[i])
			{
				if(pos>=i) ans = false;
			}

			else if(arr[i] > brr[i])
			{
				if(neg >= i) ans = false;
			}
		}

		if(ans) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
}


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

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

	while(t--)
	{
		int s;
		cin>>s;

		int arr[s];
		int brr[s];

		int p = -1, n = -1;

		for(int i = 0; i < s; i++)
		{
			cin>>arr[i];

			if(arr[i]>0 && p == -1) p = i;
			if(arr[i]<0 && n == -1) n = i;
		}

		bool ans = true;

		cin>>brr[0];

		if(arr[0]!=brr[0]) ans = false;

		for(int i = 1; i < s; i++)
		{
			cin>>brr[i];

			if(brr[i]>arr[i])
			{
				if(p>i) ans = false;
				else if( p == i)
				{
					if(arr[i]!=brr[i]) ans = false;
				}

			}
			if(brr[i]<arr[i])
			{
				if(n>i) ans = false;
				else if( n == i)
				{
					if(arr[i]!=brr[i]) ans = false;
				}
			}
		}

		//if(arr[0]!=brr[0]) ans = false;

		//cout<<p<<" "<<n<<endl;

		if(ans) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;

	}
}


#include <stdio.h>
#include <stdlib.h>

int compare(const void *a,const void *b)
{
   return *(int*)a-*(int*)b;
}
int main()
{
   int n,a[150],i,problem=0,time=0,penalty=0;

   scanf("%d",&n);
   for(i=0;i<n;i++)
   {
      scanf("%d",a+i);
   }
   qsort(a,n,sizeof(int),compare);

   /*for(i=0;i<n;i++)
   {
      printf("a[i]=%d\n",*(a+i));
   }*/
   i=0;
   while(1)
   {
      if(time+a[i] <= 710)
      {
         time+=a[i];
         problem++;
         i++;
         if(time > 350)
            penalty+=time-350;
      }
      else
         break;
   }
   printf("%d %d",problem,penalty);

   /*system("pause");*/
   return 0;
}
/****** PCCA -Mon Feb 27 09:56:15 GMT 2012 *******/


#include <stdio.h>
#include <stdlib.h>

int compare(const void *a,const void *b)
{
   return *(int*)a-*(int*)b;
}
int main()
{
   int n,a[150],i,problem=0,time=0,penalty=0;

   scanf("%d",&n);
   for(i=0;i<n;i++)
   {
      scanf("%d",a+i);
   }
   qsort(a,n,sizeof(int),compare);

   /*for(i=0;i<n;i++)
   {
      printf("a[i]=%d\n",*(a+i));
   }*/
   i=0;
   while(time < 710)
   {
      if(time+a[i] < 710)
      {
         time+=a[i];
         problem++;
         i++;
         if(time > 350)
            penalty+=time-350;
      }
      else
         break;
   }
   printf("%d %d",problem,penalty);

   /*system("pause");*/
   return 0;
}
/****** PCCA -Mon Feb 27 09:53:04 GMT 2012 *******/


#include <stdio.h>
#include <stdlib.h>

int compare(const void *a,const void *b)
{
   return *(int*)a-*(int*)b;
}
int main()
{
   int n,a[150],i,problem=0,time=0,penalty=0;

   scanf("%d",&n);
   for(i=0;i<n;i++)
   {
      scanf("%d",a+i);
   }
   qsort(a,n,sizeof(int),compare);

   /*for(i=0;i<n;i++)
   {
      printf("a[i]=%d\n",*(a+i));
   }*/
   i=0;
   while(time < 710)
   {
      if(time+a[i] < 710)
      {
         time+=a[i];
         problem++;
         i++;
         if(time > 350)
            penalty+=time-350;
      }
      else
         break;
   }
   printf("%d %d",problem,penalty);

   /*system("pause");*/
   return 0;
}
/****** PCCA -Mon Feb 27 09:53:50 GMT 2012 *******/


#include <stdio.h>

void sort(int *pointer, int size);

int main(){
    int n, done = 0, penalty = 0, total = 0, ban = 0, count=0;
    int i;

    scanf("%d", &n);
    int time[n];

    for(i=0; i<n; i++){
        scanf("%d", &time[i]);
    }

    sort(time, n);

    total = 350;
    for(i=0; i<n; i++){
        if(time[i] <= total){
            total-=time[i];
            done++;
            if(ban==1){
                count += time[i];
                penalty+=count;
            }
        }else{
            if((time[i] > total) && (ban == 0) && time[i]<=710){
                penalty = penalty + (time[i] - total);
                count = penalty;
                total = (360 - penalty);
                done++;
                ban = 1;
            }
        }
    }

    printf("%d %d", done, penalty);

    return 0;
}

void sort(int *pointer, int size){
  int i, j, aux;
  for(i = 0; i < size; i++){
     for(j = i + 1; j < size; j++){
         if(*(pointer+j) < *(pointer+i)){
             aux = *(pointer+j);
             *(pointer+j) = *(pointer+i);
             *(pointer+i) = aux;
         }
     }
  }
}


#include <stdio.h>

void sort(int *pointer, int size, int comienzo, int fin);

int main(){
    int n, counter=0, penalty=0, total = 0, ban = 0;
    int i;

    scanf("%d", &n);
    int time[n];

    for(i=0; i<n; i++){
        scanf("%d", &time[i]);
    }

    sort(time, n, 0, n);

    total = 350;
    for(i=0; i<n; i++){
        if(time[i] <= total){
            total-=time[i];
            counter++;
        }
        if((time[i] > total) && (ban == 0) && (time[i]-total < 360)){
            penalty += time[i] - total;
            total = 360 - penalty;
            counter++;
            ban = 1;
        }
    }

    printf("%d %d", counter, penalty);

    return 0;
}

void sort(int *pointer, int size, int comienzo, int fin){
  int i, j, temp;
  for(i = comienzo; i < fin; i++){
     for(j = i + 1; j < fin; j++){
         if(*(pointer+j) < *(pointer+i)){
             temp = *(pointer+j);
             *(pointer+j) = *(pointer+i);
             *(pointer+i) = temp;
         }
     }
  }
}


#include <stdio.h>

void sort(int *pointer, int size, int comienzo, int fin);

int main(){
    int n, counter=0, penalty=0, total = 0, ban = 0;
    int i;

    scanf("%d", &n);
    int time[n];

    for(i=0; i<n; i++){
        scanf("%d", &time[i]);
    }

    sort(time, n, 0, n);

    /*for(i=0; i<n; i++){
        printf("%d ", time[i]);
    }*/

    total = 350;
    for(i=0; i<n; i++){
        //printf("\n%d\n", i);
        if(time[i] <= total){
            total-=time[i];
            counter++;
        }else{
            if((time[i] > total) && (ban == 0) && (time[i]-total < 360)){
                //printf("\nTOTAL %d\nTIME %d\n", total, time[i]);
                penalty = penalty + (time[i] - total);
                total = 360 - penalty;
                counter++;
                ban = 1;
            }
        }
    }

    printf("%d %d", counter, penalty);

    return 0;
}

void sort(int *pointer, int size, int comienzo, int fin){
  int i, j, temp;
  for(i = comienzo; i < fin; i++){
     for(j = i + 1; j < fin; j++){
         if(*(pointer+j) < *(pointer+i)){
             temp = *(pointer+j);
             *(pointer+j) = *(pointer+i);
             *(pointer+i) = temp;
         }
     }
  }
}


#include <stdio.h>

void sort(int *pointer, int size, int comienzo, int fin);

int main(){
    int n, done = 0, penalty = 0, total = 0, ban = 0, count=0;
    int i;

    scanf("%d", &n);
    int time[n];

    for(i=0; i<n; i++){
        scanf("%d", &time[i]);
    }

    sort(time, n, 0, n);

    total = 350;
    for(i=0; i<n; i++){
        if(time[i] <= total){
            total-=time[i];
            done++;
            if(ban==1){
                count += time[i];
                penalty+=count;
            }
        }else{
            if((time[i] > total) && (ban == 0) && (time[i]-360 < 360) && time[i]<710){
                penalty = penalty + (time[i] - total);
                count = penalty;
                total = (360 - penalty);
                done++;
                ban = 1;
            }
        }
    }

    printf("%d %d", done, penalty);

    return 0;
}

void sort(int *pointer, int size, int comienzo, int fin){
  int i, j, temp;
  for(i = comienzo; i < fin; i++){
     for(j = i + 1; j < fin; j++){
         if(*(pointer+j) < *(pointer+i)){
             temp = *(pointer+j);
             *(pointer+j) = *(pointer+i);
             *(pointer+i) = temp;
         }
     }
  }
}


#include <stdio.h>

void sort(int *pointer, int size, int comienzo, int fin);

int main(){
    int n, done = 0, penalty = 0, total = 0, ban = 0, count=0;
    int i;

    scanf("%d", &n);
    int time[n];

    for(i=0; i<n; i++){
        scanf("%d", &time[i]);
    }

    sort(time, n, 0, n);

    total = 350;
    for(i=0; i<n; i++){
        if(time[i] <= total){
            total-=time[i];
            done++;
            if(ban==1){
                count += time[i];
                penalty+=count;
            }
        }else{
            if((time[i] > total) && (ban == 0) && (time[i]-360 < 360) && time[i]<=710){
                penalty = penalty + (time[i] - total);
                count = penalty;
                total = (360 - penalty);
                done++;
                ban = 1;
            }
        }
    }

    printf("%d %d", done, penalty);

    return 0;
}

void sort(int *pointer, int size, int comienzo, int fin){
  int i, j, temp;
  for(i = comienzo; i < fin; i++){
     for(j = i + 1; j < fin; j++){
         if(*(pointer+j) < *(pointer+i)){
             temp = *(pointer+j);
             *(pointer+j) = *(pointer+i);
             *(pointer+i) = temp;
         }
     }
  }
}


#include <stdio.h>

void sort(int *pointer, int size, int comienzo, int fin);

int main(){
    int n, done = 0, penalty = 0, total = 0, ban = 0, count=0;
    int i;

    scanf("%d", &n);
    int time[n];

    for(i=0; i<n; i++){
        scanf("%d", &time[i]);
    }

    sort(time, n, 0, n);

    total = 350;
    for(i=0; i<n; i++){
        if(time[i] <= total){
            total-=time[i];
            done++;
            if(ban==1){
                count += time[i];
                penalty+=count;
            }
        }else{
            if((time[i] > total) && (ban == 0) && (time[i]-360 < 360)){
                penalty = penalty + (time[i] - total);
                count = penalty;
                total = (360 - penalty);
                done++;
                ban = 1;
            }
        }
    }

    printf("%d %d", done, penalty);

    return 0;
}

void sort(int *pointer, int size, int comienzo, int fin){
  int i, j, temp;
  for(i = comienzo; i < fin; i++){
     for(j = i + 1; j < fin; j++){
         if(*(pointer+j) < *(pointer+i)){
             temp = *(pointer+j);
             *(pointer+j) = *(pointer+i);
             *(pointer+i) = temp;
         }
     }
  }
}


#include <stdio.h>

void sort(int *pointer, int size, int comienzo, int fin);

int main(){
    int n, done = 0, penalty = 0, total = 0, ban = 0, count=0;
    int i;

    scanf("%d", &n);
    int time[n];

    for(i=0; i<n; i++){
        scanf("%d", &time[i]);
    }

    sort(time, n, 0, n);

    total = 350;
    for(i=0; i<n; i++){
        if(time[i] <= total){
            total-=time[i];
            done++;
            if(ban==1){
                count += time[i];
                penalty+=count;
            }
        }else{
            if((time[i] > total) && (ban == 0) && time[i]<=710){
                penalty = penalty + (time[i] - total);
                count = penalty;
                total = (360 - penalty);
                done++;
                ban = 1;
            }
        }
    }

    printf("%d %d", done, penalty);

    return 0;
}

void sort(int *pointer, int size, int comienzo, int fin){
  int i, j, temp;
  for(i = comienzo; i < fin; i++){
     for(j = i + 1; j < fin; j++){
         if(*(pointer+j) < *(pointer+i)){
             temp = *(pointer+j);
             *(pointer+j) = *(pointer+i);
             *(pointer+i) = temp;
         }
     }
  }
}


#include <stdio.h>

void sort(int *pointer, int size);

int main(){
    int n, done = 0, penalty = 0, total = 0, ban = 0, count=0;
    int i;

    scanf("%d", &n);
    int time[n];

    for(i=0; i<n; i++){
        scanf("%d", &time[i]);
    }

    sort(time, n);

    total = 350;
    for(i=0; i<n; i++){
        if(time[i] <= total){
            total-=time[i];
            done++;
            if(ban==1){
                count += time[i];
                penalty+=count;
            }
        }else{
            if((time[i] > total) && (ban == 0) && time[i]<=710){
                penalty = penalty + (time[i] - total);
                count = penalty;
                total = (360 - penalty);
                done++;
                ban = 1;
            }
        }
    }

    printf("%d %d", done, penalty);

    return 0;
}

void sort(int *pointer, int size){
  int i, j, aux;
  for(i = 0; i < size; i++){
     for(j = i + 1; j < size; j++){
         if(*(pointer+j) < *(pointer+i)){
             temp = *(pointer+j);
             *(pointer+j) = *(pointer+i);
             *(pointer+i) = aux;
         }
     }
  }
}


#include <stdio.h>
#include <stdlib.h>
void intercambiar ( int*, int*);
void quicksort(int[], int, int);
int main()
{
    int n, i, cont=0, limit, band = 0, penality=0, hora;
    scanf("%d", &n);
    int a[n];
    for(i=0; i<n; i++)
    {
        scanf("%d", &a[i]);
    }
    quicksort(a, 0, n-1);
    hora = 6*60+10;
    for(i=0; i<n; i++)
    {
        hora+=a[i];
        if(hora <= 12*60)
            cont++;

        else
        {
            limit = hora - 12*60;
            if(limit <= 6*60)
            {
                cont++;
                penality+= limit;
            }
            else
            {
                i = n;
            }
        }
    }
    if(cont == 0)
        penality = 0;
    printf("%d %d",cont, penality);
    return 0;
}
void intercambiar ( int* a, int* b )
{
    int t = *a;
    *a = *b;
    *b = t;
}

void quicksort(int a[], int primero, int ultimo)
{
    int i, j, central, pivote;

    central = (primero + ultimo)/2;
    pivote = a[central];
    i = primero;
    j = ultimo;

    do{
        while (a[i] < pivote) i++;
        while (a[j] > pivote) j--;

        if(i<=j)
        {
            intercambiar(&a[i], &a[j]);
            i++;
            j--;
        }
    }while(i <= j);

    if(primero < j)
        quicksort(a, primero, j);
    if(i < ultimo)
        quicksort(a, i, ultimo);
}


#include <stdio.h>
#include <stdlib.h>
void intercambiar ( int*, int*);
void quicksort(int[], int, int);
int main()
{
    int n, i, cont=0, limit, hora;
    scanf("%d", &n);
    int a[n];
    for(i=0; i<n; i++)
    {
        scanf("%d", &a[i]);
    }
    quicksort(a, 0, n-1);
    hora = 6*60+10;
    for(i=0; i<n; i++)
    {
        hora+=a[i];
        if(hora < 12*60)
            cont++;
        else
        {
            if(hora > 12*60)
            {
                limit = hora - 12*60;
                if(limit < 6*60)
                    cont++;
                    hora -= 12*60;
                i = n;
            }
        }
    }
    if(cont == 0)
        hora = 0;
    printf("%d %d",cont, hora);
    return 0;
}
void intercambiar ( int* a, int* b )
{
    int t = *a;
    *a = *b;
    *b = t;
}

void quicksort(int a[], int primero, int ultimo)
{
    int i, j, central, pivote;

    central = (primero + ultimo)/2;
    pivote = a[central];
    i = primero;
    j = ultimo;

    do{
        while (a[i] < pivote) i++;
        while (a[j] > pivote) j--;

        if(i<=j)
        {
            intercambiar(&a[i], &a[j]);
            i++;
            j--;
        }
    }while(i <= j);

    if(primero < j)
        quicksort(a, primero, j);
    if(i < ultimo)
        quicksort(a, i, ultimo);
}


#include <stdio.h>
#include <stdlib.h>
void intercambiar ( int*, int*);
void quicksort(int[], int, int);
int main()
{
    int n, i, cont=0, limit, band = 0, penality, hora;
    scanf("%d", &n);
    int a[n];
    for(i=0; i<n; i++)
    {
        scanf("%d", &a[i]);
    }
    quicksort(a, 0, n-1);
    hora = 6*60+10;
    for(i=0; i<n; i++)
    {
        hora+=a[i];

        if(hora <= 12*60)
            cont++;

        else
        {
            limit = hora - 12*60;
            if(limit <= 6*60)
            {
                cont++;
                penality = limit;
            }
            else
            {
                i = n;
            }
        }
    }
    if(cont == 0)
        penality = 0;
    printf("%d %d",cont, penality);
    return 0;
}
void intercambiar ( int* a, int* b )
{
    int t = *a;
    *a = *b;
    *b = t;
}

void quicksort(int a[], int primero, int ultimo)
{
    int i, j, central, pivote;

    central = (primero + ultimo)/2;
    pivote = a[central];
    i = primero;
    j = ultimo;

    do{
        while (a[i] < pivote) i++;
        while (a[j] > pivote) j--;

        if(i<=j)
        {
            intercambiar(&a[i], &a[j]);
            i++;
            j--;
        }
    }while(i <= j);

    if(primero < j)
        quicksort(a, primero, j);
    if(i < ultimo)
        quicksort(a, i, ultimo);
}


#include <stdio.h>
#include <stdlib.h>
void intercambiar ( int*, int*);
void quicksort(int[], int, int);
int main()
{
    int n, i, cont=0, limit;
    scanf("%d", &n);
    int a[n];
    for(i=0; i<n; i++)
    {
        scanf("%d", &a[i]);
    }
    quicksort(a, 0, n-1);
    limit = 6*60+10;
    for(i=0; i<n; i++)
    {
        limit+=a[i];
        if(limit>12*60)
        {
            limit = limit - 12*60;
            i = n;
        }
        cont++;
    }
    printf("%d %d",cont, limit);
    return 0;
}
void intercambiar ( int* a, int* b )
{
    int t = *a;
    *a = *b;
    *b = t;
}

void quicksort(int a[], int primero, int ultimo)
{
    int i, j, central, pivote;

    central = (primero + ultimo)/2;
    pivote = a[central];
    i = primero;
    j = ultimo;

    do{
        while (a[i] < pivote) i++;
        while (a[j] > pivote) j--;

        if(i<=j)
        {
            intercambiar(&a[i], &a[j]);
            i++;
            j--;
        }
    }while(i <= j);

    if(primero < j)
        quicksort(a, primero, j);
    if(i < ultimo)
        quicksort(a, i, ultimo);
}


#include <stdio.h>
#include <stdlib.h>
void intercambiar ( int*, int*);
void quicksort(int[], int, int);
int main()
{
    int n, i, cont=0, limit, band = 0, penality, hora;
    scanf("%d", &n);
    int a[n];
    for(i=0; i<n; i++)
    {
        scanf("%d", &a[i]);
    }
    quicksort(a, 0, n-1);
    hora = 6*60+10;
    for(i=0; i<n; i++)
    {
        hora+=a[i];
        if(hora <= 12*60)
            cont++;

        else
        {
            limit = hora - 12*60;
            if(limit <= 6*60)
            {
                cont++;
                penality+= limit;
            }
            else
            {
                i = n;
            }
        }
    }
    if(cont == 0)
        penality = 0;
    printf("%d %d",cont, penality);
    return 0;
}
void intercambiar ( int* a, int* b )
{
    int t = *a;
    *a = *b;
    *b = t;
}

void quicksort(int a[], int primero, int ultimo)
{
    int i, j, central, pivote;

    central = (primero + ultimo)/2;
    pivote = a[central];
    i = primero;
    j = ultimo;

    do{
        while (a[i] < pivote) i++;
        while (a[j] > pivote) j--;

        if(i<=j)
        {
            intercambiar(&a[i], &a[j]);
            i++;
            j--;
        }
    }while(i <= j);

    if(primero < j)
        quicksort(a, primero, j);
    if(i < ultimo)
        quicksort(a, i, ultimo);
}


#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>

int n,a[100000],s,ans;
int cmp(int*a,int*b){return *a-*b;}

main(){
    int i,j;
    scanf("%d",&n);
    for(i=0;i<n;i++) scanf("%d",a+i);
    qsort(a,n,4,cmp);

    for(i=0;i<n&&s+a[i]<=710;i++)s+=a[i];
    n=i;s=0;
    for(i=0;i<n&&s+a[i]<=350;i++){
        s+=a[i];
        //printf("%d %d\n",s,ans);
    }

    for(;i<n;i++){
        s+=a[i];
        ans+=s-350;
        //printf("%d %d\n",s,ans);
    }

    printf("%d %d\n",n,ans);
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int cmpfunc (const void * a, const void * b)
{
   return ( *(int*)a - *(int*)b );
}

int main()
{
    int n;
    scanf("%d",&n);
    int time[n];
    int i,sum_time=0,penalty=0,resuelto=0;

    for(i=0; i<n; i++)
    {
        scanf("%d", &time[i]);
    }
    qsort(time,n,sizeof(int),cmpfunc);

//    for(i=0; i<n; i++)
//    {
//        printf("%d ",time[i]);
//    }

    for(i=0; i<n; i++)
    {
        sum_time += time[i];
        if(sum_time > 350 && sum_time <= 710)
        {
            penalty += sum_time - 350;
        }
        if(sum_time <= 710)
        {
            resuelto++;
        }
    }
    printf("%d %d",resuelto,penalty);
    return 0;

}


#include <stdio.h>
#include <stdlib.h>

int cmpfunc (const void * a, const void * b)
{
   return ( *(int*)a - *(int*)b );
}

int main()
{
    int n;
    scanf("%d",&n);
    int time[n];
    int i,sum_time=0,penalty=0,resuelto=0;

    for(i=0; i<n; i++)
    {
        scanf("%d", &time[i]);
    }
    qsort(time,n,sizeof(int),cmpfunc);

    for(i=0; i<n; i++)
    {
        printf("%d ",time[i]);
    }

    for(i=0; i<n; i++)
    {
        sum_time += time[i];
        if(sum_time > 350 && sum_time <= 710)
        {
            penalty += sum_time - 350;
        }
        if(sum_time <= 710)
        {
            resuelto++;
        }
    }
//
//	for (i = 0;i < n;i++) {
//	    time += a[i];
//		if (time > 350 && time <= 710) sum += time-350;
//        if (time <= 710) res++;
//	}
//	printf("%d %d\n",res,sum);

    printf("%d %d",resuelto,penalty);
    return 0;

}


#include<stdio.h>
#include<stdlib.h>

int cmp(const void *a,const void *b) {
	return *(int *)a-*(int *)b;
}

int main() {
	int a[128];
	int n,i,r,t,rt;
	scanf("%d",&n);
	for(i=0;i<n;i++) scanf("%d",&a[i]);
	qsort(a,n,sizeof(a[0]),cmp);
	for(i=r=rt=0,t=10;i<n && t+a[i]<=720;i++) {
		t+=a[i];
		r++;
		if (t>360) rt+=t-360;
	}
	printf("%d %d\n",r,rt);
	return 0;
}


#include <stdio.h>

int dividir(int *array, int inicio, int fin);
void quicksort(int *array, int inicio, int fin);
int main()
{

    int N,Ni;
    int A[200];

    scanf("%d",&N);

    for( Ni = 0; Ni < N; Ni++)
        scanf("%d", &A[Ni]);

    quicksort(A,0,N-1);

    int clk = 10;
    int cnt = 0;
    int pen = 0;

    for( Ni = 0; Ni < N; Ni++)
    {

        if( clk+A[Ni] <= 720 )
        {
            clk += A[Ni];

            if( clk > 360 )
                pen += (clk-360);

                cnt++;
        }
    }

    printf("\n%d %d\n", cnt, pen);
    return 0;
}

	int dividir(int *array, int inicio, int fin)
    {
        int izq;
        int der;
        int pibote;
        int temp;

        pibote = array[inicio];
        izq = inicio;
        der = fin;

            while (izq < der){
                while (array[der] > pibote){
                der--;
            }

                while ((izq < der) && (array[izq] <= pibote)){
                    izq++;
                }

                    if(izq < der){
                        temp= array[izq];
                        array[izq] = array[der];
                        array[der] = temp;
                    }
            }

                    temp = array[der];
                    array[der] = array[inicio];
                    array[inicio] = temp;

            return der;
    }

void quicksort(int *array, int inicio, int fin)
{
        int pivote;
        if(inicio < fin)
        {
            pivote = dividir(array, inicio, fin );
            quicksort( array, inicio, pivote - 1 );
            quicksort( array, pivote + 1, fin );
        }
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void ordenar(int v[], int n);
void swap(int *a, int *b);

main()
{

    int n, i, nyear=350, maxtime=360, penalty=0;

    scanf("%d", &n);

    int problems[n];

    for(i=0; i<n; i++)
        scanf("%d", &problems[i]);

    ordenar(problems, n);

    i=0;
    while(nyear-problems[i]>0 && i<n)
    {
        nyear-=problems[i];
        i++;
    }

    maxtime += nyear;

    while(maxtime-problems[i]>0 && i<n)
    {
        maxtime-=problems[i];
        penalty += 360-maxtime;
        i++;
    }

    printf("%d %d", i, penalty);
/*  printf("\n");
    system("pause");*/

    return 0;
}

void ordenar(int v[], int n)
{
    int i, j;

    for(i=0; i<n-2; i++)
    {
        for(j=0; j<n-i-1; j++)
        {
            if(v[j]>v[j+1])
            {
                swap(&v[j], &v[j+1]);
            }

        }
    }
}

void swap(int *a, int *b)
{
    int aux;
    aux = *a;
    *a=*b;
    *b=aux;

}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void ordenar(int v[], int n);
void swap(int *a, int *b);

main()
{

    int n, i, nyear=350, maxtime=360, penalty=0;

    scanf("%d", &n);

    int problems[n];

    for(i=0; i<n; i++)
        scanf("%d", &problems[i]);

    ordenar(problems, n);

    i=0;
    while(nyear-problems[i]>0 && i<n)
    {
        nyear-=problems[i];
        i++;
    }

    maxtime += nyear;

    while(maxtime-problems[i]>=0 && i<n)
    {
        maxtime-=problems[i];
        penalty += 360-maxtime;
        i++;
    }

    printf("%d %d", i, penalty);
/*  printf("\n");
    system("pause");*/

    return 0;
}

void ordenar(int v[], int n)
{
    int i, j;

    for(i=0; i<n-2; i++)
    {
        for(j=0; j<n-i-1; j++)
        {
            if(v[j]>v[j+1])
            {
                swap(&v[j], &v[j+1]);
            }

        }
    }
}

void swap(int *a, int *b)
{
    int aux;
    aux = *a;
    *a=*b;
    *b=aux;

}


#include <stdio.h>
int cmpfunc (const void * a, const void * b)
{
   return ( *(int*)a - *(int*)b );
}
int main()
{
             int a,b,c,d,e,f,i,j,sum=0,sum1=0,ct=0,count=0;
             int x[110];
             scanf("%d",&a);
             for(i=0;i<a;i++)
                          scanf("%d",&x[i]);
             qsort(x,a,sizeof(int),cmpfunc);

             for(i=0;i<a;i++)
             { ct=ct+x[i];
               if(ct<=350)
                 sum++;
               else
               {
                            ct=ct-x[i];
                            d=i;
                            break;
               }

             }
             sum1=(ct+x[i]-350);
             if(sum1>360)
             {
                          printf("%d 0",sum);
                          return 0;
             }
             sum++;
             count=count+sum1;
             for(j=d+1;j<a;j++)
             {
                          sum1=sum1+x[j];

                          if(sum1<=360)
                                       {sum++;
                                        count=count+sum1;}
                          else
                          {
                                       break;
                          }
             }
             printf("%d %d",sum,count);
             return 0;

}


#include <stdio.h>
int cmpfunc (const void * a, const void * b)
{
   return ( *(int*)a - *(int*)b );
}
int main()
{
             int a,b,c,d,e,f,i,j,sum=0,sum1=0,ct=0;
             int x[110];
             scanf("%d",&a);
             for(i=0;i<a;i++)
                          scanf("%d",&x[i]);
             qsort(x,a,sizeof(int),cmpfunc);

             for(i=0;i<a;i++)
             { ct=ct+x[i];
               if(ct<=350)
                 sum++;
               else
               {
                            ct=ct-x[i];
                            d=i;
                            break;
               }

             }
             sum1=(ct+x[i]-350);
             if(sum1>360)
             {
                          printf("%d 0",sum);
                          return 0;
             }
             sum++;
             for(j=d+1;j<a;j++)
             {
                          sum1=sum1+x[j];
                          if(sum1<=360)
                                       sum++;
                          else
                          {
                                       printf("%d %d",sum,sum1-x[j]);
                                       return 0;
                          }
             }

}


#include <stdio.h>
int cmpfunc (const void * a, const void * b)
{
   return ( *(int*)a - *(int*)b );
}
int main()
{
             int a,b,c,d,e,f,i,j,sum=0,sum1=0,ct=0,count=0;
             int x[110];
             scanf("%d",&a);
             for(i=0;i<a;i++)
                          scanf("%d",&x[i]);
             qsort(x,a,sizeof(int),cmpfunc);

             for(i=0;i<a;i++)
             { ct=ct+x[i];
               if(ct<=350)
                 sum++;
               else
               {
                            ct=ct-x[i];
                            d=i;
                            break;
               }

             }
             sum1=(ct+x[i]-350);
             if(sum1>360)
             {
                          printf("%d 0",sum);
                          return 0;
             }
             sum++;
             count=count+sum1;
             for(j=d+1;j<a;j++)
             {
                          sum1=sum1+x[j];

                          if(sum1<=360)
                                       {sum++;
                                        count=count+sum1;}
                          else
                          {
                                       printf("%d %d",sum,count);
                                       return 0;
                          }
             }

}


#include <stdio.h>
int cmpfunc (const void * a, const void * b)
{
   return ( *(int*)a - *(int*)b );
}
int main()
{
             int a,b,c,d,e,f,i,j,sum=0,sum1=0,ct=0;
             int x[110];
             scanf("%d",&a);
             for(i=0;i<a;i++)
                          scanf("%d",&x[i]);
             qsort(x,a,sizeof(int),cmpfunc);

             for(i=0;i<a;i++)
             { ct=ct+x[i];
               if(ct<=350)
                 sum++;
               else
               {
                            ct=ct-x[i];
                            d=i;
                            break;
               }

             }
             sum1=(ct+x[i]-350);
             if(sum1>360)
             {
                          printf("%d %d",sum,sum1);
                          return 0;
             }
             sum++;
             for(j=d+1;j<a;j++)
             {
                          sum1=sum1+x[j];
                          if(sum1<=360)
                                       sum++;
                          else
                          {
                                       printf("%d %d",sum,sum1-x[j]);
                                       return 0;
                          }
             }

}


#include <stdio.h>
#include <stdlib.h>
int a[101], n;
void quicksort(int a[], int primero, int ultimo);
int main()
{
    scanf("%d", &n);
    int i;
    for (i= 0; i < n; i++)
    {
        scanf("%d", a+i);
    }
    quicksort(a,0,n-1);
    int tiempo = 0, resueltos = 0, passed = 10;
    for (i = 0; i < n; i++)
    {
        passed += a[i];
        if (passed > 720)
        {
            break;
        }
        resueltos++;
        if (passed > 360)
        {
            tiempo += passed - 360;
        }
    }

    printf("%d %d\n", resueltos, tiempo);
    return 0;
}

void quicksort(int a[], int primero, int ultimo)
{

        int i, j, central,pivote;

        central = (primero + ultimo)/2;
        pivote = a[central];
        i = primero;
        j = ultimo;

        do {
            while (a[i] < pivote) i++;
            while (a[j] > pivote) j--;

            if (i <= j)
            {
                double tmp;
                tmp = a[i];
                a[i] = a[j];
                a[j] = tmp;
                i++;
                j--;
            }
        }while (i <= j);

        if (primero < j)
            quicksort(a, primero, j);

        if (i < ultimo)
            quicksort(a, i, ultimo);
    }


#include <stdio.h>

void sort(int *pointer, int size);

int main(){
    int n, done = 0, penalty = 0, total = 0, ban = 0, count=0;
    int i;

    scanf("%d", &n);
    int time[n];

    for(i=0; i<n; i++){
        scanf("%d", &time[i]);
    }

    sort(time, n);

    total = 350;
    for(i=0; i<n; i++){
        if(time[i] <= total){
            total-=time[i];
            done++;
            if(ban==1){
                count += time[i];
                penalty+=count;
            }
        }else{
            if((time[i] > total) && (ban == 0) && time[i]<=710){
                penalty = penalty + (time[i] - total);
                count = penalty;
                total = (360 - penalty);
                done++;
                ban = 1;
            }
        }
    }

    printf("%d %d", done, penalty);

    return 0;
}

void sort(int *pointer, int size){
  int i, j, aux;
  for(i = 0; i < size; i++){
     for(j = i + 1; j < size; j++){
         if(*(pointer+j) < *(pointer+i)){
             aux = *(pointer+j);
             *(pointer+j) = *(pointer+i);
             *(pointer+i) = aux;
         }
     }
  }
}


import java.util.*;

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

		int n = in.nextInt();
		int[] a = new int[n];

		for (int i = 0; i < n; i++) {
			a[i] = in.nextInt();
		}

		Arrays.sort(a);
		int count = 0;
		int penalty = 0;
		int time = 10;
		for (int i = 0; i < n; i++) {
			if (time + a[i] <= 360) {
				count++;
			} else if (time + a[i] <= 720) {
				count++;
				penalty += time + a[i] - 360;
			} else {
				break;
			}
			time += a[i];
		}

		System.out.println(count + " " + penalty);

		in.close();
		System.exit(0);
	}
}


import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.math.BigInteger;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author AlexFetisov
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskD solver = new TaskD();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskD {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int n = in.nextInt();
        int[] a = Utils.readIntArray(in, n);
        Arrays.sort(a);
        int curTime = -350;
        int problemSolved = 0;
        int penalty = 0;
        for (int i = 0; i < n; ++i) {
            int newTime = curTime + a[i];
            if (newTime > 360) {
                break;
            }
            ++problemSolved;
            if (newTime > 0) {
                penalty += newTime;
            }
            curTime = newTime;
        }
        out.println(problemSolved + " " + penalty);
    }
}

class InputReader {
    private BufferedReader reader;
    private StringTokenizer stt;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
    }

    public String nextLine() {
        try {
            return reader.readLine();
        } catch (IOException e) {
            return null;
        }
    }

    public String nextString() {
        while (stt == null || !stt.hasMoreTokens()) {
            stt = new StringTokenizer(nextLine());
        }
        return stt.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(nextString());
    }

}

class Utils {
    public static int[] readIntArray(InputReader in, int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; ++i) {
            a[i] = in.nextInt();
        }
        return a;
    }

}


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class CF_140D {

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int n = sc.nextInt();
		int arr[] = new int[n];
		for(int i = 0; i < n; ++i) arr[i] = sc.nextInt();

		Arrays.sort(arr);

		int soFar = 0, i = 0;
		int problems = 0, penalty = 0;

		while(i < n && soFar + arr[i] <= 350) {
			soFar += arr[i++];
		}

		problems = i;

		while(i < n && soFar + arr[i] <= 710) {
			soFar += arr[i++];
			penalty += (soFar - 350);
			problems++;
		}

		out.println(problems + " " + penalty);

		out.flush();
		out.close();
	}

	static class Scanner{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

		public Scanner(FileReader r){	br = new BufferedReader(r);}

		public String next() throws IOException
		{
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

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

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

		public String nextLine() throws IOException {return br.readLine();}

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

		public boolean ready() throws IOException {return br.ready();}
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {
	static BufferedReader reader;
	static StringTokenizer tokenizer;
	static PrintWriter writer;

	static int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	static long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	static double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	static boolean eof = false;

	static String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}

	public static void main(String[] args) throws IOException {
		tokenizer = null;
		// reader = new BufferedReader(new FileReader("ideal.in"));
		// writer = new PrintWriter(new FileWriter("ideal.out"));
		reader = new BufferedReader(new InputStreamReader(System.in, "ISO-8859-1"));
		writer = new PrintWriter(System.out);
		banana();
		reader.close();
		writer.close();
	}

	static boolean isDebug = true;

	static void banana() throws IOException {
		int n = nextInt();
		int a[] = new int[n];

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

		Arrays.sort(a);

		int count = 0;
		int cursum = 0;
		int score = 0;
		for (int i = 0; i < n; ++i)
			if (cursum + a[i] <= 710) {
				++count;
				cursum += a[i];
				score += (cursum <= 350 ? 0 : cursum - 350);
			}
		System.out.println(count + " " + score);
	}
}


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

public class Main {
    FastScanner in;
    PrintWriter out;

    static final String FILE = "";

    public void solve() {
        int n = in.nextInt();
        int mass[] = new int[n];
        for(int i = 0; i < n; i++)
            mass[i] = in.nextInt();
        Arrays.sort(mass);
        int sum = 0;
        int ans = 0;
        for(int i = 0; i < n; i++) {
            sum += mass[i];
            if(sum + 10 > 12 * 60) {
                n = i;
                break;
            }
            if(sum + 10 <= 6 * 60) {
                ans += 0;
            } else {
                ans += sum + 10 - 6 * 60;
            }
        }

        out.print(n + " " + ans);
    }

    public void run() {
        try {
            if(FILE.isEmpty()) {
                in = new FastScanner(new InputStreamReader(System.in));
                out = new PrintWriter(new OutputStreamWriter(System.out));
            } else {
                in = new FastScanner(new File(FILE + ".in"));
                out = new PrintWriter(new File(FILE + ".out"));
            }

            solve();

            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        FastScanner(InputStreamReader rd) {
            br = new BufferedReader(rd);
        }

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

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

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

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

    class Pair<U extends Comparable<U>, V extends Comparable<V>> implements Comparable<Pair<U, V>> {
        U u;
        V v;

        public Pair(U u, V v) {
            this.u = u;
            this.v = v;
        }

        public int hashCode() {
            return (u == null ? 0 : u.hashCode() * 31) + (v == null ? 0 : v.hashCode());
        }

        public boolean equals(Object o) {
            if (this == o)
                return true;
            if (o == null || getClass() != o.getClass())
                return false;
            Pair<U, V> p = (Pair<U, V>) o;
            return (u == null ? p.u == null : u.equals(p.u)) && (v == null ? p.v == null : v.equals(p.v));
        }

        public int compareTo(Pair<U, V> b) {
            int cmpU = u.compareTo(b.u);
            return cmpU != 0 ? cmpU : v.compareTo(b.v);
        }
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


// ~/BAU/ACM-ICPC/Teams/A++/BlackBurn95

import java.io.*;
import java.util.*;
import java.math.*;
import static java.lang.Math.*;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.Double.parseDouble;
import static java.lang.String.*;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
                                              // (new FileReader("input.in"));
        StringBuilder out = new StringBuilder();
        StringTokenizer tk;

        int n = parseInt(in.readLine());
        List<Integer> l = new ArrayList<>();
        tk = new StringTokenizer(in.readLine());
        for(int i=0; i<n; i++)
            l.add(parseInt(tk.nextToken()));
        Collections.sort(l);

        int time = 10,cnt = 0,pen = 0;

        for(int i=0; i<n; i++) {
            time += l.get(i);
            if(time > 720) break;
            cnt++;
            if(time <= 360) continue;
            pen += time-360;
        }

        System.out.println(cnt+" "+pen);
    }

}


import java.util.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class TestClass {
    public static void main(String args[] ) throws Exception {
        /*
         * Read input from stdin and provide input before running

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        int N = Integer.parseInt(line);
        for (int i = 0; i < N; i++) {
            System.out.println("hello world");
        }
        */
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int a[];
        a = new int[n];
        for(int i=0;i<n;i++)a[i]=sc.nextInt();
        Arrays.sort(a);
        int t=-350,s=0,p=0;
        for(int i=0;i<n;i++){
            if(t+a[i]<=0)s++;
            else if(t+a[i]<=360){
                s++;
                p+=t+a[i];
            }
            else break;
            t+=a[i];
            //System.out.println(a[i]+" "+t);
        }
        System.out.println(s+" "+p);
    }
}


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

public class Main implements Runnable {
    FastScanner sc;
    PrintWriter pw;

    final class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            try {
                br = new BufferedReader(new InputStreamReader(System.in));
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        public long nlo() {
            return Long.parseLong(next());
        }

        public String next() {
            if (st.hasMoreTokens())
                return st.nextToken();
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                e.printStackTrace();
            }
            return st.nextToken();
        }

        public int ni() {
            return Integer.parseInt(next());
        }

        public String nli() {
            String line = "";
            if (st.hasMoreTokens())
                line = st.nextToken();
            else
                try {
                    return br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            while (st.hasMoreTokens())
                line += " " + st.nextToken();
            return line;
        }

        public double nd() {
            return Double.parseDouble(next());
        }
    }

    public static void main(String[] args) throws Exception {
        new Thread(null, new Main(), "codeforces", 1 << 28).start();
    }

    public void run() {
        sc = new FastScanner();
        pw = new PrintWriter(System.out);
        solve();
        pw.flush();
        pw.close();
    }

    public long gcd(long a, long b) {
        return b == 0L ? a : gcd(b, a % b);
    }

    public long ppow(long a, long b, long mod) {
        if (b == 0L)
            return 1L;
        long tmp = 1;
        while (b > 1L) {
            if ((b & 1L) == 1)
                tmp *= a;
            a *= a;
            a %= mod;
            tmp %= mod;
            b >>= 1;
        }
        return (tmp * a) % mod;
    }

    public int gcd(int x, int y) {
        return y == 0 ? x : gcd(y, x % y);
    }

    //////////////////////////////////
    ///////////// LOGIC ///////////
    ////////////////////////////////

    public void solve() {
        int n=sc.ni();
        int[] arr=new int[n];
        for(int i=0;i<n;i++)
        arr[i]=sc.ni();
        Arrays.sort(arr);
        int total=10;
        int  ans=0,jobs=0;
        for(int i=0;i<n;i++)
        {
            if(total+arr[i]<=720)
            {total+=arr[i];jobs++;}
            else
            break;
            if(total>360)
            ans+=(total-360);
        }
        pw.println(jobs+" "+ans);
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author OmarYasser
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        static int n;
        static int[] arr;
        static TaskD.Pair[][] memo;

        static TaskD.Pair dp(int idx, int time) {
            if (idx == n) return new TaskD.Pair(0, 0);
            if (memo[idx][time] != null)
                return memo[idx][time];

            TaskD.Pair leave = dp(idx + 1, time);
            TaskD.Pair take = new TaskD.Pair(-22134, 12341244);
            if (arr[idx] + time <= 720) {
                TaskD.Pair other = dp(idx + 1, time + arr[idx]);
                int addPenalty = 0;
                if (time + arr[idx] > 360) addPenalty = time + arr[idx] - 360;
                take = new TaskD.Pair(other.problems + 1, other.penalty + addPenalty);
            }

            return memo[idx][time] = leave.problems > take.problems ? leave : take.problems > leave.problems ? take : leave.penalty < take.penalty ? leave : take;
        }

        public void solve(int testNumber, Scanner sc, PrintWriter out) {
            n = sc.nextInt();
            arr = new int[n];
            for (int i = 0; i < n; i++)
                arr[i] = sc.nextInt();
            Arrays.sort(arr);

            memo = new TaskD.Pair[n][721];
            out.println(dp(0, 10).problems + " " + dp(0, 10).penalty);
        }

        static class Pair {
            int problems;
            int penalty;

            Pair(int problems, int penalty) {
                this.problems = problems;
                this.penalty = penalty;
            }

        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(FileReader f) {
            br = new BufferedReader(f);
        }

        public String next() {
            while (st == null || !st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                }
            return st.nextToken();
        }

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

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author OmarYasser
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        static int n;
        static int arr;
        static TaskD.Pair memo;

        static TaskD.Pair dp(int idx, int time) {
            if (idx == n) return new TaskD.Pair(0, 0);
            if (memo[idx][time] != null)
                return memo[idx][time];

            TaskD.Pair leave = dp(idx + 1, time);
            TaskD.Pair take = new TaskD.Pair(-22134, 12341244);
            if (arr[idx] + time <= 720) {
                TaskD.Pair other = dp(idx + 1, time + arr[idx]);
                int addPenalty = 0;
                if (time + arr[idx] > 360) addPenalty = time + arr[idx] - 360;
                leave = new TaskD.Pair(other.problems + 1, other.penalty + addPenalty);
            }

            return memo[idx][time] = leave.problems > take.problems ? leave : take.problems > leave.problems ? take : leave.penalty < take.penalty ? leave : take;
        }

        public void solve(int testNumber, Scanner sc, PrintWriter out) {
            n = sc.nextInt();
            arr = new int[n];
            for (int i = 0; i < n; i++)
                arr[i] = sc.nextInt();
            for (int i = 0; i < n / 2; i++) {
                arr[i] ^= arr[n - i - 1];
                arr[n - i - 1] ^= arr[i];
                arr[i] ^= arr[n - i - 1];
            }

            memo = new TaskD.Pair[n][721];
            out.println(dp(0, 10).problems + " " + dp(0, 10).penalty);
        }

        static class Pair {
            int problems;
            int penalty;

            Pair(int problems, int penalty) {
                this.problems = problems;
                this.penalty = penalty;
            }

        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(FileReader f) {
            br = new BufferedReader(f);
        }

        public String next() {
            while (st == null || !st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                }
            return st.nextToken();
        }

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

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author OmarYasser
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        static int n;
        static int[] arr;
        static TaskD.Pair[][] memo;

        static TaskD.Pair dp(int idx, int time) {
            if (idx == n) return new TaskD.Pair(0, 0);
            if (memo[idx][time] != null)
                return memo[idx][time];

            TaskD.Pair leave = dp(idx + 1, time);
            TaskD.Pair take = new TaskD.Pair(-22134, 12341244);
            if (arr[idx] + time <= 720) {
                TaskD.Pair other = dp(idx + 1, time + arr[idx]);
                int addPenalty = 0;
                if (time + arr[idx] > 360) addPenalty = time + arr[idx] - 360;
                leave = new TaskD.Pair(other.problems + 1, other.penalty + addPenalty);
            }

            return memo[idx][time] = leave.problems > take.problems ? leave : take.problems > leave.problems ? take : leave.penalty < take.penalty ? leave : take;
        }

        public void solve(int testNumber, Scanner sc, PrintWriter out) {
            n = sc.nextInt();
            arr = new int[n];
            for (int i = 0; i < n; i++)
                arr[i] = sc.nextInt();
            for (int i = 0; i < n / 2; i++) {
                arr[i] ^= arr[n - i - 1];
                arr[n - i - 1] ^= arr[i];
                arr[i] ^= arr[n - i - 1];
            }

            memo = new TaskD.Pair[n][721];
            out.println(dp(0, 10).problems + " " + dp(0, 10).penalty);
        }

        static class Pair {
            int problems;
            int penalty;

            Pair(int problems, int penalty) {
                this.problems = problems;
                this.penalty = penalty;
            }

        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(FileReader f) {
            br = new BufferedReader(f);
        }

        public String next() {
            while (st == null || !st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                }
            return st.nextToken();
        }

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

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author OmarYasser
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        static int n;
        static int[] arr;
        static TaskD.Pair[][] memo;

        static TaskD.Pair dp(int idx, int time) {
            if (idx == n) return new TaskD.Pair(0, 0);
            if (memo[idx][time] != null)
                return memo[idx][time];

            TaskD.Pair leave = dp(idx + 1, time);
            TaskD.Pair take = new TaskD.Pair(-22134, 12341244);
            if (arr[idx] + time <= 720) {
                TaskD.Pair other = dp(idx + 1, time + arr[idx]);
                int addPenalty = 0;
                if (time + arr[idx] > 360) addPenalty = time + arr[idx] - 360;
                leave = new TaskD.Pair(other.problems + 1, other.penalty + addPenalty);
            }

            return memo[idx][time] = leave.problems > take.problems ? leave : take.problems > leave.problems ? take : leave.penalty < take.penalty ? leave : take;
        }

        public void solve(int testNumber, Scanner sc, PrintWriter out) {
            n = sc.nextInt();
            arr = new int[n];
            for (int i = 0; i < n; i++)
                arr[i] = sc.nextInt();
            Arrays.sort(arr);
            for (int i = 0; i < n / 2; i++) {
                arr[i] ^= arr[n - i - 1];
                arr[n - i - 1] ^= arr[i];
                arr[i] ^= arr[n - i - 1];
            }

            memo = new TaskD.Pair[n][721];
            out.println(dp(0, 10).problems + " " + dp(0, 10).penalty);
        }

        static class Pair {
            int problems;
            int penalty;

            Pair(int problems, int penalty) {
                this.problems = problems;
                this.penalty = penalty;
            }

        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(FileReader f) {
            br = new BufferedReader(f);
        }

        public String next() {
            while (st == null || !st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                }
            return st.nextToken();
        }

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

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        d140 solver = new d140();
        solver.solve(1, in, out);
        out.close();
    }

    static class d140 {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
            }
            Arrays.sort(a);
            int[] doneTime = new int[n + 1];
            doneTime[0] = -(6 * 60 - 10);
            for (int i = 1; i <= n; i++) {
                doneTime[i] = doneTime[i - 1] + a[i - 1];
            }
            int cnt = 0;
            int pen = 0;
            for (int i = 1; i <= n; i++) {
                if (doneTime[i] <= 6 * 60) {
                    cnt++;
                    if (doneTime[i] > 0) {
                        pen += doneTime[i];
                    }
                }
            }
            out.print(cnt + " " + pen);
        }

    }

    static class InputReader {
        private BufferedReader reader;
        private StringTokenizer stt;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
        }

        public String nextLine() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                return null;
            }
        }

        public String next() {
            while (stt == null || !stt.hasMoreTokens()) {
                stt = new StringTokenizer(nextLine());
            }
            return stt.nextToken();
        }

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

    }
}


import java.io.*;
import java.net.URL;
import java.util.*;

public class Template implements Runnable {

    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    void init() throws FileNotFoundException {
        try {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        } catch (Exception e) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        }
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            try {
                tok = new StringTokenizer(in.readLine(), " :");
            } catch (Exception e) {
                return null;
            }
        }
        return tok.nextToken();
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    int[] readIntArray(int size) throws IOException {
        int[] res = new int[size];
        for (int i = 0; i < size; i++) {
            res[i] = readInt();
        }
        return res;
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }

    <T> List<T>[] createGraphList(int size) {
        List<T>[] list = new List[size];
        for (int i = 0; i < size; i++) {
            list[i] = new ArrayList<>();
        }
        return list;
    }

    public static void main(String[] args) {
        new Thread(null, new Template(), "", 1l * 200 * 1024 * 1024).start();
    }

    long timeBegin, timeEnd;

    void time() {
        timeEnd = System.currentTimeMillis();
        System.err.println("Time = " + (timeEnd - timeBegin));
    }

    long memoryTotal, memoryFree;

    void memory() {
        memoryFree = Runtime.getRuntime().freeMemory();
        System.err.println("Memory = " + ((memoryTotal - memoryFree) >> 10)
                + " KB");
    }

    public void run() {
        try {
            timeBegin = System.currentTimeMillis();
            memoryTotal = Runtime.getRuntime().freeMemory();
            init();
            solve();
            out.close();
            if (System.getProperty("ONLINE_JUDGE") == null) {
                time();
                memory();
            }
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }

    class Obj implements Comparable<Obj> {
        int val;
        int cnt;

        public Obj(int val, int cnt) {
            this.val = val;
            this.cnt = cnt;
        }

        @Override
        public int compareTo(Obj o) {
            if (cnt != o.cnt) return o.cnt - cnt;
            return val - o.val;
        }
    }

    void solve() throws IOException {
        int n = readInt();
        int[] a = readIntArray(n);
        int TWELVE = 12 * 60 - 10;
        int HALF = 6 * 60;

        int cntTasks = 0;
        int cntS = 0;
        for (int x : a) {
            if (TWELVE - x < 0) break;
            cntTasks++;
            TWELVE -= x;
            int s = HALF - TWELVE;
            s = Math.max(s, 0);
            cntS += s;
        }
        out.println(cntTasks + " " + cntS);
    }

}


import java.io.*;
import java.net.URL;
import java.util.*;

public class Template implements Runnable {

    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    void init() throws FileNotFoundException {
        try {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        } catch (Exception e) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        }
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            try {
                tok = new StringTokenizer(in.readLine(), " :");
            } catch (Exception e) {
                return null;
            }
        }
        return tok.nextToken();
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    int[] readIntArray(int size) throws IOException {
        int[] res = new int[size];
        for (int i = 0; i < size; i++) {
            res[i] = readInt();
        }
        return res;
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }

    <T> List<T>[] createGraphList(int size) {
        List<T>[] list = new List[size];
        for (int i = 0; i < size; i++) {
            list[i] = new ArrayList<>();
        }
        return list;
    }

    public static void main(String[] args) {
        new Thread(null, new Template(), "", 1l * 200 * 1024 * 1024).start();
    }

    long timeBegin, timeEnd;

    void time() {
        timeEnd = System.currentTimeMillis();
        System.err.println("Time = " + (timeEnd - timeBegin));
    }

    long memoryTotal, memoryFree;

    void memory() {
        memoryFree = Runtime.getRuntime().freeMemory();
        System.err.println("Memory = " + ((memoryTotal - memoryFree) >> 10)
                + " KB");
    }

    public void run() {
        try {
            timeBegin = System.currentTimeMillis();
            memoryTotal = Runtime.getRuntime().freeMemory();
            init();
            solve();
            out.close();
            if (System.getProperty("ONLINE_JUDGE") == null) {
                time();
                memory();
            }
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }

    class Obj implements Comparable<Obj> {
        int val;
        int cnt;

        public Obj(int val, int cnt) {
            this.val = val;
            this.cnt = cnt;
        }

        @Override
        public int compareTo(Obj o) {
            if (cnt != o.cnt) return o.cnt - cnt;
            return val - o.val;
        }
    }

    void solve() throws IOException {
        int n = readInt();
        int[] a = readIntArray(n);
        Arrays.sort(a);
        int TWELVE = 12 * 60 - 10;
        int HALF = 6 * 60;

        int cntTasks = 0;
        int cntS = 0;
        for (int x : a) {
            if (TWELVE - x < 0) break;
            cntTasks++;
            TWELVE -= x;
            int s = HALF - TWELVE;
            s = Math.max(s, 0);
            cntS += s;
        }
        out.println(cntTasks + " " + cntS);
    }

}


import java.io.*;
import java.util.*;
public class Main implements Runnable{

    private void solve()throws IOException{
    	int n=nextInt();
    	int a[]=new int[n+1];
    	for(int i=1;i<=n;i++){
    		a[i]=nextInt();
    	}
    	Arrays.sort(a,1,n+1);
    	int time=10,count=0,penalty=0;
    	for(int i=1;i<=n;i++){
    		if(time+a[i]<=720){
    			count++;
    			time+=a[i];
    			penalty+=max(0,time-360);
    		}
    	}
    	out.println(count+" "+penalty);
    }

    ///////////////////////////////////////////////////////////

    final long mod=(long)(1e9+7);
    final int inf=(int)(1e9+1);
    final int maxn=(int)(1e6);
    final long lim=(long)(1e18);

    public void run(){
        try{
            br=new BufferedReader(new InputStreamReader(System.in));
            st=null;
            out=new PrintWriter(System.out);

            solve();

            // int t=nextInt();
            // for(int i=1;i<=t;i++){
            //     // out.print("Case #"+i+": ");
            //     solve();
            // }

            br.close();
            out.close();
        }catch(Exception e){
            e.printStackTrace();
            System.exit(1);
        }
    }
    public static void main(String args[])throws IOException{
        new Main().run();
    }
    int max(int ... a){
        int ret=a[0];
        for(int i=1;i<a.length;i++)
        ret=Math.max(ret,a[i]);
        return ret;
    }
    int min(int ... a){
        int ret=a[0];
        for(int i=1;i<a.length;i++)
        ret=Math.min(ret,a[i]);
        return ret;
    }
    void debug(Object ... a){
        System.out.print("> ");
        for(int i=0;i<a.length;i++)
        System.out.print(a[i]+" ");
        System.out.println();
    }
    void debug(int a[]){debuga(Arrays.stream(a).boxed().toArray());}
    void debug(long a[]){debuga(Arrays.stream(a).boxed().toArray());}
    void debuga(Object a[]){
        System.out.print("> ");
        for(int i=0;i<a.length;i++)
        System.out.print(a[i]+" ");
        System.out.println();
    }
    BufferedReader br;
    StringTokenizer st;
    PrintWriter out;
    String nextToken()throws IOException{
        while(st==null || !st.hasMoreTokens())
        st=new StringTokenizer(br.readLine());
        return st.nextToken();
    }
    String nextLine()throws IOException{
        return br.readLine();
    }
    int nextInt()throws IOException{
        return Integer.parseInt(nextToken());
    }
    long nextLong()throws IOException{
        return Long.parseLong(nextToken());
    }
    double nextDouble()throws IOException{
        return Double.parseDouble(nextToken());
    }
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {
		InputReader in = new InputReader(System.in);
		PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.flush();
		out.close();
	}
}

class Pair implements Comparable<Pair> {
	int first;
	int second;

	Pair(int first, int second) {
		this.first = first;
		this.second = second;
	}

	@Override
	public int compareTo(Pair e) {
		return Long.compare(second, e.second);

	}
}

class TaskB {
	int INF = (int) 1e9 + 7;
	int MAX_N = (int) 1e5 + 5;
	long mod = (long) 1e8;

	void solve(int testNumber, InputReader in, PrintWriter pw) {
		int n = in.nextInt();
		int times[] = new int[n];
		for (int i = 0; i < n; i++) {
			times[i] = in.nextInt();
		}
		Arrays.sort(times);
		int ans = 0;
		int sum = 10;
		int penTime = 0;
		for (int i = 0; i < n; i++) {
			sum += times[i];
			if (sum > 720) {
				break;
			}
			if (sum > 360 && sum <= 720) {
				penTime += sum - 360;
			}
			ans++;
		}
		pw.print(ans + " " + penTime);

	}

	int dist(int[] x, int[] y) {
		return (x[0] - y[0]) * (x[0] - y[0]) + (x[1] - y[1]) * (x[1] - y[1]);

	}

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

	int[] shrink(int a[]) {
		int n = a.length;
		long b[] = new long[n];
		for (int i = 0; i < n; i++) {
			b[i] = ((long) (a[i] << 32)) | i;
		}
		Arrays.sort(b);
		int ret[] = new int[n];
		int p = 0;
		for (int i = 0; i < n; i++) {
			if (i > 0 && (b[i] ^ b[i - 1]) >> 32 != 0) {
				p++;
			}
			ret[(int) b[i]] = p;
		}
		return ret;
	}

	int sum(int ft[], int i) {
		int sum = 0;
		for (int j = i; j >= 1; j -= (j & -j)) {
			sum += ft[j];
//			System.out.println(sum);
		}
		return sum;
	}

	void add(int ft[], int i, int x) {
		for (int j = i; j < ft.length; j += (j & -j)) {
//			System.out.println(j);
			ft[j] += x;
		}
	}

	boolean isValid(int i, int j, char arr[][]) {

		if (i >= arr[0].length || j >= arr[0].length) {
			return false;
		}
		if (arr[i][j] == '*') {
			return false;
		}
		return true;
	}

	long pow(long m, long k) {
		long prod = 1;
		for (int i = 0; i < k; i++) {
			prod = (prod * m) % INF;
		}
		return prod % INF;
	}

//	int sum(int k) {
//		int sum=0;
//		for(int i=k;i>=1;i) {
//			sum+=ft[k];
//		}
//	}

	long fib(int N) {
		long fib[] = new long[N + 1];
		fib[0] = 1;
		fib[1] = 1;
		for (int i = 2; i <= N; i++) {
			fib[i] = (fib[i - 1] + fib[i - 2]) % mod;
		}
		return fib[N] % mod;
	}

	long sum(int i, int j, long arr[]) {
		long sum = 0;
		for (int k = i; k <= j; k++) {
			sum += arr[k];
		}
		return sum;
	}

	int __gcd(int a, int b) {
		if (b == 0)
			return a;
		return __gcd(b, a % b);

	}

	public int isPow(long num) {
		int count = 0;
		while (num > 0) {
			num /= 2;
			count++;
		}
		return count;
	}
}

class InputReader {
	BufferedReader br;
	StringTokenizer st;

	public InputReader(InputStream in) {
		br = new BufferedReader(new InputStreamReader(in));
		st = null;
	}

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

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

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

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


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * Created by Egor on 29/09/14.
 */
public class Task140D {

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter writer;

    public String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }

    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    public double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    public long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    public static void main(String[] args) throws IOException {
        new Task140D().run();
    }

    public void solve() throws IOException {
        int n = nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
        }
        Arrays.sort(a);
        int currentTime = 10;

        long answer = 0;
        int i;

        for (i = 0; i < n; i++) {
            if (currentTime + a[i] > 720) break;

            currentTime += a[i];
            if (currentTime > 360) {
                answer += currentTime - 360;
            }
        }

        writer.println(i + " " + answer);
    }

    public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
            writer = new PrintWriter(System.out);

            solve();

            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * Created by Egor on 29/09/14.
 */
public class Task140D {

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter writer;

    public String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }

    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    public double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    public long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    public static void main(String[] args) throws IOException {
        new Task140D().run();
    }

    public void solve() throws IOException {
        int n = nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
        }
        Arrays.sort(a);
        int currentTime = 10;

        long answer = 0;
        int i;
//        while (currentTime < 300) {
//            currentTime += a[i];
//            i++;
//        }
//        i--;
//        currentTime -= a[i];
//
//        int j;
//        for (j = i; j < n; j++) {
//            answer += Math.abs(currentTime - 360);
//            currentTime += a[j];
//        }

        for (i = 0; i < n; i++) {
            if (currentTime + a[i] > 720) break;
            currentTime += a[i];
            if (currentTime > 300) {
                answer += Math.abs(360 - currentTime);
            }
        }

        writer.println(i + " " + answer);
    }

    public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
            writer = new PrintWriter(System.out);

            solve();

            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

}