akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

bool is_square(int n)
{
    for (int i = 0; i <= n; i++)
    {
        if (i * i == n)
        {
            return true;
        }
    }
    return false;
}

int main()
{
    int a, b;
    cin >> a >> b;
    for (size_t i = 0; i < 10000; i++)
    {
        if (i * 8 / 100 == a && i * 10 / 100 == b)
        {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize(2)
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <set>
#include <ctime>
using namespace std;
typedef long long ll;
#define inf 2147483647
#define IosF ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define N 200004
#define mod 1000000007

ll f[N];
int main() {
    IosF;
    f[0] = f[1] = f[2] = 0;
    for ( int i = 3; i <= 2000; ++ i )
        f[i] = 1;

    int n;
    cin >> n;
    for ( int i = 6; i <= n; ++ i ) 
    for ( int j = 3; j <= i; ++ j ) 
        f[i] = (f[i] + f[i - j]) % mod; 
    cout << f[n] << endl;
    // system("pause");
    return 0;
}

Measured memory_bytes: 3660
// Crt. 2019-12-17  18:29:20
#include <algorithm>
#include <iostream>
#include <cstdio>
#define N 503
using namespace std;

int n, m, ans[N][N];
char s[N][N];

int main() {
#ifdef LOCAL_JUDGE
    freopen("work.in", "r", stdin);
    freopen("work.out", "w", stdout);
#endif

    cin >> n >> m;
    for (int i = 1; i <= n; ++i)
        scanf("%s", s[i] + 1);

    for (int i = 1; i <= n; ++i)
        ans[i][1] = 1, ans[i][m] = 2;

    for (int i = 1; i <= n; ++i)
        for (int j = 2; j < m; ++j)
            ans[i][j] = i % 2 ? 1 : 2;

    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= m; ++j)
            if (s[i][j] == '#')
                ans[i][j] = 3;

    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j)
            if (ans[i][j] == 1 || ans[i][j] == 3) putchar('#');
            else putchar('.');
        putchar('\n');
    }

    cout << endl;

    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j)
            if (ans[i][j] == 2 || ans[i][j] == 3) putchar('#');
            else putchar('.');
        putchar('\n');
    }

    return 0;
}


Measured memory_bytes: 1920
package main

import "fmt"

func main() {
	var N int
	fmt.Scan(&N)
	for i := 1; i < 10; i++ {
		for k := 1; k < 10; k++ {
			if i*k == N {
				fmt.Println("Yes")
				return
			}
		}
	}
	fmt.Println("No")
}


Measured memory_bytes: 512
#include<stdio.h>
int main(){
	int N, a, c[1000010] = {};
	scanf("%d", &N);
	for(int i = 1; i <= N; i++){
		scanf("%d", &a);
		c[a]++;
	}
	int ans = 0;
	for(int i = 1; i <= 1000000; i++){
		if(c[i] == 0)
			continue;
		if(c[i] == 1)
			ans++;
		for(int j = 2; j * i <= 1000000; j++)
				c[j * i] = 0;
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 5612
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,n-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);

int main() {
	int Q;
	cin >> Q;
	
	REP(i, Q) {
		int N;
		cin >> N;

		int cnt = 0;
		while(N/10) {
			string str = toString(N);
			int tmp, max = 0;
			int size = str.size()-1;
			FOR(j, 1, size) {
				tmp = toInt(str.substr(0, j)) * toInt(str.substr(j));
				if(tmp > max) {
					max = tmp;
				}
			}
			N = max;
			cnt++;
		}

		cout << cnt << endl;
	}

	return 0;
}

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

#ifndef LOCAL
#define cerr dolor_sit_amet
#endif

#define mp make_pair
#define sz(x) ((int)((x).size()))
#define X first
#define Y second

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int , int > ipair;
typedef pair < ll , ll > lpair;
const int IINF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;
const double DINF = numeric_limits<double>::infinity();
const int MOD = 1000000007;
const double EPS = 1e-9;
const int DX[] = { 1,  0, -1,  0,  1, -1,  1, -1};
const int DY[] = { 0,  1,  0, -1,  1, -1, -1,  1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll sqr(ll x) { return x*x; } ll sqr(int x) { return (ll)x*x; }
double sqr(double x) { return x*x; } ld sqr(ld x) { return x*x; }
mt19937 mmtw(960172);
ll rnd(ll x, ll y) { static uniform_int_distribution<ll> d; return d(mmtw) % (y - x + 1) + x; }

// ========================================================================= //

const int N = 100179;

int n;
int a[N];
bool f[N];

int main() {
    ios::sync_with_stdio(false);

    cin >> n;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        f[i] = (x & (x-1));
        int y = 1;
        while (true) {
            if (y * 2 > x)
                break;
            y *= 2;
            ++a[i];
        }
    }

    int ans = 0;
    while (true) {
        int pans = ans;
        for (int i = 0; i < n; ++i) {
            if (f[i] || a[i]) {
                ++ans;
                int j = i;
                while (j < n - 1 && (i == j || a[j]) && (a[j+1] || f[j+1]))
                    ++j;
                if (a[i])
                    --a[i];
                else
                    f[i] = 0;
                if (i != j) {
                    if (a[j])
                        --a[j];
                    else
                        f[j] = 0;
                }
                for (int k = i+1; k < j; ++k)
                    --a[k];
                i = j;
            }
        }
        if (pans == ans)
            break;
    }
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 768
#include<iostream>
using namespace std;
#define MAX 100000
int parent(int i) { return i / 2; }
int left(int i) { return 2 * i; };
int right(int i) { return 2 * i + 1; };
int main() {
	int h, i, a[MAX + 1];
	cin >> h;
	for (i = 1; i <= h; i++)cin >> a[i];
	for (i = 1; i <= h; i++) {
		cout << "node " << i << ": key = " << a[i] << ", ";
		if (parent(i) >= 1)cout << "parent key = " << a[parent(i)] << ", ";
		if (left(i) <= h)cout << "left key = " << a[left(i)] << ", ";
		if (right(i) <= h)cout << "right key = " << a[right(i)] << ", ";
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3076
n = int(input())
a = list(map(int, input().split()))

ans = 1
r, g, b = 0, 0, 0

for x in a:
    ans *= [r, g, b].count(x)

    if r == x:r += 1
    elif g == x:g += 1
    elif b == x:b += 1

    else:
        print(0)
        exit()

ans %= 1000000007
print(ans)

Measured memory_bytes: 14056
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let s: Vec<char> = read::<String>().chars().collect();
    let year = &s[..4];
    let year_num: i64 = year.iter().collect::<String>().parse().unwrap();
    let month = &s[5..7];
    let month_num: i64 = month.iter().collect::<String>().parse().unwrap();
    let day = &s[8..10];
    let day_num: i64 = day.iter().collect::<String>().parse().unwrap();

    if year_num < 2019 {
        println!("{}", "Heisei");
        return;
    }
    if year_num > 2019 {
        println!("{}", "TBD");
        return;
    }

    if month_num < 4 {
        println!("{}", "Heisei");
        return;
    }

    if month_num > 4 {
        println!("{}", "TBD");
        return;
    }

    if day_num <= 30 {
        println!("{}", "Heisei");
        return;
    }
    if day_num > 30 {
        println!("{}", "TBD");
        return;
    }
}


Measured memory_bytes: 2116
// Code for A - Plural Form
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define FOR(i,x,y) for(ll i=x;i<(ll)(y);i++)

#define MOD 1000000007
#define mod(x) ( (x) % MOD + MOD ) % MOD

#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<typename T, typename U> void view(const std::map<T, U>& m){ for(const auto& e : m){ std::cout << e.first << "=>" << e.second << " "; } std::cout << std::endl; }

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

  if (S[S.length() - 1] == 's') {
    cout << S << "es" << endl;
  } else {
    cout << S << "s" << endl;
  }

  return 0;
}


Measured memory_bytes: 3620
using System;
class Program
{
	static void Main(string[] args)
	{
		string S = Console.ReadLine();
		string T = Console.ReadLine();   
        string X = "";
	    int len_S = S.Length;
	    int len_T = T.Length;
     	int len_ST = len_T - len_S;

      if(len_ST == 1)
      {  
  	    if(T.StartsWith(S))
    	{
        Console.WriteLine("Yes");
   		}
        else
        {
        Console.WriteLine("No");
        }
      }  
      else
      {
      Console.WriteLine("No");
      }
      
	}
}

Measured memory_bytes: 26196
use POSIX;
($N,$A,$B,@@)=glob`dd`;
$a=$%=1<<30;
map{
  $==$i=$a-$%;
  $=-=ceil(($-=$_-$B*$i)/($A-$B))for@@;
  $a-=$%*($=>=0);
  $%/=2;
  # print"$% $a $i $=$/";
}1..35;
print$i;

Measured memory_bytes: 28664
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
const int INF = 1<<30;
const ll MOD = 1000000007;

int main(void) {

    string s; cin >> s;
    int n = s.size(), m = 2019;
    reverse(s.begin(), s.end());
    int x = 1, tot = 0;
    vi cnt(m);
    ll ans = 0;
    rep (i, n) {
        // cout << tot << " " << ans << endl;
        cnt[tot]++;
        tot += (s[i]-'0')*x;
        tot %= m;
        ans += cnt[tot];
        x = x * 10 % m;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3672
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		int n = sc.nextInt();
		long[] a = new long[n*3];
		int index = 0;
		for(int i = 0; i < n; i++) {
			long x = sc.nextLong();
			a[index] = x;
			index++;
			a[index] = x-1;
			index++;
			a[index] = x+1;
			index++;
		}
		Arrays.sort(a);
		int ans = 0;
		long b = a[0];
		int count = 1;
		for(int i = 1; i < n*3; i++) {
			if(b == a[i]) {
				count++;
			}else {
				if(count > ans) {
					ans = count;
				}
				b = a[i];
				count = 1;
			}
		}
		System.out.println(ans);
	}

	static class FastScanner {
		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;
	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

	    public String next() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public String nextLine() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                return reader.readLine();
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }

	        return tokenizer.nextToken("\n");
	    }

	    public long nextLong() {
	        return Long.parseLong(next());
	    }

	    public int nextInt() {
	        return Integer.parseInt(next());
	    }

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

	    public int[] nextIntArray(int n) {
	        int[] a = new int[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextInt();
	        return a;
	    }

	    public long[] nextLongArray(int n) {
	        long[] a = new long[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextLong();
	        return a;
	    }
	}
}


Measured memory_bytes: 45464
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
     Scanner sc = new Scanner(System.in);
     int a = sc.nextInt();
     int b = sc.nextInt();
     if(a*b*1%2 != 0) {
    	 System.out.println("Yes");
     } else if(a*b*2%2 != 0) {
    	 System.out.println("Yes");
     } else if(a*b*3%2 != 0) {
    	 System.out.println("Yes");
     } else {
    	 System.out.println("No");
     }
     
     
      
      
    	  
      
    }
 }

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll a[114514],b[114514];
int main(){
	ll n,inf=1e15;
	cin>>n;
	b[n+1]=inf;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		b[i]=-inf;
	}
	ll ans=1;
	b[1]=a[1];
	b[0]=inf;
	b[n+1]=-inf;
	for(int i=2;i<=n;i++){
		if(b[ans]>=a[i]){
			ans++;
			b[ans]=a[i];
		}else{
			ll ng=0,ok=n+1;
			while(ok-ng>1){
				ll mid=(ok+ng)/2;
				if(b[mid]>=a[i])ng=mid;
				else ok=mid;
			}
			b[ok]=a[i];
		}
	}
	//for(int i=0;i<=5;i++)cout<<b[i]<<' ';
	cout<<ans;
	return 0;
}


Measured memory_bytes: 5152
loop do
	a = gets.split.map &:to_i
	break if a.inject(:+) == 0
	bo = a[0] * 5 + a[1] * 3
	lost = 3 * (a[5] - a[4]) - bo
	gain = a[0] * 15 + a[1] * 15 + bo * 15 + a[2] * 7 + a[3] * 2
	puts 100 + gain - lost
end



Measured memory_bytes: 6884
N, M = map(int, input().split())

ab_list = []
cd_list = []

for i in range(N):
    ab = list(map(int, input().split()))
    ab_list.append(ab)

for i in range(M):
    cd = list(map(int, input().split()))
    cd_list.append(cd)

for a, b in ab_list:
    num = -1
    min_num = 10 ** 10 + 1
    count = 0
    for c, d in cd_list:
        count += 1
        distance = abs(a-c) + abs(b-d)
        if distance < min_num:
            min_num = distance
            num = count
    print(num)

Measured memory_bytes: 3316
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <numeric>
#include <tuple>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
#define ALL(x)   (x).begin(),(x).end()
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define mp       make_pair
#define eb       emplace_back
typedef pair<LL, LL> P;
typedef pair<P, P> PP;

LL a[2020];

int main() {
	LL n, z, w;
	cin >> n >> z >> w;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	cout << max(abs(a[n - 1] - w), (n == 1 ? 0 : abs(a[n - 1] - a[n - 2]))) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define P pair<ll,ll>
#define ALL(a) (a).begin(),(a).end()
#define YESNO(i) if((i)) puts("YES");else puts("NO");
#define YesNo(i) if((i)) puts("Yes");else puts("No");
#define yesno(i) if((i)) puts("yes");else puts("no");
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a,b,c;cin>>a>>b>>c;
  YesNo(a==b&&b==c);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

struct Combination
{
	vector<ll> fact, inv, invFact;
	int MAX_FACT;
	ll MOD;
	Combination(int n, ll mod) : fact(n + 1), inv(n + 1), invFact(n + 1)
	{
		MAX_FACT = n + 1;
		MOD = mod;
		fact[0] = 1;
		fact[1] = 1;
		invFact[0] = 1;
		invFact[1] = 1;
		inv[1] = 1;
		for (auto i = 2; i < MAX_FACT; ++i)
		{
			fact[i] = fact[i - 1] * i % MOD;
			inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
			invFact[i] = invFact[i - 1] * inv[i] % MOD;
		}
	}

	unsigned long long calcCombination(int n, int k)
	{
		if (n < k)
		{
			return 0;
		}
		if ((n < 0) || (k < 0))
		{
			return 0;
		}

		return fact[n] * (invFact[k] * invFact[n - k] % MOD) % MOD;
	}
};

ll gcd(ll a, ll b)
{
	if (b == 0)
	{
		return a;
	}

	return gcd(b, a % b);
}

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

	auto mod = (ll)1e9 + 7;
	Combination c(N + 1, mod);

	map<pair<ll, ll>, int> m;
	auto zero = 0ll;
	auto zeroA = 0ll;
	auto zeroB = 0ll;
	for (auto i = 0; i < N; ++i)
	{
		if (A[i] == 0)
		{
			if (B[i] == 0)
			{
				++zero;
			}
			else
			{
				++m[{0, LLONG_MAX}];
			}
			continue;
		}
		else if (B[i] == 0)
		{
			++m[{LLONG_MAX, 0}];
			continue;
		}
		auto g = gcd(abs(A[i]), abs(B[i]));
		auto a = A[i] / g;
		auto b = B[i] / g;
		if (a < 0)
		{
			if (b < 0)
			{
				a = -a;
				b = -b;
			}
		}
		else if (b < 0)
		{
			a = -a;
			b = -b;
		}

		++m[{a, b}];
	}

	set<pair<ll, ll>> s;
	vector<pair<ll, ll>> list;
	for (auto& p : m)
	{
		list.push_back(p.first);
	}

	vector<vector<ll>> dp(2, vector<ll>());
	dp[0].push_back(1);
	dp[1].push_back(0);
	auto index = 0;
	for (auto& val : list)
	{
		if (s.find(val) != s.end())
		{
			continue;
		}

		auto a = val.second;
		auto b = val.first;
		if (a != LLONG_MAX && b != LLONG_MAX)
		{
			if (b < 0)
			{
				b = -b;
			}
			else
			{
				a = -a;
			}
		}

		auto op = make_pair(a, b);
		s.insert(op);

		auto num = m[val];
		auto temp = 0ll;
		for (auto i = 1; i <= num; ++i)
		{
			temp = (temp + c.calcCombination(num, i)) % mod;
		}
		auto sum = temp;
		num = m[op];
		if (num > 0)
		{
			temp = 0;
			for (auto i = 1; i <= num; ++i)
			{
				temp = (temp + c.calcCombination(num, i)) % mod;
			}
			sum = (sum + temp) % mod;
		}

		auto prevSum = (dp[0][index] + dp[1][index]) % mod;
		auto temp2 = sum * prevSum % mod;
		dp[0].push_back(temp2);
		dp[1].push_back(prevSum);
		++index;
	}

	auto ans = (*dp[0].rbegin() + *dp[1].rbegin() - 1 + mod) % mod;
	ans = (ans + zero) % mod;
	cout << ans << endl;

	return 0;
}

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

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

Node *root, *NIL;

void insert(int k) {
	Node *y = NIL;
	Node *x = root;
	Node *z;
	
	z = (Node *)malloc(sizeof(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(Node *u) {
	if(u == NIL) return;
	inorder(u->left);
	printf(" %d",u->key);
	inorder(u->right);
}
void preorder(Node *u) {
	if(u == NIL) return;
	printf(" %d",u->key);
	preorder(u->left);
	preorder(u->right);
}
	
int main(void) {
	int n, i, x;
	string com;
	scanf("%d",&n);
	
	for(i=0;i<n;i++) {
		cin >> com;
		if(com == "insert") {
			scanf("%d",&x);
			insert(x);
		} else if(com == "print") {
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
	}

	return 0;
}


Measured memory_bytes: 26720
#include<bits/stdc++.h>
using namespace std; 
int n,a[26],b[26];
int main()
{
	cin>>n;
	for(int i=0;i<26;i++)a[i]=100;
	for(int i=0;i<n;i++)
	{
		string s;
		cin>>s;
		memset(b,0,sizeof(b));
		for(int j=0;j<s.size();j++)b[s[j]-'a']++;
		for(int j=0;j<26;j++)a[j]=min(a[j],b[j]);
	}
	for(int i=0;i<26;i++)
	{
		for(int j=0;j<a[i];j++)cout<<(char)('a'+i);
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int a,b,c,d;
	
	scanf("%d %d %d", &a, &b, &c);
	
	if(a > b){
	    d = a;
	    a = b;
	    b = d;
	    
	    if(b > c){
	        d = b;
	        b = c;
	        c = d;
	        
	        if(a > b){
	            d = a;
	            a = b;
	            b = d;
	            
	            printf("%d %d %d\n", a, b, c);
	            
	        }else{
	            printf("%d %d %d\n", a, b, c);
	            
	        }
	   }else{
	            printf("%d %d %d\n", a, b, c);
	             
	        }
	        
	}else if(b > c){
	    d = b;
	    b = c;
	    c = d;
	    
	    if(a > b){
	        d = a;
	        a = b;
	        b = d;
	        
	        if(b > c){
	            d = b;
	            b = c;
	            c = d;
	            
	            printf("%d %d %d\n", a, b, c);
	        }else{
	            printf("%d %d %d\n", a, b, c);
	            
	        }
	        
	        }else{
	            printf("%d %d %d\n", a, b, c);
	            
	        }
	     
	}else{
	     printf("%d %d %d\n", a, b, c);
	    
	}
	
	return 0;
}



Measured memory_bytes: 2108
#include <iostream>
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <cmath>
#include <ctime>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector< vector<int> > vvi;
typedef vector<ll> vl;
typedef vector< vector<ll> > vvl;

#define forn(i, n) for (int i = 0; i < (int)(n); i++)
#define forv(i, v) forn(i, v.size())
#define all(v) v.begin(), v.end()
#define mp make_pair
#define pb push_back

int main() {
#ifdef NEREVAR_PROJECT
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    string s;
    cin >> s;
    set<char> p;
    forv(i, s) p.insert(s[i]);
    string dir = "SNEW";
    forn(i, 2) {
        int c = p.count(dir[i * 2]) + p.count(dir[i * 2 + 1]);
        if (c & 1) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
packs = [int(candies) for candies in input().split()]
N = int(len(packs))
X = 2
if sum(packs) % X == 0:
    A = int(sum(packs) / X) 
else: 
    print('No')
    exit()

dp = [[False] * (A + 1)] * (N + 1)
dp[0][0] = True

for i in range(N):
    for j in range(A+1):
        if dp[i][j]:
            dp[i+1][j] = dp[i][j]
        elif j >= packs[i]:
            dp[i+1][j] = dp[i][j - packs[i]]

if dp[N][A]:
    ans = "Yes"
else:
    ans = "No"

print(ans)

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x, n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair< int, int > P;
typedef pair< int, P > PP;

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

int n, m, s;
const int MOD = 100000;

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

    while(true) {
		cin >> n >> m >> s;
		if (n == 0) break;
		int dp[50][3010] = {};
		dp[0][0] = 1;
		for (int j = 1; j <= m; j++) {
			for (int i = n * n - 1; i >= 0; i--) {
				for (int k = s - j; k >= 0; k--) {
					if (dp[i][k] > 0) {
						dp[i + 1][k + j] += dp[i][k];
						dp[i + 1][k + j] %= MOD;
					}
				}
			}
	   	}
		cout << dp[n * n][s] << endl;
	}

    return 0;
}




Measured memory_bytes: 3824
#include <stdio.h>

int main(){
    
    int a, b, c;
    int k;
    int maior, menor;
    
    scanf("%d %d %d", &a, &b, &c);
    scanf("%d", &k);
    
    if (a>=b && a>=c) 
        maior = a;
    else if(b>=a && b>=c)
        maior = b;
    else
        maior = c;
        
    menor = a+b+c-maior;
    
    for(int i=0; i<k; i++){
        maior = 2*maior;
    }
    
    printf("%d", maior+menor);
    
    return 0;
}

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

int h,w;
int n;
int ma[110][110];
int a[11000];

int cmp(int i,int j)
{
    return i>j;
}

int main()
{
    scanf("%d%d",&h,&w);
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);

    int i=0,j=0;
    int k=1;
    int res=1;
    while(k<=n)
    {
        while(a[k])
        {
            if(j==w){
                i++;
                j=w-1;
                res=-1;
            }
            else if(j==-1)
            {
                i++;
                j=0;
                res=1;
            }
            ma[i][j]=k;
            j+=res;
            a[k]--;
        }
        k++;
    }
    for(int p=0;p<h;p++)
    {
        for(int q=0;q<w;q++)
        {
            printf("%d",ma[p][q]);
            if(q==w-1) printf("\n");
            else printf(" ");
        }

    }
}


Measured memory_bytes: 384
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2000000000;//10^9
ll MOD  = 1000000007;
double dp[3010][3010];



int main() {
    int N;
    cin >> N;
    vector<double> p(N);
    for(int i = 0; i < N; i++){
        cin >> p.at(i);
    }
    
    dp[0][0] = 1;
    for(int i = 1; i <= N; i++){
        for(int j = 0; j < 3010; j++){
            dp[i][j] = dp[i-1][j] * (1 - p.at(i-1)) + dp[i-1][j-1] * p.at(i-1);
        }
    }
    
    double ans = 0;
    for(int i = (N + 1) / 2; i <= N; i++){
        ans += dp[N][i];
    }
    
    cout << fixed << setprecision(10) << ans << endl;
    
}

Measured memory_bytes: 70784
#include<stdio.h>
int main()
{  int a[101][101];
   int i,n,t,k,p,j,u;
   scanf("%d",&n);
   k=n;
   for(i=0;i<n;i++)
     for(j=0;j<n;j++)
       a[i][j]=0;
   while(k)
   {  scanf("%d%d",&t,&p);
      t=t-1;
      for(i=0;i<p;i++)
      {  scanf("%d",&u);
         u=u-1;
         a[t][u]=1;
      }
      k--;
   }
   for(i=0;i<n;i++)
   {  for(j=0;j<n;j++)
      {  if(j)  printf(" ");
         printf("%d",a[i][j]);
	  }
      printf("\n");
   }
}


Measured memory_bytes: 2132
#include<stdio.h>

void swap(int *x, int *y)
{
    int temp = *x;
    *x = *y;
    *y = temp;
}

void sort(int *n1, int *n2, int *n3)
{
    if (*n1 > *n2) swap(n1, n2);
    if (*n2 > *n3) swap(n2, n3);
    if (*n1 > *n2) swap(n1, n2);
}

int main(void)
{
    int a, b, c;

    scanf("%d %d %d", &a, &b, &c);
    sort(&a, &b, &c);

    printf("%d %d %d\n", a, b, c);

    return 0;
}


Measured memory_bytes: 2124
#include <bits/stdc++.h>
using namespace std;
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; }
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int n;
vector<int> x, tmp;

void input(){
    cin >> n;
    for(int i=0;i<n;i++){
        int a;
        cin >> a;
        x.push_back(a);
        tmp.push_back(a);
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    sort(tmp.begin(), tmp.end());
    int med1 = tmp[n/2 - 1];
    int med2 = tmp[n/2];
    // cout << med1 << ' ' << med2 << endl;
    for(int i=0;i<n;i++){
        if(x[i] <= med1) cout << med2 << endl;
        else cout << med1 << endl;
    }
}

Measured memory_bytes: 3948
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

N, M = LI()

N -= 2
M -= 2
result = N*M
print(abs(result))


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

int n,m,a,b,c;

int main()
{
	scanf("%d%d",&n,&m);
	if(n%2==0) n--;
	a=n/2+1,b=n/2;
	for(int i=1;i*2<=a&&c<m;i++,c++)
	{
		printf("%d %d\n",i,a-i+1);
	}
//	cout<<a<<' '<<b<<endl;
	for(int i=1;i*2<=b&&c<m;i++,c++)
	{
		printf("%d %d\n",i+a,a+b-i+1);
	}
}

Measured memory_bytes: 3824
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
int main(){
  int n,l,a[1111111];
  cin>>n>>l;
  for(int i=0;i<n;i++)cin>>a[i];
  priority_queue<P> q;
  for(int i=0;i<n;i++){
    q.push(P(-a[i],i));
    if(i<l-1)continue;
    while(q.top().second<=i-l)q.pop();
    cout<<-q.top().first;
    if(i==n-1)cout<<endl;
    else cout<<" ";
  }
  return 0;
}



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

public class Main implements Runnable{
	int N,M;
	public void solve() {
		while(true){
			M = nextInt();
			N = nextInt();

			if(N + M == 0)break;
			boolean[] used = new boolean[7777777];
			int cnt = 0;
			for(int i = M;i < 7777777;i++){
				if(used[i])continue;
				if(!used[i]){
					if(cnt < N) cnt++;
					else {
						out.println(i);
						break;
					}
				}
				for(int j = i;j < 7777777;j+=i){
					used[j] = true;
				}
			}
		}
	}

	public static void main(String[] args) {
		new Thread(null,new Main(),"",32 * 1024 * 1024).start();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

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

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

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

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

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

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

	@Override
	public void run() {
		out.flush();
		new Main().solve();
		out.close();

	}
}

Measured memory_bytes: 56196
[a, b, h, m] = map(int, input().split(' '))
 
import math

long_n = math.radians(h * 30 + 30 * (m / 60))
short_n = math.radians(360 / 60 * m)
 
y1 = a * math.sin(long_n)
x1 = a * math.cos(long_n)
 
y2 = b * math.sin(short_n)
x2 = b * math.cos(short_n)
 
print(math.sqrt((x2 - x1) **2+ (y2 - y1) **2))

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

using namespace std;

long long _();
int main() { _(); return 0; }
#define main _
#define int long long 

int main()
{
    ios_base::sync_with_stdio(false);
    int k, n;
    cin >> k >> n;
    int t[n];
    for(int i=0; i<n; i++)
        cin >> t[i];
    int m = 0;
    for(int i=0; i<n; i++)
        m = max(m, min(abs(t[i]-t[(i+1)%n]), k-abs(t[i]-t[(i+1)%n])));
    cout << k - m << endl;
    return 0;
}

Measured memory_bytes: 1792
_, m = STDIN.gets.split(' ').map(&:to_i)

a = STDIN.gets.split(' ').map(&:to_i)

a.sort! { |i, j| j <=> i }

total = a.inject(:+).to_f

print (a[m-1] >= total / (4 * m)) ? 'Yes' : 'No'


Measured memory_bytes: 3836
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
    
    int N(0);
    cin >> N;
    
    do
    {
        if(N % 10 == 7)
        {
            cout << "Yes" << endl;
            return 0;
        }else
            N /= 10;
    }while(N > 0);
    
    cout << "No" << endl;
}


Measured memory_bytes: 3136
#include <bits/stdc++.h>
#define watch(x) cout <<(#x)<<" is "<<(x)<<endl
#define debug cout <<"hi"<<endl
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
int main(){
  int n; cin >>n; ll sum=0; 
  vector<int>c(n); vector<ll>v(n,0);
  for(int i=0; i<n; i++){
    int a; cin >>a;
    c[i]=a; v[a-1]++;
  }
  for(int i=0; i<n; i++) sum+=v[i]*(v[i]-1)/2;
  for(int i=0; i<n; i++){
    cout <<sum-v[c[i]-1]+1<<endl;
  }
return 0;}

Measured memory_bytes: 4992
/* 144a */
#include<stdio.h>
int main(void){
  int a,b,f;
scanf("%d %d",&a,&b);
if(a<10&&b<10){
  printf("%d\n",a*b);
 }
if(a>9||b>9){
  printf("-1\n");
 }
return 0;
}


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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};


int main()
{
  int k; cin >> k;
  if(k%2==0) {
    cout << (k/2)*(k/2) << endl;
  }
  else {
    cout << (k/2+1)*(k/2) << endl;
  }
}

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

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int dp[2][110];



int main(){
	int n;
	cin >> n;
	vector<vector<int> > v(2,vector<int>(n));
	for(int i=0;i<2;i++){
		for(int j=0;j<n;j++){
			cin >> v[i][j];
		}
	}
	dp[1][n-1] = v[1][n-1];
	for(int i=n-2;i>=0;i--){
		dp[1][i] = dp[1][i+1] + v[1][i];
	}
	dp[0][n-1] = v[0][n-1] + v[1][n-1];
	for(int i=n-2;i>=0;i--){
		dp[0][i] = max(dp[1][i],dp[0][i+1])+v[0][i];
	}
	cout << dp[0][0] << endl;
	return 0;
}

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

int evencalc(int a){
    int cnt = 0;
    while(a % 2 == 0){
        a /= 2;
        cnt++;
    }

    return cnt;
}

int main(){
    int n;
    long long ans = 0;
    cin>>n;

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

    for(int i=0; i<n; i++){
        if(a[i] % 2 == 0){
            ans += (evencalc(a[i]));
        }
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)
func abs(a int) int {
	if a<0 {
		return -a
	}
	return a
}

func main() {
	var n int
	fmt.Scan(&n)

	w := make([]int,n)
	sum := 0
	for i := 0; i < n; i++ {
		fmt.Scan(&w[i])
		sum += w[i]
	}

	s1, s2 := 0, sum
	ans := sum
	for i := 0; i < n; i++ {
		s1 += w[i]
		s2 -= w[i]
		if abs(s1-s2) < ans {
			ans = abs(s1-s2)
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        Integer a[] = new Integer[N];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
        }
        Arrays.sort(a, Comparator.reverseOrder());
        Integer sub = 0;
        for (int i = 0; i < N - 1; i++) {
            sub += a[i] - a[i + 1];
        }
        System.out.println(sub);
    }
}

Measured memory_bytes: 21844
#include<iostream>
#include<string>
using namespace std;
char c;
string T1, T2;
int p1, p2;

void recS( string &T, int &p ){
    for ( int i = 0; i < 2; i++ ){
	if ( T[p] == '(' ) {
	    if ( c == 'u' ) cout << '(';
	    p++; recS(T, p); p++;
	    if ( c == 'u' ) cout << ')';
	} else {
	    p++;
	}
	if ( i == 0 && c == 'u' ) cout << ',';
    }
}

void rec(){
    for ( int i = 0; i < 2; i++ ){
	if ( T1[p1] == '(' && T2[p2] == '(' ){
	    cout << '('; p1++; p2++;
	    rec();
	    p1++; p2++; cout << ')';
	} else if ( T1[p1] == '(' ){
	    if ( c == 'u' ) cout << "(";
	    p1++; recS( T1, p1); p1++;
	    p2++;
	    if ( c == 'u' ) cout << ")";
	} else if ( T2[p2] == '(' ){
	    if ( c == 'u' ) cout << "(";
	    p2++; recS( T2, p2); p2++;
	    p1++;
	    if ( c == 'u' ) cout << ")";
	} else {
	    p1++; p2++;
	}
	if ( i == 0 ) cout << ',';
    }
}

int main(){
    while( cin >> c ){
	cin >> T1 >> T2;
	p1 = p2 = 1;
	cout << '(' ; rec(); cout << ')' << endl;
    }
    return 0;
}

Measured memory_bytes: 0
def merge_sort(arr):
 if len(arr) <= 1:
  return arr
 mid = len(arr) // 2
# ここで分割を行う
 left = arr[:mid]
 right = arr[mid:]
# 再帰的に分割を行う
 left = merge_sort(left)
 right = merge_sort(right)
# returnが返ってきたら、結合を行い、結合したものを次に渡す
 return merge(left, right)
def merge(left, right):
 merged = []
 l_i, r_i = 0, 0
# ソート済み配列をマージするため、それぞれ左から見ていくだけで良い
 while l_i < len(left) and r_i < len(right):
    # ここで=をつけることで安定性を保っている
  if left[l_i][0] <= right[r_i][0]:
   merged.append(left[l_i])
   l_i += 1
  else:
   merged.append(right[r_i])
   r_i += 1

# 上のwhile文のどちらかがFalseになった場合終了するため、あまりをextendする
 if l_i < len(left):
  merged.extend(left[l_i:])
 if r_i < len(right):
  merged.extend(right[r_i:])
 return merged
import sys
input = sys.stdin.readline
N=int(input())
lst=[0]*N
for i in range(N):
 A,B= map(int,input().split())
 lst[i]=[B,A]
lsta=merge_sort(lst)
ans=0
t=0
for i in range(N):
 t+=lsta[i][1]
 if t>lsta[i][0]:
  ans+=1
if ans==0:
 print("Yes")
else:
 print("No")

Measured memory_bytes: 119760
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using VI = vector<int>;
using VVI = vector<VI>;


int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int n; cin >> n;
  string s; cin >> s;
  for (int i = 0; i < n; i++) {
    int t = 0;
    for (int j = 0; j < s.size(); j++) {
      if (s[j] == '(') t++;
      else t--;
      if (t < 0) {
        s = "(" + s;
        break;
      }
      if (t > 0 and j == s.size() - 1) {
        s = s + ")";
        break;
      }
    }
  }
  cout << s << '\n';
  return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define rp(i,c) rep(i,(c).size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e12,EPS=1e-9;

int h,w,d[100][100];
int nq,q[100][100];

int main()
{
	bool fst=1;
	while(scanf("%d",&h),h)
	{
		scanf("%d",&w); w++; h++;
		nq=0;
		rep(i,h)rep(j,w)
		{
			char in[9]; scanf("%s",in);
			if(in[0]=='?')d[i][j]=inf,q[i][j]=1,nq++;
			else d[i][j]=atoi(in),q[i][j]=0;
		}
		
		bool f=0;
		while(nq&&!f)
		{
			f=1;
			rep(i,h-1)
			{
				int p=-1,sum=0;
				rep(j,w-1)
				{
					if(d[i][j]==inf)p=p==-1?j:-2;
					else sum+=d[i][j];
				}
				if(p>=0)
				{
					d[i][p]=d[i][w-1]-sum;
					nq--; f=0; goto NEXT;
				}
			}
			rep(j,w-1)
			{
				int p=-1,sum=0;
				rep(i,h-1)
				{
					if(d[i][j]==inf)p=p==-1?i:-2;
					else sum+=d[i][j];
				}
				if(p>=0)
				{
					d[p][j]=d[h-1][j]-sum;
					nq--; f=0; goto NEXT;
				}
			}
			NEXT:;
		}
		
		if(!fst)puts(""); else fst=0;
		if(nq)puts("NO");
		else rep(i,h)rep(j,w)if(q[i][j])printf("%d\n",d[i][j]);
	}
	return 0;
}

Measured memory_bytes: 0
N, x = map(int, input().split())
As = list(map(int, input().split()))
As.append(0)

f = sum(As)
  
for i in range(0,N):
  if As[i]+As[i+1] > x:
    if As[i] <= x:
      As[i+1] = x - As[i]
    else:
      As[i+1] = 0
      As[i] = x

s = sum(As)

print(f-s)

Measured memory_bytes: 85704
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
// Welcome to my source code!

int main() {
    int n;
    cin >> n;
    int p[n], q[n], t[n];
    for (int i = 0; i < n; i++) {
        cin >> p[i];
        t[i] = p[i];
    }
    for (int i = 0; i < n; i++) cin >> q[i];
    sort(t, t+n);
    bool flag1, flag2, p_flag = false, q_flag = false;
    ll a = 0, b = 0, cnt = 0;
    do {
        cnt++;
        flag1 = true, flag2 = true;
        for (int i = 0; i < n; i++) {
            if (!p_flag && p[i] != t[i]) {
                flag1 = false;
            }
            if (!q_flag && q[i] != t[i]) {
                flag2 = false;
            }
        }
        if (!p_flag && flag1) {
            p_flag = true;
            a = cnt;
        }
        if (!q_flag && flag2) {
            q_flag = true;
            b = cnt;
        }
    } while (next_permutation(t, t+n));
    cout << abs(a - b) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int n,k,p[N];
int ismin[N];
int fa[N];
set<int> s;
int gf(int x) {
	return fa[x] == 0 ? x : fa[x] = gf(fa[x]);
}
void merge(int a,int b) {
	if (gf(a)!=gf(b)){
		fa[gf(a)]=gf(b);
	}
}
int bd;
int main() {
	// freopen("b.in","r",stdin);
	cin>>n>>k;
	for(int i=1;i<=n;i++)scanf("%d",&p[i]);
	for(int i=1;i<k;i++)s.insert(p[i]);
	int dz=1;
	for(int i=1;i+k-1<=n;i++){
		s.insert(p[i+k-1]);
		if (*s.begin() == p[i]) {
			ismin[i] = 1;
		}
		if (ismin[i - 1] && *s.rbegin() == p[i + k - 1]) {
			merge(i - 1, i);
		}
		dz=max(dz,i);
		while(dz<=n && p[dz+1]>p[dz])dz++;
		if(dz>=i+k-1){
			if(!bd)bd=i;
			else merge(bd,i);
		}
		s.erase(p[i]);
	}
	int ans=0;for(int i=1;i+k-1<=n;i++)if(gf(i)==i)ans++;
	cout<<ans<<endl;
}

Measured memory_bytes: 10368
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


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

	int K;
	cin >> K;
	K--;

	int A[32] = { 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 };

	co(A[K]);

	Would you please return 0;
}

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

int n, cnt;
unordered_map<string, int>mp;
vector<string>a;
int main() {
	cin >> n;
	rep(i, n) {
		string s;
		cin >> s;
		mp[s]++;
		cnt = max(cnt, mp[s]);
	}
	for (auto& p : mp) {
		if (p.second == cnt) {
			a.emplace_back(p.first);
		}
	}
	sort(all(a));
	for (auto& s : a) cout << s << endl;
}


Measured memory_bytes: 26692
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;
  vector<int> dp(n + 100);
  for (int i = 1; i <= n; i++) {
    if (s[i - 1] == 'o') dp[i] = dp[max(0, i - c - 1)] + 1;
    dp[i] = max(dp[i], dp[i - 1]);
  }
  vector<int> dpr(n + 100);
  for (int i = n; i >= 1; i--) {
    if (s[i - 1] == 'o') dpr[i] = dpr[min(n + 1, i + c + 1)] + 1;
    dpr[i] = max(dpr[i], dpr[i + 1]);
  }
  for (int i = 1; i <= n; i++) {
    if (dp[i - 1] + dpr[i + 1] < k) {
      cout << i << '\n';
    }
  }
  return 0;
}

Measured memory_bytes: 3348
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m; i<n; i++)
#define co(n) cout << n << endl
using namespace std;
int main(){
  int a, b, x;
  cin >> a >> b >> x;
  
  if(a+b<x || a>x) co("NO");
  else co("YES");
  
  return 0;
}


Measured memory_bytes: 256