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

using namespace std;

const int N=305;

int a[N][N];

bool b[N];

queue<int>f[N];

int n,m;

int main()

{

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

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

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

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

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

		f[a[i][1]].push(i),a[i][0]=1;

	memset(b,true,sizeof(b));

	int ret=0;

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

		if(f[i].size()>ret)ret=f[i].size();

	int ans=ret;

	while(1){

		int k=-1;

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

			if(k==-1||f[i].size()>f[k].size())k=i;

		if(k==-1)break;

		b[k]=false;

		while(!f[k].empty()){

			int i=f[k].front();

			f[k].pop();

			while(!b[a[i][a[i][0]]])a[i][0]++;

			f[a[i][a[i][0]]].push(i);

		}

		int ret=0;

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

			if(f[i].size()>ret)ret=f[i].size();

		if(ret==0)break;

		ans=min(ans,ret);

	}

	printf("%d",ans);

	return 0;

}

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

using namespace std;



int n, m, k;

int a[305][305], vis[305], been[305];



bool check(int x) {

    memset(been, 0, sizeof(been));

    for (int i = 1; i <= n; i++) a[i][0] = 1;

    while (1) {

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

        bool flag = true;

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

            while (a[i][0] <= m && been[a[i][a[i][0]]]) a[i][0]++;

            if (++vis[a[i][a[i][0]]] > x) {

                been[a[i][a[i][0]]] = 1;

                flag = false;

            }

            if (a[i][0] > m) return false;

        }

        if (flag) return true;

    }

    return false;

}



int main() {

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

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

        a[i][0] = 1;

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

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

    }

    int l = 1, r = n;

    while (l < r) {

        int mid = (l + r) >> 1;

        if (check(mid)) r = mid;

        else l = mid + 1;

    }

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

    return 0;

}
// Slower C++ solution:
#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;



queue <int> a[301];

ll n, m, x, ans, mx, cur, cnt[301];

bool disabled[301];



int main()

{

	cin >> n >> m;

	ans=n;

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

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

			cin >> x;

			a[i].push(x);

		}

	}

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

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

			while(disabled[a[j].front()]){

				a[j].pop();

			}

			cnt[a[j].front()]++;

		}

		mx=-1;

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

			if(cnt[j]>mx){

				mx=cnt[j];

				cur=j;

			}

			cnt[j]=0;

		}

		ans=min(ans,mx);

		disabled[cur]=1;

	}

	cout << ans;

	return 0;

}


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

using namespace std;



int n, m, k;

int a[305][305], vis[305], been[305];



bool check(int x) {

    memset(been, 0, sizeof(been));

    for (int i = 1; i <= n; i++) a[i][0] = 1;

    while (1) {

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

        bool flag = true;

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

            while (a[i][0] <= m && been[a[i][a[i][0]]]) a[i][0]++;

            if (++vis[a[i][a[i][0]]] > x) {

                been[a[i][a[i][0]]] = 1;

                flag = false;

            }

            if (a[i][0] > m) return false;

        }

        if (flag) return true;

    }

    return false;

}



int main() {

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

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

        a[i][0] = 1;

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

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

    }

    int l = 1, r = n;

    while (l < r) {

        int mid = (l + r) >> 1;

        if (check(mid)) r = mid;

        else l = mid + 1;

    }

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

    return 0;

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

#include<iostream>

#include<algorithm>

#include<cmath>

long long pos[100010],sum[100010];

using namespace std;

int main()

{

	int n,k,x;long long ans=- int(1e9);

	cin>>n>>k;

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

	{

		cin>>x;

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

		pos[i]=x<0?pos[i-1]:pos[i-1]+x;

	//	cout<<sum[i]<<" "<<pos[i]<<endl;

	}

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

	{

		long long s=pos[n]-(pos[i]-pos[i-k]);//Çø¼äÍâË¢Õý 

		if(sum[i]-sum[i-k]>0) s+=sum[i]-sum[i-k];//Èç¹ûÇø¼äºÍ´óÓÚÁã¾ÍË¢ºÚ 

		ans=max(s,ans);

	}

	cout<<ans;

	return 0; 

}

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

