#include <iostream>
#include <cmath>
using namespace std;
double i,j,t,d,a,b,dd;
int main(){
cin>>t;
for(i=0;i<t;++i){
    cin>>d;
  dd= (d*d)-(4*d) ;
    if(dd<0){
        cout<<"N"<<endl;
            continue;}
      else{
   a=(d-sqrt(dd)) /2.0;
      b=d-a;
 cout<<"Y "<<a<<" "<<b<<endl;

    }

}
return 0;
}


#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
double i,j,t,d,a,b,dd;
int main(){
cin>>t;
for(i=0;i<t;++i){
    cin>>d;
  dd= (d*d)-(4*d) ;
    if(dd<0){
        cout<<"N"<<endl;
            continue;}
      else{
   a=(d-sqrt(dd)) /2.0;
      b=d-a;
 cout<<"Y "<<setprecision(10)<<a<<" "<<b<<endl;

    }

}
return 0;
}


//#include <iostream>
//#include <string>
//using namespace std;
//void swap(int *a,int *b){
//    int temp=*a;
//    *a=*b;
//    *b=temp;
//
//    return;
//}
//
//int main(){
//    int t,a1,a2,b1,b2;
//
//    cin>>t;
//
//    while(t--){
//        cin>>a1>>b1>>a2>>b2;
//
//
//        if(b1>a1){swap(a1,b1);}
//        if(b2>a2){swap(a2,b2);}
//
//
//        if(a1==a2 && b1+b2==a1)cout<<"Yes\n";
//        else cout<<"No\n";
//    }
//
//return 0;}

//#include <iostream>
//using namespace std;
//int main(){
//    int t,n,a,b,c,d,flag=1;
//
//    cin>>t;
//
//    while(t--){
//        cin>>n>>a>>b>>c>>d;
//        // a-b a+b
//        //c+d c-d
//        // [n(a-b), n(a+b)] [c-d, c+d]
//
//        for(int i=n*(a-b);i<=n*(a+b);i++){
//            if(i>=c-d && i<=c+d){cout<<"Yes\n";flag=0;break;}
//        }
//        if(flag)cout<<"No\n";
//        flag=1;
//
//    }
//return 0;}

//#include <iostream>
//using namespace std;
//int main(){
//
//    int t,n,m;
//
//    cin>>t;
//
//    while(t--){
//        cin>>n>>m;
//
//        if(n==1 || m==1 || (n==2 && m==2))cout<<"YES\n";
//        else cout<<"NO\n";
//    }
//return 0;
//}

#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main(){
    int t;
    double d,a,b,D;
    cin>>t;

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

        D=abs(pow(d,2))-4*d;

        if(D<0) cout<<"N\n";

        else{
            b=(d+sqrt(D))/2;
            a=d-b;

            if(b>a)swap(a,b);

            cout<<'Y'<<" "<<fixed<<setprecision(9)<<a<<" "<<b<<endl;
        }
    }

    // a+b=d
    //ab=d
    //a=d/b
    //a=d-b
    //d-b=d/b /.b
    //b(d-b)=d
    //bd-b^2=d
    //b^2 - bd+d=0
    //D=d^2-4d
    //b1,2=(d+=sqrt(D))/2
return 0;}


//#include <iostream>
//#include <string>
//using namespace std;
//void swap(int *a,int *b){
//    int temp=*a;
//    *a=*b;
//    *b=temp;
//
//    return;
//}
//
//int main(){
//    int t,a1,a2,b1,b2;
//
//    cin>>t;
//
//    while(t--){
//        cin>>a1>>b1>>a2>>b2;
//
//
//        if(b1>a1){swap(a1,b1);}
//        if(b2>a2){swap(a2,b2);}
//
//
//        if(a1==a2 && b1+b2==a1)cout<<"Yes\n";
//        else cout<<"No\n";
//    }
//
//return 0;}

//#include <iostream>
//using namespace std;
//int main(){
//    int t,n,a,b,c,d,flag=1;
//
//    cin>>t;
//
//    while(t--){
//        cin>>n>>a>>b>>c>>d;
//        // a-b a+b
//        //c+d c-d
//        // [n(a-b), n(a+b)] [c-d, c+d]
//
//        for(int i=n*(a-b);i<=n*(a+b);i++){
//            if(i>=c-d && i<=c+d){cout<<"Yes\n";flag=0;break;}
//        }
//        if(flag)cout<<"No\n";
//        flag=1;
//
//    }
//return 0;}

//#include <iostream>
//using namespace std;
//int main(){
//
//    int t,n,m;
//
//    cin>>t;
//
//    while(t--){
//        cin>>n>>m;
//
//        if(n==1 || m==1 || (n==2 && m==2))cout<<"YES\n";
//        else cout<<"NO\n";
//    }
//return 0;
//}

#include <iostream>
#include <cmath>
using namespace std;
int main(){
    int t;
    double d,a,b,D;
    cin>>t;

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

        D=abs(pow(d,2))-4*d;

        if(D<0) cout<<"N\n";

        else{
            b=(d+sqrt(D))/2;
            a=d-b;
            cout<<'Y'<<" "<<a<<" "<<b<<endl;
        }
    }

    // a+b=d
    //ab=d
    //a=d/b
    //a=d-b
    //d-b=d/b /.b
    //b(d-b)=d
    //bd-b^2=d
    //b^2 - bd+d=0
    //D=d^2-4d
    //b1,2=(d+=sqrt(D))/2
return 0;}


#include <iostream>
#include <cmath>
#include<iomanip>
using namespace std;
int main()
{
	int t;
	cin >> t;
	long double** arr = new long double*[t];
	for (int i = 0; i < t; i++)
	{
		arr[i] = new long double[2];
	}
	for (int i = 0; i < t; i++)
	{
		arr[i][0] = -1;
		arr[i][1] = -1;
	}
	for (int i = 0; i < t; i++)
	{
		long long int d, D;
		long double a, b;
		cin >> d;
		D = d * d - 4 * d;
		if (D < 0) continue;
		else if (!d)
		{
			arr[i][0] = 0;
			arr[i][1] = 0;
		}
		else
		{
			b = (d + sqrt(D)) / 2;
			a = (long double)(d) / b;
			arr[i][0] = a;
			arr[i][1] = b;
		}
	}
	for (int i = 0; i < t; i++)
	{
		if (arr[i][0]==-1) cout << 'N' << endl;
		else  cout  << "Y " << setprecision(12)  << arr[i][0] << setprecision(12) << " " << arr[i][1] << endl;
	}
	for (int i = 0; i < t; i++)
	{
		delete[] arr[i];
	}
	delete[] arr;
	return 0;
}


#include <iostream>
#include <cmath>
#include<iomanip>
using namespace std;
int main()
{
	int t;
	cin >> t;
	long double** arr = new long double*[t];
	for (int i = 0; i < t; i++)
	{
		arr[i] = new long double[2];
	}
	for (int i = 0; i < t; i++)
	{
		arr[i][0] = -1;
		arr[i][1] = -1;
	}
	for (int i = 0; i < t; i++)
	{
		long long int d;
		long double a, b, D;
		cin >> d;
		D = d * d - 4 * d;
		if (D < 0) continue;
		else if (!d)
		{
			arr[i][0] = 0;
			arr[i][1] = 0;
		}
		else
		{
			b = (d + sqrt(D)) / 2;
			a = (long double)(d) / b;
			arr[i][0] = a;
			arr[i][1] = b;
		}
	}
	for (int i = 0; i < t; i++)
	{
		if (arr[i][0]==-1) cout << 'N' << endl;
		else  cout  << "Y " << setprecision(12)  << arr[i][0] << setprecision(12) << " " << arr[i][1] << endl;
	}
	for (int i = 0; i < t; i++)
	{
		delete[] arr[i];
	}
	delete[] arr;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#define ll long long int
#define ld long double
ll n, m, k;
using namespace std;
int main()
{
	ll i, j, t;
	ld x1, x2, D, d;
	cin >> t;
	for (j = 0; j < t; j++)
	{
		cin >> d;
		if (d*d - 4 * d < 0)
		{
			cout << "N" << endl;
			continue;
		}
		else
		{
			cout << "Y ";
			D = d * d - 4 * d;
			x1 = (d + sqrt(D)) / 2;
			x2 = (d - sqrt(D)) / 2;
			cout << fixed;
			cout.precision(12);
			cout << x1 << " " << x2 << endl;;
		}
	}
	//system("pause");
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<iomanip>
using namespace std;
double d;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		cin>>d;
		if(d*d-4*d<0)
			cout<<"N"<<endl;
		else
		{
			double ans=max((d+sqrt(d*d-4*d))/2,(d-sqrt(d*d-4*d))/2);
			if(ans<0)
				cout<<"N"<<endl;
			else
				cout<<"Y"<<" "<<fixed<<setprecision(9)<<ans<<" "<<fixed<<setprecision(9)<<d-ans<<endl;
		}
	}
}


#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
#include <string>
#include <string.h>
#include <iomanip>

#define n 150000
#define check 0.000000000001
//bool comp(int &a, int &b)
//{
//	return a > b;
//}
using namespace std;

bool work = true;

void check1(double &a, double &b, int &d,double &k)
{
	work = false;
	while (a*b - d > check)
	{
		b -= k;
		a += k;
		//cout << "k";
		work = true;
	}
	b += k;
	a -= k;
	k /= 10;
	//cout << "b";

}

using namespace std;

int main()
{

	double a, b;
	int t;

	cin >> t;
	vector <int> arr(t);
	int d;
	for (int i = 0; i < t; i++)
	{
		cin >> arr[i];
	}
	for (int i = 0; i < t; i++)
	{

		d=arr[i];
		a = d / 2;
		b = d / 2;
		if (d == 4)
		{
			cout << "Y " << "2.000000 " << "2.000000"<<'\n';
			continue;
		}
		if (d == 0)
		{
			cout << "Y " << "0.0000000 " << "0.0000000"<<'\n';
			continue;
		}
		if (d < 4&&d!=0)
		{
			cout << "N"<<'\n';
		}
		else
		{
			double k = 0.1;
			a = d - 2;
			b = 2;
			while (a*b - d > check&&work&&k>0.000000001)
			{
				check1(a, b, d, k);
			}

			cout.precision(15);
			std::cout <<"Y "<< a << " " << b << '\n';
		}

	}

	//system("pause");
	return 0;
}


#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;
int main()
{int n;cin>>n;long double *arr1=new long double[n];long double d,a1,a2,b1,b2;long double *arr2=new long double[n];char *arr=new char[n];
for(int i=0;i<n;i++){cin>>d;while(d<0) cin>>d; if(d==0){arr[i]='Y';arr1[i]=0.000000000;arr2[i]=0.000000000;}else
    if(d>0 && d<4){arr[i]='N';arr1[i]=0.000000000;arr2[i]=0.000000000;}
else if(d==4){arr[i]='Y';arr1[i]=2.00000000;arr2[i]=2.000000000;}
 else  {b1=(d-sqrt(d*d-4*d))/2;a1=d-b1;if(b1+a1==d &&b1*a1==d){arr[i]='Y';arr1[i]=a1;arr2[i]=b1;}
   else{b2=(d+sqrt(d*d-4*d))/2;a2=d-b2;arr[i]='Y';arr1[i]=a2;arr2[i]=b2;}
}
}

for(int i=0;i<n;i++){if(arr[i]=='N')cout<<setprecision(11)<<arr[i]<<endl;
else cout<<setprecision(11)<<arr[i]<<" "<<setprecision(11)<<arr2[i]<<" "<<setprecision(11)<<arr1[i]<<endl;}
delete []arr;delete []arr1;delete []arr2;
return 0;
}


<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
	<FileVersion major="1" minor="6" />
	<Project>
		<Option title="matrices" />
		<Option pch_mode="2" />
		<Option compiler="gcc" />
		<Build>
			<Target title="Debug">
				<Option output="bin/Debug/matrices" prefix_auto="1" extension_auto="1" />
				<Option object_output="obj/Debug/" />
				<Option type="1" />
				<Option compiler="gcc" />
				<Compiler>
					<Add option="-g" />
				</Compiler>
			</Target>
			<Target title="Release">
				<Option output="bin/Release/matrices" prefix_auto="1" extension_auto="1" />
				<Option object_output="obj/Release/" />
				<Option type="1" />
				<Option compiler="gcc" />
				<Compiler>
					<Add option="-O2" />
				</Compiler>
				<Linker>
					<Add option="-s" />
				</Linker>
			</Target>
		</Build>
		<Compiler>
			<Add option="-Wall" />
			<Add option="-fexceptions" />
		</Compiler>
		<Unit filename="main.cpp" />
		<Extensions>
			<code_completion />
			<envvars />
			<debugger />
			<lib_finder disable_auto="1" />
		</Extensions>
	</Project>
</CodeBlocks_project_file>


#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;
int main()
{int n;cin>>n;double *arr1=new double[n];double d,a1,a2,b1,b2;double *arr2=new double[n];char *arr=new char[n];
for(int i=0;i<n;i++){cin>>d;if(d==0){arr[i]='Y';arr1[i]=0.000000000;arr2[i]=0.000000000;}else
    if(d>0 && d<4){arr[i]='N';arr1[i]=0.000000000;arr2[i]=0.000000000;}
else if(d==4){arr[i]='Y';arr1[i]=2.00000000;arr2[i]=2.000000000;}
 else  {b1=(d-sqrt(d*d-4*d))/2;a1=d-b1;if(b1+a1==d &&b1*a1==d){arr[i]='y';arr1[i]=a1;arr2[i]=b1;}
   else{b2=(d+sqrt(d*d-4*d))/2;a2=d-b2;arr[i]='y';arr1[i]=a2;arr2[i]=b2;}
}
}

for(int i=0;i<n;i++){if(arr[i]=='N')cout<<setprecision(11)<<arr[i]<<endl;
else cout<<setprecision(11)<<arr[i]<<" "<<setprecision(11)<<arr1[i]<<" "<<setprecision(11)<<arr2[i]<<endl;}
delete []arr;delete []arr1;delete []arr2;
return 0;
}


