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

#include<bits/stdc++.h>

using namespace std;

long long int a[1000][1000],b[1000][1000],c[1000][1000];

//char x[1050][150],y[100050][20];



int main()

{

    long long int i,n,m,j,k,x,y;

    long long  int sum=0;

    scanf("%lld",&n);

    //memset(b,1,sizeof(b));

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

    {

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

        {

            scanf("%lld",&a[i][j]);



        }

    }

    memset(c,0,sizeof(c));

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

    {

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

        {

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

            {

                if(b[i][j]==0)

                {

                    b[i][j]=a[i][j];

                }

                b[i][j]=min(b[i][j],a[i][k]+a[k][j]);

                if((a[i][j]>=a[i][k]+a[k][j])&&(i!=k&&j!=k))

                {

                    c[i][j]=1;

                    b[i][j]=a[i][k]+a[k][j];

                }

            }

        }

    }

    int f=0;

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

    {

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

        {

            if(a[i][j]!=b[i][j])

            {

                f=-1;

                break;

            }if((c[i][j]!=1)&&(a[i][j]==b[i][j]))

            {

                sum+=b[i][j];

            }

        }

        if(f==-1)

        {

            break;

        }

    }

    if(f==-1)

    {

        printf("-1");

    }else

    {

        printf("%lld",sum);

    }

    return 0;

}


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



int main()

{

    int a[309][309], n;

    while(~scanf("%d", &n))

    {

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

            for(int j = 1; j <= n; j++)

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

        long long ans = 0;

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

        {

            for(int j = 1; j < i; j++)

            {

                bool flag = 1;

                for(int k = 1; k <= n; k++)

                {

                    if(a[i][j] > a[i][k] + a[k][j])

                    {

                        printf("-1\n");

                        return 0;

                    }

                    else if(i != k && k != j && a[i][j] == a[i][k] + a[k][j])

                        flag = 0;

                }

                if(flag)

                    ans += a[i][j];

            }

        }

        printf("%lld\n", ans);

    }

    return 0;

}


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

using namespace std;

#define INF 0x3f3f3f3f;

long long a,b,v,i,n,m,k,l,an[100010],ans=0,vis[10000],j;

long long ma[600][600],dist[6000],S,vis2[610][610],vis3[6000];

int flag=0;

void dijkstra(long long x)

{//printf("ok\n");

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

        dist[i]=(i==x)?0:INF;

    memset(vis,0,sizeof(vis));

   memset(vis3,0,sizeof(vis3));

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

    {

        int mark=-1,mindis=INF;

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

        {

            if(!vis[j]&&dist[j]<mindis)

            {

                mindis=dist[j];

                mark=j;

            }

        }

        vis[mark]=1;

        for(int j=1; j<=n; j++)

        {

            if(!vis[j])

            {

                if(dist[j]>=(dist[mark]+ma[mark][j])&&mark!=x&&mark!=j) {vis3[j]=1;}

                dist[j]=min(dist[j],dist[mark]+ma[mark][j]);

            }

        }

    }

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

    {  //printf("*%lld*",vis3[i]);

        if(dist[i]<=ma[x][i])

        {

            if(vis3[i]==1){vis2[x][i]=1;vis2[i][x]=1;}

            if(dist[i]<ma[x][i])

            {

                flag=1;

            }

        }

    }

   //printf("\n");

}

int main()

{

    scanf("%lld",&n);

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

    {

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

        {

            scanf("%lld",&ma[i][j]);

        }



    }

    ans=0;

    flag=0;



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

    {

        dijkstra(l);

        if(flag==1) break;

    }

    if(flag==0)

    {

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



        {

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

            {

                if(vis2[i][j]!=1) ans+=ma[i][j];

            }

        }

        printf("%lld\n",ans);

    }

    else printf("-1\n");

    return 0;

}




// Optimized solution to the same problem (faster):
#pragma GCC optimize("O1")

#pragma GCC optimize("O2")

#pragma GCC optimize("O3")

#include<cstdio>

#define LL long long

#define N 310

int n;

LL g[N][N];

signed main()

