akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main(){
  int i,n;
  double min,max,sum,ave;
  double data[100000];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%lf",&data[i]);
  }
  max=data[0];
  min=data[0];
  for(i=0;i<n;i++){
    sum+=data[i];
    if(data[i]>max){
      max=data[i];
    }
    if(data[i]<min){
      min=data[i];
    }
  }
  printf("%.0lf %.0lf %.0lf\n",min,max,sum);
  return 0;
}

Measured memory_bytes: 2816
#include<bits/stdc++.h>
#define ll long long
#define gc getchar
using namespace std;
inline ll read(){
    ll x=0,f=1;char ch=getchar();
    while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
    while (isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
    return (f==1)?x:-x;
}
int n,m;
ll base[66],pos[66];
void insert(ll x,ll id){
    for (ll i=63;i>=0;i--){
        if (x&(1ll<<i)){
            if (!base[i]){
                pos[i]=id;base[i]=x;break;
            }
            if (pos[i]<id) swap(pos[i],id),swap(base[i],x);
            x^=base[i];
        }
    }
}
ll a[10101],s[10101];
inline void solve(){
	int n=read();
	memset(base,0,sizeof base);
	memset(pos,0,sizeof pos);
	for (int i=1;i<=n;i++) a[i]=read(),insert(a[i],i);
	for (int i=1;i<=n;i++){
		char ch=gc();
		while (!isdigit(ch)) ch=gc();
		s[i]=ch-'0';
	}
	bool flag=1;
	for (ll i=63;i>=0;i--){
		if (base[i]&&s[pos[i]]) flag=0;
	}
	cout<<!flag<<endl;
}
int main(){
	int T=read();
	while (T--) solve();
    return 0;
}

Measured memory_bytes: 3548
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(std::unique(all(x)), x.end());
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;
const double PI=acos(-1);
using namespace std;
vector<int> dx={1,0,-1,0};
vector<int> dy={0,1,0,-1};
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

vector<vector<int>> children(100100);
map<pair<int,int>,int> color;
int k=0;
void dfs(int now, int parent) {
    int c=1;
    for(int child : children[now]) {
        if(child == parent) continue;
        if(c==color[make_pair(min(now,parent),max(now,parent))]) c++;
        k=max(k,c);
        color[make_pair(min(now,child),max(now,child))]=c;
        c++;
        dfs(child, now);
    }
}

int main() {
    int n;
    cin>>n;
    vector<pair<int,int>> vec(n);
    rep(i,n-1) {
        int a,b;
        cin>>a>>b;
        a--;b--;
        vec[i]=make_pair(min(a,b),max(a,b));
        children[a].push_back(b);
        children[b].push_back(a);
    }
    
    dfs(0,-1);
    cout<<k<<endl;
    rep(i,n-1) {
        cout<<color[vec[i]]<<endl;
    }
}



Measured memory_bytes: 15872
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

const int N = 1120;
const int K = 14;

int dp[2][N+1][K+1];
bool is_prime[N+1];
vector<int> prime;

int init(){
  fill(dp[0][0], dp[2][0], 0);
  int t = 0;
  dp[t][0][0] = 1;
  for(int k=0;k<prime.size();k++){
    for(int i=0;i<=N;i++) for(int j=0;j<=K;j++) dp[1-t][i][j] = dp[t][i][j];
    for(int i=0;i<=N;i++){
      if(i+prime[k] > N) continue;
      for(int j=0;j<=K-1;j++){
        if(dp[t][i][j] == 0) continue;
        dp[1-t][i+prime[k]][j+1] += dp[t][i][j];
      }
    }
    t = 1-t;
  }
  return t;
}

void sieve(){
  fill(is_prime, is_prime+N+1, true);
  is_prime[0] = is_prime[1] = false;
  for(int i=2;i<=N;i++){
    if(is_prime[i]){
      prime.push_back(i);
      for(int j=2*i;j<=N;j+=i) is_prime[j] = false;
    }
  }
}

main(){
  sieve();
  int t = init();
  int n, k;
  while(cin >> n >> k && (n|k)){
    cout << dp[t][n][k] << endl;
  }
  return 0;
}

Measured memory_bytes: 0
from collections import Counter
def counter(li, n):
    count = Counter()
    count.update(li)
    return count[n]

import sys
input = sys.stdin.readline
S = list(input())[:-1]
S = list(map(int, S))
N = len(S)
count_0 = counter(S, 0)
count_1 = N-count_0
print(N-abs(count_1-count_0))

Measured memory_bytes: 49776
#include<bits/stdc++.h>
using namespace std;
#define ll int
 #define watch(x) cerr<<(#x)<<" is "<<x<<nl;
#define f(i,a,b) for(ll i=a; i<b; i++)
#define fr(i,a,b) for(ll i=a; i>=b; i--)
#define mp make_pair
#define ff first 
#define ss second
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define mem(v,a) memset((v),a,sizeof(v));
#define mll map<ll,ll>
#define vll vector<ll>
#define nl endl

void solve(){
ll n,k,d; cin>>n>>k;
mll m;
f(i,0,n) m[i+1]=0;
f(i,0,k){
	cin>>d; ll x;
	f(j,0,d) {
		cin>>x;
		m[x]--;
	}
}
ll ans=0;
for(auto i:m) if(i.ss==0)ans++;  
cout<<ans;
}

signed main(){  
 ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int t; 
t=1;
//~ cin>>t; 
for(int _=0;_<t;_++){
      solve();
// cout<<"Case # "<<t<<;
}
return 0;
}


Measured memory_bytes: 3620
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
using namespace std;

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


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

const int mod = 1000000007;

int main(){
    int n;
    cin >> n;
    vector<int> num(n);

    rep(i, n){
        num[i] = i + 1;
    }
    vector<int> p(n), q(n);
    rep(i, n){
        cin >> p[i];
    }
    rep(i, n){
        cin >> q[i];
    }

    int a, b;
    int count = 0;
    do{
        if(num == p) a = count;
        if(num == q) b = count;
        count++;
    }while(next_permutation(num.begin(), num.end()));

    cout << abs(a - b) << endl;
}

Measured memory_bytes: 256
//%std
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read()
{
	int out = 0, fh = 1;
	char jp = getchar();
	while ((jp > '9' || jp < '0') && jp != '-')
		jp = getchar();
	if (jp == '-')
		fh = -1, jp = getchar();
	while (jp >= '0' && jp <= '9')
		out = out * 10 + jp - '0', jp = getchar();
	return out * fh;
}
const int P = 1e9 + 7;
const int N = 2e5 + 10;
int n, k;
ll sum(int l, int r)
{
	return 1LL * (l + r) * (r - l + 1) / 2;
}
int main()
{
	n = read(), k = read();
	ll ans = 0;
	for (int i = k; i <= n + 1; ++i)
		ans += sum(n - i + 1, n) - sum(0, i - 1) + 1, ans %= P;
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 3764
#include<iostream>
#include<algorithm>
#include<math.h>

typedef long long ll;
using namespace std;

int main(void) {
  ll n, w, ans=-1;
  cin >> n >> w;
  ll value, weight;
  ll table[n+1][w+1];
  for(int i=0;i<n+1;i++) fill(table[i], table[i]+w+1, 0);
  for(int i=1;i<n+1;i++) {
    cin >> weight >> value;
    for(int j=0;j<w+1;j++) {
       if(j<weight) { table[i][j] = table[i-1][j]; continue; }
       table[i][j] = max(table[i-1][j-weight]+value, table[i-1][j]);
    }
  }
  
  for(int i=0;i<w+1;i++) {
    ans = max(ans, table[n][i]);
  }
  cout << ans << endl;
 }

Measured memory_bytes: 79104
const lines=readlines(open("/dev/fd/0"))
let
    state=0
    global input
    input()=lines[state+=1]
end
int(s::String)=parse(Int32,s)
intSub(s::SubString{String})=parse(Int32,s)
intLine()=map(intSub,split(input()))
function main()
    a,b=intLine()
    println(~-a*~-b)
end
main()

Measured memory_bytes: 117580
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")  
#pragma GCC optimize ("-fno-defer-pop")
typedef long long int ll; 
typedef long double ld; 

int main()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    ll n,k;
    cin>>n>>k;

    string s;
    cin>>s;

    vector <ll> vec;

    vec.push_back(0);
    ll ans = 0;
    for(ll i=1;i<s.size();i++)
    {
        if(s[i]!=s[vec.back()])
        {
            ans += i-vec.back()-1;
            vec.push_back(i);
        }
    }
    ans += n-vec.back()-1;
    ll p = vec.size();
    
    for(ll i=1;i+1<vec.size();i+=2)
    {
        p-=2;
        ans += 2;
        k--;
        if(k==0)
            break;
    }

    if(p>=2)
    {
        if(k>0)
        {
            ans += 1;
        }
    }

    cout<<ans<<endl;

}

Measured memory_bytes: 1480
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
random_device rnd;
mt19937 mt(rnd());

const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7;
int main()
{
    int n;
    ll l;
    cin >> n >> l;
    VL v(n);
    rep(i, n) cin >> v[i];
    rep(i, n - 1)
    {
        if (v[i] + v[i + 1] >= l)
        {
            cout << "Possible" << endl;
            rep(j, i) cout << j + 1 << endl;
            for (int j = n - 2; j > i; j--)
                cout << j + 1 << endl;
            cout << i + 1 << endl;
            return 0;
        }
    }
    cout << "Impossible" << endl;
    return 0;
}

Measured memory_bytes: 1664
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
#define maxn 20
#define maxzt 70000
const int p=1e9+7;
template <typename T>inline T read()
{
    register T sum=0;
    register char cc=getchar();
    int sym=1;
    while(cc!='-'&&(cc>'9'||cc<'0'))cc=getchar();
    if(cc=='-')sym=-1,cc=getchar();
    sum=sum*10+cc-'0';
    cc=getchar();
    while(cc>='0'&&cc<='9')sum=sum*10+cc-'0',cc=getchar();
    return sym*sum;
}
template <typename T>inline T read(T &a)
{
    a=read<T>();
    return a;
}
template <typename T,typename... Others> inline void read(T& a, Others&... b)
{
    a=read(a);
	read(b...);
}
int n,m,ans,a[maxn],f[maxn][maxzt],jc[maxzt],inv[maxzt],bit[maxzt];
void upd(int &x,int y)
{
	x+=y;
	if(x>=p)
		x-=p;
}
int add(int x,int y)
{
	return (x+y)%p;
}
int sub(int x,int y)
{
	return (x-y+p)%p;
}
int mul(int x,int y)
{
	return 1ll*x*y%p;
}
int C(int n,int m)
{
	if(n<m)return 0;
	return mul(jc[n],mul(inv[m],inv[n-m]));
}
int main()
{
	read(n,m);
	for(int i=1;i<=m;i++)
		read(a[i]);
	for(int i=1;i<1<<n;i++)
		bit[i]=bit[i>>1]+(i&1);
	jc[0]=jc[1]=inv[0]=inv[1]=1;
	for(int i=2;i<1<<n;i++)
	{
		jc[i]=mul(jc[i-1],i);
		inv[i]=mul(p-p/i,inv[p%i]);
	}
	for(int i=2;i<1<<n;i++)
		inv[i]=mul(inv[i-1],inv[i]);
	f[m][0]=1;
	for(int i=m;i>=1;i--)
	{
		for(int j=0;j<1<<n;j++)
		{
			if(!f[i][j])
				continue;
			upd(f[i-1][j],f[i][j]);
			for(int k=0;k<n;k++)
				if((j|(1<<k))!=j)
					upd(f[i-1][j|(1<<k)],mul(mul(C((1<<n)-a[i]-j,(1<<k)-1),jc[1<<k]),f[i][j]));
		}
	}
	for(int i=0;i<1<<n;i++)
	{
		if(bit[i]&1)
			ans=sub(ans,mul(f[0][i],jc[(1<<n)-1-i]));
		else
			ans=add(ans,mul(f[0][i],jc[(1<<n)-1-i]));
	}
	printf("%d\n",mul(ans,1<<n));
    return 0;
}


Measured memory_bytes: 6272
#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdio.h>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <string>
#include <ctype.h>
#include <cstring>
#include <cstdio>
#include <sstream>
#include <functional>

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ll long long
//#define scanf scanf_s



int main()
{
	string s;
	int n;
	while (cin >> n >> s, n)
	{
		REP(i, n)
		{
			string tmp = "";
			int cnt = 1;
			REP(j, s.size())
			{
				if (s[j] == s[j + 1])
				{
					cnt++;
				}
				else
				{
					tmp = tmp + to_string(cnt) + s[j];
					cnt = 1;
				}
			}
			s = tmp;
		}
		cout << s << endl;
	}
	return 0;
}

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

int main(){
    ll X;
    cin>>X;
    ll sum = 0;
    rep(i, X){
        sum += i+1;
        if(sum >= X){
            cout << i+1 << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
n = int(input())
dic = {}
ans_list = []

for i in range(n):
    cmd,num = input().split()
    if   cmd == 'insert':
        dic[num] = i
    elif cmd == 'find':
        if dic.__contains__(num):
            ans_list.append('yes')
        else:
            ans_list.append('no')

for ans in ans_list:
    print(ans)


Measured memory_bytes: 45816
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 200000;

int n; ll c, ans = 0;

ll f[N][2], g[N][2];
// f[i][0] = sum, f[i][1] = dis;

inline void ck_max( ll &a, ll b ) { if( a < b ) a = b; }

struct tSushi {
	ll x, v;
} s[N];

struct deleteable_heap {
	priority_queue <ll> q1, q2;
	
	inline void push( ll val ) { q1.push( val ); }
	inline void check() {
		if( q1.empty() || q2.empty() ) 	
			return;
			 
		while( q1.top() == q2.top() ) {
			q1.pop(), q2.pop();
			if( q1.empty() || q2.empty() )
				break;
		}
	}
	inline void erase( ll val ) { q2.push( val ); }
	inline ll top() { check(); return q1.top(); }
} heap_1, heap_2;

int main()
{
	memset( f, 0, sizeof( f ) );
	memset( g, 0, sizeof( g ) );
	
	scanf( "%d%lld", &n, &c );
	for( int i = 1; i <= n; i ++ )
		scanf( "%lld%d", &s[i].x, &s[i].v );
	
	for( int i = 1; i <= n; i ++ )
		f[i][0] = f[i-1][0] + s[i].v, f[i][1] = s[i].x;
	for( int i = n; i >= 1; i -- )
		g[i][0] = g[i+1][0] + s[i].v, g[i][1] = c - s[i].x;
		
	for( int i = 1; i <= n; i ++ )
		ck_max( ans, f[i][0] - f[i][1] ), 
		ck_max( ans, g[i][0] - g[i][1] );
		
//	for( int i = 1; i <= n; i ++ )
//		printf( "f0:%lld, f1:%lld, g0:%lld, g1:%lld\n", f[i][0], f[i][1], g[i][0], g[i][1] );
		
	for( int i = 1; i <= n; i ++ )
		heap_1.push( g[i][0] - g[i][1] ),
		heap_2.push( g[i][0] - g[i][1] * 2 );
	
	for( int i = 1; i < n; i ++ )
	{
		heap_1.erase( g[i][0] - g[i][1] );
		heap_2.erase( g[i][0] - g[i][1] * 2 );
		ll tmp_1 = heap_1.top() + f[i][0] - f[i][1] * 2;
		ll tmp_2 = heap_2.top() + f[i][0] - f[i][1];
		ck_max( ans, tmp_1 );
		ck_max( ans, tmp_2 ); 
	}
	
	printf( "%lld\n", ans );
	
	return 0;
} 

Measured memory_bytes: 13164
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
 
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#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<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
const int mod=1e9+7;

int main(){
  ll s;cin>>s;
  ll x1,x2,x3,y1,y2,y3;
  x1=y1=0;
  x2=(ll)1e9;
  y2=1ll;
  y3=(s+x2-1)/x2;
  x3=y3*x2-s;
  cout<<x1<<" "<<y1<<" "<<x2<<" "<<y2<<" "<<x3<<" "<<y3<<endl;
}

Measured memory_bytes: 256
n = int(input())


if n ==0:
    print(0)

elif n == 1:
    print(1)

else:
    l = []
    while n!=0 and n!=1:
        if n > 0:
            sho = -(n//2)
        else:
            sho = -(-n//(-2))
        amari = n-sho*(-2)
        l = [amari] + l
        n = sho

        if n == 1:
            l = [1] + l

    print("".join(list(map(str, l))))

Measured memory_bytes: 3064
#include<stdio.h>

int main(){
  int N, M, X, count0 = 0, countN = 0, a;
  scanf("%d %d %d", &N, &M, &X);
  for (int i = 0; i < M; i++){
    scanf("%d", &a);
    if(a < X){
      count0++;
    } else if(a > X){
      countN++;
    }
  }
  if(count0 < countN){
    printf("%d\n", count0);
  } else {
    printf("%d\n", countN);
  }
  
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr);
#else
	#define eprintf(...) 42
#endif

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
	return (ull)rng() % B;
}

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

clock_t startTime;
double getCurrentTime() {
	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}

const int L = 18;
const int M = (1 << L);
const int N = 52;
ll C[N][N];
ll D[N];
int cnt[M];
int ppc[M];
int n, k;
int S, T;

ll solve(vector<int> b) {
	/*
	printf("solve");
	for (int x : b)
		printf(" %d", x);
	printf("\n");
	*/
	for (int i = 0; i < M; i++)
		cnt[i] = 0;
	for (int x : b)
		cnt[x]++;
	for (int k = 0; k < L; k++)
		for (int mask = 0; mask < M; mask++)
			if (((mask >> k) & 1) == 1)
				cnt[mask] += cnt[mask ^ (1 << k)];
	ll ans = 0;
	for (int mask = 0; mask < M; mask++) {
		if ((mask & T) != mask) continue;
		if (ppc[T ^ mask] % 2 == 0)
			ans += D[cnt[mask]];
		else
			ans -= D[cnt[mask]];
	}
	return ans;
}

int main()
{
	startTime = clock();
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	for (int i = 1; i < M; i++)
		ppc[i] = ppc[i / 2] + (i & 1);

	scanf("%d%d%d%d", &n, &k, &S, &T);
	if ((S & T) != S) {
		printf("0\n");
		return 0;
	}
	for (int i = 0; i < N; i++)
		C[i][0] = C[i][i] = 1;
	for (int i = 1; i < N; i++)
		for (int j = 1; j < i; j++)
			C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
	for (int i = 0; i < N; i++)
		for (int j = 0; j < k; j++)
			D[i] += C[i][j];

	vector<int> a;
	for (int i = 0; i < n; i++) {
		int x;
		scanf("%d", &x);
		if ((x & S) != S) continue;
		if ((x & T) != x) continue;
		a.push_back(x ^ S);
	}
	T ^= S;
	//printf("T = %d\n", T);
	n = (int)a.size();
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		vector<int> b;
		for (int j = 0; j < i; j++)
			b.push_back(a[j] ^ a[i]);
		ans += solve(b);
	}
	printf("%lld\n", ans);

	return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<long long> a(n);
  for(int i = 0; i < n; i++) cin >> a.at(i);
  
  sort(a.begin(), a.end());
  long long ans = a.at(n-1), m = a.at(0);
  long long check = (ans + 1) / 2;
  for(int i = 0; i < n-1; i++){
    if(abs(check - m) > abs(check - a.at(i))) m = a.at(i);
  }
  
  cout << ans << " " << m << endl;
}

Measured memory_bytes: 4052
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<array>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cassert>
#include<functional>
#include<random>
#include<complex>
#include<bitset>
#include<chrono>
//#include<boost/multiprecision/cpp_int.hpp>
#define int int64_t
#define uint uint64_t
#define REP(i, a, b) for (int64_t i = (int64_t)(a); i < (int64_t)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define SZ(X) ((int64_t)((X).size()))
#define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define Min(x) *min_element(ALL(x))
#define Max(x) *max_element(ALL(x))
#define Unique(L) (L.erase(unique(ALL(L)), L.end()))
#define intmax (std::numeric_limits<int64_t>::max() / 4)
#define doublemax (std::numeric_limits<double>::max() / 4)
using namespace std;
//typedef boost::multiprecision::cpp_int bigint;
const double EPS = 1e-9;
const double PI = acos(-1.0);



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

	int N, C, K;
	cin >> N >> C >> K;
	vector<int>T(N);
	rep(i, N)cin >> T[i];
	sort(ALL(T));

	int ans = 0;

	int wait_person = 0;
	int time_limit = 0;
	int count = 0;
	while (count < N) {
		time_limit = T[count] + K;
		int a = count;
		for (; a < N&&T[a] <= time_limit; a++);
		int num = a - count;
		if (num <= C)count = a;
		else count += C;
		ans++;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
/**
 *    author:  zjsdut
 *    created: 2020/03/14 19:58:48
 **/
#include <bits/stdc++.h>

using namespace std;

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

template <typename A, typename B> bool chkmin(A &a, const B &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}

template <typename A, typename B> bool chkmax(A &a, const B &b) {
  if (b > a) {
    a = b;
    return true;
  }
  return false;
}

template <typename T> istream &operator>>(istream &stream, vector<T> &vec) {
  for (auto &x : vec)
    stream >> x;
  return stream;
}

void scan() {}

template <class T, class... Args> void scan(T &a, Args &... rest) {
  cin >> a;
  scan(rest...);
}

using ll = long long;
using vl = vector<ll>;
using vb = vector<bool>;
using vi = vector<int>;
using pii = pair<int, int>;
template <typename T> using vv = vector<vector<T>>;
#define rng(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define up(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define down(i, b, a) for (int i = int(b); i >= int(a); i--)
#define rep(n)                                                                 \
  for (int _iter_##n = 0, _num_##n = (int)n; _iter_##n < _num_##n; ++_iter_##n)
#define FOR(x, cont) for (const auto &x : cont)
#define For(x, cont) for (auto &x : cont)
#define all(x) begin(x), end(x)
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ep emplace
#define SZ(x) (int)(x).size()
#define UNIQ(vec) (vec).erase(unique(all(vec)), end(vec))
#define LB(cont, x) int(lower_bound(all(cont), x) - begin(cont))
#define UB(cont, x) int(upper_bound(all(cont), x) - begin(cont))

template <typename T>
ostream &operator<<(ostream &stream, const vector<T> &vec) {
  if (!vec.empty()) {
    stream << vec[0];
    for (size_t i = 1; i != vec.size(); ++i)
      stream << ' ' << vec[i];
  }
  return stream;
}

template <typename T> void print(const vector<T> &t) { cout << t << '\n'; }

template <typename T> void print(const vector<vector<T>> &t) {
  for (const auto &row : t) {
    print(row);
  }
}

template <typename T> void print(const T &t) { cout << t << ' '; }

template <typename T, typename... Args>
void print(const T &t, const Args &... rest) {
  print(t);
  print(rest...);
}

template <typename T> void println(const T &t) { cout << t << '\n'; }

template <typename T, typename... Args>
void println(const T &t, const Args &... rest) {
  print(t);
  println(rest...);
}

int main() {
#if defined LOCAL
  ifstream in("in.txt");
  cin.rdbuf(in.rdbuf());
#endif
  vi a{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k;
  scan(k);
  println(a[k-1]);
  return 0;
}

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

using namespace std;

int main() {
  int n, l, r;
  while (cin >> n >> l >> r, n) {
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    int ans = 0;
    for (int x = l; x <= r; x++) {
      int i = 0;
      while (i < n && x % a[i] != 0) {
        i++;
      }
      if (i % 2 == 0) ans++;
    }
    cout << ans << endl;
  }

  return 0;
}


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

#define PI acos(-1)
#define pb push_back
#define int long long int
#define pi pair<int, int>
#define fir first
#define sec second
#define MAXN 3001
#define MAXL 20
#define mod 1000000007

int n, m, k;
int grid[MAXN][MAXN];
int dp[MAXN][MAXN][4];

int solve(int i, int j, int k)
{
  if (i == n - 1 && j == m - 1)
  {
    if (k < 3)
      return grid[i][j];
    else
      return 0;
  }
  if (dp[i][j][k] != -1)
    return dp[i][j][k];
  int best = 0;
  if (i + 1 < n)
  {
    if (k < 3)
      best = max(best, grid[i][j] + solve(i + 1, j, 0));
    best = max(best, solve(i + 1, j, 0));
  }
  if (j + 1 < m)
  {
    if (k < 3)
      best = max(best, grid[i][j] + solve(i, j + 1, k + 1));
    best = max(best, solve(i, j + 1, k));
  }
  return dp[i][j][k] = best;
}
signed main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m >> k;
  for (int i = 0; i < k; i++)
  {
    int a, b, c;
    cin >> a >> b >> c;
    a--, b--;
    grid[a][b] = c;
  }
  memset(dp, -1, sizeof(dp));
  cout << solve(0, 0, 0) << endl;
}

Measured memory_bytes: 355612
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
template<class T> inline istream& operator >> (istream & c, vector<T> & A) {rep(i, A.size()) c >> A[i];return c;}
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<ll> a(n);
	cin >> a;
	sort(a.rbegin(), a.rend());
	priority_queue<ll> pq;
	pq.push(a[0]);
	ll ans = 0;
	rrep(i, n) {
		ll tmp = pq.top(); pq.pop();
		ans += tmp;
		pq.push(a[i]);
		pq.push(a[i]);
	}
	cout << ans << endl;
	return 0;
}

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

#define ff first
#define ss second
#define endl '\n'

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

	int n, k;
	cin >> n >> k;

	int total = ((n - 1) * (n - 2)) / 2;
	if (total < k) {
		cout << -1 << endl;
		return 0;
	}

	vector<pair<int, int> > edges;
	for (int i = 2; i <= n; ++i) {
		edges.push_back({1, i});
	}

	for (int i = 2; i <= n && total > k; ++i) {
		for (int j = i+1; j <= n && total > k; ++j, --total) {
			edges.push_back({i, j});
		}
	}

	cout << edges.size() << endl;
	for (pair<int, int> e : edges) {
		cout << e.ff << ' ' << e.ss << endl;
	}

	return 0;
}

Measured memory_bytes: 384
n=int(input())
six=[6**i for i in range(1,7)]
nine=[9**i for i in range(1,6)]
credit=[1]
for i in six:
    credit.append(i)
for i in nine:
    credit.append(i)

credit.sort()

dp=[[float("inf") for _ in range(n+1)] for _ in range(len(credit))]
for i in range(n+1):
    dp[0][i]=i
for i in range(len(credit)):
    dp[i][0]=0
for c_i in range(1,len(credit)):
    for m_i in range(1,n+1):
        if credit[c_i]>m_i:
            dp[c_i][m_i]=dp[c_i-1][m_i]
            continue
        tmp=dp[c_i][m_i-credit[c_i]]+1
        dp[c_i][m_i]=min(tmp,dp[c_i-1][m_i])
#print(credit)
#import numpy as np
#print(np.array(dp))
print(dp[-1][-1])

Measured memory_bytes: 103036
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        Main m = new Main(sc);
        m.show(m.solve());
        sc.close();
    }
    
	//フィールド
    Scanner sc;
    String S;
    
    //入力
    Main(Scanner sc) {
        this.sc = sc;
        S = sc.next();
    }
    
    //解答処理
    private boolean solve() {
    	boolean judge = false;
    	int N = S.length();
      
    	if (Palindrome(S.substring(0, N/2)) && Palindrome(S.substring(N/2+1, N)) && Palindrome(S)) {
    		judge = true;
    	}
         
        return judge;
    }
    
    private boolean Palindrome(String str) {	//回文か判定するメソッド
    	boolean kaibun = false;
    	StringBuilder reverses = new StringBuilder(str).reverse();
    	String reverseS = reverses.toString();
    	
    	if (str.equals(reverseS)) {
    		kaibun = true;
    	}
    	
    	return kaibun;
    }
    
    //出力
    public void show(boolean answer) {
        if (answer) {
        	System.out.println("Yes");
        } else {
        	System.out.println("No");
        }
    }

}


Measured memory_bytes: 35660
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

using i64 = int64_t;

int N, M, K;

const string YES = "Yes", NO = "No";

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

    for (int j = 0; j <= N; ++j) {
        int b = M * j;
        int d = N - 2*j;

        for (int k = 0; k <= M; ++k) {
            int s = b + d * k;
            if (s == K) {
                cout << YES << endl;
                return 0;
            }
        }
    }
    cout << NO << endl;

    return 0;
}


Measured memory_bytes: 384
N = int(input())
S = input()
dp = {}
si = set()
for i in range(N-2):
  if S[i] in si:
    continue
  si.add(S[i])
  for j in range(i+1, N-1):
    if dp.get(S[i] + S[j], 0) > 0:
      continue
    dp[S[i] + S[j]] = len(set(S[j+1:]))
print(sum(dp.values()))

Measured memory_bytes: 68464
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,k,x,y;

int main(){
  ll ans=0;
  cin >> n ;
  if (n%2==1)
  {
    cout<<0<<endl;
    return 0;
  }
  
  //ans=n/10;
  ll myno=10;
  ll zerosn=1;

  for(;myno<=n;myno*=5)
  {
    ans+=(n/myno);
    //zerosn++;
  }


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

Measured memory_bytes: 256
// #include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <cmath>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <stack>
#include <numeric>
// #include <windows.h>
using namespace std;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = V<VV<T>>;
template<class T1, class T2> using P = pair<T1, T2>;
using I = int;
using D = double;
using B = bool;
using C = char;
using S = string;
using LL = long long;
using LD = long double;
using ULL = unsigned long long;
using PII = P<I, I>;
using VPII = V<PII>;
using PLL = P<LL, LL>;
using VPLL = V<PLL>;
using VI = V<I>;
using VVI = VV<I>;
using VLL = V<LL>;
using VVLL = VV<LL>;
using VC = V<C>;
using VVC = VV<C>;
using VS = V<S>;
using VVS = VV<S>;
using VB = V<B>;
using VVB = VV<B>;
#define REP(type, i, n) for (type i = 0; i < (type)(n); ++i)
#define REP2(type, i, m, n) for (type i = (m); i < (type)(n); ++i)
#define REPR(type, i, n) for (type i = (n)-1; i >= 0; --i)
#define REPR2(type, i, m, n) for (type i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a, type) sort(ALL(a), greater<type>())
#define SORTF(a, comp) sort(ALL(a), comp)
#define REVERSE(a) reverse(ALL(a))
#define SIZE(a, type) ((type)(a).size())
#define bit_search(bit, n) REP(LL, bit, 1LL<<(n))
#define bit_check(bit, i) ((bit>>(i)) & 1)
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) (lower_bound(ALL(a), (x)) - a.begin())
#define bisect_right(a, x) (upper_bound(ALL(a), (x)) - a.begin())
#define INPUT(a) REPx(&x, a) cin >> x;
#define INPUT2(a) REPx(&x, a) INPUT(x);
#define INPUTP(a) REPx(&x, a) cin >> x.first >> x.second;
#define ENDL cout << endl;

const int INF = 2e9;
// const LL INF = 9e18;
const LL MOD = 1e9+7;

template<class T> using PRIORITY_QUEUE = priority_queue< T, V<T>, greater<T> >;
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> inline void debug1(V<T> A){REP(int, i, SIZE(A, int)){if (A[i] == INF) cout << "I ";else cout << A[i] << " ";}ENDL}
template<class T> inline void debug2(VV<T> A){REP(int, i, SIZE(A, int)){REP(int, j, SIZE(A[i], int)){if (A[i][j] == INF) cout << "I "; else cout << A[i][j] << " ";}ENDL}}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, s = 1, t = 1;
  cin >> n;
  REP(int, i, n)
  {
    int a;
    cin >> a;
    s *= 3;
    if (a % 2 == 0) t *= 2;
  }
  cout << s - t << endl;

  return 0;
}


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

using namespace std;

int n;
int d[100005][5];
bool check[100005][5];
int memo[100005][5];

int dp(int pos,int last){

    if(pos>n) return 0;

    if(check[pos][last])return memo[pos][last];

    int op1= (last!=1? d[pos][1]+dp(pos+1,1):0);
    int op2= (last!=2? d[pos][2]+dp(pos+1,2):0);
    int op3= (last!=3? d[pos][3]+dp(pos+1,3):0);

    memo[pos][last]=max(op1,max(op2,op3));
    check[pos][last]=true;
    return memo[pos][last];

}

int main() {
    cin>>n;
    for(int i =1;i<=n;i++){
        cin>>d[i][1]>>d[i][2]>>d[i][3];
    }

    cout << dp(0,0);

    return 0;
}

Measured memory_bytes: 10880
#include <iostream>
using namespace std;
using ll = long long;

int main() {
	ll n;
	cin>>n;
	string s;
	cin>>s;
	if(s.length() <= n)
		cout<<s;
	else
		cout<<s.substr(0,n)+"...";
	// your code goes here
	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,a100,a10,a1;
  cin >> a;
  a100=a/100;
  a10=(a-100*a100)/10;
  a1=a-(100*a100+10*a10);
  cout << a100+a10+a1 <<endl;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
typedef long long ll;
const int mod= 1e+9+7;

int main() {
    ll N,T; cin>>N>>T;
    vector<ll>t(N);
    rep(i,N)cin>>t[i];
    ll ans =0;
    rep(i,N-1){
        if(t[i]+T>=t[i+1])ans+=t[i+1]-t[i];
        else ans+=T;
    }
    ans+=T;
    cout<<ans<<endl;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int N = stdIn.nextInt();
        Activity[] days = new Activity[N];

        for (int i = 0; i < N; i++) {
            int a = stdIn.nextInt();
            int b = stdIn.nextInt();
            int c = stdIn.nextInt();
            days[i] = new Activity(a, b, c);
        }
        
        Activity[] best = new Activity[N];
        best[0] = days[0];

        for (int i = 1; i < days.length; i++) {
            Activity prev = best[i - 1];
            Activity today = days[i];

            best[i] = new Activity(
                    Math.max(today.a + prev.b, today.a + prev.c),
                    Math.max(today.b + prev.a, today.b + prev.c),
                    Math.max(today.c + prev.a, today.c + prev.b));
        }

        Activity last = best[best.length - 1];
        System.out.println(Math.max(Math.max(last.a, last.b), last.c));
    }

    static class Activity {
        int a;
        int b;
        int c;

        public Activity(int a, int b, int c) {
            this.a = a;
            this.b = b;
            this.c = c;
        }
    }
}


Measured memory_bytes: 95744
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){ 
  int n[5], k;
  rep(i, 5) cin >> n[i]; cin >> k;
  bool ok = true;
  sort(n, n+5);
  if(abs(n[0] - n[4])> k)ok = false;
  
  cout << (ok? "Yay!" : ":(") << ln;
}


Measured memory_bytes: 256
a, b = list(map(int, input().split()))
bin_b = bin(b)[2:]
bin_a = bin(a)[2:].zfill(len(bin_b))
ans = []
for i in range(len(bin_b)):
    cnt = b-a+1
    d = {-1:0,1:0}
    ai = bin_a[-(i+1)]
    if ai == "0":
        ai = -1
    else:
        ai = 1
    if i == 0:
        hoge = 0
        if ai == 1:
            hoge = (cnt+1)//2
        else:
            hoge = cnt//2
        if hoge%2:
            ans.append(1)
        else:
            ans.append(0)
        continue
    ai_1 = int(bin_a[-i:],2) if i >0 else 0
    start = 2**i - ai_1
    if start >= cnt:
        d[ai] += cnt
        cnt = 0
    else:
        d[ai] += start
        cnt -= start
    ai *= -1
    hoge = cnt//(2**i)
    fuga = cnt % (2**i)
    if hoge%2:
        ai *= -1
    d[ai] += fuga
    if d[1]%2:
        ans.append(1)
    else:
        ans.append(0)
e = int("".join(map(str,ans[::-1])), 2)
print(e)

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

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define PRINT(item) cout << (item) << endl;
#define PRINT_VEC(V) \
    for (auto v : (V)) cout << v << ' ';
#define PRINT_ENTER() cout << endl;

int main() {
    /* code */
    string s;
    cin >> s;
    int counter{};
    REP(i, 3) {
        if (s[i] == '1') {
            ++counter;
        }
    }
    cout << counter << endl;
    return 0;
}

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

int main() {
  string S;
  cin >> S;
  int ans=1000000;
  for (int i = 0; i < S.size()-2; i++) {
    int g=stoi(S.substr(i,3));   

    ans=min(abs(753-g),ans);
  }
    cout<<ans<<endl;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,b) FOR(i,0,b)
#define PB push_back
#define ALL(c) c.begin(),c.end()
using namespace std;
typedef long long LL;
typedef int ut;
typedef pair<ut,ut> pr;
typedef vector<ut> VI;
typedef vector<pr> Vpr;
const int SIZE=100;
int maps[SIZE][SIZE];
int d[SIZE],a[SIZE],k[SIZE],t[SIZE];
int DP[5][10][10];//d,n,l;
int p[5][10][10];//d,n,k
int N,M,L;
int solve2(int now,int n,int l){
//	cout << now << " " << n << " " << l << endl;
	if(n>N) return 0;
	if(DP[now][n][l]) return DP[now][n][l];	
	int ans=solve2(now,n+1,l);
	if(l)
	FOR(i,1,N+1){
		ans=max(ans,p[now][n][i]+solve2(now,n+i,l-1));
	}
	return DP[now][n][l]=ans;
}
int solve(int now,int l){
//	cout << now <<" 1 " << endl;
	if(now==5) return 0;
	int ans=solve(now+1,l);
	FOR(i,1,min(l,N)+1){
	//	cout << now << " " << i<< endl;
		//cout << solve2(now,1,i) << " "<< i << endl;
		ans=max(ans,solve2(now,1,i)+solve(now+1,l-i));
	//	cout << now << endl;
	}
	return ans;
}
int main(){
	cin >> N >> M >> L;
	REP(i,M){
		cin >> d[i] >> a[i] >> k[i] >> t[i];
		p[d[i]][a[i]][k[i]]=max(t[i],p[d[i]][a[i]][k[i]]);
	}
	cout << solve(0,L) << endl;
	return 0;
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vb=vector<bool>;
using vvb=vector<vb>;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pll = pair<ll,ll>;
using vpii = vector<pii>;
using vpli = vector<pli>;
using vpll = vector<pll>;

#define rep(i, n) for(int i=0;i<(int)n;i++)
#define rep2(i, s, n) for(int i=(s);i<(int)n;i++)
int INF=1e9+7;

int main() {
  int N;
  string S;
  cin >> N >> S;
  
  int ans=1;
  rep(i,N-1) {
    if(S[i]!=S[i+1]) ans++;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3756
#include<iostream>
using namespace std;
int main(){
  int n,cnt=0;
  cin >> n;
  int tv[n],tc[n];
  for(int i=0;i<n;i++){
    cin >> tv[i] ;
   }
  for(int i=0;i<n;i++){
    cin >> tc[i] ;
   }

  for(int i=0;i<n;i++){
    if(tv[i]>tc[i]){
      cnt+=tv[i]-tc[i];
    }
  }

  cout <<cnt << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> i_i;

#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)(x).size())

const double PI  = acos(-1.0);
const double EPS = 1e-9;
const ll INF = 1e9+10;
const ll mod = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define print(x) cerr << #x << " is " << x << endl;
//#define print(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; 

vector<pair<ll, ll> > pairs;

int main()
{
    int N;
    string S;
    cin >> N;
    cin >> S;
    int ans;
    rep(i, N - 2){
        if (S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C'){
            ans++;
        }
    }
    cout << ans;
    return 0;    
}


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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

const int CM = 200010;
LL ans = 123456789012345678;
int N;
int a[CM];
LL s[CM];

int main(){
	scanf("%d" , &N);
	repp(i,1,N+1){
		scanf("%d" , a + i);
		s[i] = s[i-1] + a[i];
	}
	repp(i,1,N){
		ans = min(ans , abs(s[N]-2*s[i]));
	}
	printf("%lld\n" , ans);
	return 0;
}


Measured memory_bytes: 2560
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val aList = readLine()!!.split(' ').map(String::toInt).toMutableList()
    aList.add(0, -1)
    val ansArray = IntArray(n + 2) { 0 }

    for (i in n downTo 1) {
        if (n / i <= 1) {
            ansArray[i] = aList[i]
        } else {
            var sum = 0
            for (j in 1..(n / i)) {
                sum += ansArray[i * j]
            }
            if (sum % 2 == aList[i]) {
                //do nothing
            } else {
                ansArray[i] = 1
            }
        }
    }
    val count = ansArray.count { it == 1 }
    println(count)
    if (count > 0) {
        for (i in 1..n) {
            if (ansArray[i] == 1) {
                print(i)
                print(" ")
            }
        }
        println()
    }
}

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

#define rep(i, s, t) for (int i = s; i < int(t); ++i)

#define sc	scanf
#define pr	printf
#define ff	first
#define ss	second
#define mp	make_pair
#define pb	push_back
#define eb	emplace_back
#define range(c)	c.begin(), c.end()
#define const_range(c)	c.cbegin(), c.cend()
#define lowbit(x)	((x) & -(x))
#define pop_count	__builin_popcount
#define pop_count64	__builtin_popcountll
#define tail_count	__builtin_ctz
#define tail_count64	__builtin_ctzll
#define lead_count	__builtin_clz
#define lead_count64	__builtin_clzll

#define temp_name template<typename

temp_name T1, typename T2> ostream& operator<< (ostream& os, const pair<T1, T2>& p) { return os << "<" << p.ff << "," << p.ss << ">"; }
#define container_ostream(container)						\
temp_name... T> ostream& operator<< (ostream& os, const container<T...>& c) {	\
	if (c.empty()) return os << "{ }";					\
	auto iter = c.cbegin();							\
	os << "{ " << *iter;							\
	while (++iter != c.cend()) os << ", " << *iter;				\
	return os << " }";							\
}
container_ostream(vector);
container_ostream(set);
container_ostream(map);

void dbg() { cerr << endl;}
temp_name Head, typename... Tail> void dbg(Head h, Tail... t) { cerr << " " << h; dbg(t...); }

#ifdef LOCAL
#define debug(...) cerr << "[ "#__VA_ARGS__" ] :", dbg(__VA_ARGS__)
#else
#define debug(...) 0
#endif

typedef long long i64;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<i64> vl;

temp_name T> T& minn(T& x, const T& y) { return x = min(x, y); }
temp_name T> T& maxx(T& x, const T& y) { return x = max(x, y); }

constexpr const int mod = 1000000007;
constexpr int add(int a, int b) { return a + b < mod ? a + b : a + b - mod; }
constexpr int sub(int a, int b) { return a < b ? mod + a - b : a - b; }
constexpr int mul(int a, int b) { return 1LL * a * b % mod; }
#define more_para(type, func) temp_name... T> constexpr type func(type a, type b, T... c) { return func(func(a, b), c...); }
more_para(int, add);
more_para(int, sub);
more_para(int, mul);
constexpr int square(int a) { return mul(a, a); }
constexpr int fpow(int a, int b) { return b ? mul(b & 1 ? a : 1, square(fpow(a, b >> 1))) : 1; }

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	constexpr const int maxn = 1024;
	vi inv(maxn), fac(maxn), fiv(maxn);
	inv[0] = inv[1] = fac[0] = fac[1] = fiv[0] = fiv[1] = 1;
	rep(i, 2, maxn) {
		inv[i] = mul(inv[mod % i], mod - mod / i);
		fac[i] = mul(fac[i - 1], i);
		fiv[i] = mul(fiv[i - 1], inv[i]);
	}
	auto C = [&] (int n, int k) -> int { return mul(fac[n], fiv[k], fiv[n - k]); };
	int n, k;
	cin >> n >> k;
	vi a(k);
	rep(i, 0, k) cin >> a[i];
	if (accumulate(const_range(a), 0) < n) return cout << "0" << endl, 0;
	vvi f(k);
	rep(i, 0, k) {
		f[i].resize(a[i] + 1);
		rep(j, 0, a[i] + 1) f[i][j] = mul(fiv[j], C(n - j, a[i] - j));
	}
	rep(i, 1, k) {
		vi g(f[0].size() + f[i].size() - 1);
		rep(j0, 0, f[0].size()) rep(j1, 0, f[i].size()) g[j0 + j1] = add(g[j0 + j1], mul(f[0][j0], f[i][j1]));
		f[0] = move(g);
	}
	int ans = mul(f[0][n], fac[n]);
	cout << ans << endl;
}


Measured memory_bytes: 512
n, m = map(int, input().split())
dic = {}
ans = [0]*m
for i in range(m):
  p, y = map(int, input().split())
  dic.setdefault(p, []).append([y, i])
for i, j in dic.items():
  j = sorted(j)
  for k, l in enumerate(j):
    ans[l[1]]= str(i).zfill(6) + str(k + 1).zfill(6)
for i in range(len(ans)):
  print(ans[i])
  

Measured memory_bytes: 47536
#include <bits/stdc++.h>
#include <algorithm>
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define RFOR(i, a, b) for(int i = a; i >= b; --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
const int INF = 1e9;
typedef long long ll;
using namespace std;
int main() {
    int n, m;
    cin >> n >> m;
    int G[8][8] = {};
    int ans = 0;
    REP(i, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a][b] = G[b][a] = 1;
    }
    vector<int> nums(n);
    REP(i, n) {
        nums[i] = i;
    }
    do {
        bool flag = true;
        FOR(i, 0, n-1) {
            if(!G[nums[i]][nums[i+1]]) flag = false;
        }
        if(flag) ans++;
    }while(next_permutation(nums.begin()+1, nums.end()));
    cout << ans << endl;
}

Measured memory_bytes: 256