akhauriyash/Code-Regression huggingface dataset:
// ABC143_A
#include <iostream>
#include <string>
#include <vector>
#include <iterator>  // std::prev(iter, n) n 個分デクリメントしたイテレータ
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <cstring>  // std::memset 初期化
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> pll;

#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define MIN(vec) min_element(vec.begin(), vec.end())  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(vec.begin(), vec.end())
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(vec.begin(), vec.end(), 0LL)  // 0 は初期値
#define F first
#define S second
const ll INF = 1LL<<60;  // 10^18（const int inf   = 1<<29;）

int main() {
    // input(sunippets: inpv, inpn, inps)
    ll N, M;
    cin >> N >> M;
    
    // calculation
    cout << max(0LL, N-2*M) << "\n";
    
    return 0;
}

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

vector<int> l;
int n,m;

bool input(){
  cin>>n>>m;
  if(n==m&&n==0)return false;
  l.clear(),l.resize(n);
  for(int i=0;i<n;i++){
    cin>>l[i];
  }
  return true;
}

int solve(){
  sort(l.rbegin(),l.rend());
  int ans = 0;
  for(int i=0;i<n;i++){
    if( (i+1) %m == 0){
      continue;
    }
    ans += l[i];
  }
  return ans;
}

int main(){
  while(input()){
    cout<<solve()<<endl;
  }
}

Measured memory_bytes: 1208
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#include <assert.h>
#define int long long
#define double long double
#define oku7 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	//ない環境用
#define LL_HALFMAX 9223372036854775807 / 2	//ない環境用

using namespace std;
std::mt19937 mt((int)time(0));

int dx[4] = { 0, 1, 0, -1 }; // x軸方向への変位
int dy[4] = { 1, 0, -1, 0 }; // y軸方向への変位

int a[200001];
int mapData[200001];

signed main() {
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		int inp;
		cin >> inp;
		a[i] = inp;
		mapData[inp] = i+1;
	}
	set<int> s{0,N+1};
	auto last = s.end();
	int ans = 0;
	for (int i = 1; i <= N; i++) {
		//int l, r;
		s.insert(mapData[i]);
		auto near = s.find(mapData[i]);
		auto lit = near;
		auto rit = near;
		lit--;
		rit++;
		int add = (mapData[i] - *lit ) * (*rit - mapData[i] );
		add *= i;
		ans += add;
	}
	cout << ans << "\n";


}

Measured memory_bytes: 12800
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.CodeFestival2016Final
{
    class D
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int[] nm = ReadInts();
            int n = nm[0];
            int m = nm[1];
            int[] xs = ReadInts();
            Array.Sort(xs);
            int remainVal = -1;
            int[] pairCnts = new int[m];
            int[] remainCnts = new int[m];
            for (int i = 0; i < n; i++)
            {
                if (remainVal == xs[i])
                {
                    pairCnts[xs[i] % m]++;
                    remainVal = -1;
                }
                else
                {
                    if (remainVal > 0) remainCnts[remainVal % m]++;
                    remainVal = xs[i];
                }
            }
            if (remainVal > 0) remainCnts[remainVal % m]++;

            int res = 0;
            for (int i = 0; i <= m - i; i++)
            {
                int other = m - i;
                if (i == 0 || i == m - i)
                {
                    res += remainCnts[i] / 2 + pairCnts[i];
                }
                else
                {
                    int a, b;
                    if (remainCnts[i] < remainCnts[other])
                    {
                        a = i;
                        b = other;
                    }
                    else
                    {
                        a = other;
                        b = i;
                    }
                    res += remainCnts[a];
                    remainCnts[b] -= remainCnts[a];
                    res += Min(pairCnts[a] * 2, remainCnts[b]);
                    pairCnts[a] = Max(
                        (pairCnts[a] * 2 - remainCnts[b]) / 2, 0);
                    res += pairCnts[a] + pairCnts[b];
                }
            }
            WriteLine(res);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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

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

    for(int i=a;i<=b;i++){
        if(i%k==0){
            cout<<"OK\n";
            return 0;
        }
    }
    cout<<"NG\n";
    return 0;
}


Measured memory_bytes: 3592
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		double a = sc.nextInt();
		// スペース区切りの整数の入力
		double b = sc.nextInt();
		System.out.println(a/b);
	}
}

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

public class Main {
	static Scanner sc = new Scanner(System.in);
	static List<Integer> list = new ArrayList<>();
	static int num = 0;

	
	public static void main(String[] args) {
		int n = sc.nextInt();
		for (int i=0; i<n; i++) list.add(sc.nextInt());

		mergeSort(list);
		
		StringBuilder sb = new StringBuilder();
		for (int i=0; i<list.size(); i++) sb.append((i==0?"":" ")+list.get(i));
		out.println(sb);
		out.println(num);
	}

	
	static void mergeSort(List<Integer> list) {
		int size = list.size();

		//listの大きさが1なら再帰終了
		if (size == 1) return;

		//1でないなら分割
		ArrayList<Integer> L = new ArrayList<>(), R = new ArrayList<>();
		int M = size/2;

			//分割処理、左側を作成
			for (int i=0; i<M; i++) L.add(list.get(i));
			//分割処理、右側を作成
			for (int i=M; i<size; i++) R.add(list.get(i));

			
		//再帰
		mergeSort(L); mergeSort(R);

		//マージ処理
		list.clear();
		int indexL = 0, indexR = 0;
		while (indexL<L.size() || indexR<R.size()) {
			if (indexL == L.size()) {
				list.add(R.get(indexR)); indexR++; num++;
			}
			else if (indexR == R.size()) {
				list.add(L.get(indexL)); indexL++; num++;
			}
			else {
				int tempL = L.get(indexL);
				int tempR = R.get(indexR);
				if (tempL <= tempR) {
					list.add(tempL); indexL++;
				}
				else {
					list.add(tempR); indexR++;
				}
				num++;
			}
		}
	}
}


