akhauriyash/Code-Regression huggingface dataset:
#include <math.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i,j,n) for(int i = (int)(j); i < (int)(n); i++)
#define mrep(i,n) for (int i = (int)(n-1); i > 0; i--)
#define be(v) (v).begin(), (v).end()
#define scout cout << fixed << setprecision(20) 
#define fi first
#define se second
ll INF = 1LL << 60;
ll mod = 1e9 + 7;
ll MAX=1e18;

int main() {
	int n; cin >> n;
	vint a(n);
	rep(i,n) cin >> a[i];
	sort(be(a));
	cout << a[n-1]-a[0] << endl;
}

Measured memory_bytes: 3604
#include<stdio.h>
int main(void){
  int a[3];
  int i, ans=0;
  for(i=0;i<3;i++){
    scanf("%1d", &a[i]);
    if(a[i]==1){
      ans++;
    }
  }
  printf("%d\n", ans);
  return 0;
 }

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
struct mice{
	double R,Y,B;
};
int n,m;
double ans;
mice  q[100];
mice cr[100];
void check()
{
	double sum=0;
	int i,j;
	for(i=0;i<m;i++)
		for(j=i+1;j<m;j++)
		{
			sum+=(q[i].R-q[j].R)*(q[i].R-q[j].R)+(q[i].B-q[j].B)*(q[i].B-q[j].B)+(q[i].Y-q[j].Y)*(q[i].Y-q[j].Y);
		}
	if(sum-ans>0)
		ans=sum;
}
void dfs(int num,int k)
{
	if(k==n)
		return ;
	q[num]=cr[k];
	if(num+1==m)
	{
		check();
	}
	if(num+1!=m)
		dfs(num+1,k+1);
	dfs(num,k+1);
}

int main()
{
	int i,j;
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		for(i=0;i<n;i++)
			scanf("%lf%lf%lf",&cr[i].B,&cr[i].R,&cr[i].Y);
		ans=0;
		dfs(0,0);
		printf("%.10lf\n",ans);
	}
}

Measured memory_bytes: 1260
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product, combinations_with_replacement
import sys
import bisect
import string
import math
import time


def I(): return int(input())
def S(): return input()
def MI(): return map(int, input().split())
def MS(): return map(str, input().split())
def LI(): return [int(i) for i in input().split()]
def LI_(): return [int(i)-1 for i in input().split()]
def StoI(): return [ord(i)-97 for i in input()]
def ItoS(nn): return chr(nn+97)
def input(): return sys.stdin.readline().rstrip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def print_matrix(mat):
    for i in range(len(mat)):
        print(*['IINF' if v == IINF else "{:0=4}".format(v) for v in mat[i]])


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
show_flg = False
# show_flg = True


def main():
    N = I()

    if N % 1000 == 0:
        print(0)
    else:
        cur = 1000
        while cur <= N:
            cur += 1000
        print(cur - N)


if __name__ == '__main__':
    main()


Measured memory_bytes: 68316
#include<bits/stdc++.h>
#include<vector>
#include<deque>
#include<list>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000000000000001;
struct edge{int to,cost;};
struct pos{
	int x,y,cost;
	double ma=0;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

int main() {

	int f;
	cin>>f;
	cout<<(f-30)/2<<endl;

	return 0;
}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define endl "\n"
    #define int long long int
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define f first
    #define s second

    using namespace std;
int power(int base, int exp)
{
    if (exp == 0)
       return 1;
    else if (exp == 1)
       return base;
    else
    {
       int calc;
       if (exp % 2 == 0)
       {
         calc = power(base, exp/2);
         calc =(calc* calc)%mod;
       }
       else
       {
         calc = (base*power(base, exp-1))%mod;
       }
       return calc%mod;
    }
}
    int32_t main()
    {
        std::ios::sync_with_stdio(false);
        int n,m;
        cin>>n>>m;
        int a[n];
        for(int i=0;i<n;i++)
            cin>>a[i];

        sort(a,a+n);
        int res=0;
        for(int i=0;i<m;i++)
            res+=a[i];

            cout<<res<<endl;
        return 0;
    }


Measured memory_bytes: 3660
#include <iostream>//数据输入输出流
#include <cstring>//字符串操作函数
#include <cstdio>//C的输入输出
#include <cstdlib>//定义杂项函数及内存分配函数
#include <cmath>//C中的数学函数
#include <string>//c++中的string类 他不能用strcpy等c函数去操作
#include <vector>//STL vetor
#include <list>//STL list
#include <map>// STL map
#include <queue>// STL queue
#include <stack>//sTL stack
#include <bitset>//bitset可按位定义串
//比如：bitset <1000> all;定义一个1000位的串
#include <algorithm>//STL各种算法 比如 swap sort merge max min 比较
#include <numeric>//常用数字操作 一般和algorithm搭配使用
#include <functional>//STL定义运算函数（代替运算符）
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
#define LOCAL
#define zeros(a,n) memset(a,0,(n)*sizeof(a[0]))
const int modn = 1e9+7;
int mod(int x) { return x<0?x+modn:x<modn?x:x-modn; }
//inv [ i ] = (modn - modn/i)*inv[ modn%i ] %modn;
int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    int n, k;
    cin>> n >> k;
    if(k == n + 1) cout << 1 << endl;
    else{
        LL ans = 1;
        vector<LL> a(n+1);
        a[0] = 0;
        for(int i = 1; i <= n; ++i) a[i] = a[i-1] + i;
        for(int i = k; i <= n; ++i){
            //cout << k<< " " << a[n] - a[n-k] << " " << a[i-1] << endl;
            ans = ((a[n] - a[n-i] - a[i-1] + 1 + ans) % modn + modn) % modn;
        }
        cout << ans << "\n";
    }
    return 0;
}



Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    int n, m;
    cin >> n >> m;
    vector<ll> a(n), b(n);
    rep(i, n) cin >> a[i] >> b[i];
    vector<ll> c(m), d(m);
    rep(i, m) cin >> c[i] >> d[i];
    
    rep(i, n) {
        ll best = 1e12;
        int idx = 0;
        rep(j, m) {
            ll dist = abs(c[j] - a[i]) + abs(d[j] - b[i]);
            if (best > dist) {
                best = dist;
                idx = j;
            }
        }
        put(idx + 1);
    }
    
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define int long long 

const int MOD = 1e9+7;

int p(int n, int a){ //nのa乗
  if( a == 0 ){ return 1LL;}
  else if( a == 1 ){ return n;}
  else{
    if( a % 2 == 0 ){ return (p(n,a/2)*p(n,a/2))%MOD;}
    else{ return (((p(n,(a-1)/2)*p(n,(a-1)/2))%MOD)*n)%MOD;}
    
  }
  
}

int cal(int n, int a){
  
  int up = 1LL; int down = 1LL;
  
  for(int i = n-a+1; i <= n; i++){ 
    up *= i; up %= MOD;
  }
  
  for(int i = 1; i <= a; i++){ 
    down *= i; down %= MOD;
  }
  
  down = p(down,MOD-2);
  
  return (up*down)%MOD;
}


signed main(void){
  int n,a,b; cin >> n >> a >> b;
  
  int res = p(2,n)-1-cal(n,a)-cal(n,b);
  
  cout << (res+MOD*MOD)%MOD << endl;
  
  return 0;
}
    

Measured memory_bytes: 764
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    void solve() {
        int N, D;
        cin >> N >> D;
        int a = N;
        int b = 2 * D + 1;
        int ans = a / b + !!(a % b);
        cout << ans << endl;
    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
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;}
// void solve(){
// }
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	bool ans=false;
	if(a==b && a!=c) ans=true;
	if(a==c && a!=b) ans=true;
	if(b==c && a!=b) ans=true;
	ote(ans?"Yes":"No");
	// cout<< solve() <<endl;
	// printf("%f\n",solve());
}


Measured memory_bytes: 256
N,M = map(int,input().split())
A=[input()for _ in range(N)]
B=[input()for _ in range(M)]
print('Yes'if any([A[i+k][j:j+M]for k in range(M)]==B for i in range(N-M+1)for j in range(N-M+1)) else'No')


Measured memory_bytes: 70320
s = input().rstrip().split(' ')
a = int(s[0])
b = int(s[1])
c = int(s[2])
if a > b:
	a,b = b,a
if b > c:
	b,c = c,b
if a > b:
	a,b = b,a
print(str(a) + " " + str(b) + " " + str(c))

Measured memory_bytes: 7580
using System;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        string[] inputs = Console.ReadLine().Split(' ');
        int k = int.Parse(inputs[0]);
        int x = int.Parse(inputs[1]);

        List<int> nums = new List<int>();

        nums.Add(x);

        for(int i = 1; i<k; i++)
        {
            nums.Add(x + i);
            nums.Add(x - i);
        }
        nums.Sort();

        string tmp = "";
        foreach(int i in nums)
        {
            tmp += i.ToString();
            tmp += " ";
        }

        Console.WriteLine(tmp);


    }



}



Measured memory_bytes: 13268
import sys
input = sys.stdin.readline

O = list(input().rstrip('\n'))
E = list(input().rstrip('\n'))
n = len(O) + len(E)
A = []

for i in range(n):
    if i % 2 == 0:
        A.append(O[i//2])
    else:
        A.append(E[i//2])
ans = "".join(A)
print(ans)


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

typedef long long ll;


int d[200];
bool table[200][200];

void init(){
    for(int i=0;i<200;i++){
        d[i]=-1;
        for(int j=0;j<200;j++){
            table[i][j]=false;
        }
    }
}

void bfs(int itr, int dis, int n){
    d[itr] = dis;
    for(int i=0;i<n;i++){
        if(table[itr][i]&&(d[i]<0||d[i]>dis+1)){
            bfs(i, dis+1,n);
        }
    }
}

void solve(int n){
    bfs(0,0,n);
}

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

    init();
    int n;
    cin >> n;
    int u,k,v;
    for(int i=0;i<n;i++){
        cin >> u >> k;
        for(int j=0;j<k;j++){
            cin >> v;
            table[u-1][v-1]=true;
        }
    }

    solve(n);

    for(int i=0;i<n;i++){
        cout << i+1 << " " << d[i] << endl;
    }

    return 0;
}



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

using namespace std;
using ll = long long;

int main() {
	int mp[13][1005] = {};
	int h, w, k;
	cin >> h >> w >> k;
	rep(i, h) rep(j, w) scanf("%1d", &mp[i+1][j+1]);
	rep(i, h - 1) rep(j, w) mp[i + 2][j+1] += mp[i+1][j+1];
	rep(j, w - 1) rep(i, h) mp[i+1][j + 2] += mp[i+1][j+1];
	int ans = 1e9;

	for (int i = 0; i < (1 << (h - 1)); i++) {
		int cut = 0;
		rep(x, h - 1) if (i >> x & 1) cut++;
		int afterH = 0;
		int afterW = 0;
		bool small = true;
		int now = 1;
		while (now <= w) {
			int c;
			afterH = 0;
			small = true;
			for (int b = 0; b < (h - 1); b++) {
				if (i >> b & 1) {
	c = mp[b+1][now] - mp[b+1][afterW] - mp[afterH][now] + mp[afterH][afterW];
					if (c > k) small = false;
					afterH = b + 1;
				}
			}
	c = mp[h][now] - mp[h][afterW] - mp[afterH][now] + mp[afterH][afterW];
			if (c > k) small = false;
			if (small == false) {
				if (afterW == now - 1) {
					cut = 1e9;
					now++;
				}
				cut++;
				afterW = now - 1;
				now--;
			}
			now++;
		}
		ans = min(ans, cut);
	}
	cout << ans << endl;
	return 0;
}
//......mp[ah][aw] ..............mp[ah][now]


//......mp[b+1][aw]..............mp[b+1][now]












Measured memory_bytes: 3732
while true
a,op,b = gets.split(" ")
a = a.to_i
b = b.to_i
  case op
  when "+" then
    puts a + b
  when "-" then
    puts a - b
  when "*" then
    puts a * b
  when "/" then
    puts a / b
  else
    break
  end
end

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

using namespace std;

int main()
{
	int n;
	string title[1000];
	int time[1000];
	string x;

	cin >> n;

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

	int sum = 0;
	bool flag = false;
	for (int i = 0; i < n; i++)
	{
		if (flag)
		{
			sum += time[i];
		}
		if (title[i] == x)
		{
			flag = true;
		}
		
	}
	cout << sum << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define elif else if
#define INF 1000000007
using namespace std;
int a,b=0,aa[110000],ab[110000],cnt=0;
double d;
string s,ss;
signed main()
{
	cin>>a;
	rep(i,(a+1)/2){
		rep(j,i*2+1){
			if((i*2+1)%(j+1)==0){
				b++;
			}
		}
		if(b==8){
			cnt++;
		}
		b=0;
	}
	cout<<cnt;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"io"
	"os"
	"sort"
)

func proc(r io.Reader, w io.Writer) {
	var n, d int
	fmt.Fscanf(r, "%d", &n)
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(r, "%d", &d)
		arr[i] = d
	}
	sort.Sort(sort.Reverse(sort.IntSlice(arr)))

	var alice, bob int
	for i := 0; i < n; i++ {
		if i%2 == 0 {
			alice += arr[i]
		} else {
			bob += arr[i]
		}
	}
	res := alice - bob

	fmt.Fprintf(w, "%d", res)
}

func main() {
	proc(os.Stdin, os.Stdout)
}


Measured memory_bytes: 512
#include<algorithm>
#include<cstring>
#include<cctype>
#include<cstdio>
#define rep(i,x,y) for(int i=x; i<=y; ++i)
#define mid (l+r>>1)

using namespace std;
const int N=100005;
int n,poola[N],poolb[N],a[N],b[N],jdga,jdgb,tot,ans,f[N+N];
struct data{int a,b;} dat[N];

int getint()
{
	char ch;
	while(!isdigit(ch=getchar()));
	int x=ch-48;
	while(isdigit(ch=getchar())) x=x*10+ch-48;
	return x;
}

int find(int x)
{
	int l=0,r=n;
	while(l<=r)
		poola[mid]<=x?l=mid+1:r=mid-1;
	return l;
}

int getfa(int x)
{
	return f[x]==x?x:f[x]=getfa(f[x]);
}

void merge(int x,int y)
{
	x=getfa(x),y=getfa(y);
	if(x!=y) f[x]=y;
}

int query()
{
	rep(i,1,n) if(a[i]!=b[i]) dat[++tot]=(data){a[i],b[i]};
	dat[++tot]=(data){jdga,jdgb};
	rep(i,1,tot) dat[i].a=find(dat[i].a),dat[i].b=find(dat[i].b);
	rep(i,1,tot+n+1) f[i]=i;
	rep(i,1,tot) merge(i,dat[i].a+tot),merge(i,dat[i].b+tot);
	rep(i,1,tot) if(f[i]==i) ++ans;
	rep(i,1,tot) poola[i]=dat[i].a;
	sort(poola+1,poola+1+tot);
	rep(i,1,tot) if(i==1 || poola[i]!=poola[i-1]) if(f[tot+poola[i]]==tot+poola[i]) ++ans;
	return tot+ans-2;
}

int main()
{
	n=getint();
	rep(i,1,n) poola[i]=a[i]=getint(),jdga^=a[i];
	rep(i,1,n) poolb[i]=b[i]=getint(),jdgb^=b[i];
	poola[0]=jdga,poolb[0]=jdgb;
	sort(poola,poola+1+n),sort(poolb,poolb+1+n);
	rep(i,0,n) if(poola[i]!=poolb[i]) {puts("-1"); return 0;}
	printf("%d\n",query());
	return 0;
}

Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


signed main() {
    int n, k;
    cin >> n >> k;
    vi A(n), F(n);
    rep(i, n) cin >> A[i];
    rep(i, n) cin >> F[i];

    SORT(A); GSORT(F);
   
    int low=-1, high=5e18, mid;

    //全員の完食にかかる時間をt秒以下にできるかを二分探索によって求める
    while(high-low>1) {

        //mid秒を基準に比較する
        mid = (low+high)/2;

        //全員がmid秒以下で完食するための修行コストをtempに保存する
        int temp = 0;

        rep(i, n) {
            //mid秒以下で完食できるように修行する
            if(A[i]*F[i] > mid) {
                temp += A[i] - mid/F[i];
            }
        }

        //修行コストがオーバーする場合、答えはmidより大きい
        //そうでない場合、答えはmidより更に小さくできる
        if(temp > k) low = mid;
        else high = mid;
    }

    //二分探索の終了時、条件を満たしているのはhighの値であることに注意する
    cout << high << endl;
    
    return 0;
}

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

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	char a,b,c;
	cin>>a>>b>>c;
	if(a=='R' and b=='R' and c=='R')
		cout<<3<<endl;
	else if((a=='R' and b=='R') or (b=='R' and c=='R'))
		cout<<2<<endl;
	else if(a=='R' or b=='R' or c=='R')
		cout<<1<<endl;
	else
		cout<<0<<endl;
	return 0;
}

Measured memory_bytes: 3608
import java.util.Arrays;
import java.util.Scanner;
        
        public class Main {
        	public static void main(String[] args) {
        		Scanner in = new Scanner(System.in);
        		int N = in.nextInt();
        		int K = in.nextInt();
        		int [] p = new int [N];
        		int total = 0;
        		
        		for(int i=0;i<N;i++) {
        			p[i] = in.nextInt();
        		}
        		
        		Arrays.sort(p);
        		
        		for(int i=0;i<K;i++) {
        			total+=p[i];
        		}
        		
        		System.out.println(total);
        		
        	}
        }

Measured memory_bytes: 38372
#include <stdio.h>
#include <stdlib.h>


typedef struct{
  int parent;
  int cnum;
  int child[2];
} Node;

void alr(int);
void lar(int);
void lra(int);

Node A[100000];

int main(){
  int n;
  int N;
  int num;
  int i,j;
  int root;
  
  
  
  scanf("%d",&n);
  for(i=0;i<n;i++) A[i].parent=-1;
  for(i=0;i<n;i++){
    scanf("%d",&num);
    A[num].cnum=0;
    for(j=0;j<2;j++){
      scanf("%d",&A[num].child[j]);
      if(A[num].child[j]!=-1){
        A[A[num].child[j]].parent=num;
        A[num].cnum++;
      }
    }
  }
  for(i=0;i<n;i++){
    if(A[i].parent==-1){
       root=i;
       break;
    }
  }
  printf("Preorder\n");
  alr(root);
  printf("\n");
  printf("Inorder\n");
  lar(root);
  printf("\n");
  printf("Postorder\n");
  lra(root);
  printf("\n");

  return 0;
}

void alr(int i){
  if(A[i].cnum==0){
     printf(" %d",i);
     return;
  }
  printf(" %d",i);
  if(A[i].child[0]!=-1) alr(A[i].child[0]);
  if(A[i].child[1]!=-1) alr(A[i].child[1]);
  return;
} 

void lar(int i){
  if(A[i].cnum==0){
     printf(" %d",i);
     return;
  }
  if(A[i].child[0]!=-1) lar(A[i].child[0]);
  printf(" %d",i);  
  if(A[i].child[1]!=-1) lar(A[i].child[1]);
  return;
}

void lra(int i){
  if(A[i].cnum==0){
     printf(" %d",i);
     return;
  }
  if(A[i].child[0]!=-1) lra(A[i].child[0]);
  if(A[i].child[1]!=-1) lra(A[i].child[1]);
  printf(" %d",i);
  return;
}



Measured memory_bytes: 2076
#include <bits/stdc++.h>
#define ll long long
#define REV(v) reverse(v.begin(), v.end());
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, start, stop) for (ll i = start; i < stop; i++)
#define FORR(i, start, stop) for (ll i = start; i > stop; i--)
#define SORT(v, n) sort(v, v + n);
#define SORTR(v, n) sort(v, v + n,greater<ll>());
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.begin(), v.end(),greater<ll>());
#define REMOVE(v,n) remove(vector<ll> v,v+v.size(),ll n)
#define ERASE(v,n) v.erase(v.begin()+n);
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 999999999
#define V(v,i,j) vector(v.begin() + i, v.begin() + j)
#define INSERT(va,vb) va.insert(va.end(), vb.begin(), vb.end())
using namespace std;
typedef vector<ll> vll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
const int MOD = 1000000007;
void chmin(int &a, int b) { if (a > b) a = b; }

//vector< vector<int> > v (size1, vector<int>(size2) );



int main(){
    string al="abcdefghijklmnopqrstuvwxyz";
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll H,W,A,B;
    cin>>H>>W>>A>>B;
    string row="";
    string not_row="";
    FOR(i,0,A){
        row+='1';
        not_row+='0';
    }
    FOR(i,0,W-A){
        row+='0';
        not_row+='1';
    }
    FOR(i,0,B){
        cout<<row<<endl;
    }
    FOR(i,0,H-B){
        cout<<not_row<<endl;
    }
    
}


Measured memory_bytes: 1280
using System;
using System.Collections.Generic;
using System.Linq;
 
namespace at
{
    class Program
    {
        static void Main(string[] args)
        {
            var str = Console.ReadLine().Split(' ');
            var ab = int.Parse(str[0])*int.Parse(str[1]);

            for (int i = 1; i <= 3; i++)
            {
                if((ab*i)%2 == 1)
                {
                    Console.WriteLine("Yes");
                    return;
                }
            }
            Console.WriteLine("No");
        }
    }
}


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

#define ll long long
#define ar array

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

    int x;
    cin >> x;
    int y=x/500, z=x%500;
    cout << 1000*y+z/5*5;
}

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

int main() {
    int N;
    cin >> N;
    vector<ll> L(N);
    for (int i=0; i<N; i++) {
        cin >> L[i];
    }

    int count = 0;
    for (int i=0; i<N-2; i++) {
        for (int j=i+1; j<N-1; j++) {
            for (int k=j+1; k<N; k++) {
                if (L[i]!=L[j] and L[j]!=L[k] and L[k]!=L[i]) {
                    if (L[i]+L[j]>L[k] and L[j]+L[k]>L[i] and L[k]+L[i]>L[j]) {
                        count++;
                    }
                }
            }
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define sz(x) ((int) (x).size())
#define forn(i,n) for (int i = 0; i < int(n); ++i)
typedef long long ll;
typedef long long i64;
typedef long double ld;
const int inf = int(1e9) + int(1e5);
const ll infl = ll(2e18) + ll(1e10);

struct pt {
    ld x, y;

    pt operator+(const pt &p) const {
        return pt{x + p.x, y + p.y};
    }

    pt operator*(ld a) const {
        return pt{x * a, y * a};
    }

    pt operator-(const pt &p) const {
        return pt{x - p.x, y - p.y};
    }

    ld operator%(const pt &p) const {
        return x * p.y - y * p.x;
    }

    ld abs() const {
        return hypotl(x, y);
    }

    void norm() {
        ld d = abs();
        x /= d, y /= d;
    }

    pt rot() const {
        return pt{-y, x};
    }
};

pt p[6];

pt intersect(pt a, pt b, pt c, pt d) {
    ld s = (b - a) % (d - c);
    ld s1 = (c - a) % (d - a);
    return a + (b - a) * (s1 / s);
}

ld sdist(pt x, pt a, pt b) {
    return (b - a) % (x - a) / (b - a).abs();
}

const ld eps = 1e-9;
bool check(ld r) {
    forn (q, 3)
        p[q + 3] = p[q];
    pt x[3];
    forn (q, 3) {
        pt A = p[q], B = p[q + 1];
        pt v = (B - A).rot();
        v.norm();
        v = v * r;
        A = A + v;
        B = B + v;

        pt C = p[q + 2], D = p[q];
        v = (D - C).rot();
        v.norm();
        v = v * r;
        C = C + v;
        D = D + v;

        x[q] = intersect(A, B, C, D);
    }
    forn (q, 3) {
        pt A = x[q];
        pt B = x[(q + 1) % 3];
        if ((A - B).abs() < 2 * r)
            continue;
        bool shit = false;
        forn (c, 3) {
            ld d = sdist(A, p[c], p[c + 1]);
            if (d - r < -eps)
                shit = true;
            d = sdist(B, p[c], p[c + 1]);
            if (d - r < -eps)
                shit = true;
        }
        if (!shit)
            return true;
    }
    return false;
}

int main() {
    #ifdef LOCAL
    assert(freopen("b.in", "r", stdin));
    #else
    #endif
    forn (i, 3) {
        cin >> p[i].x >> p[i].y;
    }
    if ((p[1] - p[0]) % (p[2] - p[0]) < 0)
        swap(p[1], p[2]);
    ld L = 0, R = 1e4;
    forn (iter, 100) {
        ld r = (L + R) / 2;
        if (check(r))
            L = r;
        else
            R = r;
    }
    cout.precision(20);
    cout << fixed;
    cout << (L + R) / 2 << '\n';
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define all(X) X.begin(), X.end()
//for(int i = 0; i < n; i++)
using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int n; cin >> n;
    string s; cin >> s;
    int red = 0, white = 0, ans= 0;
    int i = 0, j = n -1;
    while(i <= j)
    {
        if(s[i] == 'W')
        {
            white++;
        }
        if(s[i] == 'R' && white)
        {
            while(white && i <= j)
            {
                if(s[j] == 'R')
                {
                    white--;
                    ans++;
                }

                j--;
            }
        }
        i++;
    }
    cout << ans;


}


Measured memory_bytes: 3740
#include <iostream>

char S[101], T[101], A[201];

int main()
{
  std::cin >> S >> T;

  int i = 0;
  int t = 0;
  while (T[t] != '\0')
  {
    A[i++] = T[t++];
  }

  int s = 0;
  while (S[s] != '\0')
  {
    A[i++] = S[s++];
  }

  A[i] = '\0';

  std::cout << A << std::endl;

  return 0;
}


Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {
    static final int MOD = 1000000007;
    static final int INF = 1 << 30;

    Main() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int max = 0;
        int min = INF;
        for(int i=0;i<N;i++){
            int num = sc.nextInt();
            max = Math.max(max,num);
            min = Math.min(min,num);
        }
        System.out.println(max-min);
    }

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


Measured memory_bytes: 23380
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

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

long long comb(ll n, ll r) {
  if(r > n - r) r = n - r; // because C(n, r) == C(n, n - r)
  long long ans = 1;

  for(int i = 1; i <= r; i++) {
    ans *= n - r + i;
    ans /= i;
  }

  return ans;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  string s;
  cin >> s;

  ll res = 0;
  for (int i = 0; i < 1000; i++) {
    string tmp = to_string(i);
    if(i < 10) tmp = "00" + tmp;
    else if(i < 100) tmp = "0" + tmp;

    int j = 0;
    for (int k = 0; k < n; k++) {
      if(tmp[j] == s[k]) j++;
      if(j == 3){
        res++;
        break;
      }
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using ll = long long int;
using vec = vector<int>;
using P = pair<int,int>;
const int INF = 1e9+7;

int main() {
  int l, r, d; cin >> l >> r >> d;

  cout << r/d - (l-1)/d << endl;
}


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

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

using namespace std;
using ll = long long;

int main(void) {
  int n;
  cin >> n;
  vector<int> sec(n+1);
  vector<pair<int, int>> vec(n+1);
  bool f = true;
  rep(i, n) {
    cin >> sec[i+1] >> vec[i+1].first >> vec[i+1].second; 
    if (sec[i+1] % 2 != (vec[i+1].first + vec[i+1].second) % 2) {
      f = false;
    }
  }
  if (not f) {
    cout << "No" << endl;
    return 0;
  }
  rep(i, n) {
    if (sec[i+1] - sec[i] < abs(vec[i].first - vec[i+1].first) + abs(vec[i].second - vec[i+1].second)) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}



Measured memory_bytes: 1408
cards = [[0 for i in range(13)] for j in range(4)]

pattern = ["S", "H", "C", "D"]

n = int(input())

ch_list=[]
rank_list_0=[]
while n > 0:
  ch, rank = input().split()
  ch_list.append(ch)
  rank_list_0.append(rank)
  n = n - 1

rank_list = [int(rank_list) for rank_list in rank_list_0]

for (chlist, ranklist) in zip(ch_list,rank_list):
      cards[pattern.index(chlist)][ranklist-1] = 1
      
for i in range(0, 4):
  for j in range(0, 13):
    if cards[i][j] == 0:
        print(pattern[i], j+1)


Measured memory_bytes: 5608
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

#define ANS(f) if(f) cout << "YES" << endl; else cout << "NO" << endl;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }
void debug(mat m){REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl; }}

int modpow(int x, int n, int m){
    int a = 1;
    IREP(i, 64){
        a = (a * a) % m;
        if(((n >> i) & 1) == 1) a = (a * x) % m;
    }
    return a;
}

class Combination
{
public:

    vec fact, invfact;
    int MAX_N, mod;

    Combination(int MAX_N, int mod): MAX_N(MAX_N), mod(mod) {
        initialize();
    }

    void initialize(){
        fact = vec(MAX_N + 1);
        invfact = vec(MAX_N + 1);
        fact[0] = 1;
        FOR(i, 1, MAX_N + 1){
            fact[i] = (fact[i - 1] * i) % mod;
        }
        invfact[MAX_N] = modpow(fact[MAX_N], mod - 2, mod);
        IREP(i, MAX_N){
            invfact[i] = (invfact[i + 1] * (i + 1)) % mod;
        }
    }

    int nCr(int n, int r){
        if(r > n || r < 0 || n < 0) return 0;
        if(n > MAX_N){
            MAX_N = n;
            initialize();
        }
        int a = fact[n];
        a = (a * invfact[r]) % mod;
        a = (a * invfact[n - r]) % mod;
        return a;
    }
};

signed main(){

    int N, M; cin >> N >> M;
    string S; cin >> S;
    vec l(M), r(M);
    REP(i, M){
        cin >> l[i] >> r[i];
        l[i]--; r[i]--; 
    }
    l.push_back(N);
    r.push_back(N);

    vec n1(N + 1, 0);
    REP(i, N){
        n1[i + 1] = n1[i];
        if(S[i] == '1') n1[i + 1]++;
    }

    int mod = 1000000007;
    Combination comb(N, mod);

    mat dp(M + 1, vec(N + 1, 0));
    dp[0][n1[l[0]]] = 1;
    int rmax = -1;
    REP(i, M){
        rmax = max(rmax, r[i]);
        int l0 = l[i], l1 = l[i + 1];
        int t = n1[rmax + 1];
        if(l1 <= rmax){
            int u = max(0LL, t - (rmax - l1 + 1));
            FOR(j, u, t + 1){ 
                REP(k, j + 1){
                    dp[i + 1][j] += dp[i][k] * comb.nCr(l1 - l0, j - k);
                    dp[i + 1][j] %= mod;
                }
            }
        }else{
            REP(k, t + 1){
                dp[i + 1][n1[l1]] += dp[i][k] * comb.nCr(rmax - l0 + 1, t - k);
                dp[i + 1][n1[l1]] %= mod;
            }
        }
    }
    //debug(dp);
    cout << dp[M][n1[N]] << endl;
    
    return 0;
}

Measured memory_bytes: 70912
#pragma comment (linker, "/STACK:256000000")
 
#define _USE_MATH_DEFINES
#define _CRT_NO_DEPRECEATE
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <memory.h>
#include <sstream>
#include <cassert>
#include <ctime>
#include <complex>
 
//#include <random>
 
using namespace std;
 
 
double PI = 3.1415926535897932384626433832795;
long double EPS = 1e-12;
 
typedef unsigned int uint32;
typedef long long int64;
typedef unsigned long long uint64;
const int MOD = 1e9 + 7;
const int BASE = 1327; 
typedef pair<int, int> pii;
const int MAXN = 100100;

int b, a;

void solve()
{
	cin >> a >> b;
	
	if (a > 0)
	{
		cout << "Positive";
		return;
	}
	if (a <= 0 && b >= 0)
	{
		cout << "Zero";
		return;
	}
	if ((b - a) & 1)
		cout << "Positive";
	else
		cout << "Negative";
	
}

 
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef _MY_DEBUG
    freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout);
#else
    //freopen(TASK ".in", "rt", stdin); freopen(TASK ".out", "wt", stdout);
#endif
    srand(1313);
	
	int t = 1;
	//cin >> t;
	
	
		solve();
	
	
    return 0;
}   

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define MAX 100000

int n, A[MAX + 1], B[MAX + 1];

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

  int prev = 0;
  long long sum = 0;
  for ( int i = 0; i <= n ; i++ ){
    sum += min(A[i], prev + B[i]);
    prev = max(0, B[i] - max(A[i] - prev, 0));
  }

  cout << sum << endl;

  return 0;
}

Measured memory_bytes: 1024
N = int(input())
S = []
maxnum = 0
maxyouso = {}
anslist = []
for kai in range (N):
    S.append(input())
for moji in S:
    if moji not in maxyouso:
        maxyouso[moji] = 1
    else:
        maxyouso[moji] = maxyouso[moji] + 1
for num in maxyouso:
    if maxyouso[num] > maxnum:
        maxnum = maxyouso[num]
for num in maxyouso:
    if maxyouso[num] == maxnum:
        anslist.append(num)
anslist.sort()
for k in anslist:
    print(k)

Measured memory_bytes: 35220
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  map<int,int> mp;
  for(int i=0;i<n;i++){
    cin >> a[i];
    mp[a[i]]=i%2;
  }
  sort(a.begin(),a.end());
  int cnt=0;
  for(int i=0;i<n;i++){
    if(i%2!=mp[a[i]]){
      cnt++;
    }
  }
  cout << cnt/2 << endl;
}

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

int main(){
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i, n) cin >> p[i];

  int cnt = 0;
  repi(i, 1, n-1) if((p[i-1]-p[i])*(p[i+1]-p[i]) < 0) cnt++;

  cout << cnt << endl;

}


Measured memory_bytes: 256
n,k = map(int,input().split())
p = list(map(int,input().split()))

def init_max(init_val):
    #set_val
    for i in range(n):
        seg[i+num-1]=init_val[i]    
    #built
    for i in range(num-2,-1,-1) :
        seg[i]=max(seg[2*i+1],seg[2*i+2]) 
    
def update_max(k,x):
    k += num-1
    seg[k] = x
    while k+1:
        k = (k-1)//2
        seg[k] = max(seg[k*2+1],seg[k*2+2])
    
def query_max(p,q):
    if q<=p:
        return ide_ele
    p += num-1
    q += num-2
    res=ide_ele
    while q-p>1:
        if p&1 == 0:
            res = max(res,seg[p])
        if q&1 == 1:
            res = max(res,seg[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = max(res,seg[p])
    else:
        res = max(max(res,seg[p]),seg[q])
    return res

def init_min(init_val):
    #set_val
    for i in range(n):
        seg[i+num-1]=init_val[i]    
    #built
    for i in range(num-2,-1,-1) :
        seg[i]=min(seg[2*i+1],seg[2*i+2]) 
    
def update_min(k,x):
    k += num-1
    seg[k] = x
    while k+1:
        k = (k-1)//2
        seg[k] = min(seg[k*2+1],seg[k*2+2])
    
def query_min(p,q):
    if q<=p:
        return ide_ele
    p += num-1
    q += num-2
    res=ide_ele
    while q-p>1:
        if p&1 == 0:
            res = min(res,seg[p])
        if q&1 == 1:
            res = min(res,seg[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = min(res,seg[p])
    else:
        res = min(min(res,seg[p]),seg[q])
    return res


#####単位元######
ide_ele = -1

#num:n以上の最小の2のべき乗
num =2**(n-1).bit_length()
seg=[ide_ele]*2*num

init_max(p)

a = [-1]*(n-k+1)
for i in range(n-k+1):
    a[i] = query_max(i,i+k)

#####単位元######
ide_ele = n

#num:n以上の最小の2のべき乗
num =2**(n-1).bit_length()
seg=[ide_ele]*2*num

init_min(p)

b = [-1]*(n-k+1)
for i in range(n-k+1):
    b[i] = query_min(i,i+k)

c = [1]*n
d = [True]*n
for i in range(n-2,-1,-1):
    if p[i] < p[i+1]:
        c[i] = c[i+1]+1
        if c[i] >= k:
            d[i] = False



res = 0
res2 = 0


for i in range(n-k):
    if not d[i]:
        res2 = 1
        continue
    if b[i] == p[i] and a[i+1] == p[i+k]:
        continue
    res += 1
if d[n-k]:
    res += 1

if n==k:
    print(1)
else:
    print(res+res2)


Measured memory_bytes: 100684
# -*- coding: utf-8 -*-
N = int(input())
A = list(map(int, input().split()))

money = 1000
stock = 0

i = 0
for i in range(N):
  # 前日よりも株価が上がっている場合は、株を全て売却
  if i != 0 and A[i] > A[i-1]:
    money += stock * A[i]
    stock = 0
  
  # 翌日に株価が上がる場合は、所持金を全て株に変える
  if i != (N-1) and A[i+1] > A[i]:
    stock += money // A[i]
    money = money % A[i]
print(money)

Measured memory_bytes: 62016
//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error('\n');
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr('time : ' + end + 'ms');
  myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var one = nextIntArray();
  var H = one[0];
  var W = one[1];
  var list = new Array(H);
  for(var i = 0; i < H; i++){
    list[i] = nextIntArray();
  }
  var output = [];
  for(var i = 0; i < H; i++){
    var nextY = i;
    if(i % 2 == 0){
      for(var j = 0; j < W; j++){
        if(i == H - 1 && j == W - 1){continue;}
        if(list[i][j] % 2 == 1){
          var nextX = j + 1;
          if(j == W - 1){
            nextY = i + 1;
            nextX = j;
          }
          list[i][j]--;
          list[nextY][nextX]++;
          output.push((i + 1) + " " + (j + 1) + " " + (nextY + 1) + " " + (nextX + 1));
        }
      }
    }else{
      for(var j = W - 1; j >= 0; j--){
        if(i == H - 1 && j == 0){continue;}
        if(list[i][j] % 2 == 1){
          var nextX = j - 1;
          if(j == 0){
            nextY = i + 1;
            nextX = j;
          }
          list[i][j]--;
          list[nextY][nextX]++;
          output.push((i + 1) + " " + (j + 1) + " " + (nextY + 1) + " " + (nextX + 1));
        }
      }
    }
  }
  myout(output.length);
  myout(myconv(output, 9));
}


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

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << "Line " << __LINE__ << ": " <<  #x << " = " << (x) << "\n";
#define spa << " " <<
#define fi first
#define se second
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()

using ld = long double;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;

template<typename T> using V = vector<T>;
template<typename T> using P = pair<T, T>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){os << "(" << v.first << ", " << v.second << ")"; return os;}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<vector<T>> &v){ for(auto &e : v){os << e << "\n";} return os;}
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

template <class T> void UNIQUE(vector<T> &x) {sort(ALL(x));x.erase(unique(ALL(x)), x.end());}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
void fail() { cout << -1 << '\n'; exit(0); }
inline int popcount(const int x) { return __builtin_popcount(x); }
inline int popcount(const ll x) { return __builtin_popcountll(x); }
template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<"\n";}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<"\n";};

const ll INF = (1ll<<62);
// const ld EPS   = 1e-10;
// const ld PI    = acos(-1.0);
const ll mod = (int)1e9 + 7;
//const ll mod = 998244353;

int main(){

    ll N;
    cin >> N;
    V<ll> X(N), Y(N);
    REP(i, N) cin >> X[i] >> Y[i];

    bool ok = false;
    REP(i, N-3+1){
        if(X[i] == Y[i] and X[i+1] == Y[i+1] and X[i+2] == Y[i+2]){
            //dump(i)
            ok = true;
        }
    }
    cout << (ok ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef vector <ll> vi;
typedef pair <ll, ll> ii;
typedef vector <ii> vii;
#define mod 1000000007
#define pb push_back
int main()
{
    ll n,k;
    cin>>n>>k;
    vi arr(n+1);
    for(ll i=1;i<=n;i++)
    {
        cin>>arr[i];
    }
    vi dp(n+1,0);
    dp[n]=0;
    dp[n-1]=abs(arr[n]-arr[n-1]);
    for(ll i=n-2;i>=1;i--)
    {
        ll m=abs(arr[i]-arr[i+1])+dp[i+1];
        for(ll j=i+1;j<=n && j<=i+k;j++)
        {
            ll e=abs(arr[i]-arr[j])+dp[j];
            if(e<m)
            {
                m=e;
            }
        }
        dp[i]=m;
    }
//    for(ll i=1;i<=n;i++)
  //  {
    //    cout<<dp[i]<<" ";
   // }
   // cout<<endl;
    cout<<dp[1]<<endl;
}


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

// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

typedef long long ll; 
typedef long double ld; 
typedef vector<int> vi; 
typedef pair<int,int> pii; 
#define pb push_back
#define mp make_pair
#define prarr(a,n) cerr<<#a<<" : ";for(ll i=0;i<n;i++) cerr<<a[i]<<" "; cerr<<endl;
#define prmat(mat,row,col) cerr<<#mat<<" :\n";for(ll i=0;i<row;i++) {for(ll j=0;j<col;j++) cerr<<mat[i][j]<<"\t";cerr<<endl;}
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
#define all(a) a.begin(),a.end()
#define sz(x) ((int)x.size())
#define endl '\n'
#define fast_io ios_base::sync_with_stdio(NULL); cin.tie(NULL)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {ll idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ", "; dbs(str.substr(idx + 1), s...);}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}
template <class T> void prall(T a) { prc(all(a)); }
const int inf=1000*1000*1000+9; 
const ll infl=1ll*inf*inf; 
const int mod=1000*1000*1000+7;  

// ----------------------------------------------------------------------------	-------------- 


const int nax=1e5+5; 
int ops[nax]; 
int tr[nax<<2]; 
void up(int p, int l, int r, int i, int v){
  if(i<l || i>r) return;
  if(l==r){
    tr[p]=v; 
    return;
  }
  int m=(l+r)>>1; 
  up(p<<1,l,m,i,v); 
  up(p<<1|1,m+1,r,i,v);
  tr[p]=min(tr[p<<1],tr[p<<1|1]); 
}
int qq(int p,int l,int r,int i,int j){
  if(r<i || l>j) return inf;
  else if(i<=l && r<=j) return tr[p]; 
  int m=(l+r)>>1; 
  int a=qq(p<<1,l,m,i,j); 
  int b=qq(p<<1|1,m+1,r,i,j); 
  return min(a,b); 
}

void solve(){
  int n,m; cin>>n>>m; 
  string s; cin>>s; 
  ops[n]=0; 
  for(int i=0;i<4*nax;i++) tr[i]=inf;
  up(1,1,n,n,0); 
  map<int,int> pos; 
  vi nn(n+1); 
  pos[0]=n; 
  for(int i=n-1;i>=0;i--){
    if(s[i]=='1'){
      ops[i]=inf; 
    }
    else {
      int next=qq(1,1,n,i+1,min(n,i+m)); 
      if(next== inf){
        cout<<-1; return;
      }
      else{
        ops[i]=next+1; 
        nn[i]=pos[next]; 
      }
    }
    pos[ops[i]]=i; 
    if(i>0){
      up(1,1,n,i,ops[i]);
    }
  }
  for(int i=0;i<n;i++){
    cout<<nn[i]-i<<" " ;  
    i=nn[i]; 
    i--; 
  }
}



int main(){
	// clock_t beg=clock(); 
	fast_io; 
  // cout << fixed << setprecision(13); 
  int t; 
  t=1; 
  //cin>>t; 
  while(t--){
	  solve(); 	
  }
	// clock_t end=clock(); 
	// fprintf(stderr, "%lf\n", (double)(end-beg)/(CLOCKS_PER_SEC));
}

Measured memory_bytes: 7632