akhauriyash/Code-Regression huggingface dataset:
int1 = lambda x: int(x) - 1

# https://note.nkmk.me/python-union-find/
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    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

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    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())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


N, M = map(int, input().split())
uf = UnionFind(N)

for _ in range(M):
    x, y, z = map(int1, input().split())
    uf.union(x,y)

print(uf.group_count())

Measured memory_bytes: 7860
#include <stdio.h>
int main() {
	int a,b,total=0;
	scanf("%d %d",&a,&b);
	if(a==1){
	    total+= 300000;
	    if(b==1)
	        total+=700000;
        else if(b==2)
            total+=200000;
	    else if(b==3)
	        total+=100000;
	}
	else if(a==2){
	    total+= 200000;
	    if(b==1)
	        total+=300000;
        else if(b==2)
            total+=200000;
	    else if(b==3)
	        total+=100000;
	}
	
	else if(a==3){
	    total+= 100000;
	    if(b==1)
	        total+=300000;
        else if(b==2)
            total+=200000;
	    else if(b==3)
	        total+=100000;
	}
	else{
	    if(b==1)
	        total+=300000;
        else if(b==2)
            total+=200000;
	    else if(b==3)
	        total+=100000;
	}
	printf("%d\n",total);
	
	return 0;
}

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

int main() {
	int n, k, cnt = 0;
  cin >> n >> k;
  for (int i=0; i<n; i++) {
  	int h;
    cin >> h;
    if (h >= k) cnt++;
  }
  cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
//y16-5
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define segment_size 65536
#define ROOP() while (true)

int main(){
    int N;
    cin >> N;
    set<vector<int> > s;

    int ans = 0;
    for(int i=0; i<N; i++){
        vector<int> tmp(3);
        cin >> tmp[0] >> tmp[1] >> tmp[2];
        sort(tmp.begin(), tmp.end());
        
        if(s.count(tmp) == 1) ans++;
        s.insert(tmp);
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#define _GLIBCXX_DEBUG // check []
#define DIVISOR 1000000007

using namespace std;
typedef pair<int,int> pii;
typedef pair<int64_t, int64_t> pII;

template<typename T>
void cins(vector<T>& arr) { for(T& e: arr) cin >> e; }

#ifdef DEBUG
#define debug(fmt, ...) \
    printf("[debug: %s] " fmt, __func__, __VA_ARGS__)
#else
#define debug(fmt, ...)
#endif

int main(void) {
    string str1;
    string str2;
    cin >> str1;
    cin >> str2;
    int len = str1.length();
    int ans = 0;
    for(int i = 0; i < len; i++) {
        ans += (str1[i] != str2[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3916
N,W=list(map(int,input().split()))
VW=[list(map(int,input().split())) for _ in range(N)]
dp=[0 for _ in range(W+1)]

for i in range(N):
  for j in range(VW[i][1],W+1):
    dp[j] = max(dp[j],dp[j-VW[i][1]] + VW[i][0])
    
print(dp[W])


Measured memory_bytes: 5928
#NOTE:18:02 start writing, 

require 'scanf'

def ip(a,b)
    a[0]*b[0]+a[1]*b[1]
end

while s = STDIN.gets
    x1,y1,x2,y2,xq,yq = s.scanf("%f,%f,%f,%f,%f,%f")
    v1=[x1-xq,y1-yq]
    v2=[x2-xq,y2-yq]
    v3=[x2-x1,y2-y1]
    s = ip(v1,v3)/(ip(v1,v3)-ip(v2,v3))
    xr = xq+2.0*(1-s)*v1[0]+2.0*s*v2[0]
    yr = yq+2.0*(1-s)*v1[1]+2.0*s*v2[1]
    puts(sprintf("%1.6f %#1.6f",xr,yr))
end

Measured memory_bytes: 9148
#include<bits/stdc++.h>
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define forn(i,n,m) for(int (i)=(n);i<=(int)(m);(i)++)
#define push_back pb
#define make_pair mp
using namespace std;
typedef long long ll;
typedef long double ld;
bool cmp(pair <ll,ll> l,pair <ll,ll> r){
	if(l.first!=r.first)
		return l.first>r.first;
	return l.second>r.second;
}
int main(){
	ll N,M;
	pair <ll,ll> p[100010];
	cin>>N>>M;
	for(ll i=0;i<N;i++){
		cin>>p[i].first;
		cin>>p[i].second;
	}
	sort(p,p+N);
	priority_queue<ll> q;
	ll in=0;
	ll ans=0;
	for(ll i=1;i<=M;i++){
		while(in<N&&p[in].first<=i){
			q.push(p[in].second);
			in++;
		}
		if(!q.empty())
		{
			ans+=q.top();
			q.pop();
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2936
import java.io.*;
import java.util.*;
public class Main
{
	public static void main(String args[])
	{
		Scanner x=new Scanner(System.in);
		long c=0;
    	int n=x.nextInt();
		String k[]=new String[n];
		for(int i=0;i<n;i++)
		{
			String r=x.next();
			char a[]=r.toCharArray();
			Arrays.sort(a);
			String b=new String(a);
			k[i]=b;
		}
		HashMap<String,Integer> m1 = new HashMap<>();
		for(int i=0;i<n;i++)
		{
			if(m1.containsKey(k[i])) m1.put(k[i], m1.get(k[i])+1);
			else m1.put(k[i],1);
		}
		for (Map.Entry<String,Integer> entry : m1.entrySet())
		{
            String s1 = entry.getKey();
			long freq = entry.getValue();
			c+=(freq)*(freq-1)/2;
		}
		System.out.println(c);
	}
}

Measured memory_bytes: 56108
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = 1000000;
        boolean[] l = new boolean[n+1];
        int[] c=new int[n+1];
        l[1] = true;
        c[1]=1;
        for (int i = 2; i <= n; i++) {
            if(i%2==0&&l[i/2])l[i]=true;
            if(i%3==0&&l[i/3])l[i]=true;
            if(i%5==0&&l[i/5])l[i]=true;
            c[i]=c[i-1]+(l[i]?1:0);
        }
        for (;;) {
            int s = sc.nextInt();
            if (s == 0) {
                break;
            }
            int f = sc.nextInt();
            System.out.println(c[f]-c[s-1]);
        }
    }
}


Measured memory_bytes: 31620
#include <bits/stdc++.h> 
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x,y,z) max((x),max((y),(z)))
#define tmin(x,y,z) min((x),min((y),(z)))
typedef long long ll;ll MM = 1000000000;ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
ll GCD(ll x, ll y) {if (y == 0) return x;else return GCD(y, x % y);}
ll LCM(ll x, ll y) { return x / GCD(x, y) * y;}
//cout << fixed << setprecision(10);

int main(){
 string s,t ; cin>>s>>t  ; 
  cout<< t<<s <<endl;
  
}



Measured memory_bytes: 256
#coding: utf-8                                  
                                                
NMX = [int(i) for i in input().split()]         
N, M, X = NMX[0],  NMX[1],  NMX[2]              
fee_station = [int(i) for i in input().split()] 
                                                
increase = 0                                    
decrease = 0                                    
                                                
for i in range(M):                              
  if fee_station[i] > X:                        
    increase += 1                               
  else:                                         
    decrease += 1                               
                                                
print(min(increase, decrease))                  


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

using namespace std;
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vvs = vector<vector<string>>;
template<typename T> using vv = vector<vector<T>>;
template<typename T> using vvv = vector<vector<vector<T>>>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using pqg = priority_queue<T, vector<T>, greater<T>>;

const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
const int DX[4] = {1, 0, -1, 0};
const int DY[4] = {0, 1, 0, -1};

#define _sel(_1, _2, x, ...) x
#define repn(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, ...) _sel(__VA_ARGS__, reps, repn)(i, __VA_ARGS__)
#define reppn(i, n) for (ll i = 1; i <= (n); i++)
#define repps(i, a, b) for (ll i = (a); i <= (b); i++)
#define repp(i, ...) _sel(__VA_ARGS__, repps, reppn)(i, __VA_ARGS__)
#define rrepn(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, a, b) for (ll i = (b) - 1; i >= (a); i--)
#define rrep(i, ...) _sel(__VA_ARGS__, rreps, rrepn)(i, __VA_ARGS__)
#define rreppn(i, n) for (ll i = (n); i >= 1; i--)
#define rrepps(i, a, b) for (ll i = (b); i >= (a); i--)
#define rrepp(i, ...) _sel(__VA_ARGS__, rrepps, rreppn)(i, __VA_ARGS__)

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define rng(v) (v).begin(), (v).end()
#define rrng(v) (v).rbegin(), (v).rend()
#define siz(x) int((x).size())
#define pow2(x) (1ll << (x))
#define bit(x, n) ((x) >> (n) & 1)
#define prt(x) cout << (x) << endl
#define dbg(x) dbgn(#x, x)

template<typename T, typename U> inline bool umax(T& m, U x) { if (m < x) { m = x; return true; } return false; }
template<typename T, typename U> inline bool umin(T& m, U x) { if (m > x) { m = x; return true; } return false; }
template<typename T> inline void errv(T& v) { for (auto x: v) cerr << x << " "; cerr << endl; }
inline void errv(vb& v) { for (auto x: v) cerr << (x ? 1 : 0) << " "; cerr << endl; }
template<typename T> inline void dbgn(string n, T x) { cerr << n << ": " << x << endl; }
template<typename T> inline void dbgn(string n, vector<T>& v) { cerr << n << ": "; errv(v); }
template<typename T> inline void dbgn(string n, vv<T>& m) { cerr << n << ":" << endl; for (auto& v: m) errv(v); }

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

    ll ans = 0;
    repp(i, n) {
        ll cnt = n / i;
        ans += cnt * (cnt * i + i) / 2;
    }
    prt(ans);

    return 0;
}


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

using namespace std;

int main() {
  int n, a, b;
  cin >> n >> a >> b;

  int turn = 0;
  while (true) {
    if (turn == 0) {
      if (a + 1 != b) {
        a++;
      } else if (a != 1) {
        a--;
      } else {
        puts("Borys");
        return 0;
      }
    } else {
      if (b - 1 != a) {
        b--;
      } else if (b != n) {
        b++;
      } else {
        puts("Alice");
        return 0;
      }
    }
    turn ^= 1;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define drep(i,r,l) for(int i=r;i>=l;--i)
using namespace std;
const int sz=4007;
typedef long long ll;
int n;
int cst;
int a[sz];
ll ans;
deque<int>q;
void insert(int x){
	while(!q.empty()&&a[q.back()]>a[x]) q.pop_back();
	q.push_back(x);
}
int main(){
	ans=1e18;
	scanf("%d%d",&n,&cst);
	rep(i,1,n) scanf("%d",&a[i]),a[i+n]=a[i];
	rep(k,0,n-1){
		ll sum=0;
		while(q.size()) q.pop_back();
		rep(i,n-k+1,n) insert(i);
		rep(i,n+1,2*n){
			while(!q.empty()&&i-q.front()>k) q.pop_front();
			insert(i);
			sum+=a[q.front()];
		}
		ans=min(ans,sum+1ll*k*cst);
	}
	printf("%lld\n",ans);
}

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

typedef long long ll;

int main() {
	int a, b;
	cin >> a >> b;
	if (a < b) {
		for (int i = 0; i < b; ++i) {
			cout << a;
		}
	}else {
		for (int i = 0; i < a; ++i) {
			cout << b;
		}
	}
}


















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

int main(){
  ll n,m,ans;
  cin>>n>>m;
  vector<ll> a(m);
  vector<ll> p(n+1);
  vector<ll> pa(n+1);
for(ll i=0;i<n+1;i++){
  p.at(i)=i;
  pa.at(i)=i;
}
p.at(0)=1;
pa.at(0)=1;
  for(ll i=0;i<m;i++){
    cin>>a.at(i);
  }
  for(ll i=0;i<m;i++){
    p.at(a.at(i))=0;
  }
  for(ll i=0;i<n+1;i++){
    if(i>=2){
    pa.at(i)=(pa.at(i-1)+pa.at(i-2))%1000000007;
  }
    if(p.at(i)==0){
      pa.at(i)=0;
    }
  }
  ans=pa.at(n)%1000000007;
  cout<<ans<<endl;
}


Measured memory_bytes: 2560
input()
A = map(int, input().split())
one, two, four = 0,0,0

for a in A:
    if a % 4 == 0:
        four += 1
    elif a % 2 == 0:
        two += 1
    else:
        one += 1

if one <= four or (one == four + 1 and two == 0):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 11096
/**
 * Created by hiroqn on 13/10/08.
 */
/**
 * Created by hiroqn on 13/10/07.
 */
var fs = require('fs'),
    length = fs.fstatSync(process.stdin.fd).size,
    buffer = new Buffer(length),
    bytesRead = fs.readSync(process.stdin.fd, buffer, 0, length, 0),
    input = buffer.toString('utf8', 0, bytesRead).split('\n');
main();
function transTime(t){
  var temp = t.split(':');
  return +temp[0] * 60 + +temp[1];
}
function main() {
  var temp = input[0].split(' '),
      n = +temp[0],
      t = +temp[1];
  temp = input[1].split(' ');
  var time1 = transTime(temp[0]),
      sta1 = temp[1],
      time2 = transTime(temp[2]),
      sta2 = temp[3],
      ans = [];
  for (var i = 2; i <= n; i++) {
    temp = input[i].split(' ');
    time1 =  transTime(temp[0]);
    if(t <= time1 - time2){
      ans.push([sta2, time1 - time2]);
    }
    sta1 = temp[1];
    time2 = transTime(temp[2]);
    sta2 = temp[3];
//    console.log(time1,sta1,time2,sta2)
  }
  console.log(ans.length);
  for(i=0;i<ans.length;i++){
    console.log(ans[i][0] + ' ' + ans[i][1])
  }
}

Measured memory_bytes: 7652
w,h,n = map(int,input().split())
lx,hx,ly,hy = 0,w,0,h
for i in range(n):
  x,y,a = map(int,input().split())
  if a == 1:
    lx = max(lx, x)
  elif a == 2:
    hx = min(hx, x)
  elif a == 3:
    ly = max(ly, y)
  elif a == 4:
    hy = min(hy, y)
print(max(0, hx-lx) * max(0, hy-ly))

Measured memory_bytes: 3064
using System;

namespace AizuOnline
{
    class Program
    {
        static void Main()
        {
            char[] c = new char[] { ' ' };
            string[] ab = Console.ReadLine().Split(c);
            short a = Int16.Parse(ab[0]);
            short b = Int16.Parse(ab[1]);

            if (a > b)
            {
               Console.WriteLine("a > b");
            }
            else if (a < b)
            {
                Console.WriteLine("a < b");
            }
            else
            {
                Console.WriteLine("a == b");
            }
        }
    }
}


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

#define EPS (1e-7)
#define INF (1<<25)
#define PI (acos(-1))

#define FOR(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define REP(i,n) FOR(i,0,n)

#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using ll = long long;

struct Edge {
  int to, cost;
};

vector<Edge> G[100001];
ll dist[100001];

void dfs(int v, int p, ll d) {
  dist[v] = d;
  for (const auto &e : G[v]) {
    if (e.to == p) continue;
    dfs(e.to, v, d+e.cost);
  }
}

int main() {
  int n; cin >> n;
  REP(i,n-1) {
    int a, b, c;
    cin >> a >> b >> c;
    G[a-1].push_back(Edge{b-1, c});
    G[b-1].push_back(Edge{a-1, c});
  }
  int q, k; cin >> q >> k;
  dfs(k-1, -1, 0);
  vector<ll> ans (q);
  REP(i,q) {
    int x, y; cin >> x >> y;
    ans[i] = dist[x-1] + dist[y-1];
  }
  REP(i,q) cout << ans[i] << endl;
  return 0;
}


Measured memory_bytes: 13568
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <string>
#include <vector>
#include <unordered_map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N, M;
	cin >> N >> M;

	vector<pair<int, int>> city(M);
	for (int i = 0; i < M; i++) cin >> city[i].first >> city[i].second;

	vector<vector<int>> prefec(N);
	for (int i = 0; i < M; i++) prefec[city[i].first - 1].emplace_back(city[i].second);
	for (int i = 0; i < N; i++) sort(prefec[i].begin(), prefec[i].end());
	
	unordered_map<int, int> id;
	for (int i = 0; i < N; i++) {
		for (int j = 1; j <= (int)prefec[i].size(); j++) {

			id[prefec[i][j - 1]] = j;

		}
	}

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

		cout << setfill('0') << setw(6) << city[i].first;
		cout << setfill('0') << setw(6) << id[city[i].second] << "\n";

	}

	return 0;
}

Measured memory_bytes: 11940
import sys
n, m = map(int, input().split())

if m % n == 0:
    print(m // n)
    sys.exit()


def make_divisors(n):
    lower_divisors, upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


div = make_divisors(m)
div = [x for x in div if x <= m // n]

print(max(div))

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <ctime>
#include <climits>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <utility>
#include <cstdlib>

using namespace std;
long int pow107 = (int)pow(10, 9) + 7;
long int limit = LONG_MAX;

bool comp(pair<int, string> a, pair<int, string> 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;
}

bool pn(long int x){
    if(x != 2 && x % 2 == 0)
        return false;
    for(int i = 3; i < x; ++i){
        if(x != i && 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;
}

//最大limit
//10^9+7    pow107
//素数pn
//n乗jou
//コンビネーションfactorial
//

int main(){
    int a,b;
    cin >> a >> b;
    if(a + b < 10)
        cout << a + b << endl;
    else
    {
        cout << "error" << endl;
    }
    
}

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

#define cc(x) cout << (x) << endl
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); ++i)
typedef long long ll;

template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

const ll inf = 1LL<<58;
const int iinf = 1<<30;
int keta[100][2];

int main(){
    string s;
    cin >> s;
    string acgt = "ACGT";
    int size = 0;
    int tmp = 0;
    rep(i,s.size()){
        if(s[i] == acgt[0]){
            tmp++;
        }else if(s[i] == acgt[1]){
            tmp++;
        }else if(s[i] == acgt[2]){
            tmp++;
        }else if(s[i] == acgt[3]){
            tmp++;
        }else{
            amax(size, tmp);
            tmp=0;
        }
        amax(size, tmp);
    }
    cc(size);
}

Measured memory_bytes: 256
h, w = gets.split.map(&:to_i)
total = h * w
black = []
black[0] = []
a = []
a[0] = ("-1 " * (w+2)).split.map(&:to_i)
for hh in 1..h do
  tmp = gets.chomp
  a[hh] = []
  a[hh][0] = -1
  for ww in 1..w do
    if tmp[ww-1] == "#"
      a[hh][ww] = 0
      black[0].push([hh, ww])
    else
      a[hh][ww] = total
    end
  end
  a[hh][w+1] = -1
end
a[h+1] = ("-1 " * (w+2)).split.map(&:to_i)
cnt = black[0].size

step = 0
while cnt < total do
  step += 1
  black[step] = []
  black[step-1].each { |hh, ww|
    if a[hh-1][ww] == total
      a[hh-1][ww] = step
      black[step].push([hh-1, ww])
    end
    if a[hh+1][ww] == total
      a[hh+1][ww] = step
      black[step].push([hh+1, ww])
    end
    if a[hh][ww-1] == total
      a[hh][ww-1] = step
      black[step].push([hh, ww-1])
    end
    if a[hh][ww+1] == total
      a[hh][ww+1] = step
      black[step].push([hh, ww+1])
    end
  }
  cnt += black[step].size
end

puts step


Measured memory_bytes: 88060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <utility>
#include <tuple>
#include <cstdio>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
    int N,Y;
    cin >> N >> Y;
    int i,j,k;
    bool finished = false;
    for(i=0;i<=N;i++){
        for(j=0;j<=(N-i);j++){
            k = N -(i+j);
            if( 1000*i+5000*j+10000*k == Y){
                finished = true;
                break;
            }
        }
        if(finished){break;}
    }
    if(finished){
        cout << k << " " << j << " " << i <<endl;
    }
    else{
        cout << -1 << " " << -1 << " " << -1 <<endl;
    }
}
    

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define mp(a, b) make_pair(a, b)
const int maxn = 2e5 + 10; 
int main()
{
	int x;
	cin >> x;
	cout << (x ^ 1) << endl;
	return 0;
}

Measured memory_bytes: 3592
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [list(input()) for _ in range(n)]
#a = [int(input()) for _ in range(n)]



x,y = map(str, input().split())

if (x < y):
    print("<")
elif (x > y):
    print(">")
else:
    print("=")



Measured memory_bytes: 9024
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int intput(int *W, int *H, int *x, int *y, int *r);
int judge(int *W, int *H, int *x, int *y, int *r);
int main(void)
{
	int W = 0;
	int H = 0; 
	int x = 0;
	int y = 0; 
	int r = 0;

	intput(&W, &H, &x, &y, &r);
	judge(&W, &H, &x, &y, &r);

	return 0;
}
int intput(int *W, int *H, int *x, int *y, int *r)
{
	//printf("以下の数値を指定してください\n");
	//printf("長方形の横の長さ：");
	scanf("%d", W);
	//printf("長方形の縦の長さ：");
	scanf("%d", H);
	//printf("円のx軸の座標：");
	scanf("%d", x);
	//printf("円のy軸の座標：");
	scanf("%d", y);
	//printf("円の半径の長さ：");
	scanf("%d", r);

	return 0;
}
int judge(int *W, int *H, int *x, int *y, int *r)
{
	int iYoko = ( *x - *r );
	int iTate = ( *y - *r );
	int iCyokkei = ( *x + *r );
	int iSuicyoku = ( *y + *r );

	if (( iYoko < 0 )
	 || ( *W < iCyokkei )
	 || ( iTate < 0 )
	 || ( *H < iSuicyoku ))
	{
		printf("No\n");
	}
	else
		printf("Yes\n");
	return 0;
}



Measured memory_bytes: 2100
def main():
  n, k = map(int, input().split())
  if (n - k) % (k - 1) == 0:
    print(1 + (n - k) // (k - 1))
  else:
    print(1 + (n - k) // (k - 1) + 1)
if __name__=="__main__":
  main()

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

//type
#define ll long long
typedef pair<int, int> P;
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素
#define Z class
// OTHER
// xの二乗を返す (関数テンプレート版)
template <typename T>
T square(T x) { return x * x; }
#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
// loop
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= ll(b); i--)
#define FORA(i, I) for (const auto &i : I)

// vector
#define ALL(x) x.begin(), x.end()

// output
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ln cout << '\n'
template <Z A>
void pr(A a)
{
  cout << a;
  ln;
}
template <Z A, Z B>
void pr(A a, B b)
{
  cout << a << ' ';
}

int ans = 0;
bool check = 0;
string s;
int N = 3;
vector<int> v(N);
int a, b;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

int main()
{
  int c, d, x, y;

  cin >> a >> b >> c >> d;
  x = a + b;
  y = c + d;
  if (x < y)
    pr("Right");
  else if (x > y)
    pr("Left");
  else
    pr("Balanced");
  return 0;
}

Measured memory_bytes: 3612
n = gets.to_i
arr = gets.split(' ').map(&:to_i)
answer = arr[n-1]

dp = Array.new(n).map { Array.new(21, 0) }
dp[0][arr[0]] = 1
1.upto(n-2) do |i|
  0.upto(20) do |j|
    next if dp[i-1][j] == 0
    vp = j + arr[i]
    vm = j - arr[i]

    dp[i][vp] += dp[i-1][j] if vp <= 20
    dp[i][vm] += dp[i-1][j] if vm >= 0
  end
end

puts dp[n-2][answer]

Measured memory_bytes: 6128
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e5 + 5;
vector<int> a(N), b(N), c(N);
int dp[N][4], n;

int res(int id, int prev){
		if(id == n){
    	if(prev == 1)
      	return a[id];
      else if(prev == 2)
      	return b[id];
      else return c[id];
    }
    int &ans = dp[id][prev];
    if(ans != -1)
    	return ans;
    
    if(prev == 1){
    	ans = a[id];
      ans += max(res(id + 1, 2), res(id + 1, 3));
    }
    if(prev == 2){
    	ans = b[id];
      ans += max(res(id + 1, 1), res(id + 1, 3));
    }
    if(prev == 3){
    	ans = c[id];
      ans += max(res(id + 1, 1), res(id + 1, 2));
    }
    return ans;
}
int32_t main(){
		
	memset(dp, -1, sizeof(dp));
  cin >> n;
  for(int i = 1; i <= n; i++){
  		cin >> a[i] >> b[i] >> c[i];
  }
  cout << max({ res(1, 1), res(1, 2), res(1, 3) }); /// 1st day -> a or b or c -- > ( , 1) ( , 2) ( , 3)
}

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

int main()
{
    int N;
    int64_t answer = 0;
    cin >> N;
    vector<int> A(N+1);
    vector<int> B(N);
    for (int i = 0; i < N+1; i++)
    {
        cin >> A.at(i);
    }

    for (int i = 0; i < N; i++)
    {
        cin >> B.at(i);
    }

    for (int i = 0; i < N; i++)
    {
        if (A.at(i) - B.at(i) >= 0)
        {
            answer += B.at(i);
            A.at(i) = A.at(i) - B.at(i);
        }

        else
        {
            answer += A.at(i);
            if (A.at(i+1)+A.at(i)-B.at(i) >= 0)
            {
                answer += B.at(i)-A.at(i);
                A.at(i+1) -= B.at(i) - A.at(i);
                A.at(i) = 0; 
            }
            else
            {
                answer += A.at(i+1);
                A.at(i+1) = 0;
            }
            
            
        }
        
        
        
    }

    cout << answer;

    
    
}

Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, a, n) for (i = a; i < (n); i++)
#define all(in) in.begin(), in.end()

typedef long double LD;
typedef long long LL;
typedef pair<LL, LL> pll;
typedef pair<int32_t, int32_t> pii;
typedef vector<int32_t> vi;

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

  int32_t N, W;
  cin >> N >> W;

  int64_t bag[2][W + 1];
  bag[0][0] = 0;
  bag[1][0] = 0;
  for (int i = 1; i <= W; i++) {
    bag[0][i] = -1;
    bag[1][i] = -1;
  }

  int64_t best = 0;
  rep(i, N) {
    int32_t w, v;
    cin >> w >> v;

    for (int iw = 1; iw <= W; iw++) {
      int64_t maxV = bag[(i + 1) % 2][iw];
      if (iw - w >= 0 && bag[(i + 1) % 2][iw - w] >= 0)
        maxV = max(maxV, bag[(i + 1) % 2][iw - w] + v);
      if (maxV >= 0) bag[i % 2][iw] = maxV;
      best = max(best, maxV);
      //cerr << setw(3) << bag[i % 2][iw] << ' ';
    }
    //cerr << '\n';
  }

  cout << best;
}

Measured memory_bytes: 1792
flag = 1
while flag:
    numbers = []
    n = raw_input()
    numbers = n.split(" ")
    x = int(numbers[0])
    y = int(numbers[1])
    if x == 0 and y == 0:
    	flag = 0
    	continue
    if x >= y:
    	x, y = y, x
    print x, y

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

int main(){
	int n;
	cin>>n;
	int a=n%100;
	int b=a%10;

	if(b==3){
		cout<<"bon"<<endl;
	}else if(b==2 || b==4 || b==5 || b==7 || b==9){
		cout<<"hon"<<endl;
	}else if(b==0 || b==1 || b==6 || b==8){
		cout<<"pon"<<endl;
	}
}


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

bool data[110];
int main(){
    int a, b, c;
    cin >> a >> b >> c;

    data[a] = true;
    data[b] = true;
    data[c] = true;

    int ans = 0;
    for(int i = 0; i < 110; ++i){
        if(data[i]) ++ ans;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
a, b = map(int, input().split())

late_1 = 0.08
late_2 = 0.1

i = 1

while (i <= (100 / 0.08)):
  if int(i * late_1) == a and int(i * late_2) == b:
    print(i)
    break
  i += 1

if (i == (100 / 0.08) + 1):
  print(-1)


Measured memory_bytes: 38640
#include<iostream>
#include<cstdio>
#include<cassert>
#include<climits>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define IINF (INT_MAX)
#define MAX 5001

using namespace std;

typedef pair<int,int> ii;

struct Data
{
  int cur,cost;
  Data(int cur=IINF,int cost=IINF):cur(cur),cost(cost){}
  bool operator < (const Data& a)const
  {
    return cost > a.cost;
  }
};

int N,E;
int C[MAX],R[MAX];
vector<int> pG[MAX];
vector<Data> G[MAX];
int mincost[MAX];
bool visited[MAX];


void makeGraph()
{
  rep(sp,N)
    {
      rep(i,N)visited[i] = false;
      visited[sp] = true;
      priority_queue<Data> Q;
      Q.push(Data(sp,-R[sp]));
      while(!Q.empty())
	{
	  Data data = Q.top(); Q.pop();
	  int remain = -data.cost;

	  if(remain <= 0)continue;

	  rep(i,pG[data.cur].size())
	    {
	      int next = pG[data.cur][i];
	      if(!visited[next])
		{
		  visited[next] = true;
		  G[sp].push_back(Data(next,C[sp]));
		  Q.push(Data(next,-(remain-1)));
		}
	    }
	}
    }

  rep(i,N)pG[i].clear();

}

void dijkstra()
{
  priority_queue<Data> Q;
  Q.push(Data(0,0));
  rep(i,N)mincost[i] = IINF;
  mincost[0] = 0;

  while(!Q.empty())
    {
      Data data = Q.top(); Q.pop();

      if(data.cur == N-1)
	{
	  cout << data.cost << endl;
	  return;
	}

      rep(i,G[data.cur].size())
	{
	  int next = G[data.cur][i].cur;
	  int cost = G[data.cur][i].cost;
	  if(mincost[next] > data.cost + cost)
	    {
	      mincost[next] = data.cost + cost;
	      Q.push(Data(next,data.cost+cost));
	    }
	}
    }
}

int main()
{
  cin >> N >> E;
  rep(i,N)
    {
      cin >> C[i] >> R[i];
    }

  rep(i,E)
    {
      int A,B;
      cin >> A >> B;

      A--, B--;
      pG[A].push_back(B);
      pG[B].push_back(A);
    }

  makeGraph();

  dijkstra();

  return 0;
}

Measured memory_bytes: 126164
n,m=map(int,input().split())
ac=[0]*n
wa=[0]*n
for i in range(m):
  p,s=map(str,input().split())
  if ac[int(p)-1]==0:
    if s=="AC":
      ac[int(p)-1]=ac[int(p)-1]+1
    else:
      wa[int(p)-1]=wa[int(p)-1]+1
for i in range(n):
  if ac[i]==0:
    wa[i]=0
print(sum(ac),sum(wa))

Measured memory_bytes: 4596
#include <vector>
#include<iostream>
#include<algorithm>
#include<functional>
#include<queue>
#include<string>
//#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pii = pair<int, int>;

using weight = int;
const int inf = 1e9;
struct edge {
	int to;
	weight cap;
	int rev;
};

using edges = std::vector<edge>;
using graph = std::vector<edges>;

void add_edge(graph& g, int from, int to, weight cap) {
	g[from].push_back(edge{ to, cap, static_cast<int>(g[to].size()) });
	g[to].push_back(edge{ from, 0, static_cast<int>(g[from].size() - 1) });
}

void bfs(graph& g, std::vector<int>& level, int s) {
	for (int i = 0; i < (int)level.size(); ++i) {
		level[i] = -1;
	}
	level[s] = 0;
	std::queue<int> que;
	que.push(s);
	while (!que.empty()) {
		int v = que.front(); que.pop();
		for (int i = 0; i < (int)g[v].size(); ++i) {
			edge& e = g[v][i];
			if (e.cap > 0 && level[e.to] < 0) {
				level[e.to] = level[v] + 1;
				que.push(e.to);
			}
		}
	}
}

weight dfs(graph& g, std::vector<int>& level, std::vector<int>& iter, int v, int t, weight f) {
	if (v == t) {
		return f;
	}
	for (int& i = iter[v]; i < (int)g[v].size(); ++i) {
		edge& e = g[v][i];
		if (e.cap > 0 && level[v] < level[e.to]) {
			weight d = dfs(g, level, iter, e.to, t, std::min(f, e.cap));
			if (d > 0) {
				e.cap -= d;
				g[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

weight max_flow(graph& g, int s, int t) {
	weight flow = 0;
	std::vector<int> level(g.size(), -1);
	std::vector<int> iter(g.size(), 0);
	weight INF = 1e9;
	while (true) {
		bfs(g, level, s);
		if (level[t] < 0) {
			return flow;
		}
		for (int i = 0; i < (int)iter.size(); ++i) {
			iter[i] = 0;
		}
		weight f;
		while ((f = dfs(g, level, iter, s, t, INF)) > 0) {
			flow += f;
		}
	}
}

int main() {
	int H, W;
	cin >> H >> W;
	vector<string> a(H);
	for (int i = 0; i < H; ++i) {
		cin >> a[i];
	}
	graph g(2 * H * W);
	int source, sink;
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			if (a[i][j] == 'S') {
				source = i * W + j;
			}
			else if (a[i][j] == 'T') {
				sink = i * W + j;
			}
			if (a[i][j] == '.') {
				continue;
			}
			add_edge(g, i * W + j, i * W + j + H * W, (a[i][j] == 'T' || a[i][j] == 'S' ? inf : 1));
			for (int k = 0; k < H; ++k) {
				if (i != k && a[k][j] != '.') {
					add_edge(g, i * W + j + H * W, k * W + j, 1);
				}
			}
			for (int k = 0; k < W; ++k) {
				if (j != k && a[i][k] != '.') {
					add_edge(g, i * W + j + H * W, i * W + k, 1);
				}
			}
		}
	}
	if (source / W == sink / W || source % W == sink % W) {
		cout << -1 << endl;
	}
	else {
		cout << max_flow(g, source, sink) << endl;
	}
	return 0;
}


Measured memory_bytes: 62464
class Node
    attr_accessor :value
    attr_accessor :prev
    attr_accessor :next
    def initialize(value="END", prev_node=nil, next_node=nil)
        @value = value
        @prev = prev_node
        @next = next_node
    end
end


class MyList
    attr_accessor :head
    attr_accessor :end_node
    def initialize(head = Node.new("END") , end_node = nil)
        @head = head
        @end_node = @head
    end

    def insert(x)
        new_node = Node.new(x)
        unless @end_node.prev.nil? 
            @end_node.prev.next = new_node
            new_node.prev = @end_node.prev
            @end_node.prev = new_node
            new_node.next = @end_node
        else
            @end_node.prev = new_node
            new_node.next = @end_node
            @head = new_node
        end
    end

    def splice(s)
        if @end_node.prev.nil?
            @head = s.head
            @end_node = s.end_node
        else
            unless s.end_node.prev.nil?
                @end_node.prev.next = s.head
                s.head.prev = @end_node.prev
                @end_node = s.end_node
            end
        end
        s.head = Node.new("END")
        s.end_node = s.head
    end

    def dump
        node = @head
        unless node.next.nil?
            while(node.next.value != "END")
                print "#{node.value} "
                node = node.next
            end
            print node.value
        end
        puts
    end

end

# def test_print(n,b)
#     puts "*******"
#     (0...n).each { |x|
#         print "List #{x}: "
#         b[x].dump
#     }
#     puts "*******"
#     puts "\n"
# end


n, q = gets.chomp.split(" ").map &:to_i

A=[]
n.times{
    A.push(MyList.new())
}

q.times{
    choice, t, x = gets.chomp.split(" ").map &:to_i
    case choice
    when 0
        A[t].insert(x)
    when 1
        A[t].dump
    when 2 
        A[x].splice(A[t])
    end
    #test_print(n,A)
}


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

constexpr size_t print_limit = 10;

template <typename It>
void print(ostream& os, It begin, It end, size_t len) {
    size_t count = 0;
    os << "{";
    while (begin != end && count < print_limit) {
        os << "(" << *begin << ")";
        count++;
        begin++;
    }
    if (print != end)
        os << "... " << len << " total";
    os << "}";
}

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& t) {
    print(os, t.begin(), t.end(), t.size());
    return os;
}

constexpr size_t MAXX = 10000;

struct P {
    int64_t x;
    int64_t y;
};

namespace std {
template<>
struct hash<P> {
    size_t operator()(const P& p) const {
        auto h = hash<int64_t>();
        return 13 + h(p.x) ^ h(p.y);
   }
};
} // std

struct L {
    P a;
    P b;
};

namespace std {
template<>
struct hash<L> {
    size_t operator()(const L& l) const {
        auto h = hash<P>();
        return 42 + h(l.a) ^ h(l.b); 
    }
};
} // std

bool operator==(P p1, P p2) { return p1.x == p2.x && p1.y == p2.y; }

bool operator==(L l1, L l2) { return l1.a == l2.a && l1.b == l2.b; }

bool parallel_line(P p1, P p2, P p3, P p4) {
    auto x1 = p2.x - p1.x, x2 = p4.x - p3.x, y1 = p2.y - p1.y, y2 = p4.y - p3.y;
    return x1 * y2 == x2 * y1; 
}

bool same_line(P p1, P p2, P p3) {
    return parallel_line(p1, p2, p1, p3);
}


constexpr int64_t MODP = 998244353;

int main () {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    vector<P> v;
    {
        size_t n;
        cin >> n;
        while (n--) {
            P p;
            cin >> p.x >> p.y;
            v.push_back(p);
        }
    }
    
    unordered_set<L> lines;

    size_t ans = 1;
    for (size_t i = 0; i < v.size(); i++)
        ans = ans * 2 % MODP;
    ans = (ans + MODP - v.size() - 1) % MODP; // 0 and 1-sized

    for (size_t i = 0; i < v.size(); i++) {
        for (size_t j = i + 1; j < v.size(); j++) {
            if (lines.find(L{v[i], v[j]}) == lines.end()) {
                vector<P> line = {v[i], v[j]};
                for (size_t k = j + 1; k < v.size(); k++)
                    if (same_line(v[i], v[j], v[k]))
                        line.push_back(v[k]);
                for (size_t k = 0; k < line.size(); k++)
                    for (size_t l = k + 1; l < line.size(); l++)
                        lines.insert(L{line[k], line[l]});
//                cerr << "line of size " << line.size() << endl; 
                size_t pw = 1;
                for (size_t k = 0; k < line.size(); k++)
                    pw = pw * 2 % MODP;
                ans = (ans + MODP - (pw - 1 - line.size())) % MODP;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
N = int(input())

ans = round(N / 1.08)
b = N / 1.08 - int(N / 1.08)
if b < 0.08 / 1.08 and 0 < b:
    print(":(")
else:
    if not int(ans*1.08) == N:
        print(ans + 1)
    else:
        print(ans)

Measured memory_bytes: 3060
#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){
  
  
}

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){
  
  
}

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


}

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){
    if(u==root){
      printf(" %d",u->key);
      preorder(u->left);
      preorder(u->right);
    }
    else{
      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: 19364
#include <bits/stdc++.h>
using namespace std;

int main(){
  long long a,b;
  char op;
  cin >> a >> op >> b;
  if(op=='+'){
    cout << a + b << endl;
  }else if (op=='-'){
    cout << a - b << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n, m, r;
  cin >> n >> m >> r;
  vl v(r);
  rep(i, r) {
    cin >> v[i];
    v[i]--;
  }
  vector<vl> g(n, vl(n, 1e18));
  rep(i, m) {
    ll a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    g[a][b] = c;
    g[b][a] = c;
  }
  rep(k, n) rep(i, n) rep(j, n) g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
  ll ans = 1e18;
  sort(all(v));
  do {
    ll now = 0;
    rep(i, r - 1) now += g[v[i]][v[i + 1]];
    ans = min(ans, now);
  } while(next_permutation(all(v)));
  cout << ans << endl;
}

Measured memory_bytes: 512
parseInt(x) = parse(Int, x)
parseArray(x::Array{SubString{String}, 1}) = map(parseInt, x)

function main()
  s = readline() |> strip

  s=replace(s, "BC", "D")
  n=0

  # while true
  #   nn=0
  #   a=collect(s)
  #   for m in eachmatch(r"AD", s)
  #     i=m.offset
  #     a[i],a[i+1]=a[i+1],a[i] # "AD" -> "DA"
  #     nn+=1
  #   end
  #   nn==0 && break
  #   n+=nn
  #   s=join(a)
  # end

  for m in eachmatch(r"[AD]+", s)
    ss=m.match
    l=length(ss)
    ix=(1:l)[collect(ss).=='A']
    k=length(ix)
    n+=sum(l-ix)-div((k-1)*k,2)
  end

  n |> println
end

main()


Measured memory_bytes: 167824
#include<bits/stdc++.h>
//#include<iostream>
//#include<cstdio>
//#include<cstring>
//#include<string>
//#include<queue>
//#include<cmath>
//#include<algorithm>
//#define debug1 cout<<"?"<<endl;
//#define debug2 cout<<"?"<<i<<endl;
#define PII pair<int,int>
typedef long long ll;
const int maxn=3e5+9;
const double pi=acos(-1);
const int mod=998244353;
const int INF=0x3f3f3f3f;
const double ep=1e-7;
using namespace std;
vector<int>v1[maxn],v2[maxn];
int pre[maxn];
int Find(int x)
{
	return pre[x]==x?x:pre[x]=Find(pre[x]);
}
void Unix(int x,int y)
{
	int fx=Find(x),fy=Find(y);
	if(fx!=fy)pre[fy]=fx;
}
int main()
{
	int siz[maxn]={0},i,n,m,k;
	scanf("%d%d%d",&n,&m,&k);
	for(i=1;i<=n;i++)pre[i]=i,siz[i]=1;
	int x,y,fx,fy;
	for(i=1;i<=m;i++)
	{
		scanf("%d%d",&x,&y);
		v1[x].push_back(y);
		v1[y].push_back(x);
		fx=Find(x),fy=Find(y);
		if(fx!=fy)siz[fx]+=siz[fy],Unix(fx,fy);
	}
	for(i=1;i<=k;i++)
	{
		scanf("%d%d",&x,&y);
		v2[x].push_back(y);
		v2[y].push_back(x);
	}
	for(i=1;i<=n;i++)
	{
		fx=Find(i);
		int sum=siz[fx]-v1[i].size()-1;
		for(int j:v2[i])
		{
			fy=Find(j);
			if(fx==fy)sum--;
		}
		printf("%d ",sum);
	}
	puts("");
}

Measured memory_bytes: 23416
#include <iostream>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define debug(x) cout << #x << " = " << x << endl;

using namespace std;

int main(void){

    int A,B;
    cin >> A >> B;

    if(A == B){
        cout << "Draw" << endl;
    }else if(A == 1 || B == 1){
        if(A == 1){
            cout << "Alice" << endl;
        }else{
            cout << "Bob" << endl;
        }
    }else if(A == 2 || B == 2){
        if(A == 2){
            cout << "Bob" << endl;
        }else{
            cout << "Alice" << endl;
        }
    }else{
        if(A > B){
            cout << "Alice" << endl;
        }else{
            cout << "Bob" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<complex>
#include<iomanip>
#include<unordered_map>
#define deg(x) cerr<<#x<<"="<<x<<endl;
#define fd(x) for(int i=0;i<x;i++)
#define fdd(a,x) for(int i=a;i<x;i++)
#define fx(x,n) for(int i=n-1;i>=x;i--)
#define mst(x) memset(x,0,sizeof(x));
#define fi first
#define se second
#define TB ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define ok "ok"
#define HH puts("");
#define ls rt<<1
#define rs rt<<1|1
#define pb(a,b) a.push_back(b);
#define FIN  freopen("1.in","r",stdin);
#define FOUT freopen("1.out","w",stdout);
using namespace std;
typedef long long ll;typedef long long LL;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<string,int> pss;
typedef unsigned long long ull;
const ll mod=998244353;
const int inf=1e9+7;
const double eps=1e-8;
ll qpow(ll a,ll b,ll m){ ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return (r+m)%m;}
//const double pi=acos(-1);
 
int main()
{
    TB
	int x;
	cin>>x;
	cout<<!x<<'\n';
	return 0;
}

Measured memory_bytes: 3608
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author rahdirigs
 */

#include <bits/stdc++.h>

using namespace std;

class TaskF {
public:
	void solve(std::istream& in, std::ostream& out) {
		string s, t;
		in >> s >> t;
		int len1 = s.length(), len2 = t.length();
		vector<vector<int>> dp(len1 + 1, vector<int> (len2 + 1, 0));
		for (int i = 0; i <= len1; i++) {
			for (int j = 0; j <= len2; j++) {
				if (i == 0 || j == 0) continue;
				if (s[i - 1] == t[j - 1]) dp[i][j] = 1 + dp[i - 1][j - 1];
				else dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
			}
		}
		string ans;
		while (len2 > 0 && len1 > 0) {
			if (s[len1 - 1] == t[len2 - 1]) {
				ans += s[len1 - 1];
				len1--, len2--;
			} else if (dp[len1 - 1][len2] > dp[len1][len2 - 1]) {
				len1--;
			} else len2--;
		}
		reverse(ans.begin(), ans.end());
		out << ans;
	}
};


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	TaskF solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 38520