akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cstdio>
#include<cmath>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
int MOD=1000000007;
int inf=MOD;int res=inf;int buf=0;
int n,aa,bb,cc;
int l[8];
int calc(int cur,int a,int b,int c){
    if(cur==n){
        if(a==0)return inf;
        if(b==0)return inf;
        if(c==0)return inf;
        return abs(a-aa)+abs(b-bb)+abs(c-cc)-30;
    }
    vector<int> buf(4);
    buf[0]=calc(cur+1,a,b,c);
    buf[1]=calc(cur+1,a+l[cur],b,c)+10;
    buf[2]=calc(cur+1,a,b+l[cur],c)+10;
    buf[3]=calc(cur+1,a,b,c+l[cur])+10;
    int min=inf;
    rep(i,4)if(min>buf[i])min=buf[i];
    return min;
}
signed main(){
    cin>>n>>aa>>bb>>cc;
    rep(i,n)cin>>l[i];
    res=calc(0,0,0,0);
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 256
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let a: Vec<char> = input::<String>().chars().collect();
    let b: Vec<char> = input::<String>().chars().collect();
    let c: Vec<char> = input::<String>().chars().collect();
    println!(
        "{}",
        if a[a.len() - 1] == b[0] && b[b.len() - 1] == c[0] {
            "YES"
        } else {
            "NO"
        }
    );
}


Measured memory_bytes: 4352
#include<cstdio>
#include<cmath>
#include <stdlib.h>

float spase(float a,float b,float c){
	return sqrt((a+b+c)*(b-a+c)*(a-b+c)*(a+b-c));
}

int main(){
	float a,b,c,d,e,f,g,h,AB,BC,CD,DA,AC,BD,abc,bcd,cda,dab;
	while( scanf("%f,%f,%f,%f,%f,%f,%f,%f",&a,&b,&c,&d,&e,&f,&g,&h) != EOF ){
		AB=sqrt((a-c)*(a-c)+(b-d)*(b-d));
		BC=sqrt((c-e)*(c-e)+(d-f)*(d-f));
		CD=sqrt((e-g)*(e-g)+(f-h)*(f-h));
		DA=sqrt((g-a)*(g-a)+(h-b)*(h-b));
		AC=sqrt((a-e)*(a-e)+(b-f)*(b-f));
		BD=sqrt((c-g)*(c-g)+(d-h)*(d-h));
		abc=((a-c)*(c-e)+(b-d)*(d-f))/AB/BC;
		bcd=((c-e)*(e-g)+(d-f)*(f-h))/BC/CD;
		cda=((e-g)*(g-a)+(f-h)*(h-b))/CD/DA;
		dab=((g-a)*(a-c)+(h-b)*(b-d))/DA/AB;
		//printf("%f %f %f %f\n",abc,bcd,cda,dab);
		//printf("%f %f %f %f\n",acos(abc),acos(bcd),acos(cda),acos(dab));
		abc=acos(abc)+acos(bcd)+acos(cda)+acos(dab);
		//printf("%f %f %f %f\n",abc,2*M_PI,spase(AB,BC,AC)+spase(CD,DA,AC),spase(DA,AB,BD)+spase(CD,BC,BD));
		//printf("%d %d\n",abs(abc-2*M_PI)<0.0001,abs(spase(AB,BC,AC)+spase(CD,DA,AC)-spase(DA,AB,BD)-spase(CD,BC,BD))<0.0001);
		if(((abs(abc-2*M_PI)<0.0001))&&(abs(spase(AB,BC,AC)+spase(CD,DA,AC)-spase(DA,AB,BD)-spase(CD,BC,BD))<0.0001)){
			printf("YES\n");
		}
		else{
			printf("NO\n");
		}
	}
	return 0;
}

Measured memory_bytes: 2752
// https://atcoder.jp/contests/abc114/tasks/abc114_c
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)

int n;
int fn(string s) {
    if (s != "" && stoll(s) > n) {
        return 0LL;
    }
    int ret = 1;
    vector<char> v = {'3', '5', '7'};
    for (auto &x : v) {
        if (s.find(x) == string::npos) {
            ret = 0;
            break;
        }
    }
    for (auto &x : v) {
        ret += fn(s + x);
    }
    return ret;
};

void solve() {
    cin >> n;
    cout << fn("") << endl;
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}


Measured memory_bytes: 3660
/*
No i'm not down, No I'm not out
*/
#include <bits/stdc++.h>
using namespace std;
#define fast() ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll  long long
#define f(i,a,b) for(int i=a; i<b; i++)
#define pb push_back
#define MP make_pair
#define vi vector<int>
#define vll vector<long long>
#define M map<int,int>
#define F     first
#define S    second
#define nl "\n"
#define lb lower_bound
#define ub upper_bound
#define max(a, b) (a < b ? b : a)
#define min(a, b) (a > b ? b : a)
#define mem(a,n)  memset(a, n, sizeof(a))
#define all(v) v.begin(), v.end()
int dx[8] ={0, 0, 1, 1, 1, -1, -1, -1};
int dy[8] ={1, -1, -1, 0, 1, -1, 0, 1};
#define mod 10000007
#define N 100005

int main()
{
    fast();
    int n, k;
    cin >> n >> k;
    int a[n], dp[n];
    dp[0] = 0;
    f(i, 0, n)
    {
        cin >> a[i];
        if(i)dp[i] = INT_MAX;
        f(j, max(i-k, 0), i)
            dp[i] = min(dp[i], (dp[j] + abs(a[i] - a[j])));
    }
    cout << dp[n-1] ;
    return 0;
}


Measured memory_bytes: 1024
import sys
import itertools

def intinput(): return map(int,sys.stdin.readline().split())

n,m=intinput()
l = []
for i in range(m):
    l.append(list(map(lambda e:e-1,list(intinput())[1:])))
p = list(intinput())
x = list(itertools.product((0,1),repeat=n))
cnt=0
for i in x:
    r=0
    f=0
    for j in l:
        if sum(list(map(lambda e:i[e],j)))%2!=p[r]:
            f=1
            break
        r+=1
    if f==0:
        cnt += 1
print(cnt)

Measured memory_bytes: 3188
// C++ 14
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <queue>
#include <stack>
#include <math.h>

#define ll long long
#define Int int
#define loop(x, start, end) for(Int x = start; x < end; x++)
#define loopdown(x, start, end) for(int x = start; x > end; x--)
#define span(a,x,y) a.begin()+x,a.begin()+y
#define span_all(a) a.begin(),a.end()
#define len(x) (x.size())
#define last(x) (*(x.end()-1))

using namespace std;

#define MAX_N 2001

Int N;
vector<Int> L(MAX_N, -1);

void input() {
  cin >> N;
  loop(i,0,N) cin >> L[i];
}

void solve() {
  sort(span(L,0,N));
  Int count = 0;
  loop(a,0,N-2) {
    loop(b,a+1,N) {
      Int min_c = L[a] - L[b] + 1;
      Int max_c = L[a] + L[b] - 1;
      count += upper_bound(span(L,b+1,N), max_c) - lower_bound(span(L,b+1,N), min_c);
    }
  }
  cout << count << endl;
}

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

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

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

  vector<int> a(n), b(n), c(n - 1);

  for (auto&& e : a) cin >> e;
  for (auto&& e : b) cin >> e;
  for (auto&& e : c) cin >> e;

  int t = a[0] - 1;
  int ans = b[t];

  for (int i = 1; i < n; i++) {
    int u = a[i] - 1;
    ans += b[u];
    if (t + 1 == u) ans += c[t];
    t = u;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#define Cpp

#ifdef C
#include <stdio.h>
#define abs(a) ((a) < 0 ? -(a) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define isdigit(a) ((a) >= '0' && (a) <= '9' ? true : false)
#endif
#ifdef Cpp
#include <bits/stdc++.h>
using namespace std;
#endif

#define freopen(x) freopen(x".in", "r", stdin);freopen(x".out", "w", stdout)
#define repl(i, t) for (int i = fi[t]; i; i = ne[i])
#define rep(i, a, b) for (int i = (int) a;  i <= (int) b; ++i)
#define per(i, a, b) for (int i = (int) a;  i >= (int) b; --i)
#define _r read()
#define readtype long long

typedef long long var;

const int INF = 0x3f3f3f3f;
const int N = 100;

double a[N];

readtype read();

int main() {
  int n = _r;
  rep(i, 1, n) a[i] = _r;
  sort(a + 1, a + n + 1);
  rep(i, 1, n) a[i + 1] = (a[i] + a[i + 1]) / 2;
  printf("%.5lf", a[n]);
  return 0;
}

readtype read() {
  readtype a = 0, c = getchar(), s = 0;
  while (!isdigit(c)) s |= c == '-', c = getchar();
  while (isdigit(c)) a = a * 10 + c - 48, c = getchar();
  return s ? -a : a;
}


Measured memory_bytes: 256
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

ans = 0

# =============================================================================
# if A[0] > B[0]:
#     ans += B[0]
# else:
#     # 全て倒せる（次の町を参照
#     B[0] -= A[0]
#     ans += A[0]
#     A[1] -= B[0]
#     ans += B[0]
# =============================================================================

for i in range(N):
    if(A[i] > B[i]):
        # 全て倒せない
        ans += B[i]
        A[i] -= B[i]
    else:
        # 全て倒せる
        B[i] -= A[i]
        ans += A[i]
        A[i] = 0
        # 次の場所へ
        if(A[i+1] > B[i]):
            #次の場所はすべて倒せない
            ans += B[i]
            A[i+1] -= B[i]
        else:
            #次の場所もすべて倒せる
            ans += A[i+1]
            A[i+1] = 0
#    print(A[i],B[i])
    
print(ans)

Measured memory_bytes: 18624
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  string s;
  cin>>s;
  int n;
  n = s.size();
  int p=0;
  REP(i,n){
    if(s[i]=='p'){
      p++;
    }
  }
  int ans=n/2-p;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 512
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_MOD			1000000007								// 除数(10の9乗+7)
#define D_ARRAY_MAX		200000									// 最大配列数

// 内部変数
static FILE *szpFpI;											// 入力
static int si1Array[D_ARRAY_MAX];								// 配列
static int siACnt;												// 配列数

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
	static int siTNo;
#endif

// １行出力
int
fOutLine(
	char *pcpLine				// <I> １行
)
{
	char lc1Buf[1024];

#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, pcpLine)) {
		siRes = -1;
	}
#else
	printf("%s", pcpLine);
#endif

	return 0;
}

// ソート関数 - int降順
int
fSortFncID(
	const void *pzpVal1			// <I> 値１
	, const void *pzpVal2		// <I> 値２
)
{
	int *lipVal1 = (int *)pzpVal1;
	int *lipVal2 = (int *)pzpVal2;

	// int降順
	if (*lipVal1 > *lipVal2) {
		return -1;
	}
	else if (*lipVal1 < *lipVal2) {
		return 1;
	}

	return 0;
}

// べき乗 - 取得
int
fGetModPower(
	int piBase					// <I> 基数
	, int piIdx					// <I> 指数
)
{
	// 平方リスト - 作成
	int li1Val[100];
	li1Val[0] = piBase;
	int liCnt = 1;
	int liIdx = 1;
	while (piIdx > liIdx) {
		li1Val[liCnt] = (int)((long long)li1Val[liCnt - 1] * (long long)li1Val[liCnt - 1] % D_MOD);
		liCnt++;
		liIdx += liIdx;
	}

	// べき乗 - 取得
	int liVal = 1;
	while (piIdx > 0) {
		if (piIdx >= liIdx) {
			piIdx -= liIdx;
			liVal = (int)((long long)liVal * (long long)li1Val[liCnt - 1] % D_MOD);
		}
		liCnt--;
		liIdx /= 2;
	}

	return liVal;
}

// 実行メイン
int
fMain(
)
{
	int i;
	char lc1Buf[1024];

	// 配列数 - 取得
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d", &siACnt);

	// 配列 - 取得
	for (i = 0; i < siACnt; i++) {
		fscanf(szpFpI, "%d", &si1Array[i]);
	}
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	qsort(si1Array, siACnt, sizeof(int), fSortFncID);

	// パターン数(１項目) - 取得
	long long llVal = fGetModPower(2, siACnt - 1);
	long long llPCnt1 = llVal * llVal % D_MOD;
	long long llPCnt2 = llPCnt1 * 2 % D_MOD;

	// コスト合計 - 取得
	long long llPSum = llPCnt2;
	long long llCSum = 0;
	for (i = 0; i < siACnt; i++) {
		llCSum = (llCSum + (long long)si1Array[i] * llPSum) % D_MOD;
		llPSum = (llPSum + llPCnt1) % D_MOD;
	}

	return (int)(llCSum % D_MOD);
}

// １回実行
int
fOne(
)
{
	int liRet;
	char lc1Buf[1024];

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 実行メイン
	liRet = fMain();

	// 出力
	sprintf(lc1Buf, "%d\n", liRet);
	fOutLine(lc1Buf);

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", siTNo);
	}
	else {
		printf("NG %d\n", siTNo);
	}
#endif

	return 0;
}

// プログラム開始
int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		siTNo = i;
		fOne();
	}
#else
	fOne();
#endif

	return 0;
}



Measured memory_bytes: 1788
#include<stdio.h>
#define NIL -1

typedef struct node{
  int p;
  int l;
  int r;
}Node;
Node T[100000];
int D[100000];
int n;

void print(int u){
  int i,c;
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].p);
  printf("depth = %d, ",D[u]);
  if(T[u].p == NIL){
    printf("root, ");
  }else if(T[u].l == NIL){
    printf("leaf, ");
  }else{
    printf("internal node, ");
  }
  printf("[");
  c = T[u].l;
  while(c != NIL){
    printf("%d",c);
    if(T[c].r!=NIL){
      printf(", ");
    }
    c = T[c].r;
  }
  printf("]\n");
}

void rec(int u,int p){
D[u] = p;
  if(T[u].r != NIL)rec(T[u].r,p);
  if(T[u].l != NIL)rec(T[u].l,p+1);
}


int main(){
  int i,j,k,v,c,l,r;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    T[i].p = NIL;
    T[i].l = NIL;
    T[i].r = NIL;
  }

  for(i=0;i<n;i++){
    scanf("%d%d",&v,&k);
    for(j=0;j<k;j++){
      scanf("%d",&c);

      if(j == 0){
        T[v].l = c;
      }else{
        T[l].r = c;
      }
      l = c;
      T[c].p = v;
    }
  }
  for(i=0;i<n;i++){
    if(T[i].p == NIL){
      r = i;
    }
  }
    rec(r,0);

    for(i=0;i<n;i++){
      print(i);
    }

    return 0;

}

Measured memory_bytes: 5300
#include <cstdio>
#include <vector>
#include <numeric>
#include <set>

using namespace std;