{

	scanf("%d",&n);LL ans(0);

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

		for(register int j(1);j<=n;j++)

			scanf("%lld",&g[i][j]);

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

		for(register int j(1);j<=i;j++)

		{

			bool f(1);

			for(register int k(1);k<=n;k++)

				if(g[i][j]>g[i][k]+g[k][j])

					return puts("-1"),0;

				else if(i-k&&j-k&&g[i][j]==g[i][k]+g[k][j])

					f=0;

			ans+=g[i][j]*f;

		}

	return printf("%lld\n",ans),0;

}

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

#include <cstdio>

using namespace std;

long long a[310][310];

bool b[310][310];

int main() {



//	freopen("4.in","r",stdin);



	long long n,ans=0;

	int i,j,k;



	scanf("%lld",&n);



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

		for(j=1; j<=n; j++) {

			scanf("%lld",&a[i][j]);

		}

	}



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

		for(j=1; j<=n; j++) {

			for(k=1; k<=n; k++) {

				if(i!=j&&j!=k&&k!=i) {

					if(a[i][j]==a[i][k]+a[k][j]) b[i][j]=1;

					if(a[i][j]>a[i][k]+a[k][j]) {

						printf("-1");

						return 0;

					}

				}

			}

		}

	}



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

		for(j=1; j<=n; j++) {

			if(!b[i][j]) ans+=a[i][j];

		}

	}

	

	printf("%lld",ans/2);



	return 0;

}

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

int a[305][305];

bool v[305][305];

long long ans;

main(){

	int n;scanf("%d",&n);

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

		for(register int j=1;j<=n;j++)

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

	for(register int k=1;k<=n;k++){

		for(register int i=1;i<=n;i++){

			for(register int j=1;j<=n;j++){

				if(k!=i&&k!=j&&i!=j){

					if(a[i][j]==a[i][k]+a[k][j])

						v[i][j]=1;

					else if(a[i][j]>a[i][k]+a[k][j]){

						puts("-1");

						return 0;

					}

				}

			}

		}

	}

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

		for(register int j=1;j<=n;j++)

			if(!v[i][j])

				ans+=a[i][j];

	printf("%lld\n",ans/2);

	return 0; 

} 

// Fastest known solution for this problem:
// Original C++ solution (slower):


#include<iostream>

#include<cstdio>

#include<cstdlib>

#include<string>

#include<cstring>

#include<cmath>

#include<ctime>

#include<algorithm>

#include<utility>

#include<stack>

#include<queue>

#include<vector>

#include<set>

#include<map>

#include<bitset>

#define EPS 1e-9

#define PI acos(-1.0)

#define INF 0x3f3f3f3f

#define LL long long

const int MOD = 1E9+7;

const int N = 1000+5;

const int dx[] = {-1,1,0,0,-1,-1,1,1};

const int dy[] = {0,0,-1,1,-1,1,-1,1};

using namespace std;

 

LL G[N][N];

int main() {

    int n;

    scanf("%d",&n);

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

        for(int j=1;j<=n;j++)

            scanf("%lld",&G[i][j]);

 

    bool flag=false;

    LL res=0;

    for(int i=1;i<=n&&!flag;i++){

        for(int j=i+1;j<=n&&!flag;j++){

            bool flag2=false;

            for(int k=1;k<=n&&!flag;k++){

                if(G[i][k]+G[k][j]<G[i][j])

                    flag=true;

                else{

                    if(i!=k&&j!=k&&G[i][j]==G[i][k]+G[k][j])

                        flag2=true;

                }

            }

            if(!flag2)

                res+=G[i][j];

        }

    }

 

    if(flag)

        printf("-1\n");

    else

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

 

    return 0;

}

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

int a[305][305];

bool v[305][305];

long long ans;

main(){

	int n;scanf("%d",&n);

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

		for(register int j=1;j<=n;j++)

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

	for(register int k=1;k<=n;k++){

		for(register int i=1;i<=n;i++){

			for(register int j=1;j<=n;j++){

				if(k!=i&&k!=j&&i!=j){

					if(a[i][j]==a[i][k]+a[k][j])

						v[i][j]=1;

					else if(a[i][j]>a[i][k]+a[k][j]){

						puts("-1");

						return 0;

					}

				}

			}

		}

	}

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

		for(register int j=1;j<=n;j++)

			if(!v[i][j])

				ans+=a[i][j];

	printf("%lld\n",ans/2);

	return 0; 

} 

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

