akhauriyash/Code-Regression huggingface dataset:
import java.io.InputStream;
import java.io.PrintStream;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

/**
 * 解説通りに実装したソースコード
 */
public class Main {

    public static void main(String[] args) throws Exception {
        solve(System.in, System.out);
    }

    static class Root {
        int root;
        int size;
        Root (int root) {
            this.root = root;
            this.size = 1;
        }
    }

    static Root find(int i) {
        if(roots[i].root == i) {
            return roots[i];
        }
        roots[i].root = roots[roots[i].root].root;
        return find(roots[i].root);
    }

    static void union(Root a, Root b) {
        if(a.root == b.root) return;
        if(a.size < b.size){
            a.root = b.root;
            b.size += a.size;
        } else {
            b.root = a.root;
            a.size += b.size;
        }
    }

    static Root[] roots;

    static void solve(InputStream is, PrintStream os) {
        Scanner scan = new Scanner(is);
        int N = scan.nextInt();
        int M = scan.nextInt();
        roots = new Root[N];
        for (int i = 0; i < N; i++) {
            roots[i] = new Root(i);
        }
        for (int i = 0; i < M; i++) {
            int A = scan.nextInt()-1;
            int B = scan.nextInt()-1;
            Root ra = find(A);
            Root rb = find(B);
            union(ra, rb);
        }

        int maxNumOfGroup = 0;
        for (int i = 0; i < N; i++) {
            Root root = find(i);
            maxNumOfGroup = Math.max(maxNumOfGroup, root.size);
        }
        os.println(maxNumOfGroup);
    }
}


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

public class Main
{
    PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer tok;

    public void go() throws IOException
    {
        ntok();
        String s = spar();
        ntok();
        int k = ipar();
        long rep = 0;
        char c = s.charAt(0);
        long l = 1;
        boolean diff = false;
        for (int i = 1; i < s.length(); i++)
        {
            if (c == s.charAt(i))
            {
                l++;
            }
            else
            {
                diff = true;
                rep += l / 2;
                l = 1;
            }
            c = s.charAt(i);
        }
        if (!diff)
        {
            rep = l*k / 2;
        }
        else
        {
            rep += l / 2;
            l = 1;
            c = s.charAt(0);
            for (int i = 1; i < s.length(); i++)
            {
                if (c != s.charAt(i))
                {
                    break;
                }
                l++;
            }
            int ll = 1;
            for (int i = s.length()-2; i >= 0; i--)
            {
                if (c != s.charAt(i))
                {
                    break;
                }
                ll++;
            }
            if (s.charAt(0) == s.charAt(s.length()-1))
            {
                rep -= l/2;
                rep -= ll/2;
            }
            rep *= k;
            if (s.charAt(0) == s.charAt(s.length()-1))
            {
                rep += l/2 + ll/2;
                rep += (l+ll)/2 * (k-1);
            }
        }
        out.println(rep);

        out.flush();
        in.close();
    }

    public void ntok() throws IOException
    {
        tok = new StringTokenizer(in.readLine());
    }

    public int ipar()
    {
        return Integer.parseInt(tok.nextToken());
    }

    public int[] iapar(int n)
    {
        int[] arr = new int[n];
        for (int i = 0; i < n; i++)
        {
            arr[i] = ipar();
        }
        return arr;
    }

    public long lpar()
    {
        return Long.parseLong(tok.nextToken());
    }

    public long[] lapar(int n)
    {
        long[] arr = new long[n];
        for (int i = 0; i < n; i++)
        {
            arr[i] = lpar();
        }
        return arr;
    }

    public double dpar()
    {
        return Double.parseDouble(tok.nextToken());
    }

    public String spar()
    {
        return tok.nextToken();
    }

    public static void main(String[] args) throws IOException
    {
        new Main().go();
    }
}


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

using namespace std;

#define int long long
#define x first
#define y second
#define tm (tl + tr) / 2
#define Point pair<int, int>
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int inf = 1e17;
const int mod = (1e9) + 7;

mt19937 random1(16783849);
int randlr(int l, int r) {
    return random1() % (r - l + 1) + l;
}

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

    int n, k;
    cin >> n >> k;

    if (k == 1) {
        cout << 0;
        return 0;
    }

    cout << n - k;

    return 0;
}


Measured memory_bytes: 768
/*
    JAI JAGANNATH!
*/
//@Author : zanj0
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int lli;
#define ff              first
#define ss              second
#define pb              push_back
#define mp              make_pair
#define pii             pair<lli,lli>
#define vi              vector<lli>
#define mii             map<lli,lli>
#define pqb             priority_queue<lli>
#define pqs             priority_queue<lli,vi,greater<lli> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            lli x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void zanj0()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
bool cmpA(pair <lli, lli>& a, pair <lli, lli>& b) {
	return a.second < b.second;
}
bool cmpB(pair <lli, lli>& a, pair <lli, lli>& b) {
	return a.first + a.ss > b.ff + b.ss;
}
void solve() {
	lli n;
	vector < pair <lli, lli> > v1, v2;
	cin >> n;
	string s;
	for (lli i = 0; i < n; i++) {
		cin >> s;
		lli bal = 0;
		lli minPeak = 0;
		for (auto& c : s) {
			bal += c == '(' ? 1 : -1;
			minPeak = max(minPeak, -bal);
		}
		if (bal >= 0) {
			v1.pb({bal, minPeak});
		} else {
			v2.pb({bal, minPeak});
		}
	}
	lli total = 0;
	bool ok = true;
	sort(v1.begin(), v1.end(), cmpA);
	sort(v2.begin(), v2.end(), cmpB);
	for (lli i = 0; i < v1.size(); i++) {
		if (total < v1[i].ss) ok = false;
		total += v1[i].ff;
	}
	for (lli i = 0; i < v2.size(); i++) {
		if (total < v2[i].ss) ok = false;
		total += v2[i].ff;
	}
	if (total == 0 && ok) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}

}
int main()
{
	zanj0();
	solve();
	return 0;
}

Measured memory_bytes: 19060
#define _USE_MATH_DEFINES

#include <cmath>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <bitset>

using namespace std;

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

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

const int Maxn = 100010;

int a[Maxn];
bool b[Maxn];

int n, m;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    b[0] = true;
    fill(a, a + n, 1);
    while(m--){
        int x, y;
        cin >> x >> y;
        --x, --y;
        if (b[x]){
            b[y] = true;
        }
        --a[x], ++a[y];
        if (b[x] && a[x] == 0){
            b[x] = false;
        }
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        ans += b[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 768
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include<set>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(int i = m;i < n;++i)
#define pb push_back
#define rrep(i,m,n) for(int i = m;i >= n;--i)
#define INF INT_MAX-1;
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;
const ll MOD = 1e9 + 7;
struct edge { ll from; ll to; ll cost; };

ll sum(ll mi, ll ma) {
	ll res = (ma + 1)*ma / 2 - mi * (mi - 1) / 2;
	return res;
}



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

	ll ans = 0;
	if (k == 0) {
		cout << n * n << endl;
		return 0;
	}
	for (int b = k + 1; b <= n; b++) {
		ll s = (n + 1) / b;
		ans += s * (b - k);

		ll l = k + s * b;
		if (n >= l)ans += n - l + 1;
	}
	cout << ans << endl;
	return 0;
}

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

int main(void)
{
    IOS
    int a,b,c;
    cin >> a >> b >> c;
    bool ans = b-a == c-b ? true : false;
    CFYN(ans);

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>

int compare(const void *a, const void *b)
{
  return *(int *)b - *(int *)a;
}

int main (int argc, char **argv)
{
  int n = 0;
  int *a = NULL;
  int *b = NULL;
  int i = 0;
  int j = 0;

  scanf("%d", &n);

  a = (int *)malloc(n * sizeof(int));
  b = (int *)malloc(n * sizeof(int));

  for(i = 0; i < n; i++)
  {
    scanf("%d", &a[i]);
  }
  memcpy(b, a, n * sizeof(int));

  qsort(b, n, sizeof(int), compare);

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

  free(a);
  free(b);

  return 0;
}



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

int h, w;
int pass[32];
char t[12][12];
string str = "URDL";

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

bool solve(int idx, int x, int y, int d, int rem){
  if(rem == 0){
    return true;
  }

  t[y][x] = '.';

  for(int i = -1; i <= 1; i++){
    int nd = (d + i + 4) % 4;
    int nx = x;
    int ny = y;

    while(true){
      nx += dx[nd];
      ny += dy[nd];
      if(0 > nx || nx >= w || 0 > ny || ny >= h) break;
      if(t[ny][nx] == 'o'){
        pass[idx] = nd;
        if(solve(idx + 1, nx, ny, nd, rem - 1)) return true;
        break;
      }
    }
  }

  t[y][x] = 'o';

  return false;
}

int main(){
  while(cin >> h >> w){
    int sum = 0;
    int sx, sy, sd;

    for(int i = 0; i < h; i++){
      cin >> t[i];

      for(int j = 0; j < w; j++){
        if(t[i][j] == 'o'){
          sum++;
        }
        else if(t[i][j] != '.'){
          sx = j;
          sy = i;

          if(t[i][j] == 'U') sd = 0;
          else if(t[i][j] == 'R') sd = 1;
          else if(t[i][j] == 'D') sd = 2;
          else if(t[i][j] == 'L') sd = 3;

          t[i][j] = '.';
        }
      }
    }

    solve(0, sx, sy, sd, sum);

    for(int i = 0; i < sum; i++){
      cout << str[pass[i]];
    }
    cout << endl;
  }
}

Measured memory_bytes: 0
#include <stdio.h>
#include <string.h>
#include <math.h>



int main(){
	int N,tmp;
	
	scanf("%d",&N);
	int i,cnt=0;
	for(i=0;i<N;i++){
		scanf("%d",&tmp);
		if(i%2==0){
			if(tmp%2==1)cnt++;
		}
	}
	
	
	printf("%d\n",cnt);

	return 0;
}


Measured memory_bytes: 1676
#include <stdio.h>
long long cnt;
int G[100];
int m;

void insertionSort(int A[], int n, int g) {
    int v, i, j;

    for (i=g; i<n; i++) {
        v = A[i];
        j = i-g;
        while (j>=0 && A[j]>v) {
            A[j+g] = A[j];
            j = j-g;
            cnt++;
        }
        A[j+g]=v;
    }
}

void print(int m, int G[], int A[], int n) {
    printf("%d", m);
    printf("\n");
    for (int i=0; i<m; i++) {
        if (i>0) printf(" ");
        printf("%d", G[i]);
    }
    printf("\n");
    printf("%d", cnt);
    printf("\n");
    for (int i=0; i<n; i++) {
        printf("%d", A[i]);
        printf("\n");
    }
}

void shellSort(int A[], int n) {
    int i;
    int g=0;
    m = -1;
    
    while (m<100 && g<=n) {
        g = 3*g+1;
        m++;
    }
    g = 0;
    for (i=m-1; i>=0; i--) {
        g = 3*g+1;
        G[i] = g;
    }

    for (i=0; i<m; i++) insertionSort(A, n, G[i]);
}

int main() {
    int A[1000000], n;
    cnt = 0;

    scanf("%d", &n);

    for (int i=0; i<n; i++) scanf("%d", &A[i]);

    shellSort(A, n);

    print(m, G, A, n);

    return 0;
}


Measured memory_bytes: 6472
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Main{
  public static void main(String[] args) throws IOException{
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    int n=Integer.parseInt(br.readLine());
    System.out.println(n*n*n);
  }
}


Measured memory_bytes: 21204
from collections import defaultdict
import sys
input=sys.stdin.readline


def solve():
    N, X, Y = map(int, input().split())
    d = defaultdict(list)
    for i in range(N-1):
        a, b = i+1, i+2
        d[a].append(b)
        d[b].append(a)
    d[X].append(Y)
    d[Y].append(X)

    ans = [0]*N

    for i in range(1, N+1):
        dist = [-1]*(N+1)
        dist[i] = 0
        q = [i]

        while q:
            s = q.pop()
            for t in d[s]:
                if dist[t]==-1:
                    dist[t] = dist[s]+1
                    q.append(t)
                elif dist[t] > dist[s]+1:
                    dist[t] = dist[s]+1
                    q.append(t)
        for j in range(i+1, N+1):
            ans[dist[j]] += 1

    for i in range(1, N):
        print(ans[i])


if __name__ == "__main__":
    solve()


Measured memory_bytes: 46940
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>


using namespace std;

int main()
{

	int n; cin >> n;

	vector<int> v {1, 2, 3,4 ,5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23, 32, 33, 34, 43, 44, 45, 54, 55, 56, 65, 66, 67, 76, 77, 78, 87, 88, 89, 98, 99};
	if ( n <= (int) v.size())
	{
			cout << v[n-1];
			return 0;
	}
 	vector<vector<string>> preV { {"00", "01" } , 
								 {"10", "11", "12"},
								 { "21", "22", "23"}, 
								 {"32", "33", "34" },
								 { "43", "44", "45"}, 
								 {"54", "55", "56" }, 
								 {"65", "66", "67" },
							     {"76", "77", "78" },
								 {"87", "88", "89" }, 
								{"98", "99"}
								};

	queue<string> q;
	int already = v.size();
	int dig = 3;
	while(1)
	{
		vector<vector<string>> newV(10);
		for(auto& val : preV[0])
		{
			newV[0].push_back("0" + val);
		}
		for(auto& val : preV[1])
		{
			newV[0].push_back("0" + val);
		}
		for(int dig = 1; dig <= 9; ++dig)
		{
			string s = to_string(dig);
			int pre = dig - 1;
			for(auto& val : preV[pre])
			{
				newV[dig].push_back( s + val);
				++already;
				if(already == n)
					{
						cout << s + val;
						return 0;
					}
			}	
			
			for(auto& val : preV[dig])
			{
				newV[dig].push_back( s + val);
				++already;
				if(already == n)
					{
						cout << s + val;
						return 0;
					}
			}	
			
            int next = dig + 1;
			if(next <= 9)
			{
				for(auto& val : preV[next])
				{
					newV[dig].push_back(  s + val);
					++already;
					if(already == n)
					{
						cout << s + val;
						return 0;
					}
				}
			}
	
		}
		preV = newV;
	}
    return 0;
}


Measured memory_bytes: 4864
using System;

namespace ManyHelloWorld
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			for (int i = 1; true; i++) {
				int data = int.Parse (Console.ReadLine ());
				if (data == 0)
					break;

				Console.WriteLine ("Case {0}: {1}", i, data);
			}
		}

	}
}

Measured memory_bytes: 5772
#include <stdio.h>
#include <algorithm>
int n;
int p[100000];
int l[100000], r[100000];
int id[100001];
long long x[100000];
int y[4];
int z, w;
long long ans, an;
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", p + i);
		l[i] = i - 1;
		r[i] = i + 1;
		x[i] = p[i];
		x[i] *= 100000;
		x[i] += i;
	}
	std::sort(x, x + n);
	for (int i = 0; i < n; i++) {
		id[x[i] / 100000] = x[i] % 100000;
	}
	for (int i = 1; i <= n; i++) {
		z = id[i];
		y[1] = l[z];
		if (y[1] != -1)y[0] = l[y[1]];
		y[2] = r[z];
		if (y[2] != n)y[3] = r[y[2]];
		w = r[z];
		if (r[z] != n)l[r[z]] = l[z];
		if (l[z] != -1)r[l[z]] = w;
		if (y[1] != -1) {
			an = y[1] - y[0];
			an *= (y[2] - id[i]);
			ans += an * i;
		}
		if (y[2] != n) {
			an = y[3] - y[2];
			an *= (id[i] - y[1]);
			ans += an * i;
		}
	}
	printf("%lld\n", ans);
}

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

using namespace std;
typedef long long ll;
static const int INF = 1000000000;

int solve(ll n, int i, const vector<ll> &v){
	if(n == 1){ return 0; }
	if(i < 0){ return -INF; }
	int answer = solve(n, i - 1, v);
	if(n % v[i] == 0){
		answer = max(answer, solve(n / v[i], i, v) + 1);
	}
	return answer;
}

int main(){
	ios_base::sync_with_stdio(false);
	vector<ll> table;
	for(int i = 1; i < 18; ++i){
		for(int j = 0; j < (1 << i) - 1; ++j){
			ll x = 0;
			for(int k = 0; k < i; ++k){
				if(j & (1 << k)){
					x = (x * 10) + 8;
				}else{
					x = (x * 10) + 2;
				}
			}
			table.push_back(x);
		}
	}
	ll n;
	cin >> n;
	if(n == 1){
		cout << -1 << endl;
		return 0;
	}
	vector<ll> v;
	for(const ll x : table){
		if(n % x == 0){ v.push_back(x); }
	}
	int answer = solve(n, v.size() - 1, v);
	if(answer < 0){ answer = -1; }
	cout << answer << endl;
	return 0;
}

Measured memory_bytes: 4872
#include<iostream>
#include<math.h>
#include <algorithm>
#include<float.h>
#include <limits>
#include <vector> 
#include <numeric>

#define rep(i,a,n) for(int (i) = (a);(i) < (n);(i)++)
#define MOD 1000000007
#define ll long long

using namespace::std;
int main(){

  int A;
  int B;
  char S;
  cin>>A>>S>>B;
  if(S=='+'){
    cout<<A+B;
  }else{
    cout<<A-B;
  }
  

      
}
// int *p = new int[N];

// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));

//


Measured memory_bytes: 256
#include <stdio.h>
int main(){
    int n,temp,bot,top=0,nb;
    scanf("%d",&n);
    scanf("%d",&bot);
    nb=bot;
    for(int i=1;i<n;i++){
        scanf("%d",&temp);
        if(temp-nb>top-bot){
            bot=nb;
            top=temp;
        }
        else if(temp>top)top=temp;
        if(temp<nb)nb=temp;
    }
    printf("%d\n",top-bot);
}

Measured memory_bytes: 2760
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(ll i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(ll i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
void debug(priority_queue<string> que){

}
int main(){
    string st;
    cin>>st;
    ll n;
    cin>>n;
    priority_queue<string> que;
    set<string> se;
    REP(i,(int)st.size()){
        string temp;
        REP(j,min((ll)st.size()-i,n)){
            temp+=st[i+j];
            cerr<<temp<<endl;
            if(que.size()<n){
                que.push(temp);
                se.insert(temp);
            }else{
                string p=que.top();
                if(p>temp&&!se.count(temp)){
                    string p=que.top();que.pop();
                    se.erase(p);
                    que.push(temp);
                    se.insert(temp);
                }
            }
        }
    }
    cout<<que.top()<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------
template<typename T, int N, T F(const T& a, const T& b)>
struct SegTree
{
public:
    SegTree()
    {
        dat = vector<T>(N * 2 - 1, 0);
    }

    void update(int i, T x)
    {
        i += N - 1;
        dat[i] = x;
        while (i > 0)
        {
            i = (i - 1) / 2;
            dat[i] = F(dat[i * 2 + 1], dat[i * 2 + 2]);
        }
    }

    T query(int a, int b, int k = 0, int l = 0, int r = N)
    {
        if (r <= a || b <= l) return 0;
        if (a <= l && r <= b) return dat[k];
        else
        {
            T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
            T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
            return F(vl, vr);
        }
    }

    vector<T> dat;
};

/*------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
------------------------------------------------------------------------------*/











//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    int N;
    cin >> N;
    vector<vector<pair<int, ll>>> nodes(N);
    int a, b;
    ll c;
    rep(i, 0, N - 1)
    {
        cin >> a >> b >> c;
        --a; --b;
        nodes[a].push_back(make_pair(b, c));
        nodes[b].push_back(make_pair(a, c));
    }

    int Q, K;
    cin >> Q >> K;
    --K;

    queue<pair<int, ll>> q;
    q.push(make_pair(K, 0));
    vector<ll> dists(N);
    dists.assign(N, -1);
    dists[K] = 0;
    while (!q.empty())
    {
        int curr;
        ll dist;
        tie(curr, dist) = q.front();
        q.pop();

        for (const auto node : nodes[curr])
        {
            int next;
            ll cost;
            tie(next, cost) = node;
            if (dists[next] == -1)
            {
                dists[next] = dist + cost;
                q.push(make_pair(next, dists[next]));
            }
        }
    }

    int x, y;
    rep(i, 0, Q)
    {
        cin >> x >> y;
        --x; --y;
        cout << (dists[x] + dists[y]) << endl;
    }
}


Measured memory_bytes: 12400
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
constexpr int inf=1e9+7;
constexpr ll longinf=1LL<<60 ;
constexpr ll mod=1e9+7 ;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    string s;
    cin>>s;
    vector<int> cnt(n+1);
    cnt[0]=0;
    rep(i,n){
        cnt[i+1]+=cnt[i];
        int t=i+1;
        while(t%2==0){
            t/=2;cnt[i+1]++;
        }
    }
    int sum = 0;
    rep(i,n){
        if(cnt[n-1]==cnt[i]+cnt[n-1-i])sum += s[i]-'0';
    }
    if(sum%2==1){
        cout<<1<<endl;
        return 0;
    }
    vector<int> a(n-1);
    rep(i,n-1){
        a[i]=abs((int)(s[i]-'0')-(int)(s[i+1]-'0'));
    }
    rep(i,n-1){
        if(a[i]==1){
            cout<<0<<endl;
            return 0;
        }
    }
    rep(i,n-1)a[i]/=2;
    sum = 0;
    rep(i,n-1){
        if(cnt[n-2]==cnt[i]+cnt[n-2-i])sum += a[i];
    }
    if(sum%2==1)cout<<2<<endl;
    else cout<<0<<endl;
    return 0;
}

Measured memory_bytes: 9244
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main(){
    ll x,y,a,b,c; cin>>x>>y>>a>>b>>c;
    vector<ll> p(a), q(b), r(c);
    rep(i,a) cin>>p[i];
    rep(i,b) cin>>q[i];
    rep(i,c) cin>>r[i];
    sort(p.begin(), p.end(), greater<ll>());
    sort(q.begin(), q.end(), greater<ll>());
    sort(r.begin(), r.end(), greater<ll>());
    ll res=0;
    /*
    vector<ll> pp(a+1), qq(b+1), rr(c+1);
    rep(i,a) pp[i+1]=pp[i]+p[i];
    rep(i,b) qq[i+1]=qq[i]+q[i];
    rep(i,c) rr[i+1]=rr[i]+r[i];
    res=pp[x-1]+qq[y-1];
    for(ll i=0; i<=c; i++){
        ll key=r[i];
        ll left=-1, right=y;
        while(right-left>1){
            ll mid=(right+left)/2;
            if(q[mid]<key) right=mid;
            else left=mid;
        }
        if(right==y) continue;
        if(i+y-right>c) continue;
        chmax(res, pp[x-1-i]+qq[right]+rr[i+(y-right)]);
    }
    cout<<res<<endl;
    */
    rep(i,x) res+=p[i];
    rep(i,y) res+=q[i];
    ll mina=p[x-1], minb=q[y-1];
    ll tmpx=x-1, tmpy=y-1, tmpr=0;
    rep(i,c){
        if(tmpx<0){
            while(q[tmpy]<r[tmpr]){
                res-=q[tmpy]-r[tmpr];
                tmpy--;
                tmpr++;
            }
            break;
        }else if(tmpy<0){
            while(p[tmpx]<r[tmpr]){
                res-=p[tmpx]-r[tmpr];
                tmpx--;
                tmpr++;
            }
            break;
        }
        if(min(p[tmpx], q[tmpy])<r[tmpr]){
            if(p[tmpx]<q[tmpy]){
                res-=p[tmpx]-r[tmpr];
                tmpx--;
                tmpr++;
            }else{
                res-=q[tmpy]-r[tmpr];
                tmpy--;
                tmpr++;
            }
        }else{
            break;
        }
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#include<math.h>
#include<algorithm> 
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
using PL = pair<ll , ll> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18
#define mod 1000000007

string dfs (ll x) {
    if(x == 0) {
        return "" ;
    }
    x-- ;
    return dfs(x/26) + string(1, 'a' + x%26) ;
}

int main(){
    ll n ;
    cin >> n;
    cout << dfs(n) << endl ; 
}



Measured memory_bytes: 3612
class UnionFind:
    def __init__(self, size):
        self.parent = list(range(size))
        self.rank = [0] * size

    def find(self, x):
        if self.parent[x] != x:
            self.parent[x] = self.find(self.parent[x])
        return self.parent[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

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


N, M = map(int, input().split())
p = [0] + list(map(int, input().split()))
uf = UnionFind(N+1)
for _ in range(M):
    x, y = map(int, input().split())
    uf.unite(p[x], p[y])
ans = 0
for i in range(1, N+1):
    if uf.same(i, p[i]):
        ans += 1
print(ans)


Measured memory_bytes: 95596
import java.util.*;

public class Main {

    public static void main(String args[]) {


        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int x = scan.nextInt();
        int t = scan.nextInt();

        int a = n / x;

        int b = n % x;
        if (b != 0) {
            System.out.println(t * (a + 1));
            
        } else {

            System.out.println(t * a);
            
        }
        
    }
}

Measured memory_bytes: 35612
#include <cstdio>
#include <algorithm>

using i8 = std::int8_t;
using u8 = std::uint8_t;
using i16 = std::int16_t;
using u16 = std::uint16_t;
using i32 = std::int32_t;
using u32 = std::uint32_t;
using i64 = std::int64_t;
using u64 = std::uint64_t;
using i128 = __int128_t;
using u128 = __uint128_t;
using isize = std::intptr_t;
using usize = std::uintptr_t;

auto main() -> i32 {
	i32 n, k;
	scanf("%d%d", &n, &k);
	i32 p[1000];
	for (i32 i = 0; i < n; ++i) {
		scanf("%d", p + i);
	}
	std::sort(p, p + n);
	i32 ans = 0;
	for (i32 i = 0; i < k; ++i) {
		ans += p[i];
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 1724
#include<stdio.h>
#include<algorithm>
using namespace std;
pair<int,int> c[200];
pair<int,int> d[1000];
int main(){
	int a,b;
	while(1){
		scanf("%d",&a);
		if(a==0)return 0;
		for(int i=0;i<a;i++){
			int q,w;
			scanf("%d%d",&q,&w);
			c[i]=make_pair(q,w);
		}
		scanf("%d",&b);
		for(int i=0;i<b;i++){
			int q,w;
			scanf("%d%d",&q,&w);
			d[i]=make_pair(q,w);
		}
		std::sort(d,d+b);
		int ansx;
		int ansy;
		for(int i=0;i<b;i++){
			int x=d[i].first-c[0].first;
			int y=d[i].second-c[0].second;
			bool ok=true;
			for(int j=1;j<a;j++){
				if(!binary_search(d,d+b,make_pair(c[j].first+x,c[j].second+y)))
				ok=false;
			}
			if(ok){
				ansx=x;
				ansy=y;
				printf("%d %d\n",x,y);
			}
		}
		
	}
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define INF 0X3f3f3f3f
#define M 1000000007
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))
#define mp make_pair
#define pb push_back 
#define fi first
#define se second
#define endl "\n"
#define PI acos(-1)
#define fastcin ios_base::sync_with_stdio(false);
typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef pair<int,int> ii;
typedef complex<double> base;

int n, a, b;

int main(void){
	scanf("%d%d%d", &n, &a, &b);

	if((b-a-1)%2 == 1){
		printf("Alice\n");
	}
	else{
		printf("Borys\n");
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;

/* --------------------------------------------------- */

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    ll ans = b + c;
    if(a + b < (c - 1)) ans -= (c - a - b - 1);
    cout << ans << endl;
     
    return 0;
}

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

using namespace std;
typedef long long ll;

#define floop(i, N) for (ll i = 0; i < N; i++)
#define floop1(i, N) for (ll i = 1; i <= N; i++)
#define floopi(i, j, N) for (ll j = i + 1; j < N; j++)
#define out(ans) cout << ans << endl
#define in(n) cin >> n

constexpr ll inf = 1e18;

void solve();

int main()
{
    solve();
}

void solve()
{
    ll n, m;
    in(n);
    in(m);
    priority_queue<ll> pque;
    floop(i, n)
    {
        ll a;
        in(a);
        pque.push(a);
    }
    ll ans = 0;
    while (m != 0)
    {
        ll x = pque.top() / 2;
        pque.pop();
        pque.push(x);
        m--;
    }
    while (!pque.empty())
    {
        ans += pque.top();
        pque.pop();
    }
    out(ans);
}

Measured memory_bytes: 1400
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cmath>
using namespace std;
#define ll long long
int val[45];
void init()
{
    int cur=0,now=0,last=0;
    while(cur<45)
    {
        val[cur]=now;
        last++; now++;
        cur+=last;
    }
    int pre=0;
    for(int i=1;i<45;i++)
    {
        if(val[i]) pre=val[i];
        else val[i]=pre;
    }
}
int solve(ll a)
{
    int res=0;
    for(ll i=2;i*i<=a;i++)
    {
        int num=0;
        for(;a%i==0;a/=i) num++;
        res+=val[num];
    }
    if(a>1) res++;
    return res;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    init();
    ll a; cin>>a;
    int ans=solve(a);
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define sqr(x) ((x)*(x))

using namespace std;
const double eps = 1e-9;
const int INF = (int)1e9 + 7;
const long long linf = (long long)1e18 + 7;
typedef long long ll;
const ll MOD = (ll)1e9 + 7;
const int MAXN =(int)1e6;

int main() {
    ll N;
    cin >> N;
    ll w, h, n;
    int ans = 0;
    for (int i = 1; i <= 3500; ++i)
        for (int j = 1; j <= 3500 && !ans; ++j) {
            ll up = (1ll * N * i * j);
            ll down = 1ll * 4 * i * j - 1ll * i * N - 1ll * j * N;
            if (down != 0)
            if (up % down == 0 && up / down > 0) {
                h = i, n = j, w = up / down;
                ans = 1;
            }
        }
    cout << w << " " << h << " " << n;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int N,A,B,C;

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

	cin >> A >> B >> C;

	cout << min(C,B / A) << endl;

}

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

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    bool flag = true;
    if(a >= b) flag = false;
    if(b >= c) flag = false;
    if(flag){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3100
N ,K = map(int,input().split())
L = list(map(int,input().split()))
def ceil(x):
    if x == int(x):
        return x
    else:
        return int(x) + 1


cnt = 0

N = N - K 
cnt += 1
if N > 0:
    cnt += ceil(N / (K-1))
print(int(cnt))


Measured memory_bytes: 13880
d=Array.new(4*3*10,0)
gets
while gets
  b,f,r,v=$_.split.map &:to_i
  d[(b-1)*30+(f-1)*10+r-1]+=v
end
4.times{|b|
  3.times{|f|puts " "+d[b*30+f*10,10]*" "}
  puts ?#*20 if b<3
}


Measured memory_bytes: 6892
#include <iostream>
#include <stdio.h>
#include <map>
#include <algorithm>
using namespace std;

int main()
{
    long n, max = 1;
    char str[20];
    scanf("%ld", &n);
    std::map<std::string, int> mp;
    for (long i = 0; i < n; i++)
    {
        scanf("%s", str);
        if (mp[str] == 0)
        {
            mp[str] = 1;
        }
        else
        {
            mp[str]++;
        }
    }

    for (std::map<std::string, int>::iterator i = mp.begin(); i != mp.end(); ++i)
    {
        if (i->second > max)
        {
            max = i->second;
        }
    }

    for (std::map<std::string, int>::iterator i = mp.begin(); i != mp.end(); ++i)
    {
        if (i->second == max)
        {
            cout << i->first << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 23808
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) std::begin(a), std::end(a)
#define RALL(a) std::rbegin(a), std::rend(a)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

constexpr int INF = 2e9;
constexpr double EPS = 1e-10;
constexpr double PI = acos(-1.0);

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

template <typename T>
constexpr int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
constexpr int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T, typename U>
constexpr void chmax(T& m, U x) {
	m = max(m, x);
}

template <typename T, typename U>
constexpr void chmin(T& m, U x) {
	m = min(m, x);
}

template <typename T>
constexpr T square(T x) {
	return x * x;
}

int n, m, q;

int solve(VI& a, VI& b, VI& c, VI& d, VI A, int i, int x) {
	int result = 0;
	if(i == n) {
		REP(i, q) {
			if(A[b[i] - 1] - A[a[i] - 1] == c[i]) {
				result += d[i];
			}
		}
		return result;
	}
	if(i != -1) {
		A.push_back(x);
	}
	RANGE(j, x, m) { chmax(result, solve(a, b, c, d, A, i + 1, j)); }
	return result;
}

int main() {
	cin >> n >> m >> q;
	VI a(q);
	VI b(q);
	VI c(q);
	VI d(q);
	REP(i, q) { cin >> a[i] >> b[i] >> c[i] >> d[i]; }
	cout << solve(a, b, c, d, VI(), -1, 0) << endl;
	return 0;
}


Measured memory_bytes: 3640
// https://atcoder.jp/contests/abcXXX/tasks/abcXXX_x

#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

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

static const ll INF = 1001001001;

#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define RANGE(i, m, n) for(ll i = (m); i <= (n); ++i)

void debug_out() {}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 1
#endif

void f1(ll & X, ll& ans) {
    switch (X) {
        case 1:
            ans += 300000;
            break;
        case 2:
            ans += 200000;
            break;
        case 3:
            ans += 100000;
            break;
    }
}
int run(istream& in, ostream& out) {
    ll X, Y;
    in >> X >> Y;
    ll ans = 0;
    f1(X,ans);
    f1(Y,ans);
    if (X == 1 && Y == 1) {
        ans += 400000;
    }
    out << ans << endl;
    debug(ans);
    return 0;
}

int run2(istream& in, ostream& out) {
    ll N, M, R;
    in >> N >> M >> R;
    vector<ll> r{};
    REP(i, R) {
        ll x;
        in >> x;
        r.emplace_back(x);
    }
    vector<tuple<ll,ll,ll>> v{};
    REP(i, M) {
        ll a,b,c;
        in >> a >> b >> c;
        v.emplace_back(make_tuple(a,b,c));
    }

    ll ans = 0;

    // solution here

    out << ans << endl;
    debug(ans);
    return 0;
}

int main() {
    return run(cin, cout);
}


Measured memory_bytes: 256
#include <stdio.h>
#define max(x,y) ((x>y)?x:y)

typedef struct {
	int parent;
	int left;
	int right;
} node_t;

node_t node[100];
int n;

int getRoot();
void printPreorder(int);
void printInorder(int);
void printPostorder(int);
int getSibling(int);


int main() {
	int i;
	int ID, left, right;
	scanf("%d", &n);
	for (i = 0; i < n; i++) node[i].left = node[i].right = node[i].parent = -1;
	for (i = 0; i < n; i++) {
		scanf("%d %d %d", &ID, &left, &right);
		node[ID].left = left;
		node[ID].right = right;

		if (left != -1) node[left].parent = ID;
		if (right != -1) node[right].parent = ID;
	}
	int root = getRoot();
	printf("Preorder\n");
	printPreorder(root);
	printf("\n");
	printf("Inorder\n");
	printInorder(root);
	printf("\n");
	printf("Postorder\n");
	printPostorder(root);
	printf("\n");
	return 0;
}

int getRoot(){
    int i;
    for (i = 0; i < n; i++) if (node[i].parent == -1) break;
    return i;
}

void printPreorder(int x){
    if (x != -1) {
		printf(" %d", x);
		printPreorder(node[x].left);
		printPreorder(node[x].right);
	}
}

void printInorder(int x){
    if (x != -1) {
		printInorder(node[x].left);
		printf(" %d", x);
		printInorder(node[x].right);
	}
}

void printPostorder(int x){
    if (x != -1) {
		printPostorder(node[x].left);
		printPostorder(node[x].right);
		printf(" %d", x);
	}
}


int getSibling(int ID) {
	if (node[ID].parent != -1 && node[node[ID].parent].right != ID) return node[node[ID].parent].right;
	if (node[ID].parent != -1 && node[node[ID].parent].left != ID) return node[node[ID].parent].left;
	return -1;
}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
#define int long long
using namespace std;
vector<vector<int>> g;
vector<bool> used;
vector<int> dp;
vector<int> ans;
int mod;

void dfs1(int v) {
    used[v] = true;
    dp[v] = 1;
    for (auto to : g[v]) {
        if (!used[to]) {
            dfs1(to);
            dp[v] *= dp[to] + 1;
            dp[v] %= mod;
        }
    }
}

void dfs2(int v, int cur) {
    used[v] = true;
    ans[v] = cur * dp[v] % mod;
    vector<int> sons;
    for (auto to : g[v]) {
        if (!used[to]) {
            sons.push_back(to);
        }
    }
    vector<int> pref(sons.size() + 1, 1), suf(sons.size() + 1, 1);
    for (int i = 0; i < sons.size(); i++) {
        pref[i + 1] = pref[i] * (dp[sons[i]] + 1) % mod;
    }
    for (int i = (int)(sons.size()) - 1; i >= 0; i--) {
        suf[i] = suf[i + 1] * (dp[sons[i]] + 1) % mod;
    }
    for (int i = 0; i < sons.size(); i++) {
        dfs2(sons[i], (1 + cur * pref[i] % mod * suf[i + 1] % mod) % mod);
    }
}

int32_t main () {
    int n;
    cin >> n >> mod;
    g.resize(n);
    for (int i = 0; i < n-1; ++i) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    used.resize(n);
    dp.resize(n);
    dfs1(0);
    used.assign(n, false);
    ans.resize(n);
    dfs2(0, 1);
    for (int v = 0; v < n; v++) {
        cout << ans[v] << endl;
    }
}


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

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

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

int main() {
    int n;
    cin >> n;
    vector<vector<int>> g(n+2, vector<int> (n+2, 0));
    auto h = g;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            g[i+1][j+1] = 1;
        }
    }
    array<int, 4> di = {1, 0, -1, 0}, dj = {0, 1, 0, -1};
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            for (int k = 0; k < 4; ++k) {
                h[i][j] += g[i+di[k]][j+dj[k]];
            }
        }
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            g[i+1][j+1] = 0;
        }
    }
    vector<int> v(n*n);
    int M = 2*(n*n-n);
    vector<int> a(M), b(M);
    vector<vector<int>> G(n*n);
    for (int i = 0; i < M; ++i) {
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
        v[a[i]]++; v[b[i]]++;
        G[a[i]].emplace_back(b[i]);
        G[b[i]].emplace_back(a[i]);
    }
    int cur = 0;
    for (int i = 0; i < n*n; ++i) {
        if(v[i] == 2) cur = i;
    }
    g[1][1] = cur+1;
    v[cur] = -1;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            if(g[i+1][j+1]) for (int to : G[g[i+1][j+1]-1]) {
                for (int k = 0; k < 2; ++k) {
                    int y = i+di[k]+1, x = j+dj[k]+1;
                    if(!g[y][x] && v[to] == h[y][x]){
                        g[y][x] = to+1;
                        v[to] = -1;
                    }
                }
            }

        }
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            if(j) cout << " ";
            cout << g[i+1][j+1];
        }
        puts("");
    }
    return 0;
}


Measured memory_bytes: 3676
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

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;
}

vector<int> ans;

void solve(const string S, const int slen) {
    for (int i = 0; i < slen - 1; i++) {
        if (S[i] == 'R' && S[i + 1] == 'L') {
            ans[i]++;
            ans[i + 1]++;
        }
    }

    int cnt = 0;
    for (int i = 0; i < slen; i++) {
        const char cur = S[i];
        if (cur == 'R') {
            cnt++;
        } else {
            cnt--;
            if (cnt > 0) {
                ans[i - 1] += (cnt / 2);
                ans[i] += cnt - (cnt / 2);
            }
            cnt = 0;
        }
    }

    cnt = 0;
    for (int i = slen - 1; i >= 0; i--) {
        const char cur = S[i];
        if (cur == 'L') {
            cnt++;
        } else {
            cnt--;
            if (cnt > 0) {
                ans[i + 1] += (cnt / 2);
                ans[i] += cnt - (cnt / 2);
            }
            cnt = 0;
        }
    }
}

int main(void) {
    string S;
    cin >> S;
    int slen = (int) S.size();

    ans.resize(slen, 0);
    solve(S, slen);

    cout << ans[0];
    for (int i = 1; i < slen; i++) {
        cout << " " << ans[i];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 1152
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<map>

using namespace std;

char w[105];
int flag = 1,as,len;
int sum[106];
int ans[1000];

bool solve(char*w){
	for(int i = 0;i <= len - 1;i ++){
		as = w[i];
		ans[as]++;
	}
	for(int i = 97;i <= 122;i++){
		if(ans[i] % 2 == 0) flag = 1;
		else {
			flag = 0;
			break;
		}
	}
	return flag;
}
int main(){
	scanf(" %s",w);
	len = strlen(w);
	if(solve(w)) printf("Yes\n");
	else printf("No\n");
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var A, B, C, ret int
	fmt.Scan(&A, &B, &C)

	if A == B {
		ret = C
	} else if C-(A-B) < 0 {
		ret = 0
	} else {
		ret = C - (A - B)
	}
	fmt.Println(ret)
}


Measured memory_bytes: 512