akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
const int mod = 10;
ll modpow(ll a, int b) { return b ? modpow(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& v) { rep(i, sz(v)) { if (i) os << " "; os << v[i]; } return os; }
template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
inline int add(int a, int b) { a += b; if (a >= mod) return a - mod; return a; }

void solve();

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

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
        solve();
    }
}


void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> a(3);
  rep(i, 3) cin >> a[i];
  string s;
  cin >> s;
  ll ans = 0;

  map<int, int> mp;
  mp['r'] = 0;
  mp['s'] = 1;
  mp['p'] = 2;

  vector<int> t(n, -1);
  rep(i, n) {
    int choice = (mp[s[i]] + 3 - 1) % 3;
    if (i < m || t[i - m] != choice) {
      t[i] = choice;
      ans += a[choice];
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 892
Scanf.scanf "%s" (fun s ->
    let n = String.length s in
    let rec loop i mi mx =
        if i = n then mx - mi + 1 else
            if s.[i] = 'Z' then loop (i + 1) mi i else
            if s.[i] = 'A' then loop (i + 1) (min mi i) mx else
                loop (i + 1) mi mx
    in
    loop 0 max_int 0 |> Printf.printf "%d\n"
)

Measured memory_bytes: 4556
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int N, K, x, ret; vector<int> g[100009];
int solve(int pos) {
	int mx = 0;
	for (int i : g[pos]) {
		int res = solve(i);
		if (res == K - 1) ret++;
		else mx = max(mx, res + 1);
	}
	return mx;
}
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		cin >> x; x--;
		if (i >= 1) {
			g[x].push_back(i);
		}
		else if (x != 0) ret++;
	}
	for (int i : g[0]) {
		solve(i);
	}
	cout << ret << "\n";
	return 0;
}

Measured memory_bytes: 8832
let words str =
  let len = String.length str in
  let buf = Buffer.create 128 in
  let rec aux i l =
    if i >= len then (int_of_string (Buffer.contents buf))::l
    else 
      match str.[i] with
      | ' ' ->
        let s = int_of_string (Buffer.contents buf) in
        Buffer.clear buf;
        aux (i+1) (s :: l)
      | c   ->
        Buffer.add_char buf c;
        aux (i+1) l
  in aux 0 []

let () =
  let r,c = Scanf.sscanf (read_line ()) "%d %d" (fun r c -> r,c) in
  let buf = Buffer.create 128 in
  let rec loop l sum = function
    | 0 ->
      let sl = List.fold_left (fun a b -> List.map2 (+) a b)
          (List.hd l) (List.tl l) in
      print_string (Buffer.contents buf);
      List.iter (fun x -> Printf.printf "%d " x) (List.rev sl);
      Printf.printf "%d\n" sum;
    | i ->
      let line = read_line () in
      let rl = words line in
      let s = List.fold_left (fun acc v -> acc + v) 0 rl in
      Buffer.add_string buf (Printf.sprintf "%s %d\n" line s);
      loop (rl::l) (sum+s) (i-1)
  in loop [] 0 r

Measured memory_bytes: 3144
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...) 0
#endif

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

    string s;
    cin >> s;
    int n = s.size();
    vector<int> x(n + 1), dp(n + 1, 1e9), tmp(1 << 26, 1e9);
    rep(i, 0, n) {
        x[i + 1] = x[i] ^ (1 << (s[i] - 'a'));
    }
    tmp[0] = 0;
    rep(i, 0, n) {
        dp[i + 1] = tmp[x[i + 1]] + 1;
        rep(j, 0, 26) {
            dp[i + 1] = min(dp[i + 1], tmp[x[i + 1] ^ (1 << j)] + 1);
        }
        tmp[x[i + 1]] = min(tmp[x[i + 1]], dp[i + 1]);
    }
    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 264340
#include<iostream>
#include<algorithm>
#include<cstring>
#define INF 11111111
using namespace std;

int main(){

  int a[100][100],ans,d,p;
  int n,m,t,u;

  while(cin >> n, n){
    
    for(int i=0;i<100;i++){
      for(int j=0;j<100;j++) a[i][j] = INF;
    }

    for(int i=0;i<n;i++){
      cin >> t >> u >> m;
      a[t][u] = a[u][t] = m;
    }

    for(int k=0;k<=10;k++){
      for(int i=0;i<=10;i++){
	for(int j=0;j<=10;j++) a[i][j] = min(a[i][j],a[i][k]+a[k][j]);
      }
    }

    ans = INF;

    for(int i=0;i<=10;i++){
      d = 0;

      for(int j=0;j<=10;j++){
	if(a[i][j] < INF && i != j) d += a[i][j];
      }

      if(ans > d && d){
	ans = d;
	p = i;
      }
    }

    cout << p << " " << ans << endl;
  }
}

Measured memory_bytes: 1196
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
    int n; cin>>n;
    string s; cin>>s;
    int q; cin>>q;
    vector<set<int>> pos(26);
    rep(i,s.size()) pos[s[i]-'a'].insert(i+1);
    rep(i,26) pos[i].insert(n+1);
    rep(i,q){
        int que; cin>>que;
        if(que==1){
            int ind; char ch;
            cin>>ind>>ch;
            pos[s[ind-1]-'a'].erase(ind);
            pos[ch-'a'].insert(ind);
            s[ind-1]=ch;
        }
        else{
            int cnt=0,l,r,x; cin>>l>>r;
            rep(j,26){
                x=*pos[j].lower_bound(l);
                if(x>=l && x<=r) cnt++;
            }
            cout<<cnt<<endl;
        }
    }
}

Measured memory_bytes: 24196
use proconio::marker::Usize1;
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        q: usize,
        ball: [Usize1; n],
        query: [(Usize1, Usize1); q],
    }
    let mut dup_index: Vec<Option<usize>> = vec![None; n];
    let mut ball_memo: Vec<Option<usize>> = vec![None; n];
    for (i, &b) in ball.iter().enumerate() {
        if let Some(di) = dup_index[b] {
            ball_memo[di] = Some(i);
        }
        dup_index[b] = Some(i);
    }

    let mut query_list = vec![Vec::with_capacity(q); n];
    for (i, (ql, qr)) in query.into_iter().enumerate() {
        query_list[ql].push((qr, i));
    }

    let mut res = vec![0; q];
    let mut bit = BIT::new(&vec![0; n]);
    for (ql, qvec) in query_list.into_iter().enumerate().rev() {
        if let Some(memo) = ball_memo[ql] {
            bit.add(memo, 1);
        }
        for (qr, i) in qvec {
            res[i] = (qr - ql + 1) - bit.sum(qr);
        }
    }
    for r in res {
        println!("{}", r);
    }
}

// BIT

use num_traits::{NumOps, Zero};
use std::marker::Copy;

pub struct BIT<T> {
    tree: Vec<T>,
}

impl<T> BIT<T>
where
    T: Copy + NumOps + Zero,
{
    pub fn new(data: &[T]) -> Self {
        let size = data.len();
        let mut bit = BIT {
            tree: vec![T::zero(); size],
        };
        for (i, &x) in data.iter().enumerate() {
            bit.add(i, x);
        }
        bit
    }

    pub fn size(&self) -> usize {
        self.tree.len()
    }

    pub fn add(&mut self, i: usize, x: T) {
        let size = self.size();
        let mut i = i;
        while i < size {
            self.tree[i] = self.tree[i] + x;
            i += (i + 1) & (!(i + 1)).wrapping_add(1);
        }
    }

    pub fn sum(&self, i: usize) -> T {
        let mut res = T::zero();
        let mut i = i as isize;
        while i >= 0 {
            res = res + self.tree[i as usize];
            i -= (i + 1) & -(i + 1);
        }
        res
    }
}


Measured memory_bytes: 64076
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define szz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
typedef tuple<int, int, int> t3;
typedef pair<ll, ll> pll;
typedef long double ldouble;
typedef pair<double, double> pdd;
typedef pair<pii, int> ppi;

int gc(int x, int y) { return y ? gc(y, x%y) : x; }

int n, m;
char X[100010], Y[100010];

int main(){
	scanf("%d%d", &n, &m);
	scanf("%s%s", X, Y);
	int g = gc(n, m);
	for(int i=0;i<g;i++) {
		int x = n / g * i, y = m / g * i;
		if(X[x] != Y[y]) {
			puts("-1");
			return 0;
		}
	}
	printf("%lld\n", (ll) n * m / g);
	return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;

const int MAX = 1000001;

int f(int N,int x){
    return ((x * 10) + 7) % N;
}

int main(){
    int N;
    bool check[MAX] = {false};

    cin >> N;

    int ans = 0;
    int x = 0;
    while(true){
        x = f(N,x);
        ans++;

        if(check[x] == true){
            ans = -1;
            break;
        }
        check[x] = true;

        if(x == 0){
            break;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4172
import numpy as np
n=int(input())
a = list(map(int, input().split()))
m = 1000
kabu = 0
for i in range(n-1):
  if a[i] < a[ i +1 ]:
    kabu =  kabu + int((m - (m % a[i])) / a[i])
    m = m % a[i]
  elif a[i] > a[ i +1 ]:
    m = m + (a[i] * kabu)
    kabu = 0
if kabu > 0:
  m = m + kabu * a[-1]
print(m)

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

using namespace std;

typedef long long ll;

struct seg
{
        int l;
        int r;
};

bool cmp(seg a, seg b)
{
        return a.r < b.r;
}

const int N = 100000 + 7;
int n;
seg a[N];
int dp[N];

int main()
{
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

        cin >> n;
        for (int i = 1; i <= n; i++)
        {
                int x, l;
                cin >> x >> l;
                a[i] = {x - l, x + l};
        }
        sort(a + 1, a + n + 1, cmp);
        for (int i = 1; i <= n; i++)
        {
                int l = 1, r = n, ans = 0;
                while (l <= r)
                {
                        int m = (l + r) / 2;
                        if (a[m].r <= a[i].l)
                        {
                                l = m + 1;
                                ans = m;
                        }
                        else
                                r = m - 1;
                }
                dp[i] = max(dp[i - 1], dp[ans] + 1);
        }
        cout << dp[n] << "\n";
}


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

int main() {
	string s;
	int K;
	cin >> s >> K;
	vector<vector<vector<int> > > dp(s.length(), vector<vector<int> >(s.length(), vector<int>(K + 1, 0)));
	for (int i = s.length() - 1; i >= 0; i--) {
		for (int k = 0; k <= K; k++) {
			dp[i][i][k] = 1;
		}
		for (int j = i + 1; j < s.length(); j++) {
			dp[i][j][0] = max(dp[i + 1][j][0], dp[i][j - 1][0]);
			dp[i][j][0] = max(dp[i][j][0], dp[i + 1][j - 1][0] + (s[i] == s[j]) * 2);
			for (int k = 1; k <= K; k++) {
				dp[i][j][k] = max(dp[i + 1][j][k], dp[i][j - 1][k]);
				dp[i][j][k] = max(dp[i][j][k], dp[i + 1][j - 1][k - 1] + 2);
				dp[i][j][k] = max(dp[i][j][k], dp[i + 1][j - 1][k] + (s[i] == s[j]) * 2);
			}
		}
	}
	cout << dp[0][s.length() - 1][K] << endl;
    return 0;
}

Measured memory_bytes: 109568
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep2(i, a, b) for(int i = (a); i < (b); i++)
typedef long long ll;

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

   if (b % a == 0) {
       cout << a + b << endl;
   } else {
       cout << b - a << endl;
   }
}

Measured memory_bytes: 256
#include<algorithm>
#include<cstring>
#include<stdio.h>
using namespace std;
int main(){
	int n;
	char a[100005];
	scanf("%s",a+1);
	n=strlen(a+1);
	if((a[1]==a[n]&&n%2==1)||(a[1]!=a[n]&&n%2!=1))printf("Second\n");
	else printf("First\n");
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

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

using vl = vector<ll>;

template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

#define INF 1001001001

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

    ll N, M, L;
    cin>>N>>M>>L;
    vector<vector<ll>> dp(N, vector<ll>(N, INF));
    rep(i, M) {
        ll e1, e2, c;
        cin>>e1>>e2>>c; e1--; e2--;
        dp[e1][e2] = c;
        dp[e2][e1] = c;
    }

    rep(k, N) rep(i, N) rep(j, N) {
        chmin(dp[i][j], dp[i][k] + dp[k][j]);
    }

    vector<vector<int>> dp2(N, vector<int>(N, INF));
    rep(i, N) rep(j, N) {
        if (dp[i][j] <= L) dp2[i][j] = 1;
    }
    rep(k, N) rep(i, N) rep(j, N) {
        chmin(dp2[i][j], dp2[i][k] + dp2[k][j]);
    }

    int Q;
    cin>>Q;
    rep(i, Q) {
        ll s, t;
        cin>>s>>t; s--; t--;
        
        if (dp2[s][t] == INF) cout<<-1<<endl;
        else cout<<dp2[s][t] - 1<<endl;
    }
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int s[n];
  int i;
  double sum=0;
  for(i=0;i<n;i++){
    cin >> s[i];
    sum+=(double)1/s[i];
  }
  cout << 1/sum;
}


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

//#pragma GCC optimize("O3")
//#pragma GCC target("sse4")

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ITER(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = (LL)INF * INF;

const int mod = 1000 * 1000 * 1000 + 7;
const int MAX = 1 << 11;

int add(int a, int b)
{
	return a + b < mod ? a + b : a + b - mod;
}

int a[MAX];

int main()
{
	//ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n, k;
	cin >> n >> k;
	FOR(i, 0, n)
		cin >> a[i];
	int ans = 0;
	FOR(i, 0, n)
		FOR(j, 0, n)
			if(a[i] > a[j])
			{
				ans = add(ans, (LL)k * (k - 1) / 2 % mod);
				if(i < j)
					ans = add(ans, k);
			}
	cout << ans;
	return 0;
}


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

const int mxN = 1e5;
int h[mxN],dp[mxN+1],n;

int main(){
    cin >> n ; 
    for(int i=0 ; i< n ; ++i) cin >> h[i];
    memset(dp,0x3f,sizeof((dp)));
    dp[0]=0;
    dp[1] = abs(h[1]-h[0]);
    /*
    for(int i=1 ; i<n ;++i){
        dp[i] = min(dp[i],
    }
    for(int i=0 ; i< n ; ++i)cout << dp[i] <<" ";
    cout <<"\n";*/
    for(int i=2 ; i<n ;++i){
        dp[i] = min(dp[i-1]+ abs(h[i]-h[i-1]),dp[i-2]+ abs(h[i]-h[i-2]));
    }
 /*   for(int i=0 ; i< n ; ++i)cout << dp[i] <<" ";
    cout <<"\n";*/
    cout << dp[n-1];
}

Measured memory_bytes: 4272
#include <iostream>
#include <vector>
#include <limits>
#include <boost/range/irange.hpp>
#include <boost/range/adaptors.hpp>

using namespace std;
using namespace boost;
using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long int;

int main() {
    constexpr uint a_max = 100010;
    array<uint, a_max> as; // -1, 0, ... , 100000
    as.fill(0);
    uint N;
    cin >> N;
    for (auto &&i: irange(0U, N)){
        uint a;
        cin >> a;
        as.at(a)++;
        as.at(a+1)++;
        as.at(a+2)++;
    }
    cout << *max_element(as.begin(), as.end());


    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <limits>
#include <sstream>
#include <fstream>
#include <climits>
#include <map>
#include <numeric>
#include <functional>
#include <utility>

using namespace std;

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

int main(void) {
  string s;
  cin >> s;
  int n = s.size();
  string s1, s2;
  rep(i, n) {
    s1.push_back((i % 2) + '0');
    s2.push_back((i + 1) % 2 + '0');
  }
  int d1 = 0, d2 = 0;
  rep(i, n) {
    d1 += abs(s[i] - s1[i]);
    d2 += abs(s[i] - s2[i]);
  }
  cout << min(d1, d2) << endl;
  return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;
ll MOD=1000000007;

int main() {
  ll n;
  cin>>n;
  vector<ll> a(n);
  rep(i,n) cin>>a[i];
  ll length=0;
  rep(i,n) length+=a[i];
  ll min=INF;
  ll temporarylength=0;
  rep(i,n){
temporarylength+=a[i];
    if(abs(length-2*temporarylength)<min) min=abs(length-2*temporarylength);
  }
  cout<<min<<endl;
return 0;
}


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

int main() {
  unsigned long int N=0;
  unsigned long int D=0;
  cin >> N >> D;
  
  vector<unsigned long int> X(N);
  vector<unsigned long int> Y(N);
  int count=0;
  
  for (int i=0; i<N; i++) {
    cin >> X.at(i) >> Y.at(i);
  }
  
  for (int i=0; i<N; i++) {
    if ( X.at(i)*X.at(i) + Y.at(i)*Y.at(i) <= D*D) {
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 6424
#include<cstdio>
#include<iostream>
#include<list>
#include<cstring>
#include<stack>
#include<string>
#include<vector>
#include<set>
#include<algorithm>
using namespace std;
const int maxn = 100100;
vector<int>pre, inor, post, nodes;
int  lson[30], rson[30], fat[30];

void preorder(int s)
{
	pre.push_back(s);
	if (lson[s] != -1)
		preorder(lson[s]);
	if (rson[s] != -1)
		preorder(rson[s]);
}

void inorder(int s)
{
	if (lson[s] != -1)
		inorder(lson[s]);
	inor.push_back(s);
	if (rson[s] != -1)
		inorder(rson[s]);
}
void postorder(int s)
{
	if (lson[s] != -1)
		postorder(lson[s]);
	if (rson[s] != -1)
		postorder(rson[s]);
	post.push_back(s);
}
int main()
{
	int n;
	nodes.clear();
	scanf("%d", &n);
	int a, b, c;
	memset(fat, -1, sizeof fat);
	memset(lson, -1, sizeof lson);
	
	memset(rson, -1, sizeof lson);
	for (int i = 1; i <= n; i++)
	{
		scanf("%d%d%d", &a, &b, &c);
		lson[a] = b;
		rson[a] = c;
		fat[b] = a;
		fat[c] = a;
		nodes.push_back(a);
	}
	int root = -1;
	sort(nodes.begin(), nodes.end());
	for (auto it=nodes.begin(); it!=nodes.end(); it++)
	{
		if (fat[*it] == -1)
		{
			root = *it;
			break;
		}

	}
	preorder(root);
	inorder(root);
	postorder(root);
	printf("Preorder\n");
	for (int i = 0; i < n; i++)
		printf(" %d", pre[i]);
	printf("\n");
	printf("Inorder\n");
	for (int i = 0; i < n; i++)
		printf(" %d", inor[i]);
	printf("\n");
	printf("Postorder\n");
	for (int i = 0; i < n; i++)
		printf(" %d", post[i]);

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


Measured memory_bytes: 3268
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (int i = 0; i < n; i++)
#define IREP(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(a, b) for (int i = a; i < b + 1; i++)
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
	int n=4;
	cin >> n;
	vector<ll> a(2*n);
	REP(i,n+1){
		cin >> a[i];
	}
	ll ans=0;
	REP(i,n){
		ll b;
		cin >> b;
		if(b>=a[i]){
			if(b>=a[i]+a[i+1]){
				ans+=a[i]+a[i+1];
				a[i]=0;
				a[i+1]=0;
			}
			else{
				ans+=b;
				b=b-a[i];
				a[i]=0;
				a[i+1]=a[i+1]-b;
			}
		}
		else{
			ans+=b;
			a[i]=a[i]-b;
		}
	}
	cout <<ans <<endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<math.h>

using namespace std;

int main() {
	long long int N;
	cin >> N;
	int h = sqrt(N) + 1;
	long long int a = 0;
	long long int min = 1000000000001;
	for (int i = 1;i < h;i++) {
		if (N % i == 0) {
			a = N / i;
			if (min > a + i - 2) {
				min = a + i - 2;
			}
		}
	}
	cout << min << endl;
	return 0;
}

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

int main(int argc, char *argv[]){
  int n;
  cin >> n;
  if(n == 0){
    std::cout << 1 << std::endl;
  }else if(n == 1){
    std::cout << 2 << std::endl;
  }else if(n == 2){
    std::cout << 1 << std::endl;
  }else{
    std::cout << 0 << std::endl;
  }
  return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <map>
#include <utility>
using namespace std;
typedef long long ll;
map<pair<ll,ll>,ll> mp;
int ans[200010] = {0};
int par[2][200010],ran[2][200010];
void init(int j,int n){
	for(int i=0;i<n;i++){
		par[j][i] = i;
		ran[j][i] = i;
	}
}
 
int find(int i, int x){
	if(par[i][x]==x){
		return x;
	}else{
		return par[i][x] = find(i,par[i][x]);
	}
}
 
void unite(int i,int x, int y){
	x = find(i,x);
	y = find(i,y);
	if(x==y) return;
	if(ran[i][x]<ran[i][y]){
		par[i][x] = y;
	}else{
		par[i][y] = x;
		if(ran[i][x]==ran[i][y]) ran[i][x]++;
	}
}
 
bool same(int i,int x, int y){
	return find(i,x)==find(i,y);
}

int main(){
    int i,j,n,k,l;
    cin >> n >> k >> l;
	init(0,n); init(1,n);
    for(i=0;i<k;i++){
        int p,q;
        cin >> p >> q;
        unite(0,p,q);
    }
    for(i=0;i<l;i++){
        int p,q;
        cin >> p >> q;
        unite(1,p,q);
    }
	for(i=1;i<=n;i++){
		mp[{find(0,i),find(1,i)}]++;
	}
    for(i=1;i<=n;i++){
        cout << mp[{find(0,i),find(1,i)}] << " ";
    }
	cout << endl;
}

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

using namespace std;

typedef long long ll;

template<class t>
inline bool chmax(t &a, t b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class t>
inline bool chmin(t &a, t b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

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

    int max_h = 0;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (h[i] >= max_h) {
            ans++;
            max_h = h[i];
        }
    }

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


Measured memory_bytes: 384
#include<stdio.h>


int gcd(int,int);

main()
{
 
  int x,y;
  scanf("%d%d",&x,&y);
  printf("%d\n",gcd(x,y));

  return 0;

}

int gcd(int x,int y){

  int r,k; 

  if(x < y ){
    k = y;
    y = x;
    x = k;
  }
  while(y > 0){
    r = x % y;
    x = y;
    y = r;
  }
  return x;
}

Measured memory_bytes: 592
N = gets.to_i
A = gets.chomp.split(" ").map(&:to_i)
B = gets.chomp.split(" ").map(&:to_i)
C = gets.chomp.split(" ").map(&:to_i)

ans = 0
bef = -1
A.each{|a|
  ans += B[a - 1]
  ans += C[a - 2] if a - bef == 1
  bef = a
}

puts ans


Measured memory_bytes: 3836
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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

int main() {
    int a, s = 0, m = 0;
    REP(i, 3){
        cin >> a;
        s += a;
        m = max(m, a);

    }
    cout << (s - m) << endl;

    return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <vector>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int a,b,c;
  cin>>a>>b>>c;
  c/=a;
  c*=b;
  cout<<c<<"\n";
  return 0;
}

Measured memory_bytes: 3612
#include "bits/stdc++.h"
#define int long long
#define mii map<int,int>
#define inf 1000000007 //10^9+7
#define sort(vec) sort(vec.begin(),vec.end());
#define rever(vec) reverse(vec.begin(),vec.end());
#define unsort(vec) sort(vec); rever(vec);
#define gcd __gcd
using namespace std;

signed main() {
  int n;
  cin>>n;
  int ans=0;
  vector<int>vec(n);
  for(int i=0;i<n;i++) cin>>vec.at(i);
  sort(vec);
  for(int i=0;i<n-1;i++) {
    if(vec.at(i)==vec.at(i+1)) {
      vec.at(i)=0;
      vec.at(i+1)=0;
      i++;
    }
  }
  for(int i=0;i<n;i++) {
    if(vec.at(i)) {
      ans++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <boost/range/irange.hpp>
#include <limits>

using namespace std;
using namespace boost;
using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long int;

int main() {
    vector<vector<uint>> cs(3, vector<uint>(3, 0));
    for (auto &&i: irange((unsigned int) 0, (uint) 3)) {
        for (auto &&j: irange((unsigned int) 0, (uint) 3)) {
            cin >> cs.at(i).at(j);
        }
    }
    vector<uint> as(3, numeric_limits<uint>::max());
    vector<uint> bs(3, numeric_limits<uint>::max());
    as.at(0) = 0;
    bs.at(0) = cs.at(0).at(0);
    bs.at(1) = cs.at(0).at(1);
    bs.at(2) = cs.at(0).at(2);
    as.at(1) = cs.at(1).at(0) - bs.at(0);
    as.at(2) = cs.at(2).at(0) - bs.at(0);
    bool b{true};
    if (cs.at(1).at(1) != as.at(1) + bs.at(1)){
        b = false;
    }
    if (cs.at(1).at(2) != as.at(1) + bs.at(2)){
        b = false;
    }
    if (cs.at(2).at(1) != as.at(2) + bs.at(1)){
        b = false;
    }
    if (cs.at(2).at(2) != as.at(2) + bs.at(2)){
        b = false;
    }
    if (b){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
const int inf = 1000000001;
const ll INF = 1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<<fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
static const int N = 300;

int n,R;
vector< vector< pair<int, int> > > adj(N, vector< pair<int, int> >());
vll hyou(8, vl(8, 0));
vl d(N, INF);
vi r(8);

void dijkstra(int i) {
	priority_queue< pair<int, int>, vector< pair<int, int> >, greater< pair<int, int> > > pq;
	vi color(n + 1, WHITE);

	d[r[i]-1] = 0;
	pq.push(make_pair(0, r[i]-1));
	color[r[i]-1] = GRAY;

	while (!pq.empty()) {
		pair<int, int> f = pq.top();
		pq.pop();
		int u = f.second;
		color[u] = BLACK;
		if (d[u] < f.first) {
			continue;
		}
		for (int j = 0; j < adj[u].size(); j++) {
			int v = adj[u][j].second;
			if (color[v] == BLACK) {
				continue;
			}
			if (d[v] > d[u] + adj[u][j].first) {
				d[v] = d[u] + adj[u][j].first;
				pq.push(make_pair(d[v], v));
				color[v] = GRAY;
			}
		}
	}
	for (int j = 0; j < R; j++) {
		hyou[i][j] = d[r[j]-1];
	}

}


int main() {
	srand((unsigned)time(NULL));
	int m, i, j;
	cin >> n >> m >> R;
	for (i = 0; i < R; i++) {
		cin >> r[i];
	}
	int a, b, c;
	for (i = 0; i < m; i++) {
		cin >> a >> b >> c;
		adj[a-1].push_back(make_pair(c, b-1));
		adj[b-1].push_back(make_pair(c, a-1));
	}
	for (i = 0; i < R; i++) {
		for (j = 0; j < d.size(); j++) {
			d[j] = INF;
		}
		dijkstra(i);
	}
	ll mini = INF;
	vi jun(R);
	for (i = 0; i < R; i++) {
		jun[i] = i;
	}
	do {
		ll sum = 0;
		for (i = 1; i < R; i++) {
			sum += hyou[jun[i - 1]][jun[i]];
		}
		mini = min(sum, mini);
	} while (next_permutation(jun.begin(), jun.end()));
	cout << mini << endl;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,n) for(int i = 0;i < (int)(n);i++)
#define RREP(i,n) for(int i = (int)n-1;i >= 0;i--)
#define FOR(i,s,n) for(int i = s;i < (int)n;i++)
#define RFOR(i,s,n) for(int i = (int)n-1;i >= s;i--)
#define ALL(a) a.begin(),a.end()
//#define IN(a, x, b) (a<=x && x<b)
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a = b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a = b;return true;}return false;}
template<class T>istream&operator >>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<class T>inline void IN(T&t){cin>>t;}
template<class T,class... Ts>inline void IN(T&t,Ts&...ts){cin>>t;IN(ts...);}
template<class T>inline void OUT(T t){cout<<t<<"\n";}
template<class T,class... Ts>inline void OUT(T&t,Ts&... ts){cout<<t<<" ";OUT(ts...);}
template<typename T=int>vector<T>mv(size_t a){return vector<T>(a);}
template<typename T=int,typename... Ts>auto mv(size_t a,Ts... ts){return vector<decltype(mv<T>(ts...))>(a,mv<T>(ts...));}
template<typename T,typename V>typename enable_if<is_class<T>::value==0>::type FILL(T&t,const V&v){t=v;}
template<typename T,typename V>typename enable_if<is_class<T>::value!=0>::type FILL(T&t,const V&v){for(auto &e:t)FILL(e,v);}
constexpr long long INF = 1e18;

signed main(){
	int n,q;
	IN(n,q);
	auto a = mv(n);
	IN(a);
	sort(ALL(a));
	vector<int>ans;
	REP(i,q){
		int l,r;
		cin>>l>>r;
		auto lo = lower_bound(ALL(a),l)-a.begin();
		auto up = upper_bound(ALL(a),r)-a.begin();
		ans.push_back(up-lo);
	}
	for(auto &e:ans)cout << e << endl;
}


Measured memory_bytes: 4712
// Shift-JIS（シフトジス）

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int N, M;
    cin >> N >> M;

    long long A[N] = {};
    vector<pair<int, long long>> CB(M);

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

    sort(A, A + N);

    int B;
    long long C;
    for (int i = 0; i < M; i++)
    {
        cin >> B >> C;
        CB[i] = make_pair(C, B);
    }

    sort(CB.begin(), CB.end(), greater<pair<long long, int>>());

    long long sum = 0;

    int k = 0;
    C = CB[k].first;
    B = CB[k].second;

    for (int i = 0; i < N; i++)
    {
        if (C >= A[i])
        {
            sum += C;
            B--;
            if (B == 0)
            {
                k++;
                C = CB[k].first;
                B = CB[k].second;
            }
        }
        else
        {
            sum += A[i];
        }
    }

    cout << sum << endl;
}

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

//const double PI=3.141592653589793238;
int main(void)
{
    int a,sum=0,dig;

    cin >> a;

    while(a){
    dig = a % 10;
    sum = sum + dig;
    a = a / 10;
  }


    cout << sum << endl;

    return 0;
}

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

int main(void){
  int a, b, c, num = 0;

  cin >> a >> b >> c;

  for( ; a <= b; a++){
    if ( c % a == 0 ){
      num++;
    }
  }
  cout << num << endl;
  
  return 0;
}

Measured memory_bytes: 3108
#include <iostream>

using namespace std;

int main()
{
    string s[101];
    int h,w,i;
    cin>>h>>w;

    for(i=0; i<h; i++)
    {
        cin>>s[i];
    }
    for(i=0; i<w+2; i++)
    {
        cout<<"#";
    }cout<<endl;

    for(i=0; i<h; i++)
    {
        cout<<"#"<<s[i]<<"#"<<'\n';
    }
    for(i=0; i<w+2; i++)
    {
        cout<<"#";
    }cout<<endl;

    return 0;
}


Measured memory_bytes: 3616
import math
a, b, x = map(int, input().split())

if 0 <= 2*x/a/a - b <= b:
    b_ =  2*x/a/a - b
    ans = 90 - math.degrees(math.atan2(a, b - b_) )
elif 0 <= 2*x/a/b <= a:
    a_ = 2*x/a/b
    ans = 90 - math.degrees(math.atan2(a_, b ) )

print(ans)

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastReader s = new FastReader();
		
		int x =s.nextInt();
		int n = s.nextInt();
		
		Set<Integer> set = new HashSet<>();
		
		for(int i=0;i<n;++i)
			{
				set.add(s.nextInt());
			}
		
		int i = 0;
		
		while(true)
		{
			if(!set.contains(x-i))
			{
				System.out.println(x-i);
				break;
			}
			if(!set.contains(x+i))
				{
					System.out.println(x+i);
					break;
				}
			++i;
			
		}
		
	}
	
	static class FastReader {
        BufferedReader br;
        StringTokenizer st;
 
        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }
 
        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                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());
        }
 
        double nextDouble()
        {
            return Double.parseDouble(next());
        }
 
        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
	}

}


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

// flagを用いたバブルソート
int bubbleSort(int A[], int N) {
  int sw_cnt = 0;
  bool flag = 1; // 1:未完了 | 0:完了
  // iを増やしながら、flagの値によるwhileをforで再現
  for (int i = 0; flag; i++) {
    // 何もなければ完了とする
    flag = 0;
    //iが下から迫り、jが上から迫るので、徐々に探索範囲は狭まる
    for (int j = N - 1; j >= i + 1; j--) {
      if (A[j] < A[j - 1]) {
        swap(A[j], A[j - 1]);
        // 交換がある限りは未完了にする
        flag = 1;
        sw_cnt++;
      }
    }
  }
  return sw_cnt;
}

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

  sw_cnt = bubbleSort(A, N);

  for (int i = 0; i < N; i++) {
    //  最初(i=0)以外は自分の前にスペースを置く
    if (i) cout << " ";
    cout << A[i];
  }

  cout << endl;
  cout << sw_cnt << endl;

  return 0;
}



Measured memory_bytes: 3100
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cctype>
using namespace std;

typedef long long ll;

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

#define MAX_H (10+10)
#define MAX_W (20+10)

int h,w;
char t[MAX_H][MAX_W];
set<string> tmp;

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

void solve(){
  tmp.clear();
  string res = "";
  
  /*
  rep(i,h) rep(j,w){
    string s = "";
    s += t[i][j];
    cout << "res=" << res << endl;
    if(tmp.find(s) != tmp.end()){
      if(s.size() > res.size()) res = s;
      else if(s.size() == res.size() && s < res) res = s;
    }
    else{
      tmp.insert(s);
    }
  }
  */
  
  rep(i,h) rep(j,w) rep(k,8){
    int sx = j, sy = i;
    int x = j, y = i;
    string s = "";
    s += t[y][x];
    x += w+dx[k]; x %= w;
    y += h+dy[k]; y %= h;

    while(!(x == sx && y == sy)){
      s += t[y][x];
      x += w+dx[k]; x %= w;
      y += h+dy[k]; y %= h;

//      cout << "sx=" << sx << ",sy=" << sy << endl;
//      cout << "x=" << x << ",y=" << y << endl;
//      cout << "s=" << s << endl;

      
      if(tmp.find(s) != tmp.end()){
        if(s.size() > res.size()) res = s;
        else if(s.size() == res.size() && s < res) res = s;
      }
      else{
        tmp.insert(s);
      }
    }
  }

  if(res.size() == 0) cout << 0 << endl;
  else cout << res << endl;
}

void solve2(string s){
  
}

int main(){
  while(true){
    cin >> h >> w;
    if(h == 0 && w == 0) break;
    rep(i,h) cin >> t[i];
    /*
    if(h == 1){
      s = t[0];
      solve2(s);
    }
    else if(w == 1){
      rep(i,h) s += t[0][i];
      solve2(s);
    }
    */
    solve();
  }
}

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

int main(void){
    std::string o,e;
    std::cin >> o >> e;

    for(int i = 0; i < o.size(); i++){
        std::cout << o[i];
        if(i < e.size()) std::cout << e[i];
    }

    return 0;
}




Measured memory_bytes: 256
// https://atcoder.jp/contests/abc132/tasks/abc132_a

#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); i++)
#define FORR(i, m, n) for (int(i) = (n); (i) >= (m); i--)
#define rep(...) _overload3(__VA_ARGS__, FOR, REP, )(__VA_ARGS__)
#define repr(...) _overload3(__VA_ARGS__, FORR, REPR, )(__VA_ARGS__)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

int main()
{
  string S;
  bool result = true;
  cin >> S;
  for (auto &c : S)
  {
    if (count(ALL(S), c) != 2)
      result = false;
  }

  cout << (result ? "Yes" : "No") << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define per(i,r,l) for(int i=r;i>=l;i--)
const int MX=4e5+7;
const int mod=9901;
using namespace std;
int p[MX],k[MX];
ll qpow(ll a,ll b,ll MOD=mod){for(ll ans=1;;a=a*a%MOD,b>>=1){if(b&1)ans=ans*a%MOD;if(!b)return ans;}}
ll inv(ll a,ll MOD=mod){return qpow(a,MOD-2,MOD);}
ll __gcm(ll a,ll b){return a*b/__gcd(a,b);}
map<string,int>mp;
int a[MX];
ll __C(ll n,ll m)
{
    if(n<m)return 0;

    if(m==1)return 9*n;
    else {
        return 9*9*n*(n-1)/2;
    }
}
int __get(int n,int m,int k)
{
    //if(m==0)m=1;
    if(k==0)return m;
    return m*__C(n,k);
}
int main()
{
  ios::sync_with_stdio(0),cin.tie(0);
  string s;
  int k;
  cin>>s>>k;
  int g=k;
  ll sum=0;
  ll res=0;
  int n=s.length();
  if(res==k)sum++;
  for(int i=0;i<n-1;i++)
   {
       sum+=__get(i,9,k-1);
     //cout<<sum<<endl;
   }
   //cout<<sum<<endl;
  // cout<<sum<<endl;
  for(int i=0;i<n;i++)
  {
      if(k){
       // if(i>0)s[i]++;
       if(s[i]-'0'>0)
        sum+=__get(n-i-1,s[i]-'0'-1,k-1);
       // cout<<sum<<endl;
        if(i>0&&s[i]-'0'>0)
        {
            sum+=__get(n-i-1,1,k);
          //  cout<<"i="<<i<<" "<<sum<<endl;
         // cout<<n-i-1<<" "<<s[i]-'0'-1<<" "<<k-1<<endl;
        }
       // cout<<sum<<endl;
       if(s[i]-'0'>0)k--;
      }
  }
  //cout<<sum<<endl;
  int ant=0;
  for(int i=0;i<n;i++)
  {
      if(s[i]-'0'>0)ant++;
  }
  //cout<<ant<<" "<<k<<endl;
  if(ant>=g)sum++;
  cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
	char tem;
	int i,j;
	cin>>s;
	if(s=="zyxwvutsrqponmlkjihgfedcba")
	{
		cout<<-1<<endl;
		return 0;
	}
	if(s.size()!=26)
		for(i=0;i<26;i++)
			if(s.find(i+'a')==-1)
			{
				tem=i+'a';
				cout<<s<<tem<<endl;
				return 0;
			}
	for(i=25;i>=0;i--)
	{
		tem=s[i];
		for(j=tem-'a'+1;j<26;j++)
			if(s.find(j+'a')==-1)
			{
				tem=j+'a';
				s=s.substr(0,s.size()-1);
				cout<<s<<tem<<endl;
				return 0;
			}
		s=s.substr(0,s.size()-1);
	}
	return 0;
} 


Measured memory_bytes: 256
import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

    private static int N;
    private static ArrayList<Integer>[] g;
    private static int[] match;
    private static boolean[] vis;

    private static int MCBM(int u) {
        if (vis[u]) return 0;
        vis[u] = true;
        for (int v : g[u])
            if (match[v] == -1 || MCBM(match[v]) == 1) {
                match[v] = u;
                return 1;
            }
        return 0;
    }

    public static void main(String[] args) throws IOException {
        MyScanner sc = new MyScanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        N = sc.nextInt();
        int[] rx = new int[N];
        int[] ry = new int[N];
        for (int i = 0; i < N; i++) {
            rx[i] = sc.nextInt();
            ry[i] = sc.nextInt();
        }
        int[] bx = new int[N];
        int[] by = new int[N];
        for (int i = 0; i < N; i++) {
            bx[i] = sc.nextInt();
            by[i] = sc.nextInt();
        }
        g = new ArrayList[N + N];
        for (int i = 0; i < N + N; i++) g[i] = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            int x = rx[i], y = ry[i];
            for (int j = 0; j < N; j++)
                if (x < bx[j] && y < by[j]) {
                    g[i].add(N + j);
                    g[N + j].add(i);
                }
        }
        match = new int[N + N];
        Arrays.fill(match, -1);
        int ans = 0;
        for (int node = 0; node < N; node++) {
            vis = new boolean[N + N];
            ans += MCBM(node);
        }
        out.println(ans);
        out.flush();
        out.close();
    }

    private static class MyScanner {
        StringTokenizer st;
        BufferedReader br;

        public MyScanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public MyScanner(String filename) throws IOException {
            br = new BufferedReader(new FileReader(new File(filename)));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public boolean ready() throws IOException {
            return br.ready();
        }
    }
}


Measured memory_bytes: 21588
#include<cstdio>
#include<algorithm>
using namespace std;
int D[5010], n, Mod, C[5010];
void Make(int t) {
	int i;
	for (i = 0; i <= n - t; i++) {
		D[i+t] = (D[i+t] + D[i]) % Mod;
	}
}
int main() {
	int i;
	scanf("%d%d", &n, &Mod);
	D[0] = 1;
	for (i = 2; i <= n; i++) {
		Make(min(i - 1, n + 2 - i));
	}
	int res = 0;
	for (i = 0; i < n; i++) {
		res = (res + 1ll * (n - i)*D[i]) % Mod;
	}
	printf("%d\n", res);
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n, k, x, y;
        n = sc.nextInt();
        k = sc.nextInt();
        x = sc.nextInt();
        y = sc.nextInt();
        int ans = x * Math.min(k, n);
        if (n > k) ans += y * (n - k);
        System.out.println(ans);
    }
}

Measured memory_bytes: 21716
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int r = sc.nextInt();
        int g = sc.nextInt();
        int b = sc.nextInt();
        
        if(((r * 100) + (g * 10) + b) % 4 == 0){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    }
}

Measured memory_bytes: 21076
#include <stdio.h>

int countDay(int year, int month, int day)
{
    int i;
    int table[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    int res;
    
    res = (year - 1) * 365 + (year - 1) / 4 - (year - 1) / 100 + (year - 1) / 400;
    
    if ((month > 2 || month == 2 && day >= 29) && year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)){
        res++;
    }
    for (i = 1; i < month; i++){
        res += table[i];
    }
    
    res += day;
    
    return (res);
}

int main(void)
{
    int i;
    int a[6];
    int fl;
    
    while (1){
        fl = 0;
        for (i = 0; i < 6; i++){
            scanf("%d", &a[i]);
            
            if (a[i] < 0){
                fl |= 1;
            }
        }
        
        if (fl == 1){
            break;
        }
        
        printf("%d\n", countDay(a[3], a[4], a[5]) - countDay(a[0], a[1], a[2]));
    }
    
    return (0);
}

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

int main(void){
  int n,mi=1000,i;
  int s=0,m;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&m);
    s+=m;
    if(m%10!=0){
    mi = min(mi,m);
    }
  }

  if(s%10==0){
    if(mi!=1000)
      printf("%d\n",s-mi);
    else
      printf("0\n");
  }
  else
    printf("%d\n",s);

  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main(void){
    int N, A[21], B[21], C[21], i, s;
    scanf("%d", &N);
    s=0;
    for (i=1; i<=N; i++) scanf("%d", &A[i]);
    for (i=1; i<=N; i++) {
        scanf("%d", &B[i]);
        s+=B[i];
    }
    for (i=1; i<=N-1; i++) scanf("%d", &C[i]);
    for (i=1; i<=N-1; i++) {
        if (A[i]+1==A[i+1]) s+=C[A[i]];
    }
    printf("%d", s);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
using namespace std;
typedef long long ll;
int main()
{
	ll n,d,m;
	cin>>n>>m>>d;
	ll k;
	if(d!=0)
		k=2LL*(n-d)*(m-1LL);
	else
		k=n*(m-1LL);
	double ans=(double)k/(double)n/(double)n;
	cout<<setprecision(12)<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#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() {
    int K, A, B; cin >> K >> A >> B;
    bool ok = false;
    for(int i = A; i <= B; i++) {
        if(i % K == 0) ok = true;
    }
    if(ok) cout << "OK" << endl;
    else cout << "NG" << endl;
    return 0;
}

Measured memory_bytes: 3636
a,b,c,d=map(int,input().split())
def lcm(a,b):
    ori_a=a
    ori_b=b
    while b!=0:
        a,b=b,a%b
    return (ori_a*ori_b)//a

def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a


b_div=b//lcm(c,d)
bc=b//c
bd=b//d
a=a-1
a_div=a//lcm(c,d)

ac=a//c
ad=a//d
print((b-bc-bd+b_div)-(a-ac-ad+a_div))

Measured memory_bytes: 9148