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

using namespace std;

int main(){

    int N;

    cin>>N;

    int max=0,sum=0;

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

        int temp;

        cin>>temp;

        if(temp>max){

            sum+=max;

            max=temp;

        }

        else{

            sum+=temp;

        }

    }

    if(max<sum)

        cout<<"Yes"<<endl;

    else

    {

        cout<<"No"<<endl;

    }

    return 0;

}

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

#include<stdlib.h>

#include<math.h>

#include<ctype.h>

#include<string.h>



#define size 100005



int main()

{

    int n, i, arr[size], sum=0, max;

    scanf("%d", &n);

    max=0;



    for(i=1; i<=n; i++)

    {

        scanf("%d", &arr[i]);

        sum = sum + arr[i];

        if(arr[i]>max)

            max = arr[i];

    }



    if((sum-max)>max)

        printf("Yes\n");

    else

        printf("No\n");



    return 0;

}


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



using namespace std;



int main()

{

	int n, max = 0, sum = 0;

	cin >> n;

	for (int i = 0, j;i < n;i++)

	{

		cin >> j;

		sum += j;

		if (max < j)

			max = j;

	}

	if (max < sum - max)

		cout << "Yes";

	else

		cout << "No";



	return 0;

}

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

#include<stdlib.h>

#include<math.h>

#include<ctype.h>

#include<string.h>



#define size 100005



int main()

{

    int n, i, arr[size], sum=0, max;

    scanf("%d", &n);

    max=0;



    for(i=1; i<=n; i++)

    {

        scanf("%d", &arr[i]);

        sum = sum + arr[i];

        if(arr[i]>max)

            max = arr[i];

    }



    if((sum-max)>max)

        printf("Yes\n");

    else

        printf("No\n");



    return 0;

}


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

#include<vector>

using namespace std;

int find_max(vector<int> v)

{

	int max=0;

	for(vector<int>::size_type i=0;i!=v.size();i++)

	{

		if(v[i]>max)

		max=v[i];

	}

	return max;

}

int main()

{

	int n,i=0;

	cin>>n;

	vector<int> body;

	int m;

	while(i<n&&cin>>m)

	{

	body.push_back(m);

	i++;

}

int sum=0;

for(vector<int>::size_type i=0;i!=body.size();i++)

sum+=body[i];

if((sum-find_max(body))>find_max(body))

cout<<"Yes"<<endl;

else

cout<<"No"<<endl;

return 0;

}

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

#include<stdlib.h>

#include<math.h>

#include<ctype.h>

#include<string.h>



#define size 100005



int main()

{

    int n, i, arr[size], sum=0, max;

    scanf("%d", &n);

    max=0;



    for(i=1; i<=n; i++)

    {

        scanf("%d", &arr[i]);

        sum = sum + arr[i];

        if(arr[i]>max)

            max = arr[i];

    }



    if((sum-max)>max)

        printf("Yes\n");

    else

        printf("No\n");



    return 0;

}


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

using namespace std;

int main(){

	string str;

	cin>>str;

	int len=str.size();

	int start,end;

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

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

			start=i+1;

			break;

		}

	}

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

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

			end=i+1;

			break;

		}

	}

	cout<<end-start+1<<endl;

}

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

#include<string.h>

using namespace std;

char a[200050];

int main()

{

    while(~scanf("%s",a))

    {

        int pre=-1;

        int back=-1;

        int n=strlen(a);

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

        {

            if(a[i]=='A'&&pre==-1)pre=i;

            if(a[i]=='Z')back=i;

        }

        if(pre==-1||back==-1)

        {

            printf("0\n");

        }

        else printf("%d\n",back-pre+1);

    }

}

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

#include <cstring>

#include <cstdlib>

#include <cstdio>

#include <string>

using namespace std;

#define min(x, y) ((x < y) ? x : y)

#define rep(x, n) for (int x = 1; x <= n; ++x)

