akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
	int h, w;
	cin >> h >> w;
	vector<string> s(h);
	vector<vector<vector<P>>> g(h, vector<vector<P>>(w, vector<P>(0)));
	vector<vector<int>> d(h, vector<int>(w, -1));
	int sum = 0;
	rep(i, h){
		cin >> s.at(i);
		rep(j, w) if(s.at(i).at(j) == '#') sum++;
	}
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			if(i-1 >= 0) if(s.at(i-1).at(j  ) == '.') g.at(i).at(j).push_back({i-1, j  });
			if(i+1 <  h) if(s.at(i+1).at(j  ) == '.') g.at(i).at(j).push_back({i+1, j  });
			if(j-1 >= 0) if(s.at(i  ).at(j-1) == '.') g.at(i).at(j).push_back({i,   j-1});
			if(j+1 <  w) if(s.at(i  ).at(j+1) == '.') g.at(i).at(j).push_back({i,   j+1});
		}
	}
	queue<P> q;
	q.push({0, 0});
	d.at(0).at(0) = 0;
	while(!q.empty()){
		P za = q.front();
		int dis = d.at(za.first).at(za.second) + 1;
		rep(i, g.at(za.first).at(za.second).size()){
			int fst = g.at(za.first).at(za.second).at(i).first;
			int sec = g.at(za.first).at(za.second).at(i).second;
			if(d.at(fst).at(sec) == -1){
				q.push({fst, sec});
				d.at(fst).at(sec) = dis;
			}
		}
		q.pop();
	}
/*	rep(i, h){
		rep(j, w) cout << d.at(i).at(j) << ' ';
		cout << endl;
	}*/
	if(d.at(h-1).at(w-1) != -1){
		int ans = h*w - d.at(h-1).at(w-1) - sum - 1;
		cout << ans << endl;
	}else{
		cout << -1 << endl;
	}
	return 0;
}

Measured memory_bytes: 384
//////////////////////////
/*      _        ____   */
/*  U  /"\  u U /"___|  */
/*   \/ _ \/  \| | u    */
/*   / ___ \   | |/__   */
/*  /_/   \_\   \____|  */
/*   \\    >>  _// \\   */
/*  (__)  (__)(__)(__)  */
/*  Compro by NULL_CT©  */
//////////////////////////
/*STL Libs*/
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

/*Boost*/
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#define REP(i, lower, upper) for (long long i = lower; i < upper; i++)
#define ALL(list) (list.begin()), (list.end())

using namespace std;
using bint = boost::multiprecision::cpp_int;
typedef long long ll;

constexpr int MOD = 10000007;

vector<long long> divisor(long long n) {
  vector<long long> head, tail;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      head.push_back(i);
      if (i * i != n)
        tail.push_back(n / i);
    }
  }
  head.insert(head.end(), tail.rbegin(), tail.rend());
  return (head);
}

//--------------------------------

void execute() {
  ll n;
  cin>>n;
  vector<ll> ls(pow(10,5)+2,0);
  REP(i,0,n){
    ll a;
    cin>>a;
    ls[a]+=1;
    ls[a+1]+=1;
    ls[a+2]+=1;
  }
  ll sum=0;
  for(auto i : ls){
    sum=max(sum,i);
  }
  cout<<sum<<endl;
}

//--------------------------------

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

  execute();

  return (0);
}


Measured memory_bytes: 3532
n=int(input())

l={}
for i in range(n):
    s = input()
    if s in l:
        l[s]+=17
    else:
        l[s]=1

xa = max(l.values())

keys = [k for k, v in l.items() if v == xa]
keys.sort()

for i in keys:
    print(i)

Measured memory_bytes: 32096
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <numeric>
#include <vector>
#include <functional>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;

int main() {
//  freopen("test.in", "r", stdin);
//  freopen("test.out", "w", stdout);
  
  int n, m;
  scanf("%d%d", &n, &m);
  vector<int> a(m);
  for (int i = 0; i < m; ++i)
    scanf("%d", &a[i]);
  int cnt = 0;
  for (int i = 0; i < m; ++i)
    cnt += a[i] & 1;
  if (cnt > 2) {
    puts("Impossible");
    return 0;
  }
  if (cnt)
    for (int i = 0; i < m; ++i)
      if (a[i] & 1) {
        swap(a[i], a[0]);
        break;
      }
  if (cnt == 2)
    for (int i = 1; i < m; ++i)
      if (a[i] & 1) {
        swap(a[i], a[m - 1]);
        break;
      }
  vector<int> ans;
  if (cnt == 0) {
    ans = a;
    --ans[0];
    ans.push_back(1);
  } else if (cnt == 1) {
    ans = a;
    ans.push_back(1);
    if (--ans.front() == 0)
      ans.erase(ans.begin(), ans.begin() + 1);
  } else {
    ans = a;
    ++ans[0];
    if (--ans.back() == 0)
      ans.pop_back();
  }
  for (int i = 0; i < m; ++i)
    printf("%d ", a[i]);
  printf("\n%lu\n", ans.size());
  for (int x : ans)
    printf("%d ", x);
  
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

const int MAX_N = (int)1e5 + 5;

vector<ll> Rank[MAX_N];

int main()
{
	rep (i, MAX_N) Rank[i].clear();
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N, K; cin >> N >> K;

	priority_queue<ll> kind[N];
	rep (i, N){
		int t;
		ll d;
		cin >> t >> d;
		--t;
		kind[t].push(d);
	} // end rep

	priority_queue<ll> best, remain;
	// best: 各種類で一番美味しいやつを集めたもの
	// remain: best の余り
	rep (i, N){
		if (!kind[i].empty()){
			best.push(kind[i].top());
			kind[i].pop();
			while (!kind[i].empty()){
				remain.push(kind[i].top());
				kind[i].pop();
			} // end while
		} // end if
	} // end rep

	vector<ll> bsum = {0LL};
	// best の累積和 (bsum[i] = bestの先頭から i 個の総和）
	while(!best.empty()){
		bsum.push_back(bsum.back() + best.top());
		best.pop();
	} // end while

	vector<ll> rsum = {0LL};
	// remain の累積和
	while(!remain.empty()){
		rsum.push_back(rsum.back() + remain.top());
		remain.pop();
	} // end while

	ll ans = 0LL;
	for (ll x = 1LL; x <= (ll)K; ++x){
		// 種類が多すぎるケース
		if ((int)x >= (int)bsum.size()) break;
		// 種類が少なすぎて、余り物が足りないケース
		if (K - (int)x >= (int)rsum.size()) continue;
		// best から x 個、remain から K - x 個貪欲に選ぶ
		ans = max(ans, bsum[(int)x] + rsum[K - (int)x] + x * x);
	} // end for

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 11124
#define CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include<string>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<math.h>
#include<vector>
#include<utility>
#include<functional>
#include<iostream>
#define sqr(x) x*x
bool flg=false;
using namespace std;

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b;
	cin >> a>>b;
	if (a*b%2==0) {
		cout << "Even\n";
	}
	else
	{
		cout << "Odd\n";
	}
	
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        
        boolean[] shouldSwap = new boolean[N];
        
        for(int i = 0; i < N; i++) {
            int p = scan.nextInt();
            shouldSwap[i] = (p == i+1 ? true : false);
        }
        
        int swapCount = 0;
        for(int i = 0; i < N; i++) {
            if(i == N-1 && shouldSwap[i]) {
                swapCount++;
                shouldSwap[i] = false;
            } else if(shouldSwap[i] && shouldSwap[i+1]) {
                swapCount++;
                shouldSwap[i] = false;
                shouldSwap[i+1] = false;
            } else if(shouldSwap[i]) {
                swapCount++;
                shouldSwap[i] = false;
            }
        }
        
        System.out.println(swapCount);
    }
}


Measured memory_bytes: 50416
use std::io::*;
use std::str::*;

fn read<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok()
}

fn main() {
    let s: String = read().unwrap();
    let s = s.replace("eraser", "");
    let s = s.replace("erase", "");
    let s = s.replace("dreamer", "");
    let s = s.replace("dream", "");
    if &s == "" {
        println!("YES");
    } else { println!("NO"); }
}

Measured memory_bytes: 4352
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <list>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long

int main(){
  int N;
  cin >> N;
  int W[N];
  for(int i=0;i<N;i++) cin >> W[i];


  int minW=10000;
  int sumW=0;
  for(int i=0;i<N;i++){
    sumW += W[i];
  }

  int Tsum1=0,Tsum2;
  for(int i=0;i<N;i++){
    Tsum1 += W[i];
    Tsum2 = sumW - Tsum1;
    if(minW > Tsum1 - Tsum2){
      minW = Tsum1-Tsum2;
      if(minW < 0) minW *= -1;
    }
  }

  cout << minW << endl;

}

Measured memory_bytes: 256
import numpy as np


def getNearestValue(list, num):
    """
    概要: リストからある値に最も近い値を返却する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]


X, Y = map(int, input().split())
list = list(map(int, input().split()))
list = sorted(list)


listHandred = []
for i in range(0,102):
    listHandred.append(i)
    
ansList = listHandred

for i in list:
    if i in ansList:
        ansList.remove(i)

print(getNearestValue(ansList,X))


Measured memory_bytes: 27072
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <array>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>

#define INF_LL 9000000000000000000
#define INF 2000000000

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

using namespace std;

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

class Union_find{
private:
	vector<int> par;
	vector<int> rank;
	int n;

public:
	Union_find(int a){
		n = a;
		for(int i = 0;i < n;i++){
			par.push_back(i);
			rank.push_back(0);
		}
	}

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

	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return;

		if(rank[x] < rank[y]){
			par[x] = y;
		}else{
			par[y] = x;
			if(rank[x] == rank[y]) rank[x]++;
		}
	}

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

int main(void){
	int W, H, N;
	int sx, sy;
	int nx, ny;
	int res = 0;
	cin >> W >> H >> N;
	cin >> sx >> sy;
	REP(i, N-1){
		cin >> nx >> ny;
		if(nx > sx && ny > sy){
			int cross = min(nx-sx, ny-sy);
			res += cross;
			sx = sx + cross;
			sy = sy + cross;
		}else if(nx < sx && ny < sy){
			int cross = min(sx-nx, sy-ny);
			res += cross;
			sx = sx - cross;
			sy = sy - cross;
		}
		res += abs(nx-sx) + abs(ny-sy);
		sx = nx;
		sy = ny;
	}
	cout << res << endl;
}

Measured memory_bytes: 3088
#include<iostream>
#include<sstream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<cfloat>
#include<functional>
#include<map>
#include<string>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<bitset>
#include<list>
#include<numeric>
#include<complex>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<long long, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<long long, long long> ll_ll;
typedef pair<double, double> d_d;
typedef vector<int> Vint;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define rep2d(i, j, n) for(i = 0;i < n;++i)for(j = i + 1;j < n;++j)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << x << "\n"
#define pri2(x, y) cout << x << " " << y << "\n"
#define pri3(x, y, z) cout << x << " " << y << " " << z << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define endl "\n"
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << x << "\n"
#define debug2(x, y) cout << " --- " << x << " " << y << "\n"
#define debug3(x, y, z) cout << " --- " << x << " " << y << " " << z << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)

bool myc(ll_i a, ll_i b){
  if(a.X != b.X)return a.X < b.X;
  return a.Y > b.Y;
}

signed main(void){
  int i, j, k;
  for(int testcase = 0;testcase < 1234567;testcase++){
    int(n);
    int a[n], t[n], f[n], x[n], y[n];
    rep(i, n)cin >> f[i] >> a[i] >> t[i] >> x[i] >> y[i];

    ll_i maxi = mp(0, 0);
    ll_i ares = maxi, bres = maxi;
    rep1(i, n)if(a[i - 1] != a[i] && t[i - 1] == t[i]){
      ll_i tmp;
      tmp.X = (x[i] - x[i - 1]) * (x[i] - x[i - 1]) + (y[i] - y[i - 1]) * (y[i] - y[i - 1]);
      tmp.Y = f[i] - f[i - 1];
      if(t[i] == 0 && myc(ares, tmp))ares = tmp;
      if(t[i] == 1 && myc(bres, tmp))bres = tmp;
    }

    if(ares == maxi){
      pri("-1 -1");
    }else{
      double l = sqrt(ares.X), r = (double)ares.Y / 60.0;
      printf("%.10lf %.10lf\n", l, r);
    }
    if(bres == maxi){
      pri("-1 -1");
    }else{
      double l = sqrt(bres.X), r = (double)bres.Y / 60.0;
      printf("%.10lf %.10lf\n", l, r);
    }


/*/

//*/ break;
  }
  return 0;
}

Measured memory_bytes: 1276
package main

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var sc = bufio.NewScanner(os.Stdin)

func main() {
	// Code for A - Table Tennis Training
	sc.Split(bufio.ScanWords)
	var N, A, B int
	N, A, B = nextInt(), nextInt(), nextInt()

	var ans int
	if (B-A)%2 == 0 {
		ans = (B - A) / 2
	} else {
		if A-1 > N-B {
			ans = N - B
		} else {
			ans = A - 1
		}
		ans += (B-A)/2 + 1
	}

	fmt.Println(int(ans))
}


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

int main() {
  int N, W;
  cin >> N >> W;
  vector<long> DP(W + 1);
  for (int w, v; cin >> w >> v;) {
    for (int i = W; i - w >= 0; i--) {
      DP.at(i) = max(DP.at(i), DP.at(i - w) + v);
    }
  }
  cout << *max_element(DP.begin(), DP.end()) << "\n";
}

Measured memory_bytes: 1024
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Tasks
{
    public class A
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var S = Scanner.Scan<string>();
            var T = Scanner.Scan<string>();
            var answer = true;
            for (var i = 0; i < S.Length && answer; i++)
            {
                if (S[i] != T[i]) answer = false;
            }
            Console.WriteLine(answer ? "Yes" : "No");
        }

        public static class Scanner
        {
            private static Queue<string> queue = new Queue<string>();
            public static T Next<T>()
            {
                if (!queue.Any()) foreach (var item in Console.ReadLine().Trim().Split(" ")) queue.Enqueue(item);
                return (T)Convert.ChangeType(queue.Dequeue(), typeof(T));
            }
            public static T Scan<T>() => Next<T>();
            public static (T1, T2) Scan<T1, T2>() => (Next<T1>(), Next<T2>());
            public static (T1, T2, T3) Scan<T1, T2, T3>() => (Next<T1>(), Next<T2>(), Next<T3>());
            public static (T1, T2, T3, T4) Scan<T1, T2, T3, T4>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>());
            public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>(), Next<T5>());
            public static IEnumerable<T> ScanEnumerable<T>() => Console.ReadLine().Trim().Split(" ").Select(x => (T)Convert.ChangeType(x, typeof(T)));
        }
    }
}


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

struct UnionFind{
    int gro=0;
    vector<int> d;
    UnionFind(int n=0){
        d=vector<int>(n,-1);
        gro=n;
    }
    int find(int a){
        if(d[a]<0) return a;
        return d[a]=find(d[a]);
    }
    bool unite(int a,int b){
        a=find(a); b=find(b);
        if(a==b) return false;
        gro--;
        if(d[a]>d[b]) swap(a,b);
        d[a]+=d[b];
        d[b]=a;
        return true;
    }
    bool same(int a,int b){return find(a)==find(b);}
    int size(int a) {return -d[find(a)];}
    int group() {return gro;}
};

int main()
{
    int n,m;
    cin>>n>>m;
    UnionFind uf(n);
    rep(i,m){
        int a,b;
        cin>>a>>b;a--;b--;
        if(!uf.same(a,b)){
            uf.unite(a,b);
        }
    }
    cout<<uf.group()-1<<endl;
    return 0;
}

Measured memory_bytes: 3764
#include<iostream>
#include<cmath>
#include<numeric>
#include<functional>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define ll long long
#define modbig (10*10*10*10*10*10*10*10*10+7)
using namespace std;

int main(){
  double l;
  cin>>l;
  cout<<setprecision(10)<<l*l*l/27;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

ll mod=1e9+7;

int main()
{
    fast();
    ll r,c;
    cin>>r>>c;

    ll dp[r][c];
    char arr[r][c];

    for(ll i=0;i<r;i++)
    {
        for(ll j=0;j<c;j++)
            cin>>arr[i][j];
    }

    for(ll i=0;i<r;i++)
    {
        for(ll j=0;j<c;j++){
            dp[i][j]=0;
        }
    }

    dp[r-1][c-1]=1;

    for(ll i=r-2;i>=0;i--)
    {
        if(arr[i][c-1]=='#')
            dp[i][c-1]=0;
        else
            dp[i][c-1]=dp[i+1][c-1];
    }

    for(ll i=c-2;i>=0;i--)
    {
        if(arr[r-1][i]=='#')
            dp[r-1][i]=0;
        else
            dp[r-1][i]=dp[r-1][i+1];
    }

    for(ll i=r-2;i>=0;i--)
    {
        for(ll j=c-2;j>=0;j--)
        {

            if(arr[i][j]=='#'){
                dp[i][j]=0;
            }
            else{
                dp[i][j]=(dp[i][j+1]+dp[i+1][j])%mod;
            }
        }
    }

    cout<<dp[0][0];

}


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

int main(void)
{
  int n;
  int i;
  int j;
  
  char s[100][11];
  scanf("%d", &n);

  for (i = 0; i < n; i++)
  {
    scanf("%s", s[i]);
  }

  for (i = 0; i < n; i++)
  {
    //printf("i=%d\n", i);
    for (j = i + 1; j < n; j++)
    {
      //printf("j=%d\n", j);
      //strcmp(s[i], s[j]);
      //break;
      //printf("in for of j\n");
      if (strcmp(s[i], s[j]) == 0)
      {
        printf("No\n");
        return 0;
      }
    }
  }

  for(i = 0; i<n-1; i++)
  {
    if(s[i][strlen(s[i]) - 1] != s[i+1][0])
    {
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");
  return 0;
}

Measured memory_bytes: 128
import collections
import decimal

N, K = map(int,input().split())
coin = [0] * (K+1)
ans = 0

for i in range(K-1,0,-1):
    coin[i] += 1
    for j in range(1,20):
        if i % (2**j) == 0:
            coin[i//(2**j)] += 1

if N >= K:
    ans += N-K+1

A = collections.Counter(coin[1:min(N+1,K)]).most_common()

for tmp in A:
    ans += (0.5)**tmp[0] * tmp[1]

print(decimal.Decimal(ans/N))


Measured memory_bytes: 5844
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int p = sc.nextInt();
        int odd = 0;
        int even = 0;
        for (int i = 0; i < n; i++) {
            int a = sc.nextInt();
            if (a % 2 == 0) {
                even++;
            } else {
                odd++;
            }
        }

        if ( even == n) {
            if (p == 0) {
                System.out.println((long)Math.pow(2, n));
            } else {
                System.out.println(0);
            }
        } else {
            System.out.println((long) Math.pow(2, n-1));
        }

    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N;cin >> N;
    int ans = 1;
    for(int a = 0;a<N;a++){
        int n;cin >> n;
        if(n % 2 == 0){
            ans *= 2;
        }else{
            ans *= 1;
        }
    }
    int b = 1;
    for(int a = 0; a< N;a++){
        b *= 3;
    }
    cout<<b-ans <<endl;
    return 0;
}


Measured memory_bytes: 256
n,m = map(int,input().split())
l,r = map(int,input().split())

for i in range(m-1):
    l_new,r_new = map(int,input().split())
    if l_new > l:
        l = l_new
    if r_new < r:
        r = r_new

if r - l < 0:
    print(0)
else:
    print(r-l+1)

Measured memory_bytes: 3060
n = int(input())
a = list(map(int, input().split()))
q = int(input())
b = list(list(map(int, input().split())) for i in range(q))
dic = {}
for i in range(n):
    if a[i] not in dic.keys():
        dic[a[i]] = 1
    else:
        dic[a[i]] += 1
su = sum(a)
for i in range(q):
    if b[i][0] not in dic.keys():
        pass
    else:
        su += (b[i][1]-b[i][0])*dic[b[i][0]]
        if b[i][1] not in dic.keys():
            dic[b[i][1]] = 0
        dic[b[i][1]] += dic[b[i][0]]
        dic[b[i][0]] = 0
    print(su)

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

bool g(ll a,ll b){
    return a>b;
}
int main(){
    string S;
    cin>>S;
    
    set<char> s;
    if(S.length()<26){
        for(ll i=0;i<S.length();++i){
            s.insert(S[i]);
        }
        cout<<S;
        for(ll i=0;i<26;++i){
            if(s.count('a'+i)==0){
                cout<<char('a'+i);
                break;
            }
        }
    }else{
        // string p=S;
        // next_permutation(p.begin(),p.end());
        // cout<<S<<endl;
        // cout<<p<<endl;
        s.insert(S[S.length()-1]);
        for(ll i=S.length()-2;i>=0;--i){
            s.insert(S[i]);
            if(S[i]<S[i+1]){
                S[i]= *s.upper_bound(S[i]);
                S=S.substr(0,i+1);
                cout<<S;
                return 0;
            }
        }
        cout<<-1;
    }
}

Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <algorithm>
 
//answer3 function
void display(const char& ch) {
	std::cout << ch;
}
 
int main(){
	std::string str;
	std::cin >> str;
	
	//answer1
	for(auto it = str.crbegin(); it != str.crend(); ++it){
		std::cout << *it;
	}
	//answer2
	//std::for_each(str.crbegin(), str.crend(), [](const char& ch){ std::cout << ch; });
	
	//answer3
	//std::for_each(str.crbegin(), str.crend(), display);
	
	std::cout << std::endl;
	
	return 0;
}

Measured memory_bytes: 1176
#include <bits/stdc++.h>
using namespace std;
int a[101],n,k,mem[100001];

int dp(int k){
    if(k==0) return 0;
    if(mem[k]!=-1) return mem[k];
    mem[k]=0;
    for (int x=0;x<n && mem[k]!=1;x++){
        if (k>=a[x])
            mem[k]=1-dp(k-a[x]);
    }
    return mem[k];
}
int main(){
    cin>>n>>k;
    memset(mem,-1,sizeof mem);
    for (int i=0;i<n;i++)
        cin>>a[i];
    if(dp(k))
        cout<<"First";
    else
        cout<<"Second";
}



Measured memory_bytes: 5376
n = int(input())
s = input()
print(s)
s = s.split(" ")
for i in range(n):
    s[i] = int(s[i])
for i in range(1,n):
    v = s[i]
    j = i-1
    while j >= 0 and s[j] > v:
        s[j+1] = s[j]
        j -= 1
    s[j+1] = v
    for k in range(n-1):
        print(s[k],end = " ")
    print(s[n-1])


Measured memory_bytes: 5976
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;

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

	for(int n, m, a; cin >> n >> m >> a, n;) {
		vector<pair<int, pair<int, int> > > line;
		line.reserve(m);
		for(int i = 0; i < m; ++i) {
			int h, p, q;
			cin >> h >> p >> q;
			line.push_back(make_pair(h, make_pair(p, q)));
		}

		sort(line.begin(), line.end());
		vector<int> amida(n + 1);
		for(int i = 1; i <= n; ++i)
			amida[i] = i;

		for(int i = 0; i < m; ++i)
			swap(amida[line[i].second.first], amida[line[i].second.second]);

		cout << amida[a] << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1216
# -*- coding: utf-8 -*-
# kakomon toku
import math
import sys
import itertools
import numpy as np

n = int(input())
a = [int(i) for i in input().split()]

#print(a)
ai=0
for m in a:
    if ai < m:
        ai = m
a = np.sort(a)
aj = a[0]
center = ai / 2
diff = ai
i=0
for m in a:
    if diff > abs(m - center) :
        aj = m
        diff = abs(aj - center)
    else:
        break

print(ai,aj)


Measured memory_bytes: 23348
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
void yes(bool expr) {
  cout << (expr ? "Yes" : "No") << "\n";
}
int N;
int bit[200010];
void add(int a, int w) {
  while(a <= N+1) {
    bit[a] += w;
    a += a & -a;
  }
}
int sum(int a) {
  int s = 0;
  while(a > 0) {
    s += bit[a];
    a -= a & -a;
  }
return s;
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  lint K;
  cin >> N >> K;
  vector<lint> A(N);
  REP(i, N) cin >> A[i];
  REP(i, N) A[i] -= K;
  vector<lint> S(N+1);
  REP(i, N) S[i+1] = S[i] + A[i];
  vector<lint> St(S);
  sort(ALL(St));
  map<lint, lint> mp;
  REP(i, N+1) mp[St[i]] = i+1;
  REP(i, N+1) S[i] = mp[S[i]];
  lint ans = 0;
  REP(i, N+1) {
    ans += (lint)sum(S[i]);
    add(S[i], 1);
  }
  cout << ans << endl;

}

Measured memory_bytes: 18176
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
typedef pair< long long int ,long long int > iil;
typedef long long ll;
typedef vector< ll > vl;
typedef vector< vl > vvl;
const ll MAX = 1e5+5;
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for( auto i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define EE '\n'
#define ll long long int
#define forn(i,j,n) for ( auto i=j ; i<n ; i++ )
#define fornd(i,j,n) for ( auto i=j ; i>n ; i-- )
#define PI 3.14159265
#define g(a,b) a>b?a:b
#define l(a,b) a<b?a:b
#define SOT(A) sort(A.begin(),A.end())
#define SOTR(A) sort(A.rbegin(),A.rend())

const int N = 200043;
const int MOD = 998244353;
//////////////// ncr ///////////////////////
int mul(int x, int y) {return (x * 1ll * y) % MOD;}
int binpow(int x, int y){
    int z = 1;
    while(y){
        if(y & 1) z = mul(z, x);
        x = mul(x, x);
        y >>= 1;
    }
    return z;
}
int inv(int x) {return binpow(x, MOD - 2);}
int divide(int x, int y) {return mul(x, inv(y));}
int fact[N];
void precalc(){
    fact[0] = 1;
    for(int i = 1; i < N; i++) fact[i] = mul(fact[i - 1], i);
}
int C(int n, int k)  {return divide(fact[n], mul(fact[k], fact[n - k]));}

/////////////// ncr  ///////////////////////


//////////////////Sieve////////////////////
vector<bool> is_prime(MAX+1, true);
void Sieve(){
	is_prime[0] = is_prime[1] = false;
	int i,j;
	for (i = 2; i*i <= MAX; i++) {
    	if (is_prime[i]) {
        	for (j = i * i; j <= MAX; j += i)
            	is_prime[j] = false;
    	}
	}
}
//////////////////Sieve////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


int main()
{
	int n;
	cin>>n;
	vl A(n+1,0);
	forn(i,1,n+1) cin>>A[i];
	vl v(n);
	forn(i,0,n) v[i]=A[i+1];
	SOT(v);
	ll ans=0;
	fornd(mid,n-1,-1){
	    fornd(low,mid-1,-1){
	        auto itr=lower_bound(all(v),v[mid]+v[low]);
	        ll ng=distance(itr,v.end());
	        ans+=(n-1-mid)-ng;
	    }
	}
	cout<<ans;
    
    
}	




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

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORTASC(c) sort((c).begin(),(c).end())
#define SORTDESC(c,t) sort((c).begin(),(c).end(), std::greater<t>());
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double PI  = acos(-1.0);

using ll = long long;
using namespace std;

int main() {
    ll n;
  	ll h[100010], dp[100010];

    cin >> n;

  	REP(i, n){
      	cin >> h[i];
      	dp[i] = 10000000000;
    }
	dp[0] = 0;
  
  	FOR(i, 1, n) {
      	dp[i] = min(dp[i], dp[i-1] + abs(h[i] - h[i-1]));
        if (i > 1){
          	dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2]));
        }
    }
  
    cout << setprecision(20) << dp[n-1] << endl;

    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ld long double
#define ull unsigned long long int
#define ll long long int
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007ll
#define rep(i,L,R) for(ll i=L;i<R;i++)
#define f(n) rep(i,0,n)
#define DEBUG
#ifdef DEBUG
#define deb2(args...) {dbg,args; cerr<<endl;}
#else
#define deb2(args...)
#endif
struct debb{template<typename T> debb& operator,(const T &v){cerr<<v<<" ";return *this;}}dbg;
#define deb1(args...) do {cerr << #args << " : "; dbg,args; cerr << "\n";} while(0)
#define printa(a,L,R) rep(i,L,R) cout << a[i] <<' ';cout<<"\n";
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
template<typename T>T gcd(T a,T b){if(b==0)return a;else return gcd(b,a%b);}
template<typename T>T lcm(T a,T b){return a/gcd(a,b)*b;}
ll power(ll x,ll y,ll p){ll res=1;x=x%p;while(y>0){if(y&1)res=((res%p)*(x%p))%p;y=y>>1;x=(x*x)%p;}return res;}
ll pow1(ll x,ll y){ll res=1;while(y>0){if(y&1)res=(res*x);y=y>>1;x=x*x;}return res;}
#define sq(X) ((X)*(X))
#define PI 3.141592653589
const ll INF = 1e18l+10,N = 2e5+10,MAX = 5000000;

int main()
{
    int n,i;
    string s;
    cin>>n;
    set<string> st;
    f(n){
        cin>>s;
        st.insert(s);
    }
    cout<<st.size()<<"\n";
}

Measured memory_bytes: 19224
import sys
input = sys.stdin.readline
import numpy as np
from numba import njit


def read():
    N = int(input().strip())
    A = np.fromstring(input().strip(), dtype=np.int32, sep=" ")
    return N, A


@njit
def cond(l, r, S, O = np.ones(20, dtype=np.int32)):
    s = S[r, :] - S[l, :]
    return np.less_equal(s, O).all()


@njit
def solve(N, A):
    ans = 0
    # ビット区間和
    S = np.zeros((N+1, 20), dtype=np.int32)
    for i in range(N):
        a = A[i]
        for j in range(20):
            S[i+1, j] = S[i, j] + ((a >> j) & 0x1)
    for l in range(N):
        ok = l+1
        ng = N+1
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if cond(l, mid, S):
                ok = mid
            else:
                ng = mid
        r = ok
        ans += r - l
    return ans


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


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

// ------------------------

void solve() {
    ll H; cin >> H;
    deque<ll> dq;
    dq.push_back(H);

    ll count = 0;

    while(dq.size() != 0){
        // atack
        ll hitpoint = dq.back();
        // divide
        dq.pop_back();
        if(hitpoint == 0){
        }else{
            ++count;
            dq.emplace_back(hitpoint/2);
            // dq.emplace_back(hitpoint/2);
        }
    }
    cout <<  (ll)-(1-pow(2, count))  << "\n";
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

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

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

  
    // if (sqrt(a)*sqrt(b)*2+a+b<c){
    //     cout << "Yes" << endl;
    // } else {
    //     cout << "No" << endl;
    // }
    if(c-a-b<0){
        cout << "No" << endl;
        return 0;
    }
    if(4*a*b<(c-a-b)*(c-a-b)){
        cout <<"Yes" << endl;
    } else {
        cout << "No" << endl;
    }

}

Measured memory_bytes: 256
#pragma warning (disable:4996)
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int a[200005];
int c[200005];
int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		c[i] = a[i] - (i+1);
	}
	sort(c, c + n);
	int b = c[n / 2];
	ll sadness=0;

	for (int i = 0; i < n; i++)
	{
		sadness = sadness + abs(c[i] - b);
	}

	cout << sadness << endl;
	return 0;
}

Measured memory_bytes: 1792
#![allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}
fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main() {
    let s: String = read();
    println!("{}{}", s, if s.chars().rev().next().unwrap() == 's' {"es"} else {"s"});
}


Measured memory_bytes: 2136
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define ll long long
#define PI 3.141592653589
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define EPS 1e-7
#define PII pair<int,int>
#define s second
#define f first
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
ll MOD = 998244353;
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int random_int(int l,int r){return uniform_int_distribution<int>(l,r)(rng);}
ll fast_power(ll x, ll p){
    ll res = 1;
    while(p > 0){
        if(p & 1){
            res = (res * x)%MOD;
        }
        p = p >> 1;
        x = (x*x)%MOD;
    }
    return res;
}
int main() {
    IO;
    int n;
    cin >> n;
    int arr[n][3];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 3; j++){
            cin >> arr[i][j];
        }
    }
    int dp[n][3];
    dp[0][0] = arr[0][0];
    dp[0][1] = arr[0][1];
    dp[0][2] = arr[0][2];
    for(int i = 1; i < n; i++){
        for(int j = 0; j < 3; j++){
            dp[i][j] = 0;
            for(int t = 0; t < 3 ; t++){
                if(j != t){
                    dp[i][j] = max(dp[i][j], arr[i][j] + dp[i-1][t]);
                }
            }
        }
    }
    cout << max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]));

    return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n;
    cin >> n;
    VI x(n), y(n);
    REP(i,n){
        cin >> x[i] >> y[i];
    }

    int d = 1;
    for (int s = 3; s <= n; s += 2) d *= s;

    // cout << d << endl;

    int ans = 0;

    REP(z,d){
        VI p(n, -1);
        VI dx, dy;
        int zz = z;
        REP(i,n/2){
            int r = zz % (n-1-2*i);
            zz /= n-1-2*i;
            int j = 0;
            while (p[j] != -1) j++;
            p[j] = i;
            int k = n - 1;
            r++;
            while (1){
                if (p[k] == -1) r--;
                if (!r) break;
                k--;
            }
            p[k] = i;

            dx.push_back(x[k] - x[j]);
            dy.push_back(y[k] - y[j]);
        }
        int tmp = 0;
        REP(i,n/2) REP(j,i){
            if (dx[i] * dy[j] == dx[j] * dy[i]) tmp++;
        }
        ans = max(ans, tmp);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3144
/*
    ->->->->-> Vora Mahammasasim <-<-<-<-<-
*/
#include<bits/stdc++.h>
#define Quick std :: ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define pb emplace_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define MOD 1e7+7;
using namespace std;





signed main(){

    Quick;
    int n;
    cin>>n;
    int ans = 0;
    for(int i=1;i<=n;i++){
        ans += (n-1)/i;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {
    //Apple Pie
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int p = sc.nextInt();
        int max = (a * 3 + p) / 2;
        System.out.println(max);
    }
}


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

using namespace std;

int main()
{
  int n, m;
  
  scanf("%d %d", &n, &m);
  
  vector<pair<int, int>> events;
  
  for (int i = 0; i < m; i++) {
    int l, r;
    scanf("%d %d", &l, &r);
    events.emplace_back(r, l);
  }
  
  sort(events.begin(), events.end());
  
  int ans = 0, last_pos = 0;
  for (int i = 0; i < m; i++) {
    if (events[i].second <= last_pos - 1) continue;
    last_pos = events[i].first; ans++;
  }
  
  printf("%d\n", ans);
  
}

Measured memory_bytes: 1400
n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(100):
  for j in range(n):
    if a[j] % 2 ==0:
      a[j]=a[j]//2
      if j==n-1:
        ans+=1
    else:
      break
  else:
    continue
  break
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <stdio.h>
#include <vector>
#include <cmath>

using namespace std;

class Point
{
public:
	int x, y;
};

void solve()
{
	int count = 1;
	int n;
	while(cin >> n, n)
	{
		vector<Point> p(n);
		for(int i = 0; i < n; ++i)
		{
			cin >> p[i].x >> p[i].y;
		}
		double sum = 0.0;
		for(int i = 1; i < n - 1; ++i)
		{
			double x1 = p[i].x - p[0].x;
			double y1 = p[i].y - p[0].y;
			double x2 = p[i + 1].x - p[0].x;
			double y2 = p[i + 1].y - p[0].y;
			sum += x1 * y2 - x2 * y1;
		}
		printf("%d %.1f\n", count, abs(sum) / 2);
		++count;
	}
}

int main()
{
	solve();
	return(0);
}

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

int main(){

    string s;
    int n; cin >> n;
    int d = 0;
    bool flag = true;
    for(int i = 0; i < n; i++){
        char c; cin >> c;
        int p; cin >> p;
        if(flag == false) continue;
        
        if(c == '(') d += p;
        else d -= p;

        if(d < 0){
            flag = false;
            continue;
        }
    }

    
    if(d != 0) flag = false;
    
    if(flag) cout << "YES" << endl;
    else cout << "NO" << endl;

    //cout << s << endl;
    
    return 0;
}


Measured memory_bytes: 3092
IDENTIFICATION DIVISION.
PROGRAM-ID. PROGRAM_ID.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 S              PIC X(30).

PROCEDURE DIVISION.
  ACCEPT S.
  IF S(3:1) = S(4:1) AND S(5:1) = S(6:1)
      DISPLAY "Yes"
  ELSE
      DISPLAY "No"
  END-IF.
  STOP RUN.


Measured memory_bytes: 636
import sys
class Union():
    def __init__(self, n):
        self.pre = [i for i in range(n)]
        self.rank = [1 for _ in range(n)]

    def union(self, a, b):
        aroot = self.find(a)
        broot = self.find(b)
        if aroot == broot:
            return
        if self.rank[aroot] < self.rank[broot]:
            aroot, broot = broot, aroot
        self.pre[broot] = self.pre[aroot]
        if self.rank[aroot] == self.rank[broot]:
            self.rank[aroot] += 1

    def find(self, n):
        while self.pre[n] != n:
            n = self.pre[n]
        return n

    def issame(self, a, b):
        if self.find(a) == self.find(b):
            return True
        return False

if __name__ == '__main__':
    m, n = map(int, sys.stdin.readline().split())
    union = Union(m)

    for _ in range(n):
        a, b = map(int, sys.stdin.readline().split())
        union.union(a, b)

    o = int(input())
    for _ in range(o):
        p, q = map(int, sys.stdin.readline().split())
        if union.issame(p, q):
            print('yes')
        else:
            print('no')


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

int main(){
  int n;
  char a[4] = {'S', 'H', 'C', 'D'};
  char suits[52];
  int ranks[52];

  cin >> n;
  for(int i=0; i<n; i++){
    cin >> suits[i];
    cin >> ranks[i];
  }
  for(int j=0; j<4; j++){
    for(int k=1; k<=13; k++){
      for(int i=0; i<n; i++){
        if(ranks[i]==k&suits[i]==a[j]){
          break;
        } else if(i==n-1) {
          cout << a[j] << " " << k << endl;
        }
      }
    }
  }
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;

int main() {
  int n, m, point, rest;
  while (cin >> n >> m) {
    if (n == 0 && m == 0) break;
    int ans = 0;
    vector<int> p(n + 1), pp;
    rep(i, n) {
      cin >> p[i];
    }
    rep(i, n + 1) {
      rep(j, n + 1) {
        pp.push_back(p[i] + p[j]);
      }
    }
    sort(pp.begin(), pp.end());

    rep(i, n + 1) {
      rep(j, n + 1) {
        point = p[i] + p[j];
        if (point > m) continue;
        rest = m - point;
        point += *(upper_bound(pp.begin(), pp.end(), rest) - 1);
        if (point <= m) {
          ans = max(ans, point);
        }
      }
    }

    cout << ans << endl;

  }

  
  return 0;
}


Measured memory_bytes: 10732
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <tuple>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define repn(i, x) for (int i = 1; i <= (int)(x); i++)
#define repr(i, x) for (int i = ((int)(x) - 1); i >= 0; i--)
#define reprn(i, x) for (int i = ((int)(x)); i > 0; i--)
#define all(x) (x).begin(),(x).end()
typedef long long int64;
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;

int gcd(int a, int b) {
    return b != 0 ? gcd(b, a % b) : a;
}

//逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
      fac[i] = fac[i-1] * i % MOD;
      inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
      finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
//組み合わせ
long long COM (int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

void solve() {
		int n; cin >> n;
		int d; cin >> d;
		int modulo = n % (d * 2 + 1);
		if (modulo != 0) {
			cout << (n / (d * 2 + 1)) + 1 << endl;
		} else {
			cout << (n / (d * 2 + 1)) << endl;
		}
    return;
}

int main() {
    solve();
    return 0;
}



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

int main() {
  int N;
  cin >> N;
  vector<double> a(N);
  for (int i = 0; i < N; ++i) cin >> a[i];
  sort(a.begin(), a.end());
  double res = (a[0] + a[1]) / 2;
  for (int i = 2; i < N; ++i) {
    res = (res + a[i]) / 2;
  }
  cout << fixed << setprecision(10) << res << endl;
}

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

int main() {
  // ひなあられの個数
  int N;
  cin >> N;
  
  int a = 0;
  bool l = false;

  while(a < N) {    
    string S;
    cin >> S;
    
    if(S == "Y") {
      l = true;
    }
    a++;
  }
  if(l == true) {
    cout << "Four" << endl;
  }
  else {
    cout << "Three" << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    
    int N,i,Odd_val = 0;
    double ans;

    scanf("%d",&N);
    for(i = 1;i <= N;i++){
        if(i % 2 == 1){
            Odd_val++;
        }
    }

    ans = (double)(Odd_val)/N;

    printf("%lf\n",ans);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b){if (a < b){a = b;return 1;}return 0;}
template <typename T>
inline bool chmin(T &a, T b){if (a > b){a = b;return 1;}return 0;}

int main(){
    ll n,m,x,y;cin>>n>>m>>x>>y;
    bool yes=true;
    vector<ll> x_vec(n),y_vec(m);
    rep(i,n) cin>>x_vec[i];
    rep(i,m) cin>>y_vec[i];

    for(ll z=-100;z<=100;z++){
        bool Yes=false;
        if(!(x<z && z<=y)) Yes=true;
        rep(i,n) if(!(x_vec[i]<z)) Yes=true;
        rep(i,m) if(!(y_vec[i]>=z)) Yes=true;

        if(!Yes){
            yes=false;
            break;
        }
    }

    if(yes) cout<<"War"<<endl;
    else cout<<"No War"<<endl;
    return 0;
}

Measured memory_bytes: 3612
#include <stdio.h>
 
int main( void )
{
    int h,w,i,j;
    
	do{
    	scanf("%d %d", &h, &w);
		
		if((h > 0) || (w > 0)){
			for(i = 0; i < h; i++){
				for(j = 0; j < w; j++){
					printf("#");
				}
				printf("\n");
			}
			printf("\n");
		}
		
	}while((h != 0) || (w != 0));
    
    return 0;
}

Measured memory_bytes: 572
#include<iostream>

using namespace std;

int main(){
	int N;
	int p;
	int count=0;
	string ans;
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>p;
		if(p!=i+1){
			count++;		
		}
	}
	if(count>2){
		ans="NO";
	}else{
		ans="YES";
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    int n, w;
    cin >> n >> w;
    int *we =  new int[n+1];
    int *val =  new int[n+1];
    we[0]=0;
    val[0]=0;
    for(int i = 1;i <= n;i++)
    cin >> we[i] >> val[i];
    ll ans[n+1][w+1];
    for(int i=0;i<=n;i++)
    {
        ans[i][0] = 0;
    }

    for(int i=0;i<=w;i++)
    {
        ans[0][i] = 0;
    }

    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=w;j++)
        {
            if(j-we[i]>=0)
            ans[i][j] =  max(ans[i-1][j], val[i] + ans[i-1][j-we[i]]);
            else
            ans[i][j]= ans[i-1][j];
        }
    }

    cout << ans[n][w];
}


Measured memory_bytes: 79104