akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n,v) rep(i,n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
int x_pos[4] = {1,0,-1,0}, y_pos[4] = {0,1,0,-1};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

char upper(char c){
	return c-0x20;
}

char lower(char c){
	return c+0x20;
}

void unique_vector(vector<int>& v){
	sort(all(v));
	v.erase(unique(all(v)), v.end());
}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main() {
    int n;cin >> n;
    map<pair<ll,ll>,int> mp;
    vector<pii> v(n);
    rep(i,n){
        int x,y;cin>>x>>y;
        v[i] = make_pair(x,y);
    }
    rep(i,n){
        rep(j,n){
            if(i==j)continue;
            ll x = v[j].first - v[i].first;
            ll y = v[j].second - v[i].second;
            pair<ll,ll> xy = make_pair(x,y);
            mp[xy]++;
        }
    }
    int M = 0;
    for(auto itr = mp.begin(); itr != mp.end(); itr++){
        M = max(M,itr->second);
    }
    cout << n-M << endl;
}



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

using namespace std;

int cnt;
const int maxn = 2e5 + 5;
int head[maxn * 2];

struct Edge {
    int from, to;
    int nxt;
}e[maxn * 2];

long long sz[maxn * 2];

void addedge(int u, int v) {
    e[cnt].from = u;
    e[cnt].to = v;
    e[cnt].nxt = head[u];
    head[u] = cnt++;

    e[cnt].from = v;
    e[cnt].to = u;
    e[cnt].nxt = head[v];
    head[v] = cnt++;
}


void dfs(int now, int fa = 0) {
    sz[now] += sz[fa];
    for (int i = head[now]; i != -1; i = e[i].nxt) {
        int to = e[i].to;
        if (to != fa) {
            dfs(to, now);
        }
    }
    return ;
}


int main() {
    memset(head, -1, sizeof(head));
    int n, q;
    scanf("%d %d", &n, &q);
    for (int i = 1; i <= n - 1; ++i) {
        int a, b;
        scanf("%d %d", &a, &b);
        addedge(a, b);
    }
    for (int i = 1; i <= q; ++i) {
        int p, x;
        scanf("%d %d", &p, &x);
        sz[p] += x;
    }
    dfs(1);
    for (int i = 1; i <= n; ++i) {
        printf("%lld ", sz[i]);
    }
    return 0;
}

Measured memory_bytes: 17536
a,b = map(int,input().split())
if a <= 0 and b >= 0:
    print('Zero')
elif a == 0 or b == 0:
    print('Zero')
elif a > 0:
    print('Positive')
else:
    if (b-a) % 2 != 0:
        print('Positive')
    else:
        print('Negative')


Measured memory_bytes: 38384
//From Naruto to Hokage
//#include <RJ>
#include<bits/stdc++.h>
using namespace std;

#define ll          long long
#define pb          push_back
#define eb          emplace_back
#define endl        '\n'
#define mii         map<ll,ll>
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define INF         (1ll<<60)
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N=100005;
void solve(){
    ll n,d,ans=0;
    cin>>n>>d;
    ll arr[n][d];
    rep(i,0,n-1) rep(j,0,d-1) cin>>arr[i][j];
    rep(i,0,n-1){
        rep(j,i+1,n-1){
            double dis=0;
            rep(k,0,d-1)
            dis+=((arr[i][k]-arr[j][k])*(arr[i][k]-arr[j][k]));
            ll k=sqrt(dis);
            if(k*k==dis) ans++;
        }
    }
    cout<<ans;
}
signed main()
{
    ios
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        solve();
    }
    time
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)

//struct position{int x;};

int main(void){
	int n,m,a,b;
	vector<int> count;
	cin>>n>>m;
	rep(i,n+1){
		count.push_back(0);

	}
	rep(i,m){
		cin>>a>>b;
		count[a]++;
		count[b]++;
	}
	reps(i,n){
		if(count[i]%2==1){
			cout<<"NO"<<endl;
			return 0;
		}
	}
	cout<<"YES"<<endl;
	
	return 0;
}


Measured memory_bytes: 1020
#include<iostream>
#include<string>
#include<queue>
using namespace std;
int n;
string a[10],b[10],c,d;
int F()
{
	int i,j,x=0;
	queue<string>q;
	string s,t;
	q.push(c);
	q.push("");
	while(x<10)
	{
		s=q.front();
		q.pop();
		if(s==d)return x;
		else if(s.empty()){++x;q.push(s);continue;}
		else if(s.size()<d.size())
			for(i=0;i<n;++i)
			{
				t=s;
				for(j=0;(j=t.find(a[i],j))!=string::npos;j+=b[i].size())
					t.replace(j,a[i].size(),b[i]);
				if(t!=s)q.push(t);
			}
	}
	return -1;
}
int main()
{
	while(cin>>n,n)
	{
		for(int i=0;i<n;++i)cin>>a[i]>>b[i];
		cin>>c>>d;
		cout<<F()<<endl;
	}
	return 0;
}

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

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b, a % b);
}

using Graph = vector<vector<int>>;

ll calc(ll a, ll b, ll p){//aのb乗をpで割った余り
  if(b == 0) return 1;

  else if(b%2 == 0){
    ll d = calc(a,b/2,p);
    return (d*d)%p;
  }
  else if(b%2 == 1){
    return (a * calc(a,b-1,p))%p;
  }
}

typedef pair<int,int> P;

bool is_prime(int n){//nが素数であるかどうか判定 iで割り切れると素数でない
    if(n == 1) return false;//1は例外
    for(int i = 2;i*i <= n;i++){
        if(n%i == 0) return false;
    }
    
    return true;
}
int factorial(int a){
  int res = 1;
  while(a){
    res *= a;
    a--;
  }
  return res;
}

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  int m = max(a,max(b,c));
  if(m == a+b+c - m) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
N,D = map(int,input().split())
X = []
for i in range(N):
  X.append(list(map(int,input().split())))
  
ans = 0
for i in range(N - 1):
  for j in range(i + 1,N):
    a = 0
    for k in range(D):
      a += (X[i][k] - X[j][k]) ** 2
    if int(a ** 0.5) == a ** 0.5:
      ans += 1
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REP2(i, s, n) for(int i = (s); i < (int)(n); i++)
ll PowMod(ll N, ll P, ll M) {   // Calc N^P mod M ()
    if(P == 0) return 1;
    if(P%2 == 0) {
        ll t = PowMod(N, P/2, M);
        return (t%M)*(t%M);
    }
    return N*PowMod(N, P-1, M)%M;
} 


int main() {
    int d = 1;
    int ret = 0;
    int N, M;
    cin >> N >> M;
    vector<int> S(M), C(M);
    vector<int> R(N + 1, -2);
    if(M == 0) {
        if(N == 1) {
            ret = 0;
        } else if(N == 2) {
            ret = 10;
        } else {
            ret = 100;
        }
            goto OUTPUT;
    }
    

    REP(i, M) {
        cin >> S.at(i) >> C.at(i);
    }

    // 桁をみる
 

    REP(i, M) {
        if(R.at(S.at(i) - 1) == -2) {
            R.at(S.at(i) - 1) = C.at(i);
        } else {
            if(R.at(S.at(i) - 1) != C.at(i)) {
                ret = -1;
                goto OUTPUT;
            }
        }
    }
    // うめ
    if(N == 3) {
        if(R.at(0) != -2) {
            if(R.at(1) == -2) {
                R.at(1) = 0;
            }
            if(R.at(2) == -2) {
                R.at(2) = 0;
            }
        } else {
            R.at(0) = 1;
            if(R.at(1) == -2) {
                R.at(1) = 0;
            }
            if(R.at(2) == -2) {
                R.at(2) = 0;
            }
        }

        if(R.at(0) == 0) {
            ret = -1;
            goto OUTPUT;
        }
    } else if(N == 2) {
        if(R.at(0) != -2) {
            if(R.at(1) == -2) {
                R.at(1) = 0;
            }
        } else {
            R.at(0) = 1;
        }

        if(R.at(0) == 0) {
            ret = -1;
            goto OUTPUT;
        }
    } else if(N == 1) {
        if(R.at(0) == -2) {
            ret = -1;
            goto OUTPUT;
        }
    }

    REP(i, N) {
        ret += R.at(N - i - 1) * d;
        d *= 10;
    }

OUTPUT:
    cout << ret << endl;
}

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

int main(){
	float xa[2], xb[2], ya[2], yb[2];
	while (cin >> xa[0] >> ya[0] >> xa[1] >> ya[1] >> xb[0] >> yb[0] >> xb[1] >> yb[1]){
		if(xa[0]<=xb[1] && ya[0] <= yb[1] && xa[1] >= xb[0] && ya[1] >= yb[0]){
			cout << "YES" << endl;
		}
		else{
			cout << "NO" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3040
import java.util.Scanner;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Blulogix
 */
public class Main{
    public static void main(String[] args)throws Exception {
       Scanner in=new Scanner(System.in);
        int a=in.nextInt();
        int b=in.nextInt();
        
      String out=a+""+b;
      double output=Math.sqrt(Integer.parseInt(out));
      int out1=(int)output;
      if(output==out1){
          System.out.println("Yes");
      }else{
          System.out.println("No");
      }
    }
}


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

using namespace std;
typedef long long ll;

int main() {
  ios::sync_with_stdio(0); 
  cin.tie(0); 
  
  string s; cin >> s;

  sort(begin(s), end(s));
  if (s == "abc") cout << "Yes" << "\n";
  else cout << "No" << "\n";
}


Measured memory_bytes: 3632
n = int(input())
s = [input() for i in range(3)]
c = 0
for i in range(len(s[0])):
    if s[0][i] == s[1][i] == s[2][i]:
        continue;
    if s[0][i] == s[1][i] or s[1][i] == s[2][i] or s[2][i] == s[0][i]:
        c+=1
    else :
        c+=2
print(c)


Measured memory_bytes: 3060
#include<iostream>
#include<string>
#define LL long long
#define INF 0x3f3f3f3f
#define io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
const int N=2e5+100;
using namespace std;
pair<LL,LL>a[N];
int main()
{
	int n;
	while(cin>>n)
	{
		for(int i=1;i<=n;i++)cin>>a[i].first>>a[i].second;
		if(a[1].first==a[1].second)a[1].first=a[1].second=1;
		for(int i=2;i<=n;i++)
		{
			LL tmp=max((a[i-1].first-1)/a[i].first+1,(a[i-1].second-1)/a[i].second+1);
			a[i].first*=tmp;
			a[i].second*=tmp;
		}
		cout<<a[n].first+a[n].second<<endl;
	}
	return 0;
}


Measured memory_bytes: 3532
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int sum = 0;
			int max = -1000000;
			int n = sc.nextInt();
			if( n == 0) break;
			int[] a = new int[n];
			for(int i = 0; i < n ; i++){
				a[i] = sc.nextInt();
			}
			for(int i = 0;i < n ; i++){
					sum = 0;
				for(int j = i ; j < n ; j++){
					sum += a[j];
					if(sum >= max){
						max = sum;
					}
				}
			}
			System.out.println(max);
		}
	}
}

Measured memory_bytes: 26996
#include <bits/stdc++.h>
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<ll, ll>;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
ll bpow(ll b, ll p, ll m = 1000000007LL) {
  ll rt = 1;
  for (; p; p >>= 1, b = b * b % m)
    if (p & 1)
      rt = rt * b % m;
  return rt;
}
int main() {
  IOS;
  int l, r, d, ans = 0;
  cin >> l >> r >> d;
  for (int i = l; i <= r; i++)
    if (i % d == 0)
      ans++;
  cout << ans << endl;
}

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

int main()
{
  int k; cin >> k;
  int ans=0;
  for (int a=1; a<=k; a++) {
    for (int b=1; b<=k; b++) {
      for (int c=1; c<=k; c++) {
        ans += __gcd(__gcd(a,b), c);
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3624
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from sys import stdin

n = int(input())
x_list_str = stdin.readline().rstrip().split()
x_list = [int(i) for i in x_list_str]

# 体力のリスト
sum_hp_list = []

min_x = min(x_list)
max_x = max(x_list)

if min_x == max_x:
    print(0)
    exit()

for i in range(min_x, max_x):
    sum_hp = 0
    for x in x_list:
        sum_hp += (x-i)**2
    sum_hp_list.append(sum_hp)

print(min(sum_hp_list))


Measured memory_bytes: 3060
from collections import deque

K = int(input())
que = deque(list(range(1, 10)))

c = 0
while que:
    n = que.popleft()
    s = str(n)

    flg = True

    for i in range(1, len(s)):
        if abs(int(s[i])-int(s[i-1])) >= 2:
            flg = False

    if flg:
        c += 1

    if c == K:
        print(s)
        exit()

    if n % 10 != 0:
        que.append(n*10+n % 10-1)

    que.append(n*10+n % 10)

    if n % 10 != 9:
        que.append(n*10+n % 10+1)


Measured memory_bytes: 50268
def DigitsSum(n):
    sum = 0
    while (n != 0):
        sum += (n % 10)
        n = int(n / 10)
    return sum

N = int(input())

min_sum = 10**5
for i in range(1, N):
    sum = DigitsSum(i) + DigitsSum(N-i)
    if (sum < min_sum):
        min_sum = sum

print(min_sum)


Measured memory_bytes: 3060
/* Simplicity and Goodness */

#include <bits/stdc++.h>
using namespace std;
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld ",n)
#define pri(n) printf("%d ",(int)n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define deb(x) cout << #x << ' ' << x << '\n'
#define rep(i,ini,n) for(int i=ini;i<(int)n;i++)
#define per(i,ini) for(int i=ini;i>=0;i--)
#define tc int tt; scn(tt); while(tt --)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 1e9+7;
const int N = 2e5+2;


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

    int sum = min(a, k); k -= a;

    k -= b;

    if(k <= 0)
    prin(sum);
    else
    {
        sum -= k;
        prin(sum);
    }

    return 0;
}

Measured memory_bytes: 3752
using System;
using System.Linq;

namespace AtcoderCsharp
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] NA = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long[] cards = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long[][][] dp = new long[NA[0]+1][][];
            for (long i = 0; i < NA[0] + 1; i++)
            {
                dp[i] = new long[NA[0]+1][];
                for(long j = 0;j< NA[0]+1;j++)
                dp[i][j] = new long[NA[0] * NA[1]+1];
            }
            dp[0][0][0] = 1;
            for (long i = 1; i < NA[0]+1; i++)
            {
                for (long j = 0; j < NA[0] + 1; j++)
                {
                    //i枚目まで見て、j枚使って、3番目の数を作る方法
                    for (long k = 0; k <= NA[0] * NA[1]; k++)
                    {
                        try
                        {
                            dp[i][j][k] += dp[i - 1][j][k];
                        }
                        catch { }
                        try
                        {
                            dp[i][j][k] += dp[i - 1][j - 1][k - cards[i - 1]];
                        }
                        catch { continue; }
                    }
                }
            }
            long output = 0;
            for (long i = 0; i <= NA[0]; i++)
            {
                output += dp[NA[0]][i][i * NA[1]];
            }
            Console.WriteLine(output - 1);
        }
    }
}


Measured memory_bytes: 63432
#include<iostream>
#include<algorithm>

using namespace std;

int main(){

  int W,H,x,y,r;


  cin  >> W>>H>>x>>y>>r ;

  if(r<=y&&y<=H-r&&r<=x&&x<=W-r) 
    cout<<"Yes"<<endl;

  else 
    cout<<"No"<<endl;

  return 0;

}

Measured memory_bytes: 1156
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <map>
#include <vector>
#include <iomanip>

using namespace std;

int main(void) {
  long N, M;
  cin >> N >> M;
  if (M <= N * 2) {
    cout << M / 2 << endl;
    return 0;
  }
  cout << N + (M - N * 2) / 4 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int n; cin >> n;
	int ans = INF;
	while( n-- ){
		int k; cin >> k;
		int t = 0;
		while( k % 2 == 0 ){
			k /= 2;
			++t;
		}
		ans = min( ans, t );
	}
	cout << ans << endl;
	return 0;
}

// 1:33

