akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define DEBUG
#define PI 3.141592653589793238462643383279
 
#define _GLIBCXX_DEBUG
#ifdef DEBUG
#define s(...) show(__VA_ARGS__);
#define sl(...) show(__VA_ARGS__);cout<<endl;
#else
#define s(...)
#define sl(...)
#endif
void show() {}
template <class Head,class... Args>void show(Head t,Args... args){std::cout<<t<<" ";show(args...);}
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define REP1(i, n) for(ll i = 1; i <= n; i++)
#define REPR1(i, n) for(ll i = n; i >= 1; i--)
#define FOR1(i, m, n) for(ll i = m; i <= n; i++)
const ll INF = LLONG_MAX;
const ull MOD = 1000000007;
#define VEC(type,A,N) vector<type> A(N)
#define VECi(type,A,N,i) vector<type> A(N,i)
#define VEC2(type,A,N,M) vector<vector<type>> A(N,vector<type>(M))
#define VEC2i(type,A,N,M,i) vector<vector<type>> A(N,vector<type>(M,i))
#define ALL(v) v.begin(), v.end()
ll frac(ll k){
    int s = 1;
    for (ll i=1; i<=k; ++i)s *= i;
    return s;
}
ll gcd(ll a, ll b){
   if (a%b==0)return(b);
   else return(gcd(b, a%b));
}
ll lcm(ll a,ll b){
    return a*b/gcd(a,b);
}
ll antidiv(ll N,ll C,ll D){
    return N-floor(N/C)-floor(N/D)+floor(N/lcm(C,D));
}
vector<ll> yakusuu(ll N){
    vector<ll> ret;
    for (ll i = 1; i * i <= N; i++) {
        if (N % i == 0) {
            ret.push_back(i);
            if (i * i != N) ret.push_back(N / i);
        }
    }
    sort(ret.begin(), ret.end());
    return ret;
}
ll digitPoor(ll n)
{
    assert(INT_MAX == 2147483647);
    assert(n >= 0);

    if (n < 10)         return 1;
    if (n < 100)        return 2;
    if (n < 1000)       return 3;
    if (n < 10000)      return 4;
    if (n < 100000)     return 5;
    if (n < 1000000)    return 6;
    if (n < 10000000)   return 7;
    if (n < 100000000)  return 8;
    if (n < 1000000000) return 9;
    return 10;
}
struct p{
  ll x;
  bool b;
};
int main(){
    ll X;
    cin>>X;
    
    vector<pair<ll,ll>> m(X);
    REP1(i,X){
        ll t;
        cin>>t;
        m[i-1].first=t;
        m[i-1].second=i;
    }
    
    sort(ALL(m),[](auto a,auto b){return a<b;});
    ll t1=m[X/2-1].first;
    ll t2=m[X/2].first;
    VEC(ll,q,X+1);
    REP(i,X){
        q[m[i].second]=i+1;
    }
    REP1(i,X){
        if(q[i]>X/2){
            cout<<t1<<endl;
        }else{
            cout<<t2<<endl;
        }
    }
    
    //cout<<fixed<<setprecision(32)<<m;
    //sort(ALL(C),[](auto& a, auto& b) {return a[2] < b[2];});
    //if(equal(D.begin(), D.end()-1, K.begin()))cout<<"Yes";else cout<<"No";
    cout<<endl;
    return 0;
}


Measured memory_bytes: 7940
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;

int main() {
    string S;
    ll K;
    cin >> S >> K;
    int count = 0;

    for(int i=0; i<S.size(); i++) {
        if(S[i] == '1') count++;
        if(count == K) {
            cout << 1 << endl;
            return 0;
        }
        if(S[i] != '1') {
            cout << S[i] << endl;
            return 0;
        }
    }
}

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

int main()
{
  int n;
  cin >> n;
  
  int temp, ans = 0, min = 1000000;
  for(int i = 0; i < n; i++){
    cin >> temp;
    if(min >= temp){
      min = temp;
      ans++;
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

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

int main(){
  long long A, B, C, X, Y;
  cin>>A>>B>>C>>X>>Y;
  if(A+B<=2*C) cout<<A*X+B*Y<<endl;
  else{
    if(X>=Y){
      long long price1=2*C*Y+A*(X-Y);
      long long price2=2*C*X;
      cout<<min(price1, price2)<<endl;
    }
    if(X<Y){
      long long price1=2*C*X+B*(Y-X);
      long long price2=2*C*Y;
      cout<<min(price1, price2)<<endl;
    }
  } //else
}
 


Measured memory_bytes: 256
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#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>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
//#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
//const int INF = 1<<29;
//const int MODINF = 1000000007;
using namespace std;

int main(){
    int L, R, d;
    cin >> L >> R >> d;
    int count = 0;
    rep(i, L, R + 1){
        if (i % d == 0) count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 3588
S = list(set(list(input())))
S.sort()
al = 'abcdefghijklmnopqrstuvwxyz'
if len(S)==26:
  ans = 'None'
else:
  for i in range(len(S)):
    if al[i] != S[i]:
      ans = al[i]
      break
    else:
      ans = al[len(S)]
print(ans)

Measured memory_bytes: 3956
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/




int N, A[101010];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    rep(i, 1, N + 1) cin >> A[i];

    int cur = 1;
    rep(i, 0, 101010) {
        cur = A[cur];
        if (cur == 2) {
            printf("%d\n", i + 1);
            return;
        }
    }
    printf("-1\n");
}

Measured memory_bytes: 640
N,_=gets.chomp.split(' ').map{|n| n.to_i}
A=gets.chomp.split(' ').map{|n| n.to_i}
del = A.size - A.uniq.size
if(del%2==0)
	puts A.size-del
else
	puts A.size-del-1
end




Measured memory_bytes: 15876
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<iomanip>

using namespace std;


int main()
{
	long long a, b;
	cin >> a >> b;
	if ((a + b) % 2 == 0)
		cout << (a + b) / 2;
	else
		cout << "IMPOSSIBLE";

}

Measured memory_bytes: 256
//#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()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

struct UnionFind {
    vector<int> par; // 親を指すvector,-par[親]は木のサイズ
    UnionFind(int n):par(n, -1) {} // 自分で親を埋め込んでいく必要あり
    int root(int x) { // 親をたどる&データの整理
        if(par[x] < 0) return x;
        return par[x] = root(par[x]);
    }
    bool unite(int x, int y) { // データの結合
        x = root(x);
        y = root(y);
        if(x == y) return false;
        if(par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    bool same(int x, int y) {return root(x) == root(y);} // 所属判定
    int size(int x) {return -par[root(x)];} // 木のサイズ
} uft(100000);

int main() {
    int n, m;
    cin >> n >> m;
    vi L(m+1, -1);
    rep(i, n) {
        int k;
        cin >> k;
        vi l(k);
        rep(j, k) {
            cin >> l[j];
        }
        rep(j, k) {
            if(L[l[j]] == -1) {
                L[l[j]] = i;
            } else {
                uft.unite(L[l[j]], i);
            }
        }
    }

    cout << (uft.size(0) == n ? "YES":"NO") << endl;
}

Measured memory_bytes: 1024
#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

// -----------------------------------------------
// Framework <https://github.com/vain0x/procon>
// -----------------------------------------------

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let N = read!(usize);
    let (T, A) = read!(f64, f64);
    let H = read!([f64]);

    let mut mi = N;
    let mut mi_d = 1e9;
    for i in 0..N {
        let d = ((T - H[i] * 0.006) - A).abs();

        if mi == N || d < mi_d {
            mi = i;
            mi_d = d;
        }
    }

    println!("{}", 1 + mi)
}


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

// Structured Programming

void call (int n){
	int x;

	for(int i = 1; i <= n; i++){
		x = i;
		if( x % 3 == 0){
			cout << " " << i;
		}else{
			while(1){
				if( x % 10 == 3){
					cout << " " << i;
					break;
				}

				x /= 10;
				if(x == 0) break;
			}
		}
	}
	cout << endl;
}

int main(){
	int n;
	cin >> n;
	call(n);
}


Measured memory_bytes: 3136
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
using namespace std;
using ll = long long;



int main() {
	int n;
	cin >> n;
	if (n == 1) cout << "Hello World" << endl;
	else if (n == 2) {
		int a, b;
		cin >> a >> b;
		cout << a + b << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++) 
#define rrep(i,n) for(int i = 1; i <= (int)(n); i++)
#define pb push_back
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    int n,k;
    cin >> n >> k;
    vector<double> p(n);
    rep(i,n) cin >> p[i];
    rep(i,n) {
        p[i] /= 2;
        p[i] += 0.5;
    }
    double ans = 0;
    double counter = 0;
    rep(i,k) counter += p[i];
    ans = counter;
    //cout << counter << endl;
    for(int i = 1; i <= n-k-1; i++) {
        counter -= p[i-1];
        counter += p[i+k-1];
        //cout << counter << endl;
        ans = max(ans,counter);
    }
    double counter2 = 0;
    for(int i = n-k; i <= n-1; i++) counter2 += p[i];
    //cout << counter2 << endl;
    ans = max(ans,counter2);
    cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define MAXN 200100
#define pii pair<int,int>
#define ff first
#define ss second
#define ll long long
#define in_range(x, y, n) (x >= 0 and x<n and y >=0 and y<n)
using namespace std;
const ll mod = 1e9 + 7;
map<ll, ll> dp;

ll solve(ll x){
    if (dp[x]) return dp[x];
    return dp[x] = (solve(x/2LL) + solve((x-1LL)/2LL) + solve((x-2LL)/2LL))%mod;
}

int main (){
    ios_base::sync_with_stdio(false);
    ll n;
    cin >> n;

    dp[0] = 1;
    dp[1] = 2;

    cout << solve(n) << endl;
    return 0;
}

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

using namespace std;

void Main() {
    int a, b, c;
    cin >> a >> b >> c;

    set<int> p;
    p.insert(a);
    p.insert(b);
    p.insert(c);
    cout << p.size() << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;

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 long long INF = 1LL << 60;

//bucket1
// bool ch[10] = {0};
// bool check(int n){
//     while(n!=0){
//         if(ch[n%10]) return false;
//         n /= 10;
//     }
//     return true;
// }



// --------write my code!!!!!----------//


int main(){
    int res=3;
    string a,b,c; cin >> a >> b >> c;
    if(a==b) res--;
    if(b==c) res--;
    if(c==a) res--;
    if(res==0) res=1;
    cout << res <<endl;
} 


Measured memory_bytes: 256
#include <stdio.h>

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

int main()
{
	int A, B;
	scanf("%d %d", &A, &B);
	printf("%lld\n", (long long)A * B / gcd(A, B));
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1732
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>



int main() {
  long long num;
  scanf("%lld", &num);
  printf("%lld", (num / 500) * 1000 + (num % 500) / 5 * 5);
  /*
  char m[20];
  scanf("%s", m);
  if (m[2] == m[3] && m[4] == m[5]) {
    printf("Yes");
  }
  else {
    printf("No");
  }
  */
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <iomanip>

class Point{
public:
	int x, y;
	Point(int ax = 0, int ay = 0):x(ax),y(ay){};
};

int sub_area(const Point &p1, const Point &p2){
	return (p1.x - p2.x) * (p1.y + p2.y);
}
bool judge(const Point &p1, const Point &p2, const Point &p3){
	return (p1.x * p3.y + p2.x * p1.y + p3.x * p2.y) <= (p1.x * p2.y + p2.x * p3.y + p3.x * p1.y);
}
bool fold(std::vector<Point> vec){
	bool flag = true;
	for (auto i = 0; i < vec.size() and flag; ++i){
		flag = flag && judge(vec.at((i - 1) % vec.size()), vec.at(i % vec.size()), vec.at((i + 1) % vec.size()));
	}
	return flag;
}
int main(){
	int n;
	std::cin >> n;
	std::vector<Point> vec;
	for (auto i = 0; i < n; ++i){
		int x, y;
		std::cin >> x >> y;
		vec.push_back(Point(x, y));
	}
	if (fold(vec)){
		std::cout << 1 << std::endl;
	}else{
		std::cout << 0 << std::endl;
	}
}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> p(n);
  for (auto &e : p) {
    cin >> e;
    e--;
  }
  vector<vector<int>> v(n);
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  vector<set<int>> a(n), b(n);
  vector<bool> used(n);
  for (int i = 0; i < n; i++) {
    if (!used[i]) {
      used[i] = true;
      queue<int> q;
      q.push(i);
      a[i].insert(i);
      b[i].insert(p[i]);
      while (!q.empty()) {
        int f = q.front();
        q.pop();
        for (auto e : v[f]) {
          if (!used[e]) {
            used[e] = true;
            q.push(e);
            a[i].insert(e);
            b[i].insert(p[e]);
          }
        }
      }
    }
  }
  int r = 0;
  for (int i = 0; i < n; i++) {
    for (auto e : a[i]) {
      r += b[i].count(e);
    }
  }
  cout << r << endl;
  return 0;
}


Measured memory_bytes: 24832
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for(auto&& i : a){
        cin >> i;
    }
    for(auto&& i : b){
        cin >> i;
    }
    vector<int> c(n);
    for(int i = 0; i < n; i++){
        c[i] = a[i] - b[i];
    }
    sort(begin(c), end(c));
    if(accumulate(begin(c), end(c), 0ll) < 0){
        cout << "-1\n";
        return 0;
    }
    c.push_back(0);
    int ans = 0, ep = n;
    for(int i = 0; c[i] < 0; i++){
        ans++;
        while(c[i] < 0){
            if(c[ep] == 0){
                ans++;
                ep--;
            }
            int addscore = min(-c[i], c[ep]);
            c[i] += addscore;
            c[ep] -= addscore;
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <iomanip>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
typedef map<int, int> mii;
typedef set<int> si;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
// #define endl '\n';
#define fi first
#define se second
#define NONVOID [[nodiscard]]
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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> inline void dump(T &v){irep(i, v){cout<<*i<<((i==--v.end())?'\n':' ');}}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;


int main() {
    
    int k;
    ll ans=0;
    cin>>k;
    for(int i=1;i<=k;i++){
        for(int j=1;j<=k;j++){
            for(int l=1;l<=k;l++){
                ans+=gcd(gcd(i,j),l);
            }    
        }   
    }
    fin(ans);
}




Measured memory_bytes: 3636
h,w,k = gets.chomp.split.map &:to_i
masu = []

h.times do |i|
  masu[i] = gets.chomp.split('')
end

ans = 0

h_bit = [0,1].repeated_permutation(h)
w_bit = [0,1].repeated_permutation(w)

h_bit.each do |gyo|
  w_bit.each do |retsu|
    masu_tmp = Marshal.load(Marshal.dump(masu))
    gyo.each_with_index do |v, i|
      if v == 1
        masu_tmp[i] = masu_tmp[i].fill('.')
      end
    end
    retsu.each_with_index do |v, i|
      if v == 1
        h.times do |j|
          masu_tmp[j][i] = '.'
        end
      end
    end
    if masu_tmp.flatten.count('#') == k
      ans += 1
    end
  end
end

p ans


Measured memory_bytes: 14392
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<stack>
#include<queue>
#include<cmath>
#include<list>
#include<cstdint>
#include<vector>
#include<map>
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;

unsigned long long int a = 0, b = 0, c = 1, x = 0, y = 0, z = 0, maxy = -1, mini = 9999, counter = 0,startp=0,endp=0,checker=0;
std::vector<unsigned long long int> vec{}, vecsec{};
int iremono[100001];
std::vector<long long int>kinds{}, ans{}, kaku{};
char moji,moji2;
bool okada = false,okada2=false;
std::string output, output2, input, one, two;
char cutcount[201];
int kakunou2[50][50] = {};
unsigned long long int M, A, R, C, H;

int ctoi(const char c) {
	if ('0' <= c && c <= '9') return (c - '0');
	return -1;
}
unsigned long long int LCM(unsigned long long int a, unsigned long long int b) {
	unsigned long long int i, j;
	i = a; j = b;
	while (true) {

		c = i % j;
		i = j;
		if (c != 0) {

			j = c;

		}
		else {
			break;
		}
	}
	return j * (a / j) * (b / j);
}
int main()
{

	cin >>a>>b;
	if (b%a == 0) {
		cout << a + b << endl;
	}
	else {
		cout << b - a << endl;
	}

}

	
	





Measured memory_bytes: 764
#include <bits/stdc++.h>
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0)
#define MAX_V 200005

using namespace std;

int p[MAX_V], s[MAX_V], v[MAX_V];

//GCD rapido
int gcd(int a, int b)
{
    while (b) b ^= a ^= b ^= a %= b;
    return a;
}

int main()
{
    FAST_IO;
    int n;
    scanf("%d", &n);
    scanf("%d", v+0);

    //Le o primeiro numero
    p[0] = v[0];

    //Le os demais numeros acumulando o GCD da esquerda pra direita (p)refix
    for (int i = 1; i < n; i++) {
        scanf("%d", v+i);
        p[i] = gcd(v[i], p[i-1]);
    }

    //Acumula GCD da direita pra esquerda (s)uffix
    s[n-1] = v[n-1];
    for (int i = n-2; i >= 0; i--)
        s[i] = gcd(v[i], s[i+1]);

    //Calcula o GCD de todos os numeros menos o i-esimo.
    //Faz-se isso calculando o gcd do prefixo até i-1 com o sufixo até i+1
    int ans = max(s[1], p[n-2]);
    for (int i = 1; i < n - 1; i++)
        ans = max(gcd(p[i-1], s[i+1]), ans);

    //A resposta será o maior gcd encontrado. Na pratica esta sendo substituido um numero pelo proprio gcd
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    int N;
    string S;
    cin >> N >> S;
    int count = 0;
    if (N%2 == 0){
        for (int i = 0; i < N/2; i++)
        {
        if (S[i] == S[N/2+i])
            {
                count++;  
            }
        }
    }
    string Answer;
    if (count == N/2-N%2){
        Answer = "Yes";
    }else{
        Answer = "No";
    }
    cout << Answer;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<queue>
#include<functional>
#include<iso646.h>
#include<bitset>

#ifndef M_PI
#define M_PI 3.14159265358979
#endif
#define deg_to_rad(deg) (((deg)/360)*2*M_PI)
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;

const ll INF = 1e15;
const ll MOD = 1e9 + 7;

int main() {
	ll x, y, z;
	cin >> x >> y >> z;
	cout << z << " " << x << " " << y << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n;
	cin>>n;
	map<ll,ll>a,b;
	ll maxa=0,maxb=0;
	ll nowa=-1,nowb=-1;
	for(ll i=0;i<n;i++){
		ll now;
		cin>>now;
		if(i%2==1){
			a[now]++;
			if(maxa<=a[now]){
				nowa=now;
				maxa=a[now];				
			}
		}
		else{
			b[now]++;
			if(maxb<=b[now]){
				nowb=now;
				maxb=b[now];				
			}
		}
	}
	if(nowa!=nowb){
		cout << n-maxa-maxb;
//		cout << 0;
	}
	else{
		ll ans=inf;
		ll cnt=0;
		for(auto itr=a.begin();itr!=a.end();itr++){
			ll val=itr->second;
			ll num=itr->first;
			if(val>=cnt&&num!=nowb){
				cnt=val;
			}
		}
		ans=min(ans,n-cnt-maxb);
	//	cout <<ans<<cnt<<nowb<<nowa<<endl;
		cnt=0;
		for(auto itr=b.begin();itr!=b.end();itr++){
			ll val=itr->second;
			ll num=itr->first;
			if(val>=cnt&&num!=nowa){
				cnt=val;
			}
		}
		ans=min(ans,n-cnt-maxa);
		cout <<ans;
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 6528
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int main(){
	int i=1,c,sum=0,num=0,count=0;
	int *a;
	
	scanf("%d",&num);
	c=num;
	while(c!=0){
		i=c%10;
		c=c/10;
		sum=sum+i;
	}
	
	if(num%sum==0){
		printf("Yes");
	}else{
		printf("No");
	}
	
	
	return 0;
	
}



Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <deque>
#include <list>
#include <sys/timeb.h>
#include <fstream>
#include <set>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;


bool pairCompare(const Pi& firstElof, const Pi& secondElof)
{
	return firstElof.second > secondElof.second;
}

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

	int n;
	cin >> n;

	double ans = 0;
	rep(i, n) {
		double x;
		string u;
		cin >> x >> u;
		if (u == "JPY") {
			ans += x;
		}
		else {
			ans += x * 380000;
		}
	}

	cout << ans << endl;
	
	

	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

#define N 500000

int A[N];
int n;

int parent(int);
int left(int);
int right(int);
void maxHeapify(int);
void buildMaxHeap();

int main(){

  int i;

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

  buildMaxHeap();

  for(i=0;i<n;i++){
    printf(" %d",A[i]);
  }printf("\n");
  
  return 0;
}


int parent(int i){
  return (i+1)/2-1;
}

int left(int i){
  return 2*(i+1)-1;
}

int right(int i){
  return 2*(i+1);
}

void maxHeapify(int i){
  int l = left(i);
  int r = right(i);
  int largest,key;
  
  if(l<n && A[l]>A[i]){
    largest = l;
  }else{
    largest = i;
  }
  if(r<n && A[r]>A[largest]){
    largest = r;
  }

  if(largest!=i){
    key = A[largest];
    A[largest] = A[i];
    A[i] = key;   
    maxHeapify(largest);
  } 
}

void buildMaxHeap(){
  int i;
  for(i=n/2-1;i>=0;i--){
    maxHeapify(i);
  }
  
}

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

int main(){
  ll a,b;cin >> a >> b;
  ll ab = a*b;
  if(a<b){
    swap(a,b);
  }
  while(a%b!=0){
    ll temp=b;
    b = a%b;
    a = temp;
  }
  cout << ab/b << endl;
}

Measured memory_bytes: 256
#16D8101014F KurumeRyunosuke 2018/6/20

n=int(input())
ls=[[0 for i in range(n)]for j in range(n)]
for i in range(n):
	tmp=input().split()
	for j in range(int(tmp[1])):
		ls[i][int(tmp[j+2])-1]=1

"""
for i in range(n):
    for j in range(n):
        if(j!=n-1):
            print(int(ls[i][j]), end=' ')
        else:
            print(int(ls[i][j]))
"""
stuck=[0]
count=1
d=[0 for i in range(n)]
f=[0 for i in range(n)]
d[0]=count
for i in range(n):
	ls[i][0]=0

while True:
	count+=1
	p=0
	#print("S",d)
	for i in range(n):
		if ls[stuck[len(stuck)-1]][i] is not 0:
			ls[stuck[len(stuck)-1]][i]=0
			p=1
			#print(stuck)
			stuck.append(i)
			d[stuck[len(stuck)-1]]=count
			break
	#print(d,"**")
	if p is 1:
		for i in range(n):
			ls[i][stuck[len(stuck)-1]]=0

	if p is 0:
		#print("//",count)
		a=stuck.pop()
		f[a]=count
		for i in range(n):
			ls[a][i]=0
	#print(d,"¥¥¥")
	if len(stuck) is 0:
		t=0
		for i in range(n):
			for j in range(n):
				if ls[i][j] is not 0 and t is 0:
					count+=1
					stuck.append(i)
					d[stuck[len(stuck)-1]]=count
					#print(i,"***")
					t=1
					
		if t is 0:
			break
		#print("break")
	#print("G",d,f,count)

for i in range(n):
	print(i+1,d[i],f[i])



Measured memory_bytes: 5736
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
var dice=Arr[0].split(" ").map(Number);
var nsew=Arr[1].split("");

function move(x,arr){
var d1=arr[0];
var d2=arr[1];
var d3=arr[2];
var d4=arr[3];
var d5=arr[4];
var d6=arr[5];
var after=[];
if(x=="N")after=[d2,d6,d3,d4,d1,d5];
if(x=="S")after=[d5,d1,d3,d4,d6,d2];
if(x=="E")after=[d4,d2,d1,d6,d5,d3];
if(x=="W")after=[d3,d2,d6,d1,d5,d4];
return after;
}

nsew.forEach(function(v){
dice=move(v,dice);
});

console.log(dice[0]);

Measured memory_bytes: 7648
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i;
    cin>>n;
    int ar[n+1],arr[n+1];
    for(i=1;i<=n;i++){
        cin>>ar[i];
    }
    for(i=1;i<=n;i++){
        arr[ar[i]]=i;
    }
    for(i=1;i<=n;i++){
        cout<<arr[i]<<" ";
    }
return 0;
}






Measured memory_bytes: 1536
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define pb push_back
#define mk make_pair
#define mod 1000000007
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define prec(y,x) fixed<<setprecision(y)<<x
#define inf 1e18
#define pi 3.1415926535
typedef tree<int, null_type, less<int>, rb_tree_tag,                    //if using ll change int to ll
        tree_order_statistics_node_update> pbset;
#define fob(x) find_by_order(x)
#define ook(x) order_of_key(x)
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
	string s,t;
	cin>>s>>t;int f=0;
	
	for(int i=0;i<s.size();i++)
	{
	    if(s[i]!=t[i])
	    {
	        f=1;break;
	       
	    }
	}
	if(f==1)
	cout<<"No";
	else 
	cout<<"Yes";
	
	return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> sub(N);
  int boss;
  for (int i = 0; i < N - 1; i++){
    cin >> boss;
    sub[boss - 1]++;
  }
  for (int i = 0; i < N; i++){
    cout << sub[i] << endl;
  }
}


Measured memory_bytes: 3996
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int64_t, int64_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t N;
  cin >> N;
  vector<int64_t> C(N - 1);
  vector<int64_t> S(N - 1);
  vector<int64_t> F(N - 1);
  for (int64_t i = 0; i <= N - 2; ++i) {
    cin >> C[i] >> S[i] >> F[i];
  }
  for (int64_t start = 0; start <= N - 2; ++start) {
    int64_t c_time = S[start];
    for (int64_t i = start; i <= N - 2; ++i) {
      if (c_time % F[i] == 0) {
        c_time = max(c_time, S[i]);
      } else {
        c_time = max(((c_time / F[i]) + 1) * F[i], S[i]);
      }
      c_time += C[i];
    }
    cout << c_time << endl;
  }
  cout << 0 << endl;

  return 0;
}


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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 60)

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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



int n, x[101], y[101], h[101];
void solve(){
	cin >> n;
	int I;
	for(int i = 0; i < n; i++){
		cin >> x[i] >> y[i] >> h[i];
		if(h[i] != 0) I = i;
	}
	
	for(int i = 0; i < 101; i++){
		for(int j = 0; j < 101; j++){
			bool ok = 1;
			int H = abs(x[I]-i)+abs(y[I]-j)+h[I];
			for(int k = 0; k < n; k++){
				if(h[k] == 0 && abs(x[k]-i)+abs(y[k]-j)>=H) continue;
				if(abs(x[k]-i)+abs(y[k]-j)+h[k] != H) ok = 0;
			}
			if(ok){
				cout << i << " " << j << " " << H << endl;
				return;
			}
		}
	}
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int64_t> a(n);
  rep(i,n){
    cin >> a.at(i);
  }
  int64_t h=0;
  rep(i,n){
    if(i==0)
      h=0;
    else
      if(a.at(i)<a.at(i-1)){
        h += a.at(i-1)-a.at(i);
        a.at(i) = a.at(i-1);
      }
  }
  
  cout << h << endl;
  return 0;
}

Measured memory_bytes: 4840
import math

def main():
    k = int(input())
    ans = 0
    for a in range(k):
        for b in range(k):
            for c in range(k):
                ans += math.gcd(math.gcd(a+1, b+1), c+1)
    print(ans)


if __name__ == '__main__':
    main()


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

typedef long long ll;
typedef int64_t i6;
typedef std::vector<std::vector<int64_t> > Graph;

#define rep(i, n) for (int64_t i = 0; i < n; ++i)
#define rep2(i, n) for (int64_t i = 1; i <= n; ++i)
#define ALL(v) (v).begin(), (v).end()
#define Sort(x) sort(ALL(x))
#define Sort_rev(x) Sort(x);reverse(ALL(x))
#define Push_back(p, a, b) (p).push_back( make_pair( (a), (b) ) )

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;  } return 0;  }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;  } return 0;  }
template<typename V,typename T> bool find_num(V v, T num) { if ( find(ALL(v), num) == v.end() ) { return false; } return true; }

// π M_PI
// deg = rad*180/M_PI

int main() {
    int64_t X, Y;
    cin >> X >> Y;
    int64_t a, b;
    a = (4*X-Y)/2;
    b = (Y-2*X)/2;
    // a = (4*X-Y);
    // b = (Y-2*X);

    int64_t ans = 0;
    /*
    if ( a == (int64_t)(4*X-Y)/2 && b == (Y-2*X)/2 ) {
    }*/
    if ( a >= 0 && b >= 0 && a+b == X && 2*a+4*b == Y ) {
        // cout << a << " " << b << endl;
        ans = 1;
    }
    cout << ( ans ? "Yes" : "No" ) << endl;
    return 0;
}


Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
	    Scanner scanner = new Scanner(System.in);
	    String alphabet = "abcdefghijklmnopqrstuvwxyz";

	    long N = Long.parseLong(scanner.next());
        StringBuilder sb = new StringBuilder();
	    int z = 1;
	    while(true) {
	    	double sum = Main.getValue(z);
	        if (N <= sum) {
	            for (int i = 0; i < z; i++) {
	                int index = (int)(N % 26);
	                if (index > 0) {
	                    sb.insert(0, alphabet.charAt(index - 1));
	                    N -= index - 1;
	                } else {
	                	sb.insert(0, alphabet.charAt(25));
	                	N -= 25;
	                }

	                N = N / 26;
	            }
	            break;
	        }
	        z++;
	    }

	    System.out.println(sb.toString());
	}

	public static double getValue(int z) {
	   double sum = 0;
		for (int i = 0; i < z; i++) {
		    sum += Math.pow(26, i+1);
		}
		return sum;
	}

}

Measured memory_bytes: 35760
using static System.Math;
using System;

public class hello
{
    public static void Main()
    {
        while (true)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == 0) break;
            getAns(n);
        }
    }
    static void getAns(int n)
    {
        var count = 0;
        var cmax = (int)Sqrt(n) + 1;
        for (int i = 0; i <= cmax; i++)
        {
            if (i * i > n) break;
            for (int j = i; j <= cmax; j++)
            {
                if (i * i + j * j > n) break;
                for (int k = j; k <= cmax; k++)
                {
                    if (i * i + j * j + k * k > n) break;
                    var w = n - i * i - j * j - k * k;
                    if (w >= 1)
                    {
                        var t = getRoot(w);
                        if (t != -1 && t >= k) count++;
                    }
                }
            }
        }
        Console.WriteLine(count);
    }
    static int getRoot(int a)
    {
        var t = (int)Sqrt(a);
        if (t * t == a) return t;
        if ((t + 1) * (t + 1) == a) return t + 1;
        else if ((t - 1) * (t - 1) == a) return t - 1;
        return -1;
    }
}


Measured memory_bytes: 13760
#include <iostream>
#include <algorithm>

using namespace std;
int partition(int* xs, int p, int r){
    int x = xs[r];
    int i = p-1;
    for(int j = p; j < r; ++j){
        if(xs[j] <= x){
            ++i;
            swap(xs[i], xs[j]);
        }
    }
    swap(xs[i+1], xs[r]);
    return i+1;
}

int main(){
    int n;
    cin >> n;
    int xs[n];
    for(int i = 0; i < n; ++i){
        scanf("%d", &xs[i]);
    }
    int idx = partition(xs, 0, n-1);
    for(int i = 0; i < idx; ++i){
        printf("%d ", xs[i]);
    }
    printf("[%d]", xs[idx]);
    for(int i = idx+1; i < n; ++i){
        printf(" %d", xs[i]);
    }
    cout << endl;
}

Measured memory_bytes: 1640
/*
	专 业 爆 搜
			--InterestingLSY 
*/
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define pb push_back
#define mp make_pair
#define INF 9999999
#define LINF 9999999999999999
#define SINF "%"
#define uint unsigned int
#define msn(a,v) memset(a,v,sizeof(a))
#define ms(a) msn(a,0)
#define NONE -1
#define ll long long
#define ull unsigned ll
#define uchar unsigned char
#define sint short int
#define usint unsigned sint
#define xsize(a) sizeof(a)/1024/1024
#define fr(aaaaa,bbbbb) for(aaaaa = 1;aaaaa <= bbbbb;aaaaa++)
#define frr(aaaaa,bbbbb,ccccc) for(aaaaa = ccccc;aaaaa <= bbbbb;aaaaa++)
using namespace std;
#define MAXN 100100

char s[MAXN];
int n;
string ss[5];
int lens[5];

bool kmp(int pos,int id){
	for(int i = 0;i < lens[id];i++){
		if(s[pos+i] != ss[id][i])
			return 0;
	}
	return 1;
}

bool dp[MAXN];
bool dfs(int pos){
	if(pos == n) return 1;
	bool ans = 0;
	for(int i = 1;i <= 4;i++)
		if(pos + i < n  &&  kmp(pos,i)){
			ans = dfs(pos + lens[i]);
			if(ans)
				return 1;
		}
	return 0;
}

int main(){
	//freopen("C.txt","r",stdin);
	ss[1] = "dream"; ss[2] = "dreamer";
	ss[3] = "erase"; ss[4] = "eraser";
	for(int i = 1;i <= 4;i++)
		lens[i] = ss[i].length();
	
	scanf("%s",&s);
	n = strlen(s);
	
	if(dfs(0)) printf("YES\n");
	else printf("NO\n");
	
	return 0;
}

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



int main() {
  string s, t;
  cin >> s >> t;
  int ss=s.size(), tt=t.size();
  int n=ss-tt+1;
  int ans = 1000000;
  rep(i, n){
    int cnt=0;
    string s1 = s.substr(i, tt);
    rep(j, tt){
      if(s1[j]!=t[j])cnt++;
    }
    ans = min(ans, cnt);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3628
/*************************************************************************
    > File Name: B.cpp
    > Author: HandsomeHow
    > Mail: handsomehowyxh@gmail.com 
    > Created Time: 2017/6/24 20:11:39
 ************************************************************************/

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

#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 pb push_back
#define mp make_pair
#define cl(a) memset((a),0,sizeof(a))
#ifdef HandsomeHow
#define dbg(x) cerr << #x << " = " << x << endl
#else
#define dbg(x)
#endif
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
const int inf=0x3f3f3f3f;
const double eps=1e-8;
const int mod=1000000007;
const double pi=acos(-1.0);
inline void gn(long long&x){
    int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');
    while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
ll gcd(ll a,ll b){return a? gcd(b%a,a):b;}
ll powmod(ll a,ll x,ll mod){ll t=1ll;while(x){if(x&1)t=t*a%mod;a=a*a%mod;x>>=1;}return t;}
// (づ°ω°)づe★------------------------------------------------
const int maxn = 1e5+5;
struct Point{
    int x, y,id;
    void read(){ gn(x);gn(y); }
}point[maxn];
int n;
bool cmp1(Point &a, Point &b){ return a.x < b.x; }
bool cmp2(Point &a, Point &b){ return a.y < b.y; }
bool in[maxn];
struct EDGE{
    int a, b, cost;
    EDGE(int x, int y, int z){ a = x, b = y, cost = z; }
};
vector<EDGE>edges;
int p[maxn];
int findf(int x){ return x==p[x]?x:p[x]=findf(p[x]); }
void merge(int x, int y){
    x = findf(x);y = findf(y);
    if(x!=y)p[x]=y;
}
bool cmp(EDGE &a, EDGE &b){ return a.cost < b.cost; }
ll calc(){
    ll ret = 0;
    sort(edges.begin(),edges.end(),cmp);
    int sz = edges.size();
    for(int i = 0; i < sz; ++i){
        int x = findf(edges[i].a);
        int y = findf(edges[i].b);
        if(x != y){
            merge(edges[i].a,edges[i].b);
            ret += edges[i].cost;
        }
    }
    return ret;
}

int main(){
#ifdef HandsomeHow
    //freopen("data.in","r",stdin);
    //freopen("data.out","w",stdout);
#endif
    gn(n);
    rep(i,1,n)p[i]=i;
    rep(i,1,n)point[i].read();
    rep(i,1,n)point[i].id=i;
    sort(point+1,point+1+n,cmp1);
    rep(i,2,n) edges.pb(EDGE(point[i].id,point[i-1].id,point[i].x-point[i-1].x));
    sort(point+1,point+1+n,cmp2);
    rep(i,2,n) edges.pb(EDGE(point[i].id,point[i-1].id,point[i].y-point[i-1].y));
    ll ans = calc();
    printf("%lld\n",ans);
    return 0;
}



Measured memory_bytes: 6516
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
const double PI = 3.1415926535897932;

/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}


int main()
{
	string S, T;
	cin >> S;
	cin >> T;

	int ans = 1e9;	// Large value
	for (int i = 0; i < S.size(); ++i) {
		if (T.size() + i > S.size()) break;

		int cnt = 0;
		for (int j = 0; j < T.size(); ++j) {
			if (S[i + j] != T[j]) cnt++;
		}
		
		ans = min(ans, cnt);
	}

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

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define ff first
#define ss second
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
#define all(x) x.begin(), x.end()

void solve() {
   ll a, b, c, d;
   cin >> a >> b >> c >> d;
   cout << max({b * d, a * c, a * d, c * b}) << '\n';
}

int main() {
#ifndef ONLINE_JUDGE
   freopen("C:\\inp.txt", "r", stdin);      freopen("C:\\outp.txt", "w", stdout);
#endif
   ios::sync_with_stdio(false);   cin.tie(NULL);   cout.tie(NULL);
   solve();

   return 0;
}

Measured memory_bytes: 3624
// AtCoder Beginner Contest 157 C.cpp

#include <iostream>
#include <vector>
#include <utility>

using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;
	vector<pair<int, int>>sc(m);
	vector<pair<bool, int>>z(n, pair<bool, int>(false, 0));

	for (int i = 0; i < m; i++) {
		cin >> sc[i].first >> sc[i].second;
		if (!z[sc[i].first - 1].first) {//もし既に指定されていない桁なら
			z[sc[i].first - 1].first = true;//真にして
			z[sc[i].first - 1].second = sc[i].second;//値を保持する
		}
		else if (z[sc[i].first - 1].second != sc[i].second)
			//既に指定されている桁で保持している値と今参照している値が違う場合
		{
			cout << -1 << endl;
			return 0;
		}
	}
	if (z[0].first && z.size() != 1 && z[0].second == 0) {
		//指定があって2桁以上で先頭が0のとき
		cout << -1 << endl;
		return 0;
	}
	if (z.size() != 1 && z[0].second == 0) {
		//指定がなくて2桁以上で先頭が0のとき
		z[0].second = 1;
	}
	for (int i = 0; i < n; i++) {
		cout << z[i].second;
	}
}

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


int main(){
  int N, Q;
  string S;
  cin >> N >> Q >> S;
  int len = S.size();
  vector<int> num_A(len+1);
  vector<int> num_C(len+1);
  for(int ii=1; ii<len; ii++){
    num_A[ii] = num_A[ii-1];
    num_C[ii+1] = num_C[ii];
    if(S[ii-1]=='A' && S[ii]=='C'){
      num_A[ii]++;
      num_C[ii+1]++;
    }
  }
  num_A[len] = num_A[len-1];
  for(int ii=0; ii<Q; ii++){
    int l, r;
    cin >> l >> r;
    cout << num_C[r] - num_A[l-1] << endl;
  }
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;
#define rep(i, n)  for (int i = 0; i <  (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(x) (x).begin(), (x).end()
const ll INF = ll(1e18)+1;

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

    ll N;
    cin >> N;
    vector<ll> Pi(N);
    rep(i,N){
        cin >> Pi[i];
    }

    ll result = 0;
    ll min_mem = INF;
    rep(i,N){
        if(min_mem < Pi[i]){}
        else{
            result++;
        }
        min_mem = min(min_mem,Pi[i]);
    }
    cout << result;
}

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

int main() {
    long long k;
    cin >> k;
    long long ans=0;
    for(int i=1;i<=k;i++){
        for(int j=1;j<=k;j++){
            for(int l=1;l<=k;l++){
                ans+=__gcd(i,__gcd(j,l));
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3656