#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;
int main()
{int n;cin>>n;double *arr1=new double[n];double d,a1,a2,b1,b2;double *arr2=new double[n];char *arr=new char[n];
for(int i=0;i<n;i++){cin>>d;while(d<0) cin>>d; if(d==0){arr[i]='Y';arr1[i]=0.000000000;arr2[i]=0.000000000;}else
    if(d>0 && d<4){arr[i]='N';arr1[i]=0.000000000;arr2[i]=0.000000000;}
else if(d==4){arr[i]='Y';arr1[i]=2.00000000;arr2[i]=2.000000000;}
 else  {b1=(d-sqrt(d*d-4*d))/2;a1=d-b1;if(b1+a1==d &&b1*a1==d){arr[i]='y';arr1[i]=a1;arr2[i]=b1;}
   else{b2=(d+sqrt(d*d-4*d))/2;a2=d-b2;arr[i]='y';arr1[i]=a2;arr2[i]=b2;}
}
}

for(int i=0;i<n;i++){if(arr[i]=='N')cout<<setprecision(11)<<arr[i]<<endl;
else cout<<setprecision(11)<<arr[i]<<" "<<setprecision(11)<<arr1[i]<<" "<<setprecision(11)<<arr2[i]<<endl;}
delete []arr;delete []arr1;delete []arr2;
return 0;
}


#include <iostream>
#include <math.h>
using namespace std;
int main()
{int n;cin>>n;float *arr1=new float[n];float d,a1,a2,b1,b2,y;float *arr2=new float[n];char *arr=new char[n];
for(int i=0;i<n;i++){cin>>d;if(d==0){arr[i]='Y';arr1[i]=0.00000;arr2[i]=0.00000;}else if(d>0 && d<4){arr[i]='N';arr1[i]=0.00000;arr2[i]=0.00000;}
else if(d==4){arr[i]='Y';arr1[i]=2.00000;arr2[i]=2.00000;}
 else  {y=sqrt(d*d-4*d);b1=(d-y)/2;a1=d-b1;if(b1+a1==d &&b1*a1==d){arr[i]='y';arr1[i]=a1;arr2[i]=b1;}
   else{b2=(d+y)/2;a2=d-b2;arr[i]='y';arr1[i]=a2;arr2[i]=b2;}
}
}

for(int i=0;i<n;i++){if(arr[i]=='N')
        cout<<arr[i]<<endl;else cout<<arr[i]<<" "<<arr1[i]<<" "<<arr2[i]<<endl;}
delete []arr;delete []arr1;delete []arr2;
return 0;
}


#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;
int main()
{int n;cin>>n;double *arr1=new double[n];double d,a1,a2,b1,b2;double *arr2=new double[n];char *arr=new char[n];
for(int i=0;i<n;i++){cin>>d;while(d<0) cin>>d; if(d==0){arr[i]='Y';arr1[i]=0.000000000;arr2[i]=0.000000000;}else
    if(d>0 && d<4){arr[i]='N';arr1[i]=0.000000000;arr2[i]=0.000000000;}
else if(d==4){arr[i]='Y';arr1[i]=2.00000000;arr2[i]=2.000000000;}
 else  {b1=(d-sqrt(d*d-4*d))/2;a1=d-b1;if(b1+a1==d &&b1*a1==d){arr[i]='y';arr1[i]=a1;arr2[i]=b1;}
   else{b2=(d+sqrt(d*d-4*d))/2;a2=d-b2;arr[i]='Y';arr1[i]=a2;arr2[i]=b2;}
}
}

for(int i=0;i<n;i++){if(arr[i]=='N')cout<<setprecision(11)<<arr[i]<<endl;
else cout<<setprecision(11)<<arr[i]<<" "<<setprecision(11)<<arr2[i]<<" "<<setprecision(11)<<arr1[i]<<endl;}
delete []arr;delete []arr1;delete []arr2;
return 0;
}


#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;
int main()
{int n;cin>>n;double *arr1=new double[n];double d,a1,a2,b1,b2;double *arr2=new double[n];char *arr=new char[n];
for(int i=0;i<n;i++){cin>>d;while(d<0) cin>>d; if(d==0){arr[i]='Y';arr1[i]=0.000000000;arr2[i]=0.000000000;}else
    if(d>0 && d<4){arr[i]='N';arr1[i]=0.000000000;arr2[i]=0.000000000;}
else if(d==4){arr[i]='Y';arr1[i]=2.00000000;arr2[i]=2.000000000;}
 else  {b1=(d-sqrt(d*d-4*d))/2;a1=d-b1;if(b1+a1==d &&b1*a1==d){arr[i]='y';arr1[i]=a1;arr2[i]=b1;}
   else{b2=(d+sqrt(d*d-4*d))/2;a2=d-b2;arr[i]='y';arr1[i]=a2;arr2[i]=b2;}
}
}

for(int i=0;i<n;i++){if(arr[i]=='N')cout<<setprecision(11)<<arr[i]<<endl;
else cout<<setprecision(11)<<arr[i]<<" "<<setprecision(11)<<arr2[i]<<" "<<setprecision(11)<<arr1[i]<<endl;}
delete []arr;delete []arr1;delete []arr2;
return 0;
}


#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;
int main()
{int n;cin>>n;long double *arr1=new long double[n];long double d,a1,a2,b1,b2;long double *arr2=new long double[n];char *arr=new char[n];
for(int i=0;i<n;i++){cin>>d;while(d<0) cin>>d; if(d==0){arr[i]='Y';arr1[i]=0.000000000;arr2[i]=0.000000000;}else
    if(d>0 && d<4){arr[i]='N';arr1[i]=0.000000000;arr2[i]=0.000000000;}
else if(d==4){arr[i]='Y';arr1[i]=2.00000000;arr2[i]=2.000000000;}
 else  {b1=(d-sqrt(d*d-4*d))/2;a1=d-b1;if(b1+a1==d &&b1*a1==d){arr[i]='y';arr1[i]=a1;arr2[i]=b1;}
   else{b2=(d+sqrt(d*d-4*d))/2;a2=d-b2;arr[i]='y';arr1[i]=a2;arr2[i]=b2;}
}
}

for(int i=0;i<n;i++){if(arr[i]=='N')cout<<setprecision(11)<<arr[i]<<endl;
else cout<<setprecision(11)<<arr[i]<<" "<<setprecision(11)<<arr2[i]<<" "<<setprecision(11)<<arr1[i]<<endl;}
delete []arr;delete []arr1;delete []arr2;
return 0;
}


#include<iostream>
#include<math.h>
using namespace std;
int main(){
	int t;
    double a,b,c,d;
    cin>>t;
    for(int i=0;i<t;i++){
		cin>>d;
		if (d==0) 	cout<<"Y 0.000000000 0.000000000\n"; else
			if(d<4) {cout<<"N \n";}	else{
				c=sqrt((d/2)*(d/2)-d);
				b=d/2-c;a=d-b;
				printf("Y %.9lf %.9lf\n",a,b);
			}
	}
}


//#include<bits/stdc++.h>
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#define lson rt<<1
#define rson rt<<1|1
#define LS l,mid,lson
#define RS mid+1,r,rson
#define mem(a,x) memset(a,x,sizeof(a))
#define ll long long
#define ull unsigned long long
#define lowbit(x) (x&-x)
#define pb(x) push_back(x)
#define enld endl
#define mian main
#define itn int
#define prinft printf
#pragma GCC optimize(2)
#pragma comment(linker, "/STACK:102400000,102400000")

const double PI = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int EXP = 1e-8;
const int N = 1e5 + 5;
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;
const int MAXM = 2e6 + 5;
using namespace std;
ll gcd(ll a, ll b) {
	return !b ? a : gcd(b, a%b);
}
int main() {
	int T;
	scanf("%d", &T);
	int n;
	while (T--) {
		scanf("%d", &n);
		if (n < 4&&n) {
			cout << "N" << endl;
		}
		else if (n == 0) {
			printf("Y 0.000000000000 0.000000000000\n");
		}
		else {
			cout << "Y" << ' ';
			double c = n;
			printf("%.12lf %.12lf\n", (c - sqrt(c - 4)*sqrt(c)) / 2.0, (c + sqrt(c - 4)*sqrt(c)) / 2.0);
		}
	}

	return 0;
}


#include <iostream>

using namespace std;

int main() {

	long long numTrials;
	cin >> numTrials;

	while (numTrials--) {
		long long num;
		cin >> num;

		double test = (num * num) - (4 * num);
		if (test >= 0) {
			printf("Y %.9f %.9f\n", (num + sqrt(test)) / 2, (num - sqrt(test)) / 2);
			continue;
		}
		else {
			cout << "N" << endl;
		}
	}

	return 0;
}


#include<iostream>
#include<string>
#include<cstring>
#include<vector>
#include<cmath>
#include<iomanip>
#include<map>
#include<queue>
#include<stack>
#include<algorithm>
#include <fstream>
#include <set>
#include <list>
using namespace std;
#define ll long long
#define mp make_pair
#define all(g) g.begin(),g.end()
#define allr(g) g.rbegin(),g.rend()
#define re(x)   return cout<<x,0
#define in(n)for(int i=0;i<n;i++)cin>>v[i];
#define loop(n)for(int i=0;i<n;i++)
#define matar 	ios_base::sync_with_stdio(false); cin.tie(NULL);
#define me(x,v) memset(x,v,sizeof(x))
ll GCD(ll a, ll b){ return(b == 0) ? a : GCD(b, a%b); }
ll oo = 1e18;
ll const M = 1e9 + 7, N = 1e6 + 9;
double n, k, c = 0;

bool can(double x){
	return n / x + x <= n;

}
int main()
{
	matar
		int t;

		cin >> t;
		while (t--){
			cin >> n;
			if (n == 1)cout << 'N' << endl;
			else if (n == 0)cout<<"Y 0.000000000 0.000000000"<<endl;
			else{
				double l = 0, r = n,m,ans=-1;
				while (l <= r){
					m = (l + r) / 2;
					if (can(m)){
						ans = m;
						//cout << m << endl;

						l=m+ 0.0000000000001;
					}
					else
						r = m - 0.0000000000001;

				}
				if (ans == -1)cout << "N" ;
				else
				printf("Y %0.9Lf %0.9Lf", ans, n-ans);
				cout << endl;
			}

		}

	return 0;
}


#include<iostream>
#include<string>
#include<cstring>
#include<vector>
#include<cmath>
#include<iomanip>
#include<map>
#include<queue>
#include<stack>
#include<algorithm>
#include <fstream>
#include <set>
#include <list>
using namespace std;
#define ll long long
#define mp make_pair
#define all(g) g.begin(),g.end()
#define allr(g) g.rbegin(),g.rend()
#define re(x)   return cout<<x,0
#define in(n)for(int i=0;i<n;i++)cin>>v[i];
#define loop(n)for(int i=0;i<n;i++)
#define matar 	ios_base::sync_with_stdio(false); cin.tie(NULL);
#define me(x,v) memset(x,v,sizeof(x))
ll GCD(ll a, ll b){ return(b == 0) ? a : GCD(b, a%b); }
ll oo = 1e18;
ll const M = 1e9 + 7, N = 1e6 + 9;
double n, k, c = 0;

bool can(double x){
	return n / x + x <= n;

}
int main()
{
	matar
		int t;

		cin >> t;
		while (t--){
			cin >> n;
			if (n == 1)cout << 'N' << endl;
			else if (n == 0)cout<<"Y 0.000000000 0.000000000"<<endl;
			else{
				double l = 0, r = n,m,ans=-1;
				while (l <= r){
					m = (l + r) / 2;
					if (can(m)){
						ans = m;
						//cout << m << endl;

						l=m+ 0.0000000000001;
					}
					else
						r = m - 0.0000000000001;

				}
				if (ans == -1)cout << "N" << endl;
				else
				printf("Y %0.9Lf %0.9Lf", ans, n-ans);
			}

		}

	return 0;
}


#include<iostream>
#include<string>
#include<cstring>
#include<vector>
#include<cmath>
#include<iomanip>
#include<map>
#include<queue>
#include<stack>
#include<algorithm>
#include <fstream>
#include <set>
#include <list>
using namespace std;
#define ll long long
#define mp make_pair
#define all(g) g.begin(),g.end()
#define allr(g) g.rbegin(),g.rend()
#define re(x)   return cout<<x,0
#define in(n)for(int i=0;i<n;i++)cin>>v[i];
#define loop(n)for(int i=0;i<n;i++)
#define matar 	ios_base::sync_with_stdio(false); cin.tie(NULL);
#define me(x,v) memset(x,v,sizeof(x))
ll GCD(ll a, ll b){ return(b == 0) ? a : GCD(b, a%b); }
ll oo = 1e18;
ll const M = 1e9 + 7, N = 1e6 + 9;
double n, k, c = 0;

bool can(double x){
	return n / x + x <= n;

}
int main()
{
	matar
		int t;

	cin >> t;
	while (t--){
		cin >> n;
		if (n == 1)cout << 'N' << endl;
		else if (n == 0)cout << "Y 0.000000000 0.000000000" << endl;
		else{
			double l = 0, r = n, m, ans = -1;
			while (l <= r){
				m = (l + r) / 2;
				if (can(m)){
					ans = m;
					//cout << m << endl;

					l = m + 0.0000000000001;
				}
				else
					r = m - 0.0000000000001;

			}
			if (ans == -1)cout << "N";
			else
				printf("Y %0.9Lf %0.9Lf", ans, n - ans);
			cout << endl;
		}

	}

	return 0;
}


#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <string>
using namespace std;

void solve(double x) {
    double a = 1, b = -x, c = x, d = b * b - 4 * a * c;
    if (d < -1e-9) {
        printf("N\n");
        return;
    }
    double r1 = (-b - sqrt(d)) / (2 * a);
    if (r1 >= -1e-9 && x - r1 >= -1e-9) {
        printf("Y %.10lf %.10lf\n", r1, x - r1);
        return;
    }
    double r2 = (-b + sqrt(d)) / (2 * a);
    if (r2 >= -1e-9 && x - r2 >= -1e-9) {
        printf("Y %.10lf %.10lf\n", r2, x - r2);
        return;
    }

    printf("N\n");
    return;
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n;
    scanf("%d", &n);

    for (int i = 0; i < n; i++) {
        double x;
        scanf("%lf", &x);
        solve(x);
    }
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <climits>
#include <queue>
#include <set>
#include <fstream>
#include <iomanip>
using namespace std;

#define ll long long
long double EPS = 1e-7;

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

int main(){
	ll a,b,c,e,f,g,n,m, res;
	double d,x,y,dis;
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> d;
		dis = d*d - 4*d;
		if (dis < 0)
			cout << "N" << endl;
		else{
			dis = sqrt (dis);
			if (dis == 0){
				y = d / 2;
				x = d - y;
				cout << fixed << setprecision (8) << "Y " << x << " " << y << endl;
			}
			else{
				y = (-d + dis)/(-2);
				x = d - y;
				if ((x < 0) || (y < 0)){
					y = (-d + dis)/(-2);
					x = d - y;
					if ((x < 0) || (y < 0))
						cout << "N" << endl;
					else
						cout << fixed << setprecision (8) << "Y " << x << " " << y << endl;

				}
				else
					cout << fixed << setprecision (8) << "Y " << x << " " << y << endl;
			}

		}
	}

}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <climits>
#include <queue>
#include <set>
#include <fstream>
#include <iomanip>
using namespace std;

