stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<iostream>

#include<vector>

#include<map>

#include<algorithm>

#include<cstring>

#define INF 1<<28

#define F first

#define S second

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(memo[k][t][q]) return memo[k][t][q];

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



  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].F) + abs(sy-p[d][i].S);

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

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

  }



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

}



int main(){



  int w,h;

  char c;



  while(true){

    cin >> 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++){

	cin >> 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) cout << "NA\n";

    else cout << a+1 << " " << b << endl;



  }

}

// Faster C++ solution for the same problem (measured speedup: 1.1697249628554354x):
#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);

  

  }

}
// Slower C++ solution:
#include<iostream>

#include<vector>

#include<map>

#include<algorithm>

#include<cstring>

#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){

    cin >> 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++){

	cin >> 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) cout << "NA\n";

    else cout << a+1 << " " << b << endl;



  }

}

// Faster C++ solution for the same problem (measured speedup: 1.1694556322160101x):
#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);

  

  }

}
// Slower C++ solution:
#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;

    

  }

}

// Faster C++ solution for the same problem (measured speedup: 1.1697181962996501x):
#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);

  

  }

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 5.24990776859308x):
#include <stdio.h>



int main(){

	

	

	int A,B;

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

	

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

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

	getchar();

	scanf("%s", U);

	if (S[0] == U[0]){

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

	}else if (T[0]==U[0]) {

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

	}

	





	

	return 0;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 5.24990776859308x):
#include <stdio.h>



int main(){

	

	

	int A,B;

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

	

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

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

	getchar();

	scanf("%s", U);

	if (S[0] == U[0]){

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

	}else if (T[0]==U[0]) {

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

	}

	





	

	return 0;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 5.249775246847172x):
#include <stdio.h>



int main(){

	

	

	int A,B;

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

	

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

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

	getchar();

	scanf("%s", U);

	if (S[0] == U[0]){

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

	}else if (T[0]==U[0]) {

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

	}

	





	

	return 0;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 5.206853608379035x):
#include <stdio.h>



int main(){

	

	

	int A,B;

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

	

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

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

	getchar();

	scanf("%s", U);

	if (S[0] == U[0]){

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

	}else if (T[0]==U[0]) {

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

	}

	





	

	return 0;

}
// Slower C++ solution:
#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

    ;

}


// Faster C++ solution for the same problem (measured speedup: 5.24990776859308x):
#include <stdio.h>



int main(){

	

	

	int A,B;

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

	

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

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

	getchar();

	scanf("%s", U);

	if (S[0] == U[0]){

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

	}else if (T[0]==U[0]) {

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

	}

	





	

	return 0;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 5.258113299314147x):
#include <stdio.h>



int main(){

	

	

	int A,B;

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

	

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

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

	getchar();

	scanf("%s", U);

	if (S[0] == U[0]){

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

	}else if (T[0]==U[0]) {

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

	}

	





	

	return 0;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 5.243607236865936x):
#include <stdio.h>

#include <string.h>



int main() {

	char a[11], b[11], c[11];

	int d, e;

	scanf("%s %s\n", &a, &b);

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

	scanf("%s", &c);

	

	if(strcmp(a, c) == 0) {

		printf("%d %d", d - 1, e);

	} else if (strcmp(b, c) == 0) {

		printf("%d %d", d, e - 1);

	}

	

	return 0;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 5.243607236865936x):
#include <stdio.h>

#include <string.h>



int main() {

	char a[11], b[11], c[11];

	int d, e;

	scanf("%s %s\n", &a, &b);

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

	scanf("%s", &c);

	

	if(strcmp(a, c) == 0) {

		printf("%d %d", d - 1, e);

	} else if (strcmp(b, c) == 0) {

		printf("%d %d", d, e - 1);

	}

	

	return 0;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 5.243474874162338x):
#include <stdio.h>

#include <string.h>



int main() {

	char a[11], b[11], c[11];

	int d, e;

	scanf("%s %s\n", &a, &b);

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

	scanf("%s", &c);

	

	if(strcmp(a, c) == 0) {

		printf("%d %d", d - 1, e);

	} else if (strcmp(b, c) == 0) {

		printf("%d %d", d, e - 1);

	}

	

	return 0;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 5.200604746912468x):
#include <stdio.h>

#include <string.h>



int main() {

	char a[11], b[11], c[11];

	int d, e;

	scanf("%s %s\n", &a, &b);

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

	scanf("%s", &c);

	

	if(strcmp(a, c) == 0) {

		printf("%d %d", d - 1, e);

	} else if (strcmp(b, c) == 0) {

		printf("%d %d", d, e - 1);

	}

	

	return 0;

}
// Slower C++ solution:
#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

    ;

}


// Faster C++ solution for the same problem (measured speedup: 5.243607236865936x):
#include <stdio.h>

#include <string.h>



int main() {

	char a[11], b[11], c[11];

	int d, e;

	scanf("%s %s\n", &a, &b);

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

	scanf("%s", &c);

	

	if(strcmp(a, c) == 0) {

		printf("%d %d", d - 1, e);

	} else if (strcmp(b, c) == 0) {

		printf("%d %d", d, e - 1);

	}

	

	return 0;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 5.2518029199460665x):
#include <stdio.h>

#include <string.h>



int main() {

	char a[11], b[11], c[11];

	int d, e;

	scanf("%s %s\n", &a, &b);

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

	scanf("%s", &c);

	

	if(strcmp(a, c) == 0) {

		printf("%d %d", d - 1, e);

	} else if (strcmp(b, c) == 0) {

		printf("%d %d", d, e - 1);

	}

	

	return 0;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 5.238809878538115x):
#include<stdio.h>

#include<string.h>



int main()

{

	int a,b;

	char s[11];

	char t[11];

	char u[11];



	scanf("%s %s\n",&s,&t);

	scanf("%d %d\n",&a,&b);

	scanf("%s",&u);

	

	if(strcmp(s,t)==0)

	{

		printf("error!");

	}

	else if (strcmp(s,u)==0)

	{

		printf("%d %d",a-1,b);

	}

	else if(strcmp(t,u)==0)

	printf("%d %d",a,b-1);

	}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 5.238809878538115x):
#include<stdio.h>

#include<string.h>



int main()

{

	int a,b;

	char s[11];

	char t[11];

	char u[11];



	scanf("%s %s\n",&s,&t);

	scanf("%d %d\n",&a,&b);

	scanf("%s",&u);

	

	if(strcmp(s,t)==0)

	{

		printf("error!");

	}

	else if (strcmp(s,u)==0)

	{

		printf("%d %d",a-1,b);

	}

	else if(strcmp(t,u)==0)

	printf("%d %d",a,b-1);

	}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 5.238677636932701x):
#include<stdio.h>

#include<string.h>



int main()

{

	int a,b;

	char s[11];

	char t[11];

	char u[11];



	scanf("%s %s\n",&s,&t);

	scanf("%d %d\n",&a,&b);

	scanf("%s",&u);

	

	if(strcmp(s,t)==0)

	{

		printf("error!");

	}

	else if (strcmp(s,u)==0)

	{

		printf("%d %d",a-1,b);

	}

	else if(strcmp(t,u)==0)

	printf("%d %d",a,b-1);

	}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 5.195846731415637x):
#include<stdio.h>

#include<string.h>



int main()

{

	int a,b;

	char s[11];

	char t[11];

	char u[11];



	scanf("%s %s\n",&s,&t);

	scanf("%d %d\n",&a,&b);

	scanf("%s",&u);

	

	if(strcmp(s,t)==0)

	{

		printf("error!");

	}

	else if (strcmp(s,u)==0)

	{

		printf("%d %d",a-1,b);

	}

	else if(strcmp(t,u)==0)

	printf("%d %d",a,b-1);

	}
// Slower C++ solution:
#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

    ;

}


// Faster C++ solution for the same problem (measured speedup: 5.238809878538115x):
#include<stdio.h>

#include<string.h>



int main()

{

	int a,b;

	char s[11];

	char t[11];

	char u[11];



	scanf("%s %s\n",&s,&t);

	scanf("%d %d\n",&a,&b);

	scanf("%s",&u);

	

	if(strcmp(s,t)==0)

	{

		printf("error!");

	}

	else if (strcmp(s,u)==0)

	{

		printf("%d %d",a-1,b);

	}

	else if(strcmp(t,u)==0)

	printf("%d %d",a,b-1);

	}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 5.246998063415825x):
#include<stdio.h>

#include<string.h>



int main()

{

	int a,b;

	char s[11];

	char t[11];

	char u[11];



	scanf("%s %s\n",&s,&t);

	scanf("%d %d\n",&a,&b);

	scanf("%s",&u);

	

	if(strcmp(s,t)==0)

	{

		printf("error!");

	}

	else if (strcmp(s,u)==0)

	{

		printf("%d %d",a-1,b);

	}

	else if(strcmp(t,u)==0)

	printf("%d %d",a,b-1);

	}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 5.248552177743256x):
#include <stdio.h>

#include<string.h>





int main ()

{

int A,B,index;

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



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

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

scanf("%s", &U);





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

	A--;

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



}

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

B--;

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



}





	return 0;

	}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 5.248552177743256x):
#include <stdio.h>

#include<string.h>





int main ()

{

int A,B,index;

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



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

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

scanf("%s", &U);





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

	A--;

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



}

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

B--;

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



}





	return 0;

	}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 5.248419690216094x):
#include <stdio.h>

#include<string.h>





int main ()

{

int A,B,index;

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



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

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

scanf("%s", &U);





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

	A--;

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



}

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

B--;

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



}





	return 0;

	}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 5.205509134643683x):
#include <stdio.h>

#include<string.h>





int main ()

{

int A,B,index;

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



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

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

scanf("%s", &U);





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

	A--;

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



}

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

B--;

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



}





	return 0;

	}
// Slower C++ solution:
#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

    ;

}


// Faster C++ solution for the same problem (measured speedup: 5.248552177743256x):
#include <stdio.h>

#include<string.h>





int main ()

{

int A,B,index;

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



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

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

scanf("%s", &U);





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

	A--;

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



}

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

B--;

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



}





	return 0;

	}