akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;

public class Main {
	static int mod = (int) 1e9 + 7;
	static int DX[] = { -1, 0, 1, 0 }, DY[] = { 0, -1, 0, 1 };
	static final int INF = Integer.MAX_VALUE / 3;
	static final long LINF = Long.MAX_VALUE / 3;
	
	static char as[] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n'};
	static List<String> ls;
	static int n;
	public static void main(String[] args) {
		FastScanner fs = new FastScanner(System.in);
		n = fs.nextInt();
		ls = new ArrayList<>();
		dfs("", 0);
		Collections.sort(ls);
		for(String tmp:ls) System.out.println(tmp);

	}
	static void dfs(String s,int p) {
		String ns = "";
		ns = s + as[p];
		if(ns.length()==n) {
			ls.add(ns);
			return;
		}
		int tc = 0;
		for(int i=0;i<ns.length();i++) {
			if(ns.charAt(i)==as[tc]) {
				tc ++;
			}
		}
		for(int i=0;i<=tc;i++) {
			dfs(ns,i);			
		}
	}
	

	//MOD culculations
	static long plus(long x, long y) {
		long res = (x + y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long sub(long x, long y) {
		long res = (x - y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long mul(long x, long y) {
		long res = (x * y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long div(long x, long y) {
		long res = x * pow(y, mod - 2) % mod;
		return res < 0 ? res + mod : res;
	}

	static long pow(long x, long y) {
		if (y < 0)
			return 0;
		if (y == 0)
			return 1;
		if (y % 2 == 1)
			return (x * pow(x, y - 1)) % mod;
		long root = pow(x, y / 2);
		return root * root % mod;
	}
}

//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

	public String next() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

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

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

	public double nextDouble() {
		return Double.parseDouble(next());
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}

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

int main(){
    vector<pair<int,int> >vec;
    int a, p[8], q[8]={4,1,4,1,2,1,2,1};
    while(cin>>p[0]){
        for(int i=1;i<8;i++)
            cin>>p[i];
        int m=999999999;
        for(int i=0;i<8;i++){
            int t=0;
            for(int j=0;j<8;j++)
                if(p[j]>q[(i+j)%8])
                    t+=(p[j]-q[(i+j)%8]);
            if(t<m){
                vec.clear();
                m=t;
            }
            if(t<=m){
                int te=0;
                for(int j=0;j<8;j++)
                    te=te*10+q[(i+j)%8];
                vec.push_back(make_pair(te, i));
            }
        }
        sort(vec.begin(),vec.end());
        a=vec[0].second;
        for(int i=0;i<7;i++)
            cout<<q[(a+i)%8]<<" ";
        cout<<q[(a+7)%8]<<endl;
        vec.clear();
    }
}

Measured memory_bytes: 1192
#include<stdio.h>

int main() {
	int n;
	scanf("%d", &n);
	int m = n % 10;
	if (m == 3) printf("bon");
	else if (m == 0 || m == 1 || m == 6 || m == 8) printf("pon");
	else printf("hon");

	return 0;
}

Measured memory_bytes: 2152
H, W = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(H)]
ans = []
for i in range(W):
    for j in range(H - 1):
        if a[j][i] % 2 == 1:
            a[j][i] -= 1
            a[j + 1][i] += 1
            ans.append((j, i, j + 1, i))
for i in range(W - 1):
    if a[H - 1][i] % 2 == 1:
        a[H - 1][i] -= 1
        a[H - 1][i + 1] += 1
        ans.append((H - 1, i, H - 1, i + 1))
print(len(ans))
for n in ans:
    print(' '.join(map(lambda x: str(x + 1), n)))

# for row in a:
#    print(' '.join(map(str, row)))


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

int main(){
  string S;
  cin>>S;
  int N;
  N=S.length();
  bool flag=false;
  
  for(int i=0;i<N;i++){
    if(i%2==0&&S.at(i)=='L'){
      flag=true;
    }else if(i%2!=0&&S.at(i)=='R'){
      flag=true;
    }
  }
  
  if(flag) cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
# coding: utf-8
# hello worldと表示する
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
n=I()
lis=LI()
lis.sort(reverse=True)
nl=[]
nl.append(lis[0])
for i in range(1,n):
    nl.append(lis[i])
    nl.append(lis[i])
ans=0
#print(nl)
for i in range(n-1):
    ans+=nl[i]
print(ans)
    

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

//type
#define ll long long
typedef pair<int, int> P;
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素
#define Z class
// OTHER
// xの二乗を返す (関数テンプレート版)
template <typename T>
T square(T x) { return x * x; }
template <class T>
T GCD(T a, T b)
{
    T r;
    while (a)
        r = b, b = a, a = r % a;
    return b;
}
template <class T>
T LCM(T a, T b) { return a / GCD(a, b) * b; }

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
// loop
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repe(i, n) for (ll i = 0; i <= (n); i++)
#define repd(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (b); i--)
#define FORA(i, I) for (const auto &i : I)

// vector
#define ALL(x) x.begin(), x.end()
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef vector<ll> vl;
#define ERASE(x) x.erase(unique(ALL(x)), x.end()); // erase same elements
#define VEC(type, c, n)     \
    std::vector<type> c(n); \
    for (auto &i : c)       \
        std::cin >> i;

// input
#define INIT                          \
    std::ios::sync_with_stdio(false); \
    std::cin.tie(0);
#define VAR(type, ...) \
    type __VA_ARGS__;  \
    MACRO_VAR_Scan(__VA_ARGS__);
template <typename T>
void MACRO_VAR_Scan(T &t)
{
    std::cin >> t;
}
template <typename First, typename... Rest>
void MACRO_VAR_Scan(First &first, Rest &... rest)
{
    std::cin >> first;
    MACRO_VAR_Scan(rest...);
}

// output
template <typename T>
void MACRO_OUT(const T t) { std::cout << t; }

#define OUT(...) MACRO_OUT(__VA_ARGS__);
#define SP std::cout << " ";
#define TAB std::cout << "\t";
#define BR std::cout << "\n";
#define ENDL std::cout << std::endl;

#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define yes() printf("yes\n")
#define no() printf("no\n")
#define ln cout << '\n'
template <Z A>
void pr(A a)
{
    cout << a;
    ln;
}
template <Z A, Z B>
void pr(A a, B b)
{
    cout << a << ' ';
}

bool check = 0;
bool boo = 0;
int N = 3;
vector<int> v(N);
ll minn = INF, maxx = 0;
ll x = 0, y = 0;
int sum;
char ch;

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// cout << (conditon ? (result:  == 1 ): (==0)) << endl; <- output result of if
// long long 型が表せる値の上限はおよそ 9 × 10＾18 です．
int main()
{
    INIT;
    double n, t, a, h, m = 100000;

    double ans;
    cin >> n >> t >> a;
    rep(i, n)
    {
        cin >> h;
        h = t - h * .006;
        if (m > abs(h - a))
        {
            m = abs(h - a);
            ans = i;
        }
    }
    pr(ans + 1);
    return 0;
}


Measured memory_bytes: 3800
let s = Str.global_replace (Str.regexp "BC") "D" @@ read_line ()
let rec f acc bc i =
  if i < 0 then acc
  else if s.[i] = 'A' then f (acc + bc) bc (i - 1)
  else if s.[i] = 'D' then f acc (bc + 1) (i - 1)
  else f acc 0 (i - 1)
let _ = f 0 0 @@ String.length s - 1 |> Printf.printf "%d\n"

Measured memory_bytes: 10880
import math

#パラメータの受取り
N = int(input())
X = [int(x) for x in input().split(' ')]
#会議場所の候補算出
tmp = []
tmp.append(math.floor(sum(X)/N))
tmp.append(math.ceil(sum(X)/N))

#回答算出ループ
ans = []
for val in tmp:
  S = 0
  for p in X:
    S += (p-val) ** 2
  #計算結果の格納
  ans.append(S)

#最小値を出力
print(min(ans))


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

int main()
{
    int $=1;
    //cin>>$;
    while($--)
    {
        ll x,k,d;
        cin>>x>>k>>d;
        x=abs(x);
        ll t=x/d;
        ll a=x%d;
        if(k<=t)
        {
            a=x-k*d;
        }
        else{
            k-=t;
            if(k%2==1)
            {
                a-=d;
                a=abs(a);
            }
        }
        cout<<a<<endl;
    }
}


/*
8888888888888888888888888888
    Md. Masud Mazumder
    University of Chittagong
    Department of CSE
8888888888888888888888888888
*/


Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
const int maxn=2e5+10;
long long a[maxn];
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;++i){
		cin>>a[i];
	}
	sort(a,a+n);
	for(int i=0;i<n;i++){
		if(a[i]==a[i-1]){
			cout<<"NO"<<endl;
			return 0;
		} 
	}
	cout<<"YES"<<endl;
	return 0;
}

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

int a[100001];

int main() {
    int N; cin >> N;
    vector<int> A(N);
    rep(i,N) {
        cin >> A[i];
        a[A[i]]++;
    }

    long long ans=0;
    long long f=0;
    rep(i,100001) {

        while (a[i]>=3) {
            a[i] -= 2;
            ans++;
        }

        if (a[i]>=2) {
            f++;
        }

    }

    ans += f/2+f%2;

    cout << N-ans*2 << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
/*	#include <boost/math/common_factor.hpp>  boost::math::lcm(10,20) ---> use it to find lcm. fill_n(&an[0][0],n*m,0); typedef long long ll;*/
using namespace std;
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define int long long 
#define PI pair<int , int >
#define mpr make_pair
#define ff first
#define ss second
#define endl "\n"
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define FO(i,a,b) for(int i = (int)a;i < (int)b;++i)
#define FE(i,a,b) for(int i = (int)a;i <= (int)b;++i)
const int MOD = 1e9+7;
const int MAXN = 1e5+3;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,-1,1};
#define print(x) cerr << #x << " is " << x << endl;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
bool cmp(PI p1,PI p2){
	if(p1.ff < p2.ff)return true;	// You should not be writing p1.ss <= p2.ss !!!
	else if(p1.ff == p2.ff){ if(p1.ss < p2.ss)return true; return false; }
	return false;
}

void solve(){
	string s;
	cin >> s;
	if(s[1] == 'B')s[1] = 'R';
	else s[1] = 'B';
	cout << s << endl;
}
/* When you have to multiply many things , do it in different (multiple) lines, not in a single line .*/
int32_t main(){
	IO;
	#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	#endif // ONLINE_JUDGE
	// std::cout << std::setprecision(15); std::cout << std::fixed;
	int nT = 1;
	//cin >> nT;
	FE(i,1,nT)
		solve();
	return 0;
}


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

using namespace std;

#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define INF 1000000000
#define INFL 10000000000000000LL
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define ll long long int
#define P pair<ll, ll>

int main() {
  int a[4][3][10] = { };
  int n;
  cin >> n;
  REP(i, n){
    int b, r, v, f;
    cin >> b >> r >> v >> f;
    b--;
    r--;
    v--;
    a[b][r][v] += f;
  }
  REP(i, 4){
    REP(j, 3){
      REP(k, 10){
        cout << " " << a[i][j][k];
        if(k == 9) cout << endl;
      }
      if(i != 3 && j == 2) cout << "####################" << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3076
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"


int main() {
	string st;
	vector<string>ths{ " the "," this "," that " };
	while (getline(cin, st)) {
		st.push_back(' ');
		st.insert(st.begin(), ' ');
		for (int i = 0; i < 26; ++i) {
			string nextst(st);
			for (auto&c : nextst) {
				int n = c - 'a';
				if (n < 0 || n >= 26)continue;
				n += i;
				n %= 26;
				c = 'a' + n;
			}
			bool ok = false;
			for (auto th : ths) {
				if (nextst.find(th) != -1)ok = true;
			}
			if (ok) {
				cout << nextst.substr(1,nextst.size()-2) << endl;
				break;
			}
		}
	}
	return 0;
}

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);

  int n, x;
  cin >> n >> x;
  vector<int> b(n), lb(n), rb(n);
  for (int i = 0; i < n; i++) {
    cin >> b[i] >> lb[i] >> rb[i];
  }

  auto f = [&](int k, int i) {
    long long d = k - b[i];
    long long w = (d > 0) ? d * rb[i] : d * lb[i];
    return w;
  };

  vector<long long> all(n), none(n);
  for (int i = 0; i < n; i++) {
    all[i] = f(x, i);
    none[i] = f(0, i);
  }

  vector<pair<long long, int>> c(n);
  for (int i = 0; i < n; i++) {
    c[i] = {all[i] - none[i], i};
  }
  sort(c.rbegin(), c.rend());
  vector<long long> presum(n + 1);
  for (int i = 0; i < n; i++) {
    presum[i + 1] = presum[i] + c[i].first;
  }
  long long sumnone = 0;
  for (int i = 0; i < n; i++) {
    sumnone += none[i];
  }
  
  auto sum = [&](int firstk, int skip) { // skip index in c
    long long wn = sumnone - none[c[skip].second];
    long long wa = presum[firstk];
    if (skip < firstk) {
      wa = presum[firstk + 1] - c[skip].first;
    }
    return wa + wn;
  };

  auto test = [&](long long m) {
    long long k = m / x, r = m % x;
    if (r == 0) {
      return sumnone + presum[k];
    }
    long long res = -5e16;
    for (int i = 0; i < n; i++) {
      long long s = sum(k, i);
      s += f(r, c[i].second);
      res = max(res, s);
    }
    return res;
  };

  long long l = -1, r = 1LL * n * x;
  while (r - l > 1) {
    long long m = (l + r) / 2;
    if (test(m) >= 0) r = m;
    else l = m;
  }
  
  cout << r << '\n';
  return 0;
}


Measured memory_bytes: 8264
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */


ll solve(){
    ll res = 0;
    ll N; cin >> N;
    vector<ll> A(N);
    for(auto& in:A) cin >> in;
    map<ll,ll> mp;
    for(int i = 0; i < N;i++){
        mp[A[i]-1]++;
        mp[A[i]]++;
        mp[A[i]+1]++;
    }
    for(auto it = mp.begin(); it != mp.end(); it++){
        res = max(res,it->second);
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cout << solve() << endl;
    return 0;
}


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

int main(){
	int n;
	cin >> n;
	int sum=0;
	if(pow(10.0,0.0) <= n){
		sum += min((double)n,pow(10,1)-1) - pow(10,0)+1;
	}
	if(pow(10.0,2.0) <= n){
		sum += min((double)n,pow(10,3)-1) - pow(10,2)+1;
	}
	if(pow(10.0,4.0) <= n){
		sum += min((double)n,pow(10,5)-1) - pow(10,4)+1;
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <cstdio>
#include <sstream>

using namespace std;

int main() {
	int n;
	cin >> n;
	string abc = "0123456789abcdef";
	string z1 = "01";
	for (int i = 0; i < n; i++) {
		string a;
		cin >> a;
		string b = "";
		for (int j = 0; j < a.size(); j++) {
			string c = "";
			int d;
			for (int k = 0; k < abc.size(); k++) {
				if (a[j] == abc[k]) {
					d = k;
					break;
				}
			}
			for (int k = 0; k < 4; k++) {
				c += z1[d%2];
				d /= 2;
			}
			for (int k = 3; k >= 0; k--) {
				b += c[k];
			}
		}
		string f = b.substr(0, 1);
		string g = b.substr(1, 24);
		string h = b.substr(25);
		long long int kazu = 0;
		for (int i = g.size()-1; i >= 0; i--) {
			if (g[i] == '1') {
				kazu += pow(2, g.size()-1-i);
			}
		}
		long double kazu2 = 0.0;
		for (int i = 0; i < h.size(); i++) {
			if (h[i] == '1') {
				kazu2 += pow(2.0, -1-i);
			}
		}
		if (f[0] == '1') {
			cout << '-';
		}
		int p = kazu2 * 10.0;
		kazu2 = kazu2 *10.0 - p;
		string k = "";
		while (kazu2 != 0.0) {
			//cout << k << ' ' << kazu2 << endl;
			k += abc[p];
			p = kazu2 * 10.0;
			kazu2 = kazu2 * 10.0 - p;
		}
		k += abc[p];
		/*if (k.find('.') != string::npos) {
			k = k.substr(2);
		}*/
		cout << kazu << '.' << k << endl;
	}
	return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define endl "\n"
#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define rrep(i, a, b) for (auto i = (a); i > (b); --i)

typedef long long ll;

template <typename T>
bool chmax(T &a, T b) { return a < b ? (a = b, true) : false; }

bool IsReaf[801];
bool past[801];
ll cost2[801];
ll cost3[801];
ll allcost = 0;
vector<pair<int, int>> v[801];

void dfs(int now, ll cost) {
  cost2[now] = cost;
  past[now] = true;
  rep(i, 0, (int)v[now].size()) {
    if (past[v[now][i].fi]) continue;
    if (IsReaf[v[now][i].fi]) continue;
    dfs(v[now][i].fi, cost + v[now][i].se);
  }
}

void dfs2(int now, ll cost) {
  cost3[now] = cost;
  past[now] = true;
  rep(i, 0, (int)v[now].size()) {
    if (past[v[now][i].fi]) continue;
    if (IsReaf[v[now][i].fi]) continue;
    allcost += v[now][i].se;
    dfs2(v[now][i].fi, cost + v[now][i].se);
    allcost += v[now][i].se;
  }
}

void solve(int &n) {
  int p[801], d[801];
  rep(i, 1, n) {
    cin >> p[i]; p[i]--;
  }
  ll ans = 0;
  rep(i, 1, n) {
    cin >> d[i];
    ans += d[i];
  }
  rep(i, 1, n) {
    v[i].pb(mp(p[i], d[i]));
    v[p[i]].pb(mp(i, d[i]));
  }
  rep(i, 0, n) {
    if (v[i].size() == 1) IsReaf[i] = true;
    else IsReaf[i] = false;
  }
  rep(i, 0, n) {
    if (IsReaf[i]) continue;
    dfs(i, 0);
    break;
  }
  int nxt = -1;
  ll nowmax = -1;
  rep(i, 0, n) if (!IsReaf[i] && chmax(nowmax, cost2[i])) nxt = i;
  allcost = 0;
  fill(past, past + 801, false);
  dfs2(nxt, 0);
  ans += allcost;
  nowmax = -1;
  rep(i, 0, n) chmax(nowmax, cost3[i]);
  ans -= nowmax;
  cout << ans << endl;
}

int main()
{
  int n;
  while (cin >> n, n) {
    fill(IsReaf, IsReaf + 801, false);
    fill(past, past + 801, false);
    fill(cost2, cost2 + 801, 0);
    fill(cost3, cost3 + 801, 0);
    rep(i, 0, 801) v[i].clear();
    solve(n);
  }
}


Measured memory_bytes: 3244
#include<bits/stdc++.h> 
#define ll long long 
#define pb push_back 
#define vec vector<int> 
#define fo(i,n) for (ll i = 0; i < n; i++)
#define so(v) sort(v.begin(), v.end())
#define fi first
#define se second 
using namespace std;  
int main()
{


   ll n;
   cin>>n;
   vector<ll> v(n);
   fo(i,n)
   {
       cin>>v[i];
   }
   int count=0;
  fo(i,n)
  {
      for(ll j=i+1;j<n;j++)
      {
          for(ll k=j+1;k<n;k++)
          {
              if(v[i]+v[j]>v[k]
              && v[j]+v[k]>v[i]
              && v[k]+v[i]>v[j]
              && i<j<k && v[i]!=v[j] && v[j]!=v[k] && v[k]!=v[i])
            // cout<<i<<j<<k<<endl;
              //cout<<v[i]<<v[j]<<v[k]<<endl;
              count++;
          }
      }
     
  }
 cout<<count;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
#define AC ios::sync_with_stdio(0),cin.tie(0);
#define ll long long int

const int N=1005;
int dp[1005][1005];
char a[1005][1005];
int h,w;
ll mod=1e9+7;
int main(){
	AC
	cin>>h>>w;
	for(int i=1;i<h+1;i++){
		for(int j=1;j<w+1;j++){
			cin>>a[i][j];
		}
	}	
	for(int i=1;i<h+1;i++){
		if(a[i][1]=='#')break;
		else dp[i][1]=1;
	}
	for(int i=1;i<w+1;i++){
		if(a[1][i]=='#')break;
		else dp[1][i]=1;
	}
	for(int i=2;i<h+1;i++){
		for(int j=2;j<w+1;j++){
			if(a[i][j]!='#'){
				if(a[i-1][j]!='#')dp[i][j]+=(dp[i-1][j])%mod;
				if(a[i][j-1]!='#')dp[i][j]+=(dp[i][j-1])%mod;
			}
			dp[i][j]=dp[i][j]%mod;
		}
	}
	cout<<dp[h][w]%mod<<endl;
}












Measured memory_bytes: 8464
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>

using namespace std;

int main(){
  int n,m,k;
  cin>>n>>m>>k;
  bool ans = false;
  for(int i = 0;i<=n;i++){
    for(int j = 0;j<=m;j++){
      if((i * (m-j)+(n-i)*j)==k)
	ans = true;
    }
  }
  if(ans)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int a, b;
  cin >> a >> b;
  if(a < b){
    if((b - a) % 2 == 1){
      cout << "IMPOSSIBLE" << endl;
    }else{
      cout << (b - a) / 2 + a << endl;
    }
  }else{
    if((a - b) % 2 == 1){
      cout << "IMPOSSIBLE" << endl;
    }else{
      cout << (b - a) / 2 + a << endl;
    }
  }
  return 0;
}

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

int main() {
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
  int64_t H;
  cin>>H;
  int key=0;
  while(H>0){
    H=H/2;
    key++;
  }
  int64_t answer=1;
  rep(i,key)
    answer=answer*2;
  cout<<answer-1;
  
      
}

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

int S[1000000], cnt = 0;

int sor(int n, int g){
	do{
		
		g = (g - 1) / 3;
		for(int i = g;i < n;i++){
			int j = i - g, v = S[i];
			while(j >= 0 && v < S[j]){
				//printf("*%d*", j);
				S[j + g] = S[j];
				j -= g, cnt++;
			}
			S[j + g] = v;
		}
	}while(g != 1);
	return 0;
}

int main(){
	int g = 1, n, num = 0;
	scanf("%d", &n);
	for(int i= 0;i < n;i++)scanf("%d", &S[i]);
	while(g <= n)g = g * 3 + 1, num++;
	printf("%d\n", num);
	for(int i= g;i != 1;){
		if(i != g)printf(" ");
		i = (i - 1) / 3;
		printf("%d", i);
	}
	puts("");
	sor(n, g);
	printf("%d\n", cnt);
	for(int i= 0;i < n;i++)printf("%d\n", S[i]);
	
	return 0;
}

Measured memory_bytes: 7072
#include<vector>
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<map>
#include<functional>
#include<queue>
#include<stack>
#include<string.h>
#include<list>
#define ll long long int
#define MOD 1000000007LL
using namespace std;
int main() {
    int n;
    cin>>n;
    int a[114]={};
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n,greater<int>());
    int aa=0;
    int b=0;
    for(int i=0;i<n;i++){
        if(i%2==0){
            aa+=a[i];
        }else{
            b+=a[i];
        }
    }
    cout<<aa-b<<endl;
}


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

int const N = 1234567;
double const PI = acos(-1.0);
int const INF = (1 << 30);
int xs[N], ys[N], dp[N], id[N];

int main() {
  int x1, y1, x2, y2;
  scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", xs + i, ys + i);
  }
  // if (x1 == x2 || y1 == y2) {
  //   if (x1 > x2) std::swap(x1, x2);
  //   if (y1 > y2) std::swap(y1, y2);
  //   for (int i = 0; i < n; i++) {
  //     if (xs[i] >= x1 && xs[i] <= x2 && ys[i] >= y1 && ys[i] <= y2) {
  //       printf("%.17f\n", (x2 - x1 + y2 - y1) * 100. - 20 + PI * 10);
  //       return 0;
  //     }
  //   }
  //   printf("%.17f\n", 100. * (x2 - x1 + y2 - y1));
  //   return 0;
  // }
  if (x1 > x2) {
    x1 = -x1;
    x2 = -x2;
    for (int i = 0; i < n; i++) {
      xs[i] = -xs[i];
    }
  }
  if (y1 > y2) {
    y1 = -y1;
    y2 = -y2;
    for (int i = 0; i < n; i++) {
      ys[i] = -ys[i];
    }
  }
  for (int i = 0; i < n; i++) {
    if (xs[i] < x1 || xs[i] > x2 || ys[i] < y1 || ys[i] > y2) {
      std::swap(xs[i], xs[n - 1]);
      std::swap(ys[i], ys[n - 1]);
      --n;
      --i;
    }
  }
  for (int i = 0; i < n; i++) id[i] = i;
  std::sort(id, id + n, [](int i, int j) {
    return xs[i] < xs[j];
  });
  int cn = 0;
  dp[0] = -INF;
  for (int i = 0; i < n; i++) {
    int left = 0;
    int right = cn + 1;
    int x = ys[id[i]];
    while (left < right - 1) {
      int mid = (left + right) >> 1;
      if (dp[mid] > x) {
        right = mid;
      } else {
        left = mid;
      }
    }
    if (left + 1 > cn) {
      cn = left + 1;
    }
    dp[left + 1] = x;
  }
  printf("%.17f\n", (y2 - y1 + x2 - x1) * 100. - cn * (20 - PI * .5 * 10) + (cn == x2 - x1 + 1 || cn == y2 - y1 + 1 ? PI * .5 * 10 : 0));
}


Measured memory_bytes: 9216
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		int k = sc.nextInt();
		String str = sc.next();

		if(k < str.length()){
			str = str.substring(0, k) + "...";
		}

		System.out.println(str);
	}

}


Measured memory_bytes: 27084
# AOJ 1030 Cubes Without Holes
# Python3 2018.7.6 bal4u

import sys
from sys import stdin
input = stdin.readline

# n <= 500,  2^9 = 512
while True:
	n, h = map(int, input().split())
	if n == 0: break
	ans = []
	for i in range(h):
		c, a, b = input().split()
		a, b = int(a)-1, int(b)-1
		if c == "xy":
			ans += [a+(b<<9)+(z<<18) for z in range(n)]
		elif c == "xz":
			ans += [a+(y<<9)+(b<<18) for y in range(n)]
		else:
			ans += [x+(a<<9)+(b<<18) for x in range(n)]
	print(n**3-len(set(ans)))


Measured memory_bytes: 10276
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>  
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000000000000000000000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
int main() {
#define int long long 
	while (true) {
		int n, m;
		cin >> n >> m;
		if (n == 0) return 0;
		int gogo[100][100] = {};
		int cost[100][100] = {};
		REP(i, 100) {
			REP(q, 100) {
				cost[i][q] = 10000;
			}
		}
		for (int i = 0; i < m*2 - 1; ++i) {
			for (int q = (i + 1) % 2; q < 2 * n - 1; q+= 2) {
				cin >> gogo[i][q];
			}
		}
		queue<pair<int, int>> next;
		next.push(make_pair(0, 0));
		cost[0][0] = 0;
		int xe[4] = { 0,0,1,-1 };
		while (next.empty() == false) {
			pair<int, int> now = next.front();
			next.pop();
			for (int i = 0; i < 4; ++i) {
				int now_x = now.first + xe[i];
				int now_y = now.second + xe[3 - i];
				if (now_x >= 0 && now_x < 2 * m - 1 && now_y >= 0 && now_y < 2 * n - 1) {
					if (gogo[now_x][now_y] == 0) {
						int next_x = now_x + xe[i];
						int next_y = now_y + xe[3 - i];
						if (cost[next_x][next_y] == 10000) {
							cost[next_x][next_y] = cost[now.first][now.second] + 1;
							next.push(make_pair(next_x, next_y));
						}
					}
				}
			}
		}
		if (cost[m * 2 - 2][n * 2 - 2] == 10000) {
			cout << 0 << endl;
		}
		else {
			cout << 1 + cost[2 * m - 2][n * 2 - 2] << endl;
		}
	}
}



Measured memory_bytes: 3196
def main():
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    xy=[list(map(int,input().split())) for _ in [0]*m]

    class unionfind():
        #size:要素数,tree：unionfind木
        def __init__(self,size):#self,要素数
            self.size=size
            self.tree=[[i,1] for i in range(self.size)]#root,depth
        
        #rootを探す
        def root(self,index):
            temp_list=[]
            temp=self.tree[index][0]
            while index!=temp:
                temp_list.append(index)
                index=temp
                temp=self.tree[index][0]
            for i in temp_list:
                self.tree[i][0]=index
            return index
    
        #結合
        def unite(self,index1,index2):
            r1=self.root(index1)
            r2=self.root(index2)
            if r1!=r2:
                d1,d2=self.tree[r1][1],self.tree[r2][1]
                if d1<=d2:
                    self.tree[r1][0]=r2
                    self.tree[r2][1]=max(d1+1,d2)
                else:
                    self.tree[r2][0]=r1
                    self.tree[r1][1]=max(d2+1,d1)
    
        #同じか判定
        def same(self,index1,index2):
            r1=self.root(index1)
            r2=self.root(index2)
            return r1==r2
    
        #連結成分の個数
        def component(self):
            return len({self.root(i) for i in range(self.size)})
    
    u=unionfind(n)
    for x,y in xy:
        u.unite(x,y)
    for i in range(n):
        u.tree[i][0]=u.root(i)
    ut=u.tree
    d=dict()
    for i in range(n):
        if ut[i][0] in d.keys():
            d[ut[i][0]].append(a[i])
        else:
            d[ut[i][0]]=[a[i]]
    list1=[]
    list2=[]
    for s in d.values():
        s2=sorted(s)
        list1.append(s2[0])
        list2+=s2[1:]
    if len(list1)==1:
        print(0)
    elif len(list1)>len(list2)+2:
        print("Impossible")
    else:
        list2.sort()
        print(sum(list1)+sum(list2[:len(list1)-2]))
main()

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

typedef long long ll;

#define int ll

int s[200001];

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

  int a[200001];
  for(int i = 1; i <= n; i++){
    cin >> a[i];
  }

  s[0] = 0;
  for(int i = 1; i <= n; i++){
    s[i] = s[i-1] + a[i];
  }

  sort(s, s+n+1);

  int ans = 0, cnt = 0;
  for(int i = 0; i < n; i++){
    ans += cnt;
    if(s[i] == s[i+1]){
      cnt++;
    }else{
      cnt = 0;
    }
  }
  ans += cnt;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3328
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define ll long long
using namespace std;

const ll mod = 1e9 + 7;

ll C[2005][2005];
ll dp[100005][13];


int main(){
    int N,ans=0;
    string S,T;
    cin >> N;
    cin >> S;
    for(int i=0; i< S.size(); i++){
        ans = N + int(S[i]);
        if(ans > 90) ans -= 26;
        cout << char(ans);
    }
    cout << endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main{

    int h, w;
    char[][] map;
    boolean B, W;

    void solve(){
        Scanner sc = new Scanner(System.in);

        while(true){
            w = sc.nextInt(); h = sc.nextInt();
            if(w==0 && h==0) break;
            map = new char[h][w];
            for(int i=0; i<h; i++) map[i] = sc.next().toCharArray();

            int cntB = 0, cntW = 0;
            for(int i=0; i<h; i++){
                for(int j=0; j<w; j++){
                    if(map[i][j]!='.') continue;
                    B = false;
                    W = false;
                    int cnt = bfs(i, j);
                    if(B && !W) cntB+=cnt;
                    if(!B && W) cntW+=cnt;
                }
            }
            System.out.println(cntB+" "+cntW);
        }
    }

    int[] dx = {0, 0, 1, -1};
    int[] dy = {1, -1, 0, 0};
    int bfs(int y, int x){
        LinkedList<int[]> q = new LinkedList<int[]>();
        q.add(new int[]{x, y});
        boolean[][] v = new boolean[h][w];
        int cnt = 0;

        while(q.size()>0){
            int[] qq = q.poll();
            int X = qq[0], Y = qq[1];

            if(v[Y][X]) continue;
            v[Y][X] = true;

            if(map[Y][X]=='W') {W = true; continue;}
            if(map[Y][X]=='B') {B = true; continue;}

            cnt++;
            map[Y][X] = 'x';

            for(int i=0; i<4; i++){
                int nx = X + dx[i], ny = Y + dy[i];
                if(nx<0 || nx>=w || ny<0 || ny>=h) continue;
                q.add(new int[]{nx, ny});
            }
        }
        return cnt;
    }

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

Measured memory_bytes: 35564
N,M = map(int,input().split())
L = []
R = []
for i in range(M):
    L1,R1=[int(i) for i in input().split()]
    L.append(L1)
    R.append(R1)
x = min(R)-max(L)+1
if x <= 0:
  print("0")
else:
  print(x)

Measured memory_bytes: 11036
import java.util.Scanner;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    char[] out = s.toCharArray();
    
    int index = 0;
    if(out[index] == '?') out[index] = 'D';
    index++;
    while(index < out.length) {
      if(out[index] == '?') {
        if(out[index-1] == 'P') {
          out[index] = 'D';
        }
        else {
          if(index < out.length - 1 && out[index+1] == '?') {
            out[index] = 'P';
            out[index+1] = 'D';
          }
          else {
            out[index] = 'D';
          }
        }
      }
      index++;
    }
    
    
    String outStr = new String(out);
    System.out.println(outStr);
    
  }
}


Measured memory_bytes: 41468
#ifdef LOCAL111
#else
	#define NDEBUG
#endif
#include <bits/stdc++.h>
const long long INF = 1e10;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { cout << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;
typedef pair<LL,LL> LP;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);	
}

const LL mod = 1e9+7;

#define int LL

signed main()
{
	ios_init();
	int n;
	cin >> n;
	// while(cin >> n) {
	    vector<LL> t(n);
	    vector<LL> a(n);
	    LL ans = -1;
	    REP(i,n) cin >> t[i];
	    REP(i,n) cin >> a[i];
	    vector<LL> yama(n,-1);
	    vector<LL> yamar(n,INF);
	    LL pre = -1;
	    REP(i,n){
	    	if(chmax(pre,t[i])){
	    		yama[i] = t[i];
	    	}else{
	    		yamar[i] = min(yamar[i],pre);
	    	}
	    }
	    pre = -1;
	    RREP(i,n){
	    	if(chmax(pre,a[i])){
	    		if(yama[i] == -1 or yama[i] == a[i]) yama[i] = a[i];
	    		else ans = 0;
	    	}else{
	    		yamar[i] = min(yamar[i],pre);
	    	}
	    }
	    REP(i,n) if(yama[i] > yamar[i]) ans = 0; 
	    if(ans == 0){
	    	cout << 0 << endl;
	    	return 0;
	    }
	    ans = 1;
	    dpite(ALL(yama));
	    dpite(ALL(yamar));
	    REP(i,n){
	    	if(yama[i] == -1 and yamar[i] != INF){
	    		ans = ans*yamar[i]%mod;
	    	}  
	    }
	    cout << ans << endl;
	// }
	return 0;
}


Measured memory_bytes: 3456
using namespace std;

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

int main(
){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int ans = 0;
    int N = 0;
    int     n = 0;
    int M = 0;
    int m = 0;
    cin >> N >> M;
    int     H[N];
    set<int>    slose;  
    for(n = 0; n < N; n++){
        cin >> H[n];
    }

    for(m = 0; m < M; m++){
        int tmp1, tmp2;
        cin >> tmp1 >> tmp2;
        if(H[tmp1-1] > H[tmp2-1]){
            slose.insert(tmp2);
        }else if(H[tmp1-1] < H[tmp2-1]){
            slose.insert(tmp1);
        }else{
            slose.insert(tmp1);
            slose.insert(tmp2);
        }

    }

    ans = N - slose.size();

    cout << ans << "\n";
    return 0;
    
}

Measured memory_bytes: 6688
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair
#define fst first
#define snd second
#define fr(i, a, b) for(int i=a; i<b; i++)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
int r, s, p;
int get(char a) {
    if(a=='r') return p;
    if(a=='s') return r;
    if(a == 'p') return s;
    return 0;
}
int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    int n,k; cin >> n >> k;
    cin >> r >> s >> p;
    string t; cin >> t;
    int res = 0;
    for(int i=0; i<t.size(); i++) {
        if(i<k){
            res += get(t[i]);
        } else if(t[i] == t[i-k]) {
            t[i] = '0';
        } else {
            res += get(t[i]);
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 512
N, M, X = map(int,input().split())
A = list(map(int,input().split()))

goal_N = 0
goal_0 = 0

for i in range(X, N + 1):
    if i in A:
        goal_N += 1

for i in range(0, X + 1):
    if i in A:
        goal_0 += 1

min_cost = min(goal_N,goal_0)

print(min_cost)

Measured memory_bytes: 9196
n=gets.to_i
hs=gets.split.map(&:to_i)

(n-1).times do |i|
  diff=hs[i]-hs[i+1]
  if diff>0
    if diff==1
      hs[i+1]+=1
    else
      puts "No"
      exit
    end
  end
end
puts "Yes"


Measured memory_bytes: 8580
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//const int mod = 1e9 + 7;
const int N = 310;
int dp[N][N], c[N][N], mod;
int solve(int n, int k){
    if (dp[n][k] != -1) return dp[n][k];
    if (n == 0) return 1;
    if (k == 0) return 0;
    int res = solve(n, k - 1);
    for (int i = 1; i <= n; i++){
        res = (res + solve(i - 1, k - 1) * solve(n - i, k) % mod * c[n][i - 1]) % mod;
    }
    return dp[n][k] = res;
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    int n, k;
    cin >> n >> k >> mod;
    for (int i = 0; i <= n; i++){
        c[i][0] = 1;
        for (int j = 1; j <= i; j++){
            c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod;
        }
    }
    for (int i = 0; i <= n; i++){
        for (int j = 0; j <= k; j++){
            dp[i][j] = -1;
        }
    }
    cout << solve(n, k);
}


Measured memory_bytes: 1792
n = gets.to_i
h = gets.split.map(&:to_i)

count = 0

while true
  # find l
  l = h.index {|item| item > 0}
  break if l.nil?

  # find r
  r = h[l..-1].index {|item| item <= 0}

  if r != nil
    r += l - 1
  else
    r = n - 1
  end

  l.upto(r) do |i|
    h[i] -= 1
  end

  count += 1
end

p count


Measured memory_bytes: 4348
#include<cstdio>
using namespace std;
int a[2010],n;

bool solve(int m,int i){
	if(m == 0) return true;
	else if(i>n) return false;
	bool res=solve(m-a[i],i+1)||solve(m,i+1);
	return res;
}


int main(){
	int q,m;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	scanf("%d",&q);
	for(int i=1;i<=q;i++){
		scanf("%d",&m);
		if(solve(m,1)){
			printf("yes\n");
		}
		else printf("no\n");
	}
	//printf("hello");
	return 0;
}


Measured memory_bytes: 2676
#include <bits/stdc++.h>
// #include <atcoder/all>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
// using namespace atcoder;
void Main()
{
    ll n, m, Q;
    cin >> n >> m >> Q;

    vector<ll> L(m), R(m);
    rep(i, m) cin >> L[i] >> R[i];
    vector<ll> p(Q), q(Q);
    rep(i, Q) cin >> p[i] >> q[i];
    
    vector<vector<ll>> LR(501, vector<ll>(501));
    rep(i, m) {
        LR[L[i]][R[i]]++;
    }
    
    vector<vector<ll>> S(501, vector<ll>(501));
    rep(i, 501) {
        for(int j = 1; j <= 500; j++) {
            S[i][j] = S[i][j - 1] + LR[i][j];
        }
    }

    rep(ind, Q) {
        ll pi = p[ind];
        ll qi = q[ind];
        // (pi,pi), (pi,pi+1), ... (pi,qi), (pi+1,pi), ... (qi,qi)の総和
        ll res = 0;
        for (int i = pi; i <= qi; i++) {
            res += S[i][qi] - S[i][pi-1];
        }
        put(res);
    }
    
}
signed main(){ Main();return 0;}

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

int main(){
  int d;
  cin >> d;
  cout << "Christmas" << endl;
  switch(d){
    case 22:
      cout << " Eve";
    case 23:
      cout << " Eve";
    case 24:
      cout << " Eve";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
/* winners never quit and quitters never win.
      #swap                                 */
      
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;
#pragma GCC optimize ("-O3")
using ll = long long;
using ld = long double;
const ll mod = 1000000007;
const ll inf = 1000000000000000000;
const ll rk = 256;

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

#define pb push_back
#define mp make_pair
#define vc vector
#define fs first
#define sec second
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define pll pair<ll,ll> 
#define pls pair<ll,string>
#define psl pair<string,ll>
#define plc pair<ll,char>
#define pcl pair<char,ll>
#define pss pair<string,string>
#define all(v) v.begin(),v.end()
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define T ll t=0;cin>>t;for(ll test=0;test<t;test++)


int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
	//isprime();
	//coeff();
	/*freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);*/
    ll n,d,a;
    cin>>n>>d>>a;
    set<pll> s;
    rep(e,0,n)
    {
        ll b,c;
        cin>>b>>c;
        s.insert({b,c});
    }
    ll curr=0,ans=0;
    while(!s.empty())
    {
        pll temp=*(s.begin());
        s.erase(s.begin());
        if(temp.sec<0)
        {
            curr+=temp.sec;
            continue;
        }
        temp.sec-=curr;
        if(temp.sec>0)
        {
            ll req=(temp.sec+a-1)/a;
            ans+=req;
            s.insert({temp.fs+2*d+1,-(req*a)});
            curr+=(a*req);
        }
    }
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 12800
#include<stdio.h>
 
int main(){
  int a,b,c,d;
  int turn=0;
  scanf("%d%d%d%d",&a,&b,&c,&d);
  while(a>0){
    c-=b;
    if(c<=0){
      turn=1;
      break;
    }
    a-=d;
  }
  if(turn==1)
    printf("Yes");
  else if(turn==0)
    printf("No");
}

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

int main() 
{
  int N = 0, K = 0;
  cin >> N >> K;
  int n = pow(2, N), bit = 1, i = 0;
  int ans = 1, minans = 0x7fffffff;
  //cout << "n=" << n << endl;
  for (i = 0; i < n; i++) {
    bit = 1;
    ans = 1;
    //cout << "i=" << i << endl;
    for (int k = 0; k < N;k++) {
      if (bit & i) {
        ans = ans * 2;
      } else {
        ans = ans + K;
      }
      bit <<= 1;
    }
    //cout << ans << endl;
    minans = min(minans, ans);
  }
  cout << minans << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int b[500000], p, cnt;
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		if (b[0] == 1 || x < p) {
			cout << "No" << endl;
			continue;
		}
		if (p == x && cnt > x) {
			cout << "No" << endl;
			continue;
		}
		cnt++;
		cout << "Yes" << endl;
		if (x >= n) continue;
		b[x]++;
		while (x > 0 && b[x] >= 2) b[x] -= 2, b[x - 1]++, x--, cnt--;
		while (p + 1 < n && b[p + 1] == 1) p++;
	}
}


Measured memory_bytes: 4676
#include <bits/stdc++.h>
#define N 3005
 
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
const int mod = 998244353;
 
int n, S;
int a[N], f[N];
 
int main() {
  	IOS;
	scanf("%d %d", &n, &S);
	for(int i = 1; i <= n; ++i)
		scanf("%d", &a[i]);
	
	int ans = 0;
	for(int i = 1; i <= n; ++i) {
		if(a[i] > S) continue;
		else if(a[i] == S) {
			ans = (ans + 1LL * i * (n - i + 1)) % mod;
		} else {
			ans = (ans + 1LL * f[S - a[i]] * (n - i + 1)) % mod;
			for(int j = S; j > a[i]; --j)
				(f[j] += f[j - a[i]]) %= mod;
			f[a[i]] = (f[a[i]] + i) % mod;
		}
	}
	
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 384