#define ll long long
long double EPS = 1e-7;

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

int main(){
	ll a,b,c,e,f,g,n,m, res;
	double d,x,y,dis;
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> d;
		dis = d*d - 4*d;
		if (dis < 0)
			cout << "N" << endl;
		else{
			dis = sqrt (dis);
			if (dis == 0){
				y = d / 2;
				x = d - y;
				cout << fixed << setprecision (12) << "Y " << x << " " << y << endl;
			}
			else{
				y = (-d + dis)/(-2);
				x = d - y;
				if ((x < 0) || (y < 0)){
					y = (-d + dis)/(-2);
					x = d - y;
					if ((x < 0) || (y < 0))
						cout << "N" << endl;
					else
						cout << fixed << setprecision (12) << "Y " << x << " " << y << endl;

				}
				else
					cout << fixed << setprecision (12) << "Y " << x << " " << y << endl;
			}

		}
	}

}


#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <queue>
#include <stack>
#include <string.h>
#include <iterator>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define mp make_pair
#define pb push_back

void solve(){
    int t;
    cin >> t;
    while(t--){
        ld a, b, d;
        cin >> d;
        if( d > 0){
            ld D = d * d - 4 * d;
            if(D>=0){
                a = (d + sqrt(D))/2;
                b = (d - sqrt(D))/2;
                if(a > 0 && b > 0){
                    cout <<"Y" << " " << a << " " << b << endl;

                }
            }
            else
                cout << "N" << endl;
        }
        else{
            a = 0;
            b = 0;
            cout <<"Y" << " " << a << " " << b << endl;
        }
    }
}

int main(){
    //freopen("test1.txt","r",stdin);
    //freopen("test1.txt","w",stdout);
	ios_base::sync_with_stdio(false);
	cout.setf(ios::fixed);
	cout.precision(9);
    solve();
	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <queue>
#include <stack>
#include <string.h>
#include <iterator>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define mp make_pair
#define pb push_back

void solve(){
    int t;
    cin >> t;
    while(t--){
        ld a, b, d;
        cin >> d;
        if( d > 0){
            ld D = d * d - 4 * d;
            if(D>=0){
                a = (d + sqrt(D))/2;
                b = (d - sqrt(D))/2;
                if(a > 0 && b > 0){
                    cout <<"Y" << " " << a << " " << b << endl;

                }
            }
        }
        else{
            a = 0;
            b = 0;
            cout <<"Y" << " " << a << " " << b << endl;
        }
    }
}

int main(){
    //freopen("test1.txt","r",stdin);
    //freopen("test1.txt","w",stdout);
	ios_base::sync_with_stdio(false);
	cout.setf(ios::fixed);
	cout.precision(13);
    solve();
	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
const int maxn = 100010;
typedef _int64 ll;

int main()
{
#ifdef _DEBUG
	freopen("in.txt","r",stdin);
#endif
	int t;
	double d;
	cin>>t;
	while(t--)
	{
		cin>>d;
		double tmp = d*d-4*d;
		if(tmp>=0)
		{
			double a = (sqrt(double(tmp))+d)/2;
			double b = d-a;
			printf("Y %.9lf %.9lf\n",a,b);
		}
		else
			cout<<"N"<<endl;
	}
	return 0;
}


#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <string>
#include <stdio.h>
#include <set>
#include <map>
#include <algorithm>
#include <queue>
#include <vector>
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second

using namespace std;

const int inf = 1e9 + 7;
const long long INF = 1e18 + 7;
const int maxn = 2e5 + 7;

int n;

int main(){
	ios_base::sync_with_stdio(NULL);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++){
		int x;
		cin >> x;
		if (x * x - 4 * x < 0){
			cout << "N" << endl;
		} else {
			cout << "Y ";
			double d = x * x * 1.0 - 4 * x * 1.0;
			double a1 = abs((-x - sqrt(d) * 1.0) / 2);
			double a2 = abs((-x + sqrt(d) * 1.0) / 2);
			cout << fixed << setprecision(6) << a1 << ' ' << a2 << endl;
		}
	}
	return 0;
}


#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <string>
#include <stdio.h>
#include <set>
#include <map>
#include <algorithm>
#include <queue>
#include <vector>
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second

using namespace std;

const int inf = 1e9 + 7;
const long long INF = 1e18 + 7;
const int maxn = 2e5 + 7;

int n;

int main(){
	ios_base::sync_with_stdio(NULL);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++){
		int x;
		cin >> x;
		if (x * x - 4 * x < 0){
			cout << "N" << endl;
		} else {
			cout << "Y ";
			double d = x * x * 1.0 - 4 * x * 1.0;
			double a1 = abs((-x - sqrt(d) * 1.0) / 2);
			double a2 = abs((-x + sqrt(d) * 1.0) / 2);
			cout << fixed << setprecision(9) << a1 << ' ' << a2 << endl;
		}
	}
	return 0;
}


#include <iostream>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long double x;
    cin >> x;
    if (x == 1 || x == 2 || x == 3) {
      cout << "N" << endl;
      continue;
    }
    long double d = x;
    long double l = 0, r = d;
    int cnt = 1000;
    while (cnt--) {
      long double tm = (l + r) / 2;
      if (tm * (d - tm) < d)
        r = tm;
      else
        l = tm;
    }
    printf("Y %.9Lf %.9Lf\n", l, d - l);
  }
  return 0;
}


#include <iostream>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long double x;
    cin >> x;
    if (x == 1) {
      cout << "N" << endl;
      continue;
    }
    long double d = x;
    long double l = 0, r = d;
    int cnt = 1000;
    while (cnt--) {
      long double tm = (l + r) / 2;
      if (tm * (d - tm) < d)
        r = tm;
      else
        l = tm;
    }
    printf("Y %.9Lf %.9Lf\n", l, d - l);
  }
  return 0;
}


#include <iostream>
#include <cmath>
#include <vector>
#include <iomanip>
using namespace std;

int main()
{
	int t;
	cin>>t;
	for(int i = 0;i < t;i++)
	{
		double d,a,b;
		cin>>d;
		if(d*d - 4*d < 0)
		{
			cout<<"N"<<endl;
		}
		else
		{
			double D = sqrt(d * (d - 4));
			a = ((d + D)/2.0);
			b = ((d - D)/2.0);
			cout<<"Y "<<fixed<<std::setprecision(9)<<a<<" "<<b<<endl;
		}
	}
	return 0;
}


#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
void Calculate(long double d)
{
    long double l=0,r=d/2,m1,m2;
    long double dist=0.0000000001;
    long double qual=0.000001;
    m1=(l+r)/2; m2=d-m1;

    while((r-l)>dist)
    {
        if(m1*m2<=d){l=m1;}
        else{r=m1;}
        m1=(l+r)/2;
        m2=d-m1;
    }
    m1=l;
    m2=(d-l);
    if((abs(((m1+m2)-m1*m2))<=qual)&&(abs(m1+m2-d)<=qual))
    {cout<<"Y "<<fixed<<setprecision(9)<<m1<<" "<<fixed<<setprecision(9)<<m2<<endl;}
    else{cout<<"N"<<endl;}
}
int main()
{
    int t;
    long double d;
    cin>>t;
    for(int i=0;i<t;i++)
    {
        cin>>d;
        Calculate(d);

    }
}


#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
bool Calculate(long double d)
{
    long double l=0,r=d/2,m1,m2;
    long double dist=0.000000001;
    long double qual=1e-6;
    m1=(l+r)/2; m2=d-m1;

    while((r-l)>dist)
    {
        if(m1*m2<=d){l=m1;}
        else{r=m1;}
        m1=(l+r)/2;
        m2=d-m1;
    }
    m1=l;
    m2=(d-l);
    if((abs(((m1+m2)-m1*m2))<=qual)&&(abs(m1+m2-d)<=qual))
    {cout<<"Y "<<fixed<<setprecision(9)<<m1<<" "<<fixed<<setprecision(9)<<m2<<endl;}
    else{cout<<"N"<<endl;}
}
int main()
{
    int t;
    long double d;
    cin>>t;
    for(int i=0;i<t;i++)
    {
        cin>>d;
        Calculate(d);

    }
}


#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
void Calculate(long double d)
{
    long double l=0,r=d/2,m1,m2;
    long double dist=0.000000001;
    long double qual=1e-6;
    m1=(l+r)/2; m2=d-m1;

    while((r-l)>dist)
    {
        if(m1*m2<=d){l=m1;}
        else{r=m1;}
        m1=(l+r)/2;
        m2=d-m1;
    }
    m1=l;
    m2=(d-l);
    if((abs(((m1+m2)-m1*m2))<=qual)&&(abs(m1+m2-d)<=qual))
    {cout<<"Y "<<fixed<<setprecision(9)<<m1<<" "<<fixed<<setprecision(9)<<m2<<endl;}
    else{cout<<"N"<<endl;}
}
int main()
{
    int t;
    long double d;
    cin>>t;
    for(int i=0;i<t;i++)
    {
        cin>>d;
        Calculate(d);

    }
}


#include <iostream>
using namespace std;

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

	double *arr_num = new double [test_num];
	for(int i = 0; i < test_num; i++)
		cin >> arr_num[i];
	double b,a;
	cout<<std::fixed;
	cout.precision(9);
	for(int i = 0; i < test_num; i++)
	{
		b = a = 0;
		if(arr_num[i] == 1)
			cout << "N" << endl;
		else if(arr_num[i] == 0)
			cout << "Y " << a << " " << b << " " << endl;
		else
		{
			b = (arr_num[i] + sqrt((arr_num[i]*arr_num[i]) - (4 * arr_num[i]))) / 2;
			if(b < 0)
				b = (arr_num[i] - sqrt((arr_num[i]*arr_num[i]) - (4 * arr_num[i]))) / 2;
			a = arr_num[i] / b;
			if(a > 0 && b > 0)
				cout << "Y " << a << " " << b << " " << endl;
			else
				cout << "N" << endl;
		}

	}

	return 0;
}


#include<iostream>
#include<vector>
#include<iomanip>
#include<cmath>
using namespace std;
int main()
{
    double i,d,t;
    cin>>t;
    for(i=0;i<=t-1;i++)
    {
    cin>>d;
    if(d>=4||d==0)
   {
       cout<<"Y ";
       cout<<fixed;
       cout<<setprecision(9)<<(d+pow(pow(d,2)-4*d,.5))/2;
       cout<<" ";
       //cout<<fixed;
       cout<<setprecision(9)<<(d-pow(pow(d,2)-4*d,.5))/2;
       cout<<"\n";
   }
   else
   cout<<"N\n";
    }

}


#include<iostream>
#include<vector>
#include<iomanip>
#include<cmath>
using namespace std;
int main()
{
    double a,b,c,d;
    cin>>d;
    if(d>=4)
   {
       cout<<"Y ";
       cout<<fixed;
       cout<<setprecision(9)<<(d+pow(pow(d,2)-4*d,.5))/2;
       cout<<" ";
       //cout<<fixed;
       cout<<setprecision(9)<<(d-pow(pow(d,2)-4*d,.5))/2;
   }
   else
   cout<<"N";

}


#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
#include <queue>
#include <string>
#include <string.h>
#include <map>
#include <vector>
#include <fstream>
using namespace std;
#define N 102400
#define M 401000
//#define MAXN 1125899906842624L
#define MAXVAL 1000000000
#define MAXN 520*520
#define MOD 1000000007
int d;

