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

using namespace std;

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

    scanf("%d", &N);
    vector<int> dp(3);

    for (int i = 1; i <= N; i++) {
        vector<int> tmp(3);
        scanf("%d %d %d", &a, &b, &c);
        tmp[0] = a + max(dp[1], dp[2]);
        tmp[1] = b + max(dp[0], dp[2]);
        tmp[2] = c + max(dp[0], dp[1]);
        dp = tmp;
    }

    printf("%d\n", max({dp[0], dp[1], dp[2]}));

    return 0;
}

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

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

	int n;
	long long int y;
	cin >> n >> y;
	for (int i = 0; i <= n; ++i){
		for (int j = 0; j <= n-i; ++j){
			for (int k = 0; k <= n-i-j; ++k){
				if (i+j+k == n && 10000*i + 5000*j + 1000*k == y){
					cout << i  << " " << j << " " << k << "\n";
					return 0;
				}
			}
		}
	}
	cout << "-1 -1 -1" << "\n";
	return 0;
}

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

#define vec     vector<int>
#define vecll   vector<ll>
#define vec2    vector<vector<int>>
#define vec2ll  vector<vector<ll>>
#define vpair   vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define vecst   vector<string>
#define vecb    vector<bool>

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define mpair(v1, v2)    make_pair(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << var;
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt((ok ? "YES" : "NO"));}
//----------------------------------------------------------------
int divi[1001];

int main(void) {
  int n, k;
  cin >> n >> k;
  int x, y;
  cin >> x >> y;

  prt(min(n,k)*x+max(n-k,0)*y);
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;


int main()
{ios_base::sync_with_stdio(false);
int x,y,z;
cin>>x>>y>>z;
if(x+y+z>=22)ol("bust");
else ol("win");
return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<iomanip>
#define pi 3.14159265358979323846264338327950L
using namespace std;
int main()
{
    double a,b,h,m;
    cin>> a >> b >> h >> m;
    double p;
    p=pi*(h+m/60)/6-(pi*m)/30;

    
    double c;
    c=a*a+b*b-2*a*b*cos(p);
     
     
    cout << fixed << setprecision(20)<< sqrt(c);
    
    return 0;
    
}

Measured memory_bytes: 4136
#include <iostream>
#include <vector>

int main()
{
	int r, c;
	while (std::cin >> r >> c) {
		std::vector<std::vector<int>> vvi;
		int total = 0;
		std::vector<int> col_sum;
		for (int i = 0; i != r; ++i) {
			std::vector<int> vi;
			int row_sum = 0;
			for (int j = 0; j != c; ++j) {
				int rc;
				std::cin >> rc;
				row_sum += rc;
				if (i == 0) {
					col_sum.push_back(rc);
				} else {
					col_sum[j] += rc;
				}
				total += rc;
				vi.push_back(rc);
			}
			vi.push_back(row_sum);
			vvi.push_back(vi);
		}

		for (size_t i = 0; i != vvi.size(); ++i) {
			for (size_t j = 0; j != vvi[i].size(); ++j) {
				if (j) std::cout << ' ';
				std::cout << vvi[i][j];
			}
			std::cout << std::endl;
		}
		for (size_t i = 0; i != col_sum.size(); ++i) {
			if (i) std::cout << ' ';
			std::cout << col_sum[i];
		}
		std::cout << ' ' << total << std::endl;
	}

	return 0;
}


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

const int64_t MOD = 1e9+7;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}

int64_t dp[101][4][4][4];

bool ng(int a, int b, int c){
    return (a==1 && b==2 && c==3);
}

int main(){
    int N;
    cin >> N;
    dp[0][0][0][0] = 1;
    for(int i=0; i<N; i++) for(int a=0; a<4; a++) for(int b=0; b<4; b++) for(int c=0; c<4; c++) for(int d=0; d<4; d++){
        if(ng(a, b, c) || ng(a, c, d) || ng(a, b, d) || ng(b, c, d)) continue;
        if(ng(c, b, d) || ng(b, d, c)) continue;
        add(dp[i+1][b][c][d], dp[i][a][b][c]);
    }
    int64_t ans = 0;
    for(int a=0; a<4; a++) for(int b=0; b<4; b++) for(int c=0; c<4; c++) add(ans, dp[N][a][b][c]);
    cout << ans << endl;
    return 0;
}


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

int main() {
	int ans, N; cin >> N;
	int length = log10(N) + 1;
  
	switch (length) {
      case 1:
        ans = N;
        break;
      case 2:
        ans = 9;
        break;
      case 3:
        ans = 9 + N - 99;
        break;
      case 4:
        ans = 9 + 900;
        break;
      case 5:
        ans = 9 + 900 + N - 9999;
        break;
      case 6:
        ans = 9 + 900 + 90000;
        break;
    }
	cout << ans << endl;
}


Measured memory_bytes: 512
import java.util.*;
import java.awt.Point;
import static java.lang.System.*;
import static java.lang.Math.*;

public class Main {
    static int w, h;
    static boolean t[][][];
    static int U=0, R=1, D=2, L=3;
//    static int[] dx = {0, 1, 0, -1};
//    static int[] dy = {1, 0, -1, 0};

    static void solve(){
        LinkedList<Point> open = new LinkedList<Point>();
        boolean[][] closed = new boolean[h][w];
        Point st = new Point(0, 0);

        int cnt = 1;
        open.add(st);
        while(!open.isEmpty()){
            LinkedList<Point> next = new LinkedList<Point>();
            while(!open.isEmpty()){
                st = open.poll();

//                out.println(cnt+":"+st);

                int x = st.x;
                int y = st.y;

                if(x < 0 || x >= w || y < 0 || y >= h) continue;

                if(closed[y][x]) continue;
                closed[y][x] = true;

                if(st.x == w-1 && st.y == h-1){
                    out.println(cnt);
                    return;
                }

                if(!t[y][x][U]){
                    Point ns = new Point(x, y-1);
                    next.add(ns);
                }
                if(!t[y][x][R]){
                    Point ns = new Point(x+1, y);
                    next.add(ns);
                }
                if(!t[y][x][D]){
                    Point ns = new Point(x, y+1);
                    next.add(ns);
                }
                if(!t[y][x][L]){
                    Point ns = new Point(x-1, y);
                    next.add(ns);
                }
            }
            open = next;
            cnt++;
        }
        out.println(0);
    }

    static void disp(){
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                out.println(Arrays.toString(t[i][j]).replaceAll("true", "1").replaceAll("false", "0"));
            }
        }
    }

    public static void main(String[] args){
        Scanner sc = new Scanner(in);
        while(true){
            String[] sa = sc.nextLine().split(" ");
            w = new Integer(sa[0]);
            h = new Integer(sa[1]);
            if(w == 0 && h == 0) break;
            t = new boolean[h][w][4];
            for(boolean[][] i : t) for(boolean[] j : i) Arrays.fill(j, true);

            t[0][0][U] = false;
            t[h-1][w-1][D] = false;

            for(int i=0;i<h*2-1;i++){
                sa = sc.nextLine().trim().split(" ");
                if(i % 2 == 0){
                    int y = i / 2;
                    for(int x=0;x<w-1;x++){
                        boolean v = sa[x].equals("1");
                        t[y][x][R] = v;
                        t[y][x+1][L] = v;
                    }
                }
                else{
                    int y = i / 2;
                    for(int x=0;x<w;x++){
                        boolean v = sa[x].equals("1");
                        t[y][x][D] = v;
                        t[y+1][x][U] = v;
                    }
                }
            }

//            disp();

            solve();
        }
    }
}

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

