akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define INF 1LL<<60
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,int> PP;

ll labs(ll v){
	if(v<0LL)return -v;
	return v;
}

int n;
ll dp[4001][4001];
vector<ll> d1;
vector<P> vec;

void solve(){
	d1.clear();
	vec.clear();
	ll sum=2;
	for(int i=0;i<n;i++){
		int p,d;
		scanf("%d%d",&p,&d);
		sum+=d-2;
		if(d==1){
			d1.push_back(p);
		}else{
			vec.push_back(P(p,d));
		}
	}
	sort(d1.begin(),d1.end());
	sort(vec.begin(),vec.end());
	if(sum<0){
		printf("-1\n");
		return;
	}
	if(vec.size()==0){
		printf("%lld\n",d1[1]-d1[0]);
		return;
	}
	for(int i=0;i<=d1.size();i++){
		dp[0][i]=INF;
	}
	dp[0][0]=0;
	for(int i=0;i<vec.size();i++){
		//cout << vec[i].first << " "<< vec[i].second << endl;
		int rest=vec[i].second-2;
		if(i==0){
			rest++;
		}
		if(i+1==vec.size()){
			rest++;
		}
		for(int j=0;j<=d1.size();j++){
			dp[i+1][j]=dp[i][j];
		}
		deque<PP> deq;
		ll lazysum=0;
		for(int j=0;j<d1.size();j++){
			if(rest==0)break;
			while(deq.size()>0 && deq[0].second<j+1-rest){
				deq.pop_front();
			}
			while(deq.size()>0 && deq.back().first.first+lazysum-deq.back().first.second>=dp[i][j]){
				deq.pop_back();
			}
			deq.push_back(PP(P(dp[i][j],lazysum),j));
			lazysum+=labs(d1[j]-vec[i].first);
			dp[i+1][j+1]=min(dp[i+1][j+1],deq[0].first.first+lazysum-deq[0].first.second);
		}
	}
	/*
	for(int i=0;i<=vec.size();i++){
		for(int j=0;j<=d1.size();j++){
			printf("%lld ",dp[i][j]);
		}
		printf("\n");
	}
	*/
	printf("%lld\n",dp[vec.size()][d1.size()]+vec[vec.size()-1].first-vec[0].first);
}

int main(void){
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		solve();
	}
	return 0;
}


Measured memory_bytes: 73800
#include <bits/stdc++.h>
using namespace std;
const int MAXN=200010;
int n,cnt,ans,d[11],vis[11][11];
void split (int x) {
	cnt=0;
	while (x) {
		d[++cnt]=x%10;
		x/=10;
	}
}
int main () {
	scanf("%d",&n);
	for (int i=1;i<=n;i++) {
		split(i);
		vis[d[cnt]][d[1]]++;
		ans+=vis[d[1]][d[cnt]];
	}
	memset(vis,0,sizeof(vis));
	for (int i=n;i>=1;i--) {
		split(i);
		ans+=vis[d[1]][d[cnt]];
		vis[d[cnt]][d[1]]++;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
typedef long long ll;
int N;
vector<vector<int>> G;
vector<ll> fact, invfact;
vector<map<int, pair<int, ll>>> memo;
ll modpow(ll x, int y) {
	ll r = 1;
	while (y > 0) {
		if (y&1) (r *= x) %= mod;
		(x *= x) %= mod;
		y >>= 1;
	}
	return r;
}
pair<int, ll> f(int p, int q) {
	if (memo[p].count(q)) return memo[p][q];
	int res1 = 1;
	ll res2 = 1;
	if (memo[p].count(N)) {
		res1 = memo[p][N].first;
		res2 = memo[p][N].second;
		(res2 *= invfact[res1-1]) %= mod;
		auto pp = f(q, p);
		res1 -= pp.first;
		(res2 *= modpow(pp.second, mod-2)) %= mod;
		(res2 *= fact[pp.first]) %= mod;
		(res2 *= fact[res1-1]) %= mod;
	} else {
		for (const auto& x : G[p]) if (x != q) {
			auto pp = f(x, p);
			res1 += pp.first;
			(res2 *= pp.second) %= mod;
			(res2 *= invfact[pp.first]) %= mod;
		}
		(res2 *= fact[res1-1]) %= mod;
	}
	//cerr << p << " " << q << " " << res1 << " " << res2 << endl;
	return memo[p][q] = {res1, res2};
}
int main() {
	cin >> N;
	G.resize(N);
	fact.resize(N+1);
	invfact.resize(N+1);
	fact[0] = invfact[0] = 1;
	for (int i = 1; i <= N; ++ i) {
		fact[i] = fact[i-1] * i % mod;
		invfact[i] = modpow(fact[i], mod-2);
	}
	for (int i = 0; i < N-1; ++ i) {
		int a, b;
		cin >> a >> b;
		-- a; -- b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	memo.resize(N);

	vector<pair<int,int>> hoge;
	for (int i = 0; i < N; ++ i) hoge.push_back({(int)G[i].size(), i});
	sort(hoge.rbegin(), hoge.rend());

	vector<int> res(N);
	for (auto pp : hoge) {
		int i = pp.second;
		res[i] = f(i, N).second;
	}
	for (int i = 0; i < N; ++ i) {
		cout << res[i] << endl;
	}
}


Measured memory_bytes: 66544
import java.util.*;
import java.beans.IntrospectionException;
import java.io.*;
 
public class Main {
	public static long GCD(long a, long b) {
		if(b==0)return a;
		if(a==0)return b;
		return (a>b)?GCD(a%b, b):GCD(a, b%a);
	}
	public static long LCM(long a, long b) {
		return a*b/GCD(a, b);
	}
	public static long nCk(int n, int k) { //O(K)
		if (k > n) {
			return 0;		
		}
		long res = 1;
		for(int i = 1; i<=k; i++) {
			res = (n - k + i) * res/i;
		}
		return res;
	}
	public static long C(int a, int b, long[][] s) {
		int m = (int) 1e9 + 7;
		if (s[a][b] >= 0) {
			return s[a][b];
		} else if (a < b | a < 0 | b < 0) {
			s[a][b] = 0;
			return 0;
		} else if (a == b | b == 0) {
			s[a][b] = 1;
			return 1;
		} else {
			return s[a][b] = (C(a - 1, b, s) % m + C(a - 1, b - 1, s) % m) % m;
		}
 
	}
 
	public static void main(String[] args) throws Exception {
 
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		int n=sc.nextInt();
		int k=sc.nextInt();
		Integer[] s=new Integer[n];
		boolean t=true;
		for(int i=0;i<n;i++) {
			s[i]=sc.nextInt()+1;
		}
		int sum=0;
		for (int i=0;i<k;i++) {
			sum+=s[i];
		}
		double m=sum;
		for(int i=k;i<n;i++) {
			
			sum=sum-s[i-k]+s[i];
			m=Math.max(m, sum);
		}
		System.out.printf("%.12f",m/2);
		pw.close();
		
		
	}
 
	static class Scanner {
		StringTokenizer st;
		BufferedReader br;
			
		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}
 
		public Scanner(FileReader r) {
			br = new BufferedReader(r);
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
	}
	static class pair implements Comparable<pair>  {
		int x;
		int y;
		public pair(int x,int y) {
			this.x=x;
			this.y=y;
		}
		public String toString(){
			return x+" "+y;
		}
		public int compareTo(pair other) {
			if(this.x==other.x) {
				return this.y-other.y;
			}
			else {
				return this.x-other.x;
			}
		}
	}
 
}


Measured memory_bytes: 46096
#include <stdio.h>
int main ()
{
    int n,a,sum=0 ;
    scanf ("%d",&n);
    int s=n;
    //a=n%10;
    while (n>0)
    {
        a=n%10;
        sum=sum+a;
        n=n/10;
    }
    //printf ("%d",n);
    if (s%sum==0) printf ("Yes\n");
    else printf ("No\n");
    return 0;
}


Measured memory_bytes: 128
# -*- coding: utf-8 -*-
import numpy as np
import sys


def main():
    N = int(input())
    A = np.array(input().split(), dtype='int64')
    B = np.array(input().split(), dtype='int64')
    C = np.array(input().split(), dtype='int64')

    satisfy=0
    current_i = -1
    for i in range(N):
        if current_i+1 == A[i]:
            satisfy += C[current_i-1]
        current_i = A[i]
        satisfy += B[A[i]-1]

    print(satisfy)








if __name__ =='__main__':
    main()

Measured memory_bytes: 21764
import math
from collections import Counter


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    N = read_int()
    A = []
    pair_count = Counter()
    for _ in range(N):
        line = input().strip()
        if '.' in line:
            a, b = line.split('.')
            d = 10**len(b)
            c = int(a)*d+int(b)
        else:
            c = int(line)
            d = 1
        gcd = math.gcd(c, d)
        c //= gcd
        d //= gcd
        pow2, pow5 = 0, 0
        while c and c%2 == 0:
            pow2 += 1
            c //= 2
        while c and c%5 == 0:
            pow5 += 1
            c //= 5
        while d and d%2 == 0:
            pow2 -= 1
            d //= 2
        while d and d%5 == 0:
            pow5 -= 1
            d //= 5
        pair_count[(pow2, pow5)] += 1
    answer = 0
    for pair0 in pair_count:
        for pair1 in pair_count:
            if pair0 < pair1 and pair0[0]+pair1[0] >= 0 and pair0[1]+pair1[1] >= 0:
                answer += pair_count[pair0]*pair_count[pair1]
            elif pair0 == pair1 and pair0[0] >= 0 and pair0[1] >= 0:
                answer += pair_count[pair0]*(pair_count[pair0]-1)//2
    return answer


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 78180
#include <iostream>

using namespace std;

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

    if (a < b) {
        if ((a + w) > b) ans = 0;
        else ans = b - (a + w);
    } else if (a > b) {
        if ((b + w) > a) ans = 0;
        else ans = a - (b + w);
    } else {
        ans = 0;
    }

    cout << ans << endl;

    return 0;
}


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

// #include <iostream>
// #include <fstream>
// #include <string>
// #include <map>
// #include <vector>
// #include <algorithm>
// #include <regex>
// #include <chrono>
// #include <sstream>
// #include <iomanip>
// #include <queue>
// #include <stack>
// #include <set>
// #include <unordered_map>
// #include <unordered_set>


using namespace std;
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
//#define int long long
struct IoSetup {
    IoSetup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
}IoSetup;

typedef long long ll;
typedef pair < int , int >  pii;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 998244353;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>bool chmax(T &a, const T&b){if(a<b)return(a=b,1);return 0;}
template<class T>bool chmin(T &a, const T&b){if(b<a)return(a=b,1);return 0;}



signed main() {

	ll n;

	cin >> n;
	ll ans = 0;
	ll v = 1;
	while(n) {
		ans += v;
		if(n != 1) 
			v*=2;

		n/= 2;
	}

	cout << ans << endl;
		
    return 0;
}



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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> void chmax(t&a,u b){if(a<b)a=b;};
template<class t, class u> void chmin(t&a,u b){if(a>b)a=b;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

ll gcd(ll x, ll y){
  if(y==0) return x;
  return gcd(y, x-(x/y)*y);
}

ll search(ll X, ll C, ll D){
  ll t1 = X/C;
  ll t2 = X/D;
  ll t3 = X/(C*D/gcd(C,D));
  //debug_print(t1, t2, t3);
  return X-(t1+t2-t3);
}

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll A, B, C, D;
  IN(A,B,C,D);

  OUT(search(B,C,D)-search(A-1,C,D));

  return 0;
}

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

using namespace std;

int ans, n, t, a[200001];

int main(){
	cin >> n >> t;
	for(int i = 0; i < n; ++i) cin >> a[i];
	a[n] = a[n-1] + t;
	for(int i = 0; i < n; ++i) ans += min(t, abs(a[i]-a[i+1]));
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
#include <stack>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)
int main(void)
{
    int N;
    cin >> N;
    lli a[N];
    lli b[N + 1];
    for (int i = 0; i < N; i++)
    {
        cin >> a[i];
    }
    fill(b, b + N + 1, 0);
    for (int i = 1; i <= N; i++)
    {
        b[i] = b[i - 1] + a[i - 1];
    }
    lli cnt = 0;
    sort(b, b + N + 1);
    map<lli, lli> x;
    for (int i = 0; i <= N; i++)
    {
        x[b[i]]++;
    }
    //for (map<lli, lli>::iterator y = x.begin(); y != x.end(); ++y)
    for (auto it : x)
    {
        cnt += it.second * (it.second - 1) / 2;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 19148
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main{

	public static void main(String[] args) throws IOException{
		// TODO ?????????????????????????????????????????????

		BufferedReader insBR = new BufferedReader(new InputStreamReader(System.in));

		//????????????????????????
		String strLine = insBR.readLine();
		//String Buffer????????£??\
		StringBuffer insBuffer = new StringBuffer(strLine);

		//???????????°?????????
		String strNum = insBR.readLine();
		int q = Integer.parseInt(strNum);

		for(int i = 0; i < q; i++){
			//???????????????????????????????????§?????????????´?
			String[] ary = insBR.readLine().split(" ");
			//a b ???int??????
			int a = Integer.parseInt(ary[1]);
			int b = Integer.parseInt(ary[2]);
			//??????????????????????????????
			String strCutLine = strLine.substring(a,b + 1);

			//????????¬???????????´???
			if(ary.length == 4){

				//replece??????????????§?????????????????????
				insBuffer = insBuffer.replace(a, b+1 , ary[3]);
				//String????????£??\
				strLine = insBuffer.toString();
			}else if("reverse".equals(ary[0])){

				//reverse??????????????§??????????????????????????¢
				StringBuffer insCutBuffer = new StringBuffer(strCutLine);
				String strReverse = insCutBuffer.reverse().toString();
				//replece??????????????§?????????????????????
				insBuffer = insBuffer.replace(a, b+1 , strReverse);
				strLine = insBuffer.toString();
			}else {

				System.out.println(strCutLine);
			}



		}
		//System.out.println("strLine:" + strLine);

	}
}

Measured memory_bytes: 21372
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <cctype>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr ll INF = 3000000000000000000;

int main() {
    ll X;
    cin >> X;
    
    ll N = 0;
    for (ll i = 1; i < INF; ++i) {
        N += i;
        if (N >= X) {
            cout << i << "\n";
            break;
        }
    }
    return 0;
}


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

ll a[11];
ll p[11];
ll c[11];
int d,g;
int smt(ll n,ll ad,bool f,int k,ll m){
    if(n<0){
        rep(i,d){
            if(!(k&(1<<(d-1-i)))){
                for(int j=p[d-1-i];ad>0&&j>0;j--){
                    ad -= (d-i)*100;
                    m++;
                }
            }
        }
        return m;
    }
    if(f==true){
        int s1=smt(n-1,ad-a[n],false,k|=(1<<n),m+p[n]);
        int s2=smt(n-1,ad-a[n],true,k|=(1<<n),m+p[n]);
        return min(s1,s2);
    }else{
        int s1=smt(n-1,ad,false,k,m);
        int s2=smt(n-1,ad,true,k,m);
        return min(s1,s2);
    }
}

int main(){
    cin>>d>>g;
    rep(i,d){
        cin>>p[i]>>c[i];
        a[i]=p[i]*100*(i+1)+c[i];
    }
    int s1=smt(d-1,g,true,0,0);
    int s2 =smt(d-1,g,false,0,0);
    int ans=min(s1,s2);
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
using namespace std;
typedef int64_t ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
const int INF = 1001001001;
const ll LINF = 1e18;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second

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

bool p_comp_fs(const P p1, const P p2){ return p1.first < p2.first;};
bool p_comp_fg(const P p1, const P p2){ return p1.first > p2.first;};
bool p_comp_ss(const P p1, const P p2){ return p1.second < p2.second;};
bool p_comp_sg(const P p1, const P p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}


int main(){
    ll N, M; cin >> N >> M; vl xs(N, 0), ys(N, 0), zs(N, 0);
    REP(i, N) cin >> xs[i] >> ys[i] >> zs[i];
    ll ret = 0;
    REP(i, 8){
        vl vals(N, 0);
        ll sx = (i >> 0 & 1) ? 1 : -1;
        ll sy = (i >> 1 & 1) ? 1 : -1;
        ll sz = (i >> 2 & 1) ? 1 : -1;
        REP(i, N) vals[i] = sx * xs[i] + sy * ys[i] + sz * zs[i];
        sort(vals.begin(), vals.end(), greater<ll>());
        ll tmp = 0;
        REP(i, M) tmp += vals[M-i-1];
        ret = max(ret, tmp);
    }
    cout << ret << endstr;
    return 0;
}


Measured memory_bytes: 256
n, k  = map(int, input().split())
hlst = list(map(int, input().split()))
INF = 10 ** 20
dp = [INF] * n
dp[0] = 0
for i in range(n):
  for j in range(i + 1, min(i + k + 1, n)):
    dp[j] = min(dp[j], dp[i] + abs(hlst[i] - hlst[j]))
print(dp[n - 1])

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;

Node root, NIL;
int maxh;

Node Search(Node x, int k) {
  while(x != NIL && k != x->key) {
    if(k < x->key)
      x = x->left;
    else x = x->right;
  }
  return x;
}

int main() {
  int n,i,x;
  char com[20];

  scanf("%d",&n);
  maxh = 0;
  for(i = 0 ; i < n ; i++) {
    scanf("%s",com);
    if('f' == com[0]) {
      scanf("%d",&x);
      Node t = Search(root, x);
      if(t != NIL)
	printf("yes\n");
      else printf("no\n");
    }
    else if (strcmp(com,"insert") == 0) {
      scanf("%d", &x);
      insert(x);
    }
    else if(strcmp(com,"print") == 0) {
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}

int insert(int k){
  int H;
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL) {
    y = x;
    if (z->key < x->key) {
      x = x->left;
    }
    else {
      x = x->right;
    }
  }
  z->parent = y;
  if (y == NIL) {
    root = z;
  }
  else {
    if(z->key < y->key) {
      y->left = z;
    }
    else {
      y->right = z;
    }
  }
}

int inorder(Node x) {
  if (x == NIL) return 0;
  inorder(x->left);
  printf(" %d",x->key);
  inorder(x->right);
}

int preorder(Node x) {
  if (x == NIL) return 0;
  printf(" %d",x->key);
  preorder(x->left);
  preorder(x->right);
}




Measured memory_bytes: 20496
#include <bits/stdc++.h>
#define rep(i,n) for ((i)=1;(i)<=(n);(i)++)
#define per(i,n) for ((i)=n;(i)>=(1);(i)--)
using namespace std;

const int mod=1e9+7;
int n,m,dp[3005][3005][2];
int i,j,k,ans;
void inc(int &x,int y){
	x=(x+y>=mod)?x+y-mod:x+y;
}
int main(){
	cin>>n>>m;
	rep(i,n) dp[0][i][0]=1;
	dp[0][0][1]=1;
	rep(i,m){
		for(j=0;j<=n;j++){
			for(k=0;k<2;k++){
				if(!dp[i-1][j][k]) continue;
				if(j){
					inc(dp[i][j-1][k||(j==1)],dp[i-1][j][k]);
				}
				if(j){
					inc(dp[i][j][k||(j==1)],dp[i-1][j][k]);
				}
				if(j<n){
					inc(dp[i][j][k],dp[i-1][j][k]);
				}
				if(j<n){
					inc(dp[i][j+1][k],dp[i-1][j][k]);
				}
			}
		}
	}
	for(i=0;i<=n;i++){
		inc(ans,dp[m][i][1]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 70656
#include <cstdio>

#define MAXN 500

char m[MAXN][MAXN];

int main() {
    int nrlin, nrcol;
    scanf("%d%d ", &nrlin, &nrcol);

    for (int i = 0; i < nrlin; i++) {
        for (int j = 0; j < nrcol; j++)
            m[i][j] = fgetc(stdin);
        fgetc(stdin);
    }

    for (int i = 0; i < nrlin; i++) {
        for (int j = 0; j < nrcol; j++)
            if (j != nrcol - 1 && (m[i][j] == '#' || j == 0 || i % 2 == 0))
                fputc('#', stdout);
            else fputc('.', stdout);
        fputc('\n', stdout);
    }

    fputc('\n', stdout);

    for (int i = 0; i < nrlin; i++) {
        for (int j = 0; j < nrcol; j++)
            if (j != 0 && (m[i][j] == '#' || j == nrcol - 1 || i % 2 == 1))
                fputc('#', stdout);
            else fputc('.', stdout);
        fputc('\n', stdout);
    }

    return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

void dfs(int v, vector<vector<int>>& to, vector<bool>& f) {
  if(f[v]) return;
  f[v] = true;
  for (auto u : to[v]) {
    dfs(u,to,f);
  }
}

int main() {
  int n,m,p;
  int ans = -1;
  cin >> n >> m >> p;
  vector<vector<int>> to(n+1);
  vector<vector<int>> ot(n+1);
  vector< tuple<int,int,int> > edges;

  for (int i=0; i<m; i++) {
    int a,b,c;
    cin >> a >> b >> c;
    c = -1 * (c-p);
    to[a].push_back(b);
    ot[b].push_back(a);
    edges.emplace_back(a,b,c);
  }

  // 1 からたどり着けないやつと Nにたどり着けないやつは考慮する必要が無い
  vector<bool> from1Flag(n+1,false);
  vector<bool> toNFlag(n+1,false);
  dfs(1,to,from1Flag);
  dfs(n,ot,toNFlag);

  vector<bool> ok(n+1,false);

  for (int i=1; i<=n; i++)
    ok[i] = from1Flag[i] && toNFlag[i];

  // Bellman-Ford アルゴリズム
  vector<long> d(n+1,INT_MAX);
  d[1] = 0;
  bool updated = true;
  int step = 0;

  while(updated) {
    updated = false;
    step++;
    if(step >= n+1) break;

    for(int i=0; i<m; i++) {
      int a,b,c;
      tie(a,b,c) = edges[i];
      if (!ok[a]) continue;
      if (!ok[b]) continue;

      if (d[a]+c < d[b]) {
        updated = true;
        d[b] = d[a]+c;
      }
    }
  }

  if(step <= n) ans = max(0, (int)(-1*d[n]));
  cout << ans << endl;
}


Measured memory_bytes: 888
#include<iostream>
using namespace std;
int main (){
	int W,V,y=0,z=0;
	for(;;){

		cin>>V>>W;
		if(W==0&&V==0){
			break;
		}
		if(z==0){
			z=1;
		}else{
			cout<<endl;
		}

		for(int z = 0; z < V; z++ ){

			if((z%2)==0){
				y=0;
			}else{
				y=1;
				W++;
			}

			for( ; y < W; y++ ){
				if((y%2)==0){
					cout<<"#";
				}else{
					cout<<".";
				}
			}

			if((z%2)==1)W--;
			cout<<endl;

		}

	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 3088
#include <iostream>
#include <cmath>

using namespace std;

int main() {
  double x1, y1, x2, y2, x3, y3, xp, yp;
  while (cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp) {
    double det[3];
    for (int i = 0; i < 3; i++) {
      double x0, y0;
      double xa, ya;
      double xb = xp, yb = yp;
      if (i == 0) { x0 = x1; y0 = y1; xa = x2; ya = y2; }
      else if (i == 1) { x0 = x2; y0 = y2; xa = x3; ya = y3; }
      else if (i == 2) { x0 = x3; y0 = y3; xa = x1; ya = y1; }
      xa -= x0; ya -= y0; xb -= x0; yb -= y0;
      det[i] = xa * yb - xb * ya;
    }
    if ((det[0] > 0 && det[1] > 0 && det[2] > 0) || 
        (det[0] < 0 && det[1] < 0 && det[2] < 0)) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  return 0;
}
        

      
        

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define reg register
#define maxn 5005
#define mod 1000000007
using namespace std;
inline int  read() {
    reg int s = 0, t = 0; reg char ch = getchar();
    while(ch > '9' || ch < '0') t |= ch == '-', ch = getchar();
    while(ch >= '0' && ch <= '9') s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
    return t ? -s : s;
}
int n, f[maxn], dp[maxn][maxn], siz[maxn];
int nt[maxn << 1], go[maxn << 1], fi[maxn], cnt;
void add(int u, int v){
	nt[++cnt] = fi[u]; fi[u] = cnt; go[cnt] = v;
}
void dfs(int u, int fa) {
	siz[u] = 1; dp[u][1] = 1;
	for (int i = fi[u]; i; i = nt[i]){
			int v = go[i]; if(v == fa) continue;
			dfs(v, u);
			for (int i = siz[u]; i; --i) {
				int sum = 0;
				for (int j = 1; j <= siz[v]; ++j) {
					dp[u][i + j] = (dp[u][i + j] + 1ll * dp[u][i] * dp[v][j] % mod) % mod;
					sum = (sum - 1ll * dp[v][j] * f[j] % mod + mod) % mod;
				}
				dp[u][i] = 1ll * sum * dp[u][i] % mod;
			}
			siz[u] += siz[v];
	}
}
 
int main() {
	n = read(); f[0] = 1;
	for (int i = 2; i <= n; ++i)
		f[i] = 1ll * (i - 1) * f[i - 2] % mod;
	for (int i = 1, u, v; i < n; ++i) {
		int x = read(), y = read(); 
		add(x, y); add(y, x);
	}
	dfs(1, 0);
	int sum = 0;
	for (int i = 1; i <= n; ++i) sum = (sum + 1ll * dp[1][i] * f[i] % mod) % mod;
	printf("%d\n", (sum + mod) % mod);
	return 0;
}

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

using namespace std;

typedef long long ll;

int main() {
    int n, c, k;
    cin >> n >> c >> k;
    vector<int> t(n);
    for (int i = 0; i < n; ++i) {
        cin >> t[i];
    }

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

    int cnt = 0, num = 0, cur = 0;
    for (int i = 0; i < n; ++i) {
        ++cnt;
        num = 1;
        cur = t[i++];
        while(i < n && num < c && t[i] <= cur + k){
            ++num;
            ++i;
        }
        --i;
    }

    cout << cnt << endl;
}

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

class Program
{
    static void Main(string[] args)
    {
        long N = long.Parse(Console.ReadLine());
        var input = Console.ReadLine().Split();
        long before = long.Parse(input[0]);
        bool flag = true;
        for(long i=0; i < N; i++)
        {
            long H = long.Parse(input[i]);
            if (H > before) { H = H - 1; }
            if (H < before) { flag = false; }
            before = H;
        }
        if (flag == true) { Console.WriteLine("Yes"); }
        else { Console.WriteLine("No"); }
    }
}


Measured memory_bytes: 26716
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

func main() {
	r := bufio.NewReaderSize(os.Stdin, 100000)

	s, _, _ := r.ReadLine()

	str := string(s)

	ans := "YES"
	for i := 0; i < len(str); {
		if strings.HasPrefix(str[i:], "dreamerase") {
			i += 5
		} else if strings.HasPrefix(str[i:], "dreamer") {
			i += 7
		} else if strings.HasPrefix(str[i:], "eraser") {
			i += 6
		} else if strings.HasPrefix(str[i:], "dream") {
			i += 5
		} else if strings.HasPrefix(str[i:], "erase") {
			i += 5
		} else {
			ans = "NO"
			break
		}
	}
	out(ans)
}


Measured memory_bytes: 768
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")
#include <bits/stdc++.h>

using namespace std;

#define PB push_back
#define MP make_pair
#define EB emplace_back
#define f first
#define s second
#define FOR(i,a,b) for (int i = a; i < (b); ++i)
#define RFOR(i, b, a) for (int i = b-1; i>=a; --i)
#define FILL(a, b) memset(a, b, sizeof a)
#define ALL(a) a.begin(), a.end()
#define SZ(a) ((int)a.size())
#define bitc(n) __builtin_popcount(n)
#define MAGIC0 mt19937 rnd(time(0)); //rnd()

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = 1LL * INF*INF;
const int MAX = 1e6 + 7;
const double PI = acos(-1.);
const double EPS = 1e-7;
const int MAXN = 100005;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

unordered_map<int, int> mep(200007);

int main()
{
	ios_base::sync_with_stdio(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	time_t st = clock();
	int n;
	cin >> n;
	VI a(n);
	FOR(i, 0, n)
	{
		cin >> a[i];
		mep[a[i]]++;
	}
	
	deque<int> res;
	int ind = rnd() % n;
	res.PB(a[ind]);
	mep[a[ind]]--;
	FOR(i, 0, n)
	{
		if (mep[a[i]] == 0 || !mep.count(a[i] ^ a[ind]) || mep[a[i] ^ a[ind]] == 0)
		{
			continue;
		}
		res.PB(a[i]);
		mep[a[i]]--;
		int it = 0;
		while(true)
		{
			if (((double)clock() - st) / CLOCKS_PER_SEC >= 1.9)
			{
				cout << "No\n";
				return 0;
			}
			++it;
			if (it % 2 == 0)
			{
				int sz = SZ(res);
				int el = res[sz-1] ^ res[sz-2];
				if (mep.count(el) && mep[el] > 0)
				{
					res.PB(el);
					mep[el]--;
				}
				else
				{
					break;
				}
			}
			else
			{
				int el = res[0] ^ res[1];
				if (mep.count(el) && mep[el] > 0)
				{
					res.push_front(el);
					mep[el]--;
				}
				else
				{
					break;
				}
			}
		}
		if (SZ(res) == n)
		{
			cout << "Yes\n";
			return 0;
		}
		while(SZ(res) > 1)
		{
			mep[res.back()]++;
			res.pop_back();
		}
	}
	
	cout << "No\n";
	
	return 0;
}









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

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

const int INF = 1e9 + 7;

using namespace std;

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

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

  if (a & 1 && b & 1)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX 16
#define INF 1e9
 
typedef pair<int,int> pii;
typedef pair<pii,int> piii;
 
int N,S,G;
int dp[1<<MAX][MAX];
char panels[MAX];
 
void solve(int s){
    priority_queue<piii,vector<piii>,greater<piii> > Q;
    Q.push(piii(pii(0,s),S));
   
    while(!Q.empty()){
	piii p = Q.top(); Q.pop();
	int cost = p.first.first, v = p.first.second;
	int bit = p.second;
 
	if(dp[bit][v] < cost) continue;
	for(int i = 0 ; i < N ; i++){
	    if(i == v) continue;
	    if(((bit >> v) & 1) == ((bit >> i) & 1)) continue;   
	    int c = abs(i-v), nS = bit;
	    if((nS >> v) & 1){
		nS -= (1<<v);
	    }else{
		nS |= (1<<v);
	    }
	    if((nS >> i) & 1){
		nS -= (1<<i);
	    }else{
		nS |= (1<<i);
	    }
	    if(dp[bit][v] + c < dp[nS][i]){
		dp[nS][i] = dp[bit][v] + c;
		Q.push(piii(pii(dp[nS][i],i),nS));
	    }
	}
	for(int i = 0 ; i < N ; i++){
	    if(i == v) continue;
	    int c = abs(i-v);
	    if(dp[bit][v] + c < dp[bit][i]){
		dp[bit][i] = dp[bit][v] + c;
		Q.push(piii(pii(dp[bit][i],i),bit));
	    }
	}
    }
}
 
int main(){
    string in;
    while(cin >> N && N){
	S = G = 0;
	for(int i = 0 ; i < (1<<MAX) ; i++){
	    for(int j = 0 ; j < MAX ; j++){
		dp[i][j] = INF;
	    }
	}
	for(int i = 0 ; i < 2 ; i++){
	    cin >> in;
	    for(int j = 0 ; j < N ; j++){
		if(i == 0){
		    panels[j] = in[j];
		    if(panels[j] == 'W'){
			S |= (1<<j);
		    }
		}else{
		    if(in[j] == 'W'){
			G |= (1<<j);
		    }
		}
	    }
	}
    
	for(int i = 0 ; i < N ; i++){
	    dp[S][i] = 0;
	    solve(i);
	}
 
	int ans = INF;
	for(int i = 0 ; i < N ; i++){
	    ans = min(ans,dp[G][i]);
	}
	cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 9740
H, W = map(int, input().split())
mp = [list(map(int, input().split())) for _ in range(10)]

for k in range(10):
  for i in range(10):
    for j in range(10):
      mp[i][j] = min(mp[i][j], mp[i][k]+mp[k][j])
    
rlt = 0
for i in range(H):
  for j in map(int, input().split()):
    if j != -1 and j != 1:
      rlt += mp[j][1]
      
print(rlt)

Measured memory_bytes: 73280
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main{
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		while (true){
			try{
				String uketori=br.readLine();
				int sum=Integer.parseInt(uketori);
				long kazu = 0;
				if(sum>=27 && sum<=36){
					int aki=36-sum;
					kazu=((aki+3)*(aki+2)*(aki+1))/6;
				}
				else if(sum>=10 && sum<=18){
					int aki=sum;
					kazu=((aki+3)*(aki+2)*(aki+1))/6;
					int gen=0;
					for(int a=sum-9; a>=0; a--){
						gen+=(a+1)*a*2;
					}
					kazu=kazu-gen;

				}
				else if(sum>=19 && sum<=26){
					int aki=36-sum;
					kazu=((aki+3)*(aki+2)*(aki+1))/6;
					int gen=0;
					for(int a=aki-9; a>=0; a--){
						gen+=(a+1)*a*2;
					}
					kazu=kazu-gen;
				}
				else if(sum>=0 && sum<=9){
					int aki=sum;
					kazu=((aki+3)*(aki+2)*(aki+1))/6;
				}

				else{
					kazu=0;
				}
				System.out.println(kazu);
			}

			catch(Exception e){
				System.exit(0);
			}
		}
	}
}

Measured memory_bytes: 24104
import heapq
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''
N, M = map(int, input().split())
jobs = [[] for _ in range(M + 1)]

for _ in range(N):
	a, b = map(int, input().split())
	
	if a > M:
		continue
		
	jobs[a].append(b)
	
ans = 0
myheap = []

for i in range(M + 1):
	for j in jobs[i]:
		heapq.heappush(myheap, -j)
			
	if myheap:
		ans -= heapq.heappop(myheap)
		
print(ans)


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

#define int long long
#define double long double
#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 uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint=vector<int>;
using vvint=vector<vint>;
using pint=pair<int, int>;
using vpint=vector<pint>;
template<typename T> using priority_queue_rev=priority_queue<T, vector<T>, greater<T>>;
constexpr double pi = 3.1415926535897932384626433832795028L;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T1, typename T2> bool chmax(T1 &a, const T2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> bool chmin(T1 &a, const T2 &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

string S;
signed main() {
    cin >> S;
    bool f1 = (S[0] == '0' && S[1] != '0' || S[0] == '1' && (S[1] == '0' || S[1] == '1' || S[1] == '2'));
    bool f2 = (S[2] == '0' && S[3] != '0' || S[2] == '1' && (S[3] == '0' || S[3] == '1' || S[3] == '2'));
    if (f1 && f2) { cout << "AMBIGUOUS" << endl; }
    if (!f1 && f2) { cout << "YYMM" << endl; }
    if (f1 && !f2) { cout << "MMYY" << endl; }
    if (!f1 && !f2) { cout << "NA" << endl; }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  long a, b, v, w, t;
  scanf("%ld %ld %ld %ld %ld", &a, &v, &b, &w, &t);

  int ans = 0;
  if(a < b){
    if(a-b >= (w-v)*t)
      ans = 1;
  }else{
    if((w-v)*t <= b-a)
      ans = 1;
  }

  if(ans)  printf("YES\n");
  else     printf("NO\n");

  return 0;
}




Measured memory_bytes: 1664
#include<iostream>
using namespace std;
int main(){
double xa,ya,xb,yb,xc,yc,xd,yd;
while(cin>>xa){
cin>>ya>>xb>>yb>>xc>>yc>>xd>>yd;
if((yb-ya)*(yd-yc)+(xb-xa)*(xd-xc)==0)cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return 0;
}

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

int main(){
    ll n;
    cin>>n;
    vector<ll> d(n);
    for(ll i=0;i<n;++i){
        cin>>d[i];
    }
    sort(d.begin(), d.end());
    ll ans=1;
    for(ll i=0;i<n-1;++i){
        if(d[i] < d[i+1]){
            ans++;
        }
    }
    cout<<ans<<endl;
}

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

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

    if(S[S.length()-1] == '3'){
        cout << "bon" << endl;
    }else if((S[S.length()-1] == '0') || (S[S.length()-1] == '1') || (S[S.length()-1] == '6') || (S[S.length()-1] == '8')){
        cout << "pon" << endl;
    }else{
        cout << "hon" << endl;
    }


}

Measured memory_bytes: 3620
open Printf open Scanf
open Array

let i c = int_of_char c - int_of_char '0'
let () = scanf " %s" @@ fun s ->
  let p,q,r,s = i s.[0], i s.[1], i s.[2], i s.[3] in
  let pqm =
    not (p*10+q >= 13 || p=0 && q=0) in
  let pqy = true in
  let rsm =
    not (r*10+s >= 13 || r=0 && s=0) in
  let rsy = true in
  print_string @@
    if pqm && pqy && rsm && rsy then "AMBIGUOUS"
    else if pqm && rsy then "MMYY"
    else if pqy && rsm then "YYMM"
    else "NA"





Measured memory_bytes: 2432
#include<iostream>
#include<cmath>
using namespace std;
const double eps = 1.0e-9;
int main()
{
  while(true){
    long long int n,r,ans=0;
    scanf("%lld",&n);
    if( n == 0 )break;
    long long int tmp = n>>1;
    long long int rn = (long long int)ceil(sqrt(tmp));
    for(int i = 2; i <=rn; ++i){
      int _2i1 = (i-1)<<1;
      if(n%_2i1==0)tmp+=n/_2i1;
      else tmp+=n/_2i1+1;
    }
    tmp <<= 1;
    tmp -= rn*rn;
    ans = (n+tmp)<<3;
    printf("%lld\n",ans);
  }
  return 0;
}

Measured memory_bytes: 888
import sys
input = sys.stdin.readline

class DSU:
    __slots__ = ["_n", "parent_or_size"]
    def __init__(self, n):
        self._n = n
        self.parent_or_size = [-1] * n

    def merge(self, a, b):
        x, y = self.leader(a), self.leader(b)
        if x == y:
            return x
        if -self.parent_or_size[x] < -self.parent_or_size[y]:
            x, y = y, x
        self.parent_or_size[x] += self.parent_or_size[y]
        self.parent_or_size[y] = x
        return x

    def same(self, a, b):
        return self.leader(a) == self.leader(b)

    def leader(self, a):
        stack = []
        while self.parent_or_size[a] >= 0:
            stack.append(a)
            a = self.parent_or_size[a]
        for i in stack:
            self.parent_or_size[i] = a
        return a

n, q = map(int, input().split())
dsu = DSU(n)

for _ in range(q):
    t, u, v = map(int, input().split())
    if t == 0:
        dsu.merge(u, v)
    else:
        print(1 if dsu.same(u, v) else 0)


Measured memory_bytes: 75584
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<ll, ll> P;
typedef pair<ll, P> E;
#define MOD (1000000007ll)
#define l_ength size
#define hg first
#define p second.first
#define q second.second

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

vector<E> v;

bool comp(E a, E b){
	return (a.hg < b.hg);
}

int main(void){
	int n,i;
	ll cx,cy,x,y,h;
	bool flag = true;
	cin >> n;
	for(i=0; i<n; ++i){
		cin >> x >> y >> h;
		v.push_back(E(h,P(x,y)));
	}
	for(cx=0ll; cx<=100ll; ++cx){
		for(cy=0ll; cy<=100ll; ++cy){
			h=INFLL;
			for(i=0; i<n; ++i){
				h = min(v[i].hg+abs(v[i].p-cx)+abs(v[i].q-cy),h);
			}
			flag = true;
			for(i=0; i<n; ++i){
				if(max(h-abs(v[i].p-cx)-abs(v[i].q-cy),0ll)!=v[i].hg){
					flag = false;
					break;
				}
			}
			if(flag){
				cout << cx << " " << cy << " " << h << endl;
				// return 0;
			}
		}
	}
	return 0;
}


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

int main(){
  int N;cin>>N;
  vector<long> dp(N+1,0);
  for(int i=3;i<=N;i++){
    //int l=i/2;
    for(int j=3;j<=i-3;j++){
      dp.at(i)+=dp.at(i-j);
      dp.at(i)%=1000000007;
    }
    dp.at(i)++;
  }
  cout<<dp.at(N)<<endl;
}
  
  


Measured memory_bytes: 3660
import java.io.*;
import java.text.*;
import java.util.*;
 
public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		String msg = "No";
		int A = sc.nextInt();
		int  B = sc.nextInt();
		int count = 0;
		if (A > B) {
			count = A;
			A--;
		}else {
				count = B;
				B--;
		}
		if (A > B) {
			count += A;
		}else {
				count += B;
		}
//		System.out.println(msg);
		System.out.println(count);
	}
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
long M[100000];
long solve(vector<vector<long> > &G,long i)
{
	if(G[i].size()==0)
	{
		return 0;
	}
     if(M[i]!=-1)
     {
     	return M[i];
     }
	long maxi = -1;
	for(long j=0;j<G[i].size();j++)
	{

		long m1 = solve(G,G[i][j]);
		if(m1>maxi)
			maxi = m1;

	}
     M[i] = maxi+1;
	return M[i];
}
main()
{

	long n,m;
	cin>>n>>m;
	for(int i=0;i<100000;i++)
	{
		M[i] = -1;
	}
	vector<vector<long> > G(n);
	for(long i=0;i<m;i++)
	{
		long u,v;
		cin>>u>>v;
		G[u-1].push_back(v-1);
	}

	long maxi = -1;

	for(long i=0;i<n;i++)
	{
		long mt = solve(G,i);
		if(mt>maxi)
			maxi=mt;
	}


	cout<<maxi<<"\n";


}

Measured memory_bytes: 8576
//55
#include<iostream>
#include<algorithm>
#include<cstdlib>

using namespace std;

int main(){
  int N,K;
  cin>>N>>K;
  int X[50][2],Y[50][2],D[50][2];
  int px[100],py[100],pd[100];
  for(int i=0;i<N;i++){
    for(int j=0;j<2;j++){
      cin>>X[i][j]>>Y[i][j]>>D[i][j];
      px[i*2+j]=X[i][j];
      py[i*2+j]=Y[i][j];
      pd[i*2+j]=D[i][j];
    }
  }
  sort(px,px+N*2);
  sort(py,py+N*2);
  sort(pd,pd+N*2);
  static int m[100][100][100]={};
  long long v=0;
  for(int i=0;i<N;i++){
    for(int j=lower_bound(px,px+N*2,X[i][0])-px;j<lower_bound(px,px+N*2,X[i][1])-px;j++){
      for(int k=lower_bound(py,py+N*2,Y[i][0])-py;k<lower_bound(py,py+N*2,Y[i][1])-py;k++){
	for(int l=lower_bound(pd,pd+N*2,D[i][0])-pd;l<lower_bound(pd,pd+N*2,D[i][1])-pd;l++){
	  m[j][k][l]++;
	  if(m[j][k][l]==K){
	    v+=(long long)(px[j+1]-px[j])*(py[k+1]-py[k])*(pd[l+1]-pd[l]);
	  }
	}
      }
    }
  }
  cout<<v<<endl;
  return 0;
}

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

void Main()
{
	vector<int> vec(3);
	rep(i,3) cin >> vec[i];
	// unique vec
	sort(vec.begin(), vec.end());
	vec.erase(unique(vec.begin(), vec.end()), vec.end());
	cout << vec.size() << endl;
}

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


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/*nizyou(double x,double n,double mod){
	if(n==0) return 1;
	double res=nizyou(x*x%mod,n/2,mod);
	if(n&1) res=res*x%mod;
	return res;
}*/
int main(void){
	double a,b,ans=0;
	cin>>a>>b;
	for(int i=1;i<=a;i++){
		int k=i;
		double kk=1;
		//cout<<"AA"<<endl;
		while(k<b){
			k=k*2;
			kk=kk/2;
		}
		ans=ans+kk;
		//cout<<"AAA"<<endl;
	}
	cout<<std::setprecision(15)<<ans/a<<endl;
	
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>//s1.erase(n)=文字列s1の、n文字目以降削除
#include<algorithm>//辞書順=next_permutation
#include<set>
#include<string>//char 小文字のほうが32大きい
#include<sstream>
#include<string.h>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap=数値交換
#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(s,n) rep(i,n)cin>>s[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//標準=昇順
#define reve(s) reverse(s.begin(),s.end())
#define asas int ans=0
#define llcncn llint cnt=0
#define llasas llint ans=0
#define str string
#define please return
#define AC 0
#define ic_a int a;cin>>a;
#define ic_b int b;cin>>b;
#define ic_s string s;cin>>s;
#define Rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false)
#define Pi 3.1415926535897932384626
#define nine 1000000000

using namespace std;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */


int main(void) {
	Rapid_pleaseAC_fast;

	int n;
	cin >> n;
	vint h(n);
	vcin(h, n);
	int cnt = true;
	int big = h[0];
	rep(i, n-1) {
		if (big < h[i]) {
			big = h[i];
		}
		if (big <= h[i + 1]) {
			cnt++;
		}
	}
	cout << cnt << rt;

	please AC;
}

Measured memory_bytes: 256