void solve() {
	if (d == 0) {
		printf("Y %.8f %.8f\n", 0, 0);
		return;
	} else if (d < 4) {
		printf("N\n");
		return;
	}
	double x = 0.0, y = 1.0, mid;
	double z = (double)d - 2.0;
	while (fabs(x - y) > 1e-7) {
		mid = (x + y) / 2.0;
		if (mid + 1.0/mid > z) {
			x = mid;
		} else {
			y = mid;
		}
	}
	double b = x + 1.0;
	double a = d - b;
	printf("Y %.8f %.8f\n", a, b);
}
int main() {
	int tc;
	scanf("%d", &tc);
	while (tc--) {
		scanf("%d", &d);
		solve();
	}
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
#include <queue>
#include <string>
#include <string.h>
#include <map>
#include <vector>
#include <fstream>
using namespace std;
#define N 102400
#define M 401000
//#define MAXN 1125899906842624L
#define MAXVAL 1000000000
#define MAXN 520*520
#define MOD 1000000007
int d;

void solve() {
	if (d == 0) {
		printf("Y %.8f %.8f\n", 0, 0);
		return;
	} else if (d < 4) {
		printf("N\n");
		return;
	}
	double x = 0.0, y = 1.0, mid;
	double z = (double)d - 2.0;
	while (fabs(x - y) > 1e-10) {
		mid = (x + y) / 2.0;
		if (mid + 1.0/mid > z) {
			x = mid;
		} else {
			y = mid;
		}
	}
	double b = x + 1.0;
	double a = d - b;
	printf("Y %.9f %.9f\n", a, b);
}
int main() {
	int tc;
	scanf("%d", &tc);
	while (tc--) {
		scanf("%d", &d);
		solve();
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <iomanip>

#define fixIOStream std::ios_base::sync_with_stdio(false); std::cin.tie(0);
#define endl '\n'

using namespace std;

int main(){
	cout << fixed << setprecision(9);
	int t;
	cin >> t;
	vector <int> a;
	int cur;
	for(int i = 0; i < t; i++){
		cin >> cur;
		a.push_back(cur);
	}
	for(int i = 0; i < t; i++){
		if(a[i]*a[i] - 4*a[i] < 0){
			cout << "N" << endl;
		}else{
			cout << "Y"  << " " << (a[i] + sqrtl(a[i]*a[i] - 4*a[i]))/2 << " " << (a[i] - sqrtl(a[i]*a[i] - 4*a[i]))/2 << endl;
		}
	}
	return 0;
}


#include<stdio.h>
#include<math.h>
int main()
{int t;
double a,b,c,d;
scanf("%d",&t);
for(int i=0;i<t;i++)
{scanf("%lf",&d);
if(d==0)
	printf("Y 0.000000000 0.000000000\n");
else
if(d<4)
	{printf("N\n");}
else
{
c=sqrt((d/2)*(d/2)-d);
b=d/2-c;a=d-b;
printf("Y %lf %lf\n",b,a);}}}


#include<stdio.h>
#include<math.h>
int main()
{int t;
double a,b,c,d;
scanf("%d",&t);
for(int i=0;i<t;i++)
{scanf("%lf",&d);
if(d==0)
	printf("Y 0.000000000 0.000000000\n");
else
if(d<4)
	{printf("N\n");}
else
{
c=sqrt((d/2)*(d/2)-d);
b=d/2-c;a=d-b;
printf("Y %.8lf %.8lf\n",a,b);}}}


#include<stdio.h>
#include<math.h>
int main()
{int t;
double a,b,c,d;
scanf("%d",&t);
for(int i=0;i<t;i++)
{scanf("%lf",&d);
if(d==0)
	printf("Y 0.000000000 0.000000000\n");
else
if(d<4)
	{printf("N \n");}
else
{
c=sqrt((d/2)*(d/2)-d);
b=d/2-c;a=d-b;
printf("Y %.9lf %.9lf\n",a,b);}}}


#include <iostream>
#include <iomanip>

using namespace std;
int main() {

int d;
int t;
cin >> t;

for(int i = 0; i < t; i++) {
    cin >> d;

    double dis = d * d - 4 * d;

    if (dis >= 0.0) {
        double b = (d + sqrt(dis)) / 2.0;

        double a = d - b;
        cout << fixed << setprecision(9) << "Y" << " " << b << " " << a << endl;
    } else {
        cout << "N" << endl;
    }
}
}


#include <iostream>
#include <iomanip>

using namespace std;
int main() {

int d;
int t;
cin >> t;

for(int i = 0; i < t; i++) {
    cin >> d;

    double dis = d * d - 4 * d;

    if (dis >= 0.0) {
        double b = (d + sqrt(dis)) / 2.0;

        double a = d - b;
        cout << fixed << setprecision(8) << "Y" << " " << b << " " << a << endl;
    } else {
        cout << "N" << endl;
    }
}
}


#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
const long double eps=1e-8;
int main(){
    int t;
    cin>>t;
    while(t--){
         double d;
        cin>>d;
        if(d*d<4*d){printf("N\n");continue;}
        else printf("Y\n");
       double a=(d+sqrt(d*d-4*d))/2.0;
        double b=d-a;
        if(fabs(a-0.0)<eps)a=0;
        if(fabs(b-0.0)<eps)b=0;
        printf("%.9lf %.9lf\n",a,b);
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
struct nide
{
    int x,y;
}b[1001];
int main()
{
    int n,m,k,i,j,sum=0;
    int a[1001];
    scanf("%d",&n);
    for(i=1;i<=n;i++)
        scanf("%d",&a[i]);
    scanf("%d",&m);
    for(j=1;j<=m;j++)
        scanf("%d%d",&b[j].x,&b[j].y);
        for(i=1;i<=n;i++)
        sum+=a[i];
//        printf("%d\n",sum);
//        printf("%d\n",b[m].y);
        if(sum<=b[m].y)
            {
                for(i=1;i<=m;i++)
                   {
                       if(b[i].x>=sum)
                        {
                            k=b[i].x;
                            break;
                        }
                        if(b[i].y>=sum)
                        {
                            k=sum;
                            break;
                        }
                   }
            }
        else if(sum>b[m].y) k=-1;
        printf("%d\n",k);
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
struct node
{
    int x,y;
}b[1001];
bool cmp(node a,node b)
{
    return a.x<b.x;
}
int main()
{
    int n,m,k=0,i,j,sum=0;
    int a[1001];
    scanf("%d",&n);
    for(i=1;i<=n;i++)
        scanf("%d",&a[i]);
    scanf("%d",&m);
    for(j=1;j<=m;j++)
        scanf("%d%d",&b[j].x,&b[j].y);
        for(i=1;i<=n;i++)
        sum+=a[i];
        sort(a,a+n);
        sort(b,b+n,cmp);
//        printf("%d\n",sum);
//        printf("%d\n",b[m].y);
        if(sum<=b[m].y)
            {
                for(i=1;i<=m;i++)
                   {
                       if(b[i].x>=sum)
                        {
                            k=b[i].x;
                            break;
                        }
                        if(k!=0) break;
                   }
            }
        else if(sum>b[m].y) k=-1;
        printf("%d\n",k);
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
struct node
{
    int x,y;
}b[1001];
bool cmp(node a,node b)
{
    return a.x<b.x;
}
int main()
{
    int n,m,k=0,i,j,sum=0;
    int a[1001];
    scanf("%d",&n);
    for(i=1;i<=n;i++)
        scanf("%d",&a[i]);
    scanf("%d",&m);
    for(j=1;j<=m;j++)
        scanf("%d%d",&b[j].x,&b[j].y);
        for(i=1;i<=n;i++)
        sum+=a[i];
        sort(a,a+n);
        sort(b,b+n,cmp);
//        printf("%d\n",sum);
//        printf("%d\n",b[m].y);
        if(sum<=b[m].y)
            {
                for(i=1;i<=m;i++)
                   {
                       if(b[i].x>=sum)
                        {
                            k=b[i].x;
                            break;
                        }
                        if(b[i].y>=sum)
                        {
                            k=b[i].y;
                            break;
                        }
                        if(k!=0) break;
                   }
            }
        else if(sum>b[m].y) k=-1;
        printf("%d\n",k);
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
struct nide
{
    int x,y;
}b[1001];
int main()
{
    int n,m,k,i,j,sum=0;
    int a[1001];
    scanf("%d",&n);
    for(i=1;i<=n;i++)
        scanf("%d",&a[i]);
    scanf("%d",&m);
    for(j=1;j<=m;j++)
        scanf("%d%d",&b[j].x,&b[j].y);
        for(i=1;i<=n;i++)
        sum+=a[i];
//        printf("%d\n",sum);
//        printf("%d\n",b[m].y);
        if(sum<=b[m].y)
            {
                for(i=1;i<=m;i++)
                   {
                       if(b[i].x>=sum)
                        {
                            k=b[i].x;
                            break;
                        }
                        if(b[i].y>=sum)
                        {
                            k=b[i].y;
                            break;
                        }
                   }
            }
        else if(sum>b[m].y) k=-1;
        printf("%d\n",k);
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    // freopen("test.txt","r",stdin);
    int n,m,sum=0,x,y,t;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&t);
        sum+=t;
    }
    int flag=0;
    scanf("%d",&m);
    for(int i=0;i<m;i++)
    {
        scanf("%d%d",&x,&y);
        if(flag)continue;
        if(x<=sum && sum<=y)
        {
            printf("%d\n",sum);
            flag=1;
        }
        else if(sum<x)
        {
            printf("%d\n",x);
            flag=1;
        }
    }
    if(!flag)printf("-1\n");
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
struct node
{
    int x,y;
}b[1001];
bool cmp(node a,node b)
{
    return a.x<b.x;
}
int main()
{
    int n,m,k,i,j,sum=0;
    int a[1001];
    scanf("%d",&n);
    for(i=1;i<=n;i++)
        scanf("%d",&a[i]);
    scanf("%d",&m);
    for(j=1;j<=m;j++)
        scanf("%d%d",&b[j].x,&b[j].y);
        for(i=1;i<=n;i++)
        sum+=a[i];
        sort(a,a+n);
        sort(b,b+n,cmp);
//        printf("%d\n",sum);
//        printf("%d\n",b[m].y);
        if(sum<=b[m].y)
            {
                for(i=1;i<=m;i++)
                   {
                       if(b[i].x>=sum)
                        {
                            k=b[i].x;
                            break;
                        }
                        if(b[i].y>=sum)
                        {
                            k=b[i].y;
                            break;
                        }
                   }
            }
        else if(sum>b[m].y) k=-1;
        printf("%d\n",k);
}


#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
   int answers[4];
   int a,b,c;
   cin>> a>>b>>c;

   answers[0]=a+b+c;
   answers[1]=a*b*c;

   answers[2]=a*(b+c);
   answers[3]=(a+b)*c;
   sort(answers,answers+4);
   cout<<answers[3]<<endl;
   return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
   int answers[6];
   int a,b,c;
   cin>>a>>b>>c;

   answers[0]=a+b+c;
   answers[1]=a*b*c;
   answers[2]=a*b+c;
   answers[3]=a+b*c;
   answers[4]=a*(b+c);
   answers[5]=(a+b)*c;
   sort(answers,answers+6);
   cout<<answers[5]<<endl;
   return 0;
}


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

using namespace std;

int main(){
    int n, input;
	int sum = 0;
    cin >> n;

    for(int i = 0; i<n; i++)
	{
        cin >>input;
		sum+= input;
    }
    int m;
	cin >> m;
	for(int i = 0; i<m; i++)
	{
		int l, r;

        cin >>l >> r;
		if(sum >= l && sum <= r)
		{
			cout << sum << endl;
			return 0;

		}else if(l >= sum)
		{
			cout << l << endl;
			return 0;
		}

    }
	cout << -1;
	//system("pause");
	return 0;

}


#include <iostream>

using namespace std;

int main()
{
   int answers[6];
   int a,b,c;
   cin>>a>>b>>c;

   answers[0]=a+b+c;
   answers[1]=a*b*c;
   answers[2]=a*b+c;
   answers[3]=a+b*c;
   answers[4]=a*(b+c);
   answers[5]=(a+b)*c;
   sort(answers,answers+6);
   cout<<answers[5]<<endl;
   return 0;
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int main()
{
   int answers[6];
   int a,b,c;
   cin>>a>>b>>c;

   answers[0]=a+b+c;
   answers[1]=a*b*c;
   answers[2]=a*b+c;
   answers[3]=a+b*c;
   answers[4]=a*(b+c);
   answers[5]=(a+b)*c;
   sort(answers,answers+6);
   cout<<answers[5]<<endl;
   return 0;
}


#include<iostream>
using namespace std;
int a[1000], b[1001];
int main()
{
	int n, m,x=0,l,r,y=0;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		x += a[i];
	}
	cin >> m;
	for (int i = 0; i < m; i++)
	{
		cin >> l >> r;
		if (x >= l&&x <= r)
			y = 1;
	}
	if (y == 0)
		cout << "-1" << endl;
	else
		cout << x << endl;
	return 0;
}


#include<iostream>
using namespace std;
int a[1000];
int main()
{
	int n, m,x=0,l,r,y=0,k;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		k = 0;
		if (i == 0)
		{
			x = a[0];
			continue;
		}
		for (int j = i - 1; j >= 0; j--)
			if (a[i] == a[j])
			{
				k = 1;
				continue;
			}
			x += a[i];
	}
	cin >> m;
	if (m == 0)
	{
		cout << "-1" << endl;
		return 0;
	}
	else
	{
		for (int i = 1; i < m; i++)
		{
			cin >> l >> r;
			if (x >= l&&x <= r)
				y = 1;
		}
		if (y == 0)
			cout << "-1" << endl;
		else
			cout << x << endl;
	}
	return 0;
}


#include<iostream>
using namespace std;
int a[1000];
struct c{
	int l, r;
};
c b[1001];
int main()
{
	int n, m, x, k, y = 0;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		k = 0;
		if (i == 0)
		{
			x = a[0];
			continue;
		}
		for (int j = i - 1; j >= 0; j--)
			if (a[i] == a[j])
			{
				k = 1;
				break;
			}
		if (k == 0)
			x += a[i];
	}
	cin >> m;
	if (m == 0)
	{
		cout << "-1" << endl;
		return 0;
	}
	for (int i = 1; i <= m; i++)
		cin >> b[i].l >> b[i].r;
	for (int i = 1; i <= m; i++)
	{
		if (x >= b[i].l&&x <= b[i].r)
		{
			cout << x << endl;
			return 0;
		}
		if (x <= b[i].l&&x<=b[i].r)
		{
			cout << b[i].l << endl;
			return 0;
		}
	}
	cout << "-1" << endl;
	return 0;
}


#include<iostream>
using namespace std;
int a[1000];
int main()
{
	int n, m, x,k,l,r;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		k = 0;
		if (i == 0)
		{
			x = a[0];
			continue;
		}
		for (int j = i - 1; j >= 0; j--)
			if (a[i] == a[j])
			{
				k = 1;
				break;
			}
		if (k == 0)
			x += a[i];
	}
	cin >> m;
	if (m == 0)
	{
		cout << "-1" << endl;
		return 0;
	}
	for (int i = 1; i <= m; i++)
		cin >> l >> r;
	for (int i = 1; i <= m; i++)
	{
		if (x >= l&&x <= r)
		{
		    cout<<x<<endl;
		    return 0;
		}
		if (l > x)
		{
		    cout<<l<<endl;
		    return 0;
		}
	}
		cout << "-1" << endl;
	return 0;
}


#include<iostream>
using namespace std;
int a[1000];
struct c{
	int l, r;
};
c b[1001];
int main()
{
	int n, m, x,k,y=0;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		k = 0;
		if (i == 0)
		{
			x = a[0];
			continue;
		}
		for (int j = i - 1; j >= 0; j--)
			if (a[i] == a[j])
			{
				k = 1;
				break;
			}
		if (k == 0)
			x += a[i];
	}
	cin >> m;
	if (m == 0)
	{
		cout << "-1" << endl;
		return 0;
	}
	for (int i = 1; i <= m; i++)
		cin >> b[i].l >> b[i].r;
	for (int i = 1; i <= m; i++)
	{
		if (i == m)
		{
			if (x >= b[i].l&&x <= b[i].r)
				y = 1;
		}
		else
			if ((x >= b[i].l&&x <= b[i].r)|| ( b[i + 1].l>=x))
			y = 1;
	}

	if (y == 0)
		cout << "-1" << endl;
	else
		cout << x << endl;
	return 0;
}


#include<iostream>
using namespace std;
int a[1000];
struct c{
	int l, r;
};
c b[1001];
int main()
{
	int n, m, x, k, y = 0;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		k = 0;
		if (i == 0)
		{
			x = a[0];
			continue;
		}
		for (int j = i - 1; j >= 0; j--)
			if (a[i] == a[j])
			{
				k = 1;
				break;
			}
		if (k == 0)
			x += a[i];
	}
	cin >> m;
	if (m == 0)
	{
		cout << "-1" << endl;
		return 0;
	}
	for (int i = 1; i <= m; i++)
		cin >> b[i].l >> b[i].r;
	for (int i = 1; i <= m; i++)
	{
		if (i == m)
		{
			if (x >= b[i].l&&x <= b[i].r)
			{
				cout << x << endl;
				return 0;
			}
		}
		else
			if (x >= b[i].l&&x <= b[i].r)
			{
				cout << x << endl;
				return 0;
			}
			else if (b[i + 1].l >= x)
			{
				cout << b[i + 1].l << endl;
				return 0;
			}
	}
	cout << "-1" << endl;
	return 0;
}


#include<iostream>
using namespace std;
int a[1000];
int main()
{
	int n, m,x=0,l,r,y=0,k;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		k = 0;
		if (i == 0)
		{
			x = a[0];
			continue;
		}
		for (int j = i - 1; j >= 0; j--)
			if (a[i] == a[j])
			{
				k = 1;
				continue;
			}
			x += a[i];
	}
	cin >> m;
	if (m == 0)
	{
		cout << "-1" << endl;
		return 0;
	}
	else
	{
		for (int i = 1; i <=m; i++)
		{
			cin >> l >> r;
			if (x >= l&&x <= r)
				y = 1;
		}
		if (y == 0)
			cout << "-1" << endl;
		else
			cout << x << endl;
	}
	return 0;
}


