akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <iomanip>
using namespace std;
long long n,a,b,c,d,i,j,now;
int main()
{
	cin>>n>>a>>b>>c>>d;
	d-=c;
	n-=1;
	for (i=0;i<=n;i++)
	{
		j=n-i;
		now=b-a-i*c+j*c;
		long long low=-d*j,high=d*i;
		if(now>=low&&now<=high)
		{
			cout<<"YES";
			return 0;
		}
	} 
	cout<<"NO";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	char s[101];
	cin>>s;
	int n=strlen(s),flag=0;
	for(int i=0;i<=n;i++)
	{
		if(s[i]=='C')
			for(int j=i;j<=n;j++)
				if(s[j]=='F'){cout<<"Yes"<<endl;return 0;}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
#define pb push_back

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;
}
constexpr int mod = 1e9+7;
constexpr int inf = 3e18;


signed main(){
	int A;string B;
	cin>>A>>B;
	int BB=(B[0]-'0')*100+(B[2]-'0')*10+(B[3]-'0');
	cout<<A*BB/100<<endl;
}


Measured memory_bytes: 3572
#include<stdio.h>
int main(void)
{
    double v,t=0,y=0;
    int i=1;

    while(scanf("%lf",&v)!=EOF){
    t=v/9.8;
    y=4.9*t*t;
    for(;;){
        if(y<=5*i-5)break;
        i++;
    }
    printf("%d\n",i);
    i=1;
    t=0;
    y=0;
    }
    return 0;
}

Measured memory_bytes: 628
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
using ll = long long;
using namespace std;

ll x[100];
ll dp[100][100][2600];
int main(){
    ll n,a;
    cin>>n>>a;
    dp[0][0][0]=1;
    rep(i,0,n)cin>>x[i];
    rep(i,0,n){
        rep(j,0,n){
            rep(k,0,2600){
            dp[i+1][j][k]+=dp[i][j][k];
            dp[i+1][j+1][k+x[i]] += dp[i][j][k];
          }
        }
    }
    ll ans=0;
    rep(i,1,n+1)ans+=dp[n][i][i*a];

    cout<<ans<<endl;
}

Measured memory_bytes: 102656
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a <= b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline ostream& operator << (ostream& out, const vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first; printf("\n"); }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first; printf(" "); put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first; printf("\n"); putn(rest...); }

template<typename T>
vector<T> divisor(T n) {
	vector<T> res1;
	vector<T> res2;

	for (T i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			res1.push_back(i);
			if (i != n / i) {
				res2.push_back(n / i);
			}

		}
	}
	RREP(i, res2.size()) {
		res1.push_back(res2[i]);
	}
	return res1;
}

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	int sum = 0;
	REP(i,n){
		cin >> a[i];
		sum += a[i];
	}
	if (sum == 0) {
		
	} else {
		vector<int> div = divisor(sum);
		int res = 0;
		REP(j, div.size()) {
			vector<int> r(n);
			REP(i, n) {
				r[i] = a[i] % div[j];
			}
			sort(all(r));
			int sum1 = accumulate(all(r),0);
			int index = n - 1 - sum1 / div[j];
			if (0 <= index && index < n) {
				int sum2 = accumulate(r.begin(), r.begin() + index + 1, 0);
				if (sum2 <= k) {
					chmax(res, div[j]);
				}
			}
		}
		put(res);
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
#define ALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int l,r,d;
    cin >> l >> r >> d;
    cout << r/d-(l-1)/d << endl;

    return 0;
}

Measured memory_bytes: 3604
from collections import deque

class SlideMin:
    def __init__(self, leng):
        self.que = deque([])
        self.leng = leng

    def top(self):
        return self.que[0]

    def getQue(self):
        return self.que

    def update(self, index, value=0):
        while self.que:
            if self.que[-1][1] >= value:
                self.que.pop()
            else:
                break

        self.que.append((index, value))

        if self.que[0][0] == index - self.leng:
            self.que.popleft()

N, K = map(int, input().split())
P = list(map(int, input().split()))

maxQ = SlideMin(K)
minQ = SlideMin(K)

for i in range(K):
    maxQ.update(i, -P[i])
    minQ.update(i, P[i])

ans = 1
hasSame = False
seq = 1
for i in range(1, K):
    if P[i - 1] < P[i]:
        seq += 1
    else:
        seq = 1
if seq >= K:
    hasSame = True

for left in range(N - K):
    right = left + K

    if P[right - 1] < P[right]:
        seq += 1
    else:
        seq = 1

    maxQ.update(right, -P[right])

    if left == minQ.top()[0] and right == maxQ.top()[0]:
        pass
    else:
        if seq < K:
            ans += 1
        else:
            if not hasSame:
                hasSame = True
                ans += 1

    minQ.update(right, P[right])

print(ans)

