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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Ti = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int h, w;
  cin >> h >> w;
  int a[10][10];
  rep(i, 10) rep(j, 10) cin >> a[i][j];
  rep(i, 10) rep(j, 10) rep(k, 10) chmin(a[j][k], a[j][i]+a[i][k]);
  int ans = 0;
  rep(i, h) rep(j, w) {
    int x;
    cin >> x;
    if(~x) ans += a[x][1];
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int a[3];
    int max = 1,min = 100;
    for(int i = 0; i < 3; i++){
        scanf("%d",&a[i]);
        if(a[i] > max) max = a[i];
        if(a[i] < min) min = a[i];
    }
    printf("%d",max - min);
    return 0;
}

Measured memory_bytes: 128
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
 
//#include <x86intrin.h>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <bitset> 
#include <vector>
#include <cmath>
#include <deque>
#include <queue>
#include <iomanip>
#include <stack>
#include <map>
#include <set>
//#include <ordered_set>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
 
//using namespace __gnu_pbds;
using namespace std;
 
//template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
     
#define F first
#define S second           
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair                                     
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;
const int N = (int)1e6 + 123;
const ll inf = (ll)1e18 + 1;
 
const double pi = acos (-1.0);
const double eps = 1e-9;                  
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n, a[N], b[N], st;
bool used[N];
string s[N];
vector <pii> v1, v2;

inline void boost () {
   ios_base :: sync_with_stdio (0);
   cin.tie (0), cout.tie (0);
}
 
inline void Solve () {
   cin >> n;
   for (int i = 1; i <= n; i ++) {
      cin >> s[i];
      a[i] = b[i] = 0;
      for (int j = 0; j < sz (s[i]); j ++) {
         if (s[i][j] == '(') a[i] ++;
         else {
            if (a[i] > 0) a[i] --;
            else b[i] ++;
         }
      }
      if (b[i] == 0) st += a[i];
      else {
         if (a[i] - b[i] >= 0) v1.pb ({b[i], a[i]});
         else v2.pb ({a[i], b[i]});
      }
   }
   sort (all (v1));
   sort (all (v2));
   reverse (all (v2));
   for (int i = 0; i < sz (v1); i ++) {
      st -= v1[i].F;
      if (st < 0) cout << "No", exit (0);
      st += v1[i].S;
   }
   for (int i = 0; i < sz (v2); i ++) {
      st -= v2[i].S;
      if (st < 0) cout << "No", exit (0);
      st += v2[i].F;
   }
   if (st != 0) cout << "No";
   else cout << "Yes";
}               
 
signed main () {                                       
   //#ifdef QWERTY
   //   freopen("input", "r", stdin);
   //#endif
// freopen (".in", "r", stdin);    
// freopen (".out", "w", stdout);              
   boost ();
   int tt = 1;
   //cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}                   

Measured memory_bytes: 46396
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
using namespace std;
int main()
{
	long long A,B,K;
	cin>>A>>B>>K;
	for(int i=0;i<K;i++)
	{
		if(i%2==0)
		{
			if(A%2==0)
			{
				A=A/2;
				B=B+A;
			}
			else
			{
				A=(A-1)/2;
				B=B+A; 
			}	
			 
		}
		else
		{
			if(B%2==0)
			{
				B=B/2;
				A=B+A;
			}
			else
			{
				B=(B-1)/2;
				A=B+A; 
			}	
			 
		}
	}
	cout<<A<<" "<<B;
	return 0;
}

Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;

void solve()
{
    int n, m;
    cin >> n >> m;
    priority_queue<int> pq;
    rep(i, n)
    {
        int a;
        cin >> a;
        pq.push(a);
    }
    rep(i, m)
    {
        int mx = pq.top();
        pq.pop();
        mx /= 2;
        pq.push(mx);
    }
    ll ans = 0;
    while (pq.size())
    {
        int x = pq.top();
        pq.pop();
        ans += x;
    }
    cout << ans << endl;
}

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

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

#define int long long

using namespace std;

const int mod = 1e9 + 7;

int qpow(int a, int power) {
    if(power == 0) {
        return 1;
    }
    int b = qpow(a, power/2);
    if(power % 2 == 0) {
       return (b * b) % mod;
    }
    else {
        return (((b * b) % mod) * a) % mod;
    }
}

int inv(int a) {
    return qpow(a, mod - 2);
}

vector<int> f(2e5 + 10), inv_f(2e5 + 10);

int c(int n, int k) {
    return f[n] * inv_f[k] % mod * inv_f[n - k] % mod;
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    f[0] = 1;
    for (int i = 1; i < f.size(); i++) {
        f[i] = i * f[i - 1] % mod;
    }
    for (int i = 0; i < f.size(); i++) {
        inv_f[i] = inv(f[i]);
    }
    int h, w, n;
    cin >> h >> w >> n;
    vector<pair<int, int>> obst(n);
    for(int i = 0; i < n; i ++) {
        cin >> obst[i].first >> obst[i].second;
        obst[i].first--;
        obst[i].second--;
    }
    obst.push_back({h - 1, w - 1});
    n++;
    sort(obst.begin(), obst.end());
    vector<int> dp(n);
    for (int i = 0; i < n; i++) {
        int x = obst[i].first, y = obst[i].second;
        dp[i] = c(x + y, x);
        for (int j = 0; j < i; j++) {
            int x1 = obst[j].first, y1 = obst[j].second;
            if (x1 <= x && y1 <= y) {
                dp[i] = (dp[i] - dp[j] * c(x - x1 + y - y1, x - x1) % mod + mod) % mod;
            }
        }
        //cerr << dp[i] << endl;
    }
    cout << dp.back() << endl;
}


Measured memory_bytes: 6616
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)



int mod = 1000000007;
int add(int x, int y) { return (x += y) >= mod ? x - mod : x; }
template<class... T> int add(int x, T... y) { return add(x, add(y...)); }
int mul(int x, int y) { return 1LL * x * y % mod; }
template<class... T> int mul(int x, T... y) { return mul(x, mul(y...)); }
int sub(int x, int y) { return add(x, mod - y); }
template<class V, int ME> class BIT {
public:
    V bit[1 << ME];
    V operator()(int e) { V s = 0; e++; while (e) s = add(s, bit[e - 1]), e -= e&-e; return s; }
    void update(int e, V v) { e++; while (e <= 1 << ME) bit[e - 1] = add(bit[e - 1], v), e += e&-e; }
};
//-----------------------------------------------------------------------------------
int N;
int dp[1010101];
BIT<int, 20> sm;
//-----------------------------------------------------------------------------------
int main() {
    cin >> N;

    dp[1] = N;
    sm.update(1, dp[1]);
    dp[2] = add(dp[1], mul(N - 1, N - 1), N - 1);
    sm.update(2, dp[2]);
    rep(i, 3, N + 1) {
        // Naive
        //dp[i] = add(dp[i - 1], mul(N - 1, N - 1), N - i + 2);
        //rep(j, 1, i - 2) dp[i] = add(dp[i], dp[j]);

        // Optimized
        dp[i] = add(dp[i - 1], mul(N - 1, N - 1), sm(i - 3), N - i + 2);
        sm.update(i, dp[i]);
    }

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

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

int F[102][102];

void setblock(int c, int d, int x, int y){
  if(d==0){
    for(int i=0;i<4;i++){
      F[y][x+i]=c;
      F[y+1][x+i]=c;
    }
  }else{
    for(int i=0;i<4;i++){
      F[y+i][x]=c;
      F[y+i][x+1]=c;
    }
  }

}

void DFS(int Y, int X, int c){
  if(F[Y][X]!=c)
    return;

  F[Y][X] = 6;

  DFS(Y-1, X  ,c);
  DFS(Y  , X+1,c);
  DFS(Y+1, X  ,c);
  DFS(Y  , X-1,c);
}

int main(){
  int w,h,xs,ys,xg,yg,n;
  while(true){
  cin >> w >> h;
  for(int i=0;i<h;i++){
   for(int k=0;k<w;k++){
     F[i][k]=-1;
   }
  }
  if(w==0&&h==0){
    break;
  }
  cin >> xs >> ys;
  cin >> xg >> yg;
  cin >> n;
  for(int i=0; i<n; i++){
    int c,d,x,y;
    cin >> c >> d >> x >> y;
    setblock(c,d,x,y);
  }

  DFS(ys,xs,F[ys][xs]);
  if(F[yg][xg]==6){
    cout << "OK" << endl;
  }else{
    cout << "NG" << endl;
  }
}
  return 0;
}



Measured memory_bytes: 3116
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define ALL(v) v.begin(), v.end()
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
	int K, X;
	cin >> K >> X;
	if (K*500 >= X) puts("Yes");
	else puts("No");
}

Measured memory_bytes: 384
def calc_diffsum(li):
    ans = 0
    for ind,i in enumerate(li[:-1]):
        ans += abs(i-li[ind+1])
    return ans