#include<iostream>
using namespace std;
int a[1000];
struct c{
	int l, r;
};
c b[1001];
int main()
{
	int n, m, x=0;
	cin >> n;
	for (int i = 0; i < n; i++)
          {
          	cin>>a[i];
          	x+=a[i];
          }
	cin >> m;
	if (m == 0)
	{
		cout << "-1" << endl;
		return 0;
	}
	for (int i = 1; i <= m; i++)
		cin >> b[i].l >> b[i].r;
	for (int i = 1; i <= m; i++)
	{
		if (x >= b[i].l&&x <= b[i].r)
		{
			cout << x << endl;
			return 0;
		}
		if (x <= b[i].l&&x<=b[i].r)
		{
			cout << b[i].l << endl;
			return 0;
		}
	}
	cout << "-1" << endl;
	return 0;
}


#include<bits/stdc++.h>

using namespace std;
int main()
{
    int n, i, m, j, h=0, min_h = 0, sum = 0;
    cin >> n;
    int a[n], p1[1000], p2[1000];
    for(i=0; i<n; i++) {
        cin >> a[i];
        h = h+a[i];
    }
    cin >> m;
    for(j=0; j<m; j++) {
        cin >> p1[j] >> p2[j];
        sum += p2[j] - p1[j] +1;
    }
    if(sum < h)
        cout << "-1\n";
    else {
        for(j=0; j<m; j++) {
            if(h >= p1[j] && h <= p2[j]) {
                min_h = h;
                break;
            }
        }
        if(min_h == 0)
            min_h = p1[m-1];
        cout << min_h << endl;
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;
int main()
{
    int n, i, m, j, h=0, min_h = 0, sum = 0;
    cin >> n;
    int a[n], p1[1000], p2[1000];
    for(i=0; i<n; i++) {
        cin >> a[i];
        h = h+a[i];
    }
    cin >> m;
    for(j=0; j<m; j++) {
        cin >> p1[j] >> p2[j];
        sum += p2[j] - p1[j] +1;
    }
    if(sum < h)
        cout << "-1\n";
    else {
        for(j=0; j<m; j++) {
            if(h >= p1[j] && h <= p2[j]) {
                min_h = h;
                break;
            }
        }
        if(min_h == 0) {
            for(i=0; i<m; i++) {
                if(p1[i] > h) {
                    min_h = p1[i];
                    break;
                }
            }
        }
        cout << min_h << endl;
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;
int main()
{
    long long n, s = 0, x, y, ans = -1;
    cin >> n;
    while(n--) {
        cin >> x;
        s += x;
    }
    cin >> n;
    while(n--) {
        cin >> x >> y;
        if(s >= x && s <= y) {
            ans = s;
            s = INT_MAX;
        }
        else if(s < x)
            ans = x;
    }
    cout << ans << endl;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;
int main()
{
    long long n, s = 0, x, y, ans = -1;
    cin >> n;
    while(n--) {
        cin >> x;
        s += x;
    }
    //cout << s << endl;
    cin >> n;
    while(n--) {
        cin >> x >> y;
        if(s >= x && s <= y) {
            ans = s;
            s = LONG_LONG_MAX;
        }
        else if(s < x) {
            ans = x;
            s = LONG_LONG_MAX;
        }
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int a[1000],x[1000],y[1000];
    int n,m,kol=0;
    int sum = 0;
    cin>> n;
    int pol = n;
    for(int i = 0;i < n;i++)
        cin>> a[i];
    cin>> m;
    for(int i = 0;i < m;i++)
        cin>> x[i] >> y[i];
    for(int i = 0;i < m;i++)
    {
        for(int j = 0;j < n;j++)
        {
            if(a[j]>0)
            if(sum + a[j]<=y[i]){sum+=a[j];kol+=1;a[j]=0;}
        }
        if (sum >= x[i]&&sum <= y[i])pol -=kol;
            kol=0;
    }
    if(pol == 0)cout<< sum;
    else cout<<-1;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int a[1000],x[1000],y[1000];
    int n,m,kol=0;
    int sum = 0;
    cin>> n;
    int pol = n;
    for(int i = 0;i < n;i++)
        cin>> a[i];
    cin>> m;
    for(int i = 0;i < m;i++)
        cin>> x[i] >> y[i];
        for(int i = 0;i < n;i++)
            sum+=a[i];
        for(int i = 0;i < m;i++)
            if(sum >=x[i]&&sum<=y[i])kol++;
    if(kol>0)cout<< sum;
    else cout<<-1;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    long long a[1000],x[1000],y[1000];
    long long n,m,kol=0;
    long long sum = 0;
    cin>> n;
    int pol = n;
    for(int i = 0;i < n;i++)
        cin>> a[i];
    cin>> m;
    for(int i = 0;i < m;i++)
        cin>> x[i] >> y[i];
    for(int i = 0;i < m;i++)
    {
        for(int j = 0;j < n;j++)
        {
            if(a[j]>0)
            if((sum + a[j])<=y[i]){sum+=a[j];kol+=1;a[j]=0;}
        }
        if ((sum >= x[i])&&(sum <= y[i]))pol -=kol;
            kol=0;
    }
    if(pol == 0)cout<< sum;
    else cout<<-1;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int a[1000],x[1000],y[1000];
    int n,m,kol=0;
    int sum = 0;
    cin>> n;
    int pol = n;
    for(int i = 0;i < n;i++)
        cin>> a[i];
    cin>> m;
    for(int i = 0;i < m;i++)
        cin>> x[i] >> y[i];
    for(int i = 0;i < m;i++)
    {
        for(int j = 0;j < n;j++)
        {
            if(sum + a[j]<=y[i])if(a[j]>0){sum+=a[j];kol+=1;a[j]=0;}
        }
        if (sum >= x[i]&&sum <= y[i])pol -=kol;
            kol=0;
    }
    if(pol = 0)cout<< sum;
    else cout<<-1;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int a[1000],x[1000],y[1000];
    int n,m,kol=0;
    int sum = 0,maxi=1000000000;
    cin>> n;
    int pol = n;
    for(int i = 0;i < n;i++)
        cin>> a[i];
        cin>> m;
    for(int i = 0;i < m;i++)
        cin>> x[i] >> y[i];
        for(int i = 0;i < n;i++)
            sum+=a[i];
        for(int i = 0;i < m;i++)
        {
            if((sum >=x[i])&&(sum<=y[i]))kol++;
            else if (x[i]>=sum&&x[i]<maxi)maxi=x[i];
        }
    if(kol>0)cout<< sum;
    else if(maxi!=1000000000)cout<<maxi;
    else cout<<-1;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int a[1000],x[1000],y[1000];
    int n,m,kol=0;
    int sum = 0;
    cin>> n;
    int pol = n;
    for(int i = 0;i < n;i++)
        cin>> a[i];
    cin>> m;
    for(int i = 0;i < m;i++)
        cin>> x[i] >> y[i];
    for(int i = 0;i < m;i++)
    {
        for(int j = 0;j < n;j++)
        {
            if(sum + a[j]<=y[i])if(a[j]>0){sum+=a[j];kol+=1;a[j]=0;}
        }
        if (sum >= x[i]&&sum <= y[i])pol -=kol;
            kol=0;
    }
    if(pol == 0)cout<< sum;
    else cout<<-1;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int a[1000],x[1000],y[1000];
    int n,m,kol=0;
    int sum = 0;
    cin>> n;
    int pol = n;
    for(int i = 0;i < n;i++)
        cin>> a[i];
        cin>> m;
    for(int i = 0;i < m;i++)
        cin>> x[i] >> y[i];
        for(int i = 0;i < n;i++)
            sum+=a[i];
        for(int i = 0;i < m;i++)
            if((sum >=x[i])&&(sum<=y[i]))kol++;
    if(kol>0)cout<< sum;
    else cout<<-1;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int a[1000],x[1000],y[1000];
    int n,m,kol=0;
    int sum = 0;
    cin>> n;
    int pol = n;
    for(int i = 0;i < n;i++)
        cin>> a[i];
        cin>> m;
    for(int i = 0;i < m;i++)
        cin>> x[i] >> y[i];
        for(int i = 0;i < n;i++)
            sum+=a[i];
        for(int i = 0;i < m;i++)
        {
            if((sum >=x[i])&&(sum<=y[i]))kol++;
            else if (x[i]>=sum)kol++;
        }
    if(kol>0)cout<< sum;
    else cout<<-1;
    return 0;
}


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

int main()
{
	int a,b,c,d,e;
	long butuh,hasil;
	int waktu1[1001],waktu2[1001];
	cin>>b;
	butuh=0;
	for(a=1;a<=b;a++)
	{
		cin>>c;
		butuh=butuh+c;
	}
	cin>>d;
	for(a=1;a<=d;a++)
	{
		cin>>waktu1[a];
		cin>>waktu2[a];
		if((butuh>=waktu1[a])&&(butuh<=waktu2[a]))
		{
			hasil=butuh;
		}
		else
		hasil=-1;
	}
	cout<<hasil<<endl;
}


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

int main()
{
	int a,b,c,d,e;
	long butuh,hasil;
	long waktu1[1001],waktu2[1001];
	cin>>b;
	butuh=0;
	for(a=1;a<=b;a++)
	{
		cin>>c;
		butuh=butuh+c;
	}
	cin>>d;
	for(a=1;a<=d;a++)
	{
		cin>>waktu1[a];
		cin>>waktu2[a];
		if((butuh>=waktu1[a])&&(butuh<=waktu2[a]))
		{
			hasil=butuh;
			break;
		}
		else
		hasil=-1;
	}
	cout<<hasil<<endl;
}


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

int main()
{
	int a,b,c,d,e;
	long butuh,hasil;
	long waktu1,waktu2;
	cin>>b;
	butuh=0;
	for(a=1;a<=b;a++)
	{
		cin>>c;
		butuh=butuh+c;
	}
	cin>>d;
	for(a=1;a<=d;a++)
	{
		cin>>waktu1;
		cin>>waktu2;
		if((butuh>=waktu1)&&(butuh<=waktu2))
		{
			hasil=butuh;
			break;
		}
		else
		hasil=-1;
	}
	cout<<hasil<<endl;
}


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

int main()
{
	int a,b,c,d,e,butuh,hasil;
	int waktu1[1001],waktu2[1001];
	cin>>b;
	butuh=0;
	for(a=1;a<=b;a++)
	{
		cin>>c;
		butuh=butuh+c;
	}
	cin>>d;
	for(a=1;a<=d;a++)
	{
		cin>>waktu1[a];
		cin>>waktu2[a];
		if((butuh>=waktu1[a])&&(butuh<=waktu2[a]))
		{
			hasil=butuh;
			break;
		}
		else
		hasil=-1;
	}
	cout<<hasil<<endl;
}


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

int main()
{
	long a,b,c,d,e;
	long butuh,hasil;
	long waktu1,waktu2;
	cin>>b;
	butuh=0;
	for(a=1;a<=b;a++)
	{
		cin>>c;
		butuh=butuh+c;
	}
	cin>>d;
	for(a=1;a<=d;a++)
	{
		cin>>waktu1;
		cin>>waktu2;
		if((butuh>=waktu1)&&(butuh<=waktu2))
		{
			hasil=butuh;
			break;
		}
		else
		hasil=-1;
	}
	cout<<hasil<<endl;
}


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

int main()
{
	long a,b,c,d,e;
	long butuh,hasil;
	long waktu1,waktu2;
	cin>>b;
	butuh=0;
	e=2000000000;
	for(a=1;a<=b;a++)
	{
		cin>>c;
		butuh=butuh+c;
	}
	cin>>d;
	//cout<<butuh<<endl;
	for(a=1;a<=d;a++)
	{
		cin>>waktu1;
		cin>>waktu2;
		if((waktu1<=butuh)&&(butuh<=waktu2))
		{
			hasil=butuh;
			break;
		}
		if((butuh<waktu1)&&(e>waktu1))
		{
		hasil=waktu1;
		e=waktu1;
		}
		if(butuh>waktu2)
		hasil=-1;
	}
	if(d==0)
	hasil=-1;
	cout<<hasil<<endl;
}


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

int main()
{
	long a,b,c,d,e;
	long butuh,hasil;
	long waktu1,waktu2;
	cin>>b;
	butuh=0;
	for(a=1;a<=b;a++)
	{
		cin>>c;
		butuh=butuh+c;
	}
	cin>>d;
	cout<<butuh<<endl;
	for(a=1;a<=d;a++)
	{
		cin>>waktu1;
		cin>>waktu2;
		if((waktu1<=butuh)&&(butuh<=waktu2))
		{
			hasil=butuh;
			break;
		}
		else
		hasil=-1;
	}
	if(butuh<waktu1)
	hasil=butuh;
	cout<<hasil<<endl;
}


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

int main()
{
	int a,b,c,d,e,butuh,hasil;
	int waktu1[1001],waktu2[1001];
	cin>>b;
	butuh=0;
	for(a=1;a<=b;a++)
	{
		cin>>c;
		butuh=butuh+c;
	}
	cin>>d;
	for(a=1;a<=d;a++)
	{
		cin>>waktu1[a];
		cin>>waktu2[a];
		if((butuh>=waktu1[a])||(butuh<=waktu2[a]))
		{
			hasil=butuh;
			break;
		}
		else
		hasil=-1;
	}
	cout<<hasil<<endl;
}


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

int main()
{
	long a,b,c,d,e;
	long butuh,hasil;
	long waktu1,waktu2;
	cin>>b;
	butuh=0;
	e=2000000000;
	for(a=1;a<=b;a++)
	{
		cin>>c;
		butuh=butuh+c;
	}
	cin>>d;
	//cout<<butuh<<endl;
	for(a=1;a<=d;a++)
	{
		cin>>waktu1;
		cin>>waktu2;
		if((waktu1<=butuh)&&(butuh<=waktu2))
		{
			hasil=butuh;
			break;
		}
		if((butuh<waktu1)&&(e>waktu1))
		{
		hasil=waktu1;
		e=waktu1;
		}
		if(butuh>waktu2)
		hasil=-1;
	}

	cout<<hasil<<endl;
}


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

int main()
{
	int a,b,c,d,e;
	long butuh,hasil;
	int waktu1[1001],waktu2[1001];
	cin>>b;
	butuh=0;
	for(a=1;a<=b;a++)
	{
		cin>>c;
		butuh=butuh+c;
	}
	cin>>d;
	for(a=1;a<=d;a++)
	{
		cin>>waktu1[a];
		cin>>waktu2[a];
		if((butuh>=waktu1[a])&&(butuh<=waktu2[a]))
		{
			hasil=butuh;
			break;
		}
		else
		hasil=-1;
	}
	cout<<hasil<<endl;
}


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

int main()
{
	long a,b,c,d,e;
	long butuh,hasil;
	long waktu1,waktu2;
	cin>>b;
	butuh=0;
	for(a=1;a<=b;a++)
	{
		cin>>c;
		butuh=butuh+c;
	}
	cin>>d;
	cout<<butuh<<endl;
	for(a=1;a<=d;a++)
	{
		cin>>waktu1;
		cin>>waktu2;
		if((waktu1<=butuh)&&(butuh<=waktu2))
		{
			hasil=butuh;
			break;
		}
		else
		{
		hasil=-1;
		if(butuh<waktu1)
		hasil=waktu1;
		}
	}
	cout<<hasil<<endl;
}


//Wrong answer on test 7
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1005;
int a[N];
struct time
{
	int l, r;
	int ifisin(LL n)
	{
		if (n >= l && n <= r) return 1;
		return 0;
	}
	int ifbefore(LL n)
	{
		return (n < l)?1:0;
	}
/*	bool operator < (const  time& b) const
	{
		return r < b.r ;
	}*/
}t[N];
bool mycmp(int a, int b)
{
	return a > b?1:0;
}
int main()
{
	int n, m;
	while (cin >> n)
	{
		LL sumdo = 0;
		for (int i = 0; i < n; i++)
		cin >> a[i], sumdo += a[i];
		cin >> m;
		for (int i = 0; i < m; i++)
			cin >> t[i].l >> t[i].r;

		if (sumdo > t[m-1].r)
		{
			cout << -1 << endl; continue;
		}
	//	sort(a,a+n,mycmp);
	//	cout << "test: " << endl; for (int i = 0; i < n; i++) cout << a[i] << endl;
	//	sort(t,t+m);
	//	cout << "test: " << endl; for (int i = 0; i < m; i++) cout << t[i].l << " " << t[i].r << endl;

		int flag = 1;
		for (int i = 0; i < m; i++)
		{
			if (t[i].ifisin(sumdo))
			{
				flag = 0;
				cout << sumdo << endl;
				break;
			}
		/*	else if (t[i].ifbefore(n))
			{
				flag = 0;
				cout << t[i].l << endl;
				break;
			}*/
		}
		if (flag) cout << -1 << endl;

	}
	return 0;
}


//Wrong answer on test 5
#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int a[N];
struct time
{
	int l, r;
	int ifisin(int n)
	{
		if (n >= l && n <= r) return 1;
		return 0;
	}
	int ifbefore(int n)
	{
		return (n < l)?1:0;
	}
/*	bool operator < (const  time& b) const
	{
		return r < b.r ;
	}*/
}t[N];
bool mycmp(int a, int b)
{
	return a > b?1:0;
}
int main()
{
	int n, m;
	while (cin >> n)
	{
		int sum = 0, sumdo = 0, cnt = 0, done = 0;
		for (int i = 0; i < n; i++)
		cin >> a[i], sumdo += a[i];
		cin >> m;
		for (int i = 0; i < m; i++)
			cin >> t[i].l >> t[i].r;

		if (sumdo > t[m-1].r)
		{
			cout << -1 << endl; continue;
		}
	//	sort(a,a+n,mycmp);
	//	cout << "test: " << endl; for (int i = 0; i < n; i++) cout << a[i] << endl;
	//	sort(t,t+m);
	//	cout << "test: " << endl; for (int i = 0; i < m; i++) cout << t[i].l << " " << t[i].r << endl;

		int flag = 1;
		for (int i = 0; i < m; i++)
		{
			if (t[i].ifisin(sumdo))
			{
				flag = 0;
				cout << sumdo << endl;
				break;
			}
			else if (t[i].ifbefore(n))
			{
				flag = 0;
				cout << t[i].l << endl;
				break;
			}
		}
		if (flag) cout << -1 << endl;

	}
	return 0;
}


//Wrong answer on test 5
#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int a[N];
struct time
{
	int l, r;
	int ifisin(int n)
	{
		if (n >= l && n <= r) return 1;
		return 0;
	}
	int ifbefore(int n)
	{
		return (n < l)?1:0;
	}
/*	bool operator < (const  time& b) const
	{
		return r < b.r ;
	}*/
}t[N];
/*bool mycmp(int a, int b)
{
	return a > b?1:0;
}*/
int main()
{
	int n, m;
	while (cin >> n)
	{
		int sum = 0, sumdo = 0, cnt = 0, done = 0;
		for (int i = 0; i < n; i++)
		cin >> a[i], sumdo += a[i];
		cin >> m;
		for (int i = 0; i < m; i++)
			cin >> t[i].l >> t[i].r;

		if (sumdo > t[m-1].r)
		{
			cout << -1 << endl; continue;
		}
	//	sort(a,a+n,mycmp);
	//	cout << "test: " << endl; for (int i = 0; i < n; i++) cout << a[i] << endl;
	//	sort(t,t+m);
	//	cout << "test: " << endl; for (int i = 0; i < m; i++) cout << t[i].l << " " << t[i].r << endl;

		int flag = 1;
		for (int i = 0; i < m; i++)
		{
			if (t[i].ifisin(sumdo))
			{
				flag = 0;
				cout << sumdo << endl;
				break;
			}
			else if (t[i].ifbefore(sumdo))
			{
				flag = 0;
				cout << t[i].l << endl;
				break;
			}
		}
		if (flag) cout << -1 << endl;

	}
	return 0;
}


#include<iostream>
#include<cstdlib>
#include<cstring>
using namespace std;

int main() {
    int n, sumn = 0, res = 0;
    cin>>n;
    int a[n];
    for(int i = 0; i < n; i++){
        cin>>a[i];
        sumn += a[i];
    }
    int m;
    cin>>m;
    int l[m][2];
    for(int i = 0; i < m; i++){
        for(int j = 0; j < 2; j++){
            cin>>l[i][j];
            if(sumn == l[i][j]){
                res = l[i][j];
            }
        }
    }
    if(res != 0){
        cout<<res;
    }
    else{
        for(int i = 0; i < m; i++){
            for(int j = 0; j < 2; j++){
                if(sumn < l[i][j]){
                    res = l[i][j];
                    i = m;
                    break;
                }
            }
        }
        cout<<res;
    }
    return 0;
}


#include<iostream>
#include<cstdlib>
#include<cstring>
using namespace std;

int main() {
    int n, sumn = 0, res = 0;
    cin>>n;
    int a[n];
    for(int i = 0; i < n; i++){
        cin>>a[i];
        sumn += a[i];
    }
    int m;
    cin>>m;
    int l[m][2];
    for(int i = 0; i < m; i++){
        for(int j = 0; j < 2; j++){
            cin>>l[i][j];
            if(sumn == l[i][j]){
                res = l[i][j];
            }
        }
    }
    if(res != 0){
        cout<<res;
    }
    else{
        for(int i = 0; i < m; i++){
            for(int j = 0; j < 2; j++){
                if(sumn < l[i][j]){
                    res = l[i][j];
                    i = m;
                    break;
                }
                else{
                    res = -1;
                }
            }
        }
        cout<<res;
    }
    return 0;
}


#include<iostream>
#include<cstdlib>
#include<cstring>
using namespace std;

int main() {
    int n, sumn = 0, res = 0;
    cin>>n;
    int a[n];
    for(int i = 0; i < n; i++){
        cin>>a[i];
        sumn += a[i];
    }
    int m;
    cin>>m;
    if(m == 0){
    	cout<<-1;
    	return 0;
	}
    int l[m][2];
    int flag = 0;
    for(int i = 0; i < m; i++){
        for(int j = 0; j < 2; j++){
            cin>>l[i][j];
            if(j == 1 && flag == 0){
                if(sumn <= l[i][j]){
                    res = max(sumn, l[i][0]);
                    flag = 1;
                }
            }

        }
    }
    if(flag == 1)
        cout<<res;
    else
        cout<<-1;
    return 0;
}


#include<iostream>
#include<cstdlib>
#include<cstring>
using namespace std;

int main() {
    int n, sumn = 0, res = 0;
    cin>>n;
    int a[n];
    for(int i = 0; i < n; i++){
        cin>>a[i];
        sumn += a[i];
    }
    int m;
    cin>>m;
    if(m == 0){
    	cout<<-1;
    	return 0;
	}
    int l[m][2];
    for(int i = 0; i < m; i++){
        for(int j = 0; j < 2; j++){
            cin>>l[i][j];
            if(sumn <= l[i][j]){
                res = sumn;
            }
        }
    }
    if(res != 0){
        cout<<res;
    }
    else{
    	cout<<-1;
	}
    return 0;
}


#include<iostream>
#include<cstdlib>
#include<cstring>
using namespace std;

int main() {
    int n, sumn = 0, res = 0;
    cin>>n;
    int a[n];
    for(int i = 0; i < n; i++){
        cin>>a[i];
        sumn += a[i];
    }
    int m;
    cin>>m;
    if(m == 0){
    	cout<<-1;
    	return 0;
	}
    int l[m][2];
    int flag = 0;
    for(int i = 0; i < m; i++){
        for(int j = 0; j < 2; j++){
            cin>>l[i][j];
            if(j == 1 && flag == 0){
                if(sumn <= l[i][j]){
                    res = max(sumn, l[i][0];
                    flag = 1;
                }
            }

        }
    }
    if(flag == 1)
        cout<<res;
    else
        cout<<-1;
    return 0;
}


#include<iostream>
#include<cstdlib>
#include<cstring>
using namespace std;

int main() {
    int n, sumn = 0, res = 0;
    cin>>n;
    int a[n];
    for(int i = 0; i < n; i++){
        cin>>a[i];
        sumn += a[i];
    }
    int m;
    cin>>m;
    if(m == 0){
    	cout<<-1;
    	return 0;
	}
    int l[m][2];
    for(int i = 0; i < m; i++){
        for(int j = 0; j < 2; j++){
            cin>>l[i][j];
            if(sumn == l[i][j]){
                res = l[i][j];
            }
        }
    }
    if(res != 0){
        cout<<res;
    }
    else{
        for(int i = 0; i < m; i++){
            for(int j = 0; j < 2; j++){
                if(sumn < l[i][j]){
                    res = l[i][j];
                    i = m;
                    break;
                }
                else{
                	res = -1;
				}
            }
        }
        cout<<res;
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
	int n,m,l,r,i=0,sum=0;
	cin>>n;
	int a[n];

	while(i!=n){
		cin>>a[i];
		sum = sum+a[i];
		i++;
	}

	cin>>m;
	i=0;
	int ans=0;
	while(i!=m){
		cin>>l;
		if(sum <= l && sum >= r){
			ans = l;
		}
		cin>>r;
		if(sum>=l && sum <=r){
			ans = sum;
		}

		if(i == m-1 && sum > r){
			ans = -1;
		}
		i++;
	}

	if(m==0){
		ans = -1;
	}
	cout<<ans<<endl;
	return 0;
}


#include <iostream>

using namespace std;

int main()
{
	int n,m,l,r,i=0,sum=0;
	cin>>n;
	int a[n];

	while(i!=n){
		cin>>a[i];
		sum = sum+a[i];
		i++;
	}

	cin>>m;
	i=0;
	int ans=-1;
	while(i!=m){
		cin>>l>>r;
		if(sum >= l && sum >= r && ans == -1){
			ans = l;
		}
		if(sum>=l && sum <=r){
			ans = sum;
		}

		i++;
	}

	cout<<ans<<endl;
	return 0;
}


#include<iostream>

using namespace std;

int main()
{
	int n,m,l,r,i=0,sum=0;
	cin>>n;
	int a[n];

	while(i!=n){
		cin>>a[i];
		sum = sum+a[i];
		i++;
	}

	cin>>m;
	i=0;
	int ans=-1;
	while(i!=m){
		cin>>l>>r;
		if(sum <= l && sum <= r && ans == -1){
			ans = l;
		}
		if(sum>=l && sum <=r){
			ans = sum;
		}

		i++;
	}

	cout<<ans<<endl;
	return 0;
}


#include <iostream>

using namespace std;

int main()
{
	int n,m,l,r,i=0,sum=0;
	cin>>n;
	int a[n];

	while(i!=n){
		cin>>a[i];
		sum = sum+a[i];
		i++;
	}

	cin>>m;
	i=0;
	int ans=0;
	while(i!=m){
		cin>>l;
		if(sum <= l && sum >= r){
			ans = l;
		}
		cin>>r;
		if(sum>=l && sum <=r){
			ans = sum;
		}

		if(i == m-1 && sum > r){
			ans = -1;
		}
		i++;
	}

	cout<<ans<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long n,m,a,s=0;
  cin>>n;
  for(int i=0;i<n;i++)
  {
    cin>>a;
    s+=a;
  }
  cin>>m;
  long long l,r,ans=-1;
  for(int i=1;i<=m;i++)
  {
    cin>>l>>r;
    if(s>=l && s<=r)
    {
      ans=min(s,r);
    }

  }
  cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,m,a,s=0;
  cin>>n;
  for(int i=0;i<n;i++)
  {
    cin>>a;
    s+=a;
  }
  cin>>m;
  int l,r,ans=-1,flag=0;
  for(int i=1;i<=m;i++)
  {
    cin>>l>>r;
    if(s>=l && s<=r && flag==0)
    {
      ans=min(s,r);
      flag=1;
    }

  }
  cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,m,a,s=0;
  cin>>n;
  for(int i=0;i<n;i++)
  {
    cin>>a;
    s+=a;
  }
  cin>>m;
  int l,r,ans=-1,flag=0;
  for(int i=1;i<=m;i++)
  {
    cin>>l>>r;
    if(s==l && flag==0)
    {
      ans=s;
      flag=1;
    }
     if(s<l && s<=r && flag==0)
    {
      ans=l;
      flag=1;
    }
     if(s>l && s<=r && flag==0)
    {
      ans=min(s,r);
      flag=1;
    }

  }
  cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,m,a,s=0;
  cin>>n;
  for(int i=0;i<n;i++)
  {
    cin>>a;
    s+=a;
  }
  cin>>m;
  int l,r,ans=-1;
  for(int i=1;i<=m;i++)
  {
    cin>>l>>r;
    if(s>=l && s<=r)
    {
      ans=min(s,r);
    }

  }
  cout<<ans<<endl;
}


#include<cstdio>
using namespace std;
int n,m;
int a[100005],l[100005],r[100005];
main()
{
	int t=0;
	bool flag=0;
	scanf("%d",&n);
	for (int i=1;i<=n;++i) scanf("%d",a+i),t+=a[i];
	scanf("%d",&m);
	++t;
	for (int i=1;i<=m;++i)
	{
		scanf("%d%d",l+i,r+i);
		if (l[i]<=t&&t<=r[i]) flag=1;
	}
	printf("%d\n",flag?t:-1);
}


#include<cstdio>
using namespace std;
int n,m;
int a[100005],l[100005],r[100005];
main()
{
	int t=0;
	bool flag=0;
	scanf("%d",&n);
	for (int i=1;i<=n;++i) scanf("%d",a+i),t+=a[i];
	scanf("%d",&m);
	++t;
	for (int i=1;i<=m;++i)
	{
		scanf("%d%d",l+i,r+i);
		if (l[i]<=t&&t<=r[i]) flag=1;
	}
	printf("%d\n",flag?t-1:-1);
}


#include<cstdio>
using namespace std;
int n,m;
int a[100005],l[100005],r[100005];
main()
{
	int t=0;
	bool flag=0;
	scanf("%d",&n);
	for (int i=1;i<=n;++i) scanf("%d",a+i),t+=a[i];
	scanf("%d",&m);
	for (int i=1;i<=m;++i)
	{
		scanf("%d%d",l+i,r+i);
		if (l[i]<=t&&t<=r[i]) flag=1;
	}
	printf("%d\n",flag?t:-1);
}


#include<cstdio>
#include<iostream>
using namespace std;
int n,m;
int a[100005],l[100005],r[100005];
main()
{
	int t=0;
	bool flag=0;
	scanf("%d",&n);
	for (int i=1;i<=n;++i) scanf("%d",a+i),t+=a[i];
	scanf("%d",&m);
	for (int i=1;i<=m;++i)
	{
		scanf("%d%d",l+i,r+i);
		if (t>r[i]);
		else {flag=1;t=max(t,l[i]);break;}
	}
	printf("%d\n",flag?t:-1);
}


#include<stdio.h>
long long a[1002];
long long b[1002];
int main()
{
    long long n;
    long long l,r;
    scanf("%I64d",&n);
    long long need = 0;
    for(int i = 1;i<=n;i++)
    {
        scanf("%I64d",&a[i]);
         need += a[i];
    }
    long long k;
    scanf("%I64d",&k);
    long long flag = 0;
    long long in=0;
    for(int i = 1;i<=k ;i++)
    {

        scanf("%I64d %I64d",&l,&r);
        if((l >= need&&flag==0)||(r>=need&&l<need&&flag==0) )
        {
            flag = 1;
            if(l>=need)
            {
               in = l;
            }
            else
            {
                in = need;
            }
        }
    }
    if(flag == 1)
        printf("%I64d\n",in);
    if(flag == 0)
    {
        printf("-1\n");
    }
    return 0;

}
/*2018-07-24 20:58:14.165*/


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct node
{
    int l;
    int r;
}t[1009];
bool cmp(node a,node b)
{
    return a.l<b.l;
}
int main()
{
    int n,m;
    int i,j,k;
    int a[1009];
    while(~scanf("%d",&n))
    {
        int sum=0;
        for(i=1;i<=n;i++)
            scanf("%d",&a[i]),sum+=a[i];
        scanf("%d",&m);
        for(i=1;i<=m;i++)
            scanf("%d%d",&t[i].l,&t[i].r);
        sort(t+1,t+m+1,cmp);
        int ans=-1;
        for(i=1;i<=m;i++)
        {
            if(t[i].l==sum)
                ans=sum;
            else if(t[i].r>=sum)
                ans=sum;
        }
        printf("%d\n",ans);
    }
    return 0;
}
/*2018-07-24 19:58:08.261*/


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

        if(sum > l[i])
        {
            printf("%d\n",sum);
            return 0;
        }
        else
        {
            printf("%d\n",l[i]);
            return 0;
        }
    }
    return 0;
}
/*2018-07-24 19:56:46.19*/


#include<cstdio>
#include<queue>
#include<algorithm>
#include<string.h>
using namespace std;
int main()
{
    int n,m,a[5000];
    int t1[5000],t2[5000];
    scanf("%d",&n);
    int sum=0;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    scanf("%d",&m);
    for(int i=0;i<m;i++)
    {
        scanf("%d%d",&t1[i],&t2[i]);

    }
        int j;
        int flag=1;
        for( j=0;j<m;j++)
        {
            if(sum<=t2[j])
            {
                if(sum>=t1[j])
                    printf("%d\n",sum);
                else
                printf("%d\n",t1[j]);
                return 0;
            }

        }
        if(flag==1)
            printf("-1\n");

    return 0;
}/*2018-08-16 11:51:41.638*/


#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const int MAXR = 1e5 + 5;

int main() {
    ios::sync_with_stdio(false);
    ll n, m, i, l, r, a;
    ll minl = INF, maxr = -1;
    ll sum = 0;
    cin >> n;
    for(i = 0; i < n; i++) {
        cin >> a;
        sum += a;
    }
    cin >> m;
    for(i = 0; i < m; i++) {
        cin >> l >> r;
        minl = min(minl, l);
        maxr = max(maxr, r);
    }
    if(sum >= minl && sum <= maxr)
        cout << max(minl, sum) << endl;
    else
        cout << -1 << endl;
    return 0;
}
/*2018-07-24 19:27:32.82*/


#include<cstdio>
#include<queue>
#include<algorithm>
#include<string.h>
using namespace std;
int main()
{
    int n,m,a[5000];
    int t1[5000],t2[5000];
    scanf("%d",&n);
    int sum=0;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    scanf("%d",&m);
    for(int i=0;i<m;i++)
    {
        scanf("%d%d",&t1[i],&t2[i]);

    }
        int j;
        int flag=1;
        for( j=0;j<m;j++)
        {
            if(sum<=t1[j])
            {
                printf("%d\n",t1[j]);
                return 0;
            }
            if(sum<=t2[j])
              {
                    printf("%d\n",sum);
                    return 0;

              }

        }
        if(flag==1)
            printf("-1\n");

    return 0;
}
/*2018-07-24 20:48:31.456*/


#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int n,m,a[1005],l,r,ans=0,temp;
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
        scanf("%d",&a[i]);
    scanf("%d",&m);
    sort(a+1,a+n+1);
    for(int i=1;i<=m;i++)
    {
      scanf("%d%d",&l,&r);
      temp=r-l+1;
      for(int j=n;j>0;j--)
      {
        if(temp>=a[j])
        {
          ans+=a[j];
          temp-=a[j];
          a[j]=0;
        }
      }
    }
    if(ans==0)
      printf("-1\n");
    else
      printf("%d\n",ans);
    return 0;
}
/*2018-07-24 20:04:28.034*/


#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int a[20000],v[200005],w[200005];
int main()
{
    int n,k;
    int sum=0;
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
    {
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    scanf("%d",&k);
    for(int i=1; i<=k; i++)
    {
        int q,b;
        scanf("%d %d",&v[i],&w[i]);
    }
    if(sum>w[k])
        printf("-1\n");
    else
    {
        int check=0;
        for(int i=1; i<=k; i++)
        {
            if(sum>=v[i]&&sum<=w[i])
            {
                check=1;
                printf("%d\n",sum);
                break;
            }
        }
        if(check==0)
        {
            for(int i=1; i<=k; i++)
            {
                if(v[i]>=sum)
                {
                    printf("%d\n",v[i]);
                    break;
                }
            }
        }
    }
    return 0;
}
/*2018-07-24 19:45:16.946*/


#include <bits/stdc++.h>

using namespace std;
typedef long long LL;
const int MAXN = 1e5 + 10;

int n, T, a[MAXN];

struct Node {
    int l, r;
} arr[MAXN];

int main()
{
    while(~scanf("%d", &n)) {
        int sum = 0;
        for(int i = 1; i <= n; i++ ) {
            scanf("%d", &a[i]);
            sum += a[i];
        }
        int m;
        scanf("%d", &m);
        int mx = -1;
        for(int i = 1; i <= m; i++ ) {
            int l, r;
            scanf("%d %d", &l, &r);
            arr[i].l = l;
            arr[i].r = r;
            mx = max(r, mx);
        }
        if(sum <= mx) {
            int ans = 0, ok = 0;
            for(int i = 1; i <= m; i++ ) {
                if(sum >= arr[i].l && sum <= arr[i].r) {
                    ans = sum;
                    ok = 1;
                    break;
                }
            }
            if(ok) {
                printf("%d\n", ans);
                continue;
            }
            for(int i = 1; i <= m; i++ ) {
                if(arr[i].l >= mx) {
                    ans = arr[i].l;
                    break;
                }
            }
            printf("%d\n", ans);
        } else {
            puts("-1");
        }
    }

    return 0;
}

/*2018-07-24 19:23:50.385*/


#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
    __int64 n,ans,m,x[1100],time[1100],all,r,l,i,j,flag,pos;
    scanf("%I64d",&n);
    ans=0;
    for(i=0;i<n;i++)
    {
        scanf("%I64d",&x[i]);
    }
    scanf("%I64d",&m);
    all=0;
    for(j=0;j<m;j++)
    {
        scanf("%I64d%I64d",&l,&r);
        time[j]=r-l+1;
    }
    if(n>m) puts("-1");
    else
    {
        time[m]=1e6;
        sort(x,x+n);
        sort(time,time+m+1);
        flag=1;
        for(i=n-1;i>=0;i--)
        {
            pos=lower_bound(time,time+m,x[i])-time;

            if(pos==m||(pos==0&&time[0]<x[i]))
            {
                flag=0;
                break;
            }
            else
            {
                ans+=time[pos];
                time[pos]=0;
                sort(time,time+m+1);
            }
        }
        if(flag) printf("%I64d\n",ans);
        else puts("-1");
    }
    return 0;
}
/*2018-07-24 19:59:41.203*/


#include<cstdio>
#include<algorithm>
using namespace std;
int time[500005],x[100005],y[100005];
int main()
{
    int n,a[10005],m,sum=0;
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
    {
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    scanf("%d",&m);
    int maxx=0;
    for(int i=1; i<=m; i++)
    {
        scanf("%d%d",&x[i],&y[i]);
        for(int j=x[i]; j<=y[i]; j++)
            {
                time[j]=1;
                maxx=y[i];
            }
    }
    if(sum>maxx)
        puts("-1");
    else
    {
        if(time[sum])
            printf("%d\n",sum);
        else
        {
            for(int i=1; i<=m; i++)
            {
                if(sum<=y[i])
                {
                    printf("%d\n",sum);
                    break;
                }
            }
        }
    }
    return 0;
}
/*2018-07-24 20:15:28.055*/


#include<bits/stdc++.h>

using namespace std;

struct node
{
    int x,y;
}p[1010];

int cmp(node a,node b)
{
    if(a.x != b.x)
        return a.x < b.x;
    else
        return a.y < b.y;
}

int main()
{
    int n,m;
    int sum = 0;
    scanf("%d",&n);

    for(int i = 1;i <= n;i ++)
    {
        int temp;
        scanf("%d",&temp);
        sum += temp;
    }

    scanf("%d",&m);

    for(int i = 1;i <= m;i ++)
    {
        scanf("%d %d",&p[i].x,&p[i].y);
    }

    sort(p+1,p+1+m,cmp);

    int ans = 10000000;
    for(int i = 1;i <= m;i ++)
    {
        if(sum >=p[i].x && sum <= p[i].y)
        {
            ans = sum;
            break;
        }
        else if(p[i].x >= sum)
        {
            ans = min(ans,p[i].x);
        }
    }

    printf("%d\n",ans==10000000?-1:ans);

    return 0;
}
/*2018-07-24 19:23:10.615*/


#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int n,m,f[1001],h[1001],w[1001],x,y,s[1001];
int sum,q=1,book=0;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&f[i]);
        sum+=f[i];
    }
    scanf("%d",&m);
    for(int j=1;j<=m;j++)
    {
        scanf("%d%d",&h[j],&w[j]);
    }
    for(int i=1;i<=m;i++)
    {
        if(h[i]>=sum) {book=1;sum=h[i];break;}
        else if(w[i]>=sum) {book=1;break;}

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

}
/*2018-07-24 20:24:24.978*/


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct node
{
    int l;
    int r;
}t[1009];
bool cmp(node a,node b)
{
    if(a.l==b.l)
        return a.r<b.r;
    return a.l<b.l;
}
int main()
{
    int n,m;
    int i,j,k;
    int a[1009];
    while(~scanf("%d",&n))
    {
        int sum=0;
        for(i=1;i<=n;i++)
            scanf("%d",&a[i]),sum+=a[i];
        scanf("%d",&m);
        for(i=1;i<=m;i++)
            scanf("%d%d",&t[i].l,&t[i].r);
        sort(t+1,t+m+1,cmp);
        int ans=-1;
        for(i=1;i<=m;i++)
        {
            if(t[i].l>=sum)
                {
                    ans=t[i].l;
                    break;
                }
            else if(t[i].r>=sum)
                {
                    ans=sum;
                    break;
                }
        }
        printf("%d\n",ans);
    }
    return 0;
}
/*2018-07-24 20:04:46.844*/


#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int n,m,f[1001],h[1001],w[1001],x,y,s[1001];
int sum,q=1,book=0;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&f[i]);
        sum+=f[i];
    }
    scanf("%d",&m);
    for(int j=1;j<=m;j++)
    {
        scanf("%d%d",&h[j],&w[j]);
    }
    for(int i=1;i<=m;i++)
    {
        if(h[i]>=sum) {book=1;sum=h[i];break;}
        else if(w[i]>=sum) {book=1;break;}

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

}
/*2018-07-24 19:51:36.902*/


#include<cstdio>
#include<queue>
#include<algorithm>
#include<string.h>
using namespace std;
int main()
{
    int n,m,a[1010];
    int t1[2020];
    scanf("%d",&n);
    int sum=0;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    scanf("%d",&m);
    int minn=106,maxn=0;
    for(int i=0;i<m*2;i++)
    {
        scanf("%d%d",&t1[i],&t1[i+1]);
        i++;
    }
        sort(t1,t1+m*2);
        int j;
        int flag=1;
        for( j=0;j<m*2;j++)
        {
            if(sum<=t1[j])
            {
                flag=0;
                printf("%d\n",t1[j]);
                return 0;
            }

        }
        if(flag==1)
            puts("-1");

    return 0;
}
/*2018-07-24 19:47:37.169*/


#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int n,m,a[1005],l[1005],r[1005];
    int sum=0;
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
    {
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    scanf("%d",&m);
    for(int i=1; i<=m; i++)
    {
        scanf("%d%d",&l[i],&r[i]);
    }
    if(sum<l[1])
        printf("%d\n",l[1]);
    else if(sum>r[m])
        printf("-1\n");
    else
    {
        for(int i=1; i<=m; i++)
        {
            if(sum<=l[i])
            {
              printf("%d\n",l[i]);
                break;
            }
            else if(sum>=l[i]&&sum<=r[i])
            {
               printf("%d\n",sum);
               break;
            }
        }
    }
    return 0;
}/*2018-07-24 20:40:11.798*/


#include <bits/stdc++.h>

using namespace std;
typedef long long LL;
const int MAXN = 1e5 + 10;

int n, T, a[MAXN];

struct Node {
    int l, r;
} arr[MAXN];

int main()
{
    while(~scanf("%d", &n)) {
        int sum = 0;
        for(int i = 1; i <= n; i++ ) {
            scanf("%d", &a[i]);
            sum += a[i];
        }
        int m;
        scanf("%d", &m);
        int mx = -1;
        for(int i = 1; i <= m; i++ ) {
            int l, r;
            scanf("%d %d", &l, &r);
            arr[i].l = l;
            arr[i].r = r;
            mx = max(r, mx);
        }
        if(sum <= mx) {
            int ans = 0, ok = 0;
            for(int i = 1; i <= m; i++ ) {
                if(sum >= arr[i].l && sum <= arr[i].r) {
                    ans = sum;
                    ok = 1;
                    break;
                }
            }
            if(ok) {
                printf("%d\n", ans);
                continue;
            }
            for(int i = 1; i <= m; i++ ) {
                if(arr[i].l >= sum) {
                    ans = arr[i].l;
                    break;
                }
            }
            printf("%d\n", ans);
        } else {
            puts("-1");
        }
    }

    return 0;
}

/*2018-07-24 19:25:57.049*/


#include<bits/stdc++.h>
using namespace std;
int a[10005],l[10005],r[10005];
int main()
{
	int n,m,ans,flag;
	while(cin>>n)
	{
		ans=0,flag=0;
		for(int i=0; i<n; i++)
		{
			cin>>a[i];
			ans+=a[i];
		}
		cin>>m;
		for(int i=0; i<m; i++)
			cin>>l[i]>>r[i];

		sort(l,l+m);
		sort(r,r+m);

		if(ans>r[m-1])
			cout<<"-1"<<endl;
		else
			cout<<max(ans,l[m-1])<<endl;
	}
	return 0;
}/*2018-07-24 19:58:48.54*/


#include <cstdio>
#include <algorithm>
using namespace std;
int a[1005],ans[100005];
int main()
{
    int n,x,l,r,maxn;
    scanf("%d",&n);
    int sum=0;
    for(int i=0;i<n;i++)
    {
        scanf("%d",a+i);
        sum=sum+a[i];
    }
    sort(a,a+n);
    scanf("%d",&x);
    for(int i=0;i<x;i++)
    {
        scanf("%d%d",&l,&r);
        for(int j=l;j<=r;j++)
            ans[j]=1;
        maxn=r;
    }
    if(sum>maxn)
        puts("-1");
    else
    {
        int k=0;
        for(int i=0;i<n;i++)
        {
                k=k+a[i];
        }
        if(ans[k])
            printf("%d\n",k);
        else
        {
            for(int i=k;;i++)
            {
                if(ans[i])
                {
                    printf("%d\n",i);
                    break;
                }
            }
        }
    }

    return 0;
}
/*2018-07-24 19:52:27.115*/


#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int n,m,f[1001],h[1001],w[1001],x,y;
priority_queue<long long, vector<long long>, greater<long long> > q2;
long long sum;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&f[i]);
    scanf("%d",&m);
    for(int j=1;j<=m;j++)
    {
        scanf("%d%d",&x,&y);
        q2.push(y-x+1);
    }
    sort(f+1,f+1+n);
    sort(h+1,h+1+m);
    for(int i=1;i<=n;i++)
    {   int k=0;
        while(k<f[i]&&!q2.empty())
        {
        k=q2.top();
         q2.pop();
        }
        if(k<f[i]) k=0;
        k=max(0,k);
         sum+=k;
         q2.push(k-f[i]);

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

}/*2018-07-24 19:19:49.992*/


#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const int MAXR = 1e5 + 5;

int ok[MAXR];

int main() {
    ios::sync_with_stdio(false);
    ll n, m, i, l, r, a;
    ll minl = INF, maxr = -1;
    ll sum = 0;
    cin >> n;
    for(i = 0; i < n; i++) {
        cin >> a;
        sum += a;
    }
    cin >> m;
    for(i = 0; i < m; i++) {
        cin >> l >> r;
        ok[l] ++;
        ok[r + 1] --;
    }
    for(i = 0; i < MAXR; i++) {
        ok[i] += ok[i - 1];
    }
    for(i = sum; i < MAXR; i++) {
        if(ok[i])
            break;
    }
    if(i >= MAXR)
        cout << i << endl;
    else
        cout << -1 << endl;
    return 0;
}
/*2018-07-24 20:00:55.991*/


#include<bits/stdc++.h>
using namespace std;
int per[10005];
int tim[10005];
int main()
{
    int sum = 0;
    int maxt = -1;
    int temp,l,r;
    int n,m;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>temp;
        maxt = max(temp,maxt);
        sum+=temp;
    }
    cin>>m;
    int flag = 0;
    for(int i=0;i<m;i++)
    {
        cin>>l>>r;
        if(sum>=l&&sum<=r)
        {
            flag =1;
        }
        if(sum<l&&sum<r)
        {
            flag =1;
            sum = l;
            break;
        }
    }
    if(!flag)
    {
        cout<<-1<<endl;
    }
    else
    {
        cout<<sum<<endl;
    }
    return 0;

}


