akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;
import static java.lang.System.out;

public class Main{
    static MyReader in = new MyReader();

    public static void main(String[] args){
        int X = in.i();
        int N = in.i();
        int[] p = in.ii(N);

        boolean[] b = new boolean[102];
        for (int i = 0; i < N; i++) {
            b[p[i]] = true;
        }

        int ans = X;
        if (b[X]) {
            ans = 0;
            for (int i = X - 1; i > 0; i--) {
                if (!b[i]) {
                    ans = i;
                    break;
                }
            }
            for (int i = X + 1; i < 102; i++) {
                if (!b[i]) {
                    if (i - X < X - ans) {
                        ans = i;
                    }
                    break;
                }
            }
        }
        out.println(ans);
    }

    static class MyReader extends BufferedReader {
        char[] cbuf = new char[1024];
        int head = 0;
        int tail = 0;

        MyReader() {
            super(new InputStreamReader(System.in));
        }

        char next() {
            if (head == tail) {
                try {
                    tail = read(cbuf, 0, cbuf.length);
                } catch (IOException e) {}
                head = 0;
            }
            return cbuf[head++];
        }

        void back() {
            head--;
        }

        boolean minus() {
            boolean minus;
            while (true) {
                char c = next();
                if (c != ' ' && c != '\n' && c != '\r') {
                    if (!(minus = c == '-')) back();
                    return minus;
                }
            }
        }

        void skip() {
            while (true) {
                char c = next();
                if (c != ' ' && c != '\n' && c != '\r') {
                    back();
                    break;
                }
            }
        }

        char[] s(final int N) {
            skip();
            char[] s = new char[N];
            for (int i = 0; i < s.length; i++) {
                s[i] = next();
            }
            return s;
        }

        int i() {
            boolean minus = minus();
            int n = 0;
            while (true) {
                int k = next() - '0';
                if (k < 0 || 9 < k) break;
                n = 10 * n + k;
            }
            return minus ? -n : n;
        }

        int[] ii(final int N) {
            int[] a = new int[N];
            for (int j = 0; j < a.length; j++) a[j] = i();
            return a;
        }

        long l() {
            boolean minus = minus();
            long n = 0;
            while (true) {
                int k = next() - '0';
                if (k < 0 || 9 < k) break;
                n = 10 * n + k;
            }
            return minus ? -n : n;
        }
    }
}


Measured memory_bytes: 32620
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	int N;
	cin >> N;
	ll RR = -1e18;
	ll RL = -1e18;
	ll RUD = -1e18;
	ll LR = 1e18;
	ll LL = 1e18;
	ll LUD = 1e18;
	ll UU = -1e18;
	ll UD = -1e18;
	ll URL = -1e18;
	ll DU = 1e18;
	ll DD = 1e18;
	ll DRL = 1e18;
	bool R = false;
	bool L = false;
	bool U = false;
	bool D = false;

	rep(i, N) {
		ll x, y;
		char d;
		cin >> x >> y >> d;

		if (d == 'R') {
			R = true;
			RR = max(RR, x);
			LR = min(LR, x);
			URL = max(URL, y);
			DRL = min(DRL, y);
		}
		else if (d == 'L') {
			L = true;
			RL = max(RL, x);
			LL = min(LL, x);
			URL = max(URL, y);
			DRL = min(DRL, y);
		}
		else if (d == 'U') {
			U = true;
			RUD = max(RUD, x);
			LUD = min(LUD, x);
			UU = max(UU, y);
			DU = min(DU, y);
		}
		else {
			D = true;
			RUD = max(RUD, x);
			LUD = min(LUD, x);
			UD = max(UD, y);
			DD = min(DD, y);
		}
	}

	vector<double> kouho;
	kouho.pb(0);

	if (R && L) {
		kouho.pb(0.5 * (RL - RR));
		kouho.pb(0.5 * (LL - LR));
	}
	if (R && (U || D)) {
		kouho.pb(RUD - RR);
		kouho.pb(LUD - LR);
	}
	if (L && (U || D)) {
		kouho.pb(RL - RUD);
		kouho.pb(LL - LUD);
	}
	if (U && D) {
		kouho.pb(0.5 * (UD - UU));
		kouho.pb(0.5 * (DD - DU));
	}
	if (U && (R || L)) {
		kouho.pb(URL - UU);
		kouho.pb(DRL - DU);
	}
	if (D && (R || L)) {
		kouho.pb(UD - URL);
		kouho.pb(DD - DRL);
	}

	double saishou = 1e20;
	for (double D : kouho) {
		if (D >= 0) {
			double Xmax = max({ RR + D, RL - D, (double)RUD });
			double Xmin = min({ LR + D, LL - D, (double)LUD });

			double Ymax = max({ UU + D, UD - D, (double)URL });
			double Ymin = min({ DU + D, DD - D, (double)DRL });

			saishou = min(saishou, (Xmax - Xmin) * (Ymax - Ymin));
		}
	}
	
	cout << fixed << setprecision(12) << saishou << endl;

	Would you please return 0;
}

