akhauriyash/Code-Regression huggingface dataset:
A,B,C =map(int,input().split())

if A==5 and B==5 and C==7:
    print("YES")
    
elif A==5 and B==7 and C==5:
    print("YES")

elif A==7 and B==5 and C==5:
    print("YES")
    
else:
    print("NO")

Measured memory_bytes: 2940
#include <cstdio>

int main(){
    int a,b;
    scanf("%d%d",&a,&b);
    int Hb = 0;
    for(int i = 1; i <= b - a; i++){
        Hb += i;
    }
    printf("%d\n",Hb - b);

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	int p[8];
	int mx;
	while(cin>>p[0]>>p[1]>>p[2]>>p[3]>>p[4]>>p[5]>>p[6]>>p[7]){
		mx=0;
		int buf,res=0;
		buf=min(p[0],1)+min(p[1],2)+min(p[2],1)+min(p[3],2)+min(p[4],1)+min(p[5],4)+min(p[6],1)+min(p[7],4);
		if(buf>mx){mx=buf;res=0;}
		buf=min(p[0],1)+min(p[1],2)+min(p[2],1)+min(p[3],4)+min(p[4],1)+min(p[5],4)+min(p[6],1)+min(p[7],2);
		if(buf>mx){mx=buf;res=2;}
		buf=min(p[0],1)+min(p[1],4)+min(p[2],1)+min(p[3],2)+min(p[4],1)+min(p[5],2)+min(p[6],1)+min(p[7],4);
		if(buf>mx){mx=buf;res=6;}
		buf=min(p[0],1)+min(p[1],4)+min(p[2],1)+min(p[3],4)+min(p[4],1)+min(p[5],2)+min(p[6],1)+min(p[7],2);
		if(buf>mx){mx=buf;res=4;}
		buf=min(p[0],2)+min(p[1],1)+min(p[2],2)+min(p[3],1)+min(p[4],4)+min(p[5],1)+min(p[6],4)+min(p[7],1);
		if(buf>mx){mx=buf;res=1;}
		buf=min(p[0],2)+min(p[1],1)+min(p[2],4)+min(p[3],1)+min(p[4],4)+min(p[5],1)+min(p[6],2)+min(p[7],1);
		if(buf>mx){mx=buf;res=3;}
		buf=min(p[0],4)+min(p[1],1)+min(p[2],2)+min(p[3],1)+min(p[4],2)+min(p[5],1)+min(p[6],4)+min(p[7],1);
		if(buf>mx){mx=buf;res=7;}
		buf=min(p[0],4)+min(p[1],1)+min(p[2],4)+min(p[3],1)+min(p[4],2)+min(p[5],1)+min(p[6],2)+min(p[7],1);
		if(buf>mx){mx=buf;res=5;}
		int i;
		int seat[]={1,2,1,2,1,4,1,4};
		for(i=0;i<7;i++){
			cout<<seat[(res+i)%8]<<" ";
		}
		cout<<seat[(res+7)%8]<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B;
  string As, Bs, U;
  cin >> As >> Bs >> A >> B >> U;
  
  if(U == As){
  A = A - 1;
  }
  else{
  B = B - 1;
  }
  
  cout << A << " " << B << endl;
}

Measured memory_bytes: 256
N=int(input())
d={}
for i in range(N):
	x,y,h=map(int,input().split())
	d[tuple([x,y])]=h

for i in range(101):
	for j in range(101):
		h=-1
		for p in d:
			if d[p]!=0:
				h=max(h,abs(p[0]-i)+abs(p[1]-j)+d[p])
		f=True
		for p in d:
			if d[p]!=max(0,h-abs(p[0]-i)-abs(p[1]-j)):
				f=False
				break
		if f==True:
			print(i,j,h)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define mod 998244353
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>
using namespace std;
const ll N=100010;

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

    ll n,x,y;
    cin>>n>>x>>y;

    vector<ll> adj[n+1];
    for(ll i=1;i<=n-1;++i){
        ll a=i;
        ll b=i+1;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    adj[x].pb(y);
    adj[y].pb(x);

    ll ans[n]={0};
    for(ll i=1;i<=n;++i){
        queue<ll> q;
        int vis[n+1]={0};
        vis[i]=1;
        q.push(i);
        ll dis=0;
        ll size=1;
        while(!q.empty()){
            ll v=q.front();
            q.pop();
            --size;
            ans[dis]+=1;

            for(auto u:adj[v]){
                if(vis[u]==0){
                    vis[u]=1;
                    q.push(u);
                }
            }

            if(size==0){
                ++dis;
                size=q.size();
            }
        }
    }
    for(ll i=1;i<n;++i){
        cout<<ans[i]/2<<endl;
    }

    return (0);
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

void b()
{
    int A,B,M;
    cin >>A>>B>>M;
    vector<int>a;
    vector<int>b;
    vector<int>mx;
    vector<int>my;
    vector<int>mc;
    int amin = INT32_MAX;
    int bmin = INT32_MAX;
    for (int i= 0;i<A;i++)
    {
        int te;
        cin >> te;
        if(te<amin)
        amin = te;
        a.push_back(te);
        
    }
    for (int i= 0;i<B;i++)
    {
        int te;
        cin >> te;
        if(te<bmin)
        bmin =te;
        b.push_back(te);
    }
    for (int i= 0;i<M;i++)
    {
        int te,tee,teee;
        cin >> te>>tee>>teee;
        mx.push_back(te-1);
        my.push_back(tee-1);
        mc.push_back(teee);
    }
    int min = INT32_MAX;
    for (int i= 0;i<M;i++)
    {
        int te = a[mx[i]]+b[my[i]]-mc[i];
        if(min>te){
            min = te;
        }
    }
    if(amin+bmin<min)
    min = amin+bmin;
    cout<<min;
    
    

}
int main(void){
    b();
}

Measured memory_bytes: 2552
program main
      implicit none
      integer :: a, b, h, m
      !double precision :: a2, b2, h2, m2, rad, c, tmp
      real(8) :: a2, b2, h2, m2, rad, c, tmp

      read *, a, b, h, m

      a2 = a
      b2 = b
      h2 = h
      m2 = m
      rad = abs( 0.5d0*(h2*60.0d0+m2) - 6.0d0*m2 )/180d0
      rad = 3.141592653589793238462643383279d0*rad

      c = a2**2 + b2**2 - 2.0d0*a2*b2*dcos(rad)
      c = sqrt(c)

      print *, c

end program main


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	int n; cin >> n;
	vector<ll> v(n);
	rep(i, 0, n) cin >> v[i], v[i] -= i + 1;
	sort(all(v));
	ll med = v[n / 2];
	ll ans = 0;
	for (ll x : v) ans += abs(x - med);
	cout << ans << endl;
}


Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_148
{
    class F
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int[] nuv = ReadInts();
            int n = nuv[0];
            int u = nuv[1]-1;
            int v = nuv[2]-1;
            List<int>[] graph = new List<int>[n];
            for(int i = 0; i < n; i++)
            {
                graph[i] = new List<int>();
            }
            for(int i = 0; i < n - 1; i++)
            {
                int[] ab = ReadInts();
                int a = ab[0] - 1;
                int b = ab[1] - 1;
                graph[a].Add(b);
                graph[b].Add(a);
            }
            if (graph[u].Count==1&&graph[u][0]==v)
            {
                WriteLine(0);
                return;
            }

            int[] tCosts = new int[n];
            int[] aCosts = new int[n];
            BFS(tCosts, u, graph);
            BFS(aCosts, v, graph);
            int res = 0;
            for(int i = 0; i < n; i++)
            {
                if (graph[i].Count == 1) continue;
                if (aCosts[i] >= tCosts[i]) res = Max(res, aCosts[i]);
            }
            WriteLine(res);
        }

        static void BFS(int[] costs,int start,List<int>[] graph)
        {
            Queue<int[]> queue = new Queue<int[]>();
            for(int i = 0; i < costs.Length; i++)
            {
                costs[i] = int.MaxValue / 4;
            }
            queue.Enqueue(new int[2] { start, 0 });
            while (queue.Count > 0)
            {
                int[] val = queue.Dequeue();
                int i = val[0];
                int cost = val[1];
                if (costs[i] <= cost) continue;

                costs[i] = cost;
                for(int j = 0; j < graph[i].Count; j++)
                {
                    int to = graph[i][j];
                    int next = cost + 1;
                    if (costs[to] <= next) continue;
                    queue.Enqueue(new int[2] { to, next });
                }
            }
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 33500
#include <iostream>
 
using namespace std;
 
int main(){
  int W, H, x, y, r;
 
  cin >> W >> H >> x >> y >> r;
  if(x-r < 0 || x+r > W || y-r < 0 || y+r > H){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
 
  return 0;
}

  

Measured memory_bytes: 3084
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map> 
#include<iostream>
#include<time.h>
using namespace std;
typedef long long ll;
const double pi=acos(-1.0);
const ll mod=1e9+7;
const int inf=0x3f3f3f3f;
//ll begin_time=clock();
//ll end_time=clock();printf("time=%lldms\n",end_time-begin_time);
/****************************************************************************/ 
int main()
{
	int a,b,c,d;
	scanf("%d%d",&a,&b);
	int z[105];
	memset(z,0,sizeof(z));
	while(b--)
	{
		scanf("%d",&c);
		while(c--)
		{
			scanf("%d",&d);
			z[d]++;
		}
	}
	d=0;
	for(int i=1;i<=a;i++)
	{
		if(!z[i])d++;
	}
	printf("%d\n",d);
}




Measured memory_bytes: 3812
target = gets.chomp
gets.to_i.times do
    manipulation = gets.split
    if manipulation[0] == "print"
        puts target[manipulation[1].to_i...manipulation[2].to_i+1]
    elsif manipulation[0] == "reverse"
        target = target[0...manipulation[1].to_i] + target[manipulation[1].to_i...manipulation[2].to_i+1].reverse + target[manipulation[2].to_i+1...target.size]
    else manipulation[0] == "replace"
        target = target[0...manipulation[1].to_i] + manipulation[3] + target[manipulation[2].to_i+1...target.size]
    end
end


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

typedef struct{int r; int g; int b;}RGB_CNT;

int rgb_total[3]={0};
RGB_CNT rgb_cnt[4000];

int main(void)
{
    int n;
    string s;
    cin >> n;
    cin >> s;

    /* 初期化 */
    rgb_cnt[0].r = 0, rgb_cnt[0].g = 0, rgb_cnt[0].b = 0;

    /* 集計 */
    for(int i=0; i<n; i++){
        if (s[i] == 'R'){
            rgb_total[0]++;
            rgb_cnt[i].r++;       
        }
        else if (s[i] == 'G'){
            rgb_total[1]++;
            rgb_cnt[i].g++;
        }
        else{
            rgb_total[2]++;
            rgb_cnt[i].b++;
        }
        rgb_cnt[i+1].r = rgb_cnt[i].r;
        rgb_cnt[i+1].g = rgb_cnt[i].g;
        rgb_cnt[i+1].b = rgb_cnt[i].b;
    }

    /* 計算 */
    ll ans = 0;
    for(int i=0; i<n-2; i++){
        bool flag[3] = {true, true, true};
        if (s[i] == 'R') flag[0] = false;
        else if (s[i] == 'G') flag[1] = false;
        else flag[2] = false;

        for (int j=i+1; j<n-1; j++){
            if (s[j] == s[i]) continue;
            int k = j + (j-i);
            bool temp_flag[3];
            for(int rgb=0; rgb<3; rgb++) temp_flag[rgb] = flag[rgb];

            if (s[j] == 'R') temp_flag[0] = false;
            else if (s[j] == 'G') temp_flag[1] = false;
            else flag[2] = false;

            if (temp_flag[0] == true){
                ans += rgb_total[0] - rgb_cnt[j].r;
                if (s[k] == 'R') ans--;
            }
            else if (temp_flag[1] == true){
                ans += rgb_total[1] - rgb_cnt[j].g;
                if (s[k] == 'G') ans--;
            }
            else{
                ans += rgb_total[2] - rgb_cnt[j].b;
                if (s[k] == 'B') ans--;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3676
n,y=map(int,input().split())
flag=0
for i in range(n+1):
    for j in range(n+1):
        z=n-i-j
        if z<0:
            continue
        if int(i*10000+j*5000+z*1000)==y:
            flag=1
            break
    if flag==1:
        break
if flag==1:
    print(str(i)+' '+str(j)+' '+str(z))
else:
    print('-1 -1 -1')

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

#define debug(x) cout << '>' << #x << ':' << x << endl;
#define loop0(i,n) for(int i=0; i<(n); i++)
#define loop1(i,n) for(int i=1; i<=(n); i++)
#define fori(a,b,i) for(int i=(a); i<=(b); i++)
#define ford(a,b,i) for(int i=(a); i>=(b); i--)
#define fast_io ios_base::sync_with_stdio(false), cin.tie(NULL)
#define ign cin.ignore(numeric_limits<streamsize>::max(),'\n')

#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define endl "\n"
#define fir first
#define sec second
#define pb push_back
#define mp make_pair

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MII;
typedef map<int,int> MCI;
typedef unordered_map<int,int> UMII;
typedef unordered_map<char,int> UMCI;
typedef set<int> SI;
typedef long long int llint;

// Display Map
//~for (auto const& pair: m) {
//~std::cout << "{" << pair.first << ": " << pair.second << "}\n";
//~}

// Extract word(w) from sentence(s)
//~stringstream str(s);
//~string w;
//~while(str >> w){
//~// w is your word
//~}

//Memset Syntax
// memset(array, value,sizeof(array)) val is 0,-1 or bool only

// To get accurate precision
//~cout.precision(20);

int main() {
    fast_io;
	llint n;
	cin >> n;
	vector<llint> v(n);
	unordered_map<llint, llint> m; 
	for(auto &i : v) cin >> i;
	for (llint i = 0; i < n; i++) m[v[i]]++;  
	llint q;
	cin >> q;
	llint sum = 0;
	for(int i = 0; i < n; i++) sum += v[i];
	
	for(llint i = 0; i < q; i++){
		llint a,b;
		cin >> a >> b ;
		
		sum = sum - (1LL*a*m[a]) +(1LL*b*m[a]);
		
		m[b] += m[a];
		
		m[a] = 0;

		cout << sum << endl;		
	}
	
}


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

int main() {
  int A, N,flag;
  cin >> N >> A;
  flag = N % 500;
  
  while(true){
    if(flag == 0){
      cout << "Yes" << endl;
      break;
    }else if(A == 0){
      cout << "No" << endl;
      break;
   }
    
    flag -= 1;
    A--;
  }
}


Measured memory_bytes: 256
R,C,N=map(int,input().split())
points=[list(map(int,input().split())) for i in range(N)]
def circ(x,y):
    if y==0:
        return x
    elif x==R:
        return y+R
    elif y==C:
        return R+C+R-x
    elif x==0:
        return R+C+R+C-y
    else:
        return -1

L=[]
for i in range(N):
    x1,y1,x2,y2=points[i]
    if circ(x1,y1)==-1 or circ(x2,y2)==-1:
        continue
    L.append((circ(x1,y1),i))
    L.append((circ(x2,y2),i))
#board=[[circ(x,y) for y in range(C+1)] for x in range(R+1)]
R=[s[1] for s in sorted(L)]
X=[]
for i in R:
    if len(X)==0:
        X.append(i)
    else:
        if X[-1]==i:
            X.pop()
        else:
            X.append(i)
if len(X)==0:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 98592
#include<bits/stdc++.h>
#define ll long long 
#define hell 1000000007
#define F first
#define re 15000000
#define S second
#define pb push_back
#define all(a)  (a).begin(),(a).end()
#define rep(i,a,b) for(ll int i = a;i<b;i++)
#define pi 3.1415926536
#define Mod 998244353
#define endl '\n'
//char a[2000][2000];
using namespace std;
int main()
{   
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);            
    //std::setprecision(20);    
    int tests=1;
      //freopen("input.txt", "r", stdin);   
    //cin>>tests;
  while(tests--)
    { 
      int n,l;
      cin>>n>>l;
      vector<int> v(n+1);
      ll sum = 0;
      for(int i = 0;i<n;i++){
        v[i+1] = l+i;
        sum = sum + v[i+1];
      }
      ll ans[n+1];
      for(int i=1;i<=n;i++){
        ll x = sum-v[i];
        ans[i] = abs(sum-x);
      }
      int j = min_element(ans+1,ans+n+1)-ans;
      cout<<sum-v[j];
     
     


    }
}


Measured memory_bytes: 256
def selectionSort(A, N):
    count = 0
    for i in range(N):
        minj = i
        for j in range(i, N):
            if A[j] < A[minj]:
                minj = j
        if minj != i:
            count += 1
            A[i], A[minj] = A[minj], A[i]

    print(*A)
    print(count)

arr_length = int(input())
arr_num = [int(i) for i in input().split(" ")]

selectionSort(arr_num, arr_length)

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

using namespace std;

int N;
vector < pair < int, int > > edges;

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d", &N);
vector < pair < int, int > > edges;
for (int i=1; i<=N; i++)
    for (int j=i + 1; j<=N; j++)
        if (i + j != N + 1 - (N & 1))
            edges.push_back ({i, j});
printf ("%d\n", edges.size ());
for (auto it : edges)
    printf ("%d %d\n", it.first, it.second);
return 0;
}


Measured memory_bytes: 384
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
double dot(complex<double> a, complex<double> b) {
	return a.real() * b.real() + a.imag() * b.imag();
}
double gyaku_dot(complex<double> a, complex<double> b) {
	return a.real() * b.imag() - a.imag() * b.real();
}
double leng(complex<double> a) {
	return sqrt(a.real() * a.real() + a.imag() * a.imag());
}
double angles(complex<double> a, complex<double> b) {
	double cosine = dot(a, b) / (leng(a) * leng(b));
	double sine = gyaku_dot(a, b) / (leng(a) * leng(b));
	double kaku = acos(cosine);
	if (sine <= 0) {
		kaku = 2 * Ma_PI - kaku;
	}
	return kaku;
}
vector<int> convex_hull(vector<complex<double>> a) {
	vector<int> ans;
	double now_minnest = a[0].real();
	int now_itr = 0;
	REP(i, a.size()) {
		if (now_minnest > a[i].real()) {
			now_minnest = a[i].real();
			now_itr = i;
		}
	}
	ans.push_back(now_itr);
	complex<double> ba(0, 1);
	while (true) {
		int now_go = 0;
		double now_min = 0;
		int starter = ans[ans.size() - 1];
		for (int i = 0; i < a.size(); ++i) {
			if (i != starter) {
				double goa = angles(ba, a[i] - a[starter]);
				if (goa > now_min) {
					now_min = goa;
					now_go = i;
				}
			}
		}
		if (now_go == ans[0]) break;
		ans.push_back(now_go);
		ba = complex<double>(a[now_go] - a[starter]);
	}
	return ans;
}
long long gcd(long long a, long long b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int visited[200000] = {};
int going[200000];
int main() {
	int n;
	cin >> n;
	REP(i, n) {
		cin >> going[i + 1];
	}
	int now = 1;
	int ans = 0;
	while (visited[now] == 0) {
		visited[now] = 1;
		now = going[now];
		ans++;
		if (now == 2) {
			cout << ans << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#define MAX 100000000
#define NOT -1

struct Node {
  int parent,left,right;
};

struct Node T[MAX];

int n;
//???????????????
void preParse(int u){
  //  printf("a\n");
  if(u == NOT) return;
  printf(" %d",u);
  // printf("sex\n");
  preParse(T[u].left);
  preParse(T[u].right);
}

//??????
void inParse(int u){
  // printf("b\n");
  if(u==NOT)return;
 
  inParse(T[u].left);
  printf(" %d",u);
  inParse(T[u].right);
}

//??????
void postParse(int u){
  // printf("c\n");
  if(u==NOT)return;
  postParse(T[u].left);
  postParse(T[u].right);
  printf(" %d", u);
}



int main(){
  int i,id,lef,righ;
  int root;

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

 

  for(i=0;i<n;i++){
    scanf("%d %d %d", &id, &lef, &righ);
    T[id].left=lef;
    T[id].right=righ;
    
    if(lef!=NOT)T[lef].parent=id;
    if(righ!=NOT)T[righ].parent=id;
    
  }

  for(i=0;i<n;i++){
    if(T[i].parent == NOT)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: 620
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
int F[100010];

int Mul(int a, int b) {
	return ((a % mod) * (b % mod)) % mod;
}

void fact(void) {
	F[0] = 1;
	F[1] = 1;
	for (int i = 2; i <= 100000; i++) {
		F[i] = Mul(i, F[i - 1]);
	}
}
int square(int x) {
	return (x * x) % mod;
}

int power(int x, int y) {
	if (y == 0) return 1;
	else if (y == 1) return x % mod;
	else if (y % 2 == 0) return square(power(x, y / 2)) % mod;
	else return square(power(x, y / 2)) * x % mod;
}

int Div(int a, int b) {
	return Mul(a, power(b, mod - 2));
}

int sum[100010];
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    fact();
    int N; cin >> N;
    int x[100010];
    rep(i, N) cin >> x[i];
    rep(i, N) sum[i + 1] = (sum[i] + Div(F[N - 1], i + 1)) % mod;
    int ans = 0;
    rep(i, N - 1) {
        int d = x[i + 1] - x[i];
        ans = (ans + Mul(d, sum[i + 1])) % mod;
        //cout << d << " " << sum[i + 1] << endl;
    }
    cout << ans << endl;

    return 0;
}
// x1 x2 x3
//   2  1
//      2

// x1 x2 x3 x4
//   6  3  2
//      6  3
//         6

Measured memory_bytes: 5804
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000007


using namespace std;
#define ll long long
#define dbg if(0)
#define ISRANGE(val,lo,hi) ((lo<=val)&&(val<hi))



int main(){
    ll ans=0,n,k;
    cin>>n>>k;
    while(n>=k){
        n/=k;
        ans++;
    }
    ans++;
    cout<<ans<<endl;



    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define MOD 1000000007
#define INF 2000000000
#define MAX 100001
//#define int ll
#define ll long long
#define ld long double
#define vi vector<int>
#define pa pair<int, int>
 
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...)type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void MACRO_VAR_Scan(First& first, Rest&...rest) { cin >> first; MACRO_VAR_Scan(rest...); }
#define VEC(type, c, n) vector<type> c(n);for(auto& i:c)cin>>i;
#define MAT(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
 
#define BR cout << "\n";
#define SP cout << " ";
#define ENDL cout<<endl;
#define OUT(d) cout<<(d);
#define OUTL(d) cout<<(d)<<endl;
#define YES OUTL("YES")
#define Yes OUTL("Yes")
#define NO OUTL("NO")
#define No OUTL("No")
#define RET return 0;
 
#define REP(i, n) for(int i=0;i<(n);i++)
#define RREP(i, n) for(int i=n-1;i>=0;--i)
#define FOR(i, m, n) for(int i = m;i < n; i++)
#define RFOR(i, a, b) for(int i=(a)-1;i>=(b);--i)
#define AREP(a, n) for(auto (a):(n))
#define ALL(a) (a).begin(),(a).end()

int p[100][100], t[100][100];

int gcd(int x, int y){
    if(y == 0) return x;
    return gcd(y, x % y);
}
signed main(){ INIT;
    VAR(int, n, k);
    VEC(int, a, n);
    int l, M = 0;
    l = a[0];
    REP(i, n){
        l = gcd(l, a[i]);
        M = max(M, a[i]);
    }
    if(k%l == 0 && k <= M){ OUTL("POSSIBLE"); }
    else { OUTL("IMPOSSIBLE"); }
RET;}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int x = sc.nextInt();

        if (500 * k >= x) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

    }
}


Measured memory_bytes: 21844
import std.stdio;
import std.string;
import std.conv;

void main(){
    while(true){
	auto s = readln();
	if(stdin.eof()) break;
	real w = to!real(chomp(s));

	if(w <= 48.0) writeln("light fly");
	else if(w <= 51.0) writeln("fly");
	else if(w <= 54.0) writeln("bantam");
	else if(w <= 57.0) writeln("feather");
	else if(w <= 60.0) writeln("light");
	else if(w <= 64.0) writeln("light welter");
	else if(w <= 69.0) writeln("welter");
	else if(w <= 75.0) writeln("light middle");
	else if(w <= 81.0) writeln("middle");
	else if(w <= 91.0) writeln("light heavy");
	else writeln("heavy");
    }
}

Measured memory_bytes: 2440
#include <stdio.h>
#include <string.h>
int main(void){
    // Your code here!
    char str[1010];
    scanf("%s",str);
    int l;
    l=strlen(str);
    if(str[l-1]=='s') {strcat(str,"es");}
    else strcat(str,"s");
    printf("%s\n",str);
    return 0;
}


Measured memory_bytes: 1616
#include<stdio.h>
int main(void)
{
	int c,sum,box,n,i,b,a,s;
	scanf("%d %d %d",&n,&a,&b);
	for(i=1;i<=n;i++){
		box=i;
		sum=0;
	while(box>0){
		c=box%10;
		sum=sum+c;
		box=box/10;
	}
	if(sum>=a && sum<=b){
		s=s+i;
	}
	}
	printf("%d\n",s);
	return 0;
}

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

int main()
{
    int n;
    while(cin >> n)
    {
    int k;
    cin >> k;
    int arr[n];
    for(int i=0;i<n;i++)
    {
        cin >> arr[i];
    }
    sort(arr , arr+n);
    int x=n-k;
    int cnt=0;
    if(x==k)
    {
        cout << 0<<endl;
        cnt++;
    }
    long long int sum=0;
    for(int i=0;i<x;i++)
    {
        sum+=arr[i];
    }
    if(cnt==0)
    {
    cout << sum<<endl;
    }
    }
    return 0;
}


Measured memory_bytes: 1024
N=int(input())
D=list(map(int,input().split()))
mod=998244353

if D[0]!=0:
    print(0)
    exit()


B=[0]*N
for d in D:
    B[d]+=1
if B[0]!=1:
    print(0)
    exit()

ans=1
total=1
for i in range(1,N):
    if B[i]==0:
        if total!=N:
            print(0)
            exit()
        else:break
    total+=B[i]
    ans*=(B[i-1]**B[i])
    ans%=mod

print(ans)

Measured memory_bytes: 20836
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <climits>
#include <bitset>
#include <cassert>

using namespace std;

const int SIZE = 1 << 17;

int pointer = SIZE;
char buffer[SIZE];

char Advance() {
    if (pointer == SIZE) {
        fread(buffer, 1, SIZE, stdin);
        pointer = 0;
    }
    return buffer[pointer++];
}

int Read() {
    int answer = 0,sign = 1;
    char ch = Advance();
    while (!isdigit(ch) && ch != '-')
        ch = Advance();
    if (ch == '-') {
        ch = Advance();
        sign = -1;
    }
    while (isdigit(ch)) {
        answer = answer * 10 + ch - '0';
        ch = Advance();
    }
    return answer * sign;
}

char ReadCh() {
    char ch = Advance();
    while (!isalpha(ch))
        ch = Advance();
    return ch;
}

int main() {
    //freopen("tema.in", "r", stdin);
    //freopen("tema.out", "w", stdout);
    int n, k;
    scanf("%d%d", &n, &k);
    if (k == 0) {
        printf("%lld\n", 1LL * n * n);
        return 0;
    }
    long long answer = 0;
    for (int b = k + 1; b <= n; b++) {
        int b0 = b * (n / b);
        answer += 1LL * (b0 / b) * (b - k);
        if (n - b0 >= k)
            answer += n - b0 - k + 1;
    }
    printf("%lld\n", answer);
    return 0;
}


Measured memory_bytes: 384
r,c = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(r)]
ans = [0] * c

for i in range(r):
    A[i].append(sum(A[i]))
    for j in range(c):
        ans[j] += A[i][j]

ans.append(sum(ans))

for l in A:
    l = [str(i) for i in l]
    print(' '.join(l))
else:
    l = [str(i) for i in ans]
    print(' '.join(l))


Measured memory_bytes: 5700
#include <iostream>
#include <cstdint>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	int64_t W, H;
	cin >> W >> H;
	vector<int64_t> P;
	P.reserve(W + H);
	int64_t x;
	for (int i = 0; i < W + H; i++)
		cin >> x, P.push_back((x << 1) | (i < W));
	sort(P.begin(), P.end());
	int64_t r = 0;
	int64_t wh[] = {W + 1, H + 1};
	for (auto p : P) {
		int64_t t = p & 1;
		r += (p >> 1) * wh[t];
		wh[!t]--;
	}
	cout << r << endl;
	return 0;
}


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

#define FOR(i, l, r) for (size_t i = (l); i < (r); ++i)
#define REP(i, n) FOR(i, 0, n)

using namespace std;

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

    long long counter = 0;
    for (int i = 1; i < N; i++)
    {
        int j = 1;
        while (1)
        {
            if (i * j < N)
            {
                counter++;
            }
            else
            {
                break;
            }
            j++;
        }
    }
    cout << counter << "\n";
}


Measured memory_bytes: 3188
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd, ceil
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')
import string
# string.ascii_lowercase
from bisect import bisect_left

def solve():
    n = int(input())
    a = [int(x) for x in input().split()]
    ans = float('inf')
    for y in range(min(a), max(a) + 1):
        sm = 0
        for x in a:
            sm += (x - y) ** 2
        ans = min(ans, sm)
    print(ans)

t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""

azyxwvutsrqponmlkjihgfedcb

"""


Measured memory_bytes: 9912
#include<cstdio>
#include<queue>
#define NIL (-1)

using namespace std;

struct node{
    int parent;
    int left;
    int right;
    int key;
};

node tree[500001];
int treesize;
int root = NIL;

void pre(int id){
    if(id == -1)
        return;
    printf(" %d",tree[id].key);
    if(tree[id].left >= 0)
        pre(tree[id].left);
    if(tree[id].right >= 0)
        pre(tree[id].right);
}

void in(int id){
    if(id == -1)
        return;
    if(tree[id].left >= 0)
        in(tree[id].left);
    printf(" %d",tree[id].key);
    if(tree[id].right >= 0)
        in(tree[id].right);
    
}


void insert(int key){
    int y = NIL;
    int x = root;
    while(x != NIL){
        y = x;
        if(key < tree[x].key)
            x = tree[x].left;
        else
            x = tree[x].right;
    }
    tree[treesize].parent = y;

    if(y == NIL)
        root = treesize;
    else if(key < tree[y].key)
        tree[y].left = treesize;
    else
        tree[y].right = treesize;
    tree[treesize].left = NIL;tree[treesize].right = NIL;tree[treesize].key = key;

    treesize++;
        
}
bool find(int key){
    int x = root;

    while(x != NIL){
        if(key < tree[x].key)
            x = tree[x].left;
        else if(key > tree[x].key)
            x = tree[x].right;
        else
            return true;
    }
    return false;
}

int getnext(int start){
    int x = tree[start].right;
    while(tree[x].left != NIL)
        x = tree[x].left;
    return tree[x].key;
}

void dlt(int root,int key){
    int x = root;
    while(x != NIL){
        if(key < tree[x].key)
            x = tree[x].left;
        else if(key > tree[x].key)
            x = tree[x].right;
        else{
            if(tree[x].left != NIL && tree[x].right != NIL){
                int nextkey = getnext(x);
                dlt(x,nextkey);

                tree[x].key = nextkey;

            }else if(tree[x].left == NIL && tree[x].right == NIL){
                if(tree[tree[x].parent].left == x)
                    tree[tree[x].parent].left = NIL;
                else
                    tree[tree[x].parent].right = NIL;



            }else{
                int y = tree[x].left != NIL ? tree[x].left : tree[x].right;
                if(tree[tree[x].parent].left == x)
                    tree[tree[x].parent].left = y;
                else
                    tree[tree[x].parent].right = y;
                tree[y].parent = tree[x].parent;


            }
            break;
        }
    }
}


int main(void){
    int n;
    scanf("%d",&n);

    for(int i = 0;i < n;i++){
        char s[20];
        scanf("%s",s);

        if(s[0] == 'i'){
            int key;
            scanf("%d",&key);
            insert(key);
        }else if(s[0] == 'f'){
            int key;
            scanf("%d",&key);
            if(find(key))
                printf("yes\n");
            else
                printf("no\n");
        }else if(s[0] == 'd'){
            int key;
            scanf("%d",&key);
            dlt(root,key);
        }
        else{
            in(root);
            printf("\n");
            pre(root);
            printf("\n");
        }
    }

    return 0;
}

Measured memory_bytes: 8916
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;
using LD = long double;

LL N;
LL M;

template<typename T>
class BIT {
private:
	vector<T>arr;
	int siz;
public:
	BIT(int n) :siz(1) {
		while (siz < n)siz *= 2;
		arr.resize(siz + 1);
	}
	//[0,x)までの和を取得する
	T query(int x) {
		T s = 0;
		while (x > 0) {
			s += arr[x];
			x -= (x & -x);
		}
		return s;
	}
	//xに値kを加算する
	void add(int x, const T& k) {
		++x;
		while (x <= siz) {
			arr[x] += k;
			x += (x & -x);
		}
	}
};
#define BinaryIndexedTree BIT


struct line
{
	LL A, B, C;
};


const LD EPS = 1e-9;
vector<line>plane;

LL getDrop(LD X, BinaryIndexedTree<LL>& bit)
{
	vector<pair<LD, int>>cash;
	for (int i = 0; i < N; ++i)
	{
		const auto& lin = plane[i];
		LD Y = lin.C - lin.A * X;
		Y /= lin.B;
		cash.push_back({ Y,i });
	}
	sort(cash.rbegin(), cash.rend());
	LL ret = 0;
	for (int i = 0; i < N; ++i)
	{
		ret += bit.query(cash[i].second);
		bit.add(cash[i].second, 1);
	}
	return ret;
}
LD getMedian()
{
	LD lo = -1e10, hi = 1e10;
	while (hi - lo > EPS)
	{
		BinaryIndexedTree<LL>bit(N);
		LD mid = (lo + hi) / 2;
		LL res = getDrop(mid, bit);
		if (res * 2 < M)
		{
			lo = mid;
		}
		else
		{
			hi = mid;
		}
	}
	return hi;
}

int main(void)
{
	cin >> N;
	M = (N - 1) * (N) / 2;
	for (int i = 0; i < N; ++i)
	{
		int a, b, c;
		cin >> a >> b >> c;
		plane.push_back({ a,b,c });
	}
	sort(plane.begin(), plane.end(), [](const line& l1, const line& l2)
	{
		return (LD)l1.A / l1.B < (LD)l2.A / l2.B;
	});
	LD xMedian = getMedian();
	for (int i = 0; i < N; ++i)
	{
		swap(plane[i].A, plane[i].B);
	}
	sort(plane.begin(), plane.end(), [](const line& l1, const line& l2)
	{
		return (LD)l1.A / l1.B < (LD)l2.A / l2.B;
	});
	LD yMedian = getMedian();
	cout.precision(15);
	cout << xMedian << " " << yMedian << endl;
	return 0;
}


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


int N, R;


void input() {
    cin >> N >> R;
}


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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// #define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
#define ITR(v,c) for(auto v=begin(c);v!=end(c);v++)
#define FORE(x,c) for(auto &x:c)
#define FOR(v,a,n) for(int v=a;v<(int)(n);v++)
#define REP(v,n) FOR(v,0,n)
#define RREP(v,n) for(int v=((int)(n)-1);v>=0;v--)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define SZ(c) ((int)c.size())
const int DX[9]={0,1,0,-1,1,1,-1,-1,0}, DY[9]={-1,0,1,0,-1,1,1,-1,0};
const int INF=1e9; const long long INFLL=1e18;
template<class T> ostream& operator << (ostream &os, const vector<T> &v) {
    ITR(i,v) os<<*i<<(i==end(v)-1?"":" "); return os; }
template<class T> istream& operator >> (istream &is, vector<T> &v) {
    ITR(i,v) is>>*i; return is; }
//------------------------------------------------------------------------------

signed main() {
    int n;
    cin>>n;
    vi p(n),a(n),b(n);
    cin>>p;
    REP(i,n) a[i]=500000000+i*n,b[i]=500000000+(n-i-1)*n;
    REP(i,n) {
        a[p[i]-1]+=i;
    }
    cout<<a<<endl;
    cout<<b<<endl;
    return 0;
}


Measured memory_bytes: 896
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    A, B, K = map(int, readline().split())
    for i in range(K):
        if i%2==0:
            if A%2==1:
                A -= 1
            B += A//2
            A //= 2
        else:
            if B%2==1:
                B -= 1
            A += B//2
            B //= 2
    print(A, B)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9260
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  int l, r, sum;
  for(int i = 0; i < N; i++){
    cin >> l >> r;
    
    sum += r - l + 1;
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 256
def solve(a,b):
	for i in range(1,a+1):
		x = i 
		y = a-i
		if (x*2 + y*4 == b) or (x*4 + y*2 == b):
			return True
	return False 
a,b = map(int,input().split())
if solve(a,b):
	print("Yes")
else:
	print("No")

Measured memory_bytes: 9020
n = input()
p = [int(num) for num in input().split()]

count = 0

for i in range(1,len(p)-1):
    if (p[i] < p[i+1] and p[i] > p[i-1]) or (p[i] < p[i-1] and p[i] > p[i+1]):
        count +=1

print(count)


Measured memory_bytes: 3060
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var sc = bufio.NewScanner(os.Stdin)

func main() {
	// Code for A - Addition
	var N int
	fmt.Scanf("%d", &N)

	sc.Split(bufio.ScanWords)
	var A int
	var count int
	for i := 0; i < N; i++ {
		A = nextInt()
		if A%2 != 0 {
			count++
		}
	}

	if count%2 != 0 {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
	}

}


Measured memory_bytes: 3384
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()
  val t = sc.nextLong()
  val a = List.fill(n)(sc.nextLong())
  if (n == 1) {
    println(t)
  } else {
    val ans = a.sliding(2).map{case List(a1, a2) => t.min(a2 - a1)}.sum + t
    println(ans)
  }
}


Measured memory_bytes: 73232
import java.util.Scanner;

class Main{

	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		String nums = sc.nextLine();
		String num[] = nums.split(" ");
		int N = Integer.parseInt(num[0]);
		int M = Integer.parseInt(num[1]);
		String inputs = sc.nextLine();
		String input[] = inputs.split(" ");

		int count = 0;
		int sum = 0;
		for(int i = 0;i < input.length;i++){
			sum += Integer.parseInt(input[i]);
		}
		//System.out.println("sum = " + sum);

		//int popular = sum / (4 * M);
		double popular = (double)sum / (4 * M);
		//System.out.println("popular = " + popular);
		for(int i = 0;i < input.length;i++){
			if(Integer.parseInt(input[i]) >= popular){
				count++;
			}
		}

		if(count >= M){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}

	}
}

class atcoder_20200404_2{
	public static void main(String args[]){
		new Main().main(args);
	}
}


Measured memory_bytes: 21844
import java.util.Scanner;

public class Main {

	static Scanner scanner;

	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    //String s=gs();
	    int a=gi();
	    int b=gi();
	    int c=gi();
	    int d=gi();
	    
	    //System.out.print(String.valueOf(s.charAt(0))+ (s.length()-2)+s.charAt(s.length()-1));

	    if (b<=c || d<=a) {
        	System.out.print(0);
        }else if(a<=c && b<=d){
        	System.out.print(b-c);
        } else if (c<=a && d<=b) {
        	System.out.print(d-a);
        } else {
        	System.out.print(Math.min(b-a, d-c));
        }


	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35736
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//等価なものに変換する思考
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//配列はvector<>を使う：意味わからないエラーがなくなる。
//背反な事象にちゃんとわける
//チェックリストはマップを使う
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//またはかかつか
//例外処理は最初にする
//x = p^m + q^n...の約数の個数:(n+1)*(m+1)....
//N!のどの素因数で何回割れるか
//⇔1~Nまでの数がそれぞれどの素因数で何回割り切れるかの和
//パズルの問題->一般化して全探索
//数が大きい時のせぐふぉはコードテストで試してみる
//スペルミスに注意
//stack<ll> s;
//s.push(要素);s.top();s.pop();
//queue<ll> q;
//q.push(要素);q.front();q.pop();
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
	using namespace std;

//円周率
const double PI = 3.14159265358979323846;
//割るやつ
const ll M = (pow(10, 9) + 7);

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

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

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

//階乗計算
ll f(ll n) {
	if (n == 0 || n == 1) return 1;
	else return (n * f(n - 1)) % M;
}

//Nをdで何回割れるか
ll divcnt(ll N, ll d) {
	ll ans = 0;
	while (1) {
		if (N%d == 0) {
			ans++;
			N /= d;
		}
		else break;
	}

	return ans;
}

//素数判定
bool prime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2) {
		if (num % i == 0) return false;
	}
	return true;
}

//フィボナッチ数列
vector<ll> memo(pow(10, 6) + 1);
ll fibo(ll n) {
	if (n == 1) return 1;
	else if (n == 2) return 1;
	else if (memo[n] != 0) return memo[n];
	else return memo[n] = fibo(n - 1) + f(n - 2);
}

int main() {
	double R; cin >> R;
	cout << setprecision(20) << 2 * PI * R << endl;
}

Measured memory_bytes: 11032
#include <cstdio>
#include <complex>
#include <vector>
using namespace std;
typedef complex<double> P;
const double PI=3.141592653589793238462643383279;

bool inC(P p, P c, double r){return abs(p-c)<r+1e-9;}

P getE(P p){return p/abs(p);}

double sq(double x){ return  x*x;}

int main(){
    int n,i,j,k,ans,cnt;
    double x, y;
    while(scanf("%d",&n)){
        if(n==0) break;
        ans=0;
        vector<P> ps(n);
        for(i=0; i<n; i++){
            scanf("%lf%lf",&x,&y);
            ps[i] = P(x,y);
        }
        for(i=0;i<n;i++)
            for(j=i+1;j<n;j++)if(abs(ps[i]-ps[j])<2){
                double d=sqrt(1-sq(abs(ps[j]-ps[i])*0.5));
                P c1=0.5*(ps[i]+ps[j])+getE(getE(ps[j]-ps[i]))*polar(d,PI/2);
                P c2=0.5*(ps[i]+ps[j])+getE(getE(ps[j]-ps[i]))*polar(d,-PI/2);
                cnt=0;
                for(k=0;k<n;k++)if(inC(ps[k],c1,1.0))cnt++;
                if(cnt>ans)ans=cnt;
                cnt=0;
                for(k=0;k<n;k++)if(inC(ps[k],c2,1.0))cnt++;
                if(cnt>ans)ans=cnt;
            }
        if(ans==0) ans++;
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 2752
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
const LL MOD = 1000000007LL;
int w[201];
LL dp[10001];
int main() {
	int N, W;
	cin >> N >> W;
	for (int i = 0; i < N; i++) {
		cin >> w[i];
	}
	w[N] = 1 << 30;
	sort(w, w + N);
	LL ans = 0;
	for (int i = 0; i <= N; i++) {
		int sum = 0;
		for (int j = 0; j < i; j++) sum += w[j];
		memset(dp, 0, sizeof(dp));
		dp[0] = 1;
		for (int j = i + 1; j < N; j++) {
			for (int k = W; k >= 0; k--) {
				if (k + w[j] <= W - sum) (dp[k + w[j]] += dp[k]) %= MOD;
			}
		}
		for (int j = max(W - sum - w[i] + 1, 0); j <= W - sum; j++) {
			(ans += dp[j]) %= MOD;
		}
	}
	cout << ans << endl;
}


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

int main() {
	int n;
	cin>>n;
	int a,b,count=0;
	string s;
	s="No";
	for(int i=0;i<n;i++)
	{
	    cin>>a>>b;
	    if(a==b)
	    count++;
	    else
	    count=0;
	    if(count==3)
	    s="Yes";
	}
	cout<<s;
	return 0;
}

Measured memory_bytes: 3616
import java.io.*;

class Main {

	public static void main(String[] args) {
		int num;
		String buf;
		try{
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			buf = br.readLine();
			num = Integer.parseInt(buf);
			System.out.println(num * num * num);
		} catch(Exception e) {}
	}
}


Measured memory_bytes: 24284
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(int (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num,init) vector<ll> name((num),(init));
#define op(i) cout<<(i)<<endl;
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define mat(name,fnum,snum,init); vector<vector<ll>> name((fnum),vector<ll>((snum),(init)));

int main(){
    ll n;
    ll ans=0;
    cin>>n;
    vec(c,n,0);
    vec(s,n,0);
    vec(f,n,0);
    rep(i,n-1){
        cin>>c[i]>>s[i]>>f[i];
    }
    rep(j,n){
        ans=0;
    repf(i,j,n-1){
        if(ans<s[i]){
            ans=s[i];
        }else {
            ans=(ans%f[i]? (ans/f[i]+1)*f[i]:ans);
        }
        ans+=c[i];
    }
    cout<<ans<<endl;
    }
    return 0;

}

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

#include<cstdio>
#define r(i,n) for(int i=0;i<n;i++)


int main(void){
  int n,m,x,y;
  cin>>n>>m>>x>>y;
  vector<int> a(n),b(m);
  int zmin=10000,zmax=-1000;
  r(i,n){cin>>a.at(i);zmax=max(zmax,a.at(i));}
  r(i,m){cin>>b.at(i);zmin=min(zmin,b.at(i));}

  if(zmin>y)zmin=y;
  if(zmax<x)zmax=x;

  if(zmin>zmax)cout<<"No War"<<endl;
  else cout<<"War"<<endl;








return 0;}


Measured memory_bytes: 256