using namespace std;

int main(){
    int n,a,b;
    cin >> n;
    vector<int> p(n),q(n),x(n);
    vector<vector<int>> ans(n,vector<int>());
    for(int i=0;i<n;++i) cin >> p[i];
    for(int i=0;i<n;++i) cin >> q[i];
    for(int j=0,i=1;i<=n;++i,++j) x[j] = i;
    do{
        ans.push_back(x);
    }while(next_permutation(x.begin(),x.end()));
    sort(ans.begin(),ans.end());
    for(int i=0;i<ans.size();++i){
        if(ans[i] == p)
            a = i+1;
        if(ans[i] == q)
            b = i+1;
    }
    cout << abs(a-b) << '\n';
}

Measured memory_bytes: 3256
#include <iostream>
#include <vector>

using namespace std;

using Matrix = vector<vector<int>>;

int main()
{
    int n, colors;
    cin >> n >> colors;

    if (n == 1) {
        cout << "0\n";
        return 0;
    }

    Matrix change_costs(colors, vector<int>(colors));
    for (auto &row : change_costs) {
        for (auto &cost : row) {
            cin >> cost;
        }
    }

    Matrix group_costs(3, vector<int>(colors, 0));
    for (int i = 0; i < n; i += 1) {
        for (int j = 0; j < n; j += 1) {
            int color;
            cin >> color;
            color -= 1;

            int group = (i + j) % 3;
            for (int next_color = 0; next_color < colors; next_color += 1) {
                group_costs[group][next_color] += change_costs[color][next_color];
            }
        }
    }

    int res = -1;
    for (int i = 0; i < colors; i += 1) {
        for (int j = 0; j < colors; j += 1) {
            for (int k = 0; k < colors; k += 1) {
                if (i == j || i == k || j == k) {
                    continue;
                }

                int cost = group_costs[0][i] +
                           group_costs[1][j] +
                           group_costs[2][k];
                res = (res == -1 ? cost : min(res, cost));
            }
        }
    }

    cout << res << "\n";
    return 0;
}


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

using namespace std;

const int N = 2 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

int n, k;
string s;

bool read() {
    if (!(cin >> n >> k >> s))
        return false;

    return true;
}

void solve() {
    s[k - 1] = tolower(s[k - 1]);
    cout << s << endl;
}

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

    while (read())
        solve();

    return 0;
}



Measured memory_bytes: 384
#include<stdio.h>

int main(){
    int height,width,h,w;
    char block;

    block = '#';

    for(;;){
        scanf("%d%d",&height,&width);
        if(width == 0 && height == 0)break;

        for(h = 1; h <= height; h++){
            
            if(h%2 != 0) block = '#';
            else block = '.';
            
            for(w = 1; w <= width; w++){
                printf("%c",block);

                if(block == '#')block = '.';
                else block = '#';

            }
            printf("\n");
            
        }
        printf("\n");
    }
    return 0;
}



Measured memory_bytes: 2112
#include<stdio.h>
int main (){
  int a,b[100],v,j;
  scanf("%d",&a);

  for(int i=0;i<a;i++){
    scanf("%d",&b[i]);
  }
      for(int g=0;g<a;g++){
	if(g==a-1)printf("%d",b[g]);
	else printf("%d ",b[g]);
  }
	printf("\n");

  for(int i=1;i<a;i++){
    
    v = b[i];
    j = i - 1;
   while (j >= 0 && b[j] > v){
     b[j+1] = b[j];
     j--;
     b[j+1] = v;
   }
  

      for(int g=0;g<a;g++){
	if(g==a-1)printf("%d",b[g]);
	else printf("%d ",b[g]);
  }
      printf("\n");
  }

  
  return 0;
}



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

