akhauriyash/Code-Regression huggingface dataset:
import sys
import math

from collections import defaultdict
from collections import deque
def load(vtype=int):
    return vtype(input().strip())
def load_list(seplator=" ", vtype=int):
    return [vtype(v) for v in input().strip().split(seplator)]
def exit():
    import sys
    sys.exit(0)
def perm_sub(li, used):
    if len(li) == len(used):
        return [deque()]
    k = []
    for i in range(len(li)):
        if i in used:
            continue
        used.add(i)
        sub_list = perm_sub(li, used)
        for sub in sub_list:
            sub.appendleft(li[i])
        k.extend(sub_list)
        used.discard(i)
    return k
def perm_li(li):
    return perm_sub(li, set())
def perm_n(n):
    return perm_sub(list(range(n)), set())
def join_i(li, sep=""):
    return sep.join([str(e) for e in li])
def li2n(li):
    n, base = 0, 1
    for i in range(len(li)-1, -1, -1):
        n += li[i] * base
        base *= 10
    return n
def sli2ili(li):
    return [int(s) for s in li] 
def prime_list(n):
    li = [i for i in range(2, n+1)]
    for i in range(len(li)):
        if li[i] >= int(math.sqrt(n)):
            break
        if li[i] == -1:
            continue
        for j in range(i+1, len(li)):
            if li[j] % li[i] == 0:
                li[j] = -1
    return [n for n in li if n != -1]
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while True:
        r = a % b
        if r == 0: return b
        a, b = b, r
def lcm(a, b):
    return int(a * b / gcd(a,b))
def all_subset(li):
    s = []
    n = len(li)
    for bit in range(0, (1<<(n+1))):
        ss = set()
        for i in range(0, n):
            if (bit & (1 << i)):
                ss.add(li[i])
        s.append(ss)
    return s
def factorial(n):
    if n == 1:
        return 1
    return n * factorial(n-1)
def mCn(m, n):
    def factorial_ntimes(m, n):
        r = 1
        while n:
            r *= m
            m -= 1
            n -= 1
        return r
    return int(factorial_ntimes(m, n) / factorial(n))

s = load(str)

n = len(s)

s1 = ["0" for _ in range(n)]
s2 = ["1" for _ in range(n)]

def hanten(c):
    if c == "0":
        return "1"
    return "0"

for i in range(1, n):
    s1[i] = hanten(s1[i-1])
    s2[i] = hanten(s2[i-1])

ans1 = 0
ans2 = 0
for i in range(0, n):
    if s[i] != s1[i]:
        ans1 += 1
    if s[i] != s2[i]:
        ans2 += 1

print(min(ans1, ans2))

        

Measured memory_bytes: 46324
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cout << #x " = " << (x) << '\n';
#define P(x) cout << #x << '\n';    
#define int long long
typedef pair<int, int> pii;
const int mod = 1000000007;

int mcl(int a, int b)
{
	return a * b / __gcd(a, b);
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(9);
	#ifdef LOCAL_DEFINE
		freopen("in.txt", "rt", stdin);
	#endif
	
	int n, m;
	cin >> n >> m;
	m *= 2;
	vector<int> a(n);
	for(int &x : a)
		cin >> x;
	int lcm = a[0];
	for(int &x : a)
		lcm = mcl(lcm, x);
	bool ok = true;
	for(int &x : a)
		if((lcm / x) % 2 == 0)
			ok = false;
	int till = m / lcm;
	if(ok)
		cout << (till + 1) / 2 << '\n';
	else
		cout << "0\n";
	return 0;
}






Measured memory_bytes: 1024
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.16f\n", a)//少数出力
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>

using ll = long long;

const int INF = 1073741823;
const int MINF = -1073741823;
const ll LINF = ll(4661686018427387903);
const ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

/*-----------------------------------------ここからコード-----------------------------------------*/

int main() {
	
	int a, b, c, d;
	scanf("%d%d%d%d", &a, &b, &c, &d);
	int x = c - a, y = d - b;
	printf("%d %d %d %d\n", c - y, d + x, a - y, b + x);

}

Measured memory_bytes: 384
#include <iostream>
#include <set>

using namespace std;

int main(void){
  int a,b,c;
  cin >> a >> b >> c;
  int flag = 0;
  set<int> set_int;
  int x = a;
  while(true){
    if(x%b==c){
      flag = 1;
      break;
    }else if(set_int.count(x%b) != 0){
      break;
    }
    set_int.insert(x%b);
    x += a;
  }
  if(flag == 0){
    cout << "NO" << endl;
  }else{
    cout << "YES" << endl;
  }
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

money = 0

last = 0
for a in A:
    money += abs(last - a)
    last = a
money += abs(last)

for i in range(N):
    if i == 0:
        t1 = A[i]
        t2 = A[i + 1]
        if int(t1 >= 0) ^ int(t2 >= 0):
            print(money - abs(t1) * 2)
        elif abs(t1) > abs(t2):
            print(money - abs(t1 - t2) * 2)
        else:
            print(money)

    elif i == N - 1:
        t1 = A[i]
        t2 = A[i - 1]
        if int(t1 >= 0) ^ int(t2 >= 0):
            print(money - abs(t1) * 2)
        elif abs(t1) > abs(t2):
            print(money - abs(t1 - t2) * 2)
        else:
            print(money)

    else:
        a0 = A[i - 1]
        a1 = A[i]
        a2 = A[i + 1]
        if (a0 <= a1 and a1 <= a2) or (a0 >= a1 and a1 >= a2):
            print(money)
        elif (a0 <= a2 and a2 <= a1) or (a0 >= a2 and a2 >= a1):
            print(money - abs(a2 - a1) * 2)
        else:
            print(money - abs(a1 - a0) * 2)

Measured memory_bytes: 20576
#include<bits/stdc++.h>
using namespace std;
 
int main(){
	int a[4][3][10];
	for(int h=0;h<4;h++){
			for(int i=0;i<3;i++){
				for(int j=0;j<10;j++){
					a[h][i][j]=0;
				}
			}	
		}
	int b;
	cin>>b;
	for(int c=0;c<b;c++){
		int d,e,f,g;
		cin>>d>>e>>f>>g;
		d--;e--;f--;
		a[d][e][f]+=g;
		}
		for(int h=0;;h++){
			for(int i=0;i<3;i++){
				for(int j=0;j<10;j++){
					cout<<" "<<a[h][i][j];
					}
					cout<<endl;
				}
				if(h==3)break;
	        		cout<<"####################"<<endl; 
			}	
}

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

#define ll long long
#define ld long double

using namespace std; 
void solve(); 
int main() 
{ 
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
  
    int t = 1; 
    // cin >> t; 
    while (t--) { 
        solve(); 
    } 
  
    cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl; 
    return 0; 
} 

void solve() 
{ 
	int n, m, c;
    cin >> n >> m >> c;

    int temp;
    vector<int> b;
    for (int i = 0; i < m; i++) {
        cin >> temp;
        b.push_back(temp);
    }

    int count = 0;
    int sum = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> temp;
            sum += b[j] * temp;
        }


        if (sum + c > 0) {
            count++;
        }
        sum = 0;
    }

    cout << count << "\n";
}

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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

struct Data{
  ll b,l,u;
  ll value;
  ll sum;
};


int main(){
  ll n,x;
  cin >> n >> x;

  ll aoki = 0;

  vector<Data> v(n);

  rep(i,n){
    cin >> v[i].b >> v[i].l >> v[i].u;

    aoki += v[i].b * v[i].l;
    v[i].value = (x * v[i].u) - (v[i].u - v[i].l) * v[i].b;
  }

  sort(all(v), [&](Data a,Data b){
    return a.value > b.value;
  });

  ll mini = 1e15;

  rep(i,n){
    if(i==0) v[i].sum = v[i].value;
    else v[i].sum = v[i].value + v[i-1].sum;
  }

  rep(i,n){
    int left = -1;
    int right = n-1;
    ll s = aoki;
    while(abs(right - left) > 1){
      int mid = (left + right)/2;
      ll a = v[mid].sum;
      if(mid >= i) a-= v[i].value;
      if(a >= aoki) right = mid;
      else{
        left = mid;
        s = aoki - a;
      }
    }
    if(left >= i) left--;
    left++;
    ll a = x * left;
    rep(j,2){
      ll tmp;
      if(j == 0) tmp = v[i].l;
      else tmp = v[i].u;
      s += (tmp-v[i].l)*v[i].b;
      ll b =(s+tmp-1)/tmp;
			if(b <= x) mini = min(mini,a+b);
    }
  }
  cout << mini << "\n";
}


Measured memory_bytes: 4096
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n, m, a[100007], b[100007], c[100007], l[100007], f[100007], dp[100007], sum[100007];
vector<int>e[100007], s[100007];
bool vis[100007];
int read()
{
	int num = 0;
	char c = getchar();
	while (c < '0' || c>'9')c = getchar();
	while (c >= '0' && c <= '9')num = num * 10 + c - '0', c = getchar();
	return num;
}
int cmp(int a, int b)
{
	return c[a] < c[b];
}
int find(int x)
{
	if (f[x] == x)return x;
	return f[x] = find(f[x]);
}
int dfs(int w)
{
	sum[w] = b[w];
	for (int i = 0, lim = s[w].size(); i < lim; i++)
		dfs(s[w][i]), sum[w] += sum[s[w][i]];
	dp[w] = sum[w] + c[w];
	for (int i = 0, lim = s[w].size(); i < lim; i++)
		dp[w] = min(dp[w], sum[w] - sum[s[w][i]] + max(c[w], dp[s[w][i]]));
	return 0;
}
signed main()
{
	n = read();
	m = read();
	for (int i = 1; i <= n; i++)
	{
		a[i] = read();
		b[i] = read();
		c[i] = max(a[i] - b[i], 0LL);
		l[i] = f[i] = i;
	}
	for (int i = 1; i <= m; i++)
	{
		int a = read(), b = read();
		e[a].push_back(b);
		e[b].push_back(a);
	}
	sort(l + 1, l + n + 1, cmp);
	for (int i = 1; i <= n; i++)
	{
		int x = l[i];
		vis[x] = 1;
		for (int j = 0, lim = e[x].size(); j < lim; j++)
			if (x != find(e[x][j]) && vis[e[x][j]])
				s[x].push_back(find(e[x][j])), f[find(e[x][j])] = x;
	}
	dfs(l[n]);
	cout << dp[l[n]] << endl;
	return 0;
}

Measured memory_bytes: 19832
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<string>
#include<cmath>
#include<cstdio>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repn(i, n) for(int i = 1; i <= n; i++)
#define repr(i, n) for(int i = n-1; i >=0; i--)
#define lint long long
#define all(x) (x).begin(), (x).end()

const lint MOD = 1000000007;

int main(){
    int N; cin>>N;
    int arr[100005]={};
    lint ans = 1;
    rep(i,N){
        int A; cin>>A;
        int k,l;
        if(A==0) k = 3;
        else k = arr[A-1];
        l = arr[A];
        if (k <= l) { ans = 0; break; }
        ans *= k-l;
        ans %= MOD;
        arr[A]++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1272
#include<bits/stdc++.h>
#include<string>
#include<cctype> 
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
 
int main(){
 
  int H,W;
  cin >> H >> W; 
  char a[H][W];
  rep(i,H){
    rep(j,W){
      cin >> a[i][j];
    }
  }

  char b[H+2][W+2];
  int i,j;
  
  rep(i,H+2){
    rep(j,W+2){
      b[i][j]='#';
    }
  }

  for(i=1;i<H+1;i++){
    for(j=1;j<W+1;j++){
      b[i][j]=a[i-1][j-1];
    }
  }

  rep(i,H+2){
    rep(j,W+2){
      cout << b[i][j];
    }
    cout << '\n';
  }

  return 0;
} 


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#define ff first
#define ss second
using namespace std;
const int INF = 1e9, MAX_N = 2e5;
pair<long long, long long> b[MAX_N], mm1[MAX_N], mm2[MAX_N];

int main() {
	int n; scanf("%d", &n); --n;
	for (int i = 0; i <= n; ++i) {
		scanf("%lld%lld", &b[i].ff, &b[i].ss);
		if (b[i].ff > b[i].ss) swap(b[i].ff, b[i].ss);
	}
	sort(b, b + n + 1);
	for (long long MIN = INF, MAX = 0, i = 0; i < n; ++i)
		mm1[i] = make_pair(MIN = min(MIN, b[i].ss), MAX = max(MAX, b[i].ss));
	for (long long MIN = INF, MAX = 0, i = n; i > 0; --i)
		mm2[i] = make_pair(MIN = min(MIN, b[i].ss), MAX = max(MAX, b[i].ss));
	long long ans = (b[n].ff - b[0].ff) * (max(mm1[n - 1].ss, b[n].ss) - min(mm2[1].ff, b[0].ss));
	for (int i = 0; i < n; ++i)
		ans = min(ans, (max(b[n].ff, mm1[i].ss) - min(b[i + 1].ff, mm1[i].ff)) * (max(b[i].ff, mm2[i + 1].ss) - min(b[0].ff, mm2[i + 1].ff)));
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 9472
n, m = map(int, input().split())
a = [-1] + [int(input()) for i in range(m)] + [n+1]

res = 1
for i in range(1, len(a)):
    steps = a[i] - a[i-1] - 2
    if steps < 0:
        patern_nmu = 0
    else:
        p, q = 1, 0
        for j in range(steps):
            p, q = p+q, p
        patern_nmu = p
    res *= patern_nmu
    res %= 1000000007

print(res)

Measured memory_bytes: 7824
#include<stdio.h>
#define NUMBER 10000
int main(void)
{
int x[NUMBER],i,N=0,tmp;

for(i=0;i<NUMBER;i++){
    scanf("%d",&tmp);
    if(tmp==0){break;}
    x[i]=tmp;
    N++;
}

for(i=0;i<N;i++){
    printf("Case %d: %d\n",i+1,x[i]);
}

return 0;
}


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

const int MAX_P=11;

struct team{
    int solve,penalty,num;
    vector<int> wrong;
    team(int solve,int penalty,int num):solve(solve),penalty(penalty),num(num),wrong(MAX_P,0){}
    bool operator<(const team &rhs){
        if (solve!=rhs.solve) return solve>rhs.solve;
        if (penalty!=rhs.penalty) return penalty<rhs.penalty;
        return num<rhs.num;
    }
};

int T,P,R,t,p,ti; string r;
vector<team> teams;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> T >> P >> R,T){
        teams.clear();
        for (int i=0;i<T;++i) teams.emplace_back(0,0,i+1);
        for (int i=0;i<R;++i){
            cin >> t >> p >> ti >> r; --t,--p;
            if (r=="WRONG") ++teams[t].wrong[p];
            else {
                ++teams[t].solve;
                teams[t].penalty+=ti+teams[t].wrong[p]*1200;
            }
        }
        sort(teams.begin(),teams.end());
        for (int i=0;i<T;++i){
            team te=teams[i];
            cout << te.num << ' ' << te.solve << ' ' << te.penalty << '\n';
        }
    }
}


Measured memory_bytes: 3056
#pragma warning disable

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
using System.Numerics;
using System.Collections;

static class MainClass
{
    public static void Main(string[] args)
    {
        var NM = Console.ReadLine().SplittedStringToInt32List();
        var N = NM[0];
        var M = NM[1];
        var an = new List<KeyValuePair<int, int>>();
        var dp = new int[N + 1, 100010];
        for (int i = 0; i < N; i++)
        {
            var vw = Console.ReadLine().SplittedStringToInt32List();
            an.Add(new KeyValuePair<int, int>(vw[1], vw[0]));
        }
        for (int i = 0; i < N + 1; i++)
        {
            for (int j = 0; j < 100010; j++)
            {
                dp[i, j] = INF;
            }
        }
        dp[0, 0] = 0;
        for (int i = 0; i < N; i++)
        {
            for (int j = 0; j < 100010; j++)
            {
                if (j - an[i].Key >= 0)
                    dp[i + 1, j] = Math.Min(dp[i, j], dp[i, j - an[i].Key] + an[i].Value);
                else
                    dp[i + 1, j] = dp[i, j];
            }
        }
        var max = -1;
        for (int i = 0; i < 100010; i++)
        {
            var num = dp[N, i];
            if (num <= M)
                max = i;
        }
        Console.WriteLine(max);

        Console.ReadLine();
    }


    #region ライブラリ
    public static long ToInt64(this string str) => long.Parse(str);
    public static int ToInt32(this string str) => int.Parse(str);
    public static BigInteger ToBigInteger(this string str) => BigInteger.Parse(str);
    public static List<string> SplittedStringToList(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
    public static List<int> SplittedStringToInt32List(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToList();
    public static List<BigInteger> SplittedStringToBigInteger(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => BigInteger.Parse(x)).ToList();
    public const int INF = int.MaxValue / 2;
    public const long LONGINF = long.MaxValue / 2;
    #endregion
}



Measured memory_bytes: 50528
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define mx INT_MAX
#define mn INT_MI#de
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define itr set<int> :: iterator
#define map_it map<int,int> :: iterator
const int mod = 1e9+7;

vector<int> adj[100001];

// int dp1[100001];

int mdfs(int v, int par){
    
    // if(dp1[v]!=-1)
    //   return dp1[v];

	int msize = 0;
	for(int u=0; u<adj[v].size(); u++){
        int x = adj[v][u];
        if(x == par) continue;
		msize= msize +  1 + mdfs(x, v);
	//	cout<<msize<<" ";
	}
    
    //cout<<" end of msdfs "<<endl;
    if(msize == 0){
  //  	dp1[v] = 0;
    	return 0;
    }

//    dp1[v] = msize;
	return msize;
}

int dfs(int v, int par){
 
    int mxx = INT_MIN;
   // int mxsize = 0;
	for(int u=0; u<adj[v].size(); u++){
        int x = adj[v][u];
		if(x == par) continue;
        int temp = 1 +  mdfs(x, v);
      //  cout<<"Value of temp "<<x<<" "<<v<<" "<<temp<<" ";
        mxx  = max(mxx, temp);
	}
	//cout<<endl;

	if(mxx == INT_MIN)
		return 0;
   
	return mxx;
}

int main()
{   

  
  int x;
  cin>>x;

  if(x == 0)
  	cout<<1<<endl;
  else
  	cout<<0<<endl;
  
  return 0;

}


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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left != NIL){
    x=x->left;
}
  return x;
}

Node treeMaximum(Node x){
  while(x->right != NIL){
    x=x->right;
}
  return x;
}

Node treeSearch(Node u, int k){
  if((u==NIL)||(k==u->key)){
    return u;
  } 
  if(k < u->key){
    return treeSearch(u->left,k);
  }
  else {
    return treeSearch(u->right,k);
  }
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right != NIL){
    return treeMinimum(x->right);
}
  y=x->parent;
  while(y!=NIL&&x==y->right){
    x=y;
    y=y->parent;
}
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if((z->left == NIL)||(z->right == NIL)){
    y=z;
}
  else{
    y=treeSuccessor(z);
}
  if(y->left!=NIL){
    x=y->left;
}
  else{
    x=y->right;
}
  if(x!=NIL){
    x->parent=y->parent;
}
  if(y->parent == NIL){
    root = x;
}

  else if(y==y->parent->left){
    y->parent->left=x;
}
  else{
    y->parent->right=x;
}
  if(y!=z){
    z->key = y->key;
}

}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = 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(Node u){
  if(u != NIL){
    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(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}




Measured memory_bytes: 20536
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<array>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cassert>
#include<functional>
#include<random>
#include<complex>
#include<bitset>
#include<chrono>
#include<boost/multiprecision/cpp_int.hpp>
#define int int64_t
#define uint uint64_t
#define REP(i, a, b) for (int64_t i = (int64_t)(a); i < (int64_t)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define Min(x) *min_element(ALL(x))
#define Max(x) *max_element(ALL(x))
#define Unique(L) (L.erase(unique(ALL(L)), L.end()))
#define veccat(v1, v2) std::copy((v2).begin(),(v2).end(),std::back_inserter(v1)/*v1の後ろにv2を入れる*/)
#define intmax (std::numeric_limits<int64_t>::max() / 4)
using namespace std;
typedef boost::multiprecision::cpp_int bigint;
const double EPS = 1e-9;
const double PI = acos(-1.0);


signed main()
{
	std::cin.sync_with_stdio(false);
	std::cin.tie(0);

	int n, m, d;
	cin >> n >> m >> d;

	double a;
	if (d == 0)a = 1.0 / double(n);
	else a = double((n - d) * 2) / double(n*n);
	double ans = double(m - 1)*a;

	cout << setprecision(20) << ans << endl;



	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <limits>
#define INF 0x3f3f3f3f
#define CLR(a) memset(a, 0, sizeof(a))
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	int n;
	while(scanf("%d",&n)!=EOF){
		int a=n%10;
		int b=n/10%10;
		int c=n/100;
		if(c==9){
			c=1;
		}else{
			if(c==1)
				c=9;
		}
		if(b==9){
			b=1;
		}else{
			if(b==1)
				b=9;
		}
		if(a==9){
			a=1;
		}else{
			if(a==1)
				a=9;
		}
		printf("%d%d%d\n",c,b,a);
	} 
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <numeric>

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

using namespace std;


int main(){
    int n;
    cin >> n;
    vector<int> h(n);
    int ans = 0;
    int num = 0;
    rep(i,n) cin >> h[i];
    rep(i,n-1){
        if (h[i] >= h[i+1]){
            num++;
        }else{
            num = 0;
        }
        ans = max(ans, num);
    }

    cout << ans << endl;
    return 0;
}

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

bool search(int a, vector<int> b, int N){
  bool bo = false;
  for(int i=0; i<N; i++){
    if(b.at(i) == a) bo = true;
  }
  return bo;
}

int main(){
  vector<vector<int>> A(3, vector<int>(3));
  for(int i=0; i<3; i++){
    for(int j=0; j<3; j++) cin >> A.at(i).at(j);
  }
  int N;
  cin >> N;
  vector<int> b(N);
  for(int i=0; i<N; i++) cin >> b.at(i);
  string bo = "No";
  for(int i=0; i<3; i++){
    if(search(A.at(i).at(0), b, N) && search(A.at(i).at(1), b, N) && search(A.at(i).at(2), b, N)) bo = "Yes";
    if(search(A.at(0).at(i), b, N) && search(A.at(1).at(i), b, N) && search(A.at(2).at(i), b, N)) bo = "Yes";
  }
  if(search(A.at(0).at(0), b, N) && search(A.at(1).at(1), b, N) && search(A.at(2).at(2), b, N)) bo = "Yes";
  if(search(A.at(0).at(2), b, N) && search(A.at(1).at(1), b, N) && search(A.at(2).at(0), b, N)) bo = "Yes";
  cout << bo << endl;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pow107 int(pow(10,9) + 7)
#define F(i,x,n) for(int i = x; i < n ; ++i)

bool comp(pair<int, int> a, pair<int, int> b){
    if(a.first != b.first) return a.first > b.first;
    else return a.second < b.second;
}

long int jou(long int x, long int y){
    long int f = 1;
    for(int i = 0; i < y; ++i){
        f = f * x % pow107;
    }
    return f;
}

inline bool pn(long int x){
    if(x <= 1)return false;
    if(x != 2 && x % 2 == 0)
        return false;
    for(int i = 3; i <= (3 + int(sqrt(x)))/2; ++i){
        if((x != i && x % i == 0) || (x != (3 + int(sqrt(x)) - i) && x % (3 + int(sqrt(x)) - i) == 0))
            return false;
    }
    return true;
}

long int factorial(long int n){
    long int f = 1;
    for(long int i = 1; i <= n; ++i){
        f = f * i % pow107;
    }
    return f;
}

long int Func2(long int n,long int m){
    long int s2 = 1,
        r = 1;
    for(long int i = 1; i <= m; ++i){
        s2 = (s2*(n - (i - 1))/i) % (pow107);
    }
    return s2;
}

bool secsort(pair<int, int> a, pair<int, int> b){
    if(a.second == b.second)return a.first > b.first;
    else return a.second > b.second;
}

long int GCD(long int a,long int b){
    if(b == 0)return a;
    return GCD(b,a%b);
}

long int LCM(long int a,long int b){
    return a/GCD(a,b)*b;
}

void warfl(vector<vector<int> > &dist, int n){
  for(int k=0; k<n; k++){
    for(int i=0; i<n; i++){
      for(int j=0; j<n; j++){
        dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
      }
    }
  }
  return;
}
//#define long long long

const int MAX = 1000000;
const int MOD = 1e9+7;

long mpow(long x, long n){
    long ans = 1;
    while(n != 0){
        if(n%2==1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n/2;
    }
    return ans;
}

long mfact(long n){
  long ans = 1;
  for(long i=2; i<=n; i++){
    ans = ans*i % MOD;
  }
  return ans;
}

long mcomb(long n, long m){ //aCbをmod計算
    if(n == 0 && m == 0) return 1;
    if(n < m || n < 0) return 0;
    long ans = mfact(n)*mpow(mfact(m), MOD-2) %MOD;
    ans = ans*mpow(mfact(n-m), MOD-2) %MOD;
    return ans;
}

long int jjjjj(long int n){
    long int x = 1;
    for(int i = 1; i <= n; ++i){
        x *=i;
    }
    return x;
}

int main(){
    int a,b;
    cin >> a >> b;
    if(a % 2 == 1 && b % 2 == 1)cout << "Odd" << endl;
    else cout << "Even" << endl;

}

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

int main(){
	int n;
	cin >> n;
	vector<ll> a(n);
	ll len(0);
	rep(i,n){
		cin >> a[i];
		len += a[i];
	}
	ll b_len(0);
	int b;
	rep(i,n){
		b_len += a[i];
		if(b_len >= len/2.0){
			b = i;
			break;
		}
	}
	ll ans(0);
	if(b_len - len/2.0 <= len/2.0 - (b_len - a[b])){
		ans = b_len * 2 - len;
	}else{
		ans = len - (b_len - a[b]) * 2;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
 
typedef long long ll;
typedef vector<int> vi;
typedef unsigned long ul;
typedef vector<ll> vl;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef set<int> si;
typedef multiset<int> mi;
 
const ll INF = 1e18;
const int MOD = 1e9+7;
 
int main() {
	
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
	
	//ofstream cout ("fileName.out");
	//ifstream cin ("fileName.in");
	
	int N;
	cin>>N;
	map<string,int> m;
	
	while(N--) {
		string s;
		cin>>s;
		++m[s];
	}
	
	cout<<"AC x "<<m["AC"]<<"\n";
	cout<<"WA x "<<m["WA"]<<"\n";
	cout<<"TLE x "<<m["TLE"]<<"\n";
	cout<<"RE x "<<m["RE"]<<"\n";
 	
	return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h> 
using namespace std;
#define se second
#define fr first
#define int long long int
#define pb push_back
#define inf 1e18
#define all(v) v.begin(),v.end()
#define CHAL_BAAP_KO_MT_SIKHA ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mod 1000000007
/*
    Damn Fast:TheFuckinMastermind
    while(How to solve the Question?){
                Read the Question Again!!
           }
        do
            Practise
    #Motivation::::0/0  
*/
const int N=2e5;
int dp[N+1][2];
vector<int> v[N+1];
int vis[N+1];
int solve(int node,int val,int par){
    if(dp[node][val]!=-1)
        return dp[node][val];
    int ans=1;
    for(auto it:v[node]){
        if(it==par)
            continue;
        if(val==0){
            ans*=((solve(it,0,node)+solve(it,1,node))%mod);
            ans%=mod;
        }
        else{
            ans*=solve(it,0,node);
            ans%=mod;
        }
    }
    return dp[node][val]=ans;
}
signed main()
{
    
    CHAL_BAAP_KO_MT_SIKHA
    int n;
    cin>>n;
    for(int i=1;i<=n-1;i++){
        int a,b;
        cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
    }
    memset(dp,-1,sizeof(dp));
    int ans1=solve(1,0,-1);
    memset(dp,-1,sizeof(dp));
    memset(vis,0,sizeof(vis));
    int ans2=solve(1,1,-1);
    cout<<(ans1+ans2)%mod<<endl;
}

Measured memory_bytes: 19712
//semicolon less Java
class Main{
    public static void main(String[] args){
        for(String[] str : new String[][]{{"CODEFESTIVAL2016",
            new java.util.Scanner(System.in).next()}}){

            for(int[] var : new int[][]{{0, 0}}){
                while(var[0] < str[0].length()){
                    if(str[0].charAt(var[0]) != str[1].charAt(var[0])){
                        if(var[1]++ > 0){}
                    }
                    if(var[0]++ > 0){}
                }
                if(System.out.printf("%d\n", var[1]) == null){}
            }
        }
    }
}

Measured memory_bytes: 9808
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, k, d[4019][4019] = {1}, p[4019] = {1};
    cin >> k >> n;
    for (int i = 1; i <= 4000; i++) {
        d[i][0] = 1;
        for (int j = 1; j <= i; j++) {
            d[i][j] = d[i - 1][j - 1] + d[i - 1][j];
            if (d[i][j] >= 998244353) d[i][j] -= 998244353;
        }
        p[i] = p[i - 1] + p[i - 1];
        if (p[i] >= 998244353) p[i] -= 998244353;
    }
    for (int i = 2; i <= k + k; i++) {
        ll z = 0;
        int a, b, c;
        if (i % 2) c = 0;
        else c = 1;
        if (i <= k) b = (i - 1) / 2;
        else b = (k + k + 1 - i) / 2;
        a = k - b - b - c;
        //cout << a << ' ' << b << ' ' << c << ' ';
        for (int j = 0; j <= b; j++) {
            if (n >= j) z = (z + 1ll * d[n + a - 1][n - j] * d[b][j] % 998244353 * p[j]) % 998244353;
            if (c && n > j) z = (z + 1ll * d[n + a - 2][n - j - 1] * d[b][j] % 998244353 * p[j]) % 998244353;
        }
        cout << z << '\n';
    }
}


Measured memory_bytes: 63360
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<double,double> pdd;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define SZ(i) ll(i.size())
#define FOR(i, j, k, in) for (ll i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (ll i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define REP1(i,j) FOR(i, 1, j+1, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define ALL(_a) _a.begin(),_a.end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define X first
#define Y second
#ifdef tmd
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,deque<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
#endif

const ll MOD = 1000000007;
const ll INF = 0x3f3f3f3f3f3f3f3f;
// const ll MAXN = 

string str;
/********** Good Luck :) **********/
int main()
{
    IOS();
    cin >> str;
    vector<char> stk;
    for (auto c : str) {
        if (stk.empty()) {
            stk.emplace_back(c);
        } else if (stk.back() != c) {
            stk.pop_back();
        } else {
            stk.eb(c);
        }
    }
    cout << str.size() - stk.size() << endl;
    return 0;
}


Measured memory_bytes: 592
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans = 0;
    rep(i, n-1) {
        string s1 = s.substr(0, i+1);
        string s2 = s.substr(i+1, n-1-i);
        
        int tmp = 0;
        sort(s1.begin(), s1.end());
        s1.erase(unique(s1.begin(), s1.end()), s1.end());
        for (char c : s1) {
            if (s2.find(c) != string::npos) tmp++;
        }
        chmax(ans, tmp);
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 256
// AOJ 2061: International Party
// 2017.11.8 bal4u@uu

#include <stdio.h>
#include <string.h>
#define TM 0
#if TM
#include <time.h>
#endif

#define HASHSIZ 61
typedef struct { char *s; int id; } HASH;
HASH hash[HASHSIZ+2], *hashend = hash+HASHSIZ;			// Hash table

int lookup(char *s)
{
	int w = strlen(s);
	int i = (101 * *s + 103 * *(s+w-1) + 107 * w) % HASHSIZ;
	HASH *tp = hash + i;

	while (tp->s != NULL) {
		if (!strcmp(tp->s, s)) return tp->id;
		if (++tp == hashend) tp = hash;
	}
	return -1;
}

int insert(char *s, int id)
{
	int w = strlen(s);
	int i = (101 * *s + 103 * *(s+w-1) + 107 * w) % HASHSIZ;
	HASH *tp = hash + i;

	while (tp->s != NULL) {
		if (!strcmp(tp->s, s)) return 0;
		if (++tp == hashend) tp = hash;
	}
	tp->s = s, tp->id = id;
	return 1;
}

int f[22], m;
char name[31][22]; int sz;

int check(int pat)
{
	int i, j, k, s;
	int g[6];

	for (i = 0; i < m; i++) {
		if (!(f[i] & pat)) return 0;
	}

	for (s = 0, k = pat, i = 0; k; i++, k >>= 1) if (k & 1) g[s++] = 1 << i;  
	for (i = 0; i < m; i++) {
		for (j = 0; j < s; j++) {
			if (g[j] & f[i]) g[j] |= f[i] & pat;
		}
	}
	for (k = g[0], i = 1; i < s; i++) if (g[i] & k) k |= g[i]; 
	return k == pat;
}

int main()
{
	int cno = 0, n, i, j, id, ans;
	char buf[22];
#if TM
	clock_t start, end;
	start = clock();
#endif

	while (scanf("%d%d", &n, &m) && n > 0) {
		if (cno++ > 0) putchar('\n');
		memset(hash, 0, sizeof(hash));
		memset(f, 0, sizeof(f));

		id = 1, sz = 0;
		while (n--) {
			scanf("%s", name[sz]);
			if (insert(name[sz], id)) sz++, id <<= 1;
		}

		for (i = 0; i < m; i++) {
			scanf("%d", &j);
			while (j--) {
				scanf("%s", buf);
				id = lookup(buf);
				f[i] |= id;
			}
		}

		ans = -1;
		for (i = 1; i <= 5; i++) {
			for (j = (1 << i) - 1; j < (1 << sz); ) {
				int x, y;
				if (check(j)) { ans = j, id = i; goto done; }
				x = j & ~(j - 1);
				y = j + x;
				j = (((j & ~y) / x) >> 1) | y;
			}
		}
done:	if (ans < 0) puts("Impossible");
		else {
			printf("%d\n", id);
			for (id = 1, i = 0; i < sz; i++, id <<= 1) {
				if (ans & id) puts(name[i]);
			}
		}
	}
#if TM
	end = clock();
	printf("time %lf\n", (double)(end-start)/CLOCKS_PER_SEC);
#endif
	return 0;
}

Measured memory_bytes: 1800
#include <bits/stdc++.h>
#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 ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int w,a,b;
  cin >> w >> a >> b;
  if(a>b) swap(a,b);
  cout << max(b-(a+w), 0) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
int n = 100005;
int m = 200005;
vector<vector<int>> graph(n,vector<int>());
vector<int> dist(n,-1);
vector<int> ans(n,-1);
bool ok = true;

void bfs(){
    queue<int> q;
    q.push(0);
    dist[0] = 0;
    while(!q.empty()){
        int now = q.front();
        q.pop();
        int a = -1;
        int mn = INF;
        for(int c:graph[now]){
            if(dist[c] < 0){
                dist[c] = dist[now] + 1;
                q.push(c);
            }
            else{
                if(dist[c] < mn){
                    a = c;
                    mn = dist[c];
                }
            }
        }
        ans[now] = a;
        if(a < 0 && now != 0) ok= false;
    }
}

int main(){
    cin >> n >> m;
    rep(i,m){
        int a,b;
        cin >> a >> b;
        --a;--b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    bfs();
    if(ok){
        cout << "Yes" << endl;
        for(int i=1;i<n;i++){
            cout << ans[i] + 1 << '\n';
        }
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 10628
#include <bits/stdc++.h>  // include all standard C++ libraries

using namespace std;

// Loops
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define _rrep(i,n) rrepi(i,n,0)
#define rrepi(i,a,b) for(int i=int(a)-1;i>=int(b);--i)

#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(xi, x) for (auto&& xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)


// typedef
using ll = long long;
template <class T> using vec = vector<T>;
using vi   = vector<int>;
using vvi  = vector<vi>;
using vvvi = vector<vvi>;
using pii  = pair<int, int>;


// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second


// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase( unique(all(v)), v.end() )
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<class T> pair<T, size_t> max(vector<T> &x){ auto it = max_element(all(x)); return mp(*it, it-x.begin()); }
template<class T> pair<T, size_t> min(vector<T> &x){ auto it = min_element(all(x)); return mp(*it, it-x.begin()); }

template<class T> inline bool chmax(T &maxval, const T &newval) { if (maxval<newval) { maxval=newval; return 1; } return 0; }
template<class T> inline bool chmin(T &minval, const T &newval) { if (minval>newval) { minval=newval; return 1; } return 0; }

// Utilities
// Grid world utilities
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
#define inside(H,W,y,x) 0<=(x) && (x)<(W) && 0<=(y) && (y)<(H)

inline int in() {int x; cin >> x; return x;} // read int from cin
inline  ll IN() {ll x; cin >> x; return x;}  // read ll from cin



// Debug
#ifdef LOCAL
  #include "dump.hpp"
  #define debug(x) cerr << #x << ": " << x << '\n'
#else
  #define dump(...)
  #define debug(x)
#endif

// Paste snippets here!!

// 

int main(){
  cin.tie(0); ios::sync_with_stdio(false);    // Magic for faster cin
  int N=in(); int M=in();
  vector<bool> broken(N+1,false);
  const ll mod = 1000000007;
  int ai;
  rep(i,M){
    cin >> ai;
    broken[ai] = true;
  }
  vector<ll> dp(N+1,0);
  dp[0] = 1; dp[1] = (broken[1] ? 0 : 1);
  rep(i,2,N+1){
    if(broken[i]) dp[i] = 0;
    else {
      dp[i] = (dp[i-1] + dp[i-2]) %mod;
    }
  }
  cout << dp[N] << endl;
  return 0;
}


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

using namespace std;
typedef long long ll;

int main() {
    int k, n;
    scanf("%d%d", &k, &n);
    vector<int> a(n);
    for (int i = 0; i < n; i++) scanf("%d", &a[i]);
    int ma = a[0] + k - a[n - 1];
    for (int i = 1; i < n; i++) ma = max(ma, a[i] - a[i - 1]);
    printf("%d\n", k - ma);
}


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

int n,a[100010],b[100010];
pair<int,int> c[100010];

bool cmp(pair<int,int> x,pair<int,int> y)
{
	return x.first>y.first;
}

signed main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i]>>b[i];
	for(int i=1;i<=n;i++){
		c[i]=make_pair(a[i]+b[i],i);
	}
	sort(c+1,c+n+1,cmp);
	int sum1=0,sum2=0;
	for(int i=1;i<=n;i++){
		//cout<<c[i].first<<endl;
		if(i%2==1) sum1+=a[c[i].second];
		else sum2+=b[c[i].second];
		//cout<<sum1<<" "<<sum2<<endl;
	}
	cout<<sum1-sum2<<endl;
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 1000000009
typedef long long ll;
typedef pair<int,int> P;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define int ll

signed main(void){
    int A,B;
    cin >> A >> B ;
    cout << max(A+B,max(A-B,A*B)) << endl;
  return 0;
}


Measured memory_bytes: 256
class UnionFind():
    
    # 要素数を指定して作成 はじめは全ての要素が別グループに属し、親はいない
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    
    # xの根を返す
    def find(self, x):
        if self.parents[x] < 0:  return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    
    # xとyが属するグループを併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:  return

        if self.parents[x] > self.parents[y]:  x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    # xが属するグループの要素数
    def size(self, x):  return -self.parents[self.find(x)]
    
    # ｘとyが同じグループか否か
    def same(self, x, y):  return self.find(x) == self.find(y)
    
    # xと同じメンバーの要素
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    
    # 根の一覧
    def roots(self):  return [i for i, x in enumerate(self.parents) if x < 0]
    
    # グループ数
    def group_count(self):  return len(self.roots())
    
    # 可視化 [print(uf)]
    def __str__(self):  return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def kruskal(G):

    G = sorted(G, key = lambda x: x[2])
    U = UnionFind(len(G))
    res = 0
    for e in G:
        s, t, w = e
        if not U.same(s, t):
            res += w
            U.union(s, t)
    return res

N = int(input())
in_list = []
for i in range(N):
    in1, in2 = list(map(int,input().split()))
    in_list.append([i, in1, in2])
    
x = sorted(in_list, key = lambda x: x[1])
y = sorted(in_list, key = lambda x: x[2])

G = []
for i in range(1, N):
    G.append([x[i - 1][0], x[i][0], x[i][1] - x[i - 1][1]])
    G.append([y[i - 1][0], y[i][0], y[i][2] - y[i - 1][2]])
    
ans = kruskal(G)
print(ans)

Measured memory_bytes: 134264
#include <bits/stdc++.h>
#define pi acos(-1.0)
using namespace std;

double minn(double a,double b){
    return a<b?a:b;
}

int main(){
    double a,b,h,m;
    cin>>a>>b>>h>>m;
    
    double deg1=(h*30+m*0.5);
    double deg2=m*6.0;
    
    double dif=fabs(deg1-deg2);
    dif=min(dif,360.0-dif);
    
    double power=pow(a,2.0)+pow(b,2.0)-2*a*b*cos(dif*pi/180.0);
    double c=sqrt(power);
    
    cout<<fixed<<setprecision(20)<<c<<"\n";
    return 0;
}

Measured memory_bytes: 4224
import java.util.*;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String s = sc.next();
		String t = sc.next();
		int sl = s.length();
		int tl = t.length();
		String msg = "No";

		for (int i = 0; i < sl; i++) {
			if (s.equals(t)) {
				msg = "Yes";
				break;
			} else {
				t = t.substring(1, tl) + t.substring(0, 1);
			}
//			System.out.println(t);
		}

		System.out.println(msg);

	}
}

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

int main() {
    int a, b, x;
    int m, n;

    cin >> a>>b;
    x = b - a;
    m = 0;
    for (int i = 1; i <= x; i++){
        m = m+i;
    }
    n = m -b;
    cout << n;

    cout<< endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long int ll;
template<typename T> T changeMax(T& a, T b){if(a < b)a = b;return 0;}

int h, w;
char s[25][25];
int bfs(int i, int j, int k, int l)
{
    int s_x, s_y, g_x, g_y;
    s_y = i;
    s_x = j;
    g_y = k;
    g_x = l;
    int d[25][25], dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
    memset(d, -1, sizeof(d));
    queue<pair<int, int> > q;
    pair<int, int> a(s_x, s_y);
    q.push(a);
    d[s_y][s_x] = 0;
    while(q.size()){
        pair<int, int> t = q.front();
        q.pop();
        if(t.first == g_x && t.second == g_y){
            return d[g_y][g_x];    
        }
        for(int i = 0; i < 4; i++){
            int l = t.first + dx[i], r = t.second + dy[i];
            if(0 <= l && l < w && 0 <= r && r < h && s[r][l] != '#' && d[r][l] == -1){
                d[r][l] = d[t.second][t.first]+1;
                pair<int, int> k(l, r);
                q.push(k);
            }
        }
    }
    return -1;
    

}
int main()
{
    cin >> h >> w;
    rep(i, h){
        rep(j, w){
            cin >> s[i][j];
        }
    }
    int ans = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            for(int k = 0; k < h; k++){
                for(int l = 0; l < w; l++){
                    if((i == k && j == l) || (s[i][j] == '#' || s[k][l] == '#'))continue;
                        ans = max(ans, bfs(i, j, k, l));
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256