Measured memory_bytes: 333048
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;


int main(){
    ll n, a, b;
    cin >> n >> a >> b;
    if ((b-a)%2==0) cout << (b-a)/2 << endl;
    else cout << min((b+a-1)/2, (2*n-b-a+1)/2) << endl;
    return 0;
}


Measured memory_bytes: 3620
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
    
    Scanner sc = new Scanner(System.in);
      
       int N =sc.nextInt();
       int K =sc.nextInt();
       int count =0;
      
      for(int i=0; i<N; i++){
        int H =sc.nextInt();
 
        if(H>=K){
         count++;
        }
      }
       System.out.println(count);
    }
}

Measured memory_bytes: 48528
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P>IP;
typedef vector<ll> V;
typedef vector<V> V2;
typedef vector<vector<P> > G;
void g_dir(G &graph, ll a, ll b, ll w = 1){graph[a].push_back(P(b, w));}
void g_undir(G &graph, ll a, ll b, ll w = 1){g_dir(graph, a, b, w);g_dir(graph, b, a, w);}
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
const ll INF = 1145141919;
const ll MOD = 1000000007;
const ll NUM = 101010;

ll ika_count(V &v, ll x){
    if(v[0] > x)return 0;
    if(v[v.size() - 1] <= x)return v.size();
    ll ok = 0, ng = v.size();
    while(ok + 1 < ng){
        ll mid = (ok + ng) / 2;
        if(v[mid] <= x)ok = mid;
        else ng = mid;
    }
    return ok + 1;
}
ll ijo_count(V &v, ll x){
    if(v[v.size() - 1] < x)return 0;
    if(v[0] >= x)return v.size();
    ll ng = 0, ok = v.size() -1;
    while(ng + 1 < ok){
        ll mid = (ng + ok) / 2;
        if(v[mid] >= x)ok = mid;
        else ng = mid;
    }
    return v.size() - ng - 1;
}
ll N;
V a, b, c;
ll check(ll idx){
    ll mask = 0;
    rep(i, idx + 1)mask |= (1 << i);
    rep(i, N)c[i] = b[i] & mask;
    sort(c.begin(), c.end());
    ll cnt = 0;
    rep(i, N){
        ll tmp = a[i] & mask;
        if(tmp & (1 << idx)){
            cnt += ika_count(c, mask - tmp);
            cnt += ijo_count(c, (3 << idx) - tmp);
        }
        else{
            tmp ^= (1 << idx);
            cnt += N;
            cnt -= ika_count(c, mask - tmp);
            cnt -= ijo_count(c, (3 << idx) - tmp);
        }
    }
    return cnt % 2;
}
int main(){

    cin >> N;
    a = V(N);
    b = V(N);
    c = V(N);
    rep(i, N)cin >> a[i];
    rep(i, N)cin >> b[i];
    ll ans = 0;
    rep(i, 30){
        if(check(i))ans |= (1 << i);
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 4992
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
class SuffixArray {
	void CEB(vector<int> &v, vector<int> &b) {
		int vs = v.size(), bs = b.size();
		fill(b.begin(), b.end(), 0);
		for (int i = 0; i < vs; i++) b[v[i]]++;
		for (int i = 1; i < bs; i++) b[i] += b[i - 1];
	}
	void ISort(vector<int> &v, vector<int> &SA, int mv, vector<int> &b, vector<int> &isL) {
		int vs = v.size(), bs = b.size();
		fill(b.begin(), b.end(), 0);
		for (int i = 0; i < vs; i++) b[v[i]]++;
		int sum = 0;
		for (int i = 0; i < bs; i++) b[i] += sum, swap(sum, b[i]);
		for (int i = 0; i < vs; i++) {
			if (SA[i] > 0 && isL[SA[i] - 1]) SA[b[v[SA[i] - 1]]++] = SA[i] - 1;
		}
	}
	void IISort(vector<int> &v, vector<int> &SA, int mv, vector<int> &b, vector<int> &isL) {
		CEB(v, b);
		for (int i = v.size() - 1; i >= 0; i--) {
			if (SA[i] > 0 && !isL[SA[i] - 1]) SA[--b[v[SA[i] - 1]]] = SA[i] - 1;
		}
	}
	vector<int>SA_IS(vector<int> v, int mv) {
		int vs = v.size();
		if (vs == 1) return vector<int>(1, 0);
		vector<int> isL(vs), b(mv + 1), SA(vs, -1), ord(vs);
		auto isLMS = [&](int x)->bool { return x > 0 && isL[x - 1] && !isL[x]; };
		for (int i = vs - 2; i >= 0; i--) isL[i] = (v[i] > v[i + 1]) || (v[i] == v[i + 1] && isL[i + 1]);
		CEB(v, b);
		for (int i = 0; i < vs; i++) {
			if (isLMS(i)) SA[--b[v[i]]] = i;
		}
		ISort(v, SA, mv, b, isL);
		IISort(v, SA, mv, b, isL);
		int cur = 0;
		for (int i = 0; i < vs; i++) {
			if (isLMS(i)) ord[i] = cur++;
		}
		vector<int> nxv(cur);
		cur = -1;
		int prev = -1;
		for (int i = 0; i < vs; i++) {
			if (!isLMS(SA[i])) continue;
			bool diff = false;
			for (int d = 0; d < vs; d++) {
				if (prev == -1 || v[SA[i] + d] != v[prev + d] || isL[SA[i] + d] != isL[prev + d]) {
					diff = true;
					break;
				}
				else if (d && isLMS(SA[i] + d))break;
			}
			if (diff) cur++, prev = SA[i];
			nxv[ord[SA[i]]] = cur;
		}
		vector<int> reord(nxv.size());
		for (int i = 0; i < vs; i++) {
			if (isLMS(i)) reord[ord[i]] = i;
		}
		vector<int> nxSA = SA_IS(nxv, cur);
		CEB(v, b);
		for (int i = 0; i < SA.size(); i++) SA[i] = -1;
		for (int i = nxSA.size() - 1; i >= 0; i--) {
			SA[--b[v[reord[nxSA[i]]]]] = reord[nxSA[i]];
		}
		ISort(v, SA, mv, b, isL);
		IISort(v, SA, mv, b, isL);
		return SA;
	}
	vector<int>SA_IS(string s) {
		vector<int> v(s.size() + 1);
		for (int i = 0; i < s.size(); i++) v[i] = s[i] + 1;
		return SA_IS(v, *max_element(v.begin(), v.end()));
	}
public:
	string s;
	vector<int> sa;
	void init(string &T) {
		s = T;
		sa = SA_IS(s);
	}
	SuffixArray(string &t) { init(t); }
	SuffixArray() {}
	bool contain(string &t) {
		int a = 0, b = s.size();
		while (b - a > 1) {
			int c = (a + b) / 2;
			if (s.compare(sa[c], t.size(), t) < 0) a = c;
			else b = c;
		}
		return s.compare(sa[b], t.size(), t) == 0;
	}
};
int q; string s, t;
int main() {
	cin >> s >> q;
	SuffixArray v(s);
	for(int i = 0; i < q; i++) {
		cin >> t;
		cout << (v.contain(t) ? 1 : 0) << endl;
	}
}

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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define allsort(v) sort(v.begin(),v.end())

int main() {
	cin.sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	vector<int>v(N);
	rep(i,N)v[i]=i+1;
	int a, b;
	bool path[9][9] = {};
	rep(i, M) {
		cin >> a >> b;
		path[a][b] = path[b][a] = true;
	}
	int ans = 0;
	do {
		if (v[0] != 1)break;
		int k = 0;
		bool flag = true;
		while (k != N - 1) {
			if (!path[v[k]][v[k + 1]]) {
				flag = false;
				break;
			}
			k++;
		}
		if (flag)ans++;
	} while (next_permutation(v.begin(), v.end()));
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int A, B;
	cin >> A >> B;

	int total = 0;
	if (A >= B) {
		total += A;
		A -= 1;
	}
	else {
		total += B;
		B -= 1;
	}
	if (A >= B) {
		total += A;
		A -= 1;
	}
	else {
		total += B;
		B -= 1;
	}

	cout << total << endl;

}





Measured memory_bytes: 3600
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
#include<ext/pb_ds/priority_queue.hpp>
using namespace std;

typedef long long LL;
typedef double DB;

int n,A,B,c1,c2;
DB Ans,a[55];
LL C[55][55];

int main()
{
	#ifdef DMC
		freopen("DMC.txt","r",stdin);
	#endif
	
	cin >> n >> A >> B;
	for (int i = 1; i <= n; i++) scanf("%lf",&a[i]);
	C[0][0] = 1;
	for (int i = 1; i <= 50; i++)
	{
		C[i][0] = 1;
		for (int j = 1; j <= 50; j++)
			C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
	}
	sort(a + 1,a + n + 1);
	reverse(a + 1,a + n + 1); bool flag = 1;
	for (int i = 2; i <= A; i++)
		if (fabs(a[i] - a[i - 1]) >= 1E-9) flag = 0;
	if (flag)
	{
		LL tot = 0;
		printf("%.8lf\n",a[1]);
		for (int i = 1; i <= n; i++)
			if (fabs(a[i] - a[1]) <= 1E-9) ++c1;
		for (int i = A; i <= B; i++)
			tot += C[c1][i];
		cout << tot << endl; return 0;
	}
	for (int i = 1; i <= A; i++) Ans += a[i];
	for (int i = 1; i <= n; i++) if (fabs(a[i] - a[A]) <= 1E-9) ++c1;
	for (int i = 1; i <= A; i++) if (fabs(a[i] - a[A]) <= 1E-9) ++c2;
	printf("%.10lf\n",Ans / (DB)(A));
	cout << C[c1][c2] << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    string abcd;
    cin>>abcd;

    int a=abcd[0]-'0';
    int b=abcd[1]-'0';
    int c=abcd[2]-'0';
    int d=abcd[3]-'0';
  ///  cout<<a<<b<<c<<d;
     int e=7;

    if(a+b+c+d==7) cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"="<<e;
    else if(a+b+c-d==7) cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"="<<e;
    else if(a+b-c+d==7) cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"="<<e;
    else if(a-b+c+d==7) cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"="<<e;
    else if(a+b-c-d==7) cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"="<<e;
    else if(a-b-c+d==7) cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"="<<e;
    else if(a-b-c-d==7) cout<<a<<"-"<<b<<"-"<<c<<"-"<<d<<"="<<e;
    else if(a-b+c-d==7) cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"="<<e;

}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val s = readLine()?.toCharArray()?.toSet() ?: return
    if (s.size == 26) {
        println("None")
        return
    }
    val alphabet = (97..122).map { it.toChar() }.toSet()
    println((alphabet - s).toList().min()!!)
}

Measured memory_bytes: 40716
#include "bits/stdc++.h"
using namespace std;

#define fi first
#define se second
#define pb push_back
#define int long long
#define all(x) (x).begin(), (x).end()

using LL = long long;
using LD = long double;
using pii = pair<int, int>;
using vii = vector<pii>;

const int INF = 1e18;
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;

int n, k;
int a[N], dp[N];

bool solve(int x) {
    if (dp[x] != -1) {
        return dp[x];
    }

    if (x < a[0]) {
        return 0;
    }

    bool ans = 1;
    for (int i = 0; i < n and ans; i++) {
        if (a[i] <= x) {
            ans &= solve(x - a[i]);
        }
    }

    return dp[x] = (ans == 0);
}

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

    cin >> n >> k;

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

    fill(dp, dp + N, -1);

    cout << (solve(k) ? "First" : "Second") << "\n";
    return 0;
}


Measured memory_bytes: 4224
#include <iostream>
#include <algorithm>
#include <stdint.h>
#include <cstring>
using namespace std;
enum {
	BASE = 1000000007
};
int main(void) {
	int64_t(*a)[5002] = new int64_t[5001][5002];
	memset(a, 0, sizeof(int64_t) * 5001 * 5002);
	a[0][0] = 1;
	a[1][0] = 0;
	for (int i = 1; i < 5001; i++) {
		a[i][0] = (a[i - 1][0] + 2 * a[i - 1][1]) % BASE;
		for (int j = 1; j <= i; j++) {
			a[i][j] = (a[i - 1][j-1] + 2 * a[i - 1][j + 1]) % BASE;
		}
	}
	int x,y;
	string s;
	cin >> x;
	cin >> s;
	y = s.length();
	cout << a[x][y] << endl;
}

Measured memory_bytes: 195840
#include<bits/stdc++.h>
#define sz(x) ((int)(x).size())
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
using namespace std;
 
typedef long long lld;
typedef vector<lld> vlld;
typedef pair<lld,lld> pi;
typedef tuple<lld,lld,lld> tup;
const lld mod=(lld)1e9+7;
 
lld solve(lld a[],lld n,lld k)
 {
    
    lld dp[n]={0};
    dp[0]=0;
    dp[1]=abs(a[0]-a[1]);
   
    for(lld i=1;i<n;i++)
    {
    	lld l1=mod,l2;
    	for(lld j=i-1;j>=max(i-k,0ll);j--)
    	{
            l2=abs(a[i]-a[j])+dp[j];
            l1=min(l2,l1);
    	}
    	// cout<<l1<<" ";
    	dp[i]=l1;
    	  
    }

   return dp[n-1];

 }
    	
 

int main() {

	lld n,k;
	cin>>n>>k;
	lld a[n];

	forn(i,n)
	cin>>a[i];

	cout<<solve(a,n,k);
  
  return 0;
}

Measured memory_bytes: 5124
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(x) begin(x),end(x)

#define forn(i, n) for (int i = 0; i < n; ++i)
#define rforn(i, n) for (int i = n - 1; i >= 0; --i)

const int N = 2e5 + 5; // check bounds
const int M = 1e9 + 7;
const char nl = '\n';

template< typename T > inline T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template< typename T> inline T lcm(T a, T b) { return a / gcd(a, b) * b; }

template <class T> void ckmin(T& a, T b) {a = min(a, b);}
template <class T> void ckmax(T& a, T b) {a = max(a, b);}
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;



void solve() {
	int a[5];
	for (int i = 0; i < 5; i++) {
		cin >> a[i];
		if (a[i] != i + 1) {
			cout << i + 1 << nl;
			break;
		}
	}
	
}

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

	int t = 1; //cin >> t;
	for (int i = 1; i <= t; ++i) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 3584
use proconio::input;
use proconio::marker::Chars;
use std::cmp;

fn main() {
    input! {
        s: Chars,
    }
    let mut min = std::usize::MAX;
    let c = 'a';
    for i in 0u8..26 {
        let ch = (c as u8 + i) as char;
        min = cmp::min(min, solve(&s, ch));
    }
    println!("{}", min);
}

fn solve(s: &Vec<char>, ch: char) -> usize {
    if s.iter().all(|c| *c == ch) {
        return 0;
    }
    let mut st = s.clone();
    let mut count = 0;
    let mut flag = true;
    while flag {
        flag = false;
        for i in 0..st.len() - 1 {
            if st[i + 1] == ch {
                st[i] = ch;
            }
            if st[i] != ch {
                flag = true;
            }
        }
        count += 1;
        st.pop();
    }
    return count;
}


Measured memory_bytes: 2156
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=5010;
const ll mod=1e9+7;


int main(){
  int n,a,b; cin >> n >> a >> b;
  cout << min(a*n, b) << endl;
  return 0;
}


Measured memory_bytes: 256
s = gets.chomp.split('')
a = 0
z = 0

s.each_with_index do |t,i|
  if t == "A"
    a = i
    break
  end
end

s.each_with_index do |t,i|
  if t == "Z"
    z = i
  end
end

puts z - a + 1


Measured memory_bytes: 16764
from itertools import permutations

N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))

p = 0
q = 0
L = [i for i in range(1, N+1)]
for i, v in enumerate(permutations(L), 1):
  if v == P:
    p = i
  if v == Q:
    q = i
    
print(abs(p - q))


Measured memory_bytes: 3060
#include <stdio.h>

int main(void) {
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);

  int i, count = 0;
  for (i = a; i <= b; i++) {
    if (c % i == 0) count++;
  }

  printf("%d\n", count);
  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define y_n(ans) cout<<(ans?"Yes":"No")<<endl;

