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

using namespace std;

typedef long long ll;

const ll maxn=1e5+9;

ll arr[maxn];

ll sum[maxn];

ll sz[maxn];

ll n,k;

int main(){

        ll a,b,c,d,e,f,g,h;

        ios::sync_with_stdio(0);

        cin>>n>>k;

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

                cin>>arr[i];

                sum[i]=sum[i-1]+arr[i];

                sz[i]=sz[i-1];

                if(arr[i]>0)sz[i]+=arr[i];

        }

        g=0;

        h=0;

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

                g=max(g,sz[i-k]+sz[n]-sz[i]);

                g=max(g,sz[i-k]+sz[n]-sz[i]+sum[i]-sum[i-k]);

               // if(g==20)cout<<i<<endl;

        }

        cout<<g<<endl;

        return 0;

}


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

#include<algorithm>

#include<cstring>

#define MN 100005

using namespace std;

int n,k,a[MN];

long long ans,s[MN],ss[MN];

int main(){

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

	for(int i=1;i<=n;i++)scanf("%d",&a[i]),s[i]=s[i-1]+a[i],ss[i]=ss[i-1]+max(a[i],0);

	for(int i=0;i<=n-k;i++)ans=max(ans,ss[n]-ss[i+k]+ss[i]+max(0LL,s[i+k]-s[i]));

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

}




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

using namespace std;



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

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

#define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)

#define FILL(a, value) memset(a, value, sizeof(a))



#define SZ(a) (int) a.size()

#define ALL(a) a.begin(),a.end()

#define PB push_back

#define MP make_pair



typedef long long LL;

typedef vector<int> VI;

typedef pair<int, int> PII;



const double PI = acos(-1.0);

const LL INF = 1000 * 1000 * 1000 + 7;

const LL LINF = INF * (LL)INF;



const int MAX = 100100;



int A[MAX];

LL S[MAX];

LL Sb[MAX];

int n;



LL getS(int l, int r, LL* s)

{

	LL res = s[r];

	if (l) res -= s[l-1];

	return res;

}



LL get(int l, int r, int val)

{

	LL tot = Sb[n-1];

	tot -= getS(l, r, Sb);

	tot += getS(l, r, S) * val;

	return tot;

}



int main()

{

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

	//ios::sync_with_Stdio(false); cin.tie(0);



	int k;

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

	FOR (i, 0, n)

	{

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



		S[i] = A[i];

		if (A[i] > 0) Sb[i] = A[i];



		if (i)

		{

			S[i] += S[i-1];

			Sb[i] += Sb[i-1];

		}

	}



	LL res = -LINF;



	FOR (i, 0, n)

	{

		int L = i;

		int R = i + k - 1;

		if (R >= n) break;



		res = max(res, get(L, R, 0));

		res = max(res, get(L, R, 1));

	}



	cout<<res<<endl;



}


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

#include<algorithm>

#include<cstring>

#define MN 100005

using namespace std;

int n,k,a[MN];

long long ans,s[MN],ss[MN];

int main(){

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

	for(int i=1;i<=n;i++)scanf("%d",&a[i]),s[i]=s[i-1]+a[i],ss[i]=ss[i-1]+max(a[i],0);

	for(int i=0;i<=n-k;i++)ans=max(ans,ss[n]-ss[i+k]+ss[i]+max(0LL,s[i+k]-s[i]));

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

}




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

using namespace std;

typedef long long ll;

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

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

#define co(x) cout << (x) << "\n"

#define cosp(x) cout << (x) << " "

#define ce(x) cerr << (x) << "\n"

#define cesp(x) cerr << (x) << " "

#define pb push_back

#define mp make_pair

#define Would

#define you

#define please





int main() {

	cin.tie(0);

	ios::sync_with_stdio(false);





	int N, K;

	cin >> N >> K;



	int a[100001] = {};

	ll s[100002], sa[100002];

	s[0] = 0;

	sa[0] = 0;

	rep1(i, N) {

		cin >> a[i];

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

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

	}



	ll kotae = 0;

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

		ll kari = max(s[i + K - 1] - s[i - 1], 0ll) + sa[i - 1] + sa[N] - sa[i + K - 1];

		kotae = max(kotae, kari);

	}

	co(kotae);



	Would you please return 0;

}

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

#include<cstdio>

#include<algorithm>



using namespace std;

typedef long long ll;

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

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

#define co(x) cout << (x) << "\n"

#define cosp(x) cout << (x) << " "

#define ce(x) cerr << (x) << "\n"

#define cesp(x) cerr << (x) << " "

#define pb push_back

#define mp make_pair

#define Would

#define you

#define please



const int cm = 1 << 17;

char cn[cm], * ci = cn + cm, ct;

inline char getcha() {

	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }

	return *ci++;

}

inline int getint() {

	int A = 0;

	int pn = 1;

	if (ci - cn + 16 > cm) {

		if ((ct = getcha()) == '-') { pn = -1; ct = getcha(); }

		A = ct - '0';

		while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';;

		return pn * A;

	}

	else {

		if ((ct = *ci++) == '-') { pn = -1; ct = *ci++; }

		A = ct - '0';

		while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';;

		return pn * A;

	}

}



int main() {

	//cin.tie(0);

	//ios::sync_with_stdio(false);





	int N = getint(), K = getint();



	ll s[100001], sa[100001];

	s[0] = 0;

	sa[0] = 0;

	rep1(i, N) {

		int a = getint();

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

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

	}



	ll kotae = 0;

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

		ll kari = max(s[i + K - 1] - s[i - 1], 0ll) + sa[i - 1] + sa[N] - sa[i + K - 1];

		kotae = max(kotae, kari);

	}

	printf("%lld", kotae);



	Would you please return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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);

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

  }

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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);

}


// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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);

}

// Optimized solution to the same problem (faster):
#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);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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);

}

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

#include<cstdio>

#include<iostream>

#include<cstdlib>

#include<ctime>

#include<cassert>

#include<algorithm>

#include<cmath>



#include<cstring>

#include<string>

#include<cctype>

#include<utility>

#include<vector>

#include<stack>

#include<queue>

#include<deque>

#include<map>

#include<set>

#include<list>



typedef long long ll;

typedef std::pair<int,int> pii;

typedef std::pair<ll,ll> pll;

typedef std::vector<int> vi;



const int OO=(int)2e9;

const ll INF=(ll)4e18;

const double EPS=(double)1e-12;



#define ff first

#define ss second

#define mp make_pair

#define pb push_back

#define pf push_front

#define pob pop_back

#define pof pop_front



#define INL(i,a,b) ((a<=i)&&(i<=b))

#define EXL(i,a,b) ((a< i)&&(i< b))

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

#define REP(i,a,b) REPP(i,a,b,1)

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

#define REV(i,a,b) REVV(i,a,b,1)

using namespace std;



const int MOD=(int)1e9 + 7;



int n,m;

ll a,b;

ll rea,reb;



int main(){

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

	rea=0;

	scanf("%lld",&a);

	REP(i,1,n-1){

		scanf("%lld",&b);

		rea=(rea+((((b-a)%MOD)*i)%MOD*((n-i)%MOD))%MOD)%MOD;

		a=b;

	}

	reb=0;

	scanf("%lld",&a);

	REP(i,1,m-1){

		scanf("%lld",&b);

		reb=(reb+((((b-a)%MOD)*i)%MOD*((m-i)%MOD))%MOD)%MOD;

		a=b;

	}

	printf("%lld\n",(rea*reb)%MOD);

	return 0;

}

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

long long x[100005];

long long y[100005];

const long long mod = 1e9+7;

int main(){

    int n,m;

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

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

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

    }

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

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

    }

    long long sumx = 0;

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

        sumx = (sumx + (x[j]-x[i])*(j-i))%mod;

    }

    long long sumy = 0;

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

        sumy = (sumy + (y[j]-y[i])*(j-i))%mod;

    }

    printf("%lld\n",(sumx*sumy)%mod);

    return 0;

}


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

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>



using namespace std;

using namespace __gnu_pbds;



#define fi first

#define se second

#define mp make_pair

#define pb push_back

#define fbo find_by_order

#define ook order_of_key

#define INF 1e9



typedef long long ll;

typedef pair<ll,ll> ii;

typedef vector<int> vi;

typedef vector < pair<int, int> > vii;

typedef long double ld;

typedef tree<pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> pbds;

typedef set<int>::iterator sit;

typedef map<int,int>::iterator mit;

typedef vector<int>::iterator vit;



ll n, m, x, y, xx, yy;



int main()

{

	ios_base::sync_with_stdio(false);

	cin.tie(NULL);

	ll MOD = 1e9+7;

	cin >> n >> m;

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

		cin >> x;

		xx+=(-(n-1)+2*i)*x;

		xx%=MOD;

	}

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

		cin >> y;

		yy+=(-(m-1)+2*i)*y;

		yy%=MOD;

	}

	cout<<(xx*yy)%MOD;

	return 0;

}


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

long long x[100005];

long long y[100005];

const long long mod = 1e9+7;

int main(){

    int n,m;

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

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

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

    }

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

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

    }

    long long sumx = 0;

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

        sumx = (sumx + (x[j]-x[i])*(j-i))%mod;

    }

    long long sumy = 0;

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

        sumy = (sumy + (y[j]-y[i])*(j-i))%mod;

    }

    printf("%lld\n",(sumx*sumy)%mod);

    return 0;

}


// Fastest known solution for this problem: