akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<57;
const double pi=acos(-1);
const double eps=1e-6;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,-0};
const int DX[8]={-1,-1,-1,0,1,1,1,0},DY[8]={1,0,-1,-1,-1,0,1,1};

//1 2 3 4 = 2^4-1
//1 2 3 5 4 = 2^4-1+2^3

ll n;

int main(){
	cin>>n;
	n++;
	vi a;
	for(int i=50;i>=0;i--) if(n&1ll<<i){
		for(int j=0;j<i;j++) a.push_back(j+1);
		break;
	}
	int S=a.size(),I=S+1;
	for(int i=S-1;i>=0;i--) if(n&1ll<<i){
		a.insert(a.begin()+i,I);
		I++;
	}
	for(int i=1;i<I;i++) a.push_back(i);
	S=a.size();
	cout<<S<<endl;
	for(int i=0;i<S;i++){
		if(i) cout<<' ';
		cout<<a[i];
	}
	cout<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,k,n) for(ll i= (ll) k;i< (ll) n;i++)
#define all(v) (v).begin(), (v).end()
#define SZ(v) (ll)((v).size())
#define pb push_back
#define ft first
#define sd second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const long long INF = 1e18L + 1;
const int IINF = 1e9 + 1;

using namespace std;

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

#ifdef LOCAL
#define DBG(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define DBG(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

int main()
{
#ifndef LOCAL
	ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
  	ll n; cin >> n;
	vector<ll> a(n);
	for(auto& i : a){
		cin >> i;
	}
	ll sm = accumulate(all(a), 0ll), res = INF, ans = 0;
	rep(i, 0, n){
		if(abs(n * a[i] - sm) < res){
			res = abs(n * a[i] - sm);
			ans = i;
		}
	}
	cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
s = gets.strip

d = ['dreamer', 'eraser', 'erase', 'dream']

while true
        f = false
        d.each do |word|
                if s[-word.size, word.size] == word
                        s = s[0..-(word.size + 1) ]
                        f = true
                        break
                end
        end
        if not f
                break
        end
end

if s == ""
        puts 'YES'
else
        puts 'NO'
end

Measured memory_bytes: 60732
#include <bits/stdc++.h>
using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;

    if(a + b == c || a + c == b || b + c == a){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){
	string str;
	cin >> str;

	int ans1=-1, ans2=-1;
	if(str.length()==2){
		if(str[0]==str[1]){
			ans1=1;
			ans2=2;
		}
	}else{
		REP(i, str.length()-2){
			if(str[i]==str[i+1] || str[i]==str[i+2]){
				ans1=i+1;
				ans2=i+3;
				goto LAST;
			}
		}
		if(str[str.length()-2]==str[str.length()-1]){
			ans1=str.length()-2;
			ans2=str.length();
		}
	}

LAST:
	cout << ans1 << ' ' << ans2 << '\n';
	
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

typedef long long LL;

const int oo = 0x3f3f3f3f;

const int maxn = 310;

int n, m;
int a[maxn + 5][maxn + 5];

bool ok[maxn + 5];

int main()
{
#ifdef matthew99
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	scanf("%d%d", &n, &m);
	REP(i, 0, n)
		REP(j, 0, m)
			scanf("%d", a[i] + j), --a[i][j];
	memset(ok, 1, sizeof ok);
	int ans = oo;
	REP(i, 0, m)
	{
		static int cnt[maxn + 5];
		memset(cnt, 0, sizeof cnt);
		REP(j, 0, n)
		{
			REP(k, 0, m)
				if (ok[a[j][k]])
				{
					++cnt[a[j][k]];
					break;
				}
		}
		int p = -1;
		REP(j, 0, m) if (ok[j] && (!~p || cnt[j] > cnt[p])) p = j;
		chkmin(ans, cnt[p]);
		ok[p] = 0;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>

#define N 20000

typedef struct Data{
  int area,pos;
} Data;

Data t[N];
int u[N]; 
int n,i;
char str[N];
int T,U;
int a,A;
Data B,X;

void D_push(Data );
Data D_pop();
void push(int);
int pop();
void init();
Data makeData(int,int);

int main(){
  init();
  scanf("%s",str);
  n = strlen(str);  
  for(i = 0;i < n;i++){  
    if(str[i] == '/'){   
      if(U == 0)continue;
      A = pop();
      X = makeData(i-A,A);
      a = a + i - A;
      while(T > 0){
	B = D_pop();
	if(B.pos < A){
	  D_push(B);
	  break;
	}
	X.area = X.area + B.area;
	if(B.pos < X.pos)X.pos = B.pos;
      }
      D_push(X);
    }else if(str[i] == '\\'){
      push(i);
    }
  }
  
  printf("%d\n%d", a, T);
  for(i = 0;i < T;i++){
    printf(" %d",t[i].area);
  }
  printf("\n");
  return 0;
}

void D_push(Data data){
  t[T++]=data;
}

Data D_pop(){
  return t[--T];
}

void push(int x){
  u[U++]=x;
}

int pop(){
  return u[--U];
}

void init(){
  a=0;
  T=0;
  U=0;
}

Data makeData(int x,int y){ 
  Data res; 
  res.area=x;
  res.pos=y;
  return res;
}

Measured memory_bytes: 644
s = input()
l = []
L = len(s)
for i in range(len(s)):
    l.append(s[i])
    l.append(s[i:min(i+2,L)])
    l.append(s[i:min(i+3,L)])
    l.append(s[i:min(i+4,L)])
    l.append(s[i:min(i+5,L)])
l = sorted(set(l))

print(l[int(input())-1])


Measured memory_bytes: 5052
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <queue>
#include <map>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
#define INF 1e10
typedef long long ll;
typedef long double ld;



int main(){
    ll d, n; cin>>d>>n;
    if(d==0&&n==100){
        cout<<101<<endl;
    }else if(d==1&&n==100){
        cout<<10100<<endl;
    }else if(d==2&&n==100){
        cout<<1010000<<endl;
    }else{
        cout<<pow(100,d)*n<<endl;
    }
    return 0;
}


Measured memory_bytes: 3924
X, Y, A ,B, C = list(map(int, input().split()))
P = sorted(list(map(int, input().split())), reverse = True)[:X]
Q = sorted(list(map(int, input().split())), reverse = True)[:Y]
R = sorted(list(map(int, input().split())), reverse = True)
ans = 0
for i in range(C):
  if(len(P) == 0):
    if(len(Q) == 0):
      break
    elif(Q[-1] < R[i]):
      Q.pop()
      ans += R[i]
    else:
      break
  elif(len(Q) == 0):
    if(P[-1] < R[i]):
      P.pop()
      ans += R[i]
    else:
      break
  else:
    if(P[-1] < Q[-1] and P[-1] < R[i]):
      P.pop()
      ans += R[i]
    elif(Q[-1] <= P[-1] and Q[-1] < R[i]):
      Q.pop()
      ans += R[i]
    else:
      break
ans += sum(P) + sum(Q)
print(ans)

Measured memory_bytes: 105188
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
	double a, b, c, d, e, f;
	while(scanf("%lf%lf%lf%lf%lf%lf", &a, &b, &c, &d, &e, &f) != EOF){
		double ans1 = (e*c-f*b)/(e*a-b*d);
		double ans2 = (d*c-f*a)/(b*d-a*e);
		ans1 = (fabs(ans1) < 1e-15) ? 0.0 : ans1;
		ans2 = (fabs(ans2) < 1e-15) ? 0.0 : ans2;
		printf("%.3lf %.3lf\n", ans1, ans2);
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <iterator>
#include <iomanip>
#include <sstream>
#include <numeric>
#define INF 2000000000
using namespace std;
int dx[8]={1,1,0,-1,-1,-1,0,1},dy[8]={0,1,1,1,0,-1,-1,-1};
#define sym cout<<"---------"<<endl;
#define ll long long
#define PL pair<long long, long long>
#define P pair<int,int>
#define mk make_pair
#define en endl
#define WHITE 0
#define BLACK 2
#define GRAY 1
#define RE return 0
#define int ll

#define MAX 1005
int castle[MAX][MAX];
int many[MAX][MAX];
bool come[MAX][MAX];

signed main(){
  int h,w;
  cin>>h>>w;
  
  for(int i=1; i<=h; i++) for(int j=1; j<=w; j++){
    char ch;
    cin>>ch;
    if(ch=='.') castle[i][j]=-1;
    else castle[i][j]=(int)ch-'0';
    come[i][j]=false;
  }
  
  queue<P> que;
  for(int i=1; i<=h; i++) for(int j=1; j<=w; j++){
    int cnt=0;
    if(castle[i][j]==-1) continue;
    for(int k=0; k<8; k++){
      int y=i+dy[k],x=j+dx[k];
      if(castle[y][x]==-1) cnt++;
    }
    if(cnt>=castle[i][j]){
      come[i][j]=true;
      que.push(mk(i,j));
      many[i][j]=1;
    }else castle[i][j]-=cnt;
  }
  
  while(!que.empty()){
    int y=que.front().first,x=que.front().second;
    que.pop();
    for(int i=0; i<8; i++){
      if(come[y+dy[i]][x+dx[i]]) continue;
      if(y+dy[i]<1||y+dy[i]>h) continue;
      if(x+dx[i]<1||x+dx[i]>w) continue;
      if(castle[y+dy[i]][x+dx[i]]==-1) continue;
      castle[y+dy[i]][x+dx[i]]--;
      if(castle[y+dy[i]][x+dx[i]]==0){
        que.push(mk(y+dy[i],x+dx[i]));
        many[y+dy[i]][x+dx[i]]=many[y][x]+1;
        come[y+dy[i]][x+dx[i]]=true;
      }
    }
  }
  
  int ans=0;
  for(int i=1; i<=h; i++) for(int j=1; j<=w; j++) ans=max(ans,many[i][j]);
  
  cout<<ans<<en;
}



Measured memory_bytes: 19816
using System;
using System.Collections.Generic;
using System.Linq;
class Program{
	static void Main(){
		int[] s=Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
		int n=s[0],w=s[1],m=0;
		long[] dp=new long[100001];
		for(int i=1;i<100001;i++){
			dp[i]=int.MaxValue;
		}
		for(int i=1;i<=n;i++){
			int[] q=Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
			for(int j=m;j>=0;j--){
				if(dp[j]+q[0]<=w){
					dp[j+q[1]]=Math.Min(dp[j+q[1]],dp[j]+q[0]);
				}
			}
			m+=q[1];
			//Console.WriteLine(String.Join(" ",dp));
		}
		for(int j=m;j>=0;j--){
			if(dp[j]<=w){
				Console.WriteLine("{0}",j);
				break;
			}
		}
	}
}

Measured memory_bytes: 13792
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(){
    int N;
    cin >> N;
    cout << N*(N+1)/2;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;

public class Main{
public static void main(String[] args){
Scanner scan=new Scanner(System.in);
int a=scan.nextInt();
int b=scan.nextInt();
  int sum=0;
  int i=0;
  if(a<b){
    for(i=0;i<b;i++){
      sum=sum+a*(int)Math.pow(10,i);
    }
  }else{
    for(i=0;i<a;i++){
      sum=sum+b*(int)Math.pow(10,i);
    }
  }
  
System.out.println(sum);
}
}

Measured memory_bytes: 19796
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    string S; cin >> S;
    int cnt = 0;
    rep(i, 3){
        if(S[i] == 'R')cnt++;
    }

    if(cnt != 2){
        cout << cnt << endl;
    } else {
        if(S[1] == 'R'){
            cout << cnt << endl;
        } else {
            cout << 1 << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3584
#include <iterator>
#include <list>
#include <algorithm>
#include <iostream>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <sstream>
#include <iomanip>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;

int main() {
  string S; cin >> S;

  int first = stoi(S.substr(0, 2));
  int second = stoi(S.substr(2));

  if (first >= 1 && first <= 12) {
    if (second >= 1 && second <= 12) {
      cout << "AMBIGUOUS" << endl;
    } else {
      cout << "MMYY" << endl;
    }
  } else {
    if (second >= 1 && second <= 12) {
      cout << "YYMM" << endl;
    } else {
      cout << "NA" << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 256
# coding: utf-8

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)


n = int(input())
data = list(map(int, input().split()))

ans = data[0]

for i in range(n - 1):
    ans = gcd(ans, data[i + 1])

print(ans)


Measured memory_bytes: 14252
y = {}
(:a..:z).each do |i|
    y[i] = 0
end
loop do
x = gets
if x == nil
    break
end
z = x.gsub(/[^a-zA-Z]/,"").downcase.split(//)
z.each do |i|
    y[:"#{i}"] += 1
end
end
y.each do |k,v|
    puts "#{k} : #{v}"
end

Measured memory_bytes: 8656
#include <bits/stdc++.h>
using namespace std;

int main()
{
    string S[8] = {"", "SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN"};
    string T;

    cin >> T;
    
    cout << find(begin(S), end(S), T) - S << endl;

    return ( 0 );
}


Measured memory_bytes: 256
#include <bits/stdc++.h>

using namespace std;

int main() {
  int n;
  cin >> n;
  long long a, b;
  cin >> a >> b;
  for (int i = 1; i < n; i++) {
    long long x, y, rx, ry;
    cin >> x >> y;
    rx = (a + x - 1) / x;
    ry = (b + y - 1) / y;
    x *= max(rx, ry);
    y *= max(rx, ry);
    a = x;
    b = y;
  }
  cout << a + b << '\n';
  return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using namespace std;
using uint = unsigned int;
using ll = long long;
const int M = 1e9 + 7;
const ll MLL = 1e18L + 9;
#pragma unused(M)
#pragma unused(MLL)
#ifdef LOCAL
#include"rprint.hpp"
#else
template <ostream& out = cout, class... T> void prints(T&&...){ }
template <ostream& out = cout, class... T> void printd(T&&...){ }
template <ostream& out = cout, class... T> void printb(T&&...){ }
template <ostream& out = cout, class... T> void printArr(T&&...){ }
#endif

int main(){
    int n; cin >> n;
    vector<int> as(n), bs(n);
    int x = 0;
    for(int i = 0; i < n; i++){
        cin >> as[i];
        x ^= as[i];
    }
    for(int i = 0; i < n; i++){
        cin >> bs[i];
    }

    as.push_back(x);
    auto a2 = as, b2 = bs;
    sort(a2.begin(), a2.end());
    sort(b2.begin(), b2.end());
    bool sld = false;
    prints(a2, b2);
    for(int i = 0; i < n; i++){
        if(a2[i + sld] != b2[i]){
            if(sld){
                cout << -1 << '\n';
                return 0;
            }
            sld = true;
            i--;
        }
    }

    unordered_map<int, int> um;
    set<int> s(as.begin(), as.end());
    int cnt = 0;
    for(int i : s){
        um[i] = cnt++;
    }
    for(int& a : as){
        a = um[a];
    }
    for(int& b : bs){
        b = um[b];
    }

    int ans = 0;
    unordered_set<int> rems; // index
    unordered_map<int, vector<int>> mp; // num ->  index
    for(int i = 0; i < n; i++){
        if(as[i] == bs[i]){ continue; }
        rems.insert(i);
        mp[bs[i]].push_back(i);
    }

    queue<int> q; // index
    q.push(n);
    while(rems.size()){
        while(q.size()){
            int sIdx = q.front(); q.pop();
            int sNum = as[sIdx];
            if(mp.count(sNum) == 0){ continue; }
            for(int t : mp[sNum]){
                if(rems.count(t)){
                    rems.erase(t);
                    ans++;
                    q.push(t);
                }
            }
            mp.erase(sNum);
        }
        if(rems.empty()){ break; }
        ans++;
        q.push(*rems.begin());
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 23568
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = 1e9 + 7;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<int> a(n);
    REP(i, n) cin >> a[i];

    map<int, int> mp;
    REP(i, n) mp[a[i]]++;

    vector<LL> num;
    for(auto x : mp){
        if(x.second >= 4) num.pb(x.first);
        if(x.second >= 2) num.pb(x.first);
    }

    sort(all(num), greater<LL>());
    if(num.size() >= 2) cout << num[0] * num[1] << endl;
    else cout << 0 << endl;
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, k;
  int64_t M_score = -2000000000LL;
  scanf("%d %d", &n, &k);
  vector<int> p(n + 1), c(n + 1);
  for (int i = 1; i <= n; i++) cin >> p[i];
  for (int i = 1; i <= n; i++) cin >> c[i];
  for(int i = 1; i <= n; i++) {
    int move = 0, masu = i;//開始時
    int64_t sum = 0LL, sub_max = -20000000000LL;
    vector<int64_t> v;//添え字ずれます
    bool syukai = false;
    while(move < k) {
      move++;
      masu = p[masu];
      sum += c[masu];
      v.push_back(sum);
      sub_max = max(sub_max, sum);
      if(masu == i) {
        syukai = true;
        break;
      }
    }
    //この段階でsyukai == trueならsumは一周して得られるscore
    if(syukai && sum > 0) {
      for(int j = 0; j < move; j++) {
        M_score = max(M_score, v[j] + sum * (int64_t)((k - (j + 1)) / move));
      }
    }else {
      M_score = max(M_score, sub_max);
    }
  }
  cout << M_score;
}

Measured memory_bytes: 3804
#include <bits/stdc++.h> 
using namespace std;

typedef long long ll;
#define pa pair<int, int> 
#define pal pair<long long, long long>
#define pad pair<double, double>
#define pb push_back
#define mp make_pair
#define VIN(v) for(int64_t i=0;i<(v).size();i++){cin >> (v).at(i);}

typedef vector<bool> bvec;
typedef vector<int> ivec;
typedef vector<long long> lvec;
typedef vector<double> dvec;
typedef vector<pa> pvec;

typedef vector< vector<bool> > bmat;
typedef vector< vector<int> > imat;
typedef vector< vector<long long> > lmat;

typedef vector<string> svec;
typedef vector< vector<string> > smat;
const ll infll = (1LL << 60) - 1;
const int inf = (1 << 30) - 1;

ll gcd(ll x, ll y){
    ll r = x%y;
    if(r == 0) return y;
    else return gcd(y, r);
} 

ll lcm(ll x, ll y){
    return x*y/gcd(x,y);
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string n;
    cin >> n;
    ll cnt=0;
    int carry=0;
    lmat dp = lmat(n.size(), lvec(2));
    dp[n.size()-1][0] = n[n.size()-1]-'0';
    dp[n.size()-1][1] = 10 -(ll)(n[n.size()-1]-'0');
    for (ll i = n.size()-2; i >=0; i--)
    {
        dp[i][0] = (n[i] !=9 ) ?  min(dp[i+1][0] + (ll)(n[i]-'0'), dp[i+1][1]+(ll)(n[i]-'0')+1) : dp[i+1][0]+(ll)(n[i]-'0');
        
        dp[i][1] = min(dp[i+1][0] + 10 - (ll)(n[i]-'0'), dp[i+1][1]+ 10 - ((ll)(n[i]-'0')+1));
        
        
    }
    cout << min(dp[0][0], dp[0][1]+1) << endl;
}

Measured memory_bytes: 55964
// Last Change: 04/13/2019 21:01:28.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

int main() {
  int A, B;
  cin >> A >> B;

  int ans = 0;
  for (int i = 0; i < 2; ++i) {
    if (A > B) {
      ans += A;
      --A;
    } else {
      ans += B;
      --B;
    }
  }

  cout << ans << endl;

  //NS::LoopUntilZeroInpput();
}


Measured memory_bytes: 256
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
N,P=map(int,input().split())
A=list(map(int,input().split()))
even=0
odd=0
answer=0
for a in A:
    if a%2==0:
        even+=1
    else:
        odd+=1
if even==0:
    if P==0:
        if odd==1:
            print(0)
        else:
            for n in range(2,odd+1,2):
                answer+=combinations_count(odd,n)
            print(answer+1)
    else:
        for n in range(1,odd+1,2):
            answer+=combinations_count(odd,n)
        print(answer)
elif odd==0:
    if P==1:
        print(0)
    else:
        answer+=2**even
        print(answer)
else:
    if P==0:
        suuji=0
        for n in range(0,odd+1,2):
            suuji+=combinations_count(odd,n)
        answer+=2**even
        print(answer*suuji)
    else:
        suuji=0
        for n in range(1,odd+1,2):
            suuji+=combinations_count(odd,n)
        answer+=2**even
        print(answer*suuji)
        

Measured memory_bytes: 62280
import java.util.*;
import static java.lang.System.*;

public class Main {

	Scanner sc = new Scanner(in);;
	
	@SuppressWarnings("unchecked")
	void run() {
		List<Integer>[] list = new ArrayList[30];
		for (int i = 0; i < 30; i++)
			list[i] = new ArrayList<Integer>();
		
		Set<Integer>[][] dp = new HashSet[31][50];
		for (int i = 0; i < 31; i++)
			for (int j = 0; j < 50; j++)
				dp[i][j] = new HashSet<Integer>();
		
		top:while (true) {
			int n = sc.nextInt();
			if (n == 0) break;
			
			for (int i = 0; i < 31; i++)
				for (int j = 0; j < n; j++)
					dp[i][j].clear();
			
			for (int i = 0; i < 30; i++)
				list[i].clear();
		
			for (int i = 0; i < n; i++) {
				int m = sc.nextInt();
				for (int j = 0; j < m; j++) {
					list[sc.nextInt()-1].add(i);
				}
			}
			
			for (int i = 0; i < n; i++)
					dp[0][i].add(i);
			
			for (int t = 1; t <= 30; t++) {
				for (int i = 0; i < list[t-1].size(); i++) {
					for (int j = 0; j < list[t-1].size(); j++) {
						dp[t][list[t-1].get(i)].addAll(dp[t-1][list[t-1].get(j)]);
					}
				}
				for (int i = 0; i < n; i++)
					dp[t][i].addAll(dp[t-1][i]);
				for (int i = 0; i < n; i++) {
					if (dp[t][i].size() >= n) {
						out.println(t);
						continue top;
					}
				}
			}
			out.println(-1);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}

}

Measured memory_bytes: 170244
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <math.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> P;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REPR(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define FOR(i, n, m) for (ll i = (n); i < (m); ++i)
#define FORR(i, n, m) for (ll i = (m) - 1; i >= (n); --i) 
#define FORE(x, xs) for (auto &x: (xs))
#define ALL(v) v.begin(), v.end()
#define ZERO(a) memset(a,0,sizeof(a))

const int INF = 1000000009;
const int MOD = 1000000007;
const double EPS = 1e-14;
const double PI = acos(-1);

const int MAX = 2e5;

int parent[MAX];
int rankb[MAX];
ll weight[MAX];
 
void init(int x) {
  for(int i = 0; i <= x; i++)
  parent[i] = i, rankb[i]=0, weight[i] = 0;
}
 
int root(int x) {
  if (parent[x]==x) return x;
  int r = root(parent[x]);
  weight[x] += weight[parent[x]];
  return parent[x] = r;
}

bool same(int x, int y) {
  return root(x) == root(y);
}

ll calc_weight(int x) {
  root(x);
  return weight[x];
}

bool merge(int x, int y, ll w = 0) { /// すでに同じグループならfalse
  w += calc_weight(x); w -= calc_weight(y);
  x = root(x); y = root(y);
  if (x == y) return false;
  if (rankb[x] < rankb[y]) swap(x, y), w = -w;
  if (rankb[x] == rankb[y]) rankb[x]++;
  parent[y] = x;
  weight[y] = w;
  return true;
}

ll diff(int x, int y) {
  return calc_weight(x) - calc_weight(y);
}

ll N, M;

int main() {
  cin >> N >> M;

  bool ans = true;

  init(N);
  REP (m, M) {
    int l, r, d;
    cin >> l >> r >> d;
    l--; r--;
    if (same(l, r)) ans &= (diff(r, l) == d);
    else merge(l, r, d);
  }

  cout << (ans?"Yes":"No") << endl;

  return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<set>
#include<vector>
#include<map>
using namespace std;
int n,m,K,tot;
set<int>S[11000];
map<int,int>M[11000];
int dp[11000];
int A[11000],len;
int solve(int now,int l,int r){
	for (int i=l-5;i<=r+5;i++) dp[i]=1e9;
	dp[l-1]=0; dp[l-2]=0;
	for (int i=l;i<=r;i++)
		dp[i]=min(dp[i-1]+M[now-1][A[i]],dp[i-2]+M[now-1][A[i]-1]*2);
	dp[r]=min(dp[r],dp[r-1]+M[now-1][A[r]+1]*2);
	return dp[r];
}
int main(){
	scanf("%d%d%d%d",&m,&n,&K,&tot);
	for (int i=1;i<=tot;i++){
		int x,y; scanf("%d%d",&y,&x);
		M[x][y]=1;
		if (x%2==0&&y%2==1){
			S[x].insert(y); 
			if (y+2<=m) S[x].insert(y+2);
			if (y-2>0) S[x].insert(y-2);
		}
	}
	for (int now=2;now<=n;now+=2){
		M[now][0]=1e8;
		if (m&1) M[now][m+1]=1e8; else M[now][m]=1e8;
	}
	int ans=0;
	for (int now=3;now<=n;now+=2){
		len=0;
		for (set<int>::iterator k=S[now-1].begin();k!=S[now-1].end();k++)
			A[++len]=(*k);
		int pre=1;
		for (int i=2;i<=len+1;i++)
			if (i==len+1||A[i]!=A[i-1]+2)
				ans+=solve(now,pre,i-1),pre=i;
	}
//	cout<<ans<<endl;
	tot=((m+1)/2)*((n+1)/2);
	K=min(K,tot);
	if (K<(m+1)/2){
		printf("-1\n"); return 0;
	}
	tot-=(m+1)/2; K-=(m+1)/2;
	printf("%d\n",tot+max(0,ans-K)-K);
}

Measured memory_bytes: 21692
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define perm(c) sort(ALL(c));for(bool c##p=1;c##p;c##p=next_permutation(ALL(c)))
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (ll)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vector<ll>> vec2;
typedef vector<vector<vector<ll>>> vec3;
ll MOD = 1e9 + 7;
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    ll N, M;
    cin >> N >> M;
    ll ct = 0;
    vec A(N);
    ll sum = 0;
    rep(i, N){
        cin >> A[i];
        sum += A[i];
    }

    rep(i, N){
        if(A[i] * 4 * M < sum) continue;
        else ++ct;
    }

    if(ct >= M) print("Yes");
    else print("No");

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <unordered_map>
using namespace std;

using ll = long long;

ll S[200001];

int main() {
    ll N, K;
    cin >> N >> K;

    S[0] = 0;

    for (ll i = 1; i <= N; ++i) {
        ll a;
        cin >> a;
        S[i] = S[i - 1] + a;
    }

    for (ll i = 1; i <= N; ++i) {
        S[i] = (S[i] - i) % K;
    }

    unordered_map<ll, ll> M;
    ll ans = 0;

    for (ll i = 0; i <= N; ++i) {
        if (i >= K) {
            --M[S[i - K]];

            if (M[S[i - K]] == 0) {
                M.erase(S[i - K]);
            }
        }

        auto itr = M.find(S[i]);
        
        if (itr == M.end()) {
            M[S[i]] = 1;
        }
        else {
            ans += itr->second;
            ++itr->second;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 10056
#include<iostream>
#include<string>
using namespace std;
int main()
{
	string s;
	cin >> s;
	if (s == "Sunny") {
		cout << "Cloudy" << endl;
	}
	else if (s == "Cloudy") {
		cout << "Rainy" << endl;
	}
	else {
		cout << "Sunny" << endl;
	}
	return 0;

}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main(){
  int coin[3],sum;
  for(int i = 0;i < 3;i++)cin >> coin[i];
  cin >> sum;
  int count = 0;
  for(int i = 0;i < coin[0] + 1;i++)
    for(int j = 0;j < coin[1] + 1;j++)
      for(int k = 0;k < coin[2] + 1;k++)if(sum == i * 500 + j * 100 + k * 50)count++;
  cout << count << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main(){
	char s[5001];
	scanf("%s",s);
	int K;
	scanf("%d",&K);
	
	int l=strlen(s);
	int c=0;
	for(int i=0;i<K;i++)c+=l-i;
	
	char sub[c][K+1];
	
	int cc=0;
	for(int i=1;i<=K;i++){
		for(int j=0;j<l-i+1;j++){
			for(int k=0;k<i;k++){
				sub[cc][k]=s[j+k];
				if(k==i-1)for(k;k<K;k++)sub[cc][k+1]='\0';
			}
			cc++;
		}
	}
	
	//sort
	int r=c;
	int swapped=0;
	while(r>1 || swapped==1){
		if(r>1)r=r*10/13;
		swapped=0;
		for(int i=0;i+r<c;i++){
			if(strcmp(sub[i],sub[i+r])>0){
				char tmp[K+1];
				for(int j=0;j<K+1;j++)tmp[j]=sub[i][j];
				for(int j=0;j<K+1;j++)sub[i][j]=sub[i+r][j];
				for(int j=0;j<K+1;j++)sub[i+r][j]=tmp[j];
				swapped=1;
			}
		}
	}
	
	int k=1;
	for(int i=0;i<c;i++){
		if(i>0 && strcmp(sub[i-1],sub[i])!=0)k++;
		if(k==K){
			printf("%s\n",sub[i]);
			return 0;
		}
	}
	
	//for(int i=0;i<c;i++)printf("%s\n",sub[i]);
	
	return 0;
}

Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.*;
import java.util.stream.Stream;

public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		String[] lines = scanner.nextLine().split(" ");
		int N = Integer.parseInt(lines[0]);
		long K = Long.parseLong(lines[1]);

		String[] arrays = scanner.nextLine().split(" ");
		int[] newArray = Stream.of(arrays).mapToInt(Integer::parseInt).toArray();
		ArrayList<Integer> array = new ArrayList<Integer>();
		for (int i = 0; i < newArray.length; i++)
			array.add(newArray[i]);

		long P = 0;
		for (int i = 0; i < array.size() - 1; i++) {
			for (int j = 0; j < array.size(); j++) {
				if (array.get(i) > array.get(j) && i < j)
					P++;
			}
		}

		long Q = 0;
		for (int i = 0; i < array.size(); i++) {
			for (int j = 0; j < array.size(); j++) {
				if (array.get(i) > array.get(j))
					Q++;
			}
		}

		BigInteger b_k = new BigInteger(String.valueOf(K));
		BigInteger b_k_1 = new BigInteger(String.valueOf(K - 1));

		BigInteger b = b_k.multiply(b_k_1).multiply(BigInteger.valueOf(Q)).divide(BigInteger.valueOf(2))
				.add(BigInteger.valueOf(P).multiply(BigInteger.valueOf(K)));
		BigInteger res = b.mod(BigInteger.valueOf(1000000007));

		System.out.println(res);

	}

}


Measured memory_bytes: 29012
#include<iostream>
using namespace std;

int main(){
    int n;
    int min, max;
    long sum = 0;
    cin >> n;
    int i;
    int tmp;
    for(i=0; i<n; i++){
        cin >> tmp;
        if(i == 0){
            min = tmp;
            max = tmp;
        }
        if(min > tmp){
            min = tmp;
        }
        if(max < tmp){
            max = tmp;
        }
        sum += tmp;
    }
    cout << min << " " << max << " " << sum << endl;
}


Measured memory_bytes: 3100
#include <stdio.h>
int main(void){
    int n;
    while(scanf("%d",&n)!=EOF){
        int a,b,c,d;
        int count=0;
        
        for(a=0;a<=9;a++){
            for(b=0;b<=9;b++){
                for(c=0;c<=9;c++){
                    for(d=0;d<=9;d++){
                        if(a+b+c+d==n) count++;
                    }
                }
            }
        }
        printf("%d\n",count);
    }
    return(0);    
}


Measured memory_bytes: 2036
#include<stdio.h>
int main()
{
  int a,b,c;
  int tmp;
  
  scanf("%d %d %d",&a,&b,&c);
  
  if(a<b){
    tmp=a;
    a=b;
    b=tmp;
  }
  if(a<c){
    tmp=a;
    a=c;
    c=tmp;
  }
  if(b<c){
    tmp=b;
    b=c;
    c=tmp;
  }
  
  if(a==b+c) printf("Yes");
  else printf("No");
  
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

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

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int dp[10010][110][2];
signed main() {
    int d; string n; cin >> n >> d;
    int len = n.length();
    memset(dp, 0, sizeof(dp));
    dp[0][0][0] = 1;
    rep(i,0,len) {
        rep(j,0,d) {
            int num = n[i] - '0';
            dp[i+1][(j+num) % d][0] = (dp[i+1][(j+num) % d][0] + dp[i][j][0]) % MOD;
            repq(k,0,9) {
                dp[i+1][(j+k) % d][1] = (dp[i+1][(j+k) % d][1] + dp[i][j][1]) % MOD;
                if(k < num) dp[i+1][(j+k) % d][1] = (dp[i+1][(j+k) % d][1] + dp[i][j][0]) % MOD;
            }
        }
    }
    int ans = (dp[len][0][0] + dp[len][0][1] - 1 + MOD) % MOD;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 17536
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
inline int read(){
	char c=getchar();int t=0,f=1;
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){t=(t<<3)+(t<<1)+(c^48);c=getchar();}
	return t*f;
}
int n,a[maxn],cnt;
struct node{
	int x,y;
}alfa[maxn];
bool cmp(int a,int b){return a>b;}
int main(){
	n=read();
	for(int i=1;i<=n;i++)a[i]=read();
	sort(a+1,a+1+n,cmp);
	if(a[1]<=0){
		int ans=a[1];
		for(int i=2;i<=n;i++){
			alfa[++cnt].x=ans;alfa[cnt].y=a[i];
			ans=ans-a[i];
		}
		printf("%d\n",ans);
		for(int i=1;i<=cnt;i++)
		printf("%d %d\n",alfa[i].x,alfa[i].y);
		return 0;
	}
	if(a[n]>=0){
		int ans=a[1],tmp=a[n];
		for(int i=n-1;i>=2;i--){
			alfa[++cnt].x=tmp;alfa[cnt].y=a[i];
			tmp=tmp-a[i];
		}
		alfa[++cnt].x=ans;alfa[cnt].y=tmp;
		ans=ans-tmp;
		printf("%d\n",ans);
		for(int i=1;i<=cnt;i++)
		printf("%d %d\n",alfa[i].x,alfa[i].y);
		return 0;
	}
	int pos=1;
	for(;pos<=n;pos++)if(a[pos]<0)break;
	pos--;
	int qaq=a[pos+1],ans=a[1];
	for(int i=2;i<=pos;i++){
		alfa[++cnt].x=qaq;alfa[cnt].y=a[i];
		qaq=qaq-a[i];
	}
	for(int i=pos+2;i<=n;i++){
		alfa[++cnt].x=ans;alfa[cnt].y=a[i];
		ans=ans-a[i];
	}
	alfa[++cnt].x=ans;alfa[cnt].y=qaq;
	ans=ans-qaq;
	printf("%d\n",ans);
	for(int i=1;i<=cnt;i++)
	printf("%d %d\n",alfa[i].x,alfa[i].y);
	return 0;
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;

int main()
{
	int n;
	cin >> n;
	if (n == 22)
	{
		cout << "Christmas Eve Eve Eve";
	}
	else if (n == 23)
	{
		cout << "Christmas Eve Eve";
	}
	else if (n == 24)
	{
		cout << "Christmas Eve";
	}
	else if (n == 25)
	{
		cout << "Christmas";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A, B  = [int(i) for i in input().split()]
problems  = [int(i) for i in input().split()]

first_problems = []
second_problems = []
third_problems = []
for problem in problems:
    if problem <= A:
        first_problems.append(problem)
    elif problem <= B:
        second_problems.append(problem)
    else:
        third_problems.append(problem)
        
print(min(len(first_problems), len(second_problems), len(third_problems)))

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include <cstring>
#include <cstdio>
#include <iomanip>
using namespace std;
int n,k;
int a[200005];
int m;
double Max,Sum=0;
int main()
{
	cin>>n>>k;
	Max=0;
	for(int i=1;i<=n;i++){
		cin>>a[i];	
		if(i<=k){
			double temp=a[i]*(a[i]+1)/2.0;
			Sum+=(temp)/a[i]*1.0;		
		}
	}
	Max=Sum;
	m=1;
	for(int i=1;i<=n-k;i++){
		int j=i+k;
		double temp1=a[i]*(a[i]+1)/2.0/a[i];
		double temp2=a[j]*(a[j]+1)/2.0/a[j];
			Sum+=(temp2-temp1);
		if(Sum>Max) Max=Sum;	
	}
//	
//	//cout<<m<<endl;
//	for(int i=m;i<=m+k-1;i++){
//		double temp=a[i]*(a[i]+1)/2.0;
//		Sum+=(temp)/a[i]*1.0;
//		//cout<<temp<<" "<<Sum<<endl;
//	}
	cout<<fixed<<setprecision(12)<<Max<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;

int main() {
	int n, len;
	int t_p=0, h_p=0;
	string t_c, h_c;

	cin >> n;
	for(int i=0; i<n; i++) {
		cin >> t_c >> h_c;

		if(t_c==h_c) {
			t_p++;
			h_p++;
			continue;
		}

		len = (t_c.size()<h_c.size()) ? t_c.size() : h_c.size();
		for(int j=0; j<len; j++) {
			if(t_c[j]==h_c[j]) { 
				if(j==len-1) {
					if(t_c.size()<h_c.size())
						h_p+=3;
					else
						t_p+=3;
				}
				continue;
			}else if((int)t_c[j] > (int)h_c[j]) {
				t_p += 3;
				break;
			}else{
				h_p += 3;
				break;
			}
		}
	}

	cout << t_p << " " << h_p << endl;
	return 0;
}


Measured memory_bytes: 3160
import java.util.*;
	import java.util.Map.Entry;
	 
	 
	 class Main {
		 static int mod =  (int) (Math.pow(10,9)+7);
//		 static int mod =  (int) 998244353;
		 public static void main(String[] args) {
	    	
	        Scanner sc = new Scanner(System.in);
	        int N = sc.nextInt();	
	        long[] a = new long[N];
	        for (int i=0 ; i<N; i++) {
	            a[i] = Long.parseLong(sc.next());
	        }
	        
	        long[] gcd1 = new long[N];
	        long[] gcd2 = new long[N];
	        gcd1[0]=a[0];
	        gcd2[N-1]=a[N-1];
	        
	        for(int i=1;i<N;i++) {
	        	gcd1[i]=GCD(gcd1[i-1],a[i]);
	        }
	        for(int i=N-2;i>=0;i--) {
	        	gcd2[i]=GCD(gcd2[i+1],a[i]);
	        }
	        long ans=0;
	        for(int i=1;i<N-1;i++) {
	        	long tmp = GCD(gcd1[i-1],gcd2[i+1]);
	        	ans=Math.max(ans, tmp);
	        }
	        ans=Math.max(ans, gcd1[N-2]);
	        ans=Math.max(ans, gcd2[1]);
	        
	        System.out.println(ans);
	    }
		  static long GCD(long a,long b) {
			  long tmp;
			  long r;
			  if(a<b) {
				  tmp = a;
				  a = b;
				  b = tmp;				  
			  }
			  
			  r = a % b;
			  while(r!=0) {
				  a=b;
				  b=r;
				  r=a%b;
			  }
			  
			  return b;
		  }
	}

Measured memory_bytes: 47492
#include<iostream>
#include<cmath>
using namespace std;
double a,b,x;
int main(){
	cin >> a >> b >> x;	
	//cout << atan(1.0)/M_PI*180;
	
	if(a*a*b/2>=x){
		double l=2*x/b/a;
		//  tan al = l/b
		double al=90-atan(l/b)/M_PI*180;
		printf("%.10lf",al);
	}
	else{
		double l=2*(a*a*b-x)/a/a;
		double al=atan(l/a)/M_PI*180;
		printf("%.10lf",al);
	}
	return 0;
}


Measured memory_bytes: 256
N = int(input())

def factorize(x):
    results = []
    for i in range(1, x+1):
        if i*i == x:
            results.append(i)
            break
        if i*i > x:
            break
        else:
            if x % i == 0:
                results.append(i)
                results.append(x // i)
    return results

ans = 0
for i in range(1, N+1, 2):
    if len(factorize(i)) == 8:
        ans += 1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<int> A(n);
    bool f = true;
    for(int i = 0; i < n; i++){
        cin >> A[i];
        if(A[i] % 2 == 0){
            if(A[i] % 3 == 0 or A[i] % 5 == 0);
            else f = false;
        }
    }

    if(f) cout << "APPROVED" << endl;
    else cout << "DENIED" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

int main() {
  string t;
  cin >> t;
  int n = t.size();

  string ans(n, ' ');
  for (int i = 0; i < n; ++i) {
    if (t[i] == '?') {
      ans[i] = 'D';
    } else {
      ans[i] = t[i];
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 3816
#include<stdio.h>
 
int main(void)
{
  int K, X;
 
  scanf("%d %d", &K, &X);
 
  if(K < 0 || K > 100 || X < 0 || X > 100000)
  {
    return -1;
  }
  if(500 * K >= X)
  {
    printf("Yes");
  }
  else
  {
    printf("No");
  }
 
  return 0;
}

Measured memory_bytes: 128
// AOJ ALDS1_8_A: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_8_A

package main

import (
	"fmt"
	"bufio"
	"os"
	"strconv"
)

type node struct {
	key                 int
	parent, left, right *node
}

var root *node
var sc = bufio.NewScanner(os.Stdin)

func insert(key int) {
	var y *node
	x := root

	z := &node{key, nil, nil, nil}

	for x != nil {
		y = x
		if z.key < x.key {
			x = x.left
		} else {
			x = x.right
		}
	}

	z.parent = y

	if y == nil {
		root = z
	} else {
		if z.key < y.key {
			y.left = z
		} else {
			y.right = z
		}
	}
}

func find(key int) bool {
	// start root node
	x := root
	for x != nil {
		// find key
		if x.key == key {
			return true
		}

		// move node
		if x.key > key {
			x = x.left
		} else {
			x = x.right
		}
	}
	return false
}

func inorder(u *node, list []int) []int {
	if u != nil {
		list = inorder(u.left, list)
		// fmt.Printf(" %v", u.key)
		list = append(list, u.key)
		list = inorder(u.right, list)
	}
	return list
}

func preorder(u *node, list []int) []int {
	if u != nil {
		// fmt.Printf(" %v", u.key)
		list = append(list, u.key)
		list = preorder(u.left, list)
		list = preorder(u.right, list)
	}
	return list
}

func printList(list []int) {
	buf := bufio.NewWriter(os.Stdout)
	for _, v := range list {
		buf.Write([]byte(fmt.Sprintf(" %d", v)))
	}
	buf.Write([]byte("\n"))
	buf.Flush()
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

func main() {
	var command string
	var n, key int

	fmt.Scanf("%d", &n)

	sc.Split(bufio.ScanWords)
	for i := 0; i < n; i++ {
		command = nextString()
		switch command {
		case "insert":
			key = nextInt()
			insert(key)
		case "find":
			key = nextInt()
			if exist := find(key); exist {
				fmt.Println("yes")
			} else {
				fmt.Println("no")
			}
		case "print":
			printList(inorder(root, []int{}))
			printList(preorder(root, []int{}))
		}
	}
}


Measured memory_bytes: 39312
#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 9, MOD = 998244353;

string s;

int n, cntr, cntg, cntb, r[N], g[N], b[N], pos[N * 3]; 

long long ans = 1, A, B, C; 

inline int min(int x, int y, int z) {
	return std::min(std::min(x, y), z);
}

inline int max(int x, int y, int z) {
	return std::max(std::max(x, y), z);
}

void solve() {
	A = n;
	for (int i = 0; i < n * 3; ++i) {
		if (s[i]== 'R') {
			r[cntr++] = i;
		} else if (s[i] == 'G') {
			g[cntg++] = i;
		} else {
			b[cntb++] = i;
		}
	}
	for (int i = 0; i < n; ++i) {
		pos[min(r[i], g[i], b[i])] = -1;
		pos[max(r[i], g[i], b[i])] = 1;
	} 
	for (int i = 0; i < n * 3; ++i) {
		if (pos[i] == -1) 
			ans = ans * A % MOD, A--, B++;
		else if (pos[i] == 0) 
			ans = ans * B % MOD, B--, C++;
		else 
			ans = ans * C % MOD, C--;
	}
	printf("%lld\n", ans);
}

int main() {
	cin >> n >> s;
	solve();
	return 0;
}

Measured memory_bytes: 2948
#include <bits/stdc++.h>
using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n-1;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define INF 999999999

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef unordered_map<ll, ll> ump;

const ll mod = 1e9+7;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin >> n;
	REP(i, n){
		char s;
		cin >> s;
		if (s=='Y'){
			cout << "Four" << endl; return 0;
		}
	}
	cout << "Three" << endl;
}


Measured memory_bytes: 256
// created_by  Rishi_Mohan

#include<bits/stdc++.h>

#define    ll           long long
#define    db1(x)       cout<<#x<<"="<<x<<'\n'
#define    db2(x,y)     cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define    db3(x,y,z)   cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'

using namespace std;

void solve()
{
    int x , n;
    cin >> x >> n;
    vector<int> v(n);
    for(int i=0;i<n;i++) cin >> v[i];

        int ans1 = INT_MAX;
        int ans2 = INT_MAX;
        for(int i=0;i<=100;i++)
        {
            int a = x-i;
            int b = x+i;
            if(find(v.begin(),v.end(),a)==v.end())
                {ans1 = min(ans1 , x-i);break;}
            if(find(v.begin(),v.end(),b)==v.end())
                {ans2 = min(ans2 , x+i);break;}
        }

    int ans = 0;
    if(n!=0) ans = min(abs(ans1),abs(ans2));
    if(n==0) ans = x;
     // db2(ans1 , ans2);
     cout << ans << endl;

}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
}


Measured memory_bytes: 3656
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	int a, b, c = 0, e;
	cin >> a;
	int test[101] = { 0 };
	for (int h = 1; h <= a; h++) {
		cin >> b;
		test[b] = b;
	}
	for (int j = 1; j < 101; j++) {
		if (test[j] != 0) {
			c++;
		}
	}
	cout << c << endl;
	cin >> e;
}

Measured memory_bytes: 256
N = int(input())
B = [int(_) for _ in input().split()]
ans = [0] * N
ans[0] = B[0]
ans[N - 1] = B[len(B) - 1]

for i in reversed(range(1, N - 1)):
    ans[i] = min(B[i], B[i - 1])

print(sum(ans))

Measured memory_bytes: 3064