#include<bits/stdc++.h>
using namespace std;
int main(){
	long int n;
	cin>>n;
	long int maxR=INT_MAX;
	long int minR = INT_MIN ;
	long long int finalRating=0;
	long long int constant=0,wholeConstant=0;
	long	int ratingChange[n] ;
	int division[n] ;
	bool maxRChanged=false,minRChanged=false,flagImpossible=false,infinityFlag=false;
	for(long int i=0;i<n;i++)
	{cin>>ratingChange[i]>>division[i];
	wholeConstant+=ratingChange[i] ;
	}
	if(n!=1){
	for(long int i =0;i<n-1;i++)
	{ constant+=ratingChange[i];
	if(division[i+1]==1)    // 1 division
	{long int minRating;
		minRating=1900-constant;
		if(minRating>=minR)
		{
		minR = minRating ;
         minRChanged =true;
		}
	}
	else // 2nd division
		{ long int maxRating;
			maxRating=1900-constant-1;
		 if(maxR>=maxRating)
				{
				maxR=maxRating ;
				maxRChanged = true;
				}
		}//end of else
if(maxR>=minR&&maxRChanged)
{if(division[0]==1){
	if(minR>=1900)
	finalRating = maxR+wholeConstant;
     else
		   {if(maxR>=1900)
			finalRating = maxR+wholeConstant;
		   else
		   flagImpossible=true;
	       }
		}
			else {
			if(minR>=1900)
			flagImpossible=true;
		else
			{
				if(maxR<1900)
					finalRating = maxR+wholeConstant ;
					else
			finalRating = 1899+wholeConstant ;
		}
		}

} // end of if minr>=maxR and maxRchanged
else if(maxR>=minR&&!maxRChanged)
{
if(division[0]==2)
{            if(minR>=1900)
            flagImpossible =true;
            else
             finalRating = 1899+wholeConstant;
}
else{
           infinityFlag=true;

}
} //end of else-if
else flagImpossible =true;
}
	if(flagImpossible)
	cout<<"Impossible";
	else if(infinityFlag)//||!minRChanged))
  cout<<"Infinity";
  else
	cout<<finalRating;
}
else {
	if(division[0]==1)
	{
	infinityFlag=true;
	  cout<<"Infinity";}
	else
	{
	finalRating=1899+wholeConstant ;
		cout<<finalRating;}

}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	long int n;
	cin>>n;
	long int maxR=INT_MAX;
	long int minR = INT_MIN ;
	long long int finalRating;
	long long int constant=0,wholeConstant=0;
	long	int ratingChange[n] ;
	int division[n] ;
	bool maxRChanged=false,flagImpossible=false;
	for(long int i=0;i<n;i++)
	{cin>>ratingChange[i]>>division[i];
	wholeConstant+=ratingChange[i] ;
	}
	for(long int i =0;i<n-1;i++)
	{ constant+=ratingChange[i];
	if(division[i+1]==1)
	{long int minRating;
		minRating=1900-constant;
		if(minRating>=minR)
		minR = minRating ;
	}
	else
		{ long int maxRating;
			maxRating=1900-constant-1;
		//	cout<<"final = "<<maxRating<<" constamt = "<<constant<<endl;
			if(maxR>=maxRating)
				{
				maxR=maxRating ;
				maxRChanged=true;
				}
			}
		if(maxR>=minR)
		{if(division[0]==1){
			if(minR>=1900)
			finalRating = maxR+wholeConstant;
		   else
		   {if(maxR>=1900)
			finalRating = maxR+wholeConstant;
		   else
		   flagImpossible=true;
	       }
		}
		else {
			if(minR>=1900)
			flagImpossible=true;
		else
			{
				if(maxR<1900)
					finalRating = maxR+wholeConstant ;
					else
			finalRating = 1899+wholeConstant ;
		}
		}

		}
		else flagImpossible =true;

	}
	if(flagImpossible)
	cout<<"Impossible";
	else if(!maxRChanged)
  cout<<"Infinity";
  else
	cout<<finalRating;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	long int n;
	cin>>n;
	long int maxR=INT_MAX;
	long int minR = INT_MIN ;
	long long int finalRating=0;
	long long int constant=0,wholeConstant=0;
	long	int ratingChange[n] ;
	int division[n] ;
	bool maxRChanged=false,flagImpossible=false,infinityFlag=false;
	for(long int i=0;i<n;i++)
	{cin>>ratingChange[i]>>division[i];
	wholeConstant+=ratingChange[i] ;
	}
	if(n!=1){
	for(long int i =0;i<n-1;i++)
	{ constant+=ratingChange[i];
	if(division[i+1]==1)
	{long int minRating;
		minRating=1900-constant;
		if(minRating>=minR)
		minR = minRating ;
	}
	else
		{ long int maxRating;
			maxRating=1900-constant-1;
		//	cout<<"final = "<<maxRating<<" constamt = "<<constant<<endl;
			if(maxR>=maxRating)
				{
				maxR=maxRating ;
				}
			}
		if(maxR>=minR)
		{if(division[0]==1){
			if(minR>=1900)
			finalRating = maxR+wholeConstant;
		   else
		   {if(maxR>=1900)
			finalRating = maxR+wholeConstant;
		   else
		   flagImpossible=true;
	       }
		}
		else {
			if(minR>=1900)
			flagImpossible=true;
		else
			{
				if(maxR<1900)
					finalRating = maxR+wholeConstant ;
					else
			finalRating = 1899+wholeConstant ;
		}
		}

		}
		else flagImpossible =true;

	}
}
else {
	if(division[0]==1)
	infinityFlag=true;
	else
	finalRating=1899+wholeConstant ;
}

//	cout<<finalRating;
	if(flagImpossible)
	cout<<"Impossible";
	else if(infinityFlag)
  cout<<"Infinity";
  else
	cout<<finalRating;

	return 0;
}


#include <iostream>
#include <vector>
#define c first
#define d second
using namespace std;
vector<pair<int,short> > V;
pair<int,short> tmp;
int rez=(1<<30),mod,N,nr;
pair<int,short> A[200005];
bool d2,d1;
int main()
{
    cin>>N;
    for(int i=1;i<=N;i++)
    {
        cin>>A[i].c>>A[i].d;
    }
    nr=0;
    for(int i=N;i;i--)
    {
        mod+=A[i].c;
        if(A[i].d==A[i+1].d&&A[i].d==2)
        {
            nr+=A[i].c;
            rez=min(rez,1899-nr+mod);
        }
        else if(A[i].d==2)
        {
            //nr+=A[i].c;
            rez=min(rez,1900+mod);
        }
        else if(A[i].d==1)
            nr=0;
    }
    for(int i=1;i<=N;i++)
    {
        if(!V.empty()&&(V.back()).d==A[i].d)
        {
            (V.back()).c+=A[i].c;
        }
        else
            V.push_back(A[i]);
    }
    N=V.size();
    mod=V[N-1].c;
    for(int i=N-2;i>=0;i--)
    {
        mod+=V[i].c;
        if(V[i].d!=V[i+1].d&&(V[i].d-V[i+1].d)*V[i].c<=0)
        {
            cout<<"Impossible";return 0;
        }
        if(V[i].d==1&&V[i+1].d==2)
        {
            rez=min(rez,1900-V[i].c-1+mod);nr=0;
        }
        else if(V[i].d==2&&V[i+1].d==1)
        {
            rez=min(rez,1899+mod);nr=0;
        }
    }
    if(rez==(1<<30))
        cout<<"Infinity";
    else
        cout<<rez;
    return 0;
}


#include <iostream>
#include <vector>
#define c first
#define d second
using namespace std;
vector<pair<int,short> > V;
pair<int,short> tmp;
int rez=(1<<30),mod,N,nr;
bool d2,d1;
int main()
{
    cin>>N;
    for(int i=1;i<=N;i++)
    {
        cin>>tmp.c>>tmp.d;
        V.push_back(tmp);
    }
    mod=V[N-1].c;
    for(int i=N-2;i>=0;i--)
    {
        mod+=V[i].c;
        if(V[i].d!=V[i+1].d&&(V[i].d-V[i+1].d)*V[i].c<=0)
        {
            cout<<"Impossible";return 0;
        }
        if(V[i].d==1&&V[i+1].d==2)
        {
            rez=min(rez,1900-V[i].c-1+mod);
            nr=V[i].c;d1=1;
        }
        else if(V[i].d==2&&V[i+1].d==1)
        {
            rez=min(rez,1899+mod);
            nr=V[i].c;d2=1;
        }
        else if(V[i].d==2)
        {
            nr+=V[i].c;
            rez=min(rez,1899-nr+mod);
            d2=1;
        }
        else if(V[i].d==1)
        {
           ;
        }
    }
    if(rez==(1<<30))
        cout<<"Infinity";
    else
        cout<<rez;
    return 0;
}


#include <iostream>
#include <vector>
#define c first
#define d second
using namespace std;
vector<pair<long long,short> > V;
pair<long long,short> tmp;
long long rez=(1<<30),mod,N,nr;
pair<long long,short> A[200005];
bool d2,d1;
int main()
{
    cin>>N;
    for(long long i=1;i<=N;i++)
    {
        cin>>A[i].c>>A[i].d;
    }
    mod=A[N].c;
    nr=0;
    for(long long i=N-1;i;i--)
    {
        mod+=A[i].c;
        if(A[i].d==A[i+1].d&&A[i].d==2)
        {
            nr+=A[i].c;
            rez=min(rez,1899-nr+mod);
        }
        else if(A[i].d==1)
            nr=0;
    }
    for(long long i=1;i<=N;i++)
    {
        if(!V.empty()&&(V.back()).d==A[i].d)
        {
            (V.back()).c+=A[i].c;
        }
        else
            V.push_back(A[i]);
    }
    N=V.size();
    mod=V[N-1].c;
    for(long long i=N-2;i>=0;i--)
    {
        mod+=V[i].c;
        if(V[i].d!=V[i+1].d&&(V[i].d-V[i+1].d)*V[i].c<=0)
        {
            cout<<"Impossible";return 0;
        }
        if(V[i].d==1&&V[i+1].d==2)
        {
            rez=min(rez,1900-V[i].c-1+mod);nr=0;
        }
        else if(V[i].d==2&&V[i+1].d==1)
        {
            rez=min(rez,1899+mod);nr=0;
        }
    }
    if(rez==(1<<30))
        cout<<"Infinity";
    else
        cout<<rez;
    return 0;
}


#include<iostream>
#include<fstream>
#include<string>
#define MAXIM 1999999999
using namespace std;
string s;
int N;
int i,j,c,d,poz=0,dr=-MAXIM,st=MAXIM;
int main()
{
    cin>>N;
    for(i=1;i<=N;i++)
    {
        cin>>c>>d;
        if(d==1)
            st=min(st,poz);
        else
            dr=max(dr,poz);
        poz=poz+c;
    }
    if(st<=dr)
    {
        cout<<"Impossible\n";
        return 0;
    }
    if(dr==-MAXIM)
    {
        cout<<"Infinity\n";
    }
    else
    {
        c=poz-dr;
        cout<<1899+c<<"\n";
    }
}


#include <iostream>
#include <vector>
#define c first
#define d second
using namespace std;
vector<pair<int,short> > V;
pair<int,short> tmp;
int rez=(1<<30),mod,N,nr;
pair<int,short> A[200005];
bool d2,d1;
int main()
{
    cin>>N;
    for(int i=1;i<=N;i++)
    {
        cin>>A[i].c>>A[i].d;
    }
    mod=A[N].c;
    nr=0;
    for(int i=N-1;i;i--)
    {
        mod+=A[i].c;
        if(A[i].d==A[i+1].d&&A[i].d==2)
        {
            nr+=A[i].c;
            rez=min(rez,1899-nr+mod);
        }
        else if(A[i].d==1)
            nr=0;
    }
    for(int i=1;i<=N;i++)
    {
        if(!V.empty()&&(V.back()).d==A[i].d)
        {
            (V.back()).c+=A[i].c;
        }
        else
            V.push_back(A[i]);
    }
    N=V.size();
    mod=V[N-1].c;
    for(int i=N-2;i>=0;i--)
    {
        mod+=V[i].c;
        if(V[i].d!=V[i+1].d&&(V[i].d-V[i+1].d)*V[i].c<=0)
        {
            cout<<"Impossible";return 0;
        }
        if(V[i].d==1&&V[i+1].d==2)
        {
            rez=min(rez,1900-V[i].c-1+mod);nr=0;
        }
        else if(V[i].d==2&&V[i+1].d==1)
        {
            rez=min(rez,1899+mod);nr=0;
        }
    }
    if(rez==(1<<30))
        cout<<"Infinity";
    else
        cout<<rez;
    return 0;
}


#include <iostream>
#include <vector>
#define c first
#define d second
using namespace std;
vector<pair<int,short> > V;
pair<int,short> tmp;
int rez=(1<<30),mod,N,nr;
bool d2,d1;
int main()
{
    cin>>N;
    for(int i=1;i<=N;i++)
    {
        cin>>tmp.c>>tmp.d;
        V.push_back(tmp);
    }
    mod=V[N-1].c;
    for(int i=N-2;i>=0;i--)
    {
        mod+=V[i].c;
        if(V[i].d!=V[i+1].d&&(V[i].d-V[i+1].d)*V[i].c<=0)
        {
            cout<<"Impossible";return 0;
        }
        if(V[i].d==1&&V[i+1].d==2)
        {
            rez=min(rez,1900-V[i].c-1+mod);
            nr=V[i].c;d1=1;
        }
        else if(V[i].d==2&&V[i+1].d==1)
        {
            rez=min(rez,1899+mod);
            nr=V[i].c;d2=1;
        }
        else if(V[i].d==2)
        {
            nr+=V[i].c;
            rez=min(rez,1899-nr+mod);
            d2=1;
        }
        else if(V[i].d==1)
        {
            nr+=V[i].c;d1=1;
            rez=min(rez,1899-nr+mod);
        }
    }
    if(rez==(1<<30))
        cout<<"Infinity";
    else
        cout<<rez;
    return 0;
}


#include <iostream>
#include <vector>
#define c first
#define d second
using namespace std;
vector<pair<int,short> > V;
pair<int,short> tmp;
int rez=(1<<30),mod,N,nr;
bool d2,d1;
int main()
{
    cin>>N;
    for(int i=1;i<=N;i++)
    {
        cin>>tmp.c>>tmp.d;
        V.push_back(tmp);
    }
    mod=V[N-1].c;
    for(int i=N-2;i>=0;i--)
    {
        mod+=V[i].c;
        if(V[i].d!=V[i+1].d&&(V[i].d-V[i+1].d)*V[i].c<=0)
        {
            cout<<"Impossible";return 0;
        }
        if(V[i].d==1&&V[i+1].d==2)
        {
            rez=min(rez,1900-V[i].c-1+mod);
            nr=0;
        }
        else if(V[i].d==2&&V[i+1].d==1)
        {
            rez=min(rez,1899+mod);
            nr=0;
        }
        else if(V[i].d==2)
        {
            nr+=V[i].c;
            rez=min(rez,1899-nr+mod);
            d2=1;
        }
        else if(V[i].d==1)
        {
           nr=0;
        }
    }
    if(rez==(1<<30))
        cout<<"Infinity";
    else
        cout<<rez;
    return 0;
}


#include <iostream>
#include <vector>
#define c first
#define d second
using namespace std;
vector<pair<int,short> > V;
pair<int,short> tmp;
int rez=(1<<30),mod,N,nr;
bool d2,d1;
int main()
{
    cin>>N;
    for(int i=1;i<=N;i++)
    {
        cin>>tmp.c>>tmp.d;
        V.push_back(tmp);
    }
    mod=V[N-1].c;
    for(int i=N-2;i>=0;i--)
    {
        mod+=V[i].c;
        if(V[i].d!=V[i+1].d&&(V[i].d-V[i+1].d)*V[i].c<=0)
        {
            cout<<"Impossible";return 0;
        }
        if(V[i].d==1&&V[i+1].d==2)
        {
            rez=min(rez,1900-V[i].c-1+mod);
            nr=V[i].c;d1=1;
        }
        else if(V[i].d==2&&V[i+1].d==1)
        {
            rez=min(rez,1899+mod);
            nr=V[i].c;d2=1;
        }
        else if(V[i].d==2)
        {
            nr+=V[i].c;
            rez=min(rez,1899-nr+mod);
            d2=1;
        }
        else if(V[i].d==1)
        {
            nr+=V[i].c;d1=1;
            rez=min(rez,1900-nr+mod);
        }
    }
    if(rez==(1<<30))
        cout<<"Infinity";
    else
        cout<<rez;
    return 0;
}


