akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  string s;
  cin>>s;
  if(s=="keyence") {
    cout << "YES" << endl;
    return 0;
  }
  int n=s.size();
  rep(i,n) {
    repeat(j,i,n) {
      stringstream ss;
      rep(k,i) ss<<s[k];
      repeat(k,j+1,n)ss<<s[k];
      if(ss.str()=="keyence") {
        cout << "YES" << endl;
        return 0;
      }
    }
  }
  cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
    public class Main{
	public static void main(String[] args){
	    Scanner scan = new Scanner(System.in);
	    int[] task = new int[3];
	    List<Integer> taskS = new ArrayList<Integer>();
	    int Answer;
	    for(int i = 0; i < 3; i++){
		task[i] = scan.nextInt();
		    taskS.add(task[i]);
	    }
	    Collections.sort(taskS);
	    Answer = taskS.get(1)-taskS.get(0)
		+ taskS.get(2)-taskS.get(1);
	    System.out.println(Answer);
	}

	
    }


Measured memory_bytes: 21716
import sys
input = sys.stdin.readline
sys.setrecursionlimit(pow(10, 6))


def main():
    n, m = map(int, input().split())
    s = input().strip()
    ab = [tuple(map(int, input().split())) for _ in range(m)]
    edges = [[] for _ in range(n)]
    for a, b in ab:
        edges[a - 1].append(b - 1)
        edges[b - 1].append(a - 1)
    
    ab = [[0, 0] for i in range(n)]
    stack = []
    for i in range(n):
        for e in edges[i]:
            if s[e] == 'A':
                ab[i][0] += 1
            else:
                ab[i][1] += 1
        if ab[i][0] == 0 or ab[i][1] == 0:
            stack.append(i)
    
    deleted = [False for i in range(n)]
    while len(stack) > 0:
        q = stack.pop()
        if deleted[q]:
            continue
        deleted[q] = True
        for e in edges[q]:
            if not deleted[e]:
                if s[q] == 'A':
                    ab[e][0] -= 1
                    if ab[e][0] == 0:
                        stack.append(e)
                else:
                    ab[e][1] -= 1
                    if ab[e][1] == 0:
                        stack.append(e)
    
    for d in deleted:
        if not d:
            print("Yes")
            break
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 81748
#include<bits/stdc++.h>
using namespace std;
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long

void solve() {
	int n, w;
	cin >> n >> w;
	vector<int> wi(n), vi(n);
	int totalsum = 0;
	for(int i=0; i<n; i++){
		cin >> wi[i] >> vi[i];
		totalsum += vi[i];
	}
	vector<int> dp(totalsum + 1, w+1);
	dp[0] = 0;

	for(int i=0; i<n; i++){
		for(int j=totalsum-vi[i]; j>=0; j--){
			dp[j + vi[i]] = min(dp[j+vi[i]], dp[j] + wi[i]);
		}
	}

	ll ans = 0;
	for(int i=0; i<=totalsum; i++){
		if(dp[i] <= w) {
			ans = max (ans, (ll) i);
		}
	}
	cout << ans;
}