#%%
N = int(input())
A = [int(input())for _ in range(N)]
#%%
A.sort()
li = []
li2 = []
for ind,i in enumerate(A):
    if(ind%2==1):
        li.append(A[-ind//2])
        li2.append(A[ind//2])
    else:
        li.append(A[ind//2])
        li2.append(A[-ind//2-1])

if(abs(li[-1]-li[0])>abs(li[-1]-li[-2])):
    li.insert(0,li[-1])
    del li[-1]
if(abs(li2[-1]-li2[0])>abs(li2[-1]-li2[-2])):
    li2.insert(0,li2[-1])
    del li2[-1]
print(max(calc_diffsum(li),calc_diffsum(li2)))


Measured memory_bytes: 9676
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  int A = 0;
  cin >> N;

  for (int i = 0; i < N; i++){
    int l, r;
    cin >> l >> r;

    A += (r - l) + 1;
  }

  cout << A << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int a = scan.nextInt();
    int b = scan.nextInt();
    int c = scan.nextInt();
    if(a<b&&b<c){
      System.out.println("Yes");
    }else {
      System.out.println("No");
    }
  }
}



Measured memory_bytes: 26328
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long lli;
lli n,c,k;
vector<lli> t;
lli ans = 0;
int main(int argc, char const *argv[]) {
    cin >> n >> c >> k;
    t = vector<lli> (n);
    for(lli i = 0;i < n;i++) cin >> t[i];
    sort(t.begin(),t.end(),greater<lli>());
    lli d = t[0];
    lli p = 1;
    ans = 1;
    for(lli i = 1;i < n;i++){
        if(d-t[i] > k || p == c) ans++,p = 1,d = t[i];
        else p++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)

int main() {
    int a,b,c;
    cin>>a>>b>>c;

    cout<<(a+b+c)-max({a,b,c})<<endl;

}


Measured memory_bytes: 256
#include<cstdio>
#include<utility>
#include<algorithm>
using namespace std;
typedef pair<int, int> P;
const int MAX_N = 100000;
const int MAX_V = 1000000000;
int N;
int X[MAX_N];
int L[MAX_N];
void input(){
scanf("%d", &N);
for(int i = 0; i < N; ++i){
scanf("%d%d", X + i, L + i);
}
}
P ps[MAX_N];
int solve(){
for(int i = 0; i < N; ++i){
	ps[i] = P(X[i] + L[i], X[i] - L[i]);
}
sort(ps, ps + N);
int cur = -MAX_V;
int ans = 0;
for(int i = 0; i < N; ++i){
if(cur <= ps[i].second){
ans++;
cur = ps[i].first;
}
}
return ans;
}
int main(){
input();
int ans = solve();
printf("%d\n", ans);
return 0;
}

Measured memory_bytes: 1792
S = input()
T = input()

max = 0

for i in range(len(S)-len(T) + 1):
    count = 0
    for j in range(len(T)):
        #print(i, j, S[i], T[j])
        if S[i + j] == T[j]:
            count = count + 1
    if count > max:
        max = count

print(len(T) - max)


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

using namespace std;

const int N = 1017;
const int MOD = 1000 * 1000 * 1000 + 7;
const int M = 2019;

int L, R;

bool read() {
    if (!(cin >> L >> R))
        return false;

    return true;
}

void solve() {
    R = min(R + 1, L + M);
    int ans = M;

    for (int i = L; i < R; ++i)
        for (int j = i + 1; j < R; ++j)
            ans = min(ans, (i % M) * (j % M) % M);

    cout << ans << endl;
}

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

    while (read())
        solve();

    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<utility>
#include<algorithm>
#include<queue>
#include<stack>
#include<string>
#include<stdlib.h>
#include<stdio.h>
#include<cmath>
#include<cstdlib>
#include<typeinfo>
#include<sstream>
#include<list>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define fori(i,k,n) for(int i=k;i<(int)n;i++)
using namespace std;
int in()
{
	int x;cin>>x;
	return x;
}
int stringInt(string a)
{
	return atoi(a.c_str());
}
string intString(int a)
{
	stringstream ss;
	ss<<a;
	return ss.str();
}
vector<int> SieveOfEratosthenes(int x)
{
	vector<int> a;
	vector<int> b(x+1,0);
	for(int i=2;i<=x;i++)
	{
		if(b[i]==0)
		{
			a.push_back(i);
			for(int l=i;l<=x;l+=i)
			{
				b[l]=1;
			}
		}
	}
	return a;
}

int main ()
{
	int t;
	cin>>t;
	for(int i=0;i<t;i++)
	{
		int n,k;
		vector<int> ans;
		ans.push_back(0);
		cin>>n>>k;
		int x,y=in();
		rep(l,n-1)
		{
			cin>>x;
			ans.push_back(x-y);
			y=x;
		}

		sort(ans.rbegin(),ans.rend());
		int A=0;
		fori(l,k-1,n)
		{
			A+=ans[l];
		}
		cout<<A<<endl;


	}


}

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

using namespace std;

int main(){
vector <int> vec;
int n, counter = 0;
cin>>n;

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

   int num;
   cin>>num;
   vec.push_back(num);

}

for(int i=0; i<n; i++){
    if(vec.at(i) != i+1){
     counter++;
}
}

if(counter <= 2){
    cout<<"YES"<<endl;
}else{
    cout<<"NO"<<endl;
}
      



}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main{
    public static void main(String[] args)throws IOException{
        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(isr);
        String string;
        int n, count;
        boolean[] primes = new boolean[50001];
         
        primes[0] = primes[1] = false;
        for(int i = 2; i < 50000; i++){
            boolean judge = true;
            for(int j = 2; j <= Math.sqrt(i); j++){
                if(i % j == 0){
                    judge = false;
                    break;
                }
            }
            if(judge) primes[i] = true;
            else      primes[i] = false;
        }
         
        while(!(string = reader.readLine()).equals("0")){
            n = Integer.parseInt(string);
            count = 0;
             
            for(int i = 0; i <= n / 2; i++){
                if(primes[i] && primes[n - i]) count++;
            }
            System.out.println(count);
        }
        reader.close();
    }
}

Measured memory_bytes: 24708
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

// utils
func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func max(a, b int) int {
	return int(math.Max(float64(a), float64(b)))
}

func min(a, b int) int {
	return int(math.Min(float64(a), float64(b)))
}

func abs(a, b int) int {
	return int(math.Abs(float64(a) - float64(b)))
}

//data types

type set map[int]struct{}

type pair struct {
	first  int
	second int
}

func main() {
	sc.Split(bufio.ScanWords)
	n, k := nextInt(), nextInt()
	h := make([]int, n)
	for i := 0; i < n; i++ {
		h[i] = nextInt()
	}

	sort.Sort(sort.Reverse(sort.IntSlice(h)))

	if len(h) <= k {
		fmt.Print(0)
		return
	}

	h = h[k:]
	sum := 0
	for _, v := range h {
		sum += v
	}

	fmt.Print(sum)
}


Measured memory_bytes: 5120
import bisect
n=int(input())
a=sorted([int(i) for i in input().split()])
b=sorted([int(i) for i in input().split()])
c=sorted([int(i) for i in input().split()])
ans=0
for bi in b:
    ans+=bisect.bisect_left(a, bi)*(n-bisect.bisect_right(c, bi))
print(ans)


Measured memory_bytes: 23220
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, n+1)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define rwhole(x) (x).rbegin(), (x).rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define P pair<int, int>
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    string o, e;
    cin >> o >> e;
    int n = o.size() + e.size();
    rep(i, n) {
        if (i%2==0) cout << o[i/2];
        else cout << e[i/2];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3544
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <complex>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(int i=a; i<int(b); i++)
#define rep(i,b) loop(i,0,b)
#define each(e,c) for(auto& e:c)
#define iter(it,c) for(auto it=c.begin(); it!=c.end(); ++it)

ll const inf = 1<<28;
double const pi = acos(-1);

typedef complex<double> P;
typedef vector<P> L;

double cross(const P& a, const P& b) {
    return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
    return real(conj(a)*b);
}
int ccw(P a, P b, P c) {
    b -= a; c -= a;
    if (cross(b, c) > 0)   return +1;       // counter clockwise
    if (cross(b, c) < 0)   return -1;       // clockwise
    if (dot(b, c) < 0)     return +2;       // c--a--b on line
    if (norm(b) < norm(c)) return -2;       // a--b--c on line
    return 0;
}
bool intersectSS(const L &s, const L &t) {
    return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
        ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}

P ps[4];
L l;

bool solve(){
    int c=0;
    rep(i,3){
        L m{ps[i],ps[i+1]};
        if(intersectSS(l,m))c++;
    }
    return c==1;
}

int main(){
    int n;cin>>n;
    rep(_,n){
        rep(i,3){
            double x,y;cin>>x>>y;
            ps[i]=P(x,y);
        }
        ps[3]=ps[0];
        double a,b,c,d;
        cin>>a>>b>>c>>d;
        l={P(a,b),P(c,d)};
        cout << (solve()?"OK":"NG")<<endl;
    }
}

Measured memory_bytes: 1248
#include <iostream>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define MAX_V 10000
using namespace std;
struct node{
  int id,parent,left,right,sibling;
  node():id(0),parent(-1),left(-1),right(-1),sibling(-1){}
};
node nodes[MAX_V]{};

void printPreorder(node n){
  cout<<" "<<n.id;
  if(n.left>=0) printPreorder(nodes[n.left]);
  if(n.right>=0) printPreorder(nodes[n.right]);
}
void printInorder(node n){
  if(n.left>=0) printInorder(nodes[n.left]);
  cout<<" "<<n.id;
  if(n.right>=0) printInorder(nodes[n.right]);
}
void printPostorder(node n){
  if(n.left>=0) printPostorder(nodes[n.left]);
  if(n.right>=0) printPostorder(nodes[n.right]);
  cout<<" "<<n.id;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n; cin>>n;
  REP(i,n){
    int id,left,right;
    cin>>id>>left>>right;
    nodes[id].id=id;
    nodes[id].left=left;
    nodes[id].right=right;
    if(left>=0){
      nodes[left].parent=id;
      nodes[left].sibling=right;
    }
    if(right>=0){
      nodes[right].parent=id;
      nodes[right].sibling=left;
    }
  }
  int root=-1;
  REP(i,n){
    if(nodes[i].parent==-1){
      root=i;
      break;
    }
  }
  cout<<"Preorder\n";
  printPreorder(nodes[root]); cout<<"\n";
  cout<<"Inorder\n";
  printInorder(nodes[root]); cout<<"\n";
  cout<<"Postorder\n";
  printPostorder(nodes[root]); cout<<"\n";
}

Measured memory_bytes: 1396
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    string cmp="keyence";
    string s; cin >> s;
    int len=sz(s); 
    bool ok=true;
    for (int i=0;i<7;i++){
        if (s[i] != cmp[i]){
            for (int j=len-1,k=6;k>=i;k--,j--){
                if (s[j] != cmp[k]) { ok=false; break; }
            }
            break;
        }
    }
    if (ok) cout << "YES" << endl; 
    else cout << "NO" << endl; 
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 3548
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.main = function (_N, dList) {
    var sortedDList = dList.slice().sort(function (a, b) { return a - b; });
    if (sortedDList.length % 2 !== 0)
        return 0;
    var half = sortedDList.length / 2;
    return sortedDList[half] - sortedDList[half - 1];
};
var exec = function () {
    var input = require('fs').readFileSync('/dev/stdin', 'UTF-8');
    var _a = input.split('\n'), N = _a[0], D = _a[1];
    var dList = D.split(' ').map(function (d) { return Number(d); });
    var res = exports.main(Number(N), dList);
    console.log(res);
};
exec();


Measured memory_bytes: 28376
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <sstream>
#include <deque>
#define ll long long
using namespace std;
const int maxn=10000000;
const ll mod=1000000007;
int a[maxn];
int b[maxn];


int main(){
	int N;
	cin>>N;
	int maxxx=0;
	memset(a,0,sizeof(a));
	for(int i=0;i<N;i++){
		cin>>a[i]>>b[i];
		if(a[i]>a[maxxx]){
			maxxx=i;
		}

	}

	int offset=b[maxxx]+a[maxxx];

	cout<<offset;	
	return 0;



}

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

int main(){
    ll n;
    cin >> n;
    vector <ll> a(n);
    
    rep(i,n){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    ll ans=0,ans2=0;

    if(n%2==0){
        rep(i,n/2){
            ans+=2*a[n-1-i];
        }
        ans-=a[n/2];
        rep(i,n/2){
            ans-=2*a[i];
        }
        ans+=a[n/2-1];
    }
    else{
        rep(i,n/2){
            ans+=2*a[n-1-i];
            ans2-=2*a[i];
        }
        rep(i,n/2+1){
            ans-=2*a[i];
            ans2+=2*a[n-i-1];
        }
        ans+=a[n/2];
        ans+=a[n/2-1];
        ans2-=a[n/2];
        ans2-=a[n/2+1];
        ans=max(ans,ans2);
    }

    cout << ans << endl;
    

    return 0;
}

Measured memory_bytes: 4072
from collections import Counter

# mod = (10 ** 9 + 7) ** 5
# MAX = 2 * 10 ** 5 + 1 # これは変動するので注意

# def com_init(MAX, mod):
#     fac = [0] * MAX
#     finv = [0] * MAX
#     inv = [0] * MAX
#     fac[0] = fac[1] = 1
#     finv[0] = finv[1] = 1
#     inv[1] = 1
#     for i in range(2, MAX):
#         fac[i] = fac[i - 1] * i % mod
#         inv[i] = mod - inv[mod % i] * (mod // i) % mod
#         finv[i] = finv[i - 1] * inv[i] % mod
#     return fac, finv

# fac, finv = com_init(MAX, mod)

# def nCr(n, r):
#     if n < r:
#         return 0
#     elif n < 0 or r < 0:
#         return 0
#     return fac[n] * (finv[r] * finv[n - r] % mod) % mod

# n = int(input())
# A = list(map(int, input().split()))

# counter = Counter(A)

# mapping = {}
# for k, v in counter.items():
#     mapping[k] = nCr(v, 2)

# all_sum = 0
# for v in mapping.values():
#     all_sum += v

# memo = {}
# for i in range(n):
#     num = A[i]
#     if num in memo:
#         print(memo[num])
#     else:
#         t = counter[num]
#         ans = all_sum - nCr(t, 2) + nCr(t - 1, 2)
#         print(ans)
#         memo[num] = ans


# nC2というものは、わざわざこれをやる必要がなく、
# t * (t - 1) // 2で良い.
n = int(input())
A = list(map(int, input().split()))

def nC2(n):
    return n * (n - 1) // 2
counter = Counter(A)

mapping = {}
for k, v in counter.items():
    mapping[k] = nC2(v)

all_sum = 0
for v in mapping.values():
    all_sum += v

memo = {}
for i in range(n):
    num = A[i]
    if num in memo:
        print(memo[num])
    else:
        t = counter[num]
        ans = all_sum - nC2(t) + nC2(t - 1)
        print(ans)
        memo[num] = ans



# 初期の回答。都度求めていたためにTLE
# memo = {}
# for i in range(n):
#     ans = 0
#     if A[i] in memo:
#         print(memo[A[i]])
#         continue
#     for k, v in counter.items():
#         if k == A[i]:
#             v -= 1
#         ans += nCr(v, 2)
#     memo[A[i]] = ans
#     print(ans)

Measured memory_bytes: 41988
# -*- coding:utf-8 -*-

def solve():
    S = input()
    for i in range(1, len(S)):
        s = S[:-i]
        if len(s)%2 != 0: continue # 長さが偶数じゃなければ偶文字列になりえない
        
        pivot = len(s)//2
        upper = s[0:pivot]
        lower = s[pivot:]

        if upper == lower:
            print(len(s))
            return

if __name__ == "__main__":
    solve()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);

int main()
{
	ll n,k;
	cin>>n>>k;
	ll a[n],dp[n],i;
	for(i=0;i<n;i++){
		cin>>a[i];
		dp[i]=mod;
	}
	dp[0]=0;
	for(i=1;i<n;i++)
	{
		ll mn=mod;
		for(ll j=i-1;j>=0 && (i-j)<=k;j--)
			mn=min(mn,dp[j]+abs(a[i]-a[j]));
		dp[i]=mn;
	}
	cout<<dp[n-1];
} 

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

int isPrime(int n) {
  if (n < 2) return 0;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) return 0;
  }
  return 1;
}


int main() {
  int N = 100010;
  
  // iが素数かどうか
  vector<int> a(N, 0);
   
  for (int i = 0; i < N; i++) {
    a[i] = isPrime(i);
  }

  vector<int> b(N, 0);
  
  // 2017に似た数かどうか
  for (int i = 0; i < N; i++){
    if (i % 2 == 0) continue;
    if (a[i] && a[(i+1) / 2]) b[i] = 1;
  }
   
  // 累積和
  vector<int> s(N, 0);
  
  for(int i = 0; i < N; i++) {
    s[i+1] = s[i] + b[i];
  }
  
  // クエリ
  int Q;
  cin >> Q;
  
  for (int i = 0; i < Q; i++) {
    int l, r;
    cin >> l >> r;
    
    cout << s[r+1] - s[l] << endl;
    
  }
  
  
  
}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n;
    std::cin >> n;
    int dam[100000];
    long long yama[100000];
    int t=0;
    for (int i = 0; i < n; i++) {
        std::cin >> dam[i];
        t+=dam[i];
    }
    for (int i = 1; i < n; i+=2) {
        t-=2*dam[i];
    }
    yama[0]=t;
    for (int i = 0; i < n-1; i++) {
        yama[i+1]=dam[i]*2-yama[i];
    }
    for (int i = 0; i < n; i++) {
        std::cout << yama[i] << " ";
    }
    
}


Measured memory_bytes: 2432
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <utility>
#include <algorithm>
typedef long double ld;
using namespace std;

ld x[60], y[60], pi=abs(acos(-1.0));
ld dist[60][60], ang[60][60];

int main() {
	int N;
	cin >> N;
	for(int i=0; i<N; ++i) cin >> x[i] >> y[i];
	for(int i=0; i<N; ++i){
		for(int j=0; j<N; ++j){
			if(i!=j){
				dist[i][j]=pow((x[j]-x[i])*(x[j]-x[i])+(y[j]-y[i])*(y[j]-y[i]), 0.5);
				ang[i][j]=atan2(y[j]-y[i], x[j]-x[i]);
			}
		}
	}
	ld ng=0.0, ok=2000, er=1e-8;
	while(ng+er<ok){
		ld mid=(ng+ok)/2;
		int mx=0;
		for(int i=0; i<N; ++i){
			int now=1;
			vector<pair<ld, int>> v;
			for(int j=0; j<N; ++j){
				if(mid*2>=dist[i][j]+er && i!=j){
					ld t=acos(dist[i][j]/(mid*2));
					v.emplace_back(make_pair(ang[i][j]-t, 1));
					if(v.back().first<(-pi)){
						++now;
						v.back().first += pi*2;
					}
					v.emplace_back(make_pair(ang[i][j]+t, -1));
					if(v.back().first>pi){
						++now;
						v.back().first -= pi*2;
					}
				}
			}
			sort(v.begin(), v.end());
			mx=max(mx, now);
			for(int j=0; j<v.size(); ++j){
				now += v[j].second;
				mx=max(mx, now);
			}
		}
		if(mx==N) ok=mid;
		else ng=mid;
	}
	cout << setprecision(15) << ok << endl;
	return 0;
}

Measured memory_bytes: 384
//omajinai c++ atcoder
#include <iostream> 
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include<cmath>
#include<iomanip>
#include<type_traits>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define itn int
#define yes() printf("Yes\n")
#define no() printf("No\n")
typedef long long ll;
constexpr auto mod = 1000000007;
using namespace std;

int main() {
    int r,g,b;
    cin>>r>>g>>b;
    int k;
    cin>>k;

    for(int i=0;i<k;i++){
        if(g<=r){
            g=2*g;
        }
        else if(b<=g){
            b=2*b;
        }
        else{
            break;
        }
    }

        if(r<g&&g<b){
            yes();
        }
        else{
            no();
        }
    
}

Measured memory_bytes: 3632
S = raw_input()

value = int(S, 2)

eval = ''
length = len(S)
if length % 2 == 0: val = 1
else: val = 0
for i in xrange(length):
    if i % 2 == val: eval += '1'
    else: eval += '0'

count = bin(value ^ int(eval,2)).count('1')

if count <= 0.5 * length: print count
else: print (length - count)


Measured memory_bytes: 2948
#![allow(non_snake_case)]

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let H: isize = read();
    let W: isize = read();
    let mut map: Vec<Vec<char>> = vec![];
    for _ in 0..H {
        map.push(read::<String>().chars().collect());
    }
    use std::collections::VecDeque;
    let mut q: VecDeque<(isize, isize, usize)> = VecDeque::new();
    let directions = vec![(1, 0), (0, 1), (-1, 0), (0, -1)];
    let mut costs: Vec<Vec<Option<usize>>> = vec![vec![None; W as usize]; H as usize];

    let mut min_cost = None;
    q.push_back((0, 0, 1));
    costs[0][0] = Some(1);
    while let Some((i, j, cost)) = q.pop_front() {
        if i == H - 1 && j == W - 1 {
            min_cost = Some(cost);
            break;
        }
        for &(di, dj) in &directions {
            let ni = i + di;
            let nj = j + dj;
            if ni < 0 || H <= ni {
                continue;
            }
            if nj < 0 || W <= nj {
                continue;
            }
            let ni = ni as usize;
            let nj = nj as usize;
            if costs[ni][nj].is_some() {
                continue;
            }
            if map[ni][nj] == '#' {
                continue;
            }
            q.push_back((ni as isize, nj as isize, cost + 1));
            costs[ni][nj] = Some(cost + 1);
        }
    }
    match min_cost {
        None => println!("-1"),
        Some(min_cost) => {
            let mut white_count = 0;
            for row in map {
                for cell in row {
                    if cell == '.' {
                        white_count += 1;
                    }
                }
            }
            println!("{}", white_count - min_cost);
        }
    }
}


Measured memory_bytes: 4352
#include <stdio.h>
int main(void){
  int a,b = 0;
  scanf("%d %d", &a, &b);
  if(a>12) printf("%d", b);
   if(a<=12 && a>=6) printf("%d", b/2);
  if(a<6) printf("0");  
  return 0;
}

  


Measured memory_bytes: 1696
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define chmin(x,y) x = min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

const ll MOD = 1000000007;

int main() {
    int n;
    cin >> n;
    vector<ll> a(n); 
    rep(i,n) cin >> a[i];
    ll ans = 0;
    rep(k,60) {
        ll y = 0;
        rep(i,n) if (a[i]>>k & 1) ++y;
        ll res = y*(n-y) % MOD;
        rep(j,k) res = res*2 % MOD;
        ans = (ans+res) % MOD;
    }
    cout << ans << endl;
    return 0;
}


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

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

    vector<vector<vector<int>>> vec(5, vector<vector<int>>(4, vector<int>(11, 0)));

    int ridge;              // 棟
    int floor;              // 階
    int room_number = 0;    // 部屋番号
    int people_number = 0;  // 入居者数
    for(int i=0; i<n; ++i) {
        cin >> ridge >> floor >> room_number >> people_number;
        vec[ridge][floor][room_number] += people_number;
    }

    for(int i=1; i<=4; ++i) {
        for(int j=1; j<=3; ++j) {
            for(int k=1; k<=10; ++k) {
                cout << " " << vec[i][j][k];
            }
            cout << endl;
        }
        if (i != 4) cout << "####################" << endl;
    }

    return 0;
}


Measured memory_bytes: 3164
#include <iostream>
#include <math.h>
using namespace std;
#include <stdlib.h>
#include <vector>

#define HUNDRED 100

int CharCompareA(const void *pelem1, const void *pelem2);
int CharCompareB(const void *pelem1, const void *pelem2);

int compare_int(const void *a, const void *b);


int main() {
	string a,b;
	string s,t,v;

	cin >> s >> t;



	for (int i = 0; i < (int)s.size(); i++) {
		qsort(&s[0], (int)s.size(), sizeof(s[0]), CharCompareA);
	}

	for (int i = 0; i < (int)t.size() ; i++) {
		qsort(&t[0], (int)t.size(), sizeof(t[0]), CharCompareB);
	}


	if(s < t) cout << "Yes";
	else cout << "No";

}

int CharCompareA(const void *pelem1, const void *pelem2) {

	return *(char*) pelem1 - *(char*) pelem2;
}

int CharCompareB(const void *pelem1, const void *pelem2) {

	return *(char*) pelem2 - *(char*) pelem1;
}

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


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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
// using Graph = vector<vector<Edge>>;
const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

// dp[i+1][j] i番目までの品物を選んだとき，重さj以下で最大の価値の総和
int main()
{
    int N, W;
    cin >> N >> W;
    vector<int> w(N + 5);
    vector<int> v(N + 5);
    for (int i = 0; i < N; i++) {
        cin >> w[i] >> v[i];
    }

    vector<ll> dp(W + 100, 0);
    for (int i = 0; i < N; i++) {
        for (int j = W; j >= 0; j--) {
            if (j - w[i] >= 0) {
                dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
            }
        }
    }
    cout << dp[W] << endl;
}

Measured memory_bytes: 4008
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<algorithm> // sort
#include<map> // pair
#include<cmath>
#include<cstring>
#include<set>
using namespace std;
using ll = long long;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
const ll mod = 1e9+7;
const int INF = 1e9;
const ll INFLONG = 1e18;
vector<ll> vec;
ll lower(ll first,ll last,ll a){
  ll mid;
  while(first < last){
    mid = (first+last)/2;
    if(vec[mid] < a){
      first = mid + 1;
    }else{
      last = mid;
    }
  }
  if(vec[first] < a){
    return first;
  }else{
    return first-1;
  }
}
int main(){
  ll n;
  cin >> n;
  ll a[n];
  ll size=0;
  ll first,last;
  rep(i,n){
    cin >> a[i];
  }
  rep(i,n){
    if(i == 0 || a[i] <= vec[0]){
      vec.insert(vec.begin(),a[i]);
      size++;
    }else{
      first=0;
      last=size-1;
      first = lower(first,last,a[i]);
      //MSG(first);
      vec[first] = a[i];
    }

    rep(j,size){
      //cout << vec[j] << " ";
    }
    //cout << endl;
  }
  cout << size;
}


Measured memory_bytes: 2168
#include "bits/stdc++.h"
using namespace std;
int main(void)
{
	long long N, Start, saisyo = 1000000000;
	cin >> N >> Start;
	vector<long long>arr(N, 0);
	for (int i = 0; i < N; i++)
	{
		int j;
		cin >> j;
		arr[i] = abs(Start - j);
		saisyo = min(abs(Start - j), saisyo);
	}
	for (int i = saisyo; i > 0; i--)
	{
		if (saisyo%i == 0)
		{
			for (int j = 0; j < N; j++)
			{
				if (arr[j] %i != 0)
				{
					break;
				}
				if (j == N-1)
				{
					cout << i << "\n";
					return 0;
				}
			}
		}
	}
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
// Welcome to my source code!

int main() {
    IOS
    int n, y;
    cin >> n >> y;
    int a = -1, b = -1, c = -1;
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            int f = n - i - j;
            if (f >= 0 && y == 10000 * i + 5000 * j + 1000 * f) {
                a = i; b = j; c = f;
                break;
            }
        }
    }
    cout << a << ' ' << b << ' ' << c << endl;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kishan Sairam Adapa
 */

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define ll long long int
#define MOD ((int)(1e9) + 7)

using namespace std;

class BStringRotation {
public:
    void solve(istream& cin, ostream& cout) {
        string s, t;
        cin >> s >> t;
        int n = s.length();
        for(int i=0; i<n; i++) {
            if(t.compare(s) == 0) {cout << "Yes" << '\n'; return;}
            string x = " ";
            x += s;
            x[0] = s[s.length()-1];
            s = x.substr(0, n);
        }
        cout << "No" << '\n';
    }
};


int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    BStringRotation solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
N = int(input())
P = list(map(int, input().split()))

dp = [[min(i, N - i - 1, j, N - j - 1) for j in range(N)] for i in range(N)]

presence = [[1 for j in range(N)] for i in range(N)]

ans = 0
for i in range(len(P)):
    P[i] -= 1
    x, y = divmod(P[i], N)
    ans += dp[x][y]
    presence[x][y] = 0

    Q = [(x, y)]
    #%%
    while Q:
        x, y = Q.pop()
        new_value = dp[x][y] + presence[x][y]
        if 1 <= x and dp[x - 1][y] > new_value:
            dp[x - 1][y] = new_value
            Q.append((x - 1, y))
        if x < N - 1 and dp[x + 1][y] > new_value:
            dp[x + 1][y] = new_value
            Q.append((x + 1, y))
        if 1 <= y and dp[x][y - 1] > new_value:
            dp[x][y - 1] = new_value
            Q.append((x, y - 1))
        if y < N - 1 and dp[x][y + 1] > new_value:
            dp[x][y + 1] = new_value
            Q.append((x, y + 1))

print(ans)


Measured memory_bytes: 154124
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        StringBuilder result = new StringBuilder("");

        while(sc.hasNextInt()) {
            if (!result.toString().equals("")) {
                result.append("\n");
            }

            int a = sc.nextInt();
            int b = sc.nextInt();
            int sum = a + b;
            result.append(String.valueOf(sum).length());
        }

        System.out.println(result.toString());
    }
}

Measured memory_bytes: 26480
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iostream>
#include<queue>
#include<cmath>

using namespace std;

typedef long long ll;

const int maxn = 1005;
const int maxl = 105;
const ll inf = 1ll<<55;
const double eps = 1e-8;

struct edge
{
	int to,val,mag;
	edge(int a,int b,int c):to(a),val(b),mag(c){}
};

struct node
{
	int to,mag;
	ll len;
	node(int a,int b,ll c):to(a),mag(b),len(c){}
	bool operator<(const node& a)const
	{
		return len > a.len;
	}
};

struct point
{
	double xi,lef,di;
	point(){}
	point(double a,double b,double c):xi(a),lef(b),di(c){}
};

vector<edge> v[maxn];
bool vis[maxn][maxl];
ll dis[maxn][maxl];

int n,s1,s2,tt,sp;
struct line
{
	point s[maxl];int top;
	void build()
	{
		top = 0;
		for(int i=sp;i>=0;i--)
		{
			if(dis[tt][i]==inf)
				continue;
			while(top&&i*s[top-1].lef+dis[tt][i]<=eps+s[top-1].xi*s[top-1].lef+s[top-1].di)
				top--;
			s[top] = point(i,top?(dis[tt][i]-s[top-1].di)/(s[top-1].xi-i):0,dis[tt][i]);
			top++;
		}
	}
}p1,p2;

int f1,f2;

double f(double x)
{
	return fabs(p1.s[f1].xi*x+p1.s[f1].di-p2.s[f2].xi*x-p2.s[f2].di);
}
double cal(double pl,double pr)
{
	if(abs((p2.s[f2].xi-p1.s[f1].xi))<=eps)
		return   fabs(p1.s[f1].di-p2.s[f2].di);
	pl = ceil(pl);pr = floor(pr);
	double jiao = (p1.s[f1].di-p2.s[f2].di)/(p2.s[f2].xi-p1.s[f1].xi);
	if(jiao>pr+eps)
		return f(pr);
	if(jiao<pl-eps)
		return f(pl);
	return min(f(ceil(jiao)),f(floor(jiao)));
}
double sol()
{
	double res = inf;
	vector<double> bl,v1,v2;
	for(int i=0;i<p1.top;i++)
	{
		v1.push_back(p1.s[i].lef);
		bl.push_back(p1.s[i].lef);
	}
	for(int i=0;i<p2.top;i++)
	{
		v2.push_back(p2.s[i].lef);
		bl.push_back(p2.s[i].lef);
	}
	sort(bl.begin(),bl.end());bl.push_back(1ll<<42);
	for(int i=2;i<bl.size();i++)
	{
		double va = bl[i];
		f1 = lower_bound(v1.begin(),v1.end(),va-eps)-v1.begin()-1;
		f2 = lower_bound(v2.begin(),v2.end(),va-eps)-v2.begin()-1;
		res = min(cal(bl[i-1],va),res);
	}
	return res;
}
void dij(int s)
{
	priority_queue<node> q;
	memset(vis,0,sizeof(vis));
	for(int i=1;i<=n;i++)
		fill(dis[i],dis[i]+sp+1,inf);
	dis[s][0] = 0;q.push(node(s,0,0));
	while(!q.empty())
	{
		node t = q.top();q.pop();
		if(vis[t.to][t.mag])
			continue;
		vis[t.to][t.mag] = 1;
		for(int i=0;i<v[t.to].size();i++)
		{
			int toit = v[t.to][i].to;
			if(dis[toit][t.mag+v[t.to][i].mag]>dis[t.to][t.mag]+v[t.to][i].val)
			{
				dis[toit][t.mag+v[t.to][i].mag]=dis[t.to][t.mag]+v[t.to][i].val;
				q.push(node(toit,t.mag+v[t.to][i].mag,dis[toit][t.mag+v[t.to][i].mag]));
			}
		}
	}
}
int main()
{
	int m,a,b;char s[20];
	while(scanf("%d%d%d%d%d",&n,&m,&s1,&s2,&tt)&&n)
	{
		sp = 0;
		for(int i=1;i<=n;i++)
			v[i].clear();
		for(int i=0;i<m;i++)
		{
			scanf("%d%d%s",&a,&b,s);
			if(s[0]=='x')
			{
				sp++;
				v[a].push_back(edge(b,0,1));
				v[b].push_back(edge(a,0,1));
			}
			else
			{
				int val = atoi(s);
				v[a].push_back(edge(b,val,0));
				v[b].push_back(edge(a,val,0));
			}
		}
		dij(s1);p1.build();
		dij(s2);p2.build();
		printf("%.0f\n",sol());
	}
}

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

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

Measured memory_bytes: 640
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define mod 1000000007
#define MAXH 401
#define MAXW 401
bool black[MAXH][MAXW];
bool dirty[MAXH][MAXW];
int dv[4][2] = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}};
ll blackcount = 0;
ll whitecount = 0;
void dfs(int i, int j, int h, int w) {
    if (dirty[i][j]) return;
    dirty[i][j] = true;
    if (black[i][j]) blackcount++;
    else whitecount++;
    for (int k = 0; k < 4; k++) {
        int nexti = i + dv[k][1], nextj = j + dv[k][0];
        if ((nexti >= 1) && (nexti <= h) && (nextj >= 1) && (nextj <= w)) {
            if (black[i][j] != black[nexti][nextj]) {
                dfs(nexti, nextj, h, w);
            } 
        }
    }
}


int main() { 
    int h, w;
    cin >> h >> w;
    for (int i = 1; i <= h; i++) {
        string s;
        cin >> s;
        for (int j = 1; j <= s.length(); j++) {
            if (s[j - 1] == '#') black[i][j] = true;
            else black[i][j] = false;
        }
    }
    memset(dirty, false, sizeof(dirty));
    ll ret = 0;
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            whitecount = 0;
            blackcount = 0;
            dfs(i, j , h , w);
            ret += whitecount * blackcount;
        }
    }
    cout << ret << endl;
    return 0;
}

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

using namespace std;
const int N = 1e5 + 3;
int n, m, a[N];
pair<int, int> p[N];
int main() {
#ifndef ONLINE_JUDGE
	//freopen("input.in", "r", stdin);
#endif
	scanf("%d %d", &n, &m);
	for (int i = 0; i < n; ++i)
		scanf("%d", a + i);
	sort(a, a + n);
	for (int i = 0; i < m; ++i)
		scanf("%d %d", &p[i].second, &p[i].first);
	sort(p, p + m);
	reverse(p, p + m);
	int j = 0;
	for (int i = 0; j < m && i < n; ++i) {
		if (a[i] < p[j].first)
			a[i] = p[j].first;
		else
			break;
		if (!--p[j].second) {
			++j;
		}
	}
	long long sum = 0;
	for (int i = 0; i < n; ++i)
		sum += a[i];
	printf("%lld\n", sum);
	return 0;
}

Measured memory_bytes: 1408
use proconio::input;
use std::cmp::{min, max};

fn main() {
  input! {
    n: i64, m: usize,
    gates: [(i64, i64); m],
  }
  
  let mut l_max = 1;
  let mut r_min = n;
  
  for &(l, r) in &gates {
    l_max = max(l_max, l);
    r_min = min(r_min, r);
  }
  
  let count = max(0, r_min - l_max + 1);
  
  println!("{}", count);
}

Measured memory_bytes: 4652