akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main(void){

    int H,W;
    cin >> H >> W;
    char a[H][W];


    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cin >> a[i][j];
        }
    }

    int row[H] = {0};
    for(int i = 0; i < H; i++){
        int c = 0;
        for(int j = 0; j < W; j++){
            if(a[i][j] == '.'){
                c++;
            }
        }
        if(c==W) row[i]++;//row.push_back(i);
    }

    int col[W] = {0};
    for(int i = 0; i < W; i++){
        int d = 0;
        for(int j = 0; j < H; j++){
            if(a[j][i] == '.'){
                d++;
            }
        }
        if(d==H) col[i]++;
    }


    for(int i = 0; i < H; i++){
        if(row[i]) continue;

        for(int j = 0; j < W; j++){
            if(col[j]) continue;

            cout << a[i][j];
        }
        cout << endl;
    }

    return 0;
}

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

int main(void){
    long int a,b,v,w,t;
    bool flag = false;

    cin >> a >> v;
    cin >> b >> w;
    cin >> t;

    if(abs(b - a) <= (v - w) * t) {flag = true;}

    if(v < w) {flag = false;}

    if(flag == true) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

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

    int N, K;
    cin >> N >> K;
    cout << min(N % K, K - N % K) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int N=100010;
int A,B;
int main()
{
  cin>>A>>B;
  if(B%A==0) cout<<B+A<<endl;
  else cout<<(B-A)<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n,m;
  cin >> n >> m;
  cout << (1900*m+100*(n-m))*(1<<m) << endl;
}


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! invec {
    ( $t:ty ) => {{
        let mut s = String::new();
        match std::io::stdin().read_line(&mut s) {
            Ok(0) => Vec::<$t>::new(),
            Ok(n) => s.trim().split_whitespace().map(|s| s.parse::<$t>().unwrap()).collect::<Vec<$t>>(),
            Err(_) => Vec::<$t>::new(),
        }
    }}
}

#[allow(unused_macros)]
macro_rules! input {
    ( $($t:ty),* ) => {{
        let mut s = String::new();
        std::io::stdin().read_line(&mut s);
        let mut splits = s.trim().split_whitespace();
        ($(
            {
                 splits.next().unwrap().parse::<$t>().unwrap()
            },
        )*)
    }}
}

#[allow(unused_must_use)]
#[allow(unused_variables)]
fn solve() {
    let (s,) = input!(String);

    let mut current = ' ';
    for c in s.chars() {
        if current == c {
            println!("Bad");
            std::process::exit(0);
        } else {
            current = c;
        }
    }
    println!("Good");

}

fn main() {
    solve();
}


Measured memory_bytes: 4352
/*
https://atcoder.jp/contests/dp/tasks/dp_a */
#include<bits/stdc++.h>
using namespace std;
int dp[100005];

int main()
{
	int n;
	cin >> n;
	int a[n+1];
	for(int i=1;i<=n;i++)cin >> a[i];
	dp[0]=1e6,dp[1]=0;
    for(int i=2;i<=n;i++)
    {
    	dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
    }
    cout << dp[n] << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0); cin.sync_with_stdio(false);
  int n, x;
  cin >> n >> x;
  vector<int> a(n + 1, 0);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    a[i] += a[i - 1];
  }
  int ret = upper_bound(a.begin(), a.end(), x) - a.begin();
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())


def dfs(s):
    if int(s) > n:
        return 0
    # 7，5，3がすべて文字列に少なくとも一つ含まれていればOK
    ret = 1 if all(s.count(c) > 0 for c in '753') else 0
    for c in '753':
        ret += dfs(s + c)
    return ret


print(dfs('0'))


Measured memory_bytes: 2940
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
#define inf 0x3f3f3f3f3f3f3f3fll
#define MN 200005
using namespace std;
inline int in(){
    int x=0;bool f=0;char c;
    for (;(c=getchar())<'0'||c>'9';f=c=='-');
    for (x=c-'0';(c=getchar())>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0');
    return f?-x:x;
}
ll sum[MN],ans,mn,mx;
int a[MN],n,hd,tl,pl,pr;
int main()
{
	n=in();ans=inf;
	for (int i=1;i<=n;++i)
	a[i]=in(),sum[i]=sum[i-1]+1ll*a[i];
	hd=0;tl=2;
	for (int i=2;i<n-1;++i){
		while (hd<i&&sum[i]-(sum[hd+1]<<1ll)>=0) ++hd;tl=max(tl,i+1);
		while (tl<n&&sum[n]+sum[i]-(sum[tl+1]<<1ll)>=0) ++tl;
		pl=(abs(sum[i]-(sum[hd]<<1ll))<=abs(sum[i]-(sum[hd+1]<<1ll)))?hd:hd+1;
		pr=(abs(sum[n]+sum[i]-(sum[tl]<<1ll))<=abs(sum[n]+sum[i]-(sum[tl+1]<<1ll)))?tl:tl+1;
		mn=min(min(sum[pl],sum[i]-sum[pl]),min(sum[pr]-sum[i],sum[n]-sum[pr]));
		mx=max(max(sum[pl],sum[i]-sum[pl]),max(sum[pr]-sum[i],sum[n]-sum[pr]));
		ans=min(ans,abs(mx-mn));
	}printf("%d",ans);return 0;
}

Measured memory_bytes: 2560
import java.util.*;
import java.util.stream.Collectors;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		String[] tokens = in.readLine().split(" ");
		int a = Integer.parseInt(tokens[0]);
		int b = Integer.parseInt(tokens[1]);
		StringBuilder strBuilder = new StringBuilder();
		for (int i = 0; i < b; ++i) {
			strBuilder.append(a);
		}
		String strA = strBuilder.toString();
		strBuilder = new StringBuilder();
		for (int i = 0; i < a; ++i) {
			strBuilder.append(b);
		}
		String strB = strBuilder.toString();
		if (strA.compareTo(strB) <= 0) {
			System.out.println(strA);
		} else {
			System.out.println(strB);
		}
	}

	void calc() {
	}

	void showResult() {
	}
}


