akhauriyash/Code-Regression huggingface dataset:
N = int(input())

def nasu(N):
  D = []
  t = N
  while t:
    D = [t % 10] + D
    t //= 10
  return len(D), D[0], D[-1]

L, M, P = nasu(N)
Q = (N - (M * (10 ** (L - 1))) - P) // 10
ans = 0
for i in range(1, N + 1):
  if i % 10 == 0: continue
  l, x, y = nasu(i)
  if x == y and x <= N:
    ans += 1
  if y < M:
    for j in range(L - 1):
      ans += 10 ** j
  elif y > M:
    for j in range(L - 2):
      ans += 10 ** j
  else:
    for j in range(L - 2):
      ans += 10 ** j
    t = y * 10 + x
    if t <= N:
      ans += 1
    if L >= 2:
      if x > P:
        ans += Q - 1
      else:
        ans += Q

print(ans)

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

#define endl "\n"
#define ll long long
#define INF (ll)1e18
#define fill treapdidsu

ll i, i1, j, k, k1, t, n, m, res, check1, a, b, p[250010], dp[510][510], m1, m2, x, y;
ll fill[510][510];

ll d1[4] = {1, 0, -1, 0};
ll d2[4] = {0, 1, 0, -1};

void upd(ll x, ll y) {
    ll i, j, k;
    for (i = 0; i < 4; i++) {
        m1 = x + d1[i]; m2 = y + d2[i];
        k = 1;
        if (fill[x][y] == false) k = 0;
        if (m1 >= 0 && m1 < n && m2 >= 0 && m2 < n) {
            if (dp[m1][m2] > dp[x][y] + k) {
                dp[m1][m2] = dp[x][y] + k;
                upd(m1, m2);
            }
        }
    }
}

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

    //ifstream cin("input.txt");
    //ofstream cout("output.txt");

    cin >> n; t = n * n;
    for (i = 0; i < t; i++) {
        cin >> p[i]; p[i]--;
    }

    for (i = 0; i < n; i++) {
        for (j = 0; j < n; j++) {
            dp[i][j] = min({i, j, n - i - 1, n - j - 1});
            fill[i][j] = true;
            // cout << dp[i][j] << ' ';
        }
        // cout << endl;
    }

    res = 0;
    for (i = 0; i < t; i++) {
        x = p[i] / n; y = p[i] % n;
        res += dp[x][y];
        fill[x][y] = false; upd(x, y);
    }

    cout << res;

    return 0;
}


Measured memory_bytes: 25060
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <vector>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <stack>
#include <utility>
#include <queue>
using namespace std;
typedef long long int lld;
typedef pair<int, int> pii;

const int MAXN = 1002;

int n, m;
int arr[MAXN][MAXN];
int T[MAXN][MAXN];

queue<pii> cola;
void bfs() {
  int t = 1;
  while (!cola.empty()) {
    for (int a = cola.size(); a; --a) {
      int i, j;
      tie(i, j) = cola.front();
      cola.pop();
      if (i < 0 || j < 0 || i >= n || j >= m) continue;
      if (T[i][j] > 0) continue;
      T[i][j] = t;
      cola.push({i,j+1});
      cola.push({i, j-1});
      cola.push({i+1, j});
      cola.push({i-1, j});
    }
    t++;
  }
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      char c; cin >> c;
      arr[i][j] = (c == '#' ? 1 : 0);
      if (arr[i][j] == 1) cola.push({i, j});
    }
  }
  bfs();
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      ans = max(ans, T[i][j]-1);
    }
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 40848
import math
a,b = list(map(int,input().split()))

A = list(range(math.ceil((a / 0.08)),int((a+1)/0.08)))
B = list(range(int((b / 0.1)),int((b+1)/0.1)-1))
price = set(A) & set(B)
if len(price) == 0:
    ans = -1
else:
    ans = min(price)
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define ll long long
#define pi pair<int,int>
#define pl pair<ll,ll>
#define pd pair<double,double>
#define ld long double
#define pld pair<ld,ld>
#define lg length()
#define sz size()
#define pb push_back
#define INF 1000000005
#define LINF 1000000000000000005

int n,m;

ll dp[1005][1005],mod=1e9+7;

char a[1005][1005];

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> n >> m;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin >> a[i][j];
        }
    }
    dp[1][1]=1;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(a[i][j]=='.' && (i!=1 || j!=1)){
                dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
            }
        }
    }
    cout << dp[n][m];
}


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

using namespace std;

vector<long long> x(1000),y(1000),z(1000);
vector<long long> sum[8];
int n,m;

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

	cin >> n >> m;

	for (int i = 0;i < 8;i++){
		sum[i].resize(n);
	}

	for (int i = 0;i < n;i++){
		cin >> x[i] >> y[i] >> z[i];
		sum[0][i] = x[i] + y[i] + z[i];
		sum[1][i] = -x[i] + y[i] + z[i];
		sum[2][i] = x[i] - y[i] + z[i];
		sum[3][i] = x[i] + y[i] - z[i];
		sum[4][i] = -x[i] - y[i] + z[i];
		sum[5][i] = x[i] - y[i] - z[i];
		sum[6][i] = -x[i] + y[i] - z[i];
		sum[7][i] = -x[i] - y[i] - z[i];
	}

	long long ans = 0;
	long long s = 0;

	for (int i = 0;i < 8;i++){
		sort(sum[i].begin(),sum[i].end());
		reverse(sum[i].begin(),sum[i].end());
		for (int j = 0;j < m;j++){
			s += sum[i][j];
		}
		ans = max(ans,s);
		s = 0;
	}

	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 384
n,k=map(int,input().split())
a=list(map(int,input().split()))
result=[1]
temp=1
for i in range(n):
  temp=a[temp-1]
  result.append(temp)
temp=result.index(result[len(result)-1])
c=len(result)-temp-1
if k<n:
  print(result[k])
else:
  print(result[temp+(k-temp)%c])

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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

int n;
int a[100000];