#define zrp(x, n) for (int x = n; x; --x)

const int inf = 214748364;

char s[200005];

int n;



int main()

{

	scanf("%s", s + 1);

	n = strlen(s + 1);

	int x, y;

	rep(i, n) if (s[i] == 'A')

	{

		x = i;

		break;

	}

	zrp(i, n) if (s[i] == 'Z')

	{

		y = i;

		break;

	}

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

	return 0;

}


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

#include<string.h>

using namespace std;

char a[200050];

int main()

{

    while(~scanf("%s",a))

    {

        int pre=-1;

        int back=-1;

        int n=strlen(a);

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

        {

            if(a[i]=='A'&&pre==-1)pre=i;

            if(a[i]=='Z')back=i;

        }

        if(pre==-1||back==-1)

        {

            printf("0\n");

        }

        else printf("%d\n",back-pre+1);

    }

}

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

using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

typedef pair<ll, ll> pll;

const int INF = 1e9;

const ll LINF = 1e18;

template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }

template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }

template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }

template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }



/*

 <url:>

 問題文============================================================

 =================================================================

 解説=============================================================

 ================================================================

 */

int main(void) {

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

    string s; cin >> s;

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

    return 0;

}


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

#include<string.h>

using namespace std;

char a[200050];

int main()

{

    while(~scanf("%s",a))

    {

        int pre=-1;

        int back=-1;

        int n=strlen(a);

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

        {

            if(a[i]=='A'&&pre==-1)pre=i;

            if(a[i]=='Z')back=i;

        }

        if(pre==-1||back==-1)

        {

            printf("0\n");

        }

        else printf("%d\n",back-pre+1);

    }

}

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

#include <string>

using namespace std;



int main() {

  int a = 0, z = 0, c = 0;

  string s;

  cin >> s;



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

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

      z = i;

    }

    if (!c) {

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

        a = i;

        c = 1;

      }

    }

  }

  cout<< z + 1 - a;

}


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

#include<string.h>

using namespace std;

char a[200050];

int main()

{

    while(~scanf("%s",a))

    {

        int pre=-1;

        int back=-1;

        int n=strlen(a);

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

        {

            if(a[i]=='A'&&pre==-1)pre=i;

            if(a[i]=='Z')back=i;

        }

        if(pre==-1||back==-1)

        {

            printf("0\n");

        }

        else printf("%d\n",back-pre+1);

    }

}

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

#include <cstdlib>

#include <cstring>

#include <iostream>

#include <algorithm>

typedef long long ll;

#define rep(i, a, b) for (int i = a; i <= b; ++ i)

using namespace std;

int n; char ch[200010];

int main() {

	scanf("%s", ch); n = strlen(ch);

	int a = 0, b = 0;

	rep(i, 0, n - 1) if (ch[i] == 'Z') b = i;

	for (int i = n - 1; i >= 0; -- i) if (ch[i] == 'A') a = i;

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

	return 0;

}

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

#include<string.h>

using namespace std;

char a[200050];

int main()

{

   scanf("%s",a);

    

        int pre=-1;

        int back=-1;

        int n=strlen(a);

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

        {

            if(a[i]=='A'&&pre==-1)pre=i;

            if(a[i]=='Z')back=i;

        }

        if(pre==-1||back==-1)

        {

            printf("0\n");

        }

        else printf("%d\n",back-pre+1);

    

}

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

#include<iostream>  

#include<algorithm>  

#include<cstdlib>  

#include<cstring>

#include<string>

#include<climits>

#include<vector>

#include<cmath>

#define LL long long



using namespace std;



inline char nc(){

  static char buf[100000],*p1=buf,*p2=buf;

  if (p1==p2) { p2=(p1=buf)+fread(buf,1,100000,stdin); if (p1==p2) return EOF; }

  return *p1++;

}



inline void read(int &x){

  char c=nc(),b=1;

  for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1;

  for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;

}



inline void read(LL &x){

  char c=nc(),b=1;

  for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1;

  for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;

}



