akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
// type
#define int long long
typedef long long ll;
typedef long double ld;
// loop
//#define For(i, l, r, x)     for (int i = l; i < r; i+=x)
//#define ForE(i, l, r, x)    for (int i = l; i <= r; i+=x)
//#define Ford(i, r, l)       for (int i = r; i > l; i--)
//#define FordE(i, r, l)      for (int i = r; i >= l; i--)
//#define Fora(i, a)          for (auto i : a)
// I/O 
#define openfile(file)      freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
#define testinput(file)     freopen(file".txt", "r", stdin); 
#define FAST_IO             std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
//#define PrintV(a)           Fora(ii, a) cout << ii << ' '; cout << rl;
//#define PrintVl(a)          Fora(ii, a) cout << ii << rl;
//#define PrintA(a, l, r)     for (int ii = l; ii <= r; ii++) cout << a[ii] << ' '; cout << rl;
//#define PrintAl(a, l, r)    for (int ii = l; ii <= r; ii++) cout << a[ii] << rl;
//#define Ptest(x)            return cout << x, 0;
#define setpre(n)           fixed << setprecision(n)
// pair
#define F                   first
#define S                   second
#define pii                 pair<int, int>
#define pll                 pair<ll, ll>
#define pdd                 pair<ld, ld>
// vector & !!?(string)
#define eb                  emplace_back
#define pb                  push_back
#define all(a)              a.begin(), a.end()
#define rall(a)             a.rbegin(), a.rend()
#define sz(a)               a.size()
#define len(a)              a.length()
// geometry calc    
#define pi                  acos(-1.0)
#define g_sin(a)            sin(a*pi/180)
#define g_cos(a)            cos(a*pi/180)
#define g_tan(a)            tan(a*pi/180)
// set val
#define ms0(a)              memset(a,        0, sizeof(a));
#define ms1(a)              memset(a,        1, sizeof(a));
#define msn1(a)             memset(a,       -1, sizeof(a));
#define msinf(a)            memset(a, 0x3f3f3f, sizeof(a));
// constant
const int mod1 = 998244353, mod = 1e9+7;
const int MAXN = 1000005, MAXM = 200010;
// code
const int N = (int) 3e5;
ll factinv[N + 1]; 
ll inv[N + 1]; 
ll fact[N + 1]; 
void calc_inv(ll p){
    inv[0] = inv[1] = 1; 
    for (int i = 2; i <= N; i++) 
        inv[i] = inv[p % i] * (p - p / i) % p; 
}

void calc_factinv(ll p){
    factinv[0] = factinv[1] = 1; 
    for (int i = 2; i <= N; i++) 
        factinv[i] = (inv[i] * factinv[i - 1]) % p;
} 

void factorial(ll p){
    fact[0] = 1;
    for (int i = 1; i <= N; i++)
        fact[i] = (fact[i - 1] * i) % p;
} 
  
ll Ckn(ll N, ll K, ll p){
    ll ans = ((fact[N] * factinv[K]) % p * factinv[N - K]) % p;
    return ans; 
}

void Solve() {
    ll p = 1000000007;
    calc_inv(p);
    calc_factinv(p);
    factorial(p);
	
	ll H, W, A, B;
	cin >> H >> W >> A >> B;
	
	ll ans = 0;
	for (int pp = B; pp < W; pp++){
		ans = (ans + (Ckn(H-A-1+pp, H-A-1, p) * Ckn(W-pp+A-2, A-1, p)) % p) % p;
	}
	cout << ans;
}

signed main(){
    FAST_IO;
    int TC = 1;
	//cin >> TC;
    while(TC--) Solve();
    cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
    return 0;
}

Measured memory_bytes: 10820
#include <iostream>
#include <algorithm>
#include <cstdio>
#define mod 1000000007
#define MN 110

int f[MN][MN], g[MN];
int h[MN], b[MN];
int c[MN];

int qpow(int x, int p)
{
	int ans = 1;
	while(p)
	{
		if(p & 1) ans = 1ll * ans * x % mod; 
		x = 1ll * x * x % mod; p >>= 1;
	}
	return ans;
}