Measured memory_bytes: 31928
#include<bits/stdc++.h>
using namespace std; 
int main() {
  int A,B,max=0,count=0,izen=0;
  cin >> A;
  for(int i=0; i<A; i++) {
    cin >> B;
    if(izen>=B) {count++;
                   }else{ count=0;
                        }
    if(max<count) max=count;
    izen=B;
    
  }
  
  
  
  cout << max << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  string s;
  cin >> n >> s;
  int size = s.size()-1;
  string t,u;
  int count,ans=0;
  for(int i=1; i<n; i++) {
    count = 0;
    t = s.substr(0,i);
    u = s.substr(i,size);
    for(int j=0; j<26; j++) {
      if(t.find('a'+j) != ::string::npos && u.find('a'+j) != ::string::npos) {
        count++;
      }
    }
    ans = max(ans,count);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
int main() {
    for (;;) {
        int N, M; cin >> N >> M;
        if (N == 0 && M == 0) break;
        vector<int> score(N);
        for (int i = 0; i < M; i++) {
            for (int j = 0; j < N; j++) {
                int p; cin >> p;
                score[j] += p;
            }
        }
        cout << *max_element(begin(score), end(score)) << '\n';
    }
    return 0;
}



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

int V[100][100] = {{0}};

int main(){
    int n; cin >> n;
    for(int i = 0; i < n; i++){
        int u, k; cin >> u >> k;
        for(int i = 0; i < k; i++){
            int v; cin >> v;
            V[u - 1][v - 1] = 1;
        }
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(j) cout << " ";
            cout << V[i][j];
        }
        cout << endl;
    }
}


Measured memory_bytes: 3104
#line 2 "header.hpp"

//%snippet.set('header')%
//%snippet.fold()%
#ifndef HEADER_H
#define HEADER_H

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

// varibable settings
#define int long long
const int INF = 1e18;

#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 _rrep(i, n) rrepi(i, 0, n)
#define rrepi(i, a, b) for (int i = (int)((b)-1); i >= (int)(a); --i)
#define r_rep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(i, a) for (auto &&i : a)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(...) make_tuple(__VA_ARGS__)
#define ub upper_bound
#define lb lower_bound
#define lpos(A, x) (lower_bound(all(A), x) - A.begin())
#define upos(A, x) (upper_bound(all(A), x) - A.begin())
template <class T>
inline void chmax(T &a, const T &b) {
    if ((a) < (b)) (a) = (b);
}
template <class T>
inline void chmin(T &a, const T &b) {
    if ((a) > (b)) (a) = (b);
}

#define divceil(a, b) ((a) + (b)-1) / (b)
#define is_in(x, a, b) ((a) <= (x) && (x) < (b))
#define uni(x)    \
    sort(all(x)); \
    x.erase(unique(all(x)), x.end())
#define slice(l, r) substr(l, r - l)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int, int> pii;
typedef tuple<int, int, int> iii;

template <typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast {
    Fast() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
    }
} fast;
void check_input() {
    assert(cin.eof() == 0);
    int tmp;
    cin >> tmp;
    assert(cin.eof() == 1);
}

#if defined(PCM) || defined(LOCAL)
#else
#define dump(...) ;
#define dump_1d(...) ;
#define dump_2d(...) ;
#define cerrendl ;
#endif

#endif /* HEADER_H */
//%snippet.end()%
#line 2 "solve.cpp"