using namespace std;

const int maxn = 100000;

long long b[maxn + 10];

long long w[maxn + 10];

int main()

{

	int n,k;

	long long x;

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

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

	{

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

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

		scanf("%lld",&x);

		if(x > 0)

			w[i] += x;

		if(x < 0)

			b[i] -= x;

	}

	long long mina = b[k] - b[0];

	if(w[k] - w[0] < mina)

		mina = w[k] - w[0];

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

	{

		long long temp = b[k + i] - b[i];

		if(temp < mina)

			mina = temp;

		temp = w[k + i] - w[i];

		if(temp < mina)

			mina = temp;

	}

	printf("%lld",w[n] - mina);

	return 0;

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

#include <map>

#include <stack>

#include <queue>

#include <cmath>

#include <cstdio>

#include <vector>

#include <bitset>

#include <cstring>

#include <utility>

#include <iostream>

#include <algorithm>

#define LL long long

#define Rg register

#define RI register int

#define RC register char

#define ed puts("") 

#define pair pair<LL,LL>

#define space putchar(' ')

using namespace std;

    

template <typename tp> inline void read(tp & x)

{	

    x=0;

    RI f=1;

    RC c=getchar();

    while(c<'0' || c>'9'){if(c=='-') f=-1;c=getchar(); }

    while(c>='0' && c<='9'){x=(x<<1)+(x<<3)+(c^48);c=getchar();} 

 	x*=f;

} 	

    

template <typename Tp> inline void print(Tp x)

{		

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

    if(x>9) print(x/10);

    putchar(x%10+'0');

}	



int n,k;

LL a[1000005];

LL s[1000005];

LL b[1000005];//b[i]表示正数的前缀和 正序

LL c[1000005];//c[i]表示正数的前缀和 逆序 

LL ans;



int main()

{

	read(n);

	read(k);

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

	{

		read(a[i]);

		if(a[i]>0) b[i]=b[i-1]+a[i];

		else b[i]=b[i-1];

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

	}

	for(RI i=n;i>=1;--i)//逆序求正数的前缀和 

	{

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

		else c[i]=c[i+1];

	}

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

	{

		if(s[i+k]-s[i]<0) ans=max(ans,b[i]+c[i+k+1]);//中间那段连续的区间和为负 此时可以把它们涂成白色 使总的和变大 

		else ans=max(ans,b[i]+c[i+k+1]+s[i+k]-s[i]);

	}

	print(ans);

	return 0;

}

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

using namespace std;

const int maxn = 100000;

long long b[maxn + 10];

long long w[maxn + 10];

int main()

{

	int n,k;

	long long x;

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

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

	{

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

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

		scanf("%lld",&x);

		if(x > 0)

			w[i] += x;

		if(x < 0)

			b[i] -= x;

	}

	long long mina = b[k] - b[0];

	if(w[k] - w[0] < mina)

		mina = w[k] - w[0];

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

	{

		long long temp = b[k + i] - b[i];

		if(temp < mina)

			mina = temp;

		temp = w[k + i] - w[i];

		if(temp < mina)

			mina = temp;

	}

	printf("%lld",w[n] - mina);

	return 0;

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

#include<cstdio>

using namespace std;

long long n,k;

long long a[200000];

long long sum[200000];

long long sumz[200000];

long long mx = -(long long)1e20;

long long mymax(long long a,long long b){

	return a>b?a:b;

}

int main(){

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

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

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

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

		if(a[i] > 0){

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

		}

		else{

			sumz[i] = sumz[i-1];

		}

	}

	if(n == k){

		printf("%lld",mymax(sum[n],0));

		return 0;

	}

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

		long long t = sumz[i-1] + sumz[n] - sumz[i+k-1] + sum[i+k-1] - sum[i-1];

		mx = mymax(mx,t);

	}

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

		long long t = sumz[i-1] + sumz[n] - sumz[i+k-1];

		mx = mymax(mx,t);

	}

	printf("%lld",mx);

	return 0;

}

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

