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

#include<iostream>

#include<cmath>

#include<cstring>

#include<algorithm>

#define ll long long

using namespace std;

int main()

{

    string s;

    cin>>s;

    int a, z;

    int len = s.size();

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

        if(s[i] == 'A'){

            a = i;

            break;

        }

    }

    for(int i = len-1; i >= 0; i--){

        if(s[i] == 'Z'){

            z = i;

            break;

        }

    }

    int ans = z-a+1;

    if(ans < 0)ans = 0;

    cout<<ans;





    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.285500279959576x):
#include<cstdio>

#include<algorithm>

using namespace std;

char str[200005];

int main(){



    scanf("%s",str);

    int ans = 0;

    int a=-1;

    for(int i=0;str[i];i++){

        if(str[i]=='Z'){

            if(a!=-1)

                ans = max(ans,i-a);

        }else if(str[i]=='A' && a==-1)

            a = i;

    }

    printf("%d\n",ans+1);

    return 0;

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

#include<string>

using namespace std;

int main(void){

    // Your code here!

    string s;

    cin>>s;

    

    cout<<s.rfind('Z')-s.find('A')+1<<endl;

    

    return 0;

}


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

#include <string.h>

int main(void)

{

	char s[200001];

	int a,z,i;

	scanf("%s",s);

	for(i=0; i<strlen(s); i++){

		if(s[i]=='A'){

			a=i;

			break;

		}

	}

	for(i=strlen(s)-1; i>=0; i--){

		if(s[i]=='Z'){

			z=i;

			break;

		}

	}

	printf("%d\n",z-a+1);

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int main(void){

	string s;

	int i,j;

	int x,y;

	cin>>s;

	for(i=0;i<s.size();i++){

		if(s[i]=='A'){

			x=i;

			break;

		}

	}

	for(i=s.size()-1;i>=0;i--){

		if(s[i]=='Z'){

			y=i;

			break;

		}

	}

	int cnt=0;

	for(i=x;i<=y;i++)	cnt++;

	cout<<cnt<<endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.126834596492199x):
#include<cstdio>

#include<cstring>

using namespace std;

int main(void){

	char s[200000];

	int i;

	int n;

	int x,y;

	scanf("%s",s);

	n=strlen(s);

	for(i=0;i<n;i++){

		if(s[i]=='A'){

			x=i;

			break;

		}

	}

	for(i=n-1;i>=0;i--){

		if(s[i]=='Z'){

			y=i;

			break;

		}

	}

	y=n-y;

	x=x-1;

	printf("%d\n",n-(x+y));

	return 0;

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



using namespace std;







int main () {

	string s;

	cin >> s;

	int b = 0, e = s.length()-1;

	while (s[b] != 'A') b ++;

	while (s[e] != 'Z') e --;

	cout << e - b + 1 << endl;

	

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.3385592612663935x):
#include<cstdio>

#include<cstring>

char str[200005];

int main()

{

    scanf("%s",str);

    int len=strlen(str);

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

    {

        if(str[i]=='A')

        {

            for(int j=len-1;j>=i;j--)

            {

                if(str[j]=='Z')

                {

                    printf("%d\n",j-i+1);

                    return 0;

                }

            }

        }

    }

    return 0;

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

#include <string>



using namespace std;



int main() {

	string in;

	cin >> in;



	int i = 0;

	int j = in.size() - 1;

	while(in[i] != 'A') {

		i++;

	}

	while(in[j] != 'Z') {

		j--;

	}



	cout << (j - i + 1) << endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.3385592612663935x):
#include<cstdio>

#include<cstring>

char str[200005];

int main()

{

    scanf("%s",str);

    int len=strlen(str);

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

    {

        if(str[i]=='A')

        {

            for(int j=len-1;j>=i;j--)

            {

                if(str[j]=='Z')

                {

                    printf("%d\n",j-i+1);

                    return 0;

                }

            }

        }

    }

    return 0;

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

#include <algorithm>

#include <string>



using namespace std;



int main()

{

    string s;

    cin >> s;

    cout << (s.rfind('Z') - s.find('A') + 1) << endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.300171975569946x):
#include<cstdio>

#include<cstring>

char str[200005];

int main()

{

    scanf("%s",str);

    int len=strlen(str);

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

    {

        if(str[i]=='A')

        {

            for(int j=len-1;j>=i;j--)

            {

                if(str[j]=='Z')

                {

                    printf("%d\n",j-i+1);

                    return 0;

                }

            }

        }

    }

    return 0;

}
// Slower C++ solution:
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

typedef pair<ll, ll> pll;

#define INF 1<<30

#define LINF 1LL<<60



int main(void) {

    cin.tie(0); ios::sync_with_stdio(false);

    string s; cin >> s;

    int x = s.find('A');

    int y = s.rfind('Z');

    cout << y - x + 1 << endl;

    

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.410912806106982x):
#include<cstdio>

#include<cstring>

char str[200005];

int main()

{

    scanf("%s",str);

    int len=strlen(str);

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

    {

        if(str[i]=='A')

        {

            for(int j=len-1;j>=i;j--)

            {

                if(str[j]=='Z')

                {

                    printf("%d\n",j-i+1);

                    return 0;

                }

            }

        }

    }

    return 0;

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



using namespace std;







int main () {

	string s;

	cin >> s;

	int b = 0, e = s.length()-1;

	while (s[b] != 'A') b ++;

	while (s[e] != 'Z') e --;

	cout << e - b + 1 << endl;

	

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.343565120050356x):
#include <cstdio>

#include <cstring>



const int MAXN = 2e5 + 10;



char s[MAXN];



int main() {

  int i, j;



  scanf(" %s", s);



  i = 0;

  while (s[i] != 'A') ++i;

  

  j = strlen(s);

  while (s[j] != 'Z') --j;



  printf("%d\n", j - i + 1);

  return 0;

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

#include <string>



using namespace std;



int main() {

	string in;

	cin >> in;



	int i = 0;

	int j = in.size() - 1;

	while(in[i] != 'A') {

		i++;

	}

	while(in[j] != 'Z') {

		j--;

	}



	cout << (j - i + 1) << endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.343565120050356x):
#include <cstdio>

#include <cstring>



const int MAXN = 2e5 + 10;



char s[MAXN];



int main() {

  int i, j;



  scanf(" %s", s);



  i = 0;

  while (s[i] != 'A') ++i;

  

  j = strlen(s);

  while (s[j] != 'Z') --j;



  printf("%d\n", j - i + 1);

  return 0;

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

#include <algorithm>

#include <string>



using namespace std;



int main()

{

    string s;

    cin >> s;

    cout << (s.rfind('Z') - s.find('A') + 1) << endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.305141839374386x):
#include <cstdio>

#include <cstring>



const int MAXN = 2e5 + 10;



char s[MAXN];



int main() {

  int i, j;



  scanf(" %s", s);



  i = 0;

  while (s[i] != 'A') ++i;

  

  j = strlen(s);

  while (s[j] != 'Z') --j;



  printf("%d\n", j - i + 1);

  return 0;

}
// Slower C++ solution:
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

typedef pair<ll, ll> pll;

#define INF 1<<30

#define LINF 1LL<<60



int main(void) {

    cin.tie(0); ios::sync_with_stdio(false);

    string s; cin >> s;

    int x = s.find('A');

    int y = s.rfind('Z');

    cout << y - x + 1 << endl;

    

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.4159865093430275x):
#include <cstdio>

#include <cstring>



const int MAXN = 2e5 + 10;



char s[MAXN];



int main() {

  int i, j;



  scanf(" %s", s);



  i = 0;

  while (s[i] != 'A') ++i;

  

  j = strlen(s);

  while (s[j] != 'Z') --j;



  printf("%d\n", j - i + 1);

  return 0;

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

#include <string>

using namespace std;

int main()

{

    int c1,c2;

    string s;

    cin>>s;

    int l=s.length();

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

    {

        if(s[i]=='A')

        {

            c1=i+1;

            break;

        }

    }

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

    {

        if(s[i]=='Z')

        {

            c2=i+1;

        }

    }

    cout<<c2-c1+1<<endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.3435193254295825x):
#include <cstdio>

#include <cstring>



const int MAXN = 2e5 + 10;



char s[MAXN];



int main() {

  int i, j;



  scanf(" %s", s);



  i = 0;

  while (s[i] != 'A') ++i;

  

  j = strlen(s);

  while (s[j] != 'Z') --j;



  printf("%d\n", j - i + 1);

  return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int main(){

string s;

cin>>s;

int a,b;

a=s.find("A");

b=s.rfind("Z");

cout<<b-a+1;	

}

// Faster C++ solution for the same problem (measured speedup: 5.340116250029066x):
#include <cstdio>

#include <cstring>



const int MAXN = 2e5 + 10;



char s[MAXN];



int main() {

  int i, j;



  scanf(" %s", s);



  i = 0;

  while (s[i] != 'A') ++i;

  

  j = strlen(s);

  while (s[j] != 'Z') --j;



  printf("%d\n", j - i + 1);

  return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>



#define infi            5e9

#define infl            5e18

#define MX              100005

#define pi              2*acos(0.0)

#define ll              long long int

#define rr              read()

#define ff              first

#define ss              second

#define pb              push_back

#define pii             pair<int,int>

#define ms(a,b)         memset(a, b, sizeof(a))

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

#define pool(i,n)       for(register int i=n-1;i>=0;i--)

#define loop1(i,n)      for(register int i=1;i<=n;i++)

#define pool1(i,n)      for(register int i=n;i>0;i--)



using namespace std;



inline ll read(){char c=getchar();ll num,sign=1;for(;c<'0'||c>'9';c=getchar())if(c=='-')sign=-1;for(num=0;c>='0'&&c<='9';){c-='0';num=num*10+c;c=getchar();}return num*sign;}

inline ll pw(ll b, ll p){ll ans=1;while(p>0){if(p&1)ans*=b;p>>=1;b*=b;}return ans;}

// inline bool isPrime(ll n){if(n==1)return false;if(n==2)return true;if(!(n%2))return false;for(ll i=3;i<=sqrt(n);i+=2)if(!(n%i))return false;return true;}

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



// //*************************************  Bitmask Opereations  **********************************//

// int Set(int N,int pos){return N=N | (1<<pos);}

// int reset(int N,int pos){return N= N & ~(1<<pos);}

// bool check(int N,int pos){return (bool)(N & (1<<pos));}

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





int main(){

    ios_base::sync_with_stdio(false);cin.tie(NULL);

    //#ifdef rid.dle

    //freopen("in.txt", "r", stdin);//#endif

    

    string str;

    cin >> str;



    int n=str.length();



    int cur=-1,ans=-1;

    loop(i,n){

        if(str[i]=='A' && cur==-1)cur=1;

        else if(cur!=-1)cur++;

        if(str[i]=='Z' && cur!=-1)ans=cur;

    }

    cout << ans << endl;



    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.412513432780427x):
#include <cstdio>

#include <cstring>



const int MAXN = 2e5 + 10;



char s[MAXN];



int main() {

  int i, j;



  scanf(" %s", s);



  i = 0;

  while (s[i] != 'A') ++i;

  

  j = strlen(s);

  while (s[j] != 'Z') --j;



  printf("%d\n", j - i + 1);

  return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

int main(){

int X=0,M=0,U=0,T=0;

string N;

cin>>N;

int len=N.length();

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

	if(N[i]=='A'){

	X=i;

	T=1;

}

if(T==1)

break;

}

for(int y=len-1;y>0;y--){

	

	if(N[y]=='Z'){

		

		M=y;

		U=1;

	}

	if(U==1)

	break;

}

cout<<M-X+1;

}

// Faster C++ solution for the same problem (measured speedup: 5.292014693214037x):
#include <cstdio>

#include <cstring>



const int MAXN = 2e5 + 10;



char s[MAXN];



int main() {

  int i, j;



  scanf(" %s", s);



  i = 0;

  while (s[i] != 'A') ++i;

  

  j = strlen(s);

  while (s[j] != 'Z') --j;



  printf("%d\n", j - i + 1);

  return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

int main(){

string s;

cin>>s;

if(s.find("A")<s.rfind("Z"))

{

cout<<(s.rfind("Z")-s.find("A"))+1;

}

else

cout<<0;

}

// Faster C++ solution for the same problem (measured speedup: 5.339308838780194x):
#include <cstdio>

#include <cstring>



const int MAXN = 2e5 + 10;



char s[MAXN];



int main() {

  int i, j;



  scanf(" %s", s);



  i = 0;

  while (s[i] != 'A') ++i;

  

  j = strlen(s);

  while (s[j] != 'Z') --j;



  printf("%d\n", j - i + 1);

  return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



int main(){

int max=0,counter=0,m;

string s;

cin>>s;

for(int i=0;i<s.length();i++){

	if(s[i]=='A'){

		m=i;

		if(counter>0)

		break;

	

	for(m;m<s.length();m++){

		if(s[m]=='Z'){

			counter++;

			if(counter>max){

				max=counter;

			    

			}	

		}

		else

		counter++;

		

	}

	

   

}

}

cout<<max;

return 0;

} 


// Faster C++ solution for the same problem (measured speedup: 5.292101059762663x):
#include <cstdio>

#include <cstring>



const int MAXN = 2e5 + 10;



char s[MAXN];



int main() {

  int i, j;



  scanf(" %s", s);



  i = 0;

  while (s[i] != 'A') ++i;

  

  j = strlen(s);

  while (s[j] != 'Z') --j;



  printf("%d\n", j - i + 1);

  return 0;

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

using namespace std;

int main()

{

	string s;

	int i=0,j=0,k=0;

	cin>>s;

	for(;s[i]!='A';++i){

		

	}

	for(j=s.length();s[j]!='Z';j--)

	{

	}

	j++;

	cout<<j-i<<"\n";

}

// Faster C++ solution for the same problem (measured speedup: 5.303463263022984x):
#include <cstdio>

#include <cstring>



const int MAXN = 2e5 + 10;



char s[MAXN];



int main() {

  int i, j;



  scanf(" %s", s);



  i = 0;

  while (s[i] != 'A') ++i;

  

  j = strlen(s);

  while (s[j] != 'Z') --j;



  printf("%d\n", j - i + 1);

  return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

#include <iostream>

using namespace std;

int main()

{

  string s;

 int x,y,sum=0;

  cin>>s;

x=s.find("A");

y=s.rfind("Z");

for(int i=x;i<=y;i++)

{

	sum++;

}

cout<<sum;

 return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.34004983502125x):
#include <cstdio>

#include <cstring>



const int MAXN = 2e5 + 10;



char s[MAXN];



int main() {

  int i, j;



  scanf(" %s", s);



  i = 0;

  while (s[i] != 'A') ++i;

  

  j = strlen(s);

  while (s[j] != 'Z') --j;



  printf("%d\n", j - i + 1);

  return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

char a[200005];



int main(){



	scanf("%s",a);

	string s1 (a);

	

int n=s1.find("A");

int y=s1.rfind("Z");

cout<<(y-n+1);

}

// Faster C++ solution for the same problem (measured speedup: 5.292053315526275x):
#include <cstdio>

#include <cstring>



const int MAXN = 2e5 + 10;



char s[MAXN];



int main() {

  int i, j;



  scanf(" %s", s);



  i = 0;

  while (s[i] != 'A') ++i;

  

  j = strlen(s);

  while (s[j] != 'Z') --j;



  printf("%d\n", j - i + 1);

  return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;



int main(){

	long long sum = 0,Z = 0,z;

	string s; cin >> s;

	int m = int(s.size());

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

		if(s[i] == 'A'){

			break;

		}

		sum++;

	}

	for(int i = m - 1; i >= 0; i--){

		if(s[i] == 'Z'){

			break;

		}

		Z++;

	}

	cout << m - (sum + Z);

	return 0;

}




// Faster C++ solution for the same problem (measured speedup: 5.291699125869205x):
#include <cstdio>

#include <cstring>



const int MAXN = 2e5 + 10;



char s[MAXN];



int main() {

  int i, j;



  scanf(" %s", s);



  i = 0;

  while (s[i] != 'A') ++i;

  

  j = strlen(s);

  while (s[j] != 'Z') --j;



  printf("%d\n", j - i + 1);

  return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

# define ll      long long 

# define in      freopen("input.txt", "r", stdin);

# define out     freopen("output.txt", "w", stdout);

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

# define str     string 

# define pb      push_back

# define speed   ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

# define time    cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"

using namespace std;

ll a,b,c,d,e,f,mn=1e9,mx,cnt,bnt,sum; str s,cal,kcal;

set <ll> st; map <char, int> mp; vector <ll> vc1;

void botsolve(){

	int right1=s.size()-1,left1=0;

	for (int i = 0; i <(int) s.size(); ++i){

		if(s[right1]=='Z' && sum==0){

			cnt+=(s.size()-1)-right1;

			sum++;

		}

		if(s[left1]=='A' && mx==0){

			cnt+=left1;

			mx++;

		}

		right1--;

		left1++;

	}

	cout<<s.size()-cnt;

}

int main(){

	speed;

	//in out

    cin>>s;

    botsolve();



	time;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.468613109767543x):
#include <cstdio>

#include <cstring>



const int MAXN = 2e5 + 10;



char s[MAXN];



int main() {

  int i, j;



  scanf(" %s", s);



  i = 0;

  while (s[i] != 'A') ++i;

  

  j = strlen(s);

  while (s[j] != 'Z') --j;



  printf("%d\n", j - i + 1);

  return 0;

}
// Slower C++ solution:
#include "bits/stdc++.h"

using namespace std;



#define pb push_back

#define mp make_pair

#define fst first

#define snd second



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

#define frr(i,n)	for(int i=1;i<=n;i++)



#define ms(x,i)	memset(x,i,sizeof(x))

#define dbg(x)	cout << #x << " = " << x << endl

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



#define gnl cout << endl

#define olar cout << "olar" << endl

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)



typedef long long int ll;

typedef pair<int,int> pii;

typedef vector<int> vi;

typedef vector<pii> vii;

typedef pair<ll,ll> pll;



const int INF = 0x3f3f3f3f;

const ll llINF = 0x3f3f3f3f3f3f3f;

const int MOD = 1e9+7;



int main(){



	fastio;

	string s;

	getline(cin,s);



	int a,b;

	bool ok = true;

	fr(i,s.size()){

		if(s[i] == 'A' && ok){

			a = i;

			ok = false;

		}

		if(s[i] == 'Z') b = i;

	}



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



}


// Faster C++ solution for the same problem (measured speedup: 5.401507397254332x):
#include <cstdio>

#include <cstring>



const int MAXN = 2e5 + 10;



char s[MAXN];



int main() {

  int i, j;



  scanf(" %s", s);



  i = 0;

  while (s[i] != 'A') ++i;

  

  j = strlen(s);

  while (s[j] != 'Z') --j;



  printf("%d\n", j - i + 1);

  return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

int main(){

	string s;

    cin>>s;

    int size=s.size();

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

        if(s[i]=='A'){

            s.erase(s.begin(),s.begin()+i);

            break;

        }

    }

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

        if(s[s.size()-1-j]=='Z'){

            s.erase(s.begin()+s.size()-j,s.end());

            break;

        }

    }

    cout<<s.size()<<endl;

    return 0;

}

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

#include<stdlib.h>

#include<string.h>

int main(int argc,char **argv){

    char s[200000];

    scanf("%s",s);

    int ans;

    

    ans=strrchr(s,'Z')-strchr(s,'A');

    

    printf("%d",ans+1);

  return 0;

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

#include <string>

using namespace std;

int main() {

    string s; cin >> s;

    int min_a = s.find('A');

    int max_z = s.rfind('Z');

    cout << max_z - min_a + 1;

}

// Faster C++ solution for the same problem (measured speedup: 5.118762865639996x):
#include <cstdio>

#include <cstring>

using namespace std;

int main() {

    char s[200000]; scanf("%s", s);

    int min_a = strlen(s), max_z = 0;

    for(int i = 0; i < strlen(s); i++) {

        if(s[i] == 'A' && min_a > i) min_a = i;

        if(s[i] == 'Z' && max_z < i) max_z = i;

    }

    printf("%d\n", max_z - min_a + 1);

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

#include<algorithm>



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



using namespace std;



const int INF=1<<29;



int n,c[100];

int dp1[1000000],dp2[1000000];



int main(){

	for(int T=1;scanf("%d",&n),n;T++){

		rep(i,n)	scanf("%d",c+i);



		if(c[0]!=1){

			printf("Case #%d: Cannot pay some amount\n",T);

			continue;

		}



		const int L=100*c[n-1];

		dp1[0]=0;

		fill(dp1+1,dp1+L,INF);

		rep(k,n)for(int p=c[k];p<L;p++)	dp1[p]=min(dp1[p],dp1[p-c[k]]+1);



		dp2[0]=0;

		fill(dp2+1,dp2+L,INF);

		rep(p,L)for(int k=n-1;k>=0;k--){

			if(p-c[k]>=0){

				dp2[p]=dp2[p-c[k]]+1;

				break;

			}

		}



		bool ok=true;

		rep(i,L)if(dp1[i]<dp2[i]){ ok=false; break; }

		printf("Case #%d: %s\n",T,ok?"OK":"Cannot use greedy algorithm");

	}



	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.4143207498089612x):
#include<cstdio>

#include<algorithm>



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



using namespace std;



const int INF=1<<29;



int n,c[100];

int dp1[1000000],dp2[1000000];



int main(){

	for(int T=1;scanf("%d",&n),n;T++){

		rep(i,n)	scanf("%d",c+i);



		if(c[0]!=1){

			printf("Case #%d: Cannot pay some amount\n",T);

			continue;

		}



		const int L=10*c[n-1];

		dp1[0]=0;

		fill(dp1+1,dp1+L,INF);

		rep(k,n)for(int p=c[k];p<L;p++)	dp1[p]=min(dp1[p],dp1[p-c[k]]+1);



		dp2[0]=0;

		fill(dp2+1,dp2+L,INF);

		rep(p,L)for(int k=n-1;k>=0;k--){

			if(p-c[k]>=0){

				dp2[p]=dp2[p-c[k]]+1;

				break;

			}

		}



		bool ok=true;

		rep(i,L)if(dp1[i]<dp2[i]){ ok=false; break; }

		printf("Case #%d: %s\n",T,ok?"OK":"Cannot use greedy algorithm");

	}



	return 0;

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

#include<algorithm>



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



using namespace std;



const int INF=1<<29;



int n,c[100];

int dp1[1000000],dp2[1000000];



int main(){

	for(int T=1;scanf("%d",&n),n;T++){

		rep(i,n)	scanf("%d",c+i);



		if(c[0]!=1){

			printf("Case #%d: Cannot pay some amount\n",T);

			continue;

		}



		const int L=100*c[n-1];

		dp1[0]=0;

		fill(dp1+1,dp1+L,INF);

		rep(k,n)for(int p=c[k];p<L;p++)	dp1[p]=min(dp1[p],dp1[p-c[k]]+1);



		dp2[0]=0;

		fill(dp2+1,dp2+L,INF);

		rep(p,L)for(int k=n-1;k>=0;k--){

			if(p-c[k]>=0){

				dp2[p]=dp2[p-c[k]]+1;

				break;

			}

		}



		bool ok=true;

		rep(i,L)if(dp1[i]<dp2[i]){ ok=false; break; }

		printf("Case #%d: %s\n",T,ok?"OK":"Cannot use greedy algorithm");

	}



	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.4703557224380184x):
#include<cstdio>

#include<algorithm>



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



using namespace std;



const int INF=1<<29;



int main(){

	for(int n,c[100],T=1;scanf("%d",&n),n;T++){

		rep(i,n)	scanf("%d",c+i);



		if(c[0]!=1){

			printf("Case #%d: Cannot pay some amount\n",T);

			continue;

		}



		const int L=2*c[n-1];

		int dp1[2000];	dp1[0]=0;

		fill(dp1+1,dp1+L,INF);

		rep(k,n)for(int p=c[k];p<L;p++)	dp1[p]=min(dp1[p],dp1[p-c[k]]+1);



		int dp2[2000];	dp2[0]=0;

		fill(dp2+1,dp2+L,INF);

		rep(p,L)for(int k=n-1;k>=0;k--){

			if(p-c[k]>=0){

				dp2[p]=dp2[p-c[k]]+1;

				break;

			}

		}



		bool ok=true;

		rep(i,L)if(dp1[i]<dp2[i]){ ok=false; break; }

		printf("Case #%d: %s\n",T,ok?"OK":"Cannot use greedy algorithm");

	}



	return 0;

}