using namespace std;
int main(){
	FAST(); 
	int t = 1; 
	// cin >> t; 
	while(t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>

int main(){
  int A[100000];
  int n,x,r,i,j,p,q,m;

  scanf("%d",&n);

  for(i=0; i < n; i++){
    scanf("%d",&A[i]);
  }

  r = n - 1;
  x = A[r];
  p = 0;
  i = p - 1;

  for(j=p; j < r; j++){
    if(A[j] <= x){
      i = i + 1;
      q = A[i];
      A[i] = A[j];
      A[j] = q;
    }
  }

  q = A[i+1];
  A[i+1] = A[r];
  A[r] = q;
  m = i + 1;
  
  for(i=0; i < n; i++){
    if(i == m){
      printf("[%d]",A[i]);
    } else {
      printf("%d",A[i]);
    }
    if(i != n-1){
      printf(" ");
    }
  }
  printf("\n");
  
  return 0;
}



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

int main() {
    int N, M, tmp, sum=0;
    std::scanf("%d", &N);
    std::vector<int> v;
    v.reserve(N);
    for (int i = 0; i < N; i++) {
        std::scanf("%d", &tmp);
        v.push_back(tmp);
    }
    std::scanf("%d", &M);
    std::vector<int>::iterator it;
    for (int i = 0; i < M; i++) {
        std::scanf("%d", &tmp);
        it = std::lower_bound(v.begin(), v.end(), tmp);
        if (it != v.end() && v[it-v.begin()] == tmp) sum++;
    }
    std::printf("%d\n", sum);

    return 0;

}



Measured memory_bytes: 3240
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

signed main(){
	cout<<fixed<<setprecision(10);
	
	int N, M;
	int sum = 0;
	vector<int> A;
	
	cin>>N>>M;
	
	A.resize(N);
	
	for(int i = 0; i < N; i++){
		cin>>A[i];
		
		sum += A[i];
	}
	
	sort(A.begin(), A.end(), greater<int>());
	
	for(int i = 0; i < M; i++){
		if(A[i] * 4 * M < sum) {
			cout<<"No"<<endl;
			return 0;
		}
	}
	
	cout<<"Yes"<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;scanf("%d",&N);
    int A[N];
    for(int i=0;i<N;i++)scanf("%d",&A[i]);
    set<int> ans;
    for(int bit=0;bit<(1<<N);bit++){
        int now=0;
        for(int i=0;i<N;i++){
            if(bit&(1<<i))now+=A[i];
        }
        ans.insert(now);
    }
    int Q;scanf("%d",&Q);
    while (Q--)
    {
        int q;scanf("%d",&q);
        if(ans.count(q))printf("%s\n","yes");
        else printf("%s\n","no");
    }
    return 0;
}


Measured memory_bytes: 3168
import java.util.Scanner;

public class Main {
	static int p[][];

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt()+sc.nextInt()+sc.nextInt();

		String ans = (n >= 22) ? "bust" : "win";

		System.out.println(ans);

        return;
    }
}



Measured memory_bytes: 21844
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
	template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
	template <class Arg1, class... Args>
	void __f(const char* names, Arg1&& arg1, Args&&... args) {
		const char* sep = strchr(names + 1, ',');
		cerr.write(names, sep - names) << " : " << arg1 << "  ";
		__f(sep + 1, args...);
	}
#else
#define trace(...) 0
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("popcnt")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif
 
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<int,pii> piii;
typedef pair<char,int> pci;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> plll;
 


#define pb push_back
 
// order_of_key (k), find_by_order(k)
#define fi first
#define se second
#define input_arr(a,n) for(__typeof (n) i=0; i<n; ++i) {cin>>a[i];}
#define debug_arr(a,n) {{for(__typeof (n) i=0; i<n; ++i) {cout<<a[i]<<" ";}cout<<"\n";}}
#define maxheap priority_queue<ll>
#define minheap priority_queue<ll,vector<ll> ,greater<ll>>
#define initialise(a, x) memset(a, x, sizeof(a))
#define endl '\n'
#define ordered_set tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>
#define MAX 1000020
#define maxn 200005
#define eps 0.0000001

const ll mod=1e9+7;
const ll inf=1e18+2;

#define int ll

int dp[MAX][4];
int n;

int find(int i,int ms)
{
	if(i>=n)
	{
		if(ms==3) return 1;
		return 0;
	}
	if(dp[i][ms]!=-1) return dp[i][ms];
	return dp[i][ms]=(find(i+1,ms|1)+find(i+1,ms|2)+(8*find(i+1,ms)))%mod;
}


signed main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	// freopen("input.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);

	cin>>n;

	initialise(dp,-1);

	cout<<find(0,0)<<'\n';
	
	



	


	return 0;
}

Measured memory_bytes: 81656
#include<bits/stdc++.h>
using namespace std;
int n;
const int MOD=1e9+7;
int main()
{
	 long long a,b,c,d;
	 cin>>a>>b>>c>>d;
	 long long x,y,z,v;
	 x=a*c;
	 y=a*d;
	 z=b*c;
	 v=b*d;
	 		
	cout<<max(max(x,y),max(z,v));
} 

Measured memory_bytes: 3632
from subprocess import*
call(("pypy3","-c","""
from bisect import*
def _add(data,k,x):
    while k<=N:
        data[k]+=x
        k+=k&-k
def add(l,r,x):
    _add(data0,l,-x*(l-1))
    _add(data0,r,x*(r-1))
    _add(data1,l,x)
    _add(data1,r,-x)
def _get(data,k):
    s=0
    while k:
        s+=data[k]
        k-=k&-k
    return s
def query(l,r):
    return _get(data1,r-1)*(r-1)+_get(data0,r-1)-_get(data1,l-1)*(l-1)-_get(data0,l-1)
N,d,a,*t=map(int,open(0).read().split())
data0=[0]*(N+1)
data1=[0]*(N+1)
z=sorted(zip(*[iter(t)]*2))
y=[x for x,_ in z]
c=0
for i,(x,h)in enumerate(z,1):
    h-=query(i,i+1)
    t=0--max(0,h)//a
    j=bisect(y,x+d+d)
    add(1,j+1,t*a)
    c+=t
print(c)
"""))

Measured memory_bytes: 131852
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template<class T> using vc = vector<T>;
template<class T> using vvc = vc<vc<T>>;
constexpr ll ten(int n){return (n==0) ? 1 : 10 * ten(n-1);}
#define rng(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,N) for(int i=0;i<(int)(N);i++)
#define rep1(i,N) for(int i=1;i<=(int)(N);i++)
#define a first
#define b second
#define eb emplace_back
#define pb push_back
#define all(x) x.begin(),x.end()
template<class T, class U> void chmin(T& t, const U& u){ if(t>u) t = u;}
template<class T, class U> void chmax(T& t, const U& u){ if(t<u) t = u;}

#ifdef LOCAL
#define show(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define show(x) true
#endif

