akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import static java.util.Arrays.*;
import static java.lang.Math.*;
public class Main {

	static Scanner sc = new Scanner(System.in);
	
	public static void main(String[] args) {
		while (read())
			solve();
	}
	
	static int H, W;
	static int[] C = new int[4];
	static int[][] map = new int[30][30];
	static boolean read() {
		W = sc.nextInt(); H = sc.nextInt();
		if (W == 0) return false;
		
		for (int i = 0; i < H; i++)
			for (int j = 0; j < W; j++)
				map[i][j] = sc.nextInt();
		
		for (int i = 0; i < 4; i++)
			C[i] = sc.nextInt();
				
		return true;
	}

	static final int INF = 1 << 20;
	static int[] dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
	static void solve() {
		int[][][] dist = new int[30][30][4];
		for (int i = 0; i < 30; i++)
			for (int j = 0; j < 30; j++)
				fill(dist[i][j], INF);
		
		PriorityQueue<State> que = new PriorityQueue<State>();
		que.add(new State(0, 0, 0, 0));
		while (!que.isEmpty()) {
			State s = que.poll();
			int x = s.x, y = s.y, c = s.c, d = s.d;
			if (dist[y][x][d] != INF) continue;
			dist[y][x][d] = c;
			
			if (y == H - 1 && x == W - 1) {
				
				System.out.println(c);
				break;
			}
			
			for (int i = 0; i < 4; i++) {
				int nd = (d + i) % 4;
				int nx = x + dx[nd], ny = y + dy[nd], nc = c + C[i];
					
				if (i == map[y][x])
					nc -= C[i];
				
				if (check(nx, ny) && dist[ny][nx][nd] > nc) 
					que.add(new State(nx, ny, nd, nc));
			}
		}
	}	
	static boolean check(int x, int y) {
		return (x >= 0 && x < W && y >= 0 && y < H);
	}
}

class State implements Comparable<State> {
	int x, y, c, d;	// ツコツスツト ツ陛サツ古シ
	State(int x, int y, int d, int c) {
		this.x = x;
		this.y = y;
		this.c = c;
		this.d = d;
	}
	
	public int compareTo(State s) {
		return this.c - s.c;
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0; i<n; ++i)
#define rep1(i,n) for(ll i=1; i<=n; ++i)
#define revrep(i,n) for(ll i=n-1; n>=0; --i)
inline constexpr ll Inf = (1ULL << 62) -1;
#define fastio cin.tie(nullptr); ios_base::sync_with_stdio(false);
#define endl '\n'
template <class T> void updatemax(T& a, T b) { if (b > a) a = b; }

void inc(string& s) {
    int pos;
    for (int i=s.size()-1; i >= 0; --i) {
        if (i == 0) {
            if (s[0] == '9') {
                s = "1" + string(s.size(), '0');
                return;
            }
            s[0]++;
            pos = 0;
        } else {
            if (s[i] != '9' && s[i-1] + 1 > s[i]) {
                s[i]++;
                pos = i;
                break;
            }
        }
    }
    while (++pos < (int)s.size()) {
        char c = s[pos-1];
        if (c != '0') --c;
        s[pos] = c;
    }
}

int main() {
    fastio;
    int k;
    cin >> k;
    string s("1");
    for (int ans=1; ans != k; ++ans) {
        inc(s);
    }
    cout << s << endl;
}


Measured memory_bytes: 3656
S = list(input())
T = list(input())
S = sorted(S)
T = sorted(T,reverse = True)
counter = 0
l = min(len(S), len(T))
for i in range(l) :
    if S[i] > T[i] :
        print("No")
        break
    elif S[i] < T[i] :
        print("Yes")
        break
    else :
        counter += 1
    if counter == l :
        if len(S) >= len(T) :
            print("No")
            break
        else :
            print("Yes")
            break
            

Measured memory_bytes: 3064
#include<iostream>

using namespace std;

int main(void)
{
  int a,b; cin>>a>>b;
  
  if(a==1){a=14;} if(b==1){b=14;}
  
  if(a>b){puts("Alice");}
  else if(b>a){puts("Bob");}
  else{puts("Draw");}
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using ll = long long;
#define int long long
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
signed main(void){
    int n; cin>>n;
    COMinit();
    int x = 0;
    bool ok[100200];
    int i=1;
    int key = -1;
    while(x<= 100000){
        x = COM(i, 2);
        //cout<<x<<endl;
        if(n == x) { key = i; break;}
        ok[x] = true;
        i++;
    }
    if(key == -1) {cout<<"No"<<endl; return 0;}
    else cout<<"Yes"<<endl<<key<<endl;
    vector <vector<int>> ans(key,vector <int>(0));
    for(int i=0;i<key-1;i++){
        for(int j=i+1;j<key;j++){
            ans[i].push_back(n);
            ans[j].push_back(n);
            n--;
        }
    }
    rep(i, key){
        cout<<ans[i].size()<<' ';
        rep(j, ans[i].size()){
            cout<< ans[i][j]<<' ';
        }
        cout<<endl;
    }
}


Measured memory_bytes: 15232
use whiteread::parse_line;

fn main() {
    let (mut k, a, b): (usize, usize, usize) = parse_line().unwrap();
    let mut bis = 1;
    let mut yen = false;

    if a + 1 < b {
        while k > 1 {
            if yen {
                bis += b;
                yen = false;
            } else if bis < a {
                bis += 1;
            } else {
                bis -= a;
                yen = true;
            }
            k -= 1;
        }
        if yen {
            bis += b;
        } else {
            bis += 1;
        }
    } else {
        bis += k;
    }
    println!("{}", bis);
}


Measured memory_bytes: 2184
#!/usr/bin/env ruby
n, m, q = gets.chomp.split.map(&:to_i)


a = []
b = []
c = []
d = []

1.upto(q) do |i|
  input = gets.chomp.split.map(&:to_i)
  a << input[0]
  b << input[1]
  c << input[2]
  d << input[3]
end

@ans = 0

def dfs(arr, n, m, a, b, c, d)
  if arr.length == n
    score = 0
    a.each_with_index do |a_i, i|
      score += d[i] if arr[b[i] - 1] - arr[a_i - 1] == c[i]
    end
    @ans = [score, @ans].max
    return
  end

  i = arr.last || 1
  i.upto(m) do |x|
    new_arr = arr.dup
    dfs(new_arr.push(x), n, m, a, b, c, d)
  end
end

dfs([], n, m, a, b, c, d)

puts @ans


Measured memory_bytes: 14888
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long;
using P = pair<int, int>;
using lP = pair<ll, ll>;
using fP = pair<double, double>;

int dp[55][55][105];
int main() {
    int n, K;
    cin >> n >> K;
    vector<int>v(n);
    rep(i, n)cin >> v[i];
    rep(i, 55)rep(j, 55)rep(k, 105)dp[i][j][k] = -INF;
    dp[0][n][0] = 0;
    rep(i, n)for (int j = n; j > 0; j--)rep(k, K) {
        if (i  >= j)break;
        if (dp[i][j][k] == -INF)continue;
        dp[i + 1][j][k + 2] = max(dp[i + 1][j][k + 2], dp[i][j][k]);
        dp[i + 1][j][k + 1] = max(dp[i + 1][j][k + 1], dp[i][j][k] + v[i]);
        dp[i][j - 1][k + 2] = max(dp[i][j - 1][k + 2], dp[i][j][k]);
        dp[i][j - 1][k + 1] = max(dp[i][j - 1][k + 1], dp[i][j][k] + v[j - 1]);

    }
    int ans = 0;
    rep(i, 55)rep(j, 55)rep(k,K+1) {
        ans = max(ans, dp[i][j][k]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1536
def ceil(a, b):
    return (a + b - 1) // b

N = int(input())
T = []
A = []
for _ in range(N):
    t, a = map(int, input().split())
    T.append(t)
    A.append(a)
curT = T[0]
curA = A[0]
for i in range(1, N):
    m1 = ceil(curT, T[i])
    m2 = ceil(curA, A[i])
    m = max(m1, m2)
    curT = m * T[i]
    curA = m * A[i]
print(curT+curA)

Measured memory_bytes: 3064
s=input()
n=len(s)
if all(s[i]==s[n-i-1] for i in range(n//2)):
    if all(s[i]==s[(n-1)//2-i-1] for i in range((n-1)//4)):
        if all(s[(n+3)//2-1+i]==s[n-i-1] for i in range((n-1)//4)):
            print('Yes')
            exit()
print('No')

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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define ture ture
#define flase false
#define falg flag

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;//llの最大9*10^18
const int INF = pow(2, 30) - 1;

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

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

    ll N,K;
    string S;
    cin >> N>>K;
    vector<ll> p(N);

    REP(i,N){
        cin >> p.at(i);
    }

    sort(p.begin(), p.end());

    ll ans = 0;

    REP(i,K){
        ans += p.at(i);
    }

    cout << ans << endl;
}


Measured memory_bytes: 3652
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

using Pi = pair<int, int>;
using ll = long long;
const int INF = 1 << 28;

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

void get() {}

template <class Head, class... Tail>
void get(Head& head, Tail&... tail) {
  cin >> head;
  get(tail...);
}

template <class T>
void getv(vector<T>& vec) {
  for (int i = 0; i < vec.size(); ++i)
    cin >> vec[i];
}

struct Union_Find {
  vector<int> data;
  Union_Find(int size) { data = vector<int>(size, -1); }
  bool union_set(int x, int y) {
    x = root(x);

    y = root(y);
    if (x != y) {
      if (data[y] < data[x])
        swap(x, y);
      data[x] += data[y];
      data[y] = x;
    }
    return x != y;
  }
  bool find(int x, int y) { return root(x) == root(y); }
  int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
  int size(int x) { return -data[root(x)]; }
};

int main() {
	int N,K,L;
  get(N,K,L);
  Union_Find uf1(N),uf2(N);
  FOR(i,K){
    int p,q;
    get(p,q);
    p--;q--;
    uf1.union_set(p,q);
  }
  FOR(i,L){
    int r,s;
    get(r,s);
    r--;s--;
    uf2.union_set(r,s);
  }
  map<Pi,int> list;
  FOR(i,N){
    list[Pi(uf1.root(i),uf2.root(i))]++;
  }
  FOR(i,N){
    cout<<list[Pi(uf1.root(i),uf2.root(i))]<<" ";
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 13568
import std.stdio;
import std.conv;
import std.string;

void main(){

  int[100] n;

  int num=0;
  while(true){
		n[num] = to!(int)(chomp(readln()));
    if(n[num] == 0){
      break;
    }
    num++;
  }

  for(int i=0; i<num; i++){
		writef("%d\n", calZero(n[i]));
  }

}

int calZero(int num){
	int devide = 5;
  int ret = 0;
  while(true){
		ret += num / devide;
    devide *= 5;
    if(num < devide)	break;
  }
  return ret;
}

Measured memory_bytes: 1048
#include<cstdio>
int main()
{
    long long k;
    scanf("%lld",&k);
    printf("50\n");
    long long n=k/50,t=k%50;
    for(int i=0; i<50; i++)
    {
        if(i!=0)
            printf(" ");
        if(i<t) 
            printf("%lld",i+n+50-t+1);
        else 
            printf("%lld",i+n-t);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
string a,b;
bool Is_equal(string &x,string &y){
    int i=0,len=x.size();
    do{
        if(y==x)
            return true;
        rotate(x.begin(),x.begin()+1,x.end());
        i++;
    }while(i<len);
    return false;
}
int main(){
    cin>>a>>b;
    if(Is_equal(a,b))
        cout<<"Yes\n";
    else
        cout<<"No\n";
}


Measured memory_bytes: 256
n, t = gets.split.map(&:to_i)
q = []
ans = []
now = 0
n.times do
  a, b = gets.split
  b = b.to_i
  if b <= t
    ans << [a, b + now]
    now += b
  else
    q << [a, b - t]
    now += t
  end
end
until q.empty?
  a, b = q.shift
  if b <= t
    ans << [a, b + now]
    now += b
  else
    q << [a, b - t]
    now += t
  end
end

puts ans.map { |(a, b)| "#{a} #{b}" }



Measured memory_bytes: 16196
package main
 
import (
	"fmt"
)
 
func main() {
  var n, r int
  fmt.Scanf("%d %d", &n, &r)
 
  ans := r
  if n < 10 {
    ans += 100 * (10 - n)
  }
  fmt.Printf("%d\n", ans)
}

Measured memory_bytes: 1836
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")
}

fn main() {

    let a: i32 = read();
    let b: i32 = read();

    if a > 8 || b > 8 {
        println!(":(")
    } else {
        println!("Yay!")
    }
}


Measured memory_bytes: 4352
def dfs(v,been):
    if len(been) == n:
        ans.append(1)
        #print(been)
        return
    for i in graph[v]:
        if i in been:
            pass
        else:
            been.add(i)
            dfs(i,been)
            been.remove(i)
    return

n,m = map(int,input().split())
graph = [[] for _ in range(n+1)]
for _ in range(m):
    a,b = map(int,input().split())
    graph[a].append(b)
    graph[b].append(a)
#print(graph)

ans = []

dfs(1,set([1]))
print(sum(ans))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
template <typename X, typename Y> istream& operator>>(istream& is, pair<X, Y>& p) { return is >> p.first >> p.second; }
void solve(long long N, long long M, std::vector<long long> L, std::vector<long long> R) {
    vector<vector<int>> opens_at(M + 2), closes_at(M + 2);
    for(int i = 0; i < N; i++) {
        closes_at[L[i]].push_back(i);
        opens_at[R[i]].push_back(i);
    }
    vector<bool> left_removed(N);
    auto ordering = [&](int i) {
        return make_tuple(left_removed[i] ? M + 1 : L[i], -R[i], i);
    };
    auto cmp = [&](int i, int j) {
        return ordering(i) < ordering(j);
    };
    set<int, decltype(cmp)> s(cmp);
    for(int i = 0; i < N; i++) {
        s.insert(i);
    }
    vector<bool> seated(N);
    for(int x = 0; x <= M + 1; x++) {
        for(int i : opens_at[x]) {
            if(not seated[i]) {
                s.insert(i);
            }
        }
        if(1 <= x and x <= M) {
            if(not s.empty()) {
                seated[*s.begin()] = true;
                s.erase(s.begin());
            }
        }
        for(int i : closes_at[x]) {
            s.erase(i);
            left_removed[i] = true;
        }
    }
    cout << N - count(seated.begin(), seated.end(), true) << endl;
}
int main() {
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> L(N);
    std::vector<long long> R(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&L[i]);
        scanf("%lld",&R[i]);
    }
    solve(N, M, std::move(L), std::move(R));
    return 0;
}


Measured memory_bytes: 29312
#include<bits/stdc++.h>
using namespace std;
char miku[210000];

int main()
{
    scanf("%s",&miku[1]);
    int n=strlen(miku+1),tot=0;
    for(int i=1;i<n;i++)
    {
        if(miku[i]!=miku[i-1])tot++;
        else miku[++i]=0,tot++;
    }
    if(miku[n]&&miku[n]!=miku[n-1])tot++;
    cout<<tot;
    return 0;
}


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

using namespace std;
using ll = long long;

int main() {
    ll n;
    cin >> n;
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        ll a;
        cin >> a;
        while (!(a & 1)) {
            ans++;
            a >>= 1;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
C = []
for i in range(N):
    a, b = map(int, input().split())
    C.append((a+b, a, b))

C.sort(reverse=1)

ans = 0
for i in range(N):
    _, a, b = C[i]
    if i % 2 == 0:
        ans += a
    else:
        ans -= b
print(ans)

Measured memory_bytes: 20996
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long K,A,B,ans;
    cin >> K >> A >> B;
    if (A-B+2>=0) {
        ans = K + 1;
    } else if (K+1<A) {
        ans = K + 1;
    } else {
        int k2 = K - A + 1;
        ans = A + (k2 - 2*(k2/2)) - (k2/2)*A + (k2/2)*B;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace Sort_II
{
    class Minimum_Cost_Sort
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            var A = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            var B = (int[])A.Clone();
            var p = 0;
            var r = B.Length - 1;
           
            QuickSort(B, p, r);

            var cost = MinimumCost(A,B);

            Console.WriteLine(cost);
        }

        static public int MinimumCost(int[] A,int[] sorted)
        {
            var min = 10001;
            var done = new bool[A.Length];
            var cycl = new Dictionary<int, int>();
            for (int i = 0; i < A.Length; i++)
            {
                cycl.Add(sorted[i],i);
                if (A[i] < min) min = A[i];
            }

            var cost = 0;

            for (int i = 0; i < A.Length; i++)
            {
                if (done[i]) continue;
                var index = i;
                var c = 0;
                var lmin = 10001;
                var sum = 0;
                while (true)
                {
                    if (done[index]) break;
                    c++;
                    done[index] = true;
                    if (A[index] < lmin) lmin = A[index];
                    sum += A[index];
                    index = cycl[A[index]];
                }
                var temp = sum - lmin * 2 + lmin * c;
                var alt = sum + lmin + min + min * c;
                if (alt < temp) cost += alt;
                else cost += temp;
            }

            return cost;
        }

        static public void QuickSort(int[] A, int p, int r)
        {
            if (p < r)
            {
                var q = Partition(A, p, r);
                QuickSort(A, p, q - 1);
                QuickSort(A, q + 1, r);
            }
        }

        static public int Partition(int[] A, int p, int r)
        {
            var x = A[r];
            var i = p - 1;
            for (int j = p; j < r; j++)
                if (A[j] <= x)
                {
                    i++;
                    var temp = A[i];
                    A[i] = A[j];
                    A[j] = temp;
                }
            var tmp = A[i + 1];
            A[i + 1] = A[r];
            A[r] = tmp;

            return i + 1;
        }
    }
}

Measured memory_bytes: 10224
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>

using namespace std;

int main(void) {
    int N;
    cin >> N;
    vector< tuple<string, int, int> > t;
    for(int i=0; i<N; i++) {
        string S;
        int  P;
        cin >> S >> P;
        t.emplace_back(S, -P, i+1);
    }
    
    sort(t.begin(), t.end());
    for(int i=0; i<N; i++) {
        cout << get<2>(t[i]) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
 
int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  
  lint L,R; 
  cin >> L >> R; 
  lint min = 2018;
  lint h;
  if((R-L)>2019){
    min = 0;
  }
  else{
    for(lint i=L;i<R;i++){
    for(lint j=i+1;j<R+1;j++){
      h = ((i%2019)*(j%2019))%2019;
      if( h <= min) min = h;
    }
    }
  }
  cout <<  min << '\n';
}

Measured memory_bytes: 256
/**
*    created: 12.05.2020 00:58:50
**/
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int n, l; cin >> n >> l;
    int sum = 0;
    for (int i = 1; i <= n; i++) {
        sum += l + i - 1;
    }
    int mn = 10000000000;
    int ans;
    for (int i = 1; i <= n; i++) {
        if (mn > abs(l+i-1)) {
            mn = abs(l+i-1);
            ans = i;
        }
    }
    cout << sum - (l + ans - 1) << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            String S = Console.ReadLine();
            int diffs1 = 0, diffs2 = 0;
            for (int i = 0; i < S.Length; i++)
            {
                char target1 = i % 2 == 0 ? '0' : '1';
                char target2 = i % 2 == 0 ? '1' : '0';

                if (target1 != S[i]) diffs1++;
                if (target2 != S[i]) diffs2++;
            }
            Console.WriteLine(Math.Min(diffs1, diffs2));
        }
    }
}


Measured memory_bytes: 13280
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define MOD (ll)(1e9+7)
#define INF 1e17
#define int ll
using namespace std;
using ll=long long;
using pii=pair<int,int>;

#define W first
#define V second

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

int fpow(int b,int p)
{
	if(p==0) return 1;
	int h=fpow(b,p/2);
	if(p%2) return h*b%MOD*h%MOD;
	return h*h%MOD;
}

double dp[3000][3000];

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n; cin>>n;
	vector<double> p(n);
	for(auto &i:p) cin>>i;
	For(i,0,n){
		dp[i][0]=0;
		dp[0][i]=0;
	}
	dp[0][0]=1;
	For(i,1,n){
		For(j,0,n){
			dp[i][j]=dp[i-1][j]*(1-p[i-1]);//+
			if(j>0) dp[i][j]+=dp[i-1][j-1]*p[i-1];
		}
	}
	double ans=0;
	For(i,n/2+1,n) ans+=dp[n][i];
	cout<<fixed<<setprecision(15)<<ans<<"\n";
	return 0;
}


























Measured memory_bytes: 70656
import sys
INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
LIST = lambda: list(map(int, INPUT().split()))
sys.setrecursionlimit(10 ** 9)


def main():
    N = INT()
    AB = sorted([LIST() for _ in range(N)], key=(lambda x: -x[1]))
    CD = sorted([LIST() for _ in range(N)])

    cnt = 0
    for c, d in CD:
        for a, b in AB:
            if a < c and b < d:
                AB.remove([a, b])
                cnt += 1
                break

    print(cnt)


if __name__ == '__main__':
    main()

Measured memory_bytes: 39760
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main() {
    char S[3];
    scanf("%s",&S);
    if(S[0] != S[1] || S[0] != S[2] || S[1] != S[2]){
        printf("Yes");
    }
    else{
        printf("No");
    }
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>

using namespace std;
typedef long long ll;

int main(){
    string s;
    cin >> s;
    int ans=0;
    int n=s.size();
    for (int i = 0; i < n; i+=2)
    {
        if(s[i]=='0') ans++;
        if(s[i+1]=='1') ans++;
    }
    cout << min(ans, n-ans) << endl;
}

Measured memory_bytes: 512
# import collections

N=int(input())
A=[]
PRECISION_DIGITS=9
cnt={} #collections.defaultdict(int)


for n in range(N):
	tmpA = float(input())
	tmpA = round(tmpA*10**PRECISION_DIGITS)
	#print(tmpA)

	five = 0
	two = 0
	while (tmpA % 2) == 0:
		two += 1
		tmpA //= 2
	while (tmpA % 5) == 0:
		five += 1
		tmpA //= 5

	# (10**9) -> (two,five)=(9,9)
	two -= PRECISION_DIGITS
	five -= PRECISION_DIGITS

	cnt.setdefault((two,five),0)
	cnt[(two,five)]+=1

# print(cnt)
ans = 0
for t1, cnt1 in cnt.items():
	for t2, cnt2 in cnt.items():
		# 2**a(a>=0) and 5**b(b>=0) => integer
		if 0 <= t1[0]+t2[0] and 0 <= t1[1]+t2[1]:
			if t1 < t2:
				ans += int(cnt1*cnt2)
			elif t1 == t2:
				# same entry
				# Total number of combinations choose 2 items
				# nC2 = n*(n-1)/2
				ans += int((cnt1*(cnt2-1))/2)


print(ans)



Measured memory_bytes: 77752
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.util.Arrays;

public class Main {

	/* several useful subroutines */
	private static final BigDecimal BD1000000007 = new BigDecimal(1000000007);
	private static BufferedReader brStdin = new BufferedReader(new InputStreamReader(System.in));
	private static String[] readBuf = null;
	private static int readPtr = 0;
	private static String getString() throws IOException {
		while ( readBuf == null || readPtr >= readBuf.length ) {
			readBuf = brStdin.readLine().split(" ");
			readPtr = 0;
		}
		return readBuf[readPtr++];
	}
	private static int getInt() throws IOException {
		return Integer.parseInt(getString());
	}
	private static long getLong() throws IOException {
		return Long.parseLong(getString());
	}
	private static BigDecimal getBD() throws IOException {
		return new BigDecimal(getString());
	}
	@SuppressWarnings("unused")
	private static String[] getStringArray(int size) throws IOException {
		String stringArray[] = new String[size];
		for (int i = 0; i < stringArray.length; i++) {
			stringArray[i] = getString();
		}
		return stringArray;
	}
	@SuppressWarnings("unused")
	private static int[] getIntArray(int size) throws IOException {
		int intArray[] = new int[size];
		for (int i = 0; i < intArray.length; i++) {
			intArray[i] = getInt();
		}
		return intArray;
	}
	@SuppressWarnings("unused")
	private static long[] getLongArray(int size) throws IOException {
		long longArray[] = new long[size];
		for (int i = 0; i < longArray.length; i++) {
			longArray[i] = getLong();
		}
		return longArray;
	}
	@SuppressWarnings("unused")
	private static BigDecimal[] getBDArray(int size) throws IOException {
		BigDecimal bdArray[] = new BigDecimal[size];
		for (int i = 0; i < bdArray.length; i++) {
			bdArray[i] = getBD();
		}
		return bdArray;
	}
	private static BigDecimal mod1000000007(BigDecimal bd) {
		return bd.subtract(BD1000000007.multiply(bd.divide(BD1000000007, BigDecimal.ROUND_DOWN))) ;
	}
	@SuppressWarnings("unused")
	private static BigDecimal mod1000000007(int i) {
		return mod1000000007(new BigDecimal(i)) ;
	}
	@SuppressWarnings("unused")
	private static BigDecimal mod1000000007(long l) {
		return mod1000000007(new BigDecimal(l)) ;
	}

	
	/* main routine */
	public static void main(String args[]) throws IOException {
		int n = getInt();
		int a[] = getIntArray(n);
		int s[] = new int[n];

		System.arraycopy(a, 0, s, 0, n);

		Arrays.sort(s);
		
		for ( int p : a ) {
			System.out.println( p == s[n-1] ? s[n-2] : s[n-1] );
		}
		
	}
}


Measured memory_bytes: 54196
#include <functional>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <string>
#include <cstring>
#include <math.h>
using namespace std;


int main() {
    string s;
    string t;
    int a,b;
    string u;
 
   cin >> s >> t >> a >> b >> u;
  
   if(u==s){
     cout << a-1 << " "<< b <<endl;
   }else{
     cout << a << " "<<b-1 << endl;
   }
   
  
   
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using static System.Console;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        int[] NM = ReadLineParseIntArray();
        int N = NM[0];
        int M = NM[1];
        int[][] s = new int[M][];

        for(int i = 0; i < M; i++)
            s[i] = ReadLine().Split(' ').Skip(1).Select(x => int.Parse(x) - 1).ToArray();

        int[] p = ReadLineParseIntArray();
        int n = (int)Pow(2, N);
        int ans = 0;
        for(int i = 0; i < n; i++)
        {
            bool isOK = true;
            for (int m = 0; m < M; m++)
            {
                int number = 0;
                for (int j = 0; j < s[m].Length; j++)
                {
                    if (((i >> s[m][j]) & 1) == 1)
                        number++;
                }
                if (number % 2 != p[m])
                {
                    isOK = false;
                    break;
                }
            }
            if (isOK) ans++;
        }
        WriteLine(ans);
    }

    static int ReadLineParseInt() => int.Parse(ReadLine());
    static int[] ReadLineParseIntArray() => ReadLine().Split(' ').Select(int.Parse).ToArray();
}

Measured memory_bytes: 13524
import sys
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

def main():
	S, T = input().split()
	print(T+S)

if __name__ == '__main__':
	main()

Measured memory_bytes: 3060
<?php
list($n,$m,$l) = explode(" ",trim(fgets(STDIN)));
for($i = 0; $i < $n; $i++){
    $A[$i] = explode(" ",trim(fgets(STDIN)));
}
for($i = 0; $i < $m; $i++){
    $B[$i] = explode(" ",trim(fgets(STDIN)));
}
for($i = 0; $i < $n; $i++){
    for($j = 0; $j < $l; $j++){
        $C[$i][$j] = 0;
        for($k = 0; $k < $m; $k++){
            $C[$i][$j] += $A[$i][$k] * $B[$k][$j];
        }
    }
    echo implode(" ",$C[$i])."\n";
}


Measured memory_bytes: 14256
import sys
input = sys.stdin.readline

def main():
    S, T = input().strip().split()
    A, B = map(int, input().split())
    U = input().strip()
    if S == U:
        print(A-1, B)
    else:
        print(A, B-1)


if __name__ == "__main__":
    main()

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



typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;
typedef pair<ll, ll> pint;


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

class Dice
{
public:
  vint num;


  Dice(vint num);
  void roll(char d);
  ll face();
  ll right(ll top, ll front);


  bool operator ==(Dice obj){


    return true;
  }



};

Dice::Dice(vint num){
  this->num = num;
}

void Dice::roll(char d){
  vint tmp_num = num;
  if(d == 'E'){
    num[2] = tmp_num[0];
    num[0] = tmp_num[3];
    num[3] = tmp_num[5];
    num[5] = tmp_num[2];
  }else if(d == 'N'){
    num[0] = tmp_num[1];
    num[1] = tmp_num[5];
    num[5] = tmp_num[4];
    num[4] = tmp_num[0];
  }else if(d == 'S'){
    num[0] = tmp_num[4];
    num[4] = tmp_num[5];
    num[5] = tmp_num[1];
    num[1] = tmp_num[0];
  }else if(d == 'W'){
    num[0] = tmp_num[2];
    num[2] = tmp_num[5];
    num[5] = tmp_num[3];
    num[3] = tmp_num[0];
  }else{
    assert(false);
  }
  // cout<<d<<endl;

}

ll Dice::face(){
  return num[0];
}

ll Dice::right(ll top, ll front){
  ll rtn = 1;

  return rtn;

}


void print(const vint& v)
{
  std::for_each(v.begin(), v.end(), [](int x) {
    std::cout << x << " ";
  });
  std::cout << std::endl;
}

int main() {


  cout<<fixed<<setprecision(10);

  vint v1(6);
  rep(i,6)cin>>v1[i];


  Dice d1 = Dice(v1);

  string order; cin>>order;
  rep(i,order.size()){
    d1.roll(order[i]);
  }
  cout<<d1.face()<<endl;
}





//




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

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

    vector<long long int> s(n);
    for(int i=0; i<n; i++){
        cin >> s[i];
    }
    sort(s.begin(),s.end());

    vector<vector<long long int>> dp(n+1, vector<long long int>(x+1));
    for(int j=0; j<=x; j++){
        dp[0][j] = j;
    }

    for(int i=0; i<n; i++){
        for(int j=0; j<=x; j++){
            dp[i+1][j] = (
                dp[i][j % s[i]] // when s[i] is chosen first among s[0] ~ s[i]
              + dp[i][j] * ((i-0+1) - 1) // if not
            ) % MOD;
        }
    }

    cout << dp[n][x] << endl;
    return 0;
}

Measured memory_bytes: 161508
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n;std::cin >> n;
  vll a(n);re(i, n) std::cin >> a[i];
  vvl r = vv(n, 3, 0, ll), l = vv(n, 3, 0, ll);
  vll s(n);re(i, n) s[i] = (i==0?0:s[i-1]) + a[i];

  for(int i=0;i<n;i++){
    ll t = (a[i]%2==0?(a[i]==0?2:0):1);
    ll pre = (i==0?0:s[i-1]);
    ll od = (a[i]%2==1?0:1);
    r[i][0] = t + pre;
    r[i][1] = od + pre;
    r[i][2] = t + pre;
    if(i==0) continue;
    r[i][0] = min(r[i][0], r[i-1][0] + t);
    r[i][1] = min({r[i][1], r[i-1][1]+od, r[i-1][0]+od});
    r[i][2] = min({r[i][2], r[i-1][2]+t, r[i-1][1]+t, r[i-1][0]+t});
  }

  for(int i=n-1;i>=0;i--){
    ll t = (a[i]%2==0?(a[i]==0?2:0):1);
    ll pre = s[n-1]-s[i];
    ll od = (a[i]%2==1?0:1);
    l[i][0] = t + pre;
    l[i][1] = od + pre;
    l[i][2] = t + pre;
    if(i==n-1) continue;
    l[i][0] = min(l[i][0], l[i+1][0]+t);
    l[i][1] = min({l[i][1], l[i+1][1]+od, l[i+1][0]+od});
    l[i][2] = min({l[i][2], l[i+1][2]+t, l[i+1][1]+t, l[i+1][0]+t});
  }
  ll ans = s[n-1];
  for(int i=0;i<n;i++){
    ll m = min({r[i][0], r[i][1], r[i][2]});
    ans = min(ans, m+(s[n-1]-s[i]));
  }
  for(int i=0;i<n;i++){
    ll m = min({l[i][0], l[i][1], l[i][2]});
    ans = min(ans, m+(i==0?0:s[i-1]));
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 25344
#include <iostream>
#include <string>
#include <iterator>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <sstream> 
#include <vector>
#include <cmath>
#include <map>
#include <set>

#include <queue>
#include <iomanip>
#include <functional>

using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define sp system("pause");
#define MOD 998244353 
#define mxN 2005



using namespace std;
void solve()
{
	ll n, k, min_v = -1;
	cin >> n >> k;
	
	if (n < k)
		min_v = min(n, k - n);
	else if (n == k)
		min_v = 0;
	else
	{
		ll modu = n % k;
		min_v = min(modu, k - modu);
	}
	cout << min_v;
}


int main()
{
	fast;
	solve();
	
	return 0;
}

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

int snuke[100] = {0};

int main(){
	int n, k;

	cin >> n >> k;

	for(int i=0; i<k; i++){
		int d;
		cin >> d;
		for(int j=0; j<d; j++){
			int a;
			cin >> a;
			snuke[a-1]++;
		}
	}

	int cnt = 0;
	for(int i=0; i<n; i++){
		if(snuke[i] == 0){
			cnt++;
		}
	}

	cout << cnt << endl;
}


Measured memory_bytes: 3628
/*
 
Coded and Decoded by : Yash Kapoor
 
*/
#include <bits/stdc++.h>
using namespace std;
 
#define ll          long long
#define ld          long double
#define pb          push_back
#define pf          push_front
#define mp          make_pair
#define pll         pair<ll,ll>
#define vl          vector<ll>
#define sl          set<ll> 
#define vll         vector<pll>
#define ml          map<ll,ll>
#define mll         map<pll,ll>
#define all(a)      a.begin(),a.end()
#define x           first
#define y           second
#define sz(x)       (ll)x.size()
#define dl          '\n'
#define why         (ll)1000000007
//#define why         (ll)998244353
#define lp(i,a,b)   for(ll i=a;i<b;++i)
#define lpr(i,a,b)  for(ll i=a;i>=b;i--)
#define lpd(i,x)    for(auto i:x)
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ll inf = 1e18;
ld pi = 3.141592653589;
ll mod = why;
ll fast_power(ll base,ll power,ll mod){
    ll result=1;
    while(power){
        if(power%2)
        result=(result*base)%mod;
        base=(base*base)%mod;
        power/=2;
    }
    return result;
}
 
ll inverse(ll base,ll mod){
    return fast_power(base,mod-2,mod);
}

ll solve(){
    ll n,k; cin>>n>>k;
    vl a(n+1,0);
    lp(i,0,k){
        ll p; cin>>p;
        lp(i,0,p){
            ll r; cin>>r;
            a[r] = 1;
        }
    }
    ll ans = 0;
    lp(i,1,n+1) {
        if(a[i] == 0) ans++;
    }
    cout<<ans;
    return 0;
}

int main(){
    ios
    ll t=1; 
    //cin>>t;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 3620
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var A = sc.ReadInt();
        var B = sc.ReadInt();
        var ans = A * B - (A + B - 1);
        Console.WriteLine(ans);
    }
    static Scanner sc = new Scanner();
}

class Scanner
{
    string[] S = new string[0];
    int Index = 0;
    char[] Separators = new char[] { ' ' };

    public string Next()
    {
        if (this.Index < this.S.Length) return this.S[this.Index++];
        var line = "";
        while (line == "") line = Console.ReadLine();
        this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
        if (this.S.Length == 0) return this.Next();
        this.Index = 0;
        return this.S[this.Index++];
    }
    public string ReadStr()
    {
        return this.Next();
    }
    public char ReadChar()
    {
        return this.Next()[0];
    }
    public int ReadInt()
    {
        return int.Parse(this.Next());
    }
    public uint ReadUInt()
    {
        return uint.Parse(this.Next());
    }
    public long ReadLong()
    {
        return long.Parse(this.Next());
    }
    public double ReadDouble()
    {
        return double.Parse(this.Next());
    }
    public int[] ReadIntArray(int n)
    {
        var array = new int[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadInt();
        }
        return array;
    }
    public long[] ReadLongArray(int n)
    {
        var array = new long[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadLong();
        }
        return array;
    }
    public double[] ReadDoubleArray(int n)
    {
        var array = new double[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadDouble();
        }
        return array;
    }
    public char[] ReadCharArray(int n)
    {
        var array = new char[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadChar();
        }
        return array;
    }
    public string[] ReadStrArray(int n)
    {
        var array = new string[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadStr();
        }
        return array;
    }
}


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

ll single(ll X){
  if(X&1) return ((X+1)/2)&1;
  else return ((X/2)&1)^X;
}

int main(){
  ll A, B;cin>>A>>B;
  ll ans;
  if(A==0){ans=single(B);}else{
    ans=single(A-1)^single(B);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ls(x) (x)<<1
#define rs(x) (x)<<1|1
#define fu(i,r,t) for(int i=r;i<=t;i++)
#define fd(i,r,t) for(int i=r;i>=t;i--)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define endl '\n'
#define lcm(a,b) (a*b)/__gcd(a,b)
#define Case(i,ans) cout<<"Case "<<i<<": "<<ans<<endl;
#define cp(i,ans) printf("%.if",ans);
#define cpp(i,ans) cout<<setprecision(i)<<fixed<<ans<<endl;
#define ppb pop_back
#define ppf pop_front
#define pb push_back
#define pf push_front
#define pq priority_queue
#define lowbit(x) (x)&(-x)
#define all(V) V.begin(),V.end()
#define ms multiset
#define mod(x) (x)%mo_num
#define vc vector
#define vct vector<int>
#define fa(i,V) for(auto i:V)
#define out(i) cout<<i<<endl;
#define fi first
#define sc second
#define fun(i) fu(i,1,n)
#define fut(i) fu(i,1,t)
#define fum(i) fu(i,1,m)
//#define P pair<int,int>
using namespace std;
const int INF=1e17+5;
const int maxn=2e7+5;
const int mo_num=1e9;
int n,m,a[maxn],b[maxn],ans;
struct node{
    int x,y;
}t[maxn];
int cal(int d,int e,int f)
{

    return abs((t[d].x*t[e].y-t[e].x*t[d].y)+(t[e].x*t[f].y-t[f].x*t[e].y)+(t[f].x*t[d].y-t[d].x*t[f].y));
}
int32_t main()
{
    IOS
    cin>>n;

    t[1]={0,0};
    int q=sqrt(n);
    int x1,y1,x2,y2;
    if(q==mo_num)
    {
        x1=mo_num;
        y2=mo_num;
        x2=0,y1=0;
    }else{
        q++;
        x1=y2=q;
        x2=1,y1=q*q-n;
    }
    cout<<0<<" "<<0<<" "<<x1<<" "<<y1<<" "<<x2<<" "<<y2;
//    fu(i,q,q+maxn)
//    {
//        if(n/i*i==n && max(i,n/i)<=mo_num)
//        {
//            cout<<i<<" "<<0<<" "<<0<<" "<<n/i;
//            return 0;
//        }
//    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	private static final String[] reversedWords = {"dream", "dreamer", "erase", "eraser"};

	public static void main(String[] args) {
		String s;
		try (Scanner scanner = new Scanner(System.in)) {
			s = scanner.next();
		}

		boolean canObtain = s.replace("eraser",  "")
				.replace("erase",   "")
				.replace("dreamer", "")
				.replace("dream",   "")
				.isEmpty();

		if (canObtain) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}

Measured memory_bytes: 28644
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<utility>
#include<cstdio>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include <bitset>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,x,n) for (int i= x;i<n;i++)
#define all(v) v.begin(), v.end()
using ll = long long;
using vi = vector<int>; 
using vvi = vector<vi>;
typedef pair<int,int> P;
string s;
int k;
ll INF = 10000000000000000;

int H,W;
int dh[]={1,0,-1,0};
int dw[]={0,1,0,-1};


int main(){
    cin >>H>>W;
    int ans=0;

    vector<string> grid(H);
    rep(i,H) cin >> grid[i];

    queue<P> q;
    queue<P> r;

    rep(i,H){
        rep(j,W){
            if(grid[i][j] == '#')   q.push(make_pair(i,j));
        }
    }

    while(!q.empty()||!r.empty()){
        while(!q.empty()){

            int  h =q.front().first;
            int  w =q.front().second;
            q.pop();

            rep(dir,4){
                int nh = h+dh[dir];
                int nw = w+dw[dir];

                if(nh<0||nw<0||nh==H||nw==W) continue;
                if(grid[nh][nw]=='#') continue;

                grid[nh][nw] = '#';
                r.push(make_pair(nh,nw));
            }
        }
        ans++;
        swap(q,r);
        queue<P>().swap(r);
    }
    cout << ans-1<<endl;
}

Measured memory_bytes: 9488
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, d, r;
  double f;
  cin >> a >> b;
  d = a / b;
  r = a % b;
  f = 1.0 * a / b;

  cout << d  << " " << r << " " << fixed << setprecision(5) << f << endl;
}


Measured memory_bytes: 3260
/*
ID: zhaowei10
TASK:
LANG: C++
*/
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define mp make_pair
#define eb emplace_back
#define pb push_back
#define MOD 1000000007
#define NDIG(x) floor(log10(x)) + 1
#define FOR(i, j, k, l) for (s32 i = j; i < k; i += l)
#define RFOR(i, j, k, l) for (s32 i = j; i >= k; i -= l)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define ALL(x) x.begin(), x.end()
#define MEAN(a, b) min(a, b) + (abs(b - a) >> 1)
#define FASTIO()    \
  cin.tie(nullptr); \
  ios::sync_with_stdio(false);

typedef long long ll;
typedef int64_t s64;
typedef uint64_t u64;
typedef int32_t s32;
typedef uint32_t u32;
typedef float f32;
typedef double f64;
typedef long double f80;
typedef pair<s32, s32> II;
typedef pair<s64, s64> LL;
typedef vector<s32> VI;
typedef vector<II> VII;
typedef vector<char> VC;
typedef vector<VII> VVII;
typedef priority_queue<s32> PQI;
typedef priority_queue<s32, VI, greater<s32>> PQIA;
typedef priority_queue<s64> PQL;
typedef priority_queue<II> PQII;
typedef priority_queue<II, VII, greater<II>> PQIIA;
typedef priority_queue<LL> PQLL;
typedef unordered_set<s32> USI;
typedef unordered_set<s64> USL;
typedef set<II> SII;
typedef multiset<s32> MSI;

int main() {
  FASTIO();

  ll h;
  cin >> h;

  ll divby2cnt = 0;
  while (h > 0) {
    h >>= 1;
    divby2cnt++;
  }

  cout << fixed << (ll)pow(2, divby2cnt) - 1;
}

/*
1 - 1 (2^0 = 2^1-1)
2, 1 1 - 3 (2^1 = 2^2-1)
3, 1 1 - 3 (2^2-1 = 2^2-1)
4, 2 2, 1 1 1 1 - 7
5, 2 2, 1 1 1 1 - 7
6, 3 3, 1 1 1 1 - 7
7, 3 3, 1 1 1 1 - 7
8, 4 4, 2 2 2 2, 1 1 1 1 1 1 1 1 - 15
9 - 15
10 - 15
11 - 15
12, 6 6, 3 3 3 3, 1 1 1 1 1 1 1 1 - 15
13 - 15
14 - 15
15 - 15
16 - 31
*/

Measured memory_bytes: 888
numbers = list(map(int, input().split()))

sorted_num = sorted(numbers)

maximum = max(numbers)
second_max = sorted_num[1]
minimum = min(numbers)

first_step = (maximum - second_max) // 2
second_step = (maximum - minimum) // 2

if (maximum - second_max) % 2 == 1 and (maximum - minimum) % 2 == 1:
    first_step += 1
if (maximum - second_max) % 2 == 1 and (maximum - minimum) % 2 == 0:
    first_step += 2
if (maximum - second_max) % 2 == 0 and (maximum - minimum) % 2 == 1:
    first_step += 2
print(first_step + second_step)

Measured memory_bytes: 3064
n,m=map(int,input().split())
if ((n<0 and m>0) or n==0 or m==0):
    print("Zero")
if (n>0 and m>0):
    print('Positive')
if (m<0):
    if ((m-n)%2==0):
        print("Negative")
    else:
        print("Positive")

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <tuple>
#include <algorithm>
#include <array>
using namespace std;
#define rep(i,n) for(int i=0; i<n; ++i)
using ll = long long;

ll n=0, wmax=0;
vector<ll> w, v;

ll dp[100][100000];

ll f(int i, ll weight) {
    if (i >= n)
        return 0;
    if (weight < 0)
        return 0;

    if (dp[i][weight] != -1)
        return dp[i][weight];

    ll va = f(i+1, weight);
    ll vb;
    ll result;
    if (weight >= w[i]) {
        vb = f(i+1, weight - w[i]);
        result = std::max(va, vb + v[i]);
    } else {
        result = va;
    }
    dp[i][weight] = result;
    return result;
}

int main() {
    rep(i,100) rep(j,100000) dp[i][j] = -1;
    cin >> n >> wmax;
    w.resize(n);
    v.resize(n);
    rep(i,n) cin >> w[i] >> v[i];

    ll ans = f(0, wmax);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 81192