akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

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

    double sol = 0;
    for (int i = 1; i <= n; i++) {
        double curr_prob = (double) 1 / n;
        long long int curr_score = i;

        while (curr_score < k) {
            curr_score *= 2;
            curr_prob /= 2;
        }

        sol += curr_prob;
    }

    printf("%0.10lf\n", sol);
}

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

#define se second
#define fi first
#define mk(a,b) make_pair(a,b)

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

int N;
vector<pii> G[100010];
ll ans = 0;
int sub[100010] = {0};
int INF = 1001001001;

pii DFS(int v,int p)
{
    pii res = mk(INF,0);
    int s = 1,m = 0;
    for(int i = 0; i < G[v].size(); i++)
    {
        int ne = G[v][i].fi;
        if(ne == p)continue;
        res = min(res,DFS(ne,v));
        if(sub[ne] * 2 == N)ans -= G[v][i].se;
        ans += (ll)(min(N - sub[ne],sub[ne])) * G[v][i].se * 2LL;
        s += sub[ne];
        m = max(m,sub[ne]);
    }
    m = max(m,N - s);
    res = min(res,mk(m,(ll)v));
    sub[v] = s;
    return res;
}

int main()
{
    scanf("%d",&N);
    for(int i = 0; i < N - 1; i++)
    {
        int a,b;
        ll c;
        scanf("%d%d%lld",&a,&b,&c);
        G[a].push_back(mk(b,c));
        G[b].push_back(mk(a,c));
    }

    pii res = DFS(1,0);
    if(res.fi * 2 < N)
    {
        int MIN = 1001001001;
        for(int i = 0; i < G[res.se].size(); i++)if(MIN > G[res.se][i].se)MIN = G[res.se][i].se;
        ans -= MIN;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 18944
l=[0]*200005
n=int(input())
a=[0]+list(map(int,input().split()))
l[0]=1
for i in range(1,n+1):
    if l[a[i]-1]==1:
        l[a[i]]=1

res=n
for i in range(1,n+1):
    res-=l[i]

if res==n:
    res=-1
    
print(res)  

Measured memory_bytes: 27932
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000000

struct Data{
	long long c0=0,c1=0;
	long long inv = 0LL;
};

Data op(Data a,Data b){
	a.inv += b.inv + a.c1*b.c0;
	a.c0 += b.c0;
	a.c1 += b.c1;
	return a;
}
Data e(){
	return Data();
}

Data mapping(int a,Data b){
	rep(i,a){
		b.inv = (b.c0+b.c1)*(b.c0+b.c1-1)/2 - (b.c0)*(b.c0-1)/2 - (b.c1)*(b.c1-1)/2 - b.inv;
		swap(b.c0,b.c1);
	}
	return b;
}

int composition(int a,int b){
	return a^b;
}

int id(){
	return 0;
}

int main(){
	
	int N,Q;
	cin>>N>>Q;
	vector<Data> A(N);
	rep(i,N){
		int a;
		cin>>a;
		if(a==0)A[i].c0=1;
		else A[i].c1=1;
		A[i].inv = 0;
	}
	
	lazy_segtree<Data,op,e,int,mapping,composition,id> seg(A);
	
	rep(i,Q){
		int t;
		cin>>t;
		int l,r;
		cin>>l>>r;
		if(t==1){
			seg.apply(l-1,r,1);
		}
		else{
			cout<<seg.prod(l-1,r).inv<<endl;
		}
	}
	
    return 0;
}

Measured memory_bytes: 21216
#include<bits/stdc++.h>
#define ll long long
#define clr(x,i) memset(x,i,sizeof(x))
using namespace std;
const int N=2005;
inline int read()
{
    int x=0,f=1; char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9') {x=x*10+ch-'0',ch=getchar();}
    return x*f;
}
int n,m;
void solve()
{
	string s,t; cin>>s>>t;
	n=s.size(); m=t.size();
	int ans=1e9;
	for(int i=0; i<=n-m; i++) {
		int now=0;
		for(int j=0; j<m; j++) {
			if(s[i+j] != t[j]) now++;
		}
		ans=min(ans, now);
	}
	cout<<ans<<endl;
}
int main()
{
	int T=1;
	while(T--) solve();
}

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

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

    int N, A; cin >> N >> A;
    int X = 0, y[N]; 
    for (int i = 0; i < N; ++i) { 
        int x; cin >> x; y[i] = x - A;
        X = max(X, x);
    }    

    long long dp[N + 1][2*X*N + 1];
    fill(dp[0], dp[N + 1], 0);

    for (int i = 1; i <= N; ++i) {
        dp[i][y[i - 1] + X*N] += 1;
        for (int j = 0; j < 2*X*N + 1; ++j) {
            dp[i][j] += dp[i - 1][j];
            int diff = j + y[i - 1];
            if (0 <= diff && diff <= 2*X*N)
                dp[i][diff] += dp[i - 1][j];
        }
    }

    cout << dp[N][X*N] << endl;
}

Measured memory_bytes: 2304
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main( void )
{
	int n;
	cin >> n;

	for ( int c = 0; c < n; c++ )
	{
		vector <int> vertexs;
		for ( int i = 0; i < 3; i++ )
		{
			int vertex;
			cin >> vertex;
			vertexs.push_back( vertex );
		}

		sort( vertexs.begin(), vertexs.end() );

		bool ok = false;
		do
		{
			if ( vertexs[0] * vertexs[0] == vertexs[1] * vertexs[1] + vertexs[2] * vertexs[2] )
			{
				ok = true;
			}
		} while ( next_permutation( vertexs.begin(), vertexs.end() ) );

		if ( ok )
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 0
use proconio::input;


fn main() {
    input!{
        n: usize,
        aa: [u128; n],
    };
    if aa.iter().any(|a| *a == 0) {
        println!("0");
        return;
    }
    let mut ans = 1;
    for a in aa {
        ans *= a;
        if ans > 10u128.pow(18) {
            println!("-1");
            return;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 5332
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)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $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, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (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")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        a: usize,
        v: [usize; n]
    }
    let mut tab: Vec<Vec<usize>> = vec![vec![0; 50 * n + 1]; n + 1];
    tab[0][0] = 1;
    for i in 0..n {
        for j in (0..i + 1).rev() {
            for k in 0..50 * j + 1 {
                tab[j + 1][k + v[i]] += tab[j][k];
            }
        }
    }
    let mut ans = 0;
    for i in 1..n + 1 {
        ans += tab[i][i * a];
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
namespace AtCoder_Beginner_Contest_13
{
    class Program
    {
        //配列にする
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        //Listにする
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static void Main(string[] args)
        {
            SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            Out.Flush();
        }
        static void Solve()
        {
            var NK = Sarray();
            var N = NK[0];
            var K = NK[1];
            var Ai = Slist();

            var sum = Ai.Sum();
            var max = Ai.Max();
            if(0==max)
            {
                WriteLine(0);
                return;
            }
            var dc = yaku(sum).OrderByDescending(e => e.Key);
            var ans = 0L;
            foreach (var pk in dc)
            {
                Ai.Sort((l, r) => (int)(r % pk.Key - l % pk.Key));
                var pls = new long[N + 1];
                var mns = new long[N + 1];
                for (var i = 1; i < N + 1; ++i)
                {
                    pls[i] = pls[i - 1] + (pk.Key - Ai[i - 1] % pk.Key);
                }
                for (var i = N - 1; 0 <= i; --i)
                {
                    mns[i] = mns[i + 1] + Ai[(int)i] % pk.Key;
                }
                for (var i = 1; i < N ; ++i)
                {
                    if (pls[i] == mns[i] && pls[i] <= K)
                    {
                        ans = Math.Max(ans, pk.Key);
                        break;
                    }
                }
            }
            if (max > 0)
                ans = Math.Max(1, ans);
            WriteLine(ans);
        }
        static Dictionary<long, long> yaku(long n)
        {
            var ret = new Dictionary<long, long>();
            for (long i = 1; i * i <= n; i++)
            {
                if (n % i == 0)
                {
                    ret[i] = 1;
                    ret[n/i] = 1;
                }
            }
            return ret;
        }
    }
}


Measured memory_bytes: 18016
#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;
const double PI = acos(-1.0);

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

    string s;
    cin >> s;
    cout << (s.find("YAKI") == 0 ? "Yes":"No") << "\n";
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    double x[4],y[4],m1,m2;
    int n,i,j;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        for(j=0;j<4;j++)
            scanf("%lf%lf",&x[j],&y[j]);
        m1=(y[1]-y[0])/(x[1]-x[0]);
        m2=(y[3]-y[2])/(x[3]-x[2]);
        printf("%s\n",m1==m2?"YES":"NO");
    }
    return 0;
}

Measured memory_bytes: 620
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;

int main() {
  ll D, N;
  cin >> D >> N;
  constexpr array<ll, 3> f{1, 100, 10'000};
  cout << ((N != 100 ? N : 101) * f[D]) << endl;
  return 0;
}


Measured memory_bytes: 3516
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from operator import mul


sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n = I()
A = LI()
dp = [[defaultdict(lambda:-INF) for _ in range(2)] for _ in range(n + 1)]
dp[0][0][0] = 0
for i in range(n):
    for j in range(2):
        for k, e in dp[i][j].items():
            if i // 2 <= k <= i // 2 + 1:
                dp[i + 1][0][k] = max(dp[i + 1][0][k], e)
            if i // 2 <= k + 1 <= i // 2 + 1 and j == 0:
                dp[i + 1][1][k + 1] = max(dp[i + 1][1][k + 1], e + A[i])

print(max(dp[n][0][n // 2], dp[n][1][n // 2]))

Measured memory_bytes: 297044
#include <iostream>
#include <string>
#include <algorithm>
#include  <set>
#include <cmath>
using namespace std;
typedef long long ll;
#define rep(i,n) for(i=0;i<n;i++)

int main() {
	int a, b, c, d, e, f, g, h,i,j,n,m,l,sum=0;
	ll  aa, bb;
	cin >> a ;



	cout << 180*(a-2);


	return 0;
}

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

template<class T>
T lcm(T a,T b){
    return a/__gcd(a,b)*b;
}

int main(){
    int n;cin >> n;
    long ans=0;
    vector<long> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
        a[i]--;
    }
    for(int i=0;i<n;i++){
        if(a[a[i]]==i){
            ans++;
        }
    }
    cout << ans/2;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define BUF 1e5
#define INF 1<<30
constexpr ll mod = 1e9 + 7;
using namespace std;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
//int ans = 1 << 30;

template<ll mod>
class Fp {
public:
	ll val;

private:
	inline void calc_mod(ll& v) {
		if (v >= mod)v -= mod;
	}
public:
	Fp() {}
	Fp(ll v) :val(v%mod) {
		if (val < 0)val += mod;
	}

	Fp operator+=(const Fp &in) {
		val += in.val;
		calc_mod(val);
		return *this;
	}

	Fp operator+(const Fp &in) const {
		return Fp(*this) += in;
	}

	Fp &operator-=(const Fp &in) {
		val -= in.val;
		calc_mod(val);
		if (val < 0)val += mod;
		return *this;
	}

	Fp operator-(const Fp &in) const {
		return Fp(*this) -= in;
	}

	Fp& operator*=(const Fp& in) {
		val = val * in.val % mod;
		return *this;
	}

	Fp operator*(const Fp &in) const {
		return Fp(*this) *= in;
	}

	Fp& operator/=(const Fp& in) {
		*this *= modpow(in, mod - 2);
		return *this;
	}

	Fp operator/(const Fp& in) const {
		return Fp(*this) /= in;
	}

	bool operator==(const Fp&in)const {
		return val == in.val;
	}

	bool operator!=(const Fp&in)const {
		return val != in.val;
	}

	friend Fp modpow(const Fp& in, ll n) {
		if (n == 0)return 1;
		if (n & 1) {
			return in * modpow(in*in, n / 2);
		}
		else {
			return modpow(in*in, n / 2);
		}
	}
};
using modll = Fp<mod>;

class Factorial {
public:
	vector<modll> fact, finv;
	Factorial(ll n) :fact(n, modll(1)), finv(n, modll(1)) {
		for (int i = 2; i < n; i++) {
			modll tmp(i);
			fact[i] = fact[i - 1] * tmp;
			finv[i] = finv[i - 1] / tmp;
		}
	}

	modll com(const ll& n, const ll& k) {
		if (n < k || n < 0 || k < 0)return modll(0);
		return fact[n] * finv[k] * finv[n - k];
	}
};


int main() {
	cin >> N >> M;
	vector<modll> dp(N + 1, modll(0));
	vector<int>a(N);
	set<int> set;
	for (int i = 0; i < M; i++) {
		cin >> a[i];
		set.insert(a[i]);
	}
	dp[0] = modll(1);
	if (set.count(1) == 0)dp[1] = modll(1);
	for (int i = 2; i <= N; i++) {
		if (set.count(i) == 0) {
			dp[i] = dp[i - 1] + dp[i - 2];
		}
	}
	cout << dp[N].val << endl;
}


Measured memory_bytes: 6144
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};


bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  int N,i;
  cin >> N >> i;
  cout << (N-i+1) << endl;
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}

ll bpow(ll a, ll n,ll mod){
  int i = 0;
  ll res=1;
  while(n){
    if(n & 1)
      res = (res*a) % mod;
    a = (a*a) % mod;
    n >>= 1;
  }
  return res;
}
const int MOD = 1000000007;
mat mul(mat &A, mat &B){
  mat C(A.size(),vec(B[0].size()));
    REP(i,A.size())REP(k,B.size())REP(j,B[0].size()){
    C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
  }
  return C;
}

mat pow(mat A,ll n)
{
  mat B(A.size(),vec(A.size()));
  REP(i,A.size()){
    B[i][i] = 1;
  }
  while(n > 0){
    if ( n & 1) B = mul(B,A);
    A = mul(A,A);
    n >>= 1;
  }
  return B;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = LLONG_MAX/4;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

ll gcd(ll &a, ll &b){
    if(b < a)swap(a,b);
    ll r = b%a;
    if(r == 0)return a;
    return gcd(r,a);
}

int main(){
    ll n; cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    ll res;
    res = gcd(a[0],a[1]);
    rep(i,n-1){
        res = gcd(res, a[i+1]);
    }
    cout << res << endl;
}

Measured memory_bytes: 1024
import math

def Comb(n, r):
  return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

S = int(input()) - 3
N = 1
ans = 0
mod = 10 ** 9 + 7
while S >= 0:
  ans += Comb(S+N-1, S) % mod
  ans = ans % mod
  N += 1
  S -= 3
print(ans)

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

using namespace std;

/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int maxn = 1e5+5;
struct query { int i,v,ans; } Q[maxn];

bool cmp1(const query& a, const query& b)
{ return a.v < b.v; }

bool cmp2(const query& a, const query& b)
{ return a.i < b.i; }

int main()
{
/* #ifdef foo_ */
/*     freopen("foo", "rt", stdin); */
/* #endif */
/*     ios::sync_with_stdio(false); */
    int h,n;
    while (cin >> h >> n) {
        int sum = 0;
        FOR(i,0,n) {
            int a; cin >> a; sum += a;
        }
        if (sum >= h)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
    return 0;
}


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

int main(){
	string s;
	cin >> s;
	string ans = "No";
	vector<int> vec(4);
	for (int i=0;i<4;i++){
		vec.at(i) = s.at(i);
	}
	sort(vec.begin(), vec.end());
	if (vec.at(0)==vec.at(1) &&
      vec.at(2)==vec.at(3) &&
      vec.at(0)!=vec.at(2)){
      	ans = "Yes";
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using in6 = int64_t;
using ind = double;
using pii = pair<int,int>;
using psi = pair<string,int>;
using vpi = vector<pii>;
using vps = vector<psi>;
#define rep(i, n) for (in6 i = 0; i < (in6)(n); i++)
#define repa(i,a,n) for(in6 i = a; i < (in6)(n); i++)
#define repdown(i,n) for(in6 i = n; i > 0; i--)
#define kyun ios::sync_with_stdio(false)
#define hinata cout << "\n"
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define inf 2147483647
#define dset(n) cout << fixed << setprecision(n)

void yes() {
  cout << "Yes";
}

void no() {
  cout << "No";
}

int main() {
  kyun;
  vi data(5);
  rep(i,5) cin >> data[i];
  in6 ans;
  rep(i,5) if(data[i] == 0) ans = i+1;
  cout << ans;
  hinata;
}

Measured memory_bytes: 3608
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int D = sc.nextInt();
        int [] a = new int[101];
        for (int i = 0 ; i <= 100 ; i++) {
            if (i >= A && i <= B) {
               a[i]++;
            }
            if (i >= C && i <= D) {
                a[i]++;
            }
        }
        int ans = 0;
        for (int i = 0 ; i <= 100 ; i++) {
            if (a[i] == 2) {
                ans++;
            }
        }
        if (ans != 0) {
            System.out.println(ans - 1);
        } else {
            System.out.println(ans);
        }


    }
}


Measured memory_bytes: 22996
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
const int N=57;
int read(){int x;scanf("%d",&x);return x;}
std::vector<int>e[N],g[N];
int fa[N],ndeg[N],deg[N],vis[N],mp[N][N];
void dfs(int u,int f)
{
    if(fa[u]=f,vis[f]&&mp[u][f]) vis[u]=1;
    for(int v:g[u]) if(v^f) dfs(v,u);
}
void work()
{
    int n=read(),ans=n+1;memset(mp,0,sizeof mp);
    for(int i=1;i<=n;++i) e[i].clear(),g[i].clear();
    for(int i=1,u,v;i<n;++i) u=read(),v=read(),mp[u][v]=mp[v][u]=1,e[u].push_back(v),e[v].push_back(u);
    for(int i=1,u,v;i<n;++i) u=read(),v=read(),g[u].push_back(v),g[v].push_back(u);
    for(int i=1;i<=n;++i) ndeg[i]=e[i].size();
    for(int i=1;i<=n;++i)
    {
	int cost=0,u;
	memset(vis,0,4*n+4),vis[i]=1,dfs(i,0),memcpy(deg+1,ndeg+1,4*n);
	while(1)
	{
	    for(u=1;u<=n;++u) if(!vis[u]&&deg[u]==1&&vis[fa[u]]) break;
	    if(u>n) break; else vis[u]=1,++cost;
	    for(int v:e[u]) --deg[v];
	}
	for(u=1;u<=n;++u) if(!vis[u]) break;
	if(u>n) ans=std::min(ans,cost);
	if(e[i].size()>1||u>n||ans<=n) continue;
	memset(vis,0,4*n+4),vis[0]=1,memcpy(deg+1,ndeg+1,4*n);
	while(1)
	{
	    for(u=1;u<=n;++u) if(!vis[u]&&deg[u]<=1&&vis[fa[u]]) break;
	    if(u>n) break; else vis[u]=1;
	    for(int v:e[u]) --deg[v];
	}
	for(u=1;u<=n;++u) if(!vis[u]) break;
	if(u>n) ans=n;
    }
    printf("%d\n",ans>n? -1:ans);
}
int main(){for(int T=read();T;--T)work();}


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

int main() {
  
  char c;
  cin >> c;
  
  if (c=='a' || c=='e' || c=='i' || c=='o' || c=='u') {
    cout << "vowel" << endl;
  }
    
    else {
      cout << "consonant" << endl;
    }
   
    
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <random>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> pii;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod = 1000000007;
int rnd(int x) { return mrand() % x; }
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
// head

int t;

int main()
{
    ios::sync_with_stdio(false);
#ifdef RG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout); 
#endif
    int n,k;
    cin>>n>>k;
    int ans = 0;
    while(n) {
        ans++;
        n/=k;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
def two_sum(a, b):
    s = a + b
    v = s - a
    e = (a - (s - v)) + (b - v)
    return s, e

def split(a):
    t = ((2. ** 27) + 1.) * a
    high = t - (t - a)
    low = a - high
    return high, low

def two_prod(a, b):
    p = a * b
    ah, al = split(a)
    bh, bl = split(b)
    e = ((ah * bh - p) + ah * bl + al * bh) + al * bl
    return p, e

def mul(a, ae, b, be):
    c, ce = two_prod(a, b)
    ce += ae * b + a * be + ae * be
    return two_sum(c, ce)

def div(a, ae, b, be):
    c = a / b
    t, te = two_prod(-c, b) # ~ -a
    ce = (((a + t) + te + ae) - be * c) / b
    return two_sum(c, ce)

def solve(a, b, debug=False):
    from math import floor
    c, ce = div(round(b * 100.), 0., 100., 0.) # c = round(b * 100) / 100
    if debug:
        print(f'... {round(b * 100)} / 100 = {c} + {ce}')
    p, pe = mul(a, 0., c, ce) # p = a * c
    if p < 1.0: return 0
    ph, pl = split(p) # ph + pl = p
    pl, pe = two_sum(pl, pe)
    if debug:
        print(f'... {a} * {b} = {ph} + {pl} + {pe}')
    return int(ph) + int(floor(pl))

def main():
    a, b = input().split(' ')
    print(solve(int(a), float(b)))

if __name__ == '__main__':
    main()


Measured memory_bytes: 9560
#include<bits/stdc++.h>
#define int long long
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
        string s; cin>>s;
        int N=s.size();

        int ans=0;
        REP(S,1<<(N-1)){
                int sum=0,cur=0;
                REP(i,N){
                        cur=cur*10+(s[i]-'0');
                        if(S>>i&1 or i==N-1){
                                sum+=cur; cur=0;
                        }
                }
                ans+=sum;
        }
        cout<<ans<<endl;
}


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

int main() {
  vector<int> vec(6000);
  for (int i = 0; i < 6000; i++) cin >> vec.at(i);
  for (int i = 0; i < 6000; i += 2) {
    if (vec.at(i) == 0 && vec.at(i + 1) == 0) break;
    cout << min(vec.at(i), vec.at(i + 1)) <<" " << max(vec.at(i), vec.at(i + 1)) << endl;
  }
}


Measured memory_bytes: 3112
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		String s = stdIn.next();
		String p = stdIn.next();
		s += s;
		boolean flag;

		for (int i=0; i<s.length()/2; i++) {
			if(s.charAt(i) == p.charAt(0)){
				flag = true;
				for (int j=i+1,k=1; k<p.length(); j++,k++) {
					if(s.charAt(j) != p.charAt(k))
						flag = false;
				}
				if(flag){
					System.out.println("Yes");
					return;
				}
			}
		}
		System.out.println("No");
	}
}

Measured memory_bytes: 17296
n = int(input())
a_list = list(map(int, input().split()))
base_xor = 0
for i in a_list:
    base_xor = base_xor^i
ans = [0]*n
for i in range(n):
    ans[i] = a_list[i]^base_xor
ans = " ".join([str(i) for i in ans])
print(ans)

Measured memory_bytes: 41608
import sys

bng=[[0]*3 for i in range(3)]

for i in range(3):

  a,b,c=map(int,input().split())

  bng[i][0]=a
  bng[i][1]=b
  bng[i][2]=c

n=int(input())

for j in range(n):

  k=int(input())

  for a in range(3):
    for b in range(3):
      if bng[a][b]==k:
        bng[a][b]=-1

for i in range(3):
  if bng[i][0]==-1 and bng[i][1]==-1 and bng[i][2]==-1:
    print("Yes")
    sys.exit()

  if bng[0][i]==-1 and bng[1][i]==-1 and bng[2][i]==-1:
    print("Yes")
    sys.exit()

if bng[0][0]==-1 and bng[1][1]==-1 and bng[2][2]==-1:
  print("Yes")
  sys.exit()

if bng[2][0]==-1 and bng[1][1]==-1 and bng[0][2]==-1:
  print("Yes")
  sys.exit()

print("No")

Measured memory_bytes: 38384
IDENTIFICATION DIVISION.
      PROGRAM-ID. 156A.
      DATA DIVISION.
      WORKING-STORAGE SECTION.
      01 INP PIC X(100).
      01 N PIC 9(3).
      01 K PIC 9(4).
      
      01 ANS PIC ZZZ9.
      
      PROCEDURE DIVISION.
      ACCEPT INP.
      UNSTRING INP DELIMITED BY " "
      INTO N K.
      
      IF N < 10
      	COMPUTE ANS = K + 100 * ( 10 - N )
      ELSE
      	MOVE K TO ANS
      END-IF
      
      DISPLAY FUNCTION TRIM(ANS).
      
      STOP RUN.

Measured memory_bytes: 384
import itertools
import functools
import math
from collections import Counter
from itertools import combinations
import re

"""
制約
1 ≦ N ≦ 3 桁数・・・答えは３桁の数字（０〜９９９まで）　計算回数のオーダー等は考慮不要である
0 ≦ M ≦ 5 条件の数
1 ≦ Si ≦ N 指定の桁数
0 ≦ Ci ≦ 9 指定の桁数の取りうる数字の範囲
"""


N,M=map(int,input().split())

#正規化文字列で比較する
ans = ["."] * N

for i in range(M):
    S,C=map(str,input().split())
    
    k = int(S)
    #同じ桁数に異なる条件が入った場合は、その時点で当てはまるものがなくなる
    if ans[k-1] not in (".",str(C)):
        print(-1)
        exit()

    #文字列で比較するため Cは str型に変換
    ans[k-1] = str(C)

#正規化した条件のため、先頭の文字が0であるかのチェックの必要はない
cmp = re.compile("".join(ans))

for i in range(10**3):
    #マッチした場合オブジェクトを返す、しない場合はNoneが返る
    res = cmp.match(str(i))
    if res:
        print(i)
        exit()

print(-1)


Measured memory_bytes: 9888
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;
int main(){
  int n,k;
  cin >>n>>k;
  int cnt=1;
  while (n>=k){
    n /= k;
    cnt++;
  }
  cout <<cnt;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,s,n) for (int i=s;i<n;++i)
#define drep(i,s,n) for (int i=n;i>=s;--i)
#define all(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define print(x) cout<<(x)<<endl
using namespace std;
typedef long long ll;

int gcd(int a,int b)
{if (a%b == 0) return(b);
 else          return(gcd(b,a%b));}
int lcm(int a,int b)
{return a*b/gcd(a,b);}
void printv(vector<auto> v) {cout<<'[';rep(i,0,v.size()){cout<<v[i]<<',';}cout<<']'<<endl;}
void printvv(vector<vector<auto>> vv)
{
  cout<<'['<<endl;
  rep(q,0,vv.size()){cout<<'[';rep(p,0,vv.at(q).size())cout<<vv.at(q).at(p)<<',';cout <<']'<<endl;}
  cout<<']'<<endl;
}
void solve(); int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}
int step_x[] = {-1,0,0,1};
int step_y[] = {0,-1,1,0};
//------------------------------------------------------------
ll n,ans=0;

void solve() {
  cin>>n;

  rep(i,1,n+1)
  {
    if(i%3!=0 && i%5!=0) ans+=i;
  }

  print(ans);
  return;
}

Measured memory_bytes: 3584
#include <iostream>
#include <string>
#include <array>
#include <cstdlib>
#include <cmath>

int main() {
	std::array<bool, 1000000> is_prime_table = { false, false, true };
	for( int i=3; i<=is_prime_table.size(); i+=2 ) {
		is_prime_table[i] = [&i]() -> bool
		{
			for( int j=3; j<=std::sqrt(i); j+=2 )
				if ( i % j == 0 )
					return false;
			return true;
		}();
	}
	
	int num = 0;
	while( std::cin >> num ) {
		int result = num > 1 ? 1 : 0;	// 2
		
		for( int i=3; i<=num; i+=2 )
			if ( is_prime_table[i] )
				++result;

		std::cout << result << std::endl;
	}
}

Measured memory_bytes: 2140
#!/usr/bin/env python
# coding: utf-8

# In[6]:


N,M,X = map(int, input().split())
A = list(map(int, input().split()))


# In[7]:


goal0_cost = sum(pos < X for pos in A)
goalN_cost = sum(pos > X for pos in A)
print(min(goal0_cost, goalN_cost))


# In[ ]:






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

#define llint long long int

using namespace std;

int main(){
    llint H;

    cin >> H;

    llint count;

    for(count = 0; H > 0; count ++){
        H /= 2;
    }
    llint sum = 1;

    for(int i = 0; i < count; i ++){
        sum *= 2;
    }
    cout << fixed << sum - 1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <random>
#include <climits>

#define mod 1000000007

using namespace std;
using ll = long long;

void solve(){
    double a, b;
    cin >> a >> b;
    cout << ceil((a+b)/2) << endl;
}

int main(){
    solve();
    return 0;
}



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

int main() {
    int k, a, b;  cin >> k >> a >> b;
    for (int i = a; i <= b; ++i) {
        if (i % k == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
}


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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define fi first
#define se second
#define setpre(x) cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 500005;

// 素集合データ構造 (Union-Find)
struct union_find{
    vector<int> par;
    vector<int> rank;
    union_find(int n) : par(n), rank(n){
        for(int i = 0; i < n; i++){
            par[i] = i; rank[i] = 0;
        }
    }
    int root (int x){
        if(par[x] == x) return x;
        par[x] = root(par[x]);
        return par[x];
    }
    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        if (rank[rx] < rank[ry]){
            par[rx] = ry;
        }
        else{
            par[ry] = rx;
            if (rank[rx] == rank[ry]) rank[rx]++;
        }
    }
    bool same(int x, int y){
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

/* セグメント木によるrmq */
struct rmq{
    int n; long arr[MAX];
    rmq(int n_){
        n = 2;
        while(n < n_) n *= 2;
        rep(i, n*2) arr[i] = (1L << 31) - 1;
    }
    void update(int k, int a){
        k += n - 1;
        arr[k] = a;
        while(k > 0){
            k = (k - 1) / 2;
            arr[k] = min(arr[k * 2 + 1], arr[k * 2 + 2]);
        }
    }
    long query(int a, int b, int k, int l, int r){
        // cout << k << " " << l << " " << r << endl;
        if(r <= a || b <= l) return (1L << 31) - 1;
        if(a <= l && r <= b) return arr[k];
        else{
            int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
            int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
            return min(vl, vr);
        }
    }
    void show(){
        rep(i, n*2){
            cout << arr[i] << " "; 
        }
        cout << endl;
    }
};

int main(){
    ii2(n, q);
    rmq r(n);
    rep(i, q){
        int c, x, y; cin >> c >> x >> y;
        // r.show();
        if(c == 0){
            r.update(x, y);
        }else{
            out(r.query(x, y + 1, 0, 0, r.n));
        }
    }
}


Measured memory_bytes: 5148
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  int h[100005], dp[100005];
  cin >> N;
  rep(i, N){
    cin >> h[i];
  }

  rep(i, N){
    if (i == 0){
      dp[0] = 0;
    } else if (i == 1){
      dp[1] = abs(h[0]-h[1]);
    } else {
      dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
    }
  }

  cout << dp[N-1] << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

const int N = (int)3e5;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  ret *= kaijo(n); ret %= MOD;
  ret *= gyaku_kaijo(r); ret %= MOD;
  ret *= gyaku_kaijo(n-r); ret %= MOD;
  return ret;
}


int main(void){
  int n;cin>>n;
  vector<ll> P;
  rep(i,n){
    ll p;cin>>p;p--;
    P.push_back(p);
  }
  vector<ll> A,B;
  ll base = 4e4;
  rep(i,n){
    A.push_back(i*base);
    B.push_back(i*base);
  }
  reverse(all(B));
  rep(i,n){
    ll p = P[i];
    A[p] += i+1;
    B[p] += i+1;
  }
  rep(i,n){
    cout<<A[i]<<" ";
  }
  cout<<endl;
  rep(i,n){
    cout<<B[i]<<" ";
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 1320
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cassert>

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

const int MAXN=1E5+10;

struct peo{
	ll a,b;
}p[MAXN];

int x,y,z,n;
ll Ans=-(1ll<<60),Csum,lAns[MAXN];
priority_queue<ll,vector<ll>,greater<ll> > pq;

int main()
{
	scanf("%d%d%d",&x,&y,&z);
	n=x+y+z;
	for(int i=1,a,b,c;i<=n;i++)
	{
		scanf("%d%d%d",&a,&b,&c);
		p[i].a=a-c;p[i].b=b-c;
		Csum+=c;
	}
	sort(p+1,p+1+n,[](peo a,peo b)->bool{return a.a-a.b>b.a-b.b;});
	ll sum=0;
	for(int i=1;i<=x;i++)
	{
		sum+=p[i].a;
		pq.push(p[i].a);
	}
	for(int i=x;i<=x+z;i++)
	{
		lAns[i]=sum;
		sum+=p[i+1].a;
		pq.push(p[i+1].a);
		sum-=pq.top();pq.pop();
	}
	while(!pq.empty()) pq.pop();
	sum=0;
	for(int i=n;i>=x+z+1;i--)
	{
		sum+=p[i].b;
		pq.push(p[i].b);
	}
	for(int i=x+z+1;i>x;i--)
	{
		Ans=max(Ans,lAns[i-1]+sum);
		sum+=p[i-1].b;
		pq.push(p[i-1].b);
		sum-=pq.top();pq.pop();
	}
	printf("%lld\n",Ans+Csum);
}

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


int solve(int n){
    vector<string> s(n);
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
    int idx=0;
    array<int,'Z'-'A'+1> idmap;
    fill(idmap.begin(),idmap.end(),-1);
    int var=0;
    array<int,10> impact_l;
    array<int,10> impact_r;
    fill(impact_l.begin(),impact_l.end(),0);
    fill(impact_r.begin(),impact_r.end(),0);
    array<int,10> bad_zero;
    fill(bad_zero.begin(),bad_zero.end(),false);
    for(int i=0;i<n;i++){
        vector<int> tmp(10,0);
        for(int j=0;j<s[i].size();j++){
            if(idmap[s[i][j]-'A']==-1){
                idmap[s[i][j]-'A']=idx++;
                var++;
            }
            if(j==0 && s[i].size()>1){
                bad_zero[idmap[s[i][j]-'A']]=true;
            }
            for(int k=0;k<10;k++) tmp[k]*=10;
            tmp[idmap[s[i][j]-'A']]++;
        }
        if(i==n-1){
            for(int j=0;j<10;j++){
                impact_r[j]+=tmp[j];
            }
        }
        else{
            for(int j=0;j<10;j++){
                impact_l[j]+=tmp[j];
            }
        }
    }
    array<int,10> pat;
    iota(pat.begin(),pat.end(),0);
    int res=0;
    int fact=1;
    for(int i=0;i<10-var;i++){
        fact*=(i+1);
    }
    int cnt=0;
    do{
        if(!cnt){
            bool isok=true;
            vector<int> num(n,0);
            int lhs=0;
            int rhs=0;
            for(int i=0;i<idx;i++){
                isok&=(!(bad_zero[i] && pat[i]==0));
            }
            if(isok){
                int lhs=0;
                int rhs=0;
                for(int i=0;i<idx;i++){
                    lhs+=impact_l[i]*pat[i];
                    rhs+=impact_r[i]*pat[i];
                }
                res+=(int)(lhs==rhs);
            }
        }
        cnt++;
        if(cnt==fact) cnt=0;
    }while(next_permutation(pat.begin(),pat.end()));
    return res;
}

int main(){
    int n;
    while(cin>>n,n){
        cout<<solve(n)<<endl;
    }
    return 0;
}


Measured memory_bytes: 3016
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(0); 
    cin.tie(0);   
	ll n,m,k,c;
	string s;
	cin>>n>>m>>k>>c;
	if(c<=n)
		cout<<c;
	else if(n+m>=c)
		cout<<n;
	else
	{
		cout<<n-(c-(n+m));
	}
	
	return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define MOD 1000000007
#define SORT(s) sort(s.begin(), s.end());
#define reverse(s) reverse(s.begin(), s.end());
#define P pair<int,int>
#define mp make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
//#define int ll
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int ndx[8] = { 0,1,0,-1, 1,1,-1,-1 };
int ndy[8] = { 1,0,-1,0, 1,-1,-1,1 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }

template <class T>
void VecRowShow(vector<T> vec) {
	rep(i, vec.size()) {
		if (i != vec.size() - 1) cout << vec[i] << " ";
		else cout << vec[i] << endl;
	}
}

int main() {
	ll a, b, k;
	cin >> a >> b >> k;
	if (a - k >= 0) {
		cout << a - k << " " << b << endl;
	}
	else {
		cout << 0 << " " << max(b - (k - a), (ll)0) << endl;
	}
	return 0;

}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma warning(disable:4996)
#ifdef _MSC_VER
#  define __builtin_popcount __builtin_popcountll
#  define __builtin_popcountll __popcnt
#endif
//#define int long long
using namespace std;
using ll = long long;
using ld = long double;
const long double PI = acos(-1.0);
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
inline void my_io() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cout << fixed << setprecision(10);
}

signed main(){
	int d;
	while (cin >> d, d) {
		int ans = 0;
		int n, m;
		cin>> n >> m;
		vector<int>ds(n, 0);//店舗の位置
		for (int i = 1; i < n; i++) {
			cin >> ds[i];
		}
		ds.push_back(d);
		sort(ds.begin(), ds.end());
		for (int i = 0; i < m; i++) {
			int k;
			cin >> k;
			
			auto low = lower_bound(ds.begin(), ds.end(), k);
			
			int y = (int)(low - ds.begin());
			if (y-1>=0) {
				ans += min(abs(ds[y] - k), abs(ds[y -1] - k));
			}
			else {
				ans += abs(ds[y] - k);
			}
		}
		cout<<ans<<endl;

	}



}	






Measured memory_bytes: 3676
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    string s;
    cin >> s;

    int b = 1;
    for (int i = 1; i < 4; i++) {
        if (s[i] == s[i - 1]) b = 0;
    }

    cout << (b ? "Good" : "Bad") << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)2019;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int l, r;
int32_t main(){_

   cin>>l>>r;

   if((r/mod)*mod >= l){
      cout<<0;
      return 0;
   }
      
   // 4036 4050

   else{
      l %= mod;
      r %= mod;

      int ans = inf;
      for (int i = l; i <= r; ++i)
      {
         for (int j = i+1; j <= r; ++j)
         {
            smin(ans, (i*j)%mod);
         }
      }
      cout<<ans;
   }

   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <set>

#include <regex>
#include <locale>
#include <iomanip>

using namespace std;
using ll = long long;

#define OVERLOAD3(_1,_2,_3,name,...) name
#define REP(i,n) REPI(i,0,n)
#define REPI(i,a,b) for(int i=int(a),i##_Len=int(b);i<i##_Len;++i)
#define rep(...) OVERLOAD3(__VA_ARGS__,REPI,REP,)(__VA_ARGS__)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())

int main () {
  int a, b; cin >> a >> b;
  cout << ((a+b)%2 == 0 ? (a+b)/2 : (a+b+1)/2) << endl;
}

Measured memory_bytes: 3164
#include<stdio.h>
#include<string.h>
//言語は「C++14(GCC 5.4.1)」
//AtCoder Beginner Contest 155-A

int main(void)
{
	int A, B, C;
	scanf("%d", &A);
	scanf("%d", &B);
	scanf("%d", &C);
	if ((A == B && B != C) || (B == C && C != A) || (C == A && A != B))
		printf("Yes");
	else
		printf("No");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int ans[1000000];
int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	string s;
	cin >> s;
	int n = s.size();
	for(int l=0, r=0; l<n; l=r) {
		while(r < n && s[r] == 'R')
			r++;
		int a = r-1, b = r;
		while(r < n && s[r] == 'L')
			r++;
		for(int i=l; i<r; i++) {
			if((a-i)%2)
				ans[b]++;
			else
				ans[a]++;
		}
	}
	for(int i=0; i<n; i++) {
		cout << ans[i] << ' ';
	}
}

Measured memory_bytes: 1104