akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<stack>
#include<algorithm>
#include<queue>
using namespace std;
#define MAX_N 200000
vector<int>X[MAX_N], D[MAX_N], C;
int Depth[MAX_N], a[MAX_N], b[MAX_N], N, Q, A, B, cnt = 1;
stack<long long>S;
inline void dfs(int p) {
	int A = S.top();
	for (int i = 0; i < X[A].size(); i++) {
		if (a[X[A][i]] == -1) { S.push(X[A][i]); a[X[A][i]] = cnt; b[cnt] = X[A][i]; cnt++; dfs(X[A][i]); }
	}
	S.pop();
}
inline long long LCA(int A, int B) {
	int W = min(Depth[A], Depth[B]); A = a[A]; B = a[B];
	int L = 1, R = W, M;
	if (W == 0 || (Depth[b[A]] == 1 && Depth[b[B]] == 1 && A != B)) { return 0; }
	while (true) {
		int M = (L + R) / 2;
		int pos1 = upper_bound(D[M - 1].begin(), D[M - 1].end(), A) - D[M - 1].begin(); pos1--;
		int pos2 = upper_bound(D[M - 1].begin(), D[M - 1].end(), B) - D[M - 1].begin(); pos2--;
		int pos3 = upper_bound(D[M].begin(), D[M].end(), A) - D[M].begin(); pos3--;
		int pos4 = upper_bound(D[M].begin(), D[M].end(), B) - D[M].begin(); pos4--;
		bool p1 = false, p2 = false; if (pos1 == pos2) { p1 = true; }if (pos3 == pos4) { p2 = true; }
		if (p1 == true && p2 == false) {
			return b[D[M - 1][pos1]];
		}
		if (p1 == true && p2 == true) { L = M + 1; }
		if (p1 == false && p2 == false) { R = M; }
		if (p1 == true && p2 == true && M == W) {
			return b[D[M][pos3]];
		}
	}
}
int main() {
	cin >> N; int G = 0;
	for (int i = 1; i < N; i++) {
		cin >> G; X[G - 1].push_back(i);
	}
	for (int i = 0; i < MAX_N; i++) { Depth[i] = 1 << 30; a[i] = -1; }
	Depth[0] = 0; S.push(0); a[0] = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < X[i].size(); j++) { Depth[X[i][j]] = Depth[i] + 1; }
	}
	int C1 = 0; dfs(0);
	for (int i = 0; i < N; i++) { D[Depth[i]].push_back(a[i]); }
	for (int i = 0; i < N; i++) { sort(D[i].begin(), D[i].end()); }
	vector<pair<int, int>>vec; long long sum = 0; queue<int>Q;
	Q.push(0); vec.push_back(make_pair(0, 0));
	while (!Q.empty()) {
		int to = Q.front(); Q.pop();
		for (int i = 0; i < X[to].size(); i++) {
			vec.push_back(make_pair(Depth[X[to][i]], X[to][i]));
			Q.push(X[to][i]);
		}
	}
	for (int i = 0; i < N - 1; i++) {
		sum += vec[i].first + vec[i + 1].first;
		sum -= Depth[LCA(vec[i].second, vec[i + 1].second)] * 2;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 24124
#include <bits/stdc++.h>
 
using namespace std;
 
#define sf(n) scanf("%d", &n)
#define pd(n) printf("%.12lf", n)
#define pf(n) printf("%d", n)
#define p() printf("\n")
#define ps() printf(" ")
#define ll long long
#define ull unsigned long long
#define MAX 1e9
const int mod = 1000 * 1000 * 1000 + 7;
#define ex 1e18
#define dbl 2e09
#define qu(q) queue<int> q
#define pqu(q) priority_queue<int> q
#define len(s) s.length()
#define sz(x) int(x.size())
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second
#define clr(x) x.clear()
#define LOG(x) std::cout << x << std::endl;
 
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = 3.14159265359;
 
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};


int a[100005];
int p[10005];

int main(){
   int n;
   cin>>n;
   bool boleh =true;
   for(int i=0;i<n;++i){
      cin>>a[i];
      if(a[i]%2==0){
         if(a[i]%3!=0 and a[i]%5!=0)
            boleh=false;
      }
   }
   cout<<(boleh?"APPROVED":"DENIED")<<endl;
   return 0;
}

Measured memory_bytes: 256
N,M=[int(x) for x in input().rstrip().split()]
l_n=[]
l_m=[]


if N!=0:
  for i in range(1,N+1):
    l_n.append(i*2)
else:
  l_n.append(0)


if M!=0:
  now=1
  for i in range(M):
    l_m.append(now)
    now+=2
else:
  l_m.append(0)

now_n=0
now_m=0
cnt=0

# print(l_n)
if N==0 and M==0:
  print(0)
else:
  for i in range(len(l_n)):
    for j in range(len(l_n)):
      if i<j:
        now_n=l_n[i]+l_n[j]
        if now_n%2==0:
          cnt+=1


if N==0 and M==0:
  print(0)
else:
  for i in range(len(l_m)):
    for j in range(len(l_m)):
      if i<j:
        now_m=l_m[i]+l_m[j]
        if now_m%2==0:
          cnt+=1
  print(cnt)













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

import static java.lang.Integer.parseInt;

/**
 * A Fat Wallet - Accepted
 * PCK2014 ??????2
 */
public class Main {

	static final int[] coins = new int[]{1, 5, 10, 50, 100, 500};

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

		words = br.readLine().split(" ");

		int sum = 0;
		for (int i = coins.length - 1; i >= 0; i--) {
			sum += parseInt(words[i]) * coins[i];
			if (sum >= 1000) {
				System.out.println(1);
				return;
			}
		}
		System.out.println(0);
	}
}

Measured memory_bytes: 24392
Scanf.scanf "%d %d" (fun n x ->
  let rec f i a s =
    if i = n then s
    else
      Scanf.scanf " %d" (fun b ->
        let d = a + b - x in
        if d > 0 then f (i + 1) (max 0 (b - d)) (s + d)
        else f (i + 1) b s
      ) in
  let ans = f 1 (Scanf.scanf " %d" (fun a -> a)) 0 in
  Printf.printf "%d\n" ans
)


Measured memory_bytes: 9080
use std::cmp::*;

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

fn main() {
    let (n, w) = get!(usize, usize);
    let v = get!(usize, usize;n);
    let mut dp = vec![vec![0; w + 2]; n + 2];
    dp[0][v[0].0] = v[0].1;
    for i in 0..n {
        for j in 0..w + 1 {
            if j < 1 {
                continue;
            }
            dp[i][j] = max(dp[i][j - 1], dp[i][j]);
            if i < 1 {
                continue;
            }
            dp[i][j] = max(dp[i][j], dp[i - 1][j]);
            if j < v[i].0 {
                continue;
            }
            dp[i][j] = max(dp[i][j], dp[i - 1][j - v[i].0] + v[i].1);
        }
    }
    println!("{}", dp[n - 1][w]);
}


Measured memory_bytes: 108796
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;}
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        string s;
        cin >> s;
        ll num = len(s) - 2;
        cout << s[0] << num << s[len(s)-1] << endl;
}

Measured memory_bytes: 3592
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A = LIST()
print("bust" if sum(A) >= 22 else "win")

Measured memory_bytes: 5144
#include <iostream>
#include <cstring>

std::string N;
int K;
int dp[101][4][2];

int rec(int n, int k, bool f)
{
    int &res = dp[n][k][f];
    if (res != -1)
        return res;

    if (n == (int)N.size())
        return k == K;

    res = 0;
    int x = N[n] - '0';
    if (k < K) {
        if (!f) {
            for (int i = 1; i <= x; i++)
                if (i == x)
                    res += rec(n + 1, k + 1, f);
                else
                    res += rec(n + 1, k + 1, 1);
        }
        else
            for (int i = 1; i <= 9; i++)
                res += rec(n + 1, k + 1, 1);
    }

    if (x == 0)
        res += rec(n + 1, k, f);
    else
        res += rec(n + 1, k, 1);

    return res;
}

int main()
{
    std::cin >> N >> K;
    memset(dp, -1, sizeof(dp));
    std::cout << rec(0, 0, 0) << std::endl;
    return 0;
}

Measured memory_bytes: 256
// Problem : D - Line++
// Contest : AtCoder Beginner Contest 160
// URL : https://atcoder.jp/contests/abc160/tasks/abc160_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//Zory-2020
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
// typedef __int128 ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define FR first
#define SE second
#define MP make_pair
#define PB push_back
#define vc vector
#define db double
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bin(x) (1ll<<(x))
#define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
#define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
#define mem(x,val) memset(x,val,sizeof x)
#define Swap(a,b,n) for(int I=0;I<=n;I++) swap(a[I],b[I])
#define PC __builtin_popcountll
#ifdef DEBUG
	#define debug(A,args...) fprintf(stderr,A,##args)
#else
	#define debug(A,args...) printf("")
#endif
#define deb debug("line %d\n",__LINE__)
namespace mine
{
	ll qread()
	{
		ll ans=0,f=1;char c=getchar();
		while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
		while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
		return ans*f;
	}
	void write(ll num){if(num<0) putchar('-'),num=-num;if(num>=10) write(num/10);putchar('0'+num%10);}
	void write1(ll num){write(num);putchar(' ');}
	void write2(ll num){write(num);putchar('\n');}
	template<typename T>inline bool chmax(T&a,const T&b){return a<b?a=b,1:0;}
	template<typename T>inline bool chmin(T&a,const T&b){return a>b?a=b,1:0;}
	ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
	bool IN(ll x,ll l,ll r){return l<=x and x<=r;}
	void GG(){puts("-1");exit(0);}

	const db eps=1e-8;
	const int INF=0x3f3f3f3f;
	const int MOD=1e9+7;
	int mm(const int x){return x>=MOD?x-MOD:x;}
	template<typename T> void add(T &x,const int &y){x=(x+y>=MOD?x+y-MOD:x+y);}
	ll qpower(ll x,ll e,int mod=MOD){ll ans=1;while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
	ll invm(ll x){return qpower(x,MOD-2);}
	const int MM=5e6+10;
	ll fac[MM],facinv[MM],Inv[MM];ll Comb(int n,int m){return n<0 or n<m?0:fac[n]*facinv[m]%MOD*facinv[n-m]%MOD;}
	void PRE()
	{
		fac[0]=1;fo(i,1,MM-1) fac[i]=fac[i-1]*i%MOD;
		facinv[MM-1]=invm(fac[MM-1]);fd(i,MM-1,1) facinv[i-1]=facinv[i]*i%MOD;
		Inv[1]=1;fo(i,2,MM-1) Inv[i]=(MOD-MOD/i)*Inv[MOD%i]%MOD;
	}

	const int N=1e6+10;
	//------------------FIXED------------------
	int cnt[N];
	void main()
	{
		int n=qread(),X=qread(),Y=qread();
		fo(i,1,n) fo(j,i+1,n)
		{
			int now=j-i;
			chmin(now, abs(i-X)+1+abs(Y-j) );
			cnt[now]++;
		}
		fo(i,1,n-1) write2(cnt[i]);
	}
};//变量重名！
signed main()
{
	#ifdef DEBUG
	//freopen("a.in","r",stdin);
	// freopen("z.txt","r",stdin);
	//freopen("a.out","w",stdout);
	#endif
	srand(time(0));
	mine::main();
	//debug("\n------------------------------------------\nTime: %.2lf s\n",1.0*clock()/CLOCKS_PER_SEC);
}

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

using namespace std;

#define mp make_pair
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define forlr(i, l, r) for (int i = int(l); i < int(r); i++)
#define repeat(n) for (int hjfjke = 0; hjfjke < int(n); hjfjke++)
#define all(c) c.begin(), c.end()
#define ll long long

const int mod = 1000000007;

long long dp[405][405];
int a[405];

int32_t main() {
    std::iostream::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    forn(i, n) cin >> a[i];

    forlr(l, 2, n + 1)
    forn(i, n) {
        int j = i + l - 1;
        if (j >= n)
            continue;

        dp[i][j] = 1e18;
        long long sum = 0;
        forlr(k, i, j + 1) sum += a[k];

        for (int k = i; k < j; k++)
            dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j] + sum);
    }

    cout <<  dp[0][n - 1];

    return 0;
}

Measured memory_bytes: 1536
from sys import stdin
import heapq 

N, K = map(int, input().split())
input_data = [int(x) for x in stdin.readline().strip().split(" ")]

heapq.heapify(input_data)
sumnum = 0
for k in range(K):
    sumnum += heapq.heappop(input_data)
print(sumnum)


Measured memory_bytes: 9276
import itertools
import math

n = int(input())
dislis = []
for i in range(n):
    dislis.append(list(map(int, input().split())))

rootlis = list(itertools.permutations(dislis))

dis = 0
for lis in rootlis:
    for j in range(n-1):
        dis += ((int(lis[j][0])-int(lis[j+1][0])) ** 2 + (int(lis[j][1])-int(lis[j+1][1])) ** 2) ** (1/2)


print(str(dis/math.factorial(n)))

Measured memory_bytes: 7972
#include <iostream>
#include <math.h>
//#include <numeric>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;
#define n_max 100000

#define rep(i, a, n) for(int i = a; i < n; i++)
#define rep2(i, a, n) for(int i = a; i <= n; i++)
#define rrep(i, a, n) for(int i = a; i > n; i--)
#define rrep2(i, a, n) for(int i = a; i >= n; i--)
#define lrep(i, a, n) for(long int i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl

int main()
{
    int ans=0;
    int N;

    cin >> N;
    int H[N];

    rep(i, 0, N) {
        cin >> H[i];
    }

    rep(i, 0, N-1) {
        
        if (ans > (N-(i+1)-1)) break;
        int tmp = 0;
        //cout << i << endl;
        rep(j, 0, N-i-1) {
            if(H[i+j] < H[i+j+1]) {
                break;
            } else {
                tmp++;
            }
        }
        ans = max(tmp, ans);
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define fin(ans) cout << (ans) << endl;
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef long long lli;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<ll> vll;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<ll, str>> vpls;
typedef vector<tuple<str, ll, ll>> vtsl;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

//実行部
void Main()
{
  str s; cin >> s;
  s.pop_back();
  while(1)
  {
    if(s.size() % 2 != 1)
    {
      str S = s.substr(0, s.size() / 2);
      if(S + S == s)
      {
        fin(s.size()) exit(0);
      }
    }
    s.pop_back();
  }
  return;
}

//前処理
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  Main();
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <boost/foreach.hpp>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <stdio.h>

using namespace std;

int main (){
	
	int a,b,c,d,ABCD;

	cin >>ABCD;
	
	d=ABCD%10;
	c=((ABCD-d)%100)/10;
	b=((ABCD-c*10-d)%1000)/100;
	a=((ABCD-b*100-c*10-d)%10000)/1000;

	int check =0;
	int ans=0;
	while(check == 0){
		if(a+b+c+d==7){
			ans = 0;
			break;
		}
		if(a+b+c-d==7){
			ans = 1;
			break;
		}
		if(a+b-c+d==7){
			ans = 2;
			break;
		}
		if(a+b-c-d==7){
			ans = 3;
			break;
		}
		if(a-b+c+d==7){
			ans = 4;
			break;
		}
		if(a-b+c-d==7){
			ans = 5;
			break;
		}
		if(a-b-c+d==7){
			ans = 6;
			break;
		}
		if(a-b-c-d==7){
			ans = 7;
			break;
		}
		check=1;
	}
	if(check==1){
		cout << "error" << endl;
		return 0;
	}
	else if (ans ==0){
		cout << a << "+" << b << "+" << c << "+" << d <<"=7" << endl;
		return 0;
	}
	else if (ans ==1){
		cout << a << "+" << b << "+" << c << "-" << d <<"=7" << endl;
		return 0;
	}
	else if (ans ==2){
		cout << a << "+" << b << "-" << c << "+" << d <<"=7" << endl;
		return 0;
	}
	else if (ans ==3){
		cout << a << "+" << b << "-" << c << "-" << d <<"=7" << endl;
		return 0;
	}
	else if (ans ==4){
		cout << a << "-" << b << "+" << c << "+" << d <<"=7" << endl;
		return 0;
	}
	else if (ans ==5){
		cout << a << "-" << b << "+" << c << "-" << d <<"=7" << endl;
		return 0;
	}
	else if (ans ==6){
		cout << a << "-" << b << "-" << c << "+" << d <<"=7" << endl;
		return 0;
	}
	else if (ans ==7){
		cout << a << "-" << b << "-" << c << "-" << d <<"=7" << endl;
		return 0;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define INF 1e9

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a <= c && c <= b) cout << "Yes\n";
	else cout << "No\n";
}

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

using namespace std;

#define REP(a, i, n) for (int i = a; i < n; ++i)

long gcd(long x, long y) {
    long r = x % y;
    while(r != 0) {
        x = y;
        y = r;
        r = x % y;
    }

    return y;
}

long lcm(long x, long y) {
    return (x * (y / gcd(x, y)));
}

int main() {
    int N; // 100
    scanf("%d", &N);

    long T[N]; // 1e18
    REP(0, i, N) {
        scanf("%ld", &T[i]);
    }
    sort(T, T + N);

    long ans = 0;
    REP(0, i, N) {
        ans = (i == 0) ? T[0] : lcm(ans, T[i]);
    }

    printf("%ld\n", ans);

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, N)  for(int i=0;i<N;i++)
int H,W,D,y[90001],x[90001],d[90001];
main(){
	cin>>H>>W>>D;
	rep(i,H)
		rep(j,W){
			int A;
			cin>>A;
			y[A]=i,x[A]=j;
		}
	for(int i=D+1;i<=H*W;i++)
		d[i]=d[i-D]+abs(x[i-D]-x[i])+abs(y[i-D]-y[i]);
	cin>>D;
	rep(i,D){
		cin>>H>>W;
		cout<<d[W]-d[H]<<endl;
	}
}


Measured memory_bytes: 2176
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

fn main() {
    input!(n: usize,hs: [usize;n]);
    let result = solve(n,hs);
    println!("{:?}",result);
}

pub fn solve(n: usize,hs: Vec<usize>) -> usize {
    let mut result = vec![0;n];
    let max = hs.iter().fold(0,|max,cur| if cur > &max {*cur} else {max} );
    let mut count = 0;
    for h in 0..(max + 1) {
        let mut is_continuous = false;
        for i in 0..n {
            if result[i] < hs[i] {
                is_continuous = true;
                result[i] += 1;
            } else {
                if is_continuous {
                    is_continuous = false;
                    count += 1;
                }
            }
        }
        if is_continuous {
            count += 1;
        }
    }
    return count
}


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdio>
#include <queue>
using namespace std;

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

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

Measured memory_bytes: 1152
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
ans = 0

# cnt = 0
# for i in range(1, N+1):
# 	if N%i == N//i:
# 		# print(i)
# 		cnt += i
	# print(i, "N%i=", N%i, "N//i=", N//i)

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

yaku = make_divisors(N)
if int(N**(1/2))*(int(N**(1/2))+1) == N:
	for i, num in enumerate(sorted(yaku)):
		if i == len(yaku)//2-1:
			break
		ans += N//num-1
	print(ans)
else:
	for i, num in enumerate(sorted(yaku)):
		if i == len(yaku)//2:
			break
		ans += N//num-1
	print(ans)

Measured memory_bytes: 4076
from collections import Counter
N, K = map(int,input().split())
tele = list(map(int, input().split()))

#A1から順にワープした時の経由順
now = 0
goal,loop,visit = [],[],[0]*N

while visit[now]!=2:

  if visit[now]==0:
    goal.append(now)
  else:
    loop.append(now)
    
  visit[now] += 1
  now = tele[now]-1

if len(goal)>K:
  print(goal[K]+1)
else:
  amari = len(goal)-len(loop)
  print(loop[(K-amari)%len(loop)]+1)

Measured memory_bytes: 34416
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0

N = i()

for i in range(1,N+1):
    if 2*N <= (i+1)*i:
        print(i)
        break


Measured memory_bytes: 10092
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define X first
#define Y second
#define pb push_back
#define max_el(x) max_element(x.begin(),x.end())-x.begin()
#define min_el(x) min_element(x.begin(),x.end())-x.begin()
#define mp make_pair
#define endl '\n'
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
// DONT USE MEMSET, USE VECTORS

void solve(){
	int n;
	cin>>n;
	vector<int> a(n);
	map<int,int> st;
	for(int i=0;i<n;i++){
		cin>>a[i];
		st[a[i]] += 1;
	}
	int cnt1 =0;
	int cnt2 = 0;
	for(auto x:st){
		if(x.Y == 1) continue;
		if(x.Y % 2 == 0){
			cnt1 += 1;
		}
	}
	int ans = st.size();
	if(cnt1%2 == 0){
		cout<<ans<<endl;
	}
	else{
		cout<<ans-1<<endl;
	}


}

int main(){
	fastread;
	int t = 1;
	// cin>>t;
	for(int i=1;i<=t;i++){
		// cout<<"Case #"<<i<<": ";
		solve();
	}
	return 0;
}


Measured memory_bytes: 5376
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long n; 
    cin>>n; 
    long long a[n-1]; 
    unordered_map<int, int> mp; 
    for(int i =0; i<n-1; i++){
        cin>>a[i];
        mp[a[i]]++; 
    } 
    for(int i=1; i<=n; i++){
        cout<<mp[i]<<endl;
    }

}


Measured memory_bytes: 13036
while True:
    h,w = map(int,input().split())
    if (h == 0) & (w == 0):
        break
    else:
        for j in range(h):
            if j % 2 == 0:
                for i in range(w):
                    if i % 2 == 0:
                        print("#", end = "")
                    else:
                        print(".", end = "")
                print(sep = '\n')
            else:
                for i in range(w):
                    if i % 2 == 1:
                        print("#", end = "")
                    else:
                        print(".", end = "")
                print(sep = '\n')
        print()



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

int n, pos;
vector<int>pre, in, post;

void rec(int l, int r)
{
    if(l >= r)   return;
    int root = pre[pos++];
    int m = distance(in.begin(), find(in.begin(),in.end(), root));
    rec(l, m);
    rec(m+1, r);
    post.push_back(root);
}
void solve()
{
    pos = 0;
    rec(0, pre.size());
    for(int i=0; i<n; i++)
    {
        if(i)   cout << " ";
        cout << post[i];
    }
    cout << endl;
}
int main()
{
    int k;
    cin >> n;
    for(int i=0; i<n; i++)
    {
        cin >> k;
        pre.push_back(k);
    }
    for(int i=0; i<n; i++)
    {
        cin >> k;
        in.push_back(k);
    }
    solve();
    return 0;
}

Measured memory_bytes: 3112
//abc170_a.cpp
//Sun Jun 14 20:56:25 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007

using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	for (int i=0;i<5;i++){
		if (a[i]==0){
			cout << i+1 << endl;
			return 0;
		}
	}

}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 1e5;
const int INF = numeric_limits<int>::max();

int n, k, arr[MAXN+10], dp[MAXN+10];

int main()
{
    cin.tie(0); cout.tie(0);
    ios_base::sync_with_stdio(false);
    int i, j;

    scanf("%d%d", &n, &k);
    for(i=1; i<=n; i++) scanf("%d", &arr[i]);

    dp[1]=0;
    for(i=2; i<=n; i++)
    {
        dp[i]=INF;
        for(j=max(i-k, 1); j<i; j++)
        {
            dp[i]=min(dp[i], dp[j]+abs(arr[i]-arr[j]));
        }
    }

    printf("%d", dp[n]);

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FOR(i,a,b) for (long long i = (a); i <= (b); i++)
#define FORD(i,b,a) for (long long i = (b); i >= (a); i--)
#define endl "\n"
#define ll long long
#define x1 asdasdsaas
#define y1 cdaca1231
#define fi first
#define se second
#define pb push_back
#define ms(s, n) memset(s, n, sizeof(s))
#define all(a) (a).begin(), (a).end()
#define prec(n) fixed<<setprecision(n)
#define bitcount(n) __builtin_popcountll(n)
template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
const int MOD = 1e9 + 7;
const int MAXN = 1e6;
const int dx[4] = { -1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};

using namespace std;
inline int add(int x, int y) {
	return x + y >= MOD ? x + y - MOD : x + y;
}
inline int sub(int x, int y) {
	return x - y < 0 ? x - y + MOD : x - y;
}
inline int mul(int x, int y) {
	return (x * (ll)y) % MOD;
}

string s, t, res;
int dp[3005][3005], tx, ty, len;
void solve() {
	cin >> s >> t;
	int n = s.size(), m = t.size();
	s = " " + s;
	t = " " + t;
	dp[0][0] = 0;
	FOR(i, 1, n) {
		FOR(j, 1, m) {
			if (s[i] == t[j]) {
				dp[i][j] = dp[i - 1][j - 1] + 1;
			} else {
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
			}
		}
	}
	tx = n, ty = m, len = dp[n][m];
	while (len) {
		if (s[tx] == t[ty]) {
			res += s[tx];
			tx--, ty--;
			len--;
		} else if (dp[tx][ty] == dp[tx - 1][ty]) tx--;
		else ty--;
	}
	reverse(all(res));
	cout << res;
}
int main() {
	cout << prec(9);
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	solve();
	return 0;
}

Measured memory_bytes: 35456
#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<sstream>
using namespace std;

int N;
map<string,int> Idx;
set<string> S[100];
vector< vector<string> > V;

void count(int num){
	for(int i=0;i<V[num].size();i++){
		if(Idx[V[num][i]]!=0){
			int id=Idx[V[num][i]]-1;
			if(S[id].empty())
				count(id);
			for(set<string>::iterator it=S[id].begin();it!=S[id].end();it++)
				S[num].insert(*it);
		}
		else S[num].insert(V[num][i]);
	}
}

void solve()
{
	int size=1;
	Idx.clear();
	V.clear();
	V.resize(N);
	for(int i=0;i<100;i++)
		S[i].clear();
	for(int i=0;i<N;i++){
		string now;
		cin>>now;
		for(int j=0;j<now.size();j++)
			if(!islower(now[j])) now[j]=' ';
		istringstream is(now);
		string temp;
		is>>temp;
		Idx[temp]=size++;
		while(is>>temp) V[i].push_back(temp);
	}
	count(0);
	cout<<S[0].size()<<endl;
}

int main()
{
	while(cin>>N){
		if(N==0)
			break;
		solve();
	}
	return 0;
}

Measured memory_bytes: 1096
/* Bismillahirrahmanirrahim */
/* Author : Jehian Norman Saviero (@Reiva5) */
/**
 * Contest : NPC 2018 Qualification
 * Team    : Jehian Norman Saviero
 * Author  : Jehian Norman Saviero
 * Problem : E - Bermain Tanah
 */

/* Bismillahirrahmanirrahim */
/* Author : Jehian Norman Saviero (@Reiva5) */
#include <bits/stdc++.h>

// MACROS SAMPAH
#define Jehian using
#define Norman namespace
#define Saviero std

Jehian Norman Saviero;

// MACROS TYPE
typedef long l;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef double ld;
typedef pair<int,int> pi;
typedef pair<l,l> pl;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<l> vl;
typedef vector<ll> vll;

// MACROS FOR PRINT
#define nl printf("\n")
#define sp printf(" ")

// MACROS FOR ATTRIBUTE
#define fi first
#define se second

// MACROS FOR FUNCTION AND METHOD
#define eb emplace_back
#define mp make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ALL(x) (x).begin(), (x).end()
#define ALLN(x,n) (x), (x)+(n)
#define CUBE(x) (SQR(x)*(x))
#define SET(x,y) for (int _qwe = sizeof(x)/sizeof(x[0]); _qwe; ) x[--_qwe] = (y)
#define SQR(x) ((x)*(x))
#define SSORT(x,sz) sort(ALLN(x,sz))
#define RESET(x) memset((x), 0, sizeof(x))
#define VSORT(x) sort(ALL(x))

// MACROS READ INPUT
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%ld", &x)
#define scll(x) scanf("%lld", &x)
#define scul(x) scl(x)
#define scull(x) scll(x)

const ll sz = 8e5+5;
ll seg[sz], lazy[sz], a[sz];
ll N, M, X, L, R, Y, Z, D, A;
vector<pll> dat;

void check(ll p, ll s, ll e) {
	if (lazy[p] != 0) {
		seg[p] += lazy[p];
		if (s != e) {
			lazy[2*p] += lazy[p];
			lazy[2*p+1] += lazy[p];
		}
		lazy[p] = 0;
	}
}

void build(ll p, ll s, ll e) {
	check(p,s,e); 
	if (s == e) {
		seg[p] = a[s];
		return;
	}

	build(2*p,s,(s+e)/2);
	build(2*p+1,(s+e)/2+1,e);

	seg[p] = min(seg[2*p], seg[2*p+1]);
}

void update(ll p, ll s, ll e, ll a, ll b, ll v) {
	check(p,s,e);
	if (s >= a && e <= b) {
		seg[p] += v;
		if (s != e) {
			lazy[2*p] += v;
			lazy[2*p+1] += v;
		}
		return;
	}
	if (s > b || e < a) {
		return;
	}
	update(2*p,s,(s+e)/2,a,b,v);
	update(2*p+1,(s+e)/2+1,e,a,b,v);
	seg[p] = min(seg[2*p], seg[2*p+1]);
}

ll getMin(ll p, ll s, ll e, ll a, ll b) {
	check(p,s,e);

	if (s >= a && e <= b) {
		return seg[p];
	}
	
	if (s > b || e < a) {
		return INT_MAX;
	}

	return min(getMin(2*p,s,(s+e)/2,a,b),getMin(2*p+1,(s+e)/2+1,e,a,b));
}

int main() {
	scll(N), scll(D), scll(A);
	dat.resize(N);
	for (int i = 0; i < N; ++i) {
		scll(dat[i].fi), scll(dat[i].se);
	}
	VSORT(dat);
	for (int i = 0; i < N; ++i) {
		a[i] = dat[i].se;
	}
	build(1, 0, N-1);
	ll ans = 0;
	for (int i = 0; i < N; ++i) {
		ll bawah = i;
		pll tmp = {dat[i].fi + D + D + 1, -1};
		ll atas = upper_bound(ALL(dat), tmp) - dat.begin() - 1;
		ll curr = getMin(1, 0, N-1, bawah, bawah);
		if (curr <= 0) continue;
		ll sub = (curr + A - 1) / A;
		ans += sub;
		update(1, 0, N-1, bawah, atas, -sub * A);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 17280
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll mod=1e9+7;
ll fact[500001];
ll power(ll x,ll y)
{
    ll res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = res*x;
        res%=mod;
        y = y>>1;
        x = (x%mod*x%mod)%mod;
    } 
    return res%mod;
}
ll P(ll n,ll r)
{
	ll x=power(fact[n-r],mod-2);
	x%=mod;
	return (fact[n]*x)%mod; 
}
ll C(ll n,ll r)
{
	ll y=fact[r]*fact[n-r];
	y%=mod;
	ll x=power(y,mod-2);
	x%=mod;
	return (fact[n]*x)%mod; 
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	ll i,j,n,m,k;
	cin>>n>>m;
	fact[0]=1;
	for(i=1;i<=500000;i++)
	fact[i]=(fact[i-1]*i)%mod;
	ll ans=P(m,n)*P(m,n);
	ans%=mod;
	//cout<<ans<<'\n';
	ll p=m;
	ll ctr=m;
	ll pr=1;
	for(i=1;i<=n;i++)
	{
		ll y=P(m-i,n-i)%mod;
		y*=y;
		y%=mod;
		//y*=power(2,mod-2);
		//y%=mod;
		ll x=C(n,i)*((p*y)%mod);
		x%=mod;
		ans-=pr*x;
		pr*=-1;
		if(ans<0) ans+=mod;
		else ans%=mod;
		p*=--ctr;
		p%=mod;
	//	cout<<x<<'\n';
	}
	cout<<ans;
}

Measured memory_bytes: 7516
#include <bits/stdc++.h>
using namespace std;
#define MAX_N (int)2e5+20
#define INF 1e12+20
typedef long long LL;
int n,k,a[MAX_N],x,ans;
main(){
	ios_base::sync_with_stdio(0);
	cin>>n>>k;
	for(int i=0;i<n;++i){
		cin>>x; --x; ++a[x];
	}
	sort(a,a+n);
	reverse(a,a+n);
	for(int i=0;i<n;++i){
		if(i>=k) ans+=a[i];
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 1024
N, M = gets.chomp.split.map(&:to_i)
MOD = 10**9 + 7

if (N - M).abs > 1
    puts 0
else
    ans = 1
    (1..N).each do |n|
        ans = ((ans % MOD) * (n % MOD)) % MOD
    end
    (1..M).each do |m|
        ans = ((ans % MOD) * (m % MOD)) % MOD
    end
    puts (N == M) ? (ans * 2) % MOD : ans
end


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

const int M = 100000;

int n, m;
P war[M];

int main() {
  cin >> n >> m;
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    war[i] = make_pair(b, a);
  }
  sort(war, war + m);
  int x = 0;
  int ans = 0;
  rep(i, m) {
    if (war[i].second < x) continue;
    x = war[i].first;
    ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4332
package main

import (
	"fmt"
)

func main() {
	var n, k, q int
	fmt.Scan(&n, &k, &q)
	mem := make([]int, n+1)
	As := make([]int, q)
	for i := 0; i < q; i++ {
		fmt.Scan(&As[i])
		mem[As[i]]++
	}
	//no count mem[0]
	// no one out case
	if k > q {
		for i := 0; i < n; i++ {
			fmt.Println("Yes")
		}
		return
	} else if k <= q {
		for i := 1; i <= n; i++ {
			if k-q+mem[i] > 0 {
				fmt.Println("Yes")
			} else {
				fmt.Println("No")
			}
		}
	}
}

Measured memory_bytes: 7424
#include<algorithm>
#include<iostream>
#include<functional>
#include<cmath>
#include<iomanip>
using namespace std;
int main(){
  int a,b,all=0;
  cin>>a>>b;
  int cost[a];
  for(int i=0;i<a;i++){
    cin>>cost[i];
    all+=cost[i];
  }
  sort(cost,cost+a);
  b-=all;
  b=b/cost[0];
  cout<<a+b<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define debug(x) cerr<<#x<<" = "<<x
#define sp <<"  "
#define el <<endl
#define fgx cerr<<" ---------------------------------------------- "<<endl
#define uint unsigned int 
#define ULL unsigned long long
#define LDB long double
#define DB double
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
inline LL read(){
	LL nm=0; bool fh=true; char cw=getchar();
	for(;!isdigit(cw);cw=getchar()) fh^=(cw=='-');
	for(;isdigit(cw);cw=getchar()) nm=nm*10+(cw-'0');
	return fh?nm:-nm;
}

#define mod 998244353
namespace  CALC{
	inline int add(int x,int y){return (x+y>=mod)?(x+y-mod):(x+y);}
	inline int mns(int x,int y){return (x-y<0)?(x-y+mod):(x-y);}
	inline int mul(int x,int y){return (LL)x*(LL)y%mod;}
	inline void upd(int &x,int y){x+=y;(x>=mod)?(x-=mod):0;}
	inline void dec(int &x,int y){x-=y;(x<0)?(x+=mod):0;}
	inline int qpow(int x,int sq){int res=1;for(;sq;sq>>=1,x=mul(x,x))if(sq&1)res=mul(res,x);return res;}
}using namespace CALC;
#define M 400200
int n,m;
struct seq{
	int l,r;
	inline void gtin(){
		int a=read(),b=read();
		l=a-b,r=a+b;
	}
}p[M];
inline bool cmp(seq i,seq j){return i.r<j.r;}
int main(){
	
	n=read();
	for(int i=1;i<=n;i++) p[i].gtin(); sort(p+1,p+n+1,cmp);
	int rs=-2000000000,ans=0;
	for(int i=1;i<=n;i++) if(rs<=p[i].l)
		rs=p[i].r,++ans;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1152
#

import sys
input=sys.stdin.readline

def main():
    N,D=map(int,input().split())
    ans=0
    for i in range(N):
        X,Y=map(int,input().split())
        if X**2+Y**2<=D**2:
            ans+=1
    print(ans)
    
    
    
if __name__=="__main__":
    main()


Measured memory_bytes: 68520
N = int(input())
D,X = list(map(int,input().split()))
A = []
for i in range(N):
    A.append(int(input()))
count = X
for i in range(N):
    for j in range(D):
        if (1+A[i]*j) <= D:
            count += 1
        else:
            break
print(count)

Measured memory_bytes: 38896
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <chrono>
#include <random>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <iomanip>
#define dibs reserve
#define OVER9000 1234567890
#define tisic 47
#define soclose 1e-8
#define patkan 9
#define ff first
#define ss second
#define abs(x) (((x) < 0)?-(x):(x))
using uint = unsigned int;
using cat = long long;
using dbl = long double;
constexpr dbl pi = 3.14159265358979323846;
using namespace std;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cout << fixed << setprecision(10);
	string S;
	cin >> S;
	cout << S.substr(0, 3) << "\n";
	return 0;
}

// look at my code
// my code is amazing


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

using namespace std;
int v[101];
int main()
{
    int n, k;
    cin>>n>>k;
    for(int i=0;i<k;i++){
        int x;
        cin>>x;
        for(int j=0;j<x;j++){
            int a;
            cin>>a;
            if(v[a]==0){
                n--;
            }
            v[a]++;
        }
    }
    cout<<n;
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, std::less<>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
typedef long long int64;
typedef unsigned long long uint64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//*/998244353;
const int base = 2187;
const double eps = 1e-9;
const int N = 100'000;
const int LOGN = 19;

int n, m, k;
vector<int> g[N];
int h[N];
int p[N];
int mx[N];

void dfs(int v, int p) {
  h[v] = h[p] + 1;
  ::p[v] = p;
  for (int u : g[v]) {
    if (u != p) {
      dfs(u, v);
      mx[v] = max(mx[v], mx[u] + 1);
    }
  }
}

void solve(int) {
  int a, b;
  cin >> n >> a >> b;
  --a; --b;
  for (int i = 1; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    --x; --y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  h[b] = -1;
  dfs(b, b);
  int it = (h[a] - 1) / 2;
  int ans = !(h[a] & 1);
  for (int i = 0; i < it; ++i) {
    a = p[a];
    ++ans;
  }
  ans += mx[a];
  cout << ans << '\n';
}

void precalc() {
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i) {
    solve(i);
  }
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}


Measured memory_bytes: 12032
#include <stdio.h>

int main(void)
{
	char flags[1000001];
	int num;
	int prime[168];
	int a;
	int i;
	int j;
	int k;
	int l;
	int flag;
	
	l = 0;
	
	for(j = 2; j < 1000; j++){
		flag = 0;
		k = 32;
		while (flag != 1){
			if(k == 1){
				prime[l] = j;
				l++;
				flag = 1;
			}
			
			if((j % k == 0)&&(k != j)){
				flag = 1;
			}
			k--;
		}
	}
	for (num = 2; num <= 1000000; num++){
		flags[num] = 1;
	}
	
	k = 0;
	while (scanf("%d", &a) != EOF){
		for (i = 0; i <= 167; i++){
			j = 2;
			while (j * prime[i] <= a){
				flags[j * prime[i]] = 0;
				j++;
			}
		}
		for (i = 2; i <= a; i++){
			if( flags[i] == 1){
				k++;
			}
		}
		
		printf("%d\n", k);
		k = 0;
	}
	
	return (0);
}

Measured memory_bytes: 1384
i = raw_input().split(' ')
num = int(str(i[0]+str(i[1])))
flag = 'null'
for i in range(1000):
	if i*i==num:
		flag= 'Yes'
	else:
		pass

if flag == 'Yes':
	print 'Yes'
else:
	print 'No'

Measured memory_bytes: 2568
module IntMap = Map.Make (struct
  type t = int
  let compare = compare
end)

let add a s =
  IntMap.add a (1 + try IntMap.find a s with Not_found -> 0) s

let remove a s =
  match IntMap.find a s with
  | exception Not_found -> s
  | 1 -> IntMap.remove a s
  | n -> IntMap.add a (n - 1) s

let () = Scanf.scanf "%d %d\n" @@ fun n m ->
  let as_ = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun a -> a in
  let rec solve s = function
    | 0 -> s
    | n ->
        let (a, _) = IntMap.max_binding s in
        solve (add (a / 2) (remove a s)) (n - 1) in
  Printf.printf "%d\n" @@
  IntMap.fold (fun a n acc -> acc + a * n)
    (solve (Array.fold_right add as_ IntMap.empty) m) 0


Measured memory_bytes: 12928
#include <iostream>
#include <queue>
#include <algorithm>
#include <climits>
#include <vector>
#include <string.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define oo 1e7
using namespace std;
typedef long long ull;
typedef pair<int, int> ii;
typedef pair<long double, int> id;
typedef pair<long long, long long> llp;
const int N = 3*1e3+1;
const long long MOD = 1e9;
int n, m, t, k;
double dp[N];
int main() {
    //freopen("test.inp", "r", stdin);
    //freopen("nangcap.inp", "w", stdout);
    fastIO;
    cin>>n;
    dp[0] = 1;
    double phead, ans = 0;
    for(int i=1;i<=n;i++) {
        cin>>phead;
        for(int j=i+1;j>=0;j--) dp[j] = (j==0?0:dp[j-1]*phead) + dp[j]*(1-phead);
    }
    for(int i=0;i<=n;i++) {
        if (i>n-i) ans+=dp[i];
    }
    cout << setprecision(10) << fixed << ans;
}


Measured memory_bytes: 3780
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <functional>

int main()
{
    std::string S;
    std::cin >> S;
    int day=0;
    if(S=="SUN"){
        day=7;
    }else if(S=="MON"){
        day=6;
    }else if(S=="TUE"){
        day=5;
    }else if(S=="WED"){
        day=4;
    }else if(S=="THU"){
        day=3;
    }else if(S=="FRI"){
        day=2;
    }else if(S=="SAT"){
        day=1;
    }
    std::cout << day << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>
#include <numeric>
#include <set>
// #include <bits/stdc++.h>

using namespace std;
typedef long long li;

typedef long double lf;

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

    li n;
    cin >> n;

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

    vector<vector<lf>> dp(n + 1, vector<lf>(n + 2, 0));
    dp[0][0] = 1;

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < i + 1; ++j) {
            dp[i + 1][j + 1] += dp[i][j] * ps[i];
            dp[i + 1][j] += dp[i][j] * (1 - ps[i]);
        }
    }

    lf ans = 0;
    for (int i = 0; i <= n; ++i) {
        if (i > n - i) {
            ans += dp[n][i];
        }
    }

    cout.precision(12);
    cout << ans << endl;
    return 0;
}


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

using namespace std;

static const int MAX = 200000;

int main()
{
    int n = 0,a[MAX];

    cin >> n;

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

    int maxv = -2000000000;
    int minv = a[0];

    for(int i = 1;i<n;i++)
    {
        maxv = max(maxv,a[i]-minv);
        minv = min(a[i],minv);
    }

    cout << maxv << endl;

    return 0;

}


Measured memory_bytes: 3888
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000000
#define endl '\n'
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

signed main(){
    int n; cin>>n;
    vector<int> a(n),sum(n+1,0);
    rep(i,n){
        cin>>a.at(i);
        sum.at(i+1)=sum.at(i)+a.at(i);
    }
    int ans=INF;
    for(int i=0; i<=n; i++){
        int l=0,h=i;
        while(h-l>1){
            int mid=l+(h-l)/2;
            if(sum.at(mid)>=sum.at(i)-sum.at(mid)){
                h=mid;
            }else{
                l=mid;
            }
        }
        int p=sum.at(l),q=sum.at(i)-sum.at(l),p2=sum.at(h),q2=sum.at(i)-sum.at(h);
        int lmin=min(p,q),lmax=max(p,q);
        if(abs(p2-q2)<abs(p-q)){
            lmin=min(p2,q2);
            lmax=max(p2,q2);
        }
        int l2=i,h2=n;
        while(h2-l2>1){
            int mid=l2+(h2-l2)/2;
            if(sum.at(mid)-sum.at(i)>=sum.at(n)-sum.at(mid)){
                h2=mid;
            }else{
                l2=mid;
            }
        }
        int r=sum.at(l2)-sum.at(i),s=sum.at(n)-sum.at(l2),r2=sum.at(h2)-sum.at(i),s2=sum.at(n)-sum.at(h2);
        int rmin=min(r,s),rmax=max(r,s);
        if(abs(r2-s2)<abs(r-s)){
            rmin=min(r2,s2);
            rmax=max(r2,s2);
        }
        int tmp=max(lmax,rmax)-min(lmin,rmin);
        chmin(ans, tmp);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3328