Measured memory_bytes: 256
/*
  Vivek Rathi
  CSE 2nd Year
  MNNIT
*/
#include<bits/stdc++.h>
using namespace std;
#define M 1000000007
#define ll long long int
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define debug1(x) cout<<#x<<" "<<x<<endl;
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define present(c,x) ((c).find(x) != (c).end())
#define null NULL
#define mp make_pair
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define inf 1e17
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
ll visited[100001];
ll dp[100001];
vector<ll> v[100001];
ll n,m,co;
void dfs(ll ver)
{
	visited[ver]++;
	ll count=1;
	for(ll i=0;i<v[ver].size();i++)
	{
		if(visited[v[ver][i]]==0)
		{
			dfs(v[ver][i]);
		}
		count=max(count,dp[v[ver][i]]+1);
	}
	dp[ver]=count;
}
int main()
{
	boost
	
	cin>>n>>m;
	
	for(ll i=0;i<m;i++)
	{
		ll a,b;
		cin>>a>>b;
		v[a].pb(b);
	}
	ll maxi=0;
	for(ll i=1;i<=n;i++)
	{
		if(visited[i]==0)
		{
			dfs(i);
		}
	}
	for(ll i=1;i<=n;i++)
	{
		maxi=max(maxi,dp[i]);
	}
	cout<<maxi-1<<endl;
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> d(N);
  rep(i, N) cin >> d[i];
  
  int ans = 0;
  rep(i, N) {
    for (int j = i+1; j < N; j++) {
      ans += d[i]*d[j];
    }
  }
  
  cout << ans;
  
  return 0;
}


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

using namespace std;

#define int long long
#define ar array
#define vt vector
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()

#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)

template<class T>
bool umin(T &a, const T &b) {
    return b < a ? a = b, 1 : 0;
}

template<class T>
bool umax(T &a, const T &b) {
    return a < b ? a = b, 1 : 0;
}

template<class A>
void read(vt<A> &v);

template<class A, size_t S>
void read(ar<A, S> &a);

template<class T>
void read(T &x) {
    cin >> x;
}

void read(double &d) {
    string t;
    read(t);
    d = stod(t);
}

void read(long double &d) {
    string t;
    read(t);
    d = stold(t);
}

template<class H, class... T>
void read(H &h, T &... t) {
    read(h);
    read(t...);
}

template<class A>
void read(vt<A> &x) {
    EACH(a, x)read(a);
}

template<class A, size_t S>
void read(array<A, S> &x) {
    EACH(a, x)read(a);
}

string to_string(char c) {
    return string(1, c);
}

string to_string(bool b) {
    return b ? "true" : "false";
}

string to_string(const char *s) {
    return string(s);
}

string to_string(string s) {
    return s;
}

string to_string(vt<bool> v) {
    string res;
    FOR(sz(v))res += char('0' + v[i]);
    return res;
}

template<size_t S>
string to_string(bitset<S> b) {
    string res;
    FOR(S)res += char('0' + b[i]);
    return res;
}

template<class T>
string to_string(T v) {
    bool f = 1;
    string res;
    EACH(x, v) {
        if (!f)
            res += ' ';
        f = 0;
        res += to_string(x);
    }
    return res;
}

template<class A>
void write(A x) {
    cout << to_string(x);
}

template<class H, class... T>
void write(const H &h, const T &... t) {
    write(h);
    write(t...);
}

void print() {
    write("\n");
}

template<class H, class... T>
void print(const H &h, const T &... t) {
    write(h);
    if (sizeof...(t))
        write(' ');
    print(t...);
}

template<class T, class U>
void vti(vt<T> &v, U x, size_t n) {
    v = vt<T>(n, x);
}

template<class T, class U>
void vti(vt<T> &v, U x, size_t n, size_t m...) {
    v = vt<T>(n);
    EACH(a, v)vti(a, x, m);
}

int cmp(int a, int b) {
    if (a == b) {
        return 0;
    }
    return a < b ? -1 : 1;
}

void solve() {
    string s;
    read(s);
    int v[26];
    FOR(26) {
        v[i] = 0;
    }
    FOR(s.size()) {
        v[s[i] - 'a']++;
    }
    FOR(26) {
        if (v[i] & 1) {
            print("No");
            return;
        }
    }
    print("Yes");
}

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

    int tt = 1;
//    read(tt);
    FOR(tt) {
//        write("Case #", i + 1, ": ");
        solve();
    }

}



Measured memory_bytes: 3616
#include<iostream>
using namespace std;
#define INF (1<<28)
int N,M;
int t[20000];
int u[20000];
int dp[20000][256];
 
void init(){
  for(int i=0;i<20000;i++)
    for(int j=0;j<256;j++)
      dp[i][j]=INF;
}
 
int calc(int a,int b){
  if(a+b<0)return 0;
  if(a+b>=256)return 255;
  return a+b;
}
 
int dist(int a,int b){
  return (a-b)*(a-b);
}
 
