akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
n = gets.chomp.to_i

a = Array.new(100)

str = gets.chomp
a = str.split.map(&:to_i)

count = 0
for i in 0..(n-1) do
  minj = i
  for j in i..(n-1) do
    minj = j if a[j] < a[minj]
  end
  if a[i] != a[minj] then
    change = a[i]
    a[i] = a[minj]
    a[minj] = change
    count += 1
  end
end

for i in 0..n-1 do
  print a[i]
  print " " if i != n-1
end

print "\n", count, "\n"

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

using namespace std;

const int N = 1e5 + 5;

int n, a[N], dp[N];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    memset(dp, 0x3f, sizeof dp);
    dp[1] = 0;
    for (int i = 2; i <= n; i++) {
        if (i > 2) dp[i] = min(dp[i], dp[i - 2] + abs(a[i - 2] - a[i]));
        dp[i] = min(dp[i], dp[i - 1] + abs(a[i - 1] - a[i]));
    }
    
    cout << dp[n];
    return 0;
}

Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>; 
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
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; }


int main(){
  int n, m; ll k; cin >> n >> m >> k;
  ll sum = 0;
  vector<ll> A(n); rep(i, n){ cin >> A[i]; sum += A[i];}
  vector<ll> B(m); rep(i, m) cin >> B[i];

  ll res = 0, cntA = n, cntB = 0, index = 0;
  for(int i=n; i>=0; i--){
    if(sum <= k){
      //bを読めるだけ読む
      while(sum + B[index] <= k && index < m){
        sum += B[index];
        index++;
        cntB++;
      }
      chmax(res, cntA+cntB);
    }
    if(i>0){
      sum -= A[i-1];
      cntA--;
    }
  }
  cout << res << ln;
}
  


Measured memory_bytes: 6428
#include<iostream>
#include<string>
using namespace std;
int main(){
	int a,b,s,n;
	while(cin>>a>>b>>n){
		s=0;
		for(int i=0;i<n;i++){
			a*=10;
			s+=(a/b)%10;
			a%=b;
		}
		cout<<s<<endl;
	}
	return 0;
}

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

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

const int mod = 1e9 + 7;

int H, W;
string S[20];
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};

int bfs(int sx, int sy) {
    int dist[20][20];
    fill((int *)dist, (int *)(dist + 20), -1);
    dist[sy][sx] = 0;
    queue<P> que;
    que.emplace(sx, sy);
    while (!que.empty()) {
        int x, y;
        tie(x, y) = que.front();
        que.pop();
        for (int i = 0; i < 4; i++) {
            int nx = x + dx[i];
            int ny = y + dy[i];
            if (0 > nx || nx >= W || 0 > ny || ny >= H || S[ny][nx] == '#' ||
                dist[ny][nx] != -1)
                continue;
            dist[ny][nx] = dist[y][x] + 1;
            que.emplace(nx, ny);
        }
    }
    int ans = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++)
            ans = max(ans, dist[i][j]);
    }
    return ans;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> H >> W;
    for (int i = 0; i < H; i++)
        cin >> S[i];
    int ans = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (S[i][j] == '#')
                continue;
            ans = max(ans, bfs(j, i));
        }
    }
    cout << ans << endl;
}

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

int main(void)
{
    using namespace std;
    int N, X, Y;
    scanf("%d %d %d",&N, &X, &Y);

    vector<int> k(N, 0);
    for (int i = 1; i < N; i++) {
        for (int j = i + 1; j < N + 1; j++) {
            int z = min(j - i, abs(j - Y) + abs(X - i) + 1);
            k.at(z - 1)++;
        }
    }
    for (int i = 0; i < N - 1; i++) {
        cout << k.at(i) << "\n";
    }
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.TreeSet;

public class Main {
    public void solve(BufferedReader stdin, PrintWriter stdout) throws NumberFormatException, IOException {
        int n = Integer.parseInt(stdin.readLine());
        String s = stdin.readLine();

        List<TreeSet<Integer>> t = new ArrayList<>();
        int[] mins = new int[10];
        int[] maxs = new int[10];
        Arrays.fill(mins, Integer.MAX_VALUE);
        Arrays.fill(maxs, Integer.MIN_VALUE);
        for (int i = 0; i < 10; i++) {
            t.add(new TreeSet<>());
        }

        for (int i = 0; i < n; i++) {
            int x = s.charAt(i) - '0';
            mins[x] = Math.min(mins[x], i);
            maxs[x] = Math.max(maxs[x], i);
            t.get(x).add(i);
        }

        int ans = 0;
        for (int i = 0; i < 1000; i++) {
            int a = i / 100;
            int b = (i % 100) / 10;
            int c = i % 10;

            if (mins[a] == Integer.MAX_VALUE || maxs[c] == Integer.MIN_VALUE || mins[a] > maxs[c]) {
                continue;
            }

            Integer mid = t.get(b).higher(mins[a]);
            if (mid == null) {
                continue;
            }

            if (mid < maxs[c]) {
                ans++;
            }
        }

        stdout.println(ans);
    }


    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter stdout = new PrintWriter(System.out, false);
        new Main().solve(stdin, stdout);
        stdout.flush();
    }
}


Measured memory_bytes: 26692
#include <iostream>
using namespace std;
int main(){
	int a, b, c;

	cin >> a >> b >> c;
	int count = 0;
	for(int i = a; i<=b; i++){
		if (c%i==0){
			count++;

		}
			
	}

	cout << count <<'\n';
	return 0;
}

Measured memory_bytes: 3108
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Iterator;

class Graph {
	private int totalVertex;
	//adjMatrix[u][v] = 1 if there is an edge from u to v, otherwise 0
	private int[][] adjMatrix;
	//adjWeight[u][v] -- the weight of the edge from u to v if there is one
	private int[][] adjWeight;
	//if a node is settled (e.g., processed in the Dijkstra's algorithm)
	private Boolean[] ifSettled;
	public Graph() { totalVertex = 0; }
	public int getTotalVertex() { return totalVertex; }
	//load graph from standard input
	public void loadAdjMatrix() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		adjMatrix = new int[totalVertex][totalVertex];
		adjWeight = new int[totalVertex][totalVertex];
		ifSettled = new Boolean[totalVertex];
		int i, j;
		for(i = 0; i < totalVertex; i ++) {
			ifSettled[i] = false;
			for(j = 0; j < totalVertex; j ++) {
				adjMatrix[i][j] = adjWeight[i][j] = 0;
			}
		}
		int u, v;
		for(i = 0; i < totalVertex; i ++) {
			u = in.nextInt();
			int degree = in.nextInt();
			for(j = 0; j < degree; j ++) {
				v = in.nextInt(); 
				adjMatrix[u][v] = 1;
				adjWeight[u][v] = in.nextInt();
			}	
		}
		in.close();
	}
	//return weight of the edge from u to v if there is one
	public int getWeight(int u, int v) {
		return adjWeight[u][v];
	}
	//return neighbors of u as a LinkedList
	public LinkedList<Integer> getNeighbors(int u) {
		LinkedList<Integer> tmp = new LinkedList<Integer>();
		for(int v = 0; v < totalVertex; v ++) {
			if(adjMatrix[u][v] == 1) tmp.add(v);
		}
		return tmp;
	}
	//return unsettled neighbors of u as a LinkedList
	public LinkedList<Integer> getUnsettledNeighbors(int u) {
		LinkedList<Integer> tmp = new LinkedList<Integer>();
		for(int v = 0; v < totalVertex; v ++) {
			if((adjMatrix[u][v] == 1) && (ifSettled[v] == false)) tmp.add(v);
		}
		return tmp;
	}
	//return the unsettled node that has the smallest dist
	public int getUnsettledNearest(int[] dist) {
		int md = Integer.MAX_VALUE;
		int mv = -1;
		int v;
		for(v = 0; v < totalVertex; v ++) {
			if((ifSettled[v] == false) && (dist[v] < md)) {
				md = dist[v];
				mv = v;
			}
		}
		return mv;
	}
	//implement the following	
	public int[] Dijkstra(int s) {
		int[] dist = new int[totalVertex];
		for (int i=0;i<totalVertex;i++) {
			dist[i] = Integer.MAX_VALUE;
		}
		dist[s] = 0;		
		int curr = getUnsettledNearest(dist);
		
		while (curr != -1) {
			LinkedList<Integer> neighbor = getUnsettledNeighbors(curr);
			ifSettled[curr] = true;
			for(Integer i : neighbor) {
				dist[i] = Math.min(dist[i], dist[curr]  + getWeight(curr, i));
			}
			curr = getUnsettledNearest(dist);
		}		
		return dist;

	}
}

public class Main{
	public static void main(String[] argv) {
		Graph g = new Graph();
		g.loadAdjMatrix();
		int[] dist = g.Dijkstra(0);
		for(int i = 0; i < g.getTotalVertex(); i ++) {
			System.out.println(i + " " + dist[i]);
		}
	}
}


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

int main()
{
		double x1, y1, x2, y2, ans;
		cin >> x1 >> y1 >> x2 >> y2;
		ans = sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
		cout << fixed << ans << "\n";
}

Measured memory_bytes: 3228
#include <cstdio>
#define FOR(i, l, r) for(int i = l; i <= r; ++i)

using namespace std;

typedef long long ll;
const int N = 5010;
const int mod = 1e9 + 7;

struct edge{int to, next;} e[N << 1];
ll c[N][N], f[N][N], fac[N], ans;
int Size[N], size[N], head[N], rt[10], fa[N], n, cnt, x, y, tot;

void ins(int x, int y)
{
    e[++cnt].to = y; e[cnt].next = head[x]; head[x] = cnt;

}
void pre_work()
{
    fac[0] = 1; FOR(i, 1, n) fac[i] = fac[i - 1] * i % mod;
    FOR(i, 0, n)
    {
        c[i][0] = 1;
        FOR(j, 1, i) c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;
    }
}

void dfs(int x, int y)
{
    size[x] = 1; bool fl = 1;
    for(int i = head[x]; i; i = e[i].next)
        if (e[i].to != y)
        {
            dfs(e[i].to, x); fa[e[i].to] = x;
            if (size[e[i].to] > n / 2) fl = 0;
            size[x] += size[e[i].to];
        }
    if (n - size[x] > n / 2) fl = 0;
    if (fl) rt[++tot] = x;
}

int main()
{
    scanf("%d", &n);
    FOR(i, 2, n)
    {
        scanf("%d%d", &x, &y);
        ins(x, y); ins(y, x);
    }
    pre_work();
    dfs(1, 0);
    if (tot == 2) printf("%lld\n", fac[n / 2] * fac[n / 2] % mod);
    else
    {
        f[0][0] = 1; ll now = 1;
        Size[tot = 1] = n - size[rt[1]];
        for(int i = head[rt[1]]; i; i = e[i].next)
            if (e[i].to != fa[rt[1]]) Size[++tot] = size[e[i].to];
        FOR(i, 1, tot) FOR(j, 0, Size[i]) FOR(k, 0, n)
            (f[i][k + j] += f[i - 1][k] * c[Size[i]][j] % mod * c[Size[i]][j] % mod * fac[j]) %= mod;
        FOR(i, 0, n - 1) ans = (ans + mod + now * f[tot][i] * fac[n - i] % mod) % mod, now = -now;
        printf("%lld\n", ans);
    }
    return 0;
}


Measured memory_bytes: 392192
#include <vector>
#include <iostream>
#include <map>
#include <numeric>
#include <cmath>
using namespace std;

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

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

   map<int, int> hist;
   int z = 0;
   bool isValid = true;
   for (int i = 0; i < n && isValid; ++i) {
      if (v[i] == 0) {
         ++z;
         if (z > 1) {
            isValid = false;
         }
      }
      else {
         ++hist[v[i]];
         if (hist[v[i]] > 2) {
            isValid = false;
         }
      }
   }

   long long res = 0l;
   if (isValid) {
      const int size = (int)hist.size();
      //res = (long long)pow(2l, size);
      long long bil = 1e9;
      res = 1l;
      for (int i = 0; i < size; ++i) {
         res = (2l*res) % (bil + 7l);
      }
   }

   cout << res << endl;

   //int tmp;
   //cin >> tmp;

    return 0;

}

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

int main(){
  string X;
  cin >>X;
  if(X == "A"){
    cout<<"T"<<endl;
  }else if(X == "T"){
    cout<<"A"<<endl;
  }else if(X == "C"){
    cout<<"G"<<endl;
  }else{
    cout<<"C"<<endl;
  }
}
  

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

using namespace std;

int main() {
    while(true) {
        int a, b;
        cin >> a >> b;
        if(!a && !b) break;

        vector<vector<int> > dp(a, vector<int>(b, 0));
        dp[0][0] = 1;

        int n;
        cin >> n;
        while(n--) {
            int x, y;
            cin >> x >> y;
            --x; --y;
            dp[x][y] = -1;
        }
        for(int i = 0; i < a; ++i) {
            for(int j = 0; j < b; ++j) {
                if(dp[i][j] == -1) continue;
                if(i-1 >= 0 && dp[i-1][j] != -1) dp[i][j] += dp[i-1][j];
                if(j-1 >= 0 && dp[i][j-1] != -1) dp[i][j] += dp[i][j-1];
                if(i+1 < a && dp[i+1][j] != -1) dp[i][j] += dp[i+1][j];
                if(j+1 < b && dp[i][j+1] != -1) dp[i][j] += dp[i][j+1];
            }
        }

        cout << dp[a-1][b-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 0
#include <iostream>

using namespace std;

int main(void){
	int n,y,res[3] = {-1,-1,-1};
	cin >> n >> y;
	for(int a=0;a<=n;a++){
		for(int b=0;b<=n-a;b++){
			if(10000*a + 5000*b + 1000*(n-a-b) == y){
				res[0] = a;
				res[1] = b;
				res[2] = n - a - b;
			}
		}
	}
	cout << res[0] << " " << res[1] << " " << res[2] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll mod= 1e9 + 7;



int main() {
  char c;
  cin >> c;
  if(c=='a' || c=='i' || c=='u' || c=='e' || c=='o'){cout << "vowel" << endl;}
  else{cout << "consonant" << endl;}
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define ll long long
int main(){
  int N,K;
  cin>>N>>K;
  if(N%K) cout<<"1"<<endl;
  else cout<<"0"<<endl;
}

Measured memory_bytes: 256
n = int(input())
s = input()
D = [[0] * n for i in range(n)]
 
for i in range(n):
    D[0][i] = int(s[0]==s[i])
    D[i][0] = int(s[0]==s[i])
D[0][0] = 0

for i in range(1,n):
    for j in range(i+1,n):
        mae = D[i-1][j-1]
        if s[i] == s[j]:
            if j-i <= mae:
                D[i][j] = mae
            else:
                D[i][j] = mae + 1

print(max([max(D[i]) for i in range(n)]))


Measured memory_bytes: 230024
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
#include<vector>
#include<queue>
#include<deque>
#include<iomanip>
#include<map>
using namespace std;
typedef pair<int, pair<int, int> >PP;
typedef long long ll;
typedef pair<int, int>P;
typedef vector<int>vec;
int inf=-1;
ll mod = pow(10, 9) + 7;

int main(){
	int m,d;cin>>m>>d;
	int cnt=0;
	for(int i=1;i<=m;i++){
		for(int d10=2;d10<=9;d10++){
			if(i%d10==0 && d10*10+i/d10<=d){
				if(i/d10<=9&&2<=i/d10){
					cnt++;
				}
			}
		}
	}
	cout<<cnt<<endl;
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  int C = 0;

  for (int i = 0; i < N; i++){
    int A;
    cin >> A;
    int temp = 0;

    while(1){
      if(A % 2 == 0){
        A = A / 2;
        temp += 1;
      }
      else
      {
        break;
      }
    }

    if(temp == 0){
      C = 0;
      break;
    }
    if(C == 0){
      C = temp;
    }
    else if (C > temp)
    {
      C = temp;
    }

  }
  cout << C << endl;

}



Measured memory_bytes: 256
import itertools
from itertools import zip_longest

x, y, a, b, c = map(int, input().split())
ans_list = list()
p = list()
for i in input().split():
  p.append(int(i))
q = list()
for i in input().split():
  q.append(int(i))
r = list()
for i in input().split():
  r.append(int(i))

sort_p = sorted(p, reverse=True)
sort_q = sorted(q, reverse=True)
sort_r = sorted(r, reverse=True)
sort_r_max = sort_r[:x+y]

ans_list.append(sort_p[:x])
ans_list.append(sort_q[:y])

sort_ans = sorted(list(itertools.chain.from_iterable(ans_list)))
ans = 0
for i, j in zip_longest(sort_ans, sort_r_max, fillvalue=0):
  if i < j:
    ans += j
  else:
    ans += i
print(ans)



Measured memory_bytes: 119276
#include<stdio.h>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>     
#include <numeric>
#include <utility>
#include <queue>
#include <set>
#include <sstream>
#include <iomanip>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define rep(a,t) for(int a=0;a<t;++a) 
#define forever while(true)
#define Sort(a) sort(a.begin(),a.end())
#define Reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define int_maxvalue numeric_limits<int>::max()
ll mod = 1e9 + 7;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	bool red[111111];
	int white[111111];
	for (int i = 1; i <= n; i++) {
		if (i == 1) { red[i] = true; }
		else { red[i] = false; }
		white[i] = 1;
	}
	for (int i = 1; i <= m; i++) {
		int from, to;
		cin >> from >> to;

		if (red[from]) {
			red[to] = true;
		}
		white[from]--; white[to]++;
		if (white[from] == 0) { red[from] = false; }
	}
	ll ans = 0;
	for (int i = 1; i <= n; i++) {
		if (red[i]) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 768
void main() {
    writeln(48 - readln.chomp.to!int);
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

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

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

int main() {
    int N;
    cin >> N;
    vector<int> d(N);
    rep (i, d.size())
        cin >> d.at(i);
    
    int ans = 0;
    rep(i, d.size()) {
        for (int j = i + 1; j < d.size(); j++) {
            ans += d.at(i) * d.at(j);
        }
    }

    cout << ans << endl;
}

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

int main() {
    ll t,n=0,k,k1,k2,b,m,c;
    cin>>n>>k;
    ll a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    k1=0,k2=k;
    while(k2<n){
        if(a[k2]>a[k1]){
            cout<<"Yes"<<endl;
        }else
            cout<<"No"<<endl;
        k1++;
        k2++;
    }
    return 0;
    while(t--){
        ll ans=0,c=0;
        cin>>n;
        //string s;
        //cin>>s;
        int a[n];
        for(int i=0;i<n;i++)
            cin>>a[i];

    }
    return 0;
}


Measured memory_bytes: 5156
#include<bits/stdc++.h>
using namespace std ; 
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fast ios_base:: sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long int
#define pb push_back
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second
#define pii pair<int,int> 
long long MOD  = 1e9+7;


signed main(){
     fast;
     int n,k; cin >> n >> k;
     vector <int> arr(n);
     for(int i=0 ; i<n ; i++)
          cin >> arr[i];
     int num = 0;
     for(int i=50 ; i>=0 ; i--){
          int one=0,zero=0;
          for(int j=0 ; j<n ; j++){
               int p = ((int)1<<i);
               if( arr[j] & p ){
                    one++;
               }
           
          }
       if(one*2 < n && (num + ((int)1<<i)) <= k){
                    num = num + ((int)1<<i);
               }
     }
  	//cout << num << endl;
     int ans = 0;
     for(int i=0 ; i<n ; i++){
          ans = ans + (arr[i]^num);
     }
     cout << ans << endl;
}


Measured memory_bytes: 1024
x, y, a, b, c = map(int,input().split())
Ps = list(map(int,input().split()))
Qs = list(map(int,input().split()))
Rs = list(map(int,input().split()))

Ps.sort(reverse=True)
Qs.sort(reverse=True)
Rs.sort(reverse=True)

apple = Ps[:x] + Qs[:y]
apple.sort()

point = sum(apple)
kosuu = min(x+y, c)

for i in range(kosuu):
    if apple[i] < Rs[i]:
        point = point - apple[i] + Rs[i]
    else:
        break
print(point)

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

int main() {
	unsigned n; cin >> n;
	unsigned e = n;
	for (unsigned i = 2; i * i <= n; i++) {
		int c = 0;
		while (n % i == 0) { n /= i; c++; }
		if (c == 0) continue;
		e = e / i * (i - 1);
	}
	if(n != 1) e = e / n * (n - 1);
	cout << e << endl;
	return 0;
}


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

typedef long long ll;

int main(void) {
	ll X, Y;
	string ans = "Alice";
	cin >> X >> Y;

	if (X > Y) {
		if (X - Y == 1)
			ans = "Brown";
	}
	else if (Y > X) {
		if (Y - X == 1)
			ans = "Brown";
	}
	else
		ans = "Brown";

	cout << ans << '\n';
	return 0;
}


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

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (auto& e : v) {
        cin >> e;
    }
    sort(v.begin(), v.end());
    // 1 2 4 5
    int left = v[n/2-1];
    int right = v[n/2];
    cout << right - left << endl;
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int a,n,m;
	int x,cnt,sum,y;
	int i;
	cin>>a>>n>>m;
	y=m;
	cnt=0;
	while(y>0){
		y/=10;
		cnt++;
	}
	y=9*cnt;
	cnt=0;
	for(i=1;i<=y;i++){
		sum=a+i;
		sum=pow(sum,n);
		if(sum<=m){
			x=sum;
			sum=0;
			while(x>0){
				sum+=x%10;
				x/=10;
			}
			if(sum==i)	/*printf("sum=%d i=%d\n",sum,i),*/cnt++;
		}
	}
	cout<<cnt<<endl;
	return 0;
}



Measured memory_bytes: 3280
#include <iostream>
#include <algorithm>
using namespace std;
 
int gcd(int a, int b){
    if( a==1 || b==1 ) return 1;
    else if(max(a,b)%min(a,b) == 0) return min(a,b);
    else return gcd(min(a,b), (max(a,b))%(min(a,b)));
}
 
 
int main() {
    // your code goes here
    int a, b;
    cin >> a >> b;
    cout << gcd(a, b) << endl;
    return 0;
}

Measured memory_bytes: 3048
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;
int main()
{
    long long n;
    cin>>n;
    for(long long i=sqrt(n)+1; i>=1; i--)
    {
        if(n%i==0)
        {
            cout<<n/i+i-2<<endl;
            break;
        }
    }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, k, a;
  cin >> n >> k;
  vector<int> A(200100);
  while(cin >> a) ++A[a];
  sort(A.begin(), A.end());
  int Ak = 0, idx = 0, ans = 0;
  for(int a : A) if(a) ++Ak;
  while(Ak > k){
    if(A[idx]){
      ans += A[idx];
      --Ak;
    }
    ++idx;
  }
  cout << ans << endl;
}

Measured memory_bytes: 4028
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    int d; cin >> d;
    if(d == 22) cout << "Christmas Eve Eve Eve" << endl;
    if(d == 23) cout << "Christmas Eve Eve" << endl;
    if(d == 24) cout << "Christmas Eve" << endl;
    if(d == 25) cout << "Christmas" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String args[]){
        
        Scanner sc = new Scanner(System.in);
        int baseN = sc.nextInt();
        int n = baseN;
        
        int s = 0;
        while(n > 0){
            s += n % 10;
            n /= 10;
        }
        
        System.out.println(baseN % s == 0 ? "Yes" : "No");
        
    }
}

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

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

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

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

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

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

const ll INF = 1e16;
struct segTree{
  ll n;
  vector<ll> node;

  void init(ll x){
    n = 1;
    while(n < x) n *= 2;
    node.resize(n*2-1,INF);
  }

  void update(ll i, ll x){
    i += n-1;
    node[i] = x;
    while(i > 0){
      i = (i-1)/2;
      node[i] = min(node[i*2 +1],node[i*2+2]);
    }
  }

  ll getMin(ll x, ll y, ll k=0, ll l=0, ll r=-1){
    if(r < 0) r = n;
    if(r<=x || l>=y) return INF;
    if(x<=l && r<=y) return node[k];

    ll vl = getMin(x, y, 2*k+1, l, (l+r)/2);
    ll vr = getMin(x, y, 2*k+2, (l+r)/2, r);
    return min(vl,vr);
  }
};

int main(){
  ll n,q;
  cin >> n >> q;
  segTree t;
  t.init(n);

  t.update(0,0);

  ll xx[q],tt[q],ss[q];
  vector<pair<int,PII>> p;
  rep(i,q){
    cin >> ss[i] >> tt[i] >> xx[i];
    p.push_back({ss[i],{tt[i],i}});
  }
  sort(all(p));
  rep(i,q){
    int idx = p[i].second.second;
    ll a = ss[idx];
    ll b = tt[idx];
    ll c = xx[idx];
    a--,b--;

    ll tmp = t.getMin(a,n);
    ll tmin = t.getMin(b,b+1);

    if(tmp == INF) continue;
    if(tmp + c > tmin) continue;
    t.update(b,tmp+c);
  }
  ll ans = t.getMin(n-1,n);
  if(ans == INF) cout << -1 << endl;
  else cout << ans << endl;
  return 0;
}


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

int main() {
	int N;
	cin >> N;
	string result = "Yes";
	char str[200];
	if (N == 1)
		result = "No";
	if (N % 2 == 1)
		result = "No";
	int M = N / 2;
	for (int i = 0; i < M; i++) {
		cin >> str[i];
	}
	for (int i = 0; i < M; i++) {
		char s;
		cin >> s;
		if (str[i] != s) {
			result = "No";
			break;
		}
	}
	cout << result << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
vector<int> G[2010];
int d[2010],inf = 10000000,ans[2010] = {};
void bfs(int s,int n){
    int i;
    for(i=0;i<n;i++){
        d[i] = inf;
    }
    queue<int> que;
    que.push(s); d[s] = 0;
    while(que.size()){
        int x = que.front(); que.pop();
        for(int v:G[x]){
            if(d[v]==inf){
                d[v] = d[x] + 1;
                que.push(v);
            }
        }
    }
    for(i=0;i<n;i++){
        ans[d[i]]++;
    }
}

int main(){
    int i,n,x,y;
    cin >> n >> x >> y;
    x--; y--;
    for(i=0;i<n - 1;i++){
        G[i].push_back(i + 1);
        G[i + 1].push_back(i);
    }
    G[x].push_back(y);
    G[y].push_back(x);
    for(i=0;i<n;i++){
        bfs(i,n);
    }
    for(i=1;i<n;i++){
        cout << ans[i]/2 << endl;
    }
}

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

const long long INF = 1e18;


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

    long long dp[N + 1][2];
    for (int i = 0; i < N + 1; i++) for (int j = 0; j < 2; j++) dp[i][j] = 0;
    dp[0][1] = - INF;

    for (int i = 0; i < N; i++) {
        dp[i + 1][0] = max(dp[i][0] + A[i], dp[i][1] - A[i]);
        dp[i + 1][1] = max(dp[i][0] - A[i], dp[i][1] + A[i]);
    }

    cout << dp[N][0] << endl;
    return 0;
}


Measured memory_bytes: 2176
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gcd, sqrt
from operator import mul
from functools import reduce
from operator import mul
from pprint import pprint



sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n = int(input())
a = list(map(int, input().split()))
c = a[0] + a[1]

t = 0
flg = 0

for ai in a[2:]:
    t = t ^ ai

if c < t:
    flg = 1

if (c - t) % 2:
    flg = 1

b1 = (c - t) // 2

a1 = b1

if a1 > a[0]:
    print(-1)
    sys.exit()

for i in reversed(range((a[0] + a[1]).bit_length())):
    if t & (1 << i):
        if b1 & (1 << i):
            print(-1)
            sys.exit()
        if a1 + 2 ** i <= a[0]:
            a1 += 2 ** i

if a1 == 0:
    flg = 1

print(a[0] - a1 if flg == 0 else -1)











Measured memory_bytes: 76760
require 'pp'
# IS_DEBUG = true
IS_DEBUG = false
def dputs str
	if(IS_DEBUG)
		puts str
	end
end
def dpp str
	if(IS_DEBUG)
		pp str
	end
end

require 'pp'

N,d=gets.chomp.split(' ').map{|n| n.to_i}
A=gets.chomp.split(' ').map{|n| n.to_i}
S=Array.new(N)
S[0]=A[0]
1.upto(A.size-1){|i|
	S[i] = S[i-1]+A[i]
}

# separate abc
#  A[0] 0 A[1] ... N-2 A[N-1] N-1
# a,b,c in 1 ~ N-1

INT_MAX = 99999999999999
diff = INT_MAX
i0 = 0
i1 = 1
i2 = 2
while(i1<=N-3)
	sum0 = S[i0]
	sum1 = S[i1]-S[i0]
	currdiff0 = (sum1-sum0).abs
	sum2 = S[i2]-S[i1]
	sum3 = S[N-1]-S[i2]
	currdiff1 = (sum3-sum2).abs
	while(true)
		# set
		if(i1 - i0 <= 1)
			break
		end
		nextsum0 = S[i0+1]
		nextsum1 = S[i1]-S[i0+1]
		nextdiff0 = (nextsum1 - nextsum0).abs
		# proceed
		if(currdiff0 > nextdiff0)
			currdiff0 = nextdiff0
			sum0 = nextsum0
			sum1 = nextsum1
			i0 += 1
		else
			break
		end
	end
	while(true)
		# set
		if(N-1 - i2 <= 1)
			break
		end
		nextsum2 = S[i2+1]-S[i1]
		nextsum3 = S[N-1]-S[i2+1]
		nextdiff1 = (nextsum3 - nextsum2).abs
		# proceed
		if(currdiff1 > nextdiff1)
			currdiff1 = nextdiff1
			sum2 = nextsum2
			sum3 = nextsum3
			i2 += 1
		else
			break
		end
	end
	arr = [sum0,sum1,sum2,sum3]
	tdiff = arr.max - arr.min
	dputs "i0,i1,i2 = #{i0},#{i1},#{i2}"
	dputs "#{tdiff} = #{arr.max} - #{arr.min}"
	tdiff < diff ? diff = tdiff : diff
	i1 += 1
end
puts diff


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

using ll = long long;

constexpr int DIVISOR = 1e9+7;

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

  map<char, int> m;
  for (int i{}; i < N; ++i) {
    ++m[S[i]];
  }

  ll ans{1};
  for (const auto& p : m) {
    ans = ans * (p.second+1) % DIVISOR;
  }

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


Measured memory_bytes: 512
#include <iostream>

using namespace std;

typedef long long ll;

int main(){
  ll K, N, tmp;
  cin >> K >> N;
  ll max_dis = -1;
  ll tmp_s = -1, tmp_e = -1;
  ll ans = 0;
  ll prev = -1;
  for (ll i=0; i<N; i++){
    cin >> tmp;
    if (prev != -1){
      max_dis = max(max_dis, abs(prev - tmp));
    }
    else{
      tmp_s = tmp;
    }
    prev = tmp;
    if (i == N - 1) tmp_e = tmp;
  }
  max_dis = max(max_dis, K - tmp_e + tmp_s);
  cout << K - max_dis << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = (m); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl


int main() {
    int N;  cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];

    sort(all(A));
    int s = A.size();
    vector<pair<int, int>> p;
    if (A[0] < 0 && A[s-1] >= 0) {
        int tmp1 = A[s-1];
        int tmp2 = A[0];
        if (A[1] < 0) {
            // 負数のうちtmp2以外をtmp1に集める(正数になる)
            rep(i, N) {
                if (A[i+1] >= 0) break;
                p.push_back(make_pair(tmp1, A[i+1]));
                tmp1 -= A[i+1];
            }
        }
        if (A[s-2] >= 0) { 
            // 正数のうちtmp1以外をtmp2に集める(負数になる)
            rep(i, N) {
                if (A[s-2-i] < 0) break;
                p.push_back(make_pair(tmp2, A[s-2-i]));
                tmp2 -= A[s-2-i];
            } 
        }
        print(tmp1 - tmp2);
        p.push_back(make_pair(tmp1, tmp2));
        rep(i, p.size()) print(p[i].first << ' ' << p[i].second);

    } else if (A[0] < 0) {
        int tmp = A[s-1];
        rep(i, N-1) {
            p.push_back(make_pair(tmp, A[i]));
            tmp -= A[i];
        }
        print(tmp);
        rep(i, p.size()) print(p[i].first << ' ' << p[i].second);

    } else {
        int tmp1 = A[s-1];
        int tmp2 = A[0];
        REP(i, 1, N-1) {
            p.push_back(make_pair(tmp2, A[i]));
            tmp2 -= A[i];
        }
        print(tmp1 - tmp2);
        p.push_back(make_pair(tmp1, tmp2));
        rep(i, p.size()) print(p[i].first << ' ' << p[i].second);
    }

    return 0;
}


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#include<limits.h>
#include<stdio.h>
#include<cstring>
#include<string>
using namespace  std;
typedef long long ll;
typedef long double ld;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define fi first
#define se second
#define rsz(a,n) a.resize(n)
#define test(t) ll t;cin>>t;while(t--)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define fillv(a,k) memset(a,k,sizeof(a))
#define leadzero(a) __builtin_clz(a) //count leading zeros
#define trailzero(a) __builtin_ctz(a) //count trailing zeros
#define bitcount(a) __builtin_popcount(a) // count set bits (add ll)
#define ln cout<<"\n"
// #define sp cout<<" "
#define spaceprint(a,i,s,n) {forsn(i,s,n) { cout<<a[i]; sp;}}
#define lineprint(a,i,s,n) {forsn(i,s,n) {cout<<a[i]; ln;}}
#define maxe(a) *max_element(a.begin(),a.end())
#define maxi(a) max_element(a.begin(),a.end())-a.begin()
#define mine(a) *min_element(a.begin(),a.end())
#define mini(a) min_element(a.begin(),a.end())-a.begin()
#define all(c) c.begin(),c.end()
#define trav(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element)  (find(all(container),element) != container.end())// check the presence of element
//copy(from_begin, from_end, to_begin); copy function
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<ll> v64;
typedef vector<string> vs;
typedef vector<int> v32;
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<p64> vp64;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
typedef map<ll,ll> m64;
const int LIM = 1e5+5, MOD =  1e9;
#define sumv(v) accumulate(all(v),ll(0))
#define productv(v) accumulate(all(v), ll(1), multiplies< ll >())
ll gcd(ll a, ll b) { if(b == 0) return a; return gcd(b, a % b); }
ll fastpowMOD(ll a, ll p,ll MOD){ if(p==0) return 1; ll z = fastpowMOD(a,p/2,MOD); z = (z*z)%MOD; if(p%2) z = (z*a)%MOD; return z; }
bool seive[100005];
void SieveOfEratosthenes(ll n)
{ memset(seive, true, sizeof(seive)); for (ll p=2; p*p<=n; p++) if (seive[p] == true) for (ll i=p*p; i<=n; i += p) seive[i] = false; }
// ll a[11*LIM]={0},b[11*LIM]={0};
// vp64 v[LIM];
typedef struct 
{
	ll one,two,three;
}data;





int main()
{
	fast;
	string s;
	cin>>s;
	if (s[2]==s[3]&&s[4]==s[5])
		cout<<"Yes";
	else
		cout<<"No";

} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep3(i, l, n) for (int i = l; i < n; ++i)
#define max(a, b) (a > b ? a : b)
#define min(a, b) (a < b ? a : b)
#define chmax(a, b) a = (a >= b ? a : b)
#define chmin(a, b) a = (a <= b ? a : b)
#define out(a) cout << a << endl
#define outa(a, n) { rep(_, n) cout << a[_] << " "; cout << endl; }
#define outp(a, n) { cout << endl; rep(_, n) cout << a[_].F << " " << a[_].S << endl; }
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
#define FIX(a) fixed << setprecision(a)
#define LB(v, n) (int)(lower_bound(all(v), n) - v.begin())
#define UB(v, n) (int)(upper_bound(all(v), n) - v.begin())

// https://atcoder.jp/contests/agc009/submissions/6437510

int main() {
    int n;
    cin >> n;
    ll a[n], b[n];
    rep(i, n) cin >> a[i] >> b[i];
    
    ll sum = 0;
    for (int i = n - 1; i >= 0; --i) {
        sum = (a[i] + sum + (b[i] - 1)) / b[i] * b[i] - a[i];
    }
    // a[i] + sum = a'[i]
    // a'[i] / b[i]の切り上げ * b[i] : a'[i]以上で最小のb[i]の倍数
    
    out(sum);
}


Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <cmath>
#include <complex>
#include <algorithm>
#include <utility>
#include <regex>
#include <cstdint>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
using ll = int64_t;
using ull = uint64_t;

constexpr ll INF = 1000000000;/* 1e+9a */

void sub_main(istream &cin) {
    ll A, B, C;
    cin >> A >> B >> C;
    if(!cin) return;
    cout << (A == B and B == C ? "Yes" : "No")  << endl;

}

int main(int argc, char *argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(16) << scientific;
#ifdef DEBUG
    cerr << "DEBUG MODE" << endl;
    string test_cases = "test_A.txt";
    auto fs = fstream(test_cases, fstream::in);
    int lp = 0;
    while(fs) {
        lp++;
        cout << lp <<  "#------\n";
        sub_main(fs);
    }
    cout << "------#\n";
    if(lp <= 1) sub_main(cin);
#else
    sub_main(cin);
#endif
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int a, b, k;

int main(void)
{
	cin >> a >> b >> k;
	for(int i = min(a, b); i >= 1; i--){
		if(a % i == 0 && b % i == 0) k--;
		if(k == 0){
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
# ABC134E - Sequence Decomposing
def lis(A: "Array[int]") -> int:
    from bisect import bisect_right

    # dp := length of LIS (dp table itself is not LIS)
    dp = [A[0]]
    for i in A[1:]:
        if i >= dp[-1]:
            dp.append(i)
        else:
            dp[bisect_right(dp, i)] = i
    return len(dp)


def main():
    N, *A = map(int, open(0))
    ans = lis(A[::-1])  # need the length of LDS -> reverse A
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 9368
import scala.io.StdIn.{ readLine, readInt };
object Main {
    def main(args: Array[String]): Unit = {
        val n = readInt;
        val l = (0 until n).map{ a => 
            readLine.split(" ") match {
                case Array(v, l, r) => Some((v.toInt, l.toInt, r.toInt));
                case _ => None;
            }
        }.toList
        val bTree = new BinaryTrees(n);
        bTree.build(l);
        bTree.dump();
    }
}
class BinaryTrees(len: Int) {
    case class Node(value: Int, left: Int, right: Int);
    private lazy val root = getRoot;
    private val tree = new Array[Node](len);
    def build(data: List[Option[(Int, Int, Int)]]): Unit = data match {
        case Some((value, left, right)) :: xs =>
            tree(value) = Node(value, left, right);
            build(xs);
        case x :: xs => build(xs);
        case Nil => ()
    }
    def dump(): Unit = {
        val dumpArr = new Array[String](len);
        def _dump(curr: Int, parent: Int, sibling: Int, depth: Int): Unit = {
            if (curr == -1) {
                //  nop
            } else {
                val degree = getDegree(curr);
                val nodeType = getNodeType(curr, parent);
                val height = getHeight(curr);
                dumpArr(curr) = nodeToString(curr, parent, sibling, degree, depth, height, nodeType);
                _dump(tree(curr).left, curr, tree(curr).right, depth + 1);
                _dump(tree(curr).right, curr, tree(curr).left, depth + 1);
            }
        }
        _dump(root, -1, -1, 0);
        println(dumpArr.mkString("\n"));
    }
    def getRoot(): Int = {
        def _getRoot(currRoot: Int): Int = {
            tree.foreach{ node => if (node.left == currRoot || node.right == currRoot) return _getRoot(node.value) }
            return currRoot;
        }
        _getRoot(0);
    }
    def getHeight(curr: Int): Int = {
        if (curr == -1) {
            -1;
        } else {
            val leftHeight = getHeight(tree(curr).left);
            val rightHeight = getHeight(tree(curr).right);
            if (leftHeight < rightHeight) rightHeight + 1 else leftHeight + 1;
        }
    }
    def nodeToString(curr: Int, parent: Int, sibling: Int, degree: Int, depth: Int, height: Int, nodeType: String): String = {
        s"node ${curr}: parent = ${parent}, sibling = ${sibling}, degree = ${degree}, depth = ${depth}, height = ${height}, ${nodeType}";
    }
    def getDegree(v: Int): Int = {
        val n = tree(v);
        var ret = 2;
        if (n.left == -1) ret -= 1;
        if (n.right == -1) ret -= 1;
        ret;
    }
    def getNodeType(v: Int, parent: Int): String = {
        if (parent == -1) "root" else if (tree(v).left == -1 && tree(v).right == -1) "leaf" else "internal node";
    }
}


Measured memory_bytes: 43952
#include <iostream>
#include <cmath>
using namespace std;
int N;
const int maxn = 100001;
int x[maxn],y[maxn],t[maxn];

int main(){
    int min_time,time;
    bool flag = true;
    cin>>N;
    for(int i=1;i<=N;i++)
    {
        cin>>t[i]>>x[i]>>y[i];
    }
    for(int i=1;i<=N;i++)
    {
        time = abs(t[i]-t[i-1]);
        min_time = abs(x[i]+y[i]-x[i-1]-y[i-1]);
        if(time<min_time)
        {
            flag = false;
            break;
        }
        else if(time>min_time)
        {
            if(min_time%2!=time%2)
            {
                flag = false;
                break;
            }
        }
    }
    if(flag)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define __builtin_popcount __builtin_popcountll

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; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
    os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const map<S, T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int T, n, m;
string s;

int main(int argc, char *argv[]){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    while(cin >> n){
        vector<ll> dp(200001, 0);
        int p = -1;
        string s;
        ll ans = 1;
        REP(i, n) {
            int x;
            cin >> x;
            if (x == p) {
                continue;
            }
            p = x;
            ll pans = ans;
            ans = (ans + dp[x]) % MOD;
            dp[x] = (dp[x] + pans) % MOD;
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 1920
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000000000000

long long D;
vector<long long> pow10(18,1LL);
long long ans = 0LL;

void go(long long nowD,vector<long long> &num,int ind,long long cnt){

	if(ind==num.size()){
		if(nowD==0)ans += cnt;
		return;
	}
	if(num[ind]==0 && nowD==0){
		ans += cnt*10;
		return;
	}
	map<int,int> mp;
	rep(i,10){
		rep(j,10){
			if(ind==0&&(i==0||j==0))continue;
			mp[i-j]++;
		}
	}
	
	for(auto a:mp){
		if((nowD - num[ind] * a.first)%10 == 0){
			go((nowD - num[ind]*a.first)/10,num,ind+1,cnt * a.second);
		}
	}
	
}
			

void check(int digits){
	vector<long long> num;
	rep(i,digits){
		if(i > (digits-1-i))break;
		num.push_back(pow10[digits-1-i] - pow10[i]);
		num.back()/=9;
		while(num.back()!=0&&num.back()%10==0)num.back()/=10;
	}
	go(D,num,0,1LL);
}

int main(){

	cin>>D;
	
	if(D%9!=0){
		cout<<0<<endl;
		return 0;
	}
	
	D/=9;
	
	for(int i=1;i<18;i++){
		pow10[i] = pow10[i-1] * 10;
	}
	
	rep(i,18){
		check(i+1);
	}
	
	cout<<ans<<endl;

	return 0;
}


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

int main(){
  char A,B;
  cin >> A >> B;
  if(A == 'H'){
    if(B == 'H'){
      cout << 'H' << endl;
    }
    else{
      cout << 'D' << endl;
    }
  }
  else{
    if(B == 'H'){
      cout << 'D' << endl;
    }
    else{
      cout << 'H' << endl;
    }
  }
}

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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int N, K;
  cin >> N >> K;
  if (K == 1) cout << 0 << endl;
  else cout << N - K << endl;
  return 0;
}

Measured memory_bytes: 256
def binary(N, LIST, num):  # 二分探索 # N:探索要素数
    l, r = -1, N
    while r - l > 1:
        if LIST[(l + r) // 2] > num:  # 条件式を代入
            r = (l + r) // 2
        else:
            l = (l + r) // 2
    return r + 1


n, d, a = map(int, input().split())
xh = sorted(list(map(int, input().split())) for _ in range(n))
x = [i for i, j in xh]
h = [(j + a - 1) // a for i, j in xh]

bomb, bsum, ans = [0] * (n + 1), [0] * (n + 1), 0
for i in range(n):
    j = binary(n, x, x[i] + 2 * d) - 1
    bsum[i] += bsum[i - 1] + bomb[i]
    bnum = max(h[i] - bsum[i], 0)
    bomb[i] += bnum
    bomb[j] -= bnum
    bsum[i] += bnum
    ans += bnum
print(ans)


Measured memory_bytes: 70016