akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main(){
int n, k;
  cin >> n >> k;
  int arr[k], diff[k];
  for(int i = 0; i < k; i++){
    cin >> arr[i];
  }
  for(int i = 0; i < k - 1; i++){
    diff[i] = arr[i+1] - arr[i];
  }
  diff[k-1] = n - arr[k-1] + arr[0];
  sort(diff, diff + k);
  cout << n - diff[k -1];
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
int head[N],cnt,fa[N],vis[N],ans[N];
struct node{
    int t,next;
} e[N];

void init()
{
    memset(head,-1,sizeof(head));
    cnt=0;
}
void add(int u,int v)
{
    e[cnt]=node{v,head[u]};
    head[u]=cnt++;
}


int father(int x)
{
	return x==fa[x]?x:fa[x]=father(fa[x]);
}

int join(int x,int y)
{
	x=father(x);
	y=father(y);
	if(x!=y)
		fa[x]=y;
}

void initfa(int n)
{
	for(int i=1;i<=n;i++)
		fa[i]=i;
}
 
 
void dfs1(int u,int tag,map<int ,int > &M)
{
    if(vis[u]==tag)return;
    vis[u]=tag;
    M[father(u)]++;
    for(int i=head[u];~i;i=e[i].next)
        dfs1(e[i].t,tag,M);
}
 
void dfs2(int u,int tag,map<int ,int > &M)
{
    if(vis[u]==tag)
		return;
    vis[u]=tag;
    ans[u]+=M[father(u)];
    for(int i=head[u];~i;i=e[i].next)
        dfs2(e[i].t,tag,M);
}
 
int main()
{	int n,k,L,u,v;
    cin>>n>>k>>L;
    init();
    initfa(n);
    while(k--)
	{
        cin>>u>>v;
        join(u,v);
    }
    while(L--)
	{
        cin>>u>>v;
        add(u,v);add(v,u);
    }
    memset(vis,0,sizeof(vis));
    for(int i=1;i<=n;i++) 
		if(!vis[i])
    	{
    	    map<int ,int > M;
    	    dfs1(i,i,M);
    	    dfs2(i,-i,M);
    	}
    for(int i=1;i<=n;i++)
        printf("%d%c",ans[i],i<n?' ':'\n');
}

Measured memory_bytes: 21888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
double a[500][500];
const ll mod = 1e9 + 7;
ll pre[200005];
int main() {
	ll n;
	cin >> n;
	ll k;
	cin >> k;
	ll j = 0;
	for(ll i = 1 ; i <= n + 1; i++){
			pre[i] += pre[i-1];
			pre[i] += j;
			j++;
	}
	ll ans = 0;
	for(ll i = k ; i <= n ; i++){
		//cout << n + 1 << " " << n  + 1 - k << endl;
		//cout << (pre[n + 1] - pre[n + 1 - i]) << " " << pre[i] << endl;
		ans += (pre[n + 1] - pre[n + 1 - i] - pre[i] + 1);
		ans %= mod;
	}
	cout << (ans + 1)%mod << endl;
	return 0;
	
}


Measured memory_bytes: 5152
import java.util.*;
import java.math.*;
public class Main {
    static final int MOD = 1_000_000_007; // 10^9+7
    //static final int MAX = 2_147_483_646; // intの最大値
    static final int INF = 1_000_000_000; // 10^9
    static final int MAX = 10_000_000;
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();
        if(s[2]==s[3]&&s[4]==s[5]){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }

    }       
}






Measured memory_bytes: 23764
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
template<class T>inline void read(T&X)
{
	X = 0;
	char symbol('\0'),ch(getchar());
	for(;ch<'0'||'9'<ch;(!(ch^'-'))?(symbol='\1'):(1),ch=getchar());
	for(;'0'<=ch&&ch<='9';X=(X<<3)+(X<<1)+(ch^48),ch=getchar());
	(symbol)?(X=-X):(1);
}
char s[100007];
int get[128];
const int MODIT=4;
int main()
{
	get['b'] = 0;
	get['p'] = 1;
	get['d'] = 2;
	get['q'] = 3;
//	gets(s+1);
	scanf("%s",s+1);
	int l=strlen(s+1),i;
//fprintf(stderr,"l = %d\n",l);
	for(i=1;i<=(l>>1)+1;++i)
	{
		if(get[s[i]]^((get[s[l-i+1]]+2)%4)) return printf("No\n"),0;
	}
//	for(i=1;i<=l;++i)
//	{
//		fprintf(stderr,"%c = %d   %c = %d\n",s[i],get[s[i]],s[l-i+1],get[s[l-i+1]]);
//	}
//	getchar();
//	getchar();
	return printf("Yes\n"),0;
}



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

int main() {

  int n;
  cin >> n;
  vector<string> s(n);
  vector<int> t(n);
  string x;
  for(int i = 0; i < n; i++) { cin >> s.at(i) >> t.at(i); } 
  cin >> x;
  
  int ans = 0;
  for(int i = 0; i < n; i++) {
    if(s.at(i) == x) {
      i++;
      for(int j = i; j < n; j++) {
        ans = ans + t.at(j);
      }
      cout << ans << endl;
      return 0;
    }
  }
}
  

Measured memory_bytes: 256
#include <stdio.h>

int main() {

  int i, j, k, min, n, x, array[100], count=0;

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

  for(i = 0; i < n; i++){
    min = i;
    for(j = i; j < n; j++){
      if(array[j] < array[min])
        min = j;
    }

    if(i != min){
      x = array[i];
      array[i] = array[min];
      array[min] = x;
      count++;
    }

  }

  for(i = 0; i < n-1; i++)
    printf("%d ", array[i]);

  printf("%d\n", array[n-1]);
  printf("%d\n", count);

  return 0;
}

Measured memory_bytes: 600
s = input()
tile_01 = ['0' if i % 2 == 0 else '1' for i in range(len(s))]
tile_10 = ['1' if i % 2 == 0 else '0' for i in range(len(s))]
tile_01 = ''.join(tile_01)
tile_10 = ''.join(tile_10)

s_01 = bin(int('0b' + s, 2) ^ int('0b' + tile_01, 2)).split('b')[1].zfill(len(s))
s_10 = bin(int('0b' + s, 2) ^ int('0b' + tile_10, 2)).split('b')[1].zfill(len(s))
short_01 = 0
short_10 = 0
for i in range(len(s_01)):
    if s_01[i] == '1':
        short_01 += 1
    elif s_10[i] == '1':
        short_10 += 1

print(min(short_01, short_10))


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

int main() {
  int n;
  cin>>n;
  int p[n];
  for(int i=0;i<n;i++){
    cin>>p[i];
  }
  int cnt=0;
  for(int i=1;i<n-1;i++){
    vector<int> q;
    q.push_back(p[i-1]);
    q.push_back(p[i+1]);
    q.push_back(p[i]);
    sort(q.begin(),q.end());
    if(p[i]==q[1]) cnt++;
  }
  cout<<cnt;
}

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

const int MAX_N = 200200;
const int INF = 1002003004;

vector<int> a, ans;
vector<int> to[MAX_N];
int dp[MAX_N];

void dfs(int v, int p){
    int i = lower_bound(dp, dp+MAX_N, a[v]) - dp;
    int old = dp[i];
    dp[i] = a[v];

    ans[v] = i;
    if(p != -1) ans[v] = max(ans[v], ans[p]);

    for(auto u: to[v]){
        if(u == p) continue;
        dfs(u,v);
    }
    dp[i] = old;
}


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

    a.resize(n);
    ans.resize(n);
    rep(i,n) cin >> a[i];

    rep(i,n-1){
        int u, v;
        cin >> u >> v;
        u--; v--;;

        to[v].push_back(u);
        to[u].push_back(v);
    }

    rep(i,MAX_N) dp[i] = INF;
    dp[0] = -INF;
    dfs(0, -1);

    rep(i,n) cout << ans[i] << endl;

    return 0;
}

Measured memory_bytes: 30928
n,m = map(int,input().split(" "))
x = set()
y = set()
for i in range(m):
  a,b =  map(int,input().split(" "))
  if(a==1):
    x.add(b)
  if(b==n):
    y.add(a)

x = x.intersection(y)

if len(x)!=0:
  print("POSSIBLE")
else:
  print("IMPOSSIBLE")
  
    

Measured memory_bytes: 19024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_range(i, s, e) for (int i = (s); i < (int)(e); i++)
#define rep_rev(i, s, e) for (int i = (s)-1; i >= (int)(e); i--)
#define sort_vec(v) sort((v).begin(),(v).end())
typedef int64_t lint;
// lint mod = 998244353;
lint mod = 1000000007;
template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

int app() {
  int n,a,b;
  cin>>n>>a>>b;

  if(a<b) swap(a,b);

  vector<vector<lint>>
  dp(n+1,vector<lint>(n+1,0)),
  // dp[la][lb]: 1がlbからkまで続き、長さb以上の1の連続を0にすると0がlaからkまで続く場合の数
  sumdpb(n+1,vector<lint>(n+1,0));  // sum(dp[la][0...lb])
  dp[0][0]=1;
  sumdpb[0][0]=1;
  rep_range(k,1,n+1){
    rep_range(la,max(0,k-a-b),k){
      dp[la][k]+=dp[la][k-1];  // ***0.0
      // ****.1 は変わらない
      dp[k-1][k]+=(k>=2?sumdpb[la][k-2]:0)-(k>=b+1?sumdpb[la][k-b-1]:0);  // ***1.0
      dp[la][k]+=(k>=b+1?sumdpb[la][k-b-1]:0);  // **11.0
      if(la<=k-a) dp[la][k]=0;
      else dp[la][k]%=mod;
      dp[k-1][k]%=mod;
      sumdpb[la][k]=(sumdpb[la][k-1]+dp[la][k])%mod;
    }
  }

  lint ans=0;
  rep(k,n+1){
    rep(la,n+1){
      if(k==n||n-k>=b){
        if(n-la<a) ans+=dp[la][k];
      }else{
        if(k-la<a) ans+=dp[la][k];
      }
      ans%=mod;
    }
  }

  lint all=1;
  rep(_,n) all=all*2%mod;
  return (all-ans+mod)%mod;
}

int main(){cout<<app()<<endl;return 0;}


Measured memory_bytes: 394468
/*  chuckie   */
#include <bits/stdc++.h>
//#define CHUCKIE

 
#define cint(d) scanf("%d", &d)
#define cint2(a, b) scanf("%d %d", &a, &b)
#define cint3(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define cint4(a, b, c, d) scanf("%d %d %d %d", &a, &b, &c, &d)
 
#define clong(d) scanf("%lld", &d)
#define clong2(a, b) scanf("%lld %lld", &a, &b)
#define clong3(a, b, c) scanf("%lld %lld %lld", &a, &b, &c)
#define clong4(a, b, c, d) scanf("%lld %lld %lld %lld", &a, &b, &c, &d)
 
const long long MOD = 1000000007;
#define MODSET(d) if ((d) >= MOD) d %= MOD;
#define MODR(d) ((d)>=MOD?(d)%MOD:(d))
#define MODNEGSET(d) if ((d) < 0) d = ((d % MOD) + MOD) % MOD;
#define MODADDSET(d) if ((d) >= MOD) d -= MOD;
#define MODADDWHILESET(d) while ((d) >= MOD) d -= MOD;
 
#define foreach(it,c) for(__typeof((c).begin()) it = (c).begin(); it!=(c).end(); it++) 
#define MAX 1000000
#define ll long long
#define mp make_pair
#define pb push_back
 
using namespace std;

typedef vector<int> vi;
typedef pair<int,int> ii;


int main()
{
	
	#ifdef CHUCKIE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	string s1,s2,s3;
	cin>>s1>>s2>>s3;
	
	if(s1[s1.length()-1]==s2[0] && s2[s2.length()-1]==s3[0])
	cout<<"YES"<<endl;
	
	else cout<<"NO"<<endl;
	
	
	
	
	return 0;
}


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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<double, double> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

using namespace std;

static const ll INF = 1e15;

const ll mod = 1000000007;
ll n, m;
vector<vector<int>> g;
vector<P> dp;
vector<bool> v;

P dfs(int current, int block) {
	if (v[current]) {
		return dp[current];
	}
	vector<P> path;
	const int c = g[current].size();
	for (int next : g[current]) {
		path.push_back(dfs(next, block));
	}
	double zero = 0;
	double one = 0;
	for (auto p : path) {
		zero += p.first;
		one += p.second;
	}
	double all = zero;
	zero /= c;
	zero += 1;
	one /= c;
	one += 1;
	double cut = INF;
	if (c > 1 && current == block) {
		for (auto p : path) {
			cut = min(cut, all - (p.first));
		}
		cut /= (c - 1);
		cut += 1;
	}
	dp[current] = { zero, min(cut, one) };
	v[current] = true;
	return dp[current];
}

int main() {
	cin >> n >> m;
	g.resize(n);
	rep(i, m) {
		int s, t;
		cin >> s >> t;
		s--; t--;
		g[s].push_back(t);
	}
	double ans = INF;
	for (int block = 0; block < n - 1; block++) {
		dp.assign(n, P(INF, INF));
		v.assign(n, false);
		dp[n - 1] = { 0,0 };
		v[n - 1] = true;
		for (int i = n - 2; i >= 0; i--) {
			dfs(i, block);
		}
		ans = min(ans, min(dp[0].first, dp[0].second));
	}
	cout << setprecision(10) << ans << endl;
	return 0;
}


Measured memory_bytes: 5028
#include <iostream>
#include <vector>
#define rep(i, n) for (int i=0; i < (n); i++)
using namespace std;
typedef long long ll;
 
 // 1つずつ線形探索したら、計算量が爆発
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}

ll lcm(ll a, ll b) {
    return a/gcd(a,b)*b;
}

ll f(ll x, int c, int d) {
    ll result = x;
    result -= x/c;
    result -= x/d;
    result += x/lcm(c, d);
    return result;
}

int main() {
    // int だとオーバーフローする
    ll a, b;
    int c, d;
    cin >> a >> b >> c >> d;

    ll ans = f(b, c, d) - f(a - 1, c, d);
    cout << ans << endl;
    return 0;
}


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

int main() {
  int N, M, L;
  int five = 0;
  int seven = 0;

  cin >> N >> M >> L;
  if (N == 5){
    five++;
  }
  else if (N == 7){
    seven++;
  }
  if (M == 5){
    five++;
  }
  else if (M == 7){
    seven++;
  }
  if (L == 5){
    five++;
  }
  else if (L == 7){
    seven++;
  }

  if ((five==2) && (seven==1)){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
n = gets.to_i
a = gets.split.map{|s|s.to_i}
b = gets.split.map{|s|s.to_i}

try =  b.inject(:+) - a.inject(:+)
as = bs = 0
n.times do |i|
  if a[i] == b[i]
    next
  elsif a[i] > b[i]
    as += a[i] - b[i]
  elsif a[i] < b[i]
    bs += ((b[i] - a[i] + 1)/2)
  end
end

if try < 0
  puts 'No'
elsif try >= as and try >= bs
  puts 'Yes'
else
  puts 'No'
end

Measured memory_bytes: 2940
#include <iostream>
using namespace std;
int main(void){
    int a ,b ;
    char op;
    cin >> a>> op >> b;
    while(op !='?'){
        switch (op){
            case '+':
            cout<<a+b<<endl;
            break;
            
             case '-':
            cout<<a-b<<endl;
            break;
            case '*':
            cout<<a*b<<endl;
            break; 
            case '/':
            cout<<a/b<<endl;
            break;
        }
        cin >> a >> op >> b;
    }
    
}



Measured memory_bytes: 3076
import sys
 
def main():
    input = sys.stdin.readline
    N = int(input())
    S = input().rstrip()
    tree = SegmentTree(initial_values=S, f=lambda x,y:x|y, converter=lambda c: 1 << (ord(c)-ord('a')))
    Q = int(input())
    update = tree.update
    query = tree.query
    for _ in range(Q):
        t, a, b = input().rstrip().split()
        if t == '1': update(int(a)-1, b)
        else: print(bin(query(int(a)-1, int(b))).count('1'))    

class SegmentTree:
    def __init__(self, n=None, f=max, zero_factory=int, converter=lambda x:x, initial_values=None):
        assert(n or initial_values)
        self.__f, self.__z, self.__c = f, zero_factory, converter
        size = n if n else len(initial_values)
        self.__n = 1 << ((size - 1).bit_length())
        d = [zero_factory() for _ in range(2 * self.__n + 1)]
        self.__dat = d
        if initial_values:
            for i, v in enumerate(initial_values): d[self.__n + i] = converter(v)
            for i in range(self.__n - 1, 0, -1): d[i] = f(d[i<<1], d[i<<1|1])

    def update(self, index, value):
        i, v, d, f = index + self.__n, self.__c(value), self.__dat, self.__f
        if d[i] == v: return
        d[i] = v
        while i:
            i = i >> 1
            d[i] = f(d[i<<1], d[i<<1|1])

    def query(self, from_inclusive, to_exclusive):
        ans = self.__z()
        if to_exclusive <= from_inclusive: return ans
        l, r, d, f = from_inclusive + self.__n, to_exclusive + self.__n, self.__dat, self.__f
        while l < r:
            if l & 1: ans, l = f(ans, d[l]), l+1
            if r & 1: ans, r = f(ans, d[r-1]), r-1
            l, r = l >> 1, r >> 1
        return ans

if __name__ == '__main__':
    main()


Measured memory_bytes: 116300
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <sstream>

#define rep(i, a) REP(i, 0, a)
#define REP(i, a, b) for(int i = a; i < b; ++i)
#define rrep(i, a) RREP(i, a, 0)
#define RREP(i, a, b) for(int i = a; i >= b; --i)
#define repll(i, a) REPLL(i, 0, a)
#define REPLL(i, a, b) for(ll i = a; i < b; ++i)
#define rrepll(i, a) RREPLL(i, a, 0)
#define RREPLL(i, a, b) for(ll i = a; i >= b; --i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> P;
typedef std::pair<P, int> PP;
const double PI = 3.14159265358979323846;
const double esp = 1e-9;
const int infi = (int)1e+9 + 10;
const ll infll = (ll)1e+17 + 10;

int n;
int a[100001];
int dp[100001];

int main(){
	std::cin >> n;
	rep(i, n)std::cin >> a[i];
	rep(i, n)dp[i] = infi;

	rep(i, n){
		*std::lower_bound(dp, dp + n, a[i]) = a[i];
	}
	std::cout << std::lower_bound(dp, dp + n, infi) - dp << std::endl;

	return 0;
}

Measured memory_bytes: 1940
//3:54開始
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main(){
    int N;
    cin>>N;
    int group;
    queue<int> Q[1000];
    for(int i=0;;i++){
        if(i*(i-1)==N*2){
            group=i;
            break;
        }
        if(i==1000){
            puts("No");
            return 0;
        }
    }
    if(group==1){
        Q[0].push(1);
        Q[0].push(2);
        Q[1].push(1);
        Q[1].push(2);
    }
    else{
        int pp=1;
        for(int i=0;i<group;i++){
            for(int j=i+1;j<group;j++){
                Q[i].push(pp);
                Q[j].push(pp);
                pp++;
            }
        }
    }
    cout<<"Yes"<<endl;
    cout<<group<<endl;
    for(int i=0;i<group;i++){
        cout<<Q[i].size();
        while(Q[i].size()){
            cout<<' '<<Q[i].front();
            Q[i].pop();
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 2816
#include <iomanip>
#include <iostream>

using namespace std;

#define REP(i,from,to) for( long long int i = (from); i < (to); i++ )
#define ll long long
#define LIN(a) ll a; cin >> a;
#define SIN(a) string a; cin >> a;

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}


signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
  SIN(s) LIN(k) char ans;
  bool first = 1, one = 1;
  REP( i, 0, s.size() ){
    if( i < k && s[i] != '1'){
      one = 0;
    }
    if( first && s[i] != '1'){
      ans = s[i];
      first = 0;
    }
  }
  if( one ){
    puta( 1 );
  }else{
    puta( ans );
  }
  return 0;
}


Measured memory_bytes: 256
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <iomanip>

typedef long double ld;
typedef long long ll;

using namespace std;


/* TENPLATE ENDS HERE */

#define MAXN (1 << 10)

bool a[MAXN][MAXN];
int N;

bool match(int u, bool vis[], int ass[]) {
   for (int v = 0; v < N; v++) {    //for all jobs 0 to N-1
      if (a[u][v] && !vis[v]) {    //when job v is not v and u is interested
         vis[v] = true;    //mark as job v is v
         //when v is not assed or previously assed
         if (ass[v] < 0 || match(ass[v], vis, ass)) {
            ass[v] = u;    //ass job v to applicant u
            return true;
         }
      }
   }
   return false;
}

int maxMatch() {
   int ass[N];    //an array to track which job is assed to which applicant
   for(int i = 0; i<N; i++)
      ass[i] = -1;    //initially set all jobs are available
   int ret = 0;

   for (int u = 0; u < N; u++) {    //for all applicants
      bool v[N];
      for(int i = 0; i< N; i++)
         v[i] = false;    //initially no jobs are v
      if (match(u, v, ass))    //when u get a job
         ret++;
   }
   return ret;
}

vector<pair<int, int> > v1, v2;

int main() {
	cout << fixed << setprecision(12);	
	cin >> N;
	for (int i = 0; i < N; i++) {
		int t1, t2;
		cin >> t1 >> t2;
		v1.push_back(make_pair(t1, t2));
	}
	for (int i = 0; i < N; i++) {
		int t1, t2;
		cin >> t1 >> t2;
		v2.push_back(make_pair(t1, t2));
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (v2[i].first > v1[j].first && v2[i].second > v1[j].second) {
				a[i][j] = true;
			} else {
				a[i][j] = false;
			}
		}
	}
	cout << maxMatch() << endl;
	return 0;
}





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

using namespace std;

#define pb push_back
#define eb emplace_back
#define ll long long
#define pii pair < int, int >
#define fr first
#define sc second
#define mk make_pair
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()
#define ok puts("ok");
#define whatis(x) cerr << #x << " = " << x << endl;
#define pause system("pause");

const int N = (int)2e5 + 7;
const int inf = (int)1e9 + 7;

int n;
int a[N], b[N];
ll sum;

void putans(ll asd) {
  cout << asd;
  exit(0);
}

main() {
  scanf("%d", &n);
  int mn = inf;
  bool fl = 1;
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &a[i], &b[i]);
    sum += a[i];
    fl &= (a[i] == b[i]);
    if (a[i] > b[i])
      mn = min(mn, b[i]);
  }
  if (fl) putans(0);
  putans(sum - mn);
}


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

int main()
{
	int N, M;
	long long K;
	cin >> N >> M >> K;
	vector<long long> A( N );
	for( int i = 0; i < N; i++ ) {
		cin >> A[i];
	}
	vector<long long> B( M );
	for( int i = 0; i < M; i++ ) {
		cin >> B[i];
	}

	vector<long long> asum( N + 1 );
	for( int i = 0; i < N; i++ ) {
		asum[i + 1] = asum[i] + A[i];
	}
	vector<long long> bsum( M + 1 );
	for( int i = 0; i < M; i++ ) {
		bsum[i + 1] = bsum[i] + B[i];
	}
	long long ans = 0;
	for( int i = 0; i < N + 1; i++ ) {
		long long k = K - asum[i];
		if( k < 0 ) continue;
		long long j = upper_bound( bsum.begin(), bsum.end(), k ) - bsum.begin() - 1;
		ans = max( ans, i + j );
	}

	cout << ans << endl;
}


Measured memory_bytes: 9584
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll mod = 1000000007;

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

  ll n, k, s;
  cin >> n >> k >> s;

  vector<ll> a(n);
  for (int i = 0; i < k; i++) {
    a[i] = s;
  }

  for (int i = k; i < n; i++) {
    if (s == 1000000000) a[i] = 999999999;
    else a[i] = 1000000000;
  }

  for (auto &x: a) cout << x << " ";
  cout << endl;

  return 0;
}


Measured memory_bytes: 2176
x=int(input())
i=0
while True:
  for j in range(0,i+1):
    a=j
    b=i-j
    if a**5-b**5==x:
      print(a,b)
      exit()
    a*=-1
    if a**5-b**5==x:
      print(a,b)
      exit()
    b*=-1
    if a**5-b**5==x:
      print(a,b)
      exit()
    a*=-1
    if a**5-b**5==x:
      print(a,b)
      exit()
  i+=1


Measured memory_bytes: 9200
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
ll n,a[100005];
ll w[100005];
int main(){
	cin >> n;
	for(int i=0;i<n;i++) cin >> a[i];
	sort(a,a+n);
	P cur = mp(0,0);
	while(1){
		cur.fi++; cur.sc++;
		if(cur.fi==n || a[n-1-cur.fi] <= cur.sc){
			cur.fi--; cur.sc--; break;
		}
	}
	P q = cur;
	int A=0,B=0;
	while(1){
		q.fi++;
		if(a[n-1-q.fi] <= q.sc){
			break;
		}
		A++;
	}
	q = cur;
	while(1){
		q.sc++;
		if(a[n-1-q.fi] <= q.sc){
			break;
		}
		B++;
	}
	if(B%2 || A%2) puts("First");
	else puts("Second");
}

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

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

  set<string> s;

  string v;
  cin >> v;
  s.insert(v);
  rep(i, N - 1) {
    string w;
    cin >> w;

    if (s.find(w) != s.end() || v[v.size() - 1] != w[0]) {
      puts("No");
      return 0;
    }
    s.insert(w);
    v = w;
  }

  puts("Yes");
}

Measured memory_bytes: 256
while True:
    n = input()
    if n == 0: break
    info = []
    for i in range(n):
        lu, w = map(int, raw_input().split())
        info.append((w, lu))
    info.sort()
    lu_sum = 0
    flag = True
    for w, lu in info:
        lu_sum += lu
        if lu_sum > w:
            flag = False
    print("Yes" if flag else "No")

Measured memory_bytes: 4212
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

int N;
LL K;
LL as[214514];
LL I[214514];
LL BIT[214514];

void Add(int k, int x) {
  k++;
  while (k <= 214510) {
    BIT[k] += x;
    k += k&-k;
  }
}

LL Sum(int k) {
  k++;
  LL ret = 0;
  while (k > 0) {
    ret += BIT[k];
    k -= k&-k;
  }
  return ret;
}

int main() {
  scanf("%d%lld", &N, &K);

  using Pair = pair<LL, int>;
  priority_queue<Pair> ps;

  ps.push(Pair(0, 0));
  rep(i, N) {
    LL a;
    scanf("%lld", &a);
    I[i+1] = I[i] + a;
    ps.push(Pair(I[i+1]-K*(i+1), i+1));
  }

  LL ans = 0;
  while (!ps.empty()) {
    Pair p = ps.top(); ps.pop();
    int idx = p.second;
    ans += Sum(N+10) - Sum(idx);
    Add(idx, 1);
  }
  printf("%lld\n", ans);
  
}


Measured memory_bytes: 8944
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AOJ
{
	class Program
	{
		static void Main(string[] args)
		{
			var str = "";
			var stack = new Stack<int>();
			while ((str = Console.ReadLine()) != null)
			{
				var n = 0;
				var b = int.TryParse(str,out n);
				if (!b) continue;
				if (n != 0) stack.Push(n);
				else Console.WriteLine(stack.Pop());
			}
		}
	}
}

Measured memory_bytes: 5908
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<iomanip>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>

#define int long long

using namespace std;

void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> vec(n);
    for (auto& x : vec) cin >> x;
    for (int i = k; i < n; ++i) {
        if (vec[i] > vec[i - k]) cout << "Yes\n";
        else cout << "No\n";
    }
}

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

    int t = 1;
    //cin >> t;
    while (t--) solve();

    return 0;
}

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

lli a, b, c;

int main(void){
	cin >> a >> b >> c;
	if(c-a-b > 0 && a*a+b*b+c*c-2*a*b-2*b*c-2*c*a > 0) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 3532
/*
 *       ~ AtCoder  Botay ~
 *        code by kazalika
 */

#include <bits/stdc++.h>

using namespace std;

const long long mod = 1e9 + 7;

long long pw(long long a, long long b) {
  if (!b)
    return 1;
  if (b % 2)
    return (pw(a, b - 1) * a) % mod;
  long long v = pw(a, b / 2);
  return (v * v) % mod;
}

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

pair<long long, long long> get(long long a, long long b) {
  if (b == 0)
    return {1, 0};
  if (a == 0)
    return {0, 1};
  if (b > 0)
    return {a / gcd(abs(a), abs(b)), b / gcd(abs(a), abs(b))};
  return {-a / gcd(abs(a), abs(b)), -b / gcd(abs(a), abs(b))};
}

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


  int n;
  cin >> n;

  map<pair<long long, long long>, long long> mp, rmp;
  long long ans = 1, cn = 0;
  for (int i = 0; i < n; ++i) {
    long long a, b;
    cin >> a >> b;
    if (a == 0 && b == 0) {
      cn++;
      continue;
    }
    pair<long long, long long> vp = get(a, b), rvp = (a != 0 ? get(b, -a) : get(-b, a));
    if (mp.find(rvp) != mp.end())
      rmp[rvp]++;
    else
      mp[vp]++;
  }
  for (auto& i : mp) {
    long long vl = pw(2, i.second);
    if (rmp.find(i.first) != rmp.end())
      vl += pw(2, rmp[i.first]) - 1;
    vl %= mod;
    ans = (ans * vl) % mod;
  }
  cout << (ans + cn - 1 + mod) % mod;

}

Measured memory_bytes: 16128
import numpy as np
n,k=map(int,input().split())
h=np.array(list(map(int,input().split()))+[0]*k)
dp = np.full(n+k, 10 ** 10, dtype=np.int64)
dp[0] = 0
for i in range(1,n):
    dp[i:i+k]=np.minimum(dp[i:i+k],np.abs(h[i:i+k]-h[i-1])+dp[i-1])
print(dp[n-1])

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

using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;

#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;

#define sz(x) (int)(x).size()
#define HOGE cout << "hoge" << endl;
using P = pair<ll,ll>;

template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}

int main(){
    int N, R;
    cin >> N >> R;
    if(N>=10) cout << R << endl;
    else cout << R + 100*(10-N) << endl;
}


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

int binary(int);
int n;
int S[N];

int main(){
  int q, i, c=0, flag;
  int T[Q]={};

  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d",&S[i]);
  }

  scanf("%d",&q);
  for(i=0; i<q; i++){
    scanf("%d",&T[i]);
  }

  for(i=0; i<q; i++){
    flag = binary(T[i]);
    if(flag == 1){
      c++;
    }
  }
    
  printf("%d\n",c);

  return 0;
}

int binary(int key){
  int mid, left, right;
  left = 0;
  right = n;
  while (left < right){
    mid = (left + right)/2;
  if(S[mid] == key){
    return  1;
  } else if(key < S[mid]){
    right = mid;
  } else {
    left = mid + 1;
  }
  }
    return 0;
}

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

int c2i(char c){return c - '0';}

string str;
int dp[10][10];

void solve() {
	for (int i = 0; i < 10; i++) {
		dp[0][i] = c2i(str[i]);
	}

	for (int i = 1; i < 10; i++) {
		for (int j = 0; j < 10 - i; j++) {
			dp[i][j] = (dp[i-1][j] + dp[i-1][j+1]) % 10;
		}
	}

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

int main(int argc, const char *argv[]) {
	while (cin>>str) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 0
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        OneorTwo solver = new OneorTwo();
        solver.solve(1, in, out);
        out.close();
    }

    static class OneorTwo {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();

            UnionFind uf = new UnionFind(n);
            Set<Integer> set = new HashSet<>();
            for (int i = 0; i < m; i++) {
                int x = Integer.parseInt(in.next()) - 1;
                int y = Integer.parseInt(in.next()) - 1;
                int z = Integer.parseInt(in.next());
                uf.unite(x, y);
            }
            for (int i = 0; i < n; i++) {
                set.add(uf.findSet(i));
            }
            out.print(set.size());
        }

        public class UnionFind {
            private int[] size;
            private int[] parents;

            public UnionFind() {
            }

            public UnionFind(int size) {
                this.size = new int[size];
                this.parents = new int[size];
                for (int i = 0; i < size; i++) {
                    makeSet(i);
                }
            }

            public void makeSet(int x) {
                parents[x] = x;
                size[x] = 1;
            }

            public int findSet(int x) {
                if (x != parents[x]) {
                    parents[x] = findSet(parents[x]);
                }
                return parents[x];
            }

            public boolean unite(int x, int y) {
                if (same(x, y)) {
                    return false;
                }
                link(findSet(x), findSet(y));
                return true;
            }

            public boolean same(int x, int y) {
                return findSet(x) == findSet(y);
            }

            private void link(int x, int y) {
                if (size[x] > size[y]) {
                    parents[y] = parents[x];
                    size[x] += size[y];
                } else {
                    parents[x] = parents[y];
                    size[y] += size[x];
                }
            }

        }

    }
}



Measured memory_bytes: 60616
def is_possible(x, A):
    current = {}
    length = 0
    for a in A:
        if a <= length:
            if x == 1:
                return False
            current = {k: current[k] for k in current if k < a}
            i = a - 1
            if i not in current:
                current[i] = 0
            current[i] += 1
            while i in current and current[i] >= x:
                if i == 0:
                    return False
                if (i-1) not in current:
                    current[i-1] = 0
                current[i-1] += 1
                del current[i]
                i -= 1
        length = a

    return True


def main():
    N = int(input())
    A = list(map(int, input().split()))
    left = 1
    right = N
    while left < right:
        center = (left + right) // 2
        if is_possible(center, A):
            right = center
        else:
            left = center + 1
    print(left)


if __name__ == "__main__":
    main()


Measured memory_bytes: 86868
/***
 *      百年修得同船渡，千年修得代码重.
 *      百年修得同船渡，千年修得代码重.
 *      百年修得同船渡，千年修得代码重.
 *      百年修得同船渡，千年修得代码重.
 *      百年修得同船渡，千年修得代码重.
 *      百年修得同船渡，千年修得代码重.
 *      百年修得同船渡，千年修得代码重.
 *      百年修得同船渡，千年修得代码重.
 *      百年修得同船渡，千年修得代码重.
 *      百年修得同船渡，千年修得代码重.
 *      百年修得同船渡，千年修得代码重.
 *      百年修得同船渡，千年修得代码重.
 *      百年修得同船渡，千年修得代码重.
 *      百年修得同船渡，千年修得代码重.
 *      百年修得同船渡，千年修得代码重.
 *      百年修得同船渡，千年修得代码重.
 *      百年修得同船渡，千年修得代码重.
 *      百年修得同船渡，千年修得代码重.
 *      百年修得同船渡，千年修得代码重.
 *      百年修得同船渡，千年修得代码重.
 *      百年修得同船渡，千年修得代码重.
 *      百年修得同船渡，千年修得代码重.
 *      百年修得同船渡，千年修得代码重.
 *      百年修得同船渡，千年修得代码重.
 *      百年修得同船渡，千年修得代码重.
 */
#include <iostream>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <string>
#include <stack>
using namespace std;
//int n,m,x,y;
//char a[1010][1010];
//int vis[1010][1010];
//void dfs()
//{
//
//}
//int main()
//{
//    while(~scanf("%d%d",&n,&m))
//    {
//        for(int i=0;i<n;i++)
//        scanf("%s",a[i]);
//        for(int i=0;i<n;i++)
//            for(int j=0;j<m;j++)
//        {
//            if(a[i][j]=='*')
//                vis[i][j]=2;
//                if(a[i][j]=='+')
//                    vis[i][j]=1;
//                if(a[i][j]=='F')
//                    vis[i][j]=3;
//                if(a[i][j]=='G')
//                {
//                    x=i;
//                    y=j;
//                }
//                if(i==0&&a[i][j]=='+')
//                    vis[i][j]=4;
//                if(i==n&&a[i][j]=='+')
//                    vis[i][j]=4;
//                if(j==0&&a[i][j]=='+')
//                    vis[i][j]=4;
//                if(j==m&&a[i][j]=='+')
//                    vis[i][j]=4;
//
//        }
//
//     for(int i=0;i<n;i++)
//            {
//                for(int j=0;j<m;j++)
//                printf("%d ",vis[i][j]);
//                printf("\n");
//            }
// }
//    return 0;
//}
long long a[100000];
int main()
{
    long long n;
   for(int i=1;i<=100000;i++)
   a[i]=i*i;
   while(~scanf("%lld",&n))
   {int flag=0;
       for(int i=1;i<100000;i++)
       {
           if(a[i]==n)
           {
               printf("%lld\n",a[i]);
               break;
           }
           if(a[i]>n)
           {
               printf("%lld\n",a[i-1]);
               break;
           }
       }
   }

    return 0;
}

Measured memory_bytes: 1024
N = int(input())
A = [int(i) for i in input().split(" ")]
check1 = 0
for i in range(N):
    if A[i]%2==0:
        if A[i]%3!=0 and A[i]%5!=0:
            check1=1
            
if check1==0:
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 3060
//#include<bits/stdc++.h>
    #include<iostream>
    using namespace std;
    const int N = 1000005;
    int main(){
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        long long a,b,n;  cin >> a >> b >> n;
        if(n >= b)  n = b - 1;
        long long ans = (a * n)/b;
        cout << ans;
        return 0;
    }

Measured memory_bytes: 3160
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
template <typename T>
class SegmentTree{
    public:
        ll size;
        vector<T> node;
        T identity_ele;  //comp(x, identity_ele) == x
        function<T(T, T)> comp;

        SegmentTree(const vector<T> &v, function<T(T, T)> comp, T identity_ele){
            ll tmp = 1;
            while(tmp < v.size()) tmp = (tmp << 1);
            this->size = tmp;
            this->identity_ele = identity_ele;
            this->comp = comp;
            node.resize(2 * size - 1);
            for(ll i = 0; i < v.size(); i++){
                node[i + size - 1] = v[i];
            }
            for(ll i = size - 2; 0 <= i; i--){
                node[i] = comp(node[i * 2 + 1], node[i * 2 + 2]);
            }
        }

        void update(ll pos, T value){
            pos += size - 1;
            node[pos] = value;
            while(pos > 0){
                pos = (pos - 1) / 2;
                node[pos] = comp(node[2 * pos + 1], node[2 * pos + 2]);
            }
        }

        T query(ll a, ll b){
            return subQuery(a, b, 0, 0, size);
        }

        T subQuery(ll a, ll b, ll k, ll l, ll r){
            if(r <= a || b <= l){
                return identity_ele;
            }else if(a <= l && r <= b){
                return node[k];
            }else{
                T left = subQuery(a, b, k * 2 + 1, l, (l + r) / 2);
                T right = subQuery(a, b, k * 2 + 2, (l + r) / 2, r);
                return comp(left, right);
            }
        }
};

using P = pair<ll, ll>;
const ll INF = 5e15;
const ll MOD = 1e9 + 7;

int main(){
    ll N;
    cin >> N;
    SegmentTree<ll> ST(vector<ll>(N + 1, 0), [](ll a, ll b){ return max(a, b); }, 0);
    vector<P> V(N);
    for(P &p : V) cin >> p.first;
    for(P &p : V) cin >> p.second;
    for(const P &p : V){
        ll tmp = ST.query(0, p.first);
        ST.update(p.first, tmp + p.second);
    }
    cout << ST.query(0, N + 1) << endl;
    return 0;
}


Measured memory_bytes: 7524
n,x,y = map(int, input().split())
x -= 1
y -= 1
ans = [0]*n
for i in range(n):
    for j in range(i+1,n):
        if j <= x or y <= i:
            ans[j-i] += 1
        elif i <= x and x <= j and j <= y:
            d = min(j-i,x+y-i-j+1)
            ans[d] += 1
        elif x <= i and y<= j:
            d = min(j-i,i-x+1+j-y)
            ans[d] += 1
        elif x <= i and j <= y:
            d = min(j-i,i-x+1+y-j)
            ans[d] += 1
        else:
            d = x - i + 1 + j - y
            ans[d] += 1


for i in ans[1:]:
    print(i)

Measured memory_bytes: 48604
#include<stdio.h>
#include<stdlib.h>
int main()
{
	int i,j,h,w,a[32][32],k,l,m=2147483000,r;
	scanf("%d %d",&h,&w);
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			scanf("%d",&a[i][j]);
		}
	}
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			r=0;
			for(k=0;k<h;k++){
				for(l=0;l<w;l++){
					r+=a[k][l]*(abs(i-k)>abs(j-l)?abs(j-l):abs(i-k));
				}
			}
			if(r<m)m=r;
		}
	}
	printf("%d\n",m);
	return 0;
}



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

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// cout << fixed << setprecision(20);

signed main() {
    int N;
    cin>>N;
    int ans=0;
    for(int i=0;i<1000000;i++){
        int a=i,x=0;
        int c0=0,c3=0,c5=0,c7=0;
        while(a>0){
            if(a%4==0)c0++;
            else if(a%4==1)x+=3,c3++;
            else if(a%4==2)x+=5,c5++;
            else if(a%4==3)x+=7,c7++;
            a/=4,x*=10;
        }
        x/=10;
        if(c0==0&&c3>0&&c5>0&&c7>0&&N>=x)ans++;
    }
    cout<<ans<<endl;

}


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

MOD = 10**9+7
def compress(L):
    L2 = list(set(L))
    L2.sort()
    C = {v : k for k, v in enumerate(L2)}
    return L2, C

N = int(readline())
height = [0]
H = list(map(int, readline().split()))
height.extend(H)

orih, C = compress(height)

L = len(orih)

dp = [0]*L
dp[0] = 1