int main(){
  while(1){
    cin>>N>>M;
    if(N==0&&M==0)break;
    init();
    for(int i=0;i<M;i++)cin>>t[i];
    for(int i=0;i<N;i++)cin>>u[i];
    for(int i=0;i<M;i++)dp[0][calc(128,t[i])]=dist(calc(128,t[i]),u[0]);
 
    for(int i=0;i+1<N;i++){
      for(int j=0;j<256;j++){
    if(dp[i][j]==INF)continue;
    //cout<<i<<' '<<j<<' '<<dp[i][j]<<endl;
    for(int k=0;k<M;k++){
      int A=calc(j,t[k]);
      //cout<<A<<endl;
      dp[i+1][A]=min(dp[i+1][A],dp[i][j]+dist(A,u[i+1]));
       
    }
      }
    }
    int ans=INF;
    for(int i=0;i<256;i++)
      ans=min(ans,dp[N-1][i]);
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 21240
import java.util.*;


import java.io.*;
/**
 * MLASERP
 */
public class Main {

    
    static MyScanner in  = new MyScanner();
   static int mod  = 1000000007;
    static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      static StringTokenizer st;
      static int []dr  = {1,-1,0,0};
      static int [] dc = {0,0,-1,1};
public static void main(String[] args) {
    String s = in.next();
    int max =0;
    int n= s.length();
    int length =0;
    for(int i=0;i<n;i++){
        if(s.charAt(i)=='R'){
            int j= i;
            while(j<s.length()&&s.charAt(j)=='R'){
                length++;
                j++;
            }
            max = Math.max(length, max);
            length = 0;
        }
    }
    out.println(max);

   out.flush();
   

}
static int rcToxy(int r, int c,int W){
    return r*W+c;
}
static class Node{
    int r, c,prev,change;
    Node(int r, int c){
        this.r =r ;
        this.c = c;
    }
}
public static class MyScanner {
      BufferedReader br;
      StringTokenizer st;
 
      public MyScanner() {
         br = new BufferedReader(new InputStreamReader(System.in));
      }
 
      String next() {
          while (st == null || !st.hasMoreElements()) {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      }
 
      int nextInt() {
          return Integer.parseInt(next());
      }
 
      long nextLong() {
          return Long.parseLong(next());
      }
 
      double nextDouble() {
          return Double.parseDouble(next());
      }
 
      String nextLine(){
          String str = "";
	  try {
	     str = br.readLine();
	  } catch (IOException e) {
	     e.printStackTrace();
	  }
	  return str;
      }

   }
}

Measured memory_bytes: 32780
S = input()

if S == 'SSS':
    print(0)
elif S == 'RRR':
    print(3)

elif (S[0] == 'R' and S[1] == 'R') or (S[1] == 'R' and S[2] == 'R'):
   print(2)
else:
    print(1)

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

int main(){
    char c;
    bool check=false;
    cin >> c;
    for(char vowel:{'a', 'i', 'u', 'e', 'o'}){
        if(c==vowel){
            check=true;
            }
    }
    if(check==true){
        cout << "vowel" << endl;
    }else{
        cout << "consonant" << endl;
    }
}




Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    ll n,k,ans=1; cin>>n>>k;
    vector<vector<int>> path(n);
    rep(i,n-1){
        int a,b; cin>>a>>b;
        a--; b--;
        path[a].push_back(b);
        path[b].push_back(a);
    }
    ll r=0;
    rep(i,n) r=max(r,(ll)path[i].size()+1);
    if(k<r){
        cout<<0<<endl;
        return 0;
    }
    queue<pair<ll,ll>> que;
    que.push(mk(0,-1));
    ll s,par;
    vector<ll> visited(n,0);
    vector<ll> used(n,0);
    while(!(que.empty())){
        tie(s,par)=que.front();
        que.pop();
        visited[s]=1;
        if(par==-1){
            used[s]=1;
            ans=(ans*k)%MOD;
            for(auto to:path[s])
            que.push(mk(to,s));
        }
        else{
            ans=(ans*(k-used[par]))%MOD;
            used[par]++;
            used[s]=2;
            for(auto to:path[s])if(to!=par)
            que.push(mk(to,s));
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 9336
#include<iostream>
#include <string> 
#include <vector>  
#include<math.h>

#define INF 1000000000
using namespace::std;



long Lmax(long x, long y) {
	if (x > y)return x;
	return y;
}

int max(int x, int y) {
	if (x > y)return x;
	return y;
}

long Lmin(long x, long y) {
	if (x < y)return x;
	return y;
}


int min(int x, int y) {
	if (x < y)return x;
	return y;
}

int abs(int x) {
	if (x < 0) {
		return -x;
	}
	return x;
}




int H, W, ans, N,x,y,z, A,X[8002],Y,xnum,ynum, num,sum,B,now,chain[100000];
string s,t,tt,ss;


int main() {
	cin >> N>>Y;
	Y = Y / 1000;

	for (int i = 0; i<=N; i++) {
		for (int j = 0; j <= N - i; j++) {
			if (Y == (N - i - j) + 5 * j + 10 * i) {
				cout << i << " " << j << " " << (N - i - j) << endl;
				return 0;
			}
		}
	}
	x = y = z = -1;

	cout << x << " " << y << " " << z << endl;
	return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const int nmax=200005;
ll fac[nmax],finv[nmax],inv[nmax];
 
void COMinit(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for(int i=2;i<nmax;i++){
    fac[i]=fac[i-1]*i%mod;
    inv[i]=mod-inv[mod%i]*(mod/i)%mod;
    finv[i]=finv[i-1]*inv[i]%mod;
  }
}
ll pow_mod(ll n,ll k,ll m){
  ll res=1;
  for(;k>0;k>>=1){
    if(k&1){
      res=(res*n)%m;
    }
    n=(n*n)%m;  
  }
  return res;
}
int main(){
    ll n,a,b;cin >> n >> a >> b;
    if(n==2){
        cout << 0 << endl;
        return 0;
    }
    COMinit();
    ll ans=(pow_mod(2,n,mod)-1+mod)%mod;
    ll p=finv[a],q=finv[b];
    for(ll i=0;i<a;i++){
        p*=(n-i);
        p%=mod;
    }
    for(ll i=0;i<b;i++){
        q*=(n-i);
        q%=mod;
    }
    ans=(ans-p+mod-q+mod)%mod;
    cout << ans << endl;
}

Measured memory_bytes: 4992
i = list(map(int, input().split()))
j = list(map(int, input().split()))
a=j[i[1]-1]-j[0]
if a*2>i[0]:
    a=i[0]-a
for k in range(i[1]-1):
    if j[k+1]-j[k]>a:
        a=j[k+1]-j[k]
print(i[0]-a)

Measured memory_bytes: 26444
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (ll i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
const int MAX = 1000001;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

typedef pair<int, int> P;
int main()
{
    ll X, Y, sum;
    cin >> X >> Y;

    sum = X + Y;
    COMinit();
    if (sum % 3 != 0) {
        cout << 0 << endl;
        return 0;
    }
    else {
        ll tx = min(X, Y);
        ll ty = max(X, Y);
        if (sum / 3 > tx) {
            cout << 0 << endl;
            return 0;
        }
        ll l = sum / 3;
        ll r = tx - l;

        cout << COM(l, r) << endl;
    }
    return 0;
}

Measured memory_bytes: 23680
#![allow(unused_imports)]
#![allow(unused_variables)]
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(deprecated)]

use std::cell::{Cell, Ref, RefCell, RefMut};
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;
use std::usize;

const MOD_10_9_7: u64 = 1_000_000_007;
const INF: i64 = 1_000_000_000_000;
const MIN_INF: i64 = -1_000_000_000_000;

/// FYI: https://github.com/vain0x/scan-bench
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}

#[allow(unused_macros)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn main() {
    let n = read!(usize);
    let abc: Vec<(usize, usize, usize)> = read!(usize, usize, usize; n);

    // dp[i][j(=0, 1, 2)] := i日目にjという活動をおこなった場合の最大幸福度
    let mut dp = vec![vec![0; 3]; n];

    dp[0][0] = abc[0].0;
    dp[0][1] = abc[0].1;
    dp[0][2] = abc[0].2;

    for i in 1..n {
        dp[i][0] = max(dp[i - 1][1] + abc[i].0, dp[i - 1][2] + abc[i].0);
        dp[i][1] = max(dp[i - 1][0] + abc[i].1, dp[i - 1][2] + abc[i].1);
        dp[i][2] = max(dp[i - 1][1] + abc[i].2, dp[i - 1][0] + abc[i].2);
    }

    let ans = max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2]));
    println!("{}", ans);
}


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

using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

#define MAX 100005
#define INF INT_MAX

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

// 行きがけ順は(親)(左部分木)(右部分木)の並び
// 通り掛け順は(左部分木)(親)(右部分木)の並び
// それぞれ分割して再帰に突っ込む
// 帰りがけ順は(左部分木)(右部分木)(親)の順で返せばOK
vector<int> toPostOrder(vector<int> preorder, vector<int> inorder)
{
    if (preorder.size() == 0) {
        return vector<int>(0);
    }

    int parent = preorder[0];
    auto itr = find(inorder.begin(), inorder.end(), parent);
    int l_cnt = distance(inorder.begin(), itr);
    int r_cnt = inorder.size() - l_cnt - 1;

    vector<int> pre_left, pre_right;
    vector<int> in_left, in_right;
    rep(i,l_cnt) {
        pre_left.push_back(preorder[i+1]);
        in_left.push_back(inorder[i]);
    }
    rep(i,r_cnt) {
        pre_right.push_back(preorder[l_cnt+1+i]);
        in_right.push_back(inorder[l_cnt+1+i]);
    }
    vector<int> post_left = toPostOrder(pre_left, in_left);
    vector<int> post_right = toPostOrder(pre_right, in_right);

    vector<int> postorder;
    postorder.insert(postorder.end(), post_left.begin(), post_left.end());
    postorder.insert(postorder.end(), post_right.begin(), post_right.end());
    postorder.push_back(parent);

    return postorder;
}

int main(int, char**)
{
    int n;
    cin >> n;

    vector<int> preorder(n);
    vector<int> inorder(n);

    rep(i,n) cin >> preorder[i];
    rep(i,n) cin >> inorder[i];

    vector<int> postorder = toPostOrder(preorder, inorder);

    rep(i,n) { if(i) cout << " "; cout << postorder[i]; }
    cout << endl;

    return 0;
}


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

int main(){
	int a[5];
	REP(i,5)cin >> a[i];
	cout << min(min(a[0],a[1]),a[2]) + min(a[3],a[4]) -50 << endl;
	return 0;
}


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


using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0; i<ll(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
typedef pair <int, int> P;
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

const int  INF = 1 << 29;
const ll INFL = 1LL << 60;
const ll mod = 998244353;


int main() {

	ll n, m, v, p;
	cin >> n >> m >> v >> p;
	VLL a(n);
	REP(i, n)cin >> a[i];

	sort(ALL(a));
	VLL s(n + 1, 0);
	REP(i, n) {
		s[i + 1] = s[i] + a[i];
	}


	int ans = p;

	REP(i, n - p) {
		ll b = a[i] + m;
		if (b < a[n - p])continue;
		
		ll cur = p * m;
		cur += i * m;
		if (cur >= m * v) {
			ans++;
			continue;
		}

		int c = lower_bound(ALL(a), b) - a.begin();
		c = min((ll)c, (ll)n - p);

		ll su = s[c + 1] - s[i + 1];
		ll cnt = -su + b * (c - i);
		cur += cnt;

		if (cur >= m*v) {
			ans++;
		}
	}

	cout << ans << endl;
	
	
}


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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<pair<int, int>> ranges(n);
    for (int i = 0; i < n; ++i) {
        int x, l;
        cin >> x >> l;
        ranges[i] = {x - l, x + l};
    }
    sort(ranges.begin(), ranges.end(), [](auto a, auto b) {
        return a.second < b.second;
    });
    int taken = 0;
    int r = INT_MIN;
    for (int i = 0; i < n; ++i) {
        if (ranges[i].first >= r) {
            ++taken;
            r = ranges[i].second;
        }
    }
    cout << taken << "\n";
    return 0;
}



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

using namespace std;

int main(){
    long K, X;
    cin>>K>>X;

    cout<<X-K+1;
    for(int i=X-K+1+1; i<X+K; ++i){
        if(i>=-1000000 && i<=1000000)
        cout<<" "<<i;
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <cmath>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;

int main(int argc, char const* argv[])
{
  int n, m, x, y;
  cin >> n >> m >> x >> y;
  vector<int> vecx;
  vector<int> vecy;
  for(int i = 0; i < n; i++){
    int a;
    cin >> a;
    vecx.pb(a);
  }
  for(int i = 0; i < m; i++){
    int a;
    cin >> a;
    vecy.pb(a);
  }
  int z = max(x, *max_element(vecx.begin(), vecx.end())) + 1;
  if(z <= y && z <= *min_element(vecy.begin(), vecy.end())){
    cout << "No War" << endl;
  }else{
    cout << "War" << endl;
  }
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(c) c.begin(), c.end()
#define rep(i,a,b) for(int i = a;i < b; ++i)
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
using namespace std;

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

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	char c;
	c = getchar();
	cout << (char) (c + 1) << '\n';
}


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


int main(void){
    int n,k;
    std::cin >> n >> k;
    std::vector<bool> v(n, false);
    for(int i = 0;i < k;i++){
        int d;
        std::cin >> d;
        for(int j = 0;j < d;j++){
            int x;
            std::cin >> x;
            v[x-1] = true;
        }
    }
    int r = 0;
    for(const bool &x: v){
        if(!x) r++; 
    }
    std::cout << r << std::endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 30

signed main()
{
    string S;
    cin >> S;
    REP(i, S.length()) {
        printf("%c", S[i]);
        if(i == 3) { printf(" "); }
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  for (int i =0; i< N;i++){
    string s ;
    cin >>s;
    if (s == "Y"){
      cout << "Four" <<endl;
      break;
    }
    if (i == N-1){
      cout << "Three" <<endl;
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    double a,b,c;
    cin>>a>>b>>c;
    a=a/b;
    if(a>c)
    {
        cout<<"No"<<endl;
    }
    else if(a<=c)
    {
        cout<<"Yes"<<endl;
    }
}


Measured memory_bytes: 3716
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k, n) for (ll i = k; i < (ll)(n); ++i)
#define MAX 100010
#define MOD 1000000007
typedef long long  ll;

using namespace std;

ll ans, cnt;


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

	for (int bit = 0; bit < (1 << (S.size())); ++bit) {
		ans = 0;
		
		vector<int> A; // 部分集合
		for (int i = 0; i < S.size(); ++i) {
			if (bit & (1 << i)) { // i番目にフラグが立っているか
				A.push_back(i);
			}
		}

		ll temp  = 0;
		rep(i,S.size()) {
			auto itr = find(A.begin(), A.end(), i);
			if (itr != A.end()) { // 発見出来た場合
				ans += temp;
				temp = 0;
			}
			else { // 発見出来なかった場合
				temp = temp * 10 + (S[i] - '0') ;
			}

			if (i == (S.size() - 1)) {
				ans += temp;
				temp = 0;
			}

		}

		cnt += ans;

		/*cout << "ans; " << ans << endl;
		cout << bit << ": {";
		for (int i = 0; i < (int)A.size(); ++i) {
			cout << A[i] << " ";
		}
		cout << "}" << endl;*/
	}
	
	cout << cnt << endl;

	return 0;
}


Measured memory_bytes: 256
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 06/14/20 20:53:44
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int h,w,k; cin>>h>>w>>k;
  int a,b,c,d; cin>>a>>b>>c>>d; a--; b--; c--; d--;
  vector<string> grid(h);
  for (int i = 0; i < h; i++) {
    cin>>grid[i];
  }
  vector<vector<int>> dist(h, vector<int>(w, 1e9));
  dist[a][b] = 0;
  struct Pos {
    int x,y;
  };
  queue<Pos> qs;
  qs.push({a,b});
  while (not qs.empty()) {
    auto [x,y] = qs.front(); qs.pop();
    if (x == c and y == d) {
      break;
    }
    auto cd = dist[x][y];
    // up
    for (int i = x-1, c = 0; i >= 0 and c < k; i--, c++) {
      if (grid[i][y] == '@') break;
      if (dist[i][y] < cd+1) break;
      if (dist[i][y] == cd+1) continue;
      dist[i][y] = cd+1;
      qs.push({i,y});
    }
    //down
    for (int i = x+1, c = 0; i < h and c < k; i++, c++) {
      if (grid[i][y] == '@') break;
      if (dist[i][y] < cd+1) break;
      if (dist[i][y] == cd+1) continue;
      dist[i][y] = cd+1;
      qs.push({i,y});
    }
    // left
    for (int i = y-1, c = 0; i >= 0 and c < k; i--, c++) {
      if (grid[x][i] == '@') break;
      if (dist[x][i] < cd+1) break;
      if (dist[x][i] == cd+1) continue;
      dist[x][i] = cd+1;
      qs.push({x,i});
    }
    // right
    for (int i = y+1, c = 0; i < w and c < k; i++, c++) {
      if (grid[x][i] == '@') break;
      if (dist[x][i] < cd+1) break;
      if (dist[x][i] == cd+1) continue;
      dist[x][i] = cd+1;
      qs.push({x,i});
    }
  }
  cout << (dist[c][d]==1e9 ? -1 : dist[c][d]) << endl;

  return 0;
}


Measured memory_bytes: 12128
import sys
bbn=1000000007
	
#+++++

		
def main():
	n = int(input())
	al = list(map(int, input().split()))
	count=0
	pre_max=al[0]
	for v in al:
		pre_max = min(v, pre_max)	
		if pre_max >= v:
			count+=1
	print(count)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 75216
# -*- coding: utf-8 -*-
"""
AtCoder A
"""

import sys, math, random
import numpy as np

# N = int(input())
# A = list(map(int,input().split())) # N row 1 column
# A = [int(input()) for _ in range(N)] # 1 row N column
# S = str(input()) # str(input()) == input() -> 'abc'
# S = list(input()) # abc -> ['a','b','c']
# S.replace('ABC','X') # "testABCABC" -> "testXX"
 
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
 
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    N = I()
    D = LI()
    D.sort()
    half=int(N/2-1)
    print(D[half+1]-D[half])

    
if __name__ == "__main__":
    main()

Measured memory_bytes: 24408
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << a * b / 2 << endl;
    return 0;
}


Measured memory_bytes: 256
H,W = (int(x) for x in input().split())

a_mat = []
for _ in range(H):
    a_mat.append([int(x) for x in input().split()])

out_op = []
for h in range(H):
    for w in range(W):
        if h%2 == 0:
            wd = w
            if w == W-1:
                next_pos = (h+1, wd)
            else:
                next_pos = (h, wd+1)
        else:
            wd = W-1-w
            if w == W-1:
                next_pos = (h+1, wd)
            else:
                next_pos = (h, wd-1)
        if h == H-1 and w == W-1:
            break
        if a_mat[h][wd] % 2 == 1:
            a_mat[next_pos[0]][next_pos[1]] += 1
            out_op.append((h, wd, next_pos[0], next_pos[1]))

print(len(out_op))
for y,x,yn,xn in out_op:
    print(y+1,x+1,yn+1,xn+1)


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

int main()
{
	int64_t n;
	cin >> n;
	vector<int64_t> as(n);
	for (auto &&a : as)
	{
		cin >> a;
	}

	int64_t cnt = 0;
	for (int64_t i = 0, j = 1; i < n; i++)
	{
		if (as[i] == j)
		{
			cnt++;
			j++;
		}
	}

	cout << ((cnt == 0) ? -1 : (n - cnt)) << endl;

	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx = 1e5 + 7;
ll n, ans = 1ll << 60;
ll a[maxx];

int main() {
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	int flag = 0;
	ll sum = 0;
	ll res = 0;
	for(int i = 1; i <= n; i++) {
		sum += a[i];
		if(flag == 0){
			if(sum <= 0) {
				res = res + 1 - sum;
				sum = 1;
			}
		}
		else {
			if(sum >= 0){
				res = res + sum + 1;
				sum = -1;
			}
		}
		flag ^= 1;
	}
	ans = min(ans, res);
	res = 0;
	sum = 0;
	flag = 0;
	for(int i = 1; i <= n; i++) {
		sum += a[i];
		if(flag == 1){
			if(sum <= 0) {
				res = res + 1 - sum;
				sum = 1;
			}
		}
		else {
			if(sum >= 0){
				res = res + sum + 1;
				sum = -1;
			}
		}
		flag ^= 1;
	}
	ans = min(ans, res);
	cout << ans << endl;
}

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

int main()
{
	int n, m;
	bool f = 1;

	cin >> n >> m;

	int mx = m;

	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;

		m += a - b;
		mx = max(m, mx);
		if (m < 0)
			f = 0;
	}

	if (f)
		cout << mx << endl;
	else
		cout << 0 << endl;
	
	return 0;
}



Measured memory_bytes: 3068
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0);
#define END return EXIT_SUCCESS;
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP((I),(N)) cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N)) cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N)) cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUTS(I,N,V) REP((I),(N)) cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T>inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T>inline T lcm(T a,T b){return a*b/gcd(b,a%b);}