Measured memory_bytes: 256
MAX_N = 10 ** 5
SQRT_MN = 318
isp = [1] * (MAX_N + 1)
p_list = []
isp[0] = isp[1] = 0
for i in range(2, SQRT_MN + 1):
	if isp[i] == 0:
		continue
	p_list.append(i)
	for prod in range(2, MAX_N // i + 1):
		isp[i * prod] = 0

like_num = [0] * (MAX_N + 1)
for p in range(3, MAX_N + 1):
	if isp[p] and isp[(p + 1) // 2]:
		like_num[p] = 1
	like_num[p] += like_num[p - 1]

Q = int(input())
for i in range(Q):
	l, r = map(int, input().split())
	print(like_num[r] - like_num[l - 1])


Measured memory_bytes: 8948
#include<bits/stdc++.h>
#define ll long long

using namespace std;

int main(){
	int n; cin >> n;
	vector<int>a(n);
	for(int& i: a)cin >> i;
	int c = 1;
	int ans = 0;
	for(int i = 0;i < n;i++){
		if(a[i] == c){
			c++;
		}
		else{
			ans++;
		}
	}
	if(ans == n){
		cout << -1;
	}
	else{
		cout << ans;
	}
}

Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <map>

using namespace std;

int main() {
  int n;
  string s;

  cin >> n >> s;

  string temp = "ABC";

  int num = 0;
  for(int i = 0; i < n-2; i++){
    string t = s.substr(i,3);

    if(t == temp){
      num++;
    }
  }

  cout << num << endl;

  return 0;
}

Measured memory_bytes: 256
def main():
    N=int(input())
    A=list(map(int,input().split()))
    AA=[(v,i) for i,v in enumerate(A)]
    AA.sort(reverse=True)
    dp=[[0]*(N+1) for _ in range(N+1)]
    for len in range(1,N+1):
        val,index=AA[len-1]
        for x in range(0,len+1):
            y=len-x
            if x==0:
                dp[x][y]=dp[x][y-1]+val*abs(N-y-index)
            elif y==0:
                dp[x][y]=dp[x-1][y]+val*abs(index-x+1)
            else:
                dp[x][y]=max(dp[x][y-1]+val*abs(N-y-index),dp[x-1][y]+val*abs(index-x+1))
    maxes=[]
    for i in dp:
        maxes.append(max(i))
    return max(maxes)
print(main())

Measured memory_bytes: 136076
n, m = map(int, input().split())
h = list(map(int, input().split()))
D = dict()
for i in range(1, n+1):
    D[i] = h[i-1]
L = [1 for i in range(n)]
for _ in range(m):
    a, b =map(int, input().split())
    if D[a] > D[b]:
        L[b-1] = 0
    elif D[a] == D[b]:
        L[a-1] = 0
        L[b-1] = 0
    else:
        L[a-1] = 0
ans = 0
for e in L:
    ans += e
print(ans)

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

using namespace std;
typedef long long ll;
const ll mx = 10000007;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
#define    ss   second
#define    ff   first
#define    pb   push_back
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
#define FIO ios_base::sync_with_stdio(false);  cin.tie(NULL);


int main() {
    FIO;
    ll n, k;
    cin >> n >> k;
    map<ll, ll>m;
    set<ll>su;
    for (ll i = 0; i < n; i++) {
        ll x;
        cin >> x;
        m[x]++;
        su.insert(x);
    }
    if( su.size() <= k) {
        cout << 0 << endl;
        return 0;
    }
    vector<pair<ll, ll>>v;
    for (auto i = m.begin(); i != m.end(); i++) {
        v.push_back({i->second, i->first});
    }
    ll s = 0;
    sort(v.begin(), v.end());
    for(ll i = 0; i < su.size() - k; i++) {
        s += v[i].first;
    }
    cout << s << endl;
}



Measured memory_bytes: 29192
a = []
b = []

r,c = map(int,input().split())
a = [list(map(int,input().split())) for _ in range(r)]

for i in range(c):
    x=0
    for i2 in range(r):
        x += a[i2][i]
    b.append(x)
a.extend([b])

for i in range(r+1):
    a[i].append(sum(a[i]))
    print(' '.join(map(str,a[i])))


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

const string YES = "Yes";
const string NO = "No";

void solve(long long N, std::vector<long long> A, std::vector<long long> B) {
    vector<pair<ll, ll>> pairvec;
    rep(i, N) { pairvec.push_back(pair<ll, ll>(B[i], A[i])); }
    sort(pairvec.begin(), pairvec.end());
    ll t = 0;
    rep(i, N) {
        t += pairvec[i].second;
        if (t > pairvec[i].first) {
            cout << NO << endl;
            return;
        }
    }
    cout << YES << endl;
}

int main() {
    long long N;
    scanf("%lld", &N);
    std::vector<long long> A(N);
    std::vector<long long> B(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &A[i]);
        scanf("%lld", &B[i]);
    }
    solve(N, std::move(A), std::move(B));
    return 0;
}


Measured memory_bytes: 10600
def dfs(map, ys, xs, yg, xg, n)
  return 11 if n > 10
  min = 11
  [[1, 0], [-1, 0], [0, 1], [0, -1]].each do |dy, dx|
    v, u = ys + dy, xs + dx
    next if v < 0 or v >= map.size or u < 0 or u >= map[0].size or map[v][u] == 1
    v, u = v + dy, u + dx until v < 0 or v >= map.size or u < 0 or u >= map[0].size or (v == yg && u == xg) or map[v][u] == 1
    return n if v == yg && u == xg
    next if v < 0 or v >= map.size or u < 0 or u >= map[0].size
    map[v][u] = 0
    ret = dfs(map, v - dy, u - dx, yg, xg, n + 1)
    min = ret if ret < min
    map[v][u] = 1
  end
  return min
end

loop do
  w, h = gets.split.map(&:to_i)
  break if w == 0
  map = (1..h).map { gets.split.map(&:to_i) }
  start = goal = nil
  (0..h-1).each do |i|
    (0..w-1).each do |j|
      start = [i, j] if map[i][j] == 2
      goal = [i, j] if map[i][j] == 3
      map[i][j] = 0 unless map[i][j] == 1
    end
  end
  k = dfs(map, *start, *goal, 1)
  p k == 11 ? -1 : k
end



Measured memory_bytes: 6876
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <map>
#include <math.h>
#include <algorithm> // std::sort, std::min
#include <iomanip> // std::setprecision
#include <cmath> // std::ceil
#include <numeric> // std::gcd
#include <limits> // std::numeric_limits<long int>::max()

using namespace std;
typedef long long ll;
#define INF 1999999999
#define MODA 1000000007 

template<typename T>
T powint (const T& x, const T& y) {
  T ret = 1;
  for(int i=0; i<y; ++i) ret *= x;
  return ret;
}

int main() {
  ll H;
  cin >> H;

  ll ans = 0;
  ll nummonster = 1;
  while(H > 0) {
    ans += nummonster;
    H /= 2;
    nummonster *= 2;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3596
#include<iostream>
using namespace std;
const int size=1e5+5;
const int level = 60;
typedef long long int ll;
ll basis[level];
void add(ll mask)
{
    for(int i=level-1;i>=0;i--)
    {
        if(((mask>>i)&1) == 0)
            continue;
        if(!basis[i])
        {
            basis[i] = mask;
            return;
        }
        mask ^= basis[i];
    }
}
int main()
{
    int n;
    cin>>n;
    ll arr[n];
    ll total = 0;
    for(int i=0;i<n;i++)
        cin>>arr[i],total ^= arr[i];
    ll ans = 0;
    for(int i=0;i<level;i++)
    {
        if((total>>i)&1)
        {
            for(int j=0;j<n;j++)
                if((arr[j]>>i)&1)
                arr[j] -= (1LL<<i);
        }
    }
    for(int i=0;i<n;i++)
        add(arr[i]);
    for(int i=level-1;i>=0;i--)
    {
        if(!basis[i])
            continue;
        if((ans>>i)&1) continue;
        ans ^= basis[i];
    }
    cout<<(ans+(ans+total))<<"\n";
    return 0;
}


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

int main(){
	
	int N, K;

    cin >> N >> K;

    vector<int> h(N);

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

    int count = 0;
    for (int i = 0 ; i < N; i++){
        if (h[i]>=K){
            count++;
        }
    }


    cout << count << endl;
	return 0;
}



Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vt = vector<T>;
template<class T> using vvt = vector<vt<T>>;
template<class T> using ttt = tuple<T,T>;
using tii = tuple<ll,ll>;
using vi = vector<ll>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define DIV int(1e9+7)
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
const double PI = M_PI;  
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*/
ll dp[5001][5001] = {}; // dp[i番目までで][j人選んだ] = 今のpの値（小さい方がいい）
int main(){
  int n; cin >> n;
  vector<tii> v;
  rep(i,n){
    int h,p; cin >> h >> p;
    v.pb(tii{h,p});
  }
  sort(ALL(v),[](const tii a,const tii b){
    int ah,ap; tie(ah,ap) = a;
    int bh,bp; tie(bh,bp) = b;
    return (ah + ap != bh + bp)? ah + ap < bh + bp : ah < bh;
  });
  fill_n(dp[0],5001*5001,LLINF);
  dp[0][0] = 0;
  for(int i = 1; i <= n; i++){
    rep(j,i+1){
        int nh,np; tie(nh,np) = v[i-1];
        dp[i][j] = min(dp[i-1][j],(dp[i-1][j-1] > nh)?LLINF:dp[i-1][j-1]+np);
    }
  }
  int ans = 0;
  rep(j,5001){
    if(dp[n][j] != LLINF)
      ans = max(ans,j);
  }
  cout << ans << endl;
}

Measured memory_bytes: 195840
#include<iostream>
#define REP(i,s,n) for(int i=s ; i < n ; i++)
#define rep(i,n) REP(i,0,n)
using namespace std;

int W,H;
char field[20][20];
int cnt;

void dfs(int x,int y){

  field[y][x]='#';
  
  cnt++;
  
  if( x+1 < W && field[y][x+1] == '.'){
    dfs(x+1,y);
  }
  if(x-1 >= 0 && field[y][x-1] == '.'){
    dfs(x-1,y);
  }
  if(y+1 < H && field[y+1][x] == '.'){
    dfs(x,y+1);
  }
  if(y-1 >=0 && field[y-1][x] == '.'){
    dfs(x,y-1);
  }
  
}
int main(){
  
  int x,y;
  
  while(1){
    cin >>W>>H;
    if(W==0 && H==0)break;
    
    rep(i,H){
      rep(j,W){
	cin >>field[i][j];
	if(field[i][j] == '@'){
	  x=j;
	  y=i;
	}
      }
    }
    cnt=0;
    dfs(x,y);
    cout <<cnt<<endl; 
  }
  
  return 0;
}

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

int main(){

  int N;
  int i,j;

  cin >> N;

  int H[N];

  for(i=0; i<N; i++){
    cin >> H[i]; 
  }

  int answer=1;
  
  
  for(i=1; i<N; i++){
    int count=0;
    
    for(j=0; j<i; j++){
      if(H[i]>=H[j]){
	count++;
      }
    }

    if(count==i){
      answer++;
    }

    count=0;
  }
  
  cout << answer << endl;
  
}

Measured memory_bytes: 256
open Scanf
open Printf

let power a n =
 let rec loop a ans = function
  0 -> ans
 |n' -> loop a (ans * a) (n'-1)
 in loop a 1 n

let () =
 let n, m = scanf "%d %d\n" (fun x y -> (x, y)) in
 let x = 1900 * m + 100 * (n - m) in
 x * power 2 m |> printf "%d\n" 


Measured memory_bytes: 384
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)

struct INIT{
    INIT(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(0);
        cout << fixed << setprecision(13);
    }
}INIT;

int main(){
    int n, q;
    cin >> n >> q;
    vector<LL> s(n), t(n), x(n);
    vector<LL> d(q), ans(q);
    vector<pair<LL, pair<LL, LL>>> vec;
    REP(i, n){
        cin >> s[i] >> t[i] >> x[i];
        LL L = s[i] - x[i];
        LL R = t[i] - 1 - x[i];
        vec.emplace_back(pair<LL, pair<LL, LL>>(x[i], pair<LL, LL>(L, R)));
    }
    set<pair<LL, LL>> st;
    REP(i, q){
        LL d;
        cin >> d;
        st.insert(pair<LL, LL>(d, i));
        ans[i] = -1;
    }
    sort(ALL(vec));
    REP(i, n){
        LL L = vec[i].second.first;
        LL R = vec[i].second.second;
        if(st.empty())continue;
        auto it = st.lower_bound(pair<LL, LL>(L, -1));
        while(!st.empty() && it != st.end() && (*it).first <= R){
            ans[(*it).second] = vec[i].first;
            st.erase(it++);
        }
    }
    REP(i, q)cout << ans[i] << endl;
}

Measured memory_bytes: 27244
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

impl<T: Iterator> IteratorExt for T {}

#[allow(unused)]
use std::cmp::{max, min};
#[allow(unused)]
use std::collections::HashMap;

#[allow(unused)]
fn gcd(x: i64, y: i64) -> i64 {
    if y == 0 {
        x
    } else {
        gcd(y, x % y)
    }
}

#[allow(unused)]
fn lcm(x: i64, y: i64) -> i64 {
    x * y / gcd(x, y)
}

fn main() {
    input! {
        // usize
        // n: usize,
        // vec
        // v: [i64; n],
        n: usize,
        x: i64,
        l: [i64; n]
    }

    let mut count = 1;
    let mut sum = 0;

    for i in 0..n {
        sum += l[i];
        if sum > x {
            println!("{}", count);
            return;
        } else {
            count += 1;
        }
    }
    println!("{}", count);
}


Measured memory_bytes: 4352
using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections;
using System.Linq.Expressions;

static class Program
{
    static void Main()
    {
        new Magatro().Solve();
    }
}

class Magatro
{
    private long H, W;
    private void Scan()
    {
        var line = Console.ReadLine().Split(' ');
        H = long.Parse(line[0]);
        W = long.Parse(line[1]);
    }

    public void Solve()
    {
        Scan();

        long ans = long.MaxValue;
        for (int i = 0; i <= H; i++)
        {
            long a = W * i;
            long b = ((W + 1) / 2) * (H - i);
            long c = (W / 2) * (H - i);
            long max = Math.Max(Math.Max(a, b), c);
            long min = Math.Min(Math.Min(a, b), c);
            ans = Math.Min(ans, max - min);
            b = W * ((H - i) / 2);
            c = W * ((H - i + 1) / 2);
            max = Math.Max(Math.Max(a, b), c);
            min = Math.Min(Math.Min(a, b), c);
            ans = Math.Min(ans, max - min);
        }
        for (int i = 0; i <= W; i++)
        {
            long a = H * i;
            long b = ((H + 1) / 2) * (W - i);
            long c = (H / 2) * (W - i);
            long max = Math.Max(Math.Max(a, b), c);
            long min = Math.Min(Math.Min(a, b), c);
            ans = Math.Min(ans, max - min);
            b = H * ((W - i) / 2);
            c = H * ((W - i + 1) / 2);
             max = Math.Max(Math.Max(a, b), c);
             min = Math.Min(Math.Min(a, b), c);
            ans = Math.Min(ans, max - min);
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 11092
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b, c = LI()
    ans = 10 ** 5
    ans = min(ans, abs(a - b) + abs(b - c))
    ans = min(ans, abs(a - c) + abs(b - c))
    ans = min(ans, abs(a - c) + abs(a - b))
    print(ans)
    return

#B
def B():
    s, t = S(), S()
    f = 0
    for i in range(len(s)):
        f = f or s[i:] + s[:i] == t
    print(["No","Yes"][f])
    return

#C
def C():
    return

# D
# 解説AC
# 貪欲かよ
# 言われればその通りでbi昇順でソートしていれば
# 直前で取り除いたものに関してはその橋より左側
# の街について絶対に橋が途切れているからね
# fuck!!! 
def D():
    n, m = LI()
    ab = LIR(m)
    ab.sort(key=lambda x: x[1])
    before = 0
    ans = 0
    for a, b in ab:
        if a < before <= b:
            continue
        else:
            before = b
            ans += 1
    print(ans)
    return

#Solve
if __name__ == '__main__':
    D()


Measured memory_bytes: 60508
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
long long int head, tail, n;

void enqueue(P x){
  memcpy((char*)&Q[tail%LEN], (char*)&x, sizeof(P));
  tail++;
}

P dequeue(){
  P p;
  memcpy((char*)&p, (char*)&Q[head%LEN], sizeof(P));
  head++;
  return p;
}


int main(){
  int elaps = 0, c;
  int time = 0;
  int i, q;
  P u;

  scanf("%lld %d", &n, &q);
  head = 0;
  tail = n;

  for ( i = 0; i < n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  
  while(tail!=head) {
    u = dequeue();
    c = u.t - q;
    if(c <= 0) {
      time += u.t;
      printf("%s %d\n", u.name, time);
    } else {
      u.t = c;
      enqueue(u);
      time += q;
    }
  }
  
  return 0;
}

Measured memory_bytes: 10756
using System;
using System.Collections.Generic;

class TEST
{
    static List<int[]> testlist;
    public static void Main()
    {
        (int x, int y) nowPosition = (0, 0);

        int N = int.Parse(Console.ReadLine());

        testlist = new List<int[]>();
        for (int i = 0; i < N; i++)
        {
            string[] values = Console.ReadLine().Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
            testlist.Add(GetStringtoInt(values));

        }



        for (int i = 0; i < testlist.Count; i++)
        {
            int needTimeToMove = 0;
            while (true)
            {
                if (nowPosition.x == testlist[i][1] && nowPosition.y == testlist[i][2])
                {
                    int value = GetNum(i);

                   
                    if (value >= needTimeToMove && value % 2 == 0 && needTimeToMove % 2 == 0)
                    {
                        break;
                    }
                    else if (value >= needTimeToMove && value % 2 == 1 && needTimeToMove % 2 == 1)
                    {
                        break;

                    }
                    else
                    {
                        Console.WriteLine("No");
                        return;
                    }
                }
                else
                {
                    int sa = testlist[i][1] - nowPosition.x;
                    nowPosition.x += sa;
                    needTimeToMove += Math.Abs(sa);

                    sa = testlist[i][2] - nowPosition.y;
                    nowPosition.y += sa;
                    needTimeToMove += Math.Abs(sa);
                }
            }
        }

        Console.WriteLine("Yes");



    }

    static private int[] GetStringtoInt(string[] values)
    {
        int[] values_i = new int[values.Length];

        for (int i = 0; i < values.Length; i++)
        {
            values_i[i] = int.Parse(values[i]);
        }

        return values_i;
    }

    static private int GetNum(int index)
    {
        if (index == 0)
            return testlist[index][0];
        return testlist[index][0] - testlist[index - 1][0];
    }

}

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

int main() {
  ll n, a, b; cin >> n >> a >> b;
  ll l = a * (n-1) + b;
  ll r = b * (n-1) + a;
  ll ans = r - l + 1;
  //cout << l << " " << r << " " << ans << endl;
  if (ans < 0) ans = 0;
  if (a > b) ans = 0;
  cout << ans << endl;
  return 0;
}


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


#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	string s;
	cin >>s;
	vector<VI> sk(26);
	rep(i, sz(s)){
		sk[s[i]-'a'].push_back(i);
	}
	for(auto& zs: sk){
		int m=sz(zs);
		if(m < 2) continue;
		rep(i, m) rep2(p, 1, 28){
			if(i+p>=m) break;
			int und = zs[i+p] - zs[i] + 1;
			//dbg(zs[i+p],zs[i]);
			if(und < (p+1) * 2 ){
				cout << zs[i]+1 <<" " <<zs[i+p]+1 <<"\n";
				return 0;
			}
		}
	}
	cout<<"-1 -1\n";
	return 0;
}


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

int main(void) {
    long long a, b, k;
    cin >> a >> b >> k;
    long long p, q;
    p = a - k;
    q = p + b;
    if (p > 0) cout << p << " " << b;
    else if (q > 0) cout << "0 " << q;
    else cout << "0 0\n";
    return 0;
}


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

#define int int64_t

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

    string s;
    cin >> s;
    if(s[2] == s[3] && s[4] == s[5]) cout << "Yes\n";
    else cout << "No\n";
    
}

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

int main(void)
{
    int X, Y;
    cin >> X >> Y;

    if (((4 * X) - Y) % 2 == 0 && ((4 * X) - Y) >= 0 && (Y - (2 * X)) >= 0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
const int MN=1010;
const int dx[]={1,-1,0,0};
const int dy[]={0,0,1,-1};
char a[MN][MN];
bool vis[MN][MN];
int ans[MN][MN];
int main(){
	memset(vis,true,sizeof(vis));
	memset(ans,0,sizeof(ans));
	int n,m;
	cin>>n>>m;
	queue<pair<int,int> > q;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin>>a[i][j];
			if(a[i][j]=='.')vis[i][j]=false;
			else if(a[i][j]=='#')q.push(make_pair(i,j));
		}
	}
	int cnt=0;
	while(!q.empty()){
		pair<int,int> pos;
		pos=q.front();
		q.pop();
		int x=pos.first;
		int y=pos.second;
		cnt=ans[x][y];
		for(int i=0;i<4;i++){
			int ax=x+dx[i];
			int ay=y+dy[i];
			if(ax>=0&&ax<n&&ay>=0&&ay<m&&!vis[ax][ay]){
				ans[ax][ay]=ans[x][y]+1;
				vis[ax][ay]=true;
				q.push(make_pair(ax,ay));
			}
		}
	}
	cout<<cnt<<endl;
	return 0;
}

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

#define F first
#define S second
#define pb push_back
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),a.end()
#define pw(x) (1LL<<(x))

#define db(x) cerr << #x << " = " << x << endl
#define db2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define db3(x, y, z) cerr << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", " << z << ")\n"
#define dbv(a) cerr << #a << " = "; for (auto xxxx: a) cerr << xxxx << " "; cerr << endl

using namespace std;

typedef long long ll;
typedef double dbl;
const int INF = 1.01e9;



int main() {
#define TASK "A"
#ifdef HOME
    assert(freopen(TASK".in", "r", stdin));
#endif
    string s;
    cin >> s;
    if (s.size() == 26) {
        s.pb(' ');
        if (next_permutation(all(s))) {
            for (int i = 0; i < sz(s); i++){
                if (s[i] == ' ') break;
                cout << s[i];
            }
        }
        else {
            puts("-1");
        }
        return 0;
    }
    vector<int> used(26);
    for (auto ch: s) {
        used[ch - 'a'] = 1;
    }
    for (int i = 0; i < 26; i++) {
        if (!used[i]) {
            cout << s;
            cout << char(i + 'a');
            cout << endl;
            return 0;
        }
    }




    return 0;
}


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

char room[100][100];
char visited = 'v';
int dirs[4][2] = {
    {-1, 0},
    {1, 0},
    {0, 1},
    {0, -1}};

void dfs(char room[100][100], char current, int h, int w, int i, int j)
{
  if (i < 0 || i >= h || j < 0 || j >= w || room[i][j] != current)
  {
    return;
  }
  room[i][j] = visited;
  for (int k = 0; k < 4; k++)
  {
    dfs(room, current, h, w, i + dirs[k][0], j + dirs[k][1]);
  }
}

int main()
{
  int w, h;
  while (scanf("%d%d", &h, &w) != EOF)
  {
    if (w == 0 || h == 0)
    {
      break;
    }
    for (int i = 0; i < h; i++)
    {
      scanf("%s", &room[i]);
    }
    int count = 0;
    // count
    for (int i = 0; i < h; i++)
    {
      for (int j = 0; j < w; j++)
      {
        if (room[i][j] != visited)
        {
          count += 1;
          dfs(room, room[i][j], h, w, i, j);
        }
      }
    }
    printf("%d\n", count);
  }
  return 0;
}


Measured memory_bytes: 2484
import java.util.*

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

object Problem {
    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val N = sc.next().toInt()
        val Q = sc.next().toInt()

        val to = Array(N + 2) { mutableListOf<Int>() }
        repeat(N - 1) {
            val a = sc.next().toInt()
            val b = sc.next().toInt()
            to[b].add(a)
            to[a].add(b)
        }

        val ans = LongArray(N + 2) { 0L }
        repeat(Q) {
            val p = sc.next().toInt()
            val x = sc.next().toLong()
            ans[p] += x
        }

        val q = LinkedList<Pair<Int, Int>>()
        q.addLast(Pair(1, 0))
        while (q.isNotEmpty()) {
            val item = q.pop()
            val v = item.first
            val p = item.second
            to[v].forEach { u ->
                if (u != p) {
                    ans[u] += ans[v]
                    q.addLast(Pair(u, v))
                }
            }
        }

        pw.println((1..N).map { ans[it] }.joinToString(" "))
    }
}


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

int main() {
  int n,k; cin>>n>>k;
  vector<int> h(n);
  for(int i=0; i<n; i++) cin>>h[i];
  vector<int> dp(n+1000,INT_MAX);
  dp[0] = 0;
  for(int i=0; i<n; i++) {
    for(int j=1; j<=k; j++) {
      dp[i+j]=min(dp[i+j],dp[i]+abs(h[i+j]-h[i]));
    }
  }
  cout << dp[n-1] << endl;
}


Measured memory_bytes: 4032
#include <cctype>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
typedef long long int64;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 2e5+5, INF = 0x3f3f3f3f;
struct Edge
{
    int next, to;
    Edge(int next = 0, int to = 0):next(next), to(to) {};
}edge[N<<1];
int n, tot, head[N];
void _add(int x, int y) { edge[++tot] = Edge(head[x], y); head[x] = tot; }
void add(int x, int y) { _add(x, y); _add(y, x); }
int s[N], d1[N], d2[N], d[N];
char c[N];
int64 ans;
void dfs1(int x, int fa)
{
    c[x] == '1'?d[x] = 0, s[x] = 1:d[x] = INF;
    for(int i = head[x]; i; i = edge[i].next)
    {
        int y = edge[i].to; if(y == fa) continue;
        dfs1(y, x), s[x] += s[y];
        if(d1[y]+1 > d1[x]) d2[x] = d1[x], d1[x] = d1[y]+1;
        else if(d1[y]+1 > d2[x]) d2[x] = d1[y]+1;
        if(s[y]) d[x] = min(d[x], d1[y]+1);
    }
}
void dfs2(int x, int fa)
{
    int r = min(d2[x]+1, d1[x]-1);
    if(d[x] <= r) ans += r-d[x]+1;
    for(int i = head[x]; i; i = edge[i].next)
    {
        int y = edge[i].to; if(y == fa) continue;
        int k = d1[y]+1 == d1[x]?d2[x]+1:d1[x]+1;
        if(k > d1[y]) d2[y] = d1[y], d1[y] = k;
        else if(k > d2[y]) d2[y] = k;
        if(s[1]-s[y]) d[y] = min(d[y], k);
        dfs2(y, x);      
    }
}
int main()
{
    n = read();
    for(int i = 1, x, y; i < n; ++i)
        x = read(), y = read(), add(x, y);
    scanf("%s", c+1), dfs1(1, 0), dfs2(1, 0);
    printf("%lld\n", ans+1);
    return 0;
}

Measured memory_bytes: 14464
#include<bits/stdc++.h>
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
  int a,b,c,d,e,f,g,h,i;
  vector<int>v;
  int r[1000];
  while(scanf("%d%d",&a,&b)==2)
  {
      g=0;
      for(c=0;c<a;c++)
      {
          scanf("%d",&r[c]);

      }
      sort(r,r+a);
      h=a-b;


      for(e=1;e<=b;e++,h++)
      {
          g=g+r[h];
      }
      printf("%d\n",g);


  }
    return 0;
}


Measured memory_bytes: 256