akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <numeric>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }

ll gcd(ll m, ll n) {
    ll tmp;
    while (m % n != 0) {
        tmp = n;
        n = m % n;
        m = tmp;
    }
    return n;
}

ll lcm(ll m, ll n) {
    return max(m, n)/gcd(m,n) * min(m,n);
}


int main() {
    int n; cin >> n;
    ll ans = 1;
    rep(i, n) {
        ll a; cin >> a;
        ans = lcm(ans, a);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int mod =1000000007;

#define MODMATEXPO mod
typedef long long LL;
template<typename T, int N> 
struct matrix {
	T x[N + 1][N + 1];
	matrix(){memset(x, 0, sizeof(x));};
	matrix(T v) {
		memset(x, 0, sizeof(x));
		if(v!=0)
		for (int i = 1; i <= N; ++i) x[i][i] = v;
	}
	inline matrix operator*(const matrix &r) {
		matrix<T,N> p(0);
		for (int k = 1; k <= N; ++k) {
			for (int i = 1; i <= N; ++i) {
				if (x[i][k] == 0) continue;
				for (int j = 1; j <= N; ++j) {
					p.x[i][j] += x[i][k] * r.x[k][j];
					#ifdef MODMATEXPO
						p.x[i][j]%=MODMATEXPO;
					#endif
				}
			}
		}
		return p;
	}
	inline matrix mul(const matrix &r,const int col) {// col
		matrix<T,N> p(0);
		for (int k = 1; k <= N; ++k) {
			for (int i = 1; i <= N; ++i) {
				if (x[i][k] == 0) continue;
				for (int j = 1; j <= col; ++j) {
					p.x[i][j] += x[i][k] * r.x[k][j];
					#ifdef MODMATEXPO
						p.x[i][j]%=MODMATEXPO;
   					#endif
				}
			}
		}
		return p;
	}
	inline matrix pow(LL p) {
		matrix r(1), a = *this;
		for (; p > 0 ; p >>= 1) {
			if (p & 1) r = r * a;
			a = a * a;
		}
		return r;
	}
	T determinant() const {
		T r = 1, det[N + 1][N + 1];
		for (int i = 1; i <= N; ++i) memcpy(det[i], x[i], sizeof(x[i])); 
		for (int i = 1; i <= N; ++i) {
			for (int j = i + 1; j <= N; ++j) {
				while (det[j][i] != 0) {
					T ratio = det[i][i] / det[j][i];
					for (int k = i; k <= N; ++k) {
						det[i][k] -= ratio * det[j][k];
						swap(det[i][k], det[j][k]);
					}
					r = -r;
				}
			}
			r = r * det[i][i];
		}
		return r;
	}
	void print()
	{
		cout<<N<<endl;
		for (int i = 1; i <= N; i++)
		{
			for (int j = 1; j <= N; j++)cout << x[i][j] << ' '; cout << endl;
		}
	}
	void init(int *ara,int xx,int yy)//row,col
	{
		int k=0;
		for(int i=1;i<=xx;i++)
		{
			for(int j=1;j<=yy;j++)
			{
				x[i][j]=*(ara+k++);
			}
		}
	}
};


int main(int argc, char const *argv[])
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	matrix<long long,50> mat;
	int arr[50*50+10];
	int n;
	long long k;
	cin>>n>>k;
	for(int i=0;i<n*n;i++)cin>>arr[i];
	mat.init(arr,n,n);
	mat=mat.pow(k);
	int ans=0;
	for(int i=0;i<=n;i++){
		for(int j=0;j<=n;j++){
			ans+=mat.x[i][j];
			// cout<<mat.x[i][j]<<' ';
			if(ans>=mod)ans-=mod;
		}
		// cout<<endl;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const double Pi=acos(-1);
vector<ll> A;
vector<ll> F;
ll N,K,sumcost=0;
ll binary_search(ll key,ll maximum) {
  ll answer=maximum;
  ll left=1,right=maximum;
  while (right >= left) {
    ll count=0;
    ll mid=left+(right-left)/2;
    for(ll i=0;i<N;i++){count+=max((ll)0,A.at(i)-mid/F.at(N-1-i));}
    if (count > key){left=mid+1;}
    else if (count <= key){right=mid-1;answer=min(answer,mid);}
  }
  return answer;
}
int main() {
  cin>>N>>K;
  A.resize(N);
  F.resize(N);
  for(ll i=0;i<N;i++){
    cin>>A.at(i);
    sumcost+=A.at(i);
  }
  for(ll i=0;i<N;i++){cin>>F.at(i);}
  if(sumcost<=K){cout<<0<<endl;}//k回も修行する必要がない時
  else{
    sort(A.begin(),A.end());
    sort(F.begin(),F.end());
    ll maxtime=A.at((ll)A.size()-1)*F.at((ll)F.size()-1);
    cout<<binary_search(K,maxtime); 
  }
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
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 int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  IOS;
  ll x[2],y[2];
  cin >> x[0] >> x[1];
  cin >> y[0] >> y[1];
  ll ans = -LINF;
  REP(i,2) REP(j,2) {
    ll v = x[i] * y[j];
    chmax(ans, v);
  }
  COUT(ans);

  return 0;
}

Measured memory_bytes: 3576
#include <iostream>
#include <climits>
using namespace std;
int main() {
    int A,B,M; scanf("%d%d%d",&A,&B,&M);
    int a[A],b[B];
    int am,bm; am = bm = INT_MAX;
    for (int i=0; i<A; i++) scanf("%d", &a[i]), am = min(am, a[i]);
    for (int i=0; i<B; i++) scanf("%d", &b[i]), bm = min(bm, b[i]);
    int x,y,c,abm = am + bm;
    for (int i=0; i<M; i++) scanf("%d%d%d",&x,&y,&c),abm = min(abm, a[x-1]+b[y-1]-c);
    printf("%d\n",abm);
    return 0;
}

Measured memory_bytes: 1024
s = input()

a = int(s[0])
b = int(s[1])
c = int(s[2])
d = int(s[3])

if a + b + c + d == 7:
    print(str(a) + "+" + str(b) + "+" + str(c) + "+" +str(d) + "=7")

elif a + b - c + d == 7:
    print(str(a) + "+" + str(b) + "-" + str(c) + "+" + str(d) + "=7")

elif a - b + c + d == 7:
    print(str(a) + "-" + str(b) + "+" + str(c) + "+" + str(d) + "=7")

elif a - b - c + d == 7:
    print(str(a) + "-" + str(b) + "-" + str(c) +  "+" + str(d) + "=7")

elif a + b + c - d == 7:
    print(str(a) + "+" + str(b) + "+" + str(c) + "-" + str(d) + "=7")

elif a + b - c - d == 7:
    print(str(a) + "+" + str(b) + "-" + str(c) + "-" + str(d) + "=7")

elif a - b + c - d == 7:
    print(str(a) + "-" + str(b) + "+" + str(c) + "-" + str(d) + "=7")

elif a - b - c - d == 7:
    print(str(a) + "-" + str(b) + "-" + str(c) + "-" + str(d) + "=7")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, a) for (ll i = 0; i < (a); ++i)
#define pb push_back
#define all(v) v.begin(),v.end()
#define sort_1(v) sort(v.begin(),v.end())
#define sort_2(v) sort(v.begin(),v.end(),greater<ll>())
#define reverse(v) reverse(v.begin(),v.end())
typedef long long ll;
typedef long double la;
using namespace std;
 
int main(){
  int n,k;
  cin >> n >> k;
  vector<double> p(n);
  vector<double> b;

  rep(i,n){
    cin >> p[i];
    b.pb((p[i]+1)/2);
  }

  double max = 0.0;
  double sum = 0.0;

  rep(i,k){
    sum += b[i];
  }

  max = sum;

  rep(i,n-k){
    sum = sum - b[i] + b[i+k];
    if(sum > max){
      max = sum;
    }
  }
  cout << setprecision(12) << max << endl;
}

Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

//long longのシフト演算には気をつけよう

int f(string a, string b){
    return max(a.size(), b.size());
}

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

    ll i = 1;
    int ans = 10000;
    while(i*i <= N){
        if(N%i == 0) ans = min(ans, f(to_string(i), to_string(N/i)));
        i++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
main()
{
  int n,m;
  cin>>n>>m;
  int j,i,a[n],w[n];
  char v[3];
  for(i=0;i<n;i++){a[i]=0;w[i]=0;}
  for(i=0;i<m;i++)
  {
    cin>>j>>v;
    j--;
    if(v[0]=='A')a[j]=1;
    else if(a[j]==0)w[j]++;
  }
  int p=0,c=0;
  for(i=0;i<n;i++)
  {
    if(a[i]==1)
    {
      c++;
      p+=w[i];
    }
  }
  cout<<c<<" "<<p;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;

#define ll long long
const long long llINF = 1LL << 60;
const int iINF = 0x20000000;
template<class T> inline bool chmin(T& a, T b) { if (b < a) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

void execute();
int main() 
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);// cin と scanfの併用禁止
    cout << fixed << setprecision(15);
    execute();
    return 0;
}


void execute()
{
    string s;
    cin >> s;

    int n = 0;
    int c = 0;
    for(int i = 0; i < 3; i++){
        if(s[i] == 'R'){
            c++;
        }else{
            if(n < c) n = c;
            c = 0;
        }
    }
    if(n < c) n = c;

    cout << n << endl; 
}


Measured memory_bytes: 3596
#include <stdio.h>

int main(void)
{
	for(;;){
		int H, W;
		
		scanf("%d %d", &H, &W);
		
		if(H==0 && W==0) break;

		for(int i = 0; i < H; i++){
			for(int j = 0; j < W; j++){
				if(i==0 || j==0 || i == H-1 || j == W-1)
					printf("#");
				else
					printf(".");
			}
			printf("\n");
		}
		printf("\n");
	}

	return 0;
}



Measured memory_bytes: 2048
#include <cstdio>
#include <set>
#include <vector>
#include <utility>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;

#define WALL (-1)
#define NONE (-2)

typedef pair<int,int> pii;
typedef pair<int,vector<int> > pivi;

int w, h;
char datach[14][14];
int dat[14][14];
int dist[14][14];
int start, goal;

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

vector<int> ices;

struct state{
	int step;
	int y;
	int x;
	vector<int> cnts;

	state(int s, int y, int x, const vector<int> &c)
		: step(s), y(y), x(x), cnts(c) {}

	bool operator< (const state &s) const{
		return step + dist[y][x] > s.step + dist[s.y][s.x];
	}
};

struct statecomparer{
	bool operator() (const state &s1, const state &s2){
		if( s1.y != s2.y ) return s1.y < s2.y;
		if( s1.x != s2.x ) return s1.x < s2.x;
		return s1.cnts < s2.cnts;
	}
};


void calcdist(){
	memset(dist, -1, sizeof(dist));
	
	int y = goal / 100;
	int x = goal % 100;
	dist[y][x] = 0;
	
	int t = 1;
	queue<pii> q;
	q.push( pii(y, x) );
	q.push( pii(-1, -1) );
	while( q.size() > 1 ){
		if( q.front().first < 0 ){
			++t;
			q.push( q.front() );
		}
		else{
			for(int i = 0; i < 4; ++i){
				y = q.front().first + dy[i];
				x = q.front().second + dx[i];
				
				if( dist[y][x] < 0 && dat[y][x] != WALL ){
					dist[y][x] = t;
					q.push( pii(y, x) );
				}
			}
		}
		q.pop();
	}
}

int countsteps(){
	priority_queue<state> pq;
	set<state,statecomparer> st;

	state prev(0, start / 100, start % 100, ices);
	pq.push(prev);
	st.insert(prev);

	while(true){
		prev = pq.top();
		pq.pop();


		for(int i = 0; i < 4; ++i){
			int y = prev.y + dy[i];
			int x = prev.x + dx[i];

			if( dat[y][x] == WALL ) continue;
			if( y * 100 + x == goal ){
				return prev.step + 1;
			}

			if( dat[y][x] < 0 ){
				state next(prev.step + 1, y, x, prev.cnts);
				if( st.insert(next).second ){
					pq.push(next);
				}
			}
			else{
				int k = dat[y][x];
				if( (prev.cnts[k] - 1) * 2 >= ices[k] ){
					state next(prev.step + 1, y, x, prev.cnts);
					--next.cnts[k];
					
					if( st.insert(next).second ){
						pq.push(next);
					}
				}
			}
		}
	}
}

int main(){
	while( scanf("%d%d", &w, &h), w != 0 ){
		ices.clear();

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

		for(int i = 1; i <= h; ++i){
			scanf(" %s", datach[i] + 1);
		}

		for(int i = 1; i <= h; ++i)
		for(int j = 1; j <= w; ++j){
			if( datach[i][j] == '.' ){
				dat[i][j] = NONE;
			}
			else if( datach[i][j] == 'S' ){
				start = i * 100 + j;
				dat[i][j] = NONE;
			}
			else if( datach[i][j] == 'G' ){
				goal = i * 100 + j;
				dat[i][j] = NONE;
			}
			else if( datach[i][j] == 'X' ){
				dat[i][j] = ices.size();
				datach[i][j] = '_';

				int cnt = 1;

				queue<pii> q;
				q.push( pii(i, j) );
				while( !q.empty() ){
					for(int k = 0; k < 4; ++k){
						int y = q.front().first + dy[k];
						int x = q.front().second + dx[k];
						if( datach[y][x] == 'X' ){
							datach[y][x] = '_';
							dat[y][x] = ices.size();
							q.push( pii(y, x) );
							++cnt;
						}
					}
					q.pop();
				}
				
				ices.push_back(cnt);
			}
		}

		calcdist();
		printf("%d\n", countsteps());
	}
}

Measured memory_bytes: 1324
h,w=map(int,input().split())
s=[list(input()) for i in range(h)]
for i in range(h):
    for j in range(w):
        u=s[i-1][j] if i>0 else ''
        r=s[i][j+1] if j<w-1 else ''
        d=s[i+1][j] if i<h-1 else ''
        l=s[i][j-1] if j>0 else ''
        ur=s[i-1][j+1] if i>0 and j<w-1 else ''
        ul=s[i-1][j-1] if i>0 and j>0 else ''
        dr=s[i+1][j+1] if i<h-1 and j<w-1 else ''
        dl=s[i+1][j-1] if i<h-1 and j>0 else ''
        around=[u,r,d,l,ur,ul,dr,dl]
        if s[i][j]=='.':
            s[i][j]=str(around.count('#'))
for i in s:
    print(''.join(i))

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;


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

	string s;
	cin >> s;
	int n;
	cin >> n;
	for (int i = 0; i < s.size(); i++)
	{
		if (i % n == 0)
			cout << s.at(i);
	}
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoderTest001
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Calc();
        }

        void Calc()
        {
            // read
            string[] tmpStr = Console.ReadLine().Split(' ');

            int a = int.Parse(tmpStr[0]);
            int b = int.Parse(tmpStr[1]);

            if (a <= 8 && b <= 8)
            {
                Console.WriteLine("Yay!");
            }
            else
            {
                Console.WriteLine(":(");
            }

            //int[] cake = new int[16];

            //for(int i= 0; i < cake.Length; i++)
            //{
            //    cake[i] = 0;
            //}

            //for(int i = 0; i < cake.Length ; i++)
            //{

            //    cake.

            //    if(n == 0)
            //    {
            //        Console.WriteLine(i);
            //        break;
            //    }

            //    if(n < 6)
            //    {
            //        Console.WriteLine(i + n);
            //        break;
            //    }
            //    else
            //    {
            //        if(n - x > n - y)
            //        {
            //            n = n - y;
            //        }
            //        else
            //        {
            //            n = n - x;
            //        }
            //    }

            //}

            //Console.WriteLine(x);


        }

        int getHeight(int n)
        {
            if(n == 1)
            {
                return 1;
            }
            else
            {
                return getHeight(n - 1) + n;
            }
        }

        int getJijou(int n, int i)
        {
            if (i == 0)
            {
                return 1;
            }
            else
            {
                return n * getJijou(n, i - 1);
            }
        }

        int Maxjijou(int n, int z)
        {
            int ret = 1;
            int x = 1;
            for(int i = 0; ; i++)
            {
                x = getJijou(z, i);
                if (x > n)
                {
                    return ret;
                }
                ret = x;
            }
        }


    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int N;
    cin >> N;
    int A[N];
    rep(i, N) cin >> A[i];
    map<int, int> mp1, mp2;
    rep(i, N-1){
        mp1[A[i]]++, mp2[A[N-i-1]]++;
        if(mp1.count(A[N-i-1]) && mp2.count(A[N-i-1])){
            mp1[A[N-i-1]]--, mp2[A[N-i-1]]--;
            if(mp1[A[N-i-1]] == 0) mp1.erase(A[N-i-1]);
            if(mp2[A[N-i-1]] == 0) mp2.erase(A[N-i-1]);
        }
        if(mp1.count(A[i]) && mp2.count(A[i])){
            mp1[A[i]]--, mp2[A[i]]--;
            if(mp1[A[i]] == 0) mp1.erase(A[i]);
            if(mp2[A[i]] == 0) mp2.erase(A[i]);
        }
        if(mp1.empty() && mp2.empty()) cout << i+1 << ' ';
    }
    cout << N << endl;
}


Measured memory_bytes: 4484
#include<iostream>
#include<vector>

int main(){
    unsigned long n;
    std::cin >> n;

    std::vector<std::vector<unsigned long>> edges(n);
    for(auto&& i : edges){
        unsigned long u;
        std::cin >> u;
        unsigned long k;
        std::cin >> k;
        i = std::vector<unsigned long>(k);
        for(auto&& j : i){
            std::cin >> j;
            --j;
        }
    }

    std::vector<unsigned long> d(n), f(n);

    [dfs_impl = [&edges, &d, &f](auto func, unsigned long now, unsigned long& t) -> void {
        d[now] = ++t;
        for(const auto& i : edges[now])if(!d[i])func(func, i, t);
        f[now] = ++t;
    }, &n, &d]{
        unsigned long t{0};
        for(unsigned long i{0}; i < n; ++i)if(!d[i])dfs_impl(dfs_impl, i, t);
    }();

    for(unsigned long i{0}; i < n; ++i)std::cout << i + 1 << " " << d[i] << " " << f[i] << std::endl;

    return 0;
}


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

int main(void) {
  string S;
  cin >> S;
  string last = "";
  string tmp = "";
  int ans = 0;
  for (int i = 0; i < S.length(); i++) {
    tmp += S[i];
    if (tmp == last) continue;
    last = tmp;
    tmp = "";
    ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
//alds1_1_d.cpp
using namespace std;
static const int MAX = 200000;

int main() {
	int R[MAX], n;
	
	cin >> n;
	for (int i = 0; i < n; i++) cin >> R[i];
	
	int maxv = -2000000000;
	int minv = R[0];
	
	for (int i = 1; i < n; i++) {
		maxv = max(maxv, R[i] - minv);
		minv = min(minv, R[i]);
	}
	
	cout << maxv << endl;
	
	return 0;
}

Measured memory_bytes: 3848
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
const int MOD = 1000000007;
template<class T> void add(T &a, T b) { a = (a + b) % MOD; }

int main() {
    int N; cin >> N;
    vector<vector<int>> A(N, vector<int>(N));
    rep(i, 0, N) rep(j, 0, N) cin >> A[i][j];
    vector<vector<int>> dp(N+1, vector<int>(1<<N));
    dp[0][0] = 1;
    rep(i, 0, N) rep(msk, 0, 1<<N) {
        int cnt = 0;
        rep(j, 0, N) if(msk & (1<<j)) cnt++;
        if(i != cnt) continue;
        rep(j, 0, N) if(A[i][j] && !(msk & (1<<j))) add(dp[i+1][msk|(1<<j)], dp[i][msk]);
    }
    cout << dp[N][(1<<N)-1] << endl;
    return 0;
}


Measured memory_bytes: 188800
import java.io.*;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
        init();
        int n = nextInt(), k = nextInt();
        double[] ps = new double[n];
        for (int i = 0; i < ps.length; i++) {
            ps[i] = expected(nextInt());
            if (i > 0) ps[i] += ps[i - 1];
        }

        double ans = 0.0;
        for (int i = 0; i + k - 1 < ps.length; i++) {
            ans = Math.max(ans, ps[i + k - 1] - (i - 1 >= 0 ? ps[i - 1] : 0));
        }
        System.out.println(ans);
    }

    private static double expected(double p) {
        double sum = 0.0;
        for (int i = 1; i <= p; i++) {
            sum += i;
        }
        return sum/p;
    }

    //Input Reader
    private static BufferedReader reader;
    private static StringTokenizer tokenizer;

    private static void init() {
        reader = new BufferedReader(new InputStreamReader(System.in));
        tokenizer = new StringTokenizer("");
    }

    private static String next() throws IOException {
        String read;
        while (!tokenizer.hasMoreTokens()) {
            read = reader.readLine();
            if (read == null || read.equals(""))
                return "-1";
            tokenizer = new StringTokenizer(read);
        }

        return tokenizer.nextToken();
    }

    private static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }
}

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