int main() {
    char a; cin >> a;
    if (isupper(a)) cout << "A" << endl;
    else cout << "a" << endl;
}

Measured memory_bytes: 3632
import java.util.*;

public class Main {
    public static void main(String... args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        ArrayList<Long> input_list = new ArrayList();

        int ans = 0;

        long elm = -1;
        boolean loop_flg = true;
        for (int i = 0; i < N; i++) {
            elm = sc.nextLong();
            if (elm % 2 != 0) {
                System.out.println(ans);
                loop_flg = false;
                break;
            } else {
                input_list.add(elm);
            }
        }

        while (loop_flg) {
            for (int i = 0; i < N; i++) {
                elm = input_list.get(i);
                if (elm % 2 != 0) {
                    System.out.println(ans);
                    loop_flg = false;
                    break;
                } else {
                    input_list.set(i, elm / 2);
                }
            }
            ans++;
        }
    }
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int,null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set_pair tree<pair<int,int>,null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set_mutiset tree<int,null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef pair<int,int> pi; 
#define PI 3.1415926535897932384
#define FOR(i,vv,n) for(int i=vv;i<n;i++)
#define FORR(i,n,vv) for(int i=n-1;i>=vv;i--)
#define ve vector 
#define maxind(v) (max_element(v.begin(),v.end())-v.begin())
#define minind(v) (min_element(v.begin(),v.end())-v.begin())
#define maxe(v) *max_element(v.begin(),v.end())
#define mine(v) *min_element(v.begin(),v.end())
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define eb emplace_back
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp make_pair
#define M 1000000007ll
#define INF 1000000000000000000ll
#define PRECISE cout.precision(18);
#define all(v) v.begin(),v.end()
#define BS(v,n) binary_search(all(v),n)
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(all(v),greater <ll>())
#define uni(v) v.resize(unique(all(v)-v.begin())
#define F first
#define S second
#define GET(i,p) get<p>(i)


int main(){

    FAST
//	PRECISE


ll x,n;
cin>>x>>n;
ve <ll> v(102,0);
FOR(i,0,n){
	ll x;
	cin>>x;
	v[x]++;
}

ll a1=x,a2=x;
while(v[a1]!=0){
	a1++;
}
while(v[a2]!=0)
a2--;
ll z1=a1-x;
ll z2=x-a2;
ll ans=a2;
if(z2>z1)
	ans=a1;
cout<<ans;



return 0;
 }



Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e09;

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