int wt,ss[19];

inline void print(int x){

	if (x<0) x=-x,putchar('-'); 

	if (!x) putchar(48); else {for (wt=0;x;ss[++wt]=x%10,x/=10);for (;wt;putchar(ss[wt]+48),wt--);}

}

inline void print(LL x){

	if (x<0) x=-x,putchar('-');

	if (!x) putchar(48); else {for (wt=0;x;ss[++wt]=x%10,x/=10);for (;wt;putchar(ss[wt]+48),wt--);}

}



int main()

{

    string s;

	cin>>s;

    int a,z;

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

        if (s[i]=='A') {a=i;break;}

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

        if (s[i]=='Z') {z=i;break;}

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

}

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

#include<string.h>

using namespace std;

char a[200050];

int main()

{

   scanf("%s",a);

    

        int pre=-1;

        int back=-1;

        int n=strlen(a);

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

        {

            if(a[i]=='A'&&pre==-1)pre=i;

            if(a[i]=='Z')back=i;

        }

        if(pre==-1||back==-1)

        {

            printf("0\n");

        }

        else printf("%d\n",back-pre+1);

    

}

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

#include<cstring>

#include<iostream>

#include<stdlib.h>

#include<ctime>

#include<string>

#include<cmath>

#include<algorithm>

#include<vector>

#include<set>

#include<map>

#include<queue>

#define pb push_back

#define mp make_pair

#define fi first

#define se second

#define LL long long

#define FOR(i,a,b) for (int i=a;i<=b;i++)

#define FORD(i,a,b) for (int i=a;i>=b;i--)

using namespace std;

typedef pair<int,int> pa;

void getint(int &v){

    char ch,fu=0;

    for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar());

    if(ch=='-') fu=1, ch=getchar();

    for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0';

    if(fu) v=-v;

}

char a[2333333];

int n,p,q;

int main(){

	scanf("%s",a+1);

	n=strlen(a+1);

	FOR(i,1,n)

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

			p=i;

			break;

		}

	FORD(i,n,1)

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

			q=i;

			break;

		}

	printf("%d\n",q-p+1);

	return 0;

}


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

#include<string.h>

using namespace std;

char a[200050];

int main()

{

   scanf("%s",a);

    

        int pre=-1;

        int back=-1;

        int n=strlen(a);

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

        {

            if(a[i]=='A'&&pre==-1)pre=i;

            if(a[i]=='Z')back=i;

        }

        if(pre==-1||back==-1)

        {

            printf("0\n");

        }

        else printf("%d\n",back-pre+1);

    

}

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

#include <map>

#include <queue>

#include <ctime>

#include <cmath>

#include <cstdio>

#include <vector>

#include <string>

#include <cctype>

#include <bitset>

#include <cstring>

#include <cstdlib>

#include <utility>

#include <iostream>

#include <algorithm>

#define REP(i,a,b) for(int i=(a);i<=(b);i++)

#define PER(i,a,b) for(int i=(a);i>=(b);i--)

#define RVC(i,S) for(int i=0;i<(S).size();i++)

#define RAL(i,u) for(int i=fr[u];i!=-1;i=e[i].next)

using namespace std;

typedef long long LL;

typedef pair<int,int> pii;

     

template<class T> inline

void read(T& num) {

    bool start=false,neg=false;

    char c;

    num=0;

    while((c=getchar())!=EOF) {

        if(c=='-') start=neg=true;

        else if(c>='0' && c<='9') {

            start=true;

            num=num*10+c-'0';

        } else if(start) break;

    }

    if(neg) num=-num;

}

/*============ Header Template ============*/



const int maxn=(int)(2e5)+5;

char s[maxn];



int main() {

    scanf("%s",s+1);

    int n=strlen(s+1);

    int lst=n+1,res=0;

    REP(i,1,n) if(s[i]=='A') lst=min(lst,i); else if(s[i]=='Z') res=max(res,i-lst+1);

    printf("%d\n",res);

    return 0;

}

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