using namespace std;
using ll =long long;
using db = double;
using vll = vector<long long>;

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; } return false; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define leftunique(a) {SORT(a);(a).erase(unique((a).begin(),(a).end()),(a).end());}
//leftuniqueは配列から同じ要素のものを取り除く 例 4 6 2 1 3 4 1 2 なら 1 2 3 4 6 になる
#define debug(x)  cout << #x << " = " << (x) << endl;
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}
const int mod = 1e9 + 7;
const ll INF = 1LL << 60;
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
//グラフ用
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};	
//ここから書き始める

ll combination(ll n, ll i){
	ll count = 0;
	ll multi = 1;
	ll div =1;
	int limit = i;
	while(count < limit){
		multi *= n;
		n--;
		multi/= count+1;
		count ++ ;
	}
	return multi / div;
}

int main()
{
	cout <<setprecision(10);
	ll h , w, k;
	cin >> h >> w >> k;
	vector<string> field(h);
	rep(i,h){
		cin >> field[i];
	}
	vector<vector<ll>> ans(h, vector<ll> (w));

	//入力ok.それぞれのfieldは、次の#が出てくる手前までの区画でやればいい
	//イチゴがない場所を覚えておく
	vector<bool> ichigo(h,false);

	ll firstLine = -1;
	rep(i,h){
		rep(j,w){
			if(field[i][j] == '#' ){
				if(firstLine==-1){
					firstLine = i; //イチゴが最初に出てきたのは何行目か。
					ichigo[i] = true;
				}else{
					ichigo[i] = true;
					break;
				}
			}
		}
	}

	ll count = 0 ;
	for(int i = firstLine ; i < h ; i++){//イチゴが出てきたラインから作
	bool onetime = false;//行ごとに2回目出てくるまでは前の行＋1
	//行が変わったとき、その行にイチゴがあるんだったら＋1
	if(ichigo[i]) count ++; 
		rep(j,w){
			if(ichigo[i] ==false){//イチゴがないんだったら、上のものをそのまま使う
				ans[i][j] = ans[i-1][j];
			}else{
				if(field[i][j] =='#'&&onetime){
					count ++;
					ans[i][j] = count;
				}
				else if(field[i][j] == '#'){
					ans[i][j] = count;
					onetime = true;
				}
				else{
					ans[i][j] = count;
				}
			}
		}
		//行が変わるごとに、その行にイチゴがあるんだったらカウントを++する
	}

	//firstline より前を構築していく
	for(int i = firstLine-1 ; i >= 0 ; i --){
		rep(j,w){
			ans[i][j] = ans[i+1][j];
		}
	}
	rep(i,h){
		rep(j,w){
			cout << ans[i][j] <<" ";
		}
		cout << endl;
	}
//一行目日以後がなければ、全部j
}