int main() {
    scanf("%d", &n);
    forn(i, n) scanf("%d", a + i);
    int cur = 2;
    LL ans = a[0] - 1;
    for (int i = 1; i < n; ++i) {
        int x = a[i];
        if (x == cur) {
            ++cur;
        } else {
            ans += (x - 1) / cur;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

int main()
{
	std::string s, t;

	std::cin >> s >> t;

	std::vector<int> shist;
	std::vector<int> thist;

	shist.resize(256);
	thist.resize(256);
	for (auto ch : s)
		++shist[(unsigned char)ch];
	for (auto ch : t)
		++thist[(unsigned char)ch];

	for (int i = 0; i < 256; ++i) {
		if (thist[i] != 0 && shist[i] == 0) {
			std::cout << "-1\n";
			return 0;
		}
	}

	static int nextstep[256][100000] = {};
	int lastpos[256];
	for (auto& p : lastpos)
		p = -1;
	for (auto& a : nextstep) {
		for (auto& b : a) {
			b = -1;
		}
	}

	for (int i = s.size()-1; i >= 0; --i) {
		for (int j = 'a'; j <= 'z'; ++j) {
			if (lastpos[j] != -1)
				nextstep[j][i] = (s.size() + lastpos[j] - i) % s.size();
		}
		lastpos[(unsigned char)s[i]] = i;
	}
	for (int i = s.size()-1; i >= 0; --i) {
		for (int j = 'a'; j <= 'z'; ++j) {
			if (nextstep[j][i] == -1) {
				if (lastpos[j] != i)
					nextstep[j][i] = (s.size() + lastpos[j] - i) % s.size();
				else
					nextstep[j][i] = s.size();
			}
		}
	}

#if 0
for (int i = 0; i < s.size(); ++i) {
	for (int j = 'a'; j <= 'z'; ++j) {
		std::cout << nextstep[j][i] << " ";
	}
	std::cout << "\n";
}
#endif

	long pos = s.size()-1;
	for (int i = 0; i < t.size(); ++i) {
//std::cout << nextstep[t[i]][pos%s.size()] << "\n";
		pos += nextstep[t[i]][pos%s.size()];
//std::cout << ":" << pos << "\n";
	}
	std::cout << (pos-s.size()+1) << "\n";
}


Measured memory_bytes: 100608
N = int(input())
W_list = [input() for _ in range(N)]
mae = W_list[0]
flg = "Yes"
for w in W_list[1:]:
    if mae[-1]==w[0]:
        mae = w
    else:
        flg = "No"
W_set = set(W_list)
if len(W_list)!=len(W_set):
    flg = "No"

print(flg)


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

#define rep(i,N) for(int (i)=0;(i)<(N);(i)++)
#define repi(i,j,N) for(int (i)=(j);(i)<(N);(i)++)
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define ll long long
#define numberofdigits(x) floor(log10(x)) + 1


typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;

const char nl = '\n';

int a[100000][3], dp[100000][3];


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n;
	cin >> n;
	for(int i=0; i<n; ++i)
		for(int j=0; j<3; ++j)
			cin >> a[i][j];
	for(int j=0; j<3; ++j)
		dp[0][j]=a[0][j];
	for(int i=1; i<n; ++i) {
		for(int j=0; j<3; ++j) {
			int mx=0;
			for(int k=0; k<3; ++k)
				if(k!=j)
					mx=max(dp[i-1][k], mx);
			dp[i][j]=mx+a[i][j];
		}
	}
	cout << max({dp[n-1][0], dp[n-1][1], dp[n-1][2]});

    return 0;
}


Measured memory_bytes: 5908
class Robot
  attr_accessor :position
  def initialize(position)
    @position = position
  end
  def move(dir, length)
    if dir == "N"
      @position[:y] += length
    elsif dir == "E"
      @position[:x] += length
    elsif dir == "S"
      @position[:y] -= length
    elsif dir == "W"
      @position[:x] -= length
    end
    return @position
  end
end
def delete_cross_gem(start_pos, end_pos, gems)
  if start_pos[:x] == end_pos[:x]
    gem_on_x = gems.select{|item| item[:x] == start_pos[:x]}
    min = start_pos[:y] < end_pos[:y] ? start_pos[:y] : end_pos[:y]
    max = start_pos[:y] >= end_pos[:y] ? start_pos[:y] : end_pos[:y]
    delete_gems = gem_on_x.select{|item| (item[:y] <= max && item[:y] >= min)}
  else
    gem_on_y = gems.select{|item| item[:y] == start_pos[:y]}
    min = start_pos[:x] < end_pos[:x] ? start_pos[:x] : end_pos[:x]
    max = start_pos[:x] >= end_pos[:x] ? start_pos[:x] : end_pos[:x]
    delete_gems = gem_on_y.select{|item| (item[:x] <= max && item[:x] >= min)}
  end
  delete_gems.each do |g|
    gems.delete(g)
  end
end

loop do
  gems = []
  gem_size = gets.chomp.to_i
  if gem_size == 0
    break
  end
  gem_size.times do
    g = {}
    g[:x], g[:y] = gets.chomp.split(" ").map{|item| item.to_i}
    gems.push(g)
  end
  robot = Robot.new({x: 10,y: 10})
  op_size = gets.chomp.to_i
  op_size.times do
    op_dir, op_length_str = gets.chomp.split(" ")
    op_length = op_length_str.to_i
    current_pos = robot.position.dup
    delete_cross_gem(current_pos, robot.move(op_dir, op_length), gems)
  end
  if gems.empty?
    puts "Yes"
  else
    puts "No"
  end
end


Measured memory_bytes: 6920
#include<iostream>

int main() {
	int a,b;
	std::cin >> a>>b;

	if (5<a && a< 13) {
		b = b/2;
		std::cout << b << std::endl;
		return 0;
	}

	if (a < 6) {
		b = 0;
		std::cout << b << std::endl;
		return 0;
	}

	


	std::cout << b << std::endl;
	return 0;
}

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

int main() {
	long long unsigned a[1000] = { 0 }, ans = 1;
	int n; cin >> n;
	for (int i = 2, k = i; i <= n; k = ++i) {
		for (int j = 2; j <= k; j++) {
			while (k % j == 0) {
				a[j]++; k /= j;
			}
		}
	}
	for (int i = 2; i <= n; i++)ans = ans * (a[i] + 1) % ((int)1e9 + 7);
	cout << ans << endl;
	return 0;
}

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

const ll N=1E5+7;
const ll INF =1e9+7;

ll l[N],r[N];
struct stu{
    ll a,b;
    bool friend operator < (const stu &x,const stu &y) {
        return x.a>y.a;
    }
}s[N];
ll arr[N];
int main(){
    ll n;
    cin>>n;
    for(ll i=1;i<=n;i++) cin>>l[i]>>r[i];
    ll ans1=0;
    ll maxlen=0;
    ll minnr=INF,p;
    ll maxxl=0,q;

    for(ll i=1;i<=n;i++){
        if(l[i]>maxxl) {
            maxxl=l[i];
            p=i;
        }
        if(r[i]<minnr){
            minnr=r[i];
            q=i;
        }
        maxlen=max(maxlen,r[i]-l[i]+1);
    }
    ans1+=maxlen;
    if(minnr>maxxl) ans1+=minnr-maxxl+1;
    for(ll i=1;i<=n;i++){
        s[i].a=max(r[i]-maxxl+1,(ll)0);
        s[i].b=max(minnr-l[i]+1,(ll)0);
    }
    sort(s+1,s+1+n);
    arr[n+1]=INF;
    for(ll i=n;i>=1;i--)  arr[i]=min(arr[i+1],s[i].b);
    ll ans2=0;
    for(ll i=1;i<n;i++) {
        ans2=max(ans2,s[i].a+arr[i+1]);
    }
//    cout<<ans2<<"   "<<ans1<<endl;
    cout<<max(ans2,ans1)<<endl;
    return 0;
}


Measured memory_bytes: 4096
from collections import deque

n,k = map(int,input().split())
s = list(map(int,input().split()))
score = {"r":s[0], "s":s[1],"p":s[2], "n":0}
stronger = {"r":"p", "s":"r","p":"s"}
rsp = input()


d = deque()
[d.append("n") for i in range(k)]

ans = 0
for i in range(n):
    bk = d.popleft()
    st = stronger[rsp[i]]
    if st  != bk:
        ans += score[st]
        d.append(st)
    else:
        d.append("n")

print(ans)

Measured memory_bytes: 4852
#include<iostream>
using namespace std;
int main() {
	string S;
	cin >> S;
	int ans = 0;
	if (S.length() % 2 == 0) {
		for (int i = 0; i < S.length() / 2; i++) {
			if (S[2 * i] == 'L') {
				ans++;
				break;
			}
			if (S[2 * i + 1] == 'R') {
				ans++;
				break;
			}
		}
	}
	else {
		S[S.length()] = 'D';
		for (int i = 0; i < S.length() / 2 + 1; i++) {
			if (S[2 * i] == 'L') {
				ans++;
				break;
			}
			if (S[2 * i + 1] == 'R') {
				ans++;
				break;
			}
		}
	}
	if (ans != 0) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
  int m, n;
  vector<int> a;
  long sum = 0;
  
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int v;
    cin >> v;
    a.push_back(v);
    sum += a[i];
  }

  sort(a.rbegin(), a.rend());
  bool flag = false;
  for (int i = 0; i < m; i++) {
    if (a[i] * 4 * m >= sum) {
    } else {
      flag = true;
      break;
    }
  }
  if (!flag) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

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

using ll=long long;
#define int ll

#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#ifdef LOCAL
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif

template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

template<class t,class u>
ostream& operator<<(ostream& os,const pair<t,u>& p){
	return os<<"{"<<p.a<<","<<p.b<<"}";
}

template<class t> ostream& operator<<(ostream& os,const vc<t>& v){
	os<<"{";
	for(auto e:v)os<<e<<",";
	return os<<"}";
}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout<<fixed<<setprecision(20);
	
	int n;cin>>n;
	
	const int inf=LLONG_MAX/3;
	
	int cur=0,a=0,v[2]{};
	rep(_,n+1){
		int b=0;
		if(_<n)cin>>b;
		
		int p[2]{0,b-a};
		if(p[0]<p[1])swap(p[0],p[1]);
		
		int nx[3]{inf,inf,0};
		rep(i,2)rep(j,2)
			chmin(nx[i+j],max(v[i]+p[j],int(0)));
		
		int d=nx[0]>b;
		rep(i,2)
			v[i]=nx[i+d];
		
		assert(v[0]<=b);
		assert(v[1]<=v[0]);
		
		cur+=d;
		
		a=b;
	}
	
	cout<<cur<<endl;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for(ll i = m; i < (n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>; 
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>;

int main() {
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    
    ll ans = -10e18 - 10;
    ans = max(ans, a*c);
    ans = max(ans, a*d);
    ans = max(ans, b*c);
    ans = max(ans, b*d);
    cout << ans;
}


Measured memory_bytes: 3632
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
int main()
{
	ll dp[35]={0};
	dp[1]=1ll,dp[2]=2ll,dp[3]=4ll;
	for(int i=4;i<33;i++)
	{
		dp[i]=dp[i-1]+dp[i-2]+dp[i-3];
	}
	int n;
	while(1)
	{
		cin >> n;
		if(n==0)break;
		ll day=dp[n]/10+(dp[n]%10!=0);
		ll year=day/365+(day%365!=0);
		cout << year << endl;
	}
	return 0;
}

Measured memory_bytes: 1156
use proconio::input;
use proconio::marker::{Bytes, Chars, Isize1, Usize1};

fn main() {
    input! {
        n: usize,
        edges: [(usize, usize); n],
    }

    let ans = {
        let mut ans = false;
        for i in 0..n-2 {
            if edges[i].0 == edges[i].1 && edges[i+1].0 == edges[i+1].1 && edges[i+2].0 == edges[i+2].1 {
                ans = true;
            }
        }
        ans
    };

    if ans {
        println!("Yes")
    } else {
        println!("No")
    }

}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define mem(a) memset(a,0,sizeof(a))
#define rep(i) for(int (i)=1;(i)<=n;(i)++)

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int mn=1e5+5;

int n;

char s[mn];
int a[mn];
bool vis[mn];
int b[mn];

vector<int> g[mn];

void eraseblack(int x,int fa){
     bool iserase=1;
     if (a[x]==1) iserase=0;
     for(auto &i:g[x]){
		if (i==fa) continue;
		eraseblack(i,x);
		if (vis[i]) iserase=0;
     }
     vis[x]=!iserase;
}

int ans=0;
int tans=0;

int d[mn],dc[mn];
int d2[mn],dc2[mn];//without leaf


void dp(int x,int fa){
	vector<pii> vans,vans2;
	if (sz(g[x])==1) d[x]=b[x]*2;
    for(auto &i:g[x]){
		if (i==fa) continue;
        dp(i,x);
        vans.pb(pii(d[i],dc[i]));
        vans2.pb(pii(d2[i],dc2[i]));
    }
    sort(vans.begin(),vans.end());
    sort(vans2.begin(),vans2.end());
    if (vans.size()>1){
		int rans=0;
		if (vans.back().second==vans2.back().second){
			rans=max(vans.back().first+vans2[sz(vans2)-2].first,vans2.back().first+vans[sz(vans)-2].first);
			//printf("maybe ans:%d %d %d %d\n",vans.back().first,vans[sz(vans)-2].first,vans2.back().first,vans2[sz(vans2)-2].first);
		}
		else rans=vans.back().first+vans2.back().first;
		//printf("%d %d\n",vans.back().first,vans2.back().first);
		rans+=b[x]*2;
		//printf("new ans:%d %d\n",x,rans);
		ans=min(ans,tans-rans);
    }
    dc[x]=dc2[x]=x;
    if (vans.size()>=1){
		d[x]=vans.back().first+(b[x]*2);
		d2[x]=vans2.back().first+(b[x]*2);
    }

    //printf("%d %d %d %d %d %d %d %d\n",x,a[x],b[x],d[x],dc[x],d2[x],dc2[x],sz(vans));
}

int main() {
    scanf("%d",&n);
    for(int i=1;i<n;i++){
		int u,v;
        scanf("%d%d",&u,&v);
        g[u].pb(v);
        g[v].pb(u);
    }
    scanf("%s",s+1);
    int choose=1;
    for(int i=1;i<=n;i++) {
		a[i]=(s[i]=='W');
		if (a[i]==1) choose=i;
    }
    eraseblack(choose,0);
    for(int i=1;i<=n;i++){
		if (!vis[i]) continue;
        vector<int> u;
        for(auto &j:g[i]) if (vis[j]) u.pb(j);
		swap(u,g[i]);
    }

    for(int i=1;i<=n;i++) if (vis[i]) b[i]=(sz(g[i])+a[i])%2,ans+=b[i]+sz(g[i]);
    tans=ans;
    //printf("%d\n",tans);
    for(int i=1;i<=n;i++) if (vis[i]&&sz(g[i])>=2) choose=i;
    dp(choose,0);
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 22016
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main implements Runnable {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        // Run with 32MB stack
        Thread thread = new Thread(null, new Main(), "", 32 * 1024 * 1024);
        thread.start();
    }

    @Override
    public void run() {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static void solve(Scanner scanner) {
        String s = scanner.nextLine();
        int ans = Arrays.stream(s.replaceAll("[^ACGT]", "-").split("-")).mapToInt(String::length).max().orElse(0);
        System.out.println(ans);
    }

}

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

int	main(void)
{
	int n;
	cin >> n;
	vector<string> s(n);
	for (int i = 0; i < n; i++) cin >> s[i];
	vector<pair<int, int>> positive;
	vector<pair<int, int>> negative;
	int left_cnt = 0;
	int right_cnt = 0;
	for (int i = 0; i < n; i++)
	{
		int left = 0;
		int right = 0;
		for (int j = 0; j < s[i].size(); j++)
		{
			if (s[i][j] == '(') left++;
			else
			{
				if (left > 0) left--;
				else right++;
			}
		}
		if (left == 0 && right == 0) continue;
		if (left == 0) right_cnt += right;
		else if (right == 0) left_cnt += left;
		else if (left >= right) positive.push_back({right, left});
		else negative.push_back({left, right});
	}
	sort(positive.begin(), positive.end());
	sort(negative.begin(), negative.end(), greater<pair<int, int>>());
	for (int i = 0; i < positive.size(); i++)
	{
		left_cnt -= positive[i].first;
		if (left_cnt < 0)
		{
			cout << "No" << endl;
			return (0);
		}
		left_cnt += positive[i].second;
	}
	for (int i = 0; i < negative.size(); i++)
	{
		left_cnt -= negative[i].second;
		if (left_cnt < 0)
		{
			cout << "No" << endl;
			return (0);
		}
		left_cnt += negative[i].first;
	}
	if (left_cnt != right_cnt) cout << "No" << endl;
	else cout << "Yes" << endl;
	return (0);
}

Measured memory_bytes: 34288
#include <stdio.h>
#include <iostream>
#include <queue>
#include <cstdio>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string.h>
#include <limits.h>
#include <map>
#include <string>
#include <bitset>
#include <vector>
using namespace std;
int ans[20000],p[1005],can[1005];
int main() {
    int n,m,a,b;
    cin>>n>>m;
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d",&a,&b);
        p[i]=a;
        int t;
        for(int j=0;j<b;j++)
        {
            scanf("%d",&t);
            can[i]+=pow(2,t-1);
        }
    }
    for(int i=0;i<pow(2,n);i++) ans[i]=INT_MAX;
    ans[0]=0;
    for(int i=1;i<=m;i++)
        for(int j=0;j<pow(2,n);j++) {
            if (ans[j] == INT_MAX) continue;
            ans[j | can[i]] = min(ans[j | can[i]], ans[j] + p[i]);
        }
    if(ans[int(pow(2,n))-1]==INT_MAX) printf("-1\n");
    else printf("%d\n",ans[int(pow(2,n))-1]);
}


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

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 1e5+5;
const int M = 5e6+5;
const int INF = 1e9;

int n;
vector<int> pt[N];

int st,ed;
struct edge{
	int x,f,nxt;
}e[M];
int h[N*2],tot;

void addedge(int x,int y,int f){e[++tot].x=y;e[tot].f=f;e[tot].nxt=h[x];h[x]=tot;}

void inse(int x,int y,int f){
	addedge(x,y,f);
	addedge(y,x,0);
}

int dis[N*2],que[N*2];
int vt[N*2],tim;
int cur[N*2];

bool bfs(){
	tim++;
	int he=0,ta=1;
	dis[que[1]=st]=0;
	vt[st]=tim;
	for(;he<ta;){
		int x=que[++he];
		for(int p=h[x];p;p=e[p].nxt){
			int y=e[p].x;
			if (vt[y]<tim&&e[p].f){
				vt[y]=tim;
				dis[y]=dis[x]+1;
				que[++ta]=y;
			}
		}
	}
	return vt[ed]==tim;
}

int aug(int x,int f){
	if (x==ed)return f;
	int ret=0;
	for(int &p=cur[x];p;p=e[p].nxt)
	if (e[p].f&&vt[e[p].x]==tim&&dis[e[p].x]==dis[x]+1){
		int o=aug(e[p].x,min(f,e[p].f));
		f-=o,ret+=o;
		e[p].f-=o,e[p^1].f+=o;
		if (!f)return ret;
	}
	return ret;
}

int to[N];
pair<int,int>ans[N];
int k;
bool vis[N*2];

void dfs(int x){
	vis[x]=1;
	for(auto u:pt[x])
	if (!vis[u]){
		vis[u]=1;
		k++;
		ans[u-n]=make_pair(x,to[u]);
		dfs(to[u]);
	}
}

int main(){
	n=get();
	tot=1;
	st=n*2,ed=n*2+1;
	fo(i,1,n-1){
		int k=get();
		inse(st,n+i,1);
		fo(j,1,k){
			int x=get();
			if (x>1)inse(n+i,x,1);
			pt[x].push_back(n+i);
		}
	}
	fo(i,1,n)inse(i,ed,1);
	int ret=0;
	while(bfs()){
		fo(i,0,n*2+1)cur[i]=h[i];
		int tmp=aug(st,INF);
		while(tmp){
			ret+=tmp;
			tmp=aug(st,INF);
		}
	}
	if (ret!=n-1)return printf("-1\n"),0;
	fo(i,n+1,n*2-1){
		for(int p=h[i];p;p=e[p].nxt)
		if (!e[p].f&&e[p].x>1&&e[p].x<=n){
			to[i]=e[p].x;
			break;
		}
	}
	dfs(1);
	if (k<n-1)return printf("-1\n"),0;
	fo(i,1,k)printf("%d %d\n",ans[i].first,ans[i].second);
	return 0;
}

Measured memory_bytes: 24960
#include <iostream>

using namespace std;

int main() {
    int k, x; cin >> k >> x;
    int start = x - k + 1, end = x + k - 1;
    for (int i = start; i <= end; ++i) {
        cout << i;
        if (i != end) {
            cout << " ";
        }
    }
    cout << endl;
}

Measured memory_bytes: 3176
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
#include <bitset>
#include <stack>
//#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)

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

int main(void)
{
    int N;
    string s, t;
    cin >> N >> s >> t;
    int cnt = 0;
    if (s == t)
    {
        cout << N << endl;
        return 0;
    }
    else
    {
        int tmp = 0;
        int k = 0;
        for (int i = N; i < 2 * N; i++)
        {
            k = 0;
            for (int j = i - N; j < N; j++)
            {
                if (s[j] == t[k])
                {
                    tmp++;
                    k++;
                }
                else
                {
                    tmp = 0;

                    break;
                }
                cnt = max(cnt, tmp);
            }
        }
        cout << 2 * N - cnt << endl;
    }
    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <string>
using namespace std;
string s,t;
int b,a=0;
int main(){
	cin>>s>>t;
	for(int i=0;i<s.size();i++){
		b=1;
		for(int j=0;j<s.size();j++) b&=s[(i+j)%s.size()]==t[j];
		a|=b;
	}
	cout<<(a?"Yes\n":"No\n");
}


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

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

using namespace std;

int main() {
  int n, m;
  std::cin >> n >> m;
  std::vector<int64_t> a(n), b(n), c(m), d(m);
  rep(i, n) std::cin >> a[i] >> b[i];
  rep(i, m) std::cin >> c[i] >> d[i];

  std::vector<int> v(n);

  rep(i, n) {
    int64_t minv = 1000000000;
    rep(j, m) {
      uint64_t tmp = abs(a[i] - c[j]) + abs(b[i] - d[j]);
      if (minv > tmp) {
        minv = tmp;
        v[i] = j + 1;
      }
    }
  }

  rep(i, n) { std::cout << v[i] << std::endl; }
  return 0;
}


Measured memory_bytes: 3636
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;

int n;

int main()
{
	scanf("%d",&n);
	for(register int i=1;i<=9;++i)
	{
		int x=i*100+i*10+i;
		if(x>=n)
		{
			printf("%d",x);
			return 0;
		}
	}
}


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

#define all(s) s.begin(), s.end()
#define vi vector<int>
#define pb push_back
#define ii pair<int, int>
#define x first
#define y second

bool res[1005][1005];

int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int h, w, a, b;
    cin >> h >> w >> a >> b;
    vector<ii> ac;
    for (int x = 0; x <= h; x++) {
        for (int y = 0; y <= w; y++)
            if (x * a + (h - x) * (w - a) == y * b + (w - y) * (h - b)) {
                ac.pb({x, y});
            }
    }
    if (ac.size() == 0) return cout << -1, 0;
    for (auto u : ac) {
        priority_queue<ii> pq;
        int x = u.x;
        int y = u.y;
        for (int i = 1; i <= y; i++) {
            pq.push({b, i});
        }
        for (int i = y + 1; i <= w; i++) {
            pq.push({h - b, i});
        }
        bool flag = 1;
        for (int i = 1; i <= x; i++) {
            if (!flag) break;
            for (int j = 1; j <= a; j++) {
                auto p = pq.top();
                pq.pop();
                res[i][p.y] = 1;
                p.x--;
                if (p.x < 0) flag = 0;
                pq.push(p);
            }
        }
        for (int i = x + 1; i <= h; i++) {
            if (!flag) break;
            for (int j = 1; j <= w - a; j++) {
                auto p = pq.top();
                pq.pop();
                res[i][p.y] = 1;
                p.x--;
                if (p.x < 0) flag = 0;
                pq.push(p);
            }
        }
        if (!flag) {
            for (int i = 1; i <= w; i++) {
                for (int j = 1; j <= h; j++) {
                    res[j][i] = 0;
                }
            }
        } else {
            for (int i = 1; i <= h; i++) {
                for (int j = 1; j <= w; j++) {
                    cout << res[i][j];
                }
                cout << '\n';
            }
            return 0;
        }
    }
    cout << -1;
    return 0;
}

Measured memory_bytes: 2304
//============================================================================
// Name        : AOJCpp.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
static const int MAX = 100000;
class process {
private:
	string name;
	int time;
public:
	void setName(string s);
	void setTime(int t);
	string getName();
	int getTime();
};
void process::setName(string s) {
	name = s;
}
void process::setTime(int i) {
	time = i;
}
string process::getName() {
	return name;
}
int process::getTime() {
	return time;
}
int main() {

	int n,q;
	cin >> n >> q;

	queue<process> que;
	queue<process> done;
	string name;
	int time;
	for(int i = 0; i < n; i++) {
		cin >> name;
		cin >> time;
		process p;
		p.setName(name);
		p.setTime(time);
		que.push(p);
	}
	int total = 0;
	while(!que.empty()) {
		process p = que.front();
		que.pop();
		time = p.getTime();
		if(time > q) {
			p.setTime(time - q);
			total += q;
			que.push(p);
		} else {
			total+=time;
			p.setTime(total);
			done.push(p);
		}
	}
	for(int i = 0; i < n; i++) {
		process d = done.front();
		done.pop();
		cout << d.getName() << " " << d.getTime() << endl;
	}
}




Measured memory_bytes: 6232
#include <iostream>
#include <string>

using namespace std;

int n;
int h[100005];

int main(void)
{
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> h[i];
	
	int ans = 0, cnt = 0;
	h[0] = 2e9;
	for(int i = 1; i <= n; i++){
		if(h[i-1] >= h[i]) cnt++;
		else cnt = 1;
		ans = max(ans, cnt);
	}
	cout << ans-1 << endl;

	return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
int a[4], e;
bool c;
void dfs(string s, int n, int score)
{
    if (n == 4)
    {
        if (score == 7)
        {
            cout << s << "=7"
                 << "\n";
            c = true;
        }
        return;
    }
    int temp = a[n];
    dfs(s + "+" + to_string(temp), n + 1, score + a[n]);
    if (c)
        return;
    dfs(s + "-" + to_string(temp), n + 1, score - a[n]);
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> e;
    a[3] = e % 10;
    e /= 10;
    a[2] = e % 10;
    e /= 10;
    a[1] = e % 10;
    e /= 10;
    a[0] = e % 10;
    e /= 10;
    c = false;
    int temp = a[0];
    dfs(to_string(temp), 1, a[0]);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <tuple>
#include <map>
typedef long long ll;
using namespace std;
#define rep(i,n) for (int i = 0; i <= int(n); i++)
#define mod 1000000007

int main() {
	string s, t;
	cin >> s >> t;
	sort(s.begin(), s.end());
	sort(t.begin(), t.end());
	reverse(t.begin(), t.end());
	if (s < t) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

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

typedef long long ll;

ll N,X;

ll getP( ll A, ll B ){
  if( A > B ) swap( A, B );
  if( !A ) return -B;
  return ( B / A ) * 2LL * A + getP( A, B%A );
}

int main(){
  cin >> N >> X;
  ll ret;
  if( N == 2LL*X ){
    ret =  3LL * X;
  } else 
    ret = N + getP( N-X, X );
  cout << ret << endl;
}


Measured memory_bytes: 256
s = list(input())
t = list(input())
cnt = len(t)
diff = cnt

for i in range(len(s)):
    for j in range(len(t)):
        if len(s) <= i+j:
            cnt = len(t)
            break
        elif s[i+j] == t[j]:
            cnt -= 1
    if cnt < diff:
        diff = cnt
    cnt = len(t)
print(diff)

Measured memory_bytes: 8944
///mAAria...
#include<bits/stdc++.h>
 
using namespace std;
 
#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) v.begin(),v.end()
#define ld long double
#define ff first
#define ss second
#define pii pair<int,int>
#define pi 3.1415926535897932384626433832
#define mod 1000000007
#define inf 1000000000

const long double PI = acos(-1);

int powm(int a, int b) {
    int res=1;
    while(b) {
        if(b&1)
            res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}

int a[200005], b[200005];

void solve(){
   int n;
   cin >> n;
   int m = 0;
   for(int i = 1;i<=n;i++)cin >> a[i];

    for(int i = n;i>0;i--){
        int cnt = 0;

        for(int j = i+i; j<=n; j+=i){
            cnt+=b[j];
        }

        if(cnt%2!=a[i]){
            b[i] = 1;
            m++;
        }

    }

    cout << m << endl;
    
    for(int i = 1;i<=n;i++){
        if(b[i])cout << i << " ";
    }

    cout << endl;

} 

signed main() 
{   
    IOS;
    int t = 1;
    //cin >> t;

    for(int i = 1;i<=t;i++){
        solve();
    }
    return 0;
} 

 


Measured memory_bytes: 3968
let input = require('fs').readFileSync('/dev/stdin', 'utf8');
input = input.split(/\s/);

const N = Number(input[0]);
const T = Number(input[1]);
const A = Number(input[2]);
const H = input.slice(3, 3 + N).map(Number);

const l = [];

for (let i = 0; i < H.length; i++) {
  l.push([i + 1, Math.abs(T - H[i] * 0.006 - A)]);
}

l.sort((a, b) => a[1] - b[1]);

console.log(l[0][0]);


Measured memory_bytes: 9796
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = (a); i < (b); ++i)
#define rrep(i,a,b) for(int i = (b); i --> (a);)
#define all(v) (v).begin(),(v).end()
#define trav(x,v) for(auto &x : v)
#define sz(v) int(v.size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;

int main(){
	cin.sync_with_stdio(0);
	cin.tie(0);
	
	int n, k;
	cin >> n >> k;

	vector<string> xs(n+1);
	trav(x, xs) cin >> x;

	vector<vector<vi>> cnt(2, vector<vi>(n+1)); 
	rep(t,0,2) rep(i,0,n+1){
		cnt[t][i].resize(1<<i);
		rep(j,0,1<<i) cnt[t][i][j] = xs[i][j]-'0';
	}
	rep(l,0,n){
		int t = l%2, u = 1-t;

		rep(i,l,n+1) cnt[u][i].assign(1<<i,0);

		rep(m,l,n+1) rep(j,0,1<<m){
			cnt[u][l][j>>(m-l)] += cnt[t][m][j];	
		}
		
		rep(m,l+1,n+1) rep(j,0,1<<m){
			int jj = j & ((1<<(m-l))-1);
			int jjc = (~j) & ((1<<(m-l))-1);
			int zz = 31 - __builtin_clz(jjc),
			    oo = 31 - __builtin_clz(jj);

			if(jjc){
				cnt[u][l+1+zz][((j>>(m-l))<<(zz+1))|(j&((1<<zz)-1))]
					+= cnt[t][m][j];
				
			}
			if(jj){
				cnt[u][l+1+oo][((j>>(m-l))<<(oo+1))|(1<<oo)|(j&((1<<oo)-1))]
					+= cnt[t][m][j];
			}
		}

	}
	rrep(i,0,n+1){
		rep(j,0,1<<i) if(cnt[(i+1)%2][i][j] >= k){
			rrep(k,0,i) cout << ((j&(1<<k))>>k);
			cout << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 20828
#include <stdio.h>

int main(void)
{
	int i;
	int j;
	
	for (i = 1; i <= 9; i++){
		for ( j = 1; j <= 9; j++){
			printf("%dx%d=%d\n", i, j, i * j);
		}
	}
	
	return (0);
}

Measured memory_bytes: 520
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;

int main(){
  ios_base::sync_with_stdio(false);

  int a, b, c, d;

  cin >> a >> b >> c >> d;

  if(abs(a - c) <= d){
    cout << "Yes" << endl;
  } else if(abs(a - b) <= d && abs(b - c) <= d){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
int main(){
	
	int N;
	int a=0;
	scanf("%d", &N);
	
	for (int i=1; i<=N; i++){
	
	if(i==N){
		a++;
	}
    else if(i%2==0){
    	a++;
	}
}  
printf("%d",a);
return 0 ;
}

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

using namespace std;

int main(void) {
  int a, b;
  int ans;
  
  cin >> a >> b;
  if (a > 9 || b > 9) {
    ans = -1;
  } else {
    ans = a * b;
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
sx, sy, tx, ty = STDIN.gets.chomp.split(' ')
sx = sx.to_i
sy = sy.to_i
tx = tx.to_i
ty = ty.to_i

puts('U' * (ty-sy) + 'R' * (tx-sx) +
     'D' * (ty-sy) + 'L' * (tx-sx) +
     'L' + 'U' * (ty-sy+1) + 'R' * (tx-sx+1) + 'D' +
     'R' + 'D' * (ty-sy+1) + 'L' * (tx-sx+1) + 'U')

Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
#define END '\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define trace(x) cerr<<x<<END;
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, b, a) for(int i = (b); i > (a); --i) 
const int mod = 1e9+7;
const int mod1 = 998244353;
const int inf = 1e18;
const int nax = 200005;
int a[nax],n,k;
void solve()
 {
  cin>>n>>k;
  loop(i,0,n)
   cin>>a[i];
  int lo = 0,hi = 0;
  double sum = 0,ans = 0;
  loop(i,0,k)
   sum += 1.0*(a[i]+1)/2;
  ans = sum;
  hi = k -1;
  loop(i,k,n)
   {
	   sum -= 1.0*(a[lo]+1)/2;
	   lo++;
	   sum += 1.0*(a[i]+1)/2;
	   hi++;
	   if(hi - lo + 1 == k)
	    ans = max(ans,sum);
   }
  cout<<fixed<<setprecision(10);
  cout<<ans;
   
  
 }  
signed main()
 {   
  ios_base::sync_with_stdio(false);
  cin.tie(0); 
  cout.tie(0); 
   /*int t;
   cin>>t;
   loop(i,1,t+1)*/
      solve();
      
  //cerr<<END<<1.0*clock();
  return 0;
} 


Measured memory_bytes: 5316
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
#define forn(i,n) for(ll i=0;i < ll (n); i++)

int main()
{
    string s,t, tem;
    cin>>s>>t;
    ll cnt=10e10;
    forn(i,s.size())
    {
        ll tm=0;
        if(i+t.size()>s.size()) break;
        forn(j,t.size())
        {
            if(s[i+j]!=t[j]) tm++;
        }
        cnt=min(tm,cnt);
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int A, B, C, K; cin >> A >> B >> C >> K;
    int cnt = 0;
    int max = A;
    if(max < B)
    {
        max = B;
        cnt = 1;
    }
    if(max < C)
    {
        max = C;
        cnt = 2;
    }
    for(int i = 0; i < K; i++)
    {
        max *= 2;
    }
    if(cnt == 0)
    {
        cout << max + B + C << endl;
    }
    if(cnt == 1)
    {
        cout << A + max + C << endl;
    }
    if(cnt == 2)
    {
        cout << A + B + max << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<set>
#include<iterator>
#include<algorithm>
 
using namespace std;
 
typedef long long ll;

int main() {
    int n;
    string s;
    cin >> n;
    cin >> s;

    ll sum = 0ll;

    set<int> r, g, b;

    for(int i = 0; i < n; i++) {
        if(s[i] == 'R')
            r.insert(i);
        else if(s[i] == 'G')
            g.insert(i);
        else b.insert(i);
    }

    for(auto ri = r.begin(); ri != r.end(); ri++) {
        int rx = *ri;
        for(auto gi = g.begin(); gi != g.end(); gi++) {
            int gx = *gi;
            int rm = 0;
            int a = max(rx, gx);
            int p = min(rx, gx);
            int r = a - p;
            if((p-r) >= 0 && s[p-r] == 'B') rm++;
            if((a+p) % 2 == 0 && s[(a+p)/2] == 'B') rm++;
            if((a+r) < n && s[a+r] == 'B') rm++;

            sum += (ll)(b.size() - rm);
        }
    }

    cout << sum << "\n";
}

Measured memory_bytes: 3352
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string.h>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <time.h>
#define _USE_MATH_DEFINES
#define LL long long
#define UN unsigned
using namespace std;
const double PI = acos(-1.0);

int max_num(int ary[], int length) {
	int max = ary[0];
	for (int i = 1; i < length; i++)
		if (max < ary[i]) max = ary[i];
	return max;
}

int max_ord(int ary[], int length) {
	int max;
	max = max_num(ary, length);
	for (int i = 0; i < length; i++) {
		if (ary[i] == max) return i;
	}
	return -1;
}

int min_num(int ary[], int length) {
	int min = ary[0];
	for (int i = 1; i < length; i++)
		if (min > ary[i]) min = ary[i];
	return min;
}

int min_ord(int ary[], int length) {
	int min;
	min = min_num(ary, length);
	for (int i = 0; i < length; i++) {
		if (ary[i] == min) return i;
	}
	return -1;
}

void dfs(int rest, string s) {
	if (rest == 0)
		cout << s << endl;
	else
		for (char c = 'a'; c <= 'c'; c++)
			dfs(rest - 1, s + c);
}

int mp[100][100];

int main() {
	int h, w, n, a[10000], big = 1, small = 1;
	cin >> h >> w >> n;
	for (int i = 0; i < n; i++) cin >> a[i];

	for (int i = 0; i < h; i++) {
		if (i % 2 == 0)
			for (int j = 0; j < w; j++, small++) {
				mp[i][j] = big;
				if (small == a[big - 1]) {
					big++;
					small = 0;
				}
			}
		else
			for (int j = w - 1; j >= 0; j--, small++) {
				mp[i][j] = big;
				if (small == a[big - 1]) {
					big++;
					small = 0;
				}
			}
	}

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cout << mp[i][j];
			if (j != w - 1)
				cout << ' ';
		}
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 384
import itertools

N = int(input())

speak_list = [] #証言を格納する配列
for i in range(N):
  speak_list.append([-1]*(N))

for i in range(N):
  A = int(input())
  for j in range(A):
   x,y = map(int,input().split())
   x,y = x-1,y
   speak_list[i][x] = y #i番目の人がx番目の人を「y」と証言 
    
    
#(方針)最大2^15通り 試して 「正直者(1)が不親切(0)」と言っている人が
#     親切(1)になる場合そのパターンは不可と考える
ori = [0,1]
Comb = list(itertools.product(ori, repeat=N))
ans = 0

for i in range(len(Comb)):
 tmp = list(Comb[i]) #ex: (N=3)0,0,1
 
 #正直者の言ったこと格納用
 X = []
 for i in range(N):
  X.append([-1]*(N))
 
 for i in range(N):
  if(tmp[i] == 1): #正直者なら
   for j in range(N): #言ったことを反映
    X[i][j] = speak_list[i][j]
  
 judge = 0 #矛盾なし 
 for i in range(N):
  for j in range(N):
    if(X[i][j] != -1): #正直者か不親切者か言われているなら
      if((X[i][j] == 1)and(tmp[j] == 0)): #矛盾が生じるなら
        judge = 1 
        break  
      if((X[i][j] == 0)and(tmp[j] == 1)): #矛盾が生じるなら
        judge = 1 
        break  
  
 #矛盾が生じないなら       
 if(judge == 0):
   ans = max(ans,sum(tmp))
   #sum(tmp) : 1の個数
    
print(ans)
    


Measured memory_bytes: 8868
#include <iostream>
#include <vector>
#include <string>
#include <random>
#include <algorithm>
#include <iomanip>
using namespace std;

#define FOR(i,a,b) for(int i = a; i < b; ++i)
#define REP(i,n)   for(int i = 0; i < n; ++i)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

ull powmod(ull a, ull b, ull mod) {ull res = 1; for(; b; b >>= 1){if (b & 1) {res = res * a % mod;} a = a * a % mod;} return res;}

int main(){
  ull a, b, c;

  cin >> a >> b >> c;

  if (a + b >= c){
    cout << "Yes\n";
  }else{
    cout << "No\n";
  }
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int r, g, b;
	scanf("%d%d%d", &r, &g, &b);
	if((100 * r + 10 * g + b) % 4 == 0){
		printf("YES\n");
	}
	else{
		printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 128
import math


def keisan(N):
    ans = 0
    #j = int(math.sqrt(N/6))
    
    j= 100
    
    for x in range(1,j+1):
        for z in range(1,j+1):
            D =  (x+z)*(x+z)-4*(x*x+z*z+z*x-N)
            if D>=0:
                y = -(x+z)+math.sqrt(D)
                y = y/2
                #print(y)
                #print(y.is_integer())
                if y>=1 and y.is_integer() == True:
                    ans = ans+1
                    #print(x,y,z)
    print(ans)
        

N = int(input())
for i in range(1,N+1):
    keisan(i)
    

Measured memory_bytes: 70640
lst = []
for i in range(3):
    lst.append(list(map(int, input().split())))
arr = []
N  = int(input())
for i in range(N):
    arr.append(int(input()))
for i in range(3):
    for j in range(3):
        if lst[i][j] in arr:
            lst[i][j] = True
        else:
            lst[i][j] = False

bing = False
for i in range(3):
    if lst[i][0] and lst[i][1] and lst[i][2]:
        bing = True
    if lst[0][i]and lst[1][i] and lst[2][i]:
        bing = True
if lst[0][0] and lst[1][1] and lst[2][2]:
    bing = True
if lst[0][2] and lst[1][1] and lst[2][0]:
    bing = True

if bing:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38708
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
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; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c,d;cin >> a >> b >> c >> d;
    if((c+b-1)/b<=(a+d-1)/d){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

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

using namespace std;

typedef long long ll;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(15);
    int N;
    cin >> N;
    vector<tuple<int, int, int>> ps(N);
    for (int i = 0; i < N; ++i) {
        cin >> get<1>(ps[i]) >> get<2>(ps[i]) >> get<0>(ps[i]);
    }
    sort(ps.begin(), ps.end(), greater<tuple<int, int, int>>());
    int h(-1);
    for (int cx = 0; cx <= 100; ++cx) {
        for (int cy = 0; cy <= 100; ++cy) {
            h = abs(cx - get<1>(ps[0])) + abs(cy - get<2>(ps[0])) + get<0>(ps[0]);
            bool ok(true);
            for (int i = 1; i < N; ++i) {
                int th(get<0>(ps[i]));
                if (th != 0 && h != abs(cx - get<1>(ps[i])) + abs(cy - get<2>(ps[i])) + th) {
                    ok = false;
                    break;
                }
                if (th == 0 && h > abs(cx - get<1>(ps[i])) + abs(cy - get<2>(ps[i])) + th) {
                    ok = false;
                    break;
                }
            }
            if (ok) {
                cout << cx << " " << cy << " " << h << endl;
                return 0;
            }
        }
    }
}



Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(){

  int K, X;
  cin >> K >> X;
  
  for(int i=0;i<2*K-2;i++){
  	cout << i+X-K+1 << " ";
  }

  cout << X+K-1 <<endl;

  return 0;
}




Measured memory_bytes: 256