akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define ll  long long 
#define rep(i, n)        for(ll i=0; i<(ll)(n); ++i)
#define mod 1000000007
  vector<ll>to[1000005];
int main(){
  ll a,b,d;cin>>a>>b>>d;
  cout<<(a-d+1)*(a-b+1);
}



Measured memory_bytes: 27036
N = int(input())
TS = []
for i in range(N):
    X, L = map(int, input().split())
    TS.append([X,L])

mlist=[]
for i in range(N):
    mlist.append([TS[i][0] + TS[i][1], TS[i][0] - TS[i][1]])

mlist.sort()

cur = -10**10
ans = 0
for i in range(N):
    if mlist[i][1] >= cur:
        ans+=1
        cur = mlist[i][0]
print(ans)

Measured memory_bytes: 36648
#include <bits/stdc++.h>
#include<cstdio>
using namespace std;
#define rep(i,a,n) for (long long  i=a;i<n;i++)
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define get(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
ll mod = 2e18;
ll powmod(ll a, ll b) { ll res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1)res = res*a%mod; a = a*a%mod; }return res; }

int cost(int h, int m) {
	return h * 60 + m;
}
void solve() {
	int h1, m1, h2, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	cout << (cost(h2, m2) - cost(h1, m1) - k) << endl;
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int T_ = 1;
	//cin >> T_;
	for (int i = 0; i < T_; i++)solve();
	return 0;
}







Measured memory_bytes: 3652
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
const double PI = 3.1415926535897932;

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

	if (N == M) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
} 

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

int n,m;
int p[125252];
int q;
int l[125252];
int ans[125252];  // ans[i] := length i arrow -> sonsitu

int main(){
  scanf("%d%d",&n,&m);
  REP(i,m)scanf("%d",p+i),p[i]--;
  scanf("%d",&q);
  REP(i,q)scanf("%d",l+i);
  // calc ans
  REP(i,n+2)ans[i] += p[0];
  REP(i,m){
    int x = p[i];
    int y = i==m-1 ? n : p[i+1];
    int sp = y-x-1;
    int len = 1;
    while(sp>0){
      ans[len] += sp;
      len++; sp--;
    }
  }
  REP(i,n+2)ans[i] = n - ans[i];
  // query
  REP(i,q){
    int id = lower_bound(ans+1,ans+n+2,n-l[i]) - ans;
    if(id == n+2){
      puts("-1");
    }else{
      printf("%d\n",id);
    }
  }
  return 0;
}



Measured memory_bytes: 4376
def main():
    
    h,w,k = map(int,input().split())
    l = [list(input()) for i in range(h)]

    def check(lis):
        
        num = [0]*(len(lis))
        ans = 0
        for i in range(w):
            num2 = [0]*(len(lis))
            for j in range(h):
                
                if l[j][i] == "1":
                    num2[d[j]] += 1
            if max(num2) > k:
                return float("INF")
            else:
                for i in range(len(num)):
                    num[i] += num2[i]
                    if num[i] > k:
                        ans += 1
                        num = num2
                        break 
            
            
        return ans

    ans = 10**9

    for i in range(2**(h-1)):
        count = 0
        lis1 = []
        d = []
        for j in range(h):
            d.append(count)
            if (i >> j) & 1:
                lis1.append(j)
                count += 1
        lis1.append(count+1)
        ans = min(ans,count+check(lis1))
        
    print(ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 47068
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
bool is_prime(ll N){
  if(N < 2) return false;
  for(ll i = 2; i * i <= N; i++){
    if(N % i == 0) return false;
  }
  return true;
}
string solve(int N, int C){
  if(C < 0){
    if(N == 1) return "11";
    else return string(2 * N, '9');
  }
  int b = 1;
  REP(i, N - 1) b *= 10;
  int e = b * 10;
  for(int n = e - 1; n >= b; n--){
    stringstream ss;
    ss << n;
    string s = ss.str();
    string t = s;
    reverse(t.begin(), t.end());
    s = s + (char)('0' + C) + t;
    stringstream ss2(s);
    ll p;
    ss2 >> p;
    if(is_prime(p)) return s;
  }
  return string(N, '9') + string(1, (char)('0' + C)) + string(N, '9');
}
int main(){
  int n, c;
  cin >> n >> c;
  cout << solve(n, c) << endl;
  return 0;
}

Measured memory_bytes: 1232
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 87;
char s[N];
deque<int> p[26];
int f[N];
void add(int i,int v)
{
    for (; i < N; i += i & -i)
        f[i] += v;
}
int qry(int i)
{
    int r = 0;
    for (; i; i ^= i & - i)
        r += f[i];
    return r;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> (s+1);
    int n = strlen(s+1);
    for (int i = 1; i <= n; ++i) {
        p[s[i]-'a'].push_back(i);
        add(i,1);
    }
    int mi = -1;
    for (int i = 0; i < 26; ++i)
        if (p[i].size() & 1) {
            if (mi != -1 || n % 2 == 0) {
                cout << "-1\n";
                return 0;
            }
            mi = i;
        }
    long long ans = 0;
    for (int i = 0, l = 1; i < n/2; ++i, ++l) {
        while (p[s[l]-'a'].size() < 2)
            ++l;
        auto & q = p[s[l]-'a'];
        ans += qry(l-1) + n - 2 * i - qry(q.back());
        add(l,-1);
        add(q.back(),-1);
        q.pop_front();
        q.pop_back();
    }
    cout << ans << '\n';
}


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

int main() {
    int N;
    string s;
    cin >> N >> s;
    
    int cntl = 0;
    string f = "";
    for(int i = 0; i < s.size(); i++) {
        if(s[i] == '(') cntl++;
        if(s[i] == ')' && cntl == 0) f += "(";
        else if(s[i] == ')' && cntl > 0) cntl--;
    }
    string b(cntl, ')');
    string ans = f + s + b;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
s = input()
t = input()

candidate = ("z" * len(s)) + "a"
for i in range(len(s) - len(t) + 1):
    if s[i] == t[0] or s[i] == '?':
        for j in range(len(t)):
            if s[i + j] != '?' and t[j] != s[i + j]:
                break
        else:
            candidate = min(s[0:i] + t + s[i+len(t):], candidate)
                
if candidate == ("z" * len(s)) + "a":
    print('UNRESTORABLE')
else:
    print(candidate.replace('?', 'a'))
                


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <string>
using namespace std;
typedef double  dbl;
typedef long long int lld;
#define PI 3.14159265358979323
#define foi(i,n) for(i = 0; i < n; i+=1)
#define fod(i,n) for(i=n-1; i >=0; i-=1)
#define MAX std::numeric_limits<lld>::max()
#define MIN std::numeric_limits<lld>::min()
#define FastIO  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main ()
{
	FastIO
	lld n, i;
	cin >> n;
	lld A[n+1];
	lld B[n];
	foi(i,n+1){
		cin >> A[i];
	}
	foi(i,n){
		cin >> B[i];
	}
	lld count = 0;
	foi(i,n){
		if (B[i] > A[i]){
			count += A[i];
			B[i]-=A[i];
			A[i] = 0;
			if (B[i] > A[i+1]){
				count += A[i+1];
				A[i+1] = 0;
				B[i] -= A[i+1];
			}
			else{
				count += B[i];
				A[i+1]-= B[i];
				B[i] = 0;
			}
		}
		else{
			count += B[i];
			A[i]-=B[i];
			B[i] = 0;
		}
	}
	cout << count;
	return 0;
}

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

int main(){

  int a,b,c,d;
  bool f = false;

  
  cin>>a>>b>>c>>d;

  


  if(a == b && a == c && a == d) f = true;

  if(a==b){
    if(c==d) f = true;
  }else if (a==c){
    if(b==c) f = true;
  }else if(a==d){
    if(b==c) f = true;
  }


  if(f){
    cout << "yes";
  }else cout << "no";

  cout << endl;


  
    
  return 0;
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 367
#define INF 100000000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 100005;
const int MOD = 1000000007;
int main(){
    ll n,k;
    cin>>n>>k;
    ll ans=min(abs((ll)n-k*(n/k)),abs(abs((ll)n-k*(n/k)-k)));
    OUT(ans);
    return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(unused_macros)]
use itertools::Itertools;
use std::cmp::{max, min};
use std::collections::*;
use std::i64;
use std::io::{stdin, BufWriter, Read, Write};
use std::usize;
use std::fmt::Write as _Write;

#[allow(unused_macros)]
macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, $var:ident $($r:tt)*) => {
        let $var = parse_val!($it, usize);
        parse!($it $($r)*);
    };
}

#[allow(unused_macros)]
macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: tt),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, u1) => {
        $it.next().unwrap().parse::<usize>().unwrap() -1
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    parse!(it, n: usize);
    println!("{}", "ACL".repeat(n));

}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}
trait ChMinMax {
    fn chmin(&mut self, other: Self);
    fn chmax(&mut self, other: Self);
}
impl<T> ChMinMax for T
where
    T: PartialOrd,
{
    fn chmin(&mut self, other: Self) {
        if *self > other {
            *self = other
        }
    }
    fn chmax(&mut self, other: Self) {
        if *self < other {
            *self = other
        }
    }
}



Measured memory_bytes: 2124
#include <iostream>

#include <vector>
#include <map>
#include <algorithm>
#include <fstream>
#include<cstdio>
#include<iomanip>
#include<stack>
#include<queue>

#define REP(i, n) for(int i=0;i<n;i++)
#define REP2(i, s, n) for(int i=s;i<n;i++)
#define REP_1(i, n) for(int i=1;i<n+1;i++)
#define bitSearch(bit, n) for(int bit = 0; bit < (1 << N); bit++)
using namespace std;

void printAns(long long a) { cout << a << endl; }

void yesno(bool a) { if (a)cout << "Yes" << endl; else cout << "No" << endl; }

void YESNO(bool a) { if (a)cout << "YES" << endl; else cout << "NO" << endl; }

typedef long long ll;
typedef unsigned long ul;
typedef long double ld;

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

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

ll INF = 10000000;
ll mod = 1000000007;//10^9+7