#include<cstring>

using namespace std;

int main(){



    long long int n,ans=0,i,j,k;

    cin>>n;

    long long int a[n+1][n+1];

    bool p[n+1][n+1];

    memset(p,0,sizeof(p));

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

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

            cin>>a[i][j];

    //读入数据以及初始化操作



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

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

            for(j=1;j<=n;j++){

                if(k!=j&&k!=i&&i!=j){

                    if(a[i][j]==a[i][k]+a[k][j])

                        p[i][j]=1;  //标记

                    if(a[i][j]>a[i][k]+a[k][j]){

                        cout<<"-1"<<endl;  //不是最短路，无解

                        return 0;

                    }

                }

            }

    //核心操作语句



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

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

            if(p[i][j]==0)

                ans+=a[i][j]; //统计长度总和

    cout<<ans/2<<endl;

    //统计总和及输出



    return 0;

}

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

int a[305][305];

bool v[305][305];

long long ans;

main(){

	int n;scanf("%d",&n);

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

		for(register int j=1;j<=n;j++)

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

	for(register int k=1;k<=n;k++){

		for(register int i=1;i<=n;i++){

			for(register int j=1;j<=n;j++){

				if(k!=i&&k!=j&&i!=j){

					if(a[i][j]==a[i][k]+a[k][j])

						v[i][j]=1;

					else if(a[i][j]>a[i][k]+a[k][j]){

						puts("-1");

						return 0;

					}

				}

			}

		}

	}

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

		for(register int j=1;j<=n;j++)

			if(!v[i][j])

				ans+=a[i][j];

	printf("%lld\n",ans/2);

	return 0; 

} 

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

using namespace std;

int main()

{



    long long int n,ans=0,i,j,k;

    cin>>n;

    long long int a[n+1][n+1];

    bool p[n+1][n+1];

    memset(p,0,sizeof(p));

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

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

            cin>>a[i][j];

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

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

            for(j=1;j<=n;j++){

                if(k!=j&&k!=i&&i!=j){

                    if(a[i][j]==a[i][k]+a[k][j])

                        p[i][j]=1; 

                    if(a[i][j]>a[i][k]+a[k][j]){

                        cout<<"-1"<<endl;  

                        return 0;

                    }

                }

            }





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

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

            if(p[i][j]==0)

                ans+=a[i][j]; 

    cout<<ans/2<<endl;



    return 0;

}

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

int a[305][305];

bool v[305][305];

long long ans;

main(){

	int n;scanf("%d",&n);

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

		for(register int j=1;j<=n;j++)

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

	for(register int k=1;k<=n;k++){

		for(register int i=1;i<=n;i++){

			for(register int j=1;j<=n;j++){

				if(k!=i&&k!=j&&i!=j){

					if(a[i][j]==a[i][k]+a[k][j])

						v[i][j]=1;

					else if(a[i][j]>a[i][k]+a[k][j]){

						puts("-1");

						return 0;

					}

				}

			}

		}

	}

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

		for(register int j=1;j<=n;j++)

			if(!v[i][j])

				ans+=a[i][j];

	printf("%lld\n",ans/2);

	return 0; 

} 

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

using namespace std;

typedef long long ll;

const int N = 301;

int a[N][N];

ll sum;

int main() {

	int n;



	cin >> n;

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

		for (int j = 1; j <= n; j++)

			cin >> a[i][j];



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

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

			bool temp = true;

			for (int k = 1; k <= n; k++) {

				if (k == i || k == j)

					continue;

				if (a[i][k] + a[k][j] < a[i][j]) {

					cout << -1 << endl;

					return 0;

				}

				if (a[i][k] + a[k][j] == a[i][j])

					temp = false;

			}

			if (temp)

				sum += a[i][j];

		}



	cout << sum << endl;



	return 0;

}

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

#define LL long long

#define N 310

int n;

LL g[N][N];

signed main()

{

	scanf("%d",&n);LL ans(0);

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

		for(register int j(1);j<=n;j++)

			scanf("%lld",&g[i][j]);

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

		for(register int j(1);j<=i;j++)

		{

			bool f(1);

			for(register int k(1);k<=n;k++)

				if(g[i][j]>g[i][k]+g[k][j])

					return puts("-1"),0;

				else if(i-k&&j-k&&g[i][j]==g[i][k]+g[k][j])

					f=0;

			ans+=g[i][j]*f;

		}

	return printf("%lld\n",ans),0;

}

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

#include <vector>

#include <cstdio> 

using namespace std;



typedef long long LL;



const int MAXN = 320;

const int INF = 1e9 + 100;



int n, dis[MAXN][MAXN];



namespace Part1 {

	struct Edge {

		int u, v;

	}; 

	bool tag[MAXN * MAXN];

	vector<Edge> e;

	int G[MAXN][MAXN];

	LL ans(2e18);

	void Judge() {

		LL cost = 0LL;

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

			for(int j = 1; j <= n; j ++)

				G[i][j] = i == j ? 0 : INF;

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

			if(tag[i]) {

				cost += dis[ e[i].u ][ e[i].v ];

				if(cost > ans) return ;

				G[ e[i].u ][ e[i].v ] = G[ e[i].v ][ e[i].u ] = dis[ e[i].u ][ e[i].v ];

			}

		for(int k = 1; k <= n; k ++)

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

				for(int j = 1; j <= n; j ++)

					if(G[i][k] < INF && G[k][j] < INF)

						G[i][j] = min(G[i][j], G[i][k] + G[k][j]);

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

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

				if(dis[i][j] != G[i][j]) return ;

		if(ans > cost) ans = cost;

	}

	

	void dfs(int k, int m) {

		if(k == m) {

			Judge() ;

			return ;

		}

		tag[k] = true, dfs(k + 1, m);

		tag[k] = false, dfs(k + 1, m);

	}

	

	int main() {

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

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

				e.push_back((Edge) {i, j});

		for(int i = 0; i < e.size(); i ++) tag[i] = false;

		dfs(0, (int) e.size());

		printf("%lld\n", ans == 2e18 ? -1 : ans);

		return 0;

	}

}



namespace Part2 {

	int main() {

		LL ans = 0;

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

			for(int j = 1; j <= n; j ++) {

				bool flag = false;

				for(int k = 1; k <= n; k ++) {

					if(k == i || k == j) continue ;

					if(dis[i][k] + dis[k][j] == dis[i][j]) {

						flag = true;

						break ;

					}

				}

				if(!flag) ans += dis[i][j];

			}

		}

		printf("%lld\n", ans / 2LL);

		return 0;

	}

}



bool error__() {

	for(int k = 1; k <= n; k ++)

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

			for(int j = 1; j <= n; j ++)

				if(dis[i][j] > dis[i][k] + dis[k][j]) return true;

	return false;

}



int main() {

	scanf("%d", &n);

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

		for(int j = 1; j <= n; j ++) {

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

		}

	}

	if(error__()) return puts("-1"), 0;



	if(n <= 6) Part1 :: main();

	else Part2 :: main(); 

	return 0;

}

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

#define LL long long

#define N 310

int n;

LL g[N][N];

signed main()

{

	scanf("%d",&n);LL ans(0);

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

		for(register int j(1);j<=n;j++)

			scanf("%lld",&g[i][j]);

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

		for(register int j(1);j<=i;j++)

		{

			bool f(1);

			for(register int k(1);k<=n;k++)

				if(g[i][j]>g[i][k]+g[k][j])

					return puts("-1"),0;

				else if(i-k&&j-k&&g[i][j]==g[i][k]+g[k][j])

					f=0;

			ans+=g[i][j]*f;

		}

	return printf("%lld\n",ans),0;

}

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

using namespace std;

vector<vector<long long > > A(310, vector<long long > (310)), dist(310, vector<long long > (310));

int main() {

    int n;

    cin >> n;

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

	{

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

		{

            cin >> A[i][j];

            dist[i][j]=A[i][j];

        }

    }

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

	{

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

		{

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

			{

                dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);

            }

        }

    }

    long long ans=0;

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

	{

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

		{

            if(dist[i][v]<A[i][v])

			{

                cout<<-1<<endl;

                return 0;

            }

            int flag = 0;

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

			{

                if(j!=i&&j!=v&&dist[i][v]==dist[i][j]+dist[j][v])

				{

                    flag=1;

                }

            }

            if(!flag)

			{

                ans+=dist[i][v];

            }

        }

    }

    cout<<ans<<endl;

    return 0;

}

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

using namespace std;



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



long long a[310][310];

bool used[310][310];



int main(void){

    long long N,ans=0;

    cin >> N;

    REP(i,N) REP(j,N)

        cin >> a[i][j];

    REP(k,N) REP(i,N) REP(j,N)

        if(k!=j && k!=i && i!=j) {

            if(a[i][j] == a[i][k]+a[k][j])

                used[i][j] = true;

            if(a[i][j] > a[i][k]+a[k][j]) {

                cout << "-1" << endl;

                return 0;

            }

        }

    REP(i,N) REP(j,N)

        if(used[i][j] == false) ans += a[i][j];

    cout << ans/2 << endl;

    return 0;

}

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



#define int long long



using namespace std;



const int N = 5e5 + 5;

const int base = 317;

const int mod = 1e9 + 2277;



string s;

int Hash[N], pw[N], n;

bool pref[N], suff[N];



void buildHash(){

    s = "#" + s;

    pw[0] = 1;

    for (int i = 1; i < N; i++) pw[i] = (pw[i - 1] * base) % mod;

    Hash[0] = 0;

    for (int i = 1; i <= n; i++) Hash[i] = (Hash[i - 1] * base + s[i]) % mod;

}



int get (int l, int r) {

    return ((1LL * Hash[r] - 1LL * Hash[l - 1] * pw[r - l + 1]) % mod + mod) % mod;

}



signed main(){

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);



    cin >> s;

    n = s.length();



    bool same = true;

    for (int i = 0; i < n; i++) if (s[i] != s[0]) same = false;

    if (same) {

        cout << n << "\n" << 1;

        return 0;

    }



    buildHash();

    memset(pref, 0, sizeof(pref));

    memset(suff, 0, sizeof(suff));



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

        for (int j = i * 2; j <= n; j = j + i) {

            if (get(1, i) == get(j - i + 1, j)) pref[j] = true;

            else break;

        }

    }



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

        for (int j = n - i * 2 + 1; j >= 1; j = j - i) {

            if (get(j, j + i - 1) == get(n - i + 1, n)) suff[j] = true;

            else break;

        }

    }



    if (!pref[n]) return cout << 1 << "\n" << 1, 0;

    int ans = 0;

    for (int i = 1; i < n; i++) if (!pref[i] && !suff[i + 1]) ans++;

    cout << 2 << "\n" << ans;

    return 0;

}


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

#include <string.h>

#include <algorithm>

#define Maxn 500005

char s[Maxn];

int n, ans, fail1[Maxn], fail2[Maxn];

void buildFail(char *s, int *fail) {

	int j = fail[0] = -1;

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

		while (j >= 0 && s[j] != s[i - 1]) j = fail[j];

		fail[i] = ++ j;

	}

}

int main() {

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

	buildFail(s, fail1);

	int len = n % (n - fail1[n]) == 0 && (n - fail1[n] <= n / 2) ? n - fail1[n] : -1;

	if (len == -1) return puts("1\n1") & 0;

	if (len == 1) return printf("%d\n1\n", n) & 0;

	puts("2"); std :: reverse(s, s + n);

	buildFail(s, fail2); for (int i = 1; i < n; ++ i)

		if ((!fail1[i] || i % (i - fail1[i])) && (!fail2[n - i] || (n - i) % ((n - i) - fail2[n - i]))) ++ ans;

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

	return 0;

}

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

using namespace std;

typedef long long ll;

const int N=2e6+20;

const ll mod=1e9+7;

char s[N],t[N];

int fail[N],suf[N];

void getfail(int *fail,char *s)

{

	fail[0]=-1;

	int i=0,j=-1;

	while(s[i])

	{

		if(j==-1||s[i]==s[j])

		{

			fail[i+1]=j+1;

			i++,j++;

		}

		else

			j=fail[j];

	}

}

int main()

{

	while(scanf("%s",s)!=EOF)

	{

		ll ans=0;

		int len=strlen(s);

		for(int i=0;s[i];i++)

			t[i]=s[len-i-1];

		t[len]='\0';

		getfail(fail,s);

		getfail(suf,t);

		int m;

	//	cout<<fail[len]<<endl;

		if(fail[len]==0||len%(len-fail[len]))

			m=1;

		else

			m=2;

		bool flag=true;

		for(int i=1;s[i];i++)

		{

			if(s[i]!=s[i-1])

				flag=false;

		}	

		if(flag)

			m=len;

		if(m==1||flag)

			ans=1;

		else

		{

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

			{

				int k=len-i-1;

			//	cout<<i<<' '<<k<<endl;

				if((fail[i+1]==0||(i+1)%((i+1)-fail[i+1])) &&(suf[k]==0||(k)%(k-suf[k])))

					ans++;

			}

		}	

		cout<<m<<endl<<ans<<endl;

	}

	return 0;

}


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

#include <string.h>

#include <algorithm>

#define Maxn 500005

char s[Maxn];

int n, ans, fail1[Maxn], fail2[Maxn];

void buildFail(char *s, int *fail) {

	int j = fail[0] = -1;

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

		while (j >= 0 && s[j] != s[i - 1]) j = fail[j];

		fail[i] = ++ j;

	}

}

int main() {

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

	buildFail(s, fail1);

	int len = n % (n - fail1[n]) == 0 && (n - fail1[n] <= n / 2) ? n - fail1[n] : -1;

	if (len == -1) return puts("1\n1") & 0;

	if (len == 1) return printf("%d\n1\n", n) & 0;

	puts("2"); std :: reverse(s, s + n);

	buildFail(s, fail2); for (int i = 1; i < n; ++ i)

		if ((!fail1[i] || i % (i - fail1[i])) && (!fail2[n - i] || (n - i) % ((n - i) - fail2[n - i]))) ++ ans;

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

	return 0;

}

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



using namespace std;



typedef long long ll;



const int N=2e6+20;

const ll mod=1e9+7;

char s[N],t[N];

int fail[N],suf[N];



void getfail(int *fail,char *s){

	fail[0]=-1;

	int i=0,j=-1;

	while(s[i]){

		if(j==-1||s[i]==s[j]){

			fail[i+1]=j+1;

			i++,j++;

		}

		else

			j=fail[j];

	}

}

int main(){

	while(scanf("%s",s)!=EOF){

		ll ans=0;

		int len=strlen(s);

		for(int i=0;s[i];i++)	t[i]=s[len-i-1];

		t[len]='\0';

		getfail(fail,s);

		getfail(suf,t);

		int m;

		if(fail[len]==0||len%(len-fail[len]))	m=1;

		else	m=2;

		bool flag=true;

		for(int i=1;s[i];i++)

			if(s[i]!=s[i-1])	flag=false;

		if(flag)	m=len;

		if(m==1||flag)	ans=1;

		else

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

				int k=len-i-1;

				if((fail[i+1]==0||(i+1)%((i+1)-fail[i+1])) &&(suf[k]==0||(k)%(k-suf[k])))	ans++;

			}

		cout<<m<<endl<<ans<<endl;

	}

	return 0;

}


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

#include <string.h>

#include <algorithm>

#define Maxn 500005

char s[Maxn];

int n, ans, fail1[Maxn], fail2[Maxn];

void buildFail(char *s, int *fail) {

	int j = fail[0] = -1;

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

		while (j >= 0 && s[j] != s[i - 1]) j = fail[j];

		fail[i] = ++ j;

	}

}

int main() {

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

	buildFail(s, fail1);

	int len = n % (n - fail1[n]) == 0 && (n - fail1[n] <= n / 2) ? n - fail1[n] : -1;

	if (len == -1) return puts("1\n1") & 0;

	if (len == 1) return printf("%d\n1\n", n) & 0;

	puts("2"); std :: reverse(s, s + n);

	buildFail(s, fail2); for (int i = 1; i < n; ++ i)

		if ((!fail1[i] || i % (i - fail1[i])) && (!fail2[n - i] || (n - i) % ((n - i) - fail2[n - i]))) ++ ans;

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

	return 0;

}

// Fastest known solution for this problem: