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

#include<cstring>

#include<cstdio>

#include<algorithm>

#include<queue>

#include<vector>

#include<cmath>

#include<stack>

using namespace std;

bool vis[220010];

char s[220010];

bool check(int x, int y, int len)

{

    vis[0]=x;

    vis[1]=y;

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

    {

        if(vis[i-1])

        {

            if(s[i-1]=='o') 

                vis[i]=vis[i-2];

            else 

                vis[i]=!vis[i-2];

        }

        else

        {

            if(s[i-1]=='o') 

                vis[i]=!vis[i-2];

            else 

                vis[i]=vis[i-2];

        }

    }

    if(vis[len]==vis[0]&&vis[len+1]==vis[1])

    {

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

        {

            if(vis[i])

                printf("S");

            else

                printf("W");

        }

        puts("");

        return 1;

    }

    return 0;

}

int main()

{

    int n;

    while(scanf("%d",&n)!=EOF)

    {

        scanf("%s",s);

        int len=n;

        s[len]=s[0];

        s[len+1]=s[1];

        s[len+2]='\0';

        bool fl=0;

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

        {

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

            {

                if(check(i,j,len))

                {

                    fl=1;

                    break;

                }

            }

            if(fl) 

                break;

        }

        if(!fl)

            puts("-1\n");

    }

    return 0;

}

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

#include <cstdlib>



const int MAXN=100011;



int N;

char str[MAXN];



bool isWolf[MAXN];



void Shift(){

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

		if(isWolf[i-1]){

			if(str[i-1]=='x')

				isWolf[i]=isWolf[i-2];

			else	isWolf[i]=!isWolf[i-2];

		}

		else{

			if(str[i-1]=='o')

				isWolf[i]=isWolf[i-2];

			else	isWolf[i]=!isWolf[i-2];

		}

	}

}



bool Test(int a){

	int p=a-1;if(p<0)	p+=N;

	int n=a+1;if(n>=N)	n-=N;

	if(isWolf[a]^(str[a]=='o'))

		return isWolf[p]==isWolf[n];

	return isWolf[p]!=isWolf[n];

}



bool Test(){

	bool ret=true;

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

		ret&=Test(i);

	}

	return ret;

}



void Show(){

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

		if(isWolf[i])

			printf("W");

		else	printf("S");

	}

	puts("");

	exit(0);

}



int main(){

	

	scanf("%d", &N);

	

	scanf("%s", str);

	

	isWolf[0]=false;isWolf[1]=false;

	Shift();

	if(Test())	Show();

	

	isWolf[0]=false;isWolf[1]=true;

	Shift();

	if(Test())	Show();

	

	isWolf[0]=true;isWolf[1]=false;

	Shift();

	if(Test())	Show();

	

	isWolf[0]=true;isWolf[1]=true;

	Shift();

	if(Test())	Show();

	

	puts("-1");

	

	return 0;

}

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

using namespace std;

int n;

char arr[100000];

char brr[100000];

int pd(char a,char b)

{

	brr[0]=a;

	brr[1]=b;

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

	{

		if(brr[i]=='S'&&arr[i]=='o'||brr[i]=='W'&&arr[i]=='x')

		{

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

		}

		else

		{

			if(brr[i-1]=='S')

			{

				brr[i+1]='W';

			}

			else

			{

				brr[i+1]='S';

			}

		}

	}

	char t;

	if(brr[n-1]=='S'&&arr[n-1]=='o'||brr[n-1]=='W'&&arr[n-1]=='x')

	{

		t=brr[n-2];

	}

	else

	{

		if(brr[n-2]=='S')

		{

			t='W';

		}

		else

		{

			t='S';

		}

	}

	if(t==brr[0])

	{

		if(brr[0]=='S'&&arr[0]=='o'||brr[0]=='W'&&arr[0]=='x')

		{

			if(brr[1]==brr[n-1])

			{

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

				{

					cout<<brr[i];

				}

				return 0;

			}

		}

		else

		{

			if(brr[1]!=brr[n-1])

			{

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

				{

					cout<<brr[i];

				}

				return 0;

			}

		}

	}

	return 1;

}

int main()

{

	cin>>n;

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

	{

		cin>>arr[i];

	}

	char crr[4][2]={'W','W','W','S','S','S','S','W'};

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

	{

		if(pd(crr[i][0],crr[i][1])==0)

			return 0;

	}

	cout<<-1;

}

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

#include <cstdlib>



const int MAXN=100011;



int N;

char str[MAXN];



bool isWolf[MAXN];



void Shift(){

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

		if(isWolf[i-1]){

			if(str[i-1]=='x')

				isWolf[i]=isWolf[i-2];

			else	isWolf[i]=!isWolf[i-2];

		}

		else{

			if(str[i-1]=='o')

				isWolf[i]=isWolf[i-2];

			else	isWolf[i]=!isWolf[i-2];

		}

	}

}



bool Test(int a){

	int p=a-1;if(p<0)	p+=N;

	int n=a+1;if(n>=N)	n-=N;

	if(isWolf[a]^(str[a]=='o'))

		return isWolf[p]==isWolf[n];

	return isWolf[p]!=isWolf[n];

}



bool Test(){

	bool ret=true;

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

		ret&=Test(i);

	}

	return ret;

}



void Show(){

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

		if(isWolf[i])

			printf("W");

		else	printf("S");

	}

	puts("");

	exit(0);

}



int main(){

	

	scanf("%d", &N);

	

	scanf("%s", str);

	

	isWolf[0]=false;isWolf[1]=false;

	Shift();

	if(Test())	Show();

	

	isWolf[0]=false;isWolf[1]=true;

	Shift();

	if(Test())	Show();

	

	isWolf[0]=true;isWolf[1]=false;

	Shift();

	if(Test())	Show();

	

	isWolf[0]=true;isWolf[1]=true;

	Shift();

	if(Test())	Show();

	

	puts("-1");

	

	return 0;

}

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

using namespace std;



int zz[100005],n;

char dat[100005];



bool check(){

	if(!((dat[0]=='x')==zz[1]^zz[n-1]^zz[0])) return false;

	if(!((dat[n-1]=='x')==zz[n-2]^zz[n-1]^zz[0])) return false;

	return true;

}



int main(){

	scanf("%d%s",&n,dat);

	

	dat[0];

	

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

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

			zz[1]=i;

			zz[0]=j;

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

				zz[k+1]=zz[k-1]^zz[k]^(dat[k]=='x');

			if(check()){

				for(int k=0;k<n;k++) printf("%c",zz[k]?'W':'S');

				return 0;

			}

		}

	}

	

	printf("-1\n");

	return 0;

} 

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

#include <cstdlib>



const int MAXN=100011;



int N;

char str[MAXN];



bool isWolf[MAXN];



void Shift(){

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

		if(isWolf[i-1]){

			if(str[i-1]=='x')

				isWolf[i]=isWolf[i-2];

			else	isWolf[i]=!isWolf[i-2];

		}

		else{

			if(str[i-1]=='o')

				isWolf[i]=isWolf[i-2];

			else	isWolf[i]=!isWolf[i-2];

		}

	}

}



bool Test(int a){

	int p=a-1;if(p<0)	p+=N;

	int n=a+1;if(n>=N)	n-=N;

	if(isWolf[a]^(str[a]=='o'))

		return isWolf[p]==isWolf[n];

	return isWolf[p]!=isWolf[n];

}



bool Test(){

	bool ret=true;

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

		ret&=Test(i);

	}

	return ret;

}



void Show(){

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

		if(isWolf[i])

			printf("W");

		else	printf("S");

	}

	puts("");

	exit(0);

}



int main(){

	

	scanf("%d", &N);

	

	scanf("%s", str);

	

	isWolf[0]=false;isWolf[1]=false;

	Shift();

	if(Test())	Show();

	

	isWolf[0]=false;isWolf[1]=true;

	Shift();

	if(Test())	Show();

	

	isWolf[0]=true;isWolf[1]=false;

	Shift();

	if(Test())	Show();

	

	isWolf[0]=true;isWolf[1]=true;

	Shift();

	if(Test())	Show();

	

	puts("-1");

	

	return 0;

}

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

using namespace std;



bool a[100010],r[100010];

int n;



void solve(){

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

		if(r[i]==1){

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

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

		}

		else{

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

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

		}

	}

	int x;

	if(r[0]==1){

		if(a[0]==0) x=a[1];

		else x=1-a[1];

	}

	else{

		if(a[0]==0) x=1-a[1];

		else x=a[1];

	}

	if(a[n]==a[0]&&a[n-1]==x){

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

			if(a[i]==0) cout<<"S";

			else cout<<"W";

		}

		exit(0);

	}

}



int main(){

	cin>>n;

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

		char x;

		cin>>x;

		if(x=='o') r[i]=1;

		else r[i]=0;

	}

	memset(a,0,sizeof(a));

	a[0]=0;

	a[1]=0;

	solve();

	memset(a,0,sizeof(a));

	a[0]=0;

	a[1]=1;

	solve();

	memset(a,0,sizeof(a));

	a[0]=1;

	a[1]=0;

	solve();

	memset(a,0,sizeof(a));

	a[0]=1;

	a[1]=1;

	solve();

	cout<<"-1"<<endl;

	return 0;

}

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

using namespace std;



int zz[100005],n;

char dat[100005];



bool check(){

	if(!((dat[0]=='x')==zz[1]^zz[n-1]^zz[0])) return false;

	if(!((dat[n-1]=='x')==zz[n-2]^zz[n-1]^zz[0])) return false;

	return true;

}



int main(){

	scanf("%d%s",&n,dat);

	

	dat[0];

	

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

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

			zz[1]=i;

			zz[0]=j;

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

				zz[k+1]=zz[k-1]^zz[k]^(dat[k]=='x');

			if(check()){

				for(int k=0;k<n;k++) printf("%c",zz[k]?'W':'S');

				return 0;

			}

		}

	}

	

	printf("-1\n");

	return 0;

} 

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

#define MOD 1000000007

#define INF 0x3f3f3f3f

#define INFL 0x3f3f3f3f3f3f3f3f

#define EPS (1e-10)

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

using namespace std;

typedef long long ll;

typedef pair<int, int>P;

#define prv(i)((i+n-1)%n)

#define nxt(i)((i+1)%n)



int b[100000];

int n; string s;



bool bfs(int a, int m, int c) {

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

	b[prv(0)] = a; b[0] = m; b[nxt(0)] = c;

	queue<int>que; que.push(prv(0)); que.push(nxt(0));

	while (!que.empty()) {

		int p = que.front(); que.pop();

		if (b[p]) {//本当

			if (~b[prv(p)] && !~b[nxt(p)]) {

				if (s[p] == 'o')b[nxt(p)] = b[prv(p)];

				else b[nxt(p)] = !b[prv(p)];

				que.push(nxt(p));

			}

			if (~b[nxt(p)] && !~b[prv(p)]) {

				if (s[p] == 'o')b[prv(p)] = b[nxt(p)];

				else b[prv(p)] = !b[nxt(p)];

				que.push(prv(p));

			}

		}

		else {//うそ

			if (~b[prv(p)] && !~b[nxt(p)]) {

				if (s[p] == 'o')b[nxt(p)] = !b[prv(p)];

				else b[nxt(p)] = b[prv(p)];

				que.push(nxt(p));

			}

			if (~b[nxt(p)] && !~b[prv(p)]) {

				if (s[p] == 'o')b[prv(p)] = !b[nxt(p)];

				else b[prv(p)] = b[nxt(p)];

				que.push(prv(p));

			}

		}

	}

	rep(i, n) {

		if (b[i]) {

			if (!((s[i] == 'o'&&b[prv(i)] == b[nxt(i)]) || (s[i] == 'x'&&b[prv(i)] != b[nxt(i)])))return false;

		}

		else {

			if (!((s[i] == 'o'&&b[prv(i)] != b[nxt(i)]) || (s[i] == 'x'&&b[prv(i)] == b[nxt(i)])))return false;

		}

	}

	return true;

}

signed main() {

	cin >> n >> s;

	rep(i, 2)rep(j, 2)rep(k, 2) {

		if (bfs(i, j, k)) {

			rep(t, n) {

				if (b[t])printf("S");

				else printf("W");

			}

			printf("\n"); return 0;

		}

	}

	puts("-1");

}

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

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

using namespace std;

#define nxt(i)((i+1)%n)

#define prv(i)((i+n-1)%n)



int n; string s;

int b[100000];

bool ok(int i, int j) {

	b[0] = i; b[prv(0)] = j;

	for (int i = 0; nxt(i) != prv(0); i = nxt(i)) {

		if ((b[i] && s[i] == 'o') || (!b[i] && s[i] == 'x'))b[nxt(i)] = b[prv(i)];

		else b[nxt(i)] = !b[prv(i)];

	}

	rep(i, n) {

		if (b[i]) {

			if (!((s[i] == 'o'&&b[prv(i)] == b[nxt(i)]) || (s[i] == 'x'&&b[prv(i)] != b[nxt(i)])))return false;

		}

		else {

			if (!((s[i] == 'o'&&b[prv(i)] != b[nxt(i)]) || (s[i] == 'x'&&b[prv(i)] == b[nxt(i)])))return false;

		}

	}

	return true;

}

signed main() {

	cin >> n >> s;

	rep(i, 2)rep(j, 2) {

		if (!ok(i, j))continue;

		rep(k, n) {

			if (b[k])printf("S");

			else printf("W");

		}

		printf("\n");

		return 0;

	}

	puts("-1");

}

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

using namespace std;



bool a[100010],r[100010];

int n;



void solve(){

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

		if(r[i]==1){

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

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

		}

		else{

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

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

		}

	}

	int x;

	if(r[0]==1){

		if(a[0]==0) x=a[1];

		else x=1-a[1];

	}

	else{

		if(a[0]==0) x=1-a[1];

		else x=a[1];

	}

	if(a[n]==a[0]&&a[n-1]==x){

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

			if(a[i]==0) cout<<"S";

			else cout<<"W";

		}

		exit(0);

	}

}



int main(){

	cin>>n;

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

		char x;

		cin>>x;

		if(x=='o') r[i]=1;

		else r[i]=0;

	}

	memset(a,0,sizeof(a));

	a[0]=0;

	a[1]=0;

	solve();

	memset(a,0,sizeof(a));

	a[0]=0;

	a[1]=1;

	solve();

	memset(a,0,sizeof(a));

	a[0]=1;

	a[1]=0;

	solve();

	memset(a,0,sizeof(a));

	a[0]=1;

	a[1]=1;

	solve();

	cout<<"-1"<<endl;

	return 0;

}

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

using namespace std;



char p[100005];

int S[100005],P[100005],n; 



int main(){

	scanf("%d%s",&n,&p);

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

		if(p[i]=='o') P[i+1]=0;

		else P[i+1]=1;

	}

	P[n+1]=P[1];

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

		S[0]=i&1;

		S[1]=(i>>1)&1;

		S[2]=(i>>2)&1;

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

			S[j+1]=S[j-2]^P[j];

		}

		if((S[0]^S[1]^S[n]^S[n+1])||(S[1]^S[2]^S[n+1]^S[n+2])) continue;

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

			printf("%c",(S[j-1]^S[j])?'W':'S');

		}

		return 0;

	}

	printf("-1\n");

	return 0;

} 

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



#include <iostream>

#include <sstream>

#include <algorithm>

#include <numeric>

#include <vector>

#include <cstdio>

#include <cstdlib>

#include <cstring>



using namespace std;



typedef long long LL;



#ifdef __GNUC__

#define int128_t __int128

#else

typedef LL int128_t;

#endif



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

	LL x, k, d;

	cin >> x >> k >> d;

	if (x < 0) x = -x;

	LL r = (x + d - 1) / d;

	if (d >= x && k >= 9) {

		k = 8 + (k % 8);

	}

	int128_t X = x, K = k, D = d, kd = K * D;

	if (kd <= X) {

		x -= k * d;

		k = 0;

	} else if (k >= 100) {

		LL a = x % d;

		LL b = x - a;

		r = b / d;

		if (k >= r) {

			k -= r;

			x -= r * d;

			if (k >= 8) {

				k = 8 + (k % 8);

			}

		}

	}

	vector<LL> q;

	q.push_back(x);

	for (int t = 0; t < k; ++t) {

		vector<LL> nq;

		for (auto a : q) {

			nq.emplace_back(a - d);

			nq.emplace_back(a + d);

		}

		q = nq;

	}

	LL ans = 1LL << 60;

	for (auto a : q) {

		ans = min(ans, abs(a));

	}

	cout << ans << endl;

	return 0;

}


// Optimized solution to the same problem (faster):
// C.



#include <iostream>

#include <sstream>

#include <algorithm>

#include <numeric>

#include <vector>

#include <cstdio>

#include <cstdlib>

#include <cstring>



using namespace std;



typedef long long LL;



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

	LL x, k, d;

	cin >> x >> k >> d;

	if (x < 0) x = -x;

	LL r = min(k, x / d);

	x -= r * d;

	k -= r;

	LL ans = k % 2 ? abs(x - d) : x;

	cout << ans << endl;

	return 0;

}


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

using namespace std;

long long x,k,d;

int main() {

	cin>>x>>k>>d;

	if(x<0) {

		x*=-1;

	}

	if(x/d>k) {

		cout<<x-k*d;

	}

	else {

		long long y;

		while(x>=0) {

			y=x;

			x-=d;

			k--;

		}

		if (k%2==0) {

			cout<<abs(x)<<endl;

		} else {

			cout<<abs(y)<<endl;

		}

	}

	return 0;

}


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

typedef long long LL;



int main()

{	 

	LL x, k, d, y, z;

	

	scanf("%lld%lld%lld", &x, &k, &d);	

	if(x < 0) x = -x;

	y = x / d;

	if(y >= k) z = x - d * k;

	else{

		z = x % d;

		if((k - y) & 1) z = d - z;

	}

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

		

	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 __gnu_pbds;

using namespace std;

#define PI  3.14159265358979323846

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

#define rlp(i,n) for(int i = int(n);i >= 0;i--)

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

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

#define all(x) (x).begin(),(x).end()

#define pb push_back

#define MP make_pair

#define fr first

#define sc second

#define sz(v) ((int)((v).size()))

#define sfi1(v) scanf("%d",&v)

#define sfi2(v1, v2) scanf("%d %d",&v1,&v2)

#define sfi3(v1, v2, v3) scanf("%d %d %d",&v1,&v2,&v3)

#define sfll1(v) scanf("%I64d",&v);

#define sfll2(v1, v2) scanf("%I64d %I64d",&v1,&v2)

#define sfll3(v1, v2, v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)

typedef long long ll;

typedef unsigned long long ull;

typedef vector<int> vi;

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

typedef pair<int, int> pii;

template<class T> using ordered_set=tree<T,

null_type,

less<T>,

rb_tree_tag,

tree_order_statistics_node_update>;

const ll MOD = 1e9 + 7;

const int OO = (int)1e6;

const int N = (int)1e7;

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

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

void init(){

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

}

void _run(){

   ll x,k,d;

   cin>>x>>k>>d;

   ll ans =0;

   x = abs(x);

   if(x/d>k){

       cout<<x-(k*d)<<endl;

    return;

   }

   ll rem = x/d;

   k-=rem;

   x-=rem*d;

   if(k&1)x=abs(x-d);

   ans = x;

   cout<<x<<endl;

}

int main() {

	#   ifdef LOCAL_PROJECT

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

    #   endif

    int t=1;

    // scanf("%d",&t);

    while(t--)_run();

    

    return 0;

}

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

typedef long long LL;



int main()

{	 

	LL x, k, d, y, z;

	

	scanf("%lld%lld%lld", &x, &k, &d);	

	if(x < 0) x = -x;

	y = x / d;

	if(y >= k) z = x - d * k;

	else{

		z = x % d;

		if((k - y) & 1) z = d - z;

	}

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

		

	return 0;

}

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

using namespace std;

using ll=long long;



int main()

{

    int $=1;

    //cin>>$;

    while($--)

    {

        ll x,k,d;

        cin>>x>>k>>d;

        x=abs(x);

        ll t=x/d;

        ll a=x%d;

        if(k<=t)

        {

            a=x-k*d;

        }

        else{

            k-=t;

            if(k%2==1)

            {

                a-=d;

                a=abs(a);

            }

        }

        cout<<a<<endl;

    }

}





/*

8888888888888888888888888888

    Md. Masud Mazumder

    University of Chittagong

    Department of CSE

8888888888888888888888888888

*/


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

typedef long long LL;



int main()

{	 

	LL x, k, d, y, z;

	

	scanf("%lld%lld%lld", &x, &k, &d);	

	if(x < 0) x = -x;

	y = x / d;

	if(y >= k) z = x - d * k;

	else{

		z = x % d;

		if((k - y) & 1) z = d - z;

	}

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

		

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#define ALL(obj) (obj).begin(), (obj).end()

 

#include <iomanip>

#include <iostream>

#include <fstream>

#include <cstdio>

#include <cmath>

#include <vector>

#include <string>

#include <set>

#include <map>

#include <stack>

#include <queue>

#include <deque>

#include <bitset>

#include <algorithm>

#include <complex>

#include <array>

#include <functional>

 

using namespace std;

typedef long long ll;

const ll INF = 1e18;

 

ll N;

ll K;

 

int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    cin >> N >> K;

    vector<ll> p(N);

 

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

        cin >> p[i];

    }

    

    vector<ll> table(200001);

    ll sum = 0;

    

    for (ll i=1; i<=200000; i++) {

        sum += i;

        table[i] = sum;

    }

    

    double answer = 0.0;

 

    if (N==1) {

        cout << (double)table[p[0]] / (double)p[0] << endl;

        return 0;

    }

    

    if (N==2) {

        if (K==1) {

            double a = (double)table[p[0]] / (double)p[0];

            double b = (double)table[p[1]] / (double)p[1];

            if (a > b) {

                cout << a << endl;

                return 0;

            } else {

                cout << b << endl;

                return 0;

            }

        } else {

            double ans = (double)table[p[0]] / (double)p[0] + (double)table[p[1]] / (double)p[1];

            cout << ans << endl;

            return 0;

        }

    }

    

    for (ll j=0; j<K; j++) {

        answer += (double)table[p[j]] / (double)p[j];

    }

    

    double max = answer;

    for (ll i=K; i<N; i++) {

        double left = (double)table[p[i-K]] / (double)p[i-K];

        double right = (double)table[p[i]] / (double)p[i];

        double tmp = answer + right - left;

        if (max < tmp) {

            max = tmp;

        }

        answer = tmp;

    }

    

    cout << setprecision(12) << max << endl;

    

    return 0;

}


// Optimized solution to the same problem (faster):
#define ALL(obj) (obj).begin(), (obj).end()

 

#include <iostream>

#include <iomanip>

#include <fstream>

#include <cstdio>

#include <cmath>

#include <vector>

#include <string>

#include <set>

#include <map>

#include <stack>

#include <queue>

#include <deque>

#include <bitset>

#include <algorithm>

#include <complex>

#include <array>

#include <functional>

 

using namespace std;

typedef long long ll;

const ll INF = 1e18;

 

int N;

int K;

 

int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    cin >> N >> K;

    vector<int> p(N);

 

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

        cin >> p[i];

    }

    

    double answer = 0.0;

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

        answer += (double)(1+p[j])/2;

    }

    

    double maxd = answer;

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

        double left = (double) (1+p[i-K])/2;

        double right = (double)(1+p[i])/2;

        answer += right;

        answer -= left;

        maxd = max(maxd, answer);

    }

    

    cout << setprecision(12) << maxd << endl;

    

    return 0;

}


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

using namespace std;

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

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

#define  all(x) (x).begin(),(x).end()     // 昇順ソート

#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート

#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)

typedef long long ll;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }

template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }



int main(){

    int k, n;

    cin >> n >> k;

    vector<int> p(n);

    rep(i, n) cin >> p[i];

    map<int, double> m;

    ll e = 0;

    repr(i, 1, 1001){

        e += i;

        m[i] = (double)e / (double)i;

    }

    double sum = 0.0, ans = 0.0;

    rep(i, n){

        sum += m[p[i]];

        if (i+1 < k){

            continue;

        }

        ans = max(ans, sum);

        sum -= m[p[i-k+1]];

    }

    printf("%.7lf\n", ans);

    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++)

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

#define  all(x) (x).begin(),(x).end()     // 昇順ソート

#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート

#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)

typedef long long ll;

using P = pair<int,int>;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }

template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }



ll f(ll r){

    return (r * (r + 1)) / 2;

}



int main(){

    int n, k;

    cin >> n >> k;

    vector<ll> p(n);

    rep(i,n) cin >> p[i];

    vector<double> E(n);

    rep(i,n){

        E[i] = (double)f(p[i]) / p[i];

    }



    vector<double> sum(n+1);

    sum[0] = 0;

    rep(i,n) sum[i+1] = sum[i] + E[i];

    double ans = 0;

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

        if (i + k - 1 > n) break;

        ans = max(ans, sum[i+k-1] - sum[i-1]);

    }

    printf("%.10lf\n", ans);

    return 0;

}

// Fastest known solution for this problem: