akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <utility>

using namespace std;

typedef pair<int, int> pii;
typedef vector<pii> vp;

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

    if (k > (n - 1) * (n - 2) / 2) {
        cout << -1 << endl;
        return 0;
    }

    vp ans;
    for (int i = 2; i <= n; i++) {
        ans.push_back({1, i});
    }

    for (int i = 2; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
            if (k < (n - 1) * (n - 2) / 2) {
                k++;
                ans.push_back({i, j});
            }
        }
    }

    cout << ans.size() << endl;
    for (pii a : ans) {
        cout << a.first << " " << a.second << endl;
    }

    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define mii         map<ll int,ll int>
#define msi         map<string,ll int>
#define mis         map<ll int, string>
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define mpi         map<pair<ll int,ll int>,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define vii         vector<pair<ll int, ll int>>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
//#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;
#define M  100000000
#define MAXN   200005
 //priority_queue<int, vector<int>, greater<int> > Q;
//ll int n,a,b,m;
# define N 1000000007 
ll int countSetBits(ll int n) 
 { 
ll int count = 0; 
        while (n) { 
            n &= (n - 1); 
            count++; 
        } 
        return count; 
 } 
int main()
{ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cout.precision(6);
ll int n;
cin>>n;
ll int a[n][n];
rep(i,0,n)
rep(j,0,n)
cin>>a[i][j];
vi dp((1<<n));
ll int h=0;
while(h<n)
{
dp[(1<<h)]=a[0][h];
h++;	
}
rep(i,1,(1<<n))
{
ll int t=countSetBits(i);
if(t==1)continue;
rep(j,0,n)
{
if(((1<<j) & i) && a[t-1][j])
	dp[i]=(dp[i]+dp[i & (~(1<<j))])%N;
}	
}
cout<<dp[(1<<n)-1]%N;
}


Measured memory_bytes: 16640
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <ctime>
#include <map>
#include <stack>
#include <sstream>

using namespace std;

//같은 연속된 문자열이 존재할 때.

int findmax(map <char, int> count)
{
	int M = 0;
	for (auto it = count.begin(); it != count.end(); it++)
	{
		if (M < it->second)
		{
			M = it->second;
		}
	}

	return M;
}
bool isunbalanced(string s)
{
	int len = s.size();
	map <char, int> count;
	for (int i = 0; i < len; i++)
	{
		count[s[i]] += 1;
		if (count[s[i]] >(len / 2))
		{
			return true;
		}
	}

	return false;
}

int main(void)
{
	string s;
	map <char, int> count;


	cin >> s;
	
	for (int i = 2; i <= min((long long)s.size(),5ll); i++)
	{
		for (int j = 0; j <= s.size() - i; j++)
		{
			string sub = s.substr(j, i);
			//cout << " " << j << " " << j+i << " " << sub << endl;
			if (isunbalanced(sub) == true)
			{
				cout << j + 1 << " " <<  i+j << endl;
				return 0;
			}
		}
	}
	

	cout << "-1 -1" << endl;

	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>

int main(){
	
	char c;
	int i,j,k;
	char str[1200]={0};
	
	for(i=0; i<1200; i++){
		scanf("%c",&str[i]);
		if(str[i]=='\n'){
			break;
		}
	}
	
	for(i=0; i<1200; i++){
		if(str[i]>=0x41 && str[i]<=0x5a){
			str[i] = str[i] + 0x20;
		}else if(str[i]>=0x61 && str[i]<=0x7a){
			str[i] = str[i] - 0x20;
		}else{
			;
		}
		printf("%c",str[i]);
		if(str[i]=='\n'){
			break;
		}
	}
	
	return 0;
}




Measured memory_bytes: 2036
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>

using namespace std;

int main(){

int x;
cin >>x;
int ans=1;
int l=2;
int M=0;
if(x>=4){
    while(l<=x/2){
        while(ans*l<=x){
        ans*=l;
        }
    M=max(M,ans);
    ans=1;
    l++;
    }      
}
else{
    ans=x;
} 
M=max(M,ans);
cout <<M<<endl;

 return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int k,a,b;
    scanf("%d%d%d",&k,&a,&b);
    for(int i=a;i<=b;i++)
    {
        if(i%k==0)
        {
            printf("OK\n");
            return 0;
        }
    }
    printf("NG\n");
    return 0;
}


Measured memory_bytes: 1596
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;

int w, h, n;

int x, y, a;

int area[101][101];

int main() {
    ios_base::sync_with_stdio(false);
    
    cin >> w >> h >> n;
    
    for (int i = 0; i < n; i++) {
        cin >> x >> y >> a;
        if (a == 1) {
            //x < xi
            for (int xx = 0; xx < x; xx++)
                for (int yy = 0; yy < h; yy++)
                    area[yy][xx] = 1;
            
        } else if (a == 2) {
            for (int xx = x; xx < w; xx++)
                for (int yy = 0; yy < h; yy++)
                    area[yy][xx] = 1;
            
            
        } else if (a == 3) {
            for (int yy = 0; yy < y; yy++)
                for (int xx = 0; xx < w; xx++)
                    area[yy][xx] = 1;
            
        } else if (a == 4) {
            for (int yy = y; yy < h; yy++)
                for (int xx = 0; xx < w; xx++)
                    area[yy][xx] = 1;
        }
    }
    int ans = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            //cout << area[i][j] << " ";
            if (area[i][j] == 0)
                ans++;
        }
        //cout << endl;
    }
    
    cout << ans << endl;
    
    
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1e5+5;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    string s;cin>>s;
    if(s[1]=='R')s[1]='B';
    else s[1]='R';
    cout<<s;
}


Measured memory_bytes: 3656
import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter
# a.sort(key=itemgetter(i)) # i番目要素でsort
from functools import lru_cache
# @lru_cache(maxsize=None)
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7


def inp():
    '''
    一つの整数
    '''
    return int(input())


def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))


def str_inp():
    '''
    文字列をリストとして読み込む
    '''
    return list(input()[:-1])


ans = INF
s = str_inp()
t = str_inp()

for i in range(len(s) - len(t) + 1):
    tmp = 0
    for j in range(len(t)):
        if s[i + j] != t[j]:
            tmp += 1
    ans = min(ans, tmp)
print(ans)


Measured memory_bytes: 68536
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 10000000000
using namespace std;
using ll = long long;
int main()
{
    int a,b;
    cin >> a >> b;
    if(a <= 8 && b<=8){
        cout << "Yay!" << endl;
    }else{
        cout << ":(" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define cina(a, n) for (int i = 0; i < n; ++i){ cin >> a[i]; }
#define ll long long

using namespace std;

int main () {
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n, m;
	cin >> n >> m;
	int a[n], sum = 0;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		sum += a[i];
	}
	sort(a, a+n, greater<int>());
	for (int i = 0; i < m; ++i) {
		if (a[i] < (double)sum / (4 * m)) {
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";
	return 0;
}

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

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

    ll i,j,k,l,m,n,w,x,y,z,p,q,tmp,sum=0;
    string str;
    cin>>n;
    cout<<n*2*M_PI;

    return 0;
}

Measured memory_bytes: 3864
// 互いに素なら N * M
// それ以外、少なくとも LCM(N, M)
// 対応する文字が同じなら OK
// それ以外は NG ？

#include<iostream>
#include<vector>
//#include<numeric>

using namespace std;

#define rep(i, n) for(long long i = 0;i < (n);i++)


long long gcd(long long a, long long b) {
    if (a < b) return gcd(b, a);
    if (b == 0) {
        return a;
    }
    return gcd(b, a % b);
}
// */

int main() {
    int N, M;
    string S, T;
    cin >> N >> M;
    cin >> S >> T;
    
    long long g = gcd(N, M);
    long long l = N / g * M;


    long long i = 0, j = 0;
    bool ok = true;
    while(i < N && j < M) {
        // cout << i << ", " << j << ": " << S[i] << ", " << T[j] << endl;
        if (S[i] != T[j]) ok = false;
        i += l / M;
        j += l / N;
    }

    if (ok) cout << l << endl;
    else cout << "-1" << endl;

    
    return 0;
}


Measured memory_bytes: 512
/**************************************************
 * Atcoder problems
 * Contest No :086
 * Problem No :B
 * File Name  :program.cs
 * Create date:2020/06/06
 *
 * Copyright 2020 Shunichi Sato,All Rights Reserved.
**************************************************/
//memo terinal command
//compile:mcs program.cs
//excute :mono program.exe
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
        // 整数の入力
        string input = Console.ReadLine();
		var inputlist = new List<int>();
        inputlist.Add(int.Parse(input.Substring(0,1)));
        inputlist.Add(int.Parse(input.Substring(1,1)));
        inputlist.Add(int.Parse(input.Substring(2,1)));
		// 個数の判定
		int output = 0;
		foreach(int fact in inputlist )
		{
			if(fact == 1)
			{
				output++;
			}
		}
		//出力
		Console.WriteLine(output);
	}
}


Measured memory_bytes: 13268
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<string>
#include<sstream>
#include<cmath>
#include<climits>
#include<algorithm>
#include<bitset>
#include<set>
#include<stack>
#include<queue>
#include<iomanip>
#include<memory.h>
#include<complex>
using namespace std;  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef tuple<int,int> tii;
#define rep(i,n) for(ll i=0;i<(n);i++)  
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second  
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
const double PI = M_PI;  
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define SHOWARRAY(ar,i,j) REP(a,i)REP(b,j)cerr<<ar[a][b]<<((b==j-1)?((a==i-1)?("\n\n"):("\n")):(" "))
#define DIV int(1e9+7)
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}
 
/* Coding Space*/
typedef tuple<int,int> tii;
int main(){
  int h,w,n; cin >> h >> w >> n;
  map<tii,int> m;
  rep(i,n){
    int a,b; cin >> a >> b;
    for(int x = -2; x <= 0; x++)
    for(int y = -2; y <= 0; y++){
      int aa = a+x,bb = b+y;
      if(aa >= 1 && aa <= h-2 && bb >= 1 && bb <= w-2)
        m[tii{aa,bb}]++;
    }
  }
  vector<ll> ans(10);
  ans[0] = ll(h-2)*(w-2) - m.size();
  for(auto i:m){
    ans[i.SEC]++;
  }
  rep(i,10)
    cout << ans[i] << endl;
}

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

bool lis[82];

int main() {
	int a;
	cin>>a;
	for(int i=0;i<=9;i++) for(int j=1;j<=9;j++) {
		lis[i*j]=1;
	}
	if(lis[a]) cout<<"Yes";
	else cout<<"No";
	cout<<"\n";
}

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

#define mx 4

typedef long long int ll;

ll max(ll a, ll b, ll c){
	return max(max(a,b),c);
}

int main(){
	int r, c, k; scanf("%d %d %d",&r,&c,&k);
	int tab[r][c]; 
	for(int i=0;i<r;i++){
		for(int j=0;j<c;j++){
			tab[i][j] = 0;
		}
	}
	
	for(int i=0;i<k;i++){
		int x , y, v; scanf("%d %d %d", &x,&y,&v);
		x--; y--;
		tab[x][y] = v;
	}
	
	
	ll old[c][mx];
	ll dp[c][mx];
	for(int i=0; i<r;i++){
		for(int j=0;j< c;j++){
			for(int l=0; l<mx;l++){
				dp[j][l] = 0;
				if(i==0 && j==0){
					dp[j][l] = l>0? tab[i][j] : 0;
				}
				if(i==0 && j!=0){
					if(l==0){
						dp[j][l] = 0;
					}
					else{
						dp[j][l] = max(tab[i][j]+dp[j-1][l-1], dp[j-1][l]);
					}
				}
				if(i!=0 && j==0){
					if (l==0)
						dp[j][0] = old[j][mx-1];
					else dp[j][l] = tab[i][j] + old[j][mx-1];
				}
				if(i!=0 && j!=0){
					if (l==0)
						dp[j][0] = old[j][mx-1];
					else {
						dp[j][l] = max(dp[j-1][l-1] + tab[i][j],
											old[j][mx-1]+tab[i][j], dp[j-1][l]);
					}
				}
			}
		}
		for(int j=0;j<c;j++){
			for(int l=0;l<mx;l++){
				old[j][l] = dp[j][l];
			}
		}
	}
	
	
	//~ for(int i=0;i<r;i++){
		//~ for(int j=0;j<c;j++){
			//~ for(int l=0;l<mx;l++){
				//~ printf("%d ", dp[i][j][l]);
			//~ }
			//~ printf("\t");
		//~ }
		//~ printf("\n");
	//~ }
	printf("%lld",dp[c-1][mx-1]);
}


Measured memory_bytes: 38996
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

int main(void){
  int k;
  cin >> k;

  cout << (k/2) * ((k + 1)/2) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

char str[5];
char MM[12][3] = {"01", "02", "03", "04", "05", "06",
                  "07", "08", "09", "10", "11", "12"};

int main(void)
{
  scanf("%s", str);
  bool MMYY = false;
  bool YYMM = false;
  // MMYY
  for (int i = 0; i < 12; ++i) {
    if (str[0] == MM[i][0] && str[1] == MM[i][1]) MMYY = true;
  }
  // YYMM
  for (int i = 0; i < 12; ++i) {
    if (str[2] == MM[i][0] && str[3] == MM[i][1]) YYMM = true;
  }
  if (MMYY && YYMM)
    printf("AMBIGUOUS\n");
  else if (MMYY && !YYMM)
    printf("MMYY\n");
  else if (!MMYY && YYMM)
    printf("YYMM\n");
  else
    printf("NA\n");
  return 0;
}


Measured memory_bytes: 760
/*
ID: ramil-p1
PROG: balancing
LANG: C++11
*/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef long double ld;

const int maxn = 2e5 + 100, mod = 1e9 + 7;

int n;

ll q[maxn], a[maxn];

int main(){
    #ifdef ONPC
    //ifstream cin("a.in");
    //ofstream cout("a.out");
    #endif
    ios::sync_with_stdio(0);
    ll x, y;
    cin >> n >> x >> y;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 1; i < n; i++)
        q[i] = q[i - 1] + min(y, (a[i] - a[i - 1]) * x);
    cout << q[n - 1];
}


Measured memory_bytes: 1792
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <boost/foreach.hpp>
//#include <boost/range/algorithm.hpp>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1e9
#define LINF 1e18
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
#define MOD 1000000007LL
#define int long long
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
struct edge{int to,cost;};
typedef pair<int,int> P;

bool isupper(char c){if('A'<=c&&c<='Z')return 1;return 0;}
bool islower(char c){if('a'<=c&&c<='z')return 1;return 0;}
bool isPrime(int x){if(x==1)return 0;if(x==2)return 1;if(x%2==0)return 0;for(int i=3;i*i<=x;i++)if(x%i==0)return 0;return 1;}
bool iskaibun(string s){for(int i=0;i<s.size()/2;i++)if(s[i]!=s[s.size()-i-1])return 0;return 1;}

struct S{
    int a[3];
};

signed main (){
    int n,m;cin>>n>>m;
    vector<S> v(n);
    rep(i,0,n)rep(j,0,3)cin>>v[i].a[j];
    int ans=-1e18;
    rep(i,0,1<<3){
        vector<int> sum(n,0);
        int anss=0;
        rep(j,0,n){
            rep(k,0,3){
                if(i>>k&1)sum[j]+=v[j].a[k];
                else sum[j]-=v[j].a[k];
            }
        }
        sort(all(sum),greater<int>());
        rep(j,0,m)anss+=sum[j];
        ans=max(ans,anss);
    }
    cout<<ans<<endl;


}
/*
*/


Measured memory_bytes: 256
#include <stdio.h>

int g[101];
int a, b, c;
int cnt;

int main(void) {
    
    scanf("%d%d%d", &a, &b, &c);
    
    g[a]++;
    g[b]++;
    g[c]++;
    for(int i=1; i<101; i++)
        if(g[i]) cnt++;
    
    
    printf("%d", cnt);
    
    return 0;
}

Measured memory_bytes: 128
n = int(input())
a = list(map(int, input().split()))

count = 1
increasing = None

for i in range(n-1):
  if increasing == None:
    if a[i] - a[i+1] > 0:
      increasing = True
    elif a[i] - a[i+1] < 0:
      increasing = False

  elif increasing:
    if a[i] - a[i+1] < 0:
      increasing = None
      count += 1

  elif not increasing:
    if a[i] - a[i+1] > 0:
      increasing = None
      count += 1
print(count)

Measured memory_bytes: 14252
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using P = pair<ll, ll>;

constexpr double PI = 3.14159265358979323846;
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

class BIronBarCutting {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int n; cin >> n;
      vector<ll> a(n);
      ll sum = 0;
      rep(i, n) {
        cin >> a[i];
        sum += a[i];
      }
      ll now = 0;
      ll ans = LLONG_MAX;
      rep(i, n-1) {
        now += a[i];
        ll k = sum - now;
        chmin(ans, abs(now-k));
      }
      cout << ans << endl;

    }
};

signed main() {
  BIronBarCutting solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(int argc,char ** argv){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int n , k;
  	cin >> n >> k;
  	long long h[n];
  	for(int i = 0 ; i < n ; i++)
  		cin >> h[i];
  	long long dp[n];
  //	memset(dp , 10000000 , sizeof(dp));
  	dp[0] = 0;
 	dp[1] = abs(h[1] - h[0]);
  	for(int i = 2 ; i < n ; i++)
    {	
      	long long temp = 1e18;
      	for(int j = min(i , k) ; j >= 1; j--){
      		//cout << (i - j) << endl;
      		temp = min(temp , dp[i - j] + abs(h[i] - h[i - j]));
      	}
      	dp[i] = temp;
    }
  	cout << dp[n - 1] << endl;
   
	return 0; 
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

/*
*/

template<int MOD>
struct ModInt {
	static const int Mod = MOD;
	unsigned x;
	ModInt() : x(0) { }
	ModInt(signed sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
	ModInt(signed long long sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
	int get() const { return (int)x; }

	ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
	ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }

	ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
	ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
	ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
	ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }

	ModInt inverse() const {
		signed a = x, b = MOD, u = 1, v = 0;
		while (b) {
			signed t = a / b;
			a -= t * b; std::swap(a, b);
			u -= t * v; std::swap(u, v);
		}
		if (u < 0) u += Mod;
		ModInt res; res.x = (unsigned)u;
		return res;
	}
};
typedef ModInt<998244353> mint;
vector<mint> fact, factinv;
void nCr_computeFactinv(int N) {
	N = min(N, mint::Mod - 1);
	fact.resize(N + 1); factinv.resize(N + 1);
	fact[0] = 1;
	reg(i, 1, N) fact[i] = fact[i - 1] * i;
	factinv[N] = fact[N].inverse();
	for (int i = N; i >= 1; i --) factinv[i - 1] = factinv[i] * i;
}
mint nCr(int n, int r) {
	if (n >= mint::Mod)
		return nCr(n % mint::Mod, r % mint::Mod) * nCr(n / mint::Mod, r / mint::Mod);
	return r > n ? 0 : fact[n] * factinv[n - r] * factinv[r];
}
mint nPr(int n, int r) {
	if (r<0)return 0;
	return r > n ? 0 : fact[n] * factinv[n-r];
}
mint nHr(int n, int r) { return r == 0 ? 1 : nCr(n + r - 1, r); }

ll modpow(__int128_t a, ll n,ll mo) {
	__int128_t r=1;
	while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
	return r;
}

ll n,d[100010],a[100010]={},ans=1,mod=998244353;

int main(void){
	cin>>n;
	// nCr_computeFactinv(200010);
	rep(i,n)cin>>d[i];
	rep(i,n)a[d[i]]++;
	if(a[0]!=1 || d[0]!=0)ans=0;
	// cerr<<ans.get()<<endl;
	reg(i,1,n-1){
		// cerr<<a[i]<<endl;
		if(a[i-1]==0 && a[i]>0){
			ans=0;
			break;
		}
		if(a[i]==0)continue;
		ans = (ans*modpow(a[i-1],a[i],mod))%mod;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
io = STDIN
n,m,c=io.gets.split.map(&:to_i)
br=io.gets.split.map(&:to_i)
def calc(br,ar,c)
  sum=br.zip(ar).inject(0) do |s,(b,a)|
    s+(a*b)
  end
  sum+c>0
end

cnt=0
n.times.each do
  ar=io.gets.split.map(&:to_i)
  cnt+=1 if calc(br,ar,c)
end
puts cnt


Measured memory_bytes: 1788
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define rt return
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
ll dp[55][55*55];
int k;
int n;
int main()
{
    //freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);
    //freopen("D:\\common_text\\code_stream\\out.txt","w",stdout);
    gbtb;
    cin>>n>>k;
    int x;
    dp[0][0]=1ll;
    repd(i,1,n)
    {
        cin>>x;
        for(int j=i-1;j>=0;j--)
        {
            for(int w=0;w<=55*j;w++)
            {
                dp[j+1][w+x]+=dp[j][w];
            }
        }
    }
    ll ans=0ll;
    repd(i,1,n)
    {
        ans+=dp[i][i*k];
    }
    cout<<ans<<endl;


    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}



Measured memory_bytes: 1024
//submitted by HimJ
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define fi first
#define se second
#define fr(i,s,e) for(i=s;i<e;i++)
#define ms(arr,val) memset(arr,val,sizeof(arr))
using namespace std;
const int mxn=1e5;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
  int t=1;
  //cin>>t;
    while(t--){
            ll n,k;
            ll ans=0;
    cin>>n>>k;
    ll b;
    fr(b,k+1,n+1)
    {
        ll a=k;
//        ll temp=1ll*(b-k)*(b+k-1);
//        temp/=2;
//        temp=1ll*(b-k)*n-temp;
//        temp/=b;
//        temp+=b-k;
//        ans+=temp;
//        ll num=b-k;
//        ll tn=((n-b+1)/b)+1;

        while(1)
        {
            ll mn=((n-a)/b)+1;
        ll tn=a+(mn-1)*b;
            ll gap=n-tn;
            ll num=b-a;
            if(gap+1>=num)
            {
                ans+=num*mn;
                break;
            }
            else
            {
                ans+=(gap+1)*mn;
                a+=gap+1;
            }
        }
        if(k==0)
            ans-=1;
//        ll temp=b-1+(tn-1)*b;
//        if(temp<n)
//            temp+=b;
//        ll gap=temp-n;
//        temp=0;
//        if(gap<num)
//            {
//                temp=gap;
////ans+=1;
//            }
//        ans+=1l*temp*(tn+1)+1ll*(num-temp)*tn;

//        fr(a,k,b)
//        {
//            ans+=((n-a)/b)+1;
//
//        }
//        if(k==0)
//                ans-=1;
    }
    cout<<ans;

  }
  return 0;
  }



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;
 
int main()
{
  double x1,y1;
  double x2,y2;
  double dist;

  cin >> x1 >> y1 >> x2 >> y2;

  dist = sqrt(pow((x1 - x2), 2.0) + pow((y1 - y2), 2.0));

  cout << fixed
       << setprecision(5)
       << dist
       << endl;

  return(0);
}

Measured memory_bytes: 1284
#include <bits/stdc++.h>
using namespace std;
long long n,m;
int main(){
  cin >> n >> m;
  if(n==1&&m==1){
    cout << 1 << endl;
    return 0;
  }else if(n==1){
    cout << m-2 << endl;
    return 0;
  }else if(m==1){
    cout << n-2 << endl;
    return 0;
  }

  long long ans;

  ans = (n-2)*(m-2);
  cout <<ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include<cfenv>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <ios>
#include <iostream>
#include <list>
#include <map>
#include<numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
#define itn int
#define retrun return
using namespace std;
typedef long long llong;
typedef unsigned long long ullong;
vector<llong> AllDivisors(llong N) {
	vector<llong> ANS;
	for (llong i = 1; i * i <= N; i++) {
		if (N % i == 0) {
			ANS.push_back(i);
			if (N / i != i)ANS.push_back(N / i);
		}
	}
	sort(ANS.begin(), ANS.end());
	return ANS;
}
bool IsPrime(llong N) {
	for (llong i = 2; i * i <= N; i++) {
		if (N % i == 0) return false;
	}
	return true;
}
pair<llong, llong> Reduction(pair<llong, llong> A) {
	llong tmp = gcd(A.first, A.second);
	auto p = make_pair(A.first / tmp, A.second / tmp);
	return p;
}
//ここまで共通
llong N, D;
vector<pair<int, int>> X;
int main() {
	cin >> N >> D;
	int count = 0;
	for (int i = 0; i < N; i++) {
		llong x, y;
		cin >> x >> y;
		if (x * x + y * y <= D * D) count++;
	}
	cout << count << endl;
}

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

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

    sort(a, a + 3); 
    int dif = a[2] - a[0] + a[2] - a[1];
    
    if (dif % 2 == 0) { 
         n = dif / 2;   
        }
        else { 
            n = (dif + 3) / 2;
        }
    cout << n << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

int main(void)
{
    cin.sync_with_stdio(false);
    int N;
    cin >> N;
    const ll INF = 1e15;
    vector<vector<ll>> As(N, vector<ll>(N));
    REP(n1, N) {
        REP(n2, N) {
            cin >> As[n1][n2];
        }
    }

    vector<vector<ll>> Ds(N, vector<ll>(N, INF));
    REP(n, N) Ds[n][n] = 0;

    // 長さの小さい辺から張っていく

    // <dist, v1, v2>
    set<tuple<ll, int, int>> edges;
    REP(i, N-1) {
        FOR(j, i+1, N) {
            edges.insert(mt(As[i][j], i, j));
        }
    }

    ll ans = 0;
    bool ok = true;

    // 辿れる頂点を管理
    for(auto& e: edges) {
        auto d = get<0>(e);
        auto v1 = get<1>(e);
        auto v2 = get<2>(e);

        auto cur_dist = Ds[v1][v2];
        // 矛盾発生
        if (cur_dist < d) {
            ok = false;
            break;
        }
        else if (cur_dist > d) {
            Ds[v1][v2] = Ds[v2][v1] = d;
			// 関係するとこだけ更新
			REP(i, N-1) {
				FOR(j, i + 1, N) {
					auto d1 = Ds[i][j];
					auto d2 = Ds[i][v1] + d + Ds[v2][j];
					auto d3 = Ds[i][v2] + d + Ds[v1][j];
					Ds[i][j] = Ds[j][i] = min(min(d1, d2), d3);
				}
			}


            ans += d;
        }
        else if (cur_dist == d) {
            // do nothing
        }
    }

    if (ok) {
        cout << ans << endl;
    } else {
        cout << -1 << endl;
    }

    return 0;
}


Measured memory_bytes: 4480
from collections import deque
n = int(input())
L = list(range(1, 10))
count = 9
d = deque([1,2,3,4,5,6,7,8,9])
while count < n:
    p = d.popleft()
    p1 = p%10
    if p1 == 0:
        lunlun = p*10 + p1
        d.append(lunlun)
        L.append(lunlun)
        count += 1
        lunlun += 1
        d.append(lunlun)
        L.append(lunlun)
        count += 1
    elif p1 == 9:
        lunlun = p*10 + p1 - 1
        d.append(lunlun)
        L.append(lunlun)
        count += 1
        lunlun += 1
        d.append(lunlun)
        L.append(lunlun)
        count += 1
    else:
        lunlun = p*10 + p1 - 1
        d.append(lunlun)
        L.append(lunlun)
        count += 1
        lunlun += 1
        d.append(lunlun)
        L.append(lunlun)
        count += 1
        lunlun += 1
        d.append(lunlun)
        L.append(lunlun)
        count += 1
print(L[n-1])


Measured memory_bytes: 14080
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.close();

        int nn = n % 10;

        if(nn == 2 || nn == 4 || nn == 5 || nn == 7 || nn == 9) {
            System.out.println("hon");
        } else if(nn == 0 || nn == 1 || nn == 6 || nn == 8) {
            System.out.println("pon");
        } else {
            System.out.println("bon");
        }
    }
}


Measured memory_bytes: 35748
// F.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

typedef pair<int, int> II;

bool solve(vector<string> ss) {
	vector<II> v;
	for (string s : ss) {
		int cnt = 0, mn = 0;
		for (char c : s) {
			if (c == '(') {
				++cnt;
			} else {
				--cnt;
				mn = min(mn, cnt);
			}
		}
		v.emplace_back(II(mn, cnt));
	}
	int cnt = 0;
	vector<II> mp;
	vector<pair<int, II>> mm;
	for (auto kv : v) {
		if (kv.first >= 0) {
			cnt += kv.second;
		} else if (kv.second >= 0) {
			mp.emplace_back(kv);
		} else {
			mm.emplace_back(make_pair(kv.second - kv.first, kv));
		}
	}
	bool ans = true;
	sort(mp.rbegin(), mp.rend());
	for (auto kv : mp) {
		if (cnt + kv.first < 0) {
			ans = false;
		}
		cnt += kv.second;
	}
	sort(mm.rbegin(), mm.rend());
	for (auto kv : mm) {
		if (cnt + kv.second.first < 0) {
			ans = false;
		}
		cnt += kv.second.second;
	}
	return ans && cnt == 0;
}

int main(int argc, char* argv[]) {
	cout.precision(20);
#ifdef _MSC_VER
	while (true)
#endif
	{
		int n = -1;
		cin >> n;
		if (n < 0) return 0;
		vector<string> v(n);
		for (int i = 0; i < n; ++i) {
			cin >> v[i];
		}
		bool ans = solve(v);
		cout << (ans ? "Yes" : "No") << endl;
	}
	return 0;
}


Measured memory_bytes: 85620
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){std::cout << e << std::endl;}
template<class T> void DEBUG(string str, T e){std::cout <<str << ">>" << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ DEBUG(v); } }
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void solve(void)
{

  int N;
  cin>>N;
  vector<bool> data(2019,0);
  vector<int> input(N);
  for (int i = 0; i < N; i++)
  {
    int A;
    cin>>A;
    A--;
    data[A] = true;
    input[i] = A;
  }
  int M;
  cin>>M;
  for (int q = 0; q < M; q++)
  {
    int A,B;
    cin>>B;
    B--;
    A = input[B];
    if(A != 2018 && data[min(A+1,(int)2018)] != true)
    {
      data[A] = false;
      data[A+1] = true;
      input[B]++;
      // DEBUG(A);
    }
  }

  for (int i = 0; i < 2019; i++)
  {
    if(data[i] == true)
    {
      cout<<i+1<<endl;
    }
  }
  
  
  
  return; 
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

 
  return 0;
}


Measured memory_bytes: 3212
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int ans = 0;
    vector<int> a(n), d(n + 1);
    rep(i, 0, n){
        cin >> a[i];
        if(a[i] <= n) d[a[i]]++;
        else ans++;
    }
    rep(i, 1, n + 1){
        if(d[i] > i) ans += d[i] - i;
        else if(d[i] < i) ans += d[i];
    }
    cout << ans << endl;
}

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

n,k=map(int,input().split())
h=list(map(int,input().split()))

dp=[None]*n
dp[0]=0
dp[1]=abs(h[1]-h[0])

for i in range(2,n):
    kouho=[]
    for j in range(1,k+1):
        if i-j>=0:
            kouho.append(dp[i-j]+abs(h[i-j]-h[i]))
    dp[i]=min(kouho)

print(dp[-1])

Measured memory_bytes: 84916
#include<stdio.h>
int pr[100005];
int root(int n)
{
	if (pr[n] == n)
		return n;
	else
		return pr[n] = root(pr[n]);
}
void f(int x, int y)
{
	if (root(x) == root(y))
		return;
	else
		pr[root(x)] = root(y);
	return;
}
int main()
{
	int n, m;
	scanf("%d %d", &n, &m);
	int i;
	int p[100005];
	for (i = 0; i < n; i++)
	{
		scanf("%d", &p[i]);
		p[i]--;
	}
	for (i = 0; i < n; i++)
		pr[i] = i;
	int x, y;
	for (i = 0; i < m; i++)
	{
		scanf("%d %d", &x, &y);
		f(x - 1, y - 1);
	}
	int ans = 0;
	for (i = 0; i < n; i++)
		if (root(i) == root(p[i]))
			ans++;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 896
import math

A,B,H,M = map(int, input().split())

a = A*math.cos(2*math.pi* (H+(M/60)) /12)
b = A*math.sin(2*math.pi* (H+(M/60)) /12)
c = B*math.cos(2*math.pi*M/60)
d = B*math.sin(2*math.pi*M/60)
print( ( (a-c)**2+(b-d)**2 ) ** 0.5)

Measured memory_bytes: 9580
import sys
N = int(input())

a_b_list = []
for _ in range(N):
    A, B = list(map(int, input().split(' ')))
    a_b_list.append((A, B))

pa, pb = (0, 10**9)
for a, b in sorted(a_b_list, key=lambda x: x[1]):
    pa += a
    pb = b
    if pb < pa:
        print('No')
        sys.exit(0)

print('Yes')


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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

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

    transform(s.begin(), s.end(), s.begin(), [](char c) { return c - '0'; });

    int64_t n = s.size();
    vector<vector<int64_t>> dp(2, vector<int64_t>(n + 1));
    dp[0][0] = 0;
    dp[1][0] = 1;
    for (auto i : irange(0L, n)) {
        dp[0][i + 1] = min(dp[0][i] + s[i], dp[1][i] + (10 - s[i]));
        dp[1][i + 1] = min({dp[0][i] + s[i] + 1, dp[1][i] + (10 - s[i] - 1)});
    }

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

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

#define MAX 2000000   /* キューSの最大サイズ */

void insert(int S[], int key);
void increaseKey(int S[], int i, int key);
int extractMax(int S[]);
void swap(int *, int *);
void maxHeapify(int heap[], int i);


int length;      /* 優先度付きキューSのサイズ */

int main()
{
  int S[MAX], k;
  char com[16];

  while(1)
    {
      scanf("%s", com);

      if( com[0] == 'e' && com[1] == 'n' )
	break;
      if( com[0] == 'i' )
	{
	  scanf("%d", &k);
	  insert(S, k);
	}
      else
	printf("%d\n", extractMax(S) );
    }
  
  return 0;
}


/* S[i]を根ノードとする部分木を最大ヒープに変換する関数 */
void maxHeapify(int S[], int i)
{
  int l = i*2, r = i*2+1, largest;

  /* 根ノードheap[i]、左の子、右の子の中から最大のものを求める */
  if( l<=length && S[i] < S[l] )
    largest = l;
  else
    largest = i;
  if( r<=length && S[largest] < S[r] )
    largest = r;

  if( i != largest )
    {
      swap(&S[i], &S[largest]);
      maxHeapify(S, largest);
    }
}


/* int型変数 a,b を交換する関数 */
void swap(int *a, int *b)
{
  int tmp;

  tmp = *a;
  *a  = *b;
  *b  = tmp;
}

/*　優先度付きキューSにキー値がkeyのノードを挿入する関数　*/
void insert(int S[], int key)
{
  S[++length] = INT_MIN;         /* increaseKey関数の汎用性維持のためにinsert関数内でINT_MINを代入する必要がある*/
  increaseKey(S, length, key);
}

/*　S[i]のキー値をより大きな値のkeyに変更し、最大ヒープ構造を満たすように適切な位置に移動させる関数　*/
void increaseKey(int S[], int i, int key)
{
  int parent = i/2;

  if( S[i] > key )
    {
      fprintf(stderr, "Error! New key is smaller than current key.\n");
      exit(2);
    }
  S[i] = key;

  while( i > 1 && S[i] > S[parent] )
    {
      swap(&S[i], &S[parent]);
      i = parent;
      parent = i/2;
    }
}

/*　優先度付きキューSから最大のキー値を持つノードを求め削除し、その値を返す関数　*/
int extractMax(int S[])
{
  int max;

  if( length < 1 )
    {
      fprintf(stderr, "heap underflow\n");
      exit(3);
    }

  max  = S[1];
  S[1] = S[length--];
  maxHeapify(S, 1);

  return max;
}



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

int main() {
    vector<int>x(3);
    vector<int>y(3);
    for (int i = 0; i < 3; ++i) {
      cin >> x[i] >> y[i];
    }
    vector<double>edge(3);
    for (int i = 0; i < 3; ++i) {
        double dx = x[i] - x[(i+1)%3];
        double dy = y[i] - y[(i+1)%3];
        edge[i] = sqrt(pow(dx, 2) + pow(dy, 2));
    }
    sort(edge.begin(), edge.end());
    double area = (x[0]-x[2]) * (y[1]-y[2]) - (y[0]-y[2]) * (x[1]-x[2]);
    double h = abs(area) / edge[2];

    // (e[0]+e[1]+e[2]+2*h)x=e[2]*h を満たす
    double a = edge[0] + edge[1] + edge[2] + h*2;
    double ans = edge[2] * h / a;
    cout << setprecision(16) << ans;
    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>){
    val a = readLine()!!.toInt()
    val b = readLine()!!.toInt()
    val c = readLine()!!.toInt()
    val d = readLine()!!.toInt()
    val e = readLine()!!.toInt()
    val k = readLine()!!.toInt()
    
    if(e-a > k) println(":(") else println("Yay!")
}

Measured memory_bytes: 31872
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int lld;

const lld mod = 1e9+7;
const lld INF = 1e9;
//const lld MAXN = 1e9;

struct edge
{
	int u,v;
	lld c;
	bool operator<(const edge& e) const
    {
        return c > e.c;
    }
};

int main()
{
	int n;
	cin >> n;
	int a[300][300] = {0};

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

	lld dist[300][300] = {0};
	vector<edge> e;

	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < n; j++)
		{
			dist[i][j] = a[i][j];
			edge ee;
			ee.u = i;
			ee.v = j;
			ee.c = a[i][j];
			e.push_back(ee);
		}
	}

	for(int k = 0; k < n; k++)
	{
		for(int i = 0; i < n; i++)
		{
			for(int j = 0; j < n; j++)
			{
				if (dist[i][j] > dist[i][k] + dist[k][j])
				{
					dist[i][j] = dist[i][k] + dist[k][j];
				}
			}
		}
	}

	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < n; j++)
		{
			if (dist[i][j] != a[i][j])
			{
				cout << -1 << endl;
				return 0;
			}
		}
	}

	bool ch[300][300] = {false};
	for(int k = 0; k < n; k++)
	{
		for(int i = 0; i < n; i++)
		{
			for(int j = 0; j < n; j++)
			{
				if (dist[i][j] >=  dist[i][k] + dist[k][j] && i != j && i != k && j != k)
				{
					ch[i][j] = true;
				}
			}
		}
	}


	lld sum = 0;

	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < n; j++)
		{
			if (!ch[i][j])
			{
				sum += dist[i][j];
			}
		}
	}
	
	cout << sum / 2 << endl;

	return 0;
}

Measured memory_bytes: 3444
//
//  main.cpp
//  4
//
//  Created by RISHAV SINGH MEHTA on 31/01/20.
//  Copyright © 2020 RISHAV SINGH MEHTA. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#define ll long long
using namespace std;
int main(int argc, const char * argv[]) {
    // insert code here...
    ll int T,i,j,k,l,N,K,H;
    
    cin>>H;
    
    i=log2(H);
    l=pow(2, i + 1);
    cout<< l - 1<<endl;

    return 0;
}


Measured memory_bytes: 512
def parent(i)
  i/2
end

def left(i)
  i*2
end

def right(i)
  i*2 + 1
end

def extract(i)
  l = left(i)
  r = right(i)
  h = A.length

  # printf "extract %d\n",i
  # p A
  # printf "l %d  r %d  h %d\n",l,r,h

  if l < h && A[l] > A[i]
    @largest = l
  else
    @largest = i
  end

  if r < h && A[r] > A[@largest]
    @largest = r
  end

  if @largest != i
    A[i], A[@largest] = A[@largest], A[i]
    extract(@largest)
  end
end

def insert(i)
  @parent = parent(i)
  if @parent == 0
    return
  end

  if A[i] > A[@parent]
    A[i], A[@parent] = A[@parent], A[i]
    insert(@parent)
  end
end

A = Array.new
A << 0

until (str=gets.chomp) == "end"
  # p A
  if str == "extract"
    puts A[1]
    A[1] = A.pop
    extract(1)
  else
    str = str.split(" ")
    A << str[1].to_i
    insert(A.length-1)
  end
end



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

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

#define REP(i, x, n) for(ll i=x; i<(ll)n; ++i)
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()

int main(){
    string s;
    cin >> s;
    if(s[0]==s[1]){
        if(s[0]!=s[2]&&s[2]==s[3]) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    else if(s[0]==s[2]){
        if(s[0]!=s[1]&&s[1]==s[3]) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    else if(s[0]==s[3]){
        if(s[0]!=s[1]&&s[1]==s[2]) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false);cin.tie(0);cout.precision(10);cout << fixed
#define endl '\n'

const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
struct mint {
    ll x;
    mint() : x(0) {}
    mint(ll x) : x((x % MOD + MOD) % MOD) {}
    mint& operator+=(const mint& r) { if ((x += r.x) >= MOD) { x -= MOD; } return *this; }
    mint& operator-=(const mint& r) { if ((x -= r.x) < 0) { x += MOD; } return *this; }
    mint& operator*=(const mint& r) { if ((x *= r.x) > MOD) { x %= MOD; } return *this; }
    mint& operator++() { if ((++x) >= MOD) { x -= MOD; } return *this; }
    mint operator++(int) { mint ret = x; if ((++x) >= MOD) { x-= MOD; } return ret; }
    mint& operator--() { if ((--x) < 0) { x += MOD; } return *this; }
    mint operator--(int) { mint ret = x; if ((--x) < 0) { x += MOD; } return ret; }
    mint operator+(const mint& r) { mint ret; return ret = x + r.x; }
    mint operator-(const mint& r) { mint ret; return ret = x - r.x; }
    mint operator*(const mint& r) { mint ret; return ret = x * r.x; }
    mint operator-() { return mint() - *this; }
    bool operator<(const mint& a) { return x < a.x; }
    bool operator>(const mint& a) { return x > a.x; }
    bool operator<=(const mint& a) { return x <= a.x; }
    bool operator>=(const mint& a) { return x >= a.x; }
    bool operator==(const mint& a) { return x == a.x; }
    bool operator!=(const mint& a) { return x != a.x; }
};
ostream& operator<<(ostream& os, const mint& r) { os << r.x; return os; }
ostream& operator>>(ostream& os, const mint& r) { os >> r.x; return os; }

void solve(istream& cin, ostream& cout) {
  int k, n;
  cin >> k >> n;
  vector<int> a(n);
  int max_dif = 0;
  REP(i, n) {
    cin >> a[i];
    if (i >= 1) {
      if ((a[i] - a[i - 1]) > max_dif) {
        max_dif = a[i] - a[i - 1];
      }
    }
    if (i == n - 1) {
      if ((a[0] + k - a[n - 1]) > max_dif) {
        max_dif = a[0] + k - a[n - 1];
      }
    }
  }
  int ans = k - max_dif;
  cout << ans << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
}
#endif


Measured memory_bytes: 1024