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

using namespace std;

using ll = long long int;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vs = vector<string>;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

int n;
int f[100][40];
int p[100][41];

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

	cin >> n;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> f[i][j];
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 11; j++) {
			cin >> p[i][j];
		}
	}

	int res = -INF;
	for (int b = 1; b < (1 << 10); b++) {
		int cc = 0;
		for (int i = 0; i < n; i++) {
			int c = 0;
			for (int j = 0; j < 10; j++) {
				if ((b >> j & 1) && f[i][j]) {
					c++;
				}
			}
			cc += p[i][c];
		}
		res = max(res, cc);
	}

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


Measured memory_bytes: 256
def main():
	H, W, K = map(int, input().split())
	g = [input() for _ in range(H)]
	ans = 1 << 100
	for i in range(1 << H - 1):
		need = bin(i).count("1")
		sz = need + 1
		cnt = [0] * sz
		f = 1
		for j in range(W):
			c = 0
			for k in range(H):
				cnt[c] += g[k][j] == "1"
				if cnt[c] > K:
					break
				c += (i >> k) & 1
			else:
				continue
			cnt = [0] * sz
			need += 1
			if need > ans:
				f = 0
				break
			c = 0
			for k in range(H):
				cnt[c] += g[k][j] == "1"
				if cnt[c] > K:
					break
				c += (i >> k) & 1
			else:
				continue
			f = 0
			break
		if f:
			ans = min(ans, need)
	print(ans)

if __name__ == '__main__':
	main()

Measured memory_bytes: 3064
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <map>
#include <vector>
//#include <unordered_map>
//#include <unordered_set>
#include <stack>
#include <set>
#include <queue>
#include <list>

using namespace std;
int main()
{
	int n,t,k,r,l;
	long long su=0;
	scanf("%d%d",&n,&t);
	scanf("%d",&l);
	r=l+t;
	for(int i=1;i<n;++i)
	{
		scanf("%d",&k);
		if(k>r)
		{
			su+=r-l;
			l=k;
			r=k+t;
		}
		r=k+t;
	}
	su+=r-l;
	cout<<su<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <assert.h>
#include <numeric>

using namespace std;

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

int main()
{
  double R;
  cin >> R;
  cout << 2 * 3.141592 * R << endl;
}


Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
int main()
{
string S,T;
  cin >> S >> T;
  int a;
  int b=1;
  a = S.size();
  for (int i=0; i<a ; i++)
  {
    if ( S.at(i) == T.at(i)){}
    else 
    {
      b=0;
    }
  }
  if ( b == 0)
  {
    cout << "No" << endl;
  }
  if ( b == 1)
  {
    cout << "Yes" << endl;
  }
}

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


using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(ll i=st; i<ed; i++)
#define repn(i, st, ed) for(ll i=st; i<=ed; i++)
#define repb(i, ed, st) for(ll i=ed; i>=st; i--)
#define all(v) v.begin(),v.end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 1e5 + 10;
const ll INF = 1LL << 60;

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



// Main Code
ll ppow(ll x, ll y, ll mod)
{
  ll res = 1;
  while(y > 0){
    if(y&1)
      res = (res * x)%mod;
    y = y >> 1;
    x = (x * x)%mod;
  }
  return res;
}


ll factdp[N];
ll fact(ll x)
{
  if(x == 0) return 1;
  if(x == 1) return 1;
  if(factdp[x] != 0) return factdp[x];
  return factdp[x] = (x*fact(x-1))%M;
}
// Combination
ll modcomb(ll n, ll r)
{
  if(n < r) return 0;
  ll res = fact(n);
  (res *= ppow(fact(r), M-2, M)) %= M;
  (res *= ppow(fact(n-r), M-2, M)) %= M;
  return res;
}

int main()
{
	ll n, k;
	cin>>n>>k;
	ll ans = 0;
	ll x = n - k;
	ll y = k;
	repn(i, 1, k)
	{
		ans = ((modcomb(x+1, i) * modcomb(y-1, i-1))%M)%M;
		cout<<ans<<endl;
	}
	// cout<<ans<<endl;
}



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

// _ÀWð^Æ·é
typedef complex<double> P;
// ÎÌè`
#define PI 3.1415926535898

// e·éë·Ã
#define EPS (1e-10)
//XYÀW
#define X real()
#define Y imag()
	
// Op`NX
class Triangle{

private:
	//Op`ÌR_ÌÀW
	P a, b, c;
	//Op`ÌRÓÌ·³
	double edgeA,edgeB,edgeC;
	//Op`ÌRpÌå«³(WA)
	double angleA,angleB,angleC;
	//]·è©çRÂÌpxðßéÖ
	double LawOfCosines(double a,double b, double c){
		return acos( (b*b+c*c-a*a) / (2.0*b*c) );
	}
	//QÂÌdouble^Ìlªµ¢©Ç¤©
	bool equal(double a, double b){
		return (abs( a-b ) < EPS)? true : false ;
	}

public:
	//RXgN^(RÂÌ_ÆÓÆpxðú»)
	Triangle(P p1, P p2, P p3){
		a = p1;
		b = p2;
		c = p3;
		edgeB = abs(c-a);
		edgeA = abs(b-c);
		edgeC = abs(a-b);
		angleA = LawOfCosines(edgeA,edgeB,edgeC);
		angleB = LawOfCosines(edgeB,edgeC,edgeA);
		angleC = LawOfCosines(edgeC,edgeA,edgeB);
	}
	
	double circumscribedCircleRadius(){//OÚ~Ì¼aðÔ·
		return ( edgeA / sin(angleA) / 2.0 );
	}
	double circumscribedCircleX(){//OS(OÚ~ÌS)ÌXÀWðÔ·
		double A = sin(2.0*angleA);
		double B = sin(2.0*angleB);
		double C = sin(2.0*angleC);
		return ( (a.X * A + b.X * B + c.X * C) / (A+B+C) );
	}
	double circumscribedCircleY(){//OS(OÚ~ÌS)ÌYÀWðÔ·
		double A = sin(2.0*angleA);
		double B = sin(2.0*angleB);
		double C = sin(2.0*angleC);
		return ( (a.Y * A + b.Y * B + c.Y * C) / (A+B+C) );
	}
};

int main(){
	int n;
	double x1, x2, x3, y1, y2, y3;
	double r, xp, yp;

	scanf("%d", &n);
	for (int i=0 ; i<n ; i++){
		scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3);
		P a( x1 , y1 );
		P b( x2 , y2 );
		P c( x3 , y3 );
		Triangle Tr(a,b,c);
		r  = Tr.circumscribedCircleRadius();
		xp = Tr.circumscribedCircleX();
		yp = Tr.circumscribedCircleY();
		printf("%.3f %.3f %.3f\n", xp,yp,r);
	}
}