#include<bits/stdc++.h>
using namespace std;
int per[10005];
int tim[10005];
int main()
{
    int sum = 0;
    int maxt = -1;
    int temp,l,r;
    int n,m;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>temp;
        maxt = max(temp,maxt);
        sum+=temp;
    }
    cin>>m;
    int minl=9999999,maxr=-1;
    int flag = 0;
    for(int i=0;i<m;i++)
    {
        cin>>l>>r;
        if(sum>=l&&sum<=r)
        {
            flag =1;
        }
    }
    if(!flag||m==0)
    {
        cout<<-1<<endl;
    }
    else
    {
        cout<<sum<<endl;
    }
    return 0;

}


#include<bits/stdc++.h>
using namespace std;
int per[10005];
int tim[10005];
int main()
{
    int sum = 0;
    int maxt = -1;
    int temp,l,r;
    int n,m;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>temp;
        maxt = max(temp,maxt);
        sum+=temp;
    }
    cin>>m;
    int flag = 0;
    for(int i=0;i<m;i++)
    {
        cin>>l>>r;
        if(sum>=l&&sum<=r)
        {
            flag =1;
        }
        if(sum>=l&&sum<=r)
        {
            sum = l;
            flag = 1;
        }
    }
    if(!flag)
    {
        cout<<-1<<endl;
    }
    else
    {
        cout<<sum<<endl;
    }
    return 0;

}


#include<bits/stdc++.h>
using namespace std;
int per[10005];
int tim[10005];
int main()
{
    int sum = 0;
    int temp,l,r;
    int n,m;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>temp;
        sum+=temp;
    }
    cin>>m;
    int minl=9999999,maxr=-1;
    for(int i=0;i<m;i++)
    {
        cin>>l>>r;
        minl = min (l,minl);
        maxr = max(r,maxr);
    }
    if(sum>maxr||sum<minl)
    {
        cout<<-1<<endl;
    }
    else
    {
        cout<<sum<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int per[10005];
int tim[10005];
int main()
{
    int sum = 0;
    int maxt = -1;
    int temp,l,r;
    int n,m;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>temp;
        maxt = max(temp,maxt);
        sum+=temp;
    }
    cin>>m;
    int minl=9999999,maxr=-1;
    int flag = 0;
    for(int i=0;i<m;i++)
    {
        cin>>l>>r;
        if(sum>=l&&sum<=r)
        {
            flag =1;
        }
    }
    if(!flag)
    {
        cout<<-1<<endl;
    }
    else
    {
        cout<<sum<<endl;
    }
    return 0;

}


#include<bits/stdc++.h>
using namespace std;
int per[10005];
int tim[10005];
int main()
{
    int sum = 0;
    int maxt = -1;
    int temp,l,r;
    int n,m;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>temp;
        maxt = max(temp,maxt);
        sum+=temp;
    }
    cin>>m;
    int flag = 0;
    for(int i=0;i<m;i++)
    {
        cin>>l>>r;
        if(sum>=l&&sum<=r)
        {
            flag =1;
            break;
        }
        if(sum<l&&sum<r)
        {
            flag =1;
            sum = l;
            break;
        }
    }
    if(!flag)
    {
        cout<<-1<<endl;
    }
    else
    {
        cout<<sum<<endl;
    }
    return 0;

}


