stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include<vector>

#include<map>

#include<algorithm>

#include<cstring>

#include<cstdio>

#define INF 1<<28

using namespace std;



int sx, sy, gx, gy;

typedef pair < int, int > P;

vector < P > p[5];

int memo[5][5][1111];

int a, b;



int solve(int k, int t, int q){



  if(k == 4) return abs(p[t][q].first-gx) + abs(p[t][q].second-gy);

  if(memo[k][t][q]) return memo[k][t][q];



  int ans = INF, d = (t+1)%5, s;

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

    if(!k) s = abs(sx-p[d][i].first) + abs(sy-p[d][i].second);

    else s = abs(p[t][q].first-p[d][i].first) + abs(p[t][q].second-p[d][i].second);

    ans = min(ans, solve(k+1, d, i) + s);

  }



  return memo[k][t][q] = ans;

}



int main(){



  int w,h;

  char c;



  while(true){

    scanf("%d %d", &w, &h);

    if(!w && !h) break;



    for(int i=0;i<5;i++) p[i].clear();

    

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

      for(int j=0;j<w;j++){

	scanf(" %c", &c);

	if(c == 'S') sx = j, sy = i;

	if(c == 'G') gx = j, gy = i;

	else if(c != '.') p[c-'1'].push_back(P(j,i));

      }

    }

    

    b = INF;

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

      memset(memo, 0, sizeof(memo));

      if(b > solve(0,i,0)) a = i, b = solve(0,i,0);

    }



    if(b == INF) printf("NA\n");

    else printf("%d %d\n", a+1, b);



  }

}

// Optimized solution to the same problem (faster):
#include<algorithm>

#include<cstring>

#include<cstdio>

#define INF 1<<28

using namespace std;



int sx, sy, gx, gy;

int dx[5][1111], dy[5][1111], dn[5];

int memo[5][5][1111];

int a, b;



int solve(int k, int t, int q){



  if(k == 4) return abs(dx[t][q]-gx) + abs(dy[t][q]-gy);

  if(memo[k][t][q]) return memo[k][t][q];



  int ans = INF, d = (t+1)%5, s;

  for(int i=0;i<dn[d];i++){

    if(!k) s = abs(sx-dx[d][i]) + abs(sy-dy[d][i]);

    else s = abs(dx[t][q]-dx[d][i]) + abs(dy[t][q]-dy[d][i]);

    ans = min(ans, solve(k+1, d, i) + s);

  }



  return memo[k][t][q] = ans;

}



int main(){



  int w,h;

  char c;



  while(true){

    scanf("%d %d", &w, &h);

    if(!w && !h) break;



    memset(dn, 0, sizeof(dn));



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

      for(int j=0;j<w;j++){

	scanf(" %c", &c);

	if(c == 'S') sx = j, sy = i;

	else if(c == 'G') gx = j, gy = i;

	else if(c != '.') dx[c-'1'][dn[c-'1']] = j, dy[c-'1'][dn[c-'1']] = i, dn[c-'1']++;

      }

    }

    

    b = INF;

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

      memset(memo, 0, sizeof(memo));

      if(b > solve(0,i,0)) a = i, b = solve(0,i,0);

    }



    if(b == INF) printf("NA\n");

    else printf("%d %d\n", a+1, b);



  }

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<vector>

#include<map>

#include<algorithm>

#include<cstring>

#define INF 1<<28

#define F first

#define S second

using namespace std;

 



typedef pair < int, int > P;

vector < P > p[5];

int sx, sy, gx, gy;

int memo[5][5][1111];



int solve(int k, int t, int q){

  

  if(k == 4) return abs(p[t][q].F-gx) + abs(p[t][q].S-gy);

  if(~memo[k][t][q]) return memo[k][t][q];

  

  int ans = INF, d = (t+1)%5, c;

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

    c = k?abs(p[t][q].F-p[d][i].F) + abs(p[t][q].S-p[d][i].S):abs(sx-p[d][i].F) + abs(sy-p[d][i].S);

    ans = min(ans, solve(k+1, d, i) + c);

  }

 

  return memo[k][t][q] = ans;

}

 