Measured memory_bytes: 0
#include <map>
#include <set>
#include <list>
#include <cstdio>
#include <cmath>
#include <deque>
#include <stack>
#include <bitset>
#include <cctype>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define fr first
#define sc second
#define mp make_pair
#define foreach(c, it) for(typeof(c) it = (c).begin(); it != (c).end(); it++)

typedef long long int64;
typedef pair< int, int > iP;
typedef pair< iP, int > iiP;

const int INF = 2 << 28;
const double EPS = 1e-10;

#define MAX 1000000

int main() {
    
    vector< bool > p(MAX, true);
    p[0] = p[1] = false;
    for(int i = 2; i * i < MAX; i++)
        if(p[i])
            for(int j = i + i; j < MAX; j += i)
                p[j] = false;
    
    int a, d ,n;
    while(cin >> a >> d >> n, d) {
        int cnt = 0;
        for(int i = 1; ; i++) {
            int sum = a + (i - 1) * d;
            if(p[sum]) cnt++;
            if(cnt == n) {
                cout << sum << endl;
                break;
            }
        }
    }
}

Measured memory_bytes: 1316
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;//1000000000 + 7 998244353 924844033 1000000000 + 9;
constexpr long long INF = numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<double, double> Dll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourth; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
struct Edge { LL to, cost; };
struct edge {
	LL from, to, cost;
};
vector<vector<LL>>g;
vector<edge>ed;
vector<Pll>pv;
map<string, LL>ma;
set<LL>st;
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
LL n, m, p, q, w, h, ans, cnt,a[200000], b[200000],dp[1100][1100],sum[200000];
string str;
bool f;
char c[1100][1100];