using namespace std;

const int maxn = 100000;

long long b[maxn + 10];

long long w[maxn + 10];

int main()

{

	int n,k;

	long long x;

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

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

	{

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

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

		scanf("%lld",&x);

		if(x > 0)

			w[i] += x;

		if(x < 0)

			b[i] -= x;

	}

	long long mina = b[k] - b[0];

	if(w[k] - w[0] < mina)

		mina = w[k] - w[0];

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

	{

		long long temp = b[k + i] - b[i];

		if(temp < mina)

			mina = temp;

		temp = w[k + i] - w[i];

		if(temp < mina)

			mina = temp;

	}

	printf("%lld",w[n] - mina);

	return 0;

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

using namespace std;

typedef long long int lli;

lli qsp[100005],qsn[100005];

int main(){

	int n,k;

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

	lli a;

	qsp[0]=qsn[0]=0;

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

		scanf("%lld",&a);

		qsp[i]=qsp[i-1];

		qsn[i]=qsn[i-1];

		if(a>0)

			qsp[i]+=a;

		else

			qsn[i]+=a;

	}

	lli min=qsp[k],max=qsp[k]+qsn[k],maxidx=k,ans=0;

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

		lli sum=qsp[n];

		if(qsp[i]-qsp[i-k]+qsn[i]-qsn[i-k]>0)

			sum+=qsn[i]-qsn[i-k];

		else

			sum-=qsp[i]-qsp[i-k];

		if(ans<sum)

			ans=sum;

	}

	printf("%lld",ans);

}

/*



10 5

5 -4 -5 -8 -4 7 2 -4 0 7



*/

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

#include <cstdio>

long long v,a[100001],b[100001];

long long max(long long p ,long long q){

    if(p>q) return p;

    return q;

}

using namespace std;

int main() {

    int n,k;

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

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

        scanf("%lld",&v);

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

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

        if(v>0)b[i]+=v;

    }

    long long ans=-1;

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

        ans = max(ans,max(a[i+k-1]-a[i-1],0) +b[i-1]+(b[n]-b[i+k-1]));

    }

    printf("%lld",ans);

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

using namespace std;

typedef long long int lli;

lli qsp[100005],qsn[100005];

int main(){

	int n,k;

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

	lli a;

	qsp[0]=qsn[0]=0;

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

		scanf("%lld",&a);

		qsp[i]=qsp[i-1];

		qsn[i]=qsn[i-1];

		if(a>0)

			qsp[i]+=a;

		else

			qsn[i]+=a;

	}

	lli min=qsp[k],max=qsp[k]+qsn[k],maxidx=k,ans=0;

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

		lli sum=qsp[n];

		if(qsp[i]-qsp[i-k]+qsn[i]-qsn[i-k]>0)

			sum+=qsn[i]-qsn[i-k];

		else

			sum-=qsp[i]-qsp[i-k];

		if(ans<sum)

			ans=sum;

	}

	printf("%lld",ans);

}

/*



10 5

5 -4 -5 -8 -4 7 2 -4 0 7



*/

// Faster C++ solution for the same problem (measured speedup: 5.202775676426671x):
#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);

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

#include <vector>

#include <algorithm>

using namespace std;

typedef long long lli;

lli n,k;

vector<lli> a;

lli ans = 0;

int main(){

    cin >> n >> k;

    a = vector<lli> (n);

    for(lli i = 0;i < n;i++) cin >> a[i];

    lli t = 0,s;

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

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

    }

    s = t;

    for(lli i = 0;i < k;i++){

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

        else s += a[i];

    }

    ans = max(ans,s);

    ans = max(ans,t);

    for(lli i = k,j = 0;i < n;i++,j++){

        if(a[j] > 0) t += a[j];

        else s -= a[j];

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

        else s += a[i];

        ans = max(ans,s);

        ans = max(ans,t);        

    }

    cout << ans << endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.237779069512135x):