#include<bits/stdc++.h>
using namespace std;
int per[10005];
int tim[10005];
int main()
{
    int sum = 0;
    int maxt = -1;
    int temp,l,r;
    int n,m;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>temp;
        maxt = max(temp,maxt);
        sum+=temp;
    }
    cin>>m;
    int minl=9999999,maxr=-1;
    for(int i=0;i<m;i++)
    {
        cin>>l>>r;
        minl = min (l,minl);
        maxr = max(r,maxr);
    }
    if(sum>maxr||sum<minl||maxt<=minl)
    {
        cout<<-1<<endl;
    }
    else
    {
        cout<<sum<<endl;
    }
    return 0;

}


#include<bits/stdc++.h>
using namespace std;
int per[10005];
int tim[10005];
int main()
{
    int sum = 0;
    int maxt = -1;
    int temp,l,r;
    int n,m;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>temp;
        maxt = max(temp,maxt);
        sum+=temp;
    }
    cin>>m;
    int minl=9999999,maxr=-1;
    for(int i=0;i<m;i++)
    {
        cin>>l>>r;
        minl = min (l,minl);
        maxr = max(r,maxr);
    }
    if(sum>maxr||sum<minl||maxt<minl)
    {
        cout<<-1<<endl;
    }
    else
    {
        cout<<sum<<endl;
    }
    return 0;

}


#include <iostream>
using namespace std;
int a[1050];
int b[1050];
int n,m,ans=3000;
int main(){
    cin>>n>>m;
    for(int i=1;i<=m;++i){
        cin>>a[i];
        b[a[i]]++;
    }
    for(int i=1;i<=m;++i){
        if(i==1) ans=b[i];
        else if(ans>b[i]) ans=b[i];
    }
    cout<<ans;
    return 0;
}


#include <iostream>
using namespace std;
int a[1050];
int b[1050];
int n,m,ans;
int main(){
    cin>>n>>m;
    for(int i=1;i<=m;++i){
        cin>>a[i];
        b[a[i]]++;
    }
    for(int i=1;i<=m;++i){
        if(i==1) ans=b[i];
        else if(ans>b[i]) ans=b[i];
    }
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>

# define ll long long
# define ios ios_base::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL);
# define pb push_back
# define pob pop_back
# define pf push_front
# define pof pop_front
# define fr first
# define sc second

using namespace std;

const ll N = 1e5 + 10;
const ll mod = 1e9 + 7;
const ll INF = 1e18;
const ll inf = -1e18;

long long n, m, us[1010], a[1010], mn = INF;

int main() {
    ios
    cin >> n >> m;
    for(int i = 1;i <= m;i++) {
        cin >> a[i];
        us[a[i]]++;
    }
    for(int i = 1;i <= m;i++) {
        mn = min(mn, us[a[i]]);
    }
    cout << mn;
}


#include <bits/stdc++.h>

# define ll long long
# define ios ios_base::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL);
# define pb push_back
# define pob pop_back
# define pf push_front
# define pof pop_front
# define fr first
# define sc second

using namespace std;

const ll N = 1e5 + 10;
const ll mod = 1e9 + 7;
const ll INF = 1e18;
const ll inf = -1e18;

long long n, m, us[1010], a[1010], mn = INF;

int main() {
    ios
    cin >> n >> m;
    for(int i = 1;i <= m;i++) {
        cin >> a[i];
        us[a[i]]++;
    }
    for(int i = 1;i <= n;i++) {
        mn = min(mn, us[a[i]]);
    }
    cout << mn;
}


#include <bits/stdc++.h>

# define ll long long
# define ios ios_base::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL);
# define pb push_back
# define pob pop_back
# define pf push_front
# define pof pop_front
# define fr first
# define sc second

using namespace std;

const ll N = 1e5 + 10;
const ll mod = 1e9 + 7;
const ll INF = 1e18;
const ll inf = -1e18;

long long n, m, us[1010], a[1010], mn = INF;

int main() {
    ios
    cin >> n >> m;
    for(int i = 1;i <= m;i++) {
        cin >> a[i];
        us[a[i]]++;
    }
    for(int i = 1;i <= n;i++) {
        mn = min(mn, us[i]);
    }
    cout << mn;
}


#include <bits/stdc++.h>

using namespace std;
i
int contador[1005] = {0};

int main(int argc, char const *argv[])
{
	int n, m, d, pts = 0;
	int c[n+5] = {0};

	cin >> n >> m;
	for (int i = 0; i < m; ++i)
	{
		int bloco;
		scanf("%d", &bloco);
		contador[bloco]++;
	}

	int ans = 1001;
	for (int i = 1; i <= n; ++i)
	{
		ans = min(ans, contador[i]);
	}

	cout << ans;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int contador[1005] = {0};

int main(int argc, char const *argv[])
{
	int n, m, d, pts = 0;

	cin >> n >> m;
	int bloco;
	for (int i = 0; i < m; ++i)
	{
		scanf("%d", &bloco);
		contador[bloco]++;
	}

	int ans = 1001;
	for (int i = 1; i <= n; ++i)
	{
		ans = min(ans, contador[i]);
	}

	cout << ans;

	return 0;
}