Measured memory_bytes: 21076
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e9)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;

bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}

int main(){
  
  int a,b,c;
  cin>>a>>b>>c;
  if(a==b && b==c){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){

    char* s1;
    char s2[17];

    s1="CODEFESTIVAL2016";

    scanf("%s",s2);
    int i=0;
    int count=0;

    for(i=0;i<16;i++){
        if(s1[i]!=s2[i])
            count++;
    }

    printf("%d\n",count);
	return 0;
}


Measured memory_bytes: 128
#include <cmath>
#include <cstdio>
#include <iostream>

using namespace std;

const int N = 100001;

int num[N];

int func(int n) {
	int q = (int)sqrt(n);
	num[0] = num[1] = 0;
	for (int i=2; i<=n; ++i) num[i] = 1;
	for (int i=2; i<=q; ++i) {
		if (num[i * i]) {
			int j = i + i;
			for (; j<=n; num[j]=0, j+=i);
		}
	}
	int ans = 0;
	for (int i=1; i<=n; ++i) {
		if (num[i] && num[n-i+1]) ++ans;
	}
	return ans;
}

int main() {
	int n;
	while (scanf("%d", &n) != EOF) {
		printf ("%d\n", func(n));
	}
	return 0; 
}

Measured memory_bytes: 0
//Daniel Grzegorzewski
#include <bits/stdc++.h>

#define MP make_pair
#define PB push_back
#define ST first
#define ND second

using namespace std;

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef long long LL;

void init_ios()
{
     ios_base::sync_with_stdio(0);
     cin.tie(0);
}

int n, k, res = (int)1e9;
bool nie[11];
VI ok;

void jeb(int ile)
{
	if (ile >= n) {
		res = min(res, ile);
		return;
	}
	for (auto it: ok)
		if (it != 0 || ile > 0)
			jeb(10*ile+it);
}

int main()
{
    init_ios();
    cin >> n >> k;
    while (k--) {
    	int x;
    	cin >> x;
    	nie[x] = true;
    }
    for (int i = 0; i < 10; ++i)
    	if (!nie[i])
    		ok.PB(i);
    jeb(0);
    cout<<res<<"\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define re return
#define pb push_back
#define po pop_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define ss second.second
#define sf second.first
#define ff first.first
#define fs first.second
#define si size
#define sqrt(x) sqrt(abs(x))
#define mp make_pair
#define pi 3.14159265359
#define er erase
#define in insert
#define em empty
#define ft front
#define fo(i,n) for(i = 0; i < n; i++)
#define ro(i,n) for(i = n - 1; i >= 0; i--)
#define fr(i,j,n) for(i = j; i < n; i++)
#define rf(i,j,n) for(i=n-1;i>=j;i--)
typedef std::vector<int> vi;
typedef std::vector<vi> vvi;
typedef std::pair<int,int> ii;
typedef std::vector<ii> vii;
typedef std::vector<std::string> vs;
typedef double dl;
typedef long double ld;
typedef long long ll;
typedef std::pair<ll, ll> pll;
typedef std::vector<ll> vll;
#define filename ""
using namespace std;

int main()
{
    /*
	freopen(filename".in","r",stdin);
	freopen(filename".out","w",stdout);
	*/
	/*
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
    */
    int n,m;
    cin>>n>>m;
    if (n%m==0)
    {
        cout<<-1<<'\n';
        re 0;
    }
    cout<<n<<'\n';
re 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define quick                    \
    ios::sync_with_stdio(false); \
    cin.tie(0);
#define time cerr << (0.1 * clock()) / CLOCKS_PER_SEC << endl;
#define mod 1000000007
typedef long long ll;
typedef pair<ll, ll> pl;
#define forn(n) for (ll i = 0; i < ll(n); i++)

void solve() {
    ll a, b;
    cin >> a >> b;
    ll g = __gcd(a, b);
    int count = 1;
    for (ll i = 2; i * i <= (g); ++i) {
        if (g % i == 0) {
            while (g % i == 0) {
                g /= i;
            }
            count++;
        }
    }
    count += (g > 1);
    cout << count << '\n';
}

int main() {
    quick;
    solve();
    // ll t;
    // cin >> t;
    // while (t--) {
    //     solve();
    // }
}

Measured memory_bytes: 256
#![allow(unused)]

//input
//use std::io::Read;

//collections
//use std::collections::BTreeMap;
//use std::collections::BTreeSet;
//use std::collections::HashMap;
//use std::collections::HashSet;


//入力マクロここから
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
//入力マクロここまで

fn main() {
    input! {
        n: usize,
        s: String,
        t: String,
    }
    
    let mut s:Vec<char> = s.trim().chars().rev().collect();
    let mut t:Vec<char>  = t.chars().rev().collect();

    for _ in 0..n {
        print!("{}", s.pop().unwrap());
        print!("{}", t.pop().unwrap());
    }

    println!("");
}

Measured memory_bytes: 4352
from heapq import heappop, heappush
from collections import deque
n = int(input())
mp2 = []
route = [[] for i in range(n)]
for i in range(n-1):
    a , b = map(lambda x:int(x)-1,input().split())
    mp2.append((a,b,1))
    mp2.append((b,a,1))
    route[a].append(b)
    route[b].append(a)
inf=float('inf')
d=[inf for i in range(n)]
d[0]=0
prev=[None]*n
p=dict()
for i,j,k in mp2: p[i]=p.get(i,[])+[(j,k)]

q=[]
heappush(q,(d[0],0))
while q:
    du, u = heappop(q)
    if d[u]<du: continue
    for v,weight in p.get(u,[]):
        alt=du+weight
        if d[v]>alt:
            d[v]=alt
            prev[v]=u
            heappush(q, (alt,v))

p=[n-1]
while prev[p[-1]]!=None: p.append(prev[p[-1]])

p = p[::-1]
t = p[-(-len(p)//2)-1]

d = deque()
d.append(n-1)
visit = [False for i in range(n)]
siro = 1
visit[n-1] = True
visit[t] = True
while d:
    now = d.popleft()
    for i in route[now]:
        if not visit[i] and i != t:
            visit[i] = True
            d.append(i)
            siro += 1
kuro = n - siro
if kuro <= siro:
    print("Snuke")
elif kuro > siro:
    print("Fennec")


Measured memory_bytes: 70504
# LR文字列
S = input()
# LR文字列の長さ
N = len(S)
# それぞれのマスの子供の数を入れるためのリスト
C = [0] * N
# 前回同じ記号が出た位置を記憶するためのカウンター
c = 0
# 左から見て行く
# Lが出た時は、前回Rが出たマスか、その右側に子供が溜まる
for i in range(N):
    # 前回Rが出たマスを記録しておく
    if S[i] == 'R':
        c = i
    # 前回Rが出たマスに子供を+1するか、そのマスの右側に子供を+1するか
    # 距離が偶数マス分なら前回Rが出たマスで、距離が奇数マス分ならその右側のマスに+1する
    else:
        C[c + (i - c) % 2] += 1
# 逆向きに同じことをする
# Rが出た時は、前回Lが出たマスか、その左側に子供が溜まる
for i in range(N - 1, -1, -1):
    if S[i] == 'L':
        c = i
    else:
        C[c - (c - i) % 2] += 1
print(' '.join([str(c) for c in C]))

Measured memory_bytes: 10484
#include <iostream>
#define MAX 100
using namespace std;

void trace(int a[],int n){
	for(int i = 0 ; i < n ; i++){
		if(i) cout << " ";
		cout << a[i];
	}
	cout << endl;
}

int selectionsort(int a[], int n){
	int sw = 0,min;
	bool flag;

	for(int i = 0 ; i < n - 1 ; i++){
		min = i;
		flag = 0;

		for(int j = i + 1 ; j < n ; j++){
			if(a[min] > a[j]){
				min = j;
				flag = 1;
			}
		}
		if(flag){
			sw++;
			swap(a[min],a[i]);
		}
	}

	return sw;
}

int main(){
	int n;
	int a[MAX];

	cin >> n;

	for(int i = 0 ; i < n ; i++){
		cin >> a[i];
	}

	int sw =selectionsort(a,n);
	trace(a,n);
	cout << sw << endl;

}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
int ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0; }
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
ll nod(ll F) { return log10(F) + 1; }
//**定義場所**//
//gcd, isPrime, eratos, modinv, bitSearch, dfs, bfs, dijkstra, UnionFind//
ll i, j, k, l, m, n; ll N, M, K, H, W, L; string S;
ll MOD = 1000000007; ll ans = 0; ll INF = 9999999999999;
vl flag, color; vll path; vl A, T; ll key = 0;
//***********//
int main() {
	cin >> N;
	vector<pair<string,ll>> ST(N);
	for (i = 0; i < N; i++) {
		cin >> ST[i].first >> ST[i].second;
	}
	string X;
	cin >> X;
	ll isValid = 0;
	for (i = 0; i < N; i++) {
		if (isValid == 0) {
			if (ST[i].first == X) {
				isValid = 1;
			}
		}
		else {
			ans += ST[i].second;
		}
	}
	cout << ans;
}

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

 unsigned long lucas(int n) {
    unsigned long l[90];
    l[0] = 2;
    l[1] = 1;
    int i = 2;
    while(i != n+1) {
      l[i] = l[i-1] + l[i-2];
      i++;
    }
    return l[n];
}
int main(){
    int n;
    cin >> n;
    cout << lucas(n) << endl;
}


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

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

int main()
{
    string S, T = "keyence", tmp;
    int N;

    cin >> S;
    if (S == T)
    {
        cout << "YES" << endl;
        exit(0);
    }

    N = S.length();

    REP(i, N)
    {
        FOR(j, i, N)
        {
            tmp = "";
            REP(k, N)
            {
                if (k < i || j < k)
                    tmp += S[k];
            }
            if (tmp == T)
            {
                cout << "YES" << endl;
                exit(0);
            }
        }
    }
    cout << "NO" << endl;
}

Measured memory_bytes: 3576
import collections
n = int(input())
s = []
for _ in range(n):
    si = list(input())
    si.sort()
    s.append(''.join(si))
    
con = collections.Counter(s).most_common()
cnt = 0
for sc in con:
    if sc[1] == 1:
        break
    else:
        cnt += (sc[1] * (sc[1]-1))//2
print(cnt)


Measured memory_bytes: 76760
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c, k, n;
  cin >> a >> b >> c;
  cin >> k;
  if (a <= b && c <= b) {
    n = b;
    for (int i = 0; i < k; i++) n+=n;
    n += a + c;
  } else if (a <= c && b <= c) {
    n = c;
    for (int i = 0; i < k; i++) n+=n;
    n += a + b;
  } else {
    n = a;
    for (int i = 0; i < k; i++) n+=n;
    n += b + c;
  }
  cout << n << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n,k;
    std::cin >> n >>k;
    int num=1;
    for (int i = 0; i < n; i++) {
        if(num*2>num+k){
            num+=k;
        }else{
            num*=2;
        }
    }
    std::cout << num << std::endl;
}


Measured memory_bytes: 256
N, Y = map(int, input().split())
d = (Y // 1000) - N
flg = True
for i in range(N + 1):
  if (d - 9 * i) % 4 == 0 and d >= 9 * i:
    if (i + (d - 9 * i) // 4) <= N:
      print(i, (d - 9 * i) // 4, N - i - (d - 9 * i) // 4)
      flg = False
      break
if flg:
  print(-1, -1, -1)


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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i=0; i<n; i++) {
        int a, b, c;
        cin>>a>>b>>c;
        if(a>b) swap(a, b);
        if(b>c) swap(b, c);
        cout<<((a*a+b*b==c*c) ? "YES\n" : "NO\n");
    }
    return 0;
}



Measured memory_bytes: 2936
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int n, ans = 0;
    cin >> n;
    vector<int> l(n);
    for (int i = 0; i < n; ++i) cin >> l.at(i);
    sort(l.begin(), l.end());
    for (int i = 0; i < n; ++i) for (int j = i + 1; j < n; ++j) ans += lower_bound(l.begin(), l.end(), l.at(j) + l.at(i)) - l.begin() - j - 1;
    cout << ans << endl;
    return 0;
}


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

int main()
{
	int H, W;
	do
	{
		cin >> H >> W;
		for (int x = 0; x < H; x++)
		{
			if (x % 2 != 0)
			{
				for (int y = 0; y < W; y++)
				{
					if (y % 2 != 0) cout << "#";
					if (y % 2 == 0)cout << ".";
					if (y == W - 1)cout << endl;
					if (x == H - 1 && y == W - 1) cout << endl;
				}
			}
			if (x % 2 == 0)
			{
				for (int y = 0; y < W; y++)
				{
					if (y % 2 != 0) cout << ".";
					if (y % 2 == 0)cout << "#";
					if (y == W - 1)cout << endl;
					if (x == H - 1 && y == W - 1) cout << endl;
				}
			}
		}
	} while (H != 0 || W != 0);
}


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

int main() {
    long double A, B, H, M;
    cin >> A >> B >> H >> M;
    long double T = (H * 60 + M), a = T * 11 / 2;
    while (a >= 360) {
        a -= 360;
    }
    a = min(a, 360 - a);
    if (a == 180) {
        cout << A + B << endl;
    }
    else if (a == 0) {
        cout << abs(A - B) << endl;
    }
    else {
        cout << fixed << setprecision(10) << sqrt(A * A + B * B - 2 * A * B * cos(a * 3.14159265358 / 180)) << endl;
    }
}

Measured memory_bytes: 4152
from math import ceil
H,W=map(int,input().split())
ans=float("inf")
for h in range(1,H):
  m=min(h*W,(H-h)*(W//2),(H-h)*ceil(W/2))
  M=max(h*W,(H-h)*(W//2),(H-h)*ceil(W/2))
  ans=min(ans,M-m)
  m=min(h*W,((H-h)//2)*(W),ceil((H-h)/2)*(W))
  M=max(h*W,((H-h)//2)*(W),ceil((H-h)/2)*(W))
  ans=min(ans,M-m)
for w in range(1,W):
  m=min(w*H,(W-w)*(H//2),(W-w)*ceil(H/2))
  M=max(w*H,(W-w)*(H//2),(W-w)*ceil(H/2))
  ans=min(ans,M-m)
  m=min(w*H,((W-w)//2)*H,ceil((W-w)/2)*H)
  M=max(w*H,((W-w)//2)*H,ceil((W-w)/2)*H)
  ans=min(ans,M-m)
print(ans)

Measured memory_bytes: 3064
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    //nextLineとnextを同時に使ったら死ぬ
    val sc = new Scanner(System.in)

    val n, m, q = sc.nextInt()

    val ar = bfs((1 to m).map(a => Array(a)).toArray, m, n)

    val nums = Array.fill(q) {
      val a, b, c = sc.nextInt()
      val d = sc.nextLong()
      (a, b, c, d)
    }

    val ans =
      ar.map(list => {
        nums.map {
          case (a, b, c, d) =>
            if (list(b - 1) - list(a - 1) == c) d else 0
        }.sum
      })

    println(ans.max)

//    debug((1 to m).toArray.mkString(" "))
//    ar.foreach(ar => debug(ar.mkString(" ")))
//    nums.foreach(debug(_))
  }

  @scala.annotation.tailrec
  def bfs(arr: Array[Array[Int]], m: Int, n: Int): Array[Array[Int]] = {
    if (arr.head.length == n) {
      arr
    } else {
      bfs(arr.flatMap(ar => {
        for (i <- ar.last to m) yield {
          ar :+ i
        }
      }), m, n)
    }
  }

  @scala.annotation.tailrec
  def gcd(a: Int, b: Int): Int = {
    if (b == 0) a else gcd(b, a % b)
  }
  def debug(args: Any*): Unit = {
    Console.err.println(args.mkString(" "))
  }
}


Measured memory_bytes: 70104
#include <stdio.h>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) ((a)>(0)?(a):-(a))
int main(){
  int n;
  double t,a;
  scanf("%d%lf %lf",&n,&t,&a);
  int h[n],ans=1,i;
  double sub,buf;
  for(i=0;i<n;i++)scanf("%d",&h[i]);
  sub=abs(a-(t-h[0]*0.006));
  for(i=1;i<n;i++){
    buf=sub;
    sub=min(sub,abs(a-(t-h[i]*0.006)));
    if(buf!=sub)ans=i+1;
  }
  printf("%d",ans);
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

    private static double[][][] dp;
    private static double calculate(int one, int two, int three, long len){
        double total = one + two + three;
        if(total == 0) {
            dp[one][two][three] = 0;
            return dp[one][two][three];
        }
        if(dp[one][two][three] != -1) return dp[one][two][three];
        double l = len*1.0/total;
        double ans = 0;
        if(one > 0){
            ans += (calculate(one - 1, two, three, len) + l)*(one/total);
        }
        if(two > 0){
            ans += (calculate(one + 1, two - 1, three, len) + l)*(two/total);
        }
        if(three > 0){
            ans += (calculate(one, two + 1, three - 1, len) + l)*(three/total);
        }
        dp[one][two][three] = ans;
        return ans;
    }
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        // code goes here
        int n = nextInt(br);
        int[] arr = nextIntArray(br, n);
        int one = 0, two = 0, three = 0;
        int max = 0;
        for(int i = 0; i < n; i++){
            if(arr[i] == 1) one++;
            if(arr[i] == 2) two++;
            if(arr[i] == 3) three++;
            max += arr[i];
        }

        dp = new double[n + 1][n + 1][n + 1];

        for(int i = 0; i < n + 1; i++){
            for(int j = 0; j < n + 1; j++){
                Arrays.fill(dp[i][j], -1);
            }
        }

        sb.append(calculate(one, two, three, n));
        System.out.print(sb.toString());
    }

    private static int nextInt(BufferedReader br) throws IOException{
        return Integer.parseInt(br.readLine());
    }

    private static int[] nextIntArray(BufferedReader br, int n) throws IOException{
        StringTokenizer st = new StringTokenizer(br.readLine());
        int[] arr = new int[n];
        for(int i = 0; i < n; i++){
            arr[i] = Integer.parseInt(st.nextToken());
        }
        return arr;
    }

    static class Pair<A, B>{
        A first;
        B second;
        public Pair(A first, B second){
            this.first = first;
            this.second = second;
        }
    }
}


Measured memory_bytes: 281204
#include <iostream>
using namespace std;
#include <vector>
#include <stdlib.h>


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

	string si[10000];

	for (int i=0;i<n;++i) cin >> si[i];

	int count = 0;
	for (int i=0;i<n;++i){
		for (int j=0;j<si[i].size()-1;++j){
			if(si[i][j]=='A' && si[i][j+1]=='B') count += 1;
		}
	}

	int count_a = 0;
	int count_b = 0;
	int count_ab = 0;
	for (int i=0;i<n;++i){
		if(si[i][0]=='B') count_b += 1;
		if(si[i][si[i].size()-1]=='A') count_a += 1;
		if(si[i][0]=='B'&& si[i][si[i].size()-1]=='A') count_ab += 1;
	}

	int count_out;
	if(count_a<count_b) count_out = count + count_a;
	else count_out = count + count_b;

	if((count_ab == count_a && count_ab == count_b) && count_ab != 0) count_out = count + count_ab - 1;

	cout << count_out << endl;
}



Measured memory_bytes: 768
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;


#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()

typedef tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)
ll freq[2001];
int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, x, y, i, j;
    cin>>n>>x>>y;
    for(i = 1; i <= n; i++) {
    	for(j = i + 1; j <= n; j++) {
			ll dist = j - i;
    		if(i <= x && j <= x) {
    			;
    		}
    		if(i <= x && j >= x && j <= y) {
    			dist = min(dist, x - i + 1 + abs(y - j));
    		}
    		if(i <= x && j >= y) {
    			dist = min(dist, x - i + 1 + j - y);
    		}
    		if(i >= x && i <= y && j >= x && j <= y) {
    			dist = min(dist, i - x + 1 + y - j);
    		}
    		if(i >= x && i <= y && j >= y) {
    			dist = min(dist, i - x + 1 + j - y);
    		}
    		freq[dist]++;
    		// cout<<i<<" "<<j<<" "<<dist<<"\n";
    	}
    }
    for(i = 1; i < n; i++) {
    	cout<<freq[i]<<"\n";
    }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  int N;cin >> N;
  int K=N%10;
  if(K==3){
    cout << "bon" << endl;
    return 0;
  }
  if(K==0 || K==1 || K==6 || K==8){
    cout << "pon" << endl;
    return 0;
  }
  cout << "hon" << endl;
  return 0;
}


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

typedef long long ll;
#define all(x) (x).begin(),(x).end()
ll MOD = ll(1e8) + 9;

template<typename T>
T mod(T a, T b){
    return (a + b) % b;
}

template<typename T>
T gcd(T a, T b){
    if (b == 0) return a;
    return gcd(b, a % b);
}

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

// n を素因数分解
map<ll, ll> factor(ll n){
    map<ll, ll> mp;
    for (ll i = 2; i*i <= n; i++) {
        while (n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }

    if (n > 1) {
        mp[n]++;
    }

    return mp;
}

// 文字列に "hoge" が含まれているか
// string str = "hogepiyo";
// if (str.find("hoge") != string::npos) {
//     cout << "文字列が含まれています" << endl;
// }

// char to string
// char c = 'a';
// string str = {c};


void solve(){
    int N;
    cin >> N;
    string S;
    cin >> S;

    int ans = 0;
    for (int i = 0; i < N-2; i++) {
        if (S[i] == 'A' && S[i+1] == 'B' && S[i+2] == 'C') {
            ans++;
        }
    }

    cout << ans << endl;

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}



Measured memory_bytes: 256
//om nama sivaya
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define maxn 100001
#define pb push_back
using namespace std;
void solve(){
    int n;
    cin>>n;
    int a[n],b[n],c[n];
    for(int i=0;i<n;i++)
    cin>>a[i]>>b[i]>>c[i];
    int dp1[n],dp2[n],dp3[n];
    dp1[0]=a[0],dp2[0]=b[0],dp3[0]=c[0];
    for(int i=1;i<n;i++){
        dp1[i]=max(dp2[i-1],dp3[i-1])+a[i];
        dp2[i]=max(dp1[i-1],dp3[i-1])+b[i];
        dp3[i]=max(dp1[i-1],dp2[i-1])+c[i];
    }
    cout<<max(max(dp1[n-1],dp2[n-1]),dp3[n-1]);
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tt=1;
    //cin>>tt;
    while(tt--){
        solve();
    }
}


Measured memory_bytes: 5956
#include<iostream>
#include<algorithm>
#define int long long
using namespace std;
signed main(){
	int n,m,k;
	cin>>n>>m>>k;
	int a[n+2],b[m+2];
	for(int i=1;i<=n;++i)
		cin>>a[i];
	for(int i=1;i<=m;++i)
		cin>>b[i];
	a[0]=b[0]=0;
	a[n+1]=b[m+1]=1000000000000000000;
	for(int i=1;i<=n;++i)
		a[i]+=a[i-1];
	for(int j=1;j<=m;++j)
		b[j]+=b[j-1];
	/*
	for(int i=1;i<=n;++i)
		cout<<a[i]<<' ';
	cout<<endl;
	for(int j=1;j<=m;++j)
		cout<<b[j]<<' ';
	cout<<endl;
	*/
	int maxv=0;
	for(int i=1;i<=n;++i){
		int d=k-a[i];
		int id=upper_bound(b,b+m+2,d)-b-1;
		//cout<<i<<' '<<d<<' '<<id<<endl;
		if(d<0)
			break;
		if(id>=0&&id<=m)
			maxv=max(maxv,id+i);
		else
			break;
	}
	for(int i=1;i<=m;++i){
		int d=k-b[i];
		int id=upper_bound(a,a+n+2,d)-a-1;
		//cout<<i<<' '<<d<<' '<<id<<endl;
		if(d<0)
			break;
		if(id>=0&&id<=n)
			maxv=max(maxv,id+i);
		else
			break;
	}
	cout<<maxv<<endl;
}

Measured memory_bytes: 6772
#include<bits/stdc++.h>
using namespace std;
#define cl(a,b) memset(a,b,sizeof(a))
#define ll long long
#define pb push_back
#define gcd __gcd

#define For(i,j,k) for(int i=(j);i<k;i++)
#define lowbit(i) (i&(-i))
#define _(x) printf("%d\n",x)


const int maxn = 2e5+100;

int Log[maxn], dp[2][20][maxn],pos[maxn],a[maxn],n;

int rmq(int k, int l, int r){
    int p = Log[r-l+1];
    return min(dp[k][p][l], dp[k][p][r-(1<<p)+1]);
}

pair<int,int> cal(int l, int r) {
    int x=rmq(l&1, l ,r);
    int y=rmq((pos[x]+1)&1, pos[x]+1, r);
    return {-x, -y};
}

typedef pair<int,int> P;
typedef pair<P, P> PP;

int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        pos[a[i]]=i;
    }
    for(int i=2;i<=n;i++){
        Log[i]=Log[i>>1]+1;
    }
    for(int i=0;i<2;i++){
        for(int j=0;j<n;j++){
            dp[i][0][j]=(j%2==i)?a[j]:(1<<30);
        }
        for(int j=1;1<<j<=n;j++){
            for(int k=0;k+(1<<j)-1<n;k++){
                dp[i][j][k]=min(dp[i][j-1][k], dp[i][j-1][k+(1<<j-1)]);
            }
        }
    }

    priority_queue<PP> Q;
    Q.push({cal(0, n-1), {0, n-1}});

    while(!Q.empty()) {
        PP it = Q.top();Q.pop();
        int x=it.first.first;
        int y=it.first.second;
        printf("%d %d ", -x, -y);
        int l=it.second.first;
        int r=it.second.second;
        x = pos[-x];
        y = pos[-y];
        if(x-1>l){
            Q.push({cal(l,x-1), {l,x-1}});
        }
        if(y+1<r) {
            Q.push({cal(y+1, r), {y+1, r}});
        }
        if(x+1 < y-1) {
            Q.push({cal(x+1, y-1), {x+1, y-1}});
        }
    }
    return 0;
}



Measured memory_bytes: 35828
#include<bits/stdc++.h>
#define ll long long
using namespace std;
 
ll arr[407], sum[407];
ll dp[407][407];
bool vis[407][407];
 
ll rec( int l, int r )
{
    if(l==r)
        return 0;
    if(l>r)
        return 1e18;
    if( vis[l][r] )
        return dp[l][r];
 
    ll ret= 1e18;
 
    for( int i=l;i<r;i++ )
        ret= min( ret, rec( l, i )+rec( i+1, r )+sum[r]-sum[l-1] );
 
    vis[l][r]= 1;
 
    return dp[l][r]= ret;
}
 
int main()
{
    int n;
    cin>>n;
 
    for( int i=1;i<=n;i++ )
        cin>> arr[i], sum[i]= arr[i]+sum[i-1];
 
    cout<< rec( 1, n ) <<endl;
}

Measured memory_bytes: 5072
#include<iostream>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	if(a<b){
		cout<<"a < b"<<endl;
	}
	else if(a>b){
		cout<<"a > b"<<endl;
	}
	else if(a==b){
		cout<<"a == b"<<endl;
	}
return 0;
}

Measured memory_bytes: 3080
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
struct inf
{
    long long iu;
    long long iwareru;
    long long kekka;
};
int main()
{
    long long kazuh = 0;
    cin >> kazuh;
    long long goukeis = 0;
    long long a = (kazuh - 1) * kazuh;
    struct inf syougenn[a];
    //queue<inf> syougenn;
    for (int i = 1; i <= kazuh; i++)
    {
        long long kazus = 0;
        cin >> kazus;
        for (int j = 0; j <= kazus - 1; j++)
        {
            syougenn[goukeis + j].iu = i;
            cin >> syougenn[goukeis + j].iwareru >> syougenn[goukeis + j].kekka;
            //int iwarerun = 0;
            //int kekkan = 0;
            //cin >> iwarerun >> kekkan;
            //syougenn.push({i,iwarerun,kekkan});
        }
        goukeis += kazus;
    }
    long long kotae = 0;
    for (int i = 0; i < (1 << kazuh); i++)
    {
        long long out = 0;
        //inf syougenns = syougenn.front();
        //syougenn.pop();
        //vector<int> result(kazuh + 1);
        /*for (int x = 1; x <= kazuh; x++)
        {
            result[x] = 1;
        }*/
        for (int j = 0; j <= goukeis - 1; j++)
        {
            if (i & (1 << syougenn[j].iu - 1))
            {
                if (i & (1 << syougenn[j].iwareru - 1))
                {
                  if(syougenn[j].kekka == 0){
                    out = 1;
                    j = goukeis;
                  }
                }
                else{
                  if(syougenn[j].kekka == 1){
                    out = 1;
                    j = goukeis;
                  }
                }
            }
            else{
              //result[syougenn[j].iu] = 0;
            }
        }
        long long honest = 0;
        for(int j = 0;j <= kazuh - 1;j++){
          if(i & (1 << j)){
            honest++;
            //cout << 1;
          }
          else{
            //cout << 0;
          }
          if(j == kazuh - 1){
            //cout << "" << endl;
          }
        }
        //cout << honest << " " << out << endl;
        /*for (int x = 1; x <= kazuh; x++)
        {
          if(x == kazuh){
            cout << result[x] << endl;
          }
          else{
            cout << result[x] << " ";
          }
            if (result[x] == 1)
            {
                honest++;
            }
        }*/
        if (out == 0 && honest > kotae)
        {
          //cout << out << endl;
          kotae = honest;
        }
        honest = 0;
    }
    cout << kotae << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  int N;
  while (cin >> N) {
    vector<ll> a(N), b(N);
    for (int i = 0; i < N; i++) {
      cin >> a[i];
    }
    for (int i = 0; i < N; i++) {
      cin >> b[i];
    }
    ll res = 0;
    for (int d = 0; d < 30; d++) {
      ll mask = (1ll << (d + 1)) - 1, bit = (1ll << d);
      vector<ll> b2(N);
      for (int i = 0; i < N; i++) {
        b2[i] = b[i] & mask;
      }
      sort(b2.begin(), b2.end());
      ll cnt = 0;
      for (int i = 0; i < N; i++) {
        ll a2 = a[i] & mask;
        ll lim1 = bit;
        ll lim2 = bit << 1;
        ll lim3 = (bit << 1) | bit;
        ll lim4 = bit << 2;
        int pos1 = lower_bound(b2.begin(), b2.end(), lim1 - a2) - b2.begin();
        int pos2 = lower_bound(b2.begin(), b2.end(), lim2 - a2) - b2.begin();
        int pos3 = lower_bound(b2.begin(), b2.end(), lim3 - a2) - b2.begin();
        int pos4 = lower_bound(b2.begin(), b2.end(), lim4 - a2) - b2.begin();
        cnt += (pos2 - pos1) + (pos4 - pos3);
      }
      if (cnt % 2 == 1) {
        res |= bit;
      }
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int n,a,b,c,d;
string s;
signed main() {
    cin >> n >> a >> b >> c >> d >> s;
    a--; b--; c--; d--; // 添字化

    bool can = true;
    for (int i=a;i<c;i++) {
        if(s[i]=='#' && s[i+1]=='#') can = false;
    }
    for (int i=b;i<d;i++) {
        if(s[i]=='#' && s[i+1]=='#') can = false;
    }

    if (d<c) {
        can = false;
        for (int i=b-1;i<=d-1;i++) {
            if (s[i]=='.' && s[i+1]=='.' && s[i+2]=='.') {
                can = true;
            }
        }
    }

    if (can) cout << "Yes" << endl;
    else cout << "No" << endl;

}

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

using namespace std;

#define forn(i, x, n) for (int i = int(x); i <= int(n); ++i)
#define for1(i, n, x) for (int i = int(n); i >= int(x); --i)
#define F first
#define S second
#define pb push_back

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

const int N = 2e6 + 1;
const ll INF = 1e18 + 9;
const int B = 1e9 + 7;

int n;
ll a[N], p[N];

int main() {
    #ifdef black
    freopen("in", "r", stdin);
    #endif // black
    ios_base :: sync_with_stdio(0);
    cin.tie(0);

    cin >> n;
    forn(i, 1, n)
        cin >> a[i];
    sort(a + 1, a + 1 + n);
    forn(i, 1, n)
        p[i] = p[i - 1] + a[i];
    int ans = 1;
    for1(i, n - 1, 1) {
        if (p[i] * 2 < a[i + 1]) break;
        ++ans;
    }
    cout << ans << "\n";
    return 0;

    forn(i, 1, n) {
        bool shit = 0;
        for (int ptr = i; ptr < n;) {
            if (p[ptr] * 2 < a[ptr + 1]) {
                shit = 1;
                break;
            }
            int l = ptr + 1, r = n;
            while (l < r) {
                int m = (l + r + 1) / 2;
                if (p[ptr] * 2 >= p[m] - p[ptr]) l = m;
                else r = m - 1;
            }
            ptr = l + 1;
        }
        if (!shit) ++ans;
    }
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 5120
package main

import (
	"fmt"
)

func reverse(s string) string {
	rs := []rune(s)
	for i, j := 0, len(rs)-1; i < j; i, j = i+1, j-1 {
		rs[i], rs[j] = rs[j], rs[i]
	}

	return string(rs)
}

func checker(s string, words []string) bool {
	for _, w := range words {
		if len(s) < len(w) {
			continue
		}
		if s[0:len(w)] == w {
			if len(s) == len(w) {
				return true
			}
			return checker(s[len(w):], words)
		}
	}
	return false
}

func main() {
	var s string
	fmt.Scan(&s)
	words := []string{"dream", "dreamer", "erase", "eraser"}

	for i, _ := range words {
		words[i] = reverse(words[i])
	}
	s = reverse(s)

	if checker(s, words) {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 10368
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	n := getNextInt(scanner)

	max := int64(math.MaxInt32)

	var sum int64
	for i := 0; i < n; i++ {
		a := getNextInt64(scanner)
		b := getNextInt64(scanner)
		sum += a
		if a <= b {
			continue
		}
		if max > b {
			max = b
		}
	}
	if max == int64(math.MaxInt32) {
		fmt.Fprintln(writer, 0)
	} else {
		fmt.Fprintln(writer, sum-max)
	}

	writer.Flush()
}


Measured memory_bytes: 1664
function Main(input) {
  input = input.replace(/\n/g, ' ').split(" ");
  var a = input[0];
  var ans = 0;
  var mem = 0;
  for(var i=0;i<a.length;i++){
    ans+=+a.slice(i,i+1);
  }
  console.log((ans%9==0)?"Yes":"No");
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 33044
#[macro_use]
extern crate proconio;
use std::collections::*;

fn main() {
    input! {
        n: u64
    };

    let mut s: u64 = 0;

    for i in 1..=n {
        if i % 3 == 0 {
        } else if i % 5 == 0 {
        } else {
            s += i;
        }
    }

    println!("{}", s);
}

/*
* 提出前確認
* - オーバーフローしないようにi64またはu64を使っているか
* - usizeやu64を使っている際は減算で負数になりえないか
* - 剰余算の結果が負になっていないか
**/

use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


Measured memory_bytes: 2136
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

aa = a % 10
bb = b % 10
cc = c % 10
dd = d % 10
ee = e % 10

cnt = 0

aaa = 10
bbb = 10
ccc = 10
ddd = 10
eee = 10
if aa != 0:
    cnt += 10
    aaa = aa
if bb != 0:
    cnt += 10
    bbb = bb
if cc != 0:
    cnt += 10
    ccc = cc
if dd != 0:
    cnt += 10
    ddd = dd
if ee != 0:
    cnt += 10
    eee = ee

if cnt > 0:
    cnt = cnt - 10
mmm = min([aaa, bbb, ccc, ddd, eee])
if mmm == 10:
    mmm = 0

print(a - aa + b - bb + c - cc + d - dd + e - ee + cnt + mmm)

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

using namespace std;

const int N=5000;
int dp[N][N];

int main()
{
    string a,b;
    cin>>a>>b;
    memset(dp,0,sizeof dp);
    int n=a.length(); int m=b.length();
    for(int i=0;i<=n;i++) dp[i][0]=0;
    for(int i=0;i<=m;i++) dp[0][i]=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(a[i-1]==b[j-1]) dp[i][j]=dp[i-1][j-1]+1;
            else
            {
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    string ans="";
    int i=n, j=m;
    int akt=dp[i][j];
    while(i!=0 || j!=0)
    {
        if(i==0)
        {
            if(dp[i][j-1]==dp[i][j]) j--;
            else {j--; ans+=a[i];}
        }
        else if(j==0)
        {
            if(dp[i-1][j]==dp[i][j]) i--;
            else {i--; ans+=a[i];}
        }
        else
        {
            if(dp[i-1][j]==dp[i][j]) i--;
            else if(dp[i][j-1]==dp[i][j]) j--;
            else {i--; j--; ans+=a[i];}
        }
    }
    for(int i=ans.length()-1;i>=0;i--) cout<<ans[i];
    return 0;
}


Measured memory_bytes: 98048
#include <bits/stdc++.h>
using namespace std;
typedef long long 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++)
const int MOD = 1000000007;

int main() {
  int N; cin >> N; // 社員数
 	map<int,int> A;   // 社員番号と部数のマップ

  int wk_A;
  rep(i,N-1){
    cin >> wk_A;
    A[wk_A]++;
  }
  rep1(i,N){
    cout << A[i] << endl;

  }
  return 0;

}


Measured memory_bytes: 12984
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<climits>
#include<cstring>
#include<queue>
using namespace std;

const int INF = INT_MAX / 3;

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


double EPS = 1e-10;

double add(double a, double b) {
	if (abs(a + b) < EPS * (abs(a) + abs(b))) return 0;
	return a + b;
}

struct P {
	double x, y;
	P() {}
	P(double x, double y) : x(x), y(y) {
	}
	P operator +(P p) {
		return P(add(x, p.x), add(y, p.y));
	}
	P operator -(P p) {
		return P(add(x, -p.x), add(y, -p.y));
	}
	P operator *(double d) {
		return P(d*x, d*y);
	}
	double dot(P p) {
		return add(x*p.x, y*p.y);
	}
	double det(P p) {
		return add(x*p.y, -y*p.x);
	}
	void print() {
		printf("%.10lf %.10lf \n", x, y);
		return;
	}
};

double dist(P &p, P &q, P &r){
	if((q-p).dot(r-p)*(p-q).dot(r-q) >= 0){
		double a = q.y-p.y;
		double b = -q.x+p.x;
		double c = -p.x*q.y+p.y*q.x;
		return fabs(a*r.x+b*r.y+c)/sqrt(a*a+b*b);
	}else{
		return min (sqrt((r.x-p.x)*(r.x-p.x)+(r.y-p.y)*(r.y-p.y)), sqrt((r.x-q.x)*(r.x-q.x)+(r.y-q.y)*(r.y-q.y)));
	}
	
}

P crossPoint(P p0, P p1, P p2, P p3){
	P q0 = p1-p0;
	P q1 = p3-p2;
	P r = p0 + (p1-p0)*((p3-p2).det(p2-p0)/(p3-p2).det(p1-p0));
	return r;
}

bool isCross(P &p0,P &p1,P &p2,P &p3){
	P r = crossPoint(p0, p1, p2, p3);
	return ((p1-p0).dot(r-p0) * (p0-p1).dot(r-p1)) >=0 && ((p3-p2).dot(r-p2) * (p2-p3).dot(r-p3)) >=0;;
}

double Distance(P &p0,P &p1,P &p2,P &p3){
	if(isCross(p0, p1, p2, p3)){
		return 0;
	}
	double d = dist(p0, p1, p2);
	d = min(d, dist(p0, p1, p3));
	d = min(d, dist(p2, p3, p0));
	d = min(d, dist(p2, p3, p1));
	return d;
}

int main(){
	int q;
	cin >> q ;
	REP(i,q){
		P p0, p1, p2, p3;
		cin >> p0.x >> p0.y >> p1.x >> p1.y >> p2.x >> p2.y >> p3.x >> p3.y ;
		printf("%.10lf \n", Distance(p0, p1, p2, p3));
	}
	return 0;
}

Measured memory_bytes: 1252
/*我是萌新*/
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include <iomanip> 
typedef long long LL;
const int mod = 1000000009;
using namespace std;
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    LL a, b;
    while (cin >> a >> b)
    {
        if (a >= 13) cout << b << '\n';
        else if (a < 13 && a >= 6) cout << b / 2 << '\n';
        else cout << "0\n";
    }
}



Measured memory_bytes: 256