int	main()
{
	int	N;
	cin >> N;
	int	cnt = 0;
	if (27 * 5 <= N) ++cnt;
	if (27 * 7 <= N) ++cnt;
	if (3 * 5 * 7 <= N) ++cnt;
	if (3 * 5 * 11 <= N) ++cnt;
	if (3 * 5 * 13 <= N) ++cnt;
	cout << cnt << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <utility>
using namespace std;

const int N = 1000000;
int n;
pair<int, int> a1[N];
pair<int, int> a2[N];
int n1, n2;
char s[N + 1];

bool test(pair<int, int> *a, int n) 
{
	sort(a, a + n);
	int p = 0;
	for (int i = 0; i < n; ++i) {
		if (a[i].first > p) return false;
		p += a[i].second;
	}
	return true;
}

int main() 
{
	scanf("%d", &n);
	int b = 0;
	for (int i = 0; i < n; ++i) {
		scanf("%s", s);
		int f = 0;
		int l = 0;
		for (int j = 0; s[j]; ++j) {
			f += (s[j] == '(') * 2 - 1;
			l = min(l, f);
		}
		b += f;
		if (f >= 0) {
			a1[n1] = make_pair(-l, f);
			++n1;
		}
		else {
			a2[n2] = make_pair(-l + f, -f);
			++n2;
		}
	}
	if (!b && test(a1, n1) && test(a2, n2)) printf("Yes\n");
	else printf("No\n");
	return 0;
}


Measured memory_bytes: 9424
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
struct edges
{
	int to,next;
}edge[202020];
int first[101010],now;
void adde(int x,int y)
{
	now++;
	edge[now].to=y;
	edge[now].next=first[x];
	first[x]=now;
}
int a[101010];
bool ap[101010];
int q1[101010],qn1;
int q[101010],qn;
bool vis[101010];
void dfs(int p)
{
	vis[p]=true;
	ap[a[p]]=true;
	q1[++qn1]=a[p];
	q[++qn]=p; 
	for(int e=first[p];e;e=edge[e].next)
		if(!vis[edge[e].to])
			dfs(edge[e].to);
}
int main()
{
	int n,m,x,y,ans=0;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	memset(first,0,sizeof(first));
	now=0;
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&x,&y);
		adde(x,y);
		adde(y,x);
	}
	memset(vis,0,sizeof(vis));
	memset(ap,0,sizeof(ap));
	for(int i=1;i<=n;i++)
		if(!vis[i])
		{
			qn1=qn=0;
			dfs(i);
			for(int j=1;j<=qn;j++)
				ans+=ap[q[j]];
			for(int j=1;j<=qn1;j++)
				ap[q1[j]]=false;
		}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 4608
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
p = list(li_())

a = [i*n for i in range(1, n+1)]
b = [i*n for i in range(1, n+1)][::-1]

for i, pi in enumerate(p):
    a[pi] += i
    b[pi] += i

print(*a)
print(*b)

Measured memory_bytes: 6344
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <functional>
#include <initializer_list>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, a, n) for (int i = (a); i < (int)(n); i++)
#define repc(i, a, n) for (int i = (a); i <= (int)(n); i++)
#define all(t) t.begin(), t.end()
#define rall(t) t.rbegin(), t.rend()
#define mat(type, row, col, init)                                              \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
#define DBG(str) cerr << (str) << endl;
int main() {

  string s;
  cin >> s;
  sort(all(s));
  if (s == "abc")
    cout << "Yes";
  else
    cout << "No";
  return 0;
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10**6)
def even(n): return 1 if n%2==0 else 0

k = int(readline())
lst1 = []
#最大10桁であることが保証される
def func(num,now):
    if num[0] != "0":
        lst1.append(int(num))
    if now == 10:
        return
    s = num[0]
    s = int(s)
    if s == 0:
        func("0"+num,now+1)
        func("1"+num,now+1)
    elif s == 9:
        func("8"+num,now+1)
        func("9"+num,now+1)
    else:
        for i in range(s-1,s+2):
            func(str(i)+num,now+1)

for i in range(10):
    func(str(i),0)

lst1.sort()
print(lst1[k-1])

Measured memory_bytes: 118232
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int k;
	cin >> k;
	if(k%2 == 0)
		cout << "-1\n";
	else{
		map<int,int> mp;
		int rem = 7%k;
		int ans = 1;
		int flag = 0;
		while(mp.count(rem) == 0){
			if(rem == 0){
				flag = 1;
				break;
			}
			++ans;
			mp[rem] = 1;
			rem = (rem*10 + 7)%k;
		}
		if(flag)
			cout << ans << "\n";
		else
			cout << "-1\n";
	}
}

Measured memory_bytes: 50504
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
ll llmax = LLONG_MAX;
string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alp = "abcdefghijklmnopqrstuvwxyz";
vi d1 = {1, 0, -1, 0}, d2 = {0, 1, 0, -1};
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << -1 << endl;}
void sorti(vi &a) {sort(a.begin(), a.end());}
void sortll(vll &a) {sort(a.begin(), a.end());}
void sorts(vs &a) {sort(a.begin(), a.end());}

int main() {
  ll n, k;
  cin >> n >> k;
  vll p(n);
  for (ll i = 0; i < n; i++) cin >> p[i];

  vector<double> q(n);
  for (ll i = 0; i < n; i++) {
    q[i] = (double)(p[i] + 1) / 2;
    if (i > 0) q[i] += q[i - 1];
  }

  priority_queue<double> r;
  r.push(q[k - 1]);
  for (ll i = 1; i <= n - k; i++) {
    r.push(q[k - 1 + i] - q[i - 1]);
  }
  cout << fixed << setprecision(8) << r.top() << endl;
}

Measured memory_bytes: 5492
#include<bits/stdc++.h>
#include<math.h>
#include <stdio.h>
#include<vector>
#include<stdlib.h>
//#include <algorithm>
#include <limits>
#include<string>
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define ll long long
#define d_5 100000
struct edge{
  struct treev* to;
  ll length;
};
struct treev{
  int num;
  vector<edge> nexts;
};
struct input{
  int u;
  int v;
  ll w;
};
bool cmp(const input &a, const input &b)//ソート用
{
  if(a.u!=b.u){
    return a.u<b.u;
  }else{
    return a.v<b.v;

  }
}
int* result;
vector<treev*> vs;
treev* createtreenode(int num){
  treev* newt=new treev;
  if(newt==NULL){
    cout << "memory error" << endl;
    while(1){
      num=1;//メモリエラー対策
    }
  }
  newt->num=num;
  newt->nexts={};
  //cout << "fff" << endl;
  return newt;
}
void insertree(ll len,int Va,int Vb){//結ぶ頂点を
  vs[Va]->nexts.push_back({vs[Vb],len});
  vs[Vb]->nexts.push_back({vs[Va],len});
  return;
}
void search(treev* root,ll depth,treev* pre){
  //cout << "eee" << endl;
    if(depth % 2 == 0){
      result[root->num]=0;
    }else{
      result[root->num]=1;
    }
  for(auto i:root->nexts){
    if(pre==i.to){
      continue;
    }
    search(i.to,depth+i.length,root);
  }
  return;
}
int main(void){
  ll N;
  cin >> N;
  ll tw ;
  int tu;
  int tv;
  treev* root=NULL;
  result=(int*)malloc(sizeof(int)*(N));
  rep(i,N){
    vs.push_back(createtreenode(i));
  }
  root=vs[0];//根の位置は今回どこでもいい
  rep(i,N-1){
    cin >> tu >> tv >>tw;
    tu--;tv--;
    insertree(tw,tu,tv);
  };
  //cout << "e";
  result[root->num]=0;
  search(root,0,NULL);
  rep(i,N){
    cout << result[i] << endl;
  }
	return 0;
}

Measured memory_bytes: 12532
import java.util.HashMap;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] x = new int[n];
		int[] y = new int[n];
		for ( int i = 0; i < n; i++ ) {
			x[i] = in.nextInt();
			y[i] = in.nextInt();
		}

		HashMap<String, Integer> vectorCnt = new HashMap<>();
		String vec = "";
		int maxV = 0;
		// 総当たりで2点間のベクトルを見ていく
		for ( int targ = 0; targ < n; targ++ ) {

			for ( int next = 0; next < n; next++ ) {

				int tempX = x[next] - x[targ];
				int tempY = y[next] - y[targ];
				vec = String.valueOf(tempX) + "_" + String.valueOf(tempY);

				if ( tempX == 0 && tempY == 0 ) {
					// 0移動はカウントしない
				} else {
					// ベクトルがマップにあったら個数を加算
					if ( vectorCnt.containsKey(vec) ) {
						//System.out.println(vec);
						vectorCnt.put(vec, vectorCnt.get(vec) + 1);
					} else
					// 無かったら登録して個数は１
					{
						vectorCnt.put(vec, 1);
					}
				}
			}
			//vectorCnt.clear();
		}

		// 同種ベクトルの個数の最大値を取得
		for ( Integer val : vectorCnt.values() ) {
			//System.out.println(val);
			if ( maxV < val ) maxV = val;
		}

		//System.out.println(maxV);
		System.out.println(n - maxV);
		in.close();
	}
}


Measured memory_bytes: 23892
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,i;
    cin>>n;
    int array[n];
    for(int i=0;i<n;i++){
        cin>>array[i];
    }
    sort(array,array+n);
    for(i=0;i<n-1;i++){
        if(array[i]==array[i+1]) break;
    }
    if(i==n-1) cout<<"YES";
    else cout<<"NO";
}

Measured memory_bytes: 1024
/* * * * * * * * * * * **
*                      *
*	   saurabh8522	   *
*	  I will handle	   *
*		   it.		   *
*                      *
* * * * * * * * * * * **/
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define ld long double
#define zero(a) memset((a),0,sizeof((a)))
#define one(a) memset((a),1,sizeof((a)))
#define minus(a) memset((a),-1,sizeof((a)))
#define all(g) g.begin(),g.end()
#define ppb pop_back
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> //indexed_set;
typedef long long int ll;
#define MOD 1000000007
ll extgcd(ll a,ll b,ll& x,ll& y){if(b==0){x=1;y=0;return a;}else{int g=extgcd(b,a%b,y,x);y-=a/b*x;return g;}}
ll modpow(ll a,ll b,ll m) {ll res=1;a%=m;for(;b;b>>=1){if(b&1)res=res*a%m;a=a*a%m;}return res;}
ll numdigit(ll n){return floor(log10(n)) + 1;}
bool isPowerTwo (ll x) { return x && (!(x&(x-1))); }
vector<ll>grp[200005]; 
ll dp[200005];
void dfs(ll node,ll p){
	dp[node]=0;
	for(int i=0;i<grp[node].size();i++){
		if(grp[node][i]!=p){
			dfs(grp[node][i],node);
			dp[node]++;
		}
	}
}
int  main(){
	FastRead;
	ll t=1;
	// cin>>t;
	while(t--){
		ll n;
		cin>>n;
		for(int i=0;i<n-1;i++){
			int a;
			cin>>a;
			grp[i+1].pb(a-1);
			grp[a-1].pb(i+1);
		}
		dfs(0,0);
		for(int i=0;i<n;i++){
			cout<<dp[i]<<endl;
		}
		// cout<<endl;
	}
}

Measured memory_bytes: 25404
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <sstream>
#include <queue>
#include <iomanip>
#include <algorithm>
using namespace std;

const int Maxn = 2005;

int n;
int P[Maxn];
int A[Maxn];
vector <int> neigh[Maxn];
int L[Maxn][Maxn];
vector <int> res;

void Record(int v, int whom)
{
	L[v][whom] = L[whom][whom];
	for (int i = 0; i < neigh[v].size(); i++)
		Record(neigh[v][i], whom);
}

void Traverse(int v, int lvl = 1)
{
	L[v][v] = lvl;
	Record(v, v);
	for (int i = 0; i < neigh[v].size(); i++)
		Traverse(neigh[v][i], lvl + 1);
}

void Move(int v)
{
	res.push_back(v);
	int wr = A[0];
	while (v != 0) {
		int sav = A[v]; A[v] = wr;
		wr = sav;
		v = P[v];
	}
	A[0] = wr;
}

bool Get(int v, int val)
{
	for (int i = 0; i < neigh[v].size(); i++)
		if (Get(neigh[v][i], val)) return true;
	if (!L[v][val]) return false;
	if (!L[v][A[v]] || L[v][A[v]] < L[v][val]) {
		Move(v);
		return true;
	}
	return false;
}

int main()
{
	scanf("%d", &n);
	for (int i = 1; i < n; i++) {
		scanf("%d", &P[i]);
		neigh[P[i]].push_back(i);
	}
	for (int i = 0; i < n; i++)
		scanf("%d", &A[i]);
	Traverse(0);
	while (Get(0, A[0])) ;
	printf("%d\n", int(res.size()));
	for (int i = 0; i < res.size(); i++)
		printf("%d\n", res[i]);
	return 0;
}

Measured memory_bytes: 15360
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on('line', function (line) {
  var i,j,result;
  var a = line.split(' ');
  var b = parseInt(a[0],10);
  var c = parseInt(a[1],10);
  if(!b && !c)
    process.exit();
  for(i=0;i<b;i++){
    result="";
    for(j=0;j<c;j++)
      result += "#";
    console.log(result);
  }
  console.log("");
});
process.stdin.on('end', function () {
});


Measured memory_bytes: 19844
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <string>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;

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

	//二分探索に備えて予めソートしておく
	vector<int> A(N);
	rep(i, N) cin >> A[i];
	sort(A.begin(), A.end());

	vector<int> B(N);
	rep(i, N) cin >> B[i];
	//Bを基準にA,Cを二分探索で調べるので、Bはソートの必要なし

	vector<int> C(N);
	rep(i, N) cin >> C[i];
	sort(C.begin(), C.end());

	long long ans = 0;
	rep(i, N)
	{
		auto position = lower_bound(A.begin(),A.end(),B[i]);
		long long A_count = distance(A.begin(),position);

		position = upper_bound(C.begin(), C.end(), B[i]);
		long long C_count = distance(position, C.end());

		ans += A_count * C_count;
	}

	cout << ans << endl;
}

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

#define INF 100000;

int main() {
  //A:value of 1L,B:value of 500ml, X: water of necessary
  int A, B, X, min = INF;
  std::cin >> A >> B >> X;

  for(int i=0; i*1000 <= X+1000; ++i) {
    for(int j=0; j*500 <= X+500; ++j) {
      if(i*1000+j*500 >= X) {
        if(min > i*A + j*B) min = i*A + j*B;
      }
    }
  }

  std::cout << min << "\n";

  return 0;
}



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

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int>p(N);

	for (int i = 0; i < N; i++)
	{
		cin >> p[i];
	}

	int cnt = 0;

	for (int i = 0; i < N; i++)
	{
		if (p[i] != i + 1) {
			cnt++;
		}
	}
	if (cnt <= 2) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	return 0;
}

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

using namespace std;



const int INF = 100000000;
const long long INFL = 100000000000000LL;

int n;
int size;
map<string, int> stoi;
bool visited[200][200];
long long cost[200];
int G[200][200];

int conv(string& str){
  return atoi(str.substr(3).c_str());
}

bool dfs(int p, long long cos){
  if(cost[p] == INFL) cost[p] = cos;
  if(cost[p] != cos) return false;
  for(int i=0;i<size;i++){
    if(i == p) continue;
    if(visited[p][i]) continue;
    if(G[p][i] == INF) continue;
    visited[p][i] = visited[p][i] = true;
    if(!dfs(i, cos + G[p][i])) return false;
  }
  return true;
}

main(){
  while(cin >> n && n){
    fill(G[0], G[200], INF);
    stoi.clear();
    size = 0;
    bool ans = true;
    for(int i=0;i<n;i++){
      string a, b;
      int in;
      cin >> a;
      cin >> a;
      cin >> b;
      cin >> b;
      in = conv(b);
      cin >> b;
      int c, d;
      if(stoi.find(a) == stoi.end()){
	stoi[a] = size++;
      }
      if(stoi.find(b) == stoi.end()){
	stoi[b] = size++;
      }
      c = stoi[a];
      d = stoi[b];
      if(c == d && in != 0) ans = false;
      G[c][d] = in;
      G[d][c] = -in;
    }
    if(ans){
      for(int i=0;i<size;i++){
	fill(visited[0], visited[200], false);
	fill(cost, cost+200, INFL);
	if(!dfs(i, 0LL)){
	  ans = false;
	  break;
	}
      }
    }
    cout << (ans ? "Yes" : "No") << endl;
  }
  return 0;
}

Measured memory_bytes: 1148
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
#define G() Cr=getchar()
#define LL long long
int Xr;char Cr;
inline int rd(){
	Xr=0, G();
	while(Cr<'0'||Cr>'9')G();
	while(Cr>='0'&&Cr<='9')Xr=(Xr<<3)+(Xr<<1)+Cr-'0', G();
	return Xr;
}
LL n,m;
int main(){
	cin>>n>>m;
	if(n*2==m||m*2==n)cout<<0;
	else{
		n=n%m;
		cout<<min(n,m-n);
	}
}

Measured memory_bytes: 256
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <complex>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;
constexpr ll LL_MAX = numeric_limits<ll>::max();
constexpr ull ULL_MAX = numeric_limits<ull>::max();

template<typename T>
vector<T> make_vec_nd(T init, ll size) {
	return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, ll size, Args... rest) {
	auto inner = make_vec_nd(init, rest...);
	return vector<decltype(inner)>(size, inner);
}

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrep(i, a, b) for (ll i = (a)-1; i >= (b); i--)

struct Mod {
    static uint64_t PRIME;
    struct LocalPrime {
        uint64_t backup;
        LocalPrime(uint64_t prime) { backup = exchange(Mod::PRIME, prime); }
        ~LocalPrime() { Mod::PRIME = backup; }
    };
    uint64_t value = 0;
    Mod()
    : value(0) {}
    Mod(ll v) {
        if (v >= 0) {
            value = v % PRIME;
        } else {
            value = PRIME - (-v) % PRIME;
        }
    }
    Mod operator+(const Mod& rhs) const { return Mod(*this) += rhs; }
    Mod& operator+=(const Mod& rhs) {
        value += rhs.value;
        if (value >= PRIME) {
            value -= PRIME;
        }
        return *this;
    }
    Mod operator-(const Mod& rhs) const { return Mod(*this) -= rhs; }
    Mod& operator-=(const Mod& rhs) {
        if (value < rhs.value) {
            value += PRIME;
        }
        value -= rhs.value;
        return *this;
    }
    Mod operator*(const Mod& rhs) const { return Mod(*this) *= rhs; }
    Mod& operator*=(const Mod& rhs) {
        value = (value * rhs.value) % PRIME;
        return *this;
    }
    Mod inv() const { return power(*this, PRIME - 2); }
    Mod operator/(const Mod& rhs) const { return Mod(*this) /= rhs; }
    Mod& operator/=(const Mod& rhs) {
        *this *= rhs.inv();
        return *this;
    }
    static Mod power(Mod rhs, ll exp) {
        Mod ans = 1;
        while (exp > 0) {
            if (exp % 2) {
                ans *= rhs;
            }
            rhs *= rhs;
            exp /= 2;
        }
        return ans;
    }
};
uint64_t Mod::PRIME = 1000000007;

int main() {
    ll N;
    cin >> N;
    string S;
    cin >> S;
    unordered_map<ll, ll> cnt;
    rep(i,0,N) {
        cnt[S[i]-'a']++;
    }
    Mod ans = 1;
    rep(i,0,26) {
        ans *= (1 + cnt[i]);
    }
    ans -= 1;
    cout << ans.value << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <limits.h>
#include <string>
using namespace std;

int main() {
	int N, M;
	cin >> N >> M;
	vector<int> X(M);
	for (int i = 0; i < M; i++)
		cin >> X[i];
	sort(X.begin(), X.end());
	vector<int> X_sub(M - 1);
	for (int i = 0; i < M - 1; i++)
		X_sub[i] = X[i + 1] - X[i];
	sort(X_sub.begin(), X_sub.end());
	int cnt = 0;
	for (int i = 0; i < M - N; i++)
		cnt += X_sub[i];
	cout << cnt;
}

Measured memory_bytes: 1024
#最大公約数
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a

#最大公約数の個数
def ngcd(a):
    res = a[0]
    for i in range(len(a)):
        if res != 1:
            res = gcd(a[i], res)
    return res

#最小公倍数
def lcm(a,b):
    return a * b // gcd(a, b)

#最小公倍数の個数
def nlcm(a):
    res = a[0]
    for i in range(len(a)):
        res = lcm(res, a[i])
    return res

n = int(input())
print(lcm(n, 2))

Measured memory_bytes: 3064
import java.util.*;
import java.io.*;

public class Main {
	
	public static void main(String[] args) throws IOException {
		InputReader in = new InputReader(System.in);
		int n = in.readInt();
		HashMap<Integer,Integer> map = new HashMap<>();
		for(int i = 0; i<n; i++) {
			int x = in.readInt();
			if(map.containsKey(x)) {
				map.remove(x);
			}
			else map.put(x, x);
		}
		int ans = 0; 
		for(Integer i : map.keySet()) {
			ans++;
		}
		System.out.println(ans);
	}
}
class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	public long readLong() {
		int c = read();
		while (isSpaceChar(c)) {
			c = read();
		}
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9') {
				throw new InputMismatchException();
			}
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}
	
	public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public String next() {
		return readString();
	}

	public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}


Measured memory_bytes: 31060
import java.util.*;
import java.io.*;

public class Main
{
	public static void main(String [] Args)
	{
		Scanner in=new Scanner(System.in);
		String s=in.next();
		int ans=0;
		for(int i=0;i<s.length()/2;i++)
		{
			if(s.charAt(i)!=s.charAt(s.length()-1-i))
			{
				ans++;
			}
		}
		System.out.println(ans);
	}
}
	

Measured memory_bytes: 23636
#include<stdio.h>
int main()
{
    int x,y,i;
    scanf("%d",&x);
    if(x==25)
        printf("Christmas\n");
    else if(x<25)
    {
        printf("Christmas ");
        y=25-x;
        for(i=1;i<y;i++)
        {
            printf("Eve ");
        }
        printf("Eve\n");
    }
    return 0;
}


Measured memory_bytes: 128
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(N: int, s: str):
    if(s.count('R')>s.count('B')):
        print(YES)
    else:
        print(NO)
    return


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    s = next(tokens)  # type: str
    solve(N, s)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
const ull B = 1777771;
ull S[100010],PB[100010]={1};
int n;
string str;

ull get(int l,int r){return S[r]-S[l]*PB[r-l];}
ull get(int l,int r,int x,char ch){
  ull res=get(l,r);
  if(x<l||r<=x) return res;
  return res+ch*PB[r-x-1]-str[x]*PB[r-x-1];
}

int search(int a,int b,int x,int ch){
  int L=0,M,R=1e5+1;
  while(L<R){
    M = (L+R)/2;
    if(max(a,b)+M>n||get(a,a+M,x,ch)!=get(b,b+M,x,ch)) R = M;
    else L = M+1;
  }
  return L-1;
}

bool check(int l,int r,int t){
  int p = l+t+search(l,l+t,-1,0);
  int q = l+(p-l-t)%t;
  return get(l,r-t,p,str[q])==get(l+t,r,p,str[q])||
    get(l,r-t,q,str[p])==get(l+t,r,q,str[p]);
}

int main(){
  cin>>str;
  n = str.size();
  for(int i=0;i<n;i++) S[i+1]=S[i]*B+str[i];
  for(int i=1;i<n;i++) PB[i]=PB[i-1]*B;
  
  int q;
  cin>>q;
  while(q--){
    int l,r,t;
    cin>>l>>r>>t;
    cout<<(check(l-1,r,t)? "Yes":"No")<<endl;
  }
  return 0;
}

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

#define ll long long
#define mod 1000000007

int main() {
	ll n;
	cin >> n;
	string s;
	cin >> s;
	ll lr, rw;
	ll ans = mod;
	ll buf;
	ll i, j;

	lr = 0;	rw = 0;
	for (i = 0; i <= n; i++) {
		if (s[i] == 'R')rw++;
	}
	for (i = 0; i <= n; i++) {
		
		if (lr == rw) {
			buf = lr;
		}
		else if (lr > rw) {
			buf = rw;
			buf += lr - rw;
		}
		else {
			buf = lr;
			buf += rw - lr;
		}
		if (buf < ans)ans = buf;
		if (i == n)break;
		if (s[i] == 'W')lr++;
		else rw--;
	}

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


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

int main() {
  std::string str;
  std::cin >> str;
  bool e[256] = {};
  int n = str.size();
  for(int i = 0; i < n; ++i) {
    e[(unsigned char)str[i]] = true;
  }

  puts(e['N'] == e['S'] and e['E'] == e['W'] ? "Yes" : "No");
  
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <random>
#include <iomanip>

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

typedef long long int ll;

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

#define fillInt(xs)        \
  for (int i = 0; i < (xs).size(); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs)       \
  for (int i = 0; i < (xs).size(); i++) \
    scanf("%ld", &xs[i]);
#define fillDouble(xs)       \
  for (int i = 0; i < (xs).size(); i++) \
    scanf("%lf", &xs[i]);
#define fillString(xs)       \
  for (int i = 0; i < (xs).size(); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvinv(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)
#define index_of(as, x) \
  distance(as.begin(), lower_bound(as.begin(), as.end(), x))
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define concat(xs, ys) (xs).insert((xs).end(), (ys).begin(), (ys).end())

const int mod = 1000000007;

struct td {
  char t;
  char d;
};

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

  int n, q;
  cin >> n >> q;

  string s;
  cin >> s;

  vector<td> magics;

  rep(i, q) {
    char t, d;
    cin >> t >> d;
    magics.push_back(td{t, d});
  }


int res = n;
 {
   int ub = n;
   int lb = -1;

  while(ub - lb > 1) {
    int next = (ub+lb)/2;
    char now = s[next];
    int nowi = next;
    int i = 0;
    while(i < q) {
      while(i < q && magics[i].t != now) {
        i++;
      }
      if (i == q) {
        break;
      }
      nowi = nowi + (magics[i].d == 'L' ? -1: 1);
      i++;
      if (nowi < 0 || nowi > n-1) {
        break;
      }
      now = s[nowi];
    }
    if (nowi < 0) {
      lb = next;
    } else {
      ub = next;
    }
  }
  res -= (lb+1);
 }

 {
   int ub = n;
   int lb = -1;

  while(ub - lb > 1) {
    int next = (ub+lb)/2;
    char now = s[next];
    int nowi = next;
    int i = 0;
    while(i < q) {
      while(i < q && magics[i].t != now) {
        i++;
      }
      if (i == q) {
        break;
      }
      nowi = nowi + (magics[i].d == 'L' ? -1: 1);
            i++;
      if (nowi < 0 || nowi > n-1) {
        break;
      }
      now = s[nowi];
    }
    if (nowi > n-1) {
      ub = next;
    } else {
      lb = next;
    }
  }
  res -= (n-ub);
 }
  
  cout << res << endl;
}


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

int main(){
    ios_base::sync_with_stdio(0);
    int n,h;
    cin>>n>>h;
    int mx=0;
    int b[n];
    for(int i=0;i<n;i++){
        int x;
        cin>>x>>b[i];
        mx = max(mx,x);
    }
    sort(b,b+n,greater<int>());
    int ans = 0;
    for(int i=0;i<n;i++){
        if(b[i]<=mx) break;
        h=h-b[i];
        ans++;
        if(h<=0){
            cout<<ans;
            return 0;
        }
    }
    cout<<ans+(h/mx)+(h%mx>0);
    return 0;
}


Measured memory_bytes: 640
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        char[][] map = new char[h][w];
        for(int i = 0; i < h; i++){
            map[i] = sc.next().toCharArray();
        }
        if(map[0][0] == '.'){
            System.out.println("Impossible");
            return;
        }else{
            map[0][0] = '.';
        }
        int y = 0;
        int x = 0;
        while(true){
            if(y == h-1 && x == w-1){
                break;
            }else if(y == h-1){
                if(map[y][x+1] == '#'){
                    map[y][x+1] = '.';
                    x++;
                }else{
                    System.out.println("Impossible");
                    return;
                }
            }else if(x == w-1){
                if(map[y+1][x] == '#'){
                    map[y+1][x] = '.';
                    y++;
                }else{
                    System.out.println("Impossible");
                    return;
                }
            }else{
                if(map[y+1][x] == '#' && map[y][x+1] == '#' || map[y+1][x] == '.' && map[y][x+1] == '.'){
                    System.out.println("Impossible");
                    return;
                }else if(map[y+1][x] == '#'){
                    map[y+1][x] = '.';
                    y++;
                }else if(map[y][x+1] == '#'){
                    map[y][x+1] = '.';
                    x++;
                }else{
                    System.out.println("Impossible");
                    return;
                }
            }
        }
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                if(map[i][j] == '#'){
                    System.out.println("Impossible");
                    return;
                }
            }
        }
        System.out.println("Possible");
    }
}


Measured memory_bytes: 23124
#if 1

#include <bits/stdc++.h>
using namespace std;
int n,x;
int a[100005],ap = 1;
int b[100005],bp = 1;

int main()
{
    scanf("%d",&n);
    for(int i = 1;i <= n;i++)
    {
        scanf("%d",&x);
        if(i % 2) a[x]++;
        else b[x]++;
    }
    int ma = 0,mb = 0,la = 0,lb = 0,pa,pb;
    for(int i = 1;i <= 100000;i++)
    {
        //if(a[i] > 0) cout << i << " " << a[i] << "\n";
        if(ma < a[i])
        {
            la = ma;
            ma = a[i];
            pa = i;
        }
        else if(la < a[i])
        {
            la = a[i];
        }
        if(mb < b[i])
        {
            lb = mb;
            mb = b[i];
            pb = i;
        }
        else if(lb < b[i])
        {
            lb = b[i];
        }
    }
    if(pa == pb)
    {
        printf("%d",min(n-ma-lb,n-la-mb));
    }
    else
    {
        printf("%d",n-ma-mb);
    }
}

#endif // 1++


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

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

int main(){
    int n, x, minim=INT32_MAX;
    cin >> n >> x;
    vector<int> dis;
    rep(i, n){
        int d;
        cin >> d;
        minim = min(minim, abs(d - x));
        dis.push_back(abs(d-x));
    }
    bool flag = true;
    int res = minim;
    while(flag){
        flag = false;
        rep(i, n){
            if(dis[i]%res!=0){
                flag = true;
                res--;
                break;
            }
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3876
fun main(args: Array<String>) {
    val N = readLine()!!.toLong()

    var res = N
    var k = 1L

    while(k * k <= N) {
        if (N % k == 0L) {
            res = k + N / k - 2
        }
        k++
    }

    println(res)
}


Measured memory_bytes: 33724
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

int main()
{
    int n;
    string s;
    cin >> n >> s;

    int ans = 0;
    rep(i, n - 2)
    {
        if (s.at(i) == 'A' && s.at(i + 1) == 'B' && s.at(i + 2) == 'C')
        {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define SP << " " 
#define LLi long long int

using namespace std;

int imax=2147483647;
long long int llimax=9223372036854775807;

//int型vectorを出力
void PV(vector<int> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

//LLi型vectorを出力
void PVL(vector<LLi> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

int main(){

	LLi n, ans=1;
	double d=0.0;
	vector<LLi> v;

	cin>> n;
	v.resize(n);

	rep(i, n) cin >> v[i];

	rep(i, n) {
		ans*=v[i];
		if(v[i]==0){
			cout<< "0" <<endl;
			return 0;
		}
		d+=log10(v[i]);
	}


	if(ans>1000000000000000000 || d>18.0) cout<< "-1" << endl;
	else cout<< ans << endl;
 
	return 0;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> friends(N);
  for (int i = 0; i < N; i++) {
    cin >> friends[i];
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (friends[i] >= K) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

using ll = long long;

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


Measured memory_bytes: 256