akhauriyash/Code-Regression huggingface dataset:
x,n = map(int,input().split())
a=list(map(int,input().split()))

for i in range(x,x+200):
    if i not in a:
        ans1=i
        break
for i in range(x,x-200,-1):
    if i not in a:
        ans2=i
        break
if abs(ans1-x)>=abs(ans2-x):
    print(ans2)
else:
    print(ans1)



Measured memory_bytes: 61872
#include <bits/stdc++.h>
using namespace std;
int main()
{long long x=0,n=0,f=0,temp=0,d=0,f1=0,d1=0,f2=0;
    cin>>x>>n;
    long long a[n];
    for(long long i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]==x)
        {f=1;
        }
    }
    if(f!=1||n==0)
    cout<<x;
    else
    {sort(a,a+n);
    for(long long i=0;i<n;i++)
    {
        if(a[i]==x)
        {
            temp=i;
            break;
        }
    }
        for(long long j=temp;j>=0;j--)
        {
            if(j>0)
            {
                if((a[j]-a[j-1])!=1)
                {
                    d=x-a[j]+1;
                    f1=1;
                    break;
                }
            }
        }
        if(f1!=1)
        d=x-a[0]+1;
        for(long long j=temp;j<n;j++)
        {
            if(j<n-1)
            {
                if((a[j+1]-a[j])!=1)
                {
                    d1=a[j]-x+1;
                    f2=1;
                    break;
                }
            }
        }
        if(f2!=1)
        d1=a[n-1]-x+1;
        
        if(d1<d)
        cout<<x+d1;
        else if(d1>=d)
        cout<<x-d;
    }
}


Measured memory_bytes: 3640
#include <stdio.h>

int main (){
  long n, a, b, ab, q, r, totalBolasAzuis=0;

  scanf("%ld", &n);
  scanf("%ld", &a);
  scanf("%ld", &b);

  if (a==0){
    printf("0\n");
    return 0;
  }

  ab = a + b;
  q = n/ab;
  r = n%ab;

  if(r > a){
    totalBolasAzuis = (q*a) + a;
  } else {
    totalBolasAzuis = (q*a) + r;
  }

  printf("%ld\n", totalBolasAzuis);

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define DEBUG_MODE
#define endl '\n'
#ifdef DEBUG_MODE
#define DEBUG(X) debug_func(X, #X)
#define DEBUG_ENDL endl
#define DEBUG_SEPARATOR_LINE cout<<"=================\n"
#else
#define DEBUG(X) 0
#define DEBUG_ENDL 0
#define DEBUG_SEPARATOR_LINE 0
#endif
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
#define DEBUG_ENDL_S(S) ((S).size() ? "\n" : "")
template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename Head, typename... Tail> const Head& var_min(const Head &head, const Tail&... tail) { return min(head, var_min(tail...)); }
template <typename Head, typename... Tail> const Head& var_max(const Head &head, const Tail&... tail) { return max(head, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
void debug_func_preffix(const string &s) { if(s.size()) cout << s << " = "; }
template <typename T>
void debug_func(const T &t, const string &s = "") {
    debug_func_preffix(s);
    cout << t << DEBUG_ENDL_S(s);
}
template <typename T, typename U>
void debug_func(const P<T, U> &p, const string &s = "") {
    debug_func_preffix(s);
    cout << "(";
    debug_func(p.first);
    cout << ", ";
    debug_func(p.second);
    cout << ")" << DEBUG_ENDL_S(s);
}
template <typename T>
void debug_func(const V<T> &v, const string &s = "") {
    for(ll i = 0; i < v.size(); i++) {
        string t = s + "[" + to_string(i) + "]";
        debug_func(v[i], t);
    }
}

VV<ll> cnt(9, V<ll>(9, 0));

ll calc(const V<ll> &p) {
    V<PLL> coors(9);
    for(ll i = 0; i < 3; i++) for(ll j = 0; j < 3; j++) coors[p[3 * i + j]] = PLL(i, j);
    ll ret = 0;
    for(ll i = 0; i < 9; i++) for(ll j = 0; j < 9; j++) {
        ll d = abs(coors[i].first - coors[j].first) + abs(coors[i].second - coors[j].second); 
        ret += d * cnt[i][j];
    }
    return ret;
}

int main() {
    V<ll> nums(9);
    iota(ALL(nums), 0ll);
    ll N;
    cin >> N;
    string S;
    cin >> S;
    for(ll i = 0; i < N - 1; i++) cnt[S[i] - '1'][S[i + 1] - '1']++;
    V<ll> ans = nums;
    ll mcnt = 5e15;
    do {
        ll tmp = calc(nums);
        if(tmp < mcnt) {
            mcnt = tmp;
            ans = nums;
        }
    } while(next_permutation(ALL(nums)));
    for(ll i = 0; i < 3; i++) for(ll j = 0; j < 3; j++) {
        cout << ans[3 * i + j] + 1;
        if(j + 1 == 3) cout << endl;
    }
    return 0;
}



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

#define MAXN 200005
#define int long long
#define LL long long
#define pii pair<long, long>
#define fi first
#define se second
#define fastio ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

using namespace std;

int N;
int h[MAXN], a[MAXN];
struct Seg {
    int id, l, r, m, val;
    void build(int idx, int s, int e);
    Seg& left();
    Seg& right();
    void update(int pos, int nval);
    int query(int s, int e);
} nodes[MAXN*4];
Seg& Seg::left() { return nodes[id*2]; }
Seg& Seg::right() { return nodes[id*2+1]; }
void Seg::build(int idx, int s, int e) {
    id = idx, l = s, r = e, m = (l+r) >> 1;
    if (l != r) left().build(idx*2, s, m), right().build(idx*2+1, m+1, e);
}
int Seg::query(int s, int e) {
    if (l == s && e == r) return val;
    if (e <= m) return left().query(s, e);
    if (s > m) return right().query(s, e);
    return max(left().query(s, m), right().query(m+1, e));
}
void Seg::update(int pos, int nval) {
    if (l == r) {
         val = max(val, nval);
         return;
    }
    if (pos <= m) left().update(pos, nval);
    else right().update(pos, nval);
    val = max(left().val, right().val);
}

signed main() {
    fastio;
    cin >> N;
    nodes[1].build(1, 0, N);
    for (int i = 1; i <= N; i++) cin >> h[i];
    for (int i = 1; i <= N; i++) cin >> a[i];
    for (int i = 1; i <= N; i++) {
        nodes[1].update(h[i], nodes[1].query(0, h[i]-1) + a[i]);
    }
    cout << nodes[1].query(0, N) << endl;
    return 0;
}

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

int main(){
  int n;cin>>n;
  int A[n];for(int i=0;i<n;i++)cin>>A[i];
  int ans=0,now=1;
  for(;;){
    if(now==2){
      cout<<ans<<endl;
      break;
    }
    if(ans>=n){
      cout<<-1<<endl;
      break;
    }
    ans++;
    now=A[now-1];
    }
}


Measured memory_bytes: 640
//Author : pakhandi
//
using namespace std;

#include <bits/stdc++.h>

#define wl(n) while(n--)
#define fl(i,a,b) for(i=a; i<b; i++)
#define rev(i,a,b) for(i=a; i>=b; i--)

#define si(n) scanf("%d", &n)
#define sll(l) scanf("%lld",&l)

#define debug(x) cout<<"\n#("<<x<<")#\n"
#define nline printf("\n")

#define mem(a,i) memset(a,i,sizeof(a))

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

#define PB push_back
#define SZ size
#define MP make_pair

#define IGNORE cin.ignore (std::numeric_limits<std::streamsize>::max(), '\n');

const ll INF = (1LL << 58);
const bool DEBUG = 0;

ll N;

int main()
{
	int i, j;
	sll(N);

	ll left = N % 11;

	N = N - left;

	ll ans = 0;
	if(N != 0)
	{
		ans = (N / 11) * 2;
	}

	// cout << left << "\n";

	if(left)
	{
		if(left <= 6)
			ans++;
		if(left > 6)
			ans += 2;
	}

	printf("%lld\n", ans);

	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

int main(){
  int N;
  cin>>N;
  VI A(N-1);
  rep(i,N-1) cin>>A[i];
  VI B(N);
  rep(i,N-1) B[A[i]-1]++;
  rep(i,N) cout<<B[i]<<endl;
}




Measured memory_bytes: 4792
import kotlin.random.Random

//

fun main() {
    intro_heuristicsa()
}

fun intro_heuristicsa() {
    val d = readLine()!!.toInt()
    val c = readLine()!!.split(" ").map { it.toInt() }
    val s = MutableList(d) { listOf<Int>()}
    repeat(d) {
        s[it] = readLine()!!.split(" ").map { it.toInt() }
    }
    val nextContest = (1..26).toMutableList()
    nextContest.shuffle()
    repeat(d) {
        val i = nextContest[it % 26]
        println(i)
    }
}


Measured memory_bytes: 40036
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;

alias Pair = Tuple!(int, "a", int, "b");

void main() {
    int N, M;
    scan(N, M);

    auto g = new bool[][](N, N);
    foreach (i ; 0 .. M) {
        int ai, bi;
        scan(ai, bi);
        ai--, bi--;
        g[ai][bi] = g[bi][ai] = 1;
    }

    // 補グラフを作る
    auto adj = new int[][](N, 0);
    foreach (i ; 0 .. N) {
        foreach (j ; 0 .. N) if (j != i) {
            if (!g[i][j]) {
                adj[i] ~= j;
            }
        }
    }

    debug {
        writeln(adj);
    }
    auto col = new int[](N);
    col[] = -1;

    Pair nibu(int v, int c) {
        col[v] = c;
        auto res = c ? Pair(0, 1) : Pair(1, 0);

        foreach (u ; adj[v]) {
            if (col[u] == -1) {
                auto p = nibu(u, c ^ 1);
                if (p == Pair(-1, -1)) {
                    return Pair(-1, -1);
                }
                res = Pair(res.a + p.a, res.b + p.b);
            }
            else if (col[u] == col[v]) {
                return Pair(-1, -1);
            }
        }

        return res;
    }

    Pair[] ps;

    foreach (i ; 0 .. N) {
        if (col[i] == -1) {
            auto p = nibu(i, 0);
            if (p == Pair(-1, -1)) {
                writeln(-1);
                return;
            }
            ps ~= p;
        }
    }

    debug {
        writeln(ps);
    }

    auto U = ps.length.to!int;

    auto dp = new bool[][](U + 1, N + 1);
    dp[0][0] = true;

    foreach (i ; 0 .. U) {
        foreach (j ; 0 .. N + 1) {
            if (dp[i][j]) {
                dp[i + 1][j + ps[i].a] = true;
                dp[i + 1][j + ps[i].b] = true;
            }
        }
    }

    auto k = 0;
    foreach (i ; 0 .. N + 1) {
        if (dp[U][i]) {
            chmax(k, i * (N - i));
        }
    }

    debug {
        writefln("%(%s\n%)", dp);
    }

    auto L = N * (N - 1) / 2 - M;
    auto ans = M - (k - L);
    writeln(ans);
}




void scan(T...)(ref T args) {
    auto line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x > arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x < arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

void yes(bool ok, string y = "Yes", string n = "No") {
    return writeln(ok ? y : n);
}


Measured memory_bytes: 8700
#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(){
  string s;
  cin>>s;
  int cnt=0;
  rep(i,3){
    if(s[i]=='1')cnt++;
  }
  cout<<cnt;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define P pair<int,int>
#define ll __int64
int main(){
	int x;
	cin>>x;
	cout<<x/3<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

llong n;
llong a[3005];
llong dp[3005][3005];
const llong INF = 1ll << 60ll;

llong dfs(int f, int s, int t) {
    if (s == t) return 0;

    if (dp[s][t] != INF) return dp[s][t];

    if (f) {
        return dp[s][t] = max(dfs(f ^ 1, s + 1, t) + a[s],
                              dfs(f ^ 1, s, t - 1) + a[t - 1]);
    }
    else {
        return dp[s][t] = min(dfs(f ^ 1, s + 1, t) - a[s],
                              dfs(f ^ 1, s, t - 1) - a[t - 1]);
    }
}

int main() {
    for (int i = 0; i < 3005; i++) {
        for (int j = 0; j < 3005; j++) {
            dp[i][j] = INF;
        }
    }
    
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];

    cout << dfs(1, 0, n) << endl;

    return 0;
}


Measured memory_bytes: 71040
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

#define int long long
#define ll long long
//#define double long double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

const int INF = 1e9;
const int MB = 30;
const int MOD = 1e9 + 7;
const double PI = atan2(0, -1);


void solve() {
    double r;
    cin >> r;
    cout << 2 * PI * r;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    //int t;
    //cin >> t;
    int t = 1;
    //srand(time(0));
    cout.precision(12);
    cout << fixed;
    while (t--) solve();
}

Measured memory_bytes: 3768
const input = require("fs").readFileSync("/dev/stdin", "utf8").split("\n");

const N = input[0].split(' ').map(item => parseInt(item))[0]
input.shift()
input.pop()

AB = input.map(item => item.split(' ').map(item2 => parseInt(item2)))
const A = AB.map(item => item[0])
const B = AB.map(item => item[1])

// console.log(AB)
AB.sort((a, b) => a[1] - b[1])
// console.log(AB)

count = 0
for (i = 0; i < N; i++) {
    count += AB[i][0]
    if (count > AB[i][1]) {
        console.log('No')
        return
    }
}
console.log('Yes')


Measured memory_bytes: 68656
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
ll const INF = 1LL << 60;
ll const MAX_N = 100000;
ll const MOD = 1000000007;

int main() {
    string S;
    ll w;
    cin >> S >> w;

    for (ll i = 0; i < S.length(); i += w) {
        cout << S[i];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3612
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = GetLongNumArray();
            var a = input[0];
            var b = input[1];
            var c = input[2];
            var d = input[3];
            var ans = new List<long>();

            ans.Add(a * c);
            ans.Add(a * d);
            ans.Add(b * c);
            ans.Add(b * d);

            var rrr = ans.OrderByDescending(x => x).ToList()[0];
            Console.WriteLine(rrr);
        }

        private static long[] GetLongNumArray()
        {
            var input = Console.ReadLine().Split(' ');
            return input.Select(x => long.Parse(x)).ToArray();
        }

        private static long GetLongNum()
        {
            return long.Parse(Console.ReadLine());
        }

        private static string[] GetStringArray()
        {
            return Console.ReadLine().Split(' ');
        }

        private static string GetString()
        {
            return Console.ReadLine();
        }
    }
}


Measured memory_bytes: 28452
package main

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

type TupleInt struct {
	X int
	H int
}

func main() {
	sc := NewScanner()
	N, D, A := sc.NextInt(), sc.NextInt(), sc.NextInt()
	t := make(SortInterFace, N)
	for i := 0; i < N; i++ {
		t[i] = TupleInt{sc.NextInt(), sc.NextInt()}
	}
	sort.Sort(t)
	s := make([]int, N+1)
	ans := 0
	for i := 0; i < N; i++ {
		if s[i] < t[i].H {
			need := (t[i].H - s[i] + A - 1) / A
			right := t[i].X + 2*D
			id := upper_bound(t, right)
			s[i] += need * A
			s[id] -= need * A
			ans += need
		}
		s[i+1] += s[i]
	}
	fmt.Println(ans)
}

func upper_bound(A []TupleInt, value int) int {

	l := 0
	r := len(A)
	for r-l > 1 {
		c := (r + l) / 2
		if A[c].X <= value {
			l = c
		} else {
			r = c
		}
	}
	return r
}

type SortInterFace []TupleInt

func (s SortInterFace) Len() int {
	return len(s)
}
func (s SortInterFace) Less(i, j int) bool {
	return s[i].X < s[j].X
}
func (s SortInterFace) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 10368
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

int main()
{
    size_t n,t; cin>>n;cin>>t;
    vector<string> v(n);
    for(auto&& str : v)
        cin >> str;
    sort(v.begin(), v.end());
    for(auto&& str : v)
        cout << str;
    cout << endl;
}

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

int main(){
  int K; cin >> K;
  if(K<10){
    cout << K << endl;
    return 0;
  }
  queue<int64_t> Q;
  Q.push(1);
  Q.push(2);
  Q.push(3);
  Q.push(4);
  Q.push(5);
  Q.push(6);
  Q.push(7);
  Q.push(8);
  Q.push(9);
  int count=9;
  while(true){
    int64_t a=Q.front();
    if(a%10!=0){
      Q.push(a*10+(a%10)-1);
      count++;
      if(count==K){
        cout << Q.back() << endl;
        return 0;
      }
    }
    Q.push(a*10+(a%10));
    count++;
    if(count==K){
      cout << Q.back() << endl;
      return 0;
    }
    if((a%10)!=9){
      Q.push(Q.back()+1);
      count++;
      if(count==K){
        cout << Q.back() << endl;
        return 0;
      }
    }
    Q.pop();
  }
  return 0;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n, k;
	cin >> n >> k;

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

	for (; k > 0; k--) {
//		cerr << k << " " << a[0] << endl;
		if (*min_element(all(a)) >= n) break;
		
		vector<pll> events;
		events.reserve(2*n);
		FOR(i,0,n) {
			events.eb(i-a[i],1);
			events.eb(i+a[i]+1,-1);
		}
		sort(all(events));

		ll j = 0, dep = 0;
		FOR(i,0,n) {
			while (j < sz(events) && events[j].xx <= i) dep += events[j++].yy;
			a[i] = dep;
		}
//		FOR(i,0,n) cout << a[i] << " \n"[i+1==n];
	}
	
	FOR(i,0,n) cout << a[i] << " \n"[i+1==n];

}



Measured memory_bytes: 11124
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#include <iterator>
#define FI first
#define SE second
#define PF push_front
#define PB push_back
#define POF pop_front
#define POB pop_back
#define MA make_pair
#define ll long long
#define PA pair<ll,ll>
#define VE vector<ll>
#define VP vector<pair<ll,ll> >
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
const int mod=1e9+7;
//
int main(){
  int V[3];
  FOR(i,0,3){
    cin>>V[i];
  }
  sort(V,V+3);
  int K;
  cin>>K;
  FOR(i,0,K){
    V[2]*=2;
  }
  cout<<V[0]+V[1]+V[2]<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstdio>
#include<iomanip>
#include<cmath>
using namespace std;

int main(){
//    cout << fixed << setprecision(10);
    
    int S, W;
    cin >> S >> W;
    
    cout << (S <= W ? "unsafe" : "safe");

    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int H, W;
char grid[1111][1111];
int cost[1111][1111];

void bfs()
{
    int dx[4] = {1, 0, -1, 0};
    int dy[4] = {0, 1, 0, -1};

    queue<pair<int, pair<int, int>>> que;
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            if (grid[i][j] == '#')
            {
                que.emplace(0, make_pair(i, j));
            }
        }
    }

    while (!que.empty())
    {
        auto p = que.front();
        que.pop();
        int y = p.second.first, x = p.second.second, cnt = p.first;
        if (cost[y][x] != inf)
            continue;
        cost[y][x] = cnt;
        grid[y][x] = '#';
        cnt++;
        for (int i = 0; i < 4; i++)
        {
            int ny = y + dy[i], nx = x + dx[i];
            if (ny < 0 || ny >= H)
                continue;
            if (nx < 0 || nx >= W)
                continue;
            if (grid[ny][nx] == '#')
                continue;
            que.emplace(cnt, make_pair(ny, nx));
        }
    }
}

int main()
{
    cin >> H >> W;

    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            cin >> grid[i][j];
            cost[i][j] = inf;
        }
    }
    bfs();
    int ans = 0;
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            ans = max(cost[i][j], ans);
            //printf("%3d ",cost[i][j]);
        }
        //cout << endl;
    }
    cout << ans << endl;
}


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

int main() {
  int k,a,b;
  cin >> k >> a >> b;
  bool x = 0 ;
  
  for(int i = 0 ; i < b - a + 1 ; i++){
    if((a + i) % k == 0 ) x = 1;
  }
  
  if(x) cout << "OK" << endl;
  else cout <<"NG" << endl;
}

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

int N;
const int MAX_N = 100 + 10;
int S[MAX_N];

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

    int sum = 0;
    int min_not_ten = 1.0e9;
    bool f = false;
    for (int i = 0; i < N; i++) {
        sum += S[i];
        if (S[i] % 10 != 0) {
            min_not_ten = min(min_not_ten, S[i]);
            f = true;
        }
    }

    if (sum % 10 == 0) {
        if (f) {
            cout << sum - min_not_ten << endl;
        }
        else {
            cout << 0 << endl;
        }
    }
    else {
        cout << sum << endl;
    }
    

    return 0;
}


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

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T,vector<T>,greater<T>>;

constexpr long long MOD = (long long)1e9 + 7;
constexpr long long MOD2 = 998244353;
constexpr long long HIGHINF = (long long)1e18;
constexpr long long LOWINF = (long long)1e15;
constexpr long double PI = 3.1415926535897932384626433;

template <class T> vector<T> make_v(size_t N,T init){return vector<T>(N,init);}
template <class... T> auto make_v(size_t N,T... t){return vector<decltype(make_v(t...))>(N,make_v(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max(a,b);}
template <class T> void chmin(T& a, const T b){a=min(a,b);}
void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;}

vector<pair<char,long long>> Rarts(string S){
	S = S + ".";
	int cnt = 1;
	vector<pair<char,long long>> res;
 	for(int i = 0; i+1 < S.size(); ++i){
		 if(S[i]==S[i+1]) {
			 cnt++;
		 }
		 else{
			 res.push_back({S[i],cnt});
			 cnt = 1;
		 }
	}
	return res;
}

int main() {
    int N; cin >> N;
    string S; cin >> S;
    auto R = Rarts(S);
    cout << R.size() << endl;


    return 0;
}


Measured memory_bytes: 2676
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    B = len(set(A))
    print(B - (N - B) % 2)


if __name__ == '__main__':
    main()


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

#define print(x) cerr << #x << " is " << x << endl;
#define int long long int
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vpi vector<pair<int, int>>
#define all(v) (v).begin(), (v).end()
#define pii pair<int, int>
#define pb push_back
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define out cout << fixed << setprecision(12) <<

const int N = 2e5 + 10;
const int mod = 1e9 + 7;

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

    int ans=0;
    int n;
    cin>>n;
    
    for(int i=1;i<=n;++i){
        for(int j=1;j<=n;++j){
            for(int k=1;k<=n;++k){
                ans+=__gcd(i,__gcd(j,k));
            }
        }
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 3652
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main () {
    char *s1 = malloc(sizeof(char)*55), *s2 = malloc(sizeof(char)*55);
    scanf("%s %s", s1, s2);
    for (int i=0; i<strlen(s1); ++i) {
        if((i+1 == strlen(s1)) && (strlen(s1)-strlen(s2) == 1)) {
            printf("%c", s1[i]);
            break;
        }
        printf("%c%c", s1[i], s2[i]);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 128
// Problem : A - Frog 1
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include "bits/stdc++.h"
using namespace std;
#define IOS { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define pb push_back
#define nl cout<<"\n"
#define endl "\n"
#define all(c) (c).begin(),(c).end()
#define trav(a,x) for(auto a = x.begin() ; a != x.end() ; a++)
#define rep(i,n) for(int i = 0 ; i < n ; i++)
#define lb lower_bound
#define ub upper_bound
#define pll pair<ll,ll>
#define vll vector<ll>
#define f first
#define s second
typedef long long ll;
typedef unsigned long long ull ;
typedef long double ld;

inline ll max(ll a,ll b) {return ((a>b)?a:b);}
inline ll min(ll a,ll b) {return ((a>b)?b:a);}
inline ll gcd(ll a ,ll b) {if(b==0) return a; a%=b;return gcd(b,a);}
ll power(ll x, ll y){if(y == 0) return 1; ll a = power(x,y/2);if (y % 2 == 0) return a * a; else return x * a * a; }
ll powermod(ll x, ll ex , ll md) {ll ans = 1ll;while (ex > 0) {if (ex & 1ll) ans = (ans * x) % md; ex >>= 1ll;x = (x * x) % md;}return ans;}

const ll inf = 1e18 + 9;
const ll mod = 1e9 + 7;
const ld PI = acos(-1);
const ld eps = 1e-9;

const ll N = 1e6 + 1;
ll n;
ll dp[N];
ll h[N];
void solve(){
	cin >> n;
	rep(i , n) cin >> h[i];
	rep(i , n){
		if(i == 0) dp[i] = 0;
		else if(i == 1) dp[i] = abs(h[i] - h[0]);
		else if(i == 2) dp[i] = abs(h[i] - h[0]);
		else dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]) , dp[i - 2] + abs(h[i] - h[i - 2])) ;
	}
	cout << dp[n - 1] << endl;
}
int main(){
    IOS;
    cout << fixed << setprecision(20);
    ll NTC=1;
    // cin>>NTC;
    ll PTC=0;
    while(PTC++<NTC){
        // cout<<"Case #"<<PTC<<":"<<' ';
        solve();
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}


Measured memory_bytes: 5120
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // int64_t

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

int get_int(void) {
  int num;
  scanf("%d", &num);
  return num;
}

int get_int2(int *a1, int *a2) {
  scanf("%d %d", a1, a2);
  return 0;
}

// <arr[0]> <arr[1]> .. <arr[size-1]>
int fget_array(int *arr, int size) {
    int i;
    for(i = 0; i < size; i++) {
        scanf("%d", &arr[i]);
    }
    return 0;
}

#define NUM_MAX 50
#define K_MAX 50
#define ELEM_MAX 50
#define SUM_MAX (NUM_MAX*ELEM_MAX)

int main(void) {
    static int64_t dp[NUM_MAX+1][K_MAX+1][SUM_MAX+1];
    dp[0][0][0] = 1;
    int num, ave;
    get_int2(&num, &ave);
    static int arr[NUM_MAX];
    fget_array(arr, num);

    int i, j, k;
    for(i = 1; i <= num; i++) {
        int val = arr[i-1];
        for(k = 0; k <= i; k++) {
            for(j = 0; j <= k*ELEM_MAX; j++) {
                dp[i][k][j] += dp[i-1][k][j];
                if(k >= 1 && j >= val) dp[i][k][j] += dp[i-1][k-1][j-val];
            }
        }
    }
    int64_t ans = 0;
    for(k = 1; k <= num; k++) {
#ifdef DEBUG
        if(dp[i][k][ave*k])printf("dp[%d][%d][%d]=%lld\n", i, k, ave*k, dp[i][k][ave*k]);
#endif
        ans += dp[num][k][ave*k];
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 48512
/*
    飲んだ魔剤で家が建つ。
    created at: 2020-04-06 17:12:40
*/

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()
#define rev(x) greater<x>()
#define MOD 1000000007
#define INF 1000000000

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

LL modpower(LL n, LL m, LL mod) {
    if (m == 0) {
        return 1;
    } else if (m % 2 == 0) {
        LL p = modpower(n, m/2, mod);
        return p*p % mod;
    } else {
        return n*modpower(n, m-1, mod) % mod;
    }
}

LL modinv(LL n, LL mod) {
    return modpower(n, mod-2, mod);
}

LL modcombination(LL n, LL r, LL mod) {
    LL ret = 1;

    for (int i = 0; i < r; i++) {
        ret *= (n-i);
        ret %= mod;
        ret *= modinv(i+1, mod);
        ret % mod;
    }

    return ret % mod;
}

int gcd(int k, int l) {
    if (l > 0) return gcd(l, k%l);
    else return k;
}

struct UnionFind {
    vector<int> par;

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

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

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

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

    int ans = 0;
    for (int i = 1; i <= 12; i++) {
        if (i < a) {
            ans++;
        } else if (i == a && i <= b) {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

void trace(int *,int);
void insertionSort(int *,int);

int main(){

  int i;
  int N =0;
  int A[1000];
  

  
  scanf("%d",&N);

  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  
    trace(A,N);
    insertionSort(A,N);

    return 0;
}
  
  void trace(int A[],int N){
    int i;

    for(i=0 ; i<N; i++){
      if( i > 0){
	printf(" ");
      }

      printf("%d",A[i]);
    }
    printf("\n");
  }

  
      
  void insertionSort(int A[],int N){
    int i,j,v;
    
    for(i=1 ; i<N ; i++){
      v = A[i];
      j = i - 1;
      
      while( j >= 0 && A[j] > v){
      A[j +1] = A[j];
      j--;
      }
      A[j+1] = v;
      
      trace(A,N);
    }
  }
  



Measured memory_bytes: 2068
function Main(input) {
  input = input.trim()
  var arr = input.split("\n").map(Number);
  var N = arr[0];
  arr.shift();
  arr = arr.sort();
  var sum = 1;
  for(var i=1;i<N;i++){
    if(arr[i-1]!=arr[i]){
      sum++;
    }
  }
  console.log(sum);
}Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	string s, t;
	cin >> s >> t;

	ll res = 0;
	FOR(i,0,3) res += s[i] == t[i];
	cout << res << endl;
}



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

bool ok(ll x, ll y, ll X, ll Y) {
  if (y < X+1) return false;
  if (Y < x+1) return false;
  return true;
}

int main() {
  ll N, M, X, Y; cin >> N >> M >> X >> Y;
  ll Ma = -1000;
  ll mb = 1000;
  for (ll i = 0; i < N; i++) {
    ll a; cin >> a; Ma = max(Ma, a);
  }
  for (ll i = 0; i < M; i++) {
    ll b; cin >> b; mb = min(mb, b);
  }
  
  if (Ma < mb && ok(Ma,mb,X,Y)) {
    cout << "No War" << endl;
  } else {
    cout << "War" << endl;
  }
}
  

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

int main() {
    string s;
    cin >> s;
    string correct = "CODEFESTIVAL2016";

    int convNeed = 0;

    for(int i=0;i<s.size();i++){
        if(s[i]!=correct[i])convNeed++;
    }

    cout << convNeed << endl;

    return 0;
}


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

int main()
{
	string s;
	int i, j;
	cin>>s;
	if(s[2]==s[3]&&s[4]==s[5])
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	
	return 0;
}

Measured memory_bytes: 256
n = int(input())
w = [input() for _ in range(n)]
words_hist = set([])

last_letter = w[0][0]
for word in w:
    if word in words_hist:
        print('No')
        exit()
    if not word.startswith(last_letter):
        print('No')
        exit()
    
    words_hist.add(word)
    last_letter = word[-1]

print('Yes')

Measured memory_bytes: 9164
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

a = int(input())
b = make_divisors(a)
idx = len(b) // 2
if len(b) % 2 == 0:
  target = (b[idx],b[idx-1])
else:
  target = (b[idx],b[idx])
print(target[0]-1 + target[1]-1)

Measured memory_bytes: 3296
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>
#include <locale>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x
using namespace std;


const int INF = 10000000;
const long long INFL = (1LL<<40);
const int MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}

template< typename T >
struct edge{
    int src, to;T cost;
    edge(int to,T cost) :src(-1),to(to),cost(cost){}
    edge(int src, int to, T cost) :src(src),to(to),cost(cost){}edge
    &operator=(const int &x){
        to =x;
        return *this;
    }
    operator int() const{ return to;}
};



int main() {
    int n, m,x;cin>>n>>m>>x;
    set<int>A;rep(i,m){int a; cin>>a;A.insert(a);}
    int c0=0;
    int cN=0;
    rep(i,x){
        c0+=A.count(i);
    }
    repsg(i,x+1,n+1){
        cN+=A.count(i);
    }
    cout<<min(c0,cN)<<endl;
    
    return 0;
}







Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define next Next
#define gc getchar
#define int long long
const int N=1e6+5;
/*char buf[1<<21],*p1=buf,*p2=buf;
inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}*/
inline int read()
{
    int ret=0,f=0;char c=gc();
    while(!isdigit(c)){if(c=='-')f=1;c=gc();}
    while(isdigit(c)){ret=ret*10+c-48;c=gc();}
    if(f)return -ret;return ret;
}
signed main()
{
	int a=read();
	for(int i=1;i<=9;i++)
		for(int j=1;j<=9;j++)
			if(a==i*j){puts("Yes");return 0;}
	puts("No");
}

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

using namespace std;

using ll = long long int;

bool comp(const pair<ll,ll>& a, const pair<ll,ll>& b) {
    return a.second < b.second;
}

int main() {
    int N; cin >> N;
    vector<pair<ll,ll>> jobs(N);

    for(auto& j : jobs) {
        cin >> j.first >> j.second;
    }

    sort(jobs.begin(), jobs.end(), comp);

    bool flag = true;
    ll current_time = 0ll;

    for_each(jobs.begin(), jobs.end(), [&](pair<ll,ll>& j) {

            current_time += j.first;
            if(current_time > j.second) {
                flag = false;
                return;
            }

            });


    cout << ( flag ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <stdio.h>

#include <vector>

using namespace std;

int main()
{
    int H, W;
    while (cin >> H >> W) {
        if (H == 0 && W == 0) {
            break;
        }

        for (int i = 0; i < H; i++) {

            if (i%2 == 1) {
                for (int j = 0; j < W; j++) {
                    if (j%2==1) {
                        cout << "#";
                    }
                    else {
                        cout << ".";
                    }   
                }
                cout << endl;
            }
            else {
                for (int j = 0; j < W; j++) {
                    if (j % 2 == 1) {
                        cout << ".";
                    }
                    else {
                        cout << "#";
                    }
                }
                cout << endl;
            }

            }
        cout << endl;
    }

    return 0;
}


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

int main(){
  int n,x;
  cin >> n >> x;
  int l[n];
  ll d=0;
  int ans;
  for(int i=0;i<n;i++){
    cin >> l[i];
    d += l[i];
    if(d<=x)ans=i+2;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
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; }
const ll INF = 1e18;
const ll MOD = 1e9 + 7;



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

    rep(fi, 2){
        rep(se, 2){
            vector<int> v(n, -1);
            //0:sheep, 1:wolf
            v[0] = fi;
            v[1] = se;
            bool ok = true;
            for(int i=1; i<n-1; i++){
                if(v[i] == 0){
                    if(s[i] == 'o') v[i+1] = v[i-1];
                    else v[i+1] = !v[i-1];
                }
                if(v[i] == 1){
                    if(s[i] == 'o') v[i+1] = !v[i-1];
                    else v[i+1] = v[i-1];
                }
            }

            //check
            if(s[0] == 'o'){
                if(v[0] == 0) ok &= (v[1] == v[n-1]);
                else ok &= (v[1] != v[n-1]);
            }
            if(s[0] == 'x'){
                if(v[0] == 0) ok &= (v[1] != v[n-1]);
                else ok &= (v[1] == v[n-1]);
            }
            if(s[n-1] == 'o'){
                if(v[n-1] == 0) ok &= (v[n-2] == v[0]);
                else ok &= (v[n-2] != v[0]);
            }
            if(s[n-1] == 'x'){
                if(v[n-1] == 0) ok &= (v[n-2] != v[0]);
                else ok &= (v[n-2] == v[0]);
            }

            if(ok){
                rep(i, n) cout << (v[i] ? "W" : "S");
                cout << endl;
                return 0;
            }
        }
    }
    cout << -1 << endl;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> R(n);
    rep(i,n) cin >> R[i]; 

    int maxv = -1001001001;
    int minv = R[0];

    for (int i = 1; i < n; i++){
        maxv = max(maxv, R[i] - minv);
        minv = min(minv, R[i]);
    }

    cout << maxv << endl;
    
    return 0;
}


Measured memory_bytes: 3544
package main

import (
	"fmt"
	"math"
)

func main() {
	input := scanNums(2)
	N := input[0]
	D := input[1]

	fmt.Print(math.Ceil(float64(N) / float64(2*D + 1)))

	return
}

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: 512
#!/usr/bin/env python
# coding: utf-8

# In[5]:


H,N = map(int, input().split())
A = []; B = []
for _ in range(N):
    a,b = map(int, input().split())
    A.append(a)
    B.append(b)


# In[12]:


a_max = max(A)
dp = [0]*(H+a_max)
for i in range(H+a_max):
    dp[i] = min(dp[i-a] + b for a,b in zip(A,B))
print(min(dp[H-1:]))


# In[ ]:






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

struct P
{
    int x,y;

    bool operator<(const P &a)const{
        if(x!=a.x) return x>a.x;
        return y<a.y;
    }
};


vector<int> v[1];
vector<int> v1;
//bitset<4001000> b;
int i,n,m,k,a,d,b,c;
int e;
int o[2];
int l[1];
int j[31];

int dx[10]={0,1,0,-1,1,1,-1,-1},dy[10]={1,0,-1,0,1,-1,1,-1},dz[10]={0,0,0,0,1,-1};
int px[10]={-1,1,1,-1,1,1,-1,-1},py[10]={1,1,-1,-1,1,-1,1,-1};
long long mod=1000000007,mod2=1000000009,mod3=2017;
long long x,z,y;
double pi=3.14159265;
P u[1];
stack<int> s;
//set<int> se[33],s1;

//priority_queue<P> q[2];
queue<P> q;
string r,r1;

//char r1[110],r[331];
//2147483647
//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
map<int,int> p;
//v.resize(unique(v.begin(),v.end())-v.begin());

bool as(P a,P b)
{
    //if(a.x!=b.x)
    return a.x<b.x;

}


//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//rng();



int main()
{
    cin>>r;
    for(int t=0;t<r.size();t++)
        if(r[t]=='o') k++;
    if(k+(15-r.size())>=8) puts("YES");
    else puts("NO");
}




Measured memory_bytes: 256