#include<string.h>

using namespace std;

char a[200050];

int main()

{

   scanf("%s",a);

    

        int pre=-1;

        int back=-1;

        int n=strlen(a);

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

        {

            if(a[i]=='A'&&pre==-1)pre=i;

            if(a[i]=='Z')back=i;

        }

        if(pre==-1||back==-1)

        {

            printf("0\n");

        }

        else printf("%d\n",back-pre+1);

    

}

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

using namespace std;



char s[200010];



int main()

{

    int a, b;



    scanf("%s", s);

    int x = strlen(s);

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

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

            a = i;

            break;

        }

    }

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

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

            b = i;

            break;

        }

    }

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

}


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

#include<string.h>

using namespace std;

char a[200050];

int main()

{

   scanf("%s",a);

    

        int pre=-1;

        int back=-1;

        int n=strlen(a);

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

        {

            if(a[i]=='A'&&pre==-1)pre=i;

            if(a[i]=='Z')back=i;

        }

        if(pre==-1||back==-1)

        {

            printf("0\n");

        }

        else printf("%d\n",back-pre+1);

    

}

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



using namespace std;



typedef long long int LLI;





int main() { 

    string str;

    while (cin >> str) {

        int n =str.length();

        int st = n, en = 0;

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

            if (str[i] == 'A') st = min(st, i);

            if (str[i] == 'Z') en = i;

        }

        cout << en-st+1 << "\n";

    }



    return 0;

}


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

#include<string.h>

using namespace std;

char a[200050];

int main()

{

   scanf("%s",a);

    

        int pre=-1;

        int back=-1;

        int n=strlen(a);

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

        {

            if(a[i]=='A'&&pre==-1)pre=i;

            if(a[i]=='Z')back=i;

        }

        if(pre==-1||back==-1)

        {

            printf("0\n");

        }

        else printf("%d\n",back-pre+1);

    

}

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

using namespace std;



int main() {

  ios::sync_with_stdio(false);

  cin.tie(nullptr);

  string s; cin >> s;

  int a = 0;

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

    a = i;

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

  }

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

  int z = n - 1;

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

    z = i;

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

  }

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

  return 0;

}


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

#include<string.h>

using namespace std;

char a[200050];

int main()

{

   scanf("%s",a);

    

        int pre=-1;

        int back=-1;

        int n=strlen(a);

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

        {

            if(a[i]=='A'&&pre==-1)pre=i;

            if(a[i]=='Z')back=i;

        }

        if(pre==-1||back==-1)

        {

            printf("0\n");

        }

        else printf("%d\n",back-pre+1);

    

}

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

#include <cmath>



#include <iostream>

#include <vector>

#include <string>



using namespace std;



int main(int argc, char const *argv[]) {

	string str;



	cin >> str;



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



	return 0;

}

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

#include<string.h>

using namespace std;

char a[200050];

int main()

{

   scanf("%s",a);

    

        int pre=-1;

        int back=-1;

        int n=strlen(a);

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

        {

            if(a[i]=='A'&&pre==-1)pre=i;

            if(a[i]=='Z')back=i;

        }

        if(pre==-1||back==-1)

        {

            printf("0\n");

        }

        else printf("%d\n",back-pre+1);

    

}

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

#include <string>

using namespace std;



int main(){

	string s;

	cin >> s;

	int l = -1, r = -1;

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

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

			l = i;

			break;

		}

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

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

			r = i;

			break;

		}

	if(l == -1 || r == -1 || r < l)

		cout << 0 << endl;

	else

		cout << r - l + 1 << endl;

	return 0;

}


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

#include<string.h>

using namespace std;

char a[200050];

int main()