#include<map>
#include<set>
#include<stack>
#include<queue>
#include<string.h>
#include<cstring>
#include<vector>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3f
#define FIN freopen("input.txt","r",stdin)
#define mem(x,y) memset(x,y,sizeof(x))
typedef unsigned long long ULL;
typedef long long LL;
#define MX 1111
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
typedef pair<pair<int,int>,int> PIII;
typedef pair<int,int> PII;
int arr[222222][2];
int n;
int ans;
bool check(int x)
{
    for(int i=1; i<=n; i++)
    {
        if(x<1900&&arr[i][1]==1) return 1;
        if(x>=1900&&arr[i][1]==2) return 0;
        x+=arr[i][0];

    }
    return 1;
}
bool check1(int x)
{
    for(int i=1; i<=n; i++)
    {
        if(x<1900&&arr[i][1]==1) return 0;
        if(x>=1900&&arr[i][1]==2) return 0;
        x+=arr[i][0];

    }
    ans=x;
    return 1;
}
int erfeng(int l,int r)
{
    int mid;
    while(l<r)
    {
        //cout<<l<<" "<<r<<endl;
        mid=((l+r)>>1)+1;
        if(check(mid)) l=mid;
        else r=mid-1;
    }
    return l;

}
int main()
{
    //FIN;
    while(cin>>n)
    {
        for(int i=1; i<=n; i++) scanf("%d%d",&arr[i][0],&arr[i][1]);
        if(check(INF)) puts("Infinity");
        else
        {
            int t=erfeng(-INF,INF);//
            if(check1(t)){
                   printf("%d\n",ans);
        }
                else puts("Impossible");
        }

    }
    return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
#define INF 0x3f3f3f3f3f3f3f
typedef long long LL;
const LL MAX=2e5+5;
LL n;
LL flag;
struct Node
{
    LL c,d;
}a[MAX];
LL check(LL x)
{
    LL res=x;
    for(LL i=n-1;i>=0;i--)
    {
        res-=a[i].c;
        if(a[i].d==1&&res<1900) return 0;
        if(a[i].d==2&&res>=1900) return -1;
    }
    return 1;
}
LL solve(LL l,LL r)
{
    flag=0;
    LL mid;
    while(l<r)
    {
        mid=(r+l)/2+1;
        if(check(mid)>=0)l=mid;
        else r=mid-1;
    }
    if(check(l)==1) {flag=1;return l;}
    return -1;
}
int main()
{
    //freopen("input.txt","r",stdin);
    while(~scanf("%I64d",&n))
    {
        for(int i=0;i<n;i++)
            scanf("%I64d%I64d",&a[i].c,&a[i].d);
        LL t=solve(-INF,INF);
        if(flag==1)
        {
            if(t==INF)cout<<"Infinity"<<endl;
            else cout<<t<<endl;
        }
        else cout<<"Impossible"<<endl;
    }
    return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
#define INF 0x3f3f3f3f3f3f3f
typedef long long LL;
const LL MAX=2e5+5;
LL n;
LL flag;
struct Node
{
    LL c,d;
}a[MAX];
LL check(LL x)
{
    LL res=x;
    for(LL i=n-1;i>=0;i--)
    {
        res-=a[i].c;
        if(a[i].d==1&&res<1900) return 0;
        if(a[i].d==2&&res>=1900) return -1;
    }
    return 1;
}
LL solve(LL l,LL r)
{
    flag=0;
    LL mid;
    while(l<r)
    {
        mid=(r+l)/2+1;
        if(check(mid)>=0)l=mid;
        else r=mid-1;
    }
    if(check(l)==1) {flag=1;return l;}
    return -1;
}
int main()
{
    //freopen("input.txt","r",stdin);
    while(~scanf("%I64d",&n))
    {
        for(int i=0;i<n;i++)
            scanf("%d%d",&a[i].c,&a[i].d);
        LL t=solve(-INF,INF);
        if(flag==1)
        {
            if(t==INF)cout<<"Infinity"<<endl;
            else cout<<t<<endl;
        }
        else cout<<"Impossible"<<endl;
    }
    return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
#define INF 0x3f3f3f3f
typedef long long LL;
const LL MAX=2e5+5;
LL n;
LL flag;
struct Node
{
    LL c,d;
}a[MAX];
LL check(LL x)
{
    LL res=x;
    for(LL i=n-1;i>=0;i--)
    {
        res-=a[i].c;
        if(a[i].d==1&&res<1900) return 0;
        if(a[i].d==2&&res>=1900) return -1;
    }
    return 1;
}
LL solve(LL l,LL r)
{
    flag=0;
    LL mid;
    while(l<r)
    {
        mid=（(r+l)>>1）+1;
        if(check(mid)>=0)l=mid;
        else r=mid-1;
    }
    if(check(l)==1) {flag=1;return l;}
    return -1;
}
int main()
{
    //freopen("input.txt","r",stdin);
    while(~scanf("%I64d",&n))
    {
        for(int i=0;i<n;i++)
            scanf("%I64d%I64d",&a[i].c,&a[i].d);
        LL t=solve(-INF,INF);
        if(flag==1)
        {
            if(t==INF)cout<<"Infinity"<<endl;
            else cout<<t<<endl;
        }
        else cout<<"Impossible"<<endl;
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<string.h>
#include<cstring>
#include<vector>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3f
#define FIN freopen("input.txt","r",stdin)
#define mem(x,y) memset(x,y,sizeof(x))
typedef unsigned long long ULL;
typedef long long LL;
#define MX 1111
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
typedef pair<pair<int,int>,int> PIII;
typedef pair<int,int> PII;
int arr[222222][2];
int n;
int ans;
bool check(int x)
{
    for(int i=1; i<=n; i++)
    {
        if(x<1900&&arr[i][1]==1) return 1;
        if(x>=1900&&arr[i][1]==2) return 0;
        x+=arr[i][0];

    }
    return 1;
}
bool check1(int x)
{
    for(int i=1; i<=n; i++)
    {
        if(x<1900&&arr[i][1]==1) return 0;
        if(x>=1900&&arr[i][1]==2) return 0;
        x+=arr[i][0];

    }
    ans=x;
    return 1;
}
int erfeng(int l,int r)
{
    int mid;
    while(l<r)
    {
        //cout<<l<<" "<<r<<endl;
        mid=(l+r)/2+1;
        if(check(mid)) l=mid;
        else r=mid-1;
    }
    return l;

}
int main()
{
    //FIN;
    while(cin>>n)
    {
        for(int i=1; i<=n; i++) scanf("%d%d",&arr[i][0],&arr[i][1]);
        if(check(INF)) puts("Infinity");
        else
        {
            int t=erfeng(-21111111,21111111);
            if(check1(t)){
                   printf("%d\n",ans);
        }
                else puts("Impossible");
        }

    }
    return 0;
}


#include<map>
#include<set>
#include<stack>
#include<queue>
#include<string.h>
#include<cstring>
#include<vector>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3f
#define FIN freopen("input.txt","r",stdin)
#define mem(x,y) memset(x,y,sizeof(x))
typedef unsigned long long ULL;
typedef long long LL;
#define MX 1111
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
typedef pair<pair<int,int>,int> PIII;
typedef pair<int,int> PII;
int arr[222222][2];
int n;
int ans;
bool check(int x)
{
    for(int i=1; i<=n; i++)
    {
        if(x<1900&&arr[i][1]==1) return 1;
        if(x>=1900&&arr[i][1]==2) return 0;
        x+=arr[i][0];

    }
    return 1;
}
bool check1(int x)
{
    for(int i=1; i<=n; i++)
    {
        if(x<1900&&arr[i][1]==1) return 0;
        if(x>=1900&&arr[i][1]==2) return 0;
        x+=arr[i][0];

    }
    ans=x;
    return 1;
}
int erfeng(int l,int r)
{
    int mid;
    while(l<r)
    {
        //cout<<l<<" "<<r<<endl;
        mid=((l+r)>>1)+1;
        if(check(mid)) l=mid;
        else r=mid-1;
    }
    return l;

}
int main()
{
    //FIN;
    while(cin>>n)
    {
        for(int i=1; i<=n; i++) scanf("%d%d",&arr[i][0],&arr[i][1]);
        if(check(INF)) puts("Infinity");
        else
        {
            int t=erfeng(-INF,INF);
            if(check1(t)){
                   printf("%d\n",ans);
        }
                else puts("Impossible");
        }

    }
    return 0;
}


#include<map>
#include<set>
#include<iostream>
#include<stack>
#include<queue>
#include<string.h>
#include<cstring>
#include<vector>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3f
#define FIN freopen("input.txt","r",stdin)
#define mem(x,y) memset(x,y,sizeof(x))
typedef unsigned long long ULL;
typedef long long LL;
#define MX 1111
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
typedef pair<pair<int,int>,int> PIII;
typedef pair<int,int> PII;
int arr[222222][2];
int n;
int ans;
bool check(int x)
{
    for(int i=1; i<=n; i++)
    {
        if(x<1900&&arr[i][1]==1) return 1;
        if(x>=1900&&arr[i][1]==2) return 0;
        x+=arr[i][0];

    }
    return 1;
}
bool check1(int x)
{
    for(int i=1; i<=n; i++)
    {
        if(x<1900&&arr[i][1]==1) return 0;
        if(x>=1900&&arr[i][1]==2) return 0;
        x+=arr[i][0];

    }
    ans=x;
    return 1;
}
int erfeng(int l,int r)
{
    int mid;
    while(l<r)
    {
        //cout<<l<<" "<<r<<endl;
        mid=((l+r)>>1)+1;
        if(check(mid)) l=mid;
        else r=mid-1;
    }
    return l;

}
int main()
{
    //FIN;
    while(cin>>n)
    {
        for(int i=1; i<=n; i++) scanf("%d%d",&arr[i][0],&arr[i][1]);
        if(check(INF)) puts("Infinity");
        else
        {
            int t=erfeng(-INF,INF);//
            if(check1(t)){
                   printf("%d\n",ans);
        }
                else puts("Impossible");
        }

    }
    return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
#define INF 0x3f3f3f3f
typedef long long LL;
const LL MAX=2e5+5;
LL n;
LL flag;
struct Node
{
    LL c,d;
}a[MAX];
LL check(LL x)
{
    LL res=x;
    for(LL i=n-1;i>=0;i--)
    {
        res-=a[i].c;
        if(a[i].d==1&&res<1900) return 0;
        if(a[i].d==2&&res>=1900) return -1;
    }
    return 1;
}
LL solve(LL l,LL r)
{
    flag=0;
    LL mid;
    while(l<r)
    {
        mid=(r+l)/2+1;
        if(check(mid)>=0)l=mid;
        else r=mid-1;
    }
    if(check(l)==1) {flag=1;return l;}
    return -1;
}
int main()
{
    //freopen("input.txt","r",stdin);
    while(~scanf("%I64d",&n))
    {
        for(int i=0;i<n;i++)
            scanf("%I64d%I64d",&a[i].c,&a[i].d);
        LL t=solve(-INF,INF);
        if(flag==1)
        {
            if(t==INF)cout<<"Infinity"<<endl;
            else cout<<t<<endl;
        }
        else cout<<"Impossible"<<endl;
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<string.h>
#include<cstring>
#include<vector>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3f
#define FIN freopen("input.txt","r",stdin)
#define mem(x,y) memset(x,y,sizeof(x))
typedef unsigned long long ULL;
typedef long long LL;
#define MX 1111
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
typedef pair<pair<int,int>,int> PIII;
typedef pair<int,int> PII;
int arr[222222][2];
int n;
int ans;
bool check(int x)
{
    for(int i=1; i<=n; i++)
    {
        if(x<1900&&arr[i][1]==1) return 1;
        if(x>=1900&&arr[i][1]==2) return 0;
        x+=arr[i][0];

    }
    return 1;
}
bool check1(int x)
{
    for(int i=1; i<=n; i++)
    {
        if(x<1900&&arr[i][1]==1) return 0;
        if(x>=1900&&arr[i][1]==2) return 0;
        x+=arr[i][0];

    }
    ans=x;
    return 1;
}
int erfeng(int l,int r)
{
    int mid;
    while(l<r)
    {
        //cout<<l<<" "<<r<<endl;
        mid=((l+r)>>1)+1;
        if(check(mid)) l=mid;
        else r=mid-1;
    }
    return l;

}
int main()
{
    //FIN;
    while(cin>>n)
    {
        for(int i=1; i<=n; i++) scanf("%d%d",&arr[i][0],&arr[i][1]);
        if(check(INF)) puts("Infinity");
        else
        {
            int t=erfeng(-21111111,21111111);
            if(check1(t)){
                   printf("%d\n",ans);
        }
                else puts("Impossible");
        }

    }
    return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
#define INF 0x3f3f3f3F
typedef long long LL;
const int MAX=2e5+5;
int n;
int flag;
struct Node
{
    int c,d;
}a[MAX];
LL check(LL x)
{
    LL res=x;
    for(LL i=n-1;i>=0;i--)
    {
        res-=a[i].c;
        if(a[i].d==1&&res<1900) return 0;
        if(a[i].d==2&&res>=1900) return -1;
    }
    return 1;
}
LL solve(LL l,LL r)
{
    flag=0;
    LL mid;
    while(l<r)
    {
        mid=(r+l)/2+1;
        if(check(mid)>=0)l=mid;
        else r=mid-1;
    }
    if(check(l)==1) {flag=1;return l;}
    return -1;
}
int main()
{
    //freopen("input.txt","r",stdin);
    while(~scanf("%d",&n))
    {
        for(int i=0;i<n;i++)
            scanf("%d%d",&a[i].c,&a[i].d);
        LL t=solve(-INF,INF);
        if(flag==1)
        {
            if(t==INF)cout<<"Infinity"<<endl;
            else cout<<t<<endl;
        }
        else cout<<"Impossible"<<endl;
    }
    return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
#define INF 0x3f3f3f3f
typedef long long LL;
const int MAX=2e5+5;
int n;
int flag;
struct Node
{
    int c,d;
}a[MAX];
LL check(LL x)
{
    LL res=x;
    for(LL i=n-1;i>=0;i--)
    {
        res-=a[i].c;
        if(a[i].d==1&&res<1900) return 0;
        if(a[i].d==2&&res>=1900) return -1;
    }
    return 1;
}
LL solve(LL l,LL r)
{
    flag=0;
    LL mid;
    while(l<r)
    {
        mid=(r+l)/2+1;
        if(check(mid)>=0)l=mid;
        else r=mid-1;
    }
    if(check(l)==1) {flag=1;return l;}
    return -1;
}
int main()
{
    //freopen("input.txt","r",stdin);
    while(~scanf("%d",&n))
    {
        for(int i=0;i<n;i++)
            scanf("%d%d",&a[i].c,&a[i].d);
        LL t=solve(-INF,INF);
        if(flag==1)
        {
            if(t==INF)cout<<"Infinity"<<endl;
            else cout<<t<<endl;
        }
        else cout<<"Impossible"<<endl;
    }
    return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
#define INF 0x3f3f3f3f3f3f3f
typedef long long LL;
const int MAX=2e5+5;
int n;
int flag;
struct Node
{
    int c,d;
}a[MAX];
LL check(LL x)
{
    LL res=x;
    for(LL i=n-1;i>=0;i--)
    {
        res-=a[i].c;
        if(a[i].d==1&&res<1900) return 0;
        if(a[i].d==2&&res>=1900) return -1;
    }
    return 1;
}
LL solve(LL l,LL r)
{
    flag=0;
    LL mid;
    while(l<r)
    {
        mid=(r+l)/2+1;
        if(check(mid)>=0)l=mid;
        else r=mid-1;
    }
    if(check(l)==1) {flag=1;return l;}
    return -1;
}
int main()
{
    //freopen("input.txt","r",stdin);
    while(~scanf("%d",&n))
    {
        for(int i=0;i<n;i++)
            scanf("%d%d",&a[i].c,&a[i].d);
        LL t=solve(-INF,INF);
        if(flag==1)
        {
            if(t==INF)cout<<"Infinity"<<endl;
            else cout<<t<<endl;
        }
        else cout<<"Impossible"<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[200005];
int b[200005];
int n;
int ok(int m){
	for(int i=n-1;i>=0;i--){
		m-=a[i];
		if(m>=1900&&b[i]==2)return 0;
		if(m<=1899&&b[i]==1)return 2;
	}
	return 1;
}
int main(){
	scanf("%d",&n);
	int res=0;
	for(int i=0;i<n;i++){
		scanf("%d%d",&a[i],&b[i]);
		res+=a[i];
	}
	int l=-200000000,r=200000000;
	int ans=0;
	while(l<=r){
		int m=(l+r)/2;//printf("%d\n",m);
		int f=ok(m);
		if(f){
			l=m+1;
			if(f==1)
			ans=max(ans,m);
		}
		else{
			r=m-1;
		}
	}
	if(ans==0)printf("Impossible\n");
	else if(ans==200000000)printf("Infinity\n");
	else printf("%d\n",ans);

}


#include<bits/stdc++.h>
using namespace std;
int a[200005];
int b[200005];
int n;
int ok(int m){
	for(int i=0;i<n;i++){
		if(m>=1900&&b[i]==2)return 0;
		if(m<1900&&b[i]==1)return 2;
		m+=a[i];
	}
	return 1;

}
int main(){
	scanf("%d",&n);
	int res=0;
	for(int i=0;i<n;i++){
		scanf("%d%d",&a[i],&b[i]);
		res+=a[i];
	}
	int l=0,r=2000000;
	int ans=0;
	while(l<=r){
		int m=(l+r)/2;//printf("%d\n",m);
		int f=ok(m);
		if(f){
			l=m+1;
			if(f==1)
			ans=max(ans,m);
		}
		else {
			r=m-1;
		}
	}
	if(ans==0)printf("Impossible\n");
	else if(ans==2000000)printf("Infinity\n");
	else printf("%d\n",ans+res);
}


#include<bits/stdc++.h>
using namespace std;
int a[200005];
int b[200005];
int n;
int ok(int m){
	for(int i=0;i<n;i++){
		if(m>=1900&&b[i]==2)return 0;
		if(m<1900&&b[i]==1)return 1;
		m+=a[i];
	}
	return 1;

}
int main(){
	scanf("%d",&n);
	int res=0;
	for(int i=0;i<n;i++){
		scanf("%d%d",&a[i],&b[i]);
		res+=a[i];
	}
	int l=0,r=2000000;
	int ans=0;
	while(l<=r){
		int m=(l+r)/2;//printf("%d\n",m);

		if(ok(m)){
			l=m+1;
			ans=max(ans,m);
		}
		else {
			r=m-1;
		}
	}
	if(ans==0)printf("Impossible\n");
	else if(ans==2000000)printf("Infinity\n");
	else printf("%d\n",ans+res);
}


#include<bits/stdc++.h>
using namespace std;
int a[200005];
int b[200005];
int n;
int ok(int m){
	for(int i=n-1;i>=0;i--){
		m-=a[i];
		if(m>=1900&&b[i]==2)return 0;
		if(m<=1899&&b[i]==1)return 2;
	}
	return 1;
}
int main(){
	scanf("%d",&n);
	int res=0;
	for(int i=0;i<n;i++){
		scanf("%d%d",&a[i],&b[i]);
		res+=a[i];
	}
	int l=0,r=2000000;
	int ans=0;
	while(l<=r){
		int m=(l+r)/2;//printf("%d\n",m);
		int f=ok(m);
		if(f){
			l=m+1;
			if(f==1)
			ans=max(ans,m);
		}
		else{
			r=m-1;
		}
	}
	if(ans==0)printf("Impossible\n");
	else if(ans==2000000)printf("Infinity\n");
	else printf("%d\n",ans);

}


#include<bits/stdc++.h>
using namespace std;
int a[200005];
int b[200005];
int n;
int ok(int m){
	for(int i=0;i<n;i++){
		if(m>=1900&&b[i]==2)return 0;
		if(m<1900&&b[i]==1)return 2;
		m+=a[i];
	}
	return 1;

}
int main(){
	scanf("%d",&n);
	int res=0;
	for(int i=0;i<n;i++){
		scanf("%d%d",&a[i],&b[i]);
		res+=a[i];
	}
	int l=0,r=2000000;
	int ans=0;
	while(l<=r){
		int m=(l+r)/2;//printf("%d\n",m);
		int f=ok(m);
		if(f){
			l=m+1;
			if(f==1)
			ans=max(ans,m);
		}
		else {
			r=m-1;
		}
	}
	if(ans==0)printf("Impossible\n");
	else if(ans==2000000)printf("Infinity\n");
	else printf("%d\n",ans);
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
int a[200005],b[200005];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d%d",&a[i],&b[i]);
    }
    int l=0,r=20000000,tmp=0,flag=0;
    for(int i=0;i<n;i++)
    {
        if(b[i]==1)
        {
            l=max(l,1900-tmp);
        }
        else
        {
            r=min(r,1900-tmp);
            flag=1;
        }
        tmp+=a[i];
    }
   // printf("%d %d",l,r);
    if(!flag)
    {
        printf("Infinity\n");
    }
    else
    {
        if(r>l)
        printf("%d\n",r+tmp-1);
        else
        printf("Impossible\n");
    }

}


#include<bits/stdc++.h>
using namespace std;
int a[200005];
int b[200005];
int n;
int ok(int m){
	for(int i=n-1;i>=0;i--){
		m-=a[i];
		if(m>=1900&&b[i]==2)return 0;
		if(m<=1899&&b[i]==1)return 2;
	}
	return 1;
}
int main(){
	scanf("%d",&n);
	int res=0;
	for(int i=0;i<n;i++){
		scanf("%d%d",&a[i],&b[i]);
		res+=a[i];
	}
	int l=0,r=200000000;
	int ans=0;
	while(l<=r){
		int m=(l+r)/2;//printf("%d\n",m);
		int f=ok(m);
		if(f){
			l=m+1;
			if(f==1)
			ans=max(ans,m);
		}
		else{
			r=m-1;
		}
	}
	if(ans==0)printf("Impossible\n");
	else if(ans==200000000)printf("Infinity\n");
	else printf("%d\n",ans);

}


#include<bits/stdc++.h>
using namespace std;
int a[200005];
int b[200005];
int n;
int ok(int m){
	for(int i=0;i<n;i++){
		if(m>=1900&&b[i]==2)return 0;
		if(m<1900&&b[i]==1)return 2;
		m+=a[i];
	}
	return 1;

}
int main(){
	scanf("%d",&n);
	int res=0;
	for(int i=0;i<n;i++){
		scanf("%d%d",&a[i],&b[i]);
		res+=a[i];
	}
	int l=0,r=2000000;
	int ans=0,m;
	while(l<=r){
		m=(l+r)/2;//printf("%d\n",m);
		int f=ok(m);
		if(f){
			l=m+1;
			if(f==1)
			ans=max(ans,m);
		}
		else {
			r=m-1;
		}
	}
	if(m==0)printf("Impossible\n");
	else if(m==2000000)printf("Infinity\n");
	else printf("%d\n",ans+res);
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	scanf("%d",&n);
	int c,d,l=-1e9,r=1e9,f=1;
	for(int i=0;i<n;i++){
		scanf("%d%d",&c,&d);
		if(d==1){
			l=max(l,1900);
		}
		else {
			r=min(r,1899);
			f=0;
		}
		l+=c;
		r+=c;
	}
	if(f)printf("Infinity\n");
	else if(l>r)printf("Impossible\n");
	else printf("%d\n",r);
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll n,x=0,ans=0,one=0,two=0;
    cin>>n;
    ll rat[n+5],div[n+5];
    for(int i=1;i<=n;i++)
        cin>>rat[i]>>div[i];
        bool imp=false,inf=false;
    for(int i=1;i<=n;i++)
    {
        if(div[i]==1)
            one++;
        else two++;
        if(i<n)
        {
            if(rat[i]>=0&&div[i]==1&&div[i+1]==2)
            {
                imp=true;
            }
            if(rat[i]<=0&&div[i]==2&&div[i+1]==1)
                imp=true;
            if(imp)
            {
                cout<<"Impossible"<<endl;
                return 0;
            }
        }
    }
    if(one==n)
    {
        cout<<"Infinity"<<endl;
        return 0;
    }

  ll lo=-2e9,hi=2e9;
   /*  if(div[1]==1)
        lo=1900,hi=2e9;
    else lo=0,hi=1899;  */
    while(lo<hi)
    {

        ll mid=(lo+hi)/2;
        ll nr=mid;
      //  cout<<lo<<" "<<hi<<" "<<mid<<endl;
        bool f=true;
        for(int i=1;i<=n;i++)
        {
            if(nr>=1900&&div[i]==2)
               {
                   f=false;
                   hi=mid;
                   break;
               }
            else if(nr<1900&&div[i]==1)
                {
                    f=false;
                    lo=mid+1;
                    break;
                }

            nr+=rat[i];

        }
        if(f)
        {
            ans=nr;
            lo=mid+1;
        }

    }
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll n,x=0,ans=0,one=0,two=0;
    cin>>n;
    ll rat[n+5],div[n+5];
    for(int i=1;i<=n;i++)
        cin>>rat[i]>>div[i];
        bool imp=false,inf=false;
    for(int i=1;i<=n;i++)
    {
        if(div[i]==1)
            one++;
        else two++;
        if(i<n)
        {
            if(rat[i]>=0&&div[i]==1&&div[i+1]==2)
            {
                imp=true;
            }
            if(rat[i]<=0&&div[i]==2&&div[i+1]==1)
                imp=true;
            if(imp)
            {
                cout<<"Impossible"<<endl;
                return 0;
            }
        }
    }
    if(one==n)
    {
        cout<<"Infinity"<<endl;
        return 0;
    }

  ll lo=-2e9,hi=2e9;
    while(lo<hi)
    {
        if(x==150)
            break;
            x++;
        ll mid=(lo+hi)/2;
        ll nr=mid;
      //  cout<<lo<<" "<<hi<<" "<<mid<<endl;
        bool f=true;
        for(int i=1;i<=n;i++)
        {
            if(nr>=1900&&div[i]==2)
               {
                   f=false;
                   hi=mid;
                   //cout<<"inner of hi: "<<hi<<endl;
                   break;
               }
            else if(nr<1900&&div[i]==1)
                {
                    f=false;
                    lo=mid+1;
                     // cout<<"inner of lo: "<<lo<<endl;
                    break;
                }

            nr+=rat[i];

        }
        if(f)
        {
            ans=nr;
            lo=mid+1;
        }
   //  cout<<lo<<" "<<hi<<" "<<mid<<endl;
    }
    ll cc=lo-5;
     while(lo>cc)
    {
        bool f=true;
        ll nr=lo;
        for(int i=1;i<=n;i++)
        {
            if(nr<1900&&div[i]==1)
                f=false;
            else if(nr>=1900&&div[i]==2)
                f=false;
            nr+=rat[i];
        }
        if(f)
        {
            cout<<nr<<endl;
            return 0;
        }
        lo--;
    }
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll n,x=0,ans=0,one=0,two=0;
    cin>>n;
    ll rat[n+5],div[n+5];
    for(int i=1;i<=n;i++)
        cin>>rat[i]>>div[i];
        bool imp=false,inf=false;
    for(int i=1;i<=n;i++)
    {
        if(div[i]==1)
            one++;
        else two++;
        if(i<n)
        {
            if(rat[i]>=0&&div[i]==1&&div[i+1]==2)
            {
                imp=true;
            }
            if(rat[i]<=0&&div[i]==2&&div[i+1]==1)
                imp=true;
            if(imp)
            {
                cout<<"Impossible"<<endl;
                return 0;
            }
        }
    }
    if(one==n)
    {
        cout<<"Infinity"<<endl;
        return 0;
    }

  ll lo=-2e9,hi=2e9;
   /*  if(div[1]==1)
        lo=1900,hi=2e9;
    else lo=0,hi=1899;  */
    while(lo<hi)
    {

        ll mid=(lo+hi)/2;
        ll nr=mid;
      //  cout<<lo<<" "<<hi<<" "<<mid<<endl;
        bool f=true;
        for(int i=1;i<=n;i++)
        {
            if(nr>=1900&&div[i]==2)
               {
                   f=false;
                   hi=mid-1;
                   break;
               }
            else if(nr<1900&&div[i]==1)
                {
                    f=false;
                    lo=mid+1;
                    break;
                }

            nr+=rat[i];

        }
        if(f)
        {
            ans=nr;
            lo=mid+1;
        }
     //cout<<lo<<" "<<hi<<" "<<mid<<endl;
    }
    ll cc=lo-5;
    while(lo>cc)
    {
        bool f=true;
        ll nr=lo;
        for(int i=1;i<=n;i++)
        {
            if(nr<1900&&div[i]==1)
                f=false;
            else if(nr>=1900&&div[i]==2)
                f=false;
            nr+=rat[i];
        }
        if(f)
        {
            cout<<nr<<endl;
            return 0;
        }
    }
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll n,x=0,ans=0,one=0,two=0;
    cin>>n;
    ll rat[n+5],div[n+5];
    for(int i=1;i<=n;i++)
        cin>>rat[i]>>div[i];
        bool imp=false,inf=false,imp2=false;
    for(int i=1;i<=n;i++)
    {
        if(div[i]==1)
            one++;
        else two++;
        if(i<n)
        {
            if(rat[i]>=0&&div[i]==1&&div[i+1]==2)
            {
                imp=true;
            }
            if(rat[i]<=0&&div[i]==2&&div[i+1]==1)
                imp=true;
            if(imp)
            {
                cout<<"Impossible"<<endl;
                return 0;
            }
        }
    }
        if(div[1]==1)
       {

        ll sum=0;
        sum+=rat[1];
        for(int i=2;i<=n;i++)
        {

            if((sum>=0&&div[i]==2)||(sum<0&&div[i]==1))
            {
                cout<<"Impossible"<<endl;
                return 0;
            }
                sum+=rat[i];
        }
       }
       else
       {
        ll sum=0;
        sum+=rat[1];
        for(int i=2;i<=n;i++)
        {

            if((sum<=0&&div[i]==1))
            {
                cout<<"Impossible"<<endl;
                return 0;
            }
                sum+=rat[i];
        }

       }
    if(one==n)
    {
        cout<<"Infinity"<<endl;
        return 0;
    }

  ll lo=-2e9,hi=2e9;
    while(lo<hi)
    {
        if(x==150)
            break;
            x++;
        ll mid=(lo+hi)/2;
        ll nr=mid;
      //  cout<<lo<<" "<<hi<<" "<<mid<<endl;
        bool f=true;
        for(int i=1;i<=n;i++)
        {
            if(nr>=1900&&div[i]==2)
               {
                   f=false;
                   hi=mid;
                   //cout<<"inner of hi: "<<hi<<endl;
                   break;
               }
            else if(nr<1900&&div[i]==1)
                {
                    f=false;
                    lo=mid+1;
                     // cout<<"inner of lo: "<<lo<<endl;
                    break;
                }

            nr+=rat[i];

        }
        if(f)
        {
            ans=nr;
            lo=mid+1;
        }
   //  cout<<lo<<" "<<hi<<" "<<mid<<endl;
    }
    ll cc=lo-5;
     while(lo>cc)
    {
        bool f=true;
        ll nr=lo;
        for(int i=1;i<=n;i++)
        {
            if(nr<1900&&div[i]==1)
                f=false;
            else if(nr>=1900&&div[i]==2)
                f=false;
            nr+=rat[i];
        }
        if(f)
        {
            cout<<nr<<endl;
            return 0;
        }
        lo--;
    }
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll n,x=0,ans=0,one=0,two=0;
    cin>>n;
    ll rat[n+5],div[n+5];
    for(int i=1;i<=n;i++)
        cin>>rat[i]>>div[i];
        bool imp=false,inf=false,imp2=false;
    for(int i=1;i<=n;i++)
    {
        if(div[i]==1)
            one++;
        else two++;
        if(i<n)
        {
            if(rat[i]>=0&&div[i]==1&&div[i+1]==2)
            {
                imp=true;
            }
            if(rat[i]<=0&&div[i]==2&&div[i+1]==1)
                imp=true;
            if(imp)
            {
                cout<<"Impossible"<<endl;
                return 0;
            }
        }
    }
    if(div[1]==1)
    {
        ll sum=0;
        sum+=rat[1];
        for(int i=2;i<=n;i++)
        {

            if(sum>=0&&div[i]==2)
            {
                cout<<"Impossible"<<endl;
                return 0;
            }
                sum+=rat[i];
        }
    }
    if(one==n)
    {
        cout<<"Infinity"<<endl;
        return 0;
    }

  ll lo=-2e9,hi=2e9;
    while(lo<hi)
    {
        if(x==150)
            break;
            x++;
        ll mid=(lo+hi)/2;
        ll nr=mid;
      //  cout<<lo<<" "<<hi<<" "<<mid<<endl;
        bool f=true;
        for(int i=1;i<=n;i++)
        {
            if(nr>=1900&&div[i]==2)
               {
                   f=false;
                   hi=mid;
                   //cout<<"inner of hi: "<<hi<<endl;
                   break;
               }
            else if(nr<1900&&div[i]==1)
                {
                    f=false;
                    lo=mid+1;
                     // cout<<"inner of lo: "<<lo<<endl;
                    break;
                }

            nr+=rat[i];

        }
        if(f)
        {
            ans=nr;
            lo=mid+1;
        }
   //  cout<<lo<<" "<<hi<<" "<<mid<<endl;
    }
    ll cc=lo-5;
     while(lo>cc)
    {
        bool f=true;
        ll nr=lo;
        for(int i=1;i<=n;i++)
        {
            if(nr<1900&&div[i]==1)
                f=false;
            else if(nr>=1900&&div[i]==2)
                f=false;
            nr+=rat[i];
        }
        if(f)
        {
            cout<<nr<<endl;
            return 0;
        }
        lo--;
    }
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll n,x=0,ans=0,one=0,two=0;
    cin>>n;
    ll rat[n+5],div[n+5];
    for(int i=1;i<=n;i++)
        cin>>rat[i]>>div[i];
        bool imp=false,inf=false,imp2=false;
    for(int i=1;i<=n;i++)
    {
        if(div[i]==1)
            one++;
        else two++;
        if(i<n)
        {
            if(rat[i]>=0&&div[i]==1&&div[i+1]==2)
            {
                imp=true;
            }
            if(rat[i]<=0&&div[i]==2&&div[i+1]==1)
                imp=true;
            if(imp)
            {
                cout<<"Impossible"<<endl;
                return 0;
            }
        }
    }
        if(div[1]==1)
       {

        ll sum=0;
        sum+=rat[1];
        for(int i=2;i<=n;i++)
        {

            if((sum>=0&&div[i]==2))
            {
                cout<<"Impossible"<<endl;
                return 0;
            }
                sum+=rat[i];
        }
       }
       else
       {
        ll sum=0;
        sum+=rat[1];
        for(int i=2;i<=n;i++)
        {

            if((sum<=0&&div[i]==1))
            {
                cout<<"Impossible"<<endl;
                return 0;
            }
                sum+=rat[i];
        }

       }
    if(one==n)
    {
        cout<<"Infinity"<<endl;
        return 0;
    }

  ll lo=-2e9,hi=2e9;
    while(lo<hi)
    {
        if(x==150)
            break;
            x++;
        ll mid=(lo+hi)/2;
        ll nr=mid;
      //  cout<<lo<<" "<<hi<<" "<<mid<<endl;
        bool f=true;
        for(int i=1;i<=n;i++)
        {
            if(nr>=1900&&div[i]==2)
               {
                   f=false;
                   hi=mid;
                   //cout<<"inner of hi: "<<hi<<endl;
                   break;
               }
            else if(nr<1900&&div[i]==1)
                {
                    f=false;
                    lo=mid+1;
                     // cout<<"inner of lo: "<<lo<<endl;
                    break;
                }

            nr+=rat[i];

        }
        if(f)
        {
            ans=nr;
            lo=mid+1;
        }
   //  cout<<lo<<" "<<hi<<" "<<mid<<endl;
    }
    ll cc=lo-5;
     while(lo>cc)
    {
        bool f=true;
        ll nr=lo;
        for(int i=1;i<=n;i++)
        {
            if(nr<1900&&div[i]==1)
                f=false;
            else if(nr>=1900&&div[i]==2)
                f=false;
            nr+=rat[i];
        }
        if(f)
        {
            cout<<nr<<endl;
            return 0;
        }
        lo--;
    }
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll n,x=0,ans=0,one=0,two=0;
    cin>>n;
    ll rat[n+5],div[n+5];
    for(int i=1;i<=n;i++)
        cin>>rat[i]>>div[i];
        bool imp=false,inf=false,imp2=false;
    for(int i=1;i<=n;i++)
    {
        if(div[i]==1)
            one++;
        else two++;
        if(i<n)
        {
            if(rat[i]>=0&&div[i]==1&&div[i+1]==2)
            {
                imp=true;
            }
            if(rat[i]<=0&&div[i]==2&&div[i+1]==1)
                imp=true;
            if(imp)
            {
                cout<<"Impossible"<<endl;
                return 0;
            }
        }
    }

        ll sum=0;
        sum+=rat[1];
        for(int i=2;i<=n;i++)
        {

            if((sum>=0&&div[i]==2)||(sum<0&&div[i]==1))
            {
                cout<<"Impossible"<<endl;
                return 0;
            }
                sum+=rat[i];
        }
    if(one==n)
    {
        cout<<"Infinity"<<endl;
        return 0;
    }

  ll lo=-2e9,hi=2e9;
    while(lo<hi)
    {
        if(x==150)
            break;
            x++;
        ll mid=(lo+hi)/2;
        ll nr=mid;
      //  cout<<lo<<" "<<hi<<" "<<mid<<endl;
        bool f=true;
        for(int i=1;i<=n;i++)
        {
            if(nr>=1900&&div[i]==2)
               {
                   f=false;
                   hi=mid;
                   //cout<<"inner of hi: "<<hi<<endl;
                   break;
               }
            else if(nr<1900&&div[i]==1)
                {
                    f=false;
                    lo=mid+1;
                     // cout<<"inner of lo: "<<lo<<endl;
                    break;
                }

            nr+=rat[i];

        }
        if(f)
        {
            ans=nr;
            lo=mid+1;
        }
   //  cout<<lo<<" "<<hi<<" "<<mid<<endl;
    }
    ll cc=lo-5;
     while(lo>cc)
    {
        bool f=true;
        ll nr=lo;
        for(int i=1;i<=n;i++)
        {
            if(nr<1900&&div[i]==1)
                f=false;
            else if(nr>=1900&&div[i]==2)
                f=false;
            nr+=rat[i];
        }
        if(f)
        {
            cout<<nr<<endl;
            return 0;
        }
        lo--;
    }
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll n,x,y,z,rat,b;
    ll inf=3e9;
    ll lo=-inf,hi=inf;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>rat>>b;
        if(b==1)
            lo=max(1900LL,lo);
        else hi=min(1899LL,hi);
        lo+=rat;
        hi+=rat;
    }
    if(lo>hi)
        cout<<"Impossible"<<endl;
    else if(hi>1e9)
        cout<<"Infinity"<<endl;
        else
        cout<<hi<<endl;
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll n,x=0,ans=0,one=0,two=0;
    cin>>n;
    ll rat[n+5],div[n+5];
    for(int i=1;i<=n;i++)
        cin>>rat[i]>>div[i];
        bool imp=false,inf=false;
    for(int i=1;i<=n;i++)
    {
        if(div[i]==1)
            one++;
        else two++;
        if(i<n)
        {
            if(rat[i]>=0&&div[i]==1&&div[i+1]==2)
            {
                imp=true;
            }
            if(rat[i]<=0&&div[i]==2&&div[i+1]==1)
                imp=true;
            if(imp)
            {
                cout<<"Impossible"<<endl;
                return 0;
            }
        }
    }
    if(one==n)
    {
        cout<<"Infinity"<<endl;
        return 0;
    }

  ll lo=-2e9,hi=2e9;
   /*  if(div[1]==1)
        lo=1900,hi=2e9;
    else lo=0,hi=1899;  */
    while(lo<hi)
    {

        ll mid=(lo+hi)/2;
        ll nr=mid;
      //  cout<<lo<<" "<<hi<<" "<<mid<<endl;
        bool f=true;
        for(int i=1;i<=n;i++)
        {
            if(nr>=1900&&div[i]==2)
               {
                   f=false;
                   hi=mid-1;
                   break;
               }
            else if(nr<1900&&div[i]==1)
                {
                    f=false;
                    lo=mid+1;
                    break;
                }

            nr+=rat[i];

        }
        if(f)
        {
            ans=nr;
            lo=mid+1;
        }

    }
    cout<<ans<<endl;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <stack>
#include <ctime>
#include <unordered_map>
#include <unordered_set>
#pragma comment (linker, "/STACK:256000000")
#define ll long long int
#define pb push_back
#define x first
#define y second
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORR(i, a, b) for(int i = a; i>b; i--)
#define ri(x) scanf("%d", &x)
#define rl(x) scanf("%lld", &x)
using namespace std;
const int MAXN = 2e5+8;
ll indx[53];
char s[MAXN], t[MAXN];

int main(){
    scanf("%s",s); scanf("%s",t);
    int s1 = strlen(s); int s2 = strlen(t);
    FOR(i, 0, s2){
        if(t[i]>=65 && t[i]<= 90) indx[t[i] - 65 + 26]++;
        else if(t[i]>=97 && t[i]<= 122) indx[t[i] - 97]++;
    }
    ll l=0, w = 0;
    FOR(i, 0, s1){
        if(s[i] >=65 && s[i]<=90){
            if(indx[s[i] - 65+26]){
                l++;
                indx[s[i] - 65+26]--;
            }
            else if(indx[s[i]- 65]){
                w++;
                indx[s[i] - 65]--;
            }
        }
        else if(s[i]>=97 && s[i]<= 122){
            if(indx[s[i]- 97]){
                l++;
                indx[s[i] - 97]--;
            }
            else if(indx[s[i] - 97+26] ){
                w++;
                indx[s[i] - 97+26]--;
            }
        }
    }
    printf("%lld %lld",l,w);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <stack>
#include <ctime>
#include <unordered_map>
#include <unordered_set>
#pragma comment (linker, "/STACK:256000000")
#define ll long long int
#define pb push_back
#define x first
#define y second
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORR(i, a, b) for(int i = a; i>b; i--)
#define ri(x) scanf("%d", &x)
#define rl(x) scanf("%lld", &x)
using namespace std;
const int MAXN = 2e5+8;
ll indx[257];
char s[MAXN], t[MAXN];

int main(){
    scanf("%s",s); scanf("%s",t);
    int s1 = strlen(s); int s2 = strlen(t);
    FOR(i, 0, s2){
       indx[t[i]]++;
    }
    ll l=0, w = 0;
    FOR(i, 0, s1){
      	if(indx[s[i]]){
			l++;
			indx[s[i]]--;
		}
		if(s[i]<=90) s[i]+= 32;
		else s[i]-= 32;
		if(indx[s[i]]){
			w++;
			indx[s[i]]--;
		}
    }
    printf("%lld %lld",l,w);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <stack>
#include <ctime>
#include <unordered_map>
#include <unordered_set>
#pragma comment (linker, "/STACK:256000000")
#define ll long long int
#define pb push_back
#define x first
#define y second
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORR(i, a, b) for(int i = a; i>b; i--)
#define ri(x) scanf("%d", &x)
#define rl(x) scanf("%lld", &x)
using namespace std;
const int MAXN = 2e5+8;
int indx[53];
char s[MAXN], t[MAXN];

int main(){
    scanf("%s",s); scanf("%s",t);
    int s1 = strlen(s); int s2 = strlen(t);
    FOR(i, 0, s2){
        if(t[i]>=65 && t[i]<= 90) indx[t[i] - 65 + 26]++;
        else indx[t[i] - 97]++;
    }
    ll l=0, w = 0;
    FOR(i, 0, s1){
        if(s[i] >=65 && s[i]<=90){
            if(indx[s[i] - 65+26]){
                l++;
                indx[s[i] - 65+26]--;
            }
            else if(indx[s[i]- 65]){
                w++;
                indx[s[i] - 65]--;
            }
        }
        else if(s[i]>=97 && s[i]<= 122){
            if(indx[s[i]- 97]){
                l++;
                indx[s[i] - 97]--;
            }
            else if(indx[s[i] - 97+26] ){
                w++;
                indx[s[i] - 97+26]--;
            }
        }
    }
    printf("%lld %lld",l,w);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <stack>
#include <ctime>
#include <unordered_map>
#include <unordered_set>
#pragma comment (linker, "/STACK:256000000")
#define ll long long int
#define pb push_back
#define x first
#define y second
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORR(i, a, b) for(int i = a; i>b; i--)
#define ri(x) scanf("%d", &x)
#define rl(x) scanf("%lld", &x)
using namespace std;
const int MAXN = 2e5+8;
ll indx[257];
char s[MAXN], t[MAXN];
bool vis[MAXN];

int main(){
    scanf("%s",s); scanf("%s",t);
    int s1 = strlen(s); int s2 = strlen(t);
    FOR(i, 0, s2){
       indx[t[i]]++;
    }
    ll l=0, w = 0;
    FOR(i, 0, s1){
      	if(indx[s[i]]){
			l++;
			indx[s[i]]--;
			vis[i] = true;
		}
    }
	FOR(i, 0, s1){
		if( vis[i]) continue;
		if(s[i]>='a' )
			s[i] += -'a' + 'A';
		else
			s[i] += -'A' + 'a';
		if(indx[s[i]]){
			w++;
			indx[s[i]]--;
		}
	}
    printf("%lld %lld",l,w);
    return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define x first
#define y second
#define FOR(i, a, b) for(int i=a;i<b;i++)
#define FORR(i, a, b) for(int i = a;i>b; i—-)
#define ri(x) scanf("%d", &x);
#define rl(x) scanf("%lld", &x)
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vc;
const int INF = 2e6;
const ll LINF = 8e18;
const int MOD = 1e9 + 7;
const ld EPS = 1e-9;

string S, T;
int FT[INF], yay, whoop;
bool SK[INF];

int main(){
    cin>>S;
    cin>>T;
    FOR(i, 0, T.size()) FT[T[i]] = 0;
    FOR(i, 0, T.size()) FT[T[i]]++;
    FOR(i, 0, S.size()) SK[i] = 0;
    FOR(i, 0, S.size()) if(FT[S[i]] > 0){
        yay++;
        FT[S[i]]--;
        SK[i] =1;
    }
    FOR(i, 0, S.size())
        if(!SK[i] && max(FT[S[i] +'A' -'a'],FT[S[i] + 'a' - 'A']) > 0){
            whoop++;
            FT[S[i]]--;
        }
    printf("%d %d", yay, whoop);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <stack>
#include <ctime>
#include <unordered_map>
#include <unordered_set>
#pragma comment (linker, "/STACK:256000000")
#define ll long long int
#define pb push_back
#define x first
#define y second
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORR(i, a, b) for(int i = a; i>b; i--)
#define ri(x) scanf("%d", &x)
#define rl(x) scanf("%lld", &x)
using namespace std;
const int MAXN = 2e6+8;
int indx[53];
char s[MAXN], t[MAXN];

int main(){
    scanf("%s",s); scanf("%s",t);
    int s1 = strlen(s); int s2 = strlen(t);
    FOR(i, 0, s2){
        if(t[i]>=65 && t[i]<= 90) indx[t[i] - 65 + 26]++;
        else indx[t[i] - 97]++;
    }
    ll l=0, w = 0;
    FOR(i, 0, s1){
        if(s[i] >=65 && s[i]<=90){
            if(indx[s[i] - 65+26]){
                l++;
                indx[s[i] - 65+26]--;
            }
            else if(indx[s[i]- 65]){
                w++;
                indx[s[i] - 65]--;
            }
        }
        else{
            if(indx[s[i]- 97]){
                l++;
                indx[s[i] - 97]--;
            }
            else if(indx[s[i] - 97+26] ){
                w++;
                indx[s[i] - 97+26]--;
            }
        }
    }
    printf("%lld %lld",l,w);
    return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define x first
#define y second
#define FOR(i, a, b) for(int i=a;i<b;i++)
#define FORR(i, a, b) for(int i = a;i>b; i—-)
#define ri(x) scanf("%d", &x);
#define rl(x) scanf("%lld", &x)
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vc;
const int INF = 2e6;
const ll LINF = 8e18;
const int MOD = 1e9 + 7;
const ld EPS = 1e-9;

string S, T;
int FT[INF], yay, whoop;
bool SK[INF];

int main(){
    cin>>S;
    cin>>T;
    FOR(i, 0, T.size()) FT[T[i]] = 0;
    FOR(i, 0, T.size()) FT[T[i]]++;
    FOR(i, 0, S.size()) SK[i] = 0;
    FOR(i, 0, S.size()) if(FT[S[i]] > 0){
        yay++;
        FT[S[i]]--;
        SK[i] =1;
    }
    FOR(i, 0, S.size())
        if(!SK[i] && FT[S[i] +'A' -'a']>0){
            whoop++;
            FT[S[i] + 'A' - 'a']--;
        }
        else if(!SK[i] && FT[S[i] +'a' -'A']>0){
            whoop++;
            FT[S[i] + 'a' - 'A']--;
        }
    printf("%d %d", yay, whoop);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <stack>
#include <ctime>
#include <unordered_map>
#include <unordered_set>
#pragma comment (linker, "/STACK:256000000")
#define ll long long int
#define pb push_back
#define x first
#define y second
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORR(i, a, b) for(int i = a; i>b; i--)
#define ri(x) scanf("%d", &x)
#define rl(x) scanf("%lld", &x)
using namespace std;
const int MAXN = 2e5+8;
ll indx[257];
char s[MAXN], t[MAXN];

int main(){
    scanf("%s",s); scanf("%s",t);
    int s1 = strlen(s); int s2 = strlen(t);
    FOR(i, 0, s2){
       indx[t[i]]++;
    }
    ll l=0, w = 0;
    FOR(i, 0, s1){
      	if(indx[s[i]]){
			l++;
			indx[s[i]]--;
			continue;
		}
		if(s[i]<=90) s[i]+= 32;
		else s[i]-= 32;
		if(indx[s[i]]){
			w++;
			indx[s[i]]--;
		}
    }
    printf("%lld %lld",l,w);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <stack>
#include <ctime>
#include <unordered_map>
#include <unordered_set>
#pragma comment (linker, "/STACK:256000000")
#define ll long long int
#define pb push_back
#define x first
#define y second
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORR(i, a, b) for(int i = a; i>b; i--)
#define ri(x) scanf("%d", &x)
#define rl(x) scanf("%lld", &x)
using namespace std;
const int MAXN = 2e5+8;
int indx[53];
char s[MAXN], t[MAXN];

int main(){
    scanf("%s",s); scanf("%s",t);
    int s1 = strlen(s); int s2 = strlen(t);
    FOR(i, 0, s2){
        if(t[i]>=65 && t[i]<= 90) indx[t[i] - 65 + 26]++;
        else if(t[i]>=97 && t[i]<= 122) indx[t[i] - 97]++;
    }
    ll l=0, w = 0;
    FOR(i, 0, s1){
        if(s[i] >=65 && s[i]<=90){
            if(indx[s[i] - 65+26]){
                l++;
                indx[s[i] - 65+26]--;
            }
            else if(indx[s[i]- 65]){
                w++;
                indx[s[i] - 65]--;
            }
        }
        else if(s[i]>=97 && s[i]<= 122){
            if(indx[s[i]- 97]){
                l++;
                indx[s[i] - 97]--;
            }
            else if(indx[s[i] - 97+26] ){
                w++;
                indx[s[i] - 97+26]--;
            }
        }
    }
    printf("%lld %lld",l,w);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <stack>
#include <ctime>
#include <unordered_map>
#include <unordered_set>
#pragma comment (linker, "/STACK:256000000")
#define ll long long int
#define pb push_back
#define x first
#define y second
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORR(i, a, b) for(int i = a; i>b; i--)
#define ri(x) scanf("%d", &x)
#define rl(x) scanf("%lld", &x)
using namespace std;
const int MAXN = 2e5+8;
int indx[53];
char s[MAXN], t[MAXN];

int main(){
    scanf("%s",s); scanf("%s",t);
    int s1 = strlen(s); int s2 = strlen(t);
    FOR(i, 0, s2){
        if(t[i]>=65 && t[i]<= 90) indx[t[i] - 65 + 26]++;
        else if(s[i]>=97 && s[i]<= 122) indx[t[i] - 97]++;
    }
    ll l=0, w = 0;
    FOR(i, 0, s1){
        if(s[i] >=65 && s[i]<=90){
            if(indx[s[i] - 65+26]){
                l++;
                indx[s[i] - 65+26]--;
            }
            else if(indx[s[i]- 65]){
                w++;
                indx[s[i] - 65]--;
            }
        }
        else if(s[i]>=97 && s[i]<= 122){
            if(indx[s[i]- 97]){
                l++;
                indx[s[i] - 97]--;
            }
            else if(indx[s[i] - 97+26] ){
                w++;
                indx[s[i] - 97+26]--;
            }
        }
    }
    printf("%lld %lld",l,w);
    return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define x first
#define y second
#define FOR(i, a, b) for(int i=a;i<b;i++)
#define FORR(i, a, b) for(int i = a;i>b; i—-)
#define ri(x) scanf("%d", &x);
#define rl(x) scanf("%lld", &x)
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vc;
const int INF = 2e6;
const ll LINF = 8e18;
const int MOD = 1e9 + 7;
const ld EPS = 1e-9;

string S, T;
int FT[INF], yay, whoop;
bool SK[INF];

int main(){
    cin>>S;
    cin>>T;
    FOR(i, 0, T.size()) FT[T[i]] = 0;
    FOR(i, 0, T.size()) FT[T[i]]++;
    FOR(i, 0, S.size()) SK[i] = 0;
    FOR(i, 0, S.size()) if(FT[S[i]] > 0){
        yay++;
        FT[S[i]]--;
        SK[i] =1;
    }
    FOR(i, 0, S.size())
        if(!SK[i] && FT[S[i] +'A' -'a'] > 0){
            whoop++;
            FT[S[i]]--;
            SK[i] = 1;
        }
        else if(!SK[i] && FT[S[i]] + 'a' - 'A' > 0){
            whoop++;
            FT[S[i]]--;
            SK[i] = 1;
        }
    printf("%d %d", yay, whoop);
    return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define x first
#define y second
#define FOR(i, a, b) for(int i=a;i<b;i++)
#define FORR(i, a, b) for(int i = a;i>b; i—-)
#define ri(x) scanf("%d", &x);
#define rl(x) scanf("%lld", &x)
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vc;
const int INF = 2e6;
const ll LINF = 8e18;
const int MOD = 1e9 + 7;
const ld EPS = 1e-9;

string S, T;
int FT[INF], yay, whoop;
bool SK[INF];

int main(){
    cin>>S;
    cin>>T;
    FOR(i, 0, T.size()) FT[T[i]] = 0;
    FOR(i, 0, T.size()) FT[T[i]]++;
    FOR(i, 0, S.size()) SK[i] = 0;
    FOR(i, 0, S.size()) if(FT[S[i]] > 0){
        yay++;
        FT[S[i]]--;
        SK[i] =1;
    }
    FOR(i, 0, S.size())
        if(!SK[i] && max(FT[S[i] +'A' -'a'],FT[S[i]] + 'a' - 'A') > 0){
            whoop++;
            FT[S[i]]--;
        }
    printf("%d %d", yay, whoop);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int ans=0,mk[10005];

int main() {
    ios_base::sync_with_stdio(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    string s,t,ns="";
    cin >> s >> t;
    int n=s.size();
    for (int i(0); i<n; i++){
        mk[s[i]]++;
    }
    for (int i(0); i<t.size(); i++){
        if (mk[t[i]]>0) {
            ans++;
            mk[t[i]]--;
        }
    }
    cout << ans << " " << t.size()-ans << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int ans=0,mk[10005],an=0;

int main() {
    ios_base::sync_with_stdio(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    string s,t,ns="";
    cin >> s >> t;
    swap(s,t);
    for (int i(0); i<s.size(); i++){
        mk[s[i]]++;
    }
    for (int i(0); i<t.size(); i++){
        if (mk[t[i]]>0) {
            ans++;
            mk[t[i]]--;
        }
        else an++;
    }
    cout << ans << " " << an << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int ans=0,mk[10005];

int main() {
    ios_base::sync_with_stdio(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    string s,t,ns="";
    cin >> s >> t;
    swap(s,t);
    int n=s.size();
    for (int i(0); i<n; i++){
        mk[s[i]]++;
    }
    for (int i(0); i<t.size(); i++){
        if (mk[t[i]]>0) {
            ans++;
            mk[t[i]]--;
        }
    }
    cout << ans << " " << t.size()-ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define NN 200020
char s[NN],t[NN];
int cnt[400],ans[400];
int main() {
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	cin>>s>>t;
	int tot=0,cc=0;
	int lena=strlen(s);
	int lenb=strlen(t);
	for(int i=0;i<lena;i++){
		int c=s[i]-'0';
		cnt[c]++;
	}
	for(int i=0;i<lenb;i++){
		int c=t[i]-'0';
		ans[c]++;
	}
	for(int i=0;i<lena;i++){
		int c=s[i]-'0';
		if(s[i]>='a'){
			if(ans[c-32]>0) cc++,ans[c-32]--,cnt[c]--;
			else if(ans[c]>0) tot++,ans[c]--,cnt[c]--;
		}
		else {
			if(ans[c+32]>0) cc++,ans[c+32]--,cnt[c]--;
			else if(ans[c]>0) tot++,ans[c]--,cnt[c]--;
		}
	}

	cout<<tot<<' '<<cc<<endl;

	return 0;
}


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

typedef long long INT;

char s[NN], t[NN];

int cnt1[60], cnt2[60];

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	cin>>s>>t;
	int L1 = strlen(s);
	for(int i = 0; i < L1; i++)
		cnt1[s[i] - 'A']++;
	int L2 = strlen(t);
	for(int i = 0; i < L2; i++)
		cnt2[t[i] - 'A']++;

	int ans = 0;
	for(int i = 0; i < 60; i++){
		if(cnt1[i] == 0) continue;
		ans += min(cnt1[i], cnt2[i]);
	}
	cout<<ans<<" "<<L1 - ans<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define NN 200020
char s[NN],t[NN];
int cnt[400],ans[400];
int main() {
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	cin>>s>>t;
	int tot=0;
	int lena=strlen(s);
	int lenb=strlen(t);
	for(int i=0;i<lena;i++){
		int c=s[i]-'0';
		cnt[c]++;
	}
	for(int i=0;i<lenb;i++){
		int c=t[i]-'0';
		ans[c]++;
	}
	for(int i=0;i<300;i++){
		if(cnt[i]){
			tot+=min(cnt[i],ans[i]);
		}
	}
	lena-=tot;
	cout<<tot<<' '<<lena<<endl;

	return 0;
}


#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define pb push_back
#define sq(x) ((x)*(x))
#define x first
#define y second
#define eps 1e-9
#define bpt(x) (__builtin_popcount(x))
#define bptl(x) (__builtin_popcountll(x))
#define bit(x, y) (((x)>>(y))&1)
#define bclz(x) (__builtin_clz(x))
#define bclzl(x) (__builtin_clzll(x))
#define bctz(x) (__builtin_ctz(x))
#define bctzl(x) (__builtin_ctzll(x))
#define sgn(x) (((x)>eps)-((x)<-eps))
#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;
typedef long long INT;
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef pair<pii, int> pi3;
typedef double DO;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}
template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

template<class T>inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}
template<class T, class T1>inline void gn(T &x, T1 &y) {gn(x); gn(y);}
template<class T, class T1, class T2>inline void gn(T &x, T1 &y, T2 &z) {gn(x); gn(y); gn(z);}
template<class T>inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}
template<class T>inline void printsp(T x) {print(x); putchar(' ');}
template<class T>inline void println(T x) {print(x); putchar('\n');}
template<class T, class U>inline void print(T x, U y) {printsp(x); println(y);}
template<class T, class U, class V>inline void print(T x, U y, V z) {printsp(x); printsp(y); println(z);}

int power(int a, int b, int m, int ans=1) {
	for (; b; b>>=1, a=1LL*a*a%m) if (b&1) ans=1LL*ans*a%m;
	return ans;
}
char a[200100],b[200200];
int n[30],N[30],fl[200200];
int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	cin>>a>>b;
	int n1=strlen(a);
	int n2=strlen(b);
	for(int i=0;i<n1;i++){
		if(a[i]>='a' and a[i]<='z') n[a[i]-'a']++;
		else N[a[i]-'A']++;
	}
	int A=0,B=0;
	for(int i=0;i<n2;i++){
		if(b[i]>='a' and b[i]<='z'){
			if(n[b[i]-'a']) A++,n[b[i]-'a']--,fl[i]=1;
		}
		else {
			if(N[b[i]-'A']) A++,N[b[i]-'A']--,fl[i]=1;
		}
	}
	for(int i=0;i<n2;i++){
		if(fl[i]) continue;
		if(b[i]>='a' and b[i]<='z'){
			if(N[b[i]-'a']) B++,N[b[i]-'a']--;
		}
		else {
			if(n[b[i]-'A']) B++,n[b[i]-'A']--;
		}
	}
	cout<<A<<' '<<B<<endl;
	return 0;
}


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

using namespace std;

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

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

char s[NN],t[NN];
int ps[1111],pt[1111];

main(){
#ifndef ONLINE_JUDGE
freopen("in.in","r",stdin);
#endif
	cin>>s>>t;
	int ns=strlen(s);
	int nt=strlen(s);

	for(int i=0;i<ns;i++){
		ps[s[i]-'A']++;
	}

	for(int i=0;i<nt;i++){
		pt[t[i]-'A']++;
	}

	int ans=0;
	for(int i=0;i<1110;i++){
		ans+=min(ps[i],pt[i]);
	}

	cout<<ans<<" "<<nt-ans<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define NN 200020
char s[NN],t[NN];
int cnt[400],ans[400];
int main() {
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	cin>>s>>t;
	int tot=0;
	int lena=strlen(s);
	int lenb=strlen(t);
	for(int i=0;i<lena;i++){
		int c=s[i]-'0';
		cnt[c]++;
	}
	for(int i=0;i<lenb;i++){
		int c=t[i]-'0';
		ans[c]++;
	}
	for(int i=0;i<lena;i++){
		int c=s[i]-'0';
		if(ans[c]>0) tot++,ans[c]--;
		else break;
	}
	cout<<tot<<' '<<lena-tot<<endl;

	return 0;
}


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

using namespace std;
typedef long long INT;
typedef pair<int, int> pii;

#define NN 200010
char s[NN], t[NN];
int cnt[1000];

int main () {
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out","w",stdout);
#endif
	//ios_base::sync_with_stdio(0); cin.tie(0);
	cin>>s>>t;
	int lent=strlen(t);
	for (int i=0; i<lent; i++) cnt[t[i]]++;
	int lens=strlen(s);
	int Y=0, W=0;
	for (int i=0; i<lens; i++) {
		if (cnt[s[i]]) {
			cnt[s[i]]--, Y++;
		}
		else W++;
	}
	printf("%d %d\n", Y, W);
	return 0;
}


#include<bits/stdc++.h>

#define bul __builtin_clz
#define NN 200100

using namespace std;

typedef long long INT;

char s[NN],t[NN];

int cnt1[30],cnt2[30],tmp1[30],tmp2[30];

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	cin>>s>>t;
	int n=strlen(s),m=strlen(t);
	for(int i=0;i<n;i++){
		if(s[i]>='a')cnt1[s[i]-'a']++;
		else cnt2[s[i]-'A']++;
	}

	for(int i=0;i<m;i++){
		if(t[i]>='a')tmp1[t[i]-'a']++;
		else tmp2[t[i]-'A']++;
	}
	int ans=0;
	for(int i=0;i<26;i++){
		ans+=min(cnt1[i],tmp1[i]);
		ans+=min(cnt2[i],tmp2[i]);
		int x=min(cnt1[i],tmp1[i]);
		int y=min(cnt2[i],tmp2[i]);
		cnt1[i]-=x;
		tmp1[i]-=x;
		cnt2[i]-=y;
		tmp2[i]-=y;
	}

	int t=0;
	for(int i=0;i<26;i++){
		if(cnt1[i]){
			t+=min(cnt1[i],tmp2[i]);
		}
		else if(cnt2[i]){
			t+=min(cnt2[i],tmp1[i]);
		}
	}
	printf("%d %d\n",ans,t);

	return 0;
}


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

typedef long long INT;

char s[NN], t[NN];

int cnt1[60], cnt2[60];

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	cin>>s>>t;
	int L1 = strlen(s);
	for(int i = 0; i < L1; i++)
		cnt1[s[i] - 'A']++;
	int L2 = strlen(t);
	for(int i = 0; i < L2; i++)
		cnt2[t[i] - 'A']++;

	int ans = 0;
	for(int i = 0; i < 26; i++){
		ans += min(cnt1[i], cnt2[i + 32]);
	}
	for(int i = 32; i < 60; i++){
		ans += min(cnt1[i], cnt2[i - 32]);
	}
	cout<<L1 - ans<<" "<<ans<<endl;
	return 0;
}


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

using namespace std;

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

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

char s[NN],t[NN];
int ps[1111],pt[1111];

main(){
#ifndef ONLINE_JUDGE
freopen("in.in","r",stdin);
#endif
	cin>>s>>t;
	int ns=strlen(s);
	int nt=strlen(s);

	for(int i=0;i<ns;i++){
		ps[s[i]-'A']++;
	}

	for(int i=0;i<nt;i++){
		pt[s[i]-'A']++;
	}

	int ans=0;
	for(int i=0;i<1110;i++){
		ans+=min(ps[i],pt[i]);
	}

	cout<<ans<<" "<<nt-ans<<endl;
	return 0;
}


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

using namespace std;

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

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

char s[NN],t[NN];
int ps[1111],pt[1111];

main(){
#ifndef ONLINE_JUDGE
freopen("in.in","r",stdin);
#endif
	cin>>s>>t;
	int ns=strlen(s);
	int nt=strlen(t);

	for(int i=0;i<ns;i++){
		ps[s[i]-'A']++;
	}

	for(int i=0;i<nt;i++){
		pt[t[i]-'A']++;
	}

	int ans=0;
	for(int i=0;i<1110;i++){
		ans+=min(ps[i],pt[i]);
	}

	cout<<ans<<" "<<ns-ans<<endl;
	return 0;
}


#include <bits/stdc++.h>

#define x first
#define y second
#define mod 1000000007
#define pb push_back
#define inf 0x3f3f3f3f
#define bclz(x) (__builtin_clz(x))
#define bctz(x) (__builtin_ctz(x))

using namespace std;

typedef long long INT;
typedef pair<int, int> pii;
typedef pair<pii, int> pi3;
typedef double DO;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}
template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

template<typename T> inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}
template<class T, class T1>inline void gn(T &x, T1 &y) {gn(x); gn(y);}
template<class T, class T1, class T2>inline void gn(T &x, T1 &y, T2 &z) {gn(x); gn(y); gn(z);}
template<typename T> inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}
template<typename T> inline void println(T x) {print(x), putchar('\n');}
template<typename T> inline void printsp(T x) {print(x), putchar(' ');}
template<class T, class T1> inline void print(T x, T1 y) {printsp(x), println(y);}
template<class T, class T1, class T2> inline void print(T x, T1 y, T2 z) {printsp(x), printsp(y), println(z);}

int power(int a, int b, int m, int ans=1) {
	for (; b; b>>=1, a=1LL*a*a%m) if (b&1) ans=1LL*ans*a%m;
	return ans;
}

#define NN 200010

char s[NN], t[NN];
int cs[NN], ct[NN];

int main () {
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out","w",stdout);
#endif
	cin>>s>>t;
	int lens=strlen(s), lent=strlen(t);
	for (int i=0; i<lens; i++) cs[s[i]]++;
	for (int i=0; i<lent; i++) ct[t[i]]++;

	int ansA=0, ansB=0;
	for (int i=0; i<26; i++) {
		int resa=min(ct[i+'a'], cs[i+'a']);
		ansA+=resa, ct[i+'a']-=resa, cs[i+'a']-=resa;
		int resA=min(ct[i+'A'], cs[i+'A']);
		ansA+=resA, ct[i+'A']-=resA, cs[i+'A']-=resA;
	}

	int aa;
	for (int i=0; i<26; i++) {
		aa=min(cs[i+'a'], ct[i+'A']);
		ansB+=aa, cs[i+'a']-=aa, ct[i+'A']-=aa;
		aa=min(cs[i+'A'], ct[i+'a']);
		ansB+=aa, cs[i+'A']-=aa, ct[i+'a']-=aa;
	}
	print(ansA, ansB);
	return 0;
}


#include<bits/stdc++.h>

#define bul __builtin_clz
#define NN 200100

using namespace std;

typedef long long INT;

char s[NN],t[NN];

int cnt1[30],cnt2[30],tmp1[30],tmp2[30];

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	cin>>s>>t;
	int n=strlen(s),m=strlen(t);
	for(int i=0;i<n;i++){
		if(s[i]>='a')cnt1[s[i]-'a']++;
		else cnt2[s[i]-'A']++;
	}
	for(int i=0;i<m;i++){
		if(t[i]>='a')tmp1[t[i]-'a']++;
		else tmp2[t[i]-'A']++;
	}
	int ans=0;
	for(int i=0;i<26;i++){
		ans+=min(cnt1[i],tmp1[i]);
		cnt1[i]-=min(cnt1[i],tmp1[i]);
		tmp1[i]-=min(cnt1[i],tmp1[i]);
	}
	for(int i=0;i<26;i++){
		ans+=min(cnt2[i],tmp2[i]);
		cnt2[i]-=min(cnt2[i],tmp2[i]);
		tmp2[i]-=min(cnt2[i],tmp2[i]);
	}

	int t=0;
	for(int i=0;i<26;i++){
		if(cnt1[i]){
			t+=min(cnt1[i],tmp2[i]);
		}
		if(cnt2[i]){
			t+=min(cnt2[i],tmp1[i]);
		}
	}
	printf("%d %d\n",ans,t);

	return 0;
}


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

using namespace std;

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

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

char s[NN],t[NN];
int cnt[1111];
int vst[NN];

main(){
#ifndef ONLINE_JUDGE
freopen("in.in","r",stdin);
#endif
	cin>>s>>t;
	int ns=strlen(s);
	int nt=strlen(t);

	for(int i=0;i<nt;i++){
		cnt[t[i]-'A']++;
	}

	int ans1=0,ans2=0;
	for(int i=0;i<ns;i++){
		if(cnt[s[i]-'A']){
			cnt[s[i]-'A']--;
			vst[i]=1;
			ans1++;
		}
	}

	for(int i=0;i<ns;i++){
		if(vst[i])continue;
		if(islower(s[i]))s[i]-=32;
		else s[i]+=32;
		if(cnt[s[i]-'A']){
			cnt[s[i]-'A']--;
			ans2++;
		}
	}

	cout<<ans1<<" "<<ans2<<endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define NN 200020
char s[NN],t[NN];
int cnt[400],ans[400];
int main() {
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	cin>>s>>t;
	int tot=0,cc=0;
	int lena=strlen(s);
	int lenb=strlen(t);
	for(int i=0;i<lena;i++){
		int c=s[i]-'0';
		cnt[c]++;
	}
	for(int i=0;i<lenb;i++){
		int c=t[i]-'0';
		ans[c]++;
	}
	for(int i=0;i<lena;i++){
		int c=s[i]-'0';
		if(s[i]>='a'){
			if(ans[c-32]>0) cc++,ans[c-32]--,cnt[c]--;
			else tot++,ans[c]--,cnt[c]--;
		}
		else {
			if(ans[c+32]>0) cc++,ans[c+32]--,cnt[c]--;
			else tot++,ans[c]--,cnt[c]--;
		}
	}

	cout<<tot<<' '<<cc<<endl;

	return 0;
}


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

using namespace std;
typedef long long INT;
typedef pair<int, int> pii;

#define NN 200010
char s[NN], t[NN];
int cnt[1000], flag[NN];

int main () {
#ifndef ONLINE_JUDGE
	freopen("in.in",  "r", stdin);
	freopen("out.out", "w",stdout);
#endif
	//ios_base::sync_with_stdio(0); cin.tie(0);
	cin>>s>>t;
	int lent=strlen(t);
	for (int i=0; i<lent; i++) cnt[t[i]]++;
	int lens=strlen(s);
	int y=0, w=0;
	for (int i=0; i<lens; i++) if (cnt[s[i]]) y++, cnt[s[i]]--, flag[i]=1;
	for (int i=0; i<lens; i++) {
		if (flag[i]) continue;
		if (isupper(s[i]) and cnt[s[i]+32]) cnt[s[i]+32]--, w++;
		if (islower(s[i]) and cnt[s[i]-32]) cnt[s[i]-32]--, w++;
	}
	printf("%d %d\n", y, w);
	return 0;
}


#include<bits/stdc++.h>

#define bul __builtin_clz
#define NN 200100

using namespace std;

typedef long long INT;

char s[NN],t[NN];

int cnt1[30],cnt2[30],tmp1[30],tmp2[30];

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	cin>>s>>t;
	int n=strlen(s),m=strlen(t);
	for(int i=0;i<n;i++){
		if(s[i]>='a')cnt1[s[i]-'a']++;
		else cnt2[s[i]-'A']++;
	}
	for(int i=0;i<m;i++){
		if(t[i]>='a')tmp1[t[i]-'a']++;
		else tmp2[t[i]-'A']++;
	}
	int ans=0;
	for(int i=0;i<26;i++)ans+=min(cnt1[i],tmp1[i]);
	for(int i=0;i<26;i++)ans+=min(cnt2[i],tmp2[i]);

	printf("%d %d\n",ans,n-ans);

	return 0;
}


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

typedef long long INT;

char s[NN], t[NN];

int cnt1[60], cnt2[60];

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	cin>>s>>t;
	int L1 = strlen(s);
	for(int i = 0; i < L1; i++)
		cnt1[s[i] - 'A']++;
	int L2 = strlen(t);
	for(int i = 0; i < L2; i++)
		cnt2[t[i] - 'A']++;
	int ans1 = 0, ans2 = 0;
	for(int i = 0; i < 60; i++){
		int temp = min(cnt1[i], cnt2[i]);
		ans1 += temp;
		cnt1[i] -= temp;
		cnt2[i] -= temp;
	}
	for(int i = 0; i < 26; i++){
		int temp = min(cnt1[i], cnt2[i + 32]);
		ans2 += temp;
	}
	for(int i = 32; i < 60; i++){
		int temp = min(cnt1[i], cnt2[i - 32]);
		ans2 += temp;
	}
	cout<<ans1<<" "<<ans2<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define NN 200020
char s[NN],t[NN];
int cnt[400],ans[400];
int main() {
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	cin>>s>>t;
	int tot=0,cc=0;
	int lena=strlen(s);
	int lenb=strlen(t);
	for(int i=0;i<lena;i++){
		int c=s[i]-'0';
		cnt[c]++;
	}
	for(int i=0;i<lenb;i++){
		int c=t[i]-'0';
		ans[c]++;
	}
	for(int i=0;i<lena;i++){
		int c=s[i]-'0';
		if(ans[c]>0) tot++,ans[c]--,cnt[c]--;
	}
	for(int i=0;i<lena;i++){
		int c=s[i]-'0';
		if(cnt[c]){
			if(s[i]>='a'){
				if(ans[c-32]) cc++,ans[c-32]--;
			}
			else {
				if(ans[c+32]) cc++,ans[c+32]--;
			}
		}
	}
	cout<<tot<<' '<<cc<<endl;

	return 0;
}


#include<bits/stdc++.h>

using namespace std;
#define NN 210000

char s[NN],t[NN];

int cs[70],ct[70];

int main (){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	cin>>s>>t;
	int l=strlen(s),k=strlen(t);
	for(int i=0;i<l;i++)cs[s[i] - 'A']++;
	for(int j=0;j<k;j++)ct[t[j]-'A']++;
	int x=0,y=0;
	for(int i=0;i<=60;i++)x+=min(cs[i],ct[i]);
	y=l-x;
	cout<<x<<" "<<y<<endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll n,t = 0,c = 0,m = 0;
    string s,s1;
    char ch,ch1;

    cin>>s>>s1;

    map<char,ll>p;
    map<char,ll>q;

    for(int i = 0; i < s1.size(); i++)
    {
        p[s1[i]]++;
    }

    for(int i = 0; i < s.size(); i++)
    {
        if(p[s[i]] >= 1)
        {
            c++;
            p[s[i]]--;
        }
        else
        {
              m++;
        }
    }

    cout<<c<<" "<<m<<endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll n,t = 0,c = 0,m = 0;
    string s,s1;
    char ch,ch1;

    cin>>s>>s1;

    map<char,ll>p;
    map<char,ll>q;

    for(int i = 0; i < s.size(); i++)
    {
        p[s[i]]++;
        q[s[i]]++;
    }

    for(int i = 0; i < s1.size(); i++)
    {
        if(p[s1[i]] >= 1)
        {
            c++;
            p[s1[i]]--;
        }
    }

    for(int i = 0; i < s1.size(); i++)
    {
        ch = toupper(s1[i]);
        ch1 = tolower(s1[i]);

        if(ch!=s1[i])
        {
            if(q[ch] >= 1)
            {
                m++;
                q[ch]--;
            }
        }
        else if(ch1!=s1[i])
        {
            if(q[ch1] >= 1)
            {
                m++;
                q[ch1]--;
            }
        }
    }

    cout<<c<<" "<<m<<endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll n,t = 0,c = 0,m = 0;
    string s,s1;
    char ch,ch1;

    cin>>s>>s1;

    map<char,ll>p;
    map<char,ll>q;

    for(int i = 0; i < s.size(); i++)
    {
        p[s[i]]++;
    }

    for(int i = 0; i < s1.size(); i++)
    {
        ch = toupper(s1[i]);
        ch1 = tolower(s1[i]);

        if(p[s1[i]] >= 1)
        {
            c++;
            p[s1[i]]--;
        }
        else
        {
            if(p[ch] >= 1)
            {
                m++;
                //p[ch]--;
            }
            else if(p[ch1] >= 1)
            {
                m++;
                //p[ch1]--;
            }
        }
    }

    cout<<c<<" "<<m<<endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll n,t = 0,c = 0,m = 0;
    string s,s1;
    char ch,ch1;

    cin>>s>>s1;

    map<char,ll>p;
    map<char,ll>q;

    for(int i = 0; i < s1.size(); i++)
    {
        if(s1[i] >= 'a' && s1[i] <= 'z')
        {
            p[s1[i]]++;
        }
        else
        {
            q[s1[i]]++;
        }

    }

    for(int i = 0; i < s.size(); i++)
    {
        if(s[i] >= 'a' && s[i] <= 'z')
        {
            if(p[s[i]] >= 1)
            {
                c++;
                p[s[i]]--;
            }
            else
            {
                m++;
            }
        }
        else
        {
            if(q[s[i]] >= 1)
            {
                c++;
                q[s[i]]--;
            }
            else
            {
                m++;
            }
        }
    }

    cout<<c<<" "<<m<<endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll n,t = 0,c = 0,m = 0;
    string s,s1;
    char ch,ch1;

    cin>>s>>s1;

    map<char,ll>p;
    map<char,ll>q;

    for(int i = 0; i < s1.size(); i++)
    {
        p[s1[i]]++;
    }

    for(int i = 0; i < s.size(); i++)
    {
        ch = toupper(s[i]);
        ch1 = tolower(s[i]);

        if(p[s[i]] >= 1)
        {
            c++;
            p[s[i]]--;
        }
        else
        {
            if(p[ch] >= 1)
            {
                m++;
                //p[ch]--;
            }
            else if(p[ch1] >= 1)
            {
                m++;
                //p[ch1]--;
            }
        }
    }

    cout<<c<<" "<<m<<endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll n,t = 0,c = 0,m = 0;
    string s,s1;
    char ch,ch1;

    cin>>s>>s1;

    map<char,ll>p;
    map<char,ll>q;

    for(int i = 0; i < s1.size(); i++)
    {
        p[s1[i]]++;
    }

    for(int i = 0; i < s.size(); i++)
    {
        ch = toupper(s[i]);
        ch1 = tolower(s[i]);

        if(p[s[i]] >= 1)
        {
            c++;
            p[s[i]]--;
        }
        else
        {
            if(p[ch] >= 1)
            {
                m++;
                p[ch]--;
            }
            else if(p[ch1] >= 1)
            {
                m++;
                p[ch1]--;
            }
        }
    }

    cout<<c<<" "<<m<<endl;
}


#include<bits/stdc++.h>
#include<string>
using namespace std;
string a,b;
int cnt[256],ans,x;
char f(char c)
{
	if (c>='a'&&c<='z') return c-'a'+'A';
	else return c-'A'+'a';
}
int main()
{
	cin>>a>>b;
	for (int i=0;i<b.size();i++)
		cnt[b[i]]++;
	for (int i=0;i<a.size();i++)
		if (cnt[a[i]])cnt[a[i]]--,ans++,a[i]=233;
	cout<<ans;
	ans=0;
	for (int i=0;i<a.size();i++)
		if (a[i]!=233&&cnt[f(a[i])]) cnt[f(a[i])]--,ans++;
	cout<<' '<<ans;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace __gnu_pbds;
using namespace __gnu_cxx;
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the iterator to kth largest element.(0-based)
typedef long long int lli;
#define pb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pair<int,int>>
#define vc vector<char>
#define vs vector<string>
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define fastio	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
/*-------CONSTANTS------- */
const int MAXN = 1000005;
const int SQRTN = 1003;
const int LOGN = 22;
const double PI=acos(-1);
const int INF = 1000000000;
const int MOD = 1000000007;
const int FMOD = 998244353;
const double eps = 1e-9;
/*-----------------------------MATH STUFF----------------------------- */
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
int mod_neg(int a, int b, int c){int res;if(abs(a-b)<c)res=a-b;else res=(a-b)%c;return(res<0?res+c:res);}
int mulmod(int a, int b, int c){lli res=(lli)a*b;return(res>=c?res%c:res);}
template<typename T>T power_mod(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mulmod(x,p,m);p=mulmod(p,p,m);n>>=1;}return x;}
template<typename T>T extended_euclid(T a, T b, T &x, T &y){T xx=0,yy=1;y=0;x=1;while(b){T q=a/b,t=b;b=a%b;a=t;\
t=xx;xx=x-q*xx;x=t;t=yy;yy=y-q*yy;y=t;}return a;}
template<typename T>T mod_inverse(T a, T n){T x,y,z=0;T d=extended_euclid(a,n,x,y);return(d>1?-1:mod_neg(x,z,n));}
//Factorials upto 1e5%MOD,nCr%MOD,nPr%MOD
lli fact[100000+5],fact_modinv[100000+5];
void fact_init(){
    fact[0] = 1ll;
    fact_modinv[0] = mod_inverse(fact[0],1ll*MOD);
    for(int i = 1;i<=100000;i++){
        fact[i] = mulmod(fact[i-1],i,1ll*MOD);
        fact_modinv[i] = mod_inverse(fact[i],1ll*MOD);
    }
}
lli choose(int n,int r){
    return mulmod(fact_modinv[n-r],mulmod(fact[n],fact_modinv[r],MOD),MOD);
}
lli P(int n,int r){
    return mulmod(fact[n],fact_modinv[n-r],1ll*MOD);
}
/*-----------------------------START----------------------------- */

string s,t;
unordered_map<char,int> cnt;
int main(){
    fastio;
    cin>>s>>t;

    for(auto x: t)
        cnt[x]++;

    int cnt1 = 0,cnt2 = 0;
    for(auto x : s){
        if(cnt[x] > 0){
            cnt[x]--;
            cnt1++;
        }
    }

    for(auto x : s){
        char ch = x;
        if(x >= 'A' && x <= 'Z'){
            ch += 32;
        }else{
            ch -= 32;
        }
        if(cnt[ch] > 0){
            cnt[ch]--;
            cnt2++;
        }
    }

    cout<<cnt1<<" "<<cnt2<<endl;

    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace __gnu_pbds;
using namespace __gnu_cxx;
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the iterator to kth largest element.(0-based)
typedef long long int lli;
#define pb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pair<int,int>>
#define vc vector<char>
#define vs vector<string>
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define fastio	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
/*-------CONSTANTS------- */
const int MAXN = 1000005;
const int SQRTN = 1003;
const int LOGN = 22;
const double PI=acos(-1);
const int INF = 1000000000;
const int MOD = 1000000007;
const int FMOD = 998244353;
const double eps = 1e-9;
/*-----------------------------MATH STUFF----------------------------- */
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
int mod_neg(int a, int b, int c){int res;if(abs(a-b)<c)res=a-b;else res=(a-b)%c;return(res<0?res+c:res);}
int mulmod(int a, int b, int c){lli res=(lli)a*b;return(res>=c?res%c:res);}
template<typename T>T power_mod(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mulmod(x,p,m);p=mulmod(p,p,m);n>>=1;}return x;}
template<typename T>T extended_euclid(T a, T b, T &x, T &y){T xx=0,yy=1;y=0;x=1;while(b){T q=a/b,t=b;b=a%b;a=t;\
t=xx;xx=x-q*xx;x=t;t=yy;yy=y-q*yy;y=t;}return a;}
template<typename T>T mod_inverse(T a, T n){T x,y,z=0;T d=extended_euclid(a,n,x,y);return(d>1?-1:mod_neg(x,z,n));}
//Factorials upto 1e5%MOD,nCr%MOD,nPr%MOD
lli fact[100000+5],fact_modinv[100000+5];
void fact_init(){
    fact[0] = 1ll;
    fact_modinv[0] = mod_inverse(fact[0],1ll*MOD);
    for(int i = 1;i<=100000;i++){
        fact[i] = mulmod(fact[i-1],i,1ll*MOD);
        fact_modinv[i] = mod_inverse(fact[i],1ll*MOD);
    }
}
lli choose(int n,int r){
    return mulmod(fact_modinv[n-r],mulmod(fact[n],fact_modinv[r],MOD),MOD);
}
lli P(int n,int r){
    return mulmod(fact[n],fact_modinv[n-r],1ll*MOD);
}
/*-----------------------------START----------------------------- */

string s,t;
unordered_map<char,int> cnt;
int main(){
    fastio;
    cin>>s>>t;

    for(auto x: t)
        cnt[x]++;

    int cnt1 = 0,cnt2 = 0;
    for(auto x : s){
        char ch = x;
        if((x-'A') >= 0 && (x-'A') < 26){
            ch += 32;
        }else{
            ch -= 32;
        }

        if(cnt[x] > 0){
            cnt[x]--;
            cnt1++;
        }else if(cnt[ch] > 0){
            cnt[ch]--;
            cnt2++;
        }
    }

    cout<<cnt1<<" "<<cnt2<<endl;

    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace __gnu_pbds;
using namespace __gnu_cxx;
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the iterator to kth largest element.(0-based)
typedef long long int lli;
#define pb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pair<int,int>>
#define vc vector<char>
#define vs vector<string>
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define fastio	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
/*-------CONSTANTS------- */
const int MAXN = 1000005;
const int SQRTN = 1003;
const int LOGN = 22;
const double PI=acos(-1);
const int INF = 1000000000;
const int MOD = 1000000007;
const int FMOD = 998244353;
const double eps = 1e-9;
/*-----------------------------MATH STUFF----------------------------- */
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
int mod_neg(int a, int b, int c){int res;if(abs(a-b)<c)res=a-b;else res=(a-b)%c;return(res<0?res+c:res);}
int mulmod(int a, int b, int c){lli res=(lli)a*b;return(res>=c?res%c:res);}
template<typename T>T power_mod(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mulmod(x,p,m);p=mulmod(p,p,m);n>>=1;}return x;}
template<typename T>T extended_euclid(T a, T b, T &x, T &y){T xx=0,yy=1;y=0;x=1;while(b){T q=a/b,t=b;b=a%b;a=t;\
t=xx;xx=x-q*xx;x=t;t=yy;yy=y-q*yy;y=t;}return a;}
template<typename T>T mod_inverse(T a, T n){T x,y,z=0;T d=extended_euclid(a,n,x,y);return(d>1?-1:mod_neg(x,z,n));}
//Factorials upto 1e5%MOD,nCr%MOD,nPr%MOD
lli fact[100000+5],fact_modinv[100000+5];
void fact_init(){
    fact[0] = 1ll;
    fact_modinv[0] = mod_inverse(fact[0],1ll*MOD);
    for(int i = 1;i<=100000;i++){
        fact[i] = mulmod(fact[i-1],i,1ll*MOD);
        fact_modinv[i] = mod_inverse(fact[i],1ll*MOD);
    }
}
lli choose(int n,int r){
    return mulmod(fact_modinv[n-r],mulmod(fact[n],fact_modinv[r],MOD),MOD);
}
lli P(int n,int r){
    return mulmod(fact[n],fact_modinv[n-r],1ll*MOD);
}
/*-----------------------------START----------------------------- */

multiset<char> pq;
string s,t;

int main(){
    fastio;
    cin>>s>>t;
    for(auto x : t){
        pq.insert(x);
    }
    int cnt1 = 0,cnt2 = 0;

    for(auto x : s){
        char ch = x;
        if((x - 'A') >=0 && (x - 'A') < 26){
            ch += 32;
        }else{
            ch -= 32;
        }
        if(pq.find(x) != pq.end()){
            cnt1++;
            pq.erase(pq.find(x));
        }else if(pq.find(ch) != pq.end()){
            cnt2++;
            pq.erase(pq.find(ch));
        }
    }

    cout<<cnt1<<" "<<cnt2<<endl;

    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace __gnu_pbds;
using namespace __gnu_cxx;
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the iterator to kth largest element.(0-based)
typedef long long int lli;
#define pb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pair<int,int>>
#define vc vector<char>
#define vs vector<string>
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define fastio	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
/*-------CONSTANTS------- */
const int MAXN = 1000005;
const int SQRTN = 1003;
const int LOGN = 22;
const double PI=acos(-1);
const int INF = 1000000000;
const int MOD = 1000000007;
const int FMOD = 998244353;
const double eps = 1e-9;
/*-----------------------------MATH STUFF----------------------------- */
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
int mod_neg(int a, int b, int c){int res;if(abs(a-b)<c)res=a-b;else res=(a-b)%c;return(res<0?res+c:res);}
int mulmod(int a, int b, int c){lli res=(lli)a*b;return(res>=c?res%c:res);}
template<typename T>T power_mod(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mulmod(x,p,m);p=mulmod(p,p,m);n>>=1;}return x;}
template<typename T>T extended_euclid(T a, T b, T &x, T &y){T xx=0,yy=1;y=0;x=1;while(b){T q=a/b,t=b;b=a%b;a=t;\
t=xx;xx=x-q*xx;x=t;t=yy;yy=y-q*yy;y=t;}return a;}
template<typename T>T mod_inverse(T a, T n){T x,y,z=0;T d=extended_euclid(a,n,x,y);return(d>1?-1:mod_neg(x,z,n));}
//Factorials upto 1e5%MOD,nCr%MOD,nPr%MOD
lli fact[100000+5],fact_modinv[100000+5];
void fact_init(){
    fact[0] = 1ll;
    fact_modinv[0] = mod_inverse(fact[0],1ll*MOD);
    for(int i = 1;i<=100000;i++){
        fact[i] = mulmod(fact[i-1],i,1ll*MOD);
        fact_modinv[i] = mod_inverse(fact[i],1ll*MOD);
    }
}
lli choose(int n,int r){
    return mulmod(fact_modinv[n-r],mulmod(fact[n],fact_modinv[r],MOD),MOD);
}
lli P(int n,int r){
    return mulmod(fact[n],fact_modinv[n-r],1ll*MOD);
}
/*-----------------------------START----------------------------- */

string s,t;
unordered_map<char,int> cnt;
int main(){
    fastio;
    cin>>s>>t;

    for(auto x: t)
        cnt[x]++;

    int cnt1 = 0,cnt2 = 0;
    for(auto x : s){
        if(cnt[x] > 0){
            cnt[x]--;
            cnt1++;
        }
    }

    for(auto x : s){
        char ch = x;
        if((x-'A') >= 0 && (x-'A') < 26){
            ch += 32;
        }else{
            ch -= 32;
        }
        if(cnt[ch] > 0){
            cnt[ch]--;
            cnt2++;
        }
    }

    cout<<cnt1<<" "<<cnt2<<endl;

    return 0;
}