template<class T,class U>
ostream& operator<<(ostream& os, const pair<T,U>& p){
    return os << "P(" << p.fs << ", " << p.sc << ")";
}
template<class T> ostream& operator<<(ostream& os, const vc<T>& v){
    os << "[";
    for(auto d: v) os << d << ", ";
    return os << "]";
}

using vi=vector<int>;

vi kmp(const string&s){
	int n=s.size();
	vi v(n+1);
	v[0]=-1;
	rng(i,1,n+1){
		int j=v[i-1];
		while(j>=0&&s[j]!=s[i-1])
			j=v[j];
		v[i]=j+1;
	}
	return v;
}

const int inf=INT_MAX/2-100;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int n;cin>>n;
    vi a(1<<n);
    rep(i,1<<n)cin>>a[i];
    {
		vi dp=a;
		rep(i,n)rep(bit,1<<n)if(bit&1<<i)
			dp[bit]+=dp[bit^1<<i];
		rep(i,1<<n)if(dp[i]&&!a[i]){
			cout<<-1<<endl;
			return 0;
		}
	}
	int ans=0;
	rep(bit,1<<n)if(a[bit]){
		bool f=true;
		rep(i,n)if((bit&1<<i)&&a[bit^1<<i])
			f=false;
		ans+=f;
	}
	cout<<ans<<endl;
}



Measured memory_bytes: 11052
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn=1e5+10;
int n,m,a[maxn];
string s;
int main()
{
	int i,j,k;
	long long ans=0;
	char c;
	cin>>n;
	for(i=0;i<n;i++)
	{
		int x;
		cin>>x;
		a[x]++;
		ans+=x;
	}
	cin>>m;
	for(i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		a[y]+=a[x];
		ans+=((y-x)*a[x]);
		a[x]=0;
		cout<<ans<<endl;
	}
	return 0;
}


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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
//const int mod = 1000000007;
const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

//[mint]
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} c(200005);

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

    mint ans = 0;
    mint col = m;
    for(int x = n-1; x >= 0; --x){
        mint now = col;
        now *= c(n-1,x);
        if(x <= k) ans += now;
        col *= m-1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 6232
N = 1000
A = ["B","D"]
B = ["A","C","E"]
C = ["B","F"]
D = ["A","E","G"]
E = ["B","D","F","H"]
F = ["C","E","I"]
G = ["D","H"]
H = ["E","G","I"]
I = ["F","H"]

def check(string):
    if len(string) == 1:
        return True
    for i in range(len(string)-1):
        if string[i] == "A" and not(string[i+1] in A):
            return False
        if string[i] == "B" and not(string[i+1] in B):
            return False
        if string[i] == "C" and not(string[i+1] in C):
            return False
        if string[i] == "D" and not(string[i+1] in D):
            return False
        if string[i] == "E" and not(string[i+1] in E):
            return False
        if string[i] == "F" and not(string[i+1] in F):
            return False
        if string[i] == "G" and not(string[i+1] in G):
            return False
        if string[i] == "H" and not(string[i+1] in H):
            return False
        if string[i] == "I" and not(string[i+1] in I):
            return False
    return True

for i in range(N):
    s = str(input())
    if check(s):
        print(s)


Measured memory_bytes: 5576
#define TEMPLATE_USED
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;

void solve();

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

void solve(){
    ll n,l;cin>>n>>l;
    vl a(n);rep(i,n)cin>>a[i];

    ll idx=-1;
    rep(i,n-1){
        if(a[i]+a[i+1]>=l)idx=i;
    }
    if(idx==-1){
        cout<<"Impossible"<<endl;
        return;
    }

    cout<<"Possible"<<endl;
    rep(i,idx)cout<<i+1<<endl;
    rrep(i,idx,n-1)cout<<i+1<<endl;
}

Measured memory_bytes: 1664
#include <cstdio>
#include <cstring>
#include <cctype>
#include <algorithm>
#define ll long long
#define il inline
#define rgi register int

using namespace std;

int a, b, c;

il int read()
{
	rgi x = 0, f = 0, ch;
	while(!isdigit(ch = getchar())) f |= ch == '-';
	while(isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

int main()
{
	a = read(), b = read(), c = read();
	if(c - (a - b) > 0)
		printf("%d", c - (a - b));
	else
		puts("0");
	return 0;
}


Measured memory_bytes: 128
n,x=map(int,input().split())

d=[1 for i in range(n+1)]
p=[1 for i in range(n+1)]

for i in range(1,n+1):
  d[i]=2*d[i-1]+3
  p[i]=2*p[i-1]+1

def bp(n,x):
  if x==d[n]:
    return p[n]
  if x==1:
    return 0
  if x==2+d[n-1]:
    return 1+p[n-1]
  if x<2+d[n-1]:
    return bp(n-1,x-1)
  if x<d[n]:
    return 1+p[n-1]+bp(n-1,x-d[n-1]-2)

print(bp(n,x))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
 
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    } 
 
  int main(){      
 lint n;
 cin >>n; vector<lint> a(n);
 rep(i,n)cin >> a[i];
 lint b[n];
 map<lint,lint>mp;
 rep(i,n){
     b[i]=i+1-a[i];
     mp[b[i]]++;
 }
 lint ans=0;
    rep(i,n){
        lint x=a[i]+i+1;
        ans+=mp[x];
    }
    cout<<ans<<endl;
  }
          
  

Measured memory_bytes: 28896
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
//C++11
#if __cplusplus == 201103L
#include <tuple>
#endif

using namespace std;

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

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
vector<int> adj[50];
int power[50];
bool used[50];
int ans, rest, sum;
int N;
void dfs(int k){
  //printf("%d:%d %d %d\n", k,sum , rest, ans);
  if(k == N){
    ans = max(ans,  sum);
    return ;
  }
  if(sum + rest <= ans){
    ans = max(ans,  sum);
    return;
  }
  bool usedtmp[50];
  REP(i, 50) usedtmp[i] = used[i];
  int sumtmp = sum;
  int resttmp = rest;
  if(!used[k]){
    used[k] = true;
    sum += power[k];
    rest -= power[k];
    FORIT(it, adj[k])if(!used[*it]){
      rest -= power[*it];
      used[*it] = true;
    }
    dfs(k + 1);
    REP(i, 50) used[i] = usedtmp[i];
    sum = sumtmp;
    rest = resttmp;
  }
  if(k != 0){
    if(!used[k])rest -= power[k];
    used[k] = true;
    dfs(k + 1);
    rest += power[k];
    used[k] = false;
  }
}

int main(){
  while(cin>>N && N){
    ans = 0, rest = 0, sum = 0;
    REP(i, 50) adj[i].clear();
    memset(used, 0, sizeof(used));
    map<string, int> id;
    vector<string> adjstr[50];
    REP(i, N){
      string s; cin>>s; id[s] = i;
      cin>>power[i];
      rest += power[i];
      int k; cin>>k;
      while(k--){
        string str; cin>>str;
        adjstr[i].push_back(str);
      }
    }
    REP(i, N){
      REP(j, adjstr[i].size()){
        adj[i].push_back(id[adjstr[i][j]]);
      }
    }
    dfs(0);
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1024
#include <cstdint>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
using namespace std;

typedef int64_t LL;

LL get_dp(vector<vector<LL>>& items,int m, int s1, int s2, int s3) {
	LL inf = (1LL << 62);
	vector<vector<LL>> dp = vector<vector<LL>>(items.size() + 1, vector<LL>(m + 1, inf));
	// dp[item_index][eated_number] = achievable cost
	dp[0][0] = 0;
	for (int i = 0; i < items.size(); ++i) {
		// dont eat
		for (int j = 0; j <= m; ++j) {
			if(dp[i][j] < inf)
				dp[i + 1][j] = dp[i][j];
		}

		auto item = items[i];
		LL inc = item[0] * s1 + item[1] * s2 + item[2] * s3;

		// compare with eating
		for (int j = 0; j+1 <= m; ++j) {
			if (dp[i][j] < inf) {
				if (dp[i + 1][j + 1] < inf)
					dp[i + 1][j + 1] = max(dp[i][j] + inc, dp[i + 1][j + 1]);
				else
					dp[i + 1][j + 1] = dp[i][j] + inc;
			}
		}
	}
	return dp[items.size()][m];
}

int main() {
	int n, m;
	cin >> n >> m;
	vector<vector<LL>> items;
	for (int i = 0; i < n; ++i) {
		LL x, y, z;
		cin >> x >> y >> z;
		vector<LL> item;
		item.push_back(x);
		item.push_back(y);
		item.push_back(z);
		items.push_back(item);
	}
	LL best = 0;
	for (int si = 0; si < 8; si++) {
		int s1 = si % 2;
		int s2 = (si >> 1) % 2;
		int s3 = (si >> 2) % 2;
		s1 = 2 * s1 - 1;
		s2 = 2 * s2 - 1;
		s3 = 2 * s3 - 1;
		best = max(best,get_dp(items,m,s1,s2,s3));
	}
	cout << best << endl;
	return 0;
}

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

using namespace std;

const long long MOD = 1000000007;
const int MAX = 2147483647;
const double PI = 3.14159265358979323846;

int main() {
  long long n, sum = 0, x;
  cin >> n;
  for (int i = 1; i < n + 1; i++) {
    x = n / i;
    sum += i * x * (x + 1) / 2;
  }
  cout << sum << endl;
}


Measured memory_bytes: 3624
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<vector>
using namespace std;
int n,m,minn[1005],maxx[1005],u[200005],v[200005];
bool f1[1005][1005],f2[1005][1005],flag[1005];
queue<int>q;
long long tot;
vector<int>out[1005];
void bfs(int s,bool*flag,int*a)
{
	flag[s]=1;
	a[s]=s;
	q.push(s);
	while(!q.empty())
	{
		int node=q.front();
		q.pop();
		for(auto to:out[node])
		{
			tot++;
			if(!flag[to])
			{
				flag[to]=1,a[to]=s;
				q.push(to);
			}
		}
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&u[i],&v[i]);
		out[u[i]].push_back(v[i]);
	}
	for(int i=1;i<=n;i++)bfs(i,f1[i],minn);
	for(int i=1;i<=n;i++)
	{
		sort(out[i].begin(),out[i].end());
		int t=(int)out[i].size();
		memset(flag,0,sizeof(flag));
		flag[i]=1;
		for(int j=0;j<t;j++)
		  if(!flag[out[i][j]])
		    bfs(out[i][j],flag,minn);
		memset(flag,0,sizeof(flag));
		flag[i]=1;
		for(int j=t-1;j>=0;j--)
		  if(!flag[out[i][j]])
		    bfs(out[i][j],flag,maxx);
		for(auto x:out[i])f2[i][x]=minn[x]<maxx[x];
	}
	for(int i=1;i<=m;i++)
	{
		if(f1[v[i]][u[i]]^f2[u[i]][v[i]])puts("diff");
		else puts("same");
	}
	return 0;
}

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


using LL = long long int;
using uLL = unsigned long long int;
using uint = unsigned int;
using ld = long double;

const int N = 1007;
const int M = 1000000007;

bool tab[N][N];
int dp[N][N];

int main(){
    cin.tie(NULL);
    ios_base::sync_with_stdio(0);
    int h, w;
    cin >> h >> w;
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            char c;
            cin >> c;
            if(c == '#') tab[i][j] = true;
        }
    }
    dp[1][1] = 1;
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            if(tab[i][j] == false){
                dp[i][j] = max(dp[i][j], dp[i-1][j]+dp[i][j-1]);
                if(dp[i][j] >= M) dp[i][j] -= M;
            }
        }
    }
    cout << dp[h][w] << '\n';
    
    
    return 0;
}

Measured memory_bytes: 5248
#include <iostream>
using namespace std;
#define rep(i, n) for (int i=0; i < (int)(n); i++)
using ull = unsigned long long;
using ll = long long;

int main() {
    while (true) {
        int n, x;
        cin >> n >> x;
        if ((n==0) && (x==0)) break;

        int ans = 0;
        for (int i=1; i<=n-2; i++) {
            for (int j=i+1; j<=n-1; j++) {
                for (int k=j+1; k<=n; k++) {
                    if (i+j+k == x) ans++;
                }
            }
        }
        cout << ans << endl;

    }


    return 0;
}




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

using ll = long long int;
using P = std::pair<int, int>;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rag(con) std::begin(con), std::end(con)

constexpr ll mod = 1e9 + 7;

ll pow(ll x, ll m)
{

    ll re = 1, y = 1;

    for (int i = 0; i < 60; ++i)
    {
        if (m & y)
            re = re * x % mod;
        x = x * x % mod;
        y *= 2;
    }

    return re;
}

ll inv(ll x)
{

    return pow(x, mod - 2);
}

class mint
{
    ll num = 0;

public:
    mint(ll x = 0) : num(x) {}

    mint operator+(const mint &rhs) const
    {
        return (num + rhs.num) % mod;
    }
    mint operator*(const mint &rhs) const
    {
        return num * rhs.num % mod;
    }
    mint operator-(const mint &rhs) const
    {
        return (num - rhs.num + mod) % mod;
    }
    mint operator/(const mint &rhs) const
    {
        return num * inv(rhs.num) % mod;
    }
    mint operator+=(const mint &rhs)
    {
        return *this = *this + rhs;
    }
    mint operator*=(const mint &rhs)
    {
        return *this = *this * rhs;
    }
    mint operator-=(const mint &rhs)
    {
        return *this = *this - rhs;
    }
    mint operator/=(const mint &rhs)
    {
        return *this = *this / rhs;
    }
    friend std::ostream &operator<<(std::ostream &os, const mint &rhs);
};

std::ostream &operator<<(std::ostream &os, const mint &rhs)
{

    os << rhs.num;

    return os;
}

mint ss[2010];

int main()
{
    int s;
    std::cin >> s;

    if (s < 3)
    {
        std::cout << 0 << std::endl;
        return 0;
    }

    ss[3] = 1;
    ss[4] = 2;
    ss[5] = 3;

    for (int i = 6; i <= s - 3; ++i)
    {
        ss[i] = ss[i - 3] + ss[i - 1] + 1;
    }

    std::cout << ss[s - 3] + 1 << std::endl;

    return 0;
}

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

using namespace std;

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

    bool flag=true;
    for(int i=0; i<s.size(); i++){
        if(s.at(i) != t.at(i))flag = false;
    }

    if(flag)cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 3624
#include<iostream>
#include<string>
using namespace std;
int main(){
  string s,a,b,k = "keyence";cin >> s;int i,c,d,n = s.size();bool ans = false;
  for(i=1;i<7;i++){
    a = k.substr(0,i);b = k.substr(i);
    c = s.find(a);d = s.rfind(b);
    if(c != string::npos && d != string::npos && ((c==0 && (d==n-(7-i) || d==c)) || c==n-7)) ans = true;
  }
  cout << ((ans) ? "YES":"NO") << endl;
}
  


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Node{
    int key;
    struct Node *right, *left, *parent;
};