{

   scanf("%s",a);

    

        int pre=-1;

        int back=-1;

        int n=strlen(a);

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

        {

            if(a[i]=='A'&&pre==-1)pre=i;

            if(a[i]=='Z')back=i;

        }

        if(pre==-1||back==-1)

        {

            printf("0\n");

        }

        else printf("%d\n",back-pre+1);

    

}

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

#include <string>

#include <vector>



using namespace std;



int main()

{

    string s;

    cin >> s;



    int pos = 0;

    int num = 0;



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

        if (s[i] == 65){

            pos = i;

            break;

        }

    }



    int num2 = 0;



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

        num++;

        if (s[i] == 90){

            if (num > num2){

                num2 = num;

            }

        }

    }



    cout << num2 << endl;

    return 0;

}

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

#include<string.h>

using namespace std;

char a[200050];

int main()

{

   scanf("%s",a);

    

        int pre=-1;

        int back=-1;

        int n=strlen(a);

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

        {

            if(a[i]=='A'&&pre==-1)pre=i;

            if(a[i]=='Z')back=i;

        }

        if(pre==-1||back==-1)

        {

            printf("0\n");

        }

        else printf("%d\n",back-pre+1);

    

}

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

using namespace std;

typedef long long ll;

int  main(){

    string s;

    //int flat=1;

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

    cin>>s;

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

return 0;

}


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

#include<string.h>

using namespace std;

char a[200050];

int main()

{

   scanf("%s",a);

    

        int pre=-1;

        int back=-1;

        int n=strlen(a);

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

        {

            if(a[i]=='A'&&pre==-1)pre=i;

            if(a[i]=='Z')back=i;

        }

        if(pre==-1||back==-1)

        {

            printf("0\n");

        }

        else printf("%d\n",back-pre+1);

    

}

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

using namespace std;

int main(){

	string s;

	cin>>s;

	int start=0,end=0;

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

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

			start=i;

			break;

		}

	}

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

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

	}

	cout<<end-start+1;

	return 0;

} 

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

#include<string.h>

using namespace std;

char a[200050];

int main()

{

   scanf("%s",a);

    

        int pre=-1;

        int back=-1;

        int n=strlen(a);

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

        {

            if(a[i]=='A'&&pre==-1)pre=i;

            if(a[i]=='Z')back=i;

        }

        if(pre==-1||back==-1)

        {

            printf("0\n");

        }

        else printf("%d\n",back-pre+1);

    

}

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

#include<iomanip>

#include<cstdio>

#include<algorithm>

#include<math.h>

#include <string.h>

using namespace std;

int main(){

	int i,j,m,n,a,b;

	string s;

	while(cin>>s){

		n=s.length();

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

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

				b=i;

			}

		}

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

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

				a=i;

				break;

			}

		}

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

	} 

	return 0;

}

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

#include<string.h>

using namespace std;

char a[200050];

int main()

{

   scanf("%s",a);

    

        int pre=-1;

        int back=-1;

        int n=strlen(a);

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

        {

            if(a[i]=='A'&&pre==-1)pre=i;

            if(a[i]=='Z')back=i;

        }

        if(pre==-1||back==-1)

        {

            printf("0\n");

        }

        else printf("%d\n",back-pre+1);

    

}

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

#include<cstring>

using namespace std;

char s[200001];

int main(){

	cin>>s;

	char *start,*end;

	end=strrchr(s,'Z');

	start=strchr(s,'A');

//	if(end==NULL||start==NULL){

//		cout<<"-1"<<endl;

//	}

//	else{

		cout<<end-start+1<<endl;

//	}

	return 0;

}

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

#include<string.h>

using namespace std;

char a[200050];

int main()

{

   scanf("%s",a);

    

        int pre=-1;

        int back=-1;

        int n=strlen(a);

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

        {

            if(a[i]=='A'&&pre==-1)pre=i;

            if(a[i]=='Z')back=i;

        }

        if(pre==-1||back==-1)

        {

            printf("0\n");

        }

        else printf("%d\n",back-pre+1);

    

}

// Fastest known solution for this problem: