akhauriyash/Code-Regression huggingface dataset:
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(ll __x = __start; __x < __end; __x++)

int main() {
  ll n; cin >> n;
  int min_ = 10000000;
  for (ll x = 1; x*x<=n; x++) {
    if (n%x!=0) continue;
    int a = to_string(x).size();
    int b = to_string(n/x).size();
    int c = max(a, b);
    if (min_ > c) {
      min_ = c;
    }
  }
  cout << min_ << endl;
  return 0;
}


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

int main(void) 
{
   int k;
   string s;
   cin >> k >> s;

   if(s.size() <= k) cout << s << endl;
   else{
       cout << s.substr(0,k)+ "..." << endl;;
   }
}

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

using namespace std;

using i64 = int64_t;

const i64 MOD = 1e9+7;

const i64 INF = 1e18+7;


signed main(){
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> a(m);
    for(auto& x : a)
        cin >> x;
    k = distance(a.begin(), lower_bound(a.begin(), a.end(), k));
    cout << min(k, m - k) << endl;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.lang.*;
import static java.lang.System.*;
public class Main
{
public static void  main (String args[])throws Exception
{
Scanner sc=new Scanner(in);
long n=sc.nextLong();
int ans=10000;
for(int i=1;i<=(int)(Math.sqrt(n))+2;i++)
{
	if(n%i==0)
	{
		String a=String.valueOf(i);
		String b=String.valueOf(n/i);
		int c=Math.max(a.length(),b.length());
		if(c<=ans)
		ans=c;

	}
}
out.println(ans);
}
}

Measured memory_bytes: 23764
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
#include <bitset>
#include <stack>
//#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)

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

int main(void)
{
    //i*2^x >= K
    //2^x>=K/i
    //x >= log2(K/i)
    int N, K;
    cin >> N >> K;
    double ans = 0.0;
    double ini = (double)(1.0 / (double)N);
    int powarray[21];
    for (int i = 0; i <= 20; i++)
    {
        powarray[i] = (int)(pow(2, i + 1));
    }
    bool f = false;
    for (int i = 1; i <= N; i++)
    {
        if (i < K)
        {
            for (int j = 0; j <= 20; j++)
            {
                if (i * powarray[j] >= K)
                {
                    ans += ini * pow(0.5, j + 1);
                    break;
                }
            }
        }
        else
        {
            ans += ini;
        }
    }
    printf("%.13f", ans);
    return 0;
}


Measured memory_bytes: 4136
"""
author : halo2halo
date : 4, Feb, 2020
"""

import sys
import itertools

import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

S = readline().decode('utf8').rstrip()

lis = []

for m in S:
    if m != 'B':
        lis.append(m)
    else:
        if len(lis):
            lis.pop()

print(*lis, sep='')


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

int main(){
    int n;
    cin >> n;
    for(int i=1;i<=n;i++){
        int ans = i*1.08;
        if(ans==n){
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
}

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

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

const double PI = 3.14159265358979323846;
const int mod = 1e9+7;
// int 1e9+7 double 1e-12 long long 1e18

#define rep(i, a, b) for(int (i) = (a); (i) < (b);++i)

int main(){
  ll N;
  cin >> N;
  ll a[N];
  rep(i,0,N)cin >> a[i];
  sort(a, a+N);
  cout << a[N-1] - a[0] << endl;


  return 0;
}


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

using namespace std;

int main()
{
	string S;

	cin >> S;

	sort(S.begin(), S.end());

	if (S == "abc")
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;


/*
AC
最大要素が先頭に来るかどうかで場合分け
*/

ll n,x,s[210],dp[210][100010]={},mod=1e9+7;

ll f(ll i,ll x){
	if(i==n)return x;
	if(dp[i][x]!=-1)return dp[i][x];
	ll ans=0;
	ans+=f(i+1,x%s[i]);
	ans+=f(i+1,x) * (n-1-i); 
	return dp[i][x]=ans%mod;
}

int main(void){
	cin>>n>>x;
	rep(i,n)cin>>s[i];
	sort(s,s+n);
	reverse(s,s+n);
	rep(i,210)rep(j,100010)dp[i][j]=-1;
	cout<<f(0,x)<<endl;
	return 0;
}

Measured memory_bytes: 164352
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let mut arr: Vec<i64> = vec![0];
    let mut acc = 0;
    for i in 0..n {
        let x: i64 = read();
        acc += (arr[i] - x).abs();
        arr.push(x);
    }
    acc += arr[n].abs();
    arr.push(0);
    for i in 1..=n {
        println!(
            "{}",
            acc + (arr[i - 1] - arr[i + 1]).abs()
                - (arr[i - 1] - arr[i]).abs()
                - (arr[i] - arr[i + 1]).abs()
        );
    }
}

Measured memory_bytes: 2956
#include <bits/stdc++.h>
using namespace std;
int A[3]={};
int main(){
  cin >> A[0] >> A[1] >> A[2];
  sort(A,A+3);
  if(A[0]==5 && A[1]==5 && A[2]==7) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


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

int main() { 
    int n;
    cin >> n;
    double a[n];
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a, a+n);
    for(int i = 0; i < n-1; ++i) {
        a[i+1] = (a[i] + a[i+1])/2.0;
    }
    cout << a[n-1] << '\n';
}


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

using namespace std;

using int64 = long long;

struct INFTY {
  const int64 infll = (1LL << 62) - 1;
  const int inf = (1 << 30) - 1;

  operator int64() { return infll; }

  operator int() { return inf; }
} inf;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

int main() {
  string X;
  cin >> X;
  stack< int > st;
  for(auto &c : X) {
    if(st.size() && c == 'T' && st.top() == 'S') {
      st.pop();
    } else {
      st.push(c);
    }
  }
  cout << st.size() << endl;
}




Measured memory_bytes: 1300
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef int in;
typedef vector<in> VI;
typedef vector<VI> VVI;
in n,m;
void psh(VVI& v){
  for(in i=1;i<=n+1;++i){
    for(in j=1;j<=m+1;++j){
      v[i][j]+=v[i-1][j]+v[i][j-1]-v[i-1][j-1];
    }
  }
}
in hv(VVI& v, in x1, in y1, in x2, in y2){
  return v[x2][y2]-v[x1-1][y2]-v[x2][y1-1]+v[x1-1][y1-1];
}
VVI mbd,cel,hor,ver;
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  in q;
  cin>>n>>m>>q;
  mbd.resize(n+2,VI(m+2));
  cel=hor=ver=mbd;
  string s;
  for(in i=1;i<=n;++i){
    cin>>s;
    for(in j=1;j<=m;++j)
      mbd[i][j]=s[j-1]-'0';
  }
  for(in i=1;i<=n;++i){
    for(in j=1;j<=m;++j){
      cel[i][j]=mbd[i][j];
      hor[i][j]=(mbd[i][j]&mbd[i][j-1]);
      ver[i][j]=(mbd[i][j]&mbd[i-1][j]);
    }
  }
  psh(cel);
  psh(hor);
  psh(ver);
  in x1,y1,x2,y2;
  forn(z,q){
    cin>>x1>>y1>>x2>>y2;
    cout<<hv(cel,x1,y1,x2,y2)-hv(hor,x1,y1+1,x2,y2)-hv(ver,x1+1,y1,x2,y2)<<"\n";
  }
  return 0;
}


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

int n;
int M[100][100];

int prim(){
  int d[100]; //最小コスト
  int color[100];
  int p[100];
  for(int i=0;i<n;i++){
    d[i] = (1 << 21);
    color[i] = 0;
    p[i] = -1;
  }
  d[0] = 0;
  p[0] = 0;

  int mincost;
  int u;
  int cost = 0;

  while(true){
    mincost = (1 << 21);
    for(int i=0;i<n;i++){
      if(color[i] != 2 && d[i] < mincost){
        mincost = d[i];
        u = i;
      }
    }

    if(mincost == (1 << 21)) break;

    color[u] = 2;
    cost += mincost;

    // uと隣接する頂点についてdの更新
    for(int i=0;i<n;i++){
      if(M[u][i] != -1 && color[i] != 2 && M[u][i] < d[i]){
        d[i] = M[u][i];
        p[i] = u;
        color[i] = 1;
      }
    }
  }
  return cost;
}

int main(){
  cin >> n;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      cin >> M[i][j];
    }
  }
  cout << prim() << endl;
  return 0;
}



Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
const int N=1e5+2;
ll d[102][N];
int main()
{
    ft
    ll t,i,j,n,m,l,r;
    cin>>n>>m;
    ll w[n+1],v[n+1];
    for(i=1;i<=n;i++)
    {
        cin>>w[i]>>v[i];
    }
    for(i=0;i<=n;i++)
    {
        for(j=0;j<=m;j++)
        {
            if(i==0 || j==0)
            {
                d[i][j]=0;
            }
            else if(w[i]>j)
            {
                d[i][j]=d[i-1][j];
            }
            else
            {
                d[i][j]=max(d[i-1][j],d[i-1][j-w[i]]+v[i]);
            }
        }
    }
    cout<<d[n][m]<<"\n";
    return 0;
}

Measured memory_bytes: 82516
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#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)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

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


void c_p_c()
{
	ios_base::sync_with_stdio(0); 
	cin.tie(0);
	cout.tie(0);
/*
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
*/
}

int32_t main()
{
	c_p_c();
	int n,w;
	cin>>n>>w;
	int arr[n][2];
	for(int i=0;i<n;i++)
	{
		cin>>arr[i][0]>>arr[i][1];
	}
	int dp[n+1][w+1];
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=w;j++)
		{
			if(i==0 || j==0)
			dp[i][j]=0;
			else
			{
			if(arr[i-1][0]>j)
				dp[i][j]=dp[i-1][j];
			else
			{
				dp[i][j]=max((arr[i-1][1]+dp[i-1][j-arr[i-1][0]]),dp[i-1][j]);
			}
		}
		}
	}
	cout<<dp[n][w]<<endl;
	/*
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=w;j++)
		{
			cout<<dp[i][j]<<" ";
		}
		cout<<endl;
	}
	 */
	
	return 0;
}


Measured memory_bytes: 79232
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Stack;
import java.util.StringTokenizer;

public class Main {

	public static long sum(int a[],int l,int r) {
		long ans=0;
		for(int i=l;i<=r;i++) ans+=a[i];
		return ans;
		
	}
	
	public static void main(String[] args) {
		FastScanner sc=new FastScanner();
	int n=sc.nextInt();
	int a[]=sc.readArray(n);
	
	// dp[i][j] minimum cost to mergge the array from i to j
	long dp[][]=new long[n][n];
	
	for(int i=n-1;i>=0;i--) {
		
		for(int j=i;j<n;j++) {
			if(i==j) dp[i][j]=0;
			else {
				dp[i][j]=Long.MAX_VALUE;
				long s=sum(a,i,j);
			
				for(int k=i;k<=j-1;k++)
				{
					
					dp[i][j]=Math.min(dp[i][j], dp[i][k]+dp[k+1][j]+s);
				}
				
				
			}
		
		}
	
	}
	System.out.println(dp[0][n-1]);
	
	
	}
	static class FastScanner{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {
			return Integer.parseInt(next());
		}
		long nextLong() {
			return Long.parseLong(next());
		}
		int [] readArray(int n) {
			int a[]=new int[n];
			for(int i=0;i<n;i++) a[i]=nextInt();
			return a;
		}
		
		
	}

}


Measured memory_bytes: 35084
use std::cmp::max;
use std::io::*;

fn main() {
    let stdin = stdin();

    let mut buf = String::new();
    stdin.read_line(&mut buf).ok();
    let (n, _m) = to_pair(&buf);

    let conflicts: Vec<(i32, i32)> =
        stdin.lock().lines().map(|l| to_pair(&l.unwrap())).collect();
    
    let mut nearest_as = vec![-1; n as usize];

    for t in &conflicts {
        let a = t.0 - 1;
        let b = (t.1 - 1) as usize;
        let current = nearest_as[b];
        nearest_as[b] = max(current, a);
    }
    
    let mut eastmost_broken = -1;
    let mut cnt = 0;

    for i in 0..nearest_as.len() {
        let a = nearest_as[i];
        if a != -1 && a > eastmost_broken {
            eastmost_broken = (i - 1) as i32;
            cnt += 1;
        }
    }

    println!("{}", cnt);
}

fn to_pair(s: &str) -> (i32, i32) {
    let v: Vec<_> = s.split_whitespace().map(|w| w.parse().unwrap()).collect();
    let (l, r) = (v[0], v[1]);
    (l, r)
}


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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  for (auto &v : vec)
    cin >> v;

  sort(vec.begin(), vec.end());

  int sum = 0;
  for (int i = 0; i < n - 2; ++i) {
    for (int j = i + 1; j < n - 1; ++j) {
      int a = vec[i];
      int b = vec[j];
      auto itr = lower_bound(vec.begin() + j + 1, vec.end(), a + b);
      sum += itr - 1 - (vec.begin() + j);
    }
  }

  cout << sum << endl;
}

Measured memory_bytes: 256
h, w = gets.split.map!(&:to_i)
m = w < h ? w : h
m = 0  if (w%3)*(h%3) == 0
f =-> x,y {
  (1..(x/2)).each.map { |i|
    s, b = [i*y, (y+1)/2*(x-i), y/2*(x-i)].minmax
    m = b  if m > (b-=s)
  }
}
f[w,h];f[h,w]
p m

Measured memory_bytes: 2684
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define mod 1e9 +7;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
const double phi = (1 + sqrt(5)) / 2;
const double phi_ = (1 - sqrt(5)) / 2;
ll fib(ll n){
    double res = pow(phi, n+1) - pow(phi_, n+1);
    return res / sqrt(5);
}
ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}
ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    y /= gcd(x,y);
    return (x*y);
}
string to_bin_string(ll n){
    stringstream ss;
    ss << bitset<8>(n); //任意の桁数<m>
    string s = ss.str();
    return s;
}
int main()
{
    ll n; cin >> n;
    vll cnt(100000, 0);
    rep(i,n){
        ll a; cin >> a;
        cnt[a]++;
    }
    
    int mj = 1;
    REP(i,1,99999){
        ll tmp = cnt[i-1] + cnt[i] + cnt[i+1];
        ll ma = cnt[mj-1] + cnt[mj] + cnt[mj+1];
        if(ma < tmp)mj = i;
    }
    cout << cnt[mj-1] + cnt[mj] + cnt[mj+1] << endl;
    return 0;
} 

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define repr(i,k,n) for(int i = (k); i < (n); i++)
#define rep(i,n) repr(i,0,n)
#define ALL(a) begin(a),end(a)
const int INF = 114514810;
const int MOD = 1000000007;
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b;
	cin >> a >> b;
	cout << (a<=b?a:a-1) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int R,G;
  cin >> R >> G;
  cout << 2*G-R << endl;
  return 0;
}

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

struct node{
    struct node *right;
    struct node *left;
    struct node *parent;
    int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

/*Node treeMinimum(Node x){
    
}

Node treeMaximum(Node x){
    
}

Node treeSearch(Node u,int k){
    
}

Node treeSuccessor(Node x){
    
}
*/
void insert(int k){
    Node y=NIL;
    Node x=root;
    Node z;
    
    z=malloc(sizeof(struct node));
    z->key=k;
    z->left=NIL;
    z->right=NIL;
    
    while(x!=NIL){
        y=x;
        if(z->key<x->key)x=x->left;
        else x=x->right;
    }
    z->parent=y;
    
    if(y==NIL)root=z;
    else if(z->key<y->key)y->left=z;
    else y->right=z;
}

void inorder(Node u){
    if(u==NIL)return;
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}
void preorder(Node u){
    if(u==NIL)return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}


int main(){
    int n, i, x;
    char com[20];
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
        scanf("%s", com);
       /* if ( com[0] == 'f' ){
            scanf("%d", &x);
            Node t = treeSearch(root, x);
            if ( t != NIL ) printf("yes\n");
            else printf("no\n");
        } else*/ if ( com[0] == 'i' ){
            scanf("%d", &x);
            insert(x);
        } else if ( com[0] == 'p' ){
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        } /*else if ( com[0] == 'd' ){
            scanf("%d", &x);
            treeDelete(treeSearch(root, x));
        }*/
    }
    
    return 0;
}



Measured memory_bytes: 25140
#include<bits/stdc++.h>
#define MX 1000005
#define INF 1000000005
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
 
struct UF
{
	int par[MX],rank[MX];
	
	void init(int n)
	{
		for(int i=0;i<n;i++)
		{
			par[i]=i;
			rank[i]=0;
		}
	}
	void rem(int i)
	{
		par[i]=i;
		rank[i]=0;
	}
	int find(int x)
	{
		if(x==par[x]) return x;
		return par[x]=find(par[x]);
	}
	void unite(int x,int y)
	{
		x=find(x);
		y=find(y);
		if(x==y) return;
		if(rank[x]<rank[y])
		{
			par[x]=y;
		}
		else
		{
			par[y]=x;
			if(rank[x]==rank[y]) rank[x]++;
		}
	}
	bool same(int x,int y)
	{
		return find(x)==find(y);
	}
};
UF uf;
vector <int> vec[MX];
vector <P> query[MX];
int id[MX];
bool use[MX];
int dp[MX];
 
int main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i=0;i<m;i++)
	{
		int p,q,c;
		scanf("%d %d %d",&p,&q,&c);p--,q--,c--;
		query[c].push_back(P(p,q));
	}
	int sz=n;
	for(int i=0;i<MX;i++)
	{
		if(query[i].empty()) continue;
		for(int j=0;j<query[i].size();j++)
		{
			P p=query[i][j];
			uf.rem(p.first);
			uf.rem(p.second);
			id[p.first]=id[p.second]=-1;
		}
		for(int j=0;j<query[i].size();j++)
		{
			P p=query[i][j];
			uf.unite(p.first,p.second);
		}
		for(int j=0;j<query[i].size();j++)
		{
			P p=query[i][j];
			int r=uf.find(p.first);
			if(id[r]==-1) id[r]=sz++;
			//printf("%d %d: %d\n",r,id[r],p.first);
			vec[p.first].push_back(id[r]);
			vec[id[r]].push_back(p.first);
			//printf("%d %d: %d\n",r,id[r],p.second);
			vec[p.second].push_back(id[r]);
			vec[id[r]].push_back(p.second);
		}
	}
	queue <int> que;
	que.push(0);
	memset(dp,-1,sizeof(dp));
	dp[0]=0;
	while(!que.empty())
	{
		int v=que.front();que.pop();
		for(int i=0;i<vec[v].size();i++)
		{
			int to=vec[v][i];
			if(dp[to]==-1)
			{
				dp[to]=dp[v]+1;
				que.push(to);
			}
		}
	}
	if(dp[n-1]==-1) puts("-1");
	else printf("%d\n",dp[n-1]/2);
	return 0;
}

Measured memory_bytes: 73600
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define showmap(is, js, x) {rep(i, is){rep(j, js){cout << x[i][j] << " ";}cout << endl;}}
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> llP;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


int main()
{
    string s;
    cin >> s;
    int n = s.size();

    vector<int> num(3);
    rep(i, n){
        num[s[i]-'a']++;
    }

    int max_n = max(max(num[0], num[1]), num[2]);
    int min_n = min(min(num[0], num[1]), num[2]);

    if (abs(max_n-min_n)<=1){
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

}



Measured memory_bytes: 512
import sys
input = sys.stdin.readline

#木の根を求める
def find(x):
    if par[x] == x:
        return x
    else:
        return find(par[x])

#xとyの属する集合の併合
def unite(x,y):
    x = find(x)
    y = find(y)
    
    if x != y:
        #xとyの属している集合が異なる時
        if rank[x] < rank[y]:
            par[x] = y
            size[y] += size[x]
        else:
            par[y] = x
            size[x] += size[y]
            if rank[x]==rank[y]:
                rank[x] += 1

#xとyが同じ集合に属するかの判定
def same(x,y):
    return find(x) == find(y)

########################################
#初期化
n,m = map(int,input().split())

par = [0]*n #親
for i in range(n):
    par[i] = i
rank = [1]*n #深さ
size = [1]*n #size[i]:iを根とするグループのサイズ

edge = [tuple(map(int,input().split())) for i in range(m)]
edge = edge[::-1]
for i in range(m):
    edge[i] = (edge[i][0]-1,edge[i][1]-1)

res = []
for i in range(m):
    fi = find(edge[i][0])
    se = find(edge[i][1])
    if fi == se:
        res.append(0)
    else:
        res.append(size[fi]*size[se])
        unite(fi,se)
ass = 0
for i in range(m):
    ass += res[m-1-i]
    print(ass)


Measured memory_bytes: 24052
use std::io;

fn main() {
	//let mut a: Vec<Vec<i32>> = vec![vec![0, 0, 0], vec![0, 0, 0], vec![0, 0, 0]];
	let mut flag = true;
	let mut a: Vec<Vec<i32>> = Vec::new();
	a.push(Vec::new());
	a.push(Vec::new());
	a.push(Vec::new());
	for number in (0..3){
		let mut buf = String::new();
		io::stdin().read_line(&mut buf).expect("error");
		let mut iter = buf.split_whitespace();
		for num in (0..3) {
			a[number].push(match iter.next().unwrap().parse() {
				Ok(n) => n,
				Err(_) => panic!(""),
			}
			);
		}
	}
	
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("error");
	let n: i32 = match buf.trim().parse() {
		Ok(num) => num,
		Err(_) => panic!(""),
	};
	let mut b: Vec<i32> = Vec::new();
	for number in (0..n) {
		let mut buf = String::new();
		io::stdin().read_line(&mut buf).expect("error");
		b.push(
			match buf.trim().parse() {
				Ok(num) => num,
				Err(_) => panic!(""),
			}
		);
	}
	
	
	let mut c: Vec<Vec<bool>> = Vec::new();
	for i in (0..3) {
		c.push(Vec::new());
	}
	for i in (0..3) {
		for j in (0..3) {
			c[i].push(false);
		}
	}
	for i in (0..3) {
		for j in (0..3) {
			for k in &b {
				if a[i][j] == *k {
 					c[i][j] = true;
				}
				if c[i][j] {
					break;
				}
			}
		}
	}
	
	for i in (0..3) {
		if c[i][0] && c[i][1] && c[i][2] {
			flag = false;
		}
	}
	
	if flag {
		for i in (0..3) {
			if c[0][i] && c[1][i] && c[2][i] {
				flag = false;
			}
		}
	}
	
	if flag {
		if c[0][0] && c[1][1] && c[2][2] {
			flag = false;
		}
		if flag && c[0][2] && c[1][1] && c[2][0] {
			flag = false;
		}
	}
	if flag {
		println!("No");
	}else {
		println!("Yes");
	}
}

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

int main() {
    string X;
    cin >> X;

    int cntS = 0;
    int ans = X.size();
    for (int i = 0; i < X.size(); i++) {
        if (X[i] == 'S') cntS++;
        else {
            if (cntS > 0) {
                cntS--;
                ans -= 2;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N,A,B,n,ans=0;
  cin>>N>>A>>B>>n;
  N--;
  while(N--){
    int a;cin>>a;
    ans+=min((a-n)*A,B);
    n=a;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3568
N = int(input())
W = [input() for i in range(N)]
 
WS = list(set(W))
cnt = 0
 
if len(WS) != len(W):
  cnt += 1
else:
  for i in range(N-1):
      if W[i][-1] != W[i+1][0]:
          cnt += 1
 
print('No' if cnt >0 else 'Yes')

Measured memory_bytes: 9124
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;

int main(int argc, char *argv[]) {
	
	string s; cin >> s;

	int sum = 700;
	for (int i = 0; i < s.size(); i++) {
		if(s[i] == 'o') {
			sum += 100;
		}
	}
	cout << sum << endl;

	return 0;
}


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

int main()

{
   long long a=0,b,c,d,e,f,g,h,i,j,k,l,m,n,t;

   cin>>n;

   long long ar[n];

   for(i=1;i<=n;i++)
   {
       cin>>ar[i];

       if(ar[i]!=i) a++;
   }

   if(a<=2) cout<<"YES"<<endl;

   else if(a>2) cout<<"NO"<<endl;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
typedef long long int ll;
typedef pair<int, int> P;
#define INF 1e9 + 7

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

    int N,Q;
    cin >> N >> Q;
    // bool child[N][N];
    // rep(i,N) rep(j,N) child[i][j] = false;
    vector<vector<int>> child(N, vector<int>());
    rep(i,N-1){
        ll a,b;
        cin >> a >> b;
        // child[a-1][b-1] = true;
        child[a-1].push_back(b-1);
    }
    
    int p[Q], x[Q];
    rep(i,Q){
        cin >> p[i] >> x[i];
        p[i]--;
    }
    
    vector<ll> count(N, 0);
    rep(i,Q){
        count[p[i]] += x[i];
    }
    
    rep(i,N){
        // for(int j=i+1; j<N; j++){
        //     if(child[i][j]){
        //         count[j] += count[i];
        //     }
        // }
        rep(j, child[i].size()){
            count[child[i][j]] += count[i];
        }
    }
    
    rep(i,N){
        cout << count[i] << ' ';
    }

    return 0;
}

Measured memory_bytes: 16512
#include <stdio.h>
int main(void) {
    int n,car,in,out,i,max;
    scanf("%d %d",&n,&car);
    max=car;
    for (i=0; i<n; i++) {
        scanf("%d %d",&in,&out);
        car=car+in-out;
        if (car<0) break;
        if (car>max) max=car;
    }
    if (car<0) {
        printf("0\n");
    } else {
        printf("%d\n",max);
    }
    return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL


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

    int N, K;
    cin >> N >> K;
    vs64 p(N);
    s64 temp;
    rep (i, N)
    {
        cin >> temp;
        p[i] = temp + 1;
    }

    s64 ans = 0;
    rep (i, K)
    {
        ans += p[i];
    }

    int l = 0;
    s64 sum = ans;
    for (int i = K; i < N; ++i)
    {
        sum = sum - p[l] + p[i];
        ans = MAX(ans, sum);
        ++l;
    }

    cout << setprecision(10) << (double)ans / 2.0 << "\n";
    return 0;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const string EMP = " ";
const ll INF = 1LL<<60;
const ll MOD = 1000000007;

int main(){
  int n, q; string s;
  cin >> n >> q >> s;
  vector<int> cnt(n,0);
  for(int i = 1; i < n; i++){
    if(s[i-1] == 'A' && s[i] == 'C'){
      cnt[i] = cnt[i-1]+1;
    }else{
      cnt[i] = cnt[i-1];
    }
  }
  for(int i = 0; i < q; i++){
    int l,r; cin >> l >> r;
    l--; r--;
    int now = cnt[r] - cnt[l];
    cout << now << endl;
  }
  return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const ll MOD2=998244353;
const double PI=acos(-1);
const ll INF=1e15;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

int main() {
  ll n;
  cin >> n;
  vl a(n);
  rep(i,n){
    cin >> a[i];
  }
  ll cnt=a[0]-1;
  ll D=2;
  FOR(i,1,n){
    if(a[i]==D){
      D++;
    }
    else{
      cnt +=(a[i]-1)/D;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <fstream>
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <numeric>
#include <functional>
#include <string> 
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <random>

using namespace std;
using ll = long long;

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

#define REP(i,n) for(int i = 0; i < int(n); i++)
#define FOR(i, m, n) for(int i = int(m);i < int(n);i++)
#define ALL(obj) (obj).begin(),(obj).end()

const ll MOD = (ll)1e9 + 7;
const ll HINF = (ll)1e18;
const ll LINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;

template<class T> void corner(bool flg, T hoge) {
	if (flg) {
		cout << hoge << endl;
		exit(0);
	}
	else return;
}

template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {
	o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;
}

template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {
	o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}

template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {
	o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;
}

template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {
	o << "{" << obj.first << ", " << obj.second << "}"; return o;
}

template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {
	o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}

void print(void) {
	cout << endl;
}

template <class Head> void print(Head&& head) {
	cout << head;
	print();
}

template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {
	cout << head << " ";
	print(forward<Tail>(tail)...);
}

void YN(bool flg) {
	cout << ((flg) ? "YES" : "NO") << endl;
}

void Yn(bool flg) {
	cout << ((flg) ? "Yes" : "No") << endl;
}

void yn(bool flg) {
	cout << ((flg) ? "yes" : "no") << endl;
}

int main() {
	string S; cin >> S;
	int ans = LINF;
	for(int i = 2; i < S.size(); ++i){
		int X = (S[i - 2] - '0') * 100 + (S[i - 1] - '0') * 10 + (S[i] - '0');
		ans = min(ans, abs(X - 753));
	}
	cout << ans << endl;
	
	return 0;
}



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

int main(){
    int k,s;
    cin>>k>>s;
    ll ans=0;
    for (int i = 0; i <=k; ++i) {//x
        for (int j = 0; j <=k; ++j) {//y
            if(i+j<=s && s-i-j<=k)ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int selectionsort(int a[],int n)
{
    int i,j,mini,temp,count=0;
    for(i=0;i<n-1;i++)
    {
        mini=i;
        for(j=i;j<n;j++)
        {
            if(a[j]<a[mini])
                mini=j;
        }
            temp=a[i];
            a[i]=a[mini];
            a[mini]=temp;
            if(i!=mini) count++;
    }
    return count;
}
int main()
{
    int a[100],n,i,count;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    count=selectionsort(a,n);
    for(i=0;i<n;i++)
    {
        if(i>0&&i!=n)cout<<" ";
        cout<<a[i];
    }
        cout<<endl;
        cout<<count<<endl;
}



Measured memory_bytes: 3088
#include<iostream>
#include<cmath>
using namespace std;
void swap(int &a,int &b)
{
	int c=a;
	a=b;
	b=c;
}
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
	if(a>b)
		swap(a,b);
	if(a>c)
		swap(a,c);
	if(b>c)
		swap(b,c);
	cout<<a<<" "<<b<<" "<<c<<endl;
    return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int inf = 1e9;
double pi = 3.14159265359;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, b, a) for (int i = a - 1; i >= b; i--)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

int main() {
    int a, b;
    cin >> a >> b;
    cout << a * b << "\n";
}

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

int main() {
  int X;
  cin >> X;
  int ans = 0;
  int num = X / 100; //モノを何個買うかを計算
  int small_yen = X % 100;//払うべき値段(10の位と1の位)
  //cout << "small_yen: " << small_yen << endl;
  //cout << "num: " << num << endl;
  for(int i=5; i>=1; i--){
    int num_each = small_yen / i;
    num = num - num_each;
    small_yen = small_yen - num_each*i; 
    //cout << "i: " << i << " num: " << num << " small_yen: " << small_yen<< endl;
  }
  

  if( num < 0  ||  small_yen != 0 ){
    cout << ans << endl;
    return 0;
  }
  
  if( small_yen == 0){
    ans = 1;
    cout << ans << endl;
    return 0;
  }
  
}


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

using namespace std;

void solve()
{
	int H, W;
	cin >> H >> W;
	vector<string> a(H);
	for (int i = 0; i < H; ++i)
	{
		cin >> a[i];
	}
	string temp = "";
	for (int i = 0; i < W + 2; ++i)
	{
		temp += "#";
	}
	cout << temp << endl;
	for (int i = 0; i < H; ++i)
	{
		cout << "#" << a[i] << "#" << endl;
	}
	cout << temp << endl;
}

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

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

int main() {
    int n; cin >> n;
    vector<vector<int>> g(n * n);
    for(int i = 0; i < 2 * n * n - 2 * n; ++i) {
        int a, b; cin >> a >> b;
        g[a - 1].push_back(b - 1);
        g[b - 1].push_back(a - 1);
    }

    vector<bool> used(n * n);
    vector<vector<int>> ans(n, vector<int>(n, -1));
    for(int i = 0; i < n * n; ++i) { // r1
        if(g[i].size() == 2u) {
            int cur = i;
            ans[0][0] = cur;
            used[cur] = true;
            for(int j = 0; j < n - 1; ++j) {
                int nxt = -1;
                for(auto to : g[cur]) {
                    if(used[to] || (nxt != -1 && g[nxt].size() < g[to].size())) continue;
                    nxt = to;
                }
                cur = ans[0][j + 1] = nxt;
                used[nxt] = true;
            }
            break;
        }
    }
    for(int i = 0; i < n - 1; ++i) {
        for(int j = 0; j < n; ++j) {
            for(auto to : g[ans[i][j]]) {
                if(used[to]) continue;
                ans[i + 1][j] = to;
                used[to] = true;
            }
        }
    }

    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < n; ++j) {
            cout << ans[i][j] + 1 << " \n"[j + 1 == n];
        }
    }
}



Measured memory_bytes: 3520
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
int ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.second < secondElof.second;
}
ll nod(ll F) { return log10(F) + 1; }
//**定義場所**//
//gcd, isPrime, eratos, modinv, bitSearch, dfs, bfs, dijkstra, UnionFind//
ll i, j, k, l, m, n; ll N, M, K, H, W, L; string S;
ll MOD = 1000000007; ll ans = 0; ll INF = 9999999999999;
vl flag, color; vll path, path2;
//***********//
class UnionFind {
public:
	vl rank, par, siz;
	UnionFind() {}
	UnionFind(ll N) {
		rank.resize(N, 0);
		par.resize(N, 0);
		siz.resize(N, 1);
		init(N);
	}
	void init(ll N) {
		for (ll i = 0; i < N; i++) {
			par[i] = i;
			rank[i] = 0;
		}
	}
	ll find(ll x) {
		if (par[x] == x) {
			return x;
		}
		else {
			return par[x] = find(par[x]);
		}
	}
	void unite(ll x, ll y) {
		x = find(x);
		y = find(y);
		if (x != y) {
			if (rank[x] < rank[y]) {
				par[x] = y;
				siz[y] += siz[x];
			}
			else {
				par[y] = x;
				siz[x] += siz[y];
				if (rank[x] == rank[y]) rank[x]++;
			}
		}
	}
	bool issame(ll x, ll y) {
		return find(x) == find(y);
	}
	ll size(ll x) {
		return siz[find(x)];
	}
};
int main() {
	cin >> N >> M >> K;
	path.resize(N);
	path2.resize(N);
	UnionFind UF(N);
	UnionFind UF2(N);
	UF.init(N);
	UF2.init(N);
	for (i = 0; i < M; i++) {
		ll a, b;
		cin >> a >> b;
		path[a-1].push_back(b-1);
		path[b - 1].push_back(a - 1);
		UF.unite(a - 1, b - 1);
	}
	for (i = 0; i < K; i++) {
		ll a, b;
		cin >> a >> b;
		if (!UF.issame(a - 1, b - 1)) { continue; }
		path[a - 1].push_back(b - 1);
		path[b - 1].push_back(a - 1);
		UF2.unite(a - 1, b - 1);
	}
	for (i = 0; i < N; i++) {
		cout << UF.size(i) -1 - path[i].size() << " ";
	}
}


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

int main() {
  int N;
  int A;
  cin >> N;
  cin >> A;
  
  if (A - N >= 0) {
    cout << "Yes" << endl;
  }
  else {
    if (A - N % 500 >= 0) {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
using namespace std;
int cnt[200010], total, resi[200010][2], xremain[2];
int main(){
	int n;
	char x[200010];
	cin >> n >> x;
	for(int i = 0; i <= n; ++i)
		cnt[i] = cnt[i >> 1] + (i & 1);
	for(int i = 0; i < n; ++i) if(x[i] == '1') ++total;

	if(total != 1) resi[0][0] = 1 % (total - 1);
	resi[0][1] = 1 % (total + 1);
	for(int i = 1; i < n; ++i)
	{
		if(total != 1) resi[i][0] = (resi[i-1][0] * 2) % (total - 1);
		resi[i][1] = (resi[i-1][1] * 2) % (total + 1);
	}
	for(int i = 0; i < n; ++i)
	{
		if(total != 1) xremain[0] = (xremain[0] * 2 + x[i] - '0') % (total - 1),
		xremain[1] = (xremain[1] * 2 + x[i] - '0') % (total + 1);
	}

	for(int i = 0; i < n; ++i)
	{
		int t, rem;
		if(x[i] == '0')
		{
			t = total + 1;
			rem = (xremain[1] + resi[n-1-i][1]) % t;
		}
		else
		{
			t = total - 1;
			if (t == 0) {printf("0\n");continue;}
			rem = (t + xremain[0] - resi[n-1-i][0]) % t;
		}

		int ans = 1;
		while(rem) {
			rem %= cnt[rem];
			++ans;
		}
		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 6284
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define watch(x) cout<<"->"<<#x<<" : "<<x<<endl;
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c)) 
#define all(v) (v).begin(),(v).end()
typedef long long ll;
typedef unsigned long long llu;
const double PI = 2*acos(0.0);
#define int long long
signed main()
{
	//freopen("","r",stdin);
	//freopen("","w",stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int a,b,c;
	cin>>a>>b>>c;
	int res = 0;
	while((a%2==0)&&(b%2==0)&&(c%2==0)&&res<1e7)
	{
		int tmpa=a,tmpb=b,tmpc=c;
		a=tmpb/2 + tmpc/2;
		b=tmpa/2 + tmpc/2;
		c=tmpa/2 + tmpb/2;
		++res;
	}	
	cout<<((res==1e7)?-1:res)<<endl;
	return 0;
}

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

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

int W,H;
char fld[50][50];

int calc(){
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(!isdigit(fld[i][j]))continue;
            int dir=fld[i][j]-'0';
            for(int d=1;d>=-2;d--){
                int nd=(dir+d+4)%4;
                int ny=i+dy[nd],nx=j+dx[nd];
                if(ny<0||ny>=H||nx<0||nx>=W||(fld[ny][nx]!='X'&&fld[ny][nx]!='.'))continue;
                fld[i][j]=nd+'0';
                break;
            }
        }
    }
    int ret=0;
    char nfld[50][50];
    bool ok[50][50]={{0}};
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(fld[i][j]=='#'||isdigit(fld[i][j]))continue;
            for(int d=0;d>=-3;d--){
                int nd=(d+4)%4;
                int ny=i+dy[nd],nx=j+dx[nd];
                if(ny<0||ny>=H||nx<0||nx>=W)continue;
                if(!isdigit(fld[ny][nx])||fld[ny][nx]!='0'+(nd+2)%4)continue;
                ok[ny][nx]=true;
                break;
            }
        }
    }

    for(int i=0;i<H;i++)for(int j=0;j<W;j++)nfld[i][j]='*';
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(nfld[i][j]!='*')continue;
            if(ok[i][j]){
                int ny=i+dy[fld[i][j]-'0'];
                int nx=j+dx[fld[i][j]-'0'];
                if(fld[ny][nx]!='X'){
                    nfld[ny][nx]=fld[i][j];
                    nfld[i][j]='.';
                }
                else{
                    nfld[ny][nx]='X';
                    nfld[i][j]='.';
                    ret++;
                }
            }
            else{
                nfld[i][j]=fld[i][j];
            }

        }
    }

    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            fld[i][j]=nfld[i][j];
        }
    }

    return ret;
}

int main(){

    while(cin>>W>>H,W||H){
        int cnt=0;
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                cin>>fld[i][j];
                switch(fld[i][j]){
                case 'E':fld[i][j]='0';break;
                case 'S':fld[i][j]='1';break;
                case 'W':fld[i][j]='2';break;
                case 'N':fld[i][j]='3';break;
                }
                if(isdigit(fld[i][j]))cnt++;

            }
        }

        for(int i=1;i<=180;i++){
            cnt-=calc();
            if(cnt==0){
                cout<<i<<endl;
                break;
            }
        }
        if(cnt)cout<<"NA"<<endl;
    }
    return 0;
}

Measured memory_bytes: 1164
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        x: i128,
        k: i128,
        d: i128,
    }

    let ans;

    if x.abs() > k * d {
        ans = x.abs() - k * d;
    } else {
        let q = x.abs() / d;
        let r = x.abs() % d;
        if (k - q) & 1 == 0 {
            ans = r;
        } else {
            ans = d - r;
        }
    }

    println!("{}", ans);
}


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

int main(){
    int n,s=0;
    cin>>n;
    int a[n];
    for(int i=1;i<=n;i++){
        cin>>a[i];
        s+=a[i];
    }
    int m;
    cin>>m;
    for(int i=0;i<m;i++){
        int m1,m2;
        cin>>m1>>m2;
        cout<<s-a[m1]+m2<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define FOR1(i, n) FOR(i, 1, n+1)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define int long long
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));
#define myCeil(dividend, divisor) ceil((double)(dividend) / (double)(divisor))
#define myFloor(dividend, divisor) floor((double)(dividend) / (double)(divisor))
#define calcDigits(num) floor(log10(num))+1

#define dl(line) cerr << "RUN: until " << (line) << "th line." << endl;
#define dv(name, value) cerr << (name) << " is " << (value) << endl;
#define da(v)  cerr << "["; REPI(itr, v){cerr << *itr << (itr != --v.end() ? ", " : "");} cerr << "]" << endl;
#define dpa(v) cerr << "[ " << endl;REPI(itr, v) { cerr << "  [" << (*itr).first << ", " << (*itr).second << ']' << (itr != --v.end() ? "," : "") << endl; } cerr << "]" << endl;


void solve(long long X){
  FOR(a, -1000, 1001) {
    int a5 = 1;
    REP(x, 5) a5 *= a;
    FOR(b, -1000, 1001) {
      int b5 = 1;
      REP(x, 5) b5 *= b;

      if (a5 - b5 == X) {
        cout << a << ' ' << b << endl;
        return;
      }
    }
  }
}

signed main(){
  long long X;
  scanf("%lld",&X);
  solve(X);
}


Measured memory_bytes: 3704
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
int ai[1000];
int bi[1000];
int main()
{
    int n,m,x,y;
    scanf("%d %d %d %d",&n,&m,&x,&y);
    for(int i=0;i<n;i++)
        scanf("%d",&ai[i]);
    for(int j=0;j<m;j++)
        scanf("%d",&bi[j]);
    sort(ai,ai+n);
    sort(bi,bi+m);
    int flag = 0;
    for(int i=x+1;i<=y;i++)
    {
        if(i>ai[n-1]&&i<=bi[0])
        {
            flag = 1;
            break;
        }
    }
    if(flag)
        printf("No War\n");
    else
        printf("War\n");
    return 0;
}


Measured memory_bytes: 256