signed main() {
    //input
    int n,m,q;cin>>n>>m>>q;

    vi a(q), b(q), c(q), d(q);

    rep(i, q){
        cin>>a[i]>>b[i]>>c[i]>>d[i];
        a[i]--;b[i]--;
    }
    dump(a);
    dump(b);
    dump(c);
    dump(d);

    vector<int> used(n);
    auto dfs = [&](const auto& dfs, vi p, int i) -> int {
        int res = 0;
        if (i==n){
            rep(j, q){
                if (p[b[j]]-p[a[j]]==c[j]) res+=d[j];
            }
            return res;
        }

        rep(x, p[i-1], m+1){
            vi np(p); np.pb(x);
            chmax(res, dfs(dfs, np, i+1));
        }
        return res;
    };
    //solve
    int ans = 0;

    rep(i, 1, m+1){
        vi tmp(1, i);
        chmax(ans, dfs(dfs, tmp, 1));
    }
    cout << ans << endl;

    return 0; 
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
int main(){
	string o,e;
	cin>>o>>e;
	int x=o.size();
	int y=e.size();
	for(int i=0;i<y;i++){
		cout<<o[i]<<e[i];
		}
	if(x!=y){cout<<o[x-1]<<endl;}
	else{cout<<endl;}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <string>
#include <cstdlib>
using namespace std;

int main()
{
	int a, b;
	stack<int> s;
	string str;
	while(cin >> str)
	{
		if(str == "+")
		{
			b = s.top();
			s.pop();
			a = s.top();
			s.pop();
			
			s.push(a + b);
		}
		else if(str == "-")
		{
			b = s.top();
			s.pop();
			a = s.top();
			s.pop();
			
			s.push(a - b);
		}
		else if(str == "*")
		{
			b = s.top();
			s.pop();
			a = s.top();
			s.pop();
			
			s.push(a * b);
		}
		else if(str == "/")
		{
			b = s.top();
			s.pop();
			a = s.top();
			s.pop();
			
			s.push(a / b);
		}
		else
		{
			s.push(atoi(str.c_str()));
		}
	}
	
	cout << s.top() << endl;

    return 0;
}



Measured memory_bytes: 3208
#include <bits/stdc++.h>
using namespace std;
int main(){
    string S;
    cin>>S;
    string divide[4]={"dream","dreamer","erase","eraser"};

    reverse(S.begin(),S.end());
    for(int i=0;i<4;i++){
        reverse(divide[i].begin(),divide[i].end());
    }

    bool can=true;
    for(int i=0;i<S.size();){
        bool can2=false;
        for(int j=0;j<4;j++){
            if(S.substr(i,divide[j].size())==divide[j]){
                can2=true;
                i=i+divide[j].size();
            }
        }
        if(!can2){
            can=false;
            break;
        }
    }
    if(can){
        cout<<"YES";
    }
    else{
        cout<<"NO";
    }
    return 0;
}

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

int main() {
    long long n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    for (long long i = 0; i < n; i++) {
        if (c * (n - 1 - i) - d * i <= b - a && b - a <= -c * i + (n - 1 - i) * d) {
            cout << "YES";
            return 0;
        }
    }
    cout << "NO";
    return 0;
}

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

int main(){
  int n, m;
  cin >> n >> m;
  vector<int> num(m,0);
  vector<int> p(m,0);
  set<int> s;
  rep(i,n) {
    int x;
    cin >> x;
    num[x%m]++;
    auto itr = s.find(x);
    if(itr != s.end()) {
      p[x%m]++;
      s.erase(x);
    } else {
      s.insert(x);
    }
  }
  int ans = 0;
  ans += num[0]/2;
  if(m % 2 == 0) ans += num[m/2]/2;
  for(int i = 1; i < m-i; i++){
    int a = i, b = m - i;
    if(num[a] < num[b]) swap(a,b);
    ans += num[b];
    int c = num[a] - num[b];
    ans += min(c/2,p[a]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5760
#include <iostream>
using namespace std;
long long a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,ans;
int main()
{
    cin>>n;
    for(i=0;i<n;i++)
    {
        if((i+1)%15==0)
        {
            ans-=200;
        }
        ans+=800;
    }
    cout<<ans<<endl;
    return 0;
}

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

int N,M,A,B,C,T;
struct matrix{
    vector<vector<int>> m;
    matrix(int N){
        m = vector<vector<int>>(N,vector<int>(N,0));
    }
};

matrix mult(matrix& A,matrix& B){
    matrix C(N);
    for(int i=0;i<N;i++) for(int j=0;j<N;j++) for(int k=0;k<N;k++)
    (C.m[i][j] += A.m[i][k]*B.m[k][j])%=M;
    return C;
}

matrix pow(matrix& A,int n){
    if(n==1) return A;
    if(n&1){
        matrix P = pow(A,n-1);
        return mult(P,A);
    }else{
        matrix P = pow(A,n>>1);
        return mult(P,P);        
    }
}

void solve(vector<int>& S){
    if(T==0){
        for(int i=0;i<N;i++) cout << S[i] << (i!=N-1? " ":"\n");
        return ;
    }
    matrix X(N);
    for(int i=0;i<N;i++){
        if(i-1>=0) X.m[i][i-1] = A;
        X.m[i][i] = B;
        if(i+1<N) X.m[i][i+1] = C;
    }
    matrix res = pow(X,T);
    for(int i=0;i<N;i++){
        int ans = 0;
        for(int j=0;j<N;j++){
            (ans += res.m[i][j]*S[j])%=M;
        }
        cout << ans << (i!=N-1? " ":"\n");
    }
}

int main(){
    while(cin >> N >> M >> A >> B >> C >> T && N){
        vector<int> S(N);
        for(int i=0;i<N;i++) cin >> S[i];
        solve(S);
    }
}


Measured memory_bytes: 3128
from sys import stdin
n = int(stdin.readline())
M = [None] + [list(map(int, stdin.readline().split()[2:])) for i in range(n)]
sndf = [None] + [[False, i] for i in range(1, n + 1)]
tt = 0
def dfs(u):
    global tt
    sndf[u][0] = True
    tt += 1
    sndf[u].append(tt)
    for v in M[u]:
        if not sndf[v][0]:
            dfs(v)
    tt += 1
    sndf[u].append(tt)
for i in range(1, n + 1):
    if not sndf[i][0]:
        dfs(i)
for x in sndf[1:]:
    print(*x[1:])

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

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

	int R, S, P; cin >> R >> S >> P;

	string T; cin >> T;

	int score = 0;

	for (int i = 0; i < K; i++)
	{
		char pre = -1;
		for (int j = i; j < N; j += K)
		{
			if (T[j] != pre)
			{
				if (T[j] == 'r')
					score += P;
				if (T[j] == 's')
					score += R;
				if (T[j] == 'p')
					score += S;
				pre = T[j];
			}
			else pre = -1;
		}
	}

	cout << score << endl;

	return 0;
}

Measured memory_bytes: 512
fun main(args: Array<String>) {
    val x = readInputLine().toInt()
    
    var max = 1
    
    for (i in 2..Int.MAX_VALUE) {
        if (i * i > x) {
            break
        }
        for (j in 2..Int.MAX_VALUE) {
            val pow = pow(i, j)
            if (pow > x) {
                break
            }
            if (pow > max) {
                max = pow
            }
        }
    }
    
    println(max)
}
 
fun readInputLine(): String {
    return readLine()!!
}

fun pow(x:Int, y:Int): Int {
    var ret = 1
    
    for (i in 1..y) {
        ret *= x
    }
    
    return ret
}


Measured memory_bytes: 31740
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<int, pair<int, int>> PP;
typedef pair<P, int> PPi;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    int n, m;
    cin >> n >> m;
    vector<ll> x(n), y(n), z(n);
    for(int i = 0; i < n; ++i)  cin >> x[i] >> y[i] >> z[i];
    
    ll ans = 0;
    for(int bit = 0; bit < (1 << 3); ++bit){
        vector<int> sign(3);
        for(int i = 0; i < 3; ++i){
            if(bit & (1 << i))  sign[i] = 1;
            else    sign[i] = -1;
        }
        vector<Pl> S(n);
        for(int i = 0; i < n; ++i){
            S[i].first = sign[0] * x[i] + sign[1] * y[i] + sign[2] * z[i];
            S[i].second = i;
        }
        sort(S.begin(), S.end(), greater<Pl>());
        vector<ll> sum(3, 0);
        for(int i = 0; i < m; ++i){
            int id = S[i].second;
            sum[0] += x[id];
            sum[1] += y[id];
            sum[2] += z[id];
        }
        ll foo = abs(sum[0]) + abs(sum[1]) + abs(sum[2]);
        chmax(ans, foo);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define range(c) c.begin() , c.end()
#define forn(i,n) for(ll i=0; i<n; ++i)
#define endl '\n'
#define MOD 1000000007
#define test ll t;cin >> (t);while(t--)
using namespace std;
//////////////////////////////////////////////////////////////
const ll maxi=1e5+5;
ll dist[maxi];
bool vis[maxi];
vector<ll> v[maxi];
ll id[maxi];// to store in degree of the vertex
void dfs(int a)
{
    if(!vis[a])
    {
        vis[a]=true;
        for(int b: v[a])
        {
            dist[b]=max(dist[b], dist[a] +1);
            id[b]--;
            if(id[b]==0)
                dfs(b);
        }
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,m;
    cin >> n >> m;
    
    memset(id,0,sizeof(id)); 
    for(ll i=0;i<m;i++)
    {
        ll x,y; 
        cin >> x >>y;
        v[x].pb(y);
        id[y]++;
    }
    for(ll i=1;i<=n;i++)
    {
        if(!vis[i] && id[i]==0) // checking in_deg as 0 eliminates the need for generating a fake vertex that connects all veetices
            dfs(i);
    }
    ll ans=0;
    forn(i,n+1)
    {
        ans=max(ans,dist[i]);
    }
    cout << ans << endl;
}

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

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

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


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

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

// 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];
    }
};
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N, K; cin >> N >> K;

//    if (K == 1 || N == 0) {
//        cout << 0 << endl;
//    }
    N = N % K;
    while(N > abs(N-K)) {
        N = abs(N-K);
    }
    cout << N << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define in insert
#define er erase
#define fr first
#define sc second
typedef long long ll;
const long long llinf=LLONG_MAX;
const int inf=INT_MAX;
const int nmax=2e5+5;
const int mod=1e9+7;
using namespace std;
int n,i,m;
ll x;
map<ll,int>mp;
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	cin>>n;
	for(i=1;i<=n;i++)cin>>x,mp[x]++;
	cin>>m;
	for(i=1;i<=m;i++)
	{
		cin>>x;
		mp[x]--;
		if(mp[x]<0)rc("NO");
	}
	rc("YES");
} 

Measured memory_bytes: 12800
#include <stdio.h>

int main(void){
  int a,b,w;
  
  scanf("%d %d %d",&w,&a,&b);
  
  if(a<b){
    if(b-a-w>0){
      printf("%d\n",b-a-w);
    }else{
      printf("0\n");
    }
  }
  
  if(b<a){
    if(a-w-b>0){
      printf("%d\n",a-b-w);
    }else{
      printf("0\n");
    }
  }
  
  if(b==a){
    printf("0\n");
  }
  
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using bint = boost::multiprecision::cpp_int;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
#define ssort(v) sort(v.begin(), v.end())
#define gsort(v) sort(v.rbegin(), v.rend())
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }

int main()
{
    int S, W;
    cin >> S >> W;
    bool ret = (W>=S);
    cout << (ret?"unsafe":"safe") << "\n";
    return 0;
}


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

int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    int count = 0;
    bool flg=false;
    while(true){
        int x=1;
        for(int i=0;i<n;i++){
            if(a[i] % 2 == 1)
                flg=true;
        }
        if(flg)
            break;

        count++;
        for(int i=0;i<n;i++){
            a[i] = a[i]/2;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
/*
	Copyright: razouq (c)
	Author: Anass BENDARSI
	Date: 06/08/2017 13:05:25
	flamers will **** you
*/
#include<bits/stdc++.h>
//#include<flamers.h>
#define ll long long
#define ull unsigned long long
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define POB pop_back
#define dist(a, b) sqrt(a*a + b*b)
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<pair<int, int>> vipi;
bool compare(pi p1, pi p2){
	 if(1) return true;
	 return false;
}

int main(){
//	freopen("input.in", "r", stdin);
//	freopen("output.out", "w", stdout);
	ios::sync_with_stdio(0);
	cin.tie();
	string s;
	cin>>s;
	cout<<s[0]<<s.size()-2<<s[s.size()-1]<<endl;
	return 0;
}


Measured memory_bytes: 256
<?php
  $n = trim(fgets(STDIN));
  $s = [];
  for($i=0; $i<$n; $i++){
    $s[trim(fgets(STDIN))] += 1;
  }
  arsort($s);
  $max = max($s);
  $ss = [];
  foreach ($s as $k => $t){
    if($max == $t){
      $ss[] = $k;
    }
  }
  sort($ss);
  for($i=0; $i<count($ss); $i++){
    echo $ss[$i]."\n";
  }

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

long long modpow(long long a, long long b, long long m) {
	long long p = 1, q = a;
	for (int i = 0; i < 30; i++) {
		if ((b / (1LL << i)) % 2 == 1) { p *= q; p %= m; }
		q *= q; q %= m;
	}
	return p;
}

long long Div(long long a, long long b, long long m) {
	return (a*modpow(b, m - 2, m)) % m;
}

long long dp[33][1344], fact[100009], factinv[100009], mod = 1000000007; bool used[1344][1344]; vector<long long>X;
long long N, M;

void init() {
	fact[0] = 1; for (int i = 1; i <= 100000; i++) fact[i] = (fact[i - 1] * i) % mod;
	for (int i = 0; i <= 100000; i++) factinv[i] = Div(1, fact[i], mod);
}

long long ncr(long long n, long long r) {
	if (n < r || r < 0) return 0;
	return (fact[n] * factinv[r] % mod) * factinv[n - r] % mod;
}

int main() {
	cin >> N >> M; init();
	for (int i = 1; i*i <= M; i++) {
		if (M%i != 0) continue;
		X.push_back(i);
		X.push_back(M / i);
	}
	sort(X.begin(), X.end());
	X.erase(unique(X.begin(), X.end()), X.end());

	for (int i = 0; i < X.size(); i++) {
		for (int j = i + 1; j < X.size(); j++) {
			if (X[j] % X[i] == 0) used[i][j] = true;
		}
	}
	dp[0][0] = 1;
	for (int i = 0; i < 32; i++) {
		for (int j = 0; j < X.size(); j++) {
			for (int k = 0; k < X.size(); k++) {
				if (used[j][k] == true) { dp[i + 1][k] += dp[i][j]; dp[i + 1][k] %= mod; }
			}
		}
	}
	long long sum = 0;
	for (int i = 0; i < 33; i++) { sum += ncr(N, i) * dp[i][X.size() - 1]; sum %= mod; }
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3456
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
using namespace std;
#define MM 1000000000
#define MOD MM+7
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T lcm(T x,T y){
    return x*y/GCD(x,y);
}
long long Pow(long long base,long long x){
    if (x == 0) return 1;
    if (x%2 == 1) return (base*Pow(base,x-1))%MOD;
    long long y = Pow(base, x/2);
    return y*y%MOD;
}

int main(){
    long long n,q; cin >> n;
    vector<long long> a(0);
    for(int i = 0; i < n; i++){
        long long num;
        cin >> num;
        a.push_back(num);
    }
    cin >> q;
    for(int i = 0; i < q; i++){
        long long k; cin >> k;
        cout << lower_bound(a.begin(), a.end(), k) - a.begin() << " ";
        cout << upper_bound(a.begin(), a.end(), k) - a.begin() << endl;
    }
}
  




Measured memory_bytes: 3884
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
using namespace std;

int main(){
    string n;cin>>n;
    for(int i=0;i<3;i++){
        if(n[i]=='1')n[i]='9';
        else n[i]='1';
    }
    cout<<n<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N,M;
  cin >> N >> M;
  vector<int> A(N);
  int sum=0;
  for(int i=0;i<N;i++){
    cin >> A.at(i);
    sum += A.at(i);
  }
  sort(A.begin(),A.end());
  reverse(A.begin(),A.end());
  if(A.at(M-1)*4*M >= sum){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
// 2011/01/12 Tazoe

#include <iostream>
using namespace std;

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

		int emp[4000][3];
		for(int i=0; i<4000; i++){
			emp[i][0] = i+1;
			emp[i][1] = 0;
			emp[i][2] = 5000;
		}

		int ord = 1;
		for(int i=0; i<n; i++){
			int id, p, q;
			cin >> id >> p >> q;
			if(p!=0&&1000000/p+1<=q)
				emp[id-1][1] = 1000000;
			else if(emp[id-1][1]<1000000)
				emp[id-1][1] += p*q;
			if(emp[id-1][2]==5000){
				emp[id-1][2] = ord;
				ord++;
			}
		}

		for(int i=0; i<3999; i++)
			for(int j=i+1; j<4000; j++)
				if(emp[i][2]>emp[j][2]){
					int tmp1 = emp[i][0];
					int tmp2 = emp[i][1];
					int tmp3 = emp[i][2];
					emp[i][0] = emp[j][0];
					emp[i][1] = emp[j][1];
					emp[i][2] = emp[j][2];
					emp[j][0] = tmp1;
					emp[j][1] = tmp2;
					emp[j][2] = tmp3;
				}

		int cnt =0;
		for(int i=0; emp[i][2]!=5000&&i<4000; i++)
			if(emp[i][1]>=1000000){
				cout << emp[i][0] << endl;
				cnt++;
		}
		if(cnt==0)
			cout << "NA" << endl;
	}

	return 0;
}

Measured memory_bytes: 912
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#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 repd(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>; // グラフ型
using pint = pair<int, int>;

int main()
{
    ll N, Y;
    cin >> N >> Y;
    rep2(i, 0, N + 1)
    {
        rep2(j, 0, N + 1)
        {
            int k = N - i - j;
            if (k >= 0 && i + j + k == N && 10000 * i + 5000 * j + 1000 * k == Y)
            {
                cout << i << ' ' << j << ' ' << k << endl;
                return 0;
            }
        }
    }
    cout << -1 << ' ' << -1 << ' ' << -1 << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.math.*;
import java.io.*;
import java.text.*;

class Main {

    //public static PrintWriter pw;
    public static PrintWriter pw = new PrintWriter(System.out);

    public static  void solve() throws IOException {
        //	pw=new PrintWriter(new FileWriter("C:\\Users\\shree\\Downloads\\small_output_in"));
        FastReader sc = new FastReader();
        char s[]=sc.next().toCharArray();
        for(int i=0;i<s.length-1;i++){
            if(s[i]=='A' && s[i+1]=='C') {
                pw.println("Yes");
                pw.close();
                return;
            }
        }
        pw.println("No");
        pw.close();

    }


    public static void main(String[] args) {
        new Thread(null, new Runnable() {
            public void run() {
                try {

                    solve();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }, "1", 1 << 26).start();

    }

    static BufferedReader br;
    static long M = (long) 1e9 + 7;

    static class FastReader {

        StringTokenizer st;

        public FastReader() throws FileNotFoundException {
            //br=new BufferedReader(new FileReader("C:\\Users\\shree\\Downloads\\B-small-practice.in"));
            br = new BufferedReader(new InputStreamReader(System.in));

        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int I() {
            return Integer.parseInt(next());
        }

        long L() {
            return Long.parseLong(next());
        }

        double D() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        public boolean hasNext() throws IOException {
            while (st == null || !st.hasMoreTokens()) {
                String s = br.readLine();
                if (s == null) {
                    return false;
                }
                st = new StringTokenizer(s);
            }
            return true;
        }

    }
}

Measured memory_bytes: 23636
L = 100005
 
n,c = map(int, input().split())
 
arr = [[0]*L for j in range(c)]
for _ in range(n):
    s,t,col = map(lambda x:int(x)-1, input().split())
    arr[col][s] += 1
    arr[col][t] -= 1
 
imos = [0]*L
 
for i in range(c):
    for p in range(L):
        if arr[i][p] == 1: imos[p] += 1
        if arr[i][p] == -1: imos[p+1] -= 1
 
ans = 0
for i in range(1,L):
    imos[i] += imos[i-1]
    ans = max(ans, imos[i])
 
print(ans)

Measured memory_bytes: 27508
import Control.Monad
import Control.Applicative
import Data.List

main = do
	n <- readLn
	[a, b] <- map (read :: String -> Int) . words <$> getLine
	l <- replicateM (n + 1) $ readLn
	print $ solve a b l

solvew :: Int -> Int -> [(Int, Int)] -> (Int, Int)
solvew a b [] = (a, b)
solvew a b ((x, y):z) = 
	let
		q = solvew a b z
		i = fst q
		j = snd q
		solveww c d e f
			| e * d <= c * f = (c, d)
			| otherwise = (c + e, d + f)
	in
		solveww i j x y

solve :: Int -> Int -> [Int] -> Int
solve a b (c:l) = 
	let
		q = solvew c a $ sort $ map (\x -> (x, b)) l
		x = fst q
		y = snd q
	in
		x `div` y

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


def main(input_str):
    n = int(input_str)
    if n == 0:
        print(0)
        return
    chi = -2
    bai = -2
    dif = n
    ret = ""
    while dif != 0:
        #print(n % chi)
        #print("amari {} {}".format(dif % chi, chi))
        if 0 != dif % chi:
            # print('1',end="")
            ret = '1' + ret
            #print(1)
            dif -= chi/bai
        else:
            # print('0',end="")
            #print(0)
            ret = '0' + ret
        chi *= bai

    print(ret)
        
    
if __name__ == '__main__':
    try:
        main(input().strip())
    except EOFError:
        pass


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define double long double
using namespace std;
typedef complex<double> P; //Point
typedef pair<P,P> L; //Line, Segment
const double EPS = 1e-10;
const double eps = 1e-10;
double dot(P a, P b){ return real(conj(a)*b);}
double cross(P a, P b){ return imag(conj(a)*b);}
bool eq(double a,double b){return abs(a-b)<eps;}
bool eq(P a,P b){return eq(a.real(),b.real())&&eq(a.imag(),b.imag());}
double getDistanceLP(L s, P p){

  assert( !eq( s.first, s.second) );

  return abs(cross(s.second - s.first, p - s.first) / abs(s.second - s.first));
}
bool isParalell(L a,L b){return  eq(0,cross(a.second-a.first,b.second-b.first));}

P crossPoint(L l, L m){
  double A = cross(l.second - l.first, m.second - m.first);
  double B = cross(l.second - l.first, l.second - m.first);
  if(fabs(A) < EPS && fabs(B) < EPS) return m.first;
  else if(fabs(A) >= EPS) return m.first + B / A * (m.second - m.first);
}

vector<L> A;
bool check(P a){
  double dis = getDistanceLP(A[0],a);

  for(int i=0;i<(int)A.size();i++)
    if(!eq(dis,getDistanceLP(A[i],a))) return 0;

  return  1;
}

L calc(P o,P a,P b){
  a-=o,b-=o;
  return L(o,(a/abs(a) + b/abs(b)) + o);
}

int main(){
  int n;
  while(cin>>n,n){
    A.resize(n);
    for(int i=0,x1,y1,x2,y2;i<n;i++){
      cin>>x1>>y1>>x2>>y2;
      A[i] = L(P(x1,y1),P(x2,y2));
    }


    if(n<=2){cout<<"Many"<<endl;continue;}
    
    vector<L> B; 
    for(int i=0;i<n;i++)
      for(int j=0;j<i;j++){
	L a = A[i], b = A[j];

	if(isParalell(a,b)||B.size()>100)continue;

	P o = crossPoint(a,b);
	P va=a.second-a.first;
	P vb=b.second-b.first;
	va /= abs(va);
	vb /= abs(vb);

	B.push_back( L( o , o+va+vb) );
	B.push_back( L( o , o+va-vb ) );

      }

    vector<P> ans;
    for(int i=0;i<(int)B.size();i++)
      for(int j=i+1;j<(int)B.size();j++){
	L a = B[i], b = B[j];
	if(isParalell(a,b)) continue;
	P c = crossPoint(a,b);
	if(check(c)&&(ans.empty()||!eq(ans[0],c))) ans.push_back(c);

      }
    
    if(ans.size()>=2) cout<<"Many"<<endl;
    else if(ans.empty()) cout<<"None"<<endl;
    else printf("%Lf %Lf\n",ans[0].real(),ans[0].imag());
  }
  return 0;
}

Measured memory_bytes: 3252
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    import bisect
    
    mod=10**9+7
    s=input()
    t=input()
    
    L=[[]for _ in range(26)]
    
    N=len(s)
    for i in range(N):
        c=ord(s[i])-97
        L[c].append(i)
        
    cur=-1
    rep=0
    
    M=len(t)
    for i in range(M):
        c=ord(t[i])-97
        if len(L[c])==0:
            print(-1)
            exit()
            
        num=bisect.bisect_right(L[c],cur)
        if num>=len(L[c]):
            rep+=1
            num=0
        cur=L[c][num]
        
    ans=N*rep + cur + 1
    print(ans)
        
        
        

main()


Measured memory_bytes: 79628
#!/usr/bin/env python3

import itertools
import sys


INF = sys.maxsize // 10


def all_subsets(xs):
    n = len(xs)
    gs = (itertools.combinations(xs, i) for i in range(n + 1))
    return itertools.chain(*gs)


def optimize(n, m, x, cs, table):
    res = INF
    for book_ids in all_subsets(list(range(n))):
        unds = [0 for _ in range(m)]
        cost = 0
        for book_id in book_ids:
            cost += cs[book_id]
            for j, a in enumerate(table[book_id]):
                unds[j] += a
        if all(und >= x for und in unds):
            res = min(res, cost)
    return res


def main():
    n, m, x = (int(z) for z in input().split())
    cs = [0 for _ in range(n)]
    table = [None for _ in range(n)]
    for i in range(n):
        ys = [int(z) for z in input().split()]
        cs[i] = ys[0]
        table[i] = ys[1:][:]
    res = optimize(n, m, x, cs, table)
    if res < INF:
        print(res)
    else:
        print(-1)


if __name__ == '__main__':
    main()

Measured memory_bytes: 9276
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input! {
        s: String,
    }
    let s = s.chars().collect::<Vec<_>>();
    let n = s.len();
    let mut result = 0;
    for i in 0..n / 2 {
        if s[i] != s[n - 1 - i] {
            result += 1;
        }
    }
    println!("{}", result);
}


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

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int X;
  cin>>X;
  if(X>=30)
  {
    cout<<"Yes";
  }
  else
  {
    cout<<"No";
  }
  return 0;
}

Measured memory_bytes: 3648
n = int(input())
list_A = list(map(int, input().split()))
list_B = list(map(int, input().split()))
ans = 0
for i in range(n):
  if list_A[i] >= list_B[i]:
    list_A[i] -= list_B[i]
    ans += list_B[i]
    list_B[i] = 0
  else:
    ans += list_A[i]
    list_B[i] -= list_A[i]
    list_A[i] = 0
    if list_B[i] > list_A[i+1]:
      ans += list_A[i+1]
      list_A[i+1] = 0
    else:
      ans += list_B[i]
      list_A[i+1] -= list_B[i]
print(ans)

Measured memory_bytes: 24132
let nil = -1;;
type node =
  {
    mutable parent:int;
    mutable left:int;
    mutable right:int;
    mutable height:int;
    mutable depth: int
  };;

let tree = Array.init 25 (fun x -> { parent=nil; left=nil; right=nil; height=0; depth=0 });;

let rec set_height u =
  let h1 = if tree.(u).right != nil then set_height tree.(u).right + 1
           else 0
    and
      h2 = if tree.(u).left != nil then set_height tree.(u).left + 1
           else 0
  in
  let hmax = if h1 > h2 then h1 else h2 in
  tree.(u).height <- hmax; hmax
;;

let rec set_depth u d =
  if u != nil then
    begin
      tree.(u).depth <- d;
      set_depth tree.(u).left (d+1);
      set_depth tree.(u).right (d+1)
    end
;;

let rec get_root = function
    -1 -> nil
  | i -> if tree.(i).parent = nil then i
         else get_root (i-1)
;;

let get_sibling u =
  if tree.(u).parent = nil then nil
  else if tree.(tree.(u).parent).left != u && tree.(tree.(u).parent).left != nil then
    tree.(tree.(u).parent).left
  else if tree.(tree.(u).parent).right != u && tree.(tree.(u).parent).right != nil then
    tree.(tree.(u).parent).right
  else nil
;;

let rec read = function
    0 -> ()
  | i ->
     let l = read_line ()
             |> Str.split (Str.regexp " ")
             |> List.map int_of_string
             |> Array.of_list
     in
     tree.(l.(0)).left <- l.(1);
     tree.(l.(0)).right <- l.(2);
     if l.(1) != nil then tree.(l.(1)).parent <- l.(0);
     if l.(2) != nil then tree.(l.(2)).parent <- l.(0);
     read (i-1)
;;

let print_node u =
  Printf.printf "node %d: " u;
  Printf.printf "parent = %d, " tree.(u).parent;
  Printf.printf "sibling = %d, " (get_sibling u);
  let ldeg = if tree.(u).left != nil then 1 else 0 and
      rdeg = if tree.(u).right != nil then 1 else 0 in
  Printf.printf "degree = %d, "  (ldeg+rdeg);
  Printf.printf "depth = %d, " tree.(u).depth;
  Printf.printf "height = %d, " tree.(u).height;
  if tree.(u).parent = nil then Printf.printf "root\n"
  else if tree.(u).left = nil && tree.(u).right = nil then Printf.printf "leaf\n"
  else Printf.printf "internal node\n"
;;

let () =
  let n = read_int () in
  read n;
  let root = get_root (n-1) in
  set_depth root 0;
  let _ = set_height root in
  let rec print = function
      i when i = n -> ()
    | i -> print_node i; print (i+1)
  in print 0
;;

Measured memory_bytes: 2356
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    String S = in.next();

    int ans = 0;
    for (int i = 0; i < S.length(); i++) {
      for (int j = i + 1; j <= S.length(); j++) {
        String s = S.substring(i, j);
        boolean match = true;
        for (int k = 0; k < s.length(); k++) {
          char c = s.charAt(k);
          if (!(c == 'A' || c == 'C' || c == 'G' || c == 'T')) {
            match = false;
          }
        }
        if (match) {
          ans = Math.max(ans, s.length());
        }
      }
    }
    
    System.out.println(ans);
  }
}

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



int main()
{
	string s; cin >> s;
	string t = "";
	for (int i = s.size() - 1; i >= 0; --i)
	{
		t += s[i];
		if (t == "maerd" || t == "remaerd" || t == "esare" || t == "resare")
			t = "";
	}
	cout << ((t == "") ? "YES" : "NO") << endl;
}



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

int main() {
    int a, b, ret = -1;
    cin >>a >>b;
    for (int i = 1; i<=1251; i++) {
        if ((int)(i*0.08)==a && (int)(i*0.10)==b){ret=i;break;}
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256