struct Node *root, *NIL;

void insert(int k){
    struct Node *y = NIL, *x = root, *z;
    
    z = (struct Node *)malloc(sizeof(struct Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;
    
    while(x != NIL){
        y = x;
        if(z->key < x->key){
            x = x->left;
        }else{
            x = x->right;
        }
    }
    z->parent = y;
    if(y == NIL){
        root = z;
    }else{
        if(z->key < y->key){
            y->left = z;
        }else{
            y->right = z;
        }
    }
}

void inorder(struct Node *u){
    if(u == NIL) return;
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}

void preorder(struct Node *u){
    if(u == NIL) return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}
int main(void){
    int n,i,x;
    char str[10];
    
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%s",str);
        if(strcmp(str,"insert") == 0){
            scanf("%d",&x);
            insert(x);
        }else if(strcmp(str,"print") == 0){
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }
    return 0;
}



Measured memory_bytes: 25136
#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define ranger(i, a, b) for (int i = (a)-1; i >= (b); i--)
#define repr(i, b) for (int i = (b)-1; i >= 0; i--)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
#define int long long
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}
template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
	rep(i, v.size()) { os << v[i] << (i == v.size() - 1 ? "" : " "); }
	return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S>& p) {
	os << '(' << p.first << ',' << p.second << ')';
	return os;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
	for (T& x : v) { is >> x; }
	return is;
}

template <typename T>
class CumulativeSum {
	vector<T> a;

  public:
	CumulativeSum(vector<T>& x) : a(x.size() + 1, 0) {
		rep(i, x.size()) { a[i + 1] = a[i] + x[i]; }
	}
	T get(int l, int r) { // [l, r]$B$N6h4V$N9g7W$r5a$a$k(B
		return a[r + 1] - a[l];
	}
	T operator[](const int i) const { return a[i]; }
};

const int INF = 1e18;

int memo[405][405];
int n;
vector<int> a;

int dfs(int l, int r, CumulativeSum<int>& sum) { // [l, r)
	if (l > r) return 0;
	// if(l > r) return INF;
	if (memo[l][r] != -1) return memo[l][r];
	// if(r -l == 1){ return sum.get(l,r-1); }
	// cout << l << ' ' << r << endl;
	// cout << min(dfs(l, r - 1) + a[r - 1], dfs(l + 1, r) + a[l]) << endl;

	int res = INF;
	range(i, l + 1, r) {
		if (i == l + 1)
			res = min(res,
					  dfs(l, i, sum) + dfs(i, r, sum) + sum.get(l + 1, r - 1));
		else if (i + 1 == r)

			res = min(res, dfs(l, i, sum) + dfs(i, r, sum) + sum.get(l, r - 2));
		else
			res = min(res, dfs(l, i, sum) + dfs(i, r, sum) + sum.get(l, r - 1));
	}
	if (r - l <= 2) res = sum.get(l, r - 1);
	//cout << l << ' ' << r << ' ' << res << endl;
	return memo[l][r] = res;
}

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

	a = vector<int>(n);
	cin >> a;
	CumulativeSum<int> sum(a);

	rep(i, 405) rep(j, 405) memo[i][j] = -1;
	cout << dfs(0, n, sum) << endl;
}


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

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

const long long MAXN = 1e5 + 10, inf = 1e18 + 21, LG = 20;

int n, q, m;
long long re = inf, res = inf;
long long x, y , c;
long long a[MAXN], b[MAXN];
long long ans = inf;

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n >> q >> m;
    for (int i = 1; i <= n; i++) {
	cin >> a[i];
	re = min(re, a[i]);
    }
    for (int i = 1; i <= q; i++)  {
	cin >> b[i];
	res = min(res, b[i]);
    }

    for (int i = 0; i < m; i++) {
	cin >> x >> y >> c;
	ans = min(ans, a[x] + b[y] - c);
    }
    cout << min(ans, re + res) << '\n';
    return 0;
}


Measured memory_bytes: 1792
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,vector<T>(w)))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,vector<T>(w,i)))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

signed main()
{
	vector<int>n(4);
	REP(i, 4)n[i] = in();
	sort(ALL(n));
	do {
		if (n[0] * 1000 + n[1] * 100 + n[2] * 10 + n[3] == 1974) {
			cout << "YES" << endl;
			return 0;
		}
	} while (next_permutation(ALL(n)));
	cout << "NO" << endl;
}

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