  string s, t;
  cin >> s >> t;
  REP(i, s.size() + 1){
    if(s == t){
      cout << "Yes";
      return 0;
    }
    char c = s[s.size() - 1];
    s.pop_back();
    s.insert(s.begin(), c);
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <tuple>
#include <math.h>
#include <set>
#include <map>
using namespace std ;
using ll = long long ;
using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
using vc = vector<char> ;
using vvc = vector<vc> ;
using vb = vector<bool> ;
using vvb = vector<vb> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end() 
const ll INF = 1e18 ;
const ll mod = 1e9+7 ;
const double pie = acos(-1); 
vll dx4 = {-1,0,1,0} ;
vll dy4 = {0,-1,0,1} ;
vll dx8 = {-1,0,1,1,1,0,-1,-1} ;
vll dy8 = {-1,-1,-1,0,1,1,1,0} ; 

void fix_cout(){cout << fixed << setprecision(20) ; }
ll gcd(ll a,ll b){if(b==0) return a ; return gcd(b,a%b) ; }
ll lcm(ll a,ll b){return a/gcd(a,b)*b ; }
void chmax(ll &a,ll b){if(a<b) a = b ; }
void chmin(ll &a,ll b){if(a>b) a = b ; }

int main(){
	ll a,b,c ;
	cin >> a >> b >> c ;
	ll k ; cin >> k ;
	ll cnt = 0 ;
	while(a>=b){
		cnt++ ;
		b *= 2 ;
	}
	while(b>=c){
		cnt++ ;
		c *= 2 ;
	}
	cout << (cnt<=k?"Yes\n":"No\n") ;
}

Measured memory_bytes: 3628
//header{{{
#include<bits/stdc++.h>
  
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define setout(n,x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
#define int long long
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9+7; 
 
int gcd(int a,int b){ return b ? gcd(b,a % b) : a;}
int lcm(int a,int b){ return a / gcd(a,b) * b;}
//}}}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int r,g,b,n;
	cin >> r >> g >> b >> n;
	int cnt = 0;
	rep(i,n/r+1){
		rep(j,n/g+1){
			if((n - r * i - g * j) >= 0 && (n - r * i - g * j) % b == 0){
				++cnt;
			}
		}
	}
	cout << cnt << '\n';
	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.HashSet;
import java.util.Set;

public class Main {
    public static void main(String[] args) throws Exception {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

        int n = Integer.parseInt(br.readLine());
        Set<Integer> set = new HashSet<>();
        String[] in = br.readLine().split(" ");

        br.close();

        for (int i = 0; i < n; i++) {
            set.add(Integer.parseInt(in[i]));
        }

        bw.write(set.size() == n ? "YES" : "NO");

        bw.flush();

    }
}

Measured memory_bytes: 77184
import scala.io.StdIn._
import scala.annotation.tailrec

object Main {

  object Dice{
    private val northPer = List(2,6,3,4,1,5).map(_ - 1)
    private val eastPer = List(4,2,1,6,5,3).map(_ - 1)
    private val ccwPer = List(1,4,2,5,3,6).map(_ - 1)

    type Per = List[Int]
    type Rot = Dice => Dice

    def rot(dice: Dice, perm: Per):Dice = Dice(perm.map(dice.pip))

    def foldLeft(dice: Dice, perm: Per, n:Int = 4, f:(Dice,Per)=>Dice = rot):Dice =
      if(n<=0) dice else foldLeft(f(dice,perm),perm,n-1,f)

    def rev(dice: Dice, perm: Per):Dice = foldLeft(dice,perm)

    def axial(d: Dice,f: Rot): List[Dice] = List(d,f(d),f(f(d)),f(f(f(d))))

    def north(d: Dice) = rot(d,northPer)
    def east(d: Dice) = rot(d,eastPer)
    def ccw(d: Dice) = rot(d,ccwPer)

    def south(d: Dice) = rev(d,northPer)
    def west(d: Dice) = rev(d,eastPer)
    def cw(d: Dice) = rev(d,ccwPer)

    def vertical(d: Dice): List[Dice] = axial(d, north)
    def horizontal(d: Dice): List[Dice] = axial(d, east)
    def turn(d: Dice): List[Dice] = axial(d, ccw)

    def enumerateTop(d: Dice, n: Int = 6): List[Dice] = {
      if(n<=0)List[Dice]()
      else d :: enumerateTop(if(n%2==0) north(d) else east(d), n-1)
    }

    def enumerate(d: Dice): List[Dice] = enumerateTop(d).flatMap(turn)
  }

  case class Dice(pip: List[Int] = List(1,2,3,4,5,6)) {

    def rotate(com: Char):Dice = com match {
      case 'N' => Dice.north(this)
      case 'E' => Dice.east(this)
      case 'S' => Dice.south(this)
      case 'W' => Dice.west(this)
      case _ => this
    }
  }

  @tailrec
  def loop(n:Int, all: List[Dice]):Unit = if(n>0){
    val Array(a,b,_*) = readLine.split(" ").map(_.toInt)
    val res = all.filter(d => d.pip(0)==a && d.pip(1)==b)
    println(res(0).pip(2))
    loop(n-1,all)
  }

  def main(args: Array[String]): Unit = {
    val pip = readLine.split(" ").map(_.toInt).toList
    val all: List[Dice] = Dice.enumerate(Dice(pip))
    val Array(n,_*) = readLine.split(" ").map(_.toInt)
    loop(n,all)
  }
}

Measured memory_bytes: 41316
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;

int n,x[30],y[30],r[30],c[30],cover[30];
bool dp[1<<24];

int main(){
  while(cin >> n, n){
    for(int i=0;i<n;i++)cin >> x[i] >> y[i] >> r[i] >> c[i];
    
    vector<pii> same_col;
    for(int i=0;i<n;i++){
      cover[i] = 0;
      for(int j=0;j<i;j++){
	if( (x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]) < (r[i]+r[j])*(r[i]+r[j]) ){
	  cover[i] |= 1<<j;
	}
	if(c[i] == c[j])same_col.push_back(pii(i,j));
      }
    }

    memset(dp,0,sizeof(dp));
    dp[0] = true;

    for(int bit=0;bit<(1<<n);bit++){
      if(!dp[bit])continue;
      for(int i=0;i<(int)same_col.size();i++){
	const int a = same_col[i].first, b = same_col[i].second;
	if( (~bit)&(1<<a) && (~bit)&(1<<b) ){
	  if( (~bit)&cover[a] || (~bit)&cover[b])continue;
	  dp[bit | (1<<a) | (1<<b)] = true;
	}
      }
    }

    int ans = 0;
    for(int bit=0;bit<(1<<n);bit++){
      if(dp[bit])ans = max(ans, __builtin_popcount(bit));
    }
    cout << ans << endl;
  }	  
}

Measured memory_bytes: 17596
#include<cstdio>
int main()
{
    int a,b;scanf("%d %d",&a,&b);
    if(a==0 || b==0) return printf("Zero\n"),0;
    if(a>0) return printf("Positive\n"),0;
    if(a<0 && b>0) return printf("Zero\n"),0;
    if((a&1) ^ (b&1)) return printf("Positive\n"),0;
    printf("Negative\n");
    return 0;
}

Measured memory_bytes: 128
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

# https://atcoder.jp/contests/abc125/tasks/abc125_d

# 理想としてはすべて+にしたい
# i<=N-1ならばすべて自由にflipできるのでは？ #まえから愚直にflipのシミュレーションをしていっても良いしな
# iを都合のいいように変えたときには、i+1も操作で都合のいいように変えられる。よって後ろに押し付けられる
# つまり後ろの2要素の大小関係のみが重要
# んー前から愚直にシミュレーション
# すべて正にできないときは1個だけ負になるのだから、absの最小を持っておけば良い

N = read_a_int()
A = read_ints()
ans = 0
for i in range(N - 1):
    if A[i] < 0:
        ans += -A[i]
        A[i + 1] = -A[i + 1]
    else:
        ans += A[i]
if A[N - 1] >= 0:
    ans += A[N - 1]
else:
    ans += -A[N - 1]
    min_abs = abs(min(A, key=abs))
    # print(ans, min_abs)
    ans -= min_abs * 2
print(ans)


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

int main(void){
  int n,m,c,b[20],a[20][20],count = 0;
  cin >> n >> m >> c;
  for(int i = 0; i < m; i++)cin >> b[i];
  for(int i = 0; i < n; i++){
    for(int j = 0; j < m; j++)cin >> a[i][j];
  }

  for(int i = 0; i < n; i++){
    int sum = 0;
    for(int j = 0; j < m; j++)sum += a[i][j] * b[j];
    if(sum + c > 0)count++;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define _ << ' ' <<
using namespace std;
using ll = long long;


int main()
{
    int n;
    string s;
    cin >> n >> s;
    for (int i = 0; i < s.size(); ++i)
    {
        char x = s[i] - 'A';
        x += n;
        x %= 26;
        x += 'A';
        cout << x;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;  // 1e9+7
const int INF = 100100100;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define debug(x) cerr << #x << ": " << x << '\n'

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  float N;
  cin >> N;
  vector<float> v(N + 1);
  float ans = 0;
  FOR(i, 1, N + 1) cin >> v[i];
  sort(v.begin() + 1, v.end());
  v[1] = v[1] / (pow(2.0, N - 1));
  ans += v[1];
  for (float i = 2.0; i < N + 1; i += 1.0) {
    v[i] = v[i] / (pow(2.0, N - i + 1));
    ans += v[i];
    // debug(pow(2.0, N - i + 1));
  }
  cout << ans << '\n';
}

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

int main() {
    cin.tie(0)->sync_with_stdio(false);

    ll k, a, b;
    cin >> k >> a >> b;

    ll ans = 0;
    if (a >= b - 2) ans = k + 1;
    else {
        ll tmp = (k + 1) - a;
        ll div = tmp / 2;
        ll rem = tmp % 2;
        ans = div * (b - a) + rem + a;
    }

    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define ll long long int
int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	// int T;
	// cin>>T;
	// while(T--)
	
		int N;
		cin>>N;
		// int arr[N];
		if(N%2==0)
			printf("%d",N/2);
		else
			printf("%d",N/2+1);
	// }

}

Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
using namespace std;

//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp> 
//using namespace __gnu_pbds;
//template<typename T>
//using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define F first
#define S second
#define pb push_back
#define pii pair <int, int>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define reunique(x) (x).resize(std::unique(all(x)) - (x).begin())
#define roflan ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ld long double
#define int long long

vector <int> g[100500];
void dfs(int v, vector <int> &dist, int par) {
	for (auto u : g[v]) {
		if (u == par) continue;
		dist[u] = dist[v] + 1;
		dfs(u, dist, v);
	}
}
void SOLVE() {
	int n, U, V;
	cin >> n >> U >> V;
	U--, V--;
	for (int i = 0; i < n - 1; i++) {
		int v, u;
		cin >> v >> u; v--, u--;
		g[v].pb(u);
		g[u].pb(v);
	}
	vector <int> d1(n), d2(n);
	dfs(U, d1, -1);
	dfs(V, d2, -1);
	int mx = 0;
	for (int i = 0; i < n; i++) {
		if (d1[i] < d2[i]) {
			mx = max(mx, d2[i] - 1);
		}
	}
	cout << mx << '\n';
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cout << fixed;
	cout.precision(10);
	//freopen("longpath.in", "r", stdin);
	//freopen("longpath.out", "w", stdout);
	int Q = 1;
	//cin >> Q;
	while (Q--)
		SOLVE();

	return 0;
}
/*
*/

Measured memory_bytes: 12672
def main():
  n=int(input())
  A=list(map(int, input().split()))
  if 0 in A:
    print(0)
    return
  p=1
  for a in A:
    p*=a
    if p>1000000000000000000:
      print(-1)
      return
  print(p)
main()
  



Measured memory_bytes: 21652
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp110 {
    class Program {
        static void Main(string[] args) {
            var st = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long N = st[0];
            long M = st[1];

            long sum = N * 2 + M;

            if (N * 2 >= M) {
                Console.WriteLine(M / 2);
            } else {
                Console.WriteLine(sum / 4);
            }

        }
    }
}


Measured memory_bytes: 13396
#include <stdio.h>

int power(int a, int x)
{
	int b = a;
	int i;
	
	for(i=1; i<x; i++)
		a *= b;
	
	return a;
}

int max(int a, int b)
{
	if(a > b)
		return a;
	else
		return b;
}

int main(void)
{
	int a, b, c, k;
	int d;
	
	scanf("%d %d %d", &a, &b, &c);
	scanf("%d", &k);
	
	d = max( a, max(b, c) );
	
	printf("%d", d*power(2, k)+(a+b+c-d) );
	
	
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define lld long double
#define MOD 1000000007
#define CAP 100000001
#define inf 1000000000000000LL
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define sz(v) v.size()
#define all(v)    v.begin(),v.end()
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
//#define int ll
using namespace std;
ll power(ll x,ll y, ll md=MOD){ll res = 1;x%=md;while(y>0){if(y&1)res = (res*x)%md;x = (x*x)%md;y = y>>1;}return res%md;}

signed main() {
	fast;
	ll n,m;
	cin>>n>>m;
	std::vector<ll> v(n);
	for(int i=0;i<n;i++) cin>>v[i];
	std::vector<pii > q(m);
	for(int i=0;i<m;i++) cin>>q[i].s>>q[i].f;
	sort(all(v));
	reverse(all(v));
	sort(all(q));
	ll pt=n-1;
	ll f=1;
	for(int i=m-1;i>-1;i--){
		ll st=max(0LL,pt-q[i].s+1);
		for(int j=pt;j>=st;j--){
			if(v[j]>=q[i].f) {
				f=0;
				break;
			}
			v[j]=q[i].f;
		}
		pt=st-1;
		if(pt<0||!f) break;
	}
	ll s=0;
	for(int i=0;i<n;i++) s+=v[i];
	cout<<s;
}

Measured memory_bytes: 2560
#include<iostream>

using namespace std;

int main(){

    int n, a, b;
    cin >> n >> a >> b;

    int ans = 0;
    for(int i=1;i<=n;i++){
        int tmp = i;
        int sum = 0;
        while(tmp!=0){
            sum += tmp%10;
            tmp /= 10;
        }
        if(a<=sum && sum<=b)ans += i;
    }
    cout << ans << endl;
}


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

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

typedef long long ll;

int main()
{
	vector<string> s;
	vector<pair<int,int> > v;

	rep(i,9)
	{
		string temp;
		int a,b;
		cin >> temp >> a >> b;

		s.push_back(temp);
		v.push_back(make_pair(a,b));
	}

	rep(i,9)
	{
		cout << s[i] << " " << v[i].first + v[i].second << " " << v[i].first*200 + v[i].second*300 << endl;
	}

	
	return 0;
}

Measured memory_bytes: 1216
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))
s = input()

for i in range(0, len(s), 2):
    if s[i] == 'L':
        print('No')
        sys.exit()
for i in range(1, len(s), 2):
    if s[i] == 'R':
        print('No')
        sys.exit()
print('Yes')

Measured memory_bytes: 5076
# coding: utf-8
# Your code here!
h,w=map(int,input().split())

maze=[]
m=[]
wn=0
INF = 10**5

for i in range(h):
    row=list(input())
    maze.append(row)
    m.append([INF for i in range(w)])
    for j in range(w):
        if row[j]==".":
            wn+=1


m[0][0]=0
dx=[1,0,-1,0]
dy=[0,1,0,-1]

queue=[]
queue.append([0,0])
maze[0][0]="#"

while len(queue)>0:

    y,x=queue.pop(0)
    for i in range(4):
        ny=y+dy[i]
        nx=x+dx[i]
        if 0<=ny<h and 0<=nx<w:
            if maze[ny][nx]==".":
                queue.append([ny,nx])
                maze[ny][nx]="#"
                m[ny][nx]=min(m[ny][nx],m[y][x]+1)


if m[-1][-1]==INF:
    print(-1)
else:
    print(wn-2-(m[-1][-1]-1))

    


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

int C[5];

int main()
{
    for (int i = 0; i < 3; i++)
    {
        int a, b;
        cin >> a >> b;
        C[a]++;
        C[b]++;
    }
    for (int i = 1; i <= 4; i++) if (C[i] != 1 && C[i] != 2)
    {
        cout << "NO\n";
        return(0);
    }
    cout << "YES\n";
    return(0);
}

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

using namespace std;
#define inf             0x3f3f3f3f
#define INF             2e18
#define eps             1e-9

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0)
#define fRead           freopen("input.txt","r",stdin)
#define fWrite          freopen("output.txt","w",stdout)

#define LL              long long
#define ull            unsigned long long
#define PI              acos(-1.0)
#define pb              push_back
#define mk              make_pair
#define pii             pair<int,int>
#define pLL             pair<LL,LL>
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define SQR(a)          ((a)*(a))
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define vi              vector <int>
#define vL              vector <LL>
#define LB(a,x)         (lower_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which does not compare less than val.
#define UB(a,x)         (upper_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which compares greater than val.
#define prec(n)         fixed << setprecision(n)

#define MEM(a,x)        memset(a,x,sizeof(a))
#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())

#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define IT(it,x)	    for(it=x.begin();it!=x.end();it++)
int main()
{
    LL n,d;
    cin>>n>>d;
    LL cnt=0;
    for(LL i=0; i<n; i++)
    {
        LL x,y;
        cin>>x>>y;
        if(x*x+y*y<=d*d)cnt++;
    }
    cout<<cnt;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    char a;
    cin >> a;
    if(a == 'a' || a == 'i' || a == 'u' || a == 'e' || a == 'o'){
    cout << "vowel" << endl;
    }
    else{
    cout << "consonant" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
a[101],i;main(f,t,j){for(;~scanf("%d%d",&f,&t);){f&&a[f]++,a[t]++;if(!f){j=a[1]&1&&a[2]&1;for(i=2;i++<100;)if(a[i]&1)j=0;puts(j?"OK":"NG");bzero(a,101);}}}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define DEBUG2(x, y) cerr << #x << ": " << x << " " << #y << ": " << y << "\n"
#define DEBUG3(x, y, z) cerr << #x << ": " << x << " " << #y << ": " << y << " " << #z << ": " << z << "\n"
#define PRINTALL(V)    \
  for (auto v : (V)) { \
    cerr << v << " ";  \
  }                    \
  cerr << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
#define pint pair<int, int>
#define ld long double
using namespace std;
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 (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> using vec = std::vector<T>;
template <class T> void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567, INF2 = INF * INF;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int N, M;
  cin >> N >> M;
  vec<bool> flg(N, false);
  vec<int> ball(N, 1);
  flg[0] = true;

  REP(i, M) {
    int p, q;
    cin >> p >> q;
    p--, q--;

    if (flg[p] && !flg[q]) {
      flg[q] = true;
    }
    ball[p]--;
    ball[q]++;
    if (ball[p] == 0) {
      flg[p] = false;
    }
  }
  print(count(ALL(flg), true));
}

Measured memory_bytes: 1024
s = input()
a = int(s[0:2])
b = int(s[2:4])
if 1 <= a <= 12 and 1 <= b <= 12:
  print('AMBIGUOUS')
elif 1 <= a <= 12 and not 1 <= b <= 12:
  print('MMYY')
elif not 1 <= a <= 12 and 1 <= b <= 12:
  print('YYMM')
else:
  print('NA')

Measured memory_bytes: 3060