int main(){

 

  int w, h;

  char c;

 

  while(cin >> w >> h, w){

 

    for(int i=0;i<5;i++) p[i].clear();

     

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

      for(int j=0;j<w;j++){

	cin >> c;

	if(c == '.') continue;

	else if(c == 'S') sx = j, sy = i;

	else if(c == 'G') gx = j, gy = i;

	else  p[c-'1'].push_back( P(j,i) );

      }

    }

    

    P q = P(0, INF);

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

      memset(memo, -1, sizeof(memo));

      if(q.S > solve(0,i,0)) q.F = i+1, q.S = solve(0,i,0);

    }

    

    if(q.S == INF) cout << "NA\n";

    else cout << q.F << " " << q.S << endl;

    

  }

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<vector>

#include<map>

#include<algorithm>

#include<cstring>

#define INF 1<<28

#define F first

#define S second

using namespace std;



typedef pair < int, int > P;

vector < P > v[5];

int sx, sy, gx, gy;

int memo[5][5][1111];

 

int dist(P a, P b){

  return abs(a.F - b.F) + abs(a.S - b.S);

}

 

 

int solve(int cnt, int now, int idx){

  

  if(cnt == 4) return dist(v[now][idx], P(gx, gy));

  if(~memo[cnt][now][idx]) return memo[cnt][now][idx];

  

  int ans = INF, next = (now+1)%5, cost;

  for(int i=0;i<v[next].size();i++){

    cost = cnt?dist(v[now][idx], v[next][i]):dist(P(sx, sy), v[next][i]);

    ans = min(ans, solve(cnt+1, next, i) + cost);

  }

  

  return memo[cnt][now][idx] = ans;

}

  

int main(){

  

  int w, h;

  char c;

  

  while(scanf("%d %d", &w, &h), w){

     

    for(int i=0;i<5;i++) v[i].clear();

     

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

      for(int j=0;j<w;j++){

	scanf(" %c", &c);

	if(c == '.') continue;

	else if(c == 'S') sx = j, sy = i;

	else if(c == 'G') gx = j, gy = i;

	else v[c-'1'].push_back( P(j,i) );

      }

    }

     

    int a, b = INF;

    memset(memo, -1, sizeof(memo));

    for(int i=0;i<5;i++) if(b > solve(0,i,0)) a = i+1, b = solve(0,i,0);

  

    b == INF?puts("NA"):printf("%d %d\n", a, b);

  

  }

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <string>

#include <cstring>

#include <algorithm>





using namespace std;



int main()

{

    string s,t,ch;

    int a,b;

    cin>>s>>t;

    cin>>a>>b;

    cin>>ch;

    if(ch==s)

        a--;

    else if(ch==t)

        b--;

    cout<<a<<" "<<b;

    return 0;

}


// Optimized solution to the same problem (faster):
#include<stdio.h>

int main()

{

  int A,B;

  char S[10],T[10],U[10];

  scanf("%s %s\n%d %d\n%s",S,T,&A,&B,U);



  if(*S==*U)

  {

    printf("%d %d\n", A-1, B);

  }

  else if(*T==*U)

  {

    printf("%d %d\n", A,B-1);

  }

  return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

using namespace std;

int main() {

    string S,T,U;

    int A,B;

    cin >>S>>T;

    cin>>A>>B;

    cin>>U;

    if (S==U){

        A-=1;

    } else if (T==U){

        B-=1;

    }

    cout<<A<<" "<<B;

    return 0;

}


// Optimized solution to the same problem (faster):
#include<stdio.h>

int main()

{

  int A,B;

  char S[10],T[10],U[10];

  scanf("%s %s\n%d %d\n%s",S,T,&A,&B,U);



  if(*S==*U)

  {

    printf("%d %d\n", A-1, B);

  }

  else if(*T==*U)

  {

    printf("%d %d\n", A,B-1);

  }

  return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<cmath>

#include<string>

using namespace std;

int main(){

string x,s,e; cin>>x>>s;

int a,b; cin>>a>>b;

cin>>e;

if(x == e){

    a-=1;

}

else{

    b-=1;

}

cout<<a<<" "<<b;

}


// Optimized solution to the same problem (faster):
#include<stdio.h>

int main()

{

  int A,B;

  char S[10],T[10],U[10];

  scanf("%s %s\n%d %d\n%s",S,T,&A,&B,U);



  if(*S==*U)

  {

    printf("%d %d\n", A-1, B);

  }

  else if(*T==*U)

  {

    printf("%d %d\n", A,B-1);

  }

  return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

using namespace std;

int main(){

    string s,t,u;

    int a,b;

    cin>>s;

    cin >>t;

    cin>>a;

    cin>>b;

    cin>>u;

    if (u==s){

        a--;

        cout<<a<<' '<<b;

    } else if (u==t){

        b--;

        cout<<a<<' '<<b;

    }



    return 0;

}


// Optimized solution to the same problem (faster):
#include<stdio.h>

int main()

{

  int A,B;

  char S[10],T[10],U[10];

  scanf("%s %s\n%d %d\n%s",S,T,&A,&B,U);



  if(*S==*U)

  {

    printf("%d %d\n", A-1, B);

  }

  else if(*T==*U)

  {

    printf("%d %d\n", A,B-1);

  }

  return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

using namespace std;



int main()

{

    string s,t,u;

    int a,b;

    cin >> s >> t;

    cin >> a >> b;

    cin >> u;



    if(u == s){

        a--;

    }

    else if(u == t){

        b--;

    }



    cout << a << " " << b;

    return 0

    ;

}


// Optimized solution to the same problem (faster):
#include<stdio.h>

int main()

{

  int A,B;

  char S[10],T[10],U[10];

  scanf("%s %s\n%d %d\n%s",S,T,&A,&B,U);



  if(*S==*U)

  {

    printf("%d %d\n", A-1, B);

  }

  else if(*T==*U)

  {

    printf("%d %d\n", A,B-1);

  }

  return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<string>

using namespace std;

int main ()

{

    string s;

    string t;

    int a,b;

    string u;

    cin>>s>>t;

    cin>>a>>b;

    cin>>u;

    if(u==s)

        cout<<a-1<<" "<<b<<endl;

    else if (u==t)

        cout<<a<<" "<<b-1<<endl;

    return 0;

}


// Optimized solution to the same problem (faster):
#include<stdio.h>

int main()

{

  int A,B;

  char S[10],T[10],U[10];

  scanf("%s %s\n%d %d\n%s",S,T,&A,&B,U);



  if(*S==*U)

  {

    printf("%d %d\n", A-1, B);

  }

  else if(*T==*U)

  {

    printf("%d %d\n", A,B-1);

  }

  return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;

using ll = long long;

using P = pair<int, int>;

 

int main(){

	string s, t, u;

  	int a, b;

  	cin >> s >> t >> a >> b >> u;

  

  	if(u == s) a--;

  	else b--;

  	cout << a << " " << b << endl;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

int main()

{

  int A,B;

  char S[10],T[10],U[10];

  scanf("%s %s\n%d %d\n%s",S,T,&A,&B,U);



  if(*S==*U)

  {

    printf("%d %d\n", A-1, B);

  }

  else if(*T==*U)

  {

    printf("%d %d\n", A,B-1);

  }

  return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>



using namespace std;



int main()

{

    string x,y,z;

    int x1,y1;

    cin>>x>>y;

    cin>>x1>>y1;

    cin>>z;

    if(z==x){x1--;}

    else if(z==y){y1--;}

    cout<<x1<<" "<<y1<<endl;

    return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<string.h>





int main(){

	char S[25];

	char T[25];

	char U[25];

	int A;

	int B;

	

	scanf ("%s %s",&S,&T);

	scanf("%d %d",&A,&B);

	scanf("%s",&U);

	

	if (strcmp(S,U) ==0){

		A--;

		printf("%d %d",A,B);

		

	}

	else if (strcmp(T,U) ==0){

		

		B--;

		printf("%d %d",A,B);

	}

	

	

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

using namespace std;

int main() {

string S,T,U;

int A,B;

cin >> S >> T >> A >> B >> U;

if(U==S){

  A-=1;

}else if (U==T){

  B-=1;

}

cout <<A<<" " <<B;

    return 0;}

// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<string.h>





int main(){

	char S[25];

	char T[25];

	char U[25];

	int A;

	int B;

	

	scanf ("%s %s",&S,&T);

	scanf("%d %d",&A,&B);

	scanf("%s",&U);

	

	if (strcmp(S,U) ==0){

		A--;

		printf("%d %d",A,B);

		

	}

	else if (strcmp(T,U) ==0){

		

		B--;

		printf("%d %d",A,B);

	}

	

	

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>



using namespace std;



int main()



{

string c1 , c2 ,c3;

    cin>>c1>>c2;



    int no1,no2;

    cin>>no1>>no2;



    cin>>c3;



if (c1==c3){

    no1--;

}

else{

    no2--;

}

cout<<no1<<" "<<no2<<endl;





 return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<string.h>





int main(){

	char S[25];

	char T[25];

	char U[25];

	int A;

	int B;

	

	scanf ("%s %s",&S,&T);

	scanf("%d %d",&A,&B);

	scanf("%s",&U);

	

	if (strcmp(S,U) ==0){

		A--;

		printf("%d %d",A,B);

		

	}

	else if (strcmp(T,U) ==0){

		

		B--;

		printf("%d %d",A,B);

	}

	

	

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>



using namespace std;



int main()

{

    string s,a,u;

    int t,b;

    cin >>s>>a;

    cin>>t>>b;

    cin>>u;

    if (u==s){

        cout<<t-1<<' '<<b<<endl;

    }

    else{

        cout<<t<<' '<<b-1<<endl;

    }

    return 0;

}


// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<string.h>





int main(){

	char S[25];

	char T[25];

	char U[25];

	int A;

	int B;

	

	scanf ("%s %s",&S,&T);

	scanf("%d %d",&A,&B);

	scanf("%s",&U);

	

	if (strcmp(S,U) ==0){

		A--;

		printf("%d %d",A,B);

		

	}

	else if (strcmp(T,U) ==0){

		

		B--;

		printf("%d %d",A,B);

	}

	

	

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#pragma GCC optimize ("O3")

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

#include<iostream>

#include<string>

using namespace std;







/// Info.

///****************************************************************************************************************************************///

/// Coder               : BAHAA El_DEEN OSAMA SAYED.

/// Problem name        : F - Remaining Balls

/// Method              : IM-string

/// Date                : 23/2/2020

///****************************************************************************************************************************************///





#define rep0(i,x)         for(int i=0; i<=x ;++i)

#define all(v)           ((v.begin()),((v.end())

#define mm(v,d)          memset(v,d,sizeof(v))

#define lp(i,v)          for(int i=0;i<sizeof(v);++i)

#define lpi(i,j,n)       for(int i=(j);i>=(int)n;++i)

#define lpd(i,j,n)       for(int i=(j);i>=(int)n;--i)

#define MP               make_pair

#define SZ(v)            ((int) ( (v).size() ) )

#define ull              unsigned long long

#define ll               long long

#define pi               3.1415926536

#define oo               1e9

#define OO               1e18

#define Fx(n)            fixed<<setprecision(n)

#define FasterIO           std::ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)

#define RE0              return 0

#define RE1              return 1

#define mp(a,b)          make_pair(a,b)

#define X                first

#define Y                second

#define pii              pair(int a, int b)

#define rep1(i,x)        for(int i=1;i<x;++i)

#define rep2(i,x)        for(int i=2;i<x;++i)

#define RE               return

//#define LD               long double

#define all(v) ((v).begin()),((v).end())





const  int  N   = (int) 1e5+100;

const  int  M   = (int) 1e4+4;

const  int  INF = (int) 0x3f3f3f3f;

///const double ESP = 1e-7;

///const ll MOD=1e8+9;





string str1,str2,str3;

int a=0,b=0;



int main()

{

FasterIO;



cin>> str1 >> str2 ;

cin >> a   >> b;

cin >> str3;

(str1==str3) ? --a : --b;

cout << a << " " << b;







 RE0;}


// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<string.h>





int main(){

	char S[25];

	char T[25];

	char U[25];

	int A;

	int B;

	

	scanf ("%s %s",&S,&T);

	scanf("%d %d",&A,&B);

	scanf("%s",&U);

	

	if (strcmp(S,U) ==0){

		A--;

		printf("%d %d",A,B);

		

	}

	else if (strcmp(T,U) ==0){

		

		B--;

		printf("%d %d",A,B);

	}

	

	

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

using namespace std;

int main (){

    string s,t,u;

    int a,b;

    cin>>s>>t;

    cin>>a>>b;

    cin>>u;

    if (s==u){

        a-=1;

        cout<<a<<" "<<b;

    }else{

        b-=1;

        cout<<a<<" "<<b;

    }

    return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<string.h>





int main(){

	char S[25];

	char T[25];

	char U[25];

	int A;

	int B;

	

	scanf ("%s %s",&S,&T);

	scanf("%d %d",&A,&B);

	scanf("%s",&U);

	

	if (strcmp(S,U) ==0){

		A--;

		printf("%d %d",A,B);

		

	}

	else if (strcmp(T,U) ==0){

		

		B--;

		printf("%d %d",A,B);

	}

	

	

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

using namespace std;

int main(){

    string s1 , s2 , chosen;

    int n1 , n2;

    cin >> s1 >> s2 >> n1 >> n2 >> chosen;

    if (chosen == s1) n1--;

    else if (chosen == s2) n2--;

    cout << n1 << " " << n2;

    return 0;

}

// Optimized solution to the same problem (faster):
#include <stdio.h>

#include <string.h>



int main()

{

	int A, B;

	char S[11];

	char T[11];

	char U[11];

	

	scanf("%s %s", &S, &T);

	scanf("%d %d", &A, &B);

	scanf("%s", &U);

	

	if (strcmp(S,U) == 0){

		A--;

		printf("%d %d", A,B);

	} else if (strcmp(T,U) == 0){

		B--;

		printf("%d %d", A,B);

	}

		

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include<string>



using namespace std;



int main()

{   string S ,T,U;

    int A,B;

    cin>>S>>T;

    cin>>A>>B;

    cin>>U;

    if (U==S){

        A--;

    }

    else{

        B--;

    }

    cout <<A<<" "<<B;



    return 0;

}


// Optimized solution to the same problem (faster):
#include <stdio.h>

#include <string.h>



int main()

{

	int A, B;

	char S[11];

	char T[11];

	char U[11];

	

	scanf("%s %s", &S, &T);

	scanf("%d %d", &A, &B);

	scanf("%s", &U);

	

	if (strcmp(S,U) == 0){

		A--;

		printf("%d %d", A,B);

	} else if (strcmp(T,U) == 0){

		B--;

		printf("%d %d", A,B);

	}

		

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

using namespace std;

int main(){

    string s,t,u;

    int A, B;

    cin>>s>>t;

    cin>>A>>B;

    cin>>u;

    if (s==u){

        A--;

    } else B--;

    cout<<A<<" "<<B;



    return 0;

}

// Optimized solution to the same problem (faster):
#include <stdio.h>

#include <string.h>



int main()

{

	int A, B;

	char S[11];

	char T[11];

	char U[11];

	

	scanf("%s %s", &S, &T);

	scanf("%d %d", &A, &B);

	scanf("%s", &U);

	

	if (strcmp(S,U) == 0){

		A--;

		printf("%d %d", A,B);

	} else if (strcmp(T,U) == 0){

		B--;

		printf("%d %d", A,B);

	}

		

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>



using namespace std;



int main()

{



    string firstType, secondType, chosenType;

    int firstTypeNumber, secondTypeNumber;



    cin >> firstType >> secondType >> firstTypeNumber

    >> secondTypeNumber >> chosenType;



    if (chosenType == firstType){

        firstTypeNumber--;

    }



    else{

        secondTypeNumber--;

    }



    cout << firstTypeNumber << " " << secondTypeNumber;



    return 0;

}


// Optimized solution to the same problem (faster):
#include <stdio.h>

#include <string.h>



int main()

{

	int A, B;

	char S[11];

	char T[11];

	char U[11];

	

	scanf("%s %s", &S, &T);

	scanf("%d %d", &A, &B);

	scanf("%s", &U);

	

	if (strcmp(S,U) == 0){

		A--;

		printf("%d %d", A,B);

	} else if (strcmp(T,U) == 0){

		B--;

		printf("%d %d", A,B);

	}

		

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

    using namespace std;

    int main() {

      int a,b;

      string r,g,x;

      cin>>r;

      cin>>g;

      cin>>a>>b;

      cin>>x;

      if(x==r){

          a-=1;

      }

      else{

          b-=1;

      }

        cout<<a<<' '<<b;

     }

// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<string.h>



 

 int main(){

 	char S[30],T[30];

 	int A, B;

 	char U[30];

 	scanf("%s %s", &S, &T );

 	scanf("%d %d", &A, &B );

 	scanf("%s", &U);

 	int com = strcmp(U,S);

 	int com2 = strcmp(U,T);

 	if(com == 0){

 		printf("%d %d", A-1, B);

	 }

	else if(com2 == 0){

		printf("%d %d", A, B-1);

	}

	return 0;

 }

 

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

using namespace std;



int main()

{

    string S, T, U;

    int A, B;

    cin >> S >> T;

    cin >> A >> B;

    cin >> U;

    if (U == S) {

        A-=1;

        cout << A<<" "<<B;

    }

    else if (U == T) {

        B-=1;

        cout << A<<" "<<B;

    }

    return 0;



}

// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<string.h>



 

 int main(){

 	char S[30],T[30];

 	int A, B;

 	char U[30];

 	scanf("%s %s", &S, &T );

 	scanf("%d %d", &A, &B );

 	scanf("%s", &U);

 	int com = strcmp(U,S);

 	int com2 = strcmp(U,T);

 	if(com == 0){

 		printf("%d %d", A-1, B);

	 }

	else if(com2 == 0){

		printf("%d %d", A, B-1);

	}

	return 0;

 }

 

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <string>

using namespace std;







int main()

{

    int A,B;

    string S,T,U;

    cin >> S >> T;

    cin >> A >> B;

    cin >> U;



    if(S==U){

            A = A-1;



    } else if(T==U){

       B = B-1;



    }

    cout << A << " " << B << endl;



    return 0;

}


// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<string.h>



 

 int main(){

 	char S[30],T[30];

 	int A, B;

 	char U[30];

 	scanf("%s %s", &S, &T );

 	scanf("%d %d", &A, &B );

 	scanf("%s", &U);

 	int com = strcmp(U,S);

 	int com2 = strcmp(U,T);

 	if(com == 0){

 		printf("%d %d", A-1, B);

	 }

	else if(com2 == 0){

		printf("%d %d", A, B-1);

	}

	return 0;

 }

 

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>



using namespace std;



int main()

{

    string s,t,u;

    int a,b;

    cin>>s>>t;

    cin>>a>>b;

    cin>>u;

    if(u==s)

        cout<<a-1<<" "<<b<<endl;

    else if(u==t)

        cout<<a<<" "<<b-1<<endl;



    return 0;

}


// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<string.h>



 

 int main(){

 	char S[30],T[30];

 	int A, B;

 	char U[30];

 	scanf("%s %s", &S, &T );

 	scanf("%d %d", &A, &B );

 	scanf("%s", &U);

 	int com = strcmp(U,S);

 	int com2 = strcmp(U,T);

 	if(com == 0){

 		printf("%d %d", A-1, B);

	 }

	else if(com2 == 0){

		printf("%d %d", A, B-1);

	}

	return 0;

 }

 

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;



int main() {



   string color1,color2;

   int no1,no2;

   string color;

   cin>>color1>>color2>>no1>>no2>>color;

   if(color==color1){

       cout<<--no1<<" "<<no2<<endl;

   }

   else cout<<no1<<" "<<--no2<<endl;

    return 0;

}


// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<string.h>



 

 int main(){

 	char S[30],T[30];

 	int A, B;

 	char U[30];

 	scanf("%s %s", &S, &T );

 	scanf("%d %d", &A, &B );

 	scanf("%s", &U);

 	int com = strcmp(U,S);

 	int com2 = strcmp(U,T);

 	if(com == 0){

 		printf("%d %d", A-1, B);

	 }

	else if(com2 == 0){

		printf("%d %d", A, B-1);

	}

	return 0;

 }

 

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <map>

#include <iostream>



using namespace std;



int main()

{

	int N, M;



	char A, B, C;



	while (true)

	{

		cin >> N;



		if (N == 0) { break; }



		map<char, char> converse;



		for (char i = '0'; i <= 'z'; i++)

		{

			converse[i] = i;

		}



		for (int i = 0; i < N; i++)

		{

			cin >> A >> B;



			converse[A] = B;

		}



		cin >> M;



		for (int i = 0; i < M; i++)

		{

			cin >> C;



			cout << converse[C];

		}



		cout << endl;

	}



	return 0;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cstring>

int n, m; char e[261], f, g;

int main() {

	while(scanf("%d\n", &n), n) {

		for(int i = 0; i < 256; i++) e[i] = i;

		for(int i = 0; i < n; i++) scanf("%c %c\n", &f, &g), e[f] = g;

		scanf("%d\n", &m);

		for(int i = 0; i < m; i++) scanf("%c\n", &f), printf("%c", e[f]);

		printf("\n");

	}

}

// Fastest known solution for this problem: