akhauriyash/Code-Regression huggingface dataset:
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static class Tree {
		public class Edge {
			int to, rev;

			public Edge(int to, int rev) {
				this.to = to;
				this.rev = rev;
			}
		}

		int V;
		ArrayList<ArrayList<Edge>> G;
		int root;
		int[] p;
		int[] min;
		int[] max;
		int[] evenOdd;

		public Tree(int[] a, int[] b) {
			this.V = a.length+1;
			p = new int[V];
			min = new int[V];
			max = new int[V];
			evenOdd = new int[V];

			Arrays.fill(min, -10000000);
			Arrays.fill(max, 10000000);

			G = new ArrayList<ArrayList<Edge>>();
			for(int i=0; i<V; i++) {
				G.add(new ArrayList<Edge>());
			}

			for(int i=0; i<V-1; i++) {
				G.get(a[i]).add(new Edge(b[i], G.get(b[i]).size()));
				G.get(b[i]).add(new Edge(a[i], G.get(a[i]).size()-1));
			}
			setRoot(0);
		}

		public void setRoot(int root) {
			this.root = root;
			setRoot(root, -1);
		}
		public void setRoot(int cur, int parent) {
			p[cur] = parent;
			for(int i=0; i<G.get(cur).size(); i++) {
				int next = G.get(cur).get(i).to;
				if(next!=parent) {
					setRoot(next, cur);
				}
			}
		}
		public boolean check() {
			if(!check(0))
				return false;
			setRecursive(0, min[0], min[0]);
			return true;
		}
		public void set(int i, int v) {
			min[i] = max[i] = v;
			evenOdd[i] = v%2==0 ? 2 : 1;
		}

		boolean check(int i) {
			boolean[] eo = new boolean[3];
			for(Edge e : G.get(i)) {
				if(e.to==p[i])
					continue;
				if(!check(e.to))
					return false;
				min[i] = Math.max(min[i], min[e.to]-1);
				max[i] = Math.min(max[i], max[e.to]+1);
				eo[evenOdd[e.to]] = true;
			}
			if(evenOdd[i]!=0)
				eo[3-evenOdd[i]] = true;
			if(eo[1] && eo[2])
				return false;
			evenOdd[i] = eo[1] ? 2 : (eo[2] ? 1 : 0);
			return min[i]<=max[i];
		}
		void setRecursive(int i, int x1, int x2) {
			if(min[i]<=x1 && x1<=max[i])
				min[i] = max[i] = x1;
			else
				min[i] = max[i] = x2;

			for(Edge e : G.get(i)) {
				if(e.to==p[i])
					continue;
				setRecursive(e.to, min[i]-1, min[i]+1);
			}
		}

	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);

		int N = sc.nextInt();

		int[] a = new int[N-1];
		int[] b = new int[N-1];
		for(int i=0; i<N-1; i++) {
			a[i] = sc.nextInt()-1;
			b[i] = sc.nextInt()-1;
		}

		Tree tree = new Tree(a, b);

		int K = sc.nextInt();
		for(int i=0; i<K; i++) {
			int V = sc.nextInt()-1;
			int P = sc.nextInt();
			tree.set(V, P);
		}

		if(tree.check()) {
			pw.println("Yes");
			for(int i=0; i<N; i++)
				pw.println(tree.min[i]);
		} else {
			pw.println("No");
		}

		sc.close();
		pw.close();
	}

}


Measured memory_bytes: 115564
#include <iostream>

using namespace std;

int main() {
  string w;
  int char_count[26] = {0};
  cin >> w;
  for (char c : w) {
    char_count[c - 'a'] += 1;
  }
  for (int i = 0; i < 26; i++) {
    if (char_count[i] % 2 != 0) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>){
    val (A, B) = readLine()!!.split(" ").map{it.toInt()}


    if(A+B <= 16){
        if(A <= 8){
            if(B <= 8){
                println("Yay!")
            }else {
                println(":(")
            }
        }else{
            println(":(")
        }
    }else{
        println(":(")
    }
}


Measured memory_bytes: 37944
s=str(input())

if 1<=int(s[:2])<=12 and 1<=int(s[2:])<=12:
    print('AMBIGUOUS')
elif 1<=int(s[:2])<=12 and (int(s[2:])>12 or int(s[2:])==0):
    print('MMYY')
elif (int(s[:2])>12 or int(s[:2])==0) and 1<=int(s[2:])<=12:
    print('YYMM')
elif (int(s[:2])>12 or int(s[:2])==0) and (int(s[2:])>12 or int(s[2:])==0):
    print('NA')

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <numeric>
#include <string>
#include <cstring>
#include <cmath>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long int int64;


const double eps = 1e-9;

bool doubleEqual(double x, double y)
{
    return fabs(x - y) < eps;
}


struct Task
{
    int n;
    double d1, x;

    Task() : n(), d1(), x() {}

    Task(int _n, double _d1, double _x) : n(_n), d1(_d1), x(_x) {}

    double curDist()
    {
        return (double) d1 + (2. * n - 1) / 2. * x;
    }

    void read()
    {
        scanf("%d%lf%lf", &n, &d1, &x);
    }

    void eprint()
    {
        eprintf("%d %.10lf %.10lf\n", n, d1, x);
    }
};

Task reduceFast(Task T)
{
    double d1 = (T.n + 1.) / (double) T.n * T.d1 + (5. * T.x) / (2. * T.n);
    double d2 = (T.n + 1.) / (double) T.n * T.d1 + (2. * T.n + 9.) / (2. * T.n) * T.x;
    return Task(T.n - 1, d1, d2 - d1);
}

Task reduceSlow(Task T)
{
    vector <double> cd;
    cd.push_back(T.d1);
    while ((int) cd.size() < 2 * T.n)
        cd.push_back(cd.back() + T.x);

    for (int i = 0; i < 10; i++)
        eprintf("%.5lf ", cd[i]); eprintf("... \n");

    vector <double> d(2 * (T.n - 1));

    for (int i = 0; i < (int) cd.size(); i++)
    {
        for (int j = 0; j < i - 1; j++)
            d[j] += cd[j];
       
        if (i != 0 && i != (int) cd.size() - 1)
            d[i - 1] += cd[i - 1] + cd[i] + cd[i + 1];
        
        for (int j = i + 2; j < (int) cd.size(); j++)
            d[j - 2] += cd[j];
    }
    for (auto &x : d)
        x /= (double) cd.size();

    for (int i = 0; i < 10; i++)
        eprintf("%.5lf ", d[i]); eprintf("... \n");

    double x = d[1] - d[0];

    for (int i = 0; i + 1 < (int) d.size(); i++)
        if (!doubleEqual(d[i + 1] - d[i], x))
        {
            eprintf("i = %d\n", i);
            eprintf("x = %.5lf, d[i] = %.5lf, d[i + 1] = %.5lf\n", x, d[i], d[i + 1]);
            throw;
        }

    return Task(T.n - 1, d[0], x);
}


int main(int,  char **)
{
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

    Task T;
    T.read();

    //Task Ts = reduceSlow(T);
    //Task Tf = reduceFast(T);

    //Ts.eprint();
    //Tf.eprint();
    
    double ans = 0;
    while (T.n > 0)
    {
        ans += T.curDist();
        T = reduceFast(T);
    }

    printf("%.10lf\n", ans);



	return 0;
}




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

using namespace std;

using ll = long long;

int const maxn = 101010;

int mod;

vector<int> v[maxn];
int dp[maxn], up[maxn];

int pref[maxn], suf[maxn];

void mul(int& a, int b) {
    a = (ll)a*b%mod;
}

int solve(int x, int p) {
    int& d = dp[x];

    if (d != -1) return d;

    d = 1;
    for (int u : v[x]) {
        if (u == p) continue;

        mul(d, solve(u, x) + 1);
    }

    int k = 1;
    for (int u : v[x]) {
        if (u == p) continue;
        pref[u] = k;
        mul(k, solve(u, x) + 1);
    }

    k = 1;
    for (int i = (int)v[x].size()-1; i >= 0; i--) {
        int u = v[x][i];

        if (u == p) continue;
        suf[u] = k;
        mul(k, solve(u, x) + 1);
    }

    return d;
}

void solve2(int x, int p) {
    for (int u : v[x]) {
        if (u == p) continue;

        up[u] = 1;
        mul(up[u], pref[u]);
        mul(up[u], suf[u]);
        mul(up[u], up[x] + 1);

        mul(dp[u], up[u] + 1);

        solve2(u, x);
    }
}

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    
    int n;
    cin >> n >> mod;

    for (int i = 1; i < n; i++) {
        int a, b;
        cin >> a >> b;

        v[a].push_back(b);
        v[b].push_back(a);
    }

    memset(dp, -1, sizeof(dp));

    solve(1, 1);
    solve2(1, 1);

    for (int i = 1; i <= n; i++) {
        cout << dp[i] << "\n";
    }
}

Measured memory_bytes: 13952
program prob5
    implicit none
    integer(16)::N, i, j, cnt, ans1
    integer(16),allocatable::A(:), c(:), d(:)
    read(*,*) N
    allocate(A(N), c(N), d(N))
    read(*,*) A
    call heapsort(N,A)

    j = 1
    cnt = 0
    c(1) = 1
    d(1) = A(N)
    do i = N-1, 1, -1
        if(A(i) == d(j))then
            c(j) = c(j) + 1
            if(cnt == 1 .and. c(j) >= 4)then
                write(*,*) A(i)*A(i)
                stop
            else if(c(j) == 2)then
                if(cnt == 0)then
                    cnt = 1
                    ans1 = d(j)
                else if(cnt == 1)then
                    write(*,*) ans1*d(j)
                    stop
                end if
            end if
        else
            j = j+1
            c(j) = 1
            d(j) = A(i)
        end if

    end do
    write(*,*) 0
    stop
    contains
    subroutine heapsort(n,array)
        implicit none
        integer(16),intent(in) :: n
        integer(16),intent(inout) :: array(1:n)
       
        integer ::i,k,j,l
        double precision :: t
       
        if(n.le.0)then
           write(6,*)"Error, at heapsort"; stop
        endif
        if(n.eq.1)return
      
        l=n/2+1
        k=n
        do while(k.ne.1)
           if(l.gt.1)then
              l=l-1
              t=array(L)
           else
              t=array(k)
              array(k)=array(1)
              k=k-1
              if(k.eq.1) then
                 array(1)=t
                 exit
              endif
           endif
           i=l
           j=l+l
           do while(j.le.k)
              if(j.lt.k)then
                 if(array(j).lt.array(j+1))j=j+1
              endif
              if (t.lt.array(j))then
                 array(i)=array(j)
                 i=j
                 j=j+j
              else
                 j=k+1
              endif
           enddo
           array(i)=t
        enddo
      
        return
    end subroutine heapsort
end program

Measured memory_bytes: 7048
// AOJ 1367: Rearranging a Sequence
// 2017.10.9 bal4u@uu
// 2018.1.8

#include <stdio.h>

typedef struct { int id, a; } T;
T tbl[200002], tb2[200002];

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

#define VMAX 300000
int f[VMAX+1];
void distsort(int n)
{
	int i, x;
	T *tp;

//	memset(f, 0, sizeof(f));
	tp = tbl+1, i = n; while (i--) f[tp->id]++, tp++;
	for (i = 2; i <= VMAX; i++) f[i] += f[i-1];
	for (i = n; i > 0; i--) x = tbl[i].id, tb2[--f[x]] = tbl[i];
}

int main()
{
	int n, m, i, j;
	register T *tp;

	n = in(), m = in();
	tp = tbl+1, j = n; for (i = 1; i <= n; i++) tp->id = j--, tp->a = i, tp++;

	while (m-- > 0) tbl[in()].id = i++;

	distsort(n);
	while (n--) printf("%d\n", tb2[n].a);
	return 0;
}



Measured memory_bytes: 6144
#include"iostream"
using namespace std;
void insertionsort(int num[], int n);
int main()
{
	int n;
	cin >> n;
	int*num = new int[n];
	int i;
	for (i = 0; i < n; ++i)
		cin >> num[i];
	insertionsort(num, n);
	return 0;
}
void insertionsort(int num[], int n)
{
	int i, j;
	int key;
	cout << num[0];
	for (j = 1; j < n; ++j)cout << ' ' << num[j];
	cout << endl;
	for(i=1;i<n;++i)
	{
		key = num[i];
		j = i - 1;
		while (j >= 0 && num[j] > key)
		{
			num[j + 1] = num[j];
			--j;
		}
		num[j + 1] = key;
		cout << num[0];
		for (j = 1; j < n; ++j)cout << ' ' << num[j];
		cout << endl;
	}
}


Measured memory_bytes: 3092
S=input()

S_1=int(S[0]+S[1])
S_2=int(S[2]+S[3])

if S_1 in range(1, 13):
    #YYMM MMYY
    if S_2 in range(1,13):
        print("AMBIGUOUS")
    else :
        print("MMYY")

elif S_1 ==0:
    if S_2 in range(1,13):
        print("YYMM")
    else:
        print("NA")

elif S_1 >12:
    if S_2 in range(1,13):
        print("YYMM")
    else :
        print("NA")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	map<int,int> cnt;
	rep(i,3){
		int a,b;
		cin>>a>>b;
		cnt[a]++;
		cnt[b]++;
	}
	vector<int> now(10,0);
	for(auto itr:cnt){
		now[itr.se]++;
	}
	if(now[1]==2 && now[2]==2) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#include <iterator>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

template <typename T> inline void voutput(T &v){
    rep(i, v.size()){
        if (i) cout << " " << v[i];
        else cout << v[i];
    }
    cout << endl;
}

vector<vector<int>> shift(vector<vector<int>> C, int s){
    int n = (int)C.size();
    vector<vector<int>>  ret(n, vector<int>(n));
    rep(i, n){
        rep(j, n){
            ret[i][j] = C[j][(i + s * j) % n];
        }
    }
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    
    int N = 44;
    vector<vector<int>>  A(N * N - N + 1, vector<int>(N));
    vector<vector<int>>  B(N - 1, vector<int> (N - 1));
    int cur = 1;
    rep(i, N){
        A[i][0] = 1;
        rep(j, 1, N){
            A[i][j] = cur + 1;
            cur++;
        }
    }
    rep(i, 1, N){
        rep(j, 1, N){
            B[i - 1][j - 1] = A[i][j];
        }
    }
    
    int ind = N;
    rep(i, N - 1){
        int t = i + 2;
        auto tmp = shift(B, i);
        rep(j, N - 1){
            A[ind][0] = t;
            rep(k, N - 1){
                A[ind][k + 1] = tmp[j][k];
            }
            ind++;
        }
    }
    
    cout << cur << " " << N << endl;
    rep(i, N * N - N + 1){
        voutput(A[i]);
    }
    
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const double eps=1e-9;
const int inf=1e9;
typedef pair<int,int> P;
struct Point
{
  double x,y;
  Point(){x=0;y=0;}
  Point(double d_x,double d_y){x=d_x,y=d_y;}
  double operator*(Point obj){return obj.x*x+obj.y*y;}
  double operator%(Point obj){return obj.y*x-obj.x*y;}
  Point operator*(double b){Point tmp;tmp.x=x*b;tmp.y=y*b;return tmp;}
  Point operator/(double b){Point tmp;tmp.x=x/b;tmp.y=y/b;return tmp;}
  Point operator+(Point obj){Point tmp;tmp.x=x+obj.x;tmp.y=y+obj.y;return tmp;}
  Point operator-(){Point tmp;tmp.x=-x;tmp.y=-y;return tmp;}
  Point operator-(Point obj){Point tmp;tmp.x=x-obj.x;tmp.y=y-obj.y;return tmp;}
  Point operator-=(Point obj){x-=obj.x;y-=obj.y;return *this;}
  Point operator+=(Point obj){x+=obj.x;y+=obj.y;return *this;}
  Point operator/=(double b){x=x/b;y=y/b;return *this;}
  Point operator*=(double b){x=x*b;y=y*b;return *this;}
  double size(){return hypot(x,y);}
  Point unit(){return Point(x/size(),y/size());}
  Point normal(){return Point(y,-x);}
  double atan(){return atan2(y,x);}
};

bool operator<(Point a,Point b){return a.x!=b.x?a.x<b.x:a.y<b.y;}
bool operator>(Point a,Point b){return b<a;}
bool operator<=(Point a,Point b){return !(b<a);}
bool operator>=(Point a,Point b){return !(a<b);}
bool operator==(Point a,Point b){return (a-b).size()<eps;}
bool operator!=(Point a,Point b){return !(a==b);}

bool equal(double a,double b){return abs(a-b)<eps;}
double cross(Point a,Point b){return a%b;}
double dot(Point a,Point b){return a*b;}

int ccw(Point a,Point b,Point c)
{
  b=b-a;
  c=c-a;
  if(b%c>0) return +1;
  else if(b%c<0)return -1;
  else if(b*c<0) return +2;
  else if(b.size()<c.size()) return -2;
  else return 0;
}

struct Tree
{
  int _d;
  string _name;
  vector<Tree*> _v;
  Tree(string name,int d)
  {
    _name=name;
    _d=d;
  }
  void add(Tree* t)
  {
    _v.push_back(t);
  }
  void print()
  {
    for(int i=0;i<_d;i++)
      {
	cout << '.';
      }
    cout << _name << endl;
    for(int i=0;i<_v.size();i++)
      {
	_v[i]->print();
      }
  }
};

int main(int argc,char const* argv[])
{
  int n,k1,k;
  string m1,m;
  Tree* v[1005];
  Tree *t,*root;
  cin >> n >> k1 >> m1;
  root=t=new Tree(m1,k1);
  v[1]=t;
  for(int i=2;i<n+1;i++)
    {
      cin >> k >> m;
      t=new Tree(m,v[k]->_d+1);
      v[k]->add(t);
      v[i]=t;
    }
  root->print();
  return 0;
}



Measured memory_bytes: 3376
#include<bits/stdc++.h>
using namespace std;
int main()
{
      int n;
      cin >> n;
      string s,t;
      cin >> s >> t;
      string ans = "";
      for(int i=0;i<n;i++)
      {

                  ans += s[i];
                  ans += t[i];
            

      }
      cout << ans << endl;
}


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

#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i<(ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)

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

int dy[4]={-1,1,0,0};
int dx[4]={0,0,1,-1};

int main(){
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int ans = INF;
    REP(i, s.size() - 2) {
        int n;
        stringstream ss;
        ss << s.substr(i, 3);
        ss >> n;
        ans = chmin(ans, abs(753 - n));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = 998244353;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
ll x[100000];
int main(){
	int n,k; cin >> n >> k;
	rep(i, n) {
		cin >> x[i];
	}
	ll out = INF;
	rep(i, n - k+1) {
		out = min(out, x[i + k-1] - x[i] + min(abs(x[i]), abs(x[i + k-1])));
	}
	cout << out << endl;
	return 0;
}

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

typedef long long int ll;

ll gcd(ll a, ll b){
	return (b > 0)? gcd( b , a%b ) : a ;
}

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

int main(){
	ll a1, a2, a3, m1, m2, m3;
	while( cin >> a1 >> m1 >> a2 >> m2 >> a3 >> m3 , a1||m1||a2||m2||a3||m3 ){
		ll x, y, z, a, b, c;
		a = b = c = x = y = z = 1;
		x = (x * a1) % m1;
		y = (y * a2) % m2;
		z = (z * a3) % m3;
		for( ; x != 1 ; a++ ){
			x = (x * a1) % m1;
		}
		for( ; y != 1 ; b++ ){
			y = (y * a2) % m2;
		}
		for( ; z != 1 ; c++ ){
			z = (z * a3) % m3;
		}
		ll ans = lcm( lcm(a,b) , c);
		cout << ans << endl;
	}
}

Measured memory_bytes: 1156
using System.Linq;
using System.Collections.Generic;
using static System.Math;
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var k = int.Parse(line[1]);
        var s = Console.ReadLine().Trim();
        if (n == 1 ) { Console.WriteLine(1); goto exit; }
        var a = s.ToCharArray();
        var b = new List<int>();
        if (a[0] == '0') b.Add(0);
        var t = a[0];
        var count = 1;
        for (int i = 1; i < n; i++)
        {
            if (a[i] == t) count++;
            else
            {
                b.Add(count);
                count = 1;
            }
            t = a[i];
        }
        b.Add(count);
        var x = 2 * k + 1;
        for (int i = 0; i < x + 1; i++) b.Add(0);
        var bc = b.Count();
        var c = new int[bc+ 1];
        for (int i = 1; i < bc + 1; i++)
            c[i] = c[i - 1] + b[i - 1];
        var ans = 0;
        for (int i = 0; i <= c.Length - x -1 ; i+=2)
        {
            var tt = c[i + x ] - c[i];
            ans = Max(ans, tt);
        }
        Console.WriteLine(ans);
        exit:;
    }
}

Measured memory_bytes: 13792
n = int(input())

A = [[] for i in range(n)]

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

f_inf = float("inf")
B = [[f_inf for i in range(2)] for j in range(n)]
B[0][1] = 0

for i in range(n):
  B[i][0] = i+1

def dbs(a):
  global order
  l = len(A[a-1])-2
  if l:
    for i in range(l):
      depth = B[a-1][1]+1
      b = A[a-1][i+2]
      if not b in order or depth < B[b-1][1]:
        B[b-1][1] = depth
        order.append(b)
        dbs(b)

order = [1]
dbs(1)

for i in range(n):
  if B[i][1] == f_inf:
    B[i][1] = -1
  print(" ".join(map(str, B[i])))


Measured memory_bytes: 5656
package main

import "fmt"

func main() {
	var s, p string
	fmt.Scan(&s, &p)
	s = s + s
	for i := 0; i+len(p) < len(s); i++ {
		if s[i:i+len(p)] == p {
			fmt.Println("Yes")
			return
		}
	}
	fmt.Println("No")
}



Measured memory_bytes: 1180
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            //int n = int.Parse(Console.ReadLine());
            int[] NK = Console.ReadLine().Split(" ").Select(x => int.Parse(x)).ToArray();
            int[] P = Console.ReadLine().Split(" ").Select(x => int.Parse(x)).ToArray();
            int k = NK[1];
            Array.Sort(P);
            int res=0;
            for (int i = 0; i < k; i++)
            {
                res += P[i];
            }
            Console.WriteLine(res);
        }
    }
}

Measured memory_bytes: 28464
#include<bits/stdc++.h>//万能头文件好 
using namespace std;
int main(){
	int n,k,ai,ans=0;
	scanf("%d%d",&n,&k);
	while(n--){
		scanf("%d",&ai);
		ans+=min(ai-0,k-ai)*2;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>

using namespace std;
using ll=long long int;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> X(M);
    for (auto &e: X) cin >> e;

    vector<int> diff(M-1);
    sort(X.begin(), X.end());
    for (int i = 0; i < M-1; ++i) {
        diff[i] = X[i+1] - X[i];
    }

    sort(diff.begin(), diff.end());
    int ans = accumulate(diff.begin(), diff.begin()+max(0, M-N), 0);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
N,K,C = map(int,input().split())
S = input()
L = []
R = []
i = 0
while i < N:
    if S[i] == "o":
        L.append(i)
        i += C
    i += 1
j = N-1
while j >= 0:
    if S[j] == "o":
        R.append(j)
        j -= C
    j -= 1   
for i in range(K):
    if L[i] == R[K-1-i]:
        print(L[i]+1)

Measured memory_bytes: 25448
n = int(input())
s = input()

left = [0] * n
right = [0] * n

tmp = 0
for i in range(1, n):
    if s[i - 1] == "W":
        tmp += 1
        left[i] = tmp
    else:
        left[i] = tmp

tmp = 0
for i in range(n - 2, -1, -1):
    if s[i + 1] == "E":
        tmp += 1
        right[i] = tmp
    else:
        right[i] = tmp

res = 10**9
for i in range(n):
    res = min(res, left[i] + right[i])
print(res)


Measured memory_bytes: 23524
import java.util.Scanner


object Main {

  case class ResidueRing(private val input: Long) {
    val representative: Long = ((input % ResidueRing.mod) + ResidueRing.mod) % ResidueRing.mod

    def +(that: ResidueRing): ResidueRing = ResidueRing(this.representative + that.representative)

    def -(that: ResidueRing): ResidueRing = ResidueRing(this.representative - that.representative)

    def *(that: ResidueRing): ResidueRing = ResidueRing(this.representative * that.representative)

    def unary_- : ResidueRing = ResidueRing(-this.representative)

  }

  object ResidueRing {
    val mod: Long = (1e9 + 7).toLong
    val zero: ResidueRing = ResidueRing(0)
    val one: ResidueRing = ResidueRing(1)
  }

  def read() = {
    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    val s = sc.next()
    (n, s)
  }

  def solve(n: Int, s: String): Long = {
    val result = s.groupBy(identity).map(_._2.length).map(i => ResidueRing(i)).map(r => r + ResidueRing.one).foldLeft(ResidueRing.one)(_ * _) - ResidueRing.one
    result.representative
  }

  def main(args: Array[String]): Unit = {
    val (n, s) = read()
    println(solve(n, s))
  }
}

Measured memory_bytes: 31344
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <utility>
#include <random>
#include <chrono>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

using namespace std;

using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using PIL = pair<int, LL>;
using PLL = pair<LL, LL>;
const int mod = 1e9 + 7;
// const int mod = 998244353;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

int n, k;

inline void work() {
    cin >> n >> k;
    int ans = 0;
    for (int i = k; i <= n + 1; ++i) {
        ans = (ans + (LL)(n - i + 1) * i % mod + 1) % mod;
    }
    cout << ans << "\n";
}

int main() {
    // freopen("input.txt", "r", stdin);
    quickread();
    work();
    return 0;
}

Measured memory_bytes: 3648
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=5e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll n,v[100005]={},ans=0;
  cin >> n;
  for(ll i=0; i<n; i++) {
    cin >> v[i];
  }
  sort(v,v+n,greater<ll>());
  for(ll i=0; i<n; i++) {
    ans+=v[i]-i-1;
  }
  cout << ans << endl;
}


Measured memory_bytes: 4000
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

#define INF 1e9
#define MAXN 100005
#define MAXM 100005
#define MOD 1000000007
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pii pair<int, int>

ll ans = 0;
int D, day = 0;
vi C, S[370], T, V, cost;

int calc(){
    int res = 0;
    rep(i, 26){
        res += C[i] * (day - cost[i]); 
    }
    return res;
}

void solve(){
    rep(i, D){
        day++;
        ans += S[i][T[i]-1];
        cost[T[i]-1] = day;
        ans -= calc();
        cout << ans << endl;
    }
}

int main(){
    cin >> D;
    C.resize(26);
    T.resize(D);
    cost.resize(26, 0);
    
    rep(i, 26){
        cin >> C[i];
    }   

    rep(i, D){
        S[i].resize(26);
        rep(j, 26) cin >> S[i][j];
    }

    rep(i, D) cin >> T[i];

    solve();
}


Measured memory_bytes: 3684
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<climits>
#include<set>
#include<utility>
using namespace std;
typedef long long int ll;
 
int main(){

	ll h, w, ans, s1, s2, s3, mx, mn, tmp;
	cin >> h >> w;
	s1=h/3*w;
	s2=(2*h/3-h/3)*w;
	s3=(h-2*h/3)*w;
	mx=max(s1, s2);
	mx=max(mx, s3);
	mn=min(s1, s2);
	mn=min(mn, s3);
	ans=mx-mn;
	s1=w/3*h;
	s2=(2*w/3-w/3)*h;
	s3=(w-2*w/3)*h;
	mx=max(s1, s2);
	mx=max(mx, s3);
	mn=min(s1, s2);
	mn=min(mn, s3);
	tmp=mx-mn;
	ans=min(ans, tmp);
	
	for(int i=1; i<h; i++){
		s1=i*w;
		s2=(h-i)*(w/2);
		s3=(h-i)*((w+1)/2);
		mx=max(s1, s2);
		mx=max(mx, s3);
		mn=min(s1, s2);
		mn=min(mn, s3);
		tmp=mx-mn;
		ans=min(ans, tmp);
	}
	for(int i=1; i<w; i++){
		s1=i*h;
		s2=(w-i)*(h/2);
		s3=(w-i)*((h+1)/2);
		mx=max(s1, s2);
		mx=max(mx, s3);
		mn=min(s1, s2);
		mn=min(mn, s3);
		tmp=mx-mn;
		ans=min(ans, tmp);
	}
	cout << ans << endl;

	return 0;
}


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

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

    int ans = 1;
    for (int A = 1; A * A <= M; ++A)
    {
        if(M%A != 0)
            continue;
        int B = M / A;

        if ((long)A * N <= M)
            ans = max(ans, A);
        if ((long)B * N <= M)
            ans = max(ans, B);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
def factorial(n):
    table = [1, 1, 2, 6, 24, 120, 720, 5040]
    return table[n]

def calc_order(A, N):
    l = [i + 1 for i in range(N)]
    order = 1
    for i in range(N):
        a = A[i]
        len_l = N - i
        index = l.index(a)
        # print(a, index, factorial(len_l - 1), order)
        order += index * factorial(len_l - 1)
        del l[index]
    return order

def main():
    N = int(input())
    P = list(map(int, input().split()))
    Q = list(map(int, input().split()))
    ord_p = calc_order(P, N)
    ord_q = calc_order(Q, N)
    ans = abs(ord_p - ord_q)
    # print(ord_p, ord_q)
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9204
// https://atcoder.jp/contests/abc089/tasks/abc089_b
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    set<char> st;
    REP(i, n) {
        char t;
        cin >> t;
        st.insert(t);
    }
    cout << (st.size() == 3 ? "Three\n" : "Four\n");
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    static long MOD = 1000000007;
    public static void main(String[] args) {


        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        HashSet<Integer> set1 = new HashSet<>();
        HashSet<Integer> set2 = new HashSet<>();
        if(n%2==1)set1.add(0);

        boolean avable = true;

        for(int i=0;i<n;i++){
            int a=sc.nextInt();
            if(!set1.contains(a)){
                set1.add(a);
            }else if(!set2.contains(a)){
                set2.add(a);
            }else{
                avable = false;
            }
        }

        if(n%2==0){
            for(int i=1;i<n;i+=2){
                if(!set2.contains(i))avable=false;
            }
        }else {
            for(int i=0;i<n;i+=2){
                if(!set2.contains(i))avable=false;
            }
        }
        long ans=1;
        for(int i=0;i<n/2;i++){
            ans = (ans*2)%MOD;
        }

        if(avable)System.out.println(ans);
        else System.out.println(0);




    }
}


Measured memory_bytes: 62400
#include<bits/stdc++.h>
using namespace std;
#define eps 0
typedef struct{
	double x,y;
	
}point;

typedef struct{
point a,b;
}line;

line make_line(point a,point b){
	line res; res.a=a; res.b=b;
	return res;
}
point make(double x,double y){
	point res;
	res.x=x;
	res.y=y;
	return res;
}
//a-b
point vec(point a,point b){
	point res;
	res.x=a.x-b.x;
	res.y=a.y-b.y;
	return res;
}

// a・b
double dot(point a,point b){
	return a.x*b.x+a.y*b.y;
}
//|a|
double  norm(point a){
return sqrt(dot(a,a));
}
//|a|^2
double absolute(point a){
return dot(a,a);
}
//a×ｂ　外積z成分
double cross(point a,point b){
return a.x*b.y-a.y*b.x;
}
//a=x1+iy1,b=x2+iy2 a*b
point imaseki(point a,point b){
point res;
res.x=a.x*b.x-a.y*b.y;
res.y=a.x*b.y+a.y*b.x;
return res;
}
//vec * a
point product(point v,double a){
	point res; res.x=v.x*a; res.y=v.y*a;
	return res;
}

//共役
point conjugate(point a){
point res;
res.x=a.x;
res.y=-a.y;
return res;
}


int ccw(point p0,point p1,point p2){
point a=vec(p1,p0);
point b=vec(p2,p0);
	if(cross(a,b)>eps){
	return 1;//counter_clockwise
	}else if(cross(a,b)<eps){
	return -1;//clockwise
	}else if(dot(a,b)<-eps){
	return 2;//online_back
	}else if(absolute(a)<absolute(b)){
	return -2;//online_front
	}else{
	return 0;//on_segment
	}

}
//交差判定　s1-s2 s3-s4
bool intersect(point s1,point s2,point s3,point s4){
 if(ccw(s1,s2,s3)*ccw(s1,s2,s4)<=0 && ccw(s3,s4,s1)*ccw(s3,s4,s2)<=0)
        return true;
    return false;
}

//交点
point crosspoint(line l1,line l2){
	point veca=vec(l1.b,l1.a);
	point vecb=vec(l2.b,l2.a);
	double d= cross(veca,vecb);
	double e= cross(vecb,vec(l2.b,l1.a));
	return vec(l1.a,product(veca,e/d));

}
int main(){
	int q;
	cin>>q;
	for(int i=0;i<q;i++){
	double x,y;
	point p0,p1,p2,p3;
	cin>>x>>y;
	p0=make(x,y);
	cin>>x>>y;
	p1=make(x,y);
	cin>>x>>y;
	p2=make(x,y);
	cin>>x>>y;
	p3=make(x,y);
	line l1,l2;
	l1=make_line(p0,p1);
	l2=make_line(p2,p3);
	point ans= crosspoint(l1,l2);
//	cout<<ans.x<<' '<<ans.y<<endl;
	printf("%0.10lf %0.10lf\n",ans.x,ans.y);

	}
return 0;
}



Measured memory_bytes: 3288
#include <vector>
#include <iterator>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
typedef long long ll;
using namespace std;
typedef vector<ll> vll; typedef set<ll> sll; typedef map<ll,ll> mll;
int bitct(long long r) {int c=0; for(; r; r&=r-1) c++; return c;}
long long gcd(long long x, long long y) {return x ? gcd(y%x,x) : y;}
long long choose(long long n, long long q) { if(n==0 || q==0) return 1;
  if (q==1) return n; else return ( choose(n, q-1) * (n-q+1 ) /q); }
template<typename T> ostream& operator << (ostream &o,vector<T> v) {o<<"[";
  int i=0,s=v.size();for(;i+1<s;i++)o<<v[i]<<", ";if(s)o<<v[i];o<<"]";return o;}
template<typename K, typename V> ostream& operator << (ostream &o,
  unordered_map<K, V> m) {o<<"{";for(auto i:m)o<<i.first<<" -> "<< i.second <<
  ", "; o<<"}";return o;}
template<typename K, typename V> ostream& operator << (ostream &o, map<K, V> m)
  {o<<"{";for(auto i:m)o<<i.first<<" -> "<< i.second << ", "; o<<"}";return o;}
template<typename K> ostream& operator << (ostream &o, set<K> m)
  {o<<"{";for(auto i:m)o<<i<< ", "; o<<"}";return o;}
template<typename K> ostream& operator << (ostream &o, unordered_set<K> m)
  {o<<"{";for(auto i:m)o<<i<< ", "; o<<"}";return o;}
template<typename T> ostream& printv(vector<T> v) {int i=0,s=v.size();
  for(;i+1<s;i++)cout<<v[i]<<" ";if(s)cout<<v[i];return cout;}

int main() {
  ios_base::sync_with_stdio(false);
  ll N , M;
  cin >> N >> M;
  vector<vector<ll> > E(N);
  for(int i=0;i<M;i++) {
    ll x, y;
    cin >> x >> y;

    x--, y--;
    E[x].push_back(y);
    E[y].push_back(x);
  }

  vector<bool> odd(N, false), even(N, false);
  ll o=0,e=0;
  vector<ll> Q;
  vector<ll> Qs;
  Q.push_back(0);
  Qs.push_back(0);
  ll idx=0;
  bool comp=false;
  while(idx<Q.size()) {
    ll mes=Qs[idx];
    ll me=Q[idx++];


    if(mes%2==1 && even[me] || mes%2==0 && odd[me]) {
      comp=true;
      break;
    }
    if(odd[me] || even[me])
      continue;
    if(mes%2==1) {
      odd[me]=true;
      o++;
    }
    if(mes%2==0) {
      even[me]=true;
      e++;
    }
    for(ll n:E[me]) {
      Q.push_back(n);
      Qs.push_back(mes+1);
    }
  }

  if(comp)
    cout << N*(N-1)/2 - M << endl;
  else
    cout << N*(N-1)/2 - M - o*(o-1)/2 - e*(e-1)/2 << endl;
}

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

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

  vector<int> c = {25, 10, 5, 1};
  int ans = 0;
  for (int i = 0; i < 4; i ++) {
    int a = n / c[i];
    int b = n % c[i];
    ans += a;
    n -= a * c[i];
  }

  cout << ans << endl;
}



Measured memory_bytes: 3124
# coding: utf-8
# Your code here!

class Node:
    def __init__(self, id):
        self.id = id
        self.parent = None
        self.left = None
        self.right = None

class BinaryTree:
    def __init__(self):
        self.root = None
        
    def insert(self, node, parent=None):
        if self.root is None:
            self.root = node
            return
        
        if parent is None:
            parent = self.root
            
        if node.id < parent.id:
            if parent.left:
                self.insert(node, parent.left)
            else:
                parent.left = node
                node.parent = parent
        else:
            if parent.right:
                self.insert(node, parent.right)
            else:
                parent.right = node
                node.parent = parent
    
    def walk_inorder(self, result, current_node=None):
        if current_node is None:
            current_node = self.root
        
        if current_node.left:
            self.walk_inorder(result, current_node.left)
            
        result.append(current_node.id)
        
        if current_node.right:
            self.walk_inorder(result, current_node.right)
    
    def walk_preorder(self, result, current_node=None):
        if current_node is None:
            current_node = self.root
        
        result.append(current_node.id)
        
        if current_node.left:
            self.walk_preorder(result, current_node.left)
            
        if current_node.right:
            self.walk_preorder(result, current_node.right)

    def find_node(self, id, current_node=None):
        if current_node is None:
            current_node = self.root
            
        if current_node.id == id:
            return True
        if id < current_node.id:
            if current_node.left and self.find_node(id, current_node.left):
                return True
        else:
            if current_node.right and self.find_node(id, current_node.right):
                return True
        return False

def main():
    n = int(input())
    tree = BinaryTree()
    
    for _ in range(n):
        cmd = input()
        if cmd[0] == 'p':
            result = []
            tree.walk_inorder(result)
            print('', *result)
            
            result = []
            tree.walk_preorder(result)
            print('', *result)
        elif cmd[0] == 'i':
            id = int(cmd.split()[1])
            node = Node(id)
            tree.insert(node)
        elif cmd[0] == 'f':
            id = int(cmd.split()[1])
            if tree.find_node(id):
                print('yes')
            else:
                print('no')

if __name__=='__main__':
    main()


Measured memory_bytes: 94428
import java.util.*;
import java.io.*;

public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();   
        int m = sc.nextInt();   
        int[] h = new int[n];
        int a;
        int b;
        int[] good = new int[n];
        for (int i = 0; i < n; i++) {
            good[i] = 0;
        }
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }
        for (int i = 0; i < m; i++) {
            a = sc.nextInt();
            b = sc.nextInt();
            a--; b--;
            if (h[a] < h[b]) {
                good[a] = -1;
            } else if (h[a] > h[b]) {
                good[b] = -1;
            } else if (h[a] == h[b]) {
                good[a] = -1;
                good[b] = -1;
            }
        }
        int res = 0;
        for (int i = 0; i < n; i++) {
            if (good[i] == 0) res++;
        }
        System.out.println(res);   
    }
}