phidx = 0
for i in range(1, N+1):
    hidx = C[H[i-1]]
    dp2 = [0]*L
    if phidx >= hidx:
        for h in range(hidx+1):
            dp2[h] = (dp[hidx]+dp[h])%MOD
    else:
        if phidx == 0:
            dp2[0] = pow(2, orih[hidx])%MOD
            for h in range(1, hidx+1):
                dp2[h] = pow(2,  orih[hidx]-orih[h]+1, MOD)
        else:
            for h in range(hidx+1):
                dp2[h] = (dp[phidx] + dp[min(phidx, h)])*pow(2, orih[hidx]-orih[max(h, phidx)], MOD)%MOD
    dp = dp2[:]
    phidx = hidx
    #print(dp)
print(dp[0])
            


Measured memory_bytes: 156188
import numpy as np

n, k = map(int, input().split())
A = list(map(int, input().split()))
All = [[0]*41 for i in range(n)]
K = [0]*41
stopper = 0
sum_ = 0



for i in range(len(A)):
    bin_a = format(A[i],'b')
    list_a = [int(i) for i in bin_a]
    All[i] = [0]*(41-len(list_a))+ list_a
    
bin_k =   format(k,'b') 
list_k = [int(i) for i in bin_k]
K = [0]*(41-len(list_k))+list_k

b = np.cumsum(All, axis = 0)
B = b[len(b)-1]
    
for i in range(41):
    if K[i]==1 and B[i]>= (n+1)//2:
        K[i]=0
        stopper = i
        break

if stopper!=0 and stopper<=39:
    for i in range(stopper+1,41):
        if  B[i]>= (n+1)//2:
            K[i] = 0
        else:
            K[i] = 1
            
            
for i in range(41):
    if K[i]==1:
        B[i] = n-B[i]

for i in range(1,42):
    sum_ = sum_ + B[-i]*(2**(i-1))

print(sum_)

Measured memory_bytes: 119960
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
using namespace std;
#define ll           long long
#define all(v)       (v).begin() , (v).end()
#define vi           vector <ll>
#define vii          vector <pair<ll,ll>>
#define ii           pair<ll,ll>
#define sz(v)	     ((int)((v).size()))
#define lp(i,a,b)    for(int i=a;i<b;i++)
#define pb           push_back
#define pf           push_front
#define F            first
#define S            second
#define endl         "\n"
#define IOS          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const double PI = 3.14159265358979323846;
const ll inf=2e9,MOD=998244353,MAX=1e7+2;

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    IOS;
    int n;
    cin>>n;
    int a[n];
    lp(i,0,n)
        cin>>a[i];
    sort(a,a+n);
    cout<<a[n/2]-a[n/2-1];
}

Measured memory_bytes: 4040
#include "bits/stdc++.h"
#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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define ALL(obj) (obj).begin(),(obj).end()

using namespace std;

const int INF = 99999999;
const ll LINF = 9999999999999;

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
int vx[4] = { 0,1,0,-1 };
int vy[4] = { 1,0,-1,0 };


int n, m,k;
bool ban[1000][1000] = {};
signed main() {

	std::ios::sync_with_stdio(false);
	std::cin.tie(0);

	cin >> n >> m >> k;

	REP(i, n+1)REP(j, m+1) {
		if (i*m + j*(n - i * 2 )== k) {
			cout << "Yes" << endl;
			return 0;
		}

	}
	cout << "No" << endl;
	return 0;

}

Measured memory_bytes: 256
#include <iostream>

int main() {
    int n, res=0;
    std::string a, b, c;
    std::cin >> n >> a >> b >> c;
    for (int i=0; i<n; ++i) {
        if (a[i] != b[i] || b[i] != c[i]) {
            res += (a[i] != b[i] && b[i] != c[i] && c[i] != a[i]) ? 2:1;
        }
    }
    std::cout << res << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define pob pop_back
#define vi vector<ll>
#define mp make_pair
#define sz size()
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define rep(i,n) for(ll i=0;i<n;i++)
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define maxx 10005
#define se second
#define fi first
#define sortv(v) sort(v.begin(),v.end());
#define w() ll _;cin>>_;while(_--)
#define edge pair<ll,ll>
#define pq priority_queue<ll>
#define M 10000007
#define Endl "\n"
using namespace std;



int main()
{
	fast;
	
	ll n;
	cin>>n;
	ll a[n];
	ll i;
	map<ll,ll>m;
	set<ll>s;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		m[a[i]]++;
	
	}
	
	sort(a,a+n);
	ll cnt=0;
	ll j;
	
	for(i=0;i<n;i++)
	{
		ll x=a[i];
		ll f=0;
		if(m[a[i]]==1)
		{
			for(j=1;j*j<=x;j++)
			{
				if(x%j==0)
				{
					if(s.count(j) || s.count(x/j))
					{
						f++;
						break;	
					}	
				}	
			}		
			
			if(f==0)
			{
				cnt++;
			}
		}
	
		s.insert(x);
			
	}
	
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 26956
#include<stdio.h>
#define MAX 10000
#define NIL -1

struct Node { int p, l, r; };
struct Node T[MAX];
int n;

void preParse(int u) {
  if ( u == NIL ) return;
  printf(" %d", u);
  preParse(T[u].l);
  preParse(T[u].r);
}

void inParse(int u) {
  if ( u == NIL ) return;
  inParse(T[u].l);
  printf(" %d", u);
  inParse(T[u].r);
}

void postParse(int u) {
  if ( u == NIL ) return;
  postParse(T[u].l);
  postParse(T[u].r);
  printf(" %d", u);
}

int main() {
  int i, v, l, r, root;

  scanf("%d", &n);
  for( i = 0; i < n; i++ )
    T[i].p = NIL;

  for ( i = 0; i < n; i++ ) {
    scanf("%d %d %d", &v, &l, &r);
    T[v].l = l;
    T[v].r = r;
    if ( l != NIL ) T[l].p = v;
    if ( r != NIL ) T[r].p = v;
  }

  for ( i = 0; i < n; i++ ) if ( T[i].p == NIL ) root = i;

  printf("Preorder\n");
  preParse(root);
  printf("\n");
  printf("Inorder\n");
  inParse(root);
  printf("\n");
  printf("Postorder\n");
  postParse(root);
  printf("\n");

  return 0;
}


Measured memory_bytes: 2708