akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;cin>>n>>k;
    vector<int>h(n,0);
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    vector<int>dp(n+1,1e9+5);
    dp[1]=0;
    for(int i=1;i<n+1;i++){
        for(auto j=i+1;j<i+k+1;j++){
            if(j<=n){
                dp[j]=min(dp[j],dp[i]+abs(h[j-1]-h[i-1]));
            }
        }
    }
    cout<<dp[n];
    return 0;
}

Measured memory_bytes: 1024
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

    class Sep {
        int rCount, lCount, rlStartIdx;
        public Sep(int rCount, int lCount, int rlStartIdx) {
            this.rCount = rCount;
            this.lCount = lCount;
            this.rlStartIdx = rlStartIdx;
        }

        int lValue() {
            if (this.rCount == this.lCount) {
                return this.rCount;
            } else if (this.rCount % 2 == 0) {
                return (this.rCount + this.lCount) / 2;
            } else {
                return (this.rCount + this.lCount) / 2 + (this.rCount + this.lCount) % 2;
            }
        }

        int rValue() {
            if (this.rCount == this.lCount) {
                return this.rCount;
            } else if (this.rCount % 2 == 0) {
                return (this.rCount + this.lCount) / 2 + (this.rCount + this.lCount) % 2;
            } else {
                return (this.rCount + this.lCount) / 2 ;
            }
        }
    }

    void run() {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();

        List<Sep> sepList = new ArrayList<>();

        int rlStartIdx = 0;
        int rCount = 0;
        int lCount = 0;
        for (int i = 0 ; i < s.length(); i++) {
            if (s.charAt(i) == 'R') {
                rCount++;
                if (s.charAt(i + 1) == 'L') {
                    rlStartIdx = i;
                }
            } else {
                lCount++;
                if (i == s.length() - 1 || s.charAt(i + 1) == 'R') {
                    sepList.add(new Sep(rCount, lCount, rlStartIdx));
                    rlStartIdx = 0;
                    rCount = 0;
                    lCount = 0;
                }
            }
        }

        int[] ans = new int[s.length()];

        for (Sep sep : sepList) {
            ans[sep.rlStartIdx] = sep.lValue();
            ans[sep.rlStartIdx + 1] = sep.rValue();
        }

        for (int i = 0 ; i < s.length() - 1; i++) {
            System.out.print(ans[i]);
            System.out.print(" ");
        }
        System.out.println(ans[s.length() - 1]);

    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

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


Measured memory_bytes: 45248
'use strict';
process.stdin.on('data', function(chunk) {
  var lines = chunk.toString().split('\n');
  var result = (function(data) {
    var RectAngle = {
      width:data[0]
      ,height:data[1]
    };
    var Circle = {
      x:data[2]
      ,y:data[3]
      ,r:data[4]
    };
    return ((0 <= Circle.x - Circle.r) && (0 <= Circle.y - Circle.r) && (Circle.x + Circle.r <= RectAngle.width)
        && (Circle.y + Circle.r <= RectAngle.height)) ? 'Yes' : 'No';
  }(lines[0].split(' ').map(Number)
  ));

  console.log(result);
});

process.stdin.resume();
process.stdin.setEncoding('utf8');

Measured memory_bytes: 7648
#include <cstdio>
#include <algorithm>

using namespace std;

int a[100];

int main() {
    int n, sum = 0, x = 0, i;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) scanf("%d", &a[i]);
    
    for (i = 0; i < n; i++) sum += a[i];
    
    for (i = 0; i < n; i++) {
        if (abs(a[i] * n - sum) < abs(a[x] * n - sum)) x = i;
    }
    
    printf("%d\n", x);
    
    return 0;
}


Measured memory_bytes: 128
package main

import (
	"fmt"
	"sort"
)

type res struct {
	s string
	p int
	ind int
}
type rs []res

func (rs rs)Len() int {
	return len(rs)
}
func (rs rs)Swap(i, j int) {
	rs[i], rs[j] = rs[j], rs[i]
}
func (rs rs)Less(i, j int) bool {
	if rs[i].s < rs[j].s {
		return true
	} else if rs[i].s == rs[j].s {
		return rs[i].p > rs[j].p
	}
	return false
}

func main() {
	var (
		n int
		rs rs
	)
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		var in res
		fmt.Scan(&in.s, &in.p)
		in.ind = i + 1
		rs = append(rs, in)
	}
	sort.Sort(rs)
	for _, r := range rs {
		fmt.Println(r.ind)
	}
}


Measured memory_bytes: 512
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]

def main():
    n = i_input()
    a = i_list()
    b = i_list()
    c = i_list()
    a.sort()
    b.sort()
    c.sort()

    al = []
    bl = [0]
    import bisect

    for k,i in enumerate(b):
        x = bisect.bisect(c, i)
        bl.append(bl[k]+(n-x))

    ans = 0

    for i in a:
        x = bisect.bisect(b,i)
        ans += bl[-1] - bl[x]
    print(ans)




if __name__=="__main__":
    main()


Measured memory_bytes: 30220
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let n = read_as_vec::<usize>()[0];
    let line = read_as_vec::<u64>();
    let (d, x) = (line[0], line[1]);
    let mut ans = x;
    for _ in 0..n{
        let a = read_as_vec::<u64>()[0];
        ans += (d-1)/a+1;
    }

    println!("{}", ans);

}


Measured memory_bytes: 4352
import sys
input = sys.stdin.readline
from collections import Counter

N = int(input())
S = input().rstrip()
S_rev = S[::-1]

cnt = 0
left = 0
for i in S:
    if i == "(":
        cnt += 1
    elif cnt <= 0:
        left += 1
    else:
        cnt -= 1
S = "(" * left + S

cnt = 0
right = 0
for j in S_rev:
    if j == ")":
        cnt += 1
    elif cnt <= 0:
        right += 1
    else:
        cnt -= 1
S += ")" * right

print(S)
    



Measured memory_bytes: 38384
import java.util.Scanner;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int endPoint = 10000;
    int[] ary = new int[endPoint];
    int s = sc.nextInt();
    ary[0] = s;
    for(int i=1; i<endPoint; i++) {
    	if(ary[i-1] %2 ==0) {
    		ary[i] = ary[i-1]/2;
    	}
    	else {
    		ary[i] = ary[i-1]*3+1;
    	}
    }
    int ans=0;
    for1:
    for(int m=2; m<endPoint; m++) {
        for(int n=0; n<m-1; n++) {
        	if(ary[n]==ary[m]) {
        		ans = m; break for1;
        	}
        }
    }
    System.out.println(ans+1);
  }
}

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

int main(){
	int n;	cin>>n;
	vector<int> a(n), b(n);
	for(int i=0; i<n; i++){
		cin>>a[i];
		if(i) a[i]+=a[i-1];
	}

	for(int i=0; i<n; i++) cin>>b[i];

	for(int i=n-1; i-1>=0; i--){
		b[i-1]+=b[i];
	}

	int ans=0;
	for(int i=0; i<n; i++){
		ans=max(ans, a[i]+b[i]);
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<stdlib.h>
#include<algorithm>
#include<queue>
#include<string.h>
#include<vector>
using namespace std;
namespace io {
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	// getchar
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	// print the remaining part
	inline void flush () {
		fwrite (obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	// putchar
	inline void putc (char x) {
		*oS ++ = x;
		if (oS == oT) flush ();
	}
	// input a signed integer
	template <class I>
	inline void read (I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = x * 10 + (c & 15); x *= f;
	}
	// print a signed integer
	template <class I>
	inline void print (I x) {
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10;
		while (qr) putc (qu[qr --]);
	}
	//no need to call flush at the end manually!
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io :: read;
using io :: putc;
using io :: print;

int n,p,a;
long long J=0,O=1;

int main()
{
    read(n),read(p);
    for(int i=1;i<=n;i++)
    {
        read(a);
        if(a&1)
        {
            O=J+O;
            J=O;
        }
        else
        {
            J=J<<1;
            O=O<<1;
        }
    }
    if(p)cout<<J;
    else cout<<O;
    return 0;
}

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

/* define const */
const long M = 10000000010;
/* finish defineing const */

long n;

long func(long x, long y)
{
    long tx = 0, ty = 0;

    while (x > 0)
    {
        tx++;
        x /= 10;
    }
    while (y > 0)
    {
        ty++;
        y /= 10;
    }

    return max(tx, ty);
}

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

    long mn = M;

    for (long a = 1; a * a <= n; a++)
    {
        if (n % a == 0)
        {
            long b = n / a;
            mn = min(mn, func(a, b));
        }
    }
    cout << mn << endl;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.Scanner;
 


public class Main {
	private static Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	static long mod =1000000007;
	//static 	ArrayList<Integer> cc = new ArrayList<>(100);
	
	
	
	
	public static void main(String[] args) {
		//int N=sc.nextInt();for(int i=0;i<N;i++) {}
		//Random sc =new Random();
		int N=sc.nextInt();
		int M=sc.nextInt();
		
		boolean v1[]=new boolean[N+1];
		boolean vN[]=new boolean[N+1];
		
		int a,b;
		boolean x=false;
		for(int i=0;i<M;i++) {
		a=sc.nextInt();
		b=sc.nextInt();
		if(a==N) {
			vN[b]=true;
			
		}else if(a==1) {
			v1[b]=true;;
		}else if(b==N) {
			vN[a]=true;
		}else if(b==1) {
			v1[a]=true;
		}
		}
		for(int i=0;i<=N;i++) {
			if(v1[i]&&vN[i]) {
				x=true;
				break;
			}
			
			
			
		}
		
		
		
		
		if(x)p("POSSIBLE");
		else p("IMPOSSIBLE");
		
		
		
		
		
		
	}
	

	
	
	
	

	


	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
}
	


Measured memory_bytes: 94016
#include <stdio.h>
 
using namespace std;
 
int main(){
    int n;
    scanf("%d",&n);
    int A[n];
 
    for(int i = 0; i < n; i++) scanf("%d",&A[i]);
 
    for(int i = n-1; i > 0; i--) printf("%d ",A[i]);
    printf("%d\n",A[0]);
}


Measured memory_bytes: 2724
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int n;
double t[24],u[3][8],v[6];
map<double,int> m;

int main(){
	for(int i=0;i<24;i++){
		cin>>n>>t[i];
		u[i/8][i%8]=t[i];
		m[t[i]]=n;
	}
	for(int i=0;i<3;i++)sort(u[i],u[i]+8);
	for(int i=0;i<6;i++){
		double tt=u[i/2][i%2];
		cout<<m[tt]<<" ";
		if((int)(tt*100+0.1)%10)cout<<tt<<endl;
		else if((int)(tt*10)%10)cout<<tt<<"0"<<endl;
		else cout<<tt<<".00"<<endl;
		v[i]=tt;
	}
	for(int i=0;i<24;i++)for(int j=0;j<6;j++)if(t[i]==v[j])t[i]=2e+9;
	sort(t,t+24);
	for(int i=0;i<2;i++){
		double tt=t[i];
		cout<<m[tt]<<" ";
		if((int)(tt*100+0.1)%10)cout<<tt<<endl;
		else if((int)(tt*10)%10)cout<<tt<<"0"<<endl;
		else cout<<tt<<".00"<<endl;
	}
}

Measured memory_bytes: 0
#include<stdio.h>
#include<string.h>
#define N 100

void BubbleSort(char (*)[3],int);
void SelectionSort(char (*)[3],int);

int main(){
  int i,j,n,temp,cnt=0,minj;
  char A[N][3],B[N][3],S[N][3];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",A[i]);
    strcpy(B[i],A[i]);
    strcpy(S[i],A[i]);
  }
  BubbleSort(B,n);
  SelectionSort(S,n);

  int check=0;
  for(i=0;i<n;i++){
    if(strcmp(B[i],S[i])!=0)check=1;
  }
  if(check==0) printf("Stable\n");
  else printf("Not stable\n");
  return 0;
}
void BubbleSort(char A[N][3],int n){
  int i,j;
  char temp[3];
      for(i=0;i<n;i++){
	for(j=n-1;j>i;j--){
	  if(A[j][1]<A[j-1][1]){
	  strcpy(temp,A[j]);
	  strcpy(A[j],A[j-1]);
	  strcpy(A[j-1],temp);
	  }
	}
      }
      for(i=0;i<n-1;i++){
	printf("%s ",A[i]);
      }
     printf("%s\n",A[n-1]);
     printf("Stable\n");
}
void SelectionSort(char A[N][3],int n){
  int i,j,minj;
  char temp[3];
    for(i=0;i<n;i++){
      minj=i;
      for(j=i;j<n;j++){
	if(A[j][1]<A[minj][1])minj=j;
      }
      strcpy(temp,A[i]);
      strcpy(A[i],A[minj]);
      strcpy(A[minj],temp);
    }
  for(i=0;i<n-1;i++){
  printf("%s ",A[i]);
  }
  printf("%s\n",A[n-1]);
}





Measured memory_bytes: 2104
N = int(input())
h = list(map(int, input().split()))

dp = [0]*N

for i in range(1, N):
  if i == 1:
    dp[i] = abs(h[i] - h[i-1])
  else:
    dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]))
  
print(dp[N-1])

Measured memory_bytes: 13980
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define ull unsigned ll
#define pb push_back
#define popb pop_back
#define mt make_tuple
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define pii pair <int,int>
#define piii pair <pii,int>
#define piiii pair <pii,pii>
#define plll pair <pair <ll, ll>, ll>
#define rep0(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define rep(i,x,y) for(ll i=x;i<=y;i++)
#define reprev(i,n) for(ll i=n;i>=0;i--)
#define all(c) c.begin(),c.end()
#define print(a) rep0(i,a.size()) cout << a[i] << " "
#define hi() cout << "\nHello, I am error. Can you find me? :):):)\n"
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_eppoch().count())
 
using namespace __gnu_pbds;
using namespace std;
using ordered_set =  tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>;

const int mod = 1e9+7;
const long double pi = acos(-1);

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

void solve(){

	string s;
	cin >> s;
	int flag = 0;
	int n =s.size();
	rep0(i,s.size()) if(s[i] != s[n-1-i]) flag = 1;
	int m  = (n-1)/2;
	rep0(i,m) if(s[i] != s[m-1-i]) flag = 1;
	m = (n+3)/2;
	for(int i=m-1;i<n;i++){
		if(s[i] != s[n-1-(i-(m-1))]){
			flag = 1;
		}
	}
		if(flag) cout << "No";
	else cout << "Yes";

	return;
}

int main(){

	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	int TC = 1,t = 0;
	// cin >> TC;
	while(t++ < TC){
		// cout << "Case #" << t << ": ";
		solve();
		// cout << "\n";
	}

	cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";

	return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;

int N;
vi A;
ll ans;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> N; A.resize(3*N);
    F0R(i,3*N) cin >> A[i];
    sort(all(A)); reverse(all(A));
    F0R(i,N) ans += A[2*i+1];
    cout << ans;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS

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

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

void code() {
    int n;
    cin>>n;
    ll ans=0;
    int curr;
    vector<int> A(n);
    for(int i=0; i<n; i++) {
        cin>>A[i];
    }
    curr = A[0];
    for(int i=1; i<n; i++) {
        ans += max(0, curr-A[i]);
        curr = max(curr, A[i]);
    }


    cout << ans << "\n";
}

signed main() {
    std::ios_base::sync_with_stdio(false);
    int t=1;
    // cin>>t;
    for(int i=0; i<t; i++) {
        code();
    }
}


Measured memory_bytes: 4056
import java.io.*;
import java.util.*;
 
 
public class  Main{
	static TreeSet<String>all,ans;
	static void solve(char[]in) {
		StringBuilder sb=new StringBuilder();
		for(char x:in) {
			sb.append(x);
		}
		
		if(all.contains(sb.toString()))return;
		all.add(sb.toString());
		
		
		for(int j=0;j<in.length-1;j++) {
			char c=(char)(in[j]+1);
			if(in[j+1]!=c) {
				char[]tmp=in.clone();
				tmp[j+1]=c;
				solve(tmp);
			}
		}
	}
	static void gen(StringBuilder sb,int n) {
		if(all.contains(sb.toString()))return;
		all.add(sb.toString());
		if(sb.length()==n) {
			ans.add(sb.toString());
			return;
		}
		
		
		for(int j=0;j<sb.length();j++) {
			StringBuilder tmp=new StringBuilder(sb);
			tmp.append((char)(sb.charAt(j)+1));
			gen(tmp,n);
		}
		
		for(int j=0;j<sb.length();j++) {
			StringBuilder tmp=new StringBuilder(sb);
			tmp.append(sb.charAt(j));
			gen(tmp,n);
		}
	}
	public static void main(String[] args) throws Exception{
		MScanner sc=new MScanner(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		char[]in=new char[sc.nextInt()];
		for(int i=0;i<in.length;i++) {
			in[i]='a';
		}
		all=new TreeSet<String>();
		ans=new TreeSet<String>();
		StringBuilder sb=new StringBuilder();
		sb.append('a');
		gen(sb, in.length);
		
//		System.out.println(ans.size());
		while(!ans.isEmpty()) {
			pw.println(ans.pollFirst());
		}
		pw.flush();
	}
	static class MScanner {
		StringTokenizer st;
		BufferedReader br;
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int[] takearr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public long[] takearrl(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public Integer[] takearrobj(int n) throws IOException {
	        Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public Long[] takearrlobj(int n) throws IOException {
	        Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}


Measured memory_bytes: 90956
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <queue>
#include <cstdio>
#include <map>
#include <set>
#include <utility>
#include <stack>
#include <cstring>
#include <cmath>
#include <vector>
#include <ctime>
#include <ostream>
using namespace std;
typedef long long ll;

int main()
{
#ifdef LOCAL
    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
#endif // LOCAL
    int n;
    char str[500];
    scanf("%s",str);
    n=strlen(str);
    for(int i=0;i<n;i++)
    {
        if(i==5||i==13)
            putchar(' ');
        else
            putchar(str[i]);
    }
    return 0;
}


Measured memory_bytes: 256
//A
#include<bits/stdc++.h>
#define se second
#define fi first
#define all(v) v.begin(), v.end()
#define mp make_pair
#define pb push_back

using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const double PI = 2 * acos(0);

int main() {
	int D, T, S;	
	scanf("%d%d%d", &D, &T, &S);
	if (D / S + (D % S > 0) <= T) printf("Yes\n");
	else printf("No\n");
}

Measured memory_bytes: 3716
#include <stdio.h>

int main (void) {
  int N, M;
  int A[1000];
  int i, ns, sel;
  float limit;
  float Atotal;
  
  scanf("%d %d", &N, &M);
  Atotal = 0;
  for (i = 0; i < N; i++) {
    scanf("%d", &A[i]);
    Atotal += A[i];
  }

  limit = Atotal / (4 * M);

  ns = 0;
  sel = 0;
  for (i = 0; i < N; i++) {
    if (A[i] >= limit) {
      sel++;
    }
  }

  if (sel < M) {
    printf("No\n");
  } else {
    printf("Yes\n");
  }

  return 0;
}


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

int main(){
  int N,x,y;
  double total=0,ans,count=0;
  cin >>N;
  vector<pair<double,double>> mati(N);
  vector<int> v(N);
  for(int i=0;i<N;i++){
    cin>>x>>y;
    mati.at(i)=make_pair(x,y);
    v.at(i)=i;
  }
  
  sort(v.begin(), v.end());
  do {
    // 1行で今の並び方を出力
    for (int i=0;i<N-1;i++) {
      double kyori2=pow(mati.at(v.at(i)).first-mati.at(v.at(i+1)).first,2)+pow(mati.at(v.at(i)).second-mati.at(v.at(i+1)).second,2);
      double kyori=pow(kyori2,0.5);
      total+=kyori;
    }
    count++;
  } while (next_permutation(v.begin(), v.end()));
  ans=total/count;
  cout << fixed << setprecision(10);
  cout<<ans<<endl;

  
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

bool isprime (int n){

	if (n == 0 || n == 1){
		return false;
	}else if (n == 2){
		return true;
	}else if (n % 2 == 0){
		return false;
	} // end if
	
	for (int i = 3; i <= sqrt(n); i+= 2){
		if (n % i == 0){
			return false;
		} // end if
	} // end for
		
	return true;
}

int main()
{
//	cut here before submit 
//	freopen("testcase.p2", "r", stdin);
	string str = "";

	while (getline (cin, str ) ){
		if (str.empty() ){
			break;
		} // end if
		int n;
		stringstream ss(str);
		ss >> n;
		int i;
		int res1 = 0;
		int res2 = 0;

		for (i = n + 1;; ++i){
			if (isprime(i) ){
				res1 = i;
				break;
			} // end if
		} // end for
	
		for (i = n - 1;; --i){			
			if (isprime(i) ){
				res2 = i;
				break;
			} // end if
		} // end for

		cout << res2 << ' ' << res1 << endl;
	} // end for
		
	return 0;
}

Measured memory_bytes: 0
import java.util.*;
import java.lang.*;
public class Main{
  public static void main(String[]args){
    Scanner sn=new Scanner(System.in);
     int n=sn.nextInt();
    int[] arr=new int[n];
            for(int i=0;i<n;i++)
            {
              arr[i]=sn.nextInt();}
    int ans[]=new int[100003];
         for(int i=0;i<n;i++)
         {
           ans[arr[i]]++;
           ans[arr[i]+1]++;
           ans[arr[i]+2]++;}
    int max=0;
    for(int i=0;i<ans.length;i++)
      max=Math.max(ans[i],max);
    System.out.println(max);}}

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

#define int long long
#define MOD 1000000007

 
using namespace std;

signed main(){

    int N;
    cin >> N;
    int A[N],B[N],C[N];

    

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

    for(int i=0;i<N;i++){
        cin >> C[i];
    }

    sort(A,A+N);
    sort(B,B+N);
    sort(C,C+N);

    int sum = 0;

    for(int i=0;i<N;i++){
        auto itr1 = lower_bound(A,A+N,B[i]);

        int a = itr1-A;
        //cout <<c <<endl;
        auto itr2 = upper_bound(C,C+N,B[i]);
        int c = C+N-itr2;
        //cout <<a <<endl;
        sum = sum + c*a;
    }

    cout <<sum <<endl;

    return 0;
}

Measured memory_bytes: 2688
#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;

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

  long ans = 0;
  for (int i = 0; i < (1 << (s.size() - 1)); ++i) {
    long sum = 0;
    long num = s[0] - '0';
 
    for (int j = 0; j < s.size() - 1; ++j) {
      if(i & (1 << j)) {
        sum += num;
        num = 0;
      }
    
    num = num * 10 + s[j + 1] - '0';
    }

    sum += num;
    ans += sum;
  }

  cout << ans << "\n";
  
  return 0;
}

Measured memory_bytes: 764
#include <iostream>

using namespace std;

int main() {
	int n;
	cin >> n;
	
	int result;
	int num = n / 100;
	if (n <= num * 100 + num * 10 + num) {
		result = num;
	} else {
		result = num + 1;
	}
	
	cout << result << result << result << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ll long long
#define lld long double
#define MOD 1000000007
#define CAP 10000000
#define inf 1000000000000000000LL
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define sz(v) v.size()
#define all(v)    v.begin(),v.end()
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
ll power(ll x,ll y, ll md=MOD){ll res = 1;x%=md;while(y>0){if(y&1)res = (res*x)%md;x = (x*x)%md;y = y>>1;}return res%md;}

#define int ll
#define endl '\n'

signed main() {
	fast;

	int n;
	cin>>n;

	string s[n];
	int t[n];

	for(int i=0;i<n;i++) {
		cin>>s[i];
		cin>>t[i];
	}

	string ss;
	cin>>ss;
	int f = 0, sum = 0;
	for(int i=0;i<n;i++) {
		if(f) sum += t[i];
		if(s[i]==ss) f = 1;
	}
	cout<<sum;
}

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

int main(){
	string a;
  	int count = 0;
  	cin >> a;
  	int k=0;
  	int i;
  	for(i = 0; i <a.size(); i++) {
      	k+=a[i]-'0';
	}
  	for(i = 0; i <a.size()-1; i++) {
      	if(a[i] == '9' && a[i+1] == '9')
          	count+=9;
  		else
          	break;
	}
  	if(i==a.size()-1)
      	count += a[a.size()-1]-'0';
  	else
      	count += (a[i]-'0'-1) +9*(a.size()-1-i);
  	cout << max(k,count) <<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
ll mod=1e9+7;

int main() {
  vector<ll> ans={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  ll k;
  cin >> k;
  cout << ans[k-1] << endl;
}

Measured memory_bytes: 256
package main

import "fmt"

//Library for input and output
// "strconv" //For conversion of strings to ints and vice versa
//i, err := strconv.Atoi("-42")
//s := strconv.Itoa(-42)
// "sort"

func main() {
	var N int
	fmt.Scan(&N)
	v := make([][]int, N)
	dp := make([][]int, N)
	for i := 0; i < N; i++ {
		v[i] = make([]int, 3)
		dp[i] = make([]int, 3)
	}

	for i := 0; i < N; i++ {
		fmt.Scan(&v[i][0], &v[i][1], &v[i][2])
	}

	dp[0][0], dp[0][1], dp[0][2] = v[0][0], v[0][1], v[0][2]
	for i := 1; i < N; i++ {
		dp[i][0] = v[i][0] + Max(dp[i-1][1], dp[i-1][2])
		dp[i][1] = v[i][1] + Max(dp[i-1][2], dp[i-1][0])
		dp[i][2] = v[i][2] + Max(dp[i-1][0], dp[i-1][1])
	}

	fmt.Println(Max(dp[N-1][0], Max(dp[N-1][1], dp[N-1][2])))
}

// Reverse a string s
func Reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

// Abs returns the absolute value of x.
func Abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

// Min returns the min of x and y
func Min(x int, y int) int {
	if x < y {
		return x
	}
	return y
}

// Max returns the min of x and y
func Max(x int, y int) int {
	if x < y {
		return y
	}
	return x
}


Measured memory_bytes: 19960
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define VVi vector<vector<ll>>
#define Vd vector<double>
#define Vb vector<bool>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

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;}

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN(n);
  Vi p(n);
  VIN(p)
  FOR(i,1,n){
    if(i == p[i-1]){
      swap(p[i-1],p[i]);
      z++;
    }
  }
  if(p[n-1]==n) z++;
  OUT(z);
}

Measured memory_bytes: 1024
import java.util.*;

class Main {
    static String divide[] = {
        "dream",
        "dreamer",
        "erase",
        "eraser"
    };

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

        int index = S.length();
        boolean canDiv;
        while (true) {
            boolean isFit = false;
            for (String d: divide) {
                if (d.length() > index) continue;
                String substr = S.substring(index - d.length(), index);
                if (d.equals(substr)) {
                    index -= d.length();
                    isFit = true;
                    break;
                }
            }
            if (!isFit) {
                canDiv = false;
                break;
            }
            if (index == 0) {
                canDiv = true;
                break;
            }
        }

        if (canDiv)
            System.out.println("YES");
        else
            System.out.println("NO");
    }
}


Measured memory_bytes: 30452
// eddy1021
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef double D;
typedef long double LD;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
#define mod9 1000000009LL
#define mod7 1000000007LL
#define INF  1023456789LL
#define INF16 10000000000000000LL
#define eps 1e-9
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()
#ifndef ONLINE_JUDGE
#define debug(...) printf(__VA_ARGS__)
#else 
#define debug(...)
#endif
inline LL getint(){
  LL _x=0,_tmp=1; char _tc=getchar();    
  while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
  if( _tc == '-' ) _tc=getchar() , _tmp = -1;
  while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
  return _x*_tmp;
}
inline LL add( LL _x , LL _y , LL _mod = mod7 ){
  _x += _y;
  return _x >= _mod ? _x - _mod : _x;
}
inline LL sub( LL _x , LL _y , LL _mod = mod7 ){
  _x -= _y;
  return _x < 0 ? _x + _mod : _x;
}
inline LL mul( LL _x , LL _y , LL _mod = mod7 ){
  _x *= _y;
  return _x >= _mod ? _x % _mod : _x;
}
LL mypow( LL _a , LL _x , LL _mod ){
  if( _x == 0 ) return 1LL;
  LL _ret = mypow( mul( _a , _a , _mod ) , _x >> 1 , _mod );
  if( _x & 1 ) _ret = mul( _ret , _a , _mod );
  return _ret;
}
LL mymul( LL _a , LL _x , LL _mod ){
  if( _x == 0 ) return 0LL;
  LL _ret = mymul( add( _a , _a , _mod ) , _x >> 1 , _mod );
  if( _x & 1 ) _ret = add( _ret , _a , _mod );
  return _ret;
}
inline bool equal( D _x ,  D _y ){
  return _x > _y - eps && _x < _y + eps;
}
#define Bye exit(0)
int __ = 1 , _cs;
/*********default*********/
#define N 101010
void build(){

}
int n , m , q , d[ N ] , v[ N ] , c[ N ];
vector<int> g[ N ];
void init(){
  n = getint();
  m = getint();
  while( m -- ){
    int ai = getint();
    int bi = getint();
    g[ ai ].push_back( bi );
    g[ bi ].push_back( ai );
  }
  q = getint();
  for( int i = 0 ; i < q ; i ++ ){
    v[ i ] = getint();
    d[ i ] = getint();
    c[ i ] = getint();
  }
}
int clr[ N ][ 11 ];
int tt[ N ][ 11 ];
void go( int now , int dst , int tclr , int stmp ){
  if( clr[ now ][ dst ] ) return;
  clr[ now ][ dst ] = tclr;
  tt[ now ][ dst ] = stmp;
  if( dst == 0 ) return;
  for( int x : g[ now ] )
    go( x , dst - 1 , tclr , stmp );
}
void solve(){
  for( int i = q - 1 ; i >= 0 ; i -- )
    go( v[ i ] , d[ i ] , c[ i ] , i );
  for( int i = 1 ; i <= n ; i ++ ){
    int rc = 0 , ttt = -1;
    for( int j = 0 ; j < 11 ; j ++ )
      if( clr[ i ][ j ] and tt[ i ][ j ] > ttt )
        rc = clr[ i ][ j ], ttt = tt[ i ][ j ];
    printf( "%d\n" , rc );
  }
}
int main(){
  build();
  //__ = getint();
  while( __ -- ){
    init();
    solve();
  }
}


Measured memory_bytes: 16376
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = n;
		boolean judge = false;
		for(int i = 0; m >= 4; i++) {
			m = n - (4 * i);
			if(m % 7 == 0) {
				judge = true;
				break;
			}
		}
		if(judge) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		sc.close();
	}

}


Measured memory_bytes: 23764
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		long n     = Long.parseLong(scanner.nextLine());
		char[] ans = scanner.nextLine().toCharArray();
		int a = 0;

		for(int i = 0; i < n; i++) {

			if(i < n - 2 && ans[i] == 'A') {
				if(ans[i + 1] == 'B') {
					if(ans[i + 2] == 'C') {

						a++;
						i += 2;

					}
				}
			}
		}
		System.out.println(a);
	}
}

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

ll mpow(ll a, ll b){
	if(b==0){
		return a;
	}else if(b%2==0){
		ll memo = mpow(a,b/2);
		return memo*memo%MOD;
	}else{
		return mpow(a,b-1) * a % MOD;
	}
}

int main(void){
	ll n,m;cin>>n>>m;
	ll s,t;
	vector<ll> S,T;
	rep(i,n){
		cin>>s;
		S.push_back(s);
	}
	rep(i,m){
		cin>>t;
		T.push_back(t);
	}

	vector<vector<ll>> dp;
	rep(i,n){
		dp.push_back(vector<ll>());
		rep(j,m){
			dp[i].push_back(0);
		}
	}

	rep(i,n){
		ll rui = 0;
		rep(j,m){
			if(i>0) dp[i][j] = dp[i-1][j];
			if(T[j] == S[i]){
				dp[i][j] += rui + 1;
			}
			if(i==0) continue;
			rui += dp[i-1][j];
			rui %= MOD;
		}
	}

	ll ans = 0;

	/*rep(i,n){
		rep(j,m){
			cout<<dp[i][j]<<" ";

		}
		cout<<endl;
	}*/

	rep(j,m){
		ans += dp[n-1][j];
		ans %= MOD;
	}
	cout<<ans+1<<endl;

	return 0;
}


Measured memory_bytes: 32384
import itertools

N = int(input())

H = []
for n in range(N):
    A = int(input())
    tmp = []
    for a in range(A):
        tmp.append(list(map(int, input().split())))
    H.append(tmp)
ans = 0 
for pro in itertools.product([0, 1], repeat=N):
    flag = 0
    for p in range(len(pro)):
        if pro[p] != 0:
            for h in H[p]:
                if pro[h[0]-1] != h[1]:
                    flag = 1
                    break
        if flag == 1:
            break
        if p == len(pro) - 1:
            ans = max(ans, sum(pro))

print(ans)




Measured memory_bytes: 9176
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcdEx(ll a, ll b, ll *x, ll *y) {
    if (!a) {*x = 0; *y = 1; return b;}
    ll x1, y1, gcd = gcdEx(b % a, a, &x1, &y1); *x = y1 - (b / a) * x1; *y = x1; return gcd;
}
ll modI(ll b, ll m)      {ll x, y; gcdEx(b, m, &x, &y); return (x % m + m) % m;}
typedef pair<ll, ll>      pii;
typedef vector<ll>         vi;
typedef vector<pii>         vii;
typedef set<ll>            si;
typedef map<string, ll>    msi;
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
#define loop(i,b,n)           for(ll i=b;i<n;i++)
#define loopv(i,b,n,a)         for(ll i=b;i<n;i+=a)
#define loopr(i,b,n)           for(ll i=n;i>=0;i--)

#define sum(a)     ( accumulate ((a).begin(), (a).end(), 0ll))
#define mine(a)    (*min_element((a).begin(), (a).end()))
#define maxe(a)    (*max_element((a).begin(), (a).end()))
#define mini(a)    ( min_element((a).begin(), (a).end()) - (a).begin())
#define maxi(a)    ( max_element((a).begin(), (a).end()) - (a).begin())
#define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin())

#define start_routine() ll begtime = clock();
#define end_routine() ll endtime = clock(); \
                      cerr << "\n\n" << "Time elapsed: " << \
                      (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
                      return 0
#define mp                  make_pair
#define ff                  first
#define ss                  second
#define pb                  push_back
#define MOD                 1000000007
#define modA(a,b)           (((a%MOD)+(b%MOD))%MOD)
#define modS(a,b)           (((((a%MOD)-(b%MOD))%MOD)<0)?(ll)(MOD+((a%MOD)-(b%MOD))%MOD):(ll)(((a%MOD)-(b%MOD))%MOD))
#define modM(a,b)           (ll)((((ll)(a%MOD))*((ll)(b%MOD)))%MOD)
#define modD(a,b)           ((modI(b,MOD)*(a%MOD))%MOD)
ll modP(ll x, ll y)         {
    ll r = 1; x %= MOD; while (y > 0) {
        if (y & 1) {r = (r * x) % MOD;}
        y = y >> 1; x = (x * x) % MOD;
    } return r;
}
ll max(ll a, ll b) {return (a > b ? a : b);}
ll min(ll a, ll b) {return (a < b ? a : b);}
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << '\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " = " << arg1 << " | "; __f(comma + 1, args...);
}
ll gcd( ll a, ll b )
{
    if (b == 0)
    {
        return a;
    }
    else
    {
        return gcd( b, (a % b) );
    }
}
ll lcm (ll a, ll b)
{
    ll ans = (a  / gcd(a, b)) * b;
    return ans;
}

#define test int t;cin >>t;while(t--)
int main()
{

    ll n;
    cin >> n;
    n%=10;
    if (n == 3)
    {
        cout << "bon";
    }
    else if (n == 0 || n == 1 || n == 6 || n == 8)
        cout << "pon";
    else
        cout << "hon";
}

Measured memory_bytes: 3616
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define ll long long
int main(){
    ll n;
    cin >> n;
    ll i;
    ll a[n];
    for(i=0;i<n;i++){
      cin >> a[i];
    }
    sort(a,a+n);
    cout << a[n-1]-a[0];
    return 0;
}


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

using namespace std;

typedef long long ll;

int N, M;

vector<int> parent;
vector<vector<int>> adj;

vector<ll> down, up;
vector<vector<ll>> prefix, suffix;

void dfs_parent(int v, int u) {
    parent[v] = u;
    for (int w : adj[v])
        if (w != u)
            dfs_parent(w, v);
}

ll dfs_down(int v) {
    down[v] = 1;
    for (int w : adj[v])
        down[v] = down[v] * (1 + dfs_down(w)) % M;
    return down[v];
}

void bfs_up() {
    queue<int> q;
    q.push(0);
    while (!q.empty()) {
        int v = q.front();
        q.pop();
        up[v] = (up[v] + 1) % M;
        int n = adj[v].size();
        for (int i = 0; i < n; i++) {
            int w = adj[v][i];
            up[w] = up[v];
            up[w] = up[w] * prefix[v][i] % M;
            up[w] = up[w] * suffix[v][i + 1] % M;
            q.push(w);
        }
    }
}

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

    adj.resize(N);
    for (int i = 0; i < N - 1; i++) {
        int v, w;
        cin >> v >> w;
        v--, w--;
        adj[v].push_back(w);
        adj[w].push_back(v);
    }

    parent.resize(N);
    dfs_parent(0, 0);

    adj.assign(N, vector<int>());
    for (int v = 1; v < N; v++)
        adj[parent[v]].push_back(v);

    down.resize(N);
    dfs_down(0);

    prefix.resize(N);
    suffix.resize(N);
    for (int v = 0; v < N; v++) {
        int n = adj[v].size();
        prefix[v].assign(n + 1, 1);
        suffix[v].assign(n + 1, 1);
        for (int i = 0; i < n; i++)
            prefix[v][i + 1] = prefix[v][i] * (1 + down[adj[v][i]]) % M;
        for (int i = n; i > 0; i--)
            suffix[v][i - 1] = suffix[v][i] * (1 + down[adj[v][i - 1]]) % M;
    }

    up.resize(N);
    bfs_up();
    for (int v = 0; v < N; v++)
        cout << up[v] * down[v] % M << endl;
}


Measured memory_bytes: 23808
#include <stdio.h>
#define N 10000
void setDepth(int u,int d);
int setHeight(int u);
int getSibling(int u);
typedef struct{
  int p;
  int l;
  int r;
}Node;
 
Node T[N];
int n,D[N],H[N];
 
void setDepth(int u,int d){
  if(u == -1) return;
  D[u] = d;
  setDepth(T[u].l, d+1);
  setDepth(T[u].r, d+1);
}
 
int setHeight(int u){
  int h1=0, h2=0;
  if(T[u].l != -1) h1 = setHeight(T[u].l)+1;
  if(T[u].r != -1) h2 = setHeight(T[u].r)+1;
  return H[u]=(h1 > h2 ? h1 : h2);
}
 
int getSibling(int u){
  if(T[u].p==-1) return -1;
  if(T[T[u].p].l!=u && T[T[u].p].l!=-1) return  T[T[u].p].l;
  if(T[T[u].p].r!=u && T[T[u].p].r!=-1) return T[T[u].p].r;
  return -1;
}
 
int main(){
  int i,v,l,r,degree,root=0;
 
  scanf("%d",&n);
 
  for(i=0;i<n;i++) T[i].p = -1;
 
  for(i=0;i<n;i++){
    scanf("%d %d %d",&v,&l,&r);
    T[v].l = l;
    T[v].r = r;
    if(l!=-1) T[l].p = v;
    if(r!=-1) T[r].p = v;
  }
 
  for(i=0;i<n;i++){
    if(T[i].p==-1) root = i;
  }
 
  setDepth(root,0);
  setHeight(root);
 
  for(i=0; i<n; i++){
    printf("node %d: ",i);
    printf("parent = %d, ",T[i].p);
    printf("sibling = %d, ",getSibling(i));
    degree = 0;
    if(T[i].l != -1) degree++;
    if(T[i].r != -1) degree++;
    printf("degree = %d, ",degree);
    printf("depth = %d, ",D[i]);
    printf("height = %d, ",H[i]);
    if(T[i].p == -1) printf("root\n");
    else if(T[i].l == -1 && T[i].r == -1) printf("leaf\n");
    else printf("internal node\n");
  }
  return 0;
}

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

long long gcd(long long aaa,long long bbb) {
    if(bbb==0) {
        return aaa;
    }
    return gcd(bbb,aaa%bbb);
}

int main (){

    string s,tmp[25000000],tmpp;
    ll K,count=0,countt=0;
    map<string,ll>m;
    cin >> s >> K;
    ll tmppp = s.size();
    tmppp = min(tmppp,K);
    for(int i = 1; i <= tmppp; i++) {
        for(int j = 0; j <= s.size()-i; j++) {
            tmpp = s.substr(j,i);
            m[tmpp]++;
            if(m[tmpp] == 1) {
                tmp[count] = s.substr(j, i);
                count++;
            }
        }
    }
    sort(tmp,tmp+count);
    cout << tmp[K-1] << endl;

    return 0;
}


Measured memory_bytes: 197888
#include<iostream>
#include<cmath>

using  namespace std;

int main() {
	double xa, ya, xb, yb, xc, yc, xp, yp;
	while (cin >> xa >> ya >> xb >> yb >> xc >> yc >> xp >> yp) {
		/*外積で正負で判定する*/
		double one, two, three;
		one = (xc - xp)*(ya - yc) - (yc - yp)*(xa - xc);
		two = (xb - xp)*(yc - yb) - (yb - yp)*(xc - xb);
		three = (xa - xp)*(yb - ya) - (ya - yp)*(xb - xa);
		double t_one = abs(one), t_two = abs(two), t_three = abs(three);
		one = one / t_one;
		two = two / t_two;
		three = three / t_three;
		if (one == two && one == three && two == three) {

			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
}


Measured memory_bytes: 3136
#include <bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define eps 1e-9

typedef long long ll;

using namespace std;

const ll inf = 1e18;
const ll mod = 1e9+7;
const int N = 1e5+5;

int main()

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

    int n, x, maxi = 0, ans = 0;

    cin >> n;

    while (n--) {

    	cin >> x;

    	if (x >= maxi) ans++;

    	maxi = max(maxi, x);
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 256