akhauriyash/Code-Regression huggingface dataset:
n,k=map(int,input().split())
l=list(map(int,input().split()))
ans=n
def judge(m,li):
    ml=list(str(m))
    for i in ml:
        if int(i) in li:
            return True
    return False
while judge(ans,l):
    ans+=1
print(ans)
  

Measured memory_bytes: 40924
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String args[]) {
		FastScanner scanner = new FastScanner();
		int n=scanner.nextInt();
		int[] l=new int[n];
		for(int i=0;i<n;i++) {
			l[i]=scanner.nextInt();
		}
		Arrays.sort(l);
		int sum=0;
		for(int i=0;i<n-1;i++) {
			sum+=l[i];
		}
		System.out.println(sum>l[n-1]?"Yes":"No");
	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}


Measured memory_bytes: 21844
#include <stdio.h>

int main(void) {

  long n;
  scanf("%ld", &n);
  long a[n];
  for (long i = 0; i < n; i++) {
    scanf("%ld", &a[i]);
  }
  long plus = 0, minus = 0, sum = 0;
  for (long i = 0; i < n; i++) {
    sum += a[i];
    if (i%2 == 0) {
      if (sum <= 0) {
        plus += 1-sum;
        sum = 1;
      }
    } else {
      if (sum >= 0) {
        plus += sum+1;
        sum = -1;
      }
    }
  }
  sum = 0;
  for (long i = 0; i < n; i++) {
    sum += a[i];
    if (i%2 == 0) {
      if (sum >= 0) {
        minus += sum+1;
        sum = -1;
      }
    } else {
      if (sum <= 0) {
        minus += 1-sum;
        sum = 1;
      }
    }
  }
  long ans = plus;
  if (minus < ans) {
    ans = minus;
  }
  printf("%ld\n", ans);

  return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <string>
#include <numeric>
#include <queue>
#include <cstdio>
#include <cstring>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<n;++i)
#define mrep(i,n) for(ll i=n;i>=0;--i)
#define all(a) (a).begin(),(a).end()
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define pl pair<ll,ll>
#define inf 1001001001001001000
//#define mod 1000000007
#define mod 998244353
#define pi 3.1415926535
using namespace std;
struct __INIT {
	__INIT() {
		cin.tie(0);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(15);
	}
}__init;



int main(void) {
    ll n;
    cin>>n;
    vl c(n-1),s(n-1),f(n-1);
    rep(i,n-1){
        cin>>c[i]>>s[i]>>f[i];
    }
    rep(i,n-1){
        ll tim = s[i]+c[i];
        for(ll j = i+1;j<n-1;j++){
            if(tim <= s[j]) tim = s[j]+c[j];
            else tim = ceil((double)tim/f[j])*f[j]+c[j];
        }
        cout<<tim<<endl;
    }
    cout<<0<<endl;
    return 0;
}


Measured memory_bytes: 3608
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String a,b,c;
        a = sc.next();
        b = sc.next();
        c = sc.next();
        
        char al = a.charAt(a.length()-1);
        char bf = b.charAt(0);
        char bl = b.charAt(b.length()-1);
        char cf = c.charAt(0);
        
        if(al != bf){
            System.out.println("NO");
        }else{
            if(bl == cf){
                System.out.println("YES");
            }else{
                System.out.println("NO");
            }
        }
        
        
        
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;

long long f[100100];
void fanc() {
	f[0] = f[1] = 1;
	for (int i = 2; i < 100100; i++)
	{
		f[i] = f[i-1] * i % MOD;
	}
}

int main() {
	int N, M; cin >> N >> M;
	fanc();
	if(abs(N - M) >= 2) cout << "0" << endl;
	else if(abs(N - M) == 1) {
		long long res = f[N] * f[M] % MOD;
		cout << res << endl;
	}
	else {
		long long res = (f[N] * f[M] % MOD) * 2 % MOD;
		cout << res << endl;
	}
	return 0;
}


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

long long S;

int main() {
	cin >> S;
	long long A = 1000000000LL;
	long long D = ((S + A - 1) / A);
	long long C = 1LL;
	long long B = A * D - S;

	cout << "0 0 " << A << " " << B << " " << C << " " << D << " " << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstdlib>
using namespace std;

typedef long long LL;
const int N = 2005;
const LL mod = 1000000007LL;

int n, k;
LL dp[N][N], C[N][N], pref[N];

inline LL pow(LL x, LL exp) {
  if (exp < 0) return 1;
  LL res = 1;
  for (; exp; exp >>= 1, x = x * x % mod)
    if (exp & 1) res = res * x % mod;
  return res;
}

inline void pre() {
  for (int i = 0; i < N; i ++) {
    C[i][0] = 1;
    for (int j = 1; j <= i; j ++) {
      C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
      if (C[i][j] >= mod) C[i][j] -= mod;
    }
  }
}

inline LL DP() {
  pref[0] = 1;
  for (int i = 2; i <= n - 1; i ++) {
    for (int j = 1; j < i; j ++) {
      pref[j] = pref[j - 1] + dp[i - 1][j];
      if (pref[j] >= mod) pref[j] -= mod;
      dp[i][j] = pref[j];
    }
  }
  LL ans = 1;
  for (int i = 1; i <= k - 1; i ++) {
    ans += dp[n - 1][i];
    if (ans >= mod) ans -= mod;
  }
  return ans;
}

int main() {
  pre();
  scanf("%d%d", &n, &k);
  if (k == 1) return printf("%lld\n", pow(2LL, n - 2)), 0;
  if (k == 2) {
    LL ans = pow(2LL, n - k - 1) * (n - 1) % mod;
    return printf("%lld\n", ans), 0;
  }
  LL ans = DP();
  ans = ans * pow(2LL, n - k - 1) % mod;
  printf("%lld\n", ans);
  return 0; 
}


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

using namespace std;

vector<pair<int,int>>adj[100005];
vector<pair<int,int>>radj[100005];
vector<bool>visited(100005);
vector<bool>visited1(100005);
vector<tuple<int,int,int>>edges;

int n,m,p;

void dfs(int v)
{
    visited[v]=true;
    for(auto u:radj[v])
    {
        int vertex=u.first;
        if(!visited[vertex])
            dfs(vertex);
    }
}

void dfs1(int v)
{
    visited1[v]=true;
    for(auto u:adj[v])
    {
        int vertex=u.first;
        if(!visited1[vertex])
            dfs1(vertex);
    }
}

int main(){

    ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);  
  
  	cin>>n>>m>>p;
  
    for(int i=0;i<m;i++)
    {
        int a,b,w;
        cin>>a>>b>>w;
        w-=p; w*=-1;
        adj[a].push_back({b,w});
        radj[b].push_back({a,w});
        edges.push_back(make_tuple(a,b,w));
    }

    dfs(n);
    dfs1(1);

    vector<int>distance(n+1,2e9);
    distance[1]=0;

    for(int i=1;i<=n-1;i++)
    {
        for(auto e:edges)
        {
            int a,b,w;
            tie(a,b,w)=e;
            
            if(distance[a]+w<distance[b]){

                    distance[b]=distance[a]+w;

                    }
        }
    }

    int has_negative_cycle=0;

    for(int i=1;i<=n;i++)
    {
        for(auto e:edges)
        {
            int a,b,w;
            tie(a,b,w)=e;

            if(visited1[a]&&visited[a]&&visited[b]&&visited1[b]){

            if(distance[a]+w<distance[b]){
                    has_negative_cycle=1;
                    break;
                    }
            }
            else
                continue;
        }
    }
    if(has_negative_cycle)
        cout<<"-1"<<endl;
    else
        cout<<max(0,-distance[n])<<endl;
return 0;
}


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

int main() {
    int n;
    cin >> n;
    pair <int, int> pii[n];
    rep (i, n) pii[i] = make_pair(0, i + 1);

    rep (i, n * (n - 1) / 2) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        a--, b--;
        if (c == d) pii[a].first += 1, pii[b].first += 1;
        else        c > d ? pii[a].first += 3 : pii[b].first += 3;
    }

    sort(pii, pii + n);
    map <int, int> mp;
    int num = 1;
    rep (i, n) {
        num = i + 1;
        while(1) {
            if (i >= n) break;
            mp[pii[n - 1 - i].second] = num;
            if (pii[n - 1 - i].first == pii[n - 1 - i - 1].first) i++;
            else break;
        }
    }

    rep (i, n) cout << mp[i + 1] << endl;

    return 0;
}


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