Measured memory_bytes: 1664
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int H = sc.nextInt();
            int W = sc.nextInt();
            if(H == 0 && W == 0){
                break;
            }
            for(int i=1;i<=H;i++){
                if(i==1 || i==H){
                    for(int j=1;j<=W;j++){
                        System.out.print("#");
                    }
                }else{
                    for(int j=1;j<=W;j++){
                        if(j==1 || j == W){
                            System.out.print("#");
                        }else{
                            System.out.print(".");
                        }
                    }
                }
                System.out.print("\n");
            }
        System.out.print("\n");
        }    
    sc.close();
    }
}


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

typedef long long LL;
typedef pair<int, int> II;

const int N = (int) 2e5 + 10;
int a[N];

int main() {
    #ifdef LOCAL
        freopen("Data.inp", "r", stdin);
        freopen("Data.out", "w", stdout);
    #endif

    int n, x;
    cin >> n >> x;

    if (x == 1 || x == 2 * n - 1) {
        puts("No");
        return 0;
    }

    a[n] = x;
    for (int i = n - 1, j = n + 1; i >= 1; --i, ++j) {
        a[i] = a[i + 1] - 1; if (a[i] == 0) a[i] = 2 * n - 1;
        a[j] = a[j - 1] + 1; if (a[j] == 2 * n) a[j] = 1;
    }

    puts("Yes");
    for (int i = 1; i <= 2 * n - 1; ++i) printf("%d\n", a[i]);
    return 0;
}


Measured memory_bytes: 2304
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
    int n, cntp, cntq, cnt;
    cin >> n;
    cnt = 1;
    vector<int> p(n);
    vector<int> q(n);
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin >> p.at(i);
    }
    for(int i=0; i<n; i++){
        cin >> q.at(i);
    }
    for(int i=0; i<n; i++)  a.at(i) = i+1;
    map<vector<int>, int> mp;
    do{
       mp[a] = cnt;
       cnt++;
    }while( next_permutation(a.begin(), a.end()) );
    cntp = mp[p];
    cntq = mp[q];
    cout << abs(cntp - cntq) << endl;
    return 0;
}


Measured memory_bytes: 5248
//   ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
// ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
//■■■■■■■■■■■■■   ■■■■■■■■■■      ■■■■■■■■■■■■■
//■■■■■■■■■■■■ ■■■ ■■■■■■■■ ■■■■■■ ■■■■■■■■■■■■
//■■■■■■■■■■■ ■■■■■ ■■■■■■ ■■■■■■■■■■■■■■■■■■■■
//■■■■■■■■■■         ■■■■■ ■■■■■■■■■■■■■■■■■■■■
//■■■■■■■■■■ ■■■■■■■ ■■■■■ ■■■■■■■■■■■■■■■■■■■■
//■■■■■■■■■■ ■■■■■■■ ■■■■■■ ■■■■■■ ■■■■■■■■■■■■
//■■■■■■■■■■ ■■■■■■■ ■■■■■■■      ■■■■■■■■■■■■■
// ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
//   ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■

#include<bits/stdc++.h>
using namespace std;
int main(){
	int a;
	cin>>a;

	if(a<=999)cout<<"ABC";
	else cout<<"ABD";
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#define ll long long
using namespace std;
int n,a,x[55];
ll dp[100000];
ll tp[100000];
int main()
{
    while(cin>>n>>a)
    {
      for(int i=0;i<n;i++)cin>>x[i],x[i]-=a;
      memset(dp,0,sizeof(dp));
      dp[3000]=1;
      for(int i=0;i<n;i++){
        for(int j=0;j<10000;j++)tp[j]=dp[j];
        for(int j=-2500;j<=2500;j++){
          if(dp[j+3000]){
            tp[(x[i]+j)+3000]+=dp[j+3000];
          }
        }
        for(int j=0;j<10000;j++)dp[j]=tp[j];
      }
      cout<<dp[3000]-1<<endl;
    }
    return 0;
}


Measured memory_bytes: 1152
// in the name if Allah
// YA Ali!
#include <bits/stdc++.h>

using namespace std;

typedef long long ll ;

const ll INF = 1<<30 ;
const ll N= 1e6 ;

#define f first
#define s second

ll a , b ;

int main()
{
std::ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> a >> b ;
if((a+b) % 2 != 0)cout << "IMPOSSIBLE" ;
else cout << (a+b)/2 ;

    return 0;
}
 /*
              _     _   __
        /_\  (_    (_)  __)
       /   \  _) . (_) (__
 */


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する


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

    int n;
    cin >> n;
    vector<int> a(n);

    rep(i,0,n) cin >> a[i];


    sort(all(a));

    int first = a.back();
    int second = a[0];
    int val =  min(a[0],first - a[0]);

    rep(i,0,n - 1){
        int kouho = min(a[i],first - a[i]);
        if(val < kouho){
            second = a[i];
            val = kouho;
        }
    }

    cout << first << " " << second << endl;




    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
using namespace std;
int n,l;
int main(){
	scanf("%d%d",&n,&l);
	if(l>=0) printf("%d",l*n+n*(n-1)/2-l);
	else if(l<0){
		if(-l<n) printf("%d",l*n+n*(n-1)/2);
		else{
			printf("%d",l*n+n*(n-1)/2-(l+n-1));
		}
	}
	return 0;
}

Measured memory_bytes: 256
#%%
s = list(input())

f1 = False
f2 = False

for i in range(len(s)):
    if s[i] == 'C':
        f1 = True
    if f1 and s[i] == 'F':
        f2 = True
if f1 and f2:
    print('Yes')
else:
    print('No')


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

int main() {
	// 코틀린 ,문자열 알고리즘 보기, 앳코더, (시간되면 코드포스까지)
	ios_base::sync_with_stdio(false); cin.tie(NULL); //9 90 900 
	int n; cin >> n;
	vector<int>  a(n);

	vector<int>  b(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		b[i] = a[i];
	}
	sort(b.begin(), b.end());
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] != b[i]) {
			cnt++;
		}
	}
	if (cnt == 0 || cnt == 2) {
		cout << "YES" << '\n';
	}
	else {
		cout << "NO" << '\n';
	}



	
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int a[110],s1,s2;
int main()
{
	int n,m,x,ii;
	cin>>n>>m>>x;
	for(int i=1;i<=m;i++) cin>>a[i];
	for(int i=1;;i++)
	{
		if(a[i]<x)
		{
			s1++;
			ii=i;
		} 
		else break;
	}
	for(int i=ii+1;i<n;i++)
	{
		if(a[i]!=0) s2++;
	}
	cout<<min(s1,s2)<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
#include<numeric>
#include<iostream>
#include<array>
#include<string>
#include<sstream>
#include<stack>
#include<queue>
#include<list>
#include<functional>
#define _USE_MATH_DEFINES

#include<math.h>
#include<map>

#define SENTINEL 1000000001

#define min(a,b) (a)>(b)?(b):(a)
#define max(a,b) (a)>(b)?(a):(b)

using namespace std;

typedef pair<int, int> pii;

using namespace std;

struct UnionFind
{
	vector<int> parent;
	vector<int> rank;

	UnionFind(int n) :parent(n), rank(n, 0)
	{
		for (int i = 0; i < n; i++)
		{
			parent[i] = i;
		}
	}

	int find(int x)
	{
		if (x == parent[x])return x;
		else return parent[x] = find(parent[x]);
	}

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

	void unite(int x, int y)
	{
		int a = find(x);
		int b = find(y);

		if (a == b)
		{
			return;
		}

		if (rank[a] < rank[b])
		{
			parent[a] = b;
		}
		else
		{
			parent[b] = a;
			if (rank[a] == rank[b])rank[b]++;
		}
	}
};

int main()
{
	int n, q;
	cin >> n >> q;
	
	UnionFind uf(n);

	for (int i = 0; i < q; i++)
	{
		int c, x, y;
		cin >> c >> x >> y;

		switch (c)
		{
		case 0:
			uf.unite(x, y);
			break;
		case 1:
			cout << (uf.same(x, y) ? 1 : 0) << endl;
			break;
		}
	}

	return 0;
}




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

#define ft first
#define sd second
#define pb push_back
#define all(x) x.begin(),x.end()

#define ll long long int
#define vi vector<int>
#define vii vector<pair<int,int> >
#define pii pair<int,int>
#define plii pair<pair<ll, int>, int>
#define piii pair<pii, int>
#define viii vector<pair<pii, int> >
#define vl vector<ll>
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define mp make_pair
#define ms(x, v) memset(x, v, sizeof x)
#define pr_vec(v) for(int i=0;i<v.size();i++) cout << v[i] << " " ;

#define f_in(st) freopen(st,"r",stdin)
#define f_out(st) freopen(st,"w",stdout)

#define fr(i, a, b) for(i=a; i<=b; i++)
#define fb(i, a, b) for(i=a; i>=b; i--)
#define ASST(x, l, r) assert( x <= r && x >= l )
const int  p=31,po=1,N=260, M=(ll)1e9+1 ;
const int mod = 998244353 ;
// struct node{
//   ll prefixsum,suffixsum,bettersum,totalsum;
//   void create(ll val){
//     prefixsum=suffixsum=bettersum=val;
//   }
//   void Merge(node& a,node &b){
//     prefixsum=max(a.prefixsum,a.totalsum+b.prefixsum);
//     suffixsum=max(b.suffixsum,a.suffixsum+b.sum);
//     totalsum=a.totalsum+b.totalsum;
    
//   }
// }
//ll dp[2][100];
vl compute(string s){
        vl has(s.length());
        ll i;

        for(i=0;i<s.length();i++){
            if(i==0){
                has[i]=((s[i]-'a'+1))%mod;
            }
            else
                has[i]=(has[i-1]*p + (s[i]-'a'+1))%mod;
        }
        return has;
}
ll g[N][N],keep[N*N];

ll solve(ll l,ll r){
  if(l==r)
    return l;
  ll n1=solve(l,(l+r)/2);
  ll n2=solve((l+r)/2 +1,r);
  if(g[n1][n2]>0){
    keep[g[n1][n2]]=true;
    return n1;
  }
  else{
    keep[g[n2][n1]]=true;
    return n2;
  }
  
}
ll x(ll n){
  ll rem=n%4;
  if(rem==0)
    return n;
  else if(rem==1)
    return 1;
  else if(rem==2)
    return n+1;
  else
    return 0;
}
int main(){
 ios_base::sync_with_stdio(0);
  ll n,h,w;
  cin >> n >> h >> w;
  cout << (n-h+1)*(n-w+1);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
const int MAX_N=100;
int N,a[MAX_N];
int main(){
	cin>>N;
	REP(i,N)cin>>a[i];
	int sm=0;
	REP(i,N)sm+=a[i];
	int inx=0;
	REP(i,N){
		if (abs(N*a[i]-sm)<abs(N*a[inx]-sm)){
			inx=i;
		}
	}
	cout<<inx<<endl;
}

Measured memory_bytes: 256
#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 sqr(x) ((x)*(x))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

const int mn = 2e5 + 5;
const int mm = 2100;
const int mod = 11380;
#define P mod

int n;
string s;

int main() {
	//cin.sync_with_stdio(0);
#ifdef LOCAL
	freopen("../1.txt", "r", stdin);
#endif
	cin>>n>>s;
	int cntb=0,cntr=0;
	for(auto &i:s){
		if (i=='R') cntr++;
		else cntb++;
	}
	if (cntr>cntb) puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;



int main(){
    ll n; cin >> n;
    string s; cin >> s;
    set<char> st;
    ll mx = 0;
    rep(i,n-1){
        ll cnt = 0;
        rep(j,i+1){
            st.insert(s[j]);
        }
        REP(j,i+1,n){
            if(st.find(s[j]) != st.end()){
                st.erase(s[j]);
                cnt++;
            }
        }
        mx = max(mx,cnt);
    }
    cout << mx << endl;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

vint idx[222222];
string S;
int N;

int dp[222222];

signed main(){
    cin>>S;
    S="a"+S;
    N=S.size();

    rep(i,S.size())idx[S[i]-'a'].pb(i);

    for(int i=N-1;i>=0;i--){
        int mi=INT_MAX;
        rep(j,26){
            auto it=upper_bound(all(idx[j]),i);
            if(it==idx[j].end())mi=0;
            else chmin(mi,dp[*it]);
        }
        dp[i]=mi+1;
    }

    string ans;
    int las=0;

    int cnt=dp[0];
    rep(ei,cnt){
        int mi=INT_MAX,arcmi,arcidx;
        rep(i,26){
            auto it=upper_bound(all(idx[i]),las);
            int k;
            if(it==idx[i].end())k=N;
            else k=*it;
            if(mi>dp[k]){
                mi=dp[k];
                arcmi=i;
                arcidx=k;
            }
        }

        cout<<(char)(arcmi+'a');
        las=arcidx;
    }
cout<<endl;

    return 0;
}


Measured memory_bytes: 9152
n,d=map(int,input().split())
xy=[]
for i in range(n):
    x,y=map(int,input().split())
    xy.append((x,y))
ans=0
for i in range(len(xy)):
    p=(xy[i][0]**2+xy[i][1]**2)
    if d**2>=p:
        ans+=1
print(ans)


Measured memory_bytes: 35996
#include "iostream"
using namespace std;

int main()
{
	int h, w;

	while (1){
		cin >> h >> w;
		if (h == 0 && w == 0)break;
		for (int j = 0; j < h; j++){

			for (int i = 0; i < w; i++){
				if(j==0||j==h-1||i==0||i==w-1){
					cout << '#';
				}
				else{
					cout << '.';
				}
				
			}
			cout << endl;

		}
		cout << endl;//空行のため
	}
	return 0;
}



Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long N,A,B;cin>>N>>A>>B;vector<long long>C(N);
  for(int X=0;X<N;X++){
    cin>>C[X];
  }
  long long V=0;
  for(int X=1;X<N;X++){
    if((C[X]-C[X-1])*A<B)V+=(C[X]-C[X-1])*A;
    else V+=B;
  }
  cout<<V<<endl;
}


Measured memory_bytes: 3952
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
int main()
{
	long long a,b,c;
	scanf("%lld%lld",&a,&b);
	c = a*b;
	if(c%2==1)printf("Odd\n");
	else printf("Even\n");
	return 0;
	}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>

using namespace std;

typedef pair<long, long> P;

int main(){
    int N;
    long A[200000], B[200000];
    P p[200000];
    cin >> N;
    for(int i = 0; i < N; i++) {
        cin >> A[i] >> B[i];
        p[i] = P(B[i], A[i]);
    }
    sort(p, p+N);
    long sum = 0;
    for(int i = 0; i < N; i++) {
        sum += p[i].second;
        if(sum > p[i].first){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 6528
#define NguyenDangQuan the_author
#define my_heart love_you_to_the_moon_and_back

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;

bool typetest;
inline void fastIOfileinput()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	typetest = 0;
}

const int N = 5e3 + 3;
int n;
int p[N];
ll c[N], cur[N];
int num[N], k;

void Read()
{
	cin >> n >> k;
	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 piv = i;
		do
		{
			++num[i];
			piv = p[piv];
			cur[i] += c[piv];
		} while (piv != i);
	}
}

void Solve()
{
	ll ans = -1e18;
	for (int i = 1; i <= n; ++i)
	{
		if (cur[i] > 0 && k / num[i] > 0)
		{
			ll score = (k / num[i] - 1) * cur[i];
			ans = max(score, ans);
			int K = k - (k / num[i] - 1) * num[i];
			int piv = i;
			do
			{
				--K;
				piv = p[piv];
				score += c[piv];
				ans = max(ans, score);
			} while (piv != i && K > 0);
			if (K > 0)
			{
				piv = i;
				do
				{
					--K;
					piv = p[piv];
					score += c[piv];
					ans = max(ans, score);
				} while (piv != i && K > 0);
			}
		}
		else
		{
			int piv = i;
			int K = k;
			ll score = 0;
			do
			{
				--K;
				piv = p[piv];
				score += c[piv];
				ans = max(ans, score);
			} while (piv != i && K > 0);
		}
	}
	cout << ans;
}

int32_t main()
{
	fastIOfileinput();
	if (typetest)
	{
		int t;
		cin >> t;
		while (t--)
		{
			Read();
			Solve();
		}
	}
	else
	{
		Read();
		Solve();
	}
}

Measured memory_bytes: 3728
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define stpr setprecision
#define rep(i,n) for(ll i=0;i<(n);++i)
#define REP(i,a,b) for(ll i=(a);i<(b);++i)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define endl '\n'
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ld EPS=10e-8;
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
    for(auto i=begin(v); i != end(v); ++i){
        if(i !=begin(v)) os << ' ';
        os << *i;
    }
    return os;
}

ll C=0,T,Q,G;
map<ll,ll> A;

void tsnnsaku(ll j){
    for(int i=30;i>0;i--){
        T=j;
        G=(pow(2,i));
        Q=G-T;
        if(Q>0){
            if( (Q!=j&&A[Q]>0) || A[Q]>1 ){
                A[Q]--;
                A[j]--;
                C++;
                return;
            }
        }
    }
}
 
int main() {
    ll N,B[200007];
    cin >> N;
    rep(i,N){
        cin >> B[i];
        A[B[i]]++;
    }
    sort(B,B+N);
    reverse(B,B+N);
    rep(j,N){
        if(A[B[j]]>0){
            tsnnsaku(B[j]);
        }
    }
    cout << C << endl;
}

Measured memory_bytes: 40192
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "functional"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


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

	cin >> N;
	vector<string>s(N);
	for (auto &i : s)cin >> i;
	vector<int>dis(N,MOD);
	map<char, set<int>>mp;
	for (int i = 0; i < N; i++) {
		mp[s[i][0]].insert(i);
	}
	dis[0] = 1;
	deque<int>Q;
	Q.push_back(0);
	while (!Q.empty()) {
		int cn = Q.front();
		Q.pop_front();
		auto it = mp[s[cn][0]].upper_bound(cn);
		if (it != mp[s[cn][0]].end()) {
			if (dis[*it] > dis[cn]) {
				dis[*it] = dis[cn];
				Q.push_front(*it);
			}
		}
		if (cn + 1 < N) {
			if (dis[cn + 1] > dis[cn] + 1) {
				dis[cn + 1] = dis[cn] + 1;
				Q.push_back(cn + 1);
			}
		}
	}
	cout << dis.back() << endl;
}


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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define ull unsigned long long
#define ld long double

template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;
template <class T>
using VVV = V<V<V<T>>>;

#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) rep2(i, 0, n)
#define rep1(i, n) rep1(i, 1, n + 1)

// #define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
// #define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()  //

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

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

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

const string YES = "Yes";
const string NO = "No";

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::fixed << std::setprecision(15);
    //    cout << std::setfill('0') << std::setw(2);

    std::string S;
    std::cin >> S;
    std::string T;
    std::cin >> T;

    int n = S.size();
    rep(i, n) {  // 何個ずらしか
        bool f = true;
        rep(j, i) {  //
            if (T[j] != S[n - i + j]) f = false;
        }
        rep2(j, i + 1, n) {
            if (T[j] != S[j - i]) f = false;
        }
        if (f) {
            cout << YES << endl;
            return 0;
        }
    }
    cout << NO << endl;

    return 0;
}


Measured memory_bytes: 256
def hasMultiWord(W):
    for i in range(len(W)-1):
            if W[i] in W[i+1:]:
                return True
    return False


def isPrevTailEqualNextHead(W):
    for i in range(1, len(W)):
        if W[i-1][-1] != W[i][0]:
            return False
    return True


def main():
    W = []
    N = int(input())
    for _ in range(N):
        W.append(input())
    print(['No', 'Yes'][not hasMultiWord(W) and isPrevTailEqualNextHead(W)])


if __name__ == '__main__':
    main()


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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int rec(int turn, int ix, int x, int y, vector<int>& A, vector<vector<int> >& memo)
{
  int n = A.size();
  if (ix == n) { return abs(x - y); }
  if (memo[turn][ix] != -1) { return memo[turn][ix]; }

  if (turn == 0) {
    // maximize
    int score = -INF;
    for (int i = ix; i < n; ++i) {
      score = max(score, rec(1 - turn, i + 1, A[i], y, A, memo));
    }
    return memo[turn][ix] = score;
  }
  else {
    // minimize
    int score = INF;
    for (int i = ix; i < n; ++i) {
      score = min(score, rec(1 - turn, i + 1, x, A[i], A, memo));
    }
    return memo[turn][ix] = score;
  }
}

int main()
{
  int N, Z, W; scanf("%d %d %d", &N, &Z, &W);
  vector<int> A(N);
  for (int i = 0; i < N; ++i) {
    scanf("%d", &A[i]);
  }

  vector<vector<int>> memo(2, vector<int>(2000 + 5, -1));
  int ans = rec(0, 0, Z, W, A, memo);
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 512