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

#include <string.h>

#define MN 100005

long long n,k,a[MN],b[MN],c[MN],K,ans=0,tc=0;

inline long long min(long long a,long long b){return a<b?a:b;}

inline long long max(long long a,long long b){return a>b?a:b;}

int main(){

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

	memset(b,0,sizeof(b));

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

	scanf("%lld%lld",&n,&k);

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

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

		b[i]=b[i-1]; b[i]+=a[i];

		c[i]=c[i-1];

		if(a[i]>0){

			c[i]+=a[i];

			tc+=a[i];

		}

	}

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

		ans=max(ans,tc-(c[i]-c[i-k]));// printf("%lld\n",ans);

		ans=max(ans,tc-(c[i]-c[i-k])+(b[i]-b[i-k]));// printf("%lld\n",ans);

	}

	printf("%lld",ans);

}

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

#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

int n,k;

long long a[100000+10],pre[100000+10];

long long ans,sum,minn,maxx,want;

int main(){

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

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

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

		sum+=a[i];

		pre[i]=pre[i-1]+a[i];

		if(a[i]>=0)want+=a[i];

	}

	//最后白：

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

//		long long judge=want;

//		for(int j=i;j<=i+k-1;j++){

//			if(a[j]>=0)judge-=a[j];

//		}

//		ans=max(ans,judge);

//	} 

	long long judge=want;

	for(int i=1;i<=k;i++)if(a[i]>=0)judge-=a[i];

	ans=max(ans,judge);

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

		if(a[i-k]>=0)judge+=a[i-k];

		if(a[i]>=0)judge-=a[i];

		ans=max(ans,judge);

	}

	//最后黑：

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

//		long long judge=want;

//		for(int j=i;j<=i+k-1;j++){

//			if(a[j]<0)judge+=a[j];

//		}

//		ans=max(ans,judge);

//	} 

	judge=want;

	for(int i=1;i<=k;i++)if(a[i]<=0)judge+=a[i];

	ans=max(ans,judge);

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

		if(a[i-k]<=0)judge-=a[i-k];

		if(a[i]<=0)judge+=a[i];

		ans=max(ans,judge);

	}

	cout<<ans<<endl;

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

#include <string.h>

#define MN 100005

long long n,k,a[MN],b[MN],c[MN],K,ans=0,tc=0;

inline long long min(long long a,long long b){return a<b?a:b;}

inline long long max(long long a,long long b){return a>b?a:b;}

int main(){

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

	memset(b,0,sizeof(b));

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

	scanf("%lld%lld",&n,&k);

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

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

		b[i]=b[i-1]; b[i]+=a[i];

		c[i]=c[i-1];

		if(a[i]>0){

			c[i]+=a[i];

			tc+=a[i];

		}

	}

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

		ans=max(ans,tc-(c[i]-c[i-k]));// printf("%lld\n",ans);

		ans=max(ans,tc-(c[i]-c[i-k])+(b[i]-b[i-k]));// printf("%lld\n",ans);

	}

	printf("%lld",ans);

}

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

using namespace std;

#define rg register 

#define ll long long

inline ll read()

{

	ll x=0,f=1;

	char c=getchar();

	while(c<'0'||c>'9')

	{

		if(c=='-')

		{

			f=-1;

		}

		c=getchar();

	}

	while(c<='9'&&c>='0')

	{

		x=(x<<1)+(x<<3)+(c^48);

		c=getchar();

	}

	return x*f;

}

int n,k;

ll a[200000];

ll s[200000];

ll ss[200000];

ll sum;

ll maxx;

int main()

{

	n=read();

	k=read();

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

	{

		a[i]=read();

		s[i]=s[i-1]+a[i];

		if(a[i]>0)//用来保存区间外面的正数 

		{

			ss[i]=ss[i-1]+a[i];

		}

		else

		{

			ss[i]=ss[i-1];

		}

	}

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

	{

		sum=0;

		ll j=i+k-1;//右端点 

		if(s[j]-s[i-1]>=0)

		{

			sum+=s[j]-s[i-1];

		}

		sum+=(ss[n]-ss[j]);//统计区间外正数 

		sum+=(ss[i-1]-ss[0]);

		maxx=max(maxx,sum);	

	}

	cout<<maxx;

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

#include <string.h>

#define MN 100005

long long n,k,a[MN],b[MN],c[MN],K,ans=0,tc=0;

inline long long min(long long a,long long b){return a<b?a:b;}

inline long long max(long long a,long long b){return a>b?a:b;}

int main(){

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

	memset(b,0,sizeof(b));

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

	scanf("%lld%lld",&n,&k);

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

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

		b[i]=b[i-1]; b[i]+=a[i];

		c[i]=c[i-1];

		if(a[i]>0){

			c[i]+=a[i];

			tc+=a[i];

		}

	}

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

		ans=max(ans,tc-(c[i]-c[i-k]));// printf("%lld\n",ans);

		ans=max(ans,tc-(c[i]-c[i-k])+(b[i]-b[i-k]));// printf("%lld\n",ans);

	}

	printf("%lld",ans);

}

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

#define MAXN ((int)(1e5+10))

#define INF ((int)(1e9))

using namespace std;

typedef long long LL;

int n,k;

LL a[MAXN],sum=0,ans=-INF,tmp=0;

int main()

{

	cin>>n>>k;

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

	{

		cin>>a[i];

		tmp+=a[i];

		if(a[i]>0)

			sum+=a[i];

	}

	LL integer=0,fu=0;

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

	{

		if(a[i]>0)

			integer+=a[i];

		else

			fu+=(0-a[i]);

	}

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

	{

		LL rec;

		if(integer>=fu)

			rec=sum-fu;

		else

			rec=sum-integer;

		ans=max(ans,rec);

		if(a[i]>0)

			integer-=a[i];

		else

			fu-=(0-a[i]);

		if(a[i+k]>0)

			integer+=a[i+k];

		else

			fu+=(0-a[i+k]);

	}

	cout<<ans<<endl;

	return 0;

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

#include <string.h>

#define MN 100005

long long n,k,a[MN],b[MN],c[MN],K,ans=0,tc=0;

inline long long min(long long a,long long b){return a<b?a:b;}

inline long long max(long long a,long long b){return a>b?a:b;}

int main(){

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

	memset(b,0,sizeof(b));

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

	scanf("%lld%lld",&n,&k);

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

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

		b[i]=b[i-1]; b[i]+=a[i];

		c[i]=c[i-1];

		if(a[i]>0){

			c[i]+=a[i];

			tc+=a[i];

		}

	}

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

		ans=max(ans,tc-(c[i]-c[i-k]));// printf("%lld\n",ans);

		ans=max(ans,tc-(c[i]-c[i-k])+(b[i]-b[i-k]));// printf("%lld\n",ans);

	}

	printf("%lld",ans);

}

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

#include<ext/pb_ds/assoc_container.hpp>

#include<ext/pb_ds/tree_policy.hpp>

#define pi 3.141592653589793238

#define int long long

using namespace __gnu_pbds;

using namespace std;

template <typename T>

using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;



int pre[100005];

int pos[100005];





signed main()

{

ios_base::sync_with_stdio(false);

cin.tie(NULL);  

cout.tie(0);   



#ifndef ONLINE_JUDGE

	if(fopen("INPUT.txt","r"))

	{

	freopen ("INPUT.txt" , "r" , stdin);

	freopen ("OUTPUT.txt" , "w" , stdout);

	}

#endif  



	int n,k;

	cin>>n>>k;

	int a[n+1];

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

	{

		cin>>a[i];

		pre[i]=pre[i-1]+a[i];

		pos[i]=pos[i-1]+max(a[i],0LL);

	}

	int mx=0;

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

	{

		mx=max(mx,pos[i-k]+pos[n]-pos[i]);

		mx=max(mx,pos[i-k]+pos[n]-pos[i]+pre[i]-pre[i-k]);

	}

	cout<<mx;

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

#include<string>

#include<algorithm>

#include<vector>

using namespace std;

long long p[200000], q[200000], n, k;

int main() {

	cin >> n >> k;

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

		long long a; cin >> a;

		if (a > 0)p[i] += a;

		q[i] += a;

	}

	for (long long i = 1; i < 200000; i++)p[i] += p[i - 1];

	for (long long i = 1; i < 200000; i++)q[i] += q[i - 1];

	long long maxn = 0;

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

		long long L = i, R = i + k - 1;//区間[L, R]は制限される

		long long L1 = 1, R1 = L - 1;//区間[1, L-1]は制限されない

		long long L2 = R + 1, R2 = n;//区間[R+1, n]は制限されない

		if (R > n)continue;

		long long w1 = q[R] - q[L - 1];

		long long w2 = p[R1] - p[L1 - 1];

		long long w3 = p[R2] - p[L2 - 1];

		maxn = max(maxn, w1 + w2 + w3);

	}

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

		long long L = i, R = i + k - 1;//区間[L, R]は制限される

		long long L1 = 1, R1 = L - 1;//区間[1, L-1]は制限されない

		long long L2 = R + 1, R2 = n;//区間[R+1, n]は制限されない

		if (R > n)continue;

		long long w1 = 0;

		long long w2 = p[R1] - p[L1 - 1];

		long long w3 = p[R2] - p[L2 - 1];

		maxn = max(maxn, w1 + w2 + w3);

	}

	cout << maxn << endl;

	return 0;

}

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

#include <algorithm>

using namespace std;



long long N, K, A[100009], B[100009], L[100009], R[100009], maxn;



int main() {

	cin >> N >> K;

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

		cin >> A[i];

		B[i] = B[i - 1] + A[i];

	}

	for (int i = 1; i <= N; i++) { L[i] = L[i - 1]; if (A[i] >= 0) L[i] += A[i]; }

	for (int i = N; i >= 1; i--) { R[i] = R[i + 1]; if (A[i] >= 0) R[i] += A[i]; }

	for (int i = 1; i <= N - K + 1; i++) {

		int cl = i, cr = i + K - 1;

		long long v1 = L[cl - 1];

		long long v2 = R[cr + 1];

		long long v3 = B[cr] - B[cl - 1]; v3 = max(v3, 0LL);

		maxn = max(maxn, v1 + v2 + v3);

	}

	cout << maxn << endl;

	return 0;

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

#include<string>

#include<algorithm>

#include<vector>

using namespace std;

long long p[200000], q[200000], n, k;

int main() {

	cin >> n >> k;

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

		long long a; cin >> a;

		if (a > 0)p[i] += a;

		q[i] += a;

	}

	for (long long i = 1; i < 200000; i++)p[i] += p[i - 1];

	for (long long i = 1; i < 200000; i++)q[i] += q[i - 1];

	long long maxn = 0;

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

		long long L = i, R = i + k - 1;//区間[L, R]は制限される

		long long L1 = 1, R1 = L - 1;//区間[1, L-1]は制限されない

		long long L2 = R + 1, R2 = n;//区間[R+1, n]は制限されない

		if (R > n)continue;

		long long w1 = q[R] - q[L - 1];

		long long w2 = p[R1] - p[L1 - 1];

		long long w3 = p[R2] - p[L2 - 1];

		maxn = max(maxn, w1 + w2 + w3);

	}

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

		long long L = i, R = i + k - 1;//区間[L, R]は制限される

		long long L1 = 1, R1 = L - 1;//区間[1, L-1]は制限されない

		long long L2 = R + 1, R2 = n;//区間[R+1, n]は制限されない

		if (R > n)continue;

		long long w1 = 0;

		long long w2 = p[R1] - p[L1 - 1];

		long long w3 = p[R2] - p[L2 - 1];

		maxn = max(maxn, w1 + w2 + w3);

	}

	cout << maxn << endl;

	return 0;

}

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

#include <algorithm>

#include <cmath>

#include <vector>

#include <functional>

#include <queue>

#include <string>

#include <map>

using namespace std;



long long N, K, A[200009], B[200009], maxn;



int main() {

	cin >> N >> K;

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

		cin >> A[i]; B[i] = max(A[i], 0LL);

	}

	for (int i = 1; i <= N; i++) A[i] += A[i - 1];

	for (int i = 1; i <= N; i++) B[i] += B[i - 1];



	for (int i = 1; i <= N - K + 1; i++) {

		long long E1 = B[N] - (B[i + K - 1] - B[i - 1]);

		maxn = max(maxn, E1);

		maxn = max(maxn, E1 + A[i + K - 1] - A[i - 1]);

	}

	cout << maxn << endl;

	return 0;

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

using namespace std;



const double PI = acos(-1.0);

int main() {

    double A, B, H, M;

    cin >> A >> B >> H >> M;

    double alpha = (H * 60 + M) / 720 * (PI * 2);

    double beta = M / 60 * (PI * 2);

    double theta = alpha - beta;

    double res = sqrt(A*A + B*B - 2.0*A*B*cos(theta));

    cout << fixed << setprecision(10) << res << endl;

}

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

#include <math.h>



#define PI 3.14159265358979323846264338327950L

int main(void) {

  int a, b, h, m;

  scanf("%d%d%d%d", &a, &b, &h, &m);



  long double rad = PI * 2 * ((long double)h / 12.0 + ((long double)m / 60.0) / 12.0 - (long double)m / 60.0);

  long double rsq = (long double)(a * a + b * b) - (long double)(2 * a * b) * cosl(rad);

  printf("%20.20Lf\n", sqrtl(rsq));



  return 0;

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

using namespace std;



const double PI = acos(-1.0);

int main() {

  double A, B, H, M;

  cin >> A >> B >> H >> M;

  double alpha = (H * 60 + M) / 720 * (PI * 2);

  double beta = M / 60 * (PI * 2);

  double theta = alpha - beta;

  double res = sqrt(A*A + B*B - 2.0*A*B*cos(theta));

  cout << fixed << setprecision(10) << res << endl;

}

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

#include <math.h>



#define PI 3.14159265358979323846264338327950L

int main(void) {

  int a, b, h, m;

  scanf("%d%d%d%d", &a, &b, &h, &m);



  long double rad = PI * 2 * ((long double)h / 12.0 + ((long double)m / 60.0) / 12.0 - (long double)m / 60.0);

  long double rsq = (long double)(a * a + b * b) - (long double)(2 * a * b) * cosl(rad);

  printf("%20.20Lf\n", sqrtl(rsq));



  return 0;

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

using namespace std;

const double pi=M_PI;

int main(void)

{

  short A,B,H,M;

  cin>>A>>B>>H>>M;

  return printf("%.20lf",pow(A*A+B*B-2*A*B*cos(((H*60+M)/2.0-6*M)*pi/180.0),0.5)),0;

}

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

#include<math.h>

typedef double D;

const D pi=3.14159265358979323846264338327950288419716939937510L;

signed main(void)

{

  int A,B,H,M;

  if(~scanf("%d %d %d %d",&A,&B,&H,&M))

  {

    D theta=((H*60+M)/2.0-6*M)*pi/180.0,x,y;

    x=(A-B*cos(theta)),y=B*sin(theta);

    return printf("%.20lf",pow(x*x+y*y,0.5)),0;

  }

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

using namespace std;

const double pi=M_PI;

int main(void)

{

  short A,B,H,M;

  cin>>A>>B>>H>>M;

  return printf("%.20lf",pow(A*A+B*B-2*A*B*cos(((H*60+M)/2.0-6*M)*pi/180.0),0.5)),0;

}

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

#include<math.h>

signed main(void)

{

  int A,B,H,M;

  if(~scanf("%d %d %d %d",&A,&B,&H,&M))

  {

    double theta=(60*H-11*M)*M_PI/360.0,x=A-B*cos(theta),y=B*sin(theta);

    return printf("%.20f",sqrt(x*x+y*y)),0;

  }

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

using namespace std;

const double pi=M_PI;

int main(void)

{

  short A,B,H,M;

  cin>>A>>B>>H>>M;

  return printf("%.20lf",pow(A*A+B*B-2*A*B*cos(((H*60+M)/2.0-6*M)*pi/180.0),0.5)),0;

}

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

#include<math.h>

signed main(void)

{

  int A,B,H,M;

  if(~scanf("%d %d %d %d",&A,&B,&H,&M))

  {

    double theta=(60*H-11*M)*M_PI/360.0,x=A-B*cos(theta),y=B*sin(theta);

    return printf("%.20f",pow(x*x+y*y,0.5)),0;

  }

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

#include<vector>

using namespace std;



#define MAXN 500

#define PII pair<int,int>

int A[MAXN+5][MAXN+5];

vector<PII> S,T;



int main(){

    int H,W;

    scanf("%d%d",&H,&W);

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

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

            scanf("%d",A[i]+j);

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

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

            if(A[i][j]&1){

                S.push_back(make_pair(i,j));

                T.push_back(make_pair(i,j+1));

                A[i][j]--,A[i][j+1]++;

            }

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

        if(A[i][W]&1){

            S.push_back(make_pair(i,W));

            T.push_back(make_pair(i+1,W));

            A[i][W]--,A[i+1][W]++;

        }

    printf("%d",S.size());

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

        printf("\n%d %d %d %d",S[i].first,S[i].second,T[i].first,T[i].second);

}


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



const int N=500;

int m,n;

int a[N+5][N+5],f[N+5][N+5],Ans,ans[N*N+5][5];



int main()

{

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

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

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

		{

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

			if( ( f[i][j] ^= (a[i][j] & 1) )&& j != n)

			{

				f[i][j]=0;

				f[i][j+1]=1;

				ans[++Ans][1]=i,ans[Ans][2]=j,ans[Ans][3]=i,ans[Ans][4]=j+1;

			}

		}

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

		if(f[i][n])

		{

			f[i][n]=0;

			f[i+1][n] ^= 1;

			ans[++Ans][1]=i,ans[Ans][2]=n,ans[Ans][3]=i+1,ans[Ans][4]=n;

		}

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

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

		printf("%d %d %d %d\n",ans[i][1],ans[i][2],ans[i][3],ans[i][4]);

	return 0;

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

using namespace std;

 

#define mod 1000000007

 

int n,m,cnt,flag1,flag2,s1,s2;

long long k;

char s[2001][2001];

 

long long quickpow(long long base,long long to)

{

	if(to<=0)return 1;

	if(to==1)return base;

	long long mid=quickpow(base,to>>1);

	if(to&1)return mid*mid%mod*base%mod;

	else return mid*mid%mod;

}

 

struct Matrix{

	long long a[3][3];

	Matrix(){memset(a,0,sizeof(a));}

	Matrix operator*(Matrix &m)

	{

		Matrix ans;

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

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

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

					ans.a[i][j]=(ans.a[i][j]+a[i][k]*m.a[k][j]%mod)%mod;

		return ans;

	}

};

 

int main()

{

	scanf("%d%d%lld",&n,&m,&k);

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

		scanf("%s",s[i]+1);

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

	{

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

			if(s[i][j]=='#')

			{

				++cnt;

				s1+=s[i][j-1]=='#';

				s2+=s[i-1][j]=='#';

			}

		if(s[i][1]=='#' && s[i][m]=='#')++flag1;

	}

	for(int i=1;i<=m;++i)if(s[1][i]=='#' && s[n][i]=='#')++flag2;

	if(flag1 && flag2)

	{

		puts("1");

		return 0;

	}

	if(!flag1 && !flag2)

	{

		printf("%lld\n",quickpow(cnt,k-1));

		return 0;

	}

	if(!flag1)swap(flag1,flag2),swap(s1,s2);

	Matrix A;

	A.a[1][1]=cnt;

	A.a[2][1]=s1;

	A.a[2][2]=flag1;

	--k;

	Matrix ANS;

	ANS.a[1][1]=ANS.a[2][2]=1;

	while(k)

	{

		if(k&1)ANS=ANS*A;

		A=A*A;

		k>>=1;

	}

	printf("%lld\n",(ANS.a[1][1]-ANS.a[2][1]+mod)%mod);

}

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

#include<algorithm>

#include<cstring>

using namespace std;

#define MAXN 1010

#define MO 1000000007

#define LL long long

int cnt,s1,s2,f1,f2,n,m;

LL k;

char s[MAXN][MAXN];

LL PowMod(LL a,LL b)

{

	b%=(MO-1);

	LL ret=1;

	while(b)

	{

		if(b&1) ret=ret*a%MO;

		a=a*a%MO;

		b>>=1;

	}

	return ret;

}

struct maz

{

	LL a[2][2];

	maz(){memset(a,0,sizeof a);};

	maz operator*(maz &m)

	{

		maz ret;

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

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

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

					ret.a[i][j]=(ret.a[i][j]+a[i][k]*m.a[k][j]%MO)%MO;

		return ret;

	}

};

int main()

{

	scanf("%d%d%lld",&n,&m,&k);

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

	{

		scanf("%s",s[i]+1);

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

			if(s[i][j]=='#')

			{

				cnt++;

				s1+=(s[i-1][j]=='#');

				s2+=(s[i][j-1]=='#');

			}

		if(s[i][1]=='#'&&s[i][m]=='#') f2++;

		if(i==n)

		{

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

				if(s[1][j]=='#'&&s[n][j]=='#') f1++;

		}

	}

	if((f1&&f2)||k==0)

	{

		printf("1\n");

		return 0;

	}

	else if(f1==0&&f2==0)

	{

		printf("%lld\n",PowMod(cnt,k-1));

		return 0;

	}

	if(f1==0)

	{

		swap(f1,f2);

		swap(s1,s2);

	}

	maz A,ans;

	A.a[0][0]=cnt,A.a[1][0]=s1,A.a[1][1]=f1;

	ans.a[0][0]=ans.a[1][1]=1;

	k--;

	while(k)

	{

		if(k&1) ans=ans*A;

		A=A*A;

		k>>=1;

	}

	printf("%lld\n",(ans.a[0][0]-ans.a[1][0]+MO)%MO);

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

#include<iostream>

#include<cstring>

#include<cstdio>

#include<cmath>

#define LL long long

#define M 1020

#define mod 1000000007

using namespace std;

LL read(){

	LL nm=0,fh=1;char cw=getchar();

	for(;!isdigit(cw);cw=getchar()) if(cw=='-') fh=-fh;

	for(;isdigit(cw);cw=getchar()) nm=nm*10+(cw-'0');

	return nm*fh;

}

LL qpow(LL x,LL qs){

	LL fin=1;

	while(qs){

		if(qs&1) fin=fin*x%mod;

		qs>>=1,x=x*x%mod;

	}

	return fin;

}

struct mat{

	LL p[2][2];

	mat operator *(const mat&ot)const{

		mat tmp;

		for(LL i=0;i<2;i++){

			for(LL j=0;j<2;j++){

				tmp.p[i][j]=0;

				for(LL k=0;k<2;k++) tmp.p[i][j]+=p[i][k]*ot.p[k][j];

				tmp.p[i][j]%=mod;

			}

		}

		return tmp;

	}

}T,ANS;

bool t1=false,t2=false; 

LL n,m,K,cnt,ans,sum,con;

char ch[M][M];

int main(){

	n=read(),m=read(),K=read();

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

	    scanf("%s",ch[i]+1);

	    for(int j=1;j<=m;j++) sum+=(ch[i][j]=='#');

    }

	for(int i=1;i<=n;i++) t1|=(ch[i][1]=='#'&&ch[i][m]=='#');

	for(int i=1;i<=m;i++) t2|=(ch[1][i]=='#'&&ch[n][i]=='#');

	if((!t1)&&(!t2)){printf("%lld\n",qpow(sum,K-1));return 0;}

	else if((t1&&t2)||K==0){puts("1");return 0;}

	else if(t2){

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

			for(int j=1;j<i;j++) swap(ch[i][j],ch[j][i]);

		}

		swap(n,m);

	}

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

		con+=(ch[i][1]==ch[i][m]&&ch[i][1]=='#');

		for(int j=1;j<m;j++) cnt+=(ch[i][j]==ch[i][j+1]&&ch[i][j]=='#');

	}

	for(int i=0;i<2;i++) ANS.p[i][i]=1;

	T.p[0][0]=sum,T.p[0][1]=mod-cnt,T.p[1][1]=con;

	for(K--;K>0;K>>=1,T=T*T) if(K&1) ANS=ANS*T;

	printf("%lld\n",(ANS.p[0][0]+ANS.p[0][1])%mod);

	return 0;

}

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

typedef long long ll;



const int N=1010,p=1e9+7;

char s[N][N];

int n,m,d,c,S,col,row;

ll k;



inline int qm(int x){return x<0?x+p:x;}



template <typename _tp> inline int qpow(int A,_tp B){

	int res(1);while(B){

		if(B&1)res=1ll*res*A%p;

		A=1ll*A*A%p,B>>=1;

	}return res;

}



int main(){

	scanf("%d%d%lld",&n,&m,&k);

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

		scanf("%s",s[i]+1);

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

			if(s[i][j]=='#')++S;

	}

	for(int i=1;i<=n;++i)if(s[i][1]=='#'&&'#'==s[i][m])++row;

	for(int i=1;i<=m;++i)if(s[1][i]=='#'&&'#'==s[n][i])++col;

	if(!row&&!col){printf("%d\n",qpow(S,k-1));return 0;}

	if(!k||(row&&col)){puts("1");return 0;}

	if(row)

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

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

			d+=(s[i][j]=='#'&&s[i][j+1]=='#');

	else 

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

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

			d+=(s[i][j]=='#'&&s[i+1][j]=='#');

	

	c=row?row:col;

	

	int ans=qm(qpow(S,k-1)-qpow(c,k-1));

	

	ans=1ll*ans*d%p;

	

	ans=1ll*ans*qpow(qm(S-c),p-2)%p;

	

	printf("%d\n",qm(qpow(S,k-1)-ans));

	return 0;

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

#include<algorithm>

using namespace std;

int H,W;

int A[200];

int dp[200][200];

main()

{

	cin>>H>>W;

	for(int i=0;i<W;i++)for(int j=0;j<W;j++)dp[i][j]=-1e9;

	dp[0][1]=0;

	for(int _=0;_<H;_++)

	{

		for(int i=0;i<W;i++)cin>>A[i];

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

		{

			dp[i][j]+=A[i];

			if(i+1<j)dp[i+1][j]=max(dp[i+1][j],dp[i][j]);

		}

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

		{

			dp[i][j]+=A[j];

			if(j+1<W)dp[i][j+1]=max(dp[i][j+1],dp[i][j]);

		}

	}

	int ans=0;

	for(int i=0;i+1<W;i++)ans=max(ans,dp[i][W-1]);

	cout<<ans<<endl;

}


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

#include<algorithm>

using namespace std;

int H,W;

int A[200];

int dp[200][200];

main()

{

	scanf("%d%d",&H,&W);

	for(int i=0;i<W;i++)for(int j=0;j<W;j++)dp[i][j]=-1e9;

	dp[0][1]=0;

	for(int _=0;_<H;_++)

	{

		for(int i=0;i<W;i++)scanf("%d",&A[i]);

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

		{

			dp[i][j]+=A[i];

			if(i+1<j)dp[i+1][j]=max(dp[i+1][j],dp[i][j]);

		}

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

		{

			dp[i][j]+=A[j];

			if(j+1<W)dp[i][j+1]=max(dp[i][j+1],dp[i][j]);

		}

	}

	int ans=0;

	for(int i=0;i+1<W;i++)ans=max(ans,dp[i][W-1]);

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

}