int light[2000][2000] = {0};
//番号ズレ注意！！
int main() {
    int H, W;
    cin >> H >> W;
    string S[H];
    REP(i, H) { cin >> S[i]; }
    REP(i, H) {
        queue<int> h;
        int tmp = 0;
        REP(j, W) {
            if (S[i][j] == '.') { tmp += 1;if(j==W-1)h.push(tmp); }
            else {
                h.push(tmp);
                tmp = 0;
            }
        }
//        cout<<i<<"(size):"<<h.size()<<endl;
//        REP(i,h.size()){
//            cout<<h.front()<<endl;
//            h.pop();
//        }
//        cout<<"kokomade"<<i<<endl;
        int x = 0;
        int m=h.size();
        REP(l,m) {
            int j=h.front();
//            cout<<"j:"<<j<<endl;
            if(j!=0){
                REP(k, j) {
                    light[i][x + k] += j;
//                    cout<<"i:"<<i<<" x+k:"<<x+k<<" j:"<<j<<endl;
                }
            }
            x += j + 1;
            h.pop();
        }
    }
//    cout << light[0][2];

    REP(i, W) {
        queue<int> w;
        int tmp = 0;
        REP(j, H) {
            if (S[j][i] == '.') { tmp += 1;if(j==H-1)w.push(tmp); }
            else {
                w.push(tmp);
                tmp = 0;
            }
        }
        int x = 0;
        int m=w.size();
        REP(l,m) {
            int j=w.front();
//            cout<<"j:"<<j<<endl;
            if(j!=0){
                REP(k, j) {
                    light[x+k][i] += j;
//                    cout<<"i:"<<i<<" x+k:"<<x+k<<" j:"<<j<<endl;
                }
            }
            x += j + 1;
            w.pop();
        }
    }

    int max=0;
    REP(i,H){
        REP(j,W){
            chmax(max,light[i][j]);
        }
    }
    cout<<max-1<<endl;
}

Measured memory_bytes: 19968
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  ll mx = 0, ans = 0;
  rep(i, n) {
    ll a;
    cin >> a;
    ans += max(0LL, mx - a);
    mx = max(mx, a);
  }
  cout << ans << endl;
}

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

struct Box{
	int x1,y1,z1,x2,y2,z2;
};

vector<long long>X;
vector<long long>Y;
vector<long long>Z;
vector<Box>data;

bool che(Box B1,Box B2){
	bool re=true;
	return (B1.x1<=B2.x1 && B1.x2>=B2.x2 
		 && B1.y1<=B2.y1 && B1.y2>=B2.y2
		 && B1.z1<=B2.z1 && B1.z2>=B2.z2);
}

int cou(int x,int y,int z){
	int x1=X[x],x2=X[x+1];
	int y1=Y[y],y2=Y[y+1];
	int z1=Z[z],z2=Z[z+1];
	Box B2=(Box){x1,y1,z1,x2,y2,z2};
	int re=0;
	for(int i=0;i<data.size();i++){
		Box B1=data[i];
		if(che(B1,B2))re++;
	}
	return re;
}
int main(){
	int n,k;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		Box tmp;
		cin>>tmp.x1>>tmp.y1>>tmp.z1>>tmp.x2>>tmp.y2>>tmp.z2;
		
		data.push_back(tmp);
		X.push_back(tmp.x1);X.push_back(tmp.x2);
		Y.push_back(tmp.y1);Y.push_back(tmp.y2);
		Z.push_back(tmp.z1);Z.push_back(tmp.z2);
	}
	sort(X.begin(),X.end());
	sort(Y.begin(),Y.end());
	sort(Z.begin(),Z.end());
	long long ans=0;
	for(int x=0;x<X.size()-1;x++){
		for(int y=0;y<Y.size()-1;y++){
			for(int z=0;z<Z.size()-1;z++){
				if(cou(x,y,z)>=k)ans+=(long long)((X[x+1]-X[x])*(Y[y+1]-Y[y])*(Z[z+1]-Z[z]));
			}
		}
	}
	
	cout<<ans<<endl;
}

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

int main() {
  int N, X;
  cin >> N >> X;
  
  vector<int> m(N);
  for(int i = 0; i < N; i++) {
    cin >> m.at(i);
  }

  // 最低一個 => 粉が何グラムで、何個
  auto g = accumulate(m.begin(), m.end(), 0);
  int num = m.size();
  
  // 一番粉が少なくて良いやつを探す
  sort(m.begin(), m.end());
  auto i = min(m.begin(), m.end());
  int m1 = *i;  
  
  // 追加で何個作れるか
  num += ((X - g) / m1);
  
  // 出力
  cout << num << endl;
}


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

template <typename T, ll mod>
class RollingHash {
   private:
    struct mPair {
        ll v0, v1;
        mPair operator*(const mPair &p) { return mPair{(v0 * p.v0) % mod, (v1 * p.v1) % mod}; }
        mPair operator+(const mPair &p) { return mPair{(v0 + p.v0) % mod, (v1 + p.v1) % mod}; }
        mPair operator-(const mPair &p) {
            return mPair{(v0 + mod - p.v0) % mod, (v1 + mod - p.v1) % mod};
        }
        mPair operator*(const ll &x) { return mPair{(v0 * x) % mod, (v1 * x) % mod}; }
        mPair operator+(const ll &x) { return mPair{(v0 + x) % mod, (v1 + x) % mod}; }
        mPair operator*(const pair<int, int> &p) {
            return mPair{(v0 * p.first) % mod, (v1 * p.second) % mod};
        }
        mPair operator+(const pair<int, int> &p) {
            return mPair{(v0 + p.first) % mod, (v1 + p.second) % mod};
        }
        pair<int, int> to_pair() { return make_pair(v0, v1); }
    };
    vector<mPair> hash, bpow;
    const mPair base = {1069, 10007};

   public:
    const int len;
    // O(|S|)
    RollingHash(T &s) : len(s.size()) {
        hash.assign(len + 1, {0, 0});
        bpow.assign(len + 1, {0, 0});
        bpow[0] = {1, 1};
        for (int i = 0; i < len; i++) {
            hash[i + 1] = hash[i] * base + s[i];
            bpow[i + 1] = bpow[i] * base;
        }
    }

    // 文字列[l,r)のハッシュ値を返す O(1)
    pair<int, int> get(int l, int r) { return (hash[r] - hash[l] * bpow[r - l]).to_pair(); }
    pair<int, int> get() { return get(0, len); }

    // h1 + h2(ハッシュ値h1とハッシュ値h2の結合) O(1)
    pair<int, int> connect(pair<int, int> h1, pair<int, int> h2, int len_h2) {
        return (bpow[len_h2] * h1 + h2).to_pair();
    }

    // [l1,r1)の文字列とbの[l2,r2)の文字列の最長共通接頭辞の長さを返す O(log(min(|S1|,|S2|)))
    int LCP(RollingHash &b, int l1, int r1, int l2, int r2) {
        int ok = -1, ng = min(r1 - l1, r2 - l2) + 1;
        while (abs(ok - ng) > 1) {
            int mid = (ok + ng) / 2;
            if (get(l1, l1 + mid) == b.get(l2, l2 + mid))
                ok = mid;
            else
                ng = mid;
        }
        return ok;
    }
};
using RH = RollingHash<vector<ll>, 1000000007>;

void build_xorv(vector<ll> &v0, vector<ll> &v1) {
    for (int i = 0; i < v1.size() - 1; i++) {
        v0[i] = v1[i] ^ v1[i + 1];
    }
}

int main() {
    int n;
    cin >> n;
    vector<ll> a(2 * n), b(n), c(2 * n - 1), d(n - 1);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i + n] = a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }
    build_xorv(c, a);
    build_xorv(d, b);
    RH rc(c), rd(d);
    vector<int> k;
    for (int i = 0; i < n; i++) {
        if (rc.get(i, i + n - 1) == rd.get()) k.push_back(i);
    }
    for (int i = 0; i < k.size(); i++) {
        cout << k[i] << " " << (b[0] ^ a[k[i]]) << endl;
    }
    return 0;
}

Measured memory_bytes: 32500
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll          long long
#define pb          push_back
#define eb 			emplace_back
#define mp 			make_pair
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define fi          first
#define si          second
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define checkbit(n, b) ((n >> b) & 1)
#define mod        1000000007
#define inf        10000000000
#define puts(n)		cout<<n;
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define setbits(x) __builtin_popcount(x)
#define mset(m,v) memset(m,v,sizeof(m))
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	ll n;
	cin>>n;
	double p[n+1];
	for(ll i=1;i<=n;i++){
		cin>>p[i];
	}
	double dp[n+1][n+1];
	for(ll i=2;i<=n;i++) dp[1][i]=0;
	dp[1][0]=1-p[1];dp[1][1]=p[1];
	for(ll i=2;i<=n;i++){
		dp[i][0]=dp[i-1][0]*(1-p[i]);
	}
	for(ll i=2;i<=n;i++){
		for(ll j=1;j<=n;j++){
			dp[i][j] = p[i]*dp[i-1][j-1] + (1-p[i]) * dp[i-1][j];
		}
	}
	/*for(ll i=1;i<=n;i++){
		for(ll j=0;j<=n;j++){
			cout<<dp[i][j]<<" ";
		}
		cout<<"\n";
	}*/
	double ans=0.0;
	ll index= n/2+1;
	for(ll i=index;i<=n;i++){
		ans+=dp[n][i];
	}
	cout<<fixed<<setprecision(9)<<ans;
	return 0;
}

Measured memory_bytes: 70528
#include<bits/stdc++.h>
using namespace std;
const int mx = 1e6;
#define ll long long
int main() {
    ll a, b, c;
    cin >> a >> b >> c;
    ll chk = b * c;
    if (chk >= a) {
        cout << "Yes" << endl;
    }
    else
        cout << "No" << endl;
}

Measured memory_bytes: 3588
l = []
x = 2147483647
index = 0
for i in range(5):
   l.append( int(input()) )
   n = int(l[i]%10)
   if n>0 and n<x:
      x = n
      index = i

ans = 0
for i in range(5):
    if i == index:
        ans += l[i]
    elif l[i]%10 != 0:
        ans += int(l[i]/10)*10 +10
    else:
        ans += l[i]

print(ans)

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> mat;
#define FOR(i,a,b) for(int i=(a);i<(int)(b);++i)
#define rep(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define mset(a,x) memset(a,x,sizeof(a))
#define OUT(x) cout<<(x)<<"\n"
#define SZ(x) (int)(x).size()
#define FASTIO cin.tie(0),ios::sync_with_stdio(0)


int main() {
    FASTIO;
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    ll ans = 114514191919191919LL;
    rep(j, 2) {
        ll sum = 0, cur = 0;
        rep(i, n) {
            int plus = i % 2 == j % 2;
            sum += a[i];
            if(plus && sum > 0) continue;
            if(!plus && sum < 0) continue;

            if(plus) {
                cur += 1 - sum;
                sum = 1;
            }
            else {
                cur += sum + 1;
                sum = -1;
            }
        }
        ans = min(ans, cur);
    }


    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(){
int a,b,c,d,e,f,i;
scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
for(i=0;i<4;i++){
if(a<b){
f=a;
a=b;
b=f;
}
if(b<c){
f=b;
b=c;
c=f;
}
if(c<d){
f=c;
c=d;
d=f;
}
if(d<e){
f=d;
d=e;
e=f;
}
}
printf("%d %d %d %d %d\n",a,b,c,d,e);
return 0;
}


Measured memory_bytes: 2048
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int maxCnt = 0;
        int cntNum = 1;
        for (int i = 1; i <= n; i++) {
            int cnt = 0;
            int num = i;
            while (num % 2 == 0) {
                cnt++;
                num /= 2;
            }
            if (cnt >= maxCnt) {
                maxCnt = cnt;
                cntNum = i;
            }
        }
        System.out.println(cntNum);
    }
}

Measured memory_bytes: 21844
AB,BC,CUm = input().split()
AB = int(AB)
BC = int(BC)
CUm = int(CUm)

if 1 <= AB <= 100:
    if 1 <= BC <= 100:
        if 1 <= CUm <= 100:
            area = (AB * BC )/ 2
            print(int(area))

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
const int mod = 1000000007;
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
vector<int> f = {1},fi = {1};
int fact(int x){
    while(f.size() <=x)f.push_back((f.back()*f.size())%mod);
    return f[x];
}
int ifact(int x){
    return modpow(fact(x),mod-2,mod);
}
int C(int x,int y){
    if(x < y)return 0;
    return fact(x)*ifact(y)%mod*ifact(x-y)%mod;
}
//#########################################
signed main(){
    int n;cin >> n;
    int a[n+1];
    vector<int> vis(n);
    int r;
    rep(i,n+1){
        cin >> a[i];
        a[i]--;
    }
    rep(i,n+1){
        if(vis[a[i]]){
            r = i;
            break;
        }
        vis[a[i]] = 1;
    }
    int l;
    for(l = 0;l < n && a[r] != a[l];l++);
    int L = l;
    int R = n-r;
    for(int k = 1;k <= n+1;k++){
        int ans = C(n+1,k);
        ans -= C(L+R,k-1);
        cout << (ans%mod+mod)%mod << endl;
    }


    return 0;
}

Measured memory_bytes: 3700
#include<bits/stdc++.h>
using namespace std;
#include <numeric> 
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl "\n"
#define int long long int
#define mod 1000000007
#define INT_BITS 16
#define INF 10000000
#define pi 3.141592
#define watch(x) cout<<(#x)<<"="<<(x)<<"\n" 
#define pb push_back
//__builtin_popcount

#ifndef ONLINE_JUDGE
    #include "debug.cpp"
#endif


int32_t main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    #endif
    // fast;

   int n;
   cin>>n;

   int sum[n],dif[n];
   for(int i=0;i<n;i++)
   {
        int x,y;
        cin>>x>>y;
        sum[i]=x+y;
        dif[i]=x-y;
   }


    int mx1=INT_MIN,mx2=INT_MIN,mn1=INT_MAX,mn2=INT_MAX;
    int ans=0;
   for(int i=0;i<n;i++)
   {
        mx1=max(mx1,sum[i]);
        mx2=max(mx2,dif[i]);
        mn1=min(mn1,sum[i]);
        mn2=min(mn2,dif[i]);
        ans=max(ans,max(mx1-mn1,mx2-mn2));

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

}


Measured memory_bytes: 6784
#include <iostream>
#include <algorithm>
using namespace std;
int n, d, x, a[12][12], dp[100009];
int main() {
	cin >> n >> d >> x;
	for (int i = 0; i < d; i++) {
		for (int j = 0; j < n; j++) cin >> a[i][j];
	}
	for (int i = 1; i < d; i++) {
		int z = x;
		for (int j = 1; j <= x; j++) {
			dp[j] = 0;
			for (int k = 0; k < n; k++) {
				if (j >= a[i - 1][k]) dp[j] = max(dp[j], dp[j - a[i - 1][k]] + a[i][k]);
			}
			z = max(z, dp[j] + x - j);
		}
		x = z;
	}
	cout << x << endl;
	return 0;
}

Measured memory_bytes: 3164
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn main() {
    let n: u64 = read();
    let mut ans = 0;
    for i in 1..((n as f64).sqrt() as u64) + 1 {
        if i * i == n {
            continue;
        }
        if n % i == 0 {
            let m = n / i - 1;
            if i < m {
                ans += m;
            }
        }
    }
    println!("{}", ans);
}


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

int c[10]={0,2,5,5,4,5,6,3,7,6};

int main(){
  int n,m;
  cin>>n>>m;
  int a[m];
  rep(i,0,m) cin>>a[i];
  sort(a,a+m);
  reverse(a,a+m);
  int dp[n+1];
  rep(i,0,n+1) dp[i]=-1;
  dp[0]=0;
  rep(i,1,n+1){
    rep(j,0,m){
      if(i>=c[a[j]] && dp[i-c[a[j]]]!=-1){
        dp[i]=max(dp[i],dp[i-c[a[j]]]+1);
      }
    }
  }
  //rep(i,0,n+1) cout<<dp[i];
  int cur=n;
  while(cur>0){
    rep(i,0,m){
      if(cur-c[a[i]]>=0 && dp[cur]==dp[cur-c[a[i]]]+1){
        cur-=c[a[i]];
        cout<<a[i];
        break;
      }
    }
  }
  cout<<endl;
}

Measured memory_bytes: 3664
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <random>

using namespace std;


int main()
{
	string S, T;
	int ans = 0;

	cin >> S >> T;

	for (int si = 0; si < 3; si++){
		if (S[si] == T[si])ans++;
	}

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


	return 0;
}



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

int main(){
    int a = 700;
    string s;
    cin >> s;

    if (s[0] =='o'){
        a += 100;
    }
    if (s[1] =='o'){
        a += 100;
    }
    if (s[2] =='o'){
        a += 100;
    }
    cout << a << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)

N,M = list(map(int,input().split()))
xy = [list(map(int,input().split())) for _ in range(M)]

dp = [None] * (N+1)

def get_dp(i):
    if dp[i] != None:
        return dp[i]
    yListSub = yList[i]
    if yListSub == []:
        dp[i] = 0
        return 0
    else:
        dp[i] = 1+ max(map(get_dp,yListSub))
        return dp[i]

yList = [[] for _ in range(N+1)]
for x,y in xy:
    yList[x].append(y)

[get_dp(i) for i in range(0,N+1)]
print(max(dp))

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

using namespace std; 
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>; 

#define INF INT_MAX;
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

int main(){
  int N;
  cin>>N;
  vector<int>D(N);
  for(int i=0;i<N;i++)cin>>D[i];
  map<int,int>m;
  m[0]++;
  for(int i=0;i<N;i++)m[D[i]]++;

  for(int i=0;i<=12;i++){
    if(i==0||i==12){
      if(m[i]>=2){
        cout<<0<<endl;
        return 0;
      }
    }
    else{
      if(m[i]>=3){
        cout<<0<<endl;
        return 0;
      }
    }
  }

  vector<int>bits;
  for(int b=0;b<pow(2,13);b++){
    bool ok=true;
    if(m[0]==1&&!(b&1))continue;
    if(m[12]==1&&!((b>>12)&1))continue;
    for(int i=1;i<=11;i++){
      if(m[i]==0){
        if((b>>i)&1){
          ok=false;
          break;
        }
      }
      else if(m[i]==2){
        if(!((b>>i)&1)){
          ok=false;
          break;
        }
      }
    }
    if(ok)bits.push_back(b);
  }

  int Max=0;
  for(auto it:bits){
    vector<int>a;
    int Min=INF;
    if(m[0])a.push_back(0);
    if(m[12])a.push_back(12);
    for(int i=1;i<=11;i++){
      if(m[i]==1){
        if((it>>i)&1)a.push_back(i);
        else a.push_back(24-i);
      }
      else if(m[i]==2){
        a.push_back(i);
        a.push_back(24-i);
      }
    }
    a.push_back(24);
    sort(rng(a));
    for(int i=0;i<a.size()-1;i++){
      Min=min(Min,a[i+1]-a[i]);
    }
    Max=max(Max,Min);
  }
  cout<<Max<<endl;
  return 0;
}


Measured memory_bytes: 256
// Last Change: 01/25/2020 17:37:18.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

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

ll BFS(int rx, int ry, vector<string> &area) {
  if (area[rx][ry] == '#') {
    return -1;
  }

  int H, W;
  H = area.size();
  W = area[0].size();

  queue<pair<int, int>> q;
  queue<ll> c;

  vector<vector<int>> visited(H, vector<int>(W, 0));

  visited[rx][ry] = 1;
  q.push(make_pair(rx, ry));
  c.push(0);

  ll res = 0;

  while (!q.empty()) {
    pair<int, int> temp = q.front();
    ll cost = c.front();
    q.pop();
    c.pop();

    //何かしらの処理
    res = cost;

    //次の探索対象を入れていく
    for (int i = 0; i < 4; ++i) {
      ll nx = temp.first + dx[i];
      ll ny = temp.second + dy[i];
      ll nc = cost + 1;

      if ((nx < 0 or H <= nx) or (ny < 0 or W <= ny)) {
        continue;
      }
      if (area[nx][ny] == '#') {
        continue;
      }
      if (visited[nx][ny] == 1) {
        continue;
      }

      visited[nx][ny] = 1;
      q.push(make_pair(nx, ny));
      c.push(nc);
    }
  }

  return res;
}

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> area(H);
  for (auto &&e : area) {
    cin >> e;
  }

  ll res = 0;
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      res = max(res, BFS(i, j, area));
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 256
import bisect
import array
N = int(input())
P = list(map(int, input().split()))
P_id = [0]*(N + 1)

for i in range(N):
    P_id[P[i]] = i

A = array.array('i', [- 1, P_id[N], N])


res = 0
for i in range(N - 1, 0, - 1):
    j = bisect.bisect_left(A, P_id[i])
    A.insert(j, P_id[i])
    l1 = A[j - 1]
    r1 = A[j + 1]
    l2 = l1
    r2 = r1
    if l1 != - 1:
        l2 = A[j - 2]
    if r1 != N:
        r2 = A[j + 2]
    
    res += i*((A[j] - l1)*(r2 - r1) + (l1 - l2)*(r1 - A[j]))

print(res)

Measured memory_bytes: 14028
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
using namespace std;
#define ll           long long
#define all(v)       (v).begin() , (v).end()
#define vi           vector <ll>
#define vii          vector <pair<ll,ll>>
#define ii           pair<ll,ll>
#define sz(v)	     ((int)((v).size()))
#define lp(i,a,b)    for(int i=a;i<b;i++)
#define pb           push_back
#define pf           push_front
#define F            first
#define S            second
#define endl         "\n"
#define IOS          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const double PI = 3.14159265358979323846;
const ll inf=2e9,MOD=998244353,MAX=1e7+2;

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    IOS;
    ll n,k;
    cin>>n>>k;
    ll x=n/k;
    n-=x*k;
    ll res=n;
    lp(i,0,3){
        n=abs(n-k);
        res=min(res,n);
    }
    cout<<res;
}

Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <utility>
#include <cmath>
#include <string>
#include <bitset>
#include <queue>
#include <cstdio>
#include <cstring>
#include <deque>
#include <unordered_map>
#include <climits>
#include <map>
#include <iomanip>
#include <set>
#include <unordered_set>
#include <ctime>
#include <cstdint>

#define ci(t) cin>>t
#define co(t) cout<<t
#define LL long long
#define fa(i,a,b) for(int i=a;i<b;++i)
#define fd(i,a,b) for(int i=a;i>b;--i)
#define setp pair<pair<int,int>,int>
#define setl pair<int,int>

using namespace std;

LL gcd(LL a, LL b) { return a % b ? gcd(b, a % b) : b; }
LL lcm(LL a, LL b) { return (a * b) / gcd(a, b); }
pair <int, int> vu[4] = { {0,1}, {0,-1} , {1,0},{-1,0} }; // EWSN

const int max_v = 2e5 + 7;
const int INF = 1e9 + 7;



int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	string s;
	ci(s);
	if (s.back() == '3') co("bon");
	else if (s.back() == '0' || s.back() == '1' || s.back() == '6' || s.back() == '8') co("pon");
	else co("hon");
	return 0;
}


Measured memory_bytes: 3652
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;

int main()
{
	int n;cin >> n;
	string s;map<string,int> tb;
	while(n--)
	{
		cin >> s;++tb[s];
	}
	cout << "AC x " << tb["AC"] << endl;
	cout << "WA x " << tb["WA"] << endl;
	cout << "TLE x " << tb["TLE"] << endl;
	cout << "RE x " << tb["RE"] << endl;
    return 0;
}


Measured memory_bytes: 3252
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

using ll = long long;
using ld = long double;
const int INF = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main()
{
  int N;
  cin >> N;
  vector<int> p(N);
  for (auto &e : p)
    cin >> e;
  vector<int> q(N);
  iota(q.begin(), q.end(), 1);

  int cnt = 0;
  for (int i = 0; i < N; ++i)
  {
    if (p[i] != q[i])
      cnt++;
  }
  if (cnt <= 2)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;

  return 0;
}

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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

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

  int n, k; cin >> n >> k;
  vll h(n+1);
  for(int i=0;i<n;++i) {
    cin >> h[i+1];
  }
  if(n == 1 && k == 0) {
    cout << h[1] << endl;
    return 0;
  }
  if(n == 1 && k == 1) {
    cout << h[0] << endl;
    return 0;
  }


  vvll dp(n+1, vll(n+1, LINF));
  dp[0][0] = 0;
  for(int i=0;i<n;++i) {
    for(int j=0;j<n;++j) {
      for(int k=i+1;k<=n;++k) {
        dp[k][j+1] = min(dp[k][j+1], dp[i][j] + max(0ll, h[k] - h[i]));
      }
    }
  }

  ll mi = LINF;
  for(int i=1;i<=n;++i) {
    mi = min(mi, dp[i][n-k]);
  }
  cout << (mi == LINF ? 0 : mi) << endl;

}


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <stack>
#include <list>
#include <deque>
using namespace std;
int n, m, a, b, i, j, k, t=0;
int main(){
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>a>>b;
		t-=a;
		t+=b;
	}
	cout<<n+t;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <numeric>
#include <cassert>

#define endl '\n'
#define sp ' '

#define pb push_back
#define mp make_pair
#define ff first
#define ss second

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define MAXN 205

vector<int> adj[MAXN];

int visited[MAXN];

int bata[MAXN];

