akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;

int main() {
  ll N,K;
  cin >> N >> K;
  int sz = 0;
  map<ll,bool> mp;
  for (ll i = 1; i * i <= N; i++) {
    mp[i] = true;
  }
  for (ll i = 1; i * i <= N; i++) {
    mp[N/i] = true;
  }
  for (auto p : mp) {
    sz++;
  }
  ll DP[K][sz];
  ll num[sz];
  int cnt = 0;
  for (auto p : mp) {
    ll left1 = 0;
    ll right1 = N+1;
    ll left2 = 0;
    ll right2 = N+1;
    while (right1 - left1 > 1) {
      ll mid1 = (left1 + right1) / 2;
      if (N / mid1 <= p.F) {
        right1 = mid1;
      } else {
        left1 = mid1;
      }
    }
    while (right2 - left2 > 1) {
      ll mid2 = (left2 + right2) / 2;
      if (N / mid2 < p.F) {
        right2 = mid2;
      } else {
        left2 = mid2;
      }
    }
    DP[0][cnt] = p.F;
    num[cnt] = right2 - right1; 
    cnt++;
  }

  for (int i = 1; i < K; i++) {
    for (int j = 0; j < sz; j++) {
      if (j == 0) {
        DP[i][j] = DP[i-1][(sz-1)-j] * num[(sz-1)-j];
        DP[i][j] %= Mod;
      } else {
        DP[i][j] = DP[i-1][(sz-1)-j] * num[(sz-1)-j];
        DP[i][j] %= Mod;
        DP[i][j] += DP[i][j-1];
        DP[i][j] %= Mod;
      }
    }
  }
  cout << DP[K-1][sz-1] << endl;
  return 0;
}

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

int main(){
    int N; cin >> N;
    vector<int> A(N);
    unordered_set<int> st;
    for(int i = 0; i < N; i++) cin >> A[i];
    int cnt = 0;
    for(int i = 0; i < N; i++){
        if(A[i] / 400 >= 8) cnt++;
        else st.insert(A[i]/400);
    }
    int n = st.size();
    int MIN = 0, MAX;
    if(n == 0) MIN = 1;
    else MIN = n;
    MAX = n + cnt;
    cout << MIN << " " << MAX << endl;

}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define F            first
#define S            second
#define pb(x)        push_back(x)
#define mp(a,b)      make_pair(a,b)
#define mt(a,b,c)    make_tuple(a,b,c);
#define sz           size()
#define all(A)       A.begin(), A.end()
#define mem(a, b)    memset(a, b, sizeof(a))   // all elements of A are b=0 or b=-1 else don't work
#define f0(i,b)      for(ll i=0;i<(b);i++)
#define f1(i,b)      for(ll i=1;i<=(b);i++)
#define f2(i,a,b)    for(ll i=(a);i<=(b);i++)
#define f3(i,b,a)    for(ll i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(ll i=(a);i!=(b);i+=(c))

#define mod          10000
#define PI           acos(-1.0)

#define whilee(i,t)  while(i!=t)
#define  sl(a)       scanf("%lld",&a)
#define  pl(a)       printf("%lld\n",a)

#define scan(x)      do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;

//for(auto it =A.begin(); it!=A.end(); it++)
//sort(A.begin(),A.end()); //sort(A, +n, greater<int>());
//binary_search(A.begin(),A.end(),x);
//reverse(A.begin(), A.end());
//cout << *max_element(A.begin(), A.end());
//cout << *min_element(A.begin(), A.end());
//count(A.begin(), A.end(), X); //counts the occurrences of X
//distance(A.begin(),A.end());  //distance between first to last element
//accumulate(A.begin(), A.end(), 0); //add
//next_permutation(A.begin(), A.end());
//prev_permutation(A.begin(), A.end());
//swap(S[0], T[0]);

//scanf("%lld",&x);
//printf("%lld\n",x);
//while (scanf("%lld %lld", &a, &b) == 2)
//printf("Case %lld: %lld\n", t++, a);

//vector <ll> A;
//deque <ll> A;
//queue <ll> A;
//stack <ll> A;
//list <int> A;
//set <ll> A;
//map <ll,ll> A;
//pair <ll,ll> A ;
//tuple <ll, ll, ll> A;
//vector <pair <ll,ll>> A ;
//bitset<32> bset1;
//bool ok = true;
//char ch;
string S, T, U;
ll i=0, j=0, k=0, a, b, c, d, e, f, g, h, l, m, n, o, p, q, r, s, t=1, u, v, w, x, y, z, maxx=INT_MIN, minn=INT_MAX, ans=0, sum=0, cnt=0;

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

    //scan(n);
    cin>>S>>T>>U;

    cout<<S[0]<<T[1]<<U[2]<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,x;
    scanf("%d",&n);


    x=n%10;
    if(x== 2 || x==4 || x==5 ||x ==7|| x==9)
    {
        cout<<"hon"<<endl;
    }
    else if(x==0 || x==1 || x==6 || x==8)
    {
        cout<<"pon"<<endl;
    }
    else if(x==3)
    {
        cout<<"bon"<<endl;
    }


return 0;
}


Measured memory_bytes: 3764
#include<stdio.h>
#include<algorithm>
#include<functional>
#define MM 2100000000
using namespace std;
long long int dp[1001][1001];
int main(void)
{
	int n,m,a[1001],b[1001],i,k;
	
	scanf("%d %d",&n,&m);
	for(i=1;i<=n;i++)	scanf("%d",&a[i]);
	for(i=1;i<=m;i++) scanf("%d",&b[i]);
	a[0]=0; b[0]=0;
	for(i=0;i<=n;i++){
		for(k=0;k<=m;k++) dp[i][k]=MM;
	}

	dp[0][0]=0;
	for(i=0;i<m;i++){
		for(k=0;k<=n;k++){
			if(dp[i+1][k]>dp[i][k])  dp[i+1][k]=dp[i][k]; 
			if(k+1<=n && dp[i][k]!=MM)  dp[i+1][k+1]=dp[i][k]+a[k+1]*b[i+1]; 
		}
	}
	printf("%d\n",dp[m][n]);
	return 0;
}

Measured memory_bytes: 10424
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
int main(void) {
    char ch;
    int cnt = 0;
    for(int i = 0; i < 6; ++i) {
        cnt += (ch = getchar()) == '1';
    }
    printf("%d\n", cnt);
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

//Village
public class Main{

	double[] x, y;
	
	void run(){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		double R = sc.nextDouble(), EPS = 1e-8;
		double cos1 = Math.cos(1*Math.PI/180), sin1 = Math.sin(1*Math.PI/180);
		x = new double[n]; y = new double[n];
		for(int i=0;i<n;i++){
			double X = sc.nextDouble(), Y = sc.nextDouble();
			x[i] = cos1*X-sin1*Y;
			y[i] = sin1*X+cos1*Y;
		}
		Integer[] v = new Integer[n];
		for(int i=0;i<n;i++)v[i]=i;
		Arrays.sort(v, new Comparator<Integer>() {
			public int compare(Integer o1, Integer o2) {
				return (int)Math.signum(x[o1]-x[o2]);
			}
		});
		int res = 0;
		boolean[] u = new boolean[n];
		for(int i=0;i<n;i++){
			int idx = v[i];
			if(u[idx])continue;
			u[idx] = true;
			res++;
			double lx = x[idx]-R-EPS, rx = x[idx]+R+EPS;
			int l = 0, r = n;
			while(r-l>1){
				int m = (l+r)/2;
				if(lx<=x[v[m]])r=m;
				else l=m;
			}
			int k1 = l;
			l = 0; r = n;
			while(r-l>1){
				int m = (l+r)/2;
				if(rx<x[v[m]])r=m;
				else l=m;
			}
			int k2 = r;
			if(k2==r)k2--;
			for(int j=k1;j<=k2;j++){
				int k = v[j];
				if(u[k])continue;
				if(Math.sqrt((x[idx]-x[k])*(x[idx]-x[k]) + (y[idx]-y[k])*(y[idx]-y[k])) < R+EPS){
					u[k] = true;
				}
			}
		}
		System.out.println(res);
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 20000
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#include <vector>
#include <numeric>
#include <map>
#include <cmath>
#include <iomanip>
#include <queue>
#include <set>
using ll =long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vs = vector<string>;


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

    for(int i=0; i<=X; i++){
        if(2*i + 4*(X-i) == Y){
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
}

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

typedef long long int ll;

int a[200010];
ll ans = 0, s0[200010],s1[200010];
void solve(int n,int L){
	for(int i=1;i<=n;i++)
		s0[i] = s0[i-1]+a[i];
	for(int i=1;i<=n;i++)
		s1[i] = s1[i-1]+ (L-a[n-i+1]);
	for(int i=1;i<=n;i++){
		ll cur = 0;
		int x = (n-i) >> 1;
		if((n-i)&1){
			cur += 2 * (s0[i+x] - s0[i-1]);
			cur += s1[x+1]-s1[x];
			cur += 2 * s1[x];
		}
		else{
			cur += 2 * s1[x];
			cur += 2 * (s0[i+x-1] - s0[i-1]);
			cur += s0[i+x] - s0[i+x-1];
		}
		ans = max(ans,cur);
	}
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int L,n;
	cin>>L>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	solve(n,L);
	reverse(a+1,a+n+1);
	for(int i=1;i<=n;i++)
		a[i] = L - a[i];
	solve(n,L);
	cout<<ans<<endl;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
int const INF = 1e9+7;

int h,w,ys,xs,yg,xg; char maze[1000][1000]; int d[1000][1000];
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

int bfs(){
    queue<P> que;
    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++) d[i][j]=INF;
    }
    que.push(P(ys,xs)); d[ys][xs]=0;

    while(que.size()){
        P p=que.front(); que.pop(); int py=p.first,px=p.second;
        if(py==yg&&px==xg)break;
        for (int i = 0; i < 4; i++){
            int ny=py+dy[i],nx=px+dx[i];
            if(ny>=0&&ny<h&&nx>=0&&nx<w&&maze[ny][nx]!='X'&&d[ny][nx]==INF){
                que.push(P(ny,nx)); d[ny][nx]=d[py][px]+1;
            }
        }
    }
    return d[yg][xg];
}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
   
    int n; cin>>h>>w>>n; P che[n+1];
    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            cin>>maze[i][j];
            if(maze[i][j]=='S')che[0]=P(i,j);
            else if(maze[i][j]!='.'&&maze[i][j]!='X')che[maze[i][j]-'0']=P(i,j);
        }
    }
    int ans=0;
    for (int i = 0; i < n; i++){
        ys=che[i].first; xs=che[i].second; yg=che[i+1].first; xg=che[i+1].second;
        ans+=bfs();
    }
    cout<<ans<<'\n';
}


Measured memory_bytes: 8020
#include <stdio.h>

char* class[11]={
	"light fly",	"fly",			"bantam",
	"feather",		"light",		"light welter",
	"welter",		"light middle",	"middle",
	"light heavy",	"heavy"
};

int limit[11]={48,51,54,57,60,64,69,75,81,91,-1};

int main(void){
	float weight; int i;
	while(scanf("%f",&weight)==1){
		for(i=0; i<10; i++) if(weight<=limit[i]) break;
		printf("%s\n",class[i]);
	}
	return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <iostream>
#include <vector>
#include <utility>

using namespace std;  

int gcd(int a, int b){
  if(a < b) swap(a,b);
  int r = a % b;
  while(r){
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

int main(){

  int N; cin >> N;
  vector <int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A.at(i);
  }
  vector <int> r(N),l(N);
  l.at(0) = A.at(0);
  r.at(N-1) = A.at(N-1);
  for(int i = 1; i < N; i++){
    l.at(i) = gcd(l.at(i-1), A.at(i));
    r.at(N-i-1) = gcd(r.at(N-i), A.at(N-i-1));
  }
  vector <int> g(N);
  g.at(0) = r.at(1);
  g.at(N-1) = l.at(N-2);
  for (int i = 1; i < N-1; i++){
    g.at(i) = gcd(l.at(i-1),r.at(i+1));
  }

  cout <<  *max_element(g.begin(),g.end()) << endl;
}


Measured memory_bytes: 1792
import java.util.*;
public class Main {
    public static void main(String[] args) {
        String[] WeekDAYS = new String[]{"SUN","MON","TUE","WED","THU","FRI","SAT"};
        Scanner obj1=new Scanner(System.in);
        String str = obj1.nextLine();
        if (str.equals("SUN"))
            System.out.println(7);
        else if(str.equals("MON"))
            System.out.println(6);
        else if(str.equals("TUE"))
            System.out.println(5);
        else if(str.equals("WED"))
            System.out.println(4);
        else if(str.equals("THU"))
            System.out.println(3);
        else if(str.equals("FRI"))
            System.out.println(2);
        else if(str.equals("SAT"))
            System.out.println(1);
    }
}

Measured memory_bytes: 21844
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
#include<cassert>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long long segtree[2][524288];
long long query(int a,int b,int c,int d,int e,int f){
	if(d<a||b<c)return inf;
	if(c<=a&&b<=d)return segtree[f][e];
	return min(query(a,(a+b)/2,c,d,e*2,f),query((a+b)/2+1,b,c,d,e*2+1,f));
}
void update(int a,long long b,int c){
	a+=262144;
	while(a){
		segtree[c][a]=min(segtree[c][a],b);
		a/=2;
	}
}
int p[210000];
int main(){
	int a,b,A,B;
	scanf("%d%d%d%d",&a,&b,&A,&B);
	for(int i=0;i<2;i++)for(int j=0;j<524288;j++)segtree[i][j]=inf;
	for(int i=0;i<b;i++)scanf("%d",p+i);
	int last=B;
	update(A,A,0);
	update(A,-A,1);
	long long hs=0;
	for(int i=0;i<b;i++){
		long long L=query(0,262143,p[i],a,1,0)-p[i];
		long long R=query(0,262143,0,p[i],1,1)+p[i];
		long long V=hs+min(L,R);
		hs+=ABS(p[i]-last);
	//	printf("%lld %lld\n",hs,V);
		update(last,V-hs+last,0);
		update(last,V-hs-last,1);
		last=p[i];
	}
	long long ret=inf;
	for(int i=0;i<=a;i++){
		ret=min(ret,hs+segtree[0][i+262144]-i);
	}
	printf("%lld\n",ret);
}

Measured memory_bytes: 9088
while True:
  a, b = map(int, input().split())
  if a == 0 and b == 0:
    break
  an = [[-1 for i in range(b)] for j in range(a)]
  n = int(input())
  for i in range(n):
    x, y = map(int, input().split())
    an[x-1][y-1] = 0
  for i in range(a):
    for j in range(b):
      if an[i][j] == -1:
        if (i == 0 and j == 0):
          an[i][j] = 1
        elif i == 0:
          if an[i][j-1] == 0:
            an[i][j] = 0
          else:
            an[i][j] = 1
        elif j == 0:
          if an[i-1][j] == 0:
            an[i][j] = 0
          else:
            an[i][j] = 1
        else:
          an[i][j] = an[i-1][j] + an[i][j-1]
  print(an[i][j])


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

typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

#define pi pair<int,int>
#define pl pair<lld,lld>

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())
#define vuniq(x) x.erase(unique(x.begin(), x.end()), x.end())

#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

int main() {
    ll N,H,W;
    cin >> N >> H >> W;
    ll cnt = 0;
    for (int i = 0; i < N; i++) {
        ll A,B; cin >> A >> B;
        if(A >= H && B >= W){
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3632
// :pray: :steph:
// :pray: :bakekaga:

#include <iostream>
#include <fstream>
#include <vector>
#include <array>
#include <algorithm>
#include <utility>
#include <map>
#include <queue>
#include <set>
#include <cmath>

#define ll long long
#define eps 1e-8
#define MOD 1000000007

#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3f

// change if necessary
#define MAXN 1000000

using namespace std;

int n, m;
string s, t;
int dp[3001][3001][4];

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

    cin >> s >> t;
    n = (int)(s.size());
    m = (int)(t.size());

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (s[i - 1] == t[j - 1]) {
                dp[i][j][0] = dp[i - 1][j - 1][0] + 1;
                dp[i][j][1] = i - 1;
                dp[i][j][2] = j - 1;
                dp[i][j][3] = 1;
            } 

            if (dp[i - 1][j][0] > dp[i][j - 1][0]) {
                if (dp[i - 1][j][0] > dp[i][j][0]) {
                    dp[i][j][0] = dp[i - 1][j][0];
                    dp[i][j][1] = i - 1;
                    dp[i][j][2] = j;
                    dp[i][j][3] = 0;
                }
            } else {
                if (dp[i][j - 1][0] > dp[i][j][0]) {
                    dp[i][j][0] = dp[i][j - 1][0];
                    dp[i][j][1] = i;
                    dp[i][j][2] = j - 1;
                    dp[i][j][3] = 0;
                }
            }
        }
    }

    string ans = "";

    int curX = n;
    int curY = m;

    while (curX > 0 || curY > 0) {
        if (dp[curX][curY][3]) {
            ans += s[curX - 1];
        }

        //cout << "\t" << curX << ' ' << curY << '\n';
        //cout << "\t[" << dp[curX][curY][0] << ' ' << dp[curX][curY][1] << ' ' << dp[curX][curY][2] << ' ' << dp[curX][curY][3] << "] \n";
        int nextX, nextY;
        nextX = dp[curX][curY][1];
        nextY = dp[curX][curY][2];
        curX = nextX;
        curY = nextY;

        //cout << curX << ' ' << curY << '\n';
        //cout << "[" << dp[curX][curY][0] << ' ' << dp[curX][curY][1] << ' ' << dp[curX][curY][2] << ' ' << dp[curX][curY][3] << "] ";
    }

    /* for (int i = 0; i <= 4; i++) { */
    /*     for (int j = 0; j <= 4; j++) { */
    /*         cout << "[" << dp[j][i][0] << ' ' << dp[j][i][1] << ' ' << dp[j][i][2] << ' ' << dp[j][i][3] << "] "; */
    /*     } */
    /*     cout << '\n'; */
    /* } */

    for (int i = (int)(ans.size()) - 1; i >= 0; i--) {
        cout << ans[i];
    }
    cout << '\n';

    return 0;
}


Measured memory_bytes: 140928
#include<cstring>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<queue>
#include<bitset>
#include<cstdlib>
#include<set>
#include<unordered_map>
#define l(x) (x<<1)
#define r(x) ((x<<1)|1)
#define low(x) (x&(-x))
#define IL inline
#define reg register
#define LL long long
#define N 500010
#define MOD 998244353
#define MO 1000000007
#define INF 0x3f3f3f3f
using namespace std;

int T,n,m,i,j,k,y,z,pos,l,r;
LL Ans,x;
int a[N],b[N];
char c[N];

IL LL Min(LL a,LL b){return (a<b)?a:b;}
IL LL Max(LL a,LL b){return (a>b)?a:b;}

IL int read(){
	int p=0,f=1;	char	c=getchar();
	while (c<48||c>57)	{if (c=='-')	f=-1;	c=getchar();}
	while (c>=48&&c<=57)	p=(p<<1)+(p<<3)+c-48,c=getchar();
	return p*f;
}

struct Segtree{
	struct Tree{
		int l,r;
		LL d,lz;
	}t[N*4];

	IL void Maketree(int x,int low,int high){
		int mid=(low+high)>>1;
		t[x].l=low;	t[x].r=high;
		if (low==high){t[x].d=a[low];	return;}
		Maketree(l(x),low,mid);	Maketree(r(x),mid+1,high);
		t[x].d=Min(t[l(x)].d,t[r(x)].d);
	}

	IL void Push(int x){
		LL p=t[x].lz;
		t[l(x)].d+=p;	t[r(x)].d+=p;
		t[l(x)].lz+=p;	t[r(x)].lz+=p;
		t[x].lz=0;
	}

	IL void Add(int x,int low,int high,LL val){
		reg int mid=(t[x].l+t[x].r)>>1;
		if (t[x].l==low && t[x].r==high){
			t[x].d+=val;	t[x].lz+=val;
			return;
		}
		if (t[x].lz) Push(x);
		if (high<=mid)	Add(l(x),low,high,val);
		else if (low>mid)	Add(r(x),low,high,val);
		else Add(l(x),low,mid,val),Add(r(x),mid+1,high,val);
		t[x].d=Min(t[l(x)].d,t[r(x)].d);
	}

	IL LL Query(int x,int low,int high){
		reg int mid=(t[x].l+t[x].r)>>1;
		if (t[x].l==low && t[x].r==high)	return t[x].d;
		if (t[x].lz) Push(x);
		if (high<=mid)	return Query(l(x),low,high);
		else if (low>mid)	return Query(r(x),low,high);
		else return Min(Query(l(x),low,mid),Query(r(x),mid+1,high));
	}
}T1,T2;

struct Tree{
	int l,r;
	LL d,lz;
}t[N*4];

int main(){
	#ifdef __Marvolo
	freopen("zht.in","r",stdin);
	freopen("zht.out","w",stdout);
	#endif
	n=read();	m=read();
	T1.Maketree(1,1,m);
	for (i=1;i<=m;i++)	a[i]=-i;
	T2.Maketree(1,1,m);
	for (i=1;i<=n;i++){
		l=read();	r=read();
		
		if (r<m){
			Ans=T2.Query(1,1,r);	x=T1.Query(1,r+1,r+1);
			if (Ans+r+1<x)	T1.Add(1,r+1,r+1,Ans+r+1-x),T2.Add(1,r+1,r+1,Ans+r+1-x);
		}

		T1.Add(1,l,r,INF);	T2.Add(1,l,r,INF);
		T1.Add(1,1,m,1);	T2.Add(1,1,m,1);
		
		Ans=T1.Query(1,1,m);
		if (Ans>=INF)	puts("-1");
		else printf("%lld\n",Ans);
	}
	return 0;
}

Measured memory_bytes: 29016
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<cstdlib>
#include<stack>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<set>
using namespace std;
#define lck_max(a,b) ((a)>(b)?(a):(b))
#define lck_min(a,b) ((a)<(b)?(a):(b))
#define INF 1e9+7
typedef long long LL;
const int maxn=1e5+7;
LL n;
long double a,T,h[maxn];
inline LL read()
{
	LL kr=1,xs=0;
	char ls;
	ls=getchar();
	while(!isdigit(ls))
	{
		if(!(ls^45))
			kr=-1;
		ls=getchar();
	}
	while(isdigit(ls))
	{
		xs=(xs<<1)+(xs<<3)+(ls^48);
		ls=getchar();
	}
	return xs*kr;
}
inline void out(LL xs)
{
	if(!xs) {putchar(48); return;}
	if(xs<0) putchar('-'),xs=-xs;
	int kr[57],ls=0;
	while(xs) kr[++ls]=xs%10,xs/=10;
	while(ls) putchar(kr[ls]+48),ls--;
}
int main()
{
	LL jl;long double minn=INF;
	n=read();scanf("%Lf%Lf",&T,&a);
	for(LL i=1;i<=n;i++)
	{
		scanf("%Lf",&h[i]);
		if(abs(T-0.006*h[i]-a)<minn)
		{
			minn=abs(T-0.006*h[i]-a);
			jl=i;
		}
	}
	out(jl),putchar('\n');
return 0;
}


Measured memory_bytes: 256
#!/usr/bin/ruby
require 'rational'
while(n=gets.to_i)>0
	a=n.times.map{b=gets.split.map(&:to_i)}
	l=1;n.times{|i|l=l/l.gcd(a[i][0])*a[i][0]}
	b=n.times.map{|i|a[i][1]*l/a[i][0]}
	g=b[0];n.times{|i|g=g.gcd b[i]}
	n.times{|i|p b[i]/g}
end

Measured memory_bytes: 5588
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define pint pair<int,int>
#define pll pair<ll,ll>
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

ll dp[1000][1000];

int main(){
  int n,K;
  cin >> n >> K;
  ll h[n+1]={};
  rep(i,n)cin >> h[i+1];
  rep(i,500)rep(j,500)dp[i][j]=longinf;
  dp[0][K]=0;
  ll ans=longinf;
  for(int i=0;i<=n;i++){
    for(int j=0;j<=K;j++){
      if(dp[i][j]<longinf){
        if(j>=n-i) ans=min(ans,dp[i][j]);
        for(int k=i+1;k<=min(n,i+j+1);k++){
          dp[k][j-(k-i-1)]=min(dp[k][j-(k-i-1)],dp[i][j]+max(0LL,h[k]-h[i]));
        }
      }
    }
  }
//  for(int i=K+1;i<=n;i++)cout << dp[i][0] << endl;//ans=min(ans,dp[i+1][0]);
  cout << ans << endl;
return 0;}

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

int main() {
	ios_base::sync_with_stdio( false );

	int N;
	cin >> N;

	vector<int> A( N );
	for( auto& v: A ) { cin >> v; }

	int result = 1;
	int a = 0;
	int b = 0;

	for( int i = 1; i < N; ++i ) {
		if( A[i] > A[i-1] ) {
			if( b > 0 ) {
				b = 0;
				result += 1;
			}
			else {
				a += 1;
			}
		}
		else if( A[i] < A[i-1] ) {
			if( a > 0 ) {
				a = 0;
				result += 1;
			}
			else {
				b += 1;
			}
		}
	}

	cout << result << endl;

	return 0;
}


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


struct Dice {
    int s[6];
    void roll(char di) {
        int b;
        if (di == 'S') {
            b = s[1];
            s[1] = s[0];
            s[0] = s[4];
            s[4] = s[5];
            s[5] = b;
        }
        else if (di == 'N') {
            b = s[4];
            s[4] = s[0];
            s[0] = s[1];
            s[1] = s[5];
            s[5] = b;
        }
        else if (di == 'E') {
            b = s[2];
            s[2] = s[0];
            s[0] = s[3];
            s[3] = s[5];
            s[5] = b;
        }
        else if (di == 'W') {
            b = s[3];
            s[3] = s[0];
            s[0] = s[2];
            s[2] = s[5];
            s[5] = b;
        }
        
    }
    int top() {
        return s[0];
    }

};

int main() {
    Dice D;
    for (int i = 0; i < 6; i++)
    {
        cin >> D.s[i];  
    }
    string DI;
    cin >> DI;
    for (int i = 0; i < DI.size(); i++)
    {
        D.roll(DI[i]);
    }
    cout << D.top() << endl;


    return 0;
}


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

#ifdef DEBUG
#define debug(...) __VA_ARGS__
#else
#define endl '\n'
#define debug(...)
#endif
#define debugf(...) debug(printf(__VA_ARGS__))

const int N = 1e5 + 5;



int (((((main)))))() <%
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int x, y;
    cin >> x >> y;

    if ((y - 2*x) % 2 == 0 && y - 2*x >= 0 && x - (y - 2*x)/2 >= 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
%>

Measured memory_bytes: 3648
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split();
	long MaxSum(List<long> a) => a.Where(i => i >= 0).Sum();
	bool Good(List<long> a) => a.Any(i => i >= 0);
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var N = F;
		var a = G;
		var ev = new List<long>(N / 2);
		var od = new List<long>(N / 2);
		for (var i = 0; i < N; i++) if (i % 2 == 0) ev.Add(a[i]); else od.Add(a[i]);
		bool gev = Good(ev), god = Good(od);
		if (!gev && !god)
		{
			var m = a.Max();
			int i = 0, j = N;
			while (a[i] != m) i++;
			WriteLine(a[i]);
			WriteLine(N - 1);
			for (var k = 0; k < i; k++) { WriteLine(1); j--; }
			while (j > 1) WriteLine(j--);
			return;
		}
		long mev = MaxSum(ev), mod = MaxSum(od);
		WriteLine(Max(mev, mod));
		var del = new List<int>();
		var l = new LinkedList<bool>();
		if (mev >= mod && gev) for (var i = 0; i < N; i++) l.AddLast(i % 2 == 0 && ev[i / 2] >= 0);
		else for (var i = 0; i < N; i++) l.AddLast(i % 2 == 1 && od[i / 2] >= 0);
		while (l.Count > 2)
		{
			var n = l.First;
			if (!n.Value) { del.Add(0); l.RemoveFirst(); }
			else if (!l.Last.Value) { del.Add(l.Count - 1); l.RemoveLast(); }
			else if (n.Next.Next.Value)
			{
				del.Add(1);
				l.RemoveFirst();
				l.RemoveFirst();
			}
			else
			{
				del.Add(2);
				l.Remove(n.Next);
				l.Remove(n.Next);
			}
		}
		if (l.Count > 1) del.Add(l.First.Value ? 1 : 0);
		WriteLine(del.Count);
		foreach (var i in del) WriteLine(i + 1);
	}
}


Measured memory_bytes: 13668
#include <stdio.h>

int A[1000000];
int n;

int binarySearch(int key){
    int left = 0;
    int right = n;
    int mid;
    
    while(left < right) {
        mid = (left + right) /2 ;
        if (key == A[mid]) return 1;
        if (key > A[mid]) left = mid + 1;
        if (key < A[mid]) right = mid;
    }
    return 0;
}

int main(){
    int i, q, k, sum =0;
    
    scanf("%d", &n);
    for(i = 0; i < n; i++){
        scanf("%d",&A[i]);
    }

    scanf("%d",&q);
    for (i =0; i <q; i++) {
        scanf("%d",&k);
        if (binarySearch(k)) sum++;
    }
    printf("%d\n",sum);
    return 0;
}



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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

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

    if (K % 2 == 0) {
        cout << -1 << endl;
        return 0;
    }

    ll t = 7;
    REP(i, K + 10) {
        t = t % K;

        if (t == 0) {
            cout << i + 1 << endl;
            return 0;
        }
        //cout << t << endl;

        t = t * 10LL + 7;
    }

    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

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

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  ret *= kaijo(n); ret %= MOD;
  ret *= gyaku_kaijo(r); ret %= MOD;
  ret *= gyaku_kaijo(n-r); ret %= MOD;
  return ret;
}

int main(void){
  fast_io
  ll n,d,a;cin>>n>>d>>a;
  vector<Pll> XH;
  rep(i,n){
    ll x,h;cin>>x>>h;
    XH.push_back({x,h});
  }
  sort(all(XH));
  queue<Pll> q;
  int xi = 0;
  ll ans = 0;
  ll x = 0;
  ll ruiseki = 0;
  while(xi < n){
    if(XH[xi].second <= 0){
      xi++;
      continue;
    }
    if(q.size() > 0 && q.front().first < XH[xi].first){
      ruiseki -= q.front().second;
      q.pop();
      continue;
    }
    if(XH[xi].first + d == x){
      if(XH[xi].second <= 0){
        xi++;
        continue;
      }else{
        XH[xi].second -= ruiseki;
        ll time;
        if(XH[xi].second > 0)
          time = XH[xi].second / a + (XH[xi].second % a == 0 ? 0 : 1);
        else
          time = 0;
        XH[xi].second = 0;
        q.push({x + d, time * a});
        ruiseki += time * a;
        //cout<<xi<<" "<<x<<" "<<time<<endl;
        xi++;
        ans += time;

        continue;
      }
    }
    x = XH[xi].first + d;
  }
  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 7660
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_1_A&lang=jp 

#include <stdio.h>
#include <iostream>
#include <vector>
using namespace std;

#define NIL -1
#define N_MAX 10000

int Node[N_MAX];

void init(){
    for(int i = 0; i < N_MAX; i++){
        Node[i] = NIL;
    }
}

int findSet(int x){
    vector<int> V;
    int index = x;
    while(Node[index] != NIL){
        V.push_back(index);
        index = Node[index];
    }
    for(int i = 0; i < V.size(); i++){
        Node[V[i]] = index;
    }
    return index;
}

void unite(int x, int y){
    int root_x = findSet(x);
    int root_y = findSet(y);
    if(root_x != root_y){
        Node[root_x] = root_y;
    }
}

bool same(int x, int y){
    if(findSet(x) == findSet(y)){
        return true;
    }else{
        return false;
    }
}

int main(void){
    init();

    int n, q;
    scanf("%d %d", &n, &q);

    for(int i = 0; i < q; i++){
        int com, x, y;
        scanf("%d %d %d", &com, &x, &y);
        if(com == 0){
            unite(x, y);
        }else{
            if(same(x, y)){
                printf("1\n");
            }else{
                printf("0\n");
            }
        }
    }
}



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

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> a(H+2);

  for (int i=0; i<H+2; i++) {
    if (i == 0 || i == H+1) {
      for (int j=0; j<W+2; j++) a[i] += "#";
    } else {
      cin >> a[i];
    }
  }

  for (int i=1; i<H+1; i++) {
    a[i] = "#" + a[i] + "#";
  }

  for (int i=0; i<H+2; i++)
    cout << a[i] << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstring>
#include<utility>
#include<cmath>
#include<assert.h>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<complex>
#include<bitset>

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

int N, X;
int A[2020];
int B[2020];

signed main() {
    cin >> N >> X;
    rep(i, N) {
        cin >> A[i];
        B[i] = INF;
    }
    int ans = INF;
    rep(k, N) {
        int bs = 0;
        rep(i, N) {
            B[i] = min(B[i], A[(i - k + N) % N]);
            bs += B[i];
        }
        ans = min(ans, k * X + bs);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define pb push_back
#define pii pair<long long,long long>
#define endl '\n'
#define N 300001
int mod=1000000007;
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
vector<int> parent(N),sz(N),indegree(N),vis(N); char st[N];
vector<int> adj[N];
int modexp(int x,int n,int M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        
        return modexp((x*x)%M,n/2,M);
    else                             
        return (x*modexp((x*x)%M,(n-1)/2,M))%M;
}
void make_set(int s)
{
    parent[s]=s;
    sz[s]=1;
}
int find_parent(int p)
{
    if(p==parent[p])
    return p;
    return parent[p]=find_parent(parent[p]);
}
void union_set(int a,int b)
{
    a=find_parent(a);b=find_parent(b);
    if(a!=b)
    {
        if(a<b)
        swap(a,b);
        parent[b]=parent[a];
        sz[a]+=sz[b];
    }
}
bool comp(const pii a, const pii b)
{
    if(a.se==b.se)
    return a.fi<b.fi;
    return a.se<b.se;
}
int power(int x , int n)
{
    if(n==0)
    return 1;
    if(n%2==0)
    return power(x*x,n/2);
    else
    return x*power(x*x,n/2);
}
int root(int n) 
{ 
    // Base cases 
    if (n == 0 || n == 1) 
        return n; 
  
    // Initialize result 
    int res = 0; 
  
    // Keep incrementing res while res^5 is 
    // smaller than or equal to n 
    while (res*res*res*res*res <= n) 
        res++; 
  
    // Return floor of 5'th root 
    return res-1; 
} 
vector<vector<int>> dp,v;
void solve()
{
    int k; cin>>k;
    int y=0,x; int flag=0;
    int yy=0,xx;
    int v,vv;
    while(true && y<=1000)
    {
        x=k+power(y,5);
        xx=k+power(yy,5);
        v= root(x);
        if(xx>=0)
        vv=root(xx);
        if(power(v,5)==x)
        {
            cout<<v<<" "<<y;
            return;
        }
        if(xx>=0 && power(vv,5)==xx)
        {
            cout<<vv<<" "<<yy;
            return;
        }
        y++;
        yy--;
    }
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int test; test=1;
    while(test--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 19408
#include <iostream>
#include <string>

using namespace std;

int a[100] = {};
int T,K;

int maxIndex(int skipIndex) {
	int maxIndex = -1;
	int maxValue = 0;

	for (int i = 0; i < T; i++) {
		if (i == skipIndex) continue;
		if (a[i] <= maxValue) continue;
		maxValue = a[i];
		maxIndex = i;
	}
	return maxIndex;
}

int main() {
	cin >> K >> T;
	for (int i = 0; i < T; i++) {
		cin >> a[i];
	}
	int prevIndex = -1;
	int ans = 0;
	for (int i = 0; i < K;i++) {
		int mi = maxIndex(prevIndex);
		if (mi <= -1 && a[prevIndex] > 0) {
			ans++;
			a[prevIndex]--;
			continue;
		}
		if (a[mi] > 0) {
			a[mi]--;
			prevIndex = mi;
		}
	}
	cout << ans << endl;


	return 0;
};


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m,ans;
int main()
{
    scanf("%d %d",&n,&m);
    if(n%2==0)
	{
		        int m2 = m / 2;
        int m1 = m - m2;
        for (int i = 1; i <= m1; ++i) {
            std::cout << i << " " << m1 * 2 + 1 - i << std::endl;
        }
 
        int d = m1 * 2;
        for (int i = 1; i <= m2; ++i) {
            std::cout << d + i << " " << d + m2 * 2 + 2 - i << std::endl;
        }
	}
	else
	{
		for(int i=1;i<=m;i++)printf("%d %d\n",i,n-i+1);
	}
    return 0;
}

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

int main(void){
  int n, k;
  string s;
  cin >> n >> s >> k;
  char c = s[k-1];
  for(int i=0;i<n;i++){
    if(s[i]!=c)s[i]='*';
  }
  cout << s << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;

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

struct Node {
  int key;
  Node *prev, *next;
  
  Node() {}
  Node(int key): key(key) {}
};

class DoublyLinkedList {
  Node *nil;

public:
  DoublyLinkedList() {
    nil = new Node();
    nil->prev = nil;
    nil->next = nil;
  }

  void insert(int key) {
    auto n = new Node(key);
    n->next = nil->next;
    nil->next->prev = n;
    nil->next = n;
    n->prev = nil;
  }

  Node *search(int key) {
    auto cur = nil->next;
    while (cur != nil && cur->key != key) {
      cur = cur->next;
    }
    return cur;
  }

  void deleteNode(Node *t) {
    if (t == nil) return;

    t->prev->next = t->next;
    t->next->prev = t->prev;

    delete t;
  }

  void deleteFirst() {
    deleteNode(nil->next);
  }

  void deleteLast() {
    deleteNode(nil->prev);
  }

  void deleteKey(int key) {
    deleteNode(search(key));
  }

  string to_string() {
    string s;
    auto cur = nil->next;
    while (cur != nil) {
      s += std::to_string(cur->key);
      
      cur = cur->next;
      s += cur != nil ? " " : "";
    }

    return s;
  }
};

int main() {
  int n, key;
  char cmd[20];
  cin >> n;
  
  auto l = DoublyLinkedList();
  rep(i, n) {
    scanf("%s %d", cmd, &key);

    if (cmd[0] == 'i') l.insert(key);
    else if (cmd[0] == 'd') {
      if (strlen(cmd) > 6) {
        if (cmd[6] == 'F') l.deleteFirst();
        else if (cmd[6] == 'L') l.deleteLast();
      } else {
        l.deleteKey(key);
      }
    }
  }

  cout << l.to_string() << endl;
}



Measured memory_bytes: 33988
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n = int(input())
edges = [[]for _ in range(n)]
for _ in range(n-1):
    a, b = map(lambda x: int(x)-1, input().split())
    edges[a].append(b)
    edges[b].append(a)
INF = 10**18
dist = [INF]*n
dist[0] = 0
prev = [None]*n


def dfs(v, parent, d):
    prev[v] = parent
    dist[v] = d
    for v2 in edges[v]:
        if v2 == parent:
            continue
        dfs(v2, v, d+1)


dfs(0, -1, 0)

x = n-1
for _ in range((dist[-1]-1)//2):
    x = prev[x]
cant_go = prev[x]


def dfs2(v, parent):
    global snuke_v_cnt
    snuke_v_cnt += 1
    for v2 in edges[v]:
        if v2 == parent:
            continue
        if v2 == cant_go:
            continue
        dfs2(v2, v)


snuke_v_cnt = 0
dfs2(x, -1)

fennec_v_cnt = n-snuke_v_cnt
print('Fennec' if snuke_v_cnt < fennec_v_cnt else 'Snuke')

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


int main()
{
int A,B;
cin >> A >> B;

if(A >= 13){
    cout << B << endl;
}else if(6 <= A && A <= 12){
    cout << B/2 << endl;
}else if(A <= 5){
    cout << 0 << endl;
}


}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define sio(); ios_base::sync_with_stdio(false); cin.tie(NULL);
#define fio(); freopen("input","r",stdin); freopen("output","w",stdout);
using namespace std;
int main()
{
    double n,x,t;
    int k;
    cin>>n>>x>>t;
    k = n/x;
    if((n/x)>k)k = (n/x)+1;
    printf("%d\n",int(k*t));
    return 0;
}


Measured memory_bytes: 3748
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
const int MOD = 1e9 + 7;

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

	int n, v, u, m; cin >> n >> u >> v >> m;
	if (n == 1) {
		int usa, neko; cin >> usa >> neko;
		int usasum = 0, nekosum = 0;
		for (int i = 0; i < m; i++) {
			int a; cin >> a;
			if (a == usa) usasum=1;
			if (a == neko) nekosum=1;
			if (usasum >= u&&nekosum >= v) {
				cout << "DRAW" << endl;
				return 0;
			}
			else if (usasum >= u) {
				cout << "USAGI" << endl;
				return 0;
			}
			else if (nekosum >= v) {
				cout << "NEKO" << endl;
				return 0;
			}
		}
		cout << "DRAW" << endl;
        return 0;
	}
	vector<P> usa(1000001, P(-1, -1)),neko(1000001,P(-1,-1));//usa[i]:=usa?????§i?????????????????§?¨?
	vector<int> usatate(100000, 0), usayoko(100000, 0);
	int usasla = 0, usaback = 0;
	vector<int> nekotate(100000, 0), nekoyoko(100000, 0);
	int nekosla = 0, nekoback = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			int a; cin >> a;
			usa[a] = P(i, j);
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			int a; cin >> a;
			neko[a] = P(i, j);
		}
	}
	int usasum = 0, nekosum = 0;
	for (int i = 0; i < m; i++) {
		int a; cin >> a;
		if (usa[a] != P(-1, -1)) {
			int x = usa[a].first, y = usa[a].second;
			//cout<<x<<" "<<y<<endl;
            usayoko[x]++; usatate[y]++;
			if (x == y) usasla++;
			if (x + y == n - 1) usaback++;
			
            //cout<<usayoko[x]<<" "<<usatate[y]<<" "<<usasla<<" "<<usaback<<endl;
			if (usayoko[x] == n) usasum++;
			if (usatate[y] == n) usasum++;
			if (x==y&&usasla == n) usasum++;
			if (x+y==n-1&&usaback == n) usasum++;
		}
		if (neko[a] != P(-1, -1)) {
			int x = neko[a].first, y = neko[a].second;
			nekoyoko[x]++; nekotate[y]++;
			if (x == y) nekosla++;
			if (x + y == n - 1) nekoback++;

			if (nekoyoko[x] == n) nekosum++;
			if (nekotate[y] == n) nekosum++;
			if (x==y&&nekosla == n) nekosum++;
			if (x+y==n-1&&nekoback == n) nekosum++;
		}
        //cout<<usasum<<" "<<nekosum<<endl;
		if (usasum >= u&&nekosum >= v) {
			cout << "DRAW" << endl;
			return 0;
		}
		else if (usasum >= u) {
			cout << "USAGI" << endl;
			return 0;
		}
		else if (nekosum >= v) {
			cout << "NEKO" << endl;
			return 0;
		}
		else continue;
	}
	cout << "DRAW" << endl;
}

Measured memory_bytes: 19980
#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define endl '\n'
#define MOD 1000000007
#define MOD2 998244353

using namespace std;
typedef long long int ll;

int dp[100010];
vector<vector<int>> g(100010);

int path(int u)
{
	int &ret = dp[u];
	if (ret) return ret;
	ret = 0;
	for (auto v : g[u])
		ret = max(ret, 1 + path(v));
	return ret;
}

int main(void)
{
	fast;
	#ifndef ONLINE_JUDGE
	// freopen("in", "r", stdin);
	// freopen("out", "w", stdout);
	#endif

	int n, m; cin >> n >> m;
	for (int i = 0; i < m; ++i)
	{
		int u, v; cin >> u >> v;
		g[--v].pb(--u);
	}
	int ans = 0;
	for (int i = 0; i < n; ++i)
	{
		ans = max(ans, path(i));
	}
	cout << ans << endl;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい

#define ALL(x) x.begin(),x.end()
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<int, vector<int>, greater<int> > gpq; //逆順priority_queue
typedef priority_queue<int> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const double PI=3.1415926535;

int main(){
    string S;
    cin>>S;
    int L=S.size();
    int ans=9999999;
    for(int i=0;i<L-2;i++){
        int v=(S[i]-'0')*100+(S[i+1]-'0')*10+(S[i+2]-'0');
        ans=min(ans,abs(v-753));
    }
    cout<<ans<<endl;
}


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

using namespace std;
using ll = long long;

#define endl '\n'
#define FIO() ios_base::sync_with_stdio(0);cin.tie(NULL);
#define lson (idx<<1)
#define rson ((idx<<1) | 1)

const int mx = 2e5 + 9;

int n, q;

struct node {
    int l, r;
    int val;
    int lazy = mx;
};

struct SegTree {
    node tree[4 * mx];

    void build(int idx, int l, int r) {
        int mid = (l + r) / 2;

        tree[idx].l = l, tree[idx].r = r;
        if (l == r) {
            if (l == n) tree[idx].val = 1;
            else tree[idx].val = n;
            return;
        } 

        build(lson, l, mid);
        build(rson, mid + 1, r);

        tree[idx].val = min(tree[lson].val, tree[rson].val);
    }

    void propagate(int idx) {
        tree[idx].val = min(tree[idx].val, tree[idx].lazy);

        if (rson < 4 * mx) {
            tree[lson].lazy = min(tree[lson].lazy, tree[idx].lazy);
            tree[rson].lazy = min(tree[rson].lazy, tree[idx].lazy);
        }

        tree[idx].lazy = mx;
    }

    void update(int idx, int L, int R, int x) {
        int l = tree[idx].l, r = tree[idx].r;
        propagate(idx);

        if (r < L or R < l) return;
        if (L <= l and r <= R) {
            tree[idx].val = min(tree[idx].val, x);
            tree[idx].lazy = min(tree[idx].lazy, x);
            return;
        }

        update(lson, L, R, x);
        update(rson, L, R, x);

        tree[idx].val = min(tree[lson].val, tree[rson].val);
    }

    int query(int idx, int L, int R) {
        int l = tree[idx].l, r = tree[idx].r;
        propagate(idx);

        if (r < L or R < l) return mx;
        if (L <= l and r <= R) {
            return tree[idx].val;
        }

        int q1 = query(lson, L, R);
        int q2 = query(rson, L, R);

        return min(q1, q2);
    }
};

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

    SegTree R, C;
    R.build(1, 1, n);
    C.build(1, 1, n);

    ll ans = ll(n - 2) * (n - 2);
    while (q--) {
        int t, x; cin >> t >> x;
        if (t == 1) {
            int hi = R.query(1, x, x);
            ll stones = max(0, hi - 2);

            ans -= stones;
            R.update(1, x, x, 1);
            C.update(1, 1, hi, x);

        } else {
            int hi = C.query(1, x, x);
            ll stones = max(0, hi - 2);

            ans -= stones;
            C.update(1, x, x, 1);
            R.update(1, 1, hi, x);
        }
    }

    cout << ans << endl;
}


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count()); 

#define mp make_pair
#define pb push_back
#define F first
#define S second
#define SZ(x) (int) (x).size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n; 
	ll d;
	cin >> n >> d;
	d *= d;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		ll a, b;
		cin >> a >> b;
		ll dist = a * a + b * b;
		if (dist <= d) ans++;
	}
	cout << ans << "\n";
}


Measured memory_bytes: 3656