inline void solve(){
  int A,B;
  IN2(A,B);
  if(B%A==0){
    OUT(A+B);
  }else{
    OUT(B-A);
  }
}

int main(int argc,char**argv){
  BEGIN
  solve();
  END
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int area = a * b;
        int peri = (a + b) * 2;
        System.out.println(area + " " + peri);
    }
}


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

using namespace std;

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

    int min = n;
    int count = 0;

    int p;
    for (int i = 0; i < n; i++) {
        cin >> p;
        if (min >= p) {
            min = p;
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

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

#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#include <math.h>

constexpr long long int MOD = 998244353;

int main() {

	long long int inv[ 3 ] = {};
	inv[1] = 1;
	for ( long long int i = 2; i <= 2; i++ ) {
		inv[i] = MOD - ( MOD / i ) * inv[ MOD % i ] % MOD;
	}

    long long int n, s;
    cin >> n >> s;

    vector< long long int > v;

    long long int st = 1;
    for ( long long int i = 0; i < n; i++ ) {
        long long int in;
        cin >> in;
        v.push_back( in );
        st *= 2;
        st %= MOD;
    }

    long long int dp[3001] = {};
    dp[0] = st;

    for ( long long int i = 0; i < n; i++ ) {
        for ( long long int j = s - v[i]; j >= 0; j-- ) {

            dp[ j + v[i] ] += dp[ j ] * inv[2];
            dp[ j + v[i] ] %= MOD;

        }
    }

    cout << dp[s] << endl;

    return 0;

}


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

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

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

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

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

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

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

int main(){
	summon_tourist;

	int X; cin >> X;
	if(X >= 30){
		cout << "Yes" << ln;
	}else {
		cout << "No" << ln;
	}
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
//g++ -std=c++11 

using namespace std;
typedef long long ll;

#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define DIV 1000000007 //10^9+7

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

	map<ll, ll> M;
	rep(i, N) {
		map<ll, ll>::iterator it = M.lower_bound(A[i]);
		if(M.size() == 0 || it == M.begin()) {
			M[A[i]]++;
		} else {
			it--;
			M[(*it).first]--;
			if(M[(*it).first] == 0) {
				M.erase((*it).first);
			}
			M[A[i]]++;
		}
	}

	ll ans = 0;
	for(pair<ll, ll> item: M) {
		ans += item.second;
	}
	cout << ans  << endl;
	

}


Measured memory_bytes: 10108
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int n, a, b, c;

vector<int> l;

int x[3];
int cnt[3];

int ans = 1 << 28;

void dfs(int i) {
    if (i == n) {
        if (min({x[0], x[1], x[2]}) == 0) {
            return;
        }

        ans = min(ans, abs(a - x[0]) + abs(b - x[1]) + abs(c - x[2]) + 10 * (cnt[0] + cnt[1] + cnt[2] - 3));

        return;
    }

    {
        dfs(i + 1);
    }

    for (int j = 0; j < 3; j++) {
        x[j] += l[i];
        cnt[j]++;

        dfs(i + 1);

        x[j] -= l[i];
        cnt[j]--;
    }
}

int main() {
    cin >> n >> a >> b >> c;
    
    l.resize(n);

    for (int i = 0; i < n; i++) {
        cin >> l[i];
    }

    dfs(0);

    cout << ans << endl;
}


Measured memory_bytes: 888
#include<iostream>
#include<cstdio>
#include<queue>
#define ll long long
using namespace std;
inline ll read()
{
	ll r,s=0,c;
	for(;!isdigit(c=getchar());s=c);
	for(r=c^48;isdigit(c=getchar());(r*=10)+=c^48);
	return s^45?r:-r;
}
const int N=1000010,M=1000010<<4;
const ll inf=1e18;
int n,m;
struct edge
{
	int to,next;
	ll val;
}mem[M];
int head[N],cnt=1;
inline void add(int u,int v,ll val)
{
	mem[++cnt].next=head[u];
	mem[cnt].to=v;
	mem[cnt].val=val;
	head[u]=cnt;
}
struct tree
{
	int l,r,id;
}t1[N<<2],t2[N<<2];
int tot;
void build1(int rt,int l,int r)
{
	t1[rt].l=l,t1[rt].r=r;
	if(l==r)
	{
		t1[rt].id=l;
		return;
	}
	t1[rt].id=++tot;
	int mid=(l+r)>>1;
	build1(rt<<1,l,mid);
	build1(rt<<1|1,mid+1,r);	
	add(t1[rt<<1].id,t1[rt].id,0),add(t1[rt<<1|1].id,t1[rt].id,0);
}
void build2(int rt,int l,int r)
{
	t2[rt].l=l,t2[rt].r=r;
	if(l==r)
	{
		t2[rt].id=l+n;
		add(l+n,l,0);
		return;
	}
	add(t2[rt].id,t1[rt].id,0);
	t2[rt].id=++tot;
	int mid=(l+r)>>1;
	build2(rt<<1,l,mid);
	build2(rt<<1|1,mid+1,r);
	add(t2[rt].id,t2[rt<<1].id,0),add(t2[rt].id,t2[rt<<1|1].id,0);
}
struct node
{
	int num;
	ll val;
	friend bool operator < (node a,node b)
	{
		return a.val>b.val;
	}
}f,ff;
ll d[N];
bool vis[N];
inline void dijkstra()
{
	for(int i=1;i<=tot;++i)d[i]=inf;
	d[1]=0;
	f.num=1,f.val=0;
	priority_queue<node>q;
	while(!q.empty())q.pop();
	q.push(f);
	while(!q.empty())
	{
		f=q.top();
		q.pop();
		if(vis[f.num])continue;
		vis[f.num]=1;
		for(int i=head[f.num];i>0;i=mem[i].next)
		{
			int to=mem[i].to;
			if(d[to]>d[f.num]+mem[i].val)
			{
				d[to]=mem[i].val+d[f.num];
				ff.num=to,ff.val=d[to];
				q.push(ff);
			}
		}
	}
}
void query1(int rt,int l,int r,int pos,ll val)
{
	if(l<=t1[rt].l&&t1[rt].r<=r)
	{
		add(t1[rt].id,pos,val);
		return;
	}
	int mid=(t1[rt].l+t1[rt].r)>>1;
	if(l<=mid)
		query1(rt<<1,l,r,pos,val);
	if(r>mid)
		query1(rt<<1|1,l,r,pos,val);
}
void query2(int rt,int l,int r,int pos)
{
	if(l<=t2[rt].l&&t2[rt].r<=r)
	{
		add(pos,t2[rt].id,0);
		return;
	}
	int mid=(t2[rt].l+t2[rt].r)>>1;
	if(l<=mid)
		query2(rt<<1,l,r,pos);
	if(r>mid)
		query2(rt<<1|1,l,r,pos);
}
int main()
{
	n=read(),m=read();
	int l,r;
	ll val;
	tot=n<<1;
	build1(1,1,n),build2(1,1,n);
//	for(int i=1;i<=tot;++i){cout<<i;for(int j=head[i];j;j=mem[j].next)cout<<"->"<<mem[j].to;cout<<endl;}//	system("pause");
	while(m--)
	{
		l=read(),r=read(),val=read();
		query1(1,l,r,++tot,val);
		query2(1,l,r,tot);
	}
//	for(int i=1;i<=tot;++i){cout<<i;for(int j=head[i];j;j=mem[j].next)cout<<"->"<<mem[j].to;cout<<endl;}
	dijkstra();
//	for(int i=1;i<=tot;++i){if(d[i]==inf)d[i]=-1;cout<<d[i]<<' ';}cout<<endl<<endl;
if(d[n<<1]==inf)d[n<<1]=-1;	
  cout<<d[n<<1]<<'\n';
	return 0;
}

Measured memory_bytes: 73204
#include <bits/stdc++.h> 
#include<set>
using namespace std; 
  
// A function to print all prime  
// factors of a given number n  
long long int  primeFactors(long long int n)  
{  long long int count=0;
      set <int, greater <int> > a;
    // Print the number of 2s that divide n  
    while (n % 2 == 0)  
    {  
        a.insert(2);
        n = n/2;  
    }  
  
    // n must be odd at this point. So we can skip  
    // one element (Note i = i +2)  
    for (int i = 3; i <= sqrt(n); i = i + 2)  
    {  
        // While i divides n, print i and divide n  
        while (n % i == 0)  
        {  
            a.insert(i); 
            n = n/i;  
        }  
    }  
  
    // This condition is to handle the case when n  
    // is a prime number greater than 2  
    if (n > 2)  
        a.insert(n);
        count=a.size();
      return count;  
}  
  
/* Driver code */
int main()  
{  
    long long int a,b,c,k;cin>>a>>b;
    c=__gcd(a,b);
//    int n = 315;  
   k= primeFactors(c);  
   cout<<k+1<<endl;
    return 0;  
}  

Measured memory_bytes: 256
def main():
    n, m, x = map(int, input().split())
    ca = [list(map(int, input().split())) for _ in [0]*n]
    ans = 10**20
    for i in range(2**n):
        temp = [0]*m
        cost = 0
        for j in range(n):
            if i & 2**j:
                cost += ca[j][0]
                for k in range(m):
                    temp[k] += ca[j][k+1]
        for j in range(m):
            if temp[j] < x:
                break
        else:
            ans = min(ans, cost)
    if ans == 10**20:
        print(-1)
    else:
        print(ans)


main()


Measured memory_bytes: 9212
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n,count=0;
    cin >> n;
    vector<int> p(n);
    
    for (int i = 0; i < n; i++)
    {
        cin >> p.at(i);
    }

    for (int i = 1; i < n-1; i++)
    {
        if (p.at(i-1) < p.at(i) && p.at(i) < p.at(i+1)){
            count++;
        }
        else if (p.at(i+1) < p.at(i) && p.at(i) < p.at(i-1))
        {
            count++;
        }
    }
    

    cout << count << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);
    
    int a = sc.nextInt();
    int b = sc.nextInt();
    
    System.out.println((a + b) % 2 == 0 ? (a + b) / 2 : (a + b + 1) / 2);
  }
}

