akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <boost/optional.hpp>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

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

using namespace std;

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

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

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

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

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

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

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

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

const int I_MAX = 26;

int calc_point(const int& D, const VI& c, const VI2D& s, const VI& t) {
	int point = 0;
	VI last(I_MAX + 1, 0);
	REP(i, D) {
		point += s[i][t[i]];
		last[t[i]] = i + 1;
		int down = 0;
		REP(j, I_MAX) { down += c[j] * ((i + 1) - last[j]); }
		point -= down;
	}

	return point;
}

int main() {
	int D;
	cin >> D;
	VI c(I_MAX);
	REP(i, I_MAX) { cin >> c[i]; }
	VI2D s(D, VI(I_MAX));
	REP(i, D) {
		REP(j, I_MAX) { cin >> s[i][j]; }
	}

	std::random_device seed_gen;
	std::mt19937 engine(seed_gen());

	VI t(D);
	REP(i, D) { t[i] = engine() % I_MAX; }

	std::chrono::system_clock::time_point start, end;
	start = std::chrono::system_clock::now();

	int prev = calc_point(D, c, s, t);
	while(true) {
		end = std::chrono::system_clock::now();
		double elapsed =
			std::chrono::duration_cast<std::chrono::milliseconds>(end - start)
				.count();
		if(elapsed > 1980.0) {
			break;
		}
		int d, q;
		d = engine() % D;
		q = engine() % I_MAX;

		int old = t[d];
		t[d] = q;
		int now = calc_point(D, c, s, t);
		if(prev > now) {
			t[d] = old;
		} else {
			prev = now;
		}
	}

	REP(i, D) { cout << t[i] + 1 << endl; }

	return 0;
}

Measured memory_bytes: 3644
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
    public static void main(String args[]) throws Exception{
        BufferedReader stdR = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(stdR.readLine());
        String[] str = stdR.readLine().split(" ");
        int[] A = new int[N];
        for(int i = 0 ; i < N ; i++) {
            A[i] = Integer.parseInt(str[i]);
        }
        int minuscount = 0;
        for(int i = 0 ; i < N ; i++) {
            if(A[i] < 0)minuscount++;
            A[i] = Math.abs(A[i]);
        }
        Arrays.sort(A);
        long l = 0;
        if(minuscount % 2 == 1) {
            l -= A[0];
            for(int i = 1 ; i < N ; i++) {
                l += (long)Math.abs(A[i]);
            }
        }else {
            for(int i = 0 ; i < N ; i++) {
                l += (long)Math.abs(A[i]);
            }
        }
        System.out.println(l);
    }
}


Measured memory_bytes: 45396
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


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

    vint ls = {1};
    int num = 6;
    while(num <= n) {
        ls.push_back(num);
        num *= 6;
    }
    num = 9;
    while(num <= n) {
        ls.push_back(num);
        num *= 9;
    }
    sort(all(ls));
    vint dp(n+1, INF);
    dp[0] = 0;
    srep(i, 1, n+1) {
        for (int x : ls) {
            if (i-x < 0) break;
            dp[i] = min(dp[i], dp[i-x]+1);
        }
    }

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

Measured memory_bytes: 640
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let N = read!(usize);
    let mut red = read![u32, u32; N];
    let mut blue = read![u32, u32; N];

    red.sort();
    blue.sort();

    let mut br = N;
    let mut live = vec![true; N];
    let mut count = 0;

    for ri in (0..N).rev() {
        let (rx, ry) = red[ri];

        while br >= 1 && blue[br - 1].0 > rx {
            br -= 1;
        }

        let mut min_yx = (std::u32::MAX, std::u32::MAX);
        let mut min_bi = N;

        for bi in br..N {
            let (bx, by) = blue[bi];
            if live[bi] && ry < by && min_yx > (by, bx) {
                min_yx = (by, bx);
                min_bi = bi;
            }
        }

        if min_bi != N {
            let bi = min_bi;

            count += 1_usize;
            live[min_bi] = false;

            debug!((ri, bi, red[ri], blue[bi]));
        }
    }

    println!("{}", count)
}


Measured memory_bytes: 4352
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<functional>
#include<math.h>

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

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

	vector<ll> a(n);
	if (s >= 1e+9) {
		rep(i, k) a[i] = s;
		for (ll i = k; i < n; i++) {
			a[i] = 1;
		}
	}
	else {
		rep(i, k) a[i] = s;
		for (ll i = k; i < n; i++) {
			a[i] = s + 1;
		}
	}

	rep(i, n) cout << a[i] << endl;

	return 0;
}


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

#define ll long long int

ll val[100005];
ll wt[100005];

ll Knapsack(ll n,ll w)
{
    ll K[n+1][w+1];

    int i,j;
    

    for(i=0;i<=n;i++)
    {
        for(j=0;j<=w;j++)
        {
            if(i==0 || j==0) K[i][j]=0;
            else if(wt[i-1]<=j)
            {
                K[i][j]=max(K[i-1][j-(wt[i-1])]+val[i-1],K[i-1][j]);
            }
            else
            {
                K[i][j]=K[i-1][j];
            }
        }
    }

    return K[n][w];
    
}


int main()
{
    ll n,w,i;
    cin >> n >> w;
    // ll val[n],wt[n];

    for(i=0;i<n;i++)
    {
        cin >> wt[i] >> val[i];
    }

    cout << Knapsack(n,w) << '\n';

    

}

Measured memory_bytes: 79104
#include <iostream>
using namespace std;
int main() {
    int N, X, ans = 1, sum = 0;
    cin >> N >> X;
    for (int i = 0, L; i < N; i++) {
        cin >> L;
        sum += L;
        if (sum <= X) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
readlines.each{|line|
  arr = line.chomp.split("").map(&:to_i)
  while arr.size > 1
    (arr.size-1).times{|i|
      arr[i] = (arr[i] + arr[i+1]) % 10
    }
    arr.pop
  end
  p arr[0]
}

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

typedef long long ll;
const int MAXN=1e5+5;
const ll INF=1e18;

int n,p1,p2;
ll ans,ex=INF;
int siz[MAXN],mx[MAXN];
vector<pair<int,int> > E[MAXN];

void dfs1(int u,int fa=0){
    siz[u]=1;
    for(int i=0;i<(int)E[u].size();i++){
        int v=E[u][i].first;
        if(v==fa) continue;
        dfs1(v,u);
        siz[u]+=siz[v];
        mx[u]=max(mx[u],siz[v]);
    }
    mx[u]=max(mx[u],n-siz[u]);
    if(mx[u]<=n/2){
        if(!p1) p1=u;
        else p2=u;
    }
}

void dfs2(int u,int fa=0,ll sum=0){
    ans+=2*sum;
    for(int i=0;i<(int)E[u].size();i++){
        int v=E[u][i].first,val=E[u][i].second;
        if(v==fa) continue;
        dfs2(v,u,sum+val);
        if(v==p2||(!p2&&u==p1)) ex=min(ex,1ll*val);
    }
}

int main(){
    scanf("%d",&n);
    for(int i=1;i<n;i++){
        int u,v,val;
        scanf("%d%d%d",&u,&v,&val);
        E[u].push_back(make_pair(v,val));
        E[v].push_back(make_pair(u,val));
    }
    dfs1(1);
    dfs2(p1);
    printf("%lld",ans-ex);
}


Measured memory_bytes: 13184
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;
int v[100010][3];
signed main()
{
    int n,k;
    int r, s, p;
    string t;
    cin >> n >> k >> r >> s >> p >> t;
    int cnt = 0;
    for (int i = 0; i < n; i++)
    {
        if(t[i]=='p'){
            cnt += s;
            if(i-k>=0 && t[i]==t[i-k]){
                cnt -= s;
                t[i] = 'a';
                continue;
            }
        }
        if(t[i]=='r'){
            cnt += p;
            if (i - k >= 0 && t[i] == t[i - k])
            {
                cnt -= p;
                t[i] = 'a';
                continue;
            }
        }
        if(t[i]=='s'){
            cnt += r;
            if (i - k >= 0 && t[i] == t[i - k])
            {
                cnt -= r;
                t[i] = 'a';
                continue;
            }
        }
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define foreach(i,n) for(auto &&i:n)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define GSORT(x) sort(all(x), greater<int>())
#define REV(x) reverse(all(x))
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define LOWitr(x, n) lower_bound(all(x), n)
#define UPRitr(x, n) upper_bound(all(x), n)
#define cii(x) int x;cin >> x
#define cill(x) LL x;cin >> x
#define cis(x) string x;cin >> x
#define co(x) cout << x << endl
#define dump(x)  cout << #x << " = " << (x) << endl
#define truecheck assert
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef long long int64;
template<class T,class U>bool chmax(T &a, const U &b) { if (a<b) { a=b; return true; } return false; }
template<class T,class U>bool chmin(T &a, const U &b) { if (b<a) { a=b; return true; } return false; }
const int INF = 1e9, MOD = 1e9 + 7;
const LL LLINF = 1e16;

int main() {
    fastcin();
    cout << fixed << setprecision(10);
    cill(n);
    cill(m);
    auto ans = (n * m + 1) / 2;
    if (n == 1 || m == 1){
        ans = 1;
    }
    co(ans);
    return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    // Rust version 1.15.1, which is used by AtCoder,
    // does not support std::str::FromStr for char
    ($iter:expr, char) => {
        $iter.next().unwrap().chars().next().expect("Parse error")
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
fn main() {
    use std::cmp::max;
    use std::cmp::min;
    use std::collections::HashMap;

    input!{
        n: usize,
    }
    println!("{}", n*800 - (n/15)*200);
}


Measured memory_bytes: 4352
s=input()
if s[len(s)-1]=='2':
  print("hon")
if s[len(s)-1]=='4':
  print("hon")
if s[len(s)-1]=='5':
  print("hon")
if s[len(s)-1]=='7':
  print("hon")
if s[len(s)-1]=='9':
  print("hon")
if s[len(s)-1]=='0':
  print("pon")
if s[len(s)-1]=='1':
  print("pon")
if s[len(s)-1]=='6':
  print("pon")
if s[len(s)-1]=='8':
  print("pon")
if s[len(s)-1]=='3':
  print("bon")




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

struct combination {
    ll mod;
    vector<ll> fac, finv, inv;

    combination(int n, ll m) : fac(n), finv(n), inv(n) {
        mod = m;
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < n; i++) {
            fac[i] = fac[i - 1] * i % mod;
            inv[i] = mod - inv[mod % i] * (mod / i) % mod;
            finv[i] = finv[i - 1] * inv[i] % mod;
        }
    }

    ll C(int n, int k) {
        if (n < k) return 0;
        if (n < 0 || k < 0) return 0;
        return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
    }
    ll f(int x, int y) { return C(x + y, x); }
};

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

    ll mod = 1e9 + 7;
    combination com(300000, mod);
    int h, w, n;
    cin >> h >> w >> n;
    vector<pair<int, int>> xy(n);
    rep(i, 0, n) cin >> xy[i].first >> xy[i].second;
    xy.emplace_back(h, w);
    sort(xy.begin(), xy.end());
    vector<ll> dp(n + 1, mod);
    rep(i, 0, n + 1) {
        dp[i] = com.f(xy[i].first - 1, xy[i].second - 1);
        rep(j, 0, i) {
            if (xy[i].first >= xy[j].first && xy[i].second >= xy[j].second) {
                dp[i] -= dp[j] *
                         com.f(xy[i].first - xy[j].first,
                               xy[i].second - xy[j].second) %
                         mod;
            }
        }
        while (dp[i] < 0) dp[i] += mod;
    }
    cout << (dp[n] + mod) % mod << endl;
    return 0;
}


Measured memory_bytes: 7424
#include <stdio.h>

#include <stdlib.h>

#include <string.h>





int main (void)


{


char num_str[1002];


int num;


long sum=0;


int i;


char tmp;


while(1)


{


fgets(num_str,sizeof(num_str),stdin);


if (num_str[0]=='0')break;


for (i=0;i<strlen(num_str)-1;i++)


{


tmp=num_str[i];


num=atoi(&tmp);


sum=sum+num;


}


printf("%d\n",sum);


sum=0;


memset(num_str,1002,0);


}


return 0;


}

Measured memory_bytes: 528
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

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

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

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }


int main() {
    int n, w;
    cin >> n >> w;
    auto dp = make_v(n+1, w+1, 0LL);
    vector<pair<int, int>> v(n);
    for (int i = 0; i < n; ++i) {
        int a, b;
        scanf("%d %d", &a, &b);
        v[i] = make_pair(a, b);
    }
    for (int i = 0; i < n; ++i) {
        int a, b;
        tie(a, b) = v[i];
        for (int j = 0; j <= w; ++j) {
            if(j >= a) dp[i+1][j] = max(dp[i+1][j], dp[i][j-a] + b);
            dp[i+1][j] = max(dp[i][j], dp[i+1][j]);
        }
    }
    ll ans = 0;
    for (int i = 0; i <= w; ++i) {
        ans = max(ans, dp[n][i]);
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 80256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INTINF = 1<<29;
const ll LLINF = 1LL<<61;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int DX[8]={ 0, 1, 0,-1, 1, 1,-1,-1};
const int DY[8]={ 1, 0,-1, 0, 1,-1, 1,-1};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c;
  cin >> a >> b >> c;
  if (b-a==c-b)cout << "YES" << endl;
  else cout << "NO" << endl;
  
}

Measured memory_bytes: 256
#encoding:utf-8 No.0093 2014.10.3
years = []
while true
  range = gets.chomp.split.map{|item|
    item = item.to_i
  }
  if range == [0,0]
    break
  end
  years.push range
end

answer =[]

years.length.times do |i|
  leap_year = []
  for n in years[i][0]..years[i][1]
    if (n%4 == 0 && n%100 != 0) || n%400 == 0
      leap_year.push n      
    end
  end
  if leap_year.length == 0
    leap_year.push "NA"
  end
  answer.push leap_year
end

answer.length.times do |i|
  puts answer[i]
  unless i == answer.length - 1
    puts
  end
end

Measured memory_bytes: 6132
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

//Shuffle
public class Main{

	class Scanner {
		int nextInt() {
			try {
				int c = System.in.read();
				while (c != '-' && (c < '0' || '9' < c))
					c = System.in.read();
				if (c == '-') return -nextInt();
				int res = 0;
				do {
					res *= 10;
					res += c - '0';
					c = System.in.read();
				} while ('0' <= c && c <= '9');
				return res;
			} catch (Exception e) {
				return -1;
			}
		}
	}

	void run(){
		Scanner sc = new Scanner();
		long mask = (1L << 32)-1;
		Comparator<Long> C = new Comparator<Long>() {
			public int compare(Long o1, Long o2) {
				return (int) ((o1>>32)-(o2>>32));
			}
		};
		int[] p = new int[5000], q = new int[5000];
		for(;;){
			int n = sc.nextInt();
			if(n==0)break;
//			            long T = System.currentTimeMillis();
			int m = sc.nextInt(), P = sc.nextInt(), Q = sc.nextInt(), R = sc.nextInt();
			List<Long> l = new ArrayList<Long>();
			l.add(((long)P<<32)|Q);
			for(int i=0;i<m;i++){
				p[i] = sc.nextInt(); q[i] = sc.nextInt();
			}
			for(int i=m-1;i>=0;i--){
				long t1 = n-q[i], s2 = t1+1, t2 = n-p[i], s3 = n-p[i]+1, y = q[i];
				List<Long> next = new ArrayList<Long>();
				for(int j=0;j<l.size();j++){
					long x = l.get(j);
					long s = x>>32, t = x&mask;
					if(t<=t1){
						next.add((s+y)<<32 | (t+y));
					}
					else if(t<=t2){
						if(s<=t1){
							next.add((s+y)<<32 | (t1+y));
							s = s2;
						}
						next.add((s-s2+p[i]+1)<<32 | (t-s2+p[i]+1));
					}
					else{
						if(s<=t1){
							next.add((s+y)<<32 | (t1+y));
							s = s2;
						}
						if(s<=t2){
							next.add((s-s2+p[i]+1)<<32 | (t2-s2+p[i]+1));
							s = s3;
						}
						next.add((s-s3+1)<<32 | (t-s3+1));
					}
				}
				if(i==0||1100<=next.size()){
					l = new ArrayList<Long>();
					Collections.sort(next, C);
					long ss = next.get(0)>>32, tt = next.get(0)&mask;
					for(int j=1;j<next.size();j++){
						long x = next.get(j);
						long s = x>>32, t = x&mask;
						if(tt+1==s)tt = t;
						else{
							l.add((ss<<32)|tt);
							ss = s; tt = t;
						}
					}
					l.add((ss<<32)|tt);
				}
				else{
					l = next;
				}
			}
			int res = 0;
			for(long x:l){
				long s = x>>32, t = x&mask;
				if(R<s)break;
				if(R<t)t = R;
				res+=t-s+1;
			}
			System.out.println(res);
//			            System.out.println((System.currentTimeMillis()-T)+" ms.");
		}
	}

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

Measured memory_bytes: 10000
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        int[] line = Console.ReadLine().Split().Select(int.Parse).ToArray();

        // N/2 番目に難しい問題が「ARC 用の問題」
        int ARC = N / 2;

        // N/2 − 1 番目に難しい問題が「ABC 用の問題」
        int ABC = N / 2 - 1;

        // 問題を難易度順に昇順でソートする。
        Array.Sort(line);

        // N / 2 番目の要素から、N / 2 − 1 番目の要素を引いたものを出力する。
        Console.WriteLine(line[ARC] - line[ABC]);
    }
}


Measured memory_bytes: 20064
#include <stdio.h>
#include <stdlib.h>
 
int main(void){
  
  int N;
  scanf("%d",&N);
  
  int M;
  scanf("%d",&M);
  
  int i;
  int A[N];
  int count = 0;
  
  for(i = 0; i < N;i++){
    
   	scanf("%d",&A[i]);
 
  }
  
  int S = 0;
  
  for(i = 0; i < N;i++){
    
    S += A[i];
    
  }
  
  for(i = 0;i < N;i++){
    
    if(A[i] >= S*1./(4*M)){
      
      count ++;
    }
    
  }
 
  if(count >= M){
      printf("Yes");
    }else{printf("No");}
  
  
  return 0;
  
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include<iostream>
#include<string>
#include<map>
using namespace std;
int x, y, num;

long long N, M,Y[100000],P[100000],a,b,c,d;
string s;
bool yymm, mmyy;
map<long long, long long>m;
int main(){
	cin >> N;
	a = N / 1000;
	b = (N / 100)-(10*a);
	c = N / 10 - (100 * a + 10 * b);
	d = N % 10;
	mmyy = true;
	yymm = true;
	if (a * 10 + b > 12||a*10+b==0) {
		mmyy = false;
	}
	if (c * 10 + d > 12|| c * 10 + d == 0) {
		yymm = false;
	}
	if (mmyy) {
		if (yymm) {
			cout << "AMBIGUOUS" << endl;
		}
		else {
			cout << "MMYY" << endl;
		}
	}
	else {
		if (yymm) {
			cout << "YYMM" << endl;
		}
		else {
			cout << "NA" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int N,A,B; cin>>N>>A>>B;
  if(A+B<=N+1&&(N+A-1)/A<=B&&(N+B-1)/B<=A){
    int memo;
    REP(i,0,N){
      int X=i+(N-i+A-1)/A;
      if(X==B){
        memo=i;
        break;
      }
    }
    vi ans;
    REP(i,1,memo) ans.pb(i);
    vii C(N);
    for(int i=N;memo<i;i--){
      int X=(N-i)/A;
      C[X].pb(i);
    }
    rep(i,0,N){
      sort(ALL(C[i]));
      rep(j,0,C[i].size()) cout<<C[i][j]<<" ";
    }
    reverse(ALL(ans));
    rep(i,0,memo) cout<<ans[i]<<" ";
    cout<<endl;
  }
  else cout<<-1<<endl;
  }



Measured memory_bytes: 12784
using System;

namespace moff2 {
    class MainClass {
        public static void Main(string[] args) {


            // logic
            var yen = int.Parse(Console.ReadLine());
            var cPrice = int.Parse(Console.ReadLine());
            var dPrice = int.Parse(Console.ReadLine());

            yen -= cPrice;
            var red = yen % dPrice;

            Console.WriteLine(red);
        }
    }
}


Measured memory_bytes: 11092
#include<iostream>
#include<iomanip>
#include<string>
#include<array>
#include<cmath>
#include<vector>
#include<utility>
#include<algorithm>
#include<ctype.h>
using namespace std;


int main() {
	int n, m, x, a[110], p1=0,p2=0;
	cin >> n >> m >> x;
	for (int i = 1; i <= m;i++) {
		cin >> a[i];
		if (a[i]<x) {
			p1 ++ ;
		}
		else {
			p2++;
		}
	}
	cout << min(p1, p2) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
//typedef __int128_t Int;
#define DBG 1
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define loop(n) rep(loop,(0),(n))
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <typename T> class DisjointSet {
public:
  vector<T> rank, p;
  DisjointSet() {}
  DisjointSet(int size) {
    rank.resize(size, 0);
    p.resize(size, 0);
    rep(i, 0, size) makeSet(i);
  }
  void makeSet(int x) {
    p[x] = x;
    rank[x] = 0;
  }
  bool same(int x, int y) { return findSet(x) == findSet(y); }
  bool unite(int x, int y) {
    if (same(x, y))
      return false;
    link(findSet(x), findSet(y));
    return true;
  }
  void link(int x, int y) {
    if (rank[x] > rank[y]) {
      p[y] = x;
    } else {
      p[x] = y;
      if (rank[x] == rank[y]) {
        rank[y]++;
      }
    }
  }
  int findSet(int x) {
    if (x != p[x]) {
      p[x] = findSet(p[x]); // path compression
    }
    return p[x];
  }
};

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

  int N, M; cin >> N >> M;
  vector<int> p(N); rep(i, 0, N){ cin >> p[i];p[i]--; }
  vector<int> x(M), y(M); rep(i, 0, M){ cin >> x[i] >> y[i];x[i]--,y[i]--; }
  DisjointSet<int>uf(N);
  rep(i,0,M){
    uf.unite(x[i],y[i]);
  }
  int ans=0;
  rep(i,0,N){
    ans+=uf.same(i,p[i]);
  }
  cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 2176
#include <stdio.h>

int main(int argc, const char * argv[]) {

    
    int price=800;
    int bonus;
    int count;
    int N;
    scanf("%d",&N);
    price = price * N;
    count = N/15;
    
    printf("%d\n",price-count*200);
    return 0;
}

Measured memory_bytes: 128
#include<vector>
#include<bitset>
#include<iostream>
using namespace std;
#define df 0
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long int li;
// print_item
template<typename T>
void print_item(T x) {cout << x;}
// pair 型の print (map 含む)
template<typename F,typename S>
void print_item(pair<F,S> x);
// vector 型
// template<typename T>
// void print(vector<T>& vec,string str="");
void print(auto& vec,string str){
  if(str!="") cout << str << ":\n";
  for(auto x: vec) {print_item(x); cout << "\n ";}
  cout << endl;
}

void bset(bitset<32>& bs,int k){
  int i=0;
  while(k){
    if(k%2) bs.set(i);
    k/=2;
    i++;
  }
}
li calc(auto bs,auto& vec){
  li a=0;
  for(auto x:vec){
    if((bs | x.first) == bs) a+=x.second;
  }
  return a;
}

int main(){
  if(df) printf("*debug mode*\n");
  int n,k;bitset<32> bs; cin >>n >>k;
  bset(bs,k);
  if(df)print_item(bs);
  vector<pair<bitset<32>,li>> vec;
  rep(i,n){
    int a,b; cin >>a >>b;
    bitset<32> bs; bset(bs,a);
    vec.push_back({bs,b});
  }
  if(df)print(vec,"vec");


  li ans=0,i=0;
  while(1){
    li c=calc(bs,vec);
    if(ans<c) ans=c;
    while(bs[i])i++;
    while(i<31 and bs[i]==0) bs.set(i++);
    if(i==31)break;
    bs[i]=0;
    if(df){
      printf("get %ld next:",c);
      print_item(bs);
      printf("\n");
    }
  }
  cout << ans;
}


// pair 型の print (map 含む)
template<typename F,typename S>
void print_item(pair<F,S> x) {
  printf("(");
  print_item(x.first);
  printf(",");
  print_item(x.second);
  printf(")");
}

/*
// vector 型
template<typename T>
void print(vector<T>& vec,string str){
  if(str!="") cout << str << ":\n";
  for(T x: vec) {print_item(x); cout << "\n ";}
  cout << endl;
}
*/
/// confirm df==0 ///


Measured memory_bytes: 2420
#include<iostream>
#include<string>
#include<complex>
#include<vector>
#include<algorithm>
#include<functional>
#include<array>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 1e+9


int main() {
	int n,a;
	cin >> n;
	int min = INF, max = 0;
	for (int i = 0;i < n;i++) {
		cin >> a;
		if (a > max) max = a;
		if (a < min) min = a;
	}
	cout << max - min << endl;


	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<iomanip>
using namespace std;
int main(){
    int a,b,mem=0;
    cin >> a >> b;
    for(int i=0;i<b*15;i++){
        int x=i*0.08;
        int y=i*0.1;
        if(x==a && y==b){
            cout << i << endl;
            mem = 10;
            break;
        }
    }
    if(mem==0){
        cout << "-1" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//75=75*1
//75=25*3
//75=5*5*3
//75=5*15

int main(void){
    int n;
    int ca[4]={0,0,0,0};
    int primes[100],x;
    int count[5]={0,0,0,0,0};
    int answer=0;
    int total=0;
    cin >> n;
    x=n;
    for(int i=0;i<100;i++){
        primes[i]=0;
    }
    for(int k=2;k<=n;k++){
        x=k;
        for(int i=2;i<=x;i++){
            while(x%i==0){
                x/=i;
                primes[i]++;
                total++;
            }
        }
    }
//    for(int i=0;i<100;i++){
//        for(int j=0;j<primes[i];j++){
//            cout << i << " ";
//        }
//        if(primes[i]) cout << endl;
//    }
    for(int i=0;i<100;i++){
        if(primes[i]>=74){ 
            count[0]++;
        }
        if(primes[i]>=24){
            count[1]++;
        }
        if(primes[i]>=14){
            count[2]++;
        }
        if(primes[i]>=4){
            count[3]++;
        }
        if(primes[i]>=2){
            count[4]++;
        }
    }
    ca[0]=count[0];
    if(count[1]>=1 && count[4]>=2){
        ca[1]=count[1]*(count[4]-1);
    }else{
        ca[1]=0;
    }
    if(count[3]>=2 && count[4]>=3){
        ca[2]=((count[3])*(count[3]-1)/2)*(count[4]-2);
    }else{
        ca[2]=0;
    }
    if(count[2]>=1 && count[3]>=2){
        ca[3]=count[2]*(count[3]-1);
    }else{
        ca[3]=0;
    }
    //cout << ca[0]<<" "<<ca[1]<<" "<<ca[2]<<" "<<ca[3] << endl;
    cout << ca[0]+ca[1]+ca[2]+ca[3]<< endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <cmath>

#define INF 100000000
#define MOD 1000000007
using namespace std;


int main(){
    long long Q,H,S,D,N;
    cin>>Q>>H>>S>>D>>N;
    
    N*=4;
    
    long long ans=0;
    
    ans+=(N/8)*min(Q*8,min(H*4,min(S*2,D)));
    N%=8;
    
    ans+=(N/4)*min(Q*4,min(H*2,S));
    N%=4;
    
    ans+=(N/2)*min(Q*2,H);
    N%=2;
    
    ans+=N*Q;
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s; cin >> s;
    long long K; cin >> K;
    string res = "1";
    for (int i = 0; i < s.size(); i++)
    {
        if(s[i] != '1' && i <= K-1) {
            res = s[i];
            break;
        }
    }

    cout << res << endl;
    return 0;
}

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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    int s;
    vector<int> v;
    cin >> s;

    int idx = 1;
    while (1)
    {
        bool f = false;
        for (auto it = v.begin(); it != v.end(); it++)
        {
            if (*it == s)
            {
                f = true;
                break;
            }
        }
        if (f)
        {
            break;
        }
        else
        {
            v.push_back(s);
            if (s % 2 == 0)
            {

                s /= 2;
            }
            else
            {
                s = s * 3 + 1;
            }
        }
        idx++;
    }
    cout << idx << endl;
}


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

int main(){

    int tim[5], i, j, k, ans = 0;

    for (i=0; i<5; i++){
        scanf("%d", &tim[i]);
    }

  int max, sequence[5], max_sequence;
  int *chk = (int*)calloc(6, sizeof(int));
 
  for (i=0; i<5; i++){
    max = 0;
    for (j=0; j<5; j++){
      if ((( tim[j]%10 >= max) || tim[j]%10==0) && (chk[j] == 0)){
        max = tim[j]%10;
        if (tim[j]%10==0) max = 10000;
        max_sequence = j;
      }
    }
    sequence[i] = max_sequence;
    chk[max_sequence] = 1;
   } 


    for (i=0; i<5; i++){
        //printf("%d\n", tim[sequence[i]]);
    }

    for (i=0; i<5; i++){
        ans += tim[sequence[i]];
        if ((tim[sequence[i]]%10!=0) && i != 4){
            ans += (10-tim[sequence[i]]%10);
        }
    }

   
    printf("%d", ans);

    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
const ll mod=1000000007;

int main() {
  string s; cin >>s;
  int len = s.size();
  int cnt_p_i = len/2;
  int cnt_p =0;
  for(int i=0;i<len;++i){
    auto sub = s.substr(i,1);
    if(sub=="p") ++cnt_p;
  }
  cout << cnt_p_i - cnt_p << endl;

  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

const int maxn = 100;

int main() {

	int n, h, w;
	int c[maxn*maxn];
	pair<int, int> p;
	cin >> h >> w >> n;
	int ans[maxn][maxn];

	rep(i, n) {
		cin >> c[i];
	}

	p.first = 0, p.second = 0;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < c[i]; j++) {
			ans[p.first][p.second] = i + 1;
			if (p.first % 2 == 0) {
				if (p.second == w - 1) {
					p.first++;
				}
				else {
					p.second++;
				}
			}
			else {
				if (p.second == 0) {
					p.first++;
				}
				else {
					p.second--;
				}
			}
		}
	}

	rep(i, h) {
		rep(j, w) {
			cout << ans[i][j];
			if (j != w - 1)cout << ' ';
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;


int main(void)
{
	double v, t, y, n;

	while(cin >> v ) {
		t = v/9.8;
		y = 4.9*t*t;

		for( n=0; 5*n-5<y; n++ );

		cout << n << endl;
	}
	return 0;
}

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

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

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define dep(i, a, n) for(int i = a; i >= (n); i--)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll
#define INF 100000000

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
	ll a, b, n, s, f, ans = 0;
  cin >> a >> b >> n;
  rep(i, n) {
    cin >> s >> f;
    if(f <= a || b <= s) continue;
    ans = 1;
  }
  cout << ans << endl;
	return 0;
}


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

int main() {
    int N, X;
    cin >> N >> X;
    int m[110000];
    int sum  = 0;
    int min = 1100;
    for(int i = 0; i < N; i++) {
        cin >> m[i];
        sum += m[i];
        if(min > m[i]) {
            min = m[i];
        }
    }
    cout << N + (X-sum)/min << endl;
}

Measured memory_bytes: 3576
#include<stdio.h>
#include<stdlib.h>
#define N 10000
#define NIL NULL
struct node{
  struct node *left;
  struct node *right;
  struct node *parent;
  int key;
};

typedef struct node * Node;
Node root;

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  
  while(x != NIL){
    y = x;
    if(z->key < x->key)
      x = x->left;
    else{
      x = x->right;
    }
  }
  z->parent = y; 
    if(y==NIL){
      root=z;
    }
    else if(z->key < y -> key){
      y->left = z;
    }
    else{
      y->right =z;
    }
}
void inorder(Node u){
  if(u != NIL){
    inorder(u->left);
    printf(" ");
    printf("%d",u->key);
    inorder(u->right);
  }
 
}
void preorder(Node u){ 
    if (u != NIL) {
      printf(" ");
      printf("%d",u->key); 
      preorder(u->left);
      preorder(u->right);
    
    }
}

int main(){
  int i,j,n,m;
  char str[10];
  scanf("%d",&m);
  for(i=0;i<m;i++){
    scanf("%s",str);
    if(str[0]=='i'){  
      scanf("%d",&n);
      insert(n);
    }
    else{
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}

Measured memory_bytes: 24040
#include <bits/stdc++.h>
#define int long long
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define ff first
#define ss second
#define frr(i,n) for(int i=0;i<n;i++)
#define td(v) v.begin(),v.end()
#define MAXN 100100
typedef long long ll;
using namespace std;
typedef pair<int,int> pii;
typedef pair<pii,int> piii;
inline ll mod(ll n, ll m){ll ret = n%m; if(ret < 0) ret += m; return ret;}
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
ll exp(ll a,ll b,ll m){
    if(b==0) return 1;
    if(b==1) return mod(a,m);
    ll k = mod(exp(a,b/2,m),m);
    if(b&1){
        return mod(a*mod(k*k,m),m);
    }    else return mod(k*k,m);
}

int dp[MAXN];
int pai[MAXN];
vector<int> adj[MAXN];
int M ;
int solve(int v,int p=-1){
	if(dp[v]!=-1)return dp[v];
	
	if(adj[v].size()==1 && p!=-1)return dp[v] = 2;
	
	int op1 = 1;
	int op2 = 1;
	for(int i=0;i<adj[v].size();i++){
		int to = adj[v][i];
		if(to==p)continue;
		pai[to] = v; 
		op2 = (op2*solve(to,v))%M;
	}
	return dp[v] = (op1 + op2)%M;
}

int ans[MAXN];
int phi;
int passou[MAXN];
int pre[MAXN],suf[MAXN];

void dfs(int v,int p=-1){
	if(v==1){
		ans[v] = mod(dp[v] - 1,M);
			pre[0] = 1;
		suf[adj[v].size()] = 1;
		for(int i=0;i<adj[v].size();i++){
			int to = adj[v][i];
			if(to==p)continue;
			pre[i+1] = (pre[i]*dp[to])%M;  	
		}
		for(int i=(int)adj[v].size() - 1;i>=0;i--){
			int to = adj[v][i];
			if(to==p)continue;
			suf[i] = (suf[i+1]*dp[to])%M;
		}
		
		for(int i=0;i<adj[v].size();i++){
			int to = adj[v][i];
			if(to==p)continue;
			passou[to] = (pre[i]*suf[i+1])%M;
		}
	}else{
		int r = mod(passou[v]+1,M);
		
		ans[v] = r;
		pre[0] = 1;
		suf[adj[v].size()] = 1;
		for(int i=0;i<adj[v].size();i++){
			int to = adj[v][i];
			pre[i+1] = pre[i]; 
			if(to==p)continue;
			ans[v] = mod(ans[v]*dp[to],M);
			pre[i+1] = (pre[i]*dp[to])%M;  	
		}
		for(int i=(int)adj[v].size() - 1;i>=0;i--){
			int to = adj[v][i];
			suf[i] = suf[i+1];
			if(to==p)continue;
			suf[i] = (suf[i+1]*dp[to])%M;
		}
		
		for(int i=0;i<adj[v].size();i++){
			int to = adj[v][i];
			if(to==p)continue;
			passou[to] = (pre[i]*suf[i+1])%M;
			passou[to] = (passou[to]*r)%M; 	
		}
		
	}
	for(int i=0;i<(int)adj[v].size();i++){
		int to = adj[v][i];
		if(to==p)continue;
		dfs(to,v);
	}
}


int32_t main(){
	fastio;
	int n;
	cin>>n>>M;
	memset(dp,-1,sizeof(dp));
	
	for(int i=0;i<n-1;i++){
		int a,b;
		cin>>a>>b;
		adj[a].pb(b);
		adj[b].pb(a);
	}
	
	solve(1);
	
	dfs(1);
	
	for(int i=1;i<=n;i++)cout<<mod(ans[i],M)<<endl;
	
	// Math -> gcd it all
	//did you check N=1? Did you mix up N,M?
}

Measured memory_bytes: 14464
#include <stdio.h>

int main (){
	char input[5][5];
	for (int a=0;a<2;a++){
		for (int b=0;b<4;b++){
			scanf ("%c",&input[b][a]);
		}
	}	
	if(input[0][0]==input[2][1]&&input[1][0]==input[1][1]&&input[2][0]==input[0][1]){
		printf ("YES\n");
	}else printf ("NO\n");	
}

Measured memory_bytes: 128
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;

public static class P
{
    public static void Main()
    {
        var nab = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var n = nab[0];
        var a = nab[1];
        var b = nab[2];
        int[] chunks = Enumerable.Repeat(1, b).ToArray();
        var remain = n - b;
        if (remain < 0)
        {
            Console.WriteLine(-1);
            return;
        }
        for (int i = 0; i < chunks.Length; i++)
        {
            var adder = Min(a - chunks[i], remain);
            chunks[i] += adder;
            remain -= adder;
        }
        if (remain != 0 || chunks.Max() != a)
        {
            Console.WriteLine(-1);
            return;
        }
        int curMax = n;
        List<int> res = new List<int>();
        foreach (var chunk in chunks)
        {
            var start = curMax - chunk + 1;
            res.AddRange(Enumerable.Range(start, chunk));
            curMax = start - 1;
        }

        Console.WriteLine(string.Join(" ", res));
    }
}


Measured memory_bytes: 35284
<?php


$n = fgets(STDIN);
$line = fgets(STDIN);

$array = [];
$array = explode(' ', $line);

$cnt = 0;
foreach($array as $key => $value) {
	if (($key + 1) % 2 !== 0 && $value % 2 !== 0) $cnt++;
}

echo $cnt;

Measured memory_bytes: 15972
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <math.h>
#include <cmath>
using namespace std;

int main() {
    int N; cin >> N;
    vector<long double>A(N);
    long double ans = 0;
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
        ans += 1.0000 / A.at(i);
    }
    
    cout << 1.0000 / ans << endl;
}

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

int main() {
  std::string st;
  int s = 0;
  int r = 0;
  std::cin >> st;
  for (char c : st) {
    if (c == 'S') {
      ++s;
    } else {
      if (s > 0) {
        --s;
        ++r;
      }
    }
  }
  std::cout << st.size() - 2 * r << std::endl;
  return 0;
}


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

int main() {
  string S;
  int K;
  int64_t Q=998244353;
  cin>>S>>K;
  K=min(310,K);
  vector<int> p;
  int a=0,P=0,V=S.size();
  for(int i=0;i<V;i++){
    if(S.at(i)=='1'){
      a++;
      P++;
    }
    else{
      p.push_back(a);
      a=0;
    }
  }
  int N=p.size();
  vector<vector<vector<int64_t>>> dp(K+1,vector<vector<int64_t>>(K+1,vector<int64_t>(N+1)));
  vector<vector<vector<int64_t>>> yr(K+1,vector<vector<int64_t>>(K+1,vector<int64_t>(N+1)));
  vector<vector<vector<int64_t>>> tr(K+1,vector<vector<int64_t>>(K+1,vector<int64_t>(N+1)));
  dp.at(0).at(0).at(0)=1;
  for(int i=0;i<N;i++){
    for(int j=0;j<=K;j++){
      yr.at(0).at(j).at(i)=dp.at(0).at(j).at(i);
      tr.at(j).at(0).at(i)=dp.at(j).at(0).at(i);
      for(int k=0;k<K;k++){
        yr.at(k+1).at(j).at(i)=(yr.at(k).at(j).at(i)+dp.at(k+1).at(j).at(i))%Q;
        tr.at(j).at(k+1).at(i)=(tr.at(j).at(k).at(i)+dp.at(j).at(k+1).at(i))%Q;
      }
    }
    int b=p.at(i);
    for(int j=0;j<=K;j++){
      for(int k=0;k<=j;k++){
        int64_t X=0,Y=0;
        if(k-b-1>=0){
          X=tr.at(j).at(k-b-1).at(i);
        }
        if(j-P+b-1>=0){
          Y=yr.at(j-P+b-1).at(k).at(i);
        }
        dp.at(j).at(k).at(i+1)=(tr.at(j).at(k).at(i)+yr.at(j).at(k).at(i)-dp.at(j).at(k).at(i)-X-Y+3*Q)%Q;
      }
    }
  }
  int64_t Z=0;
  for(int j=0;j<=K;j++){
    for(int i=j;i<=min(K,j+a);i++){
      Z+=dp.at(i).at(j).at(N);
      Z%=Q;
    }
  }
  cout<<Z<<endl;
}

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

int main(){
  int n, d;
  cin >> n >> d;
  int x[n][d];
  rep(i,n) rep(j,d) cin >> x[i][j]; 
  vector<int> v;
  for(int i = 1; i*i <= 16000; i++) v.push_back(i*i);
  int ans = 0;
  rep(i,n) {
    for(int j = i+1; j < n; j++) {
      int a = 0;
      rep(k,d) a += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
      bool can = false;
      for(auto k : v) {
        if(a == k) can = true;
      }
      if(can) ans++; 
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256