#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);

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 5.291778471114332x):
#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);

}
// Slower C++ solution:
#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;



}


// Faster C++ solution for the same problem (measured speedup: 5.181686832985955x):
#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);

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

using namespace std;

typedef long long int lli;

lli qsp[100005],qsn[100005];

int main(){

	int n,k;

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

	lli a;

	qsp[0]=qsn[0]=0;

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

		scanf("%lld",&a);

		qsp[i]=qsp[i-1];

		qsn[i]=qsn[i-1];

		if(a>0)

			qsp[i]+=a;

		else

			qsn[i]+=a;

	}

	lli min=qsp[k],max=qsp[k]+qsn[k],maxidx=k,ans=0;

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

		lli sum=qsp[n];

		if(qsp[i]-qsp[i-k]+qsn[i]-qsn[i-k]>0)

			sum+=qsn[i]-qsn[i-k];

		else

			sum-=qsp[i]-qsp[i-k];

		if(ans<sum)

			ans=sum;

	}

	printf("%lld",ans);

}

/*



10 5

5 -4 -5 -8 -4 7 2 -4 0 7



*/

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

#include<algorithm>

using namespace std;

#define LL long long

#define MAXN 100010

LL sum[MAXN],posi[MAXN],ans;

int n,k;

int main()

{

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

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

	{

		posi[i]=posi[i-1];

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

		if(sum[i]>0) posi[i]+=sum[i];

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

	}

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

	{

		LL tmp=posi[n]-posi[i+k-1]+posi[i-1]+max(0LL,sum[i+k-1]-sum[i-1]);

		ans=max(ans,tmp);

	}

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

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

#include <vector>

#include <algorithm>

using namespace std;

typedef long long lli;

lli n,k;

vector<lli> a;

lli ans = 0;

int main(){

    cin >> n >> k;

    a = vector<lli> (n);

    for(lli i = 0;i < n;i++) cin >> a[i];

    lli t = 0,s;

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

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

    }

    s = t;

    for(lli i = 0;i < k;i++){

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

        else s += a[i];

    }

    ans = max(ans,s);

    ans = max(ans,t);

    for(lli i = k,j = 0;i < n;i++,j++){

        if(a[j] > 0) t += a[j];

        else s -= a[j];

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

        else s += a[i];

        ans = max(ans,s);

        ans = max(ans,t);        

    }

    cout << ans << endl;

    return 0;

}

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

#include<algorithm>

using namespace std;

#define LL long long

#define MAXN 100010

LL sum[MAXN],posi[MAXN],ans;

int n,k;

int main()

{

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

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

	{

		posi[i]=posi[i-1];

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

		if(sum[i]>0) posi[i]+=sum[i];

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

	}

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

	{

		LL tmp=posi[n]-posi[i+k-1]+posi[i-1]+max(0LL,sum[i+k-1]-sum[i-1]);

		ans=max(ans,tmp);

	}

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

}
// Slower C++ solution:
#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;

}


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

#include<algorithm>

using namespace std;

#define LL long long

#define MAXN 100010

LL sum[MAXN],posi[MAXN],ans;

int n,k;

int main()

{

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

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

	{

		posi[i]=posi[i-1];

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

		if(sum[i]>0) posi[i]+=sum[i];

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

	}

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

	{

		LL tmp=posi[n]-posi[i+k-1]+posi[i-1]+max(0LL,sum[i+k-1]-sum[i-1]);

		ans=max(ans,tmp);

	}

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

}
// Slower C++ solution:
#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;



}


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

#include<algorithm>

using namespace std;

#define LL long long

#define MAXN 100010

LL sum[MAXN],posi[MAXN],ans;

int n,k;

int main()

{

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

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

	{

		posi[i]=posi[i-1];

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

		if(sum[i]>0) posi[i]+=sum[i];

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

	}

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

	{

		LL tmp=posi[n]-posi[i+k-1]+posi[i-1]+max(0LL,sum[i+k-1]-sum[i-1]);

		ans=max(ans,tmp);

	}

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

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 6.434006813342145x):
//#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;

}