akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import static java.lang.System.*;

public class Main {

	Scanner sc = new Scanner(in);
	
	boolean isValid(int l, int r) {
		if (r == l) return false;
		if (r % 3 == 0 || l % 3 == 1) return true;
		if (r % 3 == l % 3) return true;
		return false;
	}
	
	int calc(int l, int r, int n, int[] step, int turn) {
		int count = 0;
		for (int i = 1; i < n; i++) {
			if (turn == 0) {
				if (isValid(l, step[i])) {
					r = step[i];
					turn = 1;
				} else {
					count++;
					l = step[i];
				}
			} else {
				if (isValid(step[i], r)) {
					l = step[i];
					turn = 0;
				} else {
					count++;
					r = step[i];
				}
			}
		}
		
		return count;
	}
	
	void run() {
		while (true) {
			String s = sc.nextLine();
			if (s.equals("#")) break;
			
			int n = s.length();
			int[] step = new int[n];
			for (int i = 0; i < n; i++)
				step[i] = Character.getNumericValue(s.charAt(i));
			
			int min = n;
			int r, l, turn;
			r = step[0];
			l = 4;
			turn = 1;
			min = Math.min(min, calc(l,r,n,step,turn));
			
			r = 6;
			l = step[0];
			turn = 0;
			min = Math.min(min, calc(l,r,n,step,turn));
			
			out.println(min);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}

}

Measured memory_bytes: 33732
#include<iostream>
#include<vector>
#include<numeric>
using namespace std;
int w, h, n;
int x, y, a;

int main(void) {
	cin >> w >> h >> n;
	vector<vector<int>> field(h, vector<int>(w, 1));
	for (int i = 0; i < n; i++) {
		cin >> x >> y >> a;
		if (a == 1) {
			for (int j = 0; j < h; j++) {
				for (int k = 0; k < x; k++) {
					field[j][k] = 0;
				}
			}
		}
		else if (a == 2) {
			for (int j = 0; j < h; j++) {
				for (int k = x; k < w; k++) {
					field[j][k] = 0;
				}
			}
		}
		else if (a == 3) {
			for (int j = 0; j < y; j++) {
				for (int k = 0; k < w; k++) {
					field[j][k] = 0;
				}
			}
		}
		else {
			for (int j = y; j < h; j++) {
				for (int k = 0; k < w; k++) {
					field[j][k] = 0;
				}
			}
		}
	}
	int ret = 0;
	for (int i = 0; i < h; i++) {
		ret += accumulate(field[i].begin(), field[i].end(), 0);
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,s,f) for(i=s;i<f;i++)
#define hi cout<<'h'<<'i'<<'\n' 
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define B begin()
#define E end()
#define vi vector<int>
#define vii vector<pair<int,int>>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007
#define mod2 998244353
#define space 100005
//<<fixed << setprecision(9)

int main()
{
    int n,i,j,t;
    boost;
    int po;
    cin>>n>>po>>t;
    int arr[n+1]={0};
    ll sum=0;
    rep(i,1,t+1)
    {
        cin>>j;
        arr[j]++;
    }
    rep(i,1,n+1)
    {
        if(po-(t-arr[i])>0)cout<<"Yes\n";
        else cout<<"No\n";
    }
    return 0;
}



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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

#define N_MAX 50
#define A_MAX 5050
#define INF 1e18
#define stat(v,c) ((v)*A_MAX+(c))

struct edge{int to,cost;};
vector<edge> adj[N_MAX*A_MAX];
ll dist[N_MAX*A_MAX];

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m,s; cin>>n>>m>>s;
    rep(i,m){
        int u,v,a,b; cin>>u>>v>>a>>b; u--; v--;
        FOR(j,a,A_MAX-1){
            adj[stat(v,j)].pb({stat(u,j-a),b});
            adj[stat(u,j)].pb({stat(v,j-a),b});
        }
    }
    rep(i,n){
        int c,d; cin>>c>>d;
        rep(j,A_MAX)
            adj[stat(i,j)].pb({stat(i,min(j+c,A_MAX-1)),d});
    }

    using P = pair<ll,int>;
    priority_queue<P,vector<P>, greater<P> > que;
    que.emplace(0, stat(0,min(s,A_MAX-1)));
    rep(i,N_MAX*A_MAX) dist[i]=INF;
    dist[stat(0,min(s,A_MAX-1))] = 0;
    while(!que.empty()){
        int v; ll cost;
        tie(cost,v) = que.top(); que.pop();
        if (dist[v]<cost) continue;
        for(auto e:adj[v]){
            if (dist[v]+e.cost < dist[e.to]){
                dist[e.to] = dist[v]+e.cost;
                que.emplace(dist[e.to],e.to);
            }
        }
    }
    FOR(i,1,n-1){
        ll ans = INF;
        rep(j,A_MAX) chmin(ans, dist[stat(i,j)]);
        cout<<ans<<"\n";
    }
    return 0;
}


Measured memory_bytes: 32120
#include <cstdio>
#include <iostream>
#define maxn 2000005
using namespace std;
typedef long long ll;
const int mod = 1e9+7;
int X,Y,base[maxn];
inline int gp(int x,int y){
    int ans=1;
    for(;y;x=((ll)x*x)%mod,y>>=1)
        if(y&1)
            ans=((ll)ans*x)%mod;
    return ans;
}
int getc(int x,int y){
    return ((ll)base[x]*gp(((ll)base[y]*base[x-y])%mod,mod-2))%mod;
}
int main(){
    scanf("%d%d",&X,&Y);
    base[0]=1;
    for(int i=1;i<=2000000;++i)
        base[i]=((ll)base[i-1]*i)%mod;
    if(((2*Y-X)%3||((2*X-Y)%3)))
        printf("0");
    else{
        int a = (2*Y-X)/3,b=(2*X-Y)/3;
        if(a<0||b<0)
            printf("0");
        else
            printf("%d",getc(a+b,a));
    }
    return 0;
}

Measured memory_bytes: 8064
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
// #define int ll
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#ifdef int
const ll INF = (1LL<<60);
#else
const int INF = (1LL<<30);
#endif
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

signed main(void)
{
  string s;
  cin >> s;
  if(s[0] == '9' || s[1] == '9') cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,N) for(ll i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

ll n;

int main(){
    cin >> n;
    vector<ll> a(n);
    vector<ll> b(n);
    vector<ll> c(n);
    rep(i,n)cin >> a[i];
    rep(i,n)cin >> b[i];
    rep(i,n)cin >> c[i];

    sort(ALL(a));
    sort(ALL(b));
    sort(ALL(c));
    ll ans = 0;
    rep(i,n){
        vector<ll>::iterator lb = lower_bound(ALL(a),b[i]);
        vector<ll>::iterator ub = upper_bound(ALL(c),b[i]);
        // ub--;
        // cout << (lb - a.begin()) << " " <<  (ub - c.begin()) << endl;
        // cout << (lb - a.begin()) << " " <<  (n - (ub - c.begin())) << endl;
        ans += (lb - a.begin())*(n - (ub - c.begin()));
    }
    cout << ans << endl;
}

Measured memory_bytes: 2560
s = list(input())
ans = [0 for _ in range(len(s))]
# for i in range(len(s)):
#     location = i
#     flag = [0, 0]
#     counter = 0
#     while(1):
#         if s[location] == 'R':
#             location += 1
#             counter += 1
#             flag[1] = 1
#         else:
#             location -= 1
#             counter += 1
#             flag[0] = 1
#         if flag[0]+flag[1] == 2:
#             # ループの処理
#             if counter%2 == 0:
#                 ans[location] += 1
#             elif s[location] == 'R':
#                 ans[location+1] += 1
#             else:
#                 ans[location-1] += 1
#             break
counter = 0
index = 0
is_R = True
l_index = 0
while(index < len(s)):
    # Rが続く場合
    if is_R:
        if s[index] == 'R':
            counter += 1
            index += 1
        else:
            l_index = index
            ans[l_index] += (counter)//2
            ans[l_index-1] += (counter-1)//2+1
            # print('L',l_index, counter, ans)
            counter = 1
            is_R = False
            index += 1
    else:
        if s[index] == 'L':
            counter += 1
            index += 1
        else:
            ans[l_index] += (counter-1)//2+1
            ans[l_index-1] += (counter)//2
            l_index = index-1
            # print('R',l_index, counter, ans)
            counter = 1
            is_R = True
            index += 1
ans[l_index] += (counter-1)//2+1
ans[l_index-1] += (counter)//2
# print(l_index, counter, ans)
print(' '.join(map(str, ans)))


Measured memory_bytes: 11176
#include <stdio.h>

int main(void)
{
	int a = 0, b = 0, seki = 0;
	scanf("%d%d", &a, &b);
	seki = a * b;
	if (a <= 9 && b <=9) {
		printf("%d", seki);
	}
	else {
		printf("-1");
	}

	return 0;
}


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

int lst(int n){
    cout << "lst " << n << endl;
    int k;
    cin >> k;
    if (k == 0)
        return k;
    vector<int> V(k);
    copy_n(istream_iterator<int>(cin), k, V.begin());
    return k;
}

signed main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
    cout << fixed << setprecision(20);

    int n, m;
    cin >> n >> m;
    int ans = 0;
    for (int i = 0; i < n; i++){
        auto k = lst(i);
        ans += k * (k - 1);
    }
    cout << "ans " << ans << endl;
}


Measured memory_bytes: 3216
from collections import defaultdict
from itertools import product, accumulate

N, W = map(int, input().split())
items = defaultdict(list)
for _ in range(N):
    w, v = map(int, input().split())
    items[w].append(v)
weights = list(items.keys())
nums = {w: len(items[w]) for w in weights}
cumsum = {w: None for w in weights}
for i, w in enumerate(weights):
    items[w].sort(reverse=True)
    cumsum[w] = [0] + list(accumulate(items[w]))
ans = 0
for tup in product(*[range(nums[w] + 1) for w in weights]):
    temp_weight = sum(w * t for w, t in zip(weights, tup))
    if temp_weight > W: continue
    temp_value = sum(cumsum[w][t] for w, t in zip(weights, tup))
    ans = max(temp_value, ans)
print(ans)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int N; cin >> N;
    vector<ll> A(N+1);
    REP(i,N) cin >> A[i];
    vector<int> r(N+5);
    ll ans = 0;
    REP(i,N) {
        int idx = i-A[i]+1;
        if (idx < r.size() && idx >= 0) ans += r[idx];

        int idx2 = A[i]+1+i;
        if (idx2 < r.size()) r[idx2]++;
        //cerr << idx << " " << idx2 << endl;
    }

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 5576
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  string s;
  cin >> s;
  int ret = 0;
  for (auto& c : s) ret += c == '1';
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
void rev(char s[]);
void daydream(int i,char str[],int end);

int main(void){
  int i;
  char str[100001];
  fgets(str,100001,stdin);
  int l = strlen(str);
  rev(str);
  
  daydream(0,str,l-1);
  return 0;
}
//make str in a converted way.
void rev(char s[]){
  int i,l=strlen(s);
  for(i=0;i<l/2;i++){
    char tmp = s[i];
    s[i] = s[l-i-1];
    s[l-i-1] = tmp;
  }

}
void daydream(int i,char str[],int end){
  int l,m;
  char T[4][8]={"dream","dreamer","erase","eraser"};
  for(l=0;l<4;l++)rev(T[l]);
  for(m=1;m<end+1;){
    if(strncmp(str+m,T[0],5)==0) m+=5;
    else if(strncmp(str+m,T[1],7)==0) m+=7;
    else if(strncmp(str+m,T[2],5)==0) m+=5;
    else if(strncmp(str+m,T[3],6)==0) m+=6;
    else {
      printf("NO\n");
      break;
    }
    if(m==end+1)printf("YES");
  }
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();
        while (true) {
            int n = sc.nextInt();
            int m = sc.nextInt();
            if (n == 0 && m == 0) {
                break;
            }
            int[] arr = new int[m + 1];
            for (int i = 0; i < n; i++) {
                int d = sc.nextInt();
                int x = sc.nextInt();
                arr[d] = Math.max(arr[d], x);
            }
            long total = 0;
            for (int i = 1; i <= m; i++) {
                total += arr[i];
            }
            sb.append(total).append("\n");
        }
        System.out.print(sb);
    }
}



Measured memory_bytes: 34416
t, x, y = 0, 0, 0

n = int(input())
for i in range(n):
  next_t, next_x, next_y = map(int, input().split())
  d = abs(next_x - x) + (abs(next_y - y))
  if d > (next_t - t) or (d - (next_t -t)) %2 == 1:
    print("No")
    exit(0)
  else:
    t, x, y = next_t, next_x, next_y
  
print("Yes")

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
string s;
ll k;

int main() {
  cin >> s;
  cin >> k;
  string s2 = s + s;
  string orgs = s;
  ll count = 0;
  ll count2 = 0;
  bool flg = true;
  if(s.length()%2 == 0){
    flg = false;
  }
  for(ll i = 1; i < s.length(); i++){
    if(orgs[i-1] != orgs[i]){
      flg = false;
    }
    if(s[i-1] == s[i]){
      count += 1;
      s[i] = 'X';
    }
    if(s2[i-1] == s2[i]){
      count2 += 1;
      s2[i] = 'X';
    }
  }
  if(flg){
    ll ans = count * k + (floor(k / 2));
    cout << ans << endl;
  }else{
    for(ll j = s.length(); j < s2.length(); j++){
      if(s2[j-1] == s2[j]){
        count2 += 1;
        s2[j] = 'X';
      }
    }
    ll ans = count2 * (k - 1) + count * (2 - k);
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<math.h>
using namespace std;
int main(){
  int b=0;
  vector<int> a(5);
  for (int i = 0; i < 5; i++) {
    cin >> a.at(i);
  }
  for (int i = 0; i < 5; i++) {
    b+=((a.at(i)-1)/10+1)*10;
    a.at(i)=(a.at(i)-1)%10;
  }
  sort(a.begin(), a.end());
  
    cout<<b+a.at(0)-9<<endl;
  
}
  

Measured memory_bytes: 256
# 解けなかったので、他の人の回答を一旦メモ
n = gets.chomp.to_i
ans = 0

memo = Array.new(10) {Array.new(10, 0)}

1.upto(n) do |i|
  l = i.to_s[0].to_i
  r = i.to_s[-1].to_i
  memo[l][r] += 1
end

ans = 0
1.upto(9) do |i|
  1.upto(9) do |t|
    ans += memo[i][t] * memo[t][i]
  end
end
p ans


Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

class SCC {
    void dfs(int v){
        used[v] = 1;
        for (auto &&u : G[v]) if(!used[u]) dfs(u);
        vs.emplace_back(v);
    }

    void dfs_r(int v, int k){
        used[v] = 1;
        cmp[v] = k;
        sz[k]++;
        for (auto &&u : G_r[v]) if(!used[u]) dfs_r(u, k);
    }
public:
    vector<vector<int>> G, G_r, G_out;
    vector<int> vs, used, cmp, sz;
    SCC() = default;
    explicit SCC(int n) : G(n), G_r(n), G_out(n), used(n), cmp(n), sz(n) {}

    void add_edge(int a, int b){
        G[a].emplace_back(b);
        G_r[b].emplace_back(a);
    }

    int build() {
        int n = G.size();
        for (int i = 0; i < n; ++i) if(!used[i]) dfs(i);
        fill(used.begin(),used.end(), 0);
        int k = 0;
        for (int i = n - 1; i >= 0; --i) {
            if(!used[vs[i]]){
                dfs_r(vs[i], k++);
            }
        }
        G_out.resize(k);
        sz.resize(k);
        for (int i = 0; i < n; ++i) {
            for (auto &&j : G[i]) {
                if(cmp[i] != cmp[j]){
                    G_out[cmp[i]].emplace_back(cmp[j]);
                }
            }
        }
        for (auto &&l : G_out) {
            sort(l.begin(), l.end());
            l.erase(unique(l.begin(), l.end()), l.end());
        }
        return k;
    }

    int operator[](int k) const { return cmp[k]; }
};



int main() {
    int n, m;
    cin >> n >> m;
    SCC G(n);
    for (int i = 0; i < m; ++i) {
        int a, b;
        scanf("%d %d", &a, &b);
        G.add_edge(a, b);
    }
    printf("%d\n", G.build());
    vector<vector<int>> res(G.sz.size());
    for (int i = 0; i < n; ++i) {
        res[G[i]].emplace_back(i);
    }
    for (int i = 0; i < G.sz.size(); ++i) {
        printf("%d", G.sz[i]);
        for (auto &&j : res[i]) {
            printf(" %d", j);
        }
        puts("");
    }
    return 0;
}

Measured memory_bytes: 105028
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <bitset>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define sz size()
#define pb push_back
#define mp make_pair
#define ALL(X) (X).begin(),(X).end()

using namespace std;

const int INF = 1000000000;
const double eps = 1e-8;

int main(void) {
  int m;
  cin>>m;
  map<string,bitset<256> > val;
  REP(i,m) {
    string name;
    int minv, maxv;
    cin>>name>>minv>>maxv;
    bitset<256> bs;
    REP(j,256)
      bs[j] = false;
    FOR(j,minv,maxv+1)
      bs[j] = true;
    val[name] = bs;
  }
  stack<bitset<256> > stk;
  int n;
  cin>>n;
  bool flag = false;
  REP(i,n) {
    string str;
    cin>>str;
    if(val.find(str) != val.end())
      stk.push(val[str]);
    else if(str == "/") {
      if(stk.top()[0]) {
        flag = true;
        break;
      }else{
        bitset<256> bs,lhs,rhs;
        REP(j,256)bs[j] = false;
        rhs = stk.top();stk.pop();
        lhs = stk.top();stk.pop();
        REP(j,256)REP(k,256) {
          if(lhs[j] && rhs[k])
          bs[(j/k)%256] = true;
        }
        stk.push(bs);
      }
    }else if(str == "*") {
      bitset<256> bs,lhs,rhs;
      REP(j,256)bs[j] = false;
      rhs = stk.top();stk.pop();
      lhs = stk.top();stk.pop();
      REP(j,256)REP(k,256) {
        if(lhs[j] && rhs[k])
        bs[(j*k)%256] = true;
      }
      stk.push(bs);
    }else if(str == "+") {
      bitset<256> bs,lhs,rhs;
      REP(j,256)bs[j] = false;
      rhs = stk.top();stk.pop();
      lhs = stk.top();stk.pop();
      REP(j,256)REP(k,256) {
        if(lhs[j] && rhs[k])
        bs[(j+k)%256] = true;
      }
      stk.push(bs);
    }else if(str == "-") {
      bitset<256> bs,lhs,rhs;
      REP(j,256)bs[j] = false;
      rhs = stk.top();stk.pop();
      lhs = stk.top();stk.pop();
      REP(j,256)REP(k,256) {
        if(lhs[j] && rhs[k])
        bs[(256+j-k)%256] = true;
      }
      stk.push(bs);
    } else {
      bitset<256> bs,lhs,rhs;
      REP(j,256)bs[j] = false;
      bs[atoi(str.c_str())] = true;
      stk.push(bs);
    }
  }
  if(flag)
    cout<<"error"<<endl;
  else
    cout<<"correct"<<endl;
  return 0;
}

Measured memory_bytes: 1232
#include <algorithm>
#include <iostream>
#include <set>

int main(int argc, char *argv[]) {
  int n, m;
  std::cin >> n;
  std::set<int> a, b;
  int x;
  for (int i = 0; i < n; ++i) {
    std::cin >> x;
    a.insert(x);
  }
  std::cin >> m;
  for (int i = 0; i < m; ++i) {
    std::cin >> x;
    b.insert(x);
  }

  std::set<int> res;
  std::set_symmetric_difference(a.begin(), a.end(), b.begin(), b.end(),
                 std::inserter(res, res.end()));
  for (auto &v : res)
    std::cout << v << std::endl;
}



Measured memory_bytes: 40608
n = int(input())
A = list(map(int, input().split( )))
cnt = 0
for i in range(n-1):
  if A[i] < A[i+1]:
    A[i+1] -= 1
  cnt += max(A[i] - A[i+1],0)
  if cnt >= 1:
    print('No')
    exit()
print('Yes')

Measured memory_bytes: 85288
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <utility>
#include <numeric>
#include <iomanip>
#include <locale>
#include <map>
#include <set>
#include <queue>
#include <cstdlib>
#include <cmath>

using namespace std;

pair<int, int> read();
int think(pair<int, int>);
void write(int);

int main(int argc, char* argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);

  auto input = read();
  auto output = think(input);
  write(output);

  return 0;
}

pair<int, int> read() {
  int a, b;

  cin >> a >> b;
  return make_pair(a, b);
}

int think(pair<int, int> input) {
  auto a = input.first;
  auto b = input.second;
  int ceil = 10;

  if (a >= ceil || b >= ceil) {
    return -1;
  }
  return a * b;
}

void write(int output) {
  cout << output << endl;
}


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

using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
int mod = 20437;

long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}

/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  

double eps = .000000001;


int main ()
{
  prep();
  int n, k, q;
  cin >> n >> k >> q;
  int arr[n+1] = {0};
  int onepts = k;
  for (int i=0; i<q; i++){
      int num;
      cin >> num;
      arr[num]++;
      if (num != 1){
          onepts--;
      }
  }
  int diff = onepts-arr[1];
  for (int i=1; i<=n; i++){
      arr[i] += diff;
      if (arr[i] <= 0){
          cout << "No\n";
      }else{
          cout << "Yes\n";
      }
  }
  return 0; 
}
  

Measured memory_bytes: 1024
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val array = readLine()!!.split(" ").map { it.toInt() } as MutableList<Int>
    val (sortedArray, exchanges) = selectionSort(n, array)
    println(sortedArray.joinToString(" "))
    println(exchanges)
}

fun selectionSort(n: Int, array: MutableList<Int>): Pair<List<Int>, Int> {
    var exchanges = 0
    for (i in 0 until n) {
        var minj = i
        for (j in i until n) {
            if (array[j] < array[minj]) {
                minj = j
            }
        }
        if (i < minj) {
            val a = array[i]
            array[i] = array[minj]
            array[minj] = a
            exchanges++
        }
    }

    return array to exchanges
}


Measured memory_bytes: 33996
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

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

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

int main(){
    ll d, g;
    cin >> d >> g;

    vector<ll> p(d), c(d);
    rep(i, d)cin >> p[i] >> c[i];

    ll ans = INF;
    //bitが立っているものを全部使う
    rep(bit, (1<<d)){
        ll cnt = 0;
        ll point = g;
        rep(i, d)if((1<<i) & bit){
            cnt += p[i];
            point -= (i+1)*100*p[i] + c[i];
        }

        if(point <= 0){
            ans = min(ans, cnt);
            continue;
        }

        //使っていないものを大きい物を使う
        for(ll i = d-1; i >= 0; --i){
            if(!((1<<i) & bit)){
                ll c_i = point / ((i+1)*100);
                if(point % ((i+1)*100) > 0)c_i++;

                c_i = min(c_i, p[i]);
                point -= (i+1)*100*c_i;
                cnt += c_i;
                break;
            }
        }

        if(point <= 0)ans = min(ans, cnt);
    }

    cout << ans << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>

using namespace std;

int main(int argc, char** argv) {

        int N;
        int Y;
        int cnt0=0;
        int cnt1=0;
        int diff=0;
        int out1 = -1;
        int out2 = -1;
        int out3 = -1;
        bool flag = false;

        cin >> N >> Y;
        Y = Y/1000;

        for(cnt0 = 0; cnt0 <= N; cnt0++){
                for(cnt1 = 0; cnt1 <= N-cnt0; cnt1++){
                        if(9*cnt0 + 4*cnt1 == Y - N){
                                out1 = cnt0;
                                out2 = cnt1;
                                out3 = N - cnt0 -cnt1;
                                flag = true;
                                break;
                        }
                }
                if(flag) break;
        }
        cout << out1 << " " << out2 << " " << out3 << endl;

        return 0;
}

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

int main(){
    int N; cin >> N;
    int P[N], count=0, min=N;
    for(int i=0; i<N; i++){
        cin >> P[i];
        if(min>=P[i]){
            count++;
            min = P[i];
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 1024
from collections import Counter,defaultdict,deque
from heapq import heapify,heappop,heappush
from bisect import bisect_left,bisect_right
import sys,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
res = 0
def f(x):
    global res
    if x <= n:
        l = len(str(x))
        f(3*10**l+x)
        f(5*10**l+x)
        f(7*10**l+x)
        if '3' in str(x) and '5' in str(x) and '7' in str(x):
            res += 1
f(3)
f(5)
f(7)
print(res)

Measured memory_bytes: 45156
n = int(input())
if n == 1:
    print(1)
    exit()
s = 0
cnt = 1
while True:
    s += cnt
    if s < n <= s+cnt+1:
        use = cnt+1
        sub = use*(use+1)//2 - n
        for i in range(use):
            if i+1 == sub:
                continue
            print(i+1)
        exit()
    else:
        cnt += 1


Measured memory_bytes: 3316
#include<iostream>
#include <fstream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>

unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

#define LOCAL  1
#define UPLOAD 2

using namespace std;
typedef long long ll;

template <class T = ll>
T input(){T x;cin >> x;return x;}

template <class T>
void output(T x){cout << x << endl;}

//#define int long log

#define debug(x) cerr << #x<< ": " << x<< '\n';

int main()
{
#if ENVIRONMENT == LOCAL
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif

  int N = input();
  vector<int> A;
  A.resize(N);
  for(int i=0;i<N;i++){
    A[i] = input();
  }

  vector<int> B = A;
  sort(B.begin(), B.end(), greater<int>());

  for(int i=0;i<N;i++){
    if(A[i] == B[0]){
      output(B[1]);
    }
    else{
      output(B[0]);
    }
  }

  return 0;
}

Measured memory_bytes: 3200
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string>
#include <iostream>
#include <vector>
#define mod 1000000007
using namespace std;

const int NMAX = 1010;

int dp[2][NMAX];
bool liber[NMAX];
char lin[NMAX];

void add(int & a, int b)
{
    a += b;
    if (a >= mod)
        a -= mod;
}

int main()
{
    int n, m;

    scanf("%d%d", &n, &m);

    dp[1][1] = 1;

    for (int i = 1; i <= n; i++) {
        scanf("%s", lin + 1);
        int * act = dp[i & 1];
        int * urm = dp[(i & 1) ^ 1];

        for (int j = 1; j <= m; j++) {
            add(act[j], act[j - 1]);
            if (lin[j] == '#')
                act[j] = 0;
            urm[j] = act[j];
        }
    }

    printf("%d\n", dp[n & 1][m]);

    return 0;
}


Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

int readint() {
    return readln.chomp.to!int;
}

int[] readints() {
    return readln.split.map!(to!int).array;
}

void main() {
    string s;
    while ((s = readln.chomp) != null) {
        auto ab = s.split.map!(to!int).array;
        int a = ab[0], b = ab[1];

        writeln(gcd(a, b));
    }
}

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

int max_rotate(int b, int m);
int min_rotate(int b, int m);

int main(){
	
	int i,j,l;
	int a[22];
	while(1){
		cin >> a[0] >> l;
		if(a[0] == 0 && l == 0){
			break;
		}
		for(i=0;i<21;i++){
			for(j=0;j<i;j++){
				if(a[j] == a[i] && ( j != i )){
					break;
				}
			}
			if(a[j] == a[i] && ( j != i )){
				break;
			}
			a[i+1] = max_rotate(a[i],l) - min_rotate(a[i],l);
		}
		if(i == 0){
			i++;
		}
		cout << j << " " << a[i] << " " << (i - j) <<endl;
	}
	
	return 0;
}

int max_rotate(int b, int m){
	int num[6];
	int tmp;
	int ret = 0;
	int i;
	for(int i=m-1;i>=0;i--){
		tmp = (int)pow(10,i);
		num[i] = b / tmp;
		b %= tmp;
	}

	//sort num[]
	for(i=0;i<m-1;i++){
		for(int j=m-1;j>i;j--){
			if(num[j] < num[j-1]){	//the only difference between max_ & min_
				tmp = num[j];
				num[j] = num[j-1];
				num[j-1] = tmp;
			}
		}
		ret += num[i] * (int)pow(10,i);
	}
	ret += num[i] * (int)pow(10,i);
	return ret;
}

int min_rotate(int b, int m){
	int num[6];
	int tmp;
	int ret = 0;
	int i;
	for(int i=m-1;i>=0;i--){
		tmp = (int)pow(10,i);
		num[i] = b / tmp;
		b %= tmp;
	}

	//sort num[]
	for(i=0;i<m-1;i++){
		for(int j=m-1;j>i;j--){
			if(num[j] > num[j-1]){	//the only difference between max_ & min_
				tmp = num[j];
				num[j] = num[j-1];
				num[j-1] = tmp;
			}
		}
		ret += num[i] * (int)pow(10,i);
	}
	ret += num[i] * (int)pow(10,i);
	return ret;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int N;
vector<int> C[405];

void rotate(vector<int> &a) {
    a.push_back(a[0]);
    a.erase(a.begin());
}

void minimize(vector<int> &a) {
    vector<int> ret;
    for(int i = 0; i < a.size(); i++) ret.push_back(a[i]);
    for(int i = 0; i < a.size(); i++) {
        rotate(a);
        chmin(ret, a);
    }
    for(int i = 0; i < a.size(); i++) a[i] = ret[i];
}

ll ans = 0;
map<vector<int>, int> mp;

void g(vector<int> a, vector<int> b, ll index, ll factor) {
    if(index == a.size()) {
        ans += factor;
        /*
        cerr << "---------" << endl;
        for(int i = 0; i < a.size(); i++) cerr << a[i] << " ";
        cerr << endl;
        for(int i = 0; i < a.size(); i++) cerr << b[i] << " ";
        cerr << endl;
        cerr << factor << endl;
        */
        return;
    }
    vector<int> tmp;
    int M = a.size();
    tmp.push_back(a[(index + 1) % M]);
    tmp.push_back(a[index % M]);
    tmp.push_back(b[(2 * N - index) % M]);
    tmp.push_back(b[(2 * N - index - 1) % M]);
    minimize(tmp);
    vector<int> v = tmp;
    ll counter = 0;
    for(int i = 0; i < v.size(); i++) {
        rotate(v);
        if(v == tmp) counter++;
        /*
        for(int i = 0; i < v.size(); i++) cerr << v[i] << " ";
        cerr << counter << endl;
        */
    }
    /*
    cerr << "tmp: ";
    for(int i = 0; i < tmp.size(); i++) {
        cerr << tmp[i] << " ";
    }
    cerr << endl;
    */
    ll now = mp[tmp];
    mp[tmp]--;
    //cerr << "factor: " << index << " " << factor << " " << now << " " << counter << endl;
    g(a, b, index + 1, factor * now * counter);
    mp[tmp]++;
}

void f(int up, int down) {
    mp[C[down]]--;
    for(int i = 0; i < C[down].size(); i++) {
        g(C[up], C[down], 0, 1);
        rotate(C[down]);
    }
    mp[C[down]]++;
    /*
    cerr << up << " " << down << " " << mp[C[down]] << endl;
    for(int i = 0; i < C[down].size(); i++) cerr << C[down][i] << " ";
    cerr << endl;
    */
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    for(int i = 1; i <= N; i++) {
        C[i].resize(4);
        for(int k = 0; k < 4; k++) cin >> C[i][k];
        minimize(C[i]);
        /*
        for(int j = 0; j < C[i].size(); j++) {
            cerr << C[i][j] << " ";
        }
        cerr << endl;
        */
    }
    for(int i = 1; i <= N; i++) {
        for(int j = 1; j < i; j++) {
            f(i, j);
        }
        mp[C[i]]++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 141872
import java.util.Arrays;
import java.util.Scanner;

class Main {
	public static void main (String args[]) {
		Scanner sc = new Scanner(System.in);
		String[] temp = sc.nextLine().split(" ");
		int input = Integer.parseInt(temp[0]);
		int longs = Integer.parseInt(temp[1])-1;
		int[] treesHeight = new int[input];
		for(int i=0;i<input;i++)
		{
			int trees = sc.nextInt();
			treesHeight[i] = trees;
		}
		Arrays.sort(treesHeight);
		int min = Integer.MAX_VALUE;
		for(int i = 0;i<treesHeight.length-longs;i++)
		{
			int tempLagi = treesHeight[i+longs] - treesHeight[i];
			if(tempLagi< min)
				min = tempLagi;
		}
		
		System.out.print(min);
	}
}


Measured memory_bytes: 49388
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        char[] ch = sc.next().toCharArray();

        boolean judge = false;
        if(ch[2] == ch[3] && ch[4] == ch[5]){
            judge = true;
        }
        System.out.println(judge ? "Yes" : "No");
    }
}

Measured memory_bytes: 35596
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String a = sc.next();
    String b = sc.next();
    String c = sc.next();
    String[] abc = { a, b, c };
    int turn = 0;
    while (true) {
      if (abc[turn].length() == 0) {
        System.out.println((char) (turn + 'A'));
        return;
      }
      char next = abc[turn].charAt(0);
      abc[turn] = abc[turn].substring(1, abc[turn].length());
      turn = next - 'a';
    }
  }
}

Measured memory_bytes: 23892
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>
#include <cmath>
#include <stack>
#include <random>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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

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

constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

ll calc(ll a) {
  ll ret = 0;
  ll start = a/4*4;
  for(ll i=start; i<=a; i++) {
    ret ^= i;
  }
  return ret;
}

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

  ll a, b; cin >> a >> b;
  cout << (calc(b) ^ calc(a-1)) << endl;
}


Measured memory_bytes: 256
n = int(input())
flg = False
for h in range(1,3500):
    for w in range(1, 3500):
        if 4 * h * w / n - w - h <= 0:
            continue
        res = h * w / ((4 * h * w) / n - w - h)
        if res % 1 == 0:
            flg = True
            break
    if flg:
        break
print(str(h) + " " + str(w) + " " + str(int(h * w / ((4 * h * w) / n - w - h))))

Measured memory_bytes: 40668
#include <iostream>

using namespace std;

int N, D;

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


	int per_one = 1 + D * 2;

	int ans = N / per_one;

	if (N % per_one != 0) {
		ans++;
	}

	cout << ans << endl;


	return 0;
}


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

int main() {
    ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    int n; cin >> n;
    int cnt = 0;
    for (int i = 1; i < n; i++) {
        cnt += n/i;
        if(n%i==0) {
            cnt --;
        }
    }
    cout << cnt;
    return 0;
}

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

int main()
{
  string s;
  cin >> s;
  if (s <= "2019/04/30") {
    cout << "Heisei" << endl;
  }
  else {
    cout << "TBD" << endl;
  }

  return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <unordered_set>
#include <unordered_map>

using namespace std;
const int MAXN = 3001;
int dp[MAXN][MAXN];

int main()
{
    string s, t;
    cin >> s >> t;
    for(int i = 0; i <= s.length(); i++)
    {
        for(int j = 0; j <= t.length(); j++)
        {
            if(i*j==0)
            {
                dp[i][j] = 0;
                continue;
            }
            dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
            if(s.at(i-1)==t.at(j-1)) dp[i][j] = dp[i-1][j-1]+1;
        }
    }
    string ans = "";
    int i = s.length();
    int j = t.length();
    while(dp[i][j]!=0)
    {
        if(i>0&&dp[i-1][j]==dp[i][j]) i--;
        else if(j>0&&dp[i][j-1]==dp[i][j]) j--;
        else
        {
            ans += s.at(i-1);
            i--;
            j--;
        }
    }
    for(i=ans.length()-1;i>=0;i--) cout << ans.at(i);
}

Measured memory_bytes: 35456
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  int res=0,N,A[3][101],sum[3][101];
  cin >> N;
  REP(i,N)cin >> A[0][i];
  REP(i,N)cin >> A[1][i];
  sum[0][0] = A[0][0];
  sum[1][0] = A[1][0];
  REP(i,N-1)sum[0][i+1] = sum[0][i] + A[0][i+1];
  REP(i,N-1)sum[1][i+1] = sum[1][i] + A[1][i+1];
  REP(i,N){
    res = max(res,sum[0][i] + (sum[1][N-1] - (i-1>= 0 ? sum[1][i-1] : 0)));
  }
  cout << res << endl;
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,s,a,b,res[1000001],kq;
int main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n;
    for(int i=1;i<=n;++i){
        cin>>a>>b;
        for(int j=a;j<=b;++j)if(res[j]==0)kq++,res[j]=1;
    }
    cout<<kq;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mkp make_pair
#define rep(i,s,f) for(i=s;i<f;i++)
#define db cout<<'h'<<'i'<<endl 
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define B begin()
#define E end()
#define vi vector<int>
#define vii vector<pair<int,int>>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define PI 3.14159265
#define mod 1000000007
#define mod2 998244353
#define space 100005
//<<fixed << setprecision(9)

int main()
{
    int n,i,j,t;
    boost;
    int a,b,c;
    cin>>a>>b>>c;
    cout<<max(c-(a-b),0);
    return 0;
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class Solution
{
    static void Main()
    {
        var vals = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        long n = vals[0];
        long left = vals[1];
        long right = vals[2];
        long low = vals[3];
        long high = vals[4];

        // 0からlastへ変化させる
        var last = Math.Abs(right - left);

        // highで追いつけない
        if ((n - 1) * high < last)
        {
            Console.WriteLine("NO");
            return;
        }

        for (int i = 0; i < n; i++)
        {
            // i個を-に 残りを+にする
            var minusMin = -i * high;
            var minusMax = -i * low;
            var j = n - 1 - i;
            var pulsMin = j * high;
            var pulsMax = j * low;

            if ((minusMin + pulsMin <= last && last <= minusMax + pulsMin)
                || (minusMin + pulsMax <= last && last <= minusMax + pulsMax))
            {
                Console.WriteLine("YES");
                return;
            }
        }

        Console.WriteLine("NO");
    }
}

Measured memory_bytes: 13268
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
#include<string.h>
ll dp[505][105][405]={0};
int main(){
    ll N,W; cin>>N>>W;
    vl v,w;
    ll lim=0;
    rep(i,N){
        ll value,wegiht;
        cin>>wegiht>>value;
        if(wegiht>W)continue;
        if(!i)lim=wegiht-1;
        dp[wegiht-lim][i][1]=value;
        v.push_back(value);
        w.push_back(wegiht-lim);
    }
    for(int j=0;j<N-1;j++){
        for(int i=0; i<401;i++){
            for(int k=0; k<=N;k++){
                if(dp[i][j][k]==0)continue;
                dp[i][j+1][k]=max(dp[i][j+1][k],dp[i][j][k]);
                if(i+lim*k+w[j+1]+lim>W)continue;
                cmax(dp[i+w[j+1]][j+1][k+1],dp[i][j][k]+v[j+1]);
            }
        }
    }
    ll ans=0;
    rep(i,401)rep(j,N+1)cmax(ans,dp[i][N-1][j]);
    cout<<ans<<endl;
}

Measured memory_bytes: 52992
#include<bits/stdc++.h>
using namespace std;
vector<int>g[200005];
int n,d[200005]; 
void dfs(int x,int p=0){
	d[x]=d[p]+1;for(auto t:g[x])if(t!=p)dfs(t,x);
}
int main(){
	cin>>n;d[0]=-1;
	for(int i=1;i<n;i++){
		int a,b;cin>>a>>b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	dfs(1);
	dfs(max_element(d+1,d+n+1)-d);
	cout<<(((*max_element(d+1,d+n+1))%3==1)?"Second":"First")<<endl;
	return 0;
}

Measured memory_bytes: 21376
lst = input().split()
N = int(lst[0])
M = int(lst[1])
X = int(lst[2])
L = input().split()

cost_0 = 0
for n in L:
   if 0 < int(n) < X:
      cost_0 += 1
   elif X < int(n):
      break

cost_N = 0
for n in L:
   if X < int(n) < N:
      cost_N += 1

print(min([cost_0, cost_N]))

Measured memory_bytes: 9064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC89_3
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            long[] names = new long[5] { 0, 0, 0, 0,0 };
            long c = 0;

            for (int i = 0; i < N; i++)
            {
                string s = Console.ReadLine();
                if (s[0] == 'M')
                {
                    names[0] += 1;
                    c++;
                }
                else if (s[0] == 'R')
                {
                    names[1] += 1;
                    c++;
                }
                else if (s[0] == 'H')
                {
                    names[2] += 1;
                    c++;
                }
                else if (s[0] == 'A')
                {
                    names[3] += 1;
                    c++;
                }
                else if (s[0] == 'C')
                {
                    names[4] += 1;
                    c++;
                }

            }
            long[][] b = new long[10][];
            b[0] = new long[] { 1, 1, 1, 0, 0 };
            b[1] = new long[] { 1, 1, 0, 1, 0 };
            b[2] = new long[] { 1, 1, 0, 0, 1 };
            b[3] = new long[] { 1, 0, 1, 1, 0 };
            b[4] = new long[] { 1, 0, 1, 0, 1 };
            b[5] = new long[] { 1, 0, 0, 1, 1 };
            b[6] = new long[] { 0, 1, 1, 1, 0 };
            b[7] = new long[] { 0, 1, 1, 0, 1 };
            b[8] = new long[] { 0, 1, 0, 1, 1 };
            b[9] = new long[] { 0, 0, 1, 1, 1 };
            long sum = 0;
            for (int i = 0; i < 10; i++)
            {
                long tmp = 1;
                long tmp2 = 0;
                for (int j = 0; j < 5; j++)
                {
                    
                    if (b[i][j] * names[j] > 0)
                    {
                        tmp2 += 1;
                        tmp *= (b[i][j] * names[j]);
                    }
                }
                if (tmp2 == 3)
                {
                    sum += tmp;
                }
            }
            Console.WriteLine(sum);
        }
        


    }
}


Measured memory_bytes: 13268