Measured memory_bytes: 20820
import Control.Monad
import Control.Applicative
import Data.List
import qualified Data.Map as M
--import qualified Data.Vector as V
--import qualified Data.Vector.Mutable as VM

getBysplit = map read . words <$> getLine

main :: IO()
main = do
  [a, b, t] <- getBysplit
  let ans = (t `div` a) * b
  print ans


Measured memory_bytes: 508
using System;
class Program
{
	static void Main(string[] args)
	{
         string[] Inputs = Console.ReadLine().Split();
         long N = long.Parse( Inputs[0] );
         long A = long.Parse( Inputs[1] );
         long B = long.Parse( Inputs[2] );

         long raund =0;

if( (B - A) % 2 == 0)  //偶数なら近づいていけばいい
     {
          raund = (B-A) / 2;
          
     }
else  //奇数
     {
          if(A - 1 < N - B)// Aのが近い
               {
                    long a = A - 1;
                    B -= 1;
                    raund = ((B - A) / 2) +a +1;
                    
               }
          else//Bのが近いか同じ
               {
                    long b = N - B;
                    A += 1;
                    raund = ((B - A) / 2) +b +1;
               }
     }

         Console.WriteLine(raund);
         
	}
}



Measured memory_bytes: 11092
N,X,E=map(int,input().split())
D=E+(E==0)
f,c,r={},[0]*10**8,0
for x,y,z in sorted(((((N-k)*j+~-k)*k//2+k*X//D)*(E!=0),j,k*X%D+k*(E==0 and X!=0))for k in range(N+1)for j in[0,2]):
 if c[z]+y<1:
  f[z]=x
 r+=(x-f[z]+1)*(c[z]<y)
 c[z]-=y-1
print(r)

Measured memory_bytes: 888088
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
    int n, i;

    for(;;){
      n = sc.nextInt();
      if(n == 1)break;
      out.print(n + ":");
      for(i = 6;i <= n;i++){
        if(n % i == 0 && ismsprime(i))out.print(" " + i);
      }
      out.println();
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }

  private static boolean ismsprime(int p){
    int i;
    if((p % 7 != 1 && p % 7 != 6) || p == 1)return false;
    for(i = 6;i * i <= p;i+=5){
      if(p % i == 0)return false; i += 2;
      if(p % i == 0)return false;
    }
    return true;
  }
}

Measured memory_bytes: 23840