int main() {
  int N;
  int p = 1,q = 1;
  bool pflag = true, qflag = true;
  
  cin >> N;
  vector<int> P(N);
  vector<int> Q(N);
  vector<int> C(N);
  for(int i=0;i<N;++i){
    cin >> P.at(i);
    C.at(i) = i+1;
  }
  for(int i=0;i<N;++i){
    cin >> Q.at(i);
  }
  if(C == P){
    p = 1;
    pflag = false;
  }
  if(C == Q){
    q = 1;
    qflag = false;
  }
  
  while(next_permutation(C.begin(),C.end())){
    if(pflag) p += 1;
    if(qflag) q += 1;
    if(C == Q) qflag = false;
    if(C == P) pflag = false;
  }
  
  cout << abs(p-q) << endl;
  return 0;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
#include <math.h>
#include<iostream>
#include <string>
using namespace std;
typedef long long ll;
#define pb pushback
#define fr(i,n) for(int i=0;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)


int main() {
    int x,y;
	cin >> x>> y;
    int ans;
    if(x-y>0)ans=x-y;
    else ans = 0;
      cout << ans << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
#define print(n) cout<<n<<endl
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vi vector<int>
#define vvl vector<vector<ll>>
#define vvi vector<vector<int>>
const int M=100111;
const int inf=1000000007;
const long long INF=1e18;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int ddx[8]={1,-1,0,0,1,-1,-1,1},ddy[8]={0,0,1,-1,1,-1,1,-1};

int main(){
	ll n,dam[M],mou[M];
	cin>>n;
	rep(i,1,n+1)cin>>dam[i];
	int cnt=0;
	rep(i,1,n+1){
		if(i%2==1)cnt+=dam[i];
		else cnt-=dam[i];
	}
	print(cnt);
	rep(i,1,n){
		int tmp=cnt/2;
		print((dam[i]-tmp)*2);
		cnt=(dam[i]-tmp)*2;
	}


}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
using ll=long long;
using ld=long double;
using namespace std;
const ll mod=1e9+7;
tuple<ll,ll,ll>x[110000];
main(){
  ll n,ans=0,t1,t2;
  cin>>n;
  rep(i,0,n){cin>>t1>>t2;x[i]=make_tuple(t1+t2,t1,t2);}
  sort(x,x+n,greater<tuple<ll,ll,ll>>());
  rep(i,0,n){
    if(i%2==0)ans+=get<0>(x[i]);
    ans-=get<2>(x[i]);
  }
  cout<<ans;
}

Measured memory_bytes: 2560
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = Integer.parseInt(sc.next());
		if(A >= 30) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}



Measured memory_bytes: 27024
"use strict";

function main(input) {
    input = input.split(" ").map(s => +s);
    const ia = input[0],
          ib = input[1],
          limit = ib * 100;

    let result = -1;
    for (let i = ib * 10; i < limit; i++) {
        let A = ~~(i * 0.08);
        let B = ~~(i * 0.1);
        if (A === ia && B === ib) {
            result = i;
            break;
        }
    }
    console.log(result);
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 11468
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

int main(){
    int n,m;cin>>n>>m;
    vvin ptj(100050);//part time job
    int a,b;
    rep(i,n){
        cin>>a>>b;
        ptj[a].push_back(b);
    }
    int ans=0;
    priority_queue<int> pq;//m-i日の時点で始めることのできる仕事の中で報酬が最大のものを取り出す
    rep2(i,1,m+1){
        if(ptj[i].size()){
            for(auto p:ptj[i])pq.push(p);
        }
        if(pq.size()){
            ans+=pq.top();
            pq.pop();
        }
    }
    cout<<ans<<endl;
}

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

using namespace std;

int main(){
    long long n;
    cin >> n;
    long long tmp = n;
    long long ans = 0;
    while(n > 0){
        ans += n % 10;
        n /= 10;
    }
    if(tmp % ans == 0)cout << "Yes";
    else cout << "No";
    return 0;

}


Measured memory_bytes: 256
import java.util.Collections;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		LinkedList<Double> list = new LinkedList<Double>();
		while(s.hasNext()){
			list.add(s.nextDouble());
		}
		Collections.sort(list);
		System.out.println(list.get(list.size()-1)-list.get(0));
	}

}

Measured memory_bytes: 27720
#!/usr/bin/env python3
n, l = map(int, input().split())
ans = 10**9
for i in range(n):
    c, t = map(int, input().split())
    if t <= l:
        ans = min(ans, c)
if ans == 10**9:
    print('TLE')
else:
    print(ans)


Measured memory_bytes: 9112
from bisect import bisect_right
from collections import defaultdict
import sys
read = sys.stdin.readline

s = read()[:-1]
t = read()[:-1]
# 即時終了
if set(t) - set(s):
    print(-1)
    exit()

# 前処理
# 0文字目から見たときにその文字が何文字目にあるかを記録しておく
mojiidx = defaultdict(lambda: [])
for i, ss in enumerate(s + s):
    mojiidx[ss].append(i)

# 本処理
# 最初にうまく飛べる点を探索
for i, ss in enumerate(s):
    if ss == t[0]:
        now = i
        break

for tt in t[1:]:
    idx = now % len(s)
    # 前処理の列から文字ttが何文字あとに出現するかを探索する
    ls = mojiidx[tt]
    tmp = ls[bisect_right(ls, idx)] - idx
    now += tmp
print(now + 1)

Measured memory_bytes: 53436
N,K=map(int,input().split())
d = [0]*K
A = [[]]*K
ps=[1]*N
for i in range(K):
    d[i] = int(input())
    A[i] = input().split()
    for j in range(len(A[i])):
        A[i][j] = int(A[i][j])


for i in range(K):
    for j in range(d[i]):
        ps[A[i][j]-1]=0

print(sum(ps))

Measured memory_bytes: 9280
#include<cstring>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<map>
#define N 100010
#define LL long long 
using namespace std;

int n,m,i;
char a[N],b[N];
LL L,x;
map <LL,char> f;

inline int gcd(int a,int b){return (b==0)?a:gcd(b,a%b);}

int main(){
//	freopen("zht.in","r",stdin);
//	freopen("zht.out","w",stdout); 
	scanf("%d%d",&n,&m);
	scanf("%s",&a);	scanf("%s",&b);
	if (a[0]!=b[0])	{
		printf("-1");
		return 0;
	}
	L=(LL)n*m/gcd(n,m);
//	cout<<L<<endl;
	x=L/n;
	for (i=1;i<n;i++)	f[(LL)i*x]=a[i];
	x=L/m;
	for (i=1;i<m;i++){
		if (f[(LL)i*x]>='a'&&f[(LL)i*x]<='z'&&f[(LL)i*x]!=b[i])	{
			printf("-1");	return 0;
		}
	}
	cout<<L<<endl;
	return 0;
}

Measured memory_bytes: 10880
N, M, Q = map(int, input().split())  #数字
Q = [list(map(int, input().split())) for i in range(Q)]  #数字複数列、複数行

A = []
for i in range(1,M+1):
    A.append(i)

B = []
import itertools
for i in itertools.combinations_with_replacement(A,N):
    B.append(i)

C = []
for i in range(len(B)):
    score = 0
    for j in range(len(Q)):
        if B[i][Q[j][1]-1] - B[i][Q[j][0]-1] == Q[j][2]:
            score += Q[j][3]
        C.append(score)

print(max(C))

Measured memory_bytes: 86784
/**
 🍪 the_hyp0cr1t3
 🍪 28.08.2020 22:49:51
**/
#ifdef Ws
#include "k_II.h"
#else
#include <bits/stdc++.h>
using namespace std;
#define aylmao cin.tie(nullptr)->sync_with_stdio(false);
#endif
#define endl '\n'
#define pb emplace_back
// #define int long long
#define sz(x) (int)((x).size())
#define all(x) x.begin(), x.end()

using ll = long long;
using pii = pair<int, int>;
const ll DESPACITO = 2e18;
const int INF = 2e9, MOD = 1e9+7;

const int N = 5000 + 5;
ll dp[N];

int32_t main() {
    aylmao
    int i, j, n, ans;
    cin >> n;
    vector<pii> a(n);
    for(i = 0; i < n; i++) 
        cin >> a[i].first >> a[i].second;
    sort(all(a), [](const pii& u, const pii& v) { 
        return u.first + u.second < v.first + v.second;
    });

    memset(dp, -1, sizeof(dp));
    dp[0] = 0;

    for(i = 0; i < n; i++) {
        for(j = n-1; ~j; j--) {
            if(dp[j] == -1 or a[i].first < dp[j]) continue;
            if(~dp[j+1]) dp[j+1] = min(dp[j+1], dp[j] + a[i].second);
            else dp[j+1] = dp[j] + a[i].second;
        }
    }
    for(i = 0; i <= n; i++) 
        if(~dp[i]) ans = i;
    cout << ans;
    return 0;
}

Measured memory_bytes: 3740
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {

		FastScanner sc = new FastScanner();
		int X=sc.nextInt();
		int A=sc.nextInt();
		int B=sc.nextInt();
System.out.println((X-A)%B);
	}
	//以下、自作ライブラリ

	//最大公約数
	public static long gcd(long a, long b) {
		if (a < b)
			return gcd(b, a);
		long c = 0;
		c = a % b;
		if (c == 0)
			return b;
		return gcd(b, c);
	}

	//最小公倍数
	public static long lcm(long m, long n) {
		return m * n / gcd(m, n);
	}

	//素数判定
	public static boolean isPrime(int n) {
		if (n < 2)
			return false;
		if (n == 2)
			return true;
		if (n % 2 == 0)
			return false;

		for (int i = 3; i * i <= n; i += 2) {
			if (n % i == 0)
				return false;
		}
		return true;
	}
}

//以下、高速スキャナークラス
class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 20692
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
	int n, m, ans = 0;
	cin >> n >> m;
	vector<pair<int, int>> a(m);
	for(int i = 0; i < m; i++){
		cin >> a[i].second >> a[i].first;
	}
	sort(a.begin(), a.end());
	int t = 0;
	for(int i = 0; i < m; i++){
		if(t <= a[i].second){
			ans++;
			t = a[i].first;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main{
public static void main (String[] args){
	Scanner sc = new Scanner(System.in);
	int p = sc.nextInt();
	int q = sc.nextInt();
	int r = sc.nextInt();
	int[] times = new int[3];
	times[0]=p+q;
	times[1]=q+r;
	times[2]=r+p;
	int min=0;
	for(int i=0;i<3;i++){
		if(i==0){
			min=times[0];
		}else{
			min=Math.min(min,times[i]);
		}
	}
	System.out.println(min);
	}
}

Measured memory_bytes: 21972
//vec[i]の範囲外エラー表示
#define _GLIBCXX_DEBUG
//includeとusing
#include <bits/stdc++.h>
using namespace std;
//型名省略
using ll = long long;
using st = string;
using vl = vector<long long>;
using vvl = vector<vector<long long>>;
using vc = vector<char>;
using vvc = vector<vector<char>>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using pll = pair<ll, ll>;
using pcc = pair<char, char>;
//定数
const ll INF = 1e9;
const ll MOD = 1e9+7;
const vl dx = {1,0,-1,0,1,0,-1,0};
const vl dy = {0,1,0,-1,0,1,0,-1};
//マクロ
#define rep(i,n) for(ll i = 0; i < (ll) n; i++)
#define rrep(i,n) for(ll i = (ll) n - 1; i >= 0;i--)
#define REP(i,x,n) for(ll i = (ll) x; i < (ll) n; i++)
#define RREP(i,x,n) for(ll i = (ll) n - 1; i >= x; i--)
#define each(i,A) for(ll i: (vl) A)
#define all(A) A.begin(), A.end()
#define Size(A) ll(A.size())
//入力
template<typename T> T input() {T x; cin >> x; return x;}
//正誤判定
void Yes(bool ans){cout << (ans? "Yes" : "No") << endl;}
void YES(bool ans){cout << (ans? "YES" : "NO") << endl;}
//余り切り上げ
ll ceil(ll a,ll b) {return (a + b - 1) / b;}
//最大値・最小値
template <typename T> bool chmax(T &a, const T& b) {if(a < b) {a = b; return true;} return false;}
template <typename T> bool chmin(T &a, const T& b) {if(a > b) {a = b; return true;} return false;}
//最大公約数
ll gcd(ll a,ll b){if(a<b)swap(a,b); if(a%b==0)return b; return gcd(b,a%b);}
//最小公倍数
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
//n乗の余り
ll modpow(ll x,ll n,ll mod){ll res=1;for(ll i=0;i<n;i++){res=res*x%mod;}return res;}
ll MODpow(ll x,ll n){ll res=1;for(ll i=0;i<n;i++){res=res*x%MOD;}return res;}


/*--------------------------------------------------------------------------*/

//main関数
int main() {
    ll n; cin >> n;
    vl d(n), e(n);
    rep(i,n){
        cin >> d[i] >> e[i];
    }
    bool flag = false;
    rep(i,n - 2){
        if(d[i] == e[i] && d[i + 1] == e[i + 1] && d[i + 2] == e[i + 2]) flag = true;
    }
    Yes(flag);
}


Measured memory_bytes: 3636
from itertools import product
n = int(input())
xys = []
for _ in range(n):
    a = int(input())
    tmp = []
    for _ in range(a):
        x, y = map(int, input().split())
        tmp.append((x-1, y))
    xys.append(tmp)

ans = 0
for people in product(range(2), repeat=n):
    isOK = True

    for i in range(n):
        if not people[i]:
            continue
        for x, y in xys[i]:
            if people[x] != y:
                isOK = False
                break

        if not isOK:
            break

    if isOK:
        ans = max(ans, sum(people))

print(ans)


Measured memory_bytes: 3064
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc=new Scanner(System.in);
		int X=sc.nextInt();
		int intgoukei;
		int happy1000;
		int happy5;

		BigDecimal bigX=BigDecimal.valueOf(X);
		BigDecimal gohyaku=BigDecimal.valueOf(500);
		BigDecimal bigresult=bigX.divide(gohyaku,0,RoundingMode.DOWN);

		int bigresult1=bigresult.intValue();

		int senresult=bigresult1*500;
		

		intgoukei=X-senresult;
		BigDecimal goukei=BigDecimal.valueOf(intgoukei);
			
		BigDecimal goen=BigDecimal.valueOf(5);
		BigDecimal goenresult=goukei.divide(goen,0,RoundingMode.DOWN);
		int goenresult1=goenresult.intValue();
		int goenresult2=goenresult1*5;
		
		int amari=X-(senresult+goenresult2);
		
		
		happy1000=bigresult1*1000;
		happy5=goenresult1*5;
		int happyX=happy1000+happy5;
		System.out.println(happyX);

	}

}


Measured memory_bytes: 22868
inputs = gets.strip.split(" ").map{|i| i.to_f}
a, b, c = inputs[0], inputs[1], inputs[2]
rad_c = (Math::PI / 180.0) * c 
d = Math.sqrt(a**2 + b**2 - 2*a*b*Math.cos(rad_c))
s = 0.5 * a * b * Math.sin(rad_c)
l = a + b + d
h = 2*s / a
puts s.floor(4)
puts l.floor(4)
puts h.floor(4)


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

int main()
{
    int n;
    int answer;
    cin >> n;
    if (n < 15) {
        answer = n * 800;
    } else if (n >= 15) {
        int temp = n / 15;
        answer = n * 800 - temp * 200;
    }
    cout << answer << endl;
    return 0;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!
a=int(input())
m=n=a
ans="Yay!"
for i in range(4):
    t=int(input())
    if(m<t):
        m=t
    elif(n<t):
        n=t
k=int(input())
if(m-n>k):
    ans=":("
print(ans)

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

int main(){
    ios_base::sync_with_stdio(false);
    long long n,a[1024];
    cin >> n;
    long long count = 0;
    for(long long i=0;i<n;i++){
        cin >> a[i];
    }
    for(long long i=0;i<10000000000;i++){
        for(long long j=0;j<n;j++){
            if(a[j]%2==0){
                a[j]=a[j]/2;
            }
            else if(a[j]%2==1){
                cout << count << endl;
                return 0;
            }
        }
        count++;
    }

    return 0;
}

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

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

int main() {
    int x;
    cin >> x;
    cout << ll(360 / gcd(360, x)) << endl;
}

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

int main()
{
    int n,i,temp;
    cin >> n;
    int ans = n,cnt = 0;
    for(i = 0;i <= n;++i){
        temp = i;
        while(temp){
            cnt += temp%6;
            temp /= 6;
        }
        temp = n-i;
        while(temp){
            cnt += temp%9;
            temp /= 9;
        }
        if(ans > cnt){
            ans = cnt;
        }
        cnt = 0;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
int main(void){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << ((abs(c-a) <= d || (abs(b-a) <= d && abs(c-b) <= d)) ? "Yes" : "No") << endl;
}

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

int h,n,a[1001],b[1001],k,m[30001]={0};
int main(){
scanf("%d%d",&h,&n);
for (int i=1;i<=n;i++){
	scanf("%d%d",&a[i],&b[i]);
}
for (int i=1;i<=h+10000;i++)
m[i]=2000000000;
	for (int j=0;j<=h;j++){
	for (k=1;k<=n;k++){
	if (m[j+a[k]]>m[j]+b[k]) m[j+a[k]]=m[j]+b[k];
	if (j+a[k]>h&&m[j+a[k]]<m[h]) m[h]=m[j+a[k]];
}
}
	printf("%d",m[h]);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;

bool conditions(string &s) {
    if (s[0] != 'A') {
        return false;
    }
    s[0] = 'a';

    int n = s.length();
    int cnt = 0;
    for (int i = 2; i <= n - 2; i++) {
        if (s[i] == 'C') {
            cnt++;
            s[i] = 'c';
        }
    }
    if (cnt != 1) {
        return false;
    }

    for (int i = 0; i < n; i++) {
        if (isupper(s[i])) {
            return false;
        }
    }

    return true;
}

int main() {
    string s; cin >> s;
    if (conditions(s)) {
        cout << "AC" << endl;
    } else {
        cout << "WA" << endl;
    }
    return 0;
}

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

using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

/*********** Constants ***********/
const auto INF = static_cast<ll>(1ll << 60);
const auto MOD = static_cast<ll>(1e9 + 7);
const auto NIL = -1;

/************* Utils *************/
struct Node {
    ll parent, left, right;
};

vector<Node> Tree;
vector<ll> Pre, In, Post;

void preorder(ll node) {
    if (node == NIL) {
        return;
    }
    Pre.push_back(node);
    preorder(Tree[node].left);
    preorder(Tree[node].right);
}

void inorder(ll node) {
    if (node == NIL) {
        return;
    }
    inorder(Tree[node].left);
    In.push_back(node);
    inorder(Tree[node].right);
}

void postorder(ll node) {
    if (node == NIL) {
        return;
    }
    postorder(Tree[node].left);
    postorder(Tree[node].right);
    Post.push_back(node);
}

/*********** Variables ***********/
ll N, ROOT;

/*********** Functions ***********/
bool init() {
    cin >> N;
    Tree.resize(N, Node{NIL, NIL, NIL});
    for (ll i = 0; i < N; i++) {
        ll id, left, right;
        cin >> id >> left >> right;
        Tree[id].left = left;
        Tree[id].right = right;
        Tree[left].parent = Tree[right].parent = id;
    }
    return true;
}

void solve() {
    for (ll i = 0; i < N; i++) {
        if (Tree[i].parent == NIL) {
            ROOT = i;
            break;
        }

    }
    preorder(ROOT);
    inorder(ROOT);
    postorder(ROOT);
}

void output() {
    cout << "Preorder" << endl;
    for (ll i = 0; i < Pre.size(); i++) {
        cout << " " << Pre[i];
    }
    cout << endl;
    cout << "Inorder" << endl;
    for (ll i = 0; i < In.size(); i++) {
        cout << " " << In[i];
    }
    cout << endl;
    cout << "Postorder" << endl;
    for (ll i = 0; i < Post.size(); i++) {
        cout << " " << Post[i];
    }
    cout << endl;
}

int main() {
    init();
    solve();
    output();
    return 0;
}


Measured memory_bytes: 3152
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)

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

	long long a = 2, b = 1;

	if (N == 1) cout << b << endl;
	else {
		REP(i, 1, N) {
			long long tmp = a + b;
			a = b;
			b = tmp;
		}

		cout << b << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int n;
int l[1000];

int main(){
        cin >> n;
        for (int i=0; i<n; i++)
                cin >>l[i];
        sort(l,l+n);

        int k = 0;
        for(int i=0;i<n-1;i++)
                k+=l[i];
        cout << (k > l[n-1] ? "Yes" : "No") << endl;


        return 0;
}


Measured memory_bytes: 256
#include<cstdio>
int main()
{
	int m1,d1,m2,d2;
	scanf("%d%d%d%d",&m1,&d1,&m2,&d2);
	if(m1==1||m1==3||m1==5||m1==7||m1==8||m1==10||m1==12)
	{
		if(d1==31)
		{
			if(m2==m1+1&&d2==1)
			printf("1\n");
			else
			printf("0\n");
		}
		else
		printf("0\n");
	}
	else if(m1==4||m1==6||m1==9||m1==11)
	{
		if(d1==30)
		{
			if(m2==m1+1&&d2==1)
			printf("1\n");
			else
			printf("0\n");
		}
		else
		printf("0\n");
	}
	else
	{
		if(d1==28)
		{
			if(m2==m1+1&&d2==1)
			printf("1\n");
			else
			printf("0\n");
		}
		else
		printf("0\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define N 200005
using namespace std;
int a[N],b[N],n;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%d",a+i),b[i]=a[i];
	sort(b+1,b+n+1);
	for(int i=1;i<=n;++i)
	{
		int l=1,r=n+1;
		while(r-l>1)
		{
			int mid=l+r>>1;
			if(b[mid]<=a[i])l=mid;
			else r=mid;
		}
		if(l>n/2)printf("%d\n",b[n/2]);
		else printf("%d\n",b[n/2+1]);
	}
	return 0;
}

Measured memory_bytes: 3712
n, k=map(int, input().split())
dic=[]

for i in range(k):
    d=int(input())
    a=list(map(int, input().split()))
    l=len(a)

    for j in range(l):
        if a[j] not in dic:
            dic.append(a[j])
        else:
            pass
    a.clear()

ans=n-len(dic)
print(ans)

Measured memory_bytes: 9212
/**/
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d;
int main(){
	ios::sync_with_stdio(false);
	cin>>a>>b>>c;
    if(b>=a){
        cout<<1<<endl;
        return 0; 
    }
    if(c>=b){
        cout<<-1<<endl;
        return 0;
    }
    if((a-b)%(b-c)>=1){
    	d=1;
	}
    cout<<((a-b)/(b-c)+d)*2+1<<endl;
	return 0;
}


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

const int LIMIT = 10000000;

char in[LIMIT], *p = in;

int nextInt(void) {
	
	register int res = 0;
	
	while (*p < '0' || *p > '9')++p;
	
	while (*p >= '0' && *p <= '9')
		res = res * 10 + *p++ - '0';
		
	return res;
	
}

#define N 105
#define M 2005
#define INF 10000007

#define min(x, y) (x < y ? x : y)

int n, m;
int dep[N], que[N];
int hd[N], nt[M], to[M], vl[M], tot;

__inline bool dinicBFS(void) {
	
	memset(dep, -1, n << 2), dep[0] = 0, que[0] = 0;
	
	for (register int lt = 0, rt = 1, top, i; lt < rt; )
		for (i = hd[top = que[lt++]]; ~i; i = nt[i]) 
			if (dep[to[i]] == -1 && vl[i] > 0)
				dep[que[rt++] = to[i]] = dep[top] + 1;
				
	return dep[n - 1] != -1;
	
}

int dinicDFS(int u, int f) {
	
	if (u == n - 1)return f;
	
	register int t = f, tmp;
	
	for (register int i = hd[u]; ~i; i = nt[i])
		if (dep[to[i]] == dep[u] + 1 && vl[i]) {
			tmp = dinicDFS(to[i], min(t, vl[i]));
			vl[i] -= tmp, vl[i ^ 1] += tmp, t -= tmp;	
		}
		
	return f - t;
	
}

signed main(void) {
	
	fread(p, 1, LIMIT, stdin);
	
	n = nextInt();
	m = nextInt();
	
	memset(hd, -1, n << 2), tot = 0;
	
	for (register int i = 0, x, y, w; i < m; ++i) {
		
		x = nextInt();
		y = nextInt();
		w = nextInt();
		
		nt[tot] = hd[x], to[tot] = y, vl[tot] = w, hd[x] = tot++;
		nt[tot] = hd[y], to[tot] = x, vl[tot] = 0, hd[y] = tot++;
		
	}
	
	register int maxFlow = 0, t;
	
	while (dinicBFS())
		while (t = dinicDFS(0, INF))
			maxFlow += t;
			
	printf("%d\n", maxFlow);
	
}

Measured memory_bytes: 3248
#include<cstdio>
#define LL long long
#define eps 1e-6
int main(){
	LL a,b,c;
	double d;
	scanf("%lld%lf",&a,&d);
	d+=eps;
	b=d*100;
	c=a*b/100;
	printf("%lld\n",c);
}

Measured memory_bytes: 1732
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,j=0,a[1000];
	cin>>n;
	//cout<<n<<endl;
	while(n>0)
	{
		a[j]=n%26;
		if(a[j]==0)
		{
			a[j]=26;
			n-=26;
		}
		
		n=n/26;
		//cout<<a[j]<<endl;
		j++;
		
	}
	
	for(int i=j-1;i>=0;i--)
	{
		if(a[i]==1)
		{
			cout<<"a";
		}
		else
		if(a[i]==2)
		{
			cout<<"b";
		}
		else
		if(a[i]==3)
		{
			cout<<"c";
		}
		else
		if(a[i]==4)
		{
			cout<<"d";
		}
		else
		if(a[i]==5)
		{
			cout<<"e";
		}
		else
		if(a[i]==6)
		{
			cout<< "f";
		}
		else
		if(a[i]==7)
		{
			cout<< "g";
		}
		else
		if(a[i]==8)
		{
			cout<< "h";
		}
		else
		if(a[i]==9)
		{
			cout<<"i" ;
		}
		else
		if(a[i]==10)
		{
			cout<<"j";
		}
		else
		if(a[i]==11)
		{
			cout<<"k";
		}
		else
		if(a[i]==12)
		{
			cout<< "l";
		}
		else
		if(a[i]==13)
		{
			cout<<"m";
		}
		else
		if(a[i]==14)
		{
			cout<< "n";
		}
		else
		if(a[i]==15)
		{
			cout<<"o";
		}
		else
		if(a[i]==16)
		{
			cout<< "p";
		}
		else
		if(a[i]==17)
		{
			cout<<"q" ;
		}
		else
		if(a[i]==18)
		{
			cout<<"r" ;
		}
		else
		if(a[i]==19)
		{
			cout<<"s" ;
		}
		else
		if(a[i]==20)
		{
			cout<< "t";
		}
		else
		if(a[i]==21)
		{
			cout<<"u" ;
		}
		else
		if(a[i]==22)
		{
			cout<<"v" ;
		}
		else
		if(a[i]==23)
		{
			cout<<"w";
		}
		else
		if(a[i]==24)
		{
			cout<<"x" ;
		}
		else
		if(a[i]==25)
		{
			cout<<"y";
		}
		else
		if(a[i]==26)
		{
			cout<<"z";
		}

	}
}


Measured memory_bytes: 3612
#dt = {} for i in x: dt[i] = dt.get(i,0)+1
import sys;input = sys.stdin.readline
inp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()]

x,k,d = ip()
if k*d <= abs(x):
    print(abs(x)-(k*d))
    exit()
if x < 0:
    n = abs(x)//d
    k -= n
    x += n*d
    if k%2:
        print(abs(x+d))
    else:
        print(abs(x))
elif x > 0:
    n = x//d
    x -= n*d
    k -= n
    if k%2:
        print(abs(x-d))
    else:
        print(abs(x))
else:
    if k%2:
        print(d)
    else:
        print(0)



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

int main()
{
  long long int i,j,n,k,m,mod=1000000007;
  cin>>n>>m;
  vector<vector<char>>inp(n+1,vector<char>(m+1));
  for(i=1;i<=n;i++)
    for(j=1;j<=m;j++)
     cin>>inp[i][j];
  vector<vector<long long int>>v(n+1,vector<long long int>(m+1,0));
  v[1][1]=1;
  for(i=1;i<=n;i++)
  {
   for(j=1;j<=m;j++)
   {
    if(i==1&&j==1)
     continue;
    if(inp[i][j]!='#')
     v[i][j]=(v[i-1][j]+v[i][j-1])%mod;
   }
  }
  cout<<v[n][m];
 return 0;
}

Measured memory_bytes: 12144
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll,ll> pll;
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
#define MOD 1000000007
#define ARRAY_MAX 100005

const int INF = 1e9+7;


int main(){

    int n,a,b,c,x;
    while(cin >> n >> a >> b >> c >> x,n|a|b|c|x){
        vector<int> y(n);
        for(int i = 0;i < n;i++){
            cin >> y[i];
        }
        int left = 0;
        int cnt = -1;
        while(left < n && cnt <= 10000){
            if(y[left] == x){
                left++;
            }
            x = (x*a+b)%c;
            cnt++;
        }
        if(cnt > 10000){
            cout << "-1" << endl;
        }else{
            cout << cnt << endl;
        }
    }



    return 0;
}


Measured memory_bytes: 3068
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
struct Node {
  int key;
  struct Node *right,*left,*parent;
};
 
struct Node *root,*NIL;
 
void insert(int k){
  struct Node *y = NIL;
  struct Node *x = root;
  struct Node *z;
 
  z =(struct Node*) malloc(sizeof(struct Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
 
  while(x != NIL){
    y = x;
    if( z-> key < x-> key){
      x = x->left;
    }else{
      x = x->right;
    }
  }
  z->parent = y;
  if( y == NIL){
    root = z;
  }
  else{
    if(z->key < y-> key){
      y->left = z;
    }
    else{
      y->right = z;
    }
  }
}
 
void inorder( struct Node *u){
  if(u == NIL)return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
 
void preorder(struct Node *u){
    if(u == NIL)return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}
 
int main(){
  int num,j,x;
  char c[6];
  scanf("%d", &num);

  for(j = 0;j<num;j++){
    scanf("%s",c);
    if(strcmp(c,"insert")==0){
      scanf("%d",&x);
      insert(x);
    }
    else if( strcmp(c,"print") == 0){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}



Measured memory_bytes: 25168
import numpy as np

H, W, K = map(int, input().split())
C = np.array([[i for i in input()] for j in range(H)])

ans = 0

for h_bit in range(1, 1 << H):
    for w_bit in range(1, 1 << W):
        h_count = []
        for i in range(H):
            if h_bit & (1 << i):
                h_count.append(i)

        w_count = []
        for j in range(W):
            if w_bit & (1 << j):
                w_count.append(j)
        if np.sum(C[np.ix_(h_count, w_count)] == "#") == K:
            ans += 1

print(ans)

Measured memory_bytes: 27192
#include<stdio.h>
int main(void){
	int h[1000],H,w[1000],W,a=0,i=0;
	for(;;){
		scanf("%d %d",&h[i],&w[i]);
		if(h[i]==0&&w[i]==0){
			break;
		}else{
			a++;
		}
		i++;
	}
	
	for(i=0;i<a;i++){
		for(H=0;H<h[i];H++){
			for(W=0;W<w[i];W++){
				printf("#");
				if(W==w[i]-1){
					printf("\n");
				}
			}
			if(H==h[i]-1){
				printf("\n");
			}
		}
	}
	return 0;
}


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

#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef long long int ll;

using namespace std;

int main() {
  int N, K;
  string S;
  cin >> N >> K >> S;
  vector<int> I({1});
  FOR(i, 1, N) {
    if (S[i] != S[i - 1]) I.push_back(i + 1);
  }

  int ans = 0;
  int r = I.size();
  REP(k, r) {
    int cnt;
    if (S[I[k] - 1] == '0') {
      cnt = (k + 2 * K >= r ? N + 1 : I[k + 2 * K]) - I[k];
    } else {
      cnt = (k + 2 * K + 1 >= r ? N + 1 : I[k + 2 * K + 1]) - I[k];
    }
    ans = max(ans, cnt);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;

void main_()
{
    ll N, M;
    cin >> N >> M;

    vector<pair<bitset<10>, int>> lamps(M); // pair: 繋がっているスイッチの番号、偶数か奇数か
    for (auto& l : lamps) {
        ll k;
        cin >> k;
        while (k--) {
            ll s;
            cin >> s;
            l.first.set(s - 1); // zero-origin
        }
    }

    for (auto& l : lamps) {
        cin >> l.second;
    }

    ll ans = 0;
    for (int i = 0; i < (1 << N); ++i) {
        if (all_of(begin(lamps), end(lamps),
                [bs = bitset<10>(i)](auto&& l) {
                    int on_switches_count = (l.first & bs).count();
                    return (on_switches_count % 2 == l.second);
                })) {
            ans++;
        }
    }
    cout << ans << "\n";
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 256
//Author : Sidiq Tri Pratikto
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(v) v.begin(), v.end()

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;
//order_of_key(x) = number of elements stricly smaller than x
//find_by_order(x) = return x-th largest element
typedef long long LL;
const LL MOD = 1e9 + 7;
const double PI = 2 * acos(0);

int main() {
	int A, B, C, D;
	scanf("%d%d%d%d", &A, &B, &C, &D);
	int cnt1 = C / B + (C % B != 0);
	int cnt2 = A / D + (A % D != 0);
	if (cnt1 <= cnt2) printf("Yes\n");
	else printf("No\n");
}

Measured memory_bytes: 3764
def check():
    N, M = map(int, input().split())
    edge = [[] for _ in range(N)]
    for i in range(M):
        a,b = map(int, input().split())
        edge[a-1].append(b-1)
        edge[b-1].append(a-1)
    for v in edge[0]:
        if N-1 in edge[v]:
            return 'POSSIBLE'
    return 'IMPOSSIBLE'
print(check())


Measured memory_bytes: 38320
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics; 

class _Class
{
  void _Do()
  {
    var N = Split.ints()[0];
    var Xs = Split.ints();

    //
    var X2 = new int[N];
    for (int i = 0; i < N; i++)
      X2[i] = Xs[i];

    Array.Sort(X2);
    int m1 = X2[N / 2-1];
    int m2 = X2[N / 2 ];

    //
    for (int i = 0; i < N; i++)
    {
      if (Xs[i] <= m1)
        Console.WriteLine(m2);
      else
        Console.WriteLine(m1);
    }
  }

  //
  static void Main(string[] args)
  {
    _(args);
    new _Class()._Do();
  }
  [Conditional("DEBUG")]
  static void _(string[] args)
  {
    if (args.Length != 0 && File.Exists(args[0]))
      Console.SetIn(new StreamReader(args[0]));
    else
      Console.Error.WriteLine("in");
  }
}

static class Split
{


  // 1
  public static string[] strings()
  {
    return Console.ReadLine().Split();
  }


  // [2.1] -2,147,483,648 ~ +2,147,483,647
  public static int[] ints()
  {
    var _s = Console.ReadLine().Split();

    var x = new int[_s.Length];
    for (var i = 0; i < _s.Length; i++)
      x[i] = int.Parse(_s[i]);

    return x;
  }

  // [2.2] 
  // -9,223,372,036,854,775,808 ~ 
  // +9,223,372,036,854,775,807
  public static long[] longs()
  {
    var _s = Console.ReadLine().Split();

    var x = new long[_s.Length];
    for (var i = 0; i < _s.Length; i++)
      x[i] = long.Parse(_s[i]);

    return x;
  }

  public static double[] doubles()
  {
    var _s = Console.ReadLine().Split();

    var x = new double[_s.Length];
    for (var i = 0; i < _s.Length; i++)
      x[i] = double.Parse(_s[i]);

    return x;
  }

  public static BigInteger[] bigs()
  {
    var _s = Console.ReadLine().Split();

    var x = new BigInteger[_s.Length];
    for (var i = 0; i < _s.Length; i++)
      x[i] = BigInteger.Parse(_s[i]);

    return x;
  }
}

Measured memory_bytes: 38652
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <cstdint>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
using ll = int64_t;
using ull = uint64_t;

constexpr ll INF = 1000000000;/* 1e+9a */

void solve(istream &cin) {
    ll N;
    if (!(cin >> N)) { return; }
    ll K;
    cin >> K;
    for (int i = 0; i < N; i+=2) {
        K--;
    } // end i
    cout << (K <= 0 ? "YES" : "NO") << endl;
}

int main(int argc, char *argv[]) {
    string FileName("A"), Modifier("MEPH_");
    string ExecutionName = Modifier + FileName;
    string sub(argv[0]);
    // /home/USER/.../MEPH_X -> MEPH_X
    if (sub.size() > ExecutionName.size())
        sub = sub.substr(sub.size() - ExecutionName.size(), ExecutionName.size());

    cout << setprecision(16) << scientific;
    if (sub != ExecutionName) {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        while (cin) { solve(cin); }
    } else {
        cerr << sub << " test" << endl;
        string inFile = FileName + ".txt";
        auto fs = fstream(inFile, fstream::in);
        while (fs) { solve(fs); }
    }
}


Measured memory_bytes: 256
import numpy as np
from numba import njit
from bisect import *
n, m = map(int, input().split())
A, B, C = zip(*(map(int, input().split()) for _ in range(n)))
D, E, F = zip(*(map(int, input().split()) for _ in range(m)))
X = sorted(set(C))
Y = sorted(set(D))
H = len(Y)-1
W = len(X)-1
def TX(i):
    return bisect(X, i)-1
def TY(i):
    return bisect(Y, i)-1
U = np.ones((H+1, W))
for d, e, f in zip(D, E, F):
    #d, e, f = TY(d), TX(e), TX(f)
    d = TY(d)
    e = bisect_left(X, e)
    f = bisect_right(X, f)-1
    U[d, e:f] = False
L = np.ones((H, W+1))
for a ,b, c in zip(A, B, C):
    #a, b, c = TY(a), TY(b), TX(c)
    c = TX(c)
    a = bisect_left(Y, a)
    b = bisect_right(Y, b)-1
    L[a:b, c] = False
S = np.outer(np.diff(Y), np.diff(X))
@njit
def dfs(i, j):
    s = [(i,j)]
    v = np.zeros((H,W))
    r = 0
    while s:
        i, j = s.pop()
        if not (0<=i<H and 0<=j<W):
            return -1
        if v[i,j]:
            continue
        v[i,j] = True
        r += S[i,j]
        if U[i,j]:
            s.append((i-1,j))
        if U[i+1,j]:
            s.append((i+1,j))
        if L[i,j]:
            s.append((i,j-1))
        if L[i,j+1]:
            s.append((i,j+1))
    return r
r = dfs(TY(0), TX(0))
print('INF' if r<0 else r)

Measured memory_bytes: 209696