int main() {
	cin >> h >> w;
	rep(i, h) {
		rep(j, w) {
			cin >> c[i][j];
		}
	}
	
	queue<Pll>qu;
	rep(i, h) {
		rep(j, w) {
			if (c[i][j] == '#') {
				dp[i][j] = 0;
				qu.push(Pll(i, j));
			}
			else {
				dp[i][j] = INF;
			}
		}
	}
	while (!qu.empty()) {
		LL x = qu.front().first, y = qu.front().second;
		qu.pop();
		rep(i, 4) {
			LL X = di[i][0] + x, Y = di[i][1] + y;
			if (X >= 0 && Y >= 0 && X < h&&Y < w) {
				if (dp[X][Y] > dp[x][y] + 1) {
					dp[X][Y] = dp[x][y] + 1;
					qu.push(Pll(X,Y));
				}
			}
		}
	}
	rep(i, h)rep(j, w) {
		ans = max(ans,dp[i][j]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 27956
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
use rand::prelude::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::f64::consts::*;
use std::time::*;

#[allow(unused)]
const INF: usize = std::usize::MAX / 4;
#[allow(unused)]
const M: usize = 1000000007;

fn calc_score(t: &Vec<usize>, c: &Vec<isize>, s: &Vec<Vec<isize>>) -> isize {
    let n = c.len();
    let d = t.len();
    let mut last = vec![0; n];
    let mut score = 0;
    for i in 0..d {
        let ti = t[i];
        score += s[i][ti];
        last[ti] = i + 1;
        for j in 0..n {
            score -= c[j] * (i + 1 - last[j]) as isize;
        }
    }
    score
}

fn initial_guess(c: &Vec<isize>, s: &Vec<Vec<isize>>) -> Vec<usize> {
    let n = c.len();
    let d = s.len();
    let mut t = vec![0; d];
    let mut last = vec![0; n];
    for i in 0..d {
        t[i] = (0..n)
            .max_by_key(|&j| {
                s[i][j]
                    - (0..n)
                        .map(|k| c[k] * (i + 1 - last[k]) as isize)
                        .sum::<isize>()
            })
            .unwrap();
        last[t[i]] = i + 1;
    }
    t
}

fn improve<R: Rng>(
    t: &mut Vec<usize>,
    score: isize,
    c: &Vec<isize>,
    s: &Vec<Vec<isize>>,
    rng: &mut R,
) -> isize {
    let n = c.len();
    let d = s.len();
    let di = rng.gen_range(0, d);
    let old = t[di];

    let mut last = vec![0; n];
    for i in 0..di {
        last[t[i]] = i + 1;
    }
    let mut next = vec![d; n];
    for i in di + 1..d {
        next[t[i]] = i + 1;
    }

    t[di] = (0..n)
        .max_by_key(|&j| {
            s[di][j] + c[j] * (di + 1 - last[j]) as isize
                - s[di][old]
                - c[old] * (next[old] + 1 - di) as isize
        })
        .unwrap();

    let new_score = calc_score(&t, &c, &s);
    if new_score <= score {
        t[di] = old;
        score
    } else {
        new_score
    }
}

fn main() {
    let start = SystemTime::now();
    let limit = Duration::from_millis(1800);
    let n = 26;
    input! {
        d: usize,
        c: [isize; n],
        s: [[isize; n]; d],
    }
    let mut t = initial_guess(&c, &s);
    let mut rng = thread_rng();
    let mut score = calc_score(&t, &c, &s);
    eprintln!("{}", score);
    loop {
        score = improve(&mut t, score, &c, &s, &mut rng);
        if start.elapsed().unwrap() >= limit {
            break;
        }
    }
    eprintln!("{}", score);
    for &ti in &t {
        println!("{}", ti + 1);
    }
}


Measured memory_bytes: 2744
#include <iostream>
#include <stack>
#include <vector>

using namespace std;

int main(){
    int n;
    cin >> n;
    int G[n][n];
    for (int i =0; i<n; i++) {
        for (int j =0; j<n; j++) {
            G[i][j] = 0;
        }
    }
    for (int i=0;i<n;i++) {
        int p,m;
        cin >>p >> m;
        for (int j=0; j<m; j++) {
            int q;
            cin >> q;
            G[p-1][q-1]=1;
        }
    }
    for (int i =0; i<n; i++) {
        for (int j =0; j<n; j++) {
            cout << G[i][j];
            if(j!=n-1) cout << " ";
        }
        cout << endl;
    }

}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
#define all(V) V.begin(),V.end()
#define FINISH cout<<"NO"<<endl;return 0
using ll = long long;
const ll MOD = 1000000007;

char ans[1010][1010];

void tile(int& A, int& B, int N, int M) {
	for (int i = 0;i < N;i += 2) {
		for (int j = 0;j < M;j += 2) {
			if (A > 1) {
				ans[i][j] = '<';
				ans[i][j + 1] = '>';
				ans[i + 1][j] = '<';
				ans[i + 1][j + 1] = '>';
				A -= 2;
			}
			else if (B > 1) {
				ans[i][j] = '^';
				ans[i + 1][j] = 'v';
				ans[i][j + 1] = '^';
				ans[i + 1][j + 1] = 'v';
				B -= 2;
			}
			else if (A == 1) {
				ans[i][j] = '<';
				ans[i][j + 1] = '>';
				A = 0;
			}
			else if (B == 1) {
				ans[i][j] = '^';
				ans[i + 1][j] = 'v';
				B = 0;
			}
		}
	}
}

void say(int N, int M) {
	cout << "YES\n";
	for (int i = 0;i < N;i++) {
		for (int j = 0;j < M;j++)
			cout << ans[i][j];
		cout << "\n";
	}
}

int main() {
	int N, M, A, B;
	cin >> N >> M >> A >> B;
	int T = N * M;
	for (int i = 0;i < N;i++)for (int j = 0;j < M;j++)ans[i][j] = '.';

	if (A + B > T / 2) {
		FINISH;
	}

	if (T & 1) {
		int MA = N * (M / 2);
		int MB = M * (N / 2);
		if (MA < A) {
			FINISH;
		}
		if (MB < B) {
			FINISH;
		}

		//すべてをMAに使う
		for (int i = 0;i < M - 1;i += 2) {
			if (A > 0) {
				ans[N - 1][i] = '<';
				ans[N - 1][i + 1] = '>';
				A--;
			}
		}
		for (int i = 0;i < N - 1;i += 2) {
			if (B > 0) {
				ans[i][M - 1] = '^';
				ans[i + 1][M - 1] = 'v';
				B--;
			}
		}
		tile(A, B, N - 1, M - 1);
		if (B == 1) {
			ans[N - 2][M - 3] = '^';
			ans[N - 1][M - 3] = 'v';
			ans[N - 1][M - 2] = '<';
			ans[N - 1][M - 1] = '>';
			B--;
		}
		say(N, M);
	}
	else {
		T /= 2;
		if (N & 1) {
			for (int i = 0;i < M;i += 2) {
				if (A > 0) {
					ans[N - 1][i] = '<';
					ans[N - 1][i + 1] = '>';
					A--;
				}
			}
			tile(A, B, N - 1, M);
			
			if (A > 0 || B > 0) {
				FINISH;
			}
			say(N, M);
		}
		else if (M & 1) {
			for (int i = 0;i < N;i += 2) {
				if (B > 0) {
					ans[i][M - 1] = '^';
					ans[i + 1][M - 1] = 'v';
					B--;
				}
			}

			tile(A, B, N, M - 1);

			if (A > 0 || B > 0) {
				FINISH;
			}
			say(N, M);
		}
		else {
			tile(A, B, N, M);
			if (A > 0 || B > 0) {
				FINISH;
			}
			say(N, M);
		}
	}
}

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

int main() {
  int n;
  double sum = 0;
  cin >> n;
  for(int i = 0;i < n;i++){
    double x;
    string u;
    cin >> x >> u;
    if(u == "JPY"){
      sum += x;
    }
    else{
      sum += x*380000;
    }
  }
  cout << sum << endl;
}

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

int main() {
  int n, m, c, ans = 0; cin >> n >> m >> c;
  vector<int> b(m); rep(i, m) cin >> b[i];
  vector<vector<int>> a(n, vector<int>(m));
  rep(i, n) rep(j, m) cin >> a[i][j];
  rep(i, n) {
    int sum = 0;
    rep(j, m) sum += a[i][j] * b[j];
    if (sum + c > 0) ans++;

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

Measured memory_bytes: 256
import java.util.*;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
        String A = sc.next();
        String B = sc.next();
        String C = sc.next();
        char A_last = A.charAt(A.length()-1);
        char B_first = B.charAt(0);
        char B_last = B.charAt(B.length()-1);
        char C_first = C.charAt(0);
        if(A_last == B_first && B_last == C_first){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
	}
}

Measured memory_bytes: 21844
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
using namespace std;

typedef long long ll;

const ll Inf = 1000000000000000000ll;
const int Maxn = 200005;

int n;
int a[Maxn];
ll sum[Maxn];
ll res = Inf;

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]); sum[i] = a[i] + sum[i - 1];
	}
	for (int i = 1; i < n; i++)
		res = min(res, abs(sum[i] - (sum[n] - sum[i])));
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 2560
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		String t = sc.nextLine();

		int[][] next = new int[s.length()]['z' - 'a' + 1];
		for (int i = 0; i < next.length; i++) {
			Arrays.fill(next[i], -1);
		}

		String ss = s.concat(s);

		List<Integer>[] cis = new ArrayList[26];
		for (int i = 0; i < cis.length; i++) {
			cis[i] = new ArrayList<>();
		}

		for (int i = 0; i < ss.length(); i++) {
			cis[ss.charAt(i) - 'a'].add(i);
		}

		for (int i = 0; i < cis.length; i++) {
			Collections.sort(cis[i]);
		}

		for (int i = 0; i < s.length(); i++) {
			for (int j = 0; j < 26; j++) {
				next[i][j] = lowerBound(cis[j], i);
			}
		}

		//for (int i = 0; i < next.length; i++) {
		//	for (int j = 0; j < next[i].length; j++) {
		//		System.out.print(next[i][j]);
		//		System.out.print(" ");
		//	}
		//	System.out.println();
		//}

		long a = 0;
		int current = 0;
		for (int i = 0; i < s.length(); i++) {
			if (s.charAt(i) == t.charAt(0)) {
				current = i;
				a += i;
				break;
			}
		}

		if (current == 0 && s.charAt(0) != t.charAt(0)) {
			System.out.println(-1);
			return;
		}

		for (int i = 1; i < t.length(); i++) {
			int nx = next[current][t.charAt(i) - 'a'];
			if (nx == -1) {
				System.out.println(-1);
				return;
			}

			a += nx - current;
			current = nx % s.length();
		}

		System.out.println(a + 1);
	}

	private static int lowerBound(List<Integer> a, int x) {
		if (a == null || a.size() == 0) return -1;

		int l = -1, r = a.size() - 1;
		while (r - l > 1) {
			int m = (l + r) / 2;
			if (a.get(m) <= x) {
				l = m;
			} else {
				r = m;
			}
		}

		if (r == a.size() - 1 && a.get(r) < x) return -1;
		return a.get(r);
	}
}


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

#define MAX 1000000010
#define INF 99999999
#define MIN -99999999
#define in(a,b)  ( (b).find(a) != (b).end())
#define clr(a,b) memset((a), (b), sizeof((a)))
#define pb       push_back
#define all(a)   a.begin(), a.end()
#define mp       make_pair
#define ll	long long
#define FI	first
#define SE second

using namespace std;
int a,b;
string s;
int main() {
  
  cin >> a >> b ;
  cin >> s;
  if(a+b+1!= s.length()){
    cout << "No" << endl;
    return 0;
  }
  else{
    for(int i=0; i<a; i++){
      if(s[i] <'0' || s[i] >'9'){
        cout << "No" << endl;
        return 0;
      }
    }
    if(s[a] != '-') {
        cout << "No" << endl;
        return 0;
    }
    for(int i=a+1; i<a+b+1; i++){
      if(s[i] <'0' || s[i] >'9'){
        cout << "No" << endl;
        return 0;
      }
    }
    cout << "Yes" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n=n0()
a=n1()

c=[min(x%3,x%5) if x%2==0 else 0 for x in a]
print("APPROVED" if sum(c)==0 else "DENIED")

Measured memory_bytes: 3064
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::iter::FromIterator;

fn main() {
    let cin = stdin();
    let mut scan = Scanner::new(cin.lock());
    let n = scan.read::<usize>();
    let a = arr(n, |_| scan.read::<usize>()-1);
    let b = scan.readn::<i64>(n);
    let c = scan.readn::<i64>(n-1);
    let mut ret = 0;
    for i in 0..n {
        ret += b[a[i]];
        if i >= 1 && a[i-1] + 1 == a[i] {
            ret += c[a[i-1]];
        }
    }
    println!("{}", ret);
}

// region template
#[allow(dead_code)]
fn iu(i: isize) -> usize { i as usize }

#[allow(dead_code)]
fn ui(i: usize) -> isize { i as isize }

#[allow(dead_code, deprecated)]
fn join<T: std::fmt::Display>(slice: &[T], sep: &str) -> String {
    let strings = slice.iter().map(|t| format!("{}", t)).collect::<Vec<_>>();
    strings.connect(sep)
}

#[allow(dead_code)]
fn arr<'a, S, T>(n: usize, mut f: S) -> Vec<T> where S: FnMut(usize) -> T + 'a {
    (0..n).map(|i| f(i)).collect::<Vec<T>>()
}

#[allow(dead_code)]
fn alt<S, T>(v: Vec<S>) -> T where T: FromIterator<S> {
    v.into_iter().collect::<T>()
}

#[allow(dead_code)]
fn dup<S, T>(v: &[S]) -> T where T: FromIterator<S>, S: Clone {
    v.iter().cloned().collect::<T>()
}

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }

    fn readn<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect()
    }

    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
// endregion

Measured memory_bytes: 4352
/**
*    created: 03.05.2020 21:00:14
**/

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

int main() {
    string s;
    cin >> s;  
    if(s[1]=='B'){
        cout << "ARC" << endl;
    }else{
        cout << "ABC" << endl;
    }
}

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

int main() {
    int N;
    cin >> N;
    vector<string> S(N);
    vector<int> P(N);
    for (int i = 0; i < N; i++) {
        cin >> S[i] >> P[i];
    }

    vector<int> order(N);
    iota(order.begin(), order.end(), 0);

    sort(order.begin(), order.end(), [&](int i, int j) {
        if (S[i] == S[j]) { // 文字列が同じなら数値が大きい方を優先させる
            return P[i] > P[j];
        } else { // それ以外なら文字列の辞書順が小さい方を優先させる
            return S[i] < S[j];
        }
    });

    for (int i = 0; i < N; i++) {
        cout << order[i] + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n;
  cin>>n;
  vi L(n);
  rep(i,n)cin>>L[i];
  sort(rng(L));

  int ans = 0;
  rep(i,n){
    rep(j,i){
      int y = L[i]+L[j];
      auto it = lower_bound(rng(L),y);
      int m = distance(L.begin(),it);
      int l = i+1;
      ans+=m-l;
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
//abc165-D//

//#include <math.h>
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#include<stdio.h>
#include <iostream>
#include <vector>
//#include <string.h>
using namespace std;

int main(){
    long a, b, n;
    cin >> a >> b >> n;
    long ans =0;
    if(n<b-1)
        ans = (long)(a*n/b);
    else
        ans = (long)(a*(b-1)/b);
    
    cout << ans <<endl;
    return 0;
}


Measured memory_bytes: 3596
#include<iostream>
#include<iomanip>
#include<cassert>
#include<math.h>
#include<complex>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll N;
ll A[200010];
unordered_map<ll,ll> mpI,mpJ;
int main(){
    cin>>N;
    for(ll i=0;i<N;i++)cin>>A[i];
    for(ll i=0;i<N;i++){
        mpI[A[i]+i]++;
        mpJ[i-A[i]]++;
    }
    ll ans=0;
    for(ll i=0;i<N;i++){
        ans+=mpJ[A[i]+i];
        ans-=((A[i]+i)==(i-A[i]));
        ans+=mpI[i-A[i]];
        ans-=((i-A[i])==(A[i]+i));
    }
    cout<<ans/2<<endl;

    return 0;
}

Measured memory_bytes: 35428
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf (ll)(1e18)
#define mod 1000000007


int main()
{
    int t=1;
    //cin>>t;
    while( t-- )
    {
        int n,x,t ;
        cin>>n>>x>>t;
        if( n<=x )
        {
            cout<<t;
        }
        else
        {
            if( n%x==0 )
            {
                ll ans=n/x;
                ans=ans*t;
                cout<<ans;
            }
            else
            {
                ll ans=n/x;
                ans++;
                ans=ans*t;
                cout<<ans;
            }

        }
    }

    return 0;
}












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

#define dbg(x) cerr<<#x": "<<x<<"\n"
#define dbg_p(x) cerr<<#x": "<<x.first<<","<<x.second<<"\n"
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

#define st first
#define nd second

#define DMAX 
#define NMAX 
#define MMAX 

using namespace std;

int n, k, a, b, mat[551][551];
const int N = 100;

template<class T>
ostream& operator<<(ostream& out, vector<T> v) {
	out << v.size() << '\n';
	for(auto e : v) out << e << ' ';
	return out;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin >> a >> b;
	a--;
	b--;
	//white part
	for(int i = 1; i <= N / 2; i++)
		for(int j = 1; j <= N; j++) 
		{
			mat[i][j] = 1;
		}

	for(int i = 1; i <= N / 2; i += 2)
		for(int j = 1; j <= N; j += 2) {
			if(a) mat[i][j] = 0, a--;
		}


	for(int i = N / 2 + 2; i <= N; i += 2)
		for(int j = 1; j <= N; j += 2) {
			if(b) mat[i][j] = 1, b--;
		}
		cout << N << ' ' << N << '\n';

	for(int i = 1; i <= N; i++) {
		for(int j = 1; j <= N; j++) {
			cout << (mat[i][j] ? '#' : '.');
		}
		cout << '\n';
	}
} 	

Measured memory_bytes: 384
#include <iostream>

using namespace std;
const int s= 1e5+5;
int data[s][3];
int dp [s][3];
int n;
int vacation(int a,int i){
if(i == n) return 0;
	if(dp[i][a] != -1) return dp[i][a];
	int& ans = dp[i][a];

	if(a==0){
		ans=max(ans, vacation(1, i+1)+data[i][0]);
		ans=max(ans, vacation(2, i+1)+data[i][0]);
	}
	if(a==1){
		ans=max(ans, vacation(0, i+1)+data[i][1]);
		ans=max(ans, vacation(2, i+1)+data[i][1]);
	}
	if(a==2){
		ans=max(ans, vacation(0, i+1)+data[i][2]);
		ans=max(ans, vacation(1, i+1)+data[i][2]);
	}

	return ans;
}

int main()
{
 cin >> n;
    for(int i=0;i<n;i++){
        for(int j=0; j<3;j++){
            cin >> data[i][j];
            dp[i][j]=-1;
        }

    }
 int result = max(max(vacation(0,0),vacation(1,0)),vacation(2,0));
    cout << result << endl;
 return 0;

}

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

using namespace std;
using ll = long long;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n; cin >> n;
  string res = "";
  while(n) {
    n--;
    res += (char)((n % 26) + 'a');
    n /= 26;
  }
  reverse(res.begin(), res.end());
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=n-1; i>=m; i--)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;

ll POW(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW(x*x%MOD,n/2);
  return x*POW(x,n-1)%MOD;
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, x, y);
    return mod(x, MOD);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD;
}

ll DEC(ll x,ll m,ll n)
{
  return x%POW(m,n+1)/POW(m,n);
}

ll keta(ll x,ll n)
{
  if(x==0)return 0;
  return keta(x/n,n)+1;
}

ll DIV(ll x,ll n)
{
  if(x==0)return 0;
  return x/n+DIV(x/n,n);
}


int main()
{
  ll n,a,b,p[120],x,y,z;
  x=0;
  y=0;
  z=0;
  cin >> n >> a >> b;
  rep(i,n)cin >> p[i];
  rep(i,n){if(p[i]<=a)x++;
           else if(p[i]<=b)y++;
           else z++;
          }
  printf("%lld",min({x,y,z}));
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		String S[] = new String[n];
		Map<String, Integer> map[] = new TreeMap[n];
		String abc[] = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
		for(int i = 0; i < n; i++) {
			map[i] = new TreeMap<String, Integer>();
			for(int j = 0; j < abc.length; j++) {
				map[i].put(abc[j], 0);
			}
		}
		for(int i = 0; i < n; i++) {
			S[i] = sc.next();
			for(int j = 0; j < S[i].length(); j++) {
				String str = S[i].substring(j, j + 1);
				map[i].put(str, map[i].get(str) + 1);
			}
		}
		
		String ans = "";
		for(int i = 0; i < 26; i++) {
			int temp = Integer.MAX_VALUE;
			for(int j = 0; j < n; j++) {
				temp = Math.min(map[j].get(abc[i]), temp);
			}
			ans += repeat(abc[i], temp);
		}
		System.out.println(ans);
	}
	
	public static String repeat(String str, int n) {
		String rs = "";
		for(int i = 0; i < n; i++) {
			rs += str;
		}
		return rs;
	}
}


Measured memory_bytes: 23636
#include<bits/stdc++.h>
using namespace std;
int n;
double p;
double dp[3000][3000];
int main() {
	scanf("%d",&n);
	dp[0][0]=1;
	for(int i=1; i<=n; i++) {
		scanf("%lf",&p);
		for(int j=0; j<=i; j++) {
			dp[i][j]=dp[i-1][j]*(1-p);
			if(j>0) dp[i][j]+=dp[i-1][j-1]*p;
		}
	}
	double ans=0;
	for(int i=n/2+1; i<=n; i++) {
		ans+=dp[n][i];
	}
	printf("%.12f\n",ans);
}

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

int main() {
  while(true) {
    int N; cin >> N;
    if(N == 0) break;
    vector<vector<int>> G(N, vector<int>(5));
    for(int i = 0; i < N; ++i) {
      for(int j = 0; j < 5; ++j)
        cin >> G[i][j];
    }
    int point = 0;
    while(true) {
      bool update = false;
      // ブロックを消す
      for(int i = 0; i < N; ++i) {
        for(int j = 0; j < 5; ++j) {
          if(G[i][j] == 0) continue;
          int s = 0;
          for(int k = j; k < 5; ++k) {
            if(G[i][k] == G[i][j]) ++s;
            else break;
          }
          if(s >= 3) {
            update = true;
            for(int k = j; k < j + s; ++k) {
              point += G[i][k];
              G[i][k] = 0;
            }
          }
        }
      }
      if(!update) break;
      // ブロックを落とす
      for(int i = N - 1; i >= 0; --i) {
        for(int j = 0; j < 5; ++j) {
          if(G[i][j] == 0) {
            int t = -1;
            for(int k = i - 1; k >= 0; --k) {
              if(G[k][j] != 0) {
                t = k;
                break;
              }
            }
            if(t != -1) {
              G[i][j] = G[t][j];
              G[t][j] = 0;
            }
          }
        }
      }
#if 0
      for(int i = 0; i < N; ++i) {
        for(int j = 0; j < 5; ++j) {
          cerr << G[i][j];
        }
        cerr << endl;
      }
#endif
    }
    cout << point << endl;
  }
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
	string s, t;
	cin >> s >> t;
	sort(all(s));
	sort(rall(t));
	if (s  < t) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}



Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define Phuong_ ios_base::sync_with_stdio(0); cin.tie(0);
#define REP(i,a,b) for(int i=a; i<=b; ++i)

/// easy access -------------
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
typedef pair<int,int> pi;
typedef tuple<bool, int, int> tp;
typedef vector<vector<int>> vv;
///-------------------------


int main()
{
    Phuong_; /// <3333
    int n;
    cin >> n;
    vector<int> a(n);
    for(int &x:a) cin >> x;
    int ans=0;
    for(int i=0; i<n-2; ++i){
        for(int j=i+1; j<n-1; ++j){
            for(int k=j+1; k<n; ++k){
                if (a[i]!=a[j] && a[j]!=a[k] && a[i]!=a[k]){
                    if (a[i]+a[j]>a[k] && a[j]+a[k]>a[i] && a[i]+a[k] > a[j]) ans++;
                }
            }
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3652
import math

n = int(input())
p1 = (0, 0)
p2 = (100, 0)
points = []

def koch(n, p, q):
    if n == 0:
        return

    x1, y1 = p
    x2, y2 = q
    sx = (2 * x1 + 1 * x2) / 3
    sy = (2 * y1 + 1 * y2) / 3
    s = (sx, sy)
    tx = (1 * x1 + 2 * x2) / 3
    ty = (1 * y1 + 2 * y2) / 3
    t = (tx, ty)
    theta = math.pi / 3
    ux = (tx - sx) * math.cos(theta) - (ty - sy) * math.sin(theta) + sx
    uy = (tx - sx) * math.sin(theta) + (ty - sy) * math.cos(theta) + sy
    u = (ux, uy)

    koch(n - 1, p, s)
    print(*s)
    koch(n - 1, s, u)
    print(*u)
    koch(n - 1, u, t)
    print(*t)
    koch(n - 1, t, q)


print(*p1)
koch(n, p1, p2)
print(*p2)



Measured memory_bytes: 5784
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define mem(a,k) memset(a,k,sizeof(a))
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

#define Pr(f,...) //fprintf(stderr,f,##__VA_ARGS__),fflush(stderr)

typedef long long ll;

template<typename T>
void read(T &x){
	x=0; 
	char c;
	for(c=getchar();!isdigit(c);c=getchar()); 
	for(;isdigit(c);c=getchar())x=x*10+c-'0'; 
}

const int N=1e5+50;

int n,f[N],A,B,fail;
vector<int> g[N]; 

void dfs(int v,int p){
	int x=p>0;
	f[v]=p>0;
	for(int d:g[v])if(d!=p){
		++x; dfs(d,v); f[v]+=f[d];
	}
	f[v]-=x/2;
	Pr("dfs %d,%d,f=%d\n",v,p,f[v]); 
}

int G[N];
void dp2(int v,int p){
	vector<int> a; if(p>0)a.pb(1);
	for(int d:g[v])if(d!=p){dp2(d,v);a.pb(G[d]);}
	sort(all(a));if(a.size()&1){
		int Z=0;for(int l=1,r=a.size()-1;l<=r;++l,--r)if(a[l]+a[r]>B)Z=1;
		if(!Z){G[v]=1;return;}
		a.pop_back();
	}
	if(a.empty()){G[v]=1;return;}
	int m=a.size();
	lop(i,0,m)if(a[i]+a[m-1-i]>B)fail=1;
	int L=0,R=m-1;
	while(R-L>1){
		int mid=(L+R)>>1,Fail=0;
		vector<int> b;lop(i,0,m)if(i>0&&i!=mid)b.pb(a[i]);
		lop(i,0,b.size())if(b[i]+b[b.size()-1-i]>B)Fail=1;
		if(!Fail)R=mid;else L=mid;
	}
	G[v]=a[R]+1;Pr("v=%d,g=%d\n",v,G[v]);
}

bool chk(int x){
	B=x,fail=0;
	Pr("Chk %d\n",x); 
	dp2(1,0);
	return !fail;
}
int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
freopen("d.in","r",stdin);freopen("m.out","w",stdout); 
#endif
	read(n); 
	rep(i,1,n-1){
		int u,v;
		read(u),read(v); 
		g[u].pb(v),g[v].pb(u); 
	}
	dfs(1,0);
	A=f[1];
	int l=0,r=n-1;
	while(r-l>1){
		int mid=(l+r)>>1;
		if(chk(mid))r=mid;else l=mid;
	}
	printf("%d %d\n",A,r);
	return 0;
}

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

using ll=long long;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

signed main(){
	// your code goes here
	string S;
	cin >> S;
	int i=0;
	int flag=0;
	while(i<S.size()){
		if(S.substr(i,i+5)=="dream"){
			flag=1;
			S.erase(i,i+5);
			continue;
		}
		else if(S.substr(i,i+5)=="erase"){
			flag=2;
			S.erase(i,i+5);
			continue;
		}
		if(flag==1&&S.substr(i,i+2)=="er"){
			flag=0;
			S.erase(i,i+2);
			continue;
		}
		if(flag==2&&S.substr(i,i+1)=="r"){
			flag=0;
			S.erase(i,i+1);
			continue;
		}
		cout << "NO";
		return 0;
	}
	cout << "YES";
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	vl a(n);
	cin>>a;
	sort(all(a));
	ll ans=0;
	for(int i=0;i<n;i+=2){
		if(i+1==n)ans+=a[i];
		else ans+=abs(a[i]+a[i+1]);
	}
	puta(ans);

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1LL << 60;
#define LLINF 1e12
#define PI 3.14159265359
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int ny, nx;
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

ll llmin(ll x, ll y) { return x < y ? x : y; }
ll llmax(ll x, ll y) { return x > y ? x : y; }

template <typename Container>
bool exist_in(const Container &c, const typename Container::value_type &v)
{
    return (c.end() != std::find(c.begin(), c.end(), v));
}

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

//std::cout << std::defaultfloat << std::setprecision(10);
////////////////////////////////////////
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    int N; cin >> N;
    ll sum=0;

    FOR(i,1,N+1){
        if(i%3!=0 and i%5!=0 and i%15!=0) sum+=i;
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 3632
///-----Bismillahir Rahmanir Rahim-----///

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

///---FAST I/O---///
#define Boost() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

///---DATA TYPE---///
typedef long long ll;
typedef long long int lli;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<int>::iterator vit;
typedef set<int>::iterator sit;

///---LOOP---///
#define rep0(i,n) for(i=0;i<n;i++)
#define rep1(i,n) for(i=1;i<=n;i++)

///---I/O---///
#define sf scanf
#define pf printf

///---OTHERS---///
#define pb push_back
#define all(c)		c.begin(),c.end()
#define MK make_pair
#define F first
#define S second
#define endl '\n'


///---INITIALIZATION---//
#define mem(a,b) memset(a, b, sizeof(a) )

///---CALCULATE---///
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) ((a) * (a))

///---BIT OPERATION---///
inline bool checkBit(ll n, int i)
{
    return n&(1LL<<i);
}
inline ll setBit(ll n, int i)
{
    return n|(1LL<<i);;
}
inline ll resetBit(ll n, int i)
{
    return n&(~(1LL<<i));
}

///------String/Char Related Functions-----///
string makeintString(int x)
{
    stringstream ss;
    ss << x;
    string str = ss.str();
    ///cout<<str<<endl;
    return str;
}
string makellString(ll x)
{
    stringstream ss;
    ss << x;
    string str = ss.str();
    ///cout<<str<<endl;
    return str;
}
char cpp(char c)
{
    return static_cast<char>(c + 1);
}

///------------Sorting STL----------///
struct func
{
	//this is a sample overloading function for sorting stl
	bool operator()(pii const &a, pii const &b)
	{
		if(a.F==b.F)
			return (a.S<b.S);
		return (a.F<b.F);
	}
};

///---CONSTANT---///
const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007

int main()
{
    Boost();

    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        int a;
        cin>>a;
        cout<<a+a*a+a*a*a<<endl;

    }
    return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define MAX_V 110
#define N 110
using namespace std;

/* ?????£?????????????§£ O(|V|+|E|) */
int V; //????????°
vector<int> G[MAX_V]; //??°???????????£??\??????????????¨???
vector<int> rG[MAX_V];//?????????????????????????????°??????
vector<int> vs;       //??°?????????????????????
bool used[MAX_V];     //?????§???????????????
int cmp[MAX_V];       //?±????????????£?????????????????????????????????

void add_edge(int from,int to){
  G[from].push_back(to);
  rG[to].push_back(from);
}

void dfs(int v){
  used[v]=true;
  for(int i=0;i<G[v].size();i++)if(!used[G[v][i]])dfs(G[v][i]);
  vs.push_back(v);
}

void rdfs(int v,int k){
  used[v]=true;
  cmp[v]=k;
  for(int i=0;i<rG[v].size();i++) if(!used[rG[v][i]])rdfs(rG[v][i],k);
}

int scc(){
  memset(used,0,sizeof(used));
  vs.clear();
  for(int v=0;v<V;v++) if(!used[v]) dfs(v);
  memset(used,0,sizeof(used));
  int k=0;
  for(int i=vs.size()-1;i>=0;i--)if(!used[vs[i]]) rdfs(vs[i],k++);
  return k;
}

int n,v[N],w[N],K[N],T;
int Max(int &a,int b){return a=max(a,b);}

set<int>g[N];
vector<int> DP[N];
void update(vector<int> I,vector<int> &dp){
  int col = cmp[I[0]];
  for(int i:I){ //??????
    int num = g[cmp[i]].count(cmp[i])? K[i]:1;
    for(int j=1;num;j=min(num,j*2)){ //???????????°
      num -= j;
      for(int k=T;k>=j*w[i];k--)  //?????¨?????????
        Max(dp[k],dp[k-j*w[i]]+j*v[i]);
    }
  }
  

  for(int nx:g[col])
    for(int j=0;j<=T;j++) Max(DP[nx][j],dp[j]);
  
}

void init(){
  for(int i=0;i<N;i++){
    cmp[i] = 0;
    G[i].clear();
    rG[i].clear();
    g[i].clear();
    DP[i].clear();
    DP[i].resize(T+1,0);
  }
}

int main(){
  while(1){
    int m;
    cin>>n>>m>>T;
    if(!n&&!m&&!T)break;
    init();
  
    for(int i=0;i<n;i++)cin>>v[i]>>w[i]>>K[i];
    for(int i=0,a,b;i<m;i++)cin>>a>>b,add_edge(a-1,b-1);
    V = n;
    V=scc();
    
    for(int i=0;i<n;i++)
      for(int j:G[i])g[cmp[i]].insert(cmp[j]);
  
    int ans = 0;
    for(int i=0;i<V;i++){
      vector<int> I;
      for(int j=0;j<n;j++)if(cmp[j]==i) I.push_back(j);
      update(I,DP[i]);
    }
    for(int i=0;i<V;i++)
      for(int j=0;j<=T;j++) Max(ans,DP[i][j]);
  
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 7280
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

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;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
//#define int long long

signed main() {
    int x, n;
    cin >> x >> n;
    set<int> p;
    int a;
    rep(i, n) {
        cin >> a;
        p.insert(a);
    }
    int dif = 101;
    int ans = 0;
    for (int i = 0; i <= 101; i++) {
        
            if (p.find(i) == p.end()) {
                if (chmin(dif, abs(x - i)))
                    ans = i;
            }
        }
    
    cout << ans << endl;
}

Measured memory_bytes: 3640