akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

var stdin = bufio.NewReaderSize(os.Stdin, 1000000)

func readLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, _ := stdin.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func nextStr() []string {
	line := readLine()
	line_ := strings.Split(line, "")
	return line_
}
func moveWhite(s []string) int {
	ans := 0
	whiNext := 0
	for i := 0; i < len(s); i++ {
		if s[i] == "W" {
			ans += i - whiNext
			whiNext++
		}
	}
	return ans
}
func main() {
	str := nextStr()
	ans := moveWhite(str)
	fmt.Println(ans)
}


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

namespace program
{
    class Program
    {
        static void Main()
        {
          int[] a = Input.ScanIntArray();
          
          Console.WriteLine(a[0]<=a[1] ? a[0] : a[0]-1);
        }
    }

    static class Input
    {
        static public int ScanInt() { return int.Parse(Console.ReadLine()); }
        static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
        static public double ScanDouble() { return double.Parse(Console.ReadLine()); }
        static public long ScanLong() { return long.Parse(Console.ReadLine()); }
        static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
        static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); }
        static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); }
        static public double[] ScanDoubleArray() { return Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToArray(); }
        static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); }
        static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); }

        static public string ScanStr() { return Console.ReadLine(); }
        static public string[] ScanStrArray() { return ScanStr().Split(' '); }
    }

    static class MyMath
    {
        public static int GCD(int a, int b)
        {
            Func<int, int, int> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static ulong GCD(ulong a, ulong b)
        {
            Func<ulong, ulong, ulong> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static int LCM(int a, int b)
        {
            return a * b / GCD(a, b);
        }
        public static ulong LCM(ulong a, ulong b)
        {
            return a * b / GCD(a, b);
        }
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <cstdio>
#include <algorithm>
#include <map>
using namespace std;

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

int main() {
    int n, x, d = 0, ans = 1;
    cin >> n >> x;
    rep(i, n){
        int l;
        cin >> l;
        d += l;
        if(d <= x) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string s;
char ss[9][6]={".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
cin>>n;
while(n--&&cin>>s){
int l=s.size();
int p=-1;
for(int i=0;i<l;++i) {
if(p<0){
if(s[i]!='0')p=(s[i]-'1')*10;
}else{
if(s[i]=='0'){
cout<<ss[p/10][p%10];
p=-1;
}else p=(p/10*10)+(p%10+1)%strlen(ss[p/10]);
}
}
cout<<endl;
}
}

Measured memory_bytes: 3056
(defparameter n (read-line))
(defparameter digit (read-from-string n))
(defparameter total 
  (reduce #'(lambda (m x) (+ x m)) 
    (mapcar (lambda (x) (parse-integer (string x))) (coerce n 'list))))

(if (= (mod digit total) 0) (princ "Yes") (princ "No"))

Measured memory_bytes: 9444
//
// 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 mut $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")
    };
}

// solution 
#[allow(unused_mut)]
#[allow(non_snake_case)]
fn main() {
    input! {
        N: usize,
        S: chars,
        K: usize1,
    }
    let c = S[K];
    for ind in 0..N {
        if S[ind] != c {
            S[ind] = '*';
        }
    }

    println!("{}", S.into_iter().collect::<String>());
}



Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fr first
#define sc second
#define ll  long long
#define mp make_pair
#define mod 1000000007

using namespace std;

int dx[]={0,0,-1,1,1,1,-1,-1};
int dy[]={0,0,-1,1,1,-1,1,-1};
vector<vector<int> > a;
int main()  {
    ll n,m;

    cin>>n>>m;
    if(n == 1 && m== 1){
        cout<<1;
        return 0;
    }
    if(n == 1 || m ==1){
        cout<<max(n,m)-2;
        return 0;
    }
    ll r = (n-2)*(m-2);

    cout<<r;
    return 0;
}


Measured memory_bytes: 256
def abc():
    input()
    h = list(map(int, input().rstrip().split()))

    c = 0
    for i, x in enumerate(h):
        viewable = True
        for j in range(i+1):
            if h[j] > h[i]:
                viewable = False
        else:
            if viewable:
                c += 1
    print(c)


abc()


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

vector<int> v[100005];
int a[100005];
int b[100005];
int visa[100005];
int visb[100005];

void dfs(int n , int x[] , int y[])
{
    y[n] = 1;

    for(int i = 0 ; i<v[n].size() ; i++)
    {
        if(y[v[n][i]]==0){
        x[v[n][i]]+=(x[n]+1);
        dfs(v[n][i] , x , y);
        }
    }
}

int main()
{
    int n;

    cin >> n;

    for(int i = 1 ; i<n ; i++)
    {
        int x , y;

        cin >> x >> y;

        v[x].push_back(y);
        v[y].push_back(x);
    }

    dfs(1 , a , visa);
    dfs(n , b , visb);

    int black = 0 , white = 0;

    for(int i = 2 ; i<n ; i++)
    {
        if(a[i]<=b[i])
        {
            black++;
        }
        else
        {
           white++;
        }
    }
    if(black>white)
    {
        cout << "Fennec";
        return 0;
    }
    else
    {
        cout << "Snuke";
        return 0;
    }
}


Measured memory_bytes: 13568
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<cmath>
using namespace std;
#define N 100005
typedef long long ll;

ll s=0;

int main(){
	int n,i;
	cin>>n;
	for(i=1;i<=n;i++){
		if(i%3==0||i%5==0)
		continue;
		else
		s+=i;
	}
	cout<<s;
	return 0;
}

Measured memory_bytes: 3636
# ENV[Z = 'RUBY_THREAD_VM_STACK_SIZE'] || exec( { Z => '50000000' },'ruby',$0)
# readlines.map(&:chomp!).map { |e| e.split.map(&:to_i) }
# gets.split.map(&:to_i)
#
#

a,b = gets.split.map(&:to_i)

de = 1
count = 0
while de < b
  count += 1
  de = de -1 + a
end

puts count


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

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  for (int i=0; i<n; i++){
    cin >> d[i];
  }
  
  int ans = 0;
  for (int i=0; i<n; i++){
    for (int j=0; j<i; j++){
      ans += d[i]*d[j];
    }
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define N 310
using namespace std;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}


#define rank Asdfiasofsad
int n;
int D[N][N],ans[N][N];

void WF(int dp[N][N]){

  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++) if(i!=j && dp[i][j] == 0) dp[i][j] = INF;
  
  for(int k=0;k<n;k++)
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++) Min(dp[i][j],dp[i][k]+dp[k][j]);
  
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++) if(dp[i][j] == INF) dp[i][j] = 0;
  
}

bool same(int a[N][N],int b[N][N]){
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++) if(a[i][j]!=b[i][j]) return 0;
  return 1;
}

void cp(int from[N][N],int to[N][N]){
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++) to[i][j] = from[i][j];
}

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

int solve(){
  int tmp[N][N];cp(D,tmp);WF(tmp);
  if(!same(D,tmp)) return -1;

  for(int i=0;i<n;i++)
    for(int j=i+1;j<n;j++) edge.push_back(PP(D[i][j],P(i,j)));
  sort(edge.begin(),edge.end());
  
  for(int i=0;i<n;i++)
  for(int j=0;j<n;j++)if(ans[i][j] == 0) ans[i][j] = (i!=j)*INF;

  int res = 0;
  
  for(PP e:edge){
    int a = e.second.first;
    int b = e.second.second;
    int c = e.first;
    
    for(int i=0;i<n;i++) Min(ans[a][b], ans[a][i]+ans[i][b]);
    if(ans[a][b] < c) return -1;
    if(ans[a][b] != c) res += c;
    ans[a][b] = ans[b][a] = c;
    for(int i=0;i<n;i++) Min(ans[i][a],Min(ans[a][i] ,ans[a][b]+ans[b][i]));
    for(int i=0;i<n;i++) Min(ans[i][b],Min(ans[b][i] ,ans[b][a]+ans[a][i]));
  }
  
  WF(ans);
  if(!same(ans,D)) return -1;
  return res;
}

signed main(){
  cin>>n;
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)cin>>D[i][j];

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


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

int main()
{
    lint Q, H, S, D, N;
    cin >> Q >> H >> S >> D >> N;
    vector<lint> v;
    v.push_back(S);
    v.push_back(2 * H);
    v.push_back(4 * Q);
    sort(v.begin(), v.end());
    
    vector<lint> w;
    w.push_back(v[0] * N);
    w.push_back(N / 2 * D + N % 2 * v[0]);
    sort(w.begin(), w.end());
    cout << w[0] << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <unordered_map>
#include <cstring>
#include <chrono>
#include <vector>
#include <map>
#include <random>
#include <set>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <deque>
#include <cassert>
#include <stack>
using namespace std;
 
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define ll long long
#define y1 abcde
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>
#define BUG cout << "acdsfas" << endl

const int mod = 1e9 + 7;
const int inf = 2e9;
const int N = 1e5 + 15;
int n, m, dp[N], dp2[N], exc[N], exc2[N];
vector <int> g[N], p[N], revp[N];

inline int multiply(int a, int b) {
    return ((ll)a * b) % m;
}

inline int add(int a, int b) {
    return (a + b) % m;
}

void dfs(int v, int par = -1) {
    dp[v] = 1;
    for(int i = 0; i < g[v].size(); ++i) {
        int to = g[v][i];
        if(to != par) {
            dfs(to, v);
            p[v][i] = multiply(i ? p[v][i-1] : 1, dp[to] + 1);
            dp[v] = multiply(dp[v], dp[to] + 1);
        }
        else
            p[v][i] = i ? p[v][i-1] : 1;
    }
    for(int i = (int)g[v].size() - 1; i >= 0; --i) {
        int to = g[v][i];
        if(to != par)
            revp[v][i] = multiply(revp[v][i+1], dp[to] + 1);
        else
            revp[v][i] = revp[v][i+1];
    }
    for(int i = 0; i < g[v].size(); ++i) {
        int to = g[v][i];
        if(to != par)
            exc[to] = multiply(i ? p[v][i-1] : 1, revp[v][i+1]);
    }
    dp2[v] = 1;
}

void recalc(int v, int par = -1) {
    for(int i = 0; i < g[v].size(); ++i) {
        int to = g[v][i];
        if(to != par) {
            dp2[to] = add(multiply(dp2[v], exc[to]), 1);
            recalc(to, v);
        }
    }
}

main() {
    scanf("%d %d", &n, &m);
    for(int i = 1; i < n; ++i) {
        int u, v;
        scanf("%d %d", &u, &v);
        g[u].pb(v);
        g[v].pb(u);
    }
    for(int v = 1; v <= n; ++v)
        p[v].resize(g[v].size() + 1, 1),
        revp[v].resize(g[v].size() + 1, 1);
    dfs(1);
    recalc(1);
    for(int i = 1; i <= n; ++i)
        printf("%d\n", multiply(dp2[i], dp[i]));
    return 0;
}

Measured memory_bytes: 25856
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<vector<int>> vec(N,vector<int>(2));
  for(int i=0; i<N; i++){
    for(int j=0; j<2; j++){
      cin >> vec.at(i).at(j);
    }
  }
  
  map<pair<int,int>,int> mp;
  pair<int,int> P;
  pair<int,int> Q;
  for(int i=0; i<N-1; i++){
    int px = vec.at(i).at(0);
    int py = vec.at(i).at(1);
    for(int j=i+1; j<N; j++){
      int qx = vec.at(j).at(0);
      int qy = vec.at(j).at(1);
      P = make_pair(px-qx,py-qy);
      Q = make_pair(qx-px,qy-py);
      if(mp.count(P)){
        mp[P]++;
      }
      else{
        mp[P] = 1;
      }
      if(mp.count(Q)){
        mp[Q]++;
      }
      else{
        mp[Q] = 1;
      }
    }
  }
  
  int max_mp = 0;
  for(auto itr = mp.begin(); itr != mp.end(); itr++){
    int x = itr->second;
    max_mp = max(max_mp,x);
  }
  cout << N - max_mp << endl;
}   

Measured memory_bytes: 384
#include<cstdio>

int h, w;
char grid[12][12+1];

bool solve3(int sy[]) {
	bool used[12];
	for(int i=0;i<h;i++) used[i] = false;
	bool mid_used = h % 2 == 0;
	for(int i=0;i<h;i++) if(!used[i]) {
		bool ok = false;
		for(int j=i+1;j<h;j++) if(!used[j]) {
			bool same = true;
			for(int k=0;k<w;k++) {
				if(grid[i][sy[k]] != grid[j][sy[w-1-k]]) same = false;
			}
			if(same) {
				used[i] = used[j] = true;
				ok = true;
				break;
			}
		}
		if(!ok && !mid_used) {
			bool same = true;
			for(int k=0;k<w/2;k++) {
				if(grid[i][sy[k]] != grid[i][sy[w-1-k]]) same = false;
			}
			if(same) {
				used[i] = true;
				mid_used = true;
				ok = true;
			}
		}
		if(!ok) return false;
	}
	return true;
}

bool solve2(bool used[], int ind, int sy[]) {
	if(w-2*ind <= 1) {
		return solve3(sy);
	} else {
		for(int i=0;i<w;i++) if(!used[i]) {
			sy[ind] = i;
			break;
		}
		used[sy[ind]] = true;
		for(int i=0;i<w;i++) if(!used[i]) {
			used[i] = true;
			sy[w-1-ind] = i;
			if(solve2(used, ind+1, sy)) return true;
			used[i] = false;
		}
		used[sy[ind]] = false;
		return false;
	}
}

bool solve() {
	bool used[12];
	for(int i=0;i<w;i++) used[i] = false;
	int sy[12];
	if(w % 2 == 1) {
		for(int i=0;i<w;i++) {
			used[i] = true;
			sy[w/2] = i;
			if(solve2(used, 0, sy)) return true;
			used[i] = false;
		}
		return false;
	} else {
		return solve2(used, 0, sy);
	}

}

int main() {
	scanf("%d %d", &h, &w);
	for(int i=0;i<h;i++) {
		scanf("%12s", grid[i]);
	}
	printf("%s\n", solve() ? "YES" : "NO");
	return 0;
}


Measured memory_bytes: 128
l=input().split()
n=int(l[0])
m=int(l[1])

#receive vecter a(n*m)
i=0
A=[]
while i<n:
    a=input().split()
    for p in a:
        A.append(int(p))
    i+=1

#receive vecter b(m*1)
I=0
B=[]
while I<m:
    b=int(input())
    B.append(b)
    I+=1

#Ci=ai1b1+ai2b2+...+aimbm
#C[i]=a[m*(i)+1]*b[1]+a[m*(i)+2]*b[2]+...a[m*(i)+m]*b[m]
q=0
C=[]
while q<n:
    Q=0
    cq=0
    while Q<m:
        cq+=A[m*q+Q]*B[Q]
        Q+=1
    C.append(cq)
    q+=1

for x in C:
    print(x)


Measured memory_bytes: 5948
import math
import collections
import bisect
from collections import deque
from copy import copy, deepcopy
import time

import numpy as np
import numba
from numba import njit, b1, i4, i8, f8
from numba import jit

mod = 998244353


def main():
    N,K = map(int,input().split())
    R = []
    L = []
    ans = [0 for i in range(N+1)]
    cumsum = [0 for i in range(N+1)]
    ans[1]=1
    ans[2]=-1
    cumsum[1]=1
    for i in range(K):
        r,l = map(int,input().split())
        R.append(r)
        L.append(l)
    for i in range(1,N+1):
        #print(i)
        #print("ans",ans)
        #print("cumsum",cumsum)
        for j in range(K):
            if i+R[j]<=N:
                ans[i+R[j]]+=cumsum[i]
                ans[i+R[j]]%=mod
            if i+L[j]+1<=N:
                ans[i+L[j]+1]-=cumsum[i]
                ans[i+L[j]+1]%=mod
        if i<N:
            cumsum[i+1]=cumsum[i]+ans[i+1]
            cumsum[i+1]%=mod
        
    print(cumsum[N]%mod)
if __name__ == '__main__':
    main()

Measured memory_bytes: 108116
import java.util.ArrayList;
import java.util.Scanner;

class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int k = sc.nextInt();
        ArrayList<Integer> a = new ArrayList<>();

        for(int i = 0; i < n ; i++){
            a.add(sc.nextInt());
        }
        if((n - 1)%(k - 1) != 0){
            System.out.println((n - 1)/(k - 1)+1);
        }else{
            System.out.println((n - 1)/(k - 1));
        }

    }
}

Measured memory_bytes: 58416
# 入力値を数値で返す
def gets_i()
  gets.chomp.to_i
end

N = gets_i
a_list = [1]
N.times do
  a_list.push gets_i
end

unless a_list.include?(2)
  puts -1
  exit
end

next_pos = a_list[0]
count = 0
while true do
  if count >= N
    puts -1
    exit
  end
  if next_pos == 2
    puts count
    exit
  end
  count += 1
  next_pos = a_list[next_pos]
end


Measured memory_bytes: 4732
#include <algorithm>
#include <iostream>
#include <tuple>
#include <vector>

using namespace std;
using ll = long long;

const ll MOD = 1000000007;

template <typename T, typename U>
T mypow(T b, U n) {
    if (n == 0) return 1;
    if (n == 1) return b % MOD;
    if (n % 2 == 0) {
        return mypow(b * b % MOD, n / 2);
    } else {
        return mypow(b, n - 1) * b % MOD;
    }
}

int N, M;
tuple<ll, int, int> edges[2010];

class UnionFind {
public:
    explicit UnionFind(int N) : V_NUM(N) {
        par.resize(V_NUM);
        rank.resize(V_NUM);
        num.resize(V_NUM);

        for (int i = 0; i < V_NUM; ++i) {
            par[i] = i;
        }
        fill(rank.begin(), rank.end(), 0);
        fill(num.begin(), num.end(), 1);
    }

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

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

        if (x == y) return;

        if (rank[x] < rank[y]) swap(x, y);

        num[x] += num[y];
        par[y] = x;
        if (rank[x] == rank[y]) ++rank[x];
    }

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

    bool ispar(int x) {
        return x == find(x);
    }

    int size(int x) {
        return num[find(x)];
    }

    const int INF = 1 << 25;
    int V_NUM;
    vector<int> par, rank, num;
};

ll kruskal(int id) {
    UnionFind uf(N);

    int u, v;
    ll w;

    tie(w, u, v) = edges[id];
    ll ret = w;
    uf.unite(u, v);

    for (int i = 0; i < M; ++i) {
        tie(w, u, v) = edges[i];
        if (uf.same(u, v)) continue;

        ret += w;
        uf.unite(u, v);
    }

    return ret;
}

int main() {
    ll X;
    cin >> N >> M >> X;

    for (int i = 0; i < M; ++i) {
        int u, v;
        ll w;
        cin >> u >> v >> w;
        edges[i] = make_tuple(w, u - 1, v - 1);
    }

    sort(edges, edges + M);

    int cnt[3] = {0, 0, 0};
    for (int i = 0; i < M; ++i) {
        ll cost = kruskal(i);
        ++cnt[cost < X ? 0 : (cost == X ? 1 : 2)];
    }

    if (cnt[1] == 0) {
        cout << 0 << endl;
    } else if (cnt[0] == 0) {
        cout << (mypow(2LL, cnt[1]) - 2) * mypow(2LL, cnt[2]) % MOD << endl;
    } else {
        cout << 2 * (mypow(2LL, cnt[1]) - 1) * mypow(2LL, cnt[2]) % MOD << endl;
    }
    return 0;
}


Measured memory_bytes: 256
S = input()
dp = [0]*(len(S) + 1)
dp[0] = 1

words=['dream', 'dreamer', 'erase', 'eraser']
done = 'NO'

for i in range(len(S)):
    if dp[i] == 0:
        continue
    for w in words:
        if S[i:i + len(w)] == w:
            dp[i + len(w)] = 1
            
    if dp[len(S)] ==1:
        done = 'YES'
        break
        
print(done)

Measured memory_bytes: 3956
#include <iostream>
#include <vector>
using namespace std;
int main(){
    int q,n,p,x;
    cin>>q;
    
    vector<int> A;
    
    for(int i=0;i<q;i++){
        cin>>n;
        //cout<<"n:"<<n<<endl;
        if(n==0){
            cin>>x;
            A.push_back(x);
        }
        else if(n==1){
            cin>>p;
           cout<< A.at(p)<<endl;
        }
        else if(n==2){
            A.pop_back();
        }
    }
    return 0;
}



Measured memory_bytes: 3820
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 1000000007;
const ll MAX = 200001;

ll mod(ll a){
  return a % MOD;
}

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

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll 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;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

int main(){
  string s; cin >> s;
  bool isfirstA = false;
  ll Ccount = 0;
  ll largecount = 0;
  
  ll n = s.size();
  
  if(s[0] == 'A') isfirstA = true;
  
  for(ll i=2; i <= n-2; i++){
    if(s[i] == 'C') Ccount++;
  }
  
  rep(i,n){
    rep(j,26){
      if(s[i] == large[j]) largecount++;
    }
  }
  
  if(isfirstA and Ccount == 1 and largecount == 2){
    cout << "AC" << endl;
  }
  else cout << "WA" << endl;
  
  
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

signed main(){

  int n; cin >> n;
  if(n == 1){
    cout << 1 << endl;
    return 0;
  }

  static int dp[10101010];
  for(int i = 1; i <= n; i++){
    dp[i] = dp[i-1] + i;
    if(dp[i] > n){
      for(int j = 1; j <= i; j++){
        if(dp[i] - j == n){
          for(int k = 1; k <= i; k++){
            if(k == j) continue;
            cout << k << endl;
          }
          return 0;
        }
      }
    }
  }

  return 0;
}


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

# 整数 n を m 進数 k 桁で表現した文字列
# ex. bins(3,2,2) => 11
def bins(n, m, k):
    # n がマイナスだったり、k桁で収まらない場合やばそう
    s = ""
    while n > 0:
        s = str(n%m) + s
        n //= m
    s = "0"*(k-len(s)) + s
    return s

def main():
    s = input().strip()
    n = len(s)-1 # s の各文字（"+" を入れるスキマ）の数
    ans = 0
    # s の各文字の間に "+" を挿入する・しない場合の
    # 全ての文字列 (2**n 通り) を作って計算する
    for i in range(2**n):
        b = bins(i,2,n)
        t = s[0]
        for j in range(n):
            if b[j] == "1":
                t += "+"
            t += s[j+1]
        ans += eval(t)
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
#include <map>
#include <iomanip>

using namespace std;

void solve(){
    int n;
    cin >> n;
    vector<int> a(n-1);
    vector<int> b(n, 0);
    for(int i=0; i<n-1; i++) cin >> a[i];
    for(auto e: a)
        b[e-1]++;
    for(auto e: b)
        cout << e << endl;
}

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(16);
    
    solve();

    return 0;
}


Measured memory_bytes: 4792
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#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++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;

int main(){
    int n,k;cin>>n>>k;
    vin d(k);
    vvin a(k,vin(n));
    rep(i,k){
        cin>>d[i];
        rep(j,d[i])cin>>a[i][j];
    }
    vin ans(n,0);
    rep(i,k){
        rep(j,d[i])ans[a[i][j]-1]++;
    }
    int sum=0;
    rep(i,n){
        if(ans[i]==0)sum++;
    }
    cout<<sum<<endl;
}

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

#define ll long long
#define INF 1e9
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
inline void Fail(){
	printf("0");
	exit(0);
}

const int maxn=2005;
int n,m,q;
int a[maxn][maxn];
char c[maxn];
int sum[maxn][maxn],sum2[maxn][maxn],sum3[maxn][maxn];

int main(){
	scanf("%d%d%d",&n,&m,&q);
	REP(i,n){
		scanf("%s",c);
		rep(j,m)a[i][j+1]=c[j]=='1';
		REP(j,m){
			sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+a[i][j];
			sum2[i][j]=sum2[i-1][j]+sum2[i][j-1]-sum2[i-1][j-1]+(a[i][j]&&a[i][j-1]);
			sum3[i][j]=sum3[i-1][j]+sum3[i][j-1]-sum3[i-1][j-1]+(a[i][j]&&a[i-1][j]); 
		}
	}
	while(q--){
		int r1,c1,r2,c2;
		scanf("%d%d%d%d",&r1,&c1,&r2,&c2);
		int ans=0;
		ans+=sum[r2][c2]-sum[r1-1][c2]-sum[r2][c1-1]+sum[r1-1][c1-1];
		ans-=sum2[r2][c2]-sum2[r1-1][c2]-sum2[r2][c1]+sum2[r1-1][c1];
		ans-=sum3[r2][c2]-sum3[r1][c2]-sum3[r2][c1-1]+sum3[r1][c1-1];
		printf("%d\n",ans);
	}
	return 0;
}

/*
Input:
-----------------
Output:
*/

Measured memory_bytes: 64640
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>

#define rep(i,n) for(int i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;

int main() {
	string s, t;
	cin >> s >> t;
	// check: tに使われている文字が，sに含まれているか
	map<char, vector<ll>> s_dic;
	rep(i, s.size()) {
		s_dic[s[i]].push_back(i);
	}
	rep(i, t.size()) {
		if(s_dic[t[i]].empty()) {
			cout << -1 << endl;
			return 0;
		} 
	}

	//ll ans = 0;
	ll cnt = 0;
	rep(i, t.size()) {
		//cout << "search: " << t[i] << endl;
		ll place = cnt%s.size();

		if(place>s_dic[t[i]][s_dic[t[i]].size()-1]) {
			cnt += s.size() - place;
			place = 0;
		}
		//tmp = s_dic[t[i]];
		ll left = -1, right = s_dic[t[i]].size();
    while(right-left>1) {
			ll mid = left + (right - left) /2;
			if(place<=s_dic[t[i]][mid]) right = mid;
			else left = mid;
		}
    /* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
		cnt += s_dic[t[i]][right] - place + 1;
		place = s_dic[t[i]][right] + 1;
		
		//cout << "check " << cnt << endl;
	}

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


Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int long long
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

signed main() {
    int n;
    cin >> n;
    int m = n;
    vector<int> vec;
    for (int i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            n /= i;
            vec.push_back (i);
        }
    }
    if (n != 1) vec.push_back (n);
    printf ("%lld:", m);
    for (int i : vec) printf (" %lld", i);
    cout << "\n";
}


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

using namespace std;

int main()
{
    int N, a, b;
    cin >> N;
    vector<int> v;

    for (int i = 0; i < N; i++)
    {
        cin >> a;
        v.push_back(a);
    }

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

    int i = v.size();
    cout << v[i - 1] - v[0];
}

Measured memory_bytes: 256
MOD=10**9+7
cnt=0; sum=0
#h=Hash.new(0)

def gs(): return input()
def gi(): return int(input())
def gsmi(): return [int(n) for n in input().split()]
# min,max,sum,sorted
def desc(ar): return sorted(ar,reverse=True)
def printend(s): print(s);import sys;sys.exit()
###
n=gi()
print("ABC" if n<=999 else "ABD")

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

int main(){
    ll N; cin >> N;
    int ans = to_string(N).size();

    rep(i, (int)sqrt(N)){
        if((N % i) == 0){
            int a = to_string((ll)(N/i)).size();
            ans = min(ans, a);
        }
    }
    cout << ans << endl;
}



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

int main(){
    int a,b,c,d;
    int imos[101]={};
    cin >> a >> b >> c >> d;
    imos[a]++;
    imos[b]--;
    imos[c]++;
    imos[d]--;
    for(int i=0;i<100;i++){
        imos[i+1]+=imos[i];
    }
    int ans=0;
    for(int i=0;i<=100;i++){
        if(imos[i]==2) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);
		if (a[n - 1] == 0) {
			System.out.println("Yes");
			return;
		}
		if (n % 3 != 0) {
			System.out.println("No");
			return;
		}
		if (a[0] == 0) {
			if (a[n / 3 - 1] == 0 && a[n / 3] == a[n - 1]) {
				System.out.println("Yes");
				return;
			}
		}
		if (a[0] == a[n / 3 - 1] && a[n / 3] == a[n * 2 / 3 - 1] && a[n * 2 / 3] == a[n - 1] && (a[0] ^ a[n / 3] ^ a[n - 1]) == 0) {
			System.out.println("Yes");
			return;
		}
		System.out.println("No");
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	private int readByte() {
		if (hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}
	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}
	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
		return hasNextByte();
	}
	public String next() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	public long nextLong() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || Integer.MAX_VALUE < nl) {
			throw new NumberFormatException();
		}
		return (int) nl;
	}
	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

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

#define MAX_N 500000

long long count = 0;
int A[MAX_N+1];

void merge(int left, int mid, int right) {
	int n1 = mid - left;
	int n2 = right - mid;
	int L[n1 + 1]; int R[n2 + 1];

	for(int i = 0; i < n1; i++) {
		L[i] = A[left + i];
	}

	for(int i = 0;i < n2; i++) {
		R[i] = A[mid + i];
	}

	L[n1] = R[n2] = 0x7FFFFFFF;
	int i = 0, j = 0;

	for(int k = left; k < right; k++) {
		if(L[i] <= R[j]) {
			A[k] = L[i];
			i++;
		}
		else {
			if(i != n1) {
				count += n1 - i;
			}
			A[k] = R[j];
			j++;
		}
	}
}

void merge_sort(int left, int right) {
	if(right - left > 1) {
		int mid = (left + right) / 2;
		merge_sort(left, mid);
		merge_sort(mid, right);
		merge(left, mid, right);
	}
}

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

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

	cout << count << endl;
}

Measured memory_bytes: 2720
import scala.io.StdIn
object Main extends App {
  val x = StdIn.readLine.toInt
  val r = math.sqrt(x).toInt
  val ans = if( r == 1) x else
    (2 to r).map { i =>
      val e = for {
        j <- (2 to r)
        e = math.pow(i,j).toInt if(e <= x)
      } yield e
      e.last
    }.max
  println(ans)
}

Measured memory_bytes: 27072
# coding: utf-8
ans, lastMinus = 0, 0
for i in range(5):
    try:
        k = int(input())
    except EOFError:
        pass
    
    if k % 10 != 0:
        num = (k // 10 + 1) * 10
        if lastMinus < (num - k):
            lastMinus = num - k
    else:
        num = k
    ans += num

ans -= lastMinus    
print(ans)
    

Measured memory_bytes: 2940
//=============================================================
// Name        : d
// Date        : Thu Jul  4 09:41:30 CST 2019
// Accepted    : Thu Jul  4 09:56:33 CST 2019
// Author      : landcold7
// Description : Actions speak louder more than words
//=============================================================
#include <bits/stdc++.h>
using namespace std;

#define x first
#define y second
#define sz(x) ((int)(x).size())
#ifndef _has_trace
#define trace(...)
#endif
typedef long long ll;

const int mod = 1e9 + 7;

void solve() {
  int n, k;
  cin >> n >> k;
  const int maxn = 2400;
  vector<vector<int>> dp(maxn, vector<int>(maxn));
  for (int i = 0; i < maxn; ++i) {
    dp[i][0] = 1;
  }
  for (int i = 1; i < maxn; ++i) {
    for (int j = 1; j < maxn; ++j) {
      dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j];
      dp[i][j] %= mod;
    }
  }
  for (int i = 1; i <= k; ++i) {
    int r = n - k;
    int x = dp[r + 1][i];
    int y = dp[k - 1][i - 1];
    cout << ((ll)x * y % mod) << "\n";
  }
}

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


Measured memory_bytes: 22912
import java.util.Scanner;
//import java.io.*;
//import java.util.Arrays;
public class Main {
	public static void main(String[] args) throws java.io.IOException {
		Scanner scan = new Scanner(System.in);
		//InputStreamReader is = new InputStreamReader(System.in);
		//BufferedReader br = new BufferedReader(is);
		int a = 1;
		int b = 0;
		int c = 0;
		while(scan.hasNext()){
			String str = scan.next();
			String[] text = str.split(",", 0);
			if(text[0].equals("A")){
				if(text[1].equals("B")){
					if(a == 1){
						a = 0;
						b = 1;
					}else if(b == 1){
						a = 1;
						b = 0;
					}
				}else if(text[1].equals("C")){
					if(a == 1){
						a = 0;
						c = 1;
					}else if(c == 0){
						a = 1;
						c = 0;
					}
				}
			}else if(text[0].equals("B")){
				if(text[1].equals("A")){
					if(b == 1){
						b = 0;
						a = 1;
					}else if(a == 1){
						b = 1;
						a = 0;
					}
				}else if(text[1].equals("C")){
					if(b == 1){
						b = 0;
						c = 1;
					}else if(c == 0){
						b = 1;
						c = 0;
					}
				}
			}else{
				if(text[1].equals("A")){
					if(c == 1){
						c = 0;
						a = 1;
					}else if(a == 1){
						c = 1;
						a = 0;
					}
				}else if(text[1].equals("B")){
					if(c == 1){
						c = 0;
						b = 1;
					}else if(b == 1){
						c = 1;
						b = 0;
					}
				}
			}
		}
		if(a == 1){
			System.out.println("A");
		}else if(b == 1){
			System.out.println("B");
		}else{
			System.out.println("C");
		}
	}
}

Measured memory_bytes: 26304
#include <stdio.h>
#define M 100

void bubbleSort(int[],int);
int count = 0;

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

    bubbleSort(A,n);
    printf("%d\n",count);

    return 0;

}

void bubbleSort(int A[],int N){
  int j,i,temp;

  for (i = 0 ;i<N-1;i++){
    for (j= N-1;j>=1;j--){
      if(A[j] < A[j-1]){
	temp = A[j];
	A[j] = A[j-1];
	A[j-1] = temp;
	count++;
      }
    }
  }
  for (i=0;i<N-1;i++){
    printf("%d ",A[i]);
  }
   printf("%d\n",A[i]);
    
}



Measured memory_bytes: 2104
s = input()
t = input()

sorted_s = sorted(s)
sorted_t = sorted(t, reverse=True)
len_s = len(sorted_s)
len_t = len(sorted_t)
iter_range = len_s if len_s < len_t else len_t

flag = 0
same_count = 0
for i in range(iter_range):
    s_i = sorted_s[i]
    t_i = sorted_t[i]
    if s_i < t_i:
        flag = 1
        break
    if s_i == t_i:
        same_count+= 1

if (same_count == len_s) & (len_s < len_t):
    print("Yes")
elif (same_count == len_s) & (len_s >= len_t):
    print("No")
elif flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
import qualified Data.ByteString.Char8 as BS

getString = BS.unpack <$> BS.getLine

simulate [] [] = 0
simulate (c1 : s) (c2 : t)
  | c1 == c2 = 1 + simulate s t
  | otherwise = simulate s t

main = do
  s <- getString
  t <- getString
  print $ simulate s t


Measured memory_bytes: 3772
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int main(void){
	ll x,y,ans;
	cin >> x;
	ans = (x/11)*2;
	y = x%11;
	if(y>6){
		ans += 2;
	}else if(y>0){
		ans += 1;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.util.NoSuchElementException;

public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        String S = sc.next();
        String r = "ABC";


        System.out.println((S.equals(r)) ? "ARC" : "ABC");
    }
}

class FastScanner {
    private final java.io.InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte()) return buffer[ptr++];
        else return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    private void skipUnprintable() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
    }

    public boolean hasNext() {
        skipUnprintable();
        return hasNextByte();
    }

    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return (minus ? -n : n);
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return (int) (minus ? -n : n);
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
}



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

typedef long long ll;
ll n,ans=0;
double d;
int main() {
	cin >> n >> d;
	for (int i=0; i<n; i++) {
		double x,y;
		cin >> x >> y;
		if (sqrtl(x*x + y*y) <= d) {
			ans++;
		}	
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3816
N = int(input())
s = input()
t = input()
c = 0
for o in range(len(s) + 1):
    d = 0
    for i in range(len(t)):
        if o + i >= len(s): break
        if s[o + i] == t[i]: d += 1
        else: break
    c = max(c, d)
print(len(s) + len(t) - c)


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

int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    
    for (int i=0; i<S.size(); i++) {
        if (S.at(i)+N >=91) S.at(i) += N - 26;
        else S.at(i) += N;
    }
    cout << S << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int N = sc.nextInt();
        int[] A = new int[N];

        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }

        int sum = 0;
        for (int i = 0; i < N; i++) {
            sum += A[i];
        }

        if(sum >= H){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 50720
function main(input) {
    const reverse = (s) => {
        return s.split('').reverse().join('');
    };

    const WORDS = ['dream', 'dreamer', 'erase', 'eraser'].map(reverse);
    const S = reverse(input.split('\n')[0]);

    var index = 0;

    while(true) {
        var w = WORDS.find((w) => S.startsWith(w, index));
        if (!w) break;
        index += w.length;
    }

    if (S.length === index) {
        console.log('YES');
    } else {
        console.log('NO');
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 11672
using System;
using System.Collections.Generic;
using System.Linq;
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var paper = new List<string>();

            for (int i=0;i<N;i++)
            {
                var tmp = Console.ReadLine();
                paper.Add(tmp);
            }
            var sum = paper.GroupBy(s => s).Select(g => g.Count() % 2 == 0 ? 0 : 1).Sum();
            Console.WriteLine(sum);
        }
    }

Measured memory_bytes: 32084
class Combination:
    """階乗とその逆元のテーブルをO(N)で事前作成し、組み合わせの計算をO(1)で行う"""
    def __init__(self, n, MOD):
        self.fact = [1]
        for i in range(1, n + 1):
            self.fact.append(self.fact[-1] * i % MOD)
        self.inv_fact = [0] * (n + 1)
        self.inv_fact[n] = pow(self.fact[n], MOD - 2, MOD)
        for i in reversed(range(n)):
            self.inv_fact[i] = self.inv_fact[i + 1] * (i + 1) % MOD
        self.MOD = MOD

    def factorial(self, k):
        """k!を求める O(1)"""
        return self.fact[k]

    def inverse_factorial(self, k):
        """k!の逆元を求める O(1)"""
        return self.inv_fact[k]

    def permutation(self, k, r):
        """kPrを求める O(1)"""
        if k < r:
            return 0
        return (self.fact[k] * self.inv_fact[k - r]) % self.MOD

    def combination(self, k, r):
        """kCrを求める O(1)"""
        if k < r:
            return 0
        return (self.fact[k] * self.inv_fact[k - r] * self.inv_fact[r]) % self.MOD


def way2(ball, box):
    """ball: True / box: True / constraints: 1 or less
    -> ans = permutation(box, ball)
    """
    if ball > box:
        return 0
    return comb.permutation(box, ball)


n, k = map(int, input().split())
MOD = 10 ** 9 + 7
comb = Combination(10 ** 4, MOD)

print(way2(n, k))


Measured memory_bytes: 6348
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <list>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
using namespace std;
typedef long long ll;

int main(){
  int n;
  cin >> n;
  list<ll> que;
  REP(i,n){
    ll a; cin >> a;
    if(i%2){
      que.push_back(a);
    }else{
      que.push_front(a);
    }
  }
  if(n%2==0) que.reverse();
  for(ll a: que) cout << a << " ";
  cout << endl;
  return 0;
}


Measured memory_bytes: 8448