int main() {
    int n, m, a, b;
    scanf("%d%d", &n, &m);
    vector< set<int> > e(n);
    vector< vector<int> > d(1 << n, vector<int>(n));
    for (int i = 0; i < m; ++i) {
        scanf("%d%d", &a, &b);
        --a, --b;
        e.at(a).insert(b);
        e.at(b).insert(a);
    }
    d.at(1).at(0) = 1;
    for (int i = 1; i < (1 << n); ++i) for (int k = 0; k < n; ++k) if ((i & (1 << k)) == 0) for (int j = 0; j < n; ++j) if (e.at(j).find(k) != e.at(j).end()) d.at(i | (1 << k)).at(k) += d.at(i).at(j);
    printf("%d\n", accumulate(d.back().begin(), d.back().end(), 0));
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n, k;
int a[100010];
int f[100010];
int main()
{
	cin >> n >> k;
	for(int i = 1; i <= n; i++)
		cin >> a[i];
	for(int i = 2; i <= n; i++)
	{
		f[i] = 1e9;
		for(int j = i-1; j>=max(1,i-k); j--)
			f[i] = min(f[i], f[j] + abs(a[i]-a[j]));
	}
	cout << f[n];
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
    using namespace std;
    
    int main(){
        int a , b , c;
        cin >> a >> b >> c;
        if(b - a == c - b){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
        
        
        return 0;
    }

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

using namespace std;
typedef long long ll;

int main()
{
    while (1) {
        int N;
        ll M;
        scanf("%d %lld", &N, &M);
        if (N == 0 && M == 0) {
            break;
        }
        set<ll> P;
        for (int n = 0; n < N; ++n) {
            ll tmp;
            cin >> tmp;
            P.insert(tmp);
        }

        set<ll> setP2;
        setP2.insert(0);
        for (auto it1 = P.begin(); it1 != P.end();  ++it1) {
            if (*it1 <= M) setP2.insert(*it1);
            else break;
            for (auto it2 = it1; it2 != P.end(); ++it2) {
                if (*it1 + *it2 <= M) setP2.insert(*it1 + *it2);
                else break;
            }
        }

        ll Res = 0;
        auto it1 = setP2.begin();
        auto it2 = setP2.rbegin();
        for (; it1 != setP2.end(); ++it1) {
            ll S;
            while ((S = *it1 + *it2) > M && it2 != setP2.rend()) {
                ++it2;
            }
            if (S <= M && Res < S) {
                Res = S;
            }
            if (*it1 > *it2) break;
        }
        cout << Res << endl;
    }

    return 0;
}


Measured memory_bytes: 26436
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
const int mod=1000000007;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,x;cin >> n >> x;
	if(x==1 || x==2*n-1) cout << "No" << endl;
	else{
		cout << "Yes" << endl;
		if(n==x) for(int i=1;i<=2*n-1;++i) cout << i << endl;
		else{
			int k=2;
			if(x<n){
				for(int i=1;i<2*n;++i){
					if(i>=n-1 && i<=n+2){
						if(i==n-1) cout << 2*n-2 << endl;
						else if(i==n) cout << x << endl;
						else if(i==n+1) cout << 1 << endl;
						else cout << 2*n-1 << endl;
					}
					else{
						if(k==x) k++;
						cout << k << endl;
						k++;
					}
				}
			}
			else{
				k++;
				for(int i=1;i<2*n;++i){
					if(i>=n-1 && i<=n+2){
						if(i==n-1) cout << 1 << endl;
						else if(i==n) cout << x << endl;
						else if(i==n+1) cout << 2*n-1 << endl;
						else cout << 2 << endl;
					}
					else{
						if(k==x) k++;
						cout << k << endl;
						k++;
					}
				}
			}
		}
	}
}


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

int main() {
   int X, N;
   cin >> X >> N;
   vector<int> p(N);
   for(int i=0; i<N; i++) cin >> p[i];
   sort(p.begin(), p.end());
   int div = 100;
   int ans = 0;

   if(N == 0) {
      cout << X << endl;
      return 0;
   }

   for(int i=0; i <= p[N-1] + 1; i++) {
      if(div > abs(X-i) && find(p.begin(), p.end(), i) == end(p)) {
         div = abs(X-i);
         ans = i;
      }
   }
   cout << ans << endl;
}

Measured memory_bytes: 3612
#include "bits/stdc++.h"
using namespace std;
int main(){
    int n,i,a,ans=0,tmp;
    cin >> n;
    vector<int> cnt(100000,0);
    for(i=0;i<n;i++){
        cin >> a;
        cnt.at(a)++;
    }
    for(i=1;i<99999;i++){
        tmp = cnt.at(i-1)+cnt.at(i)+cnt.at(i+1);
        ans = max(ans,tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define lli long long int
#define mod 1000000007
#define pb push_back
#define pf push_front
#define ulli unsigned long long int
#define what_is(x) cerr << #x << " is " << x << endl;
#define pi 2*acos(0.0)
#define F  first
#define S  second
#define endl '\n'
#define all(x) x.begin(),x.end()
using namespace std;
bool sortbysec(const pair<lli,lli> &a,
              const pair<lli,lli> &b)
{
    return (a.second < b.second);
}
int main()
{
//cout.precision(9);
//cout.setf(ios::fixed,ios::floatfield);
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  /// freopen("input.txt","r",stdin);
  /// freopen("output.txt","w",stdout);
	lli T=1;
    //cin>>T;
	while(T--)
	{
        lli i,n,f,j,k,l,m,ans=0,sum=0,z;
        vector<lli> v,u;
        cin>>n;
        for(i=0;i<n;i++)
        {
            cin>>z;
            v.pb(z);
            sum=sum^z;
        }
        if(sum==0)
        {
            cout<<"Yes"<<endl;
        }
        else
        {
            cout<<"No"<<endl;
        }
    }
}
/*
1
5
1 2 3 4 5
*/


Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 1000010;

vector<int> fact;

void setfact(int n){
    fact.resize(n+1);
    for(int t=2; t<=n; t*=2){
        for(int i=t; i<=n; i+=t) ++fact[i];
    }
    partial_sum(fact.begin(), fact.end(), fact.begin());
}

int getC(int n, int r){
    return r == 0 || fact[n] <= fact[r] + fact[n-r];
}

int main(){
    int n; string s;
    cin >> n >> s;
    setfact(n);
    bool flag = false;
    for(auto &a: s){
        --a;
        if(a == '1') flag = true;
    }
    if(flag){
        int b = 0;
        rep(i, n)if(s[i] == '1') b ^= getC(n-1, i);
        printf("%d\n", b);
    }
    else{
        int b = 0;
        rep(i, n)if(s[i] == '2') b ^= getC(n-1, i);
        printf("%d\n", b*2);
    }
}

Measured memory_bytes: 5252
#include <bits/stdc++.h>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef long double ld;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    ll N, i, j, k, cnt=0, cnt2=0, r, g, b;
    string S;

    cin >> N >> S;

    if(N<=2){
        cout << 0 << endl;
    }

    else{
        if(N%2==1){
            for(i=1; i<=N/2; i++){ // とばす数
                for(j=1; j+i*2<=N; j++){ // 始点
                    if(S[j-1]!=S[j+i-1] && S[j+i-1]!=S[j+i*2-1] && S[j+i*2-1]!=S[j-1]){
                        cnt++;
                    }
                }
            }
        }
        else{
            for(i=1; i<=N/2-1; i++){ // とばす数
                for(j=1; j+i*2<=N; j++){ // 始点
                    if(S[j-1]!=S[j+i-1] && S[j+i-1]!=S[j+i*2-1] && S[j+i*2-1]!=S[j-1]){
                        cnt++;
                    }
                }
            }
        }

        r=0; g=0; b=0;
        for(i=1; i<=N; i++){
            if(S[i-1]=='R'){
                r++;
                cnt2 += g*b;
            }
            if(S[i-1]=='G'){
                g++;
                cnt2 += r*b;
            }
            if(S[i-1]=='B'){
                b++;
                cnt2 += r*g;
            }
        }

        cout << cnt2-cnt << endl;
    }

    return 0;
}

Measured memory_bytes: 3640
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        int ans = 0;
        for (int i = 0; i < n; i++) {
            ans += a[i] - 1;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 25704
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n,m,a,b,s,t,dist[1000001];
bool use[1000001];
vector<int> v[1000001];
queue<int> q;
ll get_node(int nod, int cod)
{
    return 3*nod+cod;
}
void bfs()
{
    q.push(s);
    use[s]=1;
    while(!q.empty())
    {
        int nod=q.front();
        use[nod]=1;
        for(auto nd:v[nod])
            if(use[nd]==0)
        {
            use[nd]=1;
            dist[nd]=dist[nod]+1;
            q.push(nd);
        }
        q.pop();
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>m;
    for(int i=1;i<=m;i++)
    {
        cin>>a>>b;
        v[get_node(a,0)].pb(get_node(b,1));
        v[get_node(a,1)].pb(get_node(b,2));
        v[get_node(a,2)].pb(get_node(b,0));
    }
    cin>>s>>t;
    s=get_node(s,0);
    t=get_node(t,0);
    bfs();
    if(use[t]==0)
        cout<<-1;
    else
        cout<<dist[t]/3;
    return 0;
}


Measured memory_bytes: 38272
#include <stdio.h>
int findsum(int n)
{
    int c=0;
    while(n>0){
        n /= 10;
        c++;
    }
    if(c%2==0) return 0;
    else return 1;
}
int main(void)
{
    int N;
    scanf("%d",&N);
    int c=0;
    for(int i=1;i<=N;i++){
        c += findsum(i);
    }
    printf("%d\n",c);
    return 0;
}


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

const long long INF = 1LL<<60;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];

    vector<vector<long long> > dp(n + 1, vector<long long>(2, -INF));
    dp[0][0] = 0;
    for (int i = 0; i < n; i++) {
        dp[i + 1][0] = max(dp[i][0] + a[i], dp[i][1] - a[i]);
        dp[i + 1][1] = max(dp[i][0] - a[i], dp[i][1] + a[i]);
    }

    cout << dp[n][0] << endl;
    return 0;
}

Measured memory_bytes: 6144
import java.util.*;
import static java.lang.System.*;

class Main {
	public static Scanner sc = new Scanner(in);
	public static Random rand=new Random();

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

	public void run() {
		while(true){
			int n=sc.nextInt();
			if(n==0)return;
			boolean[][] jumap=new boolean[21][21];
			for(int i=0;i<n;i++){
				jumap[sc.nextInt()][sc.nextInt()]=true;
			}
			int juc=0;

			int x=10,y=10;
			int m=sc.nextInt();
			while(m--!=0){
				char d=sc.next().charAt(0);
				int t=sc.nextInt();
				int di=0;
				if(d=='E')di=1;
				if(d=='S')di=2;
				if(d=='W')di=3;

				for(int i=0;i<t;i++){
					x+=dx[di];
					y+=dy[di];
					if(jumap[x][y]){
						juc++;
						jumap[x][y]=false;
					}
				}
			}
			ln((juc==n)?"Yes":"No");
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}

	public int[] nextIntArray(int n){
		int[] res=new int[n];
		for(int i=0;i<n;i++){
			res[i]=sc.nextInt();
		}
		return res;
	}
	public static void pr(Object o) {
		out.print(o);
	}
	public static void ln(Object o) {
		out.println(o);
	}
	public static void ln() {
		out.println();
	}
}

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

int f(int);

int main(){
  int num;
  cin >> num;
  if(num%f(num)==0) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

int f(int x){
  string s=to_string(x);
  int sum=0;
  for(auto i:s) sum+=i-'0';
  return sum;
}

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

const int INF = 1000000000;

int main(){
    int n;
    int a[100000];
    scanf("%d", &n);
    for(int i = 0; i < n; i++){
        scanf("%d", a + i);
    }
    int dp[100000];
    fill(dp, dp + n + 1, INF);
    dp[0] = -1;
    for(int i = 0; i < n; i++){
        int* ptr = lower_bound(dp, dp + n + 1, a[i]);
        if(ptr == dp) continue;
        *ptr = min(*ptr, a[i]);
    }
    printf("%d\n", lower_bound(dp, dp + n + 1, INF) - dp - 1);
    return 0;
}

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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define MX              200005
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
#define ull unsigned long long
#define ll long long


void add(int &a,int b){
    a+=b;
    if(a>=mod)
        a-=mod;
}
vi dp(100002,0);
vector<bool> visit(100002,0);
int dfs(std::vector<vi> &g,int i){
    
    if(g[i].size()==0){
        return 0;
    }
    if(dp[i]!=0)return dp[i];
    int ans=0;
    for(int j=0;j<g[i].size();j++){
        if(visit[g[i][j]]!=0){
            ans=max(ans,dp[g[i][j]]);
        }else {
            visit[g[i][j]]=1;
            ans=max(ans,dfs(g,g[i][j]));
        }
    }
    dp[i]=max(dp[i],ans+1);
    return dp[i];
}
int32_t main()
{
   // sbs();
    // int t;cin>>t;
    // while(t--) {
        
    //     cout<<'\n';
    // }
    int n,m;cin>>n>>m;
    std::vector<vi> g(n);
    for(int i=0;i<m;i++){
        int x,y;cin>>x>>y;
        g[x-1].pb(y-1);
    }
    int ans=0;
    for(int i=0;i<n;i++){
        if(visit[i]==0){
            visit[i]=1;
            ans=max(ans,dfs(g,i));
        }
        else ans=max(ans,dp[i]);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 9984
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll inf = numeric_limits<ll>::max()/3;
const ll mod = 1e9 + 7;

int n;
int res[600][600];
void rec(int m,int begin,int level, int step){
  if(m <= 1){
    return;
  }
  vector<int> even;
  vector<int> odd;
  for(int i = 0;begin + i * step < n;++i){
    if(i % 2 == 0){
      even.push_back(begin + i * step);
    }else{
      odd.push_back(begin + i * step);
    }
  }
  for(int i = 0;i < even.size();++i){
    for(int j = 0;j < odd.size();++j){
      int src = min(even[i],odd[j]);
      int dst = max(even[i],odd[j]);
      res[src][dst] = level;
    }
  }
  rec((m+1)/2,begin,level+1,step*2);
  rec(m/2,begin+step,level+1,step*2);
}


int main(void){
  cin >> n;
  rec(n,0,1,1);
  for(int i = 0;i < n-1;++i){
    for(int j = 1;i+j < n;++j){
      if(j != 1)printf(" ");
      printf("%d", res[i][i+j]);
    }
    printf("\n");
  }
  return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

const long long INF = 1000000000000;

int N, K;
long long h[100100];

long long dp[100100];

int main() {
    cin >> N >> K;
    for (int i = 1; i <= N; i++) cin >> h[i];

    for (int i = 1; i <= N; i++) dp[i] = INF;
    dp[1] = 0;

    for (int i = 1; i <= N; i++) {
        for (int j = i + 1; j <= i + K; j++) {
            if (j <= N) {
                dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
            }
        }
    }

    cout << dp[N] << endl;
    return 0;
}

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

int main(){
  int N,K,A,B,H=1;
  cin >> N >>K;
  for(int i=0;i<N;i++){
    A=2*H,B=H+K;
    if(A<=B){
      H=A;
    }
    else{
      H=B;
    }
  }
  cout << H << endl;
}
    

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  int N; cin >> N;
  int x = N%10;
  string result;
  if (x==2||x==4||x==5||x==7||x==9) result = "hon";
  else if (x==0||x==1||x==6||x==8) result = "pon";
  else result = "bon";
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<ll,ll>;
#define For(i,a,b)  for(int i=a;i<=b;i++)
#define Forr(i,a,b) for(int i=a;i>=b;i--)
#define F first
#define S second
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define bpc __builtin_popcount
#define MOD (ll)(1e9+7)
#define INF (1e18)
#define EPS (1e-6)
#define NATHANLEE_IS_EVIL_AND_ELECTRIC true
#define int ll
#ifdef LOCAL_TEST
#define debug(...) do{\
	cerr<<__PRETTY_FUNCTION__<<" - "<<__LINE__<<\
	" : ("#__VA_ARGS__<<") = ";\
	_OUT(__VA_ARGS__);\
}while(0)
template<typename T>void _OUT(T x){cerr<<x<<"\n";}
template<typename T,typename...I>void _OUT(T x,I ...tail){cerr<<x<<", ";_OUT(tail...);}
#else
#define debug(...)
#endif
void INIT(){
#ifdef LOCAL_TEST
	freopen("D:\\input.in","r",stdin);
	freopen("D:\\output.out","w",stdout);
	freopen("D:\\error.out","w",stderr);
#endif
	ios::sync_with_stdio(!NATHANLEE_IS_EVIL_AND_ELECTRIC);
	cin.tie(0);
}

ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
ll fpow(ll b,ll p){
	b%=MOD;
	ll ans=1;
	while(p>0){
		if(p&1) ans=(ans*b)%MOD;
		p/=2;
		b=(b*b)%MOD;
	}
	return ans;
}

struct Node{
	vector<int> con;
	int ab,aw;
}g[100010];

void go(int n,int p){
	g[n].ab=1; g[n].aw=1;
	for(auto &i:g[n].con){
		if(i==p) continue;
		go(i,n);
		g[n].ab=g[n].ab* g[i].aw         %MOD;
		g[n].aw=g[n].aw*(g[i].aw+g[i].ab)%MOD;
	}
}

int32_t main() {
	INIT();
	//code...
	int n; cin>>n;
	int s,t;
	For(i,1,n-1){
		cin>>s>>t;
		s--; t--;
		g[s].con.eb(t);
		g[t].con.eb(s);
	}
	go(0,0);
	cout<<(g[0].ab+g[0].aw)%MOD<<"\n";
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    // = 0 にしてないとバグった
    int ans = 0;
    for (int i = 0; i <= n; i++) {
      ans += i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

int p[110];

int main() {
	int x, n;
	cin >> x >> n;
	for (int i = 0; i < n; i++)
		cin >> p[i];
	sort(p, p + n);
	int dist = 0;
	while (dist < 200) {
		if (!binary_search(p, p + n, x - dist)) {
			cout << x - dist << endl;
			return 0;
		}
		if (!binary_search(p, p + n, x + dist)) {
			cout << x + dist << endl;
			return 0;
		}
		dist++;
	}
}

Measured memory_bytes: 3620
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

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

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

  string s;
  cin >> s;

  int count = 0;
  ll sum = 0;
  for(int i = 0; i + 1 < s.length(); i++){
    if(s[i] == 'B') ++count;
    if(s[i] == 'B' && s[i + 1] == 'W'){
      sum += (ll)count;
      s[i + 1] = 'B';
      --count;
    }
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 832
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, n) for (int i = 0; i <= (int)(n); i++)
#define srep(i, l, n) for (int i = l; i < (int)(n); i++)
#define srepn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int MOD = 998244353;
const int INF = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};

void solve(){
	int n;
	cin >> n;
	map<ll, int> mp;
	ll ans = 1;
	rep(i,n) {
		ll d;
		cin >> d;
		if(d!=0&&i==0) {
			cout << 0 << endl;
			return;
		}
		mp[d]++;
	}
	if(mp[0]!=1) {
		cout << 0 << endl;
		return;
	}
	for(auto e: mp){
		if(e.first==0) continue;
		rep(i,e.second) ans *= mp[e.first-1], ans%=MOD;
	}
	cout << ans << endl;
}

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

Measured memory_bytes: 6528
using System;
using System.Linq;
using System.Collections.Generic;

namespace ConsoleApp1 {
    public class Class {
        static void Main(string[] args) {
            var NK = RL<int>();
            var H = RL<int>();
            var dp = new int[NK[0]];
            dp[0] = 0;
            for(var i = 1;i < NK[0]; i++) {
                dp[i] = Math.Abs(H[i] - H[i - 1]) + dp[i - 1];
                for(var k = 1; k <= NK[1] && k <= i; k++) {
                    dp[i] = Math.Min(dp[i], Math.Abs(H[i] - H[i - k]) + dp[i - k]);
                }
            }
            Console.Write(dp[NK[0] - 1]);
        }

        static T[] RL<T>() where T : IComparable {
            if (typeof(T) == typeof(int)) {
                return (T[])(object)Console.ReadLine().Trim().Split().Select(int.Parse).ToArray();
            }
            if (typeof(T) == typeof(long)) {
                return (T[])(object)Console.ReadLine().Trim().Split().Select(long.Parse).ToArray();
            }
            if (typeof(T) == typeof(double)) {
                return (T[])(object)Console.ReadLine().Trim().Split().Select(double.Parse).ToArray();
            }
            if (typeof(T) == typeof(decimal)) {
                return (T[])(object)Console.ReadLine().Trim().Split().Select(decimal.Parse).ToArray();
            }
            return (T[])(object)Console.ReadLine().Trim().Split().ToArray();
        }
    }
}


Measured memory_bytes: 20064
/*
 * Author : Sadi
 * Mon 20/07/2020
 * 20:59:01.97
 */
#include <bits/stdc++.h>

using namespace std;

#define    watch(x); cout << "\n" <<  #x << " is: " << x << "\n";
#define    all(a) (a).begin(), (a).end()
#define    fi first
#define    se second

template<class A, class B>
ostream& operator << (ostream& output, const pair<A, B>& p) {
    output << "(" << p.first << ", " << p.second << ")";
    return output;
}

template<class A>
ostream& operator << (ostream& output, const vector<A>& a) {
    output << "[";
    for(auto it = a.begin(); it != a.end(); ++it) {
        if(it != a.begin()) {
            output << ", ";
        }
        output << *it;
    }
    output << "]";
    return output;
}

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

//const int inf = 1e9;
//const int mod = 1e9 + 7;
//const double PI = acos(-1.0);
//const int mx = 1e5 + 5;



int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE

    int k, n;
    cin >> k >> n;
    vector<int> v(n);
    for(int i = 0; i < n; ++i) {
        cin >> v[i];
    }
    int maxDistance = 0;
    for(int i = 1; i < n; ++i) {
        maxDistance = max(maxDistance, v[i] - v[i - 1]);
    }
    // still didnt consider the distance between the first and last houses
    // that distance may also be the largest segment 
    maxDistance = max(maxDistance, v.front() + k - v.back());
    cout << k - maxDistance << "\n";
    
    return 0;
}


Measured memory_bytes: 3952
x=[]
y=[]
count=10
a=0
for i in range(5):
    x.append(int(input()))
for k in range(5):
    y.append(x[k])
for j in range(5):
    y[j]=y[j]%10
#print(y)
for m in range(5):
    if y[m]!=0:
        if count>y[m]:
            count=y[m]
            a=m
#print(a)
for w in range(5):
    if y[w]==0 or w==a:
        continue
    x[w]+=10-y[w]
print(sum(x))

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
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; }
// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

using Graph = vector<vector<int>>;

typedef pair<int, int> P;
typedef priority_queue<int, vector<int>, greater<int>> PQ;
const int MOD = 1000000007;


int main(){
    int N; cin >> N;
    vector<int> H(N,0);
    rep(i,N) cin >> H[i];

    for (int i = N-1; i > 0; i--){
        if (H[i-1] <= H[i]) continue;
        H[i-1]--;
        if (H[i-1] > H[i]){
            cout << "No" << endl;
            return 0;
        } 
    }

    cout << "Yes" << endl;
}



Measured memory_bytes: 3772
n,m = map(int,input().split())
a = list(map(int,input().split()))
bcl = [list(map(int,input().split())) for nesya in range(m)]
bcl.sort(reverse=True,key=lambda x:x[1])
t = 0
for bc in bcl:
  t += bc[0]
  a += [bc[1]]*bc[0]
  if t > n:
    break
a.sort(reverse=True)
print(sum(a[:n]))

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

template <class T>
using lim = numeric_limits<T>;

int main() {
	ios_base::sync_with_stdio(false) ;
	cin.tie(0);
	
	ll n, m;
	cin >> n >> m;
	int a[m], b[m];
	
	for (int i = 0; i < m; i++){
		cin >> a[i] >> b[i];
		a[i]--;
		b[i]--;
	}
	
	int arr[n];
	int counter[n];
	for (int i = 0; i < n; i++){
		counter[i] = 1;
		arr[i] = i;
	}
	
	ll ans[m];
	ans[m-1] = ((n-1)*n)/2;
	for (int i = m-1; i >= 1; i--){
		int u = a[i];
		int v = b[i];
		while(counter[u]==0){
			u = arr[u];
		} 
		while(counter[v]==0){
			v = arr[v];
		}
		
		int cu = counter[u];
		int cv = counter[v];
		if (u != v){
			if (cu >= cv){
				ans[i-1] = ans[i] - cu*(n-cu) - (n-cu-cv)*cv;
				counter[u] += counter[v];
				counter[v] = 0;
				
				ans[i-1] += (n-counter[u])*counter[u];
				arr[v] = u;
			}
			else{
				ans[i-1] = ans[i] - cu*(n-cu) - (n-cu-cv)*cv;
				counter[v] += counter[u];
				counter[u] = 0;
				
				ans[i-1] += (n-counter[v])*counter[v];
				arr[u] = v;
			}
		}else{
			ans[i-1] = ans[i];
		}
	}
	
	for (int i = 0; i < m; i++){
		cout << ans[i] << endl;
	}
} 


Measured memory_bytes: 3712
import java.text.DecimalFormat;
import java.util.Scanner;

/**
 * @author ??\???
 *
 */
public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		long a = scanner.nextInt();
		long b = scanner.nextInt();
		scanner.close();
		
		DecimalFormat df = new DecimalFormat("0.00000");
		
		System.out.println((a / b) + " " + (a % b) + " " + df.format(((double) a / b)));
	}

}

Measured memory_bytes: 26480
#include <stdio.h>
int A[20],M[200];
int n,q,j,count;

void Solve(int i,int m){
  if(m==0) count=1;
  else if(i!=n){
     Solve(i+1,m);
      Solve(i+1,m-A[i]);
   
  }
}
int main(){
  int i;

  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);
  scanf("%d",&q);
  for(i=0;i<q;i++) scanf("%d",&M[i]);
 
 
  for(j=0;j<q;j++){  
    count=0;  
   Solve(0,M[j]);
   if(count==1) printf("yes\n");
   else printf("no\n");
}
  return 0;
}

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

int main(){
    int s,kami2,simo2;
    cin >> s;

    kami2 = (s-s%100)/100;
    simo2 = s%100;

    if ( kami2 <= 12 && kami2 > 0) {
        if ( simo2 <= 12 && simo2 > 0 ) {
            cout << "AMBIGUOUS" << endl;
        } else {
            cout << "MMYY" << endl;
        }
    } else {
        if ( simo2 <= 12 && simo2 > 0 ) {
            cout << "YYMM" << endl;
        } else {
            cout << "NA" << endl;
        }
    }
}

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

#define int         long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        200005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<int>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>

using namespace std;


//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//const int md = 998244353;

/*int power(int a,int n)
{
    if(n == 1)return a%mod;
    if(n == 0)return 1;
    if(n&1)return ((a%mod)*(power((a*a)%mod,n/2))%mod)%mod;
    return power((a*a)%mod,n/2)%mod;
}*/
//int n,m,k;

signed main()
{
    showoff;
    //cin >> n >> m >> k;
    int n;
    cin >> n;
    bool fo = 0;
    FOR(i,1,n+1){
    int x;
    cin >> x;
    if(x&1)fo = 1;
    }
    if(fo)cout << "first\n";
    else cout << "second\n";
    return 0;
}


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

using namespace std;

int main() {
    int a, b, c, d, e, f;
    double bestc = -1;
    int bestw, bests;

    scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &f);

    double node = (100.*e)/(100+e);
    for (int bi=0; 100*b*bi <= f; bi++) {
        for (int ai=0; 100*b*bi + 100*a*ai <= f; ai++) {
            for (int di=0; 100*b*bi + 100*a*ai + d*di <= f; di++) {
                for (int ci=0; 100*b*bi + 100*a*ai + d*di + c*ci <= f; ci++) {
                    if (!ai && !bi && !ci && !di) continue;
                    //cout << ai << bi << ci << di << endl;
                    double conc = 100.*(d*di+c*ci) / (100*b*bi+100*a*ai+d*di+c*ci);
                    if (conc <= node && conc > bestc) {
                        bestc = conc;
                        bestw = 100*(a*ai + b*bi);
                        bests = c*ci + d*di;
                    }
                }
            }
        }
    }

    printf("%d %d", bestw+bests, bests);

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
 
int main(){
	int H, W;
	cin >> H >> W;
	string board[H];
	for(int i = 0; i < H; i++){
		cin >> board[i];
	}
	int sharp = 0;
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			if(board[i][j] == '#'){
				sharp++;
			}
		}
	}
	if(sharp == H + W - 1){
		cout << "Possible" << endl;
	}else{
		cout << "Impossible" << endl;
	}
}

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

int main() {
  int a,b,c;
  cin>>a>>b>>c;
  if(a==b){
    cout<<c<<endl;
  }
  else if(b==c){
    cout<<a<<endl;
  }
  else{
    cout<<b<<endl;
  }
}

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

using namespace std;
#define sf(n) scanf("%d", &n)
#define pd(n) printf("%.12lf", n)
#define pf(n) printf("%d", n)
#define p() printf("\n")
#define ps() printf(" ")
#define ll long long
#define ull unsigned long long
#define MAX 1e9
#define mod 1000 * 1000 * 1000 + 7
#define pi 3.1415926536
#define ex 1e18
#define dbl 2e09
#define qu(q) queue<int> q
#define pqu(q) priority_queue<int> q
#define len(s) s.length()
#define sz(x) int(x.size())
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second

const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

int main()
{
    int a, p;
    cin >> a >> p;
    cout << (p + (a * 3)) / 2 << endl;
    return 0;
}

Measured memory_bytes: 256