akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#include <chrono> 
 
using namespace std;
using namespace std::chrono; 
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
#define gcd(a,b) __gcd(a,b)
#define vi vector<int>
#define vll vector<ll>
#define vs vector<string>
#define vc vector<char>
#define pb(n) push_back(n)
#define pp pop_back()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define type(a) typeid(a).name();
#define print(arr) cout << "[" ;for(unsigned int i=0;i<(unsigned int) arr.size();i++){ (i==arr.size()-1)?cout << arr[i]:cout << arr[i] << ",";}cout << "]" << endl
#define Arr(arr,l) cout << "[" ;for(unsigned int i=0;i<(unsigned int) l;i++){ (i==l-1)?cout << arr[i]:cout << arr[i] << ",";}cout << "]" << endl
#define console(arr) cout << "["<<endl; for(ll i=0;i<(ll)arr.size();++i){cout << " [";for(ll j=0;j<(ll)arr[i].size();++j){(j==(int)arr[i].size()-1)?cout << arr[i][j]:cout << arr[i][j] << ",";}cout << "]"<<endl;} cout << "]"<<endl
#define starting() auto start = high_resolution_clock::now()
#define ending() auto stop = high_resolution_clock::now();auto duration = duration_cast<microseconds>(stop - start);cout << endl << endl << "Execution Time : "<<duration.count()/1000 << " ms" << endl
 
template <typename T1,typename T2>
void mapped(map<T1,T2>m){for(auto ite=m.begin();ite!=m.end();++ite){cout << "'" << ite->first << "'"<<" : "<<ite->second <<endl;}}
 
template <typename T1 , typename T2>
void mappedArr(map<T1,vector<T2>>m){for(auto ity=m.begin();ity!=m.end();++ity){cout << "'"<< ity->first <<"'"<<" : "<<"[";
for(int i=0;i<(int)ity->second.size();++i){(i==(int)ity->second.size()-1)?cout << ity->second[i]:cout << ity->second[i] << ",";}cout << "]"<<endl;}}
 
string int_to_string(int x){ stringstream ss; ss << x; string ni = ss.str(); return ni;}
int char_to_int(char c){ int n = (int)c - 48; return n; }
int string_to_int(string x){ int n; stringstream s(x); s >> n; return n; }
 
template <typename T1,typename T2>
void ArrPair(vector<pair<T1,T2>>vp){for(int i=0;i<(int)vp.size();++i){
cout << "(" << vp[i].first << "," << vp[i].second << ")"<<endl ;}}
 
const int MOD = 1e9 + 7;
const ll INF = 1e18L + 5;
 
int main(){
   ll  n, k;
   cin >> n >> k;
   vector<ll> v(n);
   for(ll i = 0; i < n; ++i){
	 cin >> v[i];
   }
   ll summed = 0;
   for (int i = 1; i < n; ++i) {
      ll l = (v[i] + v[i-1] - k > 0)?v[i] + v[i-1] - k:0;
      summed += l;
      if(l > 0)v[i] = (v[i] - l > 0)?v[i] - l:0;
   }
   cout << summed;
}















Measured memory_bytes: 1024
from collections import deque


def solve():
    N, Q = map(int, input().split())
    ab = [[0, 0] for _ in range(N-1)]
    for i in range(N-1):
        ab[i] = list(map(int, input().split()))
    px = [[0, 0] for _ in range(Q)]
    for i in range(Q):
        px[i] = list(map(int, input().split()))

    graph = [[] for _ in range(N+1)]
    for a, b in ab:
        graph[a].append(b)
        graph[b].append(a)

    val = [0 for _ in range(N+1)]
    for p, x in px:
        val[p] += x

    que = deque([1])
    parent = [0 for _ in range(N+1)]
    while que:
        i = que.popleft()
        for j in graph[i]:
            if j == parent[i]:
                continue
            parent[j] = i
            que.append(j)
            val[j] += val[i]

    print(*val[1:])


if __name__ == '__main__':
    solve()

Measured memory_bytes: 126140
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int a[200010];
ll mp[200010];
int main(){
    int n;
    while(cin>>n){
        ll ans=0;
        for(int i=0; i<n; ++i){
            scanf("%d",a+i);
            ++mp[a[i]];
        }
        for(int i=0; i<200010; ++i){
        	ans+=mp[i]*(mp[i]-1)/2;
        }
        ll tmp, tmp1;
        for(int i=0; i<n; ++i){
        	tmp1=mp[a[i]]*(mp[a[i]]-1)/2;
        	tmp=ans-tmp1+(mp[a[i]]-2)*(mp[a[i]]-1)/2;
        	printf("%lld\n",tmp);
        }
    }
  return 0;
}




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

int main() {
	int n;
	cin >> n;
	vector <pair<int,int>> x;
	for (int i=0; i<n; i++){
		int a,b;
		cin >> a >> b;
		x.push_back(make_pair(b,a));
	}
	sort(x.begin(),x.end());
	int t=0;
	for (int i=0; i<n; i++){
		t+=x[i].second;
		if (t>x[i].first){
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";
	return 0;
}

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

class unionfind{
    int last;
    int *parent, *time;
    std::vector<std::pair<int, size_t>> *size;
    const size_t length;
public:
    unionfind(size_t n, int *w): last(0), length(n){
        parent = new int[n];
        time = new int[n];
        size = new std::vector<std::pair<int, size_t>>[n];
        for(size_t i=0;i<n;++i){
            parent[i] = w[i];
            time[i] = INT32_MAX;
            size[i].emplace_back(0, w[i]);
        }
    }
    size_t root(size_t v, int t){
        if(time[v] > t) return v;
        else return root(parent[v], t);
    }
    bool is_same(size_t u, size_t v, int t=-1){
        if(t < 0) t = last;
        return root(u, t) == root(v, t);
    }
    int merge(size_t u, size_t v){
        int t = ++last;
        u = root(u, t);
        v = root(v, t);
        if(u == v) return t;
        if(parent[u] < parent[v]) std::swap(u, v);
        parent[u] += parent[v];
        size[u].emplace_back(t, parent[u]);
        parent[v] = u;
        time[v] = t;
        return t;
    }
    size_t count(size_t v, int t=-1){
        if(t < 0) t = last;
        v = root(v, t);
        return std::prev(std::lower_bound(size[v].begin(), size[v].end(), std::pair<int, size_t>{ t, ~0 }))->second;
    }
};

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n, m;
    static int vw[100000];
    static vector<pair<int, int>> edges[100000];
    static pair<int, pair<int, int>> ew[100000];
    static bool ok[100000];

    cin >> n >> m;
    for(int i=0;i<n;++i) cin >> vw[i];
    for(int i=0;i<m;++i){
        int a, b, y;
        cin >> a >> b >> y;
        --a; --b;
        edges[a].emplace_back(b, y);
        edges[b].emplace_back(a, y);
        ew[i] = {y, {a, b}};
    }
    sort(ew, ew+m);
    unionfind uf(n, vw);
    for(int i=0;i<m;++i){
        uf.merge(ew[i].second.first, ew[i].second.second);
    }
    int ans = 0;
    for(int t=m;t>0;--t){
        int u, v, w;
        w = ew[t-1].first;
        tie(u, v) = ew[t-1].second;
        if(ok[u]) continue;
        if(uf.count(u, t) < w) ++ans;
        else{
            queue<int> q;
            q.emplace(u);
            q.emplace(v);
            ok[u] = ok[v] = true;
            while(!q.empty()){
                int f = q.front();
                q.pop();
                for(auto e: edges[f]){
                    if(e.second > w) continue;
                    if(ok[e.first]) continue;
                    ok[e.first] = true;
                    q.emplace(e.first);
                }
            }
        }
    }
    cout << ans << endl;

    return 0;
}

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

flag = [0]*9
t = 0
x = 0
y = 400
while y <= 3200:
  for i in a:
    if x <= i < y: flag[t] = 1
  t += 1
  x += 400
  y += 400
else:
  for i in a:
    if 3200 <= i: flag[8] += 1

if sum(flag[:8]) == 0:
  print(1,flag[8])
  exit()
      
total = sum(flag)
print(total - flag[8], total)

Measured memory_bytes: 9064
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <bits/stdc++.h>
    
    
using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define REV(v) reverse(v.begin(),v.end())
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cout(n) cout<<fixed<<setprecision(n)
#define dout(n) cout<<# n<<" = "<<n<<endl;
#define v1out(v) FOR(j,0,v.size()){cout<<v[j]; if(j!=(ll)v.size()-1)cout<<" ";else cout<<endl; }
#define v2out(v) FOR(i,0,v.size())v1out(v[i]);

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin>>n>>m;
    FOR(i,0,m){
        ll in;
        cin>>in;
        n-=in;
    }
    n = max(n,(ll)-1);
    cout<<n<<endl;

}

Measured memory_bytes: 3660
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let N: usize = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };
    let A: Vec<i64> = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|x| x.parse().unwrap())
            .collect()
    };

    let mut c = std::collections::HashMap::new();
    for &a in &A { *(c.entry(a).or_insert(0)) += 1; }
    let d = {
        let mut d = c.iter().map(|(&k, &v)| (k, v)).collect::<Vec<_>>();
        d.sort_by_key(|&(k, v)| -k);
        d
    };
    let (ans, _) = d.iter().fold((0, 0), |(res, m), &(k, v)|
        if m == 0 && v >= 4 { (k * k, 2) }
        else if m == 1 && v >= 2 { (res * k, m + 1) }
        else if m == 0 && v >= 2 { (k, m + 1) }
        else { (res, m) }
    );

    println!("{}", ans);
}

Measured memory_bytes: 13268
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] x = new int[n];
        int[] y = new int[n];
        int[] h = new int[n];
        int j = 0;
        for (int i = 0; i < n; i++) {
            x[i] = sc.nextInt();
            y[i] = sc.nextInt();
            h[i] = sc.nextInt();
            if (h[i] > 0) j = i;
        }
        for (int cx = 0; cx <= 100; cx++) for (int cy = 0; cy <= 100; cy++) {
            int hgt = h[j] + Math.abs(x[j] - cx) + Math.abs(y[j] - cy);
            boolean ok = true;
            for (int i = 0; i < n; i++) {
                if (h[i] != Math.max(hgt - Math.abs(x[i] - cx) - Math.abs(y[i] - cy), 0)) ok = false;
            }
            if (ok) {
                System.out.println(cx + " " + cy + " " + hgt);
                return;
            }
        }
    }
}

Measured memory_bytes: 22100
N, A, B, C = map(int, input().split())

l_list = [int(input()) for _ in range(N)]
INF = 10 ** 9

def dfs(cur, a, b, c):
  if cur == N:
    return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
  ret0 = dfs(cur + 1, a, b, c)
  ret1 = dfs(cur + 1, a + l_list[cur], b, c) + 10
  ret2 = dfs(cur + 1, a, b + l_list[cur], c) + 10
  ret3 = dfs(cur + 1, a, b, c + l_list[cur]) + 10
  return min(ret0, ret1, ret2, ret3)

print(dfs(0, 0, 0, 0))

Measured memory_bytes: 3064
import Foundation

let input_line = readLine()!

// #1
var characters = Array(input_line.characters)
var count = characters.count
var result = ""
for i in 0..<count {
  switch characters[i] {
    case "0":
    result += "0"
    case "1":
    result += "1"
    case "B":
    if result.characters.count > 0 {
      result = result.substringToIndex(result.endIndex.advancedBy(-1))
    }
    default: break
  }
}
print(result)

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

using lnt = long long;
using Real = long double;

#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(lnt i=0;i<(n);++i)
#define RANGE(i, a, b) for(lnt i=(a);i<(b);++i)
#define RREP(i, n) for(lnt i=(n)-1;i>= 0;--i)

#define ln '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define dcout cout<<fixed<<setprecision(20)
#define summon_tourist cin.tie(0);ios::sync_with_stdio(false)

constexpr int dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
constexpr Real eps = 1e-9; const Real pi = acosl(-1);
constexpr lnt BIG = INT_MAX/10, BBIG = LLONG_MAX/10;

template<class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<class T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<class T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

using pint = pair<int, int>; using plnt = pair<lnt, lnt>;
using vint = vector<int>; using vlnt = vector<lnt>;
constexpr lnt MOD = 1e9+7;

lnt powmod(lnt a, lnt p, lnt m){
	lnt res = 1, tmp = a;
	while(p != 0){
		if(p % 2) res = (res*tmp) % m;
		tmp = (tmp*tmp) % m;
		p /= 2;
	}
	return res;
}

int main(){
	summon_tourist;

	lnt N; cin >> N;

	lnt c00 = 0, c01 = 0, c10 = 0;
	vector<plnt> X;
	map<plnt, lnt> mp;

	REP(i, N){
		lnt a, b; cin >> a >> b;
		if(a==0 and b==0) c00++;
		else if(a==0) c01++;
		else if(b==0) c10++;
		else X.eb(a, b);
	}

	for(plnt &p: X){
		lnt a = p.first, b = p.second;
		lnt g = __gcd(abs(a), abs(b));
		a /= g; b /= g;
		if(a < 0){
			a*=-1; b*=-1;
		}
		mp[{a, b}]++;
		if(b < 0){
			lnt ta = -b, tb = a;
			a = ta; b = tb;
		}
		p = {a, b};
	}
	sort(ALL(X));
	X.erase(unique(ALL(X)), X.end());
	lnt ans = (powmod(2, c01, MOD) + powmod(2, c10, MOD) - 1 + MOD) % MOD;
	for(plnt p: X){
		lnt a = p.first, b = p.second;
		cerr << a << ' ' << b << ln;
		lnt A = b, B = -a;
		lnt c0 = mp[p], c1 = mp[{A, B}];
		ans = ans * ((powmod(2, c0, MOD) + powmod(2, c1, MOD) - 1 + MOD) % MOD) % MOD;
	}
	
	cout << (ans-1+c00+MOD) % MOD << ln;
}

Measured memory_bytes: 35896
import itertools
import operator

def main():
    N = int(input())
    A1 = tuple(map(int, input().split()))
    A2 = tuple(map(int, input().split()))

    a1 = [0] + list(itertools.accumulate(A1, operator.add))
    a2 = [0] + list(itertools.accumulate(A2, operator.add))
    candy = -1
    for i, j in enumerate(a1):
        n = 0
        n += j
        n += a2[i] - a2[i-1] + a2[-1] - a2[i]
        candy = max(n, candy)

    print(candy)

main()


Measured memory_bytes: 3188
import java.util.*;
import java.util.stream.*;

public class Main {
  public static void main(String[] args) throws Exception {
    Scanner in = new Scanner(System.in);
    int N = in.nextInt();
    long[] A = new long[N + 1];
    long[] B = new long[N];
    for (int i = 0; i < N + 1; i++) {
      A[i] = in.nextLong();
    }
    for (int i = 0; i < N; i++) {
      B[i] = in.nextLong();
    }
    long ans = 0;
    for (int i = 0; i < N; i++) {
      ans += Math.min(A[i], B[i]);
      B[i] -= Math.min(A[i], B[i]);
      ans += Math.min(A[i + 1], B[i]);
      A[i + 1] -= Math.min(A[i + 1], B[i]);
    }
    System.out.println(ans);
  }
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
typedef long long ll;

int main() {
    int A,B,C,D,E,F; cin >> A >> B >> C >> D >> E >> F;
    double Eper = (double)E / (double)(100 + E);
    double maxper = 0;
    int sumwater;
    int sugerans;
    rep(a,31){
        rep(b,31){
            int water = 100*A*a + 100*B*b;

            for(int c = 0; c <= 3000; c += C){
                for(int d = 0; d <= 3000; d += D){
                    int suger = c + d;
                    if(suger + water > F){
                        break;
                    }

                    double per = (double)suger / (double)(water + suger);
                    if(per <= Eper && per >= maxper){
                        maxper = per;
                        sumwater = suger + water;
                        sugerans = suger;
                    }
                }
            }
        }
    }

    cout << sumwater << " " << sugerans << endl;
}

Measured memory_bytes: 256
# coding: utf-8


def main():
    N, M, Q = map(int, input().split())
    a, b, c, d = [None] * Q, [None] * Q, [None] * Q, [None] * Q
    for i in range(Q):
        a[i], b[i], c[i], d[i] = map(int, input().split())
        a[i] -= 1
        b[i] -= 1

    A_list = []

    def rec(A, now_v, now_i, N, M):
        if now_i == N-1:
            for k in range(M-now_v+1):
                A_copy = A[:]
                A_copy.append(now_v+k)
                A_list.append(A_copy)
        else:
            for k in range(M-now_v+1):
                A_copy = A[:]
                A_copy.append(now_v+k)
                rec(A_copy, now_v+k, now_i+1, N, M)

    for start in range(1, M+1):
        rec([start], start, 1, N, M)

    # for i in range(10):
    #     print(A_list[i])

    ans = 0
    for A in A_list:
        cand = 0
        for i in range(Q):
            if A[b[i]] - A[a[i]] == c[i]:
                cand += d[i]
        if cand > ans:
            ans = cand
    
    return ans

    
print(main())


Measured memory_bytes: 28624
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


s = input()
l = [chr(v) for v in range(ord("a"), ord("z")+1)]
l2 = {c:i for i,c in enumerate(l)}
def sub(s1, s2, used):
#     print(s1,s2,used)
    if not s1:
        if s2[0]=="z":
            return -1
        else:
            return l[l2[s2[0]]+1]
    if len(s1)+len(s2)<26:
        for i in range(26):
            if l[i] not in used:
                return s1+l[i]+s2
    else:
        if not s2:
            return sub(s1[:-1], s1[-1], set(s1[:-1]))
        for i in range(l2[s2[0]]+1, 26):
            if l[i] not in used:
                ans = s1+l[i]
#                 used.add(l[i])
#                 ans = ans + "".join(sorted([c for c in l if c not in used]))
                return ans
        used.remove(s1[-1])
        return sub(s1[:-1], s1[-1]+s2, used)
ans = sub(s, "", set(s))
print(ans)

Measured memory_bytes: 62200
#include <stdio.h>
#include <math.h>

int main(void)
{
	float x, h;
	
	while (1){
		scanf("%f%f", &x, &h);
		if (x == 0.0 && h == 0.0){
			break;
		}
		
		printf("%f\n", sqrt(x * x / 4 + h * h) * x * 2 + x * x);
		
	}
	
	return (0);
}

Measured memory_bytes: 0
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Spandan Mishra
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ELogsEditorial solver = new ELogsEditorial();
        solver.solve(1, in, out);
        out.close();
    }

    static class ELogsEditorial {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.readInt(), k = in.readInt();
            int[] a = new int[n];

            for (int i = 0; i < n; i++)
                a[i] = in.readInt();

            int lo = 1, hi = Integer.MAX_VALUE;

            while (lo < hi) {
                int mid = lo + (hi - lo) / 2;

                if (isPossible(mid, a, k))
                    hi = mid;
                else
                    lo = mid + 1;
            }

            System.out.println(lo);
        }

        boolean isPossible(int mid, int[] a, int k) {

            for (int x : a) {
                if (x <= mid)
                    continue;

                k -= Math.ceil((double) x / mid) - 1;
            }

            return k >= 0;
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new RuntimeException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new RuntimeException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}



Measured memory_bytes: 36784
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

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

const int MAX_BITS = 63;
const ll INF = LONG_LONG_MAX / 2;

vector<ll> as;
vector<ll> ones; // {0, ones at the MSB, ..., ones at the LSB}

vector<ll> dp1, dp2;

void calc_ones() {
    ones.push_back(0);
    for (int i = MAX_BITS - 1; i >= 0; i--) {
        int cnt = 0;
        for (auto &a : as) {
            if (a & (1LL << i)) cnt++;
        }
        ones.push_back(cnt);
    }
}

void solve(const ll N, const ll K) {
    for (int i = 1; i <= MAX_BITS; i++) {
        ll d_of_k = (K & (1LL << (MAX_BITS - i)));
        // printf("i: %d, d_of_k: %lld\n", i, d_of_k);

        // dp1
        if (d_of_k) {
            if (ones[i] * 2 >= N) {
                chmax(dp2[i], dp1[i - 1] + ones[i] * (1LL << (MAX_BITS - i)));
            }
            chmax(dp1[i], dp1[i - 1] + (N - ones[i]) * (1LL << (MAX_BITS - i)));
        } else {
            chmax(dp1[i], dp1[i - 1] + ones[i] * (1LL << (MAX_BITS - i)));
        }

        // dp2
        if (dp2[i - 1] > 0) {
            if (ones[i] * 2 >= N) {
                chmax(dp2[i], dp2[i - 1] + ones[i] * (1LL << (MAX_BITS - i)));
            }
            chmax(dp2[i], dp2[i - 1] + (N - ones[i]) * (1LL << (MAX_BITS - i)));
        }
    }
}

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

    as.resize(N);
    for (int i = 0; i < N; i++) {
        cin >> as[i];
    }

    calc_ones();
    // cout << "ones: ";
    // for (auto &one : ones) {
    //     cout << one << " ";
    // }
    // cout << endl;

    dp1.resize(MAX_BITS + 1, -INF);
    dp2.resize(MAX_BITS + 1, -INF);
    dp1[0] = 0;
    dp2[0] = 0;

    solve(N, K);

    // printf("dp1: \n");
    // for (auto &x : dp1) {
    //     cout << x << " ";
    // }
    // cout << endl;
    // printf("dp2: \n");
    // for (auto &x : dp2) {
    //     cout << x << " ";
    // }
    // cout << endl;

    cout << max(dp1[MAX_BITS], dp2[MAX_BITS]) << endl;

    return 0;
}


Measured memory_bytes: 1152
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>

using namespace std;

int main(){
	int a,b,c;
	int ty=0,hi=0;
	
	while(scanf("%d,%d,%d",&a,&b,&c)!=EOF){
		if(a==b)
		hi++;
		else if((a*a)+(b*b)==(c*c))
		ty++;
	}
	printf("%d\n%d\n",ty,hi);
}

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

int main() {
  string S;
  cin >> S;
  string out;
  if(S == "Sunny"){
    out = "Cloudy";
  }else if(S == "Cloudy"){
    out = "Rainy";
  }else{
    out = "Sunny";
  }
  cout << out;
}

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

using namespace std;

typedef long long int ll;

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

  ll n;
  cin >> n;
  vector < pair < ll, ll > > vec (n);
  for (auto &i : vec) cin >> i.first >> i.second;

  sort (vec.begin(), vec.end());

  ll add_max = INT_MIN, add_min = INT_MAX, sub_max = INT_MIN, sub_min = INT_MAX;
  for (auto i : vec) {
    add_max = max (add_max, i.first + i.second);
    add_min = min (add_min, i.first + i.second);
    sub_max = max (sub_max, i.first - i.second);
    sub_min = min (sub_min, i.first - i.second);
  }

  cout << max (add_max - add_min, sub_max - sub_min) << '\n';
}


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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
ll MOD = 1e9+7;
//ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x,ll y,ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}
void anss(bool x,string y,string z){if(x)cout<<y<<endl;else cout<<z<<endl;}   
ll gcd(ll x,ll y){ll r;while((r=x%y)!=0){x=y;y=r;}return y;}

int main(){
  ll i,j,o;
  ll res=0,res1=0,res2=INF,buf=0,buf1=0,buf2=0,buf3=0,buf4=0;
  bool judge = true;
  ll x,y;cin>>x>>y;
  if(x==2||y==2)judge=false;
  else if(x==4||x==6||x==9||x==11){
    judge=(y==4||y==6||y==9||y==11);
  }
  else if(y==4||y==6||y==9||y==11){
    judge=(x==4||x==6||x==9||x==11);
  }
  ans1(judge);

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
int main() {
    int n;
    scanf("%d", &n);
    int t[n], x[n], y[n];

    t[0] = x[0] = y[0] = 0;

    for (int i = 1; i <= n; i++) { 
        scanf("%d %d %d", &t[i], &x[i], &y[i]);
    }

    for (int i = 1; i <= n; i++) { 
        int dt = t[i] - t[i - 1];
        int dist = abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1]);

        if (dist > dt || dist % 2 != dt % 2 ) {
            puts("No");
            return 0;
        }
    }

    puts("Yes");
    return 0;
}

Measured memory_bytes: 1408
#include <cassert>
#include "limits.h"
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <memory>
#include <utility>
 
#define rep(i, a, b) for (long long (i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " <<"LINE:"<<__LINE__<<"  "<< #i <<":"<< i << std::endl

 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if ((a == 0)||(mod!=-1&&a%mod==0)) {
    return 0;
  }
 
  long long x = 1;
 
  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}
 
// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

using ll = long long;
using P = std::pair<ll, ll>;

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

  ll n;
  std::cin>>n;

  rep(i,1,n+1){
    if((i*108)/100==n){
      std::cout<<i<<"\n";
      return 0;
    }
  }

  std::cout<<":(\n";

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <vector>
#include <cstdlib>
#include <list>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

static const int MAX = 100000;
static const int NIL = -1;

int n,color[MAX];
vector<int>G[MAX];

void assignColor();
void dfs(int r, int c);

int main() {

	int s, t, m, q;
	cin >> n >> m;

	for (int i = 0; i < m; i++) {
		cin >> s >> t;
		G[s].push_back(t);
		G[t].push_back(s);
	}

	assignColor();

	cin >> q;

	for (int i = 0; i < q; i++) {
		cin >> s >> t;
		if (color[s] == color[t])
			cout << "yes" << endl;
		else
			cout << "no" << endl;
	}

	return 0;
}

void assignColor() {
	int id = 1;
	for (int i = 0; i < n; i++) {
		color[i] = NIL;
	}
	for (int u = 0; u < n; u++) {
		if (color[u] == NIL)
			dfs(u, id++);
	}
		
}

void dfs(int r, int c) {
	stack<int>S;
	S.push(r);
	color[r] = c;

	while (!S.empty()) {
		int u = S.top();
		S.pop();
		for (int i = 0; i < G[u].size(); i++) {
			int v = G[u][i];
			if (color[v] == NIL) {
				color[v] = c;
				S.push(v);
			}
		}
	}
}

Measured memory_bytes: 9040
# D - Match Matching

N, M = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse = True)

n_match = [-1,2,5,5,4,5,6,3,7,6]

dp = [-1] * (N+1) # dp[i]はちょうどi本のマッチ棒で作れる最も桁数の多い整数の桁数

dp[0] = 0
for idx in range(1,N+1):
    tmp = []
    for x in A:
        if idx - n_match[x] >= 0:
            tmp.append(dp[idx - n_match[x]] + 1)
    if tmp:
        dp[idx] = max(tmp)

ans = ""
rest_match = N
while len(ans) <= N//2 and rest_match > 0:
    for x in A:
        if rest_match - n_match[x] >= 0 and dp[rest_match - n_match[x]] == dp[rest_match] - 1:
            ans += str(x)
            rest_match -= n_match[x]
            break
            
print(ans)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n; cin >> n;
  vector<int> p(n);
  int cnt = 0;
  for(int i = 0; i < n; i++)
    cin >> p.at(i);
  
  for(int i = 1; i < n -1; i++){
    int a = p.at(i - 1),b = p.at(i),c = p.at(i + 1);
    
    if((b > a and b < c) or (b < a and b > c)){
      cnt++;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;

int main()
{
  ll n;
  string s;
  cin>>n>>s;
  map<char,ll> mp;
  for (int i = 0; i < n; ++i)
  {
    mp[s[i]]++;
  }
  ll sum=mp['R']*mp['G']*mp['B'];
  vector<vector<ll>> rightRGB(n,vector<ll>(3,0));
  for (int i = 0; i < n; ++i)
  {
    mp[s[i]]--;
    rightRGB[i][0]=mp['R'];
    rightRGB[i][1]=mp['G'];
    rightRGB[i][2]=mp['B'];
  }
  for (int i = 0; i < n; ++i)
  {
    for (int j = i+1; j < n; ++j)
    {
      if(s[i]==s[j]) continue;
      int k=2*j-i;
      if(k>=n) continue;
      //cout<<i<<" "<<j<<" "<<k<<" "<<endl;
      if(s[k]!=s[i] && s[j]!=s[k]) sum--;
    }
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 3788
package main

import (
	"fmt"
	"sort"
)

func main() {
	arr := scanNums(2)
	X := arr[0]
	N := arr[1]
	ps := scanNums(N)
	res := 0
	for i := 0; i < 100; i++ {
		isExist1 := false
		isExist2 := false
		for _, p := range ps {
			if p == X-i {
				isExist1 = true
			}
			if p == X+i {
				isExist2 = true
			}
			if isExist1 && isExist2 {
				break
			}
		}
		if isExist1 == false {
			res = X - i
			break
		}
		if isExist2 == false {
			res = X + i
			break
		}
	}
	fmt.Print(res)
}
func MySort(a []int) {
	sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })

}
func Abs(i int) int {
	if i < 0 {
		return -1 * i
	}
	return i
}
func Min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func CalcNum(tate int, yoko int, A int, B int, dp *map[[2]int]int) int {
	if (*dp)[[2]int{tate, yoko}] != 0 {
		return (*dp)[[2]int{tate, yoko}]
	}
	return yoko*CalcNum(tate-1, yoko, A, B, dp) + tate*CalcNum(tate, yoko-1, A, B, dp)
}
func scanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return
}


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

long long a[100000];
int cnt[41];

int main() {
	int n;
	long long k;

	scanf("%d %lld", &n, &k);

	for (int i = 0;i < n;++i)
		scanf("%lld", &a[i]);

	for (int i = 0;i < n;++i)
		for (int j = 40;j >= 0;--j)
			if (((1LL << j) & a[i]) == 0)
				cnt[j]++;

	long long tot = 0;
	for (int i = 40;i >= 0;--i) 
		if ((tot | (1LL << i)) <= k && cnt[i] >= n - cnt[i])
			tot |= 1LL << i;

	long long ans = 0;
	for (int i = 0;i < n;++i)
		ans += tot ^ a[i];

	printf("%lld", ans);

	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define F first
#define S second
#define pii pair<int,int>
#define ll long long
#define __ ios::sync_with_stdio(false),cin.tie(0)
/*
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimization ("unroll-loops")
*/
using namespace std;
void solve(){
string s;
int k=0;
cin>>k>>s;
if(s.size()>k) {s.erase(k,s.size()-k);cout<<s<<"...";}
else cout<<s;


}
int main(){
//freopen("","",stdin);
__;
int T=1;
//cin>>T;
while(T--){
solve();
}
}


Measured memory_bytes: 3660
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>
using namespace std;

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    int maxi = max(a, max(b, c));
    cout << a + b + c - maxi << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<unordered_map>
#include<unordered_set>

using namespace std;
typedef long long int ll;typedef pair<int, int> P;
const long long mod = 1e9 + 7;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define ALL(a) (a).begin(),(a).end()



int main(void) {
	int h, w; cin >> h >> w;
	char arr[100][100];
	bool x = 0;
	set<int> hh;
	set<int> ww;
	rep(hi, h)rep(wi, w)cin >> arr[hi][wi];
	rep(hi, h) {
		rep(wi, w) {
			if (arr[hi][wi] == '#')x = 1;
		}
		if (x)ww.insert(hi);//show
		x = 0;
	}
	rep(wi, w) {
		rep(hi, h) {
			if (arr[hi][wi]=='#')x = 1;
		}
		if (x)hh.insert(wi);
		x = 0;
	}
	rep(hi, h) {
		rep(wi, w)
			if (ww.count(hi) && hh.count(wi))
				cout << arr[hi][wi];
		if(ww.count(hi))cout << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);

	static void solve() {
		double a = in.nextDouble();
		double b = in.nextDouble();
		double r = 3.305785;

		out.println(a*b/r);
	}

	public static void main(String[] args) {
		long start = System.currentTimeMillis();

		solve();
		out.flush();

		long end = System.currentTimeMillis();
		//trace(end-start + "ms");
		in.close();
		out.close();
	}

	static void trace(Object... o) { System.out.println(Arrays.deepToString(o));}
}

Measured memory_bytes: 27952
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(long long (i)=0, i_bound = (long long)(n); (i)<i_bound; ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
signed main(){
    string s;
    cin>>s;
    bool good = true;
    for(int i=0; i<s.size(); i++){
        if(i%2==0 and s[i]=='L'){
            good = false;
            break;
        }
        else if(i%2==1 and s[i]=='R'){
            good = false;
            break;
        }
    }
    if(good) cout <<"Yes" <<endl;
    else cout <<"No" <<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
    int N;
    cin >> N;
    int l = N / 100;
    int m = (N % 100) / 10;
    int r = (N % 10);
    if (l < m || l < r) {
        l++;
        cout << l * 100 + l * 10 + l;
    } else {
        cout << l * 100 + l * 10 + l;
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
typedef long long ll;

int main() {
  int a,b,h;
  cin>>a>>b>>h;
  cout << (a+b)*h/2 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vt = vector<T>;
template<class T> using vvt = vector<vt<T>>;
template<class T> using ttt = tuple<T,T>;
using tii = tuple<int,int>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define DIV int(1e9+7)
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
//const double PI = M_PI;
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}
#define chmax(a,b) a=max(a,b)
class UF{
public:
  vi value;
  vi over; // When over < 0, 'over' keep number of node(using negative number). -1 means this tree is a node.
  int root(int index){
    int t = index;
    stack<int> stack_i;
    while(over[t] >= 0){
      stack_i.push(t);
      t = over[t];
    }
    while(!stack_i.empty()){
      int i = stack_i.top(); stack_i.pop();
      over[i] = t;
    }// reconnect
    return t;
  }
  void merge(int a,int b){
    if(this->root(a) == this->root(b)) return;
    over[root(a)] += over[root(b)]; // over have a number of nodes.
    over[root(b)] = root(a);
  }
  int NumNode(int a){
    return -over[root(a)];
  }
  UF(int Nodes){
    value.resize(Nodes);
    over.resize(Nodes);
    rep(i,Nodes)
      over[i] = -1;
  }
};
/*Coding Space*/
UF uf(300050);
ll cnt[400020][2] = {};
const int D = 100005;
int main(){
  int n; cin >> n;
  rep(i,n){
    int x,y; cin >> x >> y;
    y += D;
    uf.merge(x,y);
  }
  rep(i,200020){
    cnt[uf.root(i)][i/D]++;
  }
  ll ans = 0;
  rep(i,200020)  ans +=  cnt[i][0]*cnt[i][1];
  cout << ans - n << endl;
}


Measured memory_bytes: 6656
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  char A[50][50], B[50][50];
  for(int i=0; i<N; ++i) scanf("%s", &A[i][0]);
  for(int i=0; i<M; ++i) scanf("%s", &B[i][0]);
  for(int Ay=0; Ay<=N-M; ++Ay) {
    for(int Ax=0; Ax<=N-M; ++Ax) {
      for(int y=0; y<M; ++y) {
        for(int x=0; x<M; ++x) {
          if(B[y][x] != A[Ay+y][Ax+x]) goto next;
        }
      }
      cout << "Yes" << endl;
      return 0;
      next:
      continue;
    }
  }
  cout << "No" << endl;
  return 0;
}

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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


int N, M;
vs A, B;

bool isMatch(int x, int y)
{
    REP(i, M)
    {
        REP(j, M)
        {
            if(B[i][j] != A[y+i][x+j]) return false;
        }
    }
    return true;
}

void solve()
{
    cin >> N >> M;
    A = vs(N); B = vs(M);
    REP(i, N) cin >> A[i];
    REP(i, M) cin >> B[i];

    REP(i, N)
    {
        REP(j, N)
        {
            if(i+M>N||j+M>N) continue;
            if(isMatch(j, i))
            {
                cout << "Yes" << endl;
                return;
            }
        }
    }
    cout << "No" << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;
 
 
#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((int)(x).size())
//vvintを作る　マクロで　 #define vvint(N,M) vector<vector<int>>
 
using namespace std;

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

    int N, D;
    cin >> N >> D;

    cout << ceil((double)N/(2*D+1))  << endl;

    return 0;
}

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

int main(){
  ll n;cin>>n;
  map<ll,ll> m;
  ll su=0;
  for(int i=0;i<n;i++){
    int a;cin>>a;
    m[a]++;
    su+=a;
  }
  
  ll q;cin>>q;
  for(int i=0;i<q;i++){
    int b,c;cin>>b>>c;
    su=su-b*m[b]+c*m[b];
    cout<<su<<endl;
    m[c]+=m[b];
    m[b]=0;
  }
}

Measured memory_bytes: 9416
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef int_fast64_t ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
inline void fastio(){cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15);}
ll gcd(ll a,ll b){ll c=max(a,b);ll d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll modfact(ll a){ll b=1;FOR(i,2,a)b=b*i%MOD;return b;}
ll modpow(ll a, ll n){ll b=1;while (n>0){if(n&1)b=b*a%MOD;a=a*a%MOD;n>>=1;}return b;}
ll modcomb(ll n, ll k){ll b=1;k=min(n-k,k);DOWN(i,n,n-k+1)b=b*i%MOD;return b*modpow(modfact(k),MOD-2)%MOD;}

int N, M;
int A[200001];

int main() {
    fastio();
    cin >> N;
    REP(i, N) {
        cin >> M;
        A[M] = i;
    }
    ll ans = 0;
    set<ll> P;
    P.insert(-1);
    P.insert(N);
    FOR(i, 1, N) {
        ll pos = A[i];
        auto r = P.upper_bound(pos);
        auto l = prev(r);
        ans += (*r - pos) * (pos - *l) * i;
        P.insert(pos);
    }
    cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 10368
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections

n,m = map(int,input().split())
H = list(map(int,input().split()))
edge =[[] for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)
cnt = 0

for i in range(n):
    flag = False
    for j in range(len(edge[i])):
        if H[i]<=H[edge[i][j]]:
            flag = True
            break
    if flag == False:
        cnt+=1
print(cnt)

Measured memory_bytes: 29772
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
char A[1100];
char B[1100];
int mod=10000;
short int dp[2][520][3][11][11];
char tc[1100];
int c;
int calc(){
	int n=strlen(tc);
	for(int i=0;i<2;i++)for(int j=0;j<520;j++)for(int k=0;k<3;k++)
		for(int l=0;l<11;l++)for(int m=0;m<11;m++)
			dp[i][j][k][l][m]=0;
	dp[0][0][1][10][10]=1;
	int ret=0;
	for(int i=0;i<n;i++){
		int t=i%2;
		for(int j=0;j<520;j++)for(int k=0;k<3;k++)
		for(int l=0;l<11;l++)for(int m=0;m<11;m++)
			dp[!t][j][k][l][m]=0;
		for(int j=0;j<c;j++){
			for(int k=0;k<3;k++)for(int l=0;l<11;l++)for(int m=0;m<11;m++){
				if(!dp[t][j][k][l][m])continue;
				for(int n=0;n<10;n++){
					if(i==0&&n==0)continue;
					if(m==n)continue;
					int tm=(j*10+n)%c;
					int tk=k;
					if(tk==1&&n<tc[i]-'0')tk=0;
					if(tk==1&&n>tc[i]-'0')tk=2;
					if(l<10&&m<10&&(l-m)*(n-m)<=0)continue;
					dp[!t][tm][tk][m][n]=(dp[!t][tm][tk][m][n]+dp[t][j][k][l][m])%mod;
				}
			}
		}
		for(int j=0;j<3;j++){
			for(int k=0;k<11;k++)for(int l=0;l<11;l++){
				if(i+1==n&&j==2)continue;
				ret=(ret+dp[!t][0][j][k][l])%mod;
			}
		}
	}
	return ret;
}
int main(){
	scanf("%s%s",A,B);
	scanf("%d",&c);
	for(int i=0;i<1100;i++)tc[i]=B[i];
	int ret=calc();
	for(int i=0;i<1100;i++)tc[i]=A[i];
	ret=(ret+mod-calc())%mod;
	int now=0;
	bool ok=true;
	for(int i=0;A[i];i++){
		now*=10;
		now+=A[i]-'0';
		now%=c;
		if(i>=1&&A[i]==A[i-1])ok=false;
		if(i>=2&&(A[i]-A[i-1])*(A[i-2]-A[i-1])<=0){
			ok=false;
		}
	}
	if(ok&&now==0)ret=(ret+1)%mod;
	printf("%d\n",ret);
}

Measured memory_bytes: 1764
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
    int N;
    cin >> N;
    if (N < 105) {
        cout << 0 << endl;
    } else if (N < 135) {
        cout << 1 << endl;
    } else if (N < 165) {
        cout << 2 << endl;
    } else if (N < 189) {
        cout << 3 << endl;
    } else if (N < 195) {
        cout << 4 << endl;
    } else {
        cout << 5 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define NAME_LEN 10

typedef struct proc{
  char name[ NAME_LEN + 1 ];
  int time;
}Proc;

int main( void ){
  int n, q;
  scanf("%d %d\n", &n, &q);

  Proc *proc = ( Proc * )malloc( ( n + 1 )* sizeof( Proc ) );
  int head = 0, tail = n;

  for( int i = 0; i < n ; i ++ )
    scanf("%s %d\n", proc[ i ].name, &proc[ i ].time);

  int clock = 0;
  while( 1 ){
    if( head == tail ) break;

    Proc current = proc[ head ];
    current.time -= q;
    clock += q;

    head ++;
    head %= n + 1;

    if( current.time > 0 ){
      proc[ tail ] = current;
      tail ++;
      tail %= n + 1;
    } else {
      clock += current.time;
      printf("%s %d\n", current.name, clock);
    }
  }
  return 0;
}



Measured memory_bytes: 2508
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int A, B, C;
    cin >> A >> B >> C;
    if(A == B && B == C){
        if(A % 2 == 0 && B % 2 == 0 && C % 2 == 0){
            output(-1);
        }
        else{
            output(0);
        }
        
        return 0;
    }
    
    int ans = 0;
    while(A % 2 == 0 && B % 2 == 0 && C % 2 == 0){
        int na = (B + C) / 2;
        int nb = (C + A) / 2;
        int nc = (A + B) / 2;
        A = na, B = nb, C = nc;
        ans++;
    }
    output(ans);
    
    return 0;
}

Measured memory_bytes: 256