Measured memory_bytes: 52020
#include <cstdio>

int ch[2][1<<22], id[22][1<<21], cnt;
void get() {
	id[0][0] = (cnt++), ch[0][id[0][0]] = ch[1][id[0][0]] = -1;
	for(int i=1;i<=20;i++) {
		int t = (1 << i), k = (t >> 1);
		for(int s=0;s<t;s++) {
			id[i][s] = (cnt++);
			int p = (s & k), q = (p ? 1 : 0);
			ch[q][id[i][s]] = id[i-1][s^p];
			ch[!q][id[i][s]] = ch[!q][id[i-1][s^p]];
		}
	}
}

int a[22][1<<22], siz[22], c[22][1<<22], num[22][1<<22];

int ans[22], N, K;
void dfs(int d, int s) {
	if( ans[d] == -1 ) ans[d] = s;
	for(int p=0;p<=1;p++) {
		int tot = 0;
		for(int i=0;i<siz[d];i++) {
			int to = ch[p][a[d][i]];
			if( to == -1 ) continue;
			if( num[d + 1][to] == -1 )
				num[d + 1][a[d + 1][siz[d + 1]] = to] = siz[d + 1], siz[d + 1]++;
			tot += c[d][i], c[d + 1][num[d + 1][to]] += c[d][i];
		}
		if( tot >= K ) dfs(d + 1, (s << 1) | p);
		for(int i=0;i<siz[d + 1];i++)
			num[d + 1][a[d + 1][i]] = -1, c[d + 1][i] = 0;
		siz[d + 1] = 0;
	}
}

char s[1<<21];
int main() {
	scanf("%d%d", &N, &K), get();
	for(int i=0;i<=N;i++)
		for(int j=0;j<cnt;j++)
			num[i][j] = -1;
	for(int i=0;i<=N;i++) {
		scanf("%s", s);
		int t = (1 << i);
		for(int j=0;j<t;j++) {
			if( s[j] == '1' )
				num[0][a[0][siz[0]] = id[i][j]] = siz[0], c[0][num[0][id[i][j]]]++, siz[0]++;
		}
		ans[i] = -1;
	}
	dfs(0, 0);
	for(int i=N;i>=0;i--) {
		if( ans[i] != -1 ) {
			for(int j=i-1;j>=0;j--)
				putchar(((ans[i] >> j) & 1) + '0');
			puts(""); return 0;
		}
	}
}

Measured memory_bytes: 388224
#include<stdio.h>
int main(){
    int N;
    char s[101];
    char t[101];
    scanf("%d",&N);
    scanf("%s %s",s,t);
    for(int i=0;i<N;i++){
        printf("%c%c",s[i],t[i]);
    }
    printf("\n");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REPR(i,n) for (int i=(int)(n)-1;i>=0;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
#define tpl(...) make_tuple(__VA_ARGS__)
const int INF = 0x3f3f3f3f;
const double EPS = 1e-8;
const double PI = acos(-1);
const int dy[] = {-1,0,1,0};
const int dx[] = {0,1,0,-1};
typedef long long ll;
typedef pair<int,int> pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename Ch,typename Tr,typename C,typename=decltype(begin(C()))>basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>&os,
const C& c){os<<'[';for(auto i=begin(c);i!=end(c);++i)os<<(i==begin(c)?"":" ")<<*i;return os<<']';}
template<class S,class T>ostream&operator<<(ostream &o,const pair<S,T>&t){return o<<'('<<t.first<<','<<t.second<<')';}
template<int N,class Tp>void output(ostream&,const Tp&){}
template<int N,class Tp,class,class ...Ts>void output(ostream &o,const Tp&t){if(N)o<<',';o<<get<N>(t);output<N+1,Tp,Ts...>(o,t);}
template<class ...Ts>ostream&operator<<(ostream&o,const tuple<Ts...>&t){o<<'(';output<0,tuple<Ts...>,Ts...>(o,t);return o<<')';}
template<class T>void output(T t,char z=10){if(t<0)t=-t,putchar(45);int c[20];
int k=0;while(t)c[k++]=t%10,t/=10;for(k||(c[k++]=0);k;)putchar(c[--k]^48);putchar(z);}
template<class T>void outputs(T t){output(t);}
template<class S,class ...T>void outputs(S a,T...t){output(a,32);outputs(t...);}
template<class T>void output(T *a,int n){REP(i,n)cout<<a[i]<<(i!=n-1?',':'\n');}
template<class T>void output(T *a,int n,int m){REP(i,n)output(a[i],m);}
template<class T>bool input(T &t){int n=1,c;for(t=0;!isdigit(c=getchar())&&~c&&c-45;);
if(!~c)return 0;for(c-45&&(n=0,t=c^48);isdigit(c=getchar());)t=10*t+c-48;t=n?-t:t;return 1;}
template<class S,class ...T>bool input(S&a,T&...t){input(a);return input(t...);}
template<class T>bool inputs(T *a, int n) { REP(i,n) if(!input(a[i])) return 0; return 1;}

int main() {
  int a, b;
  while(cin>>a>>b){
    int t = 0;
    if (a >= 13) t = b;
    else if (a >= 6) t = b / 2;
    cout << t << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

signed main() {
  init();
  ll A, B;
  cin >> A >> B;

  rep(i, 4) {
    if (i == 0) {
      continue;
    }
    if ((A * B * i) % 2 == 1) {
      COUT("Yes");
      return 0;
    }
  }
  COUT("No");
  return 0;
}

Measured memory_bytes: 256