akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer tokenizer = null;
    int totalCases, testNum;

    PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

    void solve() throws IOException {

    }

    void execute() throws IOException {
        int n = ni();
        int col  = 3;
        int[][] a = new int[n][col];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < col; j++) {
                a[i][j] = ni();
            }
        }
        int[][] dp = new int[n][col];
        int res = 0;
        for (int i = 0; i < col; i++) {
            dp[0][i] = a[0][i];
            res = Math.max(res, dp[0][i]);
        }

        for (int i = 1; i < n; i++) {
            for (int j = 0; j < col; j++) {
                int max = Integer.MIN_VALUE;
                for (int k = 0; k < col; k++) {
                    if (k != j) {
                        max = Math.max(max, dp[i - 1][k]);
                    }
                }
                dp[i][j] = max + a[i][j];
                res = Math.max(res, dp[i][j]);
            }
        }

        out.print(res);

        out.close();
    }

    public static void main(String[] args) throws IOException {
        new Main().execute();
    }

    void debug(Object... os) {
        System.out.println(Arrays.deepToString(os));
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String ns() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(br.readLine());
        }
        return tokenizer.nextToken();
    }

    String nline() throws IOException {
        tokenizer = null;
        return br.readLine();
    }

    boolean input() throws IOException {
        return true;
    }

}


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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll INF = 0x3f3f3f3f;
const ll LINF = 1ll << 55;
const ll MOD = 1e9 + 7;
const ll MAXN = 400 + 5;
const ll MAXK = 1e5 + 10;

const ll dx[] = {1, 0, -1, 0};
const ll dy[] = {0, 1, 0, -1};

int main() {
    ll N;
    cin >> N;
    cout << N / 3 << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
s = input()
ans = 0

for i in range(1000):
    i = str(i).zfill(3)

    first = s.find(i[0])
    if first == -1:
        continue

    second = s.find(i[1], first+1)
    if second == -1:
        continue

    third = s.find(i[2], second+1)

    if third != -1:
        ans += 1

print(ans)

Measured memory_bytes: 3064
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    s = input()
    if s[0] == s[1] or s[1] == s[2] or s[2] == s[3]:
        print("Bad")
    else:
        print("Good")


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
N = int(input())

L = len(str(N))

import math
import itertools

ans = 0

for now_L in range(3, L):
    for a in list(itertools.product([3,5,7], repeat=now_L)):
        num = int("".join(map(str, a)))

        if set(a) == set([3,5,7]):
            ans += 1
        
for a in list(itertools.product([3,5,7], repeat=L)):
    num = int("".join(map(str, a)))
    if num > N:
        break

    if set(a) == set([3,5,7]):
        ans += 1

print(ans)

Measured memory_bytes: 11736
#include<iostream>
using namespace std;
#define MAX 100000

int parent(int i ) { return i / 2; }
int left(int i ) { return 2 * i; }
int right(int i ) { return 2 * i + 1; }

int main() {
  int H, i ,A[MAX+1];

  cin >> H;
  for ( i = 1; i <= H; i++)  cin >> A[i];

  for ( i = 1; i <= H; i++) {
    cout << "node " << i << ": key = " << A[i] << ", ";
    if ( parent(i) >= 1 ) cout << "parent key = " << A[parent(i)] << ", ";
    if ( left(i) <= H ) cout << "left key = " << A[left(i)] << ", ";
    if ( right(i) <= H ) cout << "right key = " << A[right(i)] << ", ";
    cout << endl;
  }

  return 0;
}



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

using namespace std;

int n;
vector<int> s,t;

int main() {
  cin >> n;
 
  for(int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if(i % 2 == 0) s.push_back(a);
    else t.push_back(a);
  }
  reverse(t.begin(),t.end());

   if(n % 2 == 1) {
    reverse(t.begin(),t.end());
    reverse(s.begin(),s.end());
     for(int i = 0; i < s.size(); i++) {
    cout << s[i] <<' ';
  }

     for(int i = 0; i < t.size(); i++) {
       cout << t[i] <<" ";
     }
     cout << endl;
     return 0;
     }
  
  for(int i = 0; i < t.size(); i++) {
    cout << t[i] <<' ';
  }
  
  for(int i = 0; i < s.size(); i++) {
    cout << s[i] <<" ";
  }
  cout << endl;
}

  

  
    
  


Measured memory_bytes: 3188
from collections import defaultdict
import heapq
n_pref, m_city = list(map(int, input().split()))
record = defaultdict(list)
cities = []
for i in range(m_city):
  pref, year = list(map(int, input().split()))
  cities.append({"pref": pref, "year": year})
  heapq.heappush(record[pref], year)
res = defaultdict(dict)
for key ,value in record.items():
  for i in range(1, len(value) + 1):
    res[key][heapq.heappop(value)] = i
for city in cities:
  print(format(city["pref"], '06d'), format(res[city["pref"]][city["year"]], '06d'), sep="")

Measured memory_bytes: 101064
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	int a[5];
	int b[5];
	int min_i = 0;
	rep(i, 5)
	{
		cin >> a[i];
		b[i] = (10 - a[i] % 10) % 10;
		
		if (i > 0 && (b[i]>b[min_i]))
		{
			min_i = i;
		}
	}

	int total = 0;
	rep(i, 5)
	{
		if(i == min_i)
		{
			total += a[i];
		} 
		else
		{
			if (a[i] % 10 == 0)
			{
				total += a[i];
			}
			else
			{
				total += (a[i] / 10 + 1) * 10;
			}
			
		}
		
	}

	cout << total << endl;
	
	
	return 0;
}


Measured memory_bytes: 256
#if 0

#endif
#include <iostream>
#include <memory>
#include <vector>
#include <string>
#include <algorithm>
#include <assert.h>
#include <complex>
#include <queue>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define INF (1 << 30)
using namespace std;
using ll = long long;
int A, B, K;
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> A >> B >> K;
    for (int i = 100; i > 0; --i) {
        if (A % i == 0 && B % i == 0) {
            K--;
        }
        if (K == 0) {
            cout << i << endl;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 300005
using namespace std;
struct P{
	int l,r;
}a[N];
struct trie{
	int w,l,r;
}t[N*25];
int n,m,cnt,root[N],pos[100005];
bool cmp(P a,P b){return a.l<b.l;}
void insert(int pre,int now,int l,int r,int x){
	t[now]=t[pre];
	t[now].w++;
	if(l==r) return;
	int mid=l+r>>1;
	if(x<=mid) t[now].l=++cnt,insert(t[pre].l,cnt,l,mid,x);
	else t[now].r=++cnt,insert(t[pre].r,cnt,mid+1,r,x);
}
int query(int k,int l,int r,int L,int R){
	if(L<=l&&R>=r) return t[k].w;
	int mid=l+r>>1,ans=0;
	if(L<=mid) ans+=query(t[k].l,l,mid,L,R);
	if(R>mid) ans+=query(t[k].r,mid+1,r,L,R);
	return ans;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) scanf("%d%d",&a[i].l,&a[i].r);
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;i++){
		root[i]=++cnt;
		insert(root[i-1],cnt,1,m,a[i].r);
	}
	for(int i=1;i<=m;i++){
		pos[i]=pos[i-1];
		while(pos[i]<n&&a[pos[i]+1].l<=i) pos[i]++;
	}
	for(int i=1;i<=m;i++){
		int ans=0;
		for(int p=i;p<=m;p+=i){
			ans+=query(root[pos[p]],1,m,p,p+i-1);
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 70144
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

struct Sushi{
    int type, umami;
    Sushi(int t, int d){
        type = t; umami = d;
    }
    bool operator<(const Sushi &another) const{
        return umami < another.umami;
    }
};

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

    map<int, bool>fstTaken;
    vector<Sushi> allSushi;

    for(int i = 0; i < n; i++){
        int t,d;
        cin >> t >> d;
        fstTaken[t] = false;
        allSushi.push_back(Sushi(t, d));
    }

    sort(allSushi.begin(), allSushi.end());
    reverse(allSushi.begin(), allSushi.end());

    long satisfaction = 0;
    long eaten = 0;
    vector<int> nigun;
    for(int i = 0; i < k; i++){
        Sushi next = allSushi[i];
        satisfaction += next.umami;
        if(fstTaken[next.type]){
            nigun.push_back(next.umami);
        } else {
            fstTaken[next.type] = true;
            eaten++;
        }
    }

    vector<int> waiting;
    for(int i = k; i < n; i++){
        Sushi next = allSushi[i];
        if(waiting.size() >= nigun.size()){
            break;
        }
        if(fstTaken[next.type]){
            continue;
        }
        waiting.push_back(next.umami);
        fstTaken[next.type] = true;
    }

    sort(waiting.begin(), waiting.end());
    reverse(waiting.begin(), waiting.end());
    reverse(nigun.begin(), nigun.end());

    long diff[waiting.size()];
    long total,max;
    total = max = 0;
    for(int i = 0; i < (int)waiting.size();i++){
        long lastD;
        if(i == 0){
            lastD = 0;
        } else {
            lastD = diff[i-1];
        }
        diff[i] = lastD + waiting[i] - nigun[i];
        total= diff[i] + (eaten + i + 1) * (eaten + i + 1) - eaten * eaten;
        if(max < total){
            max = total;
        }
    }
    cout << (max + satisfaction + eaten * eaten) << endl;

    return 0;
}



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

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class CGuessTheNumber {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        int N, M;
        cin >> N >> M;
        bool ok = true;
        map<int, int> pos;
        REP(i, M) {
            int s, c;
            cin >> s >> c;
            s--;
            if (pos.count(s) > 0 && pos[s] != c) {
                ok = false;
            }
            pos[s] = c;
        }
        if (!ok) {
            cout << -1 << endl;
            return;
        }

        if (pos.count(0) > 0 && pos[0] == 0 && N > 1) {
            cout << -1 << endl;
            return;
        }

        string res;
        REP(i, N) {
            if (pos.count(i) > 0) {
                res += pos[i] + '0';
            } else {
                if (i == 0 && N > 1) {
                    res += '1';
                } else {
                    res += '0';
                }
            }
        }
        cout << res << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    CGuessTheNumber solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#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++)
using ll = long long;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using P = pair<ll, ll>;

// chmin, chmax関数
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

// Yes-Noを出力する問題で楽をする
void Ans(bool f){
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
}

//---------------------------

int main(){
    int a[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
    int x,y; cin >> x >> y;
    Ans(a[x]==a[y]);
    return 0;
}

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

def main():
    N, K = [int(x) for x in input().split()]
    S = input().strip()
    ans = []
    prev = '0'
    if S[0] == '1':
        ans.append(0)
        prev = '1'

    count = 0
    for s in S:
        if s == prev:
            count += 1
        else:
            prev = s
            ans.append(count)
            count = 1
    ans.append(count)

    ans2 = 0
    tmp = 0
    count = 0
    r = 0
    l = 0
    if ans[0] == 0:
        l = 2
    for i, v in enumerate(ans):
        r = i
        if v == 0:
            continue
        tmp += v
        if count == K:
            break
        if not i & 1:
            count += 1

    ans2 = max(tmp, ans2)

    while r <= len(ans) - 2:
        if l == 0:
            tmp -= ans[0]
        else:
            tmp -= ans[l]
            tmp -= ans[l - 1]

        l += 2
        r += 2
        if not len(ans) - 1 < r:
            tmp += ans[r]
        tmp += ans[r - 1]

        ans2 = max(tmp, ans2)

    print(ans2)

if __name__ == '__main__':
    main()



Measured memory_bytes: 4092
H, W = [int(x) for x in input().split()]

A = [[0]*W for i in range(H)]
for c in [1, -1]:
    for i in range(H):
        arr = [int(x) for x in input().split()]
        for j in range(W):
            A[i][j] += arr[j] * c

M = 160*80
dp = [[0]*W for i in range(H)]
dp[0][0] = 1 << M
for i in range(H):
    for j in range(W):
        if i > 0:
            dp[i][j] |= dp[i-1][j]
        if j > 0:
            dp[i][j] |= dp[i][j-1]
        a = abs(A[i][j])
        dp[i][j] = (dp[i][j] << a) | (dp[i][j] >> a)

ans = M
for i in range(2*M):
    if dp[H-1][W-1] & (1 << i) > 0:
        ans = min(ans, abs(M-i))
print(ans)


Measured memory_bytes: 59356
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main() {
#if _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false); cin.tie(0);
	int n;
	cin >> n;
	vector<double>x(n);
	double sum = 0;
	for (int i = 0; i < n; ++i) {
		cin >> x[i];
	}
	sort(x.begin(), x.end());
	for (int i = 0; i < n - 1; ++i) {
		x[i + 1] = (x[i] + x[i + 1]) / 2;
		sum = x[i + 1];
	}
	printf("%.6f", sum);
	return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <utility>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define MOD 1e9 + 7
#define INF 1e9
#define SENTINEL 2e9
#define PIE 3.1415926535

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;}
template <class T>
inline T GCD(T a, T b){if (b == 0) return a; else return GCD(b, a % b);}
template <class T>
inline T LCM(T a, T b) {return (a * b) / GCD(a, b);}

#define itn int

int main() {
    int n;
    cin >> n;
    int a;
    bool f = true;
    rep(i, n) {
        cin >> a;
        if(a%2==0){
        if(a%10!=0 && a%6!=0)
            f = false;}
    }
    if(f) printf("APPROVED");
    else
        printf("DENIED");
    return 0;

}

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

int main() {
  
  int h, w;
  cin >> h >> w;
  
  vector<string> a(h);
  for(int i = 0; i < h; i++) {
    cin >> a.at(i);
  }
  
  for(int i = 0; i < w+2; i++) {
    cout << '#';
  } cout << endl;
  for(int i = 0; i < h; i++) {
    cout << '#' << a.at(i) << '#' << endl;
  }
  for(int i = 0; i < w+2; i++) {
    cout << '#';
  } cout << endl;
  
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}
#define N 60
ll c[N][N];

ll comb_nk(ll n, ll k){
	if(k<0||k>n) return 0;
	if(k==0||k==n) return c[n][k] = 1;
	if(c[n][k]) return c[n][k];
	return c[n][k] = comb_nk(n-1, k-1)+comb_nk(n-1, k);
}

int main(){
	ll n, a, b;
	cin>>n>>a>>b;
	vector<ll> v(n);
	rep(i, n) cin>>v[i];
	sort(all(v));
	ll sum = 0;
	rep(i, a) sum += v[n-i-1];
	double ave = (double)sum/a;
	cout.precision(9);
	cout<<ave<<endl;
	ll x = v[n-a];
	ll s = 0, t = 0;
	rep(i, n){
		if(x==v[i]) s++;
		if(x<v[i]) t++;
	}
	if(x==v.back()){
		ll res = 0;
		for(ll i = a; i <= b; i++) res += comb_nk(s, i);
		cout<<res<<endl;
	} else {
		ll res = comb_nk(s, a-t);
		cout<<res<<endl;
	}

	return 0;
}


Measured memory_bytes: 256
H,W,A,B=map(int,input().split())
INF=10**9+7
x=[0]*(H+W-1)
x[0]=1
for i in range(1,H+W-1):
    x[i]=(i*x[i-1])%INF
y=[0]*(H+W-1)
y[-1]=pow(x[-1],10**9+5,INF)
for i in range(H+W-2,0,-1):
    y[i-1]=(y[i]*i)%INF
ans=0
for i in range(B,W):
    j=H-A-1
    ans+=(x[i+j]*y[i]*y[j])*(x[W-1-i+H-2-j]*y[H-2-j]*y[W-1-i])
    ans%=INF
print(ans)


Measured memory_bytes: 44012
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
bool a[26][26],d[26];
void fn(int p){
  int i;
  if(d[p]==0){
    d[p]=1;
    for(i=0;i<26;i++){
      if(a[p][i]||a[i][p])
	fn(i);
    }
  }
  return;
}
int main(){
  int i;
  int n;
  while(cin>>n&&n){
    int b[26],c[26];
    memset(a,0,26*26);
    memset(b,0,sizeof(b));
    memset(c,0,sizeof(c));
    for(i=0;i<n;i++){
      string s;
      cin>>s;
      a[s[0]-'a'][s[s.length()-1]-'a']=1;
      b[s[0]-'a']++;
      c[s[s.length()-1]-'a']++;
    }
    memset(d,0,26);
    for(i=0;b[i]==0;i++);
    fn(i);
    for(i=0;i<26;i++){
      if(d[i]!=(b[i]||c[i]))
	break;
    }
    if(i==26){
      for(i=0;i<26;i++){
	if(b[i]!=c[i])
	  break;
      }
      if(i==26)
	cout<<"OK"<<endl;
      else
	cout<<"NG"<<endl;
    }else{
      cout<<"NG"<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 912
#include <stdio.h>

int main(void)
{
    int H, W, h, w;
    char c;
    
    
    scanf("%d%c%d", &H, &c, &W);
    scanf("%d%c%d", &h, &c, &w);
    

    
    printf("%d\n", H*W-h*W-H*w+h*w);
    
    //system("pause");
    
    return 0;
}


Measured memory_bytes: 128
def main():
  import collections
  n, k, q, *a = map(int, open(0).read().split())
  point=[k-q]*n
  
  for person,getPoint in collections.Counter(a).items():
    point[person-1]+=getPoint
  
  for res in point:
    print("Yes" if res>0 else "No")
    
if __name__=="__main__":
  main()

Measured memory_bytes: 14412
import math as m

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

def vector(theta, magnitude):
    x = magnitude * m.cos(theta)
    y = magnitude * m.sin(theta)
    return x, y

u = vector((H+M/60)/12 * 2*m.pi, A)
v = vector(M/60 * 2*m.pi, B)

print(m.dist(u, v))


Measured memory_bytes: 9336
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) (v).begin(),(v).end()
#define out(a) cout << (a) << endl
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    while(n % 111 != 0){
        n++;
    }
    out(n);
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define INF (1<<29)
 
int main()
{
    int H, W;
    while (cin >> H >> W, H) {
        int D = H * H + W * W;
        int min_d = INF, ans_h = INF, ans_w = INF;        
        for (int w = 1; w <= 150 ; w++) {
            for (int h = 1; h < w; h++) {
                int d = h * h + w * w;
                if (D > d) continue;                    
                if (d < min_d) {
                    if (D == d) {
                        if (H < h) {
                            min_d = d;
                            ans_h = h;
                            ans_w = w;
                        }
                    } else {
                        min_d = d;
                        ans_h = h;
                        ans_w = w;
                    }                        
                } else if (d == min_d) {
                    if (D == d) {
                        if (H < h && h < ans_h) {
                            ans_h = h;
                            ans_w = w;
                        }
                    } else {
                        if (h < ans_h) {
                            ans_h = h;
                            ans_w = w;
                        }
                    }
                }
            }
        }
        cout << ans_h << " " << ans_w << endl;
    }
    return 0;
}

Measured memory_bytes: 3084
#include<stdio.h>
int main(void){
	int a,b;
	char op;
	while(1){
	scanf("%d %c %d",&a,&op,&b);
	if(op=='+'){
		printf("%d\n",a+b);
	}else if(op=='-'){
		printf("%d\n",a-b);
	}else if(op=='*'){
		printf("%d\n",a*b);
	}else if(op=='/'){
		printf("%d\n",a/b);
	}else{
		break;
	}
	}
	return 0;
}

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

long long N, M, K;

struct UnionFind
{
  // par[i]：データiが属する木の親の番号。i == par[i]のとき、データiは木の根ノードである
  vector<int> par;
  // sizes[i]：根ノードiの木に含まれるデータの数。iが根ノードでない場合は無意味な値となる
  vector<int> sizes;

  UnionFind(int n) : par(n), sizes(n, 1) {
	  // 最初は全てのデータiがグループiに存在するものとして初期化
	  for(int i = 0; i < n; i++){
		  par[i] = i;
	  }
  }

  // データxが属する木の根を得る
  int find(int x) {
    if (x == par[x]) return x;
    return par[x] = find(par[x]);  // 根を張り替えながら再帰的に根ノードを探す
  }

  // 2つのデータx, yが属する木をマージする
  void unite(int x, int y) {
    // データの根ノードを得る
    x = find(x);
    y = find(y);

    // 既に同じ木に属しているならマージしない
    if (x == y) return;

    // xの木がyの木より大きくなるようにする
    if (sizes[x] < sizes[y]) swap(x, y);

    // xがyの親になるように連結する
    par[y] = x;
    sizes[x] += sizes[y];
    // sizes[y] = 0;  // sizes[y]は無意味な値となるので0を入れておいてもよい
  }

  // 2つのデータx, yが属する木が同じならtrueを返す
  bool same(int x, int y) {
    return find(x) == find(y);
  }

  // データxが含まれる木の大きさを返す
  int size(int x) {
    return sizes[find(x)];
  }
};

long long A[100005];
long long B[100005];
// groupid -> num
map<long long, long long> con;
// pairになれないやつ
vector<long long> ng[100005];

int main(){
	cin >> N >> M >> K;

	UnionFind uf(N + 5);

	for(long long i = 0; i < M; i++) {
		cin >> A[i] >> B[i];
		A[i]--;
		B[i]--;
		ng[A[i]].push_back(B[i]);
		ng[B[i]].push_back(A[i]);
		uf.unite(A[i], B[i]);
	}

	for(long long i = 0; i < K; i++) {
		long long c, d;
		cin >> c >> d;
		c--;d--;
		if(uf.find(c) == uf.find(d)) {
			ng[c].push_back(d);
			ng[d].push_back(c);
		}
	}

	for(long long i = 0; i < N; i++) {
		con[uf.find(i)]++;
	}

	for(long long i = 0; i < N; i++) {
		long long group = uf.find(i);
		long long num = con[group];
		long long blo = ng[i].size();

		cout << num - 1 - blo;
		if(i != N-1) {
			cout << " ";
		} else {
			cout << endl;
		}
	}
}

Measured memory_bytes: 19292
#include<set>
#include<cstdio>
#include<algorithm>
#define rep(a,b,c) for (int a=b;a<=c;a++)
#define push(a,b) a0.erase(b),b0.erase(b),a.insert(b)
#define move(a,b,c) a.erase(c),b.insert(c)
using namespace std;
const int N=100010;
int n,X,Y,Z,xs,ys,u,v,w,a[N],b[N];
long long ans;
struct c1{bool operator()(int x,int y){return a[x]==a[y]?x<y:a[x]>a[y];}};
struct c2{bool operator()(int x,int y){return b[x]==b[y]?x<y:b[x]>b[y];}};
struct c3{bool operator()(int x,int y){return a[x]-b[x]==a[y]-b[y]?x<y:a[x]-b[x]>a[y]-b[y];}};
struct c4{bool operator()(int x,int y){return b[x]-a[x]==b[y]-a[y]?x<y:b[x]-a[x]>b[y]-a[y];}};
set <int,c1> a0;
set <int,c2> b0;
set <int,c3> ab;
set <int,c4> ba;
int main(){
	scanf("%d%d%d",&X,&Y,&Z);
	n=X+Y+Z,X=Y,Y=Z;
	rep(i,1,n){
		int _,__,___;
		scanf("%d%d%d",&_,&__,&___);
		ans+=_,a[i]=__-_,b[i]=___-_;
		a0.insert(i),b0.insert(i);
	}
	rep(_,1,X+Y){
		if (xs==X){
			++ys;
			u=*b0.begin(),v=*ba.begin(),w=*a0.begin();
			ans+=max(b[u],b[v]-a[v]+a[w]);
			if (b[u]+a[v]>b[v]+a[w]) push(ab,u);
				else push(ba,w),move(ba,ab,v);
			continue;
		}
		if (ys==Y){
			++xs;
			u=*a0.begin(),v=*ab.begin(),w=*b0.begin();
			ans+=max(a[u],a[v]-b[v]+b[w]);
			if (a[u]+b[v]>a[v]+b[w]) push(ba,u);
				else push(ab,w),move(ab,ba,v);
			continue;
		}
		u=*a0.begin(),v=*b0.begin();
		ans+=max(a[u],b[v]);
		if (a[u]>b[v]) push(ba,u),++xs;
			else push(ab,v),++ys;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 10368
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
int max(int a,int b){return (a>b ? a:b);}
int min(int a,int b){return (a<b ? a:b);}
int compare_int(const void *a, const void *b){return *(int*)a - *(int*)b;}
//qsort(配列, 長さ, sizeof(int), compare_int);
double BS(int array[],int len,int target);

//////////////////////////////////////////



int N;

int main(){
    scanf("%d",&N);
    char s;
    int r,b;
    r = 0;
    b = 0;
    scanf("%c",&s);
    for(int i = 0;i < N;i++){
        scanf("%c",&s);
        if(s == 'R'){
            r++;
            //printf("R\n");
        }else{
            b++;
            //printf("B\n");
        }
    }
    if(r > b){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}


///////////////////////////////////////////


double BS(int array[],int len,int target){ //(配列,長さ,見つける値)
    int low,mid,high;

    low = 0;
    high = len-1;

    int mark;

    while(low <= high){
        mid = (low + high) / 2;
        if(array[mid] == target){
            mark = 0;
            break;
        }else if(array[mid] < target){
            low = mid + 1;
            mark = 1;
        }else{
            high = mid - 1;
            mark = -1;
        }
    }
    if(mark == 0){
        return mid; //配列の何番目か（０から）
    }else if(mark == 1){
        return (double)mid + 0.5;//なかったらどこのあいだか
    }else{
        return (double)mid - 0.5;
    }
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()

int main(){
    ll A,B;
    cin>>A>>B;
    if((A+B)>=10)cout<<"error";
    else cout<<(A+B);
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        var ar = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        WriteLine(gcd(ar[0], ar[1]));
    }
    private static int gcd(int num1,int num2)
    {
        return num1 < num2 ? gcd(num2, num1)
            : num2 == 0 ? num1 : gcd(num2, num1 % num2);
    }
    private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
    private const int MOD = 1000000007;
}



Measured memory_bytes: 17960
from math import *
from copy import *
from string import *				# alpha = ascii_lowercase
from random import *
from sys import stdin
from sys import maxsize
from operator import *				# d = sorted(d.items(), key=itemgetter(1))
from itertools import *
from collections import Counter		# d = dict(Counter(l))
import math

def bin1(l,r,k,t,b,val,ans):
	if(l>r):
		return ans
	else:
		mid=(l+r)//2
		v=k**mid
		if(v==val):
			return v
		elif(v>val):
			ans=mid
			return bin1(mid+1,r,k,t,b,val,ans)
		else:
			return bin1(l,mid-1,k,t,b,val,ans)
		
def bin2(l,r,k,t,b,val,ans):
	if(l>r):
		return ans
	else:
		mid=(l+r)//2
		v=t*(k**mid)+b*(mid)
		if(v==val):
			return v
		elif(v>val):
			ans=mid
			return bin2(l,mid-1,k,t,b,val,ans)
		else:
			return bin2(mid+1,r,k,t,b,val,ans)

def SieveOfEratosthenes(n): 
      
    # Create a boolean array "prime[0..n]" and initialize 
    #  all entries it as true. A value in prime[i] will 
    # finally be false if i is Not a prime, else true. 
    prime = [True for i in range(n+1)] 
    p = 2
    while (p * p <= n): 
          
        # If prime[p] is not changed, then it is a prime 
        if (prime[p] == True): 
              
            # Update all multiples of p 
            for i in range(p * p, n+1, p): 
                prime[i] = False
        p += 1
    l=[]
    for i in range(2,n+1):
    	if(prime[i]):
    		l.append(i)
    return l
def bin(l,r,ll,val):
	if(l>r):
		return -1
	else:
		mid=(l+r)//2
		if(val>=ll[mid][0] and val<=ll[mid][1]):
			return mid
		elif(val<ll[mid][0]):
			return bin(l,mid-1,ll,val)
		else:
			return bin(mid+1,r,ll,val)
def deci(n):
	s=""
	while(n!=0):
		if(n%2==0):
			n=n//2
			s="0"+s
		else:
			n=n//2
			s="1"+s
	return s
def diff(s1,s2):
	if(len(s1)<len(s2)):
		v=len(s1)
		while(v!=len(s2)):
			s1="0"+s1
			v=v+1
	else:
		v=len(s2)
		while(v!=len(s1)):
			s2="0"+s2
			v=v+1
	c=0
	for i in range(len(s1)):
		if(s1[i:i+1]!=s2[i:i+1]):
			c=c+1
	return c
from sys import stdin, stdout 
def fac(a,b):
	v=a
	while(a!=b):
		v*=a-1
		a=a-1
	return v
def bino(l,r,n):
	if(l>r):
		return -1
	else:
		mid=(l+r)//2
		val1=math.log((n/mid)+1,2)
		val2=int(val1)
		if(val1==val2):
			return val1
		elif(val1<1.0):
			return bino(l,mid-1,n)
		else:
			return bino(mid+1,r,n)

def binary(l,r,ll,val,ans):
	if(l>r):
		return ans
	else:
		mid=(l+r)//2
		if(val%ll[mid]==0):
			ans=ll[mid]
			return binary(l,mid-1,ll,val,ans)
		else:
			return binary(l,mid-1,ll,val,ans)
def odd(n,ans,s):
	if(n%2!=0 or n in s):
		return ans
	else:
		s.add(n)
		return odd(n//2,ans+1,s)

if __name__ == '__main__':
	a,b,c,d=map(int,input().split(" "))
	c1=0
	while(a>0 and c>0):
		if(c1==0):
			c-=b
			c1=1
		else:
			a-=d
			c1=0
	if(a<1):
		print("No")
	else:
		print("Yes")


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

using namespace std;
#define ll long long
#define pb push_back
int arr[100001];
int cnt[100001];
int main()
{	
	int n;
	cin >> n;
	ll ans = 0;
	for(int i=1; i<=n; i++) {
		cin >> arr[i];
		if(arr[i]>n) {
			ans++;
			continue;
		}
		cnt[arr[i]]++;
	}
	for(int i=1; i<=n; i++) {
		if(cnt[i]!=i) {
			if(cnt[i] > i) {
				ans += cnt[i]-i;
			}
			else {
				ans += cnt[i];
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4028
N,W = map(int, input().split())
dp = [[0 for x in range(W+1)] for y in range(N+1)]

for i in range(1,N+1):
    v, w = map(int, input().split())
    for j in range(W+1):
        if j < w:
            dp[i][j] = dp[i-1][j]
        else:
            dp[i][j] = max(dp[i-1][j],dp[i-1][j-w]+v)

print(dp[N][W])

Measured memory_bytes: 25932
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

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

    ll a[n];
    rep(i, n)cin >> a[i];

    rep(i, n){
        if(n <= (k-1)*i+1){
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 4404
#include <cstdio>
#include <vector>


int main()
{
  int n,k;
  scanf("%d%d",&n,&k);
  std::vector<int> a(n);
  for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  for(int t=0;t<k;t++){
    std::vector<int> s(n+1,0);
    for(int i=0;i<n;i++){
      s[std::max(0,i-a[i])]++;
      s[std::min(n,i+a[i]+1)]--;
    }
    a[0]=s[0];
    bool F=true;
    for(int i=1;i<n;i++){
      a[i]=a[i-1]+s[i];
      if(a[i]<n){
	F=false;
      }
    }
    if(F)
      break;
  }
  for(int i=0;i<n;i++){
    printf("%d%c",a[i],i<n-1?' ':'\n');
  }
  return 0;
}


Measured memory_bytes: 4468
#include<iostream>
#include<cstdio>
#include<cstring>

using namespace std;

int main()
{
	string str1,str2;
	cin>>str1>>str2;
	bool flag=0;
	if(str1.length()!=(str2.length()-1)){
		cout<<"No"<<endl;
		
		return 0;
	}
	for(int i=0;i<str1.length();i++){
		if(str1[i]!=str2[i]){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	
	return 0;
} 

Measured memory_bytes: 3624
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define FOR(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v),end(v)
#define debug(x) std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"

using ll=long long;
using vi=std::vector<int>;
using vvi=std::vector<vi>;
using vll=std::vector<ll>;
using vvll=std::vector<vll>;
template<typename T> using vvec=std::vector<std::vector<T>>;
template<typename T>
auto make_v(size_t sz){return std::vector<T>(sz);}
template<typename T,typename... Ts>
auto make_v(size_t sz,Ts...ts){return std::vector<decltype(make_v<T>(ts...))>(sz,make_v<T>(ts...));}
template<typename T>
void fill_v(T&var,const T&x){var=x;}
template<typename V,typename T>
void fill_v(V&v,const T&x){for(auto&& w:v){fill_v(w,x);}}

template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<std::vector<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<std::deque<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s, const std::set<T>&v){
  s<<"\n";for(auto&& elm:v){s<<elm<<"\t";}s<<"\n";return s;}

inline void scan(int&a){scanf("%d",&a);}
inline void scan(ll&a){scanf("%lld",&a);}
inline void scan(char&a){scanf(" %c",&a);}
inline void scan(double&a){scanf("%lf",&a);}
inline void scan(std::string&s){char BUF[3000000];scanf(" %s",BUF);s=std::string(BUF);}
template<typename T>
inline void scan(std::vector<T>&v){for(auto&& sv:v){scan(sv);}}
template<typename First,typename...Args>
inline void scan(First&f,Args&...args){scan(f);scan(args...);}
inline void print(int a){printf("%d\n",a);}
inline void print(ll a){printf("%lld\n",a);}
inline void print(double a){printf("%.12f\n",a);}
inline void print(std::string s){std::cout<<s<<"\n";}

using namespace std;

int mod = 1000000007;
int main() {
  int n;
  scan(n);
  vi a(n);
  scan(a);
  vi sep(3, 0);
  ll ans = 1;
  rep (i, n) {
    int last = -1;
    int cnt = 0;
    rep (j, 3) {
      if (sep[j] == a[i]) {
        last = j;
        cnt += 1;
      }
    }
    ans = ans * cnt % mod;
    if (last == -1) {
      assert (cnt == 0 && ans == 0);
      print(0);
      return 0;
    }
    sep[last] += 1;
  }
  print(ans);

  return 0;
}


Measured memory_bytes: 888
#include<iostream>
#include<cassert>
#include<cmath>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<numeric>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
typedef long long ll;
const int N = 40;
ll comb[N][N];

void precalc(){
  comb[0][0] = 1;
  REP(i,1,N){
    comb[i][0] = comb[i][i] = 1;
    REP(j,1,i){
      comb[i][j] = comb[i-1][j] + comb[i-1][j-1];
    }
  }
}

bool isvalid(int *in){
  int odd = 0;
  rep(i,26)if (in[i] % 2 == 1)odd++,in[i]--;
  return odd < 2;
}

main(){
  precalc();
  string in;
  while(cin>>in){
    int cnt[27]={0};
    rep(i,in.size())cnt[in[i]-'a']++;
    if (!isvalid(cnt)){cout << 0 << endl;continue;}    
    int n = accumulate(cnt,cnt+26,0)/2;
    ll ans = 1;
    rep(i,26){
      ans *= comb[n][cnt[i]/2];
      n -= cnt[i]/2;
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <math.h>

int main()
{
        int n;
        double xa,ya,ra,xb,yb,rb,d;

        scanf("%d",&n);
        while(n--){
                scanf("%lf%lf%lf%lf%lf%lf",&xa,&ya,&ra,&xb,&yb,&rb);
                d=sqrt((xa-xb)*(xa-xb)+(ya-yb)*(ya-yb));
                printf("%d\n",(rb>ra&&d<rb-ra)?-2:(rb<ra&&d<ra-rb)?2:(d>(ra+rb))?0:1);
        }
        return 0;
}

Measured memory_bytes: 640
N, M = map(int, input().split())
A = [0] * N
B = [0] * N

for i in range(M):
    a, b = map(int, input().split())
    if a == 1:
        A[b - 1] =1
    if b == N:
        B[a - 1] = 1

for i in range(N):
    if A[i] == 1:
        if B[i] == 1:
            print('POSSIBLE')
            exit()

print('IMPOSSIBLE')

Measured memory_bytes: 6132
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,m;cin >> n>> m;
  vector<ll> x(m);
  vector<ll> d(m-1);
  REP(i,m){
      cin >> x[i];
  }
  sort(all(x));
  ll ans = 0;
  REP(i,m-1){
      d[i] = x[i+1]-x[i];
      ans += d[i];
  }
  sort(all(d),greater<ll>());
  ll cnt = min(m-1, n-1);
  REP(i,cnt){
      ans -= d[i];
  }
  cout << ans << endl;
  


}

Measured memory_bytes: 1792
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 1e-5
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define seg_size 262144*4
#define REP(a,b) for(long long a = 0;a < b;++a)
long long dp[300000] = {};
int main() {
	iostream::sync_with_stdio(false);
	cin.tie(0);
#define int long long
	long long n, l;
	cin >> n >> l;
	vector<pair<int, int>> gogo;
	for (int i = 0; i < n; ++i) {
		int a, b;
		cin >> a >> b;
		gogo.push_back(make_pair(a, b));
	}
	gogo.push_back(make_pair(l, l + 1));
	sort(gogo.begin(), gogo.end());
	int next_max = 0;
	int now = 0;
	int ans = 0;
	for (int i = 0; i < gogo.size(); ++i) {
		if (gogo[i].first > now) {
			//bad,just gogo
			ans++;
			now = next_max;
			next_max = gogo[i].second;
		}
		else {
			next_max = max(next_max, gogo[i].second);
		}
	}
	cout << ans << " ";
	ans = 0;
	now = 0;
	next_max = 1e15;
	priority_queue<int,vector<int>,greater<int>> going;
	for (int i = 0; i < gogo.size(); ++i) {
		if (gogo[i].first > now) {
			//bad,just gogo
			while (gogo[i].first > now) {
				now = going.top();
				ans++;
				going.pop();
			}
		}
		if (now == l)ans++;
		going.push(gogo[i].second);
	}
	cout << ans-1 << endl;
	return 0;
}


Measured memory_bytes: 9128
import java.util.Scanner;
import static java.lang.Math.*;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		while (in.hasNext())
			print(in);
	}

	private static void print(Scanner in) {
		int i = 0, n = in.nextInt();
		while (true) {
			if (n == 1) {
				System.out.printf("%.0f\n", pow(2, i));
				break;
			}
			if ((n & 1) == 1)
				System.out.printf("%.0f ", (n & 1) * pow(2, i));
			n >>= 1;
			i++;
		}
	}
}

Measured memory_bytes: 19228
use std::cmp::max;
use std::cmp::min;

#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    (;;$n:expr) => {
        {
            (0..$n).map(|_| scan!()).collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let (w, h, n) = scan!(usize, usize, usize);
    let (mut left, mut right, mut top, mut bottom) = (0, w, h, 0);
    for _ in 0..n {
        let (x, y, a) = scan!(usize, usize, usize);
        match a {
            1 => left = max(left, x),
            2 => right = min(right, x),
            3 => bottom = max(bottom, y),
            4 => top = min(top, y),
            _ => continue,
        }
    }

    if left < right && bottom < top {
        println!("{}", (right - left) * (top - bottom))
    } else {
        println!("0")
    }
}


Measured memory_bytes: 4352
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int n = sc.nextInt();
		int ans = 0;
		Set<Integer> dict = new HashSet<>();
		for (int i = 0; i < n; i++) {
			dict.add(sc.nextInt());
		}
		int diff = 0;
		while (true) {
			int a = x - diff;
			if (!dict.contains(a)) {
				ans = a;
				break;
			}
			a = x + diff;
			if (!dict.contains(a)) {
				ans = a;
				break;
			}
			diff++;
		}
		System.out.println(ans);
	}
}








Measured memory_bytes: 35844
#include <iostream>
#include <string>
#include <vector>

typedef long long ll;

int main(int argc, char* argv[])
{
  ll a, b;
  std::cin >> a >> b;
  std::string judge = "Positive";

  if (a > 0 && b > 0) {
    judge = "Positive";
  } else if (a < 0 && b < 0) {
    if ((b-a) % 2 == 1) {
      judge = "Positive";
    } else {
      judge = "Negative";
    }
  } else {
    judge = "Zero";
  }

  std::cout << judge << std::endl;
  return 0;
}


Measured memory_bytes: 256
fn main() {
    let (n, m) = input();
    println!("{}", solve(n, m));
}

fn input() -> (usize, usize) {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.pop();
    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let m: usize = iter.next().unwrap().parse().unwrap();
    (n, m)
}

fn solve(n: usize, m: usize) -> (usize) {
    // n! / r! * (n-r)!
    // n! / 2 * (n-2)! = n * (n-1) / 2
    (n * (n-1) / 2) + (m * (m-1) / 2)
}



Measured memory_bytes: 4352
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=1e18;
using P=pair<int,int>;
int par[100005]={};
int find(int x) {
  if(par[x]==x) {
    return x;
  }
  return par[x]=find(par[x]);
}
bool same(int x,int y) {
  return par[x]==par[y];
}
void unit(int x,int y) {
  x=find(x),y=find(y);
  if(x!=y) {
    par[x]=y;
  }
}
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,m,s,t,q;
  cin >> n >> m;
  for(int i=0; i<n; i++) {
    par[i]=i;
  }
  for(int i=0; i<m; i++) {
    cin >> s >> t;
    unit(s,t);
  }
  cin >> q;
  while(q--) {
    cin >> s >> t;
    if(find(s)==find(t)) {
      cout << "yes" << "\n";
    }
    else {
      cout << "no" << "\n";
    }
  }
}


Measured memory_bytes: 4136