akhauriyash/Code-Regression huggingface dataset:
// #includes {{{
#include <algorithm>
#include <numeric>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <cstring>
#include <cmath>
using namespace std;
// }}}
// pre-written code {{{
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
//#define IFOR(i,it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();++it,++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair
//#define PB push_back
#define CLEAR(c,d) memset((c),(d),sizeof(c))
#define TO_STRING(VariableName) # VariableName
//#define DB(c) cout<<TO_STRING(c)<<"="<<(c)<<endl

#define EXIST(e,s) ((s).find(e)!=(s).end())
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define debug2(x) cerr << #x << " = [";REP(__ind,(x).size()){cerr << (x)[__ind] << ", ";}cerr << "] (L" << __LINE__ << ")" << endl;

#define clr(a) memset((a),0,sizeof(a))
#define nclr(a) memset((a),-1,sizeof(a))
#define pb push_back

typedef long long Int;
typedef unsigned long long uInt;
typedef long double rn;

typedef pair<int,int> pii;
// }}}

const int N = 5;

int median(int a,int b,int c){
	vector<int> v(3);
	v[0]=a;v[1]=b;v[2]=c;
	sort(ALL(v));
	return v[1];
}

int calc(vector<int> a){
	while(a.size()>1){
		vector<int> b(a.size()-2);
		REP(i,b.size()){
			b[i] = median(a[i],a[i+1],a[i+2]);
		}
		a = b;
	}
	return a[0];
}

vector<int> build(int N,int x){
	set<int> s;
	vector<int> ans;
	REP(i,N*2-1)s.insert(i+1);
	if(x==1 or x==N*2-1){
		return ans;
	}
	ans.assign(N*2-1,0);
	REP(i,ans.size())s.insert(i+1);
	if(x==N){
		REP(i,N*2-1){
			ans[i]=i+1;
		}
	}else if(x<N){
		ans[N-1] = x;
		ans[N-2] = x-1;
		s.erase(x);s.erase(x-1);
		REP(i,N*2-1){
			if(i==N-1 or i==N-2)continue;
			ans[i] = *s.begin();
			s.erase(*s.begin());
		}
	}else{
		ans[N-1] = x;
		ans[N] = x+1;
		s.erase(x);s.erase(x+1);
		REP(i,N*2-1){
			if(i==N-1 or i==N)continue;
			ans[i] = *s.begin();
			s.erase(*s.begin());
		}
	}
	/*
	ans[N-1] = x;
	s.erase(x);
	REP(i,N-1){
		int t = *s.begin();
		ans[N-1-1-i] = t;
		s.erase(t);
	}
	REP(i,N-1){
		int t = *s.begin();
		ans[N+i] = t;
		s.erase(t);
	}
	*/
	return ans;
}

//#define TEST

int main(){
#ifndef TEST
	int N,x;
	cin>>N>>x;
	vector<int> ans = build(N,x);
	if(ans.size()==0){
		cout<<"No"<<endl;
	}else{
		cout<<"Yes"<<endl;
		REP(i,ans.size()){
			cout<<ans[i]<<endl;
		}
//		cerr<<"result: "<<calc(ans)<<endl;
	}
#else
	vector<int> a(2*N-1);
	const int M = 2*N-1;
	REP(i,M)a[i] = i+1;
	set<int> s;
	do{
		int t = calc(a);
		if(not EXIST(t,s)){
			cout<<t<<endl;
			REP(i,a.size())cout<<a[i]<<" ";
			cout<<endl;
			s.insert(t);
		}
	}while(next_permutation(ALL(a)));
#endif
	return 0;
}


Measured memory_bytes: 11648
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    from collections import Counter
    n=int(input())
    A=list(Counter(map(int,input().split())).values())
    A.sort()
    m=len(A)
    S=[0]*(m+1) # cumulative distribution
    for i in range(m): S[i+1]=S[i]+A[i]
    # output
    p=n
    i=m
    from bisect import bisect_left
    for k in range(1,n+1):
        while(1):
            # pに対して先にi_pを求めておく
            while(1):
                if(i<=0 or A[i-1]<p): break
                i-=1
            if(S[i]+p*(m-i)>=k*p): break # p<0 or を書く必要はない
            p-=1 # pの条件が真になるまで減らし続ける
        print(p)
resolve()

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

int main() {
	int N,c=0;
	ll w=0;
	cin >> N;
	vector<ll> A(N),B(N),d;

	rep(i,N)
		cin >> A.at(i);
	rep(i,N) {
		cin >> B.at(i);
		if(B.at(i)-A.at(i) > 0) {
			w += B.at(i)-A.at(i);
			++c;
		}
		if(A.at(i)-B.at(i) > 0)
			d.push_back(A.at(i)-B.at(i));
	}

	sort(d.begin(), d.end(), greater<ll>());
	if(w > 0)
		rep(i,d.size()) {
			w -= d.at(i);
			++c;
			if(w <= 0)
				break;
		}

	cout << ((w<=0) ? c : -1) << endl;
}

Measured memory_bytes: 2428
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long A,B,C,D,E,F,G,H,I,J,K,L,M,N,T,W,X,Y;
  string S;
  cin >>  A >> B >> C;
  
  
  cout << C << " " << A << " " << B << endl;
  
  
}

Measured memory_bytes: 256
from collections import deque
  

H,W = map(int, input().split())
s = ["#"*(W+2)]+["#"+input()+"#" for i in range(H)]+["#"*(W+2)]
def bfs(sh,sw):
  if s[sh][sw] == "#":
    return 0
  queue = deque([(sh,sw)])
  dist = [[-1] * (W+1) for i in range(H+1)]
  dist[sh][sw] = 0
  while queue:
    h,w = queue.popleft()
    d = dist[h][w]
    for i in [h-1,h+1]:
      if s[i][w] == "." and dist[i][w] == -1:
        dist[i][w] = d + 1
        queue.append((i,w))
    for j in [w-1,w+1]:
      if s[h][j] == "." and dist[h][j] == -1:
        dist[h][j] = d + 1
        queue.append((h,j))
          
  max_dist = 0
  for i in dist:
    max_dist = max(max_dist,max(i))
  return max_dist
      

ans = 0          
for i in range(1,H+1):
  for j in range(1,W+1):
    now = bfs(i,j)
    ans = max(ans, now)
print(ans)

Measured memory_bytes: 3316
/* be name Khoda */
#include <bits/stdc++.h>
using namespace std;

const int N = 100 * 1001, inf = 1e9 + 7;
int h[N], dp[N], n, k;

int main() {
	cin >> n;
	k = 2;
	for (int i = 0; i < n; i++) {
		cin >> h[i];
		dp[i] = inf;
	}
	dp[n - 1] = 0;
	for (int i = n - 2; 0 <= i; i--)
		for (int j = 1; j <= k; j++)
			if (i + j < n)
				dp[i] = min(dp[i], dp[i + j] + abs(h[i + j] - h[i]));
	cout << dp[0] << endl;
}
		
	

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

struct Point {
    double x, y;

    Point() {}
    Point(double x, double y): x(x), y(y) {}

    Point operator+(const Point &A) const {
        return Point(x + A.x, y + A.y);
    }

    Point operator-(const Point &A) const {
        return Point(x - A.x, y - A.y);
    }

    void normalize() {
        double d = sqrt(x * x + y * y);
        x /= d;
        y /= d;
    }
};

struct Line {
    double a, b, c;
};

Point p[3];

double dist(Point &A, Point &B) {
    double dx = A.x - B.x;
    double dy = A.y - B.y;

    return sqrt(dx * dx + dy * dy);
}

Line getLine(Point A, Point B) {
    Line ans;
    ans.a = A.y - B.y;
    ans.b = B.x - A.x;
    ans.c = ans.a * A.x + ans.b * A.y;

    return ans;
}

double det2(double a11, double a12, double a21, double a22) {
    return a11 * a22 - a12 * a21;
}

Point getLineIntersection(Line l1, Line l2) {
    double detS = det2(l1.a, l1.b, l2.a, l2.b);
    double detX = det2(l1.c, l1.b, l2.c, l2.b);
    double detY = det2(l1.a, l1.c, l2.a, l2.c);

    return Point(detX / detS, detY / detS);
}

Line getBisec(Point O, Point A, Point B) {
    Point OA = A - O;
    Point OB = B - O;

    OA.normalize();
    OB.normalize();

    Point C = OA + OB + O;

    return getLine(O, C);
}

double distPointToLine(Point A, Line l) {
    return fabs(l.a * A.x + l.b * A.y - l.c) / sqrt(l.a * l.a + l.b * l.b);
}

int main() {

    for(int i = 0; i < 3; ++i)
        scanf("%lf %lf\n", &p[i].x, &p[i].y);

    double maxD = max(dist(p[0], p[1]), max(dist(p[0], p[2]), dist(p[1], p[2])));
    
    Point O = getLineIntersection(getBisec(p[0], p[1], p[2]), getBisec(p[1], p[0], p[2]));

    double R = distPointToLine(O, getLine(p[0], p[1]));

    // assert(fabs(distPointToLine(O, getLine(p[0], p[1])) - distPointToLine(O, getLine(p[0], p[2]))) < 1e-7);

    printf("%.20f\n", maxD / (2 * R + maxD) * R);

    return 0;
}

Measured memory_bytes: 256
import sys
def q(a,h):
 d[a]=str(h)
 for b in t[a]:q(b,h+1)
t,p,d={},{},{}
input()
for e in sys.stdin:
 e=e.split()
 t[e[0]]=e[2:]
 for i in e[2:]:p[i]=e[0]
r=(set(t)-set(p)).pop()
p[r]='-1'
q(r,0)
print('\n'.join(f"node {i}: parent = {p[i]}, depth = {d[i]}, {'root'if'-1'==p[i]else'internal node'if t[i]else'leaf'}, [{', '.join(t[i])}]"for i in map(str,sorted(map(int,t)))))


Measured memory_bytes: 65320
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <utility>
#include <map>
#include <climits>
#include <vector>
#include <set>
#include <string>
#include <numeric>

#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
//#define int long long
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<pair<int, int>> vii;
const int N = 2 * (1e5 + 1);
const int INF = 1e9 + 5;
const long long MOD = 1e9 + 7;

int32_t main() {
    FAST_IO;
    int W, a, b;
    cin >> W >> a >> b;
    cout << max(abs(a - b) - W, 0);
    return 0;
}


Measured memory_bytes: 256
n = input()
mod = [0]*2019
mod[0] += 1
T = 0
d = 1 # 桁数
for i, s in enumerate(n[::-1]):
  T += int(s) * d
  T %= 2019
  d = (d * 10) % 2019
  mod[T] += 1
  
res = 0  
for m in mod:
  res += m*(m-1)/2
print(int(res))

Measured memory_bytes: 9368
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    int cnt = 0;
    sort(a.begin(), a.end());
    vector<bool> ans(a[n - 1]+1, true);
    for (int i = 0; i < n; i++)
    {
        if(ans[a[i]])
        {
            if(a[i]!=a[i+1])
            cnt++;
            for (int j = 1; j * a[i] <= a[n - 1]; j++)
            {
                ans[j * a[i]] = false;
            }
        }
    }
    for (int i = 0; i < n; i++)
    {
        if(ans[a[i]])
        {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

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

using namespace std;

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

    int a, b;
    cin >> a >> b;
    if(a == b){
        cout << "Yes" << endl;
    }
    else 
        cout << "No" << endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define VI vector<int>
#define VVI vector<vector<int>>
#define UM unordered_map
#define MP map
#define ST set
#define US unordered_set
#define V vector
#define S string
#define D deque
#define L list
#define Q queue
#define PQ priority_queue
#define DB double
#define LDB long double
#define FOR(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define FFOR(i, n) for (int(i) = 0; (i) <= (n); ++(i))
#define RFOR(i, n) for (int(i) = (n)-1; (i) >= 0; --(i))
#define all(v) (v).begin(), (v).end()

const int dr[] = {0, 1, 0, -1};
const int dc[] = {1, 0, -1, 0};

int nxt()
{
    int n;
    cin >> n;
    return n;
}

LL llnxt()
{
    LL l;
    cin >> l;
    return l;
}

LDB ldbnxt()
{
    LDB n;
    cin >> n;
    return n;
}

DB dbnxt()
{
    DB n;
    cin >> n;
    return n;
}

void bfs(VVI &graph, int start)
{
    int n = graph.size();
    Q<int> q;
    V<bool> visited(n);
    q.push(start);
    visited[start] = true;
    while (not q.empty())
    {
        auto curr = q.front();
        q.pop();
        for (auto i : graph[curr])
        {
            if (not visited[i])
            {
                q.push(i);
                visited[i] = true;
            }
        }
    }
}

int main()
{
    int n;
    cin >> n;
    LL ans = 0;
    for (int i = 1; i <= n; ++i)
    {
        int upper = n / i;
        ans += (LL)upper * (upper + 1) / 2 * i;
    }
    cout << ans;
}

Measured memory_bytes: 3640
//keshavs first usaco solve :)
 
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) throws FileNotFoundException {
		// TODO Auto-generated method stub
 
		Scanner sc = new Scanner(System.in);
		double r = sc.nextInt();
      	System.out.println(r*Math.PI*2);
      
	}
 
}

Measured memory_bytes: 35884
/**
*    author:  souzai32
*    created: 02.08.2020 15:36:30
**/

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {

    int h,w;
    cin >> h >> w;
    char a;
    int count=0;
    rep(i,h*w){
        cin >> a;
        if(a=='#') count++;
    }

    if(count==h+w-1) cout << "Possible" << endl;
    else cout << "Impossible" << endl;

    return 0;
}

Measured memory_bytes: 3604
#include<iostream>
int main() {
	double dol = 0.0;
	int a;
	scanf("%d", &a);
	int *s;
	s = (int*)malloc(sizeof(int)*(a + 1));
	if (s == NULL) return -1;

	for (int x = 0; x < a; x++) {
		scanf("%d", s+x);
		//printf("%d ", *(s+x));
		dol += (double)(1.0/ *(s+x)*1.0);
		//printf("\n%f\n", dol);
	}
	dol = 1.0 / dol;
	printf("%f", dol);
	free(s);
	scanf("\n%d", &a);
	return 0;
}

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

using ll = long long;
#define debug(x) cerr << #x << ": " << x << endl;

int main() {
   string s;
   cin >> s;
   if (regex_match(s, regex("A?KIHA?BA?RA?")) ) {
      cout << "YES" << endl;
   } else {
      cout << "NO" << endl;
   }

   return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<algorithm>
#include <vector>
#include<cstdio>
#include <numeric>
#include <queue>
#include <list>
#include <math.h>
#include <stdio.h>
#include <math.h>
#include <errno.h>
#include <fenv.h>
#include <iomanip>
#include <cassert>
#include <algorithm>
#include <functional>
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
long long mod=1000000007;
int main(){
    long long N;cin>>N;
    vector<char>C(50);
    int a=0;
    vector<char>A(26);
    for(char moji='a'; moji<='z'; ++moji){
        A[moji-'a']=moji;
    }
    for(int i=0;i<50;i++){
        if(N>26)a+=1;
        int w=N%26;
        if(w==0)w=26;
      
        C[i]=A[w-1];
        N-=w;
        N/=26;


    } 
    string ans;
    for(int i=a;i>=0;i--){
        ans+=C[i];

    }   
    cout<<ans<<endl;





}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int h,w,s,u[35][35],rui[35][35],sum;
//(max,min_sum)
P dp[35][35][35][35];
P rec(int a,int b,int c,int d){
	if(dp[a][b][c][d].sc != -INF) return dp[a][b][c][d];
	if(rui[b][d]-rui[a-1][d]-rui[b][c-1]+rui[a-1][c-1] >= sum-s){
		dp[a][b][c][d] = mp(1,(rui[b][d]-rui[a-1][d]-rui[b][c-1]+rui[a-1][c-1]));
	}
	else return mp(-INF,-INF);
	for(int i=a;i<b;i++){
		P f = rec(a,i,c,d), s = rec(i+1,b,c,d);
		dp[a][b][c][d] = max(dp[a][b][c][d],mp(f.fi+s.fi,min(f.sc,s.sc)));
	}
	for(int i=c;i<d;i++){
		P f = rec(a,b,c,i), s = rec(a,b,i+1,d);
		dp[a][b][c][d] = max(dp[a][b][c][d],mp(f.fi+s.fi,min(f.sc,s.sc)));
		
	}
	return dp[a][b][c][d];
}
int main(){
	while(1){
		cin>>h>>w>>s;
		if(h==0&&w==0&&s==0) return 0; sum = 0;
		for(int i=1;i<=h;i++) for(int j=1;j<=w;j++) cin>>u[i][j],sum+=u[i][j];
		for(int i=1;i<=h;i++) for(int j=1;j<=w;j++) rui[i][j]=u[i][j]+rui[i-1][j]+rui[i][j-1]-rui[i-1][j-1];
		for(int i=1;i<=h;i++) for(int ii=i;ii<=h;ii++)
		for(int j=1;j<=w;j++) for(int jj=j;jj<=w;jj++) dp[i][ii][j][jj] = mp(-INF,-INF);
		P ans = rec(1,h,1,w);
		cout<<ans.fi<<" "<<s-(sum-ans.sc)<<endl;
	}
}


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

using namespace std;

int main()
{
    int N;
    cin >> N;
    string S;
    cin >> S;
    int left = 0, right = 0;
    bool flag = true;
    for (int i = 0; i < S.size(); ++i)
    {
        if (flag)
        {
            if(S[i] == ')') cout << '(';
            else{
                flag = false;
                ++left;
            }
        }
        else
        {
            if (S[i] == '(') ++left;
            else ++right;
            if(left == right) flag = true;
        }
    }

    if (left < right)
    {
        for (int i = 0; i < right - left; ++i)
        {
            cout << '(';
        }
        cout << S;
    }
    else
    {
        cout << S;
        for (int i = 0; i < left - right; ++i)
        {
            cout << ')';
        }
    }
    cout << endl;
}


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

vector<int>c;

void bfs(vector<vector<pair<int, int> > >G){
    vector<int>vc(G.size());    //親と繋がる辺の色
    queue<int>que;
    que.push(0);
    while(!que.empty()){
        int v = que.front();
        que.pop();
        int color = 1;
        rep(i, G[v].size()){
            int nv = G[v][i].second;
            int cptr = G[v][i].first;
            if(vc[v] == color)  color++;
            vc[nv] = color;
            c[cptr] = color;
            c[0] = max(c[0], color);
            que.push(nv);
            color++;
        }
    }
}

int main(){
    int n;  cin >> n;
    vector<vector<pair<int, int> > >G(n);
    c.resize(n);
    rep(i, n-1){
        int a,b;
        cin >> a >> b;
        --a;    --b;
        G[a].emplace_back(i+1, b);
    }
    bfs(G);
    rep(i, n)   printf("%d\n", c[i]);
}


Measured memory_bytes: 9344
n,k = map(int, input().split())
a = list(map(int, input().split()))

root = [1]

for i in range(n):
    t = a[root[i]-1]
    if (t == 0):
        break
    a[root[i]-1] = 0
    root.append(t)
x =  root.index(root[-1])
bef = root[0:x]
#print(bef)
loop = root[x:-1]
#print(loop)
#print(root)

if (k < len(bef)):
    print(bef[k])
else:
    p = ((k - len(bef)) % len(loop))
    #print(p)
    print(loop[p])

Measured memory_bytes: 32408
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void){
    int n,p[30];
    int yes=0;
    scanf("%d",&n);
    for(int count=1;count<=n;count++){
        scanf("%d",&p[count]);
    }
    for(int count=2;count<n;count++){
        if(((p[count-1]<p[count])&&(p[count]<p[count+1]))||((p[count-1]>p[count])&&(p[count]>p[count+1]))){yes++;}
    //printf("yes=%d\n",yes);
    }
 
    printf("%d",yes);
}


Measured memory_bytes: 128
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")

//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")

// -------------------</optimizations>--------------------
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define d long double
#define pii pair<int,int>
#define pb push_back
#define cases int tc;cin>>tc;while(tc--)
#define N 100003
#define M 103
#define inf 1e15
#define Arena ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//int mod=1e9+7;
//int mod=998244353;
int dp[N];

signed main()
{
    Arena
    
    fill(dp,dp+N,inf);
    dp[0]=0;
    int n,W;
    cin>>n>>W;
    int w,v,i,j;
    for(i=1;i<=n;++i)
    {
        cin>>w>>v;
        for(j=N-3;j>=v;--j)
        {
            dp[j]=min(dp[j],dp[j-v]+w);
        }
    }
    
    for(j=N-3;j>=0;--j)
    {
        if(dp[j]<=W)
        {
            cout<<j;
            return 0;
        }
    }
       
    
    
    return 0;
}


Measured memory_bytes: 1024
N,K = map(int, input().split())
h = []
for i in range(N):
  tmp = int(input())
  h.append(tmp)
h.sort()

ans = h[N-1]
for i in range(0, N-K+1):
  tmp = h[i+K-1] - h[i]
  ans = min(ans, tmp)
print(ans)

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

using namespace std;

#define INF 1000000007
#define LINF 1000000000000000007

typedef long long Int;
typedef pair<Int,Int> P;

Int gcd(Int x, Int y){
	if(y == 0) return x;
	return gcd(y, x%y);
}

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

bool sosuu(Int x){
	bool b = 1;
	if(x == 1) b = 1;
	for(int i = 2; i * i <= x; i++){
		if(x % i == 0){b = 0; break;}
	}
	return b;
}

int n, c[100000] = {0};

int main(){
	cin >> n;
	bool b = 1;
	for(int i = 0; i < n; i++){
		int a;
		cin >> a;
		c[a]++;
		if(c[a] > 2) b = 0;
		if(a == 0 && (c[a] > 1 || n % 2 == 0)) b = 0;
		if(a > n) b = 0;
		if(n % 2 && a % 2 || n % 2 == 0 && a % 2 == 0) b = 0;
	}
	if(b){
		Int ans = 1;
		for(int i = 0; i < n/2; i++){
			ans *= 2;
			ans %= INF;
		}
		cout << ans << endl;
	}
	else cout << 0 << endl;
	
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
using namespace std;
struct Card{
    char suit, value;
};
void BubbleSort(struct Card A[],int N)
{
    for(int i=0;i<N;i++)
    {
        for(int j=N-1;j>i;j--)
        {
            if(A[j].value < A[j-1].value)
            {
                Card temp = A[j];
                A[j] = A[j-1];
                A[j-1] = temp;
            }
        }
    }
}
void SelectionSort(struct Card A[],int N)
{
    for(int i=0; i<N; i++)
    {
        int minj = i;
        for(int j=i+1; j<N;j++)
        {
            if(A[j].value < A[minj].value)
                minj = j;
        }
        Card temp = A[i];
        A[i] = A[minj];
        A[minj] = temp;
    }
}
void print(struct Card A[], int N)
{
    for(int i=0; i<N; i++)
    {
        if(i) cout<<" ";
        cout<<A[i].suit<<A[i].value;
    }
    cout<<endl;
}
bool isStable(struct Card C1[], struct Card C2[], int N)
{
    for(int i=0;i<N;i++)
    {
        if(C1[i].suit != C2[i].suit)
            return false;
    }
    return true;
}
int main()
{
    Card C1[100],C2[100];
    int N;
    //char ch;
    
    cin>>N;
    for(int i=0; i<N; i++)
    {
        cin>>C1[i].suit>>C1[i].value;
        C2[i] = C1[i];
    }
    BubbleSort(C1,N);
    SelectionSort(C2,N);
    
    print(C1,N);
    cout<<"Stable"<<endl;
    print(C2,N);
    if(isStable(C1,C2,N))
        cout<<"Stable"<<endl;
    else
        cout<<"Not stable"<<endl;
        
    return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll gcd(ll x,ll y){
    if(x>y)swap(x,y);
    if(y%x==0)return x;
    return gcd(x,y%x);
};
int main(){
    int k;
    cin >> k;
    //cout << "OK" << endl;
    ll sum=0;
    for(int i=1; i<=k; i++){
        for(int j=1; j<=k; j++){
            for(int m=1; m<=k; m++){
                ll a=gcd(i,j);
                ll b=gcd(a,m);
                sum+=b;
            }
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <math.h>
#define ll long long 
using namespace std;

int main() {
    ll n,r1,r2,v1,v2;
    cin>>n;
    v1=n/500;
    r1=n%500;
    v2=r1/5;
    cout<<(v1*1000)+(v2*5)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,l,r) for(ll i=(l);i<(r);i++)
int main(){
    int a;
    cin>>a;
    rep(i,1,6)if(a==pow(10,i)){
        cout<<10;
        return 0;
    }
    cout<<a/100000+a/10000%10+a/1000%10+a/100%10+a/10%10+a%10;
}

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

{
int n;
cin>>n;
vector<int>  a(n);
for(int i=0;i<n;i++) cin>>a[i];
if(*min_element(a.begin(),a.end()) != 1) {
	cout<<"-1";
	return 0;
}
vector<int> p;
int k=1;
for(int i=0;i<n;i++)
{  int j=i;
	for( j=i;j<n;j++)
	{
		if(a[j]==k)
		{  k++;
			p.push_back(j);
			
			break;
		}
	}
	i=j;
	
}
//for(auto x : p) cout<<x<<' ';
cout<<n-p.size()<<endl;
}

Measured memory_bytes: 5072
#include <bits/stdc++.h>
#define endl '\n'

//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

using namespace std;
template<class T, class T2> inline int chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline int chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const int MAXN = (1 << 20);

int n;
map<int, int> o, e;

void read()
{
	cin >> n;
	for(int i = 0; i < n; i++)
	{
		int x;
		cin >> x;
		if(i % 2 == 0) o[x]++;
		else e[x]++;
	}
}

void solve()
{
	vector<pair<int, int> > li1, li2;
	li1.push_back({0, -32132});
	li2.push_back({0, -21321});

	for(auto it: o) li1.push_back({it.second, it.first});
	for(auto it: e) li2.push_back({it.second, it.first});

	sort(li1.begin(), li1.end());
	sort(li2.begin(), li2.end());

	int ans = n;
	for(auto it: li1)
	{
		int c_ans = n;
		c_ans -= it.first;

		if(it.second == li2.back().second) c_ans -= li2[li2.size() - 2].first;
		else c_ans -= li2[li2.size() - 1].first;

		chkmin(ans, c_ans);
	}

	cout << ans << endl;
}

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

	read();
	solve();
	return 0;
}



Measured memory_bytes: 6140
def main():
    N = int(input())
    A = list()
    B = list()
    for _ in range(N):
        a, b = list(map(int, input().split(' ')))
        A.append(a)
        B.append(b)
    A.sort()
    B.sort()
    if N % 2 == 1:
        print(B[(N - 1)//2] - A[(N - 1)//2] + 1)
    else:
        mid_a_2 = A[N // 2] + A[(N // 2) - 1]
        mid_b_2 = B[N // 2] + B[(N // 2) - 1]
        print(mid_b_2 - mid_a_2 + 1)


if __name__ == '__main__':
    main()

Measured memory_bytes: 25564
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  int q,i,rev=0;
  char p;
  cin>>s>>q;
  vector<int> t(q),f(q,0);
  vector<char> c(q);
  for(i=0;i<q;i++){
    scanf("%d",&t[i]);
    if(t[i]==1){
      rev++;
    }else{
      scanf("%d",&f[i]);
      scanf(" %c",&c[i]);
      if((rev%2+f[i])%2==1){
        s.insert(s.begin(),c[i]);
      }else{
        s.push_back(c[i]);
      }
    }
  }if(rev%2==0){
    cout<<s<<"\n";
  }else{
    reverse(s.begin(),s.end());
    cout<<s<<"\n";
  }
}

Measured memory_bytes: 2692
#include <cstdio>
#include <vector>
#include <map>
#include <numeric>

using namespace std;

vector<int> parentR, urankR, parentT, urankT;

int rootR(int x) { return (parentR.at(x) == x ? x: parentR.at(x) = rootR(parentR.at(x))); }

bool in_sameR(int x, int y) { return rootR(x) == rootR(y); }
void uniteR(int x, int y) {
    x = rootR(x);
    y = rootR(y);
    if (x != y) {
        if (urankR.at(x) < urankR.at(y)) parentR.at(x) = y;
        else {
            parentR.at(y) = x;
            if (urankR.at(x) == urankR.at(y)) ++(urankR.at(x));
        }
    }
}

int rootT(int x) { return (parentT.at(x) == x ? x: parentT.at(x) = rootT(parentT.at(x))); }

bool in_sameT(int x, int y) { return rootT(x) == rootT(y); }
void uniteT(int x, int y) {
    x = rootT(x);
    y = rootT(y);
    if (x != y) {
        if (urankT.at(x) < urankT.at(y)) parentT.at(x) = y;
        else {
            parentT.at(y) = x;
            if (urankT.at(x) == urankT.at(y)) ++(urankT.at(x));
        }
    }
}

int main() {
    int n, k, l, p, q;
    map< pair<int, int>, int> d;
    scanf("%d%d%d", &n, &k, &l);

    parentR.resize(n);
    urankR.resize(n);
    iota(parentR.begin(), parentR.end(), 0);
    parentT.resize(n);
    urankT.resize(n);
    iota(parentT.begin(), parentT.end(), 0);

    for (int i = 0; i < k; ++i) {
        scanf("%d%d", &p, &q);
        uniteR(--p, --q);
    }
    for (int i = 0; i < l; ++i) {
        scanf("%d%d", &p, &q);
        uniteT(--p, --q);
    }
    for (int i = 0; i < n; ++i) {
        ++d[{rootR(i), rootT(i)}];
    }
    for (int i = 0; i < n; ++i) printf("%d\n", d.at({rootR(i), rootT(i)}));
    return 0;
}


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

int main(){
  string S;
  cin >> S;
  string devide[4] ={"dream","dreamer","erase","eraser"};
  reverse(S.begin(),S.end());
  for(int i=0;i<4;i++){
    reverse(devide[i].begin(),devide[i].end());
  }
  
  bool can=true;
    for(int i=0;i<S.size();){
      bool can2=false;
      for(int j=0;j<4;j++){
        if(S.substr(i,devide[j].size())==devide[j]){
          can2=true;
          i+=devide[j].size();
          break;
        }
      }
      if(!can2){
        can=false;
        break;
      }
    }
  if(can){
    cout << "YES" <<endl;
  }
  else{
    cout  << "NO" <<endl;
  }
}


    

Measured memory_bytes: 3768
#include <iostream>
#include <iomanip>
#include <math.h>

using namespace std;

double x_1, x_2, y_1, y_2;
double distances;

double distance(double x_1, double y_1, double x_2, double y_2);

int main(void){
    
    cin >> x_1 >> y_1 >> x_2 >> y_2;
    distances = distance(x_1, y_1, x_2, y_2);
    cout << fixed << setprecision(8) << distances;
    
    return 0;
    
}

double distance(double x_1, double y_1, double x_2, double y_2){
    return sqrt((x_2 - x_1) * (x_2 - x_1) + (y_2 - y_1) * (y_2 - y_1));
}

Measured memory_bytes: 3272
#include <iostream>
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))

#include <cstring>
#include <cassert>
#include <queue>
#include <cstdio>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <set>

using namespace std;

inline int getInt(){ int s; scanf("%d", &s); return s; }

const int mx = 1024;
int g[mx][mx];
const int b = mx / 2;

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

int dp[mx][mx];

template<int m>
class Prime{
  std::vector<bool> p;
  std::vector<int> ps;
public:
  Prime(){
    p = std::vector<bool>(m,true);
    assert(m>1);
    p[0]=p[1]=false;
    for(int i=4;i<m;i+=2)
      p[i]=false;
    ps.push_back(2);
    for(int i=3;i<m;i+=2){
      if(p[i]){
        ps.push_back(i);
        for(int j=i+i;j<m;j+=i)
          p[j]=false;
      }
    }
  }

  bool isPrime(int n){
    assert(m>n);
    return p[n];
  }

  int operator [] (int n){
    if(n<ps.size()) return ps[n];
    else return 0;
  }

  int size(){
    return ps.size();
  }
};

int main(){
  Prime<mx * mx> prime;

  {
    int x = b;
    int y = b;

    int cnt  = 0;
    int dist = 1;
    int t    = 0;
    int dir = 0;

    for(int i = 1; i <= 1000 * 1000; i++){
      g[y][x] = i;
      y += dy[dir]; x += dx[dir];

      if(++cnt == dist){
        dir = (dir + 1) % 4;
        cnt = 0;
        if(t == 1) dist++;
        t = !t;
      }
    }

    /*
    for(int i = b - 3; i <= b + 3; i++){
      for(int j = b - 3; j <= b + 3; j++){
        printf("%3d", g[i][j]);
      }
      puts("");
    }
    */
  }

  while(true){
    const int n = getInt();
    const int m = getInt();
    if(n + m == 0) break;

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

    REP(i,mx) REP(j,mx) if(g[i][j] == m) dp[i][j] = prime.isPrime(m) ? 1 : 0;

    pair<int, int> ans = make_pair(0, 0);
    REP(i,mx) REP(j,mx) if(g[i][j] <= n && dp[i][j] >= 0){
      if(prime.isPrime(g[i][j])) ans = max(ans, make_pair(dp[i][j], g[i][j]));
      REP(k,3){
        const int ii = i + 1;
        const int jj = k - 1 + j;
        if(ISIN(ii, jj, mx, mx)){
          dp[ii][jj] = max(dp[ii][jj], dp[i][j] + (prime.isPrime(g[ii][jj]) ? 1 : 0));
        }
      }
    }

    /*
    for(int i = b - 3; i <= b + 3; i++){
      for(int j = b - 3; j <= b + 3; j++){
        printf("%3d", dp[i][j]);
      }
      puts("");
    }
    */

    printf("%d %d\n", ans.first, ans.second);
  }

  return 0;
}

Measured memory_bytes: 9836
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,K;
    cin>>N>>K;
    vector<int>v(N);
    int h;
    for(int i=0;i<N;i++){
        scanf("%d",&h);
        v[i]=h;
    }
    sort(v.begin(),v.end());
    int sub=1000000000;
    int c;
    for(int i=0;i<N-K+1;i++){
        c=v[i+K-1]-v[i];
        if(c<sub){sub=c;}
    }
    cout<<sub<<endl;
}

Measured memory_bytes: 640
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<functional>
#include<queue>
#include<stack>
#include<math.h>
#define INF 999999
#define EPS 1.0e-6

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int main()
{
	int n, m;
	int k = 0;
	
	while (1) {
		cin >> n;
		if (n == 0)break;
		char a, b;
		map<char, char> mp;
		for (int i = 0; i < n; i++) {
			cin >> a >> b;
			mp[a] = b;
		}

		cin >> m;

		for (int i = 0; i < m; i++) {
			cin >> a;
			auto itr = mp.find(a);
			if (itr != mp.end()) {
				cout << mp[a];
			}
			else cout << a;
		}
		cout << endl;
	}
	
	return 0;
}

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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
 
using namespace std;
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

int n;
string s;
 
int main() {
	ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("in", "r", stdin);
#endif
	
	cin >> n;
	cin >> s;
	for (int i = 0; i < s.size(); ++i) {
		int now = s[i] - 'A';
		now = (now + n) % 26;
		char ne = char('A' + now);
//		cerr << s[i] << " " << ne << endl;
		s[i] = ne;
	}
	cout << s << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}

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

#define MOD 1000000007
using namespace std;

int main(void)
{
    int n, m;
    cin >> n >> m;
    int a[n][m] = {};
    char cd;
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < m; j++)
        {
            cin >> cd;
            if(cd == '.')
            {
                a[i][j] = 1;
            }
            else if(cd == '#')
            {
                a[i][j] = 0;
            }
        }
    }

    int ans[n][m] = {};

    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < m; j++)
        {
            if(a[i][j] != 0)
            {
                if(i == 0 && j != 0)
                {
                    ans[i][j] = ans[i][j - 1];
                }
                else if(i != 0 && j == 0)
                {
                    ans[i][j] = ans[i - 1][j];
                }
                else if(i == 0 && j == 0)
                {
                    ans[i][j] = 1;
                }
                else
                {
                    ans[i][j] = ans[i - 1][j] + ans[i][j - 1];
                }
                ans[i][j] %= MOD;
            }
            else
            {
                a[i][j] = 0;
            }
        }
    }

    /*for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < m; j++)
        {
            cout << ans[i][j] << " ";
        }
        cout << endl;
    }
    cout << endl;*/

    cout << ans[n - 1][m - 1] << endl;
    return 0;
}


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

typedef vector<int> vi;
#define rep(i, n) for(int i=0; i<n; i++)

static const int INF = 1E9;
static const int dx[] = {0, 1, 0, -1};
static const int dy[] = {1, 0, -1, 0};
int w, h;
int s[55][55];
int c[5];
bool used[55][55][5];

inline bool check(int hx, int hy){ return 0 <= hx && hx < h && 0 <= hy && hy < w; }

int main()
{
  while(cin >> w >> h, w){
    rep(i, h) rep(j, w) rep(k, 5) used[i][j][k] = false;
    rep(i, h) rep(j, w) cin >> s[i][j];
    rep(i, 4) cin >> c[i];

    priority_queue<vi, vector<vi>, greater<vi> > que;
    vi tmp(4);
    tmp[0] = 0, tmp[1] = 0, tmp[2] = 0, tmp[3] = 0;
    que.push(tmp);
    while(!que.empty()){
      vi here = que.top();  que.pop();
      int cost = here[0];
      int hd = here[1];
      int hx = here[2];
      int hy = here[3];
      if(hx == h - 1 && hy == w - 1){
        cout << cost << endl;
        break;
      }
      if(used[hx][hy][hd]) continue;
      used[hx][hy][hd] = true;
      rep(k, 4){
        int nd = (hd + k) % 4;
        int nx = hx + dx[nd];
        int ny = hy + dy[nd];
        if(!check(nx, ny)) continue;
        tmp[0] = cost + (s[hx][hy] == k ? 0 : c[k]);
        tmp[1] = nd, tmp[2] = nx, tmp[3] = ny;
        que.push(tmp);
      }
    }
  }

  return 0;
}

Measured memory_bytes: 1452
#include <bits/stdc++.h>
#define vsort(v) sort(v.begin(), v.end())
#define rep(i, n) for(int i = 0; i < n; i++)
#define MOD 1000000007
#define PI 3.141592
typedef long long ll;
using namespace std;
int main()
{
	double a, b, x; cin >> a >> b >> x;
  	if (2 * x <= a * a * b) {
    	cout << fixed << setprecision(10) << atan(a * b * b / (2 * x)) * 180 / PI << endl;
    } else {
    	cout << fixed << setprecision(10) << atan(2 * (a * a * b - x) / (a * a * a)) * 180 / PI << endl;
    }
}

Measured memory_bytes: 256
def bubble_sort(arr)
  count = 0
  changed = true

  while changed
    changed = false
    (arr.size - 1).downto(1) do |i|
      if arr[i] < arr[i-1]
        arr[i], arr[i-1] = arr[i-1], arr[i]
        changed = true
        count += 1
      end
    end
  end

  count
end

n = gets.to_i
arr = gets.split.map(&:to_i)
count = bubble_sort(arr)
puts arr.join("\s")
puts count

Measured memory_bytes: 8676
main = do
 sa<-getLine
 sb<-getLine
 sc<-getLine
 putStrLn $ f sa sb sc 'a'
 
f [] y z 'a' = "A"
f x [] z 'b' = "B"
f x y [] 'c' = "C"
f (x:xs) y z 'a' = f xs y z x
f x (y:ys) z 'b' = f x ys z y
f x y (z:zs) 'c' = f x y zs z


Measured memory_bytes: 508
import numpy as np
import sys
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

N,T = inpl()
dp = np.zeros((6001),int)
ABs = [inpl() for _ in range(N)]
ABs.sort()

for A,B in ABs:
    dp[A:T+A] = np.maximum(dp[A:T+A], dp[:T]+B)
    # for i in reversed(range(A,T+A)):
    #     dp[i] = max(dp[i-A] + B, dp[i])


print(max(dp))


Measured memory_bytes: 13044
using System;
using System.Collections.Generic;
    class Program
    {
        static void Main()
        {
            var num = int.Parse(Console.ReadLine());
            var vle = Console.ReadLine().Split(' ');
            var cst = Console.ReadLine().Split(' ');
            int[] vleArray = Array.ConvertAll<string, int>(vle, delegate (string value) { return int.Parse(value); });
            int[] cstArray = Array.ConvertAll<string, int>(cst, delegate (string value) { return int.Parse(value); });
            var output = 0;
            for (int i = 0; i < num; i++)
            {
                var dif = vleArray[i] - cstArray[i];
                if (dif > 0)
                {
                    output = output + dif;
                }
            }
            Console.WriteLine(output);
            Console.ReadLine();
        }
    }


Measured memory_bytes: 11092
H, W = map(int, input().split())
ans = []

if H % 3 == 0:
    ans.append(0)
else:
    ans.append(W)

s1 = [H * (W // 3), H // 2 * (W - W // 3), (H // 2 + H % 2) * (W - W // 3)]
s2 = [H * (W // 3 + 1), H // 2 * (W - W // 3 - 1), (H // 2 + H % 2) * (W - W // 3 - 1)]

ans.append(min(max(s1) - min(s1), max(s2) - min(s2)))

H, W = W, H

if H % 3 == 0:
    ans.append(0)
else:
    ans.append(W)

s1 = [H * (W // 3), H // 2 * (W - W // 3), (H // 2 + H % 2) * (W - W // 3)]
s2 = [H * (W // 3 + 1), H // 2 * (W - W // 3 - 1), (H // 2 + H % 2) * (W - W // 3 - 1)]

ans.append(min(max(s1) - min(s1), max(s2) - min(s2)))

print(min(ans))

Measured memory_bytes: 3064
import sys
import math


# \n
def input():
    return sys.stdin.readline().rstrip()


def main():
    N=int(input())
    P=list(map(float,input().split()))

    dp=[0]*(N+1)
    dp[0]=1
    for j in range(N):
        p =P[j]
        for i in range(N, -1, -1):

            dp[i] = dp[i]*(1-p)
            if i ==0:
                continue
            dp[i] +=dp[i-1] *p

    print(sum(dp[N//2+1:]))






if __name__ == "__main__":
    main()


Measured memory_bytes: 70924
import numpy as np
N,K = map(int,input().split())
p = np.array(list(map(int,input().split())))
e = (p+1) / 2.0
s = np.zeros(len(e)+1)
s[1:] = np.cumsum(e)
f = s[K:] - s[:-K]

print(np.max(f))

Measured memory_bytes: 33904
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define MOD 1000000007 //S(vector).size()
using namespace std;
typedef long long ll;

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

  int ans = MOD;
  vector<int> c_E(n, 0), c_W(n, 0);
  for(int i = 0; i < n; i++){
    if(s[i] == 'W') c_W[i] = 1;
    if(i != 0)c_W[i] += c_W[i - 1];
  }
  for(int i = n - 1; i >= 0; i--){
    if(s[i] == 'E') c_E[i] = 1;
    if(i != n - 1) c_E[i] += c_E[i + 1];
  }
  rep(i, n){
    int tmp = c_E[i] + c_W[i] - 1;
    ans = min(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}


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

#define itn long long
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)(n);i>=0;--i)
#define debug(x) cout << #x << "=" << (x) << endl;
const ll MOD=1e9+7;

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;}
template<typename T> void fail(T v){cout << v << endl;exit(0);}
//template end

void solve(){
  int N;
  cin>>N;
  map<string,int> m;
  rep(i,N){
    string s;
    cin>>s;
    m[s]=1;
  }
  int M;
  cin>>M;
  int st=1;
  string r[]={"Unknown ","Opened by ","Closed by "};
  rep(i,M){
    string s;
    cin>>s;
    if(m[s]){cout<<r[st]<<s<<endl;st^=3;}
    else cout<<r[0]<<s<<endl;
  }
}
 
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  solve();
  return 0;
}


Measured memory_bytes: 3260
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
#define chmax(x,y) (x = max(x, y))
void solve(); int main() { solve(); return 0; }

void solve() {
  string s; cin >> s;
  if (s[2]==s[3] and s[4]==s[5]) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

int main(){
   
    int N,K;
    cin>>N>>K;
    vector<char> S(N+1,'5');//1から入れる
    vector<int> A(N,0),B(N,0);
    for(int i=0;i<N;i++){
        cin>>S[i+1];
    }
    int j=0,k=0;
    for(int i=1;i<=N;i++){
        if(S[i]=='1'){
            A[j+1]++;
            if(S[i-1]=='0') k++;
        }
        else if(S[i]=='0'){
            B[k+1]++;
            if(S[i-1]=='1') j++;
        }
    }
    int l=k;//0パートの個数
    if(S[N]=='0') l++;
    if(l<=K) cout<<N<<endl;
    else if(S[1]=='0'){
        int ans=0;
        for(int x=1;x<=K;x++){
            ans+=(A[x]+B[x]);
        }
        int now=ans;
        for(int x=1;x<=l-K;x++){
            now+=(A[x+K]+B[x+K]);
            now-=(A[x-1]+B[x]);
            ans=max(ans,now);
        }
        cout<<ans<<endl;
    }
    else if(S[1]=='1'){
        int ans=0;
        for(int x=1;x<=K;x++){
            ans+=(A[x]+B[x]);
        }
        ans+=A[K+1];
        int now=ans;
        for(int x=1;x<=l-K;x++){
            now+=(A[x+K+1]+B[x+K]);
            now-=(A[x]+B[x]);
            ans=max(ans,now);
        }
        cout<<ans<<endl;
    }
}


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

int main() 
{
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif
 
 int a;
 cin>>a;
 int b;
 cin>>b;
 int c;
 cin>>c;
 int d;
 cin>>d;
 int flag=0;
 while(a>0&&c>0)
 {if(flag==1)
  {a=a-d;
   flag=0;
  }
  else
  {c=c-b;
    flag=1;
  }

 }
 if(a<=0)
  cout<<"No";
 if(c<=0) 
  cout<<"Yes";
  return 0; 
}

Measured memory_bytes: 3644
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long
#define TBMod 1000000007

// qsort(array, size, sizeof(int),comp);
int comp(const int *a,const int *b){
	return (*a - *b);
}

int main(int argc, char const *argv[])
{
	int n,*a;
	scanf("%d",&n);
	a = (int *)malloc(sizeof(int) * n);
	for (int i = 0; i < n; ++i)	scanf(" %d",&a[i]);
	qsort(a,n,sizeof(int),comp);
	printf("%d\n", a[n - 1] - a[0]);
	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <locale>
using namespace std;
#define MS0(I) memset(I, 0, sizeof(I));
#define MS1(I) memset(I, -1, sizeof(I));
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, s, n) for(int i = (s); i < (n); ++i)
#define per1(i, a, b) for(int i = a; i >= b; --i)
#define DRI(A) int A; scanf("%d", &A);
#define DRII(A, B) int A, B; scanf("%d %d", &A, &B);
#define DRIII(A, B, C) int A, B, C; scanf("%d %d %d", &A, &B, &C);
#define SZ(X) ((int)X.size() )
#define MP make_pair 
#define pb push_back
#define F first
#define S second
#define ALL(I) (I).begin(), (I).end()
typedef const void CV;
typedef long long LL;
typedef unsigned long long ULL;
typedef double DB;
typedef long double LDB;
typedef pair<int, int> PII; 
const double eps = 1e-9;
const double PI = acos(-1);
const LL INFF = 1e18;
const int INF = 1e9;
const int mod = 1e9+7;
const int MAX = 7e2+7;
int con[MAX][MAX];
bool used[MAX], dp[MAX][MAX];
int cnt[2], typ[MAX];
int n;
void sol(int u, int p){
	used[u] = 1;
	typ[u] = p;
	cnt[p]++;
	rep1(i, 1, n+1){
		if(!con[i][u] && i != u){
			if(used[i]){
				if(typ[i] == typ[u]){
					puts("-1"); exit(0);
				}
			}
			else sol(i, p^1);
		}
	}
	return ;
}
void build(int v1, int v2){
	per1(i, n-v1-v2, 0){
		per1(j, n-v1-v2, 0){
			if(dp[i][j]){
				dp[i+v1][j+v2] = 1;
				dp[i+v2][j+v1] = 1;
			}
		}
	}
	return ;
}
int main(void){
	int m; scanf("%d %d", &n, &m);
	rep1(i, 1, m+1){
		DRII(u, v);
		con[u][v] = con[v][u] = 1;
	}
	dp[0][0] = 1;
	rep1(i, 1, n+1){
		if(!used[i]){
			MS0(cnt);	
			sol(i, 0);
			build(cnt[0], cnt[1]);
		}
	}
	int ans = INF;
	rep(i, n+1) if(dp[i][n-i]){
		ans = min(ans, (i*i+(n-i)*(n-i)-n)>>1);	
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 2688
#include <iostream>
#include <algorithm>
#include <utility>

using namespace std;
typedef pair<int, int> P;

int n;
int a[100005];
int even[100005], odd[100005];
P peven[100005], podd[100005];

int main(void)
{
	cin >> n;
	for(int i = 0; i < n; i++) cin >> a[i];
	
	if(n == 2){
		if(a[0] == a[1]) cout << 1 << endl;
		else cout << 0 << endl;
		return 0;
	}
	
	for(int i = 0; i < n; i+=2) even[a[i]]++;
	for(int i = 1; i < n; i+=2) odd[a[i]]++;
	
	for(int i = 0; i < 100005; i++) peven[i] = make_pair(even[i], i);
	for(int i = 0; i < 100005; i++) podd[i] = make_pair(odd[i], i);
	sort(peven, peven+100005), reverse(peven, peven+100005);
	sort(podd, podd+100005), reverse(podd, podd+100005);
	
	int mx;
	if(peven[0].second != podd[0].second){
		mx = peven[0].first + podd[0].first;
	}else{
		mx = max(peven[0].first + podd[1].first, peven[1].first + podd[0].first);
	}
	cout << n - mx << endl;
	
	return 0;
}

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

int main()
{
  int n;
  cin >> n;
  if(n % 2 == 0){
    cout << n/2 << endl;
  }else{
    cout << n/2+1 << endl;
  }

  system("pause");
}

Measured memory_bytes: 504