akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

bool compair(P a, P b)
{
    return a.second < b.second;
}

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

    vector<P> ab(m);

    for (int i = 0; i < m; i++)
    {
        cin >> ab[i].first >> ab[i].second;
    }

    sort(ab.begin(), ab.end(), compair);

    int ans = 0, t = 0;

    for (int i = 0; i < m; i++)
    {
        if (t <= ab[i].first)
        {
            t = ab[i].second;
            ans++;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 4836
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include <complex>
using namespace std;
 
#define FOR(i,a,b) for(LL i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it,a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))
 
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB push_back
 
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;
 
const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;

const int MAX = 705;



LL gcd(LL a, LL b)
{
	if (a == 0) return b;
	return gcd(b % a, a);
}


LL up(LL a, LL b) {
	if (a >= 0) return (a + b - 1) / b;
	return - ((-a)/b);
}

int main()
{
	//freopen("In.txt", "r", stdin);
	int t;
	scanf("%d", &t);
	while(t--) {
		LL a, b, c, d;
		scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
		//cout << a << " " << b << " " << c << " " << d << endl;
		if (a < b || b > d) {
			printf("No\n");
			continue;
		}
		if (c >= b) {
			printf("Yes\n");
			continue;
		}
		LL g = gcd(b, d);
		//cout << "g = " << g << endl;
		if (up(c - b - a % g + 1, g) * g + a % g >= 0) {
			printf("Yes\n");
		} else {
			printf("No\n");
		}
	}
	
	return 0;
}



Measured memory_bytes: 256
#-*-coding:utf-8-*-

def main():
    a, b, c, k = map(int, input().split())
    if abs(a - b) > 10 ** 18:
        print('Unfair')
        return
    if k % 2 == 0:
        print(a - b)
    else:
        print(b - a)

if __name__ == '__main__':
    main()

Measured memory_bytes: 2940
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;

#define ll long long 
#define read(x) scanf("%d",&x)

struct node
{
	int id,val;
}a[2005];
ll dp[2005][2005];
int n;

bool cmp(node n,node m){return n.val<m.val;}

int main()
{
	read(n);
	for(int i=1;i<=n;i++) read(a[i].val),a[i].id=i;
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;i++) dp[i][i]=1ll*a[1].val*abs(a[1].id-i);
	for(int i=2;i<=n;i++)
	{
		for(int l=1;l+i-1<=n;l++)
		{
			int r=l+i-1;
			dp[l][r]=0;
			dp[l][r]=max(dp[l][r],max(dp[l+1][r]+1ll*a[i].val*abs(a[i].id-l),dp[l][r-1]+1ll*a[i].val*abs(a[i].id-r)));
		}
	}
	printf("%lld\n",dp[1][n]);
}


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

using namespace std;

#define ll long long

int main()
{
	ll N;
	cin >> N;
	vector < ll > a(N);
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}

	ll ans = 0;
	for (int i = 0; i < N; i++) {
		while (a[i] % 2 == 0) {
			a[i] /= 2;
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}


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

int main() {
	long long W,H;cin>>W>>H;
	long long x,y;cin>>x>>y;
	
	cout<<fixed<<setprecision(10)<<H*W*0.5<<" "<<(y==H*0.5&&x==W*0.5 ? 1 : 0)<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,f[102];
int main (void){
    while(cin>>a>>b>>c>>d){
        memset(f,0,sizeof(f));
        int num=0;
        for(int i=a;i<b;i++){f[i]+=1;}
        for(int i=c;i<d;i++){f[i]+=1;}
        for(int i=a;i<=d;i++){
            if(f[i]==2)num++;
        }
        cout<<num<<endl;
    }
    return 0;
}


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

bool dfs(int n,int c,vector<int>& col,vector<vector<int>>& v){
    col[n] = c;
    bool ok = true;
    for(auto x:v[n]){
        if(col[x]==0) ok &= dfs(x,-c,col,v);
        else if(col[x]==c) return false;
    }
    return ok;
}

int main(){
    int N,M;
    while(cin >> N >> M && N){
        vector<vector<int>> v(N+1);
        vector<int> col(N+1,0);
        int x,y;
        for(int i=0;i<M;i++){
            cin >> x >> y;
            v[x].push_back(y);
            v[y].push_back(x);
        }
        if(!dfs(1,1,col,v)){
            cout << 0 << endl;
            continue;
        }
        int b = 0,w = 0;
        set<int> s;
        for(int i=1;i<=N;i++) (col[i]==1? b:w)++;
        if(b%2==0) s.insert(b/2);
        if(w%2==0) s.insert(w/2);
        cout << s.size() << endl;
        for(auto x:s) cout << x << endl;
    }
}


Measured memory_bytes: 3180
#include <iostream>

using namespace std;

int main(void)
{
    int n;
    int a[100];

    cin >> n;
    for (int i=0; i<n; i++)
        cin >> a[i]; 
    for (int i=n-1; i>=0 ; i--)
    {
        cout << a[i];
        if (i > 0)
            cout << " ";
    }
    cout << endl;
}


Measured memory_bytes: 3096
n = int(input())
a = list(map(int, input().split()))
gc = 0

def div2(a):
    global gc
    for i in range(n):
        if a[i] % 2:
            break
    else:
        gc += 1
        div2(list(map(lambda x: x // 2, a)))
    return gc

print(div2(a))


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

int main(){
  string s;
  cin >> s;
  
  for(int i=0; i<s.size(); i+=2){
    if (i<s.size()-1 || i<s.size()-2){
      cout << s.at(i);
    }
    else {
      cout << s.at(i);
    }
  }
}

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

int dp[100001];
int a[100];
int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 1; i <= k; i++) {
    int win = 0;
    for (int j = 0; j < n; j++)
      if (i >= a[j] && !dp[i-a[j]])
	win = 1;
    dp[i] = win;
  }
  cout << (dp[k] ? "First" : "Second") << endl;
}


Measured memory_bytes: 640
M,D=map(int,input().split())
ans = 0
for i in range(1,M+1):
  for j in range(1,D+1):
    m1 = j % 10
    m10 = j // 10
    if (m1 >= 2) and (m10 >= 2) and (m1*m10==i):
      ans += 1
print(ans)


Measured memory_bytes: 2940
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<string>
#include<stdexcept>
#include<stdio.h>
#include<queue>
#include <cmath>
#define cinf(n,x) for(int i=0;i<n;i++) cin >> x[i];
//for(int i=0;i<n;i++)
using namespace std;
using ll = long long;
//abc125のdをDPでゴリ押しする
//define dp[i][j] j=0:stay j=1:reverse i番目までのsummax
//A1,A2,...,Aiを確定しj=1ならiを選んで反転した場合 
//(すなわち Ai+1の符号が反転している状態)のA1+A2+..z.+Aiの最大値
int main(){
  int n,a[100005];
  ll dp[100005][2]={};
  cin >> n;
  cinf(n,a);
  
  dp[0][0] = 0;
  dp[0][1] = -10e8;
 
  for(int i=0;i<n;i++){
    dp[i+1][0] = max(dp[i][0]+a[i],dp[i][1]-a[i]);
    dp[i+1][1] = max(dp[i][0]-a[i],dp[i][1]+a[i]);
  }
 
  cout << dp[n][0]<<endl;

}

Measured memory_bytes: 2304
#include <iostream>
using namespace std;
void dfs1(int x,int y);
void dfs2(int x,int y);
void dfs3(int x,int y);
char ch[100][100];
int w,h;
int main()
{
    int i,j;
     int num=0;
    cin>>h>>w;
    while(w!=0&&h!=0)
    {
        for(i=0;i<h;i++)
        for(j=0;j<w;j++)
        cin>>ch[i][j];

    for(i=0;i<h;i++)
    for(j=0;j<w;j++)
    if(ch[i][j]=='#')
    {
       dfs1(i,j);
       num++;
    }
    for(i=0;i<h;i++)
    for(j=0;j<w;j++)
    if(ch[i][j]=='@')
    {
       dfs2(i,j);
       num++;
    }
    for(i=0;i<h;i++)
    for(j=0;j<w;j++)
    if(ch[i][j]=='*')
    {
       dfs3(i,j);
       num++;
    }
    cout<<num<<endl;
    num=0;
    cin>>h>>w;

    }
    return 0;
}
void dfs1(int x,int y)
{
    ch[x][y]='.';
    int nx,ny;
    for(int i=-1;i<=1;i++)
    for(int j=-1;j<=1;j++)
        if(i+j==1||i+j==-1)
        {
            nx=x+i;
            ny=y+j;
            if(nx>=0&&nx<h&&ny>=0&&ny<w&&ch[nx][ny]=='#')
            dfs1(nx,ny);
        }
}
void dfs2(int x,int y)
{
    ch[x][y]='.';
    int nx,ny;
    for(int i=-1;i<=1;i++)
    for(int j=-1;j<=1;j++)
        if(i+j==1||i+j==-1)
        {
            nx=x+i;
            ny=y+j;
            if(nx>=0&&nx<h&&ny>=0&&ny<w&&ch[nx][ny]=='@')
            dfs2(nx,ny);
        }
}
void dfs3(int x,int y)
{
    ch[x][y]='.';
    int nx,ny;
    for(int i=-1;i<=1;i++)
    for(int j=-1;j<=1;j++)
        if(i+j==1||i+j==-1)
        {
            nx=x+i;
            ny=y+j;
            if(nx>=0&&nx<h&&ny>=0&&ny<w&&ch[nx][ny]=='*')
            dfs3(nx,ny);
        }
}


Measured memory_bytes: 3784
#include <iostream>
#include <string>
#include <vector>
#include<algorithm>
#include <stdio.h>
#include <bitset>
#include<math.h>
#include<list>
#include<map>
using namespace std;
typedef long long ll;
#define PI 3.14159265358979323846  

int main() {
	int m, n;
	cin >> n >> m;
	int mi = min(m, n);
	int ma = max(m, n);
	string s = "";
	for (int i = 0; i < ma; i++) {
		s += to_string(mi);
	}
	cout << s << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define int ll
using pint = pair<int,int>;
using Graph = vector<vector<int>>;
void YN(bool flg) {cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg) {cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg) {cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define out(n) cout << n << '\n'
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const int mod = 1000000007;
const long long INF = 1e10; //10^10
const double PI = acos(-1.0L);
const int dx[4] = {1, 0, -1, 0} , dy[4] = {0, 1, 0, -1};
/*mod逆元*/long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}
template< typename T >T mod_pow(T x, T n, T p=MOD) {T ret = 1;while(n > 0) {if(n & 1) (ret *= x) %= p;(x *= x) %= p;n >>= 1;}return ret;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n >>= 1; } return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);

    int a,b,c; cin >> a >> b >> c;
    if(a+b+c>=22) out("bust");
    else out("win");

    return 0;
}


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

	
	int main() {
			int tmp;
			int  n;
			string t;
			int count = 0;
			vector<int> vec;
			cin >> n >>t;
			
			/*for (int i = 0; i < n; i++) {
				cin >> i;
				vec.push_back(i);
			}*/
			for (int i = 0; i < n; i++) {
				if (t[i] == 'A'&& t[i+1] == 'B' &&t[i+2] == 'C') {
					count++;
				}
			}
			cout << count;



	}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(){
  vector<int> a(10);
  int i,j,k;
  for(i=1;i<=9;i++){
    cin >> a[i];
  }
  int n;
  cin >> n;
  vector<int> b(100);
  for(i=1;i<=n;i++){
    cin >> b[i];
  }
  vector<bool> c(10);
  for(i=1;i<=n;i++){
    for(j=1;j<=9;j++){
      if(b[i] ==a[j]) c[j]=true;
    }
  }
  if((c[1]==true && c[2]==true && c[3]==true)||(c[4]==true && c[5]==true && \
c[6]==true) || (c[7]==true && c[8]==true && c[9]==true) || (c[1]==true && c[\
4]==true && c[7]==true) || (c[2]==true && c[5]==true && c[8]==true) || (c[3]\
==true && c[6]==true && c[9]==true) || (c[1]==true && c[5]==true && c[9]==tr\
ue) || (c[3]==true && c[5]==true && c[7]==true)){
    cout << "Yes" << "\n";
  }
  else cout << "No" << "\n";
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>


int main(){
  ll A, V, B, W, T;
  cin >> A >> V >> B >> W >> T;

  if ((V-W)*T<abs(A-B)) cout << "NO" << endl;
  else cout << "YES" << endl;

  
  
  

  
  
  // cout << fixed << setprecision(10);
  
  return 0;
}



Measured memory_bytes: 3640
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007
#define INF 1000000000
typedef pair<int64_t, int64_t> PII;
typedef vector<int64_t> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

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

string S, A = "AKIHABARA", B = "KIHBR" ; cin >> S;

if (S.size() > A.size()) {
    cout << "NO\n";
    return 0;
}

if (S.size() == A.size()) {
    if (S == A) cout << "YES\n";
    else cout << "NO\n";
    return 0;
}

if (S.rfind("KIH") == string::npos) {
    cout << "NO\n";
    return 0;
}

rep(i, 0, S.size())
    if (S[i] == 'A') S.erase(i, 1);

if (S == B) cout << "YES\n";
else cout << "NO\n";

}

// 書いて考える
// 境界，出力文字列 チェック
// 可読性優先．高速化次点．
// まずは全探索，分割統治，次にDP
// 制限を見る．境界に注意．求めたい量の変域．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<long long, long long>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;

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

  int n, k; cin >> n >> k;
  vector<ll> sum(n+1);
  vector<ll> psum(n+1);

  rep(i, n) {
    ll a; cin >> a;
    sum[i+1] = sum[i] + a;
    a = max(a, 0LL);
    psum[i+1] = psum[i] + a;
  }

  ll ans = 0;
  for(int i=0; i+k<=n; i++) {
    // i ... i+k-1: black, rest: free
    ll now = psum[i] - psum[0];
    now += psum[n] - psum[i+k];
    if (sum[i+k] - sum[i] > 0) {
      now += sum[i+k] - sum[i];
    }
    ans = max(now, ans);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ALL(c) begin(c), end(c)
using namespace std;
using ll = long long;
using ld = long double;

const int N = 1e6+6;


int main(){
	//freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout);
	ios::sync_with_stdio(0);cin.tie(0);//cout.precision(12);cout<<fixed;
	
	int n, k;
	
	cin>>n>>k;
	vector<int> a(n);
	for(auto &_ : a) cin>>_;
	
	int l = 1, r = 1e9+9;
	while(l<r){
		int d = (l+r)>>1;
		int cnt = 0;
		for(int x : a) cnt+=(x+d-1)/d - 1;
		if(cnt>k) l = d+1; else r = d;
	}
	
	cout<<r<<endl;
	
	return 0;
}


Measured memory_bytes: 3972
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define rusha scanf("%d",&n);rep(i,1,n)scanf("%d",&a[i]);
#define rushb scanf("%d",&t);while(t--)
#define debug(x) cout<<"LBWNB    "<<x<<"---\n"
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define p() puts("")
#define mem(a,b) memset(a,b,sizeof a)
#define all(x) (x.begin(),x.end())
#define judgef printf("%s\n",f?"Yes":"No")
#define Judgef printf("%s\n",f?"YES":"NO")

using namespace std;
typedef long long ll;
const int mod=998244353;
const int inf=1e9+7;
const int maxn=3e3+10;

int S[3],ord[3],res;
char s[3][4010];
bool mat[3][3][4010];
int main(){
	memset(mat,true,sizeof(mat));
	for(int i=0;i<3;i++)scanf("%s",s[i]),S[i]=strlen(s[i]),res+=S[i];
	for(int i=0;i<3;i++)for(int j=0;j<3;j++){
		if(i==j)continue;
		for(int k=0;k<S[i];k++){
			for(int l=0;l<S[j]&&k+l<S[i];l++)if(s[i][k+l]!='?'&&s[j][l]!='?'&&s[i][k+l]!=s[j][l]){mat[i][j][k]=false;break;}
			if(mat[i][j][k])res=min(res,(S[0]+S[1]+S[2])-min(S[j],S[i]-k));
		}
	}
	for(int i=0;i<3;i++)ord[i]=i;
	do{
		for(int j=0;j<S[ord[0]];j++)for(int k=j;k<max(S[ord[0]],j+S[ord[1]]);k++){
			if(!mat[ord[0]][ord[1]][j])continue;
			if(!mat[ord[0]][ord[2]][k])continue;
			if(!mat[ord[1]][ord[2]][k-j])continue;  
			res=min(res,max(S[ord[0]],max(j+S[ord[1]],k+S[ord[2]])));
		}
	}while(next_permutation(ord,ord+3));
	printf("%d\n",res);
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main { 
	Scanner in = new Scanner(System.in);
	public static void main(String[] args){
		new Main();
	}

	public Main(){      
		new AOJ0042();
	}
	class AOJ0042{
		//      int w,n;
		//      tresure[] takara;
		
		void print(int dp[]){
			for(int i=0;i<dp.length;i++)System.out.print(dp[i]+" ");
			System.out.println();
		}
		
		public AOJ0042() {
			int c=1;
			while(true){
				int w = in.nextInt();
				if(w==0)break;
				int n = in.nextInt();
				tresure[] takara = new tresure[n];
				for(int i=0;i<n;i++){
					String[] a = in.next().split(",");
					takara[i]=new tresure(Integer.parseInt(a[0]),Integer.parseInt(a[1]));
				}
				int[] dp = new int[w+1];
				for(int s=0;s<n;s++){
					int[] a = Arrays.copyOf(dp,w+1);
					for(int i=0;i<=w;i++)if(a[i]>0){
						if(takara[s].heavy+i<=w)dp[takara[s].heavy+i]=Math.max(a[takara[s].heavy+i],a[i]+takara[s].money);
					}
					if(takara[s].heavy<=w)dp[takara[s].heavy]=Math.max(dp[takara[s].heavy],takara[s].money);
//					print(dp);
				}
				int max_heavy=0;
				int max_money=0;
				for(int i=0;i<=w;i++)if(max_money<dp[i]){
					max_money=dp[i];
					max_heavy=i;
				}
				System.out.println("Case "+c+":");
				c++;
				System.out.println(max_money);
				System.out.println(max_heavy);
			}
		}
		class tresure{
			int money,heavy;
			public tresure(int money,int heavy) {
				this.money=money;
				this.heavy=heavy;
			}
		}
	}
}

Measured memory_bytes: 27852
N, K = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(N)]
ab.sort(key=lambda x: x[0])
ab.insert(0, [0, 0])

for i in range(1, N+1):
    a, b = ab[i]
    ab[i] = [a, ab[i-1][1] + b]

for i in range(N):
    if ab[i][1] < K <= ab[i+1][1]:
        ans = ab[i+1][0]
        break

print(ans)


Measured memory_bytes: 31036
#include <bits/stdc++.h>
#define m_k make_pair
#define inf 0x3f3f3f3f
using namespace std;
const int N=200100;
int n,m,vi[N];
signed main()
{
	scanf("%d%d",&n,&m);
	if (n&1)
	{
		int l,r;
		l=1;r=n;
		for (int i=1;i<=m;i++)
		{
			printf("%d %d\n",l,r);
			l++;r--;
		}
	}
	else
	{
		int l,r;
		l=1;r=n;
		while (m>0)
		{
			if (r-l+1==n+2-(r-l+1) || vi[r-l+1] || vi[n+2-(r-l+1)]) break;
			vi[r-l+1]=vi[n+2-(r-l+1)]=1;
			printf("%d %d\n",l,r);
			m--;
			l++;r--;
		}
		if (m>0)
		{
			r--;
			while (m>0)
			{
				printf("%d %d\n",l,r);
				m--;
				l++;r--;
			}
		}
	}
}


Measured memory_bytes: 4236
#include<bits/stdc++.h>
#define ALL(c) begin(c), end(c)
using namespace std;
using ll = long long;
using ld = long double;

const int N = 2e5+5;

int n;
int a[N];
vector<int> g[N];

int ans[N];

int f[N];

int rmq(int i){
	int res = 0;
	for(;i>=0;i=(i&(i+1))-1) res = max(res, f[i]);
	return res;
}

vector<pair<int,int>> h;
void upd(int i, int x){
	for(;i<n;i|=i+1){
		h.push_back({i,f[i]});
		f[i] = max(f[i],x);
	}
}


void go(int v, int p = -1, int mx = 0){
	
	int x = a[v];
	int cur = rmq(x-1) + 1;
	mx = max(mx, cur);
	ans[v] = mx;
	
	int s = h.size();
	upd(x,cur);
	
	for(int i : g[v]) if(i!=p){
		go(i,v,mx);
	}
	
	while(h.size()!=s){
		int i = h.back().first;
		int val = h.back().second;
		f[i] = val;
		h.pop_back();
	}
}


int main(){
	//freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout);
	ios::sync_with_stdio(0);cin.tie(0);//cout.precision(12);cout<<fixed;
	
	
	cin>>n;
	for(int i=0;i<n;++i) cin>>a[i];
	
	vector<int> v(a,a+n);
	sort(ALL(v));
	for(int i=0;i<n;++i) a[i] = lower_bound(ALL(v),a[i]) - begin(v);
	
	
	for(int i,j,k=1;k<n;++k){
		cin>>i>>j;
		--i; --j;
		g[i].push_back(j);
		g[j].push_back(i);
	}
	
	go(0);
	
	for(int i=0;i<n;++i) cout<<ans[i]<<'\n';
	
	return 0;
}


Measured memory_bytes: 42144
#include<stdio.h>
int main()
{
    int n,m,m1,i,sum=0;
    scanf("%d%d",&n,&m);
    for(i=1;i<=m;i++)
    {
        scanf("%d",&m1);
        sum=sum+m1;
    }
    if((n-sum)<0)
        printf("-1\n");
    else
        printf("%d\n",n-sum);
    return 0;
}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = (int)(n); i >= 0; i--)
#define repm(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define repmr(i, m, n) for(int i = (int)(n); i >= (int)(m); i--)
#define all(x) (x).begin(),(x).end()
#define inf 2e9

using namespace std;
typedef long long int lli;
typedef long long ll;

int n,q;
vector<vector<int>> tree(200000, vector<int>());

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

    cout << (n-1)*(m-1) << endl;
}


Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int MOD = 1e9+7;
using ll = long long;
using vi = vector<int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(x) x.begin(), x.end()
int main() {
    int a,b,c;
    cin >> a >> b >> c;
    c *= b;
    if(a>c)cout << "No";
    else cout << "Yes";
}


Measured memory_bytes: 3620
#include <algorithm>
#include <iterator>
#include <iostream>
#include <iomanip>
#include <utility>
#include <string>
#include <vector>
#include <limits>
#include <queue>
#include <cmath>
#include <map>
#include <set>

using namespace std;

typedef long long ll;

int calc_dist(int a, int b, int c, int d)
{
    return abs(a - c) + abs(b - d);
}

int main()
{
    int prev_t = 0;
    int prev_x = 0, prev_y = 0;
    
    int n;
    cin >> n;

    for(int i = 0; i < n; i++) {
        int t, x, y;
        cin >> t >> x >> y;
        int dist = calc_dist(prev_x, prev_y, x, y);
        int dt = t - prev_t;
        if(dist > dt) {
            cout << "No" << endl;
            return 0;
        }
        if((dt - dist) % 2) {
            cout << "No" << endl;
            return 0;
        }

        prev_x = x;
        prev_y = y;
        prev_t = t;
    }

    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
	double v,t;
	while(scanf("%lf",&v)!=EOF){
		v=((v*v*4.9)/(9.8*9.8)+5)/5;
		t=v-(int)v;
		if(t>0.0)v=1.0+(int)v;
		printf("%.0lf\n",v);
	}
	exit(0);
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int INF = 1e9 + 7;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> a(n), dp(n+2, INF);
	rep(i,n) cin >> a[i];
	for(int i = n-1; i >= 0; --i){
		int idx = lower_bound(dp.begin(), dp.end(), a[i]+1) - dp.begin();
		dp[idx] = a[i];
	}
	rep(i,n+1){
		if(dp[i] == INF){
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 3972
using System.Collections.Generic;
using System.Collections;
using System.IO;
using System.Linq;
using System.Text;
using System;

class Prog
{
    public static void Main(string[] args)
    {
        new Prog().Solve();
    }

    void Solve(){
        var S = Console.ReadLine();
        var T = Console.ReadLine();
        int count = 0;
        for (int i = 0; i < S.Length;i++){
            if(S[i] != T[i])count++;
        }
        Console.WriteLine(count);
        Console.ReadKey();
    }
}

public struct Vector2
{
    public Vector2(double x, double y)
    {
        this.@this = new double[] { x, y };
    }


    public double[] @this;

    public double x
    {
        get
        {
            return @this[0];
        }
        set
        {
            @this[0] = value;
        }
    }

    public double y
    {
        get
        {
            return @this[1];
        }
        set
        {
            @this[1] = value;
        }
    }

    public double magnitude { get { return Math.Pow(sqrMagnitude, 1 / 2); } }

    public double sqrMagnitude { get { return Math.Pow(x, 2) + Math.Pow(y, 2); } }

    public Vector2 normalized { get { return this * (1 / this.magnitude); } }

    public static Vector2 operator +(Vector2 a, Vector2 b)
    {
        return new Vector2(a.x + b.x, a.y + b.y);
    }

    public static Vector2 operator -(Vector2 a, Vector2 b)
    {
        return new Vector2(a.x - b.x, a.y - b.y);
    }

    public static Vector2 operator *(Vector2 a, double b)
    {
        return new Vector2(a.x * b, a.y * b);
    }


    public static Vector2 operator /(Vector2 a, double b)
    {
        if (b == 0)
        {
            throw new DivideByZeroException();
        }
        else return new Vector2(a.x / b, a.y / b);
    }

    public bool Equals(Vector2 other)
    {
        return (@this[0] == other.@this[0] && @this[1] == other.@this[1]);
    }

}

Measured memory_bytes: 18272
# -*- coding: utf-8 -*-


N = int(input())
Sn = [str(input()) for _ in range(N)]

ans = Sn.pop()
while len(Sn) > 0:
  s = list(Sn.pop())
  t = ans
  ans = ""
  for c in t:
    if c in s:
      ans += c
      s.remove(c)

print("".join(sorted(ans)))

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


int main()
{
  string s;
  string t;
  cin >> s >> t;
  int ret = 0;
  for (int i = 0; i < s.size();++i) {
    if(s[i]== t[i])
      ++ret;
  }
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
array = [""]*k
for i in range(n):
    array[i % k]+=t[i]
a = 0

for l in array:
    l = l.replace("rr", "r0").replace("ss", "s0").replace("pp", "p0")
    a += p * l.count("r") + r * l.count("s") + s * l.count("p")
print(a)

Measured memory_bytes: 6132
#include<stdio.h>
int main(void)
{
	int num[10];
	int tmp=0;
	int count,counta,countb,countc;
	for(count=0;count<10;count++){
		scanf("%d",&num[count]);
	}
	for(counta=0;counta<10;counta++){
		for(countb=counta+1;countb<10;countb++){
			if(num[counta]<num[countb]){
				tmp = num[counta];
				num[counta] = num[countb];
				num[countb] = tmp;
			}
		}
	}
	for(countc=0;countc<3;countc++){
		printf("%d\n",num[countc]);
	}

	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int main(void) {
    int A, B;
    cin >> A >> B;

    cout << max(A - B * 2, 0) << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
	
int W,H,x,y,r;

scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);

if( x-r>=0 &&  W>=x+r && H>=y+r && y-r>=0){
	
	printf("Yes\n");
}
else{
	printf("No\n");
}


return 0;

}

Measured memory_bytes: 584
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
    return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
    return a > b && (a = b, true);
}
/*-------------------------------------------*/

int n;
using P = pair<int, int>;
vector<P> ps;

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

    cin >> n;
    rep(i, n) {
        int x;
        int y;
        cin >> x >> y;
        ps.emplace_back(x, y);
    }

    sort(ALL(ps),
         [](P a, P b) { return a.first + a.second < b.first + b.second; });

    ll ans = abs(ps.front().first - ps.back().first) +
             abs(ps.front().second - ps.back().second);

    sort(ALL(ps),
         [](P a, P b) { return a.first - a.second < b.first - b.second; });

    chmax(ans, abs(ps.front().first - ps.back().first) +
                   abs(ps.front().second - ps.back().second));

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5232
while True:
    n = input()
    if n == 0:
        exit()
    A = [int(raw_input()) for _ in xrange(n)]
    if all(a <= 0 for a in A):
        print max(A)
        continue
    
    r = 0
    tmp = 0
    ans = 0
    while r < n:
        tmp += A[r]
        if tmp < 0:
            l = r
            tmp = 0
        else:
            ans = max(ans, tmp)
        r += 1
    print ans

Measured memory_bytes: 6444
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in=new Scanner(System.in);
		int num=in.nextInt();
		int[] arr=new int[num];
		
		for(int i=0;i<num;i++)
		{
			arr[i]=in.nextInt();
		}
		
		Map<Integer,Integer> map=new HashMap<>();
		
		for(int i=0;i<num;i++)
		{
			if(map.containsKey(arr[i])==true)
			{
				map.put(arr[i], map.get(arr[i])+1);
			}
			else
			{
				map.put(arr[i], 1);
			}
		}
		
		int count=0;
		
		for(Map.Entry<Integer, Integer> el:map.entrySet())
		{
			int key=el.getKey();
			int value=el.getValue();
			
			if(value>key)
			{
				count=count+(value-key);
			}
			else if(value<key)
			{
				count=count+value;
			}
		}
		
		System.out.println(count);

	}

}


Measured memory_bytes: 54784
a, b = map(int, input().split())
if 1 > a or a > 20:
    raise ValueError("invalid number")
    
if 1 > b or b > 20:
    raise ValueError("invalid number")

if a <= 0 or a >= 10:
    print("-1")
elif b <= 0 or b >= 10:
    print("-1")
else:
    print("{}".format(a*b))

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



// int N, M, A[10010], B[10010], COST[10010];
// pair<int, int> bridge[10010];
int P[10010];//村のrootが保存

void init(int N){
  for(int i=0; i< N; ++i){
    P[i]= i;
  }
}

int root(int a){//aのroot(代表元)を決める
  if(P[a]==a) return a;//aはroot
  return (P[a] = root(P[a]));//aの親のrootを求め,aの親とする
}
bool is_same_set(int a, int b){
  return root(a) == root(b);
}
void unite(int a, int b){
   P[root(a)] = root(b);
}


int main(){
  int N, M, A[10010], B[10010], COST[10010];
  pair<int, int> bridge[10010];

  //root決める
  while(cin >> N >> M  && N>0){
    int allcost = 0;
    // int bridgenum = 0;
    init(N);
    for (int i = 0; i < M; ++i)
    {
      cin >> A[i] >> B[i] >> COST[i];
      bridge[i].first = COST[i];
      bridge[i].second = i ;
    }
    sort(bridge,bridge+M);
    for (int i = 0; i < M; ++i)
    {
      int cost = bridge[i].first;
      int a = A[bridge[i].second];
      int b = B[bridge[i].second];

      // if (bridgenum == M-1)
      // {
      //   unite(a,b);
      //   // allcost += cost;
      // }
      if(is_same_set(a,b)){

      }else{
        unite(a,b);
        allcost += cost;
        // cout <<  allcost << endl;
        // bridgenum += 1;
      }
      // 「a から b に cost の橋がかかっている」と表示
    }
    cout <<  allcost << endl;
  }
}

Measured memory_bytes: 1256
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1LL << 30;

int main(){
  int N;
  cin >> N;
  vi a(N);
  for(int i = 0; i < N; i++){
    cin >> a.at(i);
  }
  int ans = 0;
  int num = 1;
  for(int i = 0; i < N; i++){
    if(a.at(i) != num) ans++;
    else num++;
  }
  if(ans == N) cout << -1 << endl;
  else cout << ans << endl;
}

Measured memory_bytes: 1024
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop;
// dfmt on
void main()
{
    auto input = stdin.byLine.map!split.joiner;

    long X;
    X = input.front.to!long;
    input.popFront;

    long K;
    K = input.front.to!long;
    input.popFront;

    long D;
    D = input.front.to!long;
    input.popFront;

    solve(X, K, D);
}

void solve(long X, long K, long D)
{
    X = abs(X);
    long c = X / D;
    if (K <= c)
    {
        writeln(X - K * D);
        return;
    }
    long x = X - c * D;
    long k = K - c;
    writeln((k & 1) ? abs(x - D) : x);
}


Measured memory_bytes: 3736
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d,i,j;
    double x,y,z;
   cin>>a;
    x = (double(a)/3)*( double(a)/3)*(double(a)/3);
   printf("%.12f\n",x);
   return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int lb(int l,int r,long long n,long long *d){
  int m=(l+r)/2;
  if(l==r)return m;
  return n<d[m]?lb(l,m,n,d):lb(m+1,r,n,d);
}
int main(){
  long long n,m,x,a[200020],b[200020],s[200020],t[200020],i,j,ans=0;
  scanf("%lld %lld %lld",&n,&m,&x);
  for(i=0;i<n;i++)scanf("%lld",&a[i]);
  for(i=0;i<m;i++)scanf("%lld",&b[i]);
  for(i=0;i<n;i++)s[i+1]=s[i]+a[i];
  for(i=0;i<m;i++)t[i+1]=t[i]+b[i];
  //for(i=0;i<n+1;i++)printf("%lld ",s[i]);printf("\n");
  //for(i=0;i<m+1;i++)printf("%lld ",t[i]);printf("\n");
  for(i=0;i<=n;i++){
    if(x<s[i])continue;
    j=lb(0,m+1,x-s[i],t);
    if(i+j>ans)ans=i+j;
  }
  printf("%lld\n",ans-1);
  return 0;
}
    


Measured memory_bytes: 7960
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>

#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> Vi;

const int N=1e5+19;

string s;
int f[N];
int n;

int main(){
	cin>>s;
	n=s.length();
	f[0]=1;
	For(i,1,n+1){
		if (i>=5&&s.substr(i-5,5)=="dream") f[i]|=f[i-5];
		if (i>=7&&s.substr(i-7,7)=="dreamer") f[i]|=f[i-7];
		if (i>=5&&s.substr(i-5,5)=="erase") f[i]|=f[i-5];
		if (i>=6&&s.substr(i-6,6)=="eraser") f[i]|=f[i-6];
	}
	puts(f[n]?"YES":"NO");
}

Measured memory_bytes: 896
function main(input) {
    a = input[0].split(' ');
    n = a[0];
    x = a[1];
    l = input[1].split(' ');
    var i,value = 0, ans = 0;
    for(i=0; i<n; i++) {
        l[i] = parseInt(l[i], 10);
        if (value <= x) {
            ans++;
            value += l[i];
        }
    }
    if (value <= x) ans++;
    console.log(ans);
}
main(require("fs").readFileSync("/dev/stdin", "utf8").split('\n'));

Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
int a,b,c,x,s=0;
int main(){
	cin>>a>>b>>c>>x;
	for(int i=0;i<=a;i++){
		for(int j=0;j<=b;j++){
			for(int h=0;h<=c;h++){
				if((i*500+j*100+h*50)==x){
					s++;
				}
			}
		}
	}
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = [int(x) for x in input().split()]

mod = 10**9 + 7


class Comb(object):
    def __init__(self, N, mod=10**9 + 7):
        self.mod = mod
        self.fac, self.inv = [1] * (N + 1), [1] * (N + 1)
        for i in range(2, N + 1):
            self.fac[i] = self.fac[i - 1] * i % mod
            self.inv[i] = self.inv[i - 1] * pow(i, mod - 2, mod) % mod

    def calc(self, n, k):
        if n >= k:
            return self.fac[n] * self.inv[k] * self.inv[n - k]
        else:
            return 0


c = [0] * (n + 1)
indexes = [[] for _ in range(n+1)]
for i in range(n + 1):
    c[a[i]] += 1
    indexes[a[i]].append(i)
    if c[a[i]] == 2:
        indexes = indexes[a[i]]
        break

m = indexes[0] + (n - indexes[1])
comb = Comb(n + 1)
for k in range(1, n + 2):
    x = comb.calc(n + 1, k)
    y = comb.calc(m, k - 1)
    ans = (x - y) % mod
    print(ans)


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

const int maxn=2e5+7;
int a[maxn];


int main (){
	string str;cin>>str;
	int ans=0;
	for(int i=0;i<3;i++) if(str[i]=='o')ans+=100;
	cout<<700+ans<<endl;
	return 0;
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
  int a, b;
  cin >> a >> b;
  cout << (((a * b) & 1) ? "Yes" : "No");
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3648
//2018年  3月 26日 月曜日 15:08:32 JST-15:18:06
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N, K;
int ans = 0;
vi G[MAX_N];

int loop(int v, int p) {
	int depth = 0;
	rep(i, 0, sz(G[v])) {
		int n = G[v][i];
		MAX(depth, loop(n, v) + 1);
	}
	if(depth == K - 1 && p != 0) {
		ans++;
		return -1;
	}
	else return depth;
}

void solve() {
	cin >> N >> K;
	rep(i, 0, N) {
		int a;
		cin >> a; a--;
		if(i == 0) {
			ans += (a != 0);
		}
		else {
			G[a].pb(i);
		}
	}
	rep(i, 0, sz(G[0])) {
		int n = G[0][i];
		loop(n, 0);
	}
	cout << ans << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



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

using namespace std;

// Repetitions
#define FOR(i,a,n) for(ll i = ((ll) a); i < ((ll) n); ++i)
#define FORR(i, s, g) for(ll i = ((ll)s - 1); i >= ((ll) g); --i)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, n, 0)

// Container Utils
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define SORTALL(v) sort(ALL(v))
#define SZ(a) int((a).size())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())

// For Debug
#define DMP(x)  cerr << #x << " = " << (x) << endl
#define DBG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

// Aliases
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

// I/O Asynchronizing
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;

int main() {
    int k, x;
    cin >> k >> x;
    FOR(i, x - k + 1, x + k) {
        cout << i;
        if(i + 1 < x + k) cout << " ";
    }
    cout << "\n";

    return 0;
}


Measured memory_bytes: 256
o = input()
e = input()

leno = len(o)
lene = len(e)

s=""
if leno==lene:
  for i in range(leno):
    s += o[i]+e[i]
else:
  for i in range(lene):
    s+= o[i]+e[i]
  s+=o[-1]
print(s)
  
    
    

Measured memory_bytes: 3060
n, a, b, c = map(int, input().split())

v = {
  'A': a,
  'B': b,
  'C': c
}
ss = []
for _ in range(n):
  ss.append(input())

history = [] 
flag = True
  
for i in range(n):
  
  s = ss[i]
  
  if v[s[0]] == 0 and v[s[1]] == 0:
    flag = False
    break
  elif v[s[0]] > v[s[1]]:
    history.append(s[1])
    v[s[0]] -= 1
    v[s[1]] += 1
  elif v[s[0]] < v[s[1]]:
    history.append(s[0])
    v[s[0]] += 1
    v[s[1]] -= 1
  elif i == n-1:
    history.append(s[0])
    v[s[0]] += 1
    v[s[1]] -= 1
  elif s[0] in ss[i+1]:
    history.append(s[0])
    v[s[0]] += 1
    v[s[1]] -= 1
  else:
    history.append(s[1])
    v[s[0]] -= 1
    v[s[1]] += 1
if flag:
  print("Yes")
  print('\n'.join(history))
else:
  print("No")

Measured memory_bytes: 17388
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
using namespace std;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef long long ll;
#define range(i,a,b) for(int i=a;i<b;++i)
#define rep(i,n) range(i,0,n)
#define INF 10000000000 //10^10
#define PI 3.141592

int main(){
    string s;
    cin >> s;
    int a,b,c,d;
    a=int(s[0])-48;
    b=int(s[1])-48;
    c=int(s[2])-48;
    d=int(s[3])-48;
    string op="+-";
    rep(i,2) rep(j,2) rep(k,2) {
        int ans=a;
        if(i==0){
            ans+=b;
        }else{
            ans-=b;
        }
        if(j==0){
            ans+=c;
        }else{
            ans-=c;
        }
        if(k==0){
            ans+=d;
        }else{
            ans-=d;
        }
        if(ans==7){
            cout << a << op[i] << b << op[j] << c << op[k] << d << "=7" << endl;
            return 0;
        }
    }
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <string>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
using namespace std;

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

using ll = long long int;
using pll = pair<ll, ll>;

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

    vector<ll> ps(n);
    rep (i, n) { cin >> ps[i]; }

    ll res = 0;

    rep (i, n - 2)
    {
        const bool a = ps[i] < ps[i + 1] && ps[i + 1] <= ps[i + 2];
        const bool b = ps[i + 2] < ps[i + 1] && ps[i + 1] <= ps[i];

        if (a || b) { ++res; }
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
import collections

N,M = map(int,input().split())
A = list(map(int,input().split()))
bc = [list(map(int,input().split())) for i in range(M)]

card = collections.Counter(A).most_common()

card.sort(key=lambda x: x[0])
bc.sort(key=lambda x: x[1])

#print(card)
#print(bc)

ans = 0

while N != 0 and len(card) != 0 and len(bc) != 0:
    if card[-1][0] >= bc[-1][1]:
        x = card.pop()
        ans += x[0]*min(x[1],N)
        N = max(N-x[1],0)
    else:
        x = bc.pop()
        ans += x[1]*min(x[0],N)
        N = max(N-x[0],0)

if N != 0:
    if len(card) == 0:
        while N != 0:
            x = bc.pop()
            ans += x[1]*min(x[0],N)
            N = max(N-x[0],0)
    else:
        while N != 0:
            x = card.pop()
            ans += x[0]*min(x[1],N)
            N = max(N-x[1],0)

print(ans)


Measured memory_bytes: 45900