akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int a[1000];
int main()
{
    int n,q;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    cin>>q;
    for(int i=0;i<q;i++)
    {
        int m,j,l,r,ans;
        cin>>l;cin>>r;cin>>m;
        ans=0;
        for(j=l;j<r;j++)
        {
            if(m==a[j])
                ans++;
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 3104
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using namespace std;


void solve(long long N, long long K, long long R, long long S, long long P, std::string T){
  long long score = 0;
  vector<char> hand(N, '0');
  for (int i = 0; i < N; ++i) {
    if (i < K || hand[i-K] != T[i]) {
      if (T[i] == 'r') {
        score += P;
      } else if (T[i] == 's') {
        score += R;
      } else if (T[i] == 'p') {
        score += S;
      }
      hand[i] = T[i];
    }
  }
  std::cout << score << std::endl;
}

int main(){
  long long N;
  scanf("%lld",&N);
  long long K;
  scanf("%lld",&K);
  long long R;
  scanf("%lld",&R);
  long long S;
  scanf("%lld",&S);
  long long P;
  scanf("%lld",&P);
  std::string T;
  std::cin >> T;
  solve(N, K, R, S, P, T);
  return 0;
}


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

int main() {
  int X;
  cin >> X;

  int tmp = X;
  int F_X = 0;
    
  while(tmp != 0) {
    F_X += (tmp % 10);
    tmp /= 10;
  }
  
  if ( (X % F_X) == 0 ) {
    cout << "Yes" << endl;
  } else {
    cout << "No"  << endl;
  }
}

Measured memory_bytes: 3632
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;

struct Node {
  int key;
  Node *right, *left, *parent;
};

Node *root, *NIL;

void insert(int k) {
  Node *y = NIL;
  Node *x = root;
  Node *z;

  z = (Node *)malloc(sizeof(Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while (x != NIL) {
    y = x;
    if(z->key < x->key) {
      x = x ->left;
    } else {
      x = x->right;
    }
  }
  z->parent = y;
  if(y == NIL) {
    root = z;
  } else {
    if(z->key < y->key) {
      y->left = z;
    } else {
      y->right = z;
    }
  }
}

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

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

int main() {
  int n, i, x;
  string com;

  scanf("%d", &n);
  for(i = 0; i < n; i++) {
    cin >> com;
    if(com == "insert") {
      scanf("%d",&x);
      insert(x);
    } else if(com == "print") {
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}



Measured memory_bytes: 26752
a = sorted(list(map(int, input().split(' '))))
tmp = [a[1]-a[0], a[2]-a[1], a[2]-a[0]]
if tmp[0] % 2 == 0: print(int(tmp[0] / 2) + tmp[1])
else: print(int((tmp[1]+tmp[2]+1) / 2) + 1)

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T> void operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) cin >> e; }

typedef long long ll;
int const inf = 1<<29;

int main() {

  int N; cin >> N;
  int vs[N];
  rep(i, N) {
    cin >> vs[i];
  }

  int ys[N];

  rep(i, N) {
    int cnt = 0;
    int num = vs[i];
    while(num / 2 > 0 && num % 2 == 0) {
      cnt++;
      num >>= 1;
    }
    ys[i] = std::min(cnt, 2);
  }

  int zerocnt = 0;
  int onecnt = 0;
  int twocnt = 0;
  rep(i, N) {
    zerocnt += ys[i] == 0;
    onecnt += ys[i] == 1;
    twocnt += ys[i] == 2;
  }

  if (zerocnt == twocnt + 1 && onecnt == 0) {
    std::cout << "Yes\n";
  } else if(zerocnt <= twocnt) {
    std::cout << "Yes\n";
  } else {
    std::cout << "No\n";
  }
  
  return 0;
}

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

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

class Solver {
 public:
  int n;
  vector<int> o, e, v, cnt_e, cnt_o;
  Solver(LL n) : n(n), v(n), cnt_e(100001), cnt_o(100001){};

  void solve() {
    e.push_back(0);
    o.push_back(0);
    for (int i = 0; i < n; ++i) {
      cin >> v[i];
      if (i % 2 == 0) {
        e.push_back(v[i]);
        cnt_e[v[i]]++;
      } else {
        o.push_back(v[i]);
        cnt_o[v[i]]++;
      }
    }
    DBG(v)
    sort(e.begin(), e.end(), [&](int x, int y) { return cnt_e[x] > cnt_e[y]; });
    e.erase(unique(e.begin(), e.end()), e.end());
    sort(o.begin(), o.end(), [&](int x, int y) { return cnt_o[x] > cnt_o[y]; });
    o.erase(unique(o.begin(), o.end()), o.end());
    int ans = INF;
    DBG(e, o)
    for (int i = 0; i < n; i += 2) {
      int a = (n + 1) / 2 - cnt_e[v[i]], b = 0;
      if (v[i] == o[0]) {
        b = n / 2 - cnt_o[o[1]];
      } else {
        b = n / 2 - cnt_o[o[0]];
      }
      ans = min(ans, a + b);
    }
    cout << ans << endl;
  }
};

}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(12);
  long long n = 0;
  std::cin >> n;

  Problem::Solver sol(n);
  sol.solve();
  return 0;
}


Measured memory_bytes: 2044
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <map>
#include <stack>
#include <string>
#include <list>
#include <deque>
#include <math.h>
using namespace std;

typedef pair<int, int> P;
#define ll long long
#define int ll
#define INF (1LL<<30)

signed main(){
	int N;
	deque<int> d;
	int a;

	cin >> N;
	for (int i = 0; i < N; i++){
		cin >> a;
		if (i % 2 == 1)
			d.push_front(a);
		else
			d.push_back(a);
	}

	if (N % 2 == 0)
		for (int i = 0; i < N; i++) cout << d[i] << " ";
	else
		for (int i = N-1; i >=0; i--) cout << d[i] << " ";

	cout << endl;

	return 0;
}





Measured memory_bytes: 3840
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <array>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>

#define INF_LL 9000000000000000000
#define INF 2000000000

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

using namespace std;

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

class Union_find{
private:
	vector<int> par;
	vector<int> rank;
	int n;

public:
	Union_find(int a){
		n = a;
		for(int i = 0;i < n;i++){
			par.push_back(i);
			rank.push_back(0);
		}
	}

	int find(int x){
		if(par[x] == x){
			return x;
		}else{
			return par[x] = find(par[x]);
		}
	}

	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return;

		if(rank[x] < rank[y]){
			par[x] = y;
		}else{
			par[y] = x;
			if(rank[x] == rank[y]) rank[x]++;
		}
	}

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

int main(void){
	int D, N;
	int T[200];
	int dp[200][101];
	vector<int> C[61];
	cin >> D >> N;
	REP(i, D){
		cin >> T[i];
	}
	REP(i, N){
		int a, b, c;
		cin >> a >> b >> c;
		FOR(j, a, b+1){
			C[j].push_back(c);
		}
	}
	REP(i, 200){
		fill(dp[i], dp[i]+101, -1);
	}
	REP(i, C[T[0]].size()){
		dp[0][C[T[0]][i]] = 0;
	}
	FOR(i, 1, D){
		REP(j, C[T[i]].size()){
			int diff = 0;
			REP(k, 101){
				if(dp[i-1][k] == -1) continue;
				diff = max(diff, dp[i-1][k] + abs(C[T[i]][j] - k));
			}
			dp[i][C[T[i]][j]] = diff;
		}
	}
	ll res = 0;
	REP(i, 101){
		if(dp[D-1][i] != -1) res = max(res, (ll)dp[D-1][i]);
	}
	cout << res << endl;
}

Measured memory_bytes: 3260
#include <bits/stdc++.h>
using namespace std;
int main(){
  
  int N,M;
  cin >> N >> M;
  int A[M],B[M];
  vector<vector<int>> Ren(N,vector<int>());
  for(int i=0;i<M;i++){
    cin >> A[i] >> B[i];
    A[i]--; B[i]--;
    Ren.at(A[i]).push_back(B[i]);
    Ren.at(B[i]).push_back(A[i]);
  }
  queue<int> seen;
  int Pr[N]; bool TA[N];
  for(int i=0;i<N;i++) TA[i]=false;
  for(int i=0;i<N;i++) Pr[i]=-1;
  TA[0]=true;
  seen.push(0);
  int ct=0;
  
  while(!(seen.empty()||ct==N)){
    int S =seen.front();
    for(int i=0;i<Ren.at(S).size();i++){
      int NextV = Ren.at(S).at(i);
      if(TA[NextV]) continue;
      Pr[NextV]=S;
      seen.push(NextV);
      TA[NextV]=true;
    }
    seen.pop();
    ct++;
  }
  
  cout << "Yes"<<endl;
  for(int i=1;i<N;i++){
    cout << Pr[i]+1 << endl;
  }
  
  
}

Measured memory_bytes: 11980
#include<bits/stdc++.h>
using namespace std;
#define intl long long int 

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	intl i,j,n,k;
	cin>>k>>n;
	vector<intl> ar(n);
	vector<intl> br(n);
	for(i=0;i<n;i++){
		cin>>ar[i]>>br[i];
	}
	vector<intl> dp(k+1,1e15);
	for(i=0;i<=k;i++){
		for(j=0;j<n;j++){
			if(ar[j]>=i){
				dp[i]=min(dp[i],br[j]);
			}
			else{
				dp[i]=min(dp[i],dp[i-ar[j]]+br[j]);
			}
		}
	}
	cout<<dp[k]<<"\n";
}


Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
class Solve {
public:
    void solve() {
        Int a, b, x;
        cin >> a >> b >> x;
        if (a * a * b <= 2 * x) {
            double h = 1. * x / a / a;
            double Y = 2. * (b - h);
            double R = sqrt(a * a + Y * Y);
            double ans = 180. * asin(Y / R) / acos(-1);
            if (ans < 0 || ans > 90) {
                exit(-1);
            }
            cout << ans << endl;
            return;
        } else {
            double Y = b;
            double S = 1. * x / a;
            double X = 2. * S / Y;
            double R = sqrt(X * X + Y * Y);
            double ans = 180. * asin(Y / R) / acos(-1);
            if (ans < 0 || ans > 90) {
                exit(-1);
            }
            cout << ans << endl;
        }

    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


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

using namespace std;


int main(){
  vector<char> s;
  string S;
  bool flag=false;
  cin >> S;
  for(int i=0;i<S.size();i++){
    s.push_back( S.at(i) );
  }
  int q;
  cin >> q;
  for(int i=0;i<q;i++){
    int t;
    cin >> t;
    if(t == 1){
      if(flag){
        flag = false;
      }
      else{
        flag = true;
      }
    }
    if(t == 2){
      int f;
      char c;
      cin >> f >> c;
      if(f == 1){
        if(flag){
          s.push_back(c);
        }
        else{
          s.insert(s.begin(), c);
        }
      }
      if(f == 2){
        if(flag){
          s.insert(s.begin(), c);
        }
        else{
          s.push_back(c);
        }
      }
    }
  }
  if(flag){
    reverse(s.begin(), s.end());
  }
  
  for(char a : s){
    cout << a;
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 1144
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
using ll = long long;
using P = pair<int, int>;

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

struct Edge{
    int to, id;
    Edge(int to, int id):to(to), id(id){}
};

int n;
vector<vector<Edge>> G;
vector<int> res;

void dfs(int v, int p, int pc){
    int color = 1;
    if(color==pc)color++;
    for(auto e : G[v]){
        if(e.to == p) continue;
        res[e.id] = color;
        dfs(e.to, v, color);
        ++color;
        if(color == pc) ++ color;
    }
}


int main(){
    cin >> n;
    G.resize(n);
    rep(i,n-1){
        int a, b;
        cin >> a >> b; 
        --a, --b;
        G[a].emplace_back(b, i);
        G[b].emplace_back(a, i);
    }
    int mx = 0;
    rep(i,n) mx = max(mx, (int)G[i].size());
    res.assign(n-1, 0);
    dfs(0, -1, -1);
    cout << mx << endl;
    for(auto v : res) cout << v << endl;
    return 0;
}

Measured memory_bytes: 7424
#include<algorithm>
#include<chrono>
#include<climits>
#include<numeric>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<random>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<vector>
#include<cassert>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
using namespace std;
 
#define rep(i, a, b) for(auto i = (a); i < (b); i++)
#define rrep(i, a, b) for(auto i = (a); i > (b); i--)
#define all(v) (v).begin(), (v).end()
#define print(v) {for(auto x : v) cout << x << ' '; cout << endl;}
#define printn(v, n) {for(int _i = 0; _i < n; _i++) cout << *(v + _i) << ' '; cout << endl;}
 
typedef unsigned long long ull;
typedef long long ll;
 
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
 
const int MAXN = 1e6 + 20;

int n;
int a[MAXN], b[MAXN], s[MAXN];

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

    cin >> n;
    int m = 1 << n;
    for(int i = 0; i < m; i++)
    	cin >> s[i];
    sort(s, s + m, greater<int>());
    // printn(s, m);
    // cout << endl;

    a[0] = s[0];
    for(int i = 0; i < m - 1; i++)
    	s[i] = s[i + 1];
    int cur = 1;

    bool valid = true;
    for(int it = 0; it < n; it++) {
    	int i = 0;
    	int j = 0;
    	int k = 0;
    	while(i < cur && j < m - cur) {
    		if(a[i] > s[j]) {
    			b[k++] = s[j];
    			s[j] = -1;
    			i++;
    			j++;
    		}
    		else j++;
    	}
    	if(i != cur) {
    		valid = false;
    		break;
    	}
    	i = j = 0;
    	while(j < m - cur) {
    		if(s[j] == -1) j++;
    		else s[i++] = s[j++];
    	}

    	i = j = cur - 1;
    	k = 2 * cur - 1;
    	// printn(a, cur);
    	// printn(b, cur);
    	while(i >= 0 || j >= 0) {
    		if(i < 0 || (j >= 0 && a[i] > b[j])) 
    			a[k--] = b[j--];
    		else
    			a[k--] = a[i--];
    	}
    	cur *= 2;
    	// printn(a, cur);
    	// printn(s, m - cur);
    	// cout << endl;
    }
    if(valid) cout << "Yes" << endl;
    else cout << "No" << endl;


    return 0;
}











Measured memory_bytes: 9472
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <queue>
#include <string>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int main(){
    string s,t;
    cin >> s >> t;
    int cnt = 0;
    rep(i,s.length()){
        if(s[i] != t[i]){
            cnt++;
        }
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3900
import sys
sys.setrecursionlimit(10**6)


def DFS(num):
    A.add(int(num))
    n=int(num[-1])
    for i in (max(n-1,0),n,min(n+1,9)):
        i=str(i)
        A.add(int(num+i))
        if len(num)<=8:DFS(num+i)


n=int(input())
A=set()
for i in range(1,10):
    DFS(str(i))
A=sorted(A)
print(A[n-1])

Measured memory_bytes: 84572
#include <stdio.h>
int main(void)
{
    int w,h,x,y,r;
    scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);
    if(w<x+r || 0>x-r){
        printf("No\n");
    }else if(h<y+r || 0>y-r){
        printf("No\n");
    }else{
        printf("Yes\n");
    }
    return 0;
}



Measured memory_bytes: 2096
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n,m,x,y,a[110],b[110],maxn=-110,minn=110;
int main()
{
	cin>>n>>m>>x>>y;
	int p;
	for (int i=1;i<=n;i++)
	{
		cin>>p;
		if (p>maxn) maxn=p;
	}
	for (int i=1;i<=m;i++)
	{
		cin>>p;
		if (p<minn) minn=p;
	}
	for (int z=x+1;z<=y;z++)
		if (z>maxn && z<=minn)
		{
			cout<<"No War"<<endl;
			return 0;
		}
	cout<<"War"<<endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
p = list(map(int, input().split()))
nl = list(range(1, n+1))
if nl == p:
    print("YES")
    exit()
res = []
for i in range(n):
    if p[i] != nl[i]: 
        res.append(i)
if len(res) == 2:
    if nl[res[0]] == res[0]+1 and nl[res[1]] == res[1]+1:
        print("YES")
        exit()
print("NO")      

Measured memory_bytes: 3064
n,m=map(int,input().split())
a=list(map(int,input().split()))
bc=[list(map(int,input().split())) for i in range(m)]
bc.sort(key=lambda x:x[1])
for b,c in bc[::-1]:
  a.extend([c]*b)
  if len(a) > 2*n:
    break
a.sort(reverse=True)
print(sum(a[:n]))


Measured memory_bytes: 34884
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

ll arr[10];
ll K;

int main() {
	for(int i = 0; i < 5; i++) {
		scanf("%lld", &arr[i]);
	}
	scanf("%lld", &K);
	sort(arr, arr + 5);
	if(arr[4] - arr[0] > K) {
		printf(":(\n");
	}
	else {
		printf("Yay!\n");
	}
	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 256
digit :: Int -> Int
digit n = length $ takeWhile (<= n) ( iterate (*10) 1 )


-- 各桁ペアごとのルンルン性リストを返す
checkDigits :: Int -> [Bool]
checkDigits n = reverse [ abs (a - b) <= 1 | (a,b) <- zip ms (tail ms) ]
    where
        ms = take (digit n) . map (`mod` 10) $ iterate (`div` 10) n


-- ダメな桁ペアの一番最初のもの
-- 例：97123 -> 1,2番目の要素について、 (|9-7| <= 1) を満たさないから
--     この場合 2番目の要素を +1, つまり +10^3 = 10^(digit - 2(=badIndex)) 
--     したい。よって戻り値 2。
badIndex :: [Bool] -> Int
badIndex ns = (2+) . length $ takeWhile (== True) ns


isLun :: Int -> Bool
isLun n = and $ checkDigits n


bitLun :: Int -> Int
bitLun n 
    | isLun n   = 1 
    | otherwise = 0


floorNum :: Int -> Int -> Int
floorNum n i  = n - mod n (10^i)


searchK :: Int -> Int
searchK n = f' (n+1) 0
    where
    f' 0 count = count - 1
    f' k count = f' (k - bitLun count) next
        where
        next
            | isLun count = count + 1
            | otherwise   = floorNum (count + (10 ^ pow)) pow
        pow = digit count - badIndex (checkDigits count)


main :: IO ()
main = do
    k <- read <$> getLine :: IO Int
    print $ searchK k
    

Measured memory_bytes: 892
let to_list str =
  let n = String.length str in
  let rec doit i acc =
    if i = n then acc
    else doit (i + 1) (str.[i] :: acc)
  in
  doit 0 []

let to_int c = int_of_char c - int_of_char '0'

let plus l1 l2 =
  let rec doit l1 l2 i carry acc =
    if l1 = [] && l2 = [] then begin
      if carry = 1 then (i + 1, 1 :: acc)
      else (i, acc)
    end else if l1 = [] then
      let x = to_int (List.hd l2) + carry in
      if x <= 9 then doit [] (List.tl l2) (i + 1) 0 (x :: acc)
      else doit [] (List.tl l2) (i + 1) 1 (x mod 10 :: acc)
    else if l2 = [] then
      let x = to_int (List.hd l1) + carry in
      if x <= 9 then doit (List.tl l1) [] (i + 1) 0 (x :: acc)
      else doit (List.tl l1) [] (i + 1) 1 (x mod 10 :: acc)
    else
      let x = to_int (List.hd l1) + to_int (List.hd l2) + carry in
      if x <= 9 then doit (List.tl l1) (List.tl l2) (i + 1) 0 (x :: acc)
      else doit (List.tl l1) (List.tl l2) (i + 1) 1 (x mod 10 :: acc)
  in
  doit (to_list l1) (to_list l2) 0 0 []

let () =
  let n = read_int () in
  let rec doit i =
    if i < n then begin
      let l1 = read_line () in
      let l2 = read_line () in
      let n1 = String.length l1 in
      let n2 = String.length l2 in
      if n1 > 80 || n2 > 80 then print_endline "overflow"
      else if n1 < 10 && n2 < 10 then Printf.printf "%d\n" (int_of_string l1 + int_of_string l2)
      else begin
        let z, ans = plus l1 l2 in
        if z > 80 then print_endline "overflow"
        else (List.iter (fun e -> print_int e) ans; print_newline ())
      end;
      doit (i + 1)
    end
  in
  doit 0

Measured memory_bytes: 2272
main :: IO ()
main = do
    [c11, c12, c13] <- map read . words <$> getLine :: IO [Int]
    [c21, c22, c23] <- map read . words <$> getLine :: IO [Int]
    [c31, c32, c33] <- map read . words <$> getLine :: IO [Int]
    let c2sub1 = c21 - c11 
    let c3sub1 = c31 - c11
    let r2sub1 = c12 - c11
    let r3sub1 = c13 - c11

    putStrLn $ if c22-c12==c2sub1 && c23-c13==c2sub1 
               && c32-c12==c3sub1 && c33-c13==c3sub1 
               && c22-c21==r2sub1 && c32-c31==r2sub1 
               && c23-c21==r3sub1 && c33-c31==r3sub1 then "Yes" else "No"


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

ll weight[110];
ll value[110];
ll dp[110][100100] = {0};

int main() {
    int N, W;
    cin >> N >> W;
    rep(i, N) { cin >> weight[i] >> value[i]; }

    rep(i, N) {
        for (int j = 0; j <= W; j++) {
            if (j - weight[i] >= 0)
                dp[i + 1][j] =
                    max(dp[i][j - weight[i]] + value[i], dp[i + 1][j]);

            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
        }
    }

    cout << dp[N][W] << endl;
}

Measured memory_bytes: 79360
import numpy as np
# スペース区切りの整数入力
N,M,X = map(int, input().split())

a = np.zeros((N,M+1))

for i in range(N):
    # スペース区切りの整数をリストに入力
    a[i] = [int(x) for x in input().split()]

b = np.zeros(N)
c = np.zeros(M+1)
min_cost = 9999999999999999

for i in range(2**N):
    ii = i
    for j in range(N):
        b[j] = ii % 2
        ii = ii // 2
    c = np.zeros(M+1)
    flg = "ok"
    for k in range(M+1):
        for j in range(N):
            c[k] += a[j,k] * b[j]
        if k > 0 and c[k] < X:
            flg = "ng"
            continue
    if flg == "ok":
        min_cost = min(min_cost,c[0])

if min_cost == 9999999999999999:
    print(-1)
else:
    print(int(min_cost))


            

Measured memory_bytes: 27184
// g++ -std=c++14

/*

Today might be the chance to grasp the chance to let your talent bloom.
May be tomorrow, the day after, or next year...
May be even when you are 30. I'm not sure if physique has anything to do with it
but if you think that it will never come, it probably never will.

- Tooru Oikawa.

*/


#include<bits/stdc++.h>

typedef long long ll;
typedef long double lld;
using namespace std;

#define sd(x) scanf("%d",&x)
#define sd2(x,y) scanf("%d%d",&x,&y)
#define sd3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define endl "\n"
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define LET(x, a)  __typeof(a) x(a)
#define foreach(it, v) for(LET(it, v.begin()); it != v.end(); it++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define __ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define all(c) c.begin(),c.end()
#define inf 1000000000000000001

#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)

template<typename S, typename T>
ostream& operator<<(ostream& out,pair<S,T> const& p){out<<'('<<p.fi<<", "<<p.se<<')';return out;}

template<typename T>
ostream& operator<<(ostream& out,vector<T> const& v){
ll l=v.size();for(ll i=0;i<l-1;i++)out<<v[i]<<' ';if(l>0)out<<v[l-1];return out;}

template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}

template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}

#define int ll

int32_t main(){ _
	int a, b;
	cin >> a >> b;
	cout << a + (b / 2) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int sum[100009];

int main(){
  int n;
  long long a[100009],b[100009];
  long long ans=0;
  cin>>n;
  for(int i=0;i<n+1;i++){
    cin>>a[i];
  }
  for(int i=0;i<n;i++){
    cin>>b[i];
  }
  
  for(int i=0;i<n;i++){
    if(b[i]<=a[i]){
      ans+=b[i];
    }
    else{
      b[i]-=a[i];
      ans+=min(b[i],a[i+1])+a[i];
      a[i+1]=max(a[i+1]-b[i],0ll);
    }
  }

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


Measured memory_bytes: 1792
#include<bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)
#define ROP(i, n)       for(int i = 1 ; i <= n ; i++)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define VECOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define SORT(obj) sort(ALL(obj))
#define GSORT(obj) sort(ALL(obj) , greater<int>())
#define P pair<int , int>
#define V vector<int>
#define VLL vector<long long>
#define M map<int, int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

#define MAX_H 6
#define MAX_W 6

int main(void) {
  
	ios::sync_with_stdio(false);	cin.tie(0);
    int N;  cin >> N;
    V A(N);  VECCIN(A);
    GSORT(A);
    ll ans = 0;

    for(int i = 1 ; i < N ; i++)
      ans += A[i/2];

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


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

using namespace std;
int main()
{
    string s;
    cin>>s;
    if(s[0] == s[1] && s[1] != s[2] && s[2] == s[3]){
        cout<<"Yes";
    }
    else if(s[0] == s[2] && s[2] != s[1] && s[1] == s[3]){
        cout<<"Yes";
    }
    else if(s[0] == s[3] && s[3] != s[1] && s[1] == s[2]){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }

    return 0;
}


Measured memory_bytes: 3612
#define D(x) cout << #x " = " << x << endl
#define DD(x, y) cout << "(" #x ", " #y ") = (" << x << ", " << y << ")" << endl
#define DDD(x, y, z) cout << "(" #x ", " #y ", " #z ") = (" << x << ", " << y << ", " << z << ")" << endl
#define DV(v) for (auto __macro_vi : v){ cout << __macro_vi << " ";} cout << endl;
#define DA(a, n) for (int __macro_i = 0; __macro_i < n; ++__macro_i) { cout << a[__macro_i] << " "; } cout << endl;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(v) (v).begin(), (v).end()
#include<iostream>
#include<vector>
#include<cassert>
#include<cmath>
#include<map>
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p){ os << "(" << p.first << ", " <<  p.second << ")"; return os; }

using namespace std;
int n;
map<string, int> cnt;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> n;
    REP(i, n) {
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        cnt[s]++;
    }
    long long ans = 0;
    for (auto entry : cnt) {
        long long c = entry.second;
        ans += c * (c - 1) / 2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 8064
#include <iostream>
#include <vector>
#include <numeric>
using i64 = long long;

std::vector<long long> fact, inv;

constexpr auto pow(long long x, long long n, const long long mod) {
    long long ret = 1;
    while(n > 0) {
        if ((n & 1) == 1) ret = (ret * x) % mod;
        x = (x * x) % mod;
        n >>= 1;
    }
    return ret;
}

constexpr auto inverse(const long long x, const long long p) {
    return pow(x, p - 2, p);
}

void init_factorial(const int n, const long long mod) {
    fact.resize(n + 1);
    inv.resize(n + 1);
    fact[0] = 1;
    for (long long i = 1; i <= n; i++) fact[i] = fact[i - 1] * i % mod;
    inv[n] = inverse(fact[n], mod);
    for (long long i = n; i > 0; i--) inv[i - 1] = inv[i] * i % mod;
}

int main() {
    constexpr i64 mod = 1000000007;
    int n, k;
    std::cin >> n >> k;
    init_factorial(n, mod);
    std::vector<int> a(k);
    for(auto &e : a) std::cin >> e;

    auto f = [&](int i, int j) { return fact[n - j] * inv[n - a[i]] % mod * inv[a[i] - j] % mod; };

    std::vector<i64> dp(n + 1);
    dp[0] = 1;
    for (int i = 0; i < k; i++) {
        std::vector<i64> next(n + 1);
        for (int j = 0; j <= n; j++) for (int l = 0; j + l <= n && l <= a[i]; l++) {
            next[j + l] = (next[j + l] + dp[j] * f(i, l) % mod * inv[l] % mod) % mod;
        }
        std::swap(dp, next);
    }

    std::cout << dp[n] * fact[n] % mod << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
using namespace std;
typedef pair<int,int> P;
double dat[100][100];
int dp[6][1010];//動的計画法
int prime[10000001];
char str[1010][1010];
vector<pair<int,int> > pc[100001];
int ABS(int a){return max(a,-a);}
int main(){
	int k,s;
	cin>>k>>s;
	int ans=0;
	for(int x=0;x<=k;x++){
		for(int y=0;y<=k;y++){
			int z=s-x-y;
			if(0<=z && z<=k)ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4352
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <sstream>
#include <stack>
#include <queue>
#include <list>
#include <stdio.h>
#include <algorithm>
#define MAX 100000
using namespace std;
typedef long long ll;
int a[200001];
int L[100001],R[100001];
ll ans=0;
void merge(int a[],int left,int mid,int right)
{
	int len1,len2,i,j,k;
	len1=mid-left;
	len2=right-mid;
	for(i=0;i<len1;i++) L[i]=a[left+i];
	for(i=0;i<len2;i++) R[i]=a[mid+i];
	L[len1]=R[len2]=2000000000;
	i=j=0;
	for(k=left;k<right;k++)
	{
		if(L[i]<R[j]){
			a[k]=L[i++];
		}else{
			a[k]=R[j++];
			ans+=len1-i;
		}
	}
}
void mergeSort(int a[],int left,int right)
{
	int mid;
	if(left+1<right)
	{
		mid=(left+right)/2;
		mergeSort(a,left,mid);
		mergeSort(a,mid,right);
		merge(a,left,mid,right);
	}
} 
int main()
{	
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	mergeSort(a,0,n);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 4768
n=int(input())
train=[]
for i in range(n-1):
    train.append(list(map(int,input().split())))

time=[]
for i in range(n-1):
    t=train[i][1]+train[i][0]
    for j in range(i+1,n-1):
        if t<train[j][1]:
            t=train[j][1]+train[j][0]
        elif (t-train[j][1])%train[j][2]==0:
            t+=train[j][0]
        else:
            t+=train[j][2]-(t-train[j][1])%train[j][2]+train[j][0]
    print(t)

print(0)
        

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

int main()
{
	ll h = in(), w = in();
	vector<string>f(h + 2, string(w + 2, '.'));
	REP1(i, h) {
		string s; cin >> s;
		f[i] = "." + s + ".";
	}
	REP1(i, h) {
		REP1(j, w) {
			if (f[i][j] == '.') {
				ll cnt = 0;
				for (ll k = -1; k <= 1; ++k) {
					for (ll l = -1; l <= 1; ++l) {
						if (f[i + k][j + l] == '#') {
							++cnt;
						}
					}
				}
				cout << (char)('0' + cnt);
			} else {
				cout << '#';
			}
		}
		cout << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
     int a,b,c;
     cin>>a>>b>>c;
     if(a==b&&b==c&&c==a)cout<<"No"<<endl;
     else if(a==b||b==c||c==a){
             cout<<"Yes"<<endl;
     }
     else cout<<"No"<<endl;
}


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

#define INF 1e18
#define REP(i, n) for (int i=0; i<n; i++)
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = "<< x << endl

const double PI=3.141592653589793238462643383279502884197169399375105820974944;

typedef long long ll;

using namespace std;

void solve() {
    int N;
    cin >> N;
    vector<int> P(N);
    REP(i, N) cin >> P[i];

    int M = 1001001001;
    int ans = 0;
    REP(i, N) {
        M = min(M, P[i]);
        if (M >= P[i]) ans++;
    }
    print(ans);
}

signed main() {
    solve();
}


Measured memory_bytes: 1024
from heapq import heapify, heappop, heappush


N, M = map(int, input().split())
A = list(map(lambda x: -int(x), input().split()))
if N == 1:
    print(N >> M)
    exit()
heapify(A)
while M > 0:
    a = -heappop(A)
    while M > 0 and a >= -A[0]:
        a >>= 1
        M -= 1
    heappush(A, -a)
print(-sum(A))

Measured memory_bytes: 14180
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;


int main(){
  ll w,a,b; cin >> w >> a >> b;
  
  if((a<=b&&b<=a+w)||(b<=a&&a<=b+w)) cout << 0 << endl;
  else{
  cout << min(abs(a+w-b),abs(b+w-a)) << endl;
  }
}
  

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int T = sc.nextInt();
    int[] t = new int[N];
    int ans = 0;
    
    for(int i=0; i<N; i++){
        t[i] = sc.nextInt();
      if(i > 0){
        if(t[i]-t[i-1] >= T){
          ans += T;
        }else if(t[i]-t[i-1] < T){
          ans += t[i]-t[i-1];
        }
      }
    }
    System.out.println(ans+T);
  }
}

Measured memory_bytes: 85160
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K;
  cin>>N>>K;
  
  double sum=0;
  for (int i=1;i<N+1;i++) {
    int count=0;
    int p=i;
    while (p<K) {
      p*=2;
      count++;
    }
    sum+=1/(N* pow(2,count));
  }
  
  cout<<setprecision(15)<<sum<<endl;
  
  
}

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

int main() {
  int n, max;
  cin >> n;
  int v[n], c[n];
  for ( int i = 0; i < n; i++ ) { cin >> v[i]; }
  for ( int i = 0; i < n; i++ ) { cin >> c[i]; }

  max = 0;
  for ( int i = 0; i < n; i++ ) {
    if ( v[i]-c[i] > 0 ) { max += v[i]-c[i]; }
  }

  cout << max << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <ios>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;

int main()
{
    int A, B;
    char op;
    cin >> A >> op >> B;

    if (op == '+') {
        cout << A + B << "\n";
    } else {
        cout << A - B << "\n";
    }
}

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

using namespace std;


int main() {


    int n, m;
    scanf("%d %d", &n, &m);
    vector<pair<int, int> > vp(n);
    for(int i=0; i<n; i++)
        scanf("%d %d", &vp[i].first, &vp[i].second);
    sort(vp.begin(), vp.end());

    int idx=0, res = 0;
    priority_queue<int> pq;
    for(int i=m-1; i>=0; i--){
        while(idx < vp.size() && vp[idx].first + i <= m){
            pq.push(vp[idx].second);
            idx++;
        }
        if(pq.size()) {
            res += pq.top();
            pq.pop();
        }
    }
    printf("%d\n", res);
    return 0;
}


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

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  int a_c = min(a, c);
  
  
  int ans = 0;
  if(b < c || d < a){
    cout << 0 << endl;
    return 0;
  }
  else {
    if(b > d){
      ans = min(abs(d-c), (d-a));
    }
    else if(b <= d){
      ans = min(abs(b-a), (b-c));
    }
  }
  
  cout << ans << endl;
  
}
      

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

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

#define     endl               "\n"
#define     fast_io            ios::sync_with_stdio(false); cin.tie(0);
#define     file_io            freopen("input.txt", "r", stdin);   \
                               freopen("output.txt", "w", stdout);
#define     all(x)             begin(x), end(x)
#define     debug(x)           cerr <<"Line "<< __LINE__ <<" : "<< #x " = "<< x <<endl;
 
template<typename T, typename TT>
ostream& operator<<(ostream &os, const pair<T, TT> &t) { return os<<"("<<t.first<<", "<<t.second<<")"; }
template<typename T>
ostream& operator<<(ostream& os, const vector<T> &t) { for(auto& i: t) os<<i<<" "; return os; }
 




int main(int argc, char** argv) {
    fast_io
   
	
	int w, h, x, y, r;
	cin >> w >> h >> x >> y >> r;
	
	if(x - r >= 0 && y - r >= 0 && x + r <= w && y + r <= h) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	

    return 0;
}























Measured memory_bytes: 3216
package main

import "fmt"

func kaibun(str string) bool {
	l := len(str)
	for i := 0; i < l/2; i++ {
		if str[i] != str[l-i-1] {
			return false
		}
	}
	return true
}

func main() {
	var str string
	fmt.Scan(&str)

	l := len(str)
	if kaibun(str) && kaibun(str[0:(l-1)/2]) && kaibun(str[(l+3)/2-1:]) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
s = list(input())

thresh_1 = int((len(s) - 1) / 2)
thresh_2 = int((len(s) + 3) / 2)

s_1 = s[:thresh_1]
s_2 = s[thresh_2 - 1:]

if s == s[::-1] and s_1 == s_1[::-1] and s_2 == s_2[::-1]:
    print('Yes')
else:
    print('No')


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

#define pb push_back
#define mp make_pair
#define st first
#define nd second
typedef pair < int , int > pp;
const int mod = 1e9 + 7;
const int N   = 1e5 + 5;

long long a,b,ans;

int main(){
    cin >> a >> b;
    for(; a <= b; ans++) a *= 2;
    cout << ans;
    return 0;
}

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

int main(){

	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  	
  	ll n,k;
  	cin >> n >> k;
  	n = n%k;
  	ll ans = min(n,abs(k-n));

    cout << ans << endl;

	return 0;
}

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

int main(){

    string s;
    int length;
    int dislen;
    string divide[4] = {"dream", "dreamer", "erase", "eraser"};
    
    cin >> s;

    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; // 4個の文字列たちどれかでdivideできるか
        for(int j=0; j < 4; j++){
            string d = divide[j];
            if(s.substr(i, d.size()) == d){
                can2 = true;
                i += d.size();
            }
        }
        if(!can2){
            can = false;
            break;
        }
    }

    if(can) cout << "YES" << endl;
    else cout << "NO" << endl;

}

Measured memory_bytes: 3716
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
#include <math.h>
#include <utility>
#include <map>
#include <queue>
#include <stack>

using namespace std;

#define INF 210000000
#define int long long

int gcd(int a, int b) {
  int amari = a % b;
  int c = b;
  if (amari == 0) {
    return b;
  } else {
    return gcd(b, amari);
  }
}

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

signed main() {
    int h,w;
    cin >> h >> w;
    int a,b;
    cin >> a >> b;
    cout << (h-a) * (w-b);
}



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

int main(){
	int i,j;
	i=0; j=0;
	for(i=0;i<9;i++){
		for(j=0;j<9;j++){
			cout<<(i+1)<<"x"<<(j+1)<<"="<<(i+1)*(j+1)<<endl;
		}
	}
    return 0;
}

Measured memory_bytes: 1116
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        String w1=sc.nextLine();
        String w2=sc.nextLine();
        for(int i=0;i<3;i++){
            if(w1.charAt(i)!=w2.charAt(2-i)){
                System.out.println("NO");
                break;
            }
            if(i==2)System.out.println("YES");
        }
    }
}


Measured memory_bytes: 21844
// https://atcoder.jp/contests/abc073/tasks/abc073_a

#include <iostream>
using namespace std;

int main()
{
  /* Magic word */
  cin.tie(0);
  ios::sync_with_stdio(false);
  /* ---------- */

  int n;
  string r;

  cin >> n;

  r = (int)(n / 10) == 9 || n % 10 == 9 ? "Yes" : "No";

  cout << r << '\n';

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define N 100010
#define ll long long
int main()
{
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll ans = max(max(max(a*c,a*d),b*c),b*d);
    cout<<ans;  
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printInt(a) printf("%d\n", a)
#define printll(a) printf("%lld\n", a)
#define printYes() printf("Yes\n")
#define printNo() printf("No\n")
#define scanll(a) scanf("%lld", &a)
#define scanInt(a) scanf("%d", &a)
#define scan2Int(a, b) scanf("%d %d", &a, &b)
#define scan3Int(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define scan4Int(a, b, c, d) scanf("%d %d %d %d", &a, &b, &c, &d)
typedef long long ll;
const int INF = 1001001001;
using namespace std;

int main() {
    int x, n;
    scan2Int(x,n);
    int p[n];
    rep(i, n) cin >> p[i];
    int min = INF;
    int tmp, ans = x;
    bool flag;
    for (int i = -1; i < 102; ++i) {
        flag = false;
        rep(j, n) {
            if (i == p[j]) {
                flag = true;
                break;
            }
        }
        if (flag) continue;
        tmp = x - i;
        tmp = abs(tmp);
        if (min > tmp) {
            min = tmp;
            ans = i;
        }
    }
    printInt(ans);
    return 0;
}


Measured memory_bytes: 3824
#include <stdio.h>
 
int main (void)
{
  int h , w;
  scanf("%d %d",&h,&w);
  
  char s[h+1][w+1];
  int ans[52][52] = {0};
  for(int i = 0;i < h;i ++){
    scanf("%s",s[i]);
  }
  
  
 
  
  
for(int i = 0;i < h;i++){
  for(int j = 0;j < w;j ++){
    if( s[i][j]== '#'){
      if(i-1>=0&&j-1>=0)
      ans[i-1][j-1]+=1;
      if(i-1>=0)
      ans[i-1][j]+=1;
      if(i-1>=0&&j+1<w)
      ans[i-1][j+1]+=1;
      if(j-1>=0)
      ans[i][j-1]++;
      if(j+1<w)
      ans[i][j+1]++;
      if(i+1<h&&j-1>=0)
      ans[i+1][j-1]++;
      if(i+1<h)
      ans[i+1][j]++;
      if(i+1<h&&j+1<w)
      ans[i+1][j+1]++;
     }
  }
}
  for(int i = 0;i < h;i ++){
    for(int j = 0;j < w;j++){
      if(s[i][j]=='#'){
        putchar('#');
      }
      else{
      printf("%d",ans[i][j]);
    }
    }
    putchar('\n');
  }
  
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
    using namespace std;
    int power(int n,int t){
      int x=1;
      for(int i=0;i<t;i++){
        x*=n;
      }
      return x;
    }
    int main() {
      int n ;
      cin >> n;
      int sum=0;
      for(int i=0;i<9;i++){
        sum+=(n % power(10,i+1) - n % power(10,i))/power(10,i);
      }
      if(n%sum==0)
        cout << "Yes" << endl;
      else
        cout << "No" << endl;
    }

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

#define _int64 long long
vector<pair<int,int> > ans;

void doit(int x1,int y1,int mul,int x2,int y2,int d1){
	
	int i,j;
	if(d1%4==0){
		doit(x1,y1,mul*2,x2,y2,d1/4);
		doit(x1,y1+mul,mul*2,x2,y2,d1/4);
		doit(x1+mul,y1,mul*2,x2,y2,d1/4);
		doit(x1+mul,y1+mul,mul*2,x2,y2,d1/4);
	}
	else{
		if(d1%4==1){
			for(i=x1;i<x2;i+=mul*2)
			for(j=y1;j<y2;j+=mul*2)
			ans.push_back(make_pair(i,j));
			for(i=x1+mul;i<x2;i+=mul*2)
			for(j=y1+mul;j<y2;j+=mul*2)
			ans.push_back(make_pair(i,j));
		}
		else{
			for(i=x1;i<x2;i+=mul*2)
			for(j=y1;j<y2;j+=mul*2)
			ans.push_back(make_pair(i,j));
			for(i=x1;i<x2;i+=mul*2)
			for(j=y1+mul;j<y2;j+=mul*2)
			ans.push_back(make_pair(i,j));
		}
	}
}

void doit(int x1,int y1,int mul,int x2,int y2,int d1,int d2)
{
	int i,j;
	if((d1%4!=0)&&(d2%4==0))swap(d1,d2);
	if(d1%4==0){
		if(d2%4==0){
			doit(x1,y1,mul*2,x2,y2,d1/4,d2/4);
			doit(x1+mul,y1,mul*2,x2,y2,d1/4,d2/4);
			doit(x1,y1+mul,mul*2,x2,y2,d1/4,d2/4);
			doit(x1+mul,y1+mul,mul*2,x2,y2,d1/4,d2/4);
		}
		else{
			if(d2%4==1){
			doit(x1,y1,mul*2,x2,y2,d1/4);
			doit(x1+mul,y1+mul,mul*2,x2,y2,d1/4);
			}
			else{
			doit(x1,y1,mul*2,x2,y2,d1/4);
			doit(x1,y1+mul,mul*2,x2,y2,d1/4);
			}
		}
	}
	else{
		for(i=x1;i<x2;i+=mul*2)
		for(j=y1;j<y2;j+=mul*2)
		ans.push_back(make_pair(i,j));
	}
}

int main()
{
	int n,d1,d2;
	scanf("%d%d%d",&n,&d1,&d2);
	ans.clear();
	doit(0,0,1,n+n,n+n,d1,d2);
	for(int i=0;i<n*n;++i)
	printf("%d %d\n",ans[i].first,ans[i].second);
	return 0;
}

Measured memory_bytes: 1908
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  string s;
  cin >> s;
  int cnt = 0;
  for(char c:s) {
    cnt += c-'0';
  }
  if(cnt%9==0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3736
#include <cstdio>
#include <algorithm>

using namespace std;


int main(){
    int H1,M1,H2,M2,K;
    scanf("%d%d%d%d%d",&H1,&M1,&H2,&M2,&K);

    auto ans=max((H2*60+M2-H1*60-M1-K),0);

    printf("%d\n",ans);

    return 0;
}

Measured memory_bytes: 1732