int main()
{
	int n; scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%d", &h[i]), b[i] = h[i];
	std::sort(b + 1, b + n + 1); int N = std::unique(b + 1, b + n + 1) - b - 1;
	for(int i = 1; i <= n; i++) h[i] = std::lower_bound(b + 1, b + N + 1, h[i]) - b;
	b[0] = 1; for(int i = 1; i <= N; i++) c[i] = qpow(2, b[i] - b[i - 1]) - 1;
	g[0] = 1;
	for(int i = 1; i <= n; i++)
	{
		if(h[i - 1] < h[i])
		{
			for(int j = 1; j <= h[i - 1]; j++) 
				f[i][j] = f[i - 1][j];
			for(int j = h[i - 1] + 1; j <= h[i]; j++)
				f[i][j] = 2 * g[i - 1] % mod;
			g[i] = 2 * g[i - 1] % mod;
		}
		else
		{
			for(int j = 1; j <= h[i]; j++)
				f[i][j] = 1ll * f[i - 1][j] * qpow(2, b[h[i - 1]] - b[h[i]]) % mod;
			g[i] = 2 * g[i - 1] % mod;
			for(int j = h[i] + 1; j <= h[i - 1]; j++)
				g[i] = (g[i] + 2ll * c[j] * f[i - 1][j] % mod * qpow(2, b[h[i - 1]] - b[j])) % mod;
		}
	}
	int ans = g[n]; 
	for(int i = 1; i <= h[n]; i++) ans = (ans + 1ll * c[i] * f[n][i] % mod * qpow(2, b[h[n]] - b[i])) % mod;
	printf("%d\n", ans);
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

#define D_MAX 1000000000
#define N_MAX 100000
#define M_MAX 10000
#define min(x,y) (((x)<(y))?(x):(y))

int d;
int n;
int m;

int ad[N_MAX+1];
int ak[M_MAX+1];

void MergeSort(int array[],int left,int right){
  int awork[N_MAX+1];
  int mid;
  int i;
  int j;
  int x;
  int y;
  
  if( left >= right ){
    return;
  }
  
  mid = (left + right) / 2;
  MergeSort( array, left, mid);
  MergeSort( array, mid+1, right);
  
  for( i=left; i<=mid; i++){
    awork[i] = array[i];
  }
  
  j = right;
  for( i=mid+1; i<=right; i++){
    awork[i] = array[j];
    j--;
  }
  
  x = left;
  y = right;
  
  for( i=left; i<=right; i++){
    if(awork[x] <= awork[y]){
      array[i] = awork[x];
      x++;
    }else{
      array[i] = awork[y];
      y--;
    }
  }
}

int calcDist(void){
  int i;
  int j;
  int minDist;
  int sum = 0;

  j = 1;
  for( i=1; i<=m; i++){
    while(ad[j] < ak[i]){
      j++;
    }
    minDist = min( ak[i]-ad[j-1],ad[j]-ak[i] );
    sum += minDist;
  }
  return sum;
}


void input(void){
  int i;
  scanf("%d",&d);
  if( d != 0){
    scanf("%d",&n);
    scanf("%d",&m);
    ad[0] = 0;
    for( i=1; i<=n-1; i++){
      scanf("%d",&ad[i]);
    }
    ad[n] = d;
    for( i=1; i<=m; i++){
      scanf("%d",&ak[i]);
    }
  }
}

int main(void){
  int i;
  int sumDist;
  while( 1 ){
    input();
    if( d == 0 ){
      break;
    }
    MergeSort( ad, 0, n);
    MergeSort( ak, 1, m);
    sumDist = calcDist();
    printf("%d\n",sumDist);
  }
}




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

// nの桁和
int digit_sum(int n) {
	int sum = 0;
	for (; n != 0; n /= 10) {
		sum += n % 10;
	}
	return sum;
}

// 桁和がnとなる最小の数
int min_digit_sum(int n) {
	int min = 0;
	if (n <= 9) {
		min = n;
	}
	else if (n <= 18) {
		min = (n - 9) * 10 + 9;
	}
	else if (n <= 27) {
		min = (n - 18) * 100 + 99;
	}
	else {
		min = (n - 27) * 1000 + 999;
	}
	return min;
}

// max以下で桁和がnとなる数の合計
int sum_ds(int n, int max) {
	int sum = 0;
	for (int i = min_digit_sum(n); i <= max; i += 9) {
		if (digit_sum(i) == n) {
			sum += i;
		}
	}
	return sum;
}

int main() {
	int N, A, B;
	cin >> N >> A >> B;
	int sum = 0;
	for (int i = A; i <= B; i++) {
		sum += sum_ds(i, N);
	}
	cout << sum << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define all(x) (x).begin(), (x).end()
#define print(x) cout << (x) << endl;

typedef long long ll;
const ll INF = 99999999999999;
const ll MOD = 1000000007;

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll lcm(ll number1, ll number2)
{
    return number1 * number2 / gcd(number1, number2);
}
template <class T>
bool contain(const std::string &s, const T &v)
{
    // contain(to_string(N), '3')
    return s.find(v) != std::string::npos;
}

int ctoi(char c)
{
    if (c >= '0' && c <= '9')
        return c - '0';
    return 0;
}
using namespace std;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k;
    cin >> n >> k;
    vector<ll> x(n);
    rep(i, n)
    {
        cin >> x[i];
    }
    ll ans = INF;
    rep(i, n - k + 1)
    {
        ll tmp = 0;
        ll a = x[i + k - 1];
        ll b = x[i];

        tmp = a - b + min(abs(a), abs(b));
        ans = min(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
  int N,M;
  cin>>N>>M;
  bitset<30> B(0);
  int k;
  cin>>k;
  for(int l=0;l<k;l++){
    int A;
    cin>>A;
    B.set(A-1);
  }
  for(int i=1;i<N;i++){
    int K;
    cin>>K;
    bitset<30> C(0);
    for(int j=0;j<K;j++){
      int A;
      cin>>A;
      C.set(A-1);
    }
    B&=C;
  }
  cout<<B.count()<<endl;
}

Measured memory_bytes: 256
from collections import deque
inf = 10**10
dxdy = ((0,1),(0,-1),(1,0),(-1,0)) 
h, w = map(int, input().split())
ch, cw = map(int, input().split())
dh, dw = map(int, input().split())
s = ['#'*(w+2)] + ['#' + input() + '#' for _ in range(h)] + ['#'*(w+2)]
d = [[inf]*(w+1) for _ in range(h+1)]
d[ch][cw] = 0
q = deque([(ch,cw)])
while q: 
    y,x = q.pop() 
    for dx,dy in dxdy: 
        if s[y+dy][x+dx]=='.' and d[y+dy][x+dx] > d[y][x]:
            d[y+dy][x+dx] = d[y][x]
            q.append((y+dy,x+dx))
    for i in range(-2,3):
        for j in range(-2,3):
            if i==j==0:
                continue 
            elif 1<=y+i<=h and 1<=x+j<=w and s[y+i][x+j]=='.' and d[y+i][x+j]>d[y][x]+1:
                
                d[y+i][x+j] = d[y][x]+1
                q.appendleft((y+i,x+j)) 
ans = d[dh][dw] 
if ans == inf:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 91516
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int[] check = new int[N + 1];
		//上限値検索
		for (int i = 1; i <= N; i++) {
			int n = i;
			int max = (int) Math.floor(Math.sqrt((double) n));
			for (int s = 1; s <= max; s++) {
				for (int t = 1; t <= max; t++) {
					for (int u = 1; u <= max; u++) {
						if (s * s + t * t + u * u + s * t + t * u + u * s > n) {
							break;
						}
						if (s >= t && t >= u && s * s + t * t + u * u + s * t + t * u + u * s == n) {
							if (s != t & t != u && u != s) {
								check[i] += 6;
							} else if (s == t && t == u && u == s) {
								check[i]++;
							} else {
								check[i] += 3;
							}
						}
					}
				}
			}
		}
		for (int i = 1; i <= N; i++) {
			System.out.println(check[i]);
		}
	}

}


Measured memory_bytes: 39056
#include <math.h>
int main(void){
    double Input[4];
    double Answer;
    int i;
    
    for(i=0;i<4;i++){
        scanf("%lf",&Input[i]);
    }
    
    Input[2]-=Input[0];
    Input[1]-=Input[3];
    
    printf("%f",sqrt(Input[2]*Input[2]+Input[1]*Input[1]));
    
}


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

using namespace std;

int main() {
	int n, d;
	cin >> n >> d;
	int i, j, k;
	int x[10][10],sum=0,cnt=0;
	for (i = 0; i < n; i++) {
		for (j = 0; j < d; j++) {
			cin >> x[i][j];
		}
	}
	double dist;
	int distInt;
	for (i = 0; i < n; i++) {
		for (j = i; j < n; j++) {
			if (i != j) {
				for (k = 0; k < d; k++) sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
				dist = sqrt(sum);
				distInt = dist;

				//cout << dist << distInt << (int)dist << endl;

				if (dist - (double)distInt == 0.00) cnt++;
				sum = 0;
			}
		}
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<int, int>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

using namespace std;
using ll = long long;
const int mod = 1e9+7;

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

  int N; cin >> N;
  vector<int> p(N);
  rep(i, N) {
    cin >> p.at(i);
  }
  sort(p.rbegin(), p.rend());
  int ans = p.at(0)/2;
  for(int i=1; i<N; i++) {
    ans += p.at(i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
a,b=map(int,input().split())
k=32
m=2*k
grid=[['#' for i in range(m)] for i in range(k)]
grid=grid+[['.' for i in range(m)] for i in range(k)]

for i in range(m*k):
  if a==1:
    break
  grid[2*int(i*2/m)][(i*2)%m]='.'
  a-=1

for i in range(m*k):
  if b==1:
    break
  grid[k+1+2*int(i*2/m)][(i*2)%m]='#'
  b-=1

print(str(2*k)+' '+str(2*k))
for i in range(k*2):
  print(''.join(grid[i]))

Measured memory_bytes: 3064
//JSD
#include<iostream>
#include<algorithm>
using  namespace std;
int main(){
  int n;
  cin>>n;
  int a[n],b[n];
  for(int i=0;i<n;i++){
  	cin>>a[i];
  	b[i]=a[i];
  }
  sort(a,a+n);
  int ma2=-1;
  for(int i=n-1;i>=0;i--){
  	if(a[i]<a[n-1]){
  		ma2=a[i];
  		break;
	  }
  }
  ma2=a[n-2];
  for(int i=0;i<n;i++){
  	if(b[i]==a[n-1]){
  		cout<<ma2;
	  }
	else cout<<a[n-1];  
	cout<<" ";
  }
}  

Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
template <class T>
bool maxi(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool mini(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
using namespace std;
using ll = long long;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------
ll qu[200];
char ans[200];
ll color;
ll fcolor;
char ctoc[2]={'B','R'};
ll N,M,K,H,W,T,X,Y;
void quest(){
    cout<<"? ";
    rep(i,N){
        cout<< qu[i] <<" ";
    }
    cout<<endl;

    string S; cin>>S;
    if(S=="Red") color=1;
    else color=0;
}

//--MAIN-----------------------------------
void Main() {
    cin>>N;

    rep(i,N){
        qu[i]=i+1;
    }
    quest();

    fcolor=color;

    ll low = 1; // 一番小さい値より1つ前
    ll high = N+1; // 一番でかい値より1つあと
    while (abs(high - low) > 1) {
        ll mid = (high + low) / 2;
        rep(i,N){
            qu[i]=(mid-1+i)%(N*2)+1;
        }
        quest();
        ( color!=fcolor ? high : low ) = mid; //ok条件のとき、ok方向をmidに
    }
    ans[low-1]=ctoc[fcolor];
    ans[low-1+N]=ctoc[1-fcolor];

    rep(i,N-1){
        qu[i]=high+i;
    }
    ll y=low+N;
    rep(i,N-1){
        qu[N-1]=(y+1+i-1)%(N*2)+1;
        quest();
        ans[(y+1+i-1)%(N*2)]=ctoc[color];
    }

    rep(i,N-1){
        qu[i]=(y+i+1-1)%(N*2)+1;
    }
    rep(i,N-1){
        qu[N-1]=(low+1+i-1)+1;
        quest();
        ans[(low+1+i-1)]=ctoc[color];
    }

    cout<< "! ";
    rep(i,N*2){
        cout<<ans[i];
    }
    cout<<endl;

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


Measured memory_bytes: 724
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }
#define ALL(x) (x).begin(), (x).end()
LL POW(LL a,LL p,LL M){ if(!p) return 1LL;LL T = POW(a,p/2,M);T = T*T%M; if(p&1) T=T*(a%M)%M; return T; }
LL SQRT(LL a) { LL b = (LL)sqrtl(((double)a)+0.5); while(b*b<a) ++b; while(b*b>a) --b; return (b*b==a)?b:-1; }
//endl
//<------------------------edits---------------------------------------------->
const LL MOD = 1e9+7;//998244353
// #define LOCAL LDD
// #define int LL

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(10);cout << fixed;
#ifdef LOCAL
  freopen("input.txt", "rt", stdin);
#endif
  string s;cin >> s;
  if(s[2]==s[3] && s[4]==s[5]) cout << "Yes\n";
  else cout << "No\n";
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s\n";
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 100000
#define Q 50000

int main(){
  int n,q,mid,s[N],t[Q],i,j,key[N],left,right,judge=0,count=0;

  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&s[i]); 
  scanf("%d",&q);
  for(i=0;i<q;i++) scanf("%d",&t[i]); 

  for(i=0;i<q;i++){
    left = 0;
    right = n;
    key[count]=t[i];
      for(j=0;j<count;j++){
	if(key[j]==t[i]){
	  judge=1;
	  break;
	}
      }
      if(judge==1){
	judge=0;
	continue;
      }
      while(1){
	mid = (left + right) / 2;
	if (s[mid] == key[count]){
	  count++;
	  break;
	}else if(key[count]<s[mid]) right = mid;
	else left = mid + 1;
      if(left>=right) break;
      }
  }

  

  printf("%d\n",count);

  return 0;
}



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

int main(){
    int n; cin >> n;
    for(int i = 0; i < n; i++){
        string s; cin >> s;
        int size = s.size();
        int ans = 0;
        set<string> st; //列車の種類を記録
        for(int j = 1; j < size; j++){ //列車を分岐させる場所は文字列(0-indexed)の1からsizeまで考える
            string head1 = s.substr(0,j); //車両は0からj-1までの部分文字列と
            string tail1 = s.substr(j,size); //jからsize-1までの部分文字列に分けられる。
            string head2 = s.substr(0,j); reverse(head2.begin(), head2.end()); //head1を反転したもの
            string tail2 = s.substr(j,size);  reverse(tail2.begin(), tail2.end()); //tail1を反転したもの
            // 集合に放り込む
            st.insert(head1+tail1);
            st.insert(head1+tail2);
            st.insert(head2+tail1);
            st.insert(head2+tail2);
            st.insert(tail1+head1);
            st.insert(tail1+head2);
            st.insert(tail2+head1);
            st.insert(tail2+head2);
        }
        ans = st.size(); //答えは集合の大きさ
        cout << ans << endl;
    }
}


Measured memory_bytes: 3156
#include <stdio.h>
#include <algorithm>
using namespace std;
int main(){
    int a[3],temp,n;
    bool f;
    while(1){
        f=true;
        for(int i=0;i<3;i++){
            scanf("%d",&a[i]);
            if(a[i]!=0)f=false;
        }
        sort(a,a+3);
        if(f)return 0;
        scanf("%d",&temp);
        for(int i=0;i<temp;i++){
            scanf("%d",&n);
            if(4*n*n>a[0]*a[0]+a[1]*a[1])printf("OK\n");
            else printf("NA\n");
        }
        
    }
}

Measured memory_bytes: 2588
s = input()
mod = 2019
digit = 1
mstack = 0
l = [0]*mod
l[0] = 1
ans = 0

for i in s[::-1]:
    mstack += int(i)*digit
    mstack %= mod
    l[mstack] += 1

    digit *= 10
    digit %= mod

for i in l:
    ans += i*(i - 1)//2

print(ans)

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

using namespace std;

const int maxn=10005;

char s[maxn];

int main()
{
    while(~scanf("%s", &s)){
        int len=strlen(s);
        if(len<4){
            printf("No\n");
            continue;
        }
        else if(s[0]=='Y'&&s[1]=='A'&&s[2]=='K'&&s[3]=='I'){
            printf("Yes\n");
        }
        else printf("No\n");
    }
    return 0;
}


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

int main(){
    int n ;
    cin >> n ;
    bool ans = false ;
    for (size_t i = 1; i < 10; i++)
    {
        /* code */
        if (n % i == 0  )
        {
            /* code */
            if (n / i >= 1 && n / i <= 9)
            {
                /* code */
                ans = true ;
                break;
            }
            
        }
        
    }
    if (ans == true)
    {
        /* code */
        cout <<"Yes" << endl ;
    }else
    {
        cout << "No" << endl ;
    }
    
    
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

/*
 * 重み無しグラフで、辺集合表現から隣接集合表現へ変換
 */
template<bool Directed, typename N>
std::vector<std::unordered_set<N>> edges2neighsets(const std::vector<std::pair<N, N>>& edges, N n)
{
	std::vector<std::unordered_set<N>> neighs(n);
	for (const auto& edge : edges) {
		auto a = std::get<0>(edge);
		auto b = std::get<1>(edge);
		neighs[a].insert(b);
		if (!Directed)
			neighs[b].insert(a);
	}
	return neighs;
}

/*
 * 重み付きグラフで、辺集合表現から隣接集合表現へ変換
 */
template<bool Directed, typename N, typename W>
std::vector<std::unordered_map<N, W>> edges2neighsets(const std::vector<std::tuple<N, N, W>>& edges, N n)
{
	std::vector<std::unordered_set<N>> neighs(n);
	for (const auto& edge : edges) {
		auto a = std::get<0>(edge);
		auto b = std::get<1>(edge);
		auto w = std::get<2>(edge);
		neighs[a].insert({b, w});
		if (!Directed)
			neighs[b].insert({a, w});
	}
	return neighs;
}


/*
 * 重み無し無向グラフの隣接集合表現を受け取り、深さ優先探索してノードをポストオーダーで列挙して関数を呼ぶ
 */
template<typename N, typename F>
void graph_depthfirst_postorder_call(const std::vector<std::unordered_set<N>>& neighs, N n, const F& fn, N start = 0);

template<typename N, typename F>
void graph_depthfirst_postorder_call_impl(std::vector<char>& arrived, const std::vector<std::unordered_set<N>>& neighs, N cur, const F& fn)
{
	for (auto neigh : neighs[cur]) {
		if (arrived[neigh])
			continue;
		arrived[neigh] = 1;
		graph_depthfirst_postorder_call_impl(arrived, neighs, neigh, fn);
	}
	fn(cur);
}

template<typename N, typename F>
void graph_depthfirst_postorder_call(const std::vector<std::unordered_set<N>>& neighs, N n, const F& fn, N start /* = 0 */)
{
	std::vector<char> arrived(n);
	arrived[start] = 1;
	graph_depthfirst_postorder_call_impl(arrived, neighs, start, fn);
}


/*
 * 重み無し無向グラフの隣接集合表現を受け取り、深さ優先探索してノードをポストオーダーで列挙して返す
 */
template<typename N>
std::vector<N> graph_depthfirst_postorder_enum(const std::vector<std::unordered_set<N>>& neighs, N n, N start = 0)
{
	std::vector<N> nodes(n);
	size_t num = 0;
	graph_depthfirst_postorder_call(neighs, n, [&nodes, &num](N node){
		nodes[num++] = node;
	}, start);
	return nodes;
}


int main()
{
	int N, M;
	std::vector<std::pair<int, int>> E;

	std::cin >> N >> M;
	E.resize(M);
	for (auto& e : E) {
		std::cin >> e.first >> e.second;
		--e.first;
		--e.second;
	}

	if (M % 2 == 1) {
		std::cout << "-1\n";
		return 0;
	}

	auto neighs = edges2neighsets<false>(E, N);
	auto nodes = graph_depthfirst_postorder_enum(neighs, N);

	std::vector<char> parity(N);
	for (auto node : nodes) {
		for (auto neigh : neighs[node]) {
			if (parity[node]) {
				std::cout << (node + 1) << " " << (neigh + 1) << "\n";
				parity[node] = 0;
			} else {
				std::cout << (neigh + 1) << " " << (node + 1) << "\n";
				parity[neigh] ^= 1;
			}
			neighs[neigh].erase(node);
		}
	}
}


Measured memory_bytes: 23808
N, K = map(int, input().split())
hhh = list(map(int, input().split()))

dp = [0] * N
dp[0] = 0

for i, h in enumerate(hhh):
    s = 0 if i < K else i-K
    if i == 0:
        continue
    dp[i] = \
        min([abs(h - h_k) + dp_k for h_k, dp_k in zip(hhh[s:i], dp[s:i])])

print(dp[-1])


Measured memory_bytes: 13980
#include<bits/stdc++.h>
using namespace std;
int main(){
	int s=0,a,b;
	cin>>a;
	b=a;
	while(a){
		s+=a%10;
		a/=10;
	}
	if(b%s==0)cout<<"Yes"<<"\n";
	else cout<<"No"<<"\n";
	return 0;
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    string a, b, c;
    cin >> a >> b >> c;
    if (a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0])
        OP("YES");
    else
        OP("NO");
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [list(map(int, input().split())) for _ in range(2)]
ans = 0

for i in range(N):
    ans_cand = 0
    
    for j in range(i+1):
        ans_cand += A[0][j]
    
    for j in range(i, N):
        ans_cand += A[1][j]
    
    ans = max(ans, ans_cand)

print(ans)

Measured memory_bytes: 38768
fun main(args:Array<String>) {
    val s = readLine()!!.split(" ").map{it.toInt()}
    val a = s[0]
    val b = s[1]
    if((a+b)%2 == 1){
        println("IMPOSSIBLE")
    }else{
        println((a+b)/2)
    }
}

Measured memory_bytes: 37616
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef pair<double,double> point;
const ll MAX = 200000;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b,c;
    cin >> a >> b >> c;
    if (a+b+c > 21){
        PRINT("bust");
    }
    else{
        PRINT("win");
    }
}


Measured memory_bytes: 256
from collections import deque
import sys
input = sys.stdin.readline
N, Q = map(int, input().split())
tree = [[] for i in range(N + 1)]
for i in range(N - 1):
    a, b = map(int, input().split())
    tree[a].append([a, b])
    tree[b].append([b, a])
val = [0] * (N + 1)
for i in range(Q):
    p, x = map(int, input().split())
    val[p] += x
ans = [-1] * (N + 1)
ans[1] = val[1]
bfs = deque(tree[1])
while bfs:
    p,n = bfs.popleft()
    if ans[n] == -1:
        ans[n] = val[n]+ans[p]
        for i in tree[n]:
            bfs.append(i)
print(' '.join(list(map(str,ans[1:]))))


Measured memory_bytes: 132728
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
const int MAXN = 1005;
const int MAXV = MAXN*(MAXN-1)/2;
int id[MAXN][MAXN];
 
int order[MAXN][MAXN - 1];
vector<vector<int>> E;
int convert[MAXN][MAXN - 1];

bool reached[MAXV];
bool finished[MAXV];
int dp[MAXV]; // max length of path from v
int dfs(int pos) {
	if (reached[pos]) {
		if (!finished[pos])return -1;
		return dp[pos];
	}
	dp[pos] = 0;
	reached[pos] = true;
	for (int i = 0; i < E[pos].size(); i++) {
		//cout <<"pos == " << pos <<  "to " << E[pos][i] << endl;
		int res = dfs(E[pos][i]);
		if (res == -1)return -1;
		dp[pos] = max(dp[pos], res + 1);
	}
	finished[pos] = true;
	return dp[pos];
}
 
int main() {
  int N;
  cin >> N;
	E.resize(N * (N - 1));
	
	int cnt1 = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (j < i)convert[i][j] = convert[j][i];
			else if(i < j){
				convert[i][j] = cnt1;
				cnt1++;
			}
		}
	}

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N - 1; j++) {
			cin >> order[i][j], order[i][j]--;
			order[i][j] = convert[i][order[i][j]];    
       }
	}

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N - 2; j++) {
			E[order[i][j]].push_back(order[i][j + 1]);
			//cout << order[i][j] << " -> " << order[i][j + 1] << endl;
		}
	}
  int ans = 0;
  rep(i,N) {
    rep(j,N){
      int res = dfs(order[i][j]);
      if (res == -1) {
        puts("-1");
        return 0;
      }
      ans = max(ans, res);
    }
  }
  cout << ans + 1 << endl;
  return 0;
}

Measured memory_bytes: 51584
n = gets.chomp.to_i
spots = []
n.times do
  spots << gets.chomp.split(" ").map(&:to_i)
end
selected_x, selected_y, selected_h = spots.find { |item| item[2] > 0 }

center = []
catch(:break) do 
  0.upto(100) do |x|
    0.upto(100) do |y|
      h = selected_h + (x - selected_x).abs + (y - selected_y).abs
      answer = true
      spots.each do |spot|
        if spot[2] != [h - ((x - spot[0]).abs + (y - spot[1]).abs), 0].max 
          answer = false
          break
        end
      end
      if answer
        center = [x, y, h]
        throw(:break)
      end
    end
  end
end
puts center.join(" ")

Measured memory_bytes: 3836
#include<stdio.h>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
int a[100003];
int main(){
    int n;
    cin>>n;
    int t=0;
    for(int i=1;i<=n;i++){
        int x;
        cin>>a[i];
    }
    for(int i=1;i<n;i++){
        if(i==a[i]){
			swap(a[i],a[i+1]);
			t++;
		}
    }
    for(int i=n;i>1;i--){
        if(i==a[i]){
			swap(a[i],a[i-1]);
			t++;
		}
    }
    cout<<t<<endl;
    return 0;
}
/*

in:
9
1 2 4 9 5 8 7 3 6

out:
3

*/

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    ll Q, H, S, D, N;
    cin >> Q >> H >> S >> D;
    cin >> N;

    ll minPriceS, minPriceD;
    minPriceS = min(4 * Q, min(2 * H, S));
    minPriceD = min(2 * minPriceS, D);
    ll ans = (N / 2) * minPriceD + (N % 2) * minPriceS;

    cout << ans << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline

H, N = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]

INF = 10 ** 15
dp = [INF] * H
dp[0] = 0

answer = INF
for a, b in AB:
  for i in range(H):
    if dp[i] != INF:
      if i + a < H:
        dp[i + a] = min(dp[i + a], dp[i] + b)
      else:
        answer = min(answer, dp[i] + b)

print(answer)

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n,k;
int a[1252];
ll s[1252];

int main(){
  scanf("%d%d",&n,&k);
  REP(i,n)scanf("%d",a+i);
  REP(i,n)s[i+1] = s[i] + a[i];
  vl V;
  REP(l,n)FOR(r,l+1,n+1)V.push_back(s[r]-s[l]);
  ll ans = 0;
  FORR(i,0,41){
    ll v = 1ll<<i;
    int cnt = 0;
    REP(j,V.size())if(V[j]&v)cnt++;
    if(cnt >= k){
      ans += v;
      REP(j,V.size())if(!(V[j]&v))V[j]=0;
    }
  }
  printf("%lld\n",ans);
  return 0;
}


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

const double EPS = 1e-8;

struct Point {
    double x, y;
    Point() {}
    Point(double x, double y) : x(x), y(y) {}
    Point operator+(const Point& p) const { return Point(x + p.x, y + p.y); }
    Point operator-(const Point& p) const { return Point(x - p.x, y - p.y); }
    Point operator*(double k) const { return Point(k * x, k * y); }
    Point operator/(double k) const { return Point(x / k, y / k); }
};
double dot(const Point& a, const Point& b) { return a.x * b.x + a.y * b.y; }
double cross(const Point& a, const Point& b) { return a.x * b.y - a.y * b.x; }
double norm(const Point& a) { return sqrt(dot(a, a)); }
Point rot90(const Point& p) { return Point(p.y, -p.x); } // 時計回りに90度回転 
ostream& operator<<(ostream& os, const Point& p) { return os << "(" << p.x << "," << p.y << ")"; }

int ccw(Point a, Point b, Point c){
    b = b - a; c = c - a;
    if (cross(b, c) > EPS) return +1;      // a,b,cの順に反時計周り
    if (cross(b, c) < -EPS) return -1;     // a,b,cの順に時計周り
    if (dot(b, c) < 0) return +2;          // c--a--b 直線
    if (norm(b) < norm(c)) return -2;      // a--b--c 直線
    return 0;                              // a--c--b 直線
}

istream& operator>>(istream& is, Point& p) { return is >> p.x >> p.y; }

const char* msg[] = {
    "ONLINE_FRONT",
    "CLOCKWISE",
    "ON_SEGMENT",
    "COUNTER_CLOCKWISE",
    "ONLINE_BACK"
};

int main() {
    Point a, b; cin >> a >> b;
    int Q; cin >> Q;
    for (int i = 0; i < Q; i++) {
        Point c; cin >> c;
        int r = ccw(a, b, c) + 2;
        cout << msg[r] << endl;
    }

    return 0;
}

Measured memory_bytes: 1228
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(){
  int N; scanf("%d", &N);
  
  int ans=0, prev=0, cur=0;
  for(int i=0; i<N-1; i++){
    scanf("%d", &cur);
    if(i==0){
      ans += cur;
    }else{
      ans += min(prev, cur);
    }
    prev = cur;
  }
  ans += cur;
  printf("%d\n", ans);
}



Measured memory_bytes: 128
line1 = gets.strip
nums=line1.split(' ').map do |i|
  i.to_i
end
max_num = nums[0]
min_num = nums[1]
s = (max_num / min_num).to_i
puts ([(max_num-s*min_num).abs , (max_num-min_num*(s+1)).abs].min)

Measured memory_bytes: 1788
#include<stdio.h>
int MAX(int a,int b){return a<b?b:a;}
int n,m,i,j,max=0,s[2010][3010],d[2010][3010];
int main(){
	char c;
	scanf("%d %d",&n,&m);
	while(n--){
		scanf("%d %d %c",&j,&i,&c);
		if(c=='B')j+=m;
		if(i%(2*m)/m)j+=m;
		d[i%m][j%(m*2)]++;
	}
	for(i=0;i<m;i++){
		for(j=0;j<2*m;j++)d[i+m][(j+m)%(2*m)]=d[i][j];
	}
  	for(i=0;i<2*m;i++){
      	for(j=0;j<m;j++)d[i][j+2*m]=d[i][j];
    }
	for(i=0;i<2*m;i++){
		for(j=0;j<3*m;j++)s[i+1][j+1]=d[i][j]+s[i+1][j]+s[i][j+1]-s[i][j];
	}
	for(i=0;i<=m;i++){
		for(j=0;j<2*m;j++)max=MAX(max,s[i][j]+s[i+m][j+m]-s[i+m][j]-s[i][j+m]);
	}
	printf("%d\n",max);
	return 0;
}

Measured memory_bytes: 47360
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
const int dy[] = {2, 2, 2, -1, 0, 1, -2, -2, -2, -1, 0, 1};
const int dx[] = {-1, 0, 1, 2, 2, 2, -1, 0, 1, -2, -2, -2};
int n;
int sy[10], sx[10];
bool inRange(int y, int x)
{
    if(y < 0 or x < 0 or y >= 10 or x >= 10) return false;
    return true;
}
bool dfs(int py, int px, int depth)
{
    if(depth == n) return true;
    vector<vector<int>> field(10, vector<int>(10, 0));
    for(int i = -1; i <= 1; i++)
    {
        for(int j = -1; j <= 1; j++)
        {
            int ny = sy[depth] + i, nx = sx[depth] + j;
            if(inRange(ny, nx)) field[ny][nx] = 1;
        }
    }
    bool res = false;
    for(int i = 0; i < 12; i++)
    {
        int ny = py + dy[i];
        int nx = px + dx[i];
        if(not inRange(ny, nx)) continue;
        if(field[ny][nx]) res |= dfs(ny, nx, depth + 1);
    }
    return res;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int px, py;
    while(cin >> px >> py, px | py)
    {
        cin >> n;
        for(int i = 0; i < n; i++) cin >> sx[i] >> sy[i];
        cout << (dfs(py, px, 0) ? "OK" : "NA") << endl;
    }
    return 0;
}




Measured memory_bytes: 3120
while True:
    
    a,op,b = input().split()
    a = int(a); b = int(b)
    
    if op=="?":
        break
    elif op=="+":
        print(a+b)
    elif op=="-":
        print(a-b)
    elif op=="*":
        print(a*b)
    elif op=="/":
        print(a//b)


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define ll long long
#define ull unsigned long long
#define ld long double
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rrep(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define pll pair<long long,long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vvc vector<vector<char>>
#define vc vector<char>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define maxe(x) *max_element(all(x))
#define mine(x) *min_element(all(x))
#define Size(x) ((int)(x).size())
#define umap unordered_map
const long long INF = 1LL << 60;
const long double pi = 3.1415926535897932;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

    template<class T> inline bool chmin(T& a, T b) {
        if (a > b) {
            a = b;
            return true;
        }
        return false;
    }
    template<class T> inline bool chmax(T& a, T b) {
        if (a < b) {
            a = b;
            return true;
        }
        return false;
    }

//lis,modpow,uf,modncr,soinsubunkai,yakusurekkyo,gyakugen
//mint,dijkstra

    signed main(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        ll n,m,x;
        cin>>n>>m>>x;
        ll l=0;
        ll r=0;
        rep(i,m){
            ll a;
            cin>>a;
            if(a<x)l++;
            else r++;
        }
        cout<<min(l,r)<<endl;
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main() {
  LL x, y, z, k;
  cin >> x >> y >> z >> k;
  vector<LL> a(x), b(y), c(z);
  rep(i, x) cin >> a[i];
  rep(i, y) cin >> b[i];
  rep(i, z) cin >> c[i];

  vector<LL> ab;
  for (int i = 0; i < x; i ++) {
    for (int j = 0; j < y; j ++) {
      ab.push_back(a[i] + b[j]);
    }
  }
  sort(all(ab));
  priority_queue<LL> pq;
  int n = ab.size();
  for (int i = n - 1; i >= max((LL)0, n - k); i--) {
    for (int j = 0; j < z; j ++) {
      pq.push(ab[i] + c[j]);
    }
  }

  rep(i, k) {
    cout << pq.top() << endl;
    pq.pop();
  }
}

Measured memory_bytes: 42856
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
	int N,a[200000],flag=1;
	scanf("%d",&N);
	for(int i=0;i<N;i++)
	scanf("%d",&a[i]);
	sort(a,a+N);
	for(int i=1;i<N;i++)
	{
		if(a[i]==a[i-1])
		{
			printf("NO\n");
			return 0;
		}
	}
	printf("YES\n");
	return 0;
}


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

using namespace std;

using ll = long long;

const ll inf = 1000000000000000000;

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

	int n, K;
	cin >> n >> K;

	vector<int> h;
	h.resize(n);

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

	vector<vector<vector<ll> > > dp;

	dp.resize(n + 1);

	for(int i = 0; i < n + 1; ++i) {
		dp[i].resize(n + 1);

		for(int j = 0; j < n + 1; ++j) {
			dp[i][j].assign(n + 1, inf);
		}
	}

	dp[0][0][0] = 0;

	vector<int> v = h;

	v.emplace_back(0);

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

	v.erase(unique(v.begin(), v.end()), v.end());

	vector<int> id;
	id.resize(n);

	for(int i = 0; i < n; ++i) {
		id[i] = lower_bound(v.begin(), v.end(), h[i]) - v.begin();
	}

	for(int i = 0; i < n; ++i) {
		vector<vector<ll> > pre;
		pre.resize(n + 1);

		for(int i = 0; i < n + 1; ++i) {
			pre[i].resize(n + 1);
		}
		
		vector<vector<ll> > suf;
		suf.resize(n + 1);

		for(int i = 0; i < n + 1; ++i) {
			suf[i].resize(n + 1);
		}
		
		for(int j = 0; j <= K; ++j) {
			pre[j][0] = dp[i][j][0] - v[0];

			for(int k = 0; k + 1 < v.size(); ++k) {
				pre[j][k + 1] = min(pre[j][k], dp[i][j][k + 1] - v[k + 1]);
			}
		}

		for(int j = 0; j <= K; ++j) {
			suf[j][(int)v.size() - 1] = dp[i][j][(int)v.size() - 1];
			
			for(int k = (int)v.size() - 2; k >= 0; --k) {
				suf[j][k] = min(suf[j][k + 1], dp[i][j][k]);
			}
		}
		
		for(int j = 0; j <= K; ++j) {
			for(int k = 0; k < v.size(); ++k) {
				dp[i + 1][j][id[i]] = min(dp[i + 1][j][id[i]], dp[i][j][k] + max(0, v[id[i]] - v[k]));
			} 
	
			if(j < K) {
				for(int k = 0; k < v.size(); ++k) {
					dp[i + 1][j + 1][k] = min(dp[i + 1][j + 1][k], v[k] + pre[j][k]);
					dp[i + 1][j + 1][k] = min(dp[i + 1][j + 1][k], suf[j][k]);
				}
			}
		}
	}

	cout << *min_element(dp[n][K].begin(), dp[n][K].end()) << '\n';

	return 0;

}

Measured memory_bytes: 217704
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cassert>
#include <utility>
#include <numeric>
#include <cstring>
using namespace std;
using ll = long long;

int main(){
    int N,D;
    cin >> N>> D;
    cout << ceil(float(N) / (2*D+1))  ;

}

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

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

vector<vector<ll>> dp(100010, vector<ll>(15,0)); //[keta][mod]
string s;
int d;

int main(){
  cin >> s;
  d = s.size();
  dp[0][0]=1;
  for(int i=0; i<d; i++){ rep(j,13){
    if(s[i]=='?'){ 
      rep(k,10){
        dp[i+1][(j*10+k)%13] += dp[i][j];
        dp[i+1][(j*10+k)%13] %= mod;
      }
    } else {
      dp[i+1][(j*10+(s[i]-'0'))%13] += dp[i][j];
      dp[i+1][(j*10+(s[i]-'0'))%13] %= mod;
    }
  }}

  cout << dp[d][5] << endl;
  return 0;  
}

Measured memory_bytes: 15360
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int h = in.nextInt();
		int w = in.nextInt();
		char[][] map = new char[h][w];
		int[][] hmap = new int[h][w]; // 横方向
		int[][] vmap = new int[h][w]; // 縦方向

		for ( int i = 0; i < h; i++ ) {
			map[i] = in.next().toCharArray();
		}
		in.close();

		int cnt = 0;
		// 横の処理
		for ( int r = 0; r < h; r++ ) {
			cnt = 0;
			for ( int c = 0; c < w; c++ ) {
				if ( map[r][c] == '.' ) {
					cnt++;
					hmap[r][c] += cnt;
				} else if ( map[r][c] == '#' ) {
					cnt = 0;
				}
			}

			for ( int c = w - 2; 0 <= c; c-- ) {
				if ( map[r][c] == '#' ) {
					continue;
				} else if ( map[r][c + 1] == '.' ) {
					hmap[r][c] = hmap[r][c + 1];

				}
			}
		}

		// 縦の処理
		for ( int c = 0; c < w; c++ ) {
			cnt = 0;
			for ( int r = 0; r < h; r++ ) {
				if ( map[r][c] == '.' ) {
					cnt++;
					vmap[r][c] = cnt;
				} else if ( map[r][c] == '#' ) {
					cnt = 0;
				}
			}

			for ( int r = h - 2; 0 <= r; r-- ) {
				if ( map[r][c] == '#' ) {
					continue;
				} else if ( map[r + 1][c] == '.' ) {
					vmap[r][c] = vmap[r + 1][c];
				}
			}
		}

//		for ( int r = 0; r < h; r++ ) {
//
//			for ( int c = 0; c < w; c++ ) {
//				System.out.print(hmap[r][c]);
//			}
//			System.out.println();
//		}
//		
//		System.out.println();
//		
//		
//		for ( int r = 0; r < h; r++ ) {
//
//			for ( int c = 0; c < w; c++ ) {
//				System.out.print(vmap[r][c]);
//			}
//			System.out.println();
//		}
		
		int ans = 0;
		for ( int r = 0; r < h; r++ ) {
			for ( int c = 0; c < w; c++ ) {
				ans = Math.max(ans, hmap[r][c] + vmap[r][c] - 1);
			}
		}
		System.out.println(ans);
	}
}

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

const int MAXL = 1e4 + 5;
const int MAXD = 1e2 + 5;
const ll MOD = 1e9 + 7;
ll dp[MAXL][MAXD];

int main() {
    string s;
    int d;
    cin >> s >> d;
    int l = s.length();
    int sf = 0;
    dp[0][0] = 1;
    for(int i = 0; i < l; i++) {
        for(int res = 0; res < d; res++) {
            for(int dig = 0; dig < 10; dig++) {
                dp[i + 1][(res + dig) % d] = (dp[i + 1][(res + dig) % d] + dp[i][res]) % MOD;
            }
        }
        for(int dig = s[i] - '0' + 1; dig <= 9; dig++)
            dp[i + 1][(sf + dig)%d] = (dp[i + 1][(sf + dig) % d] - 1 + MOD) % MOD;
        sf += (s[i] - '0');
        sf %= d;
    }
    cout << (dp[l][0] + MOD - 1) % MOD << endl;
}

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

int main()
{
  int h,w;
  cin >> h >> w;
  
  bool dat[52][52] = {};
  for(int i = 0; i<h;i++)
  {
    char tmp[50 + 1];
    cin >> tmp;
    for(int j = 0; j<w;j++)
    {
      dat[i + 1][j + 1] = tmp[j] == '#';
    }
  }
  for(int i = 1; i<h+1;i++)
  {
    for(int j = 1; j<w+1;j++)
    {
      if(dat[i][j])
      {
        if(!(dat[i-1][j] || dat[i][j-1]  || dat[i][j+1] || dat[i+1][j]))
        {
          cout << "No" << endl;
          return 0;
        }
      }
    }
  }
  
          cout << "Yes" << endl;
          return 0;
}

Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))
maxh = max(H)
ans = 0
for h in range(1, maxh+1):
  above = False
  for k in range(N):
    if H[k] >= h:
      if not above:
        ans += 1
    above = H[k] >= h
print(ans)

Measured memory_bytes: 3060
import java.util.*;
public class Main {
public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
  	int N = sc.nextInt();
  	int[] x = new int[N];
	for (int i=0;i<N;i++){
		x[i] = sc.nextInt();
	}
  	Arrays.sort(x);
  	int tairyoku = 0;
  	int min = Integer.MAX_VALUE;
  	for (int p=x[0];p<=x[N-1];p++){
      tairyoku = 0;
      for(int j=0;j<N;j++){
        tairyoku = tairyoku + (x[j]-p)*(x[j]-p);
      }
      if(min > tairyoku){
        min = tairyoku;
      }
      //System.out.println("p:"+p+",tairyoku:"+tairyoku);
    }

	System.out.println(min);
}
}

Measured memory_bytes: 25300
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <numeric>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, k, n) for(int i = (k); i < (int)(n); i++)
using namespace std;
using ll = long long;
int N, cnt = 0, ans = 0, tmp = 0;

int main(){
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a + 3);
    cout << a[0] + a[1] << endl;
    return 0;
    
}

Measured memory_bytes: 256
n=int(input())
l=[0]*n
l=list(map(int,input().split()))
ans=0
for i in range(n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      #print(i,j,k)
      if (l[i]+l[j]>l[k] and l[j]+l[k]>l[i] and l[k]+l[i]>l[j]  and l[i]!=l[j] and l[i]!=l[k] and l[j]!=l[k]):
        #print(i+1,j+1,k+1)
        ans+=1
        
print(ans)
      

Measured memory_bytes: 9008
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int INF = 100100100;
const double PI = 3.14159265358979323846;
typedef long long ll;
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define REP(i, n) for (ll i = 0; i < (n); ++i)

int main() {
  ll n, count = 0;
  string s;
  cin >> n >> s;
  REP(i, n - 2) {
    string threeChar = s.substr(i, 3);
    if (threeChar == "ABC") ++count;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func main() {
    let line = readInts()
    let amari = (line[0] * line[1]) % 2
    let result = amari == 0 ? "Even" : "Odd"

    print("\(result)")
}

main()

Measured memory_bytes: 8240