// =========================== DEBUGGER =================================

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ((it == d.b) ? "" : ", ") << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define tag(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

// =====================================================================







#define ll long long
const ll int INF = 1e15;

ll int dp[105][200005];
int val[105];
int wgt[105];


ll int kil(int idx, int value)
{
  if(value < 0)
    return INF;
  if(idx == 0)
  {
    if(value == 0)
      return 0;
    return INF;
  }
  if(dp[idx][value] != -1)
    return dp[idx][value];

  dp[idx][value] = INF;
  dp[idx][value] = min(dp[idx][value], kil(idx-1, value));
  dp[idx][value] = min(dp[idx][value], (kil(idx-1, value - val[idx]) + wgt[idx]));

  return dp[idx][value] = (dp[idx][value] > INF) ? INF : dp[idx][value];
}




int main()
{
  ll int n, w, ans;
  cin>>n>>w;

  for(int i=1;i<=n;i++)
    cin>>wgt[i]>>val[i];


  memset(dp, -1, sizeof dp);

  for(int value = 100003; value >= 0; value--)
  {
    ans = kil(n, value);
    if(ans <= w && ans != -1)
    {
      ans = value;
      break;
    }
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 164352
#include <bits/stdc++.h>
using namespace std;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sz(a)((int)(a).size())
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);iostream::sync_with_stdio(0);cout<<fixed<<setprecision(10);cerr<<fixed<<setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());const int D=4,dx[]={+1,0,-1,0},dy[]={0,+1,0,-1};
const int N=5050,OO=1e18;
int dp[N][N];
int a[N],w[N];
int32_t main(){

	int n,A,B;
	cin>>n>>A>>B;
	for(int i=1;i<=n;++i){
		cin>>a[i];
		w[a[i]]=i;
	}
	for(int i=0;i<=n+1;++i)for(int j=0;j<=n+1;++j)dp[i][j]=OO;
	dp[0][0]=0;
	for(int i=0;i<=n;++i)
		for(int j=0;j<=n;++j)
		{
			if(w[j+1]<=i)upn(dp[i][j+1],dp[i][j]);
			else upn(dp[i][j+1],dp[i][j]+B);
			if(a[i+1]<=j)upn(dp[i+1][j],dp[i][j]);
			else upn(dp[i+1][j],dp[i][j]+A);
			if(a[i+1]==j+1)upn(dp[i+1][j+1],dp[i][j]);
		}
	int ans=OO;
	forn(i,n+1)upn(ans,dp[i][n]);
	cout<<ans<<'\n';

    return 0;
}


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

int main(){
int A,B;
int sum=0;

cin>>A>>B;

for(int i=0;i<2;i++){

if(A>=B){
    sum+=A;
    A--;
}

else if(A<=B){
        sum+=B;
        B--;
}

}

cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

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;
}

signed main() {
  init();
  ll N;
  cin >> N;

  if (N == 0) {
    COUT(0);
    return 0;
  }

  string ans = "";
  while (N != 0) {
    if (abs(N) % 2 == 1) {
      ans = "1" + ans;
      N -= 1;
    } else {
      ans = "0" + ans;
    }
    N /= -2;
  }

  COUT(ans);
  return 0;
}

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

int main(){
  int A,B,N;
  cin >> N;
  A = 100/4;
  B = 100/7;
  bool result=0;
  for(int i=0;i<=A;i++){
    for(int j=0;j<=B;j++){
      if(4*i+7*j==N){
        result=1;
        break;
      }
    }
  }
  if(result==true){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
int main()
{
  int n,m;
  int l,r,l1,r1;


  std::cin>>n>>m;
  std::cin>>l>>r;
  for(int i=1;i<m;i++)
  {
      std::cin>>l1>>r1;
    if(l1>l)
    {
      l=l1;
    }
    if(r1<r)
    {
      r=r1;
    }
  }
  
  int a=r+1-l;
  if(a<0)
  {
    int b=0;
    std::cout<<b;
  }
  else
  {
      std::cout<<a;
  }
  return 0;
}


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

int main(){
  int w,h;
  cin >>h>>w;
  vector<string>a(h);
  for(int i=0;i<h;i++)
    cin >>a.at(i);
  vector<vector<int>>tmp(h,vector<int>(w,0));
  vector<int>dx={0,1,1,1,0,-1,-1,-1};
  vector<int>dy={1,1,0,-1,-1,-1,0,1};
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      for(int k=0;k<8;k++){
        int ni=i+dy.at(k);
        int nj=j+dx.at(k);
        if(ni<0||ni>=h||nj<0||nj>=w)
          continue;
        if(a.at(ni).at(nj)=='#')
          tmp.at(i).at(j)++;
      }
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(a.at(i).at(j)=='.')
        a.at(i).at(j)=(char)tmp.at(i).at(j)+'0';
    }
  }
  for(int i=0;i<h;i++)
    cout <<a.at(i)<<endl;
}

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

using namespace std;

#define rep(i, n) REP(i, 0, n)
#define REP(i, a, n) for(int i=(a); i<(n); i++)

int n;
int a[100010];
int b[100010];
int c[100010];

int main() {
    cin >> n;
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    rep(i, n) cin >> c[i];

    sort(a, a+n);
    sort(c, c+n);

    long long ans = 0;
    rep(i, n) ans += (lower_bound(a, a+n, b[i]) - a) * (n + c - upper_bound(c, c+n, b[i]));
    cout << ans << endl;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(i,s,e) for(ll i=s;i<e;i++ )
typedef pair<ll,ll> P;
const ll mod = 1000000007;
const ll INF = 1000000009;
ll i;

int main(){
    ll a,b,h;
    cin>>a>>b>>h;
    set<ll> j;
    j.insert(a);j.insert(b);j.insert(h);
    cout<<j.size()<<endl;
}



Measured memory_bytes: 256
import itertools

def readInt():
    return list(map(int, input().split()))

ans = False
n,y = readInt()
l = []
# print(n,y)
for i in range(n+1):
  for j in range(n+1):
      k = n-i-j
      if i+j+k == n and k>=0 and i*10000 + j*5000 + k*1000 == y:
        print(i,j,k)
        ans = True
  if ans == True:
      break
        
if  ans != True:
	print(-1, -1, -1)
        

Measured memory_bytes: 40940
#include <iostream>

using namespace std;

int main()
{
    int a,b;
    cin >> a >>b;
    if(a==b){ cout<<"Draw"; return 0;}
    if(a==1){cout<<"Alice"; return 0;}
    if(b==1){cout<<"Bob"; return 0;}
    if(a>b){cout<<"Alice";}else{cout<<"Bob";}

}


Measured memory_bytes: 256
#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 pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(...) out(__VA_ARGS__);cout<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void out(){} template<class T,class... U> void out(T t,U ...u){cout<<t<<" ";out(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(int, K, N);
  VEC(ll, A, N);
  ll diff = 0;
  rep(i, 0, N - 1) {
    diff = max(diff, A[i + 1] - A[i]);
  }
  diff = max(diff, (K - A[N - 1]) + A[0]);
  print(K - diff);
}


Measured memory_bytes: 1792
import java.util.*

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

object Problem {
    lateinit var calcScore: (ans: List<Int>) -> Long

    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val D = sc.next().toInt()
        val c = IntArray(26) { sc.next().toInt() }
        val s = Array(D) { IntArray(26) { sc.next().toInt() } }

        calcScore = { t ->
            val d = IntArray(26) { -1 }// 最後におこなった日
            var score = 0L
            for (i in t.indices) {
                score += s[i][t[i]]
                d[t[i]] = i
                for (j in 0 until 26) {
                    score -= c[j] * (i - d[j])
                }
            }
            score
        }

        val ans = Stack<Int>()
        val d = IntArray(26) // 最後におこなった日
        for (i in 0 until D) {
            var sMax = 0L
            var jMax = 0
            for (j in 0 until 26) {
                ans.push(j)
                val sco = calcScore(ans)
                if (sMax < sco) {
                    sMax = sco
                    jMax = j
                }
                ans.pop()
            }
            ans.push(jMax)
            d[jMax] = i
        }

        ans.forEach { pw.println(it + 1) }
    }
}