int main(){
    
    ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);cerr.tie(nullptr);
    
    int n;cin>>n;
    
    string s;
    for(int i=0;i<n;i++){
        cin>>s;
        for(int j=0;j<n;j++){
            if(s[j]-'0'){
                adj[i+1].pb(j+1);
                adj[j+1].pb(i+1);
            }
        }
    }
    
    queue<int> q;
    int num=0,maxnum=-0x7f7f7f7f;
    for(int i=1;i<=n;i++){
        memset(visited,0,sizeof visited);
        memset(bata,0,sizeof bata);
        q.push(i);
        visited[i]=1;
        bata[i]=1;
        bool truth = false;
        while(!q.empty()){
            int cur = q.front();q.pop();
            for(int t : adj[cur]){
                if(!visited[t]){
                    q.push(t);
                    visited[t]=1;
                    bata[t]=bata[cur]+1;
                }
                else{
                    if(abs(bata[t]-bata[cur])!=1){
                        truth=true; break;
                    }
                }
            }
        }
        if(!truth){
            for(int j=1;j<=n;j++)
                maxnum = max(maxnum,bata[j]);
        }
    }
    
    if(maxnum==-0x7f7f7f7f)
        cout<<-1<<endl;
    else
        cout<<maxnum<<endl;
    
}













Measured memory_bytes: 640
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input!(
        n : u32,
//        arr : [[i32; 3]; n],
        arr : [(i32,i32,i32); n],
    );

//    let mut arr : Vec<Vec<i32>> = arr;

//    arr.insert(0,vec![0,0,0]);
    let mut arr: Vec<(i32, i32, i32)> = arr;
    arr.insert(0, (0, 0, 0));
    let yes = arr[..].windows(2).all(|w| {
        let (t, x, y) = w[0];
        let (nt, nx, ny) = w[1];
        let time = nt - t;
        let dist = (nx - x).abs() + (ny - y).abs();
        dist <= time && time % 2 == dist % 2
    });
    println!("{}", if yes { "Yes" } else { "No" });
}

Measured memory_bytes: 6396
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int N,K,X,Y,ans;

int main(){
    cin>>N>>K>>X>>Y;
    rep(i,N){
        if(i>=K)ans+=Y;
        else ans+=X;
    }
    out(ans);
}


Measured memory_bytes: 256
input = require('fs').readFileSync('/dev/stdin', 'utf8')
lines = input.split('\n')
line = lines.shift().split(' ')
N = line[0] * 1
M = line[1] * 1
line = lines.shift().split(' ')
if (line.length <= N) {
    ans = 0
} else {
    x = line.sort((a,b) => a - b) 
    d = []
    for (i=0;i<M-1;i++) {
        d[i] = x[i+1] - x[i]
    }
    d = d.sort((a,b) => a - b)
    while(--N) {
        d.pop()
    }
    sum = 0
    for (i=0;i<d.length;i++) {
        sum += d[i]
    }
    ans = sum
}
console.log(ans)

Measured memory_bytes: 28952
n = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
data = [0, 0, 0]
ans = 1
for x in a:
    y = 0
    t = True
    for i in range(3):
        if data[i] == x:
            y += 1
            if t:
                t = False
                data[i] += 1
    ans *= y
    ans %= mod

print(ans)


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


int n,m;
int a[20]; 
int b[200];
set<int> number;
int main() {
  cin >>n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  cin >>m;
  for (int i = 0; i < m; ++i) cin >> b[i];
  bool exist = false;
  for (int bit = 0; bit < (1<<n); ++bit){
    int sum = 0; // 部分集合の和
    for (int i = 0; i < n; ++i) {
      if (bit & (1<<i)) { // i が S に入っているなら足す
        sum += a[i];
        number.insert(sum);
      }
    }
  }
  for(int i=0;i<m;i++){
    if(number.count(b[i])==1) cout << "yes" << endl;
    else cout << "no" << endl;
  }  
}


Measured memory_bytes: 3112
<?php
    /*
        Problem URL : http://abc059.contest.atcoder.jp/tasks/abc059_b

        Score  :
        Result :
        Time   : ms
        Memory : KB
     */

    ini_set('error_reporting', E_ALL & ~E_NOTICE);

    // define('DEBUG', true);
    define('DEBUG', false);

    if (DEBUG) {
        $start = microtime(true);
    }

    fscanf(STDIN, "%s", $A);
    fscanf(STDIN, "%s", $B);

    $lenA = strlen($A);
    $lenB = strlen($B);

    if ($lenA > $lenB) {
        echo "GREATER\n";
        exit;
    }
    if ($lenA < $lenB) {
        echo "LESS\n";
        exit;
    }
    if ($A == $B) {
        echo "EQUAL\n";
        exit;
    }
    if ($A > $B) {
        echo "GREATER\n";
    } else {
        echo "LESS\n";
    }


Measured memory_bytes: 4856
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
ll A,B,C,K;
int main(){
	cin>>A>>B>>C>>K;
	ll ans;
	if(K<=A+B){
		ans=min(K,A);
	}else{
		ans=A-(K-A-B);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main(void){
    string s,t;
    cin>>s>>t;
    sort(s.begin(),s.end());
    sort(t.rbegin(),t.rend());
    if(s<t){
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;
    
    return 0;
}

Measured memory_bytes: 256