Measured memory_bytes: 44276
#include <iostream>
#include <algorithm>
//#include <fstream>

using namespace std;

string dec2oct (int n )
{
	string res = "";

	while (n > 0 ){
		res += n % 8 + '0';
		n /= 8;
	} // end while
	
	reverse (res.begin(), res.end() );

	return res;
}

string hostpial_number (string s )
{
	int len = s.length();
	string res = "";
	int i;

	for (i = 0; i < len; ++i){
		if (s[i] != '4' && s[i] != '5' && s[i] != '6' && s[i] != '7'){
			res += s[i];
		}else if (s[i] == '4'){
			res += '5';
		}else if (s[i] == '5'){
			res += '7';
		}else if (s[i] == '6'){
			res += '8';
		}else if (s[i] == '7'){
			res += '9';
		} // end if
	} // end for

	return res;
}


int main()
{
//	cut here before submit 
//	freopen ("testcase.hospitalnumber", "r", stdin );
	int n;

	while (cin >> n && n ){
		string oct = dec2oct (n );
		string res = hostpial_number (oct );
		cout << res << endl;
	} // end loop
		
	return 0;
}

Measured memory_bytes: 912
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var P = cin.ReadInt;
            var Q = cin.ReadInt;
            var R = cin.ReadInt;
            if (P <= Q) {
                if (Q <= R) {
                    Write(P+Q);
                } else {
                    Write(P+R);
                }
            } else if (Q < P){
                if (P <= R) {
                    Write(P+Q);
                } else {
                    Write(Q+R);
                }
            }
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <random>
#include <utility>
#include <cmath>
#include <string.h>
#include <iomanip>
#include <stdlib.h>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする
 
struct edge{int to,cost;};
vector<int> G[100005];
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
 
std::vector<P> tree[100010];
ll i,j;

ll n,k,l;
long long int ans=0;
ll a,b,c,d;

int main(){
	cin>>n>>a>>b>>c>>d;
	bool flag=false;
	for(i=0;i<=n-1;i++){
		k=a+i*c-(n-1-i)*d;
		l=b-(d-c)*(n-1);
		if(k>=l && k<=b){
			flag=true;
		}
	}
	if(flag)cout<<"YES";
	else cout<<"NO";
	cout<<endl;
	return 0;
}

Measured memory_bytes: 4992