akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using P = pair<int, int>;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<ll> res(26, 0);
  rep(i, n){
    string s;
    cin >> s;
    vector<ll> tmp(26, 0);
    rep(j, s.size()){
      ll num = s.at(j) - 'a';
      tmp[num]++;
    }
    rep(k,26){
      if(i > 0){
        res.at(k) = min(res.at(k), tmp.at(k));
      }else {
        res.at(k) = tmp.at(k);
      }
    }
  }
  rep(i, 26){
    rep(j, res.at(i)){
      char ch =  'a' + i;
      cout << ch;
    }
  }
  cout << endl;
}

Measured memory_bytes: 256
const input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);const tn=():number=>{const a=input[0];input.shift();return Number(a)};const tnn=(n:number):number[]=>{const a=[];for(let i=0;i<n;i++){a.push(tn())}return a};const ts=():string=>{const a=input[0];input.shift();return String(a)};const tss=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(ts())}return a};const tc=():string=>{let a=input[0].split('');const b=a[0];a.shift();if(a.length>0){input[0]=a.join('')}else{input.shift()}return String(b)};const tcc=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(tc())}return a};const to=(...arg)=>{console.log(...arg)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const floor=(a)=>{return Math.floor(a)};const asc=(ar:number[])=>{return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{return ar.sort((a,b)=>{return b-a})};const sw=(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length;i+=2){if(eval(a+op+arr[i]))return arr[i+1];}return arr[arr.length-1]};const near=(n:number,arr:number[]):number=>{let ne=arr[0],ni=0;for(let i=1;i<arr.length;i++){if(Math.abs(n-ne)>Math.abs(n-arr[i])){ne=arr[i];ni=i}}return ni};
const main=()=>{
  let [a,b]=tnn(2)
  let n=b-a
  to(n*(n+1)/2-b)
}
main()


Measured memory_bytes: 7372
import java.util.Scanner;

class Main
{
   public static void main(String[] args)
   {
      Scanner stdIn = new Scanner(System.in);
      int a = stdIn.nextInt();
      int b = stdIn.nextInt();
      int c = a*b;
      int d = 2*(a+b);
      System.out.println( c + " " + d );
   }
}

Measured memory_bytes: 26160
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

const int MAX_V = 310;
const ll INF   = 1e18;
int V; // 接点数

ll d[MAX_V][MAX_V]; //d[i][i] = 0、他はINFで初期化必要
ll d2[MAX_V][MAX_V];

void floyd_warshall(){
    for(int k=0; k<V; k++){
        for(int i=0; i<V; i++){
            for(int j=0; j<V; j++){
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}

void floyd_warshall2(){
    for(int k=0; k<V; k++){
        for(int i=0; i<V; i++){
            for(int j=0; j<V; j++){
                d2[i][j] = min(d2[i][j], d2[i][k] + d2[k][j]);
            }
        }
    }
}


int main(){

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

    ll n, m, l; cin >> n >> m >> l;

    V = n;

    for(int i=0; i<V; i++){
        for(int j=0; j<V; j++){
            if(i == j){
                d[i][j] = 0;
                d2[i][j] = 0;
            }
            else{
                d[i][j] = INF;
                d2[i][j] = INF;
            }
        }
    }

    rep(i, m){
        ll a, b, c; cin >> a >> b >> c;
        a--; b--;

        d[a][b] = c;
        d[b][a] = c;
    }

    int q; cin >> q;
    int s[q], t[q];
    rep(i, q){
        cin >> s[i] >> t[i];
        s[i]--; t[i]--;
    }

    floyd_warshall();

    // rep(i, n){
    //     rep(j, n){
    //         cout << i << " " << j << " " << d[i][j] << endl;
    //     }
    // }

    rep(i, n){
        rep(j, n){
            if(i == j) continue;

            if(d[i][j] <= l){
                d2[i][j] = 1;
            }
        }
    }

    floyd_warshall2();

    // rep(i, n){
    //     rep(j, n){
    //         cout << i << " " << j << " " << d2[i][j] << endl;
    //     }
    // }

    rep(i, q){
        ll ret = d2[s[i]][t[i]];
        if(ret == INF){
            cout << -1 << endl;
        }
        else{
            cout << ret-1 << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string a,b;
  cin >> a >> b;
  int a_size = a.size();
  int b_size = b.size();
  if(a_size>b_size){
    cout << "GREATER" << endl;
  } else if (a_size<b_size){
    cout << "LESS" << endl;
  } else{
    if(a==b){
      cout << "EQUAL" << endl;
    }else{
    	for(int i=0;i<a_size;i++){
          int a_i = int(a[i]);
          int b_i = int(b[i]);
          if(a_i>b_i){
            cout << "GREATER" << endl;
            break;
          }else if(a_i<b_i){
            cout << "LESS" << endl;
            break;
          }
        }
    }  
  }
  
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


template<typename T>
struct SegmentTree{
private:
    int n;
    T E;
    vector<T> node;
    inline void updatef(T& x,T& y){
        x = y;
        //x += y;
        //x = max(x,y);
        //x = min(x,y);
    }
    inline T queryf(T& x,T& y){
        //return x*y;
        //return x+y;
        return max(x,y);
        //return min(x,y);
    }

public:
    SegmentTree(int sz,T E_):E(E_){
        n=1;
        while(n<sz)n<<=1;
        node.resize(2*n-1,E);
    }

    SegmentTree(vector<T>& A,T E_):E(E_){
        int sz=A.size();
        n=1;
        while(n<sz)n<<=1;
        node.resize(2*n-1,E);
        rep(i,sz)node[i+n-1]=A[i];
        for(int i=n-2;i>=0;--i){
            node[i]=queryf(node[2*i+1], node[2*i+2]);
        }
    }
    void update(int k,T x){
        k+=n-1;
        updatef(node[k],x);
        while(k>0){
            k=(k-1)/2;
            node[k]=queryf(node[2*k+1], node[2*k+2]);
        }
    }
       //[a,b)での和を返す
    T get(int a,int b,int k=0,int l=0,int r=-1){
        if(r<0)r=n;
        if(r<=a||b<=l)return E;
        if(a<=l&&r<=b)return node[k];
        T xl=get(a,b,2*k+1,l,(l+r)/2);
        T xr=get(a,b,2*k+2,(l+r)/2,r);
        return queryf(xl, xr);
    }
    int find(int k = 0){
        if(k>=n-1)return k-(n-1);
        if(node[2*k+1]>=node[2*k+2])return find(2*k+1);
        return find(2*k+2);
    }
};
int main(){
    int n;
    cin>>n;
    ll a[n], b[n];
    rep(i,n)cin>>a[i];
    rep(i,n)cin>>b[i];
    SegmentTree<ll> sg(n,-longinf);
    rep(i,n){
        sg.update(i,b[i]);
    }
    ll cnt = 0;
    while(1){
        if(sg.get(0,n)==-longinf)break;
        int idx = sg.find();
        if(a[idx]==b[idx]){
            sg.update(idx,-longinf);
        }
        else if(a[idx]<b[idx]){
            ll sum = b[(idx+1)%n]+b[(idx+n-1)%n];
            ll num = (b[idx]-a[idx])/sum;
            if(num==0){
                cout<<-1<<endl;
                return 0;
            }
            b[idx]-= num*sum;
            cnt+=num;
            if(b[idx]<a[idx]){
                cout<<-1<<endl;
                return 0;
            }
            sg.update(idx,b[idx]);
        }
        else {
            cout<<-1<<endl;
            return 0;
        }
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 7424
#include<string.h>
#include<iostream>
using namespace std;
int main(){
  int n,i,j,k,l;
  while(cin>>n){
    int c=0;
    for(i=0;i<10;i++){
      for(j=0;j<10;j++){
	for(k=0;k<10;k++){
	  for(l=0;l<10;l++){
	    if(i+j+k+l==n){
	      c++;
	    }
	  }
	}
      }
    }
    cout<<c<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
n = int(input())
s = input()

r = []
g = []
b = [0] * (n)

for i in range(n):
    if s[i] =='R':
        r.append(i)
    elif s[i] =='G':
        g.append(i)
    else:
        b[i] = 1

b_sum = sum(b)
#print(b_sum)
#print(len(r),len(g))
ans = 0

for i in range(len(r)):
    for j in range(len(g)):
        tmp = abs(r[i] -g[j])
        ans += b_sum
        dek = tmp + max(r[i],g[j])
        if dek <= n-1:
            if b[dek] == 1:
                ans -= 1
                
        chi = min(r[i],g[j]) - tmp
        if chi >= 0:
            #print(b[chi-1],chi)
            if b[chi] == 1:
                #print(chi-1,b[chi-1])
                ans -= 1
                
        if tmp % 2 == 0:
            #print(r[i],g[j],int(min(r[i],g[j])-1+tmp/2))
            if b[min(r[i],g[j])+tmp//2] == 1:
                ans -= 1
print(ans)
            

Measured memory_bytes: 70028
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)

#define MAXN (100)
#define MOD (998244353)

int b[MAXN];

int main(void)
{
    int n;
    scanf("%d",&n);
    
    for(int i=0;i<n-1;i++) scanf("%d",&(b[i]));
    int64_t ans = 0;

    ans += b[0];
    for(int i=1;i<n-1;i++)
    {
        ans += min(b[i],b[i-1]);
    }
    ans += b[n-2];

    printf("%ld\n",ans);
    
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;
//	Table is the complete reverse of dp
//	Always think of the pattern (LCM, GCD)
//	Be careful of unsigned
//	double epsilon = FLT_EPSILON;
//	Think of a solution that gets TLE and optimize it

int main()
{
    cin.tie(nullptr); ios_base::sync_with_stdio(false);
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    while(a >= b)
    {
    	b *= 2;
    	k--;
    }
    while(b >= c)
    {
    	c *= 2;
    	k--;
    }
    cout << (k >= 0? "Yes": "No");
}


Measured memory_bytes: 3540
N,K = map(int,input().split())
X = list(map(int,input().split()))
res = 10**10
for i in range(N-K+1):
    if X[i]*X[i+K-1] >= 0:
        res = min(res,max(abs(X[i+K-1]),abs(X[i])))
    else:
        res = min(res,abs(X[i])*2+X[i+K-1],X[i+K-1]*2+abs(X[i]))
print(res)

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

int main(){
  int  n;
  string s;
  cin >> n >> s;
  int ans =0;

  
  
  for(int i=1;i<n;i++){
      int count =0;
    for(char c='a';c<='z';c++){
    bool left = false;
    bool right = false;
    for(int j=0;j<i;j++){
      if(s[j]==c) left = true;
    }
      for(int k=i;k<n;k++){
        if(s[k]==c) right = true;
      }
      if(left&&right) count++;
    }
    ans = max(ans,count);
  }
  
  cout << ans << endl;
}
  
  



Measured memory_bytes: 3624
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int a = sc.nextInt();
        int b = sc.nextInt();
        int r=(2*a-1)>(2*b-1)?(2*a-1):(2*b-1);
        r=r>(a+b)?r:(a+b);
        // 出力
        System.out.println(r);
    }
}

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

int main()
{
int a;
int b;
int iSum;

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

	cin >> a;
	cin >> b;

	iSum = a + b;
	if( iSum % 2 == 0 )
		cout << iSum / 2 << endl;
	else
		cout << ( iSum + 1 ) / 2 << endl;

	return 0;
}






Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s[8],d,f,g,h,i,j;
	char z[8];
	while(1){
		scanf("%s",z);
		if(z[0]=='0') break;
		j=0;
		for(i=1;i<7;i+=2){
			if(z[i]=='8'||z[i]=='9'||z[i]=='a'||z[i]=='b'||z[i]=='c'||z[i]=='d'||z[i]=='e'||z[i]=='f'){
				s[j]=1;
			}
			else s[j]=0;
			j++;
		}
		if(s[0]==1){
			if(s[1]==1){
				if(s[2]==1) printf("white\n");
				else printf("yellow\n");
			}
			else{
				if(s[2]==1) printf("fuchsia\n");
				else printf("red\n");
			}
		}
		else{
			if(s[1]==1){
				if(s[2]==1) printf("aqua\n");
				else printf("lime\n");
			}
			else{
				if(s[2]==1) printf("blue\n");
				else printf("black\n");
			}
		}
	}
	return 0;
}

Measured memory_bytes: 2608
#include <stdio.h>
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <map>

//#include <bits/stdc++.h>
using namespace std;
#define print(x) cout<<(x)<<endl
#define prints(x, y) cout<<(x)<<" "<<(y)<<endl
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define r_rep(i, n) for(int i = n; i >= 0; i--)
#define ll long long int
#define pb push_back

const long long INF = 1LL << 60;

int main() {
  string s;
  cin >> s;
  vector<char> c(26, 0);
  for(char i: s){
    c[i-'a']++;
  }

  rep(i, 26){
    if(c[i] % 2 != 0){
      print("No");
      return 0;
    }
  }
  print("Yes");
}


Measured memory_bytes: 256
#include<iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <iomanip>
#include <bitset>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long ll;

int main() {
	
	int n;
	cin >> n;
	vector<int> a(n + 1);
	vector<int> b(n);
	rep(i, n + 1) cin >> a.at(i);
	rep(i, n) cin >> b.at(i);

	ll ans = 0;
	rep(i, n) {
		if (b.at(i) >= a.at(i)) {
			ans += a.at(i);
			b.at(i) = b.at(i) - a.at(i);
			a.at(i) = 0;
			if (b.at(i) >= a.at(i + 1)) {
				ans += a.at(i + 1);
				a.at(i + 1) = 0;
			}
			else if (b.at(i) < a.at(i + 1)) {
				ans += b.at(i);
				a.at(i + 1) = a.at(i + 1) - b.at(i);
			}
		}
		else if (b.at(i) < a.at(i)) {
			ans += b.at(i);
			a.at(i) = a.at(i) - b.at(i);
			b.at(i) = 0;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
import math
n = int(input())

dic = {}


def twoKimuawaseSum(num):
    result = 0
    for i in range(1, num):
        result += i
    return result


for i in range(n):
    string = input()
    sortStr = "".join(sorted(string))
    if sortStr in dic:
        dic[sortStr] += 1
    else:
        dic[sortStr] = 1
sum = 0
for num in dic.values():
    if num == 1:
        sum += 0
    else:
        sum += twoKimuawaseSum(num)
print(math.floor(sum))


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

int main() {
	int a, b, c, k;
	cin >> a >> b >> c >> k;

	int ans = 0;
	if (a < k) {
		ans += a;
		k -= a;
		if (b < k) {
			k -= b;
			ans -= k;
			cout << ans << endl;
		} else {
			cout << ans << endl;
		}
	} else {
		ans += k;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = int(1e9)+10;
const ll INFll = ll(1e18)+10;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;
using Graph = vector<vector<int>>;


template<typename T>
void warshall_floyd(vector<vector<T>> &g, T INF) {
  for(int k = 0; k < g.size(); k++) {
    for(int i = 0; i < g.size(); i++) {
      for(int j = 0; j < g.size(); j++) {
        if(g[i][k] == INF || g[k][j] == INF) continue;
        g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
      }
    }
  }
}

int main() {
  ll N, M, L; cin >> N >> M >> L;

  VVll dist(N, Vll(N, INFll));
  rep(i, N) dist[i][i] = 0;
  for (int i = 0; i < M; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--; b--;
    dist[a][b] = c;
    dist[b][a] = c;
  }

  warshall_floyd(dist, INFll);
  rep(i, N) rep(j, N) dist[i][j] = (dist[i][j] <= L) ? 1 : INFll;
  warshall_floyd(dist, INFll);

  int Q; cin >> Q;
  rep(i, Q) {
    int s, t;
    cin >> s >> t;
    s--; t--;
    if (dist[s][t] == INFll) cout << -1;
    else cout << (dist[s][t]-1);
    cout << endl;
  }
  return 0;
}

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

int main() {
    //freopen("input.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(NULL);

    int n;
    cin >> n;
    int m = n / 1000 * 1000;
    if (m < n) m += 1000;
    cout << m - n;

    return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>

#define FOR(i, f, n) for(int (i) = (f); (i) < (n); (i)++)
#define RFOR(i, f, n) for(int (i) = (f); (i) >= (n); (i)--)
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define step(i, f, n, a) for(int (i) = (f); (i) < (n); (i)+=a)
#define rstep(i, f, n, a) for(int (i) = (f); (i) >= (n); (i)-=a)
#define p(...) printf(__VA_ARGS__); cout << endl;
#define gets(x) x; cin >> x;
#define puts(x) x; cout << x << endl;
#define list_input(x, n) x[(n)]; for(int (i) = 0; (i) < (n); (i)++) cin >> x[i];
#define lambda(a, b, c) [](const a, const b){ return c ;}
#define key(t, x, compare) [](const t& a, const t& b){ return a x compare b x ;}

using namespace std;

using pii = pair<int, int>;

int main(){
	long long n, a, b, result = 0;
	cin >> n >> a >> b;
	long long x[n];
	rep(i, n){
		gets(x[i])
	}

	rep(i, n-1){
		result += min( (x[i+1]-x[i])*a, b);
	}
	puts(result)
}


Measured memory_bytes: 1024
#!/usr/bin/env python
import string
import sys
from itertools import chain, dropwhile, takewhile

INF = float("inf")


def read(
    *shape, f=int, it=chain.from_iterable(sys.stdin), whitespaces=set(string.whitespace)
):
    def read_word():
        w = lambda c: c in whitespaces
        nw = lambda c: c not in whitespaces
        return f("".join(takewhile(nw, dropwhile(w, it))))

    if not shape:
        return read_word()
    elif len(shape) == 1:
        return [read_word() for _ in range(shape[0])]
    elif len(shape) == 2:
        return [[read_word() for _ in range(shape[1])] for _ in range(shape[0])]


def readi(*shape):
    return read(*shape)


def readi1(*shape):
    return [i - 1 for i in readi(*shape)]


def readf(*shape):
    return read(*shape, f=float)


def reads(*shape):
    return read(*shape, f=str)


def arr(*shape, fill_value=0):
    if len(shape) == 1:
        return [fill_value] * shape[0]
    elif len(shape) == 2:
        return [[fill_value] * shape[1] for _ in range(shape[0])]


def dbg(**kwargs):
    print(
        ", ".join("{} = {}".format(k, repr(v)) for k, v in kwargs.items()),
        file=sys.stderr,
    )


def main():
    N = readi()
    h = readi(N) * 2
    dp = arr(N * 2, fill_value=INF)
    dp[0] = 0
    for i in range(N - 1):
        dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]))
        dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]))
    print(dp[N - 1])


if __name__ == "__main__":
    main()


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

#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif

signed main(){

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

  vector<int> v; //解の候補
  for(int i = 1; i < 30; i++){
    if(k >> i & 1){
      int t = (k ^ (1<<i)) | ((1<<i) - 1);
      v.push_back(t);
    }
  }
  v.push_back(k);

  int ans = 0;
  for(int p : v){
    int res = 0;
    for(int i = 0; i < n; i++){
      for(int j = 0; j < 30; j++){
        if((a[i] >> j & 1) && !(p >> j & 1)) break;
        if(j == 29) res += b[i];
      }
    }
    ans = max(res,ans);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
#include <cstdio>
using namespace std;

int KetanoWa(char ch[])
{
    int sum = 0;
    for(int i = 0; ch[i]; ++i){
        sum += ch[i] - 48;
    }
    return sum;
}
int main()
{
    char ch[1001];
    while(true){
        scanf("%s", ch);
        int sum = KetanoWa(ch);
        if(sum == 0) break;
        printf("%d\n", sum);
    }
    return 0;
}

Measured memory_bytes: 964
#include<bits/stdc++.h>
using namespace std;
#define gcd(a,b) __gcd(a,b)
#define ld long long int
#define ll unsigned long long int
#define pi pair<ll,ll>
#define pb push_back
#define pf push_front
#define pu push
#define po pop
#define fi first
#define se second
#define mk make_pair
#define ve vector
#define lr(n) for(ll i=0;i<n;i++)

ll ar[55]={0};
ll m=0;
void fun(ll n){
	for(ll i=0;i<25 && n>0;i++){
		ar[i]+=n;
		n=ar[i]/10;
		ar[i]%=10;
		m=max(m,i);
	}
}

void answ(){
	ld i=m;
	while(i>=0){
		ll x=ar[i];
		cout<<x;
		i--;
	}
	cout << "\n";
}

	int main(){
		ios_base::sync_with_stdio(0);
		cin.tie(0);
		cout.tie(0);
		ll n;
		cin>>n;
		ll ans=0;
		if(n>2){
			ans+=n-1;
			fun(n-1);
		}
		for(ll i=2;i*i<=n;i++){
			if(n%i==0 && (i*i+i)<n){
				ans+=n/i-1;
				fun(n/i-1);
				ll k=n/i;
				if(k!=i && (k*k+k)<n){
					ans+=i-1;
					fun(i-1);
				}
			}
		}
		answ();
		// cout << ans << "\n";
	}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int main()
{
	ll l,r,minn=2020;
	cin>>l>>r;
	for(ll i=l;i<r;i++){
		for(ll j=r;j>l;j--){
			minn=min(minn,(i*j)%2019);
			if(minn==0){
				cout<<minn;
				return 0;
			} 
			//cout<<i*j<<" "<<i*j%2019<<endl;
		}
	}
	cout<<minn;
	return 0;
}


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

#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;

int main() {
    int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin >> k;
    cout << a[k - 1] << endl;
    return 0;
}

Measured memory_bytes: 256
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    """
    OPT[value] - minimum weight that achieves value
    OPT[value] = OPT[value-v[i]]
    """
    N, W = read_ints()
    max_value = 1000*N+1
    dp = [10**12+1]*max_value
    dp[0] = 0
    for i in range(N):
        w, v = read_ints()
        for j in range(max_value-1, -1, -1):
            if j >= v:
                dp[j] = min(dp[j], dp[j-v]+w)
    ans = 0
    for j in range(max_value):
        if dp[j] <= W:
            ans = j
    return ans


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 42028
#include <iostream>

using namespace std;
typedef long long ll;
const int MAX = 2000100;
ll inv[MAX],fact[MAX],fi[MAX],mod = 1000000007;
void inverse(){
	int i;
	inv[1] = 1;
	for(i=2;i<MAX;i++){
		inv[i] = mod - (mod/i)*inv[mod%i]%mod;
	}
	fact[0] = fi[0] = 1;
	for(i=1;i<MAX;i++){
		fact[i] = fact[i-1]*i%mod;
		fi[i] = (fi[i-1]*inv[i])%mod;
	}
}

ll comb(int n,int k){
	if(n<0 || k<0 || n<k){
		return 0;
	}else{
		return fact[n]%mod*fi[k]%mod*fi[n-k]%mod;
	}
}
int main(){
	ll x,y;
	cin >> x >> y;
	if((x + y)%3!=0){
		cout << 0 << endl;
	}else{
		inverse();
		ll k = (2*x - y)/3,l = (2*y - x)/3;
		cout << comb(k + l,l) << endl;
	}
}

Measured memory_bytes: 47104
#include <iostream>
#include <vector>
#include <string>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <climits>
#include <iomanip>
#include <deque>

using namespace std;

int main()
{
  int64_t N, M;

  cin >> N >> M;

  int64_t N_result = max<int64_t>(0, N * (N - 1) / 2);
  int64_t M_result = max<int64_t>(0, M * (M - 1) / 2);

  cout << N_result + M_result << endl;

  return 0;
}


Measured memory_bytes: 256
N, K = [int(nk) for nk in input().split()]
blue = K
red = N-K

import math
for i in range(1, K+1):
  
  #赤はi-1個以上必要
  if red < i-1:
    ans = 0
  
  else:
    #青はi個に分割する　i-1個の仕切りで分割　(K-1)C(i-1)
    blue_arrangement = math.factorial(K-1) // (math.factorial(K-i) * math.factorial(i-1))
    
    #自由に使える赤は仕切り以外の分
    red_free = red - (i-1)
    #自由赤はi+1個に分割する　i個の仕切りで分割　(red_free + i)! // ((red_free)! * (i)!)
    red_arrangement = math.factorial(red_free+i) // (math.factorial(red_free) * math.factorial(i))
    ans = blue_arrangement * red_arrangement
    
  print(ans % (10**9 + 7))

Measured memory_bytes: 3316
void main() {
  import std.stdio, std.string, std.conv, std.algorithm;

  int n;
  rd(n);
  auto a = readln.split.to!(int[]);

  const int M = 10 ^^ 6;
  auto freq = new int[][](2, M);
  foreach (i, e; a) {
    freq[i & 1][e]++;
  }
  struct P {
    int val, num;
  }

  auto v = new P[][](2);
  foreach (i; 0 .. M) {
    foreach (j; 0 .. 2) {
      if (freq[j][i] > 0) {
        v[j] ~= P(i, freq[j][i]);
      }
    }
  }
  foreach (i; 0 .. 2) {
    v[i] ~= P(0, 0);
    sort!((l, r) => (l.num > r.num))(v[i]);
  }
  int ans;
  if (v[0][0].val != v[1][0].val) {
    ans = (n / 2 - v[0][0].num) + (n / 2 - v[1][0].num);
  } else {
    ans = min((n / 2 - v[0][0].num) + (n / 2 - v[1][1].num),
        (n / 2 - v[0][1].num) + (n / 2 - v[1][0].num));
  }
  writeln(ans);
}

void rd(T...)(ref T x) {
  import std.stdio : readln;
  import std.string : split;
  import std.conv : to;

  auto l = readln.split;
  assert(l.length == x.length);
  foreach (i, ref e; x)
    e = l[i].to!(typeof(e));
}


Measured memory_bytes: 15680
import sys
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(rs())
def rs_(): return [_ for _ in rs().split()]
def ri_(): return [int(_) for _ in rs().split()]

import collections
N = ri()
S = [rs() for i in range(N)]
d = collections.Counter(S)
print('AC x ', d['AC'], sep='')
print('WA x ', d['WA'], sep='')
print('TLE x ', d['TLE'], sep='')
print('RE x ', d['RE'], sep='')

Measured memory_bytes: 16488
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
long long x,ans=0;
int main()
{
	cin>>x;
	int n=x/500;
	ans+=1000*n;
	x=x-n*500;
	n=x/5;
	ans+=5*n;
	cout<<ans<<endl;
	return 0; 
}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    int absSum = 0;
    bool hasPos = false, hasNeg = false;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        absSum += abs(a[i]);
        hasPos |= (a[i] >= 0);
        hasNeg |= (a[i] < 0);
    }

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

    if (hasPos && hasNeg) {
        cout << absSum << endl;

        int val1 = a[n - 1];
        for (int i = 1; a[i] < 0; i++) {
            cout << val1 << ' ' << a[i] << endl;
            val1 -= a[i];
        }

        int val2 = a[0];
        for (int i = n - 2; a[i] >= 0; i--) {
            cout << val2 << ' ' << a[i] << endl;
            val2 -= a[i];
        }

        cout << val1 << ' ' << val2 << endl;
        return 0;
    }

    if (hasPos) {
        cout << (absSum - 2 * a[0]) << endl;

        int val = a[0];
        for (int i = 1; i < n - 1; i++) {
            cout << val << ' ' << a[i] << endl;
            val -= a[i];
        }

        cout << a[n - 1] << ' ' << val << endl;
        return 0;
    }

    if (hasNeg) {
        cout << (absSum + 2 * a[n - 1]) << endl;

        int val = a[n - 1];
        for (int i = 0; i < n - 1; i++) {
            cout << val << ' ' << a[i] << endl;
            val -= a[i];
        }

        return 0;
    }
}


Measured memory_bytes: 2304
// Undone
#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
using namespace std;
signed main() {
  double W, H, x, y;
  cin >> W >> H >> x >> y;
  cout << fixed << setprecision(15) << W*H/2.0;
  if (W/2. == x && H/2. == y) {
    cout << " 1" << endl;
  } else {
    cout << " 0" << endl;
  }
}


Measured memory_bytes: 384
import qualified Data.ByteString.Char8 as BC
import Data.Maybe (fromJust)
import Data.List

main = do
  n <- readLn :: IO Int
  a <- getIntListBC
  let odd = fst . unzip . filter (\(x, y) -> mod y 2 /= 0) $ zip a [1..n]
      even = fst . unzip . filter (\(x, y) -> mod y 2 == 0) $ zip a [1..n]
  if n == 1 then print $ head a
            else if 0 == mod n 2
                   then putStrLn $ (unwords . map show . reverse $ even) ++ " " ++ (unwords . map show $ odd)
                   else putStrLn $ (unwords . map show . reverse $ odd) ++ " " ++ (unwords . map show $ even)

bsToInt :: BC.ByteString -> Int
bsToInt = fst . fromJust . BC.readInt

getIntListBC :: IO [Int]
getIntListBC = map bsToInt . BC.words <$> BC.getLine


Measured memory_bytes: 41212
#!/usr/bin/ruby
class TLLI
	def initialize
		@trianies=[nil,[0,0,0]]
	end
	def root_triany
		1
	end
	def allocate_triany
		siz=@trianies.size
		@trianies[siz]=[0,0,0]
		return siz
	end
	def set_a(id,value)
		return if !@trianies[id]
		@trianies[id][0]=value
	end
	def set_b(id,value)
		return if !@trianies[id]
		@trianies[id][1]=value
	end
	def set_c(id,value)
		return if !@trianies[id]
		@trianies[id][2]=value
	end
	def get_a(id)
		return if !@trianies[id]
		@trianies[id][0]
	end
	def get_b(id)
		return if !@trianies[id]
		@trianies[id][1]
	end
	def get_c(id)
		return if !@trianies[id]
		@trianies[id][2]
	end
end

class SETI <TLLI # a=>key, b=>left, c=>right
	def set_entry(key)
		x=root_triany
		y=0
		while x!=0&&!(x==root_triany&&get_a(x)==0) #fixme
			y=x
			if key<get_a(x)
				x=get_b(x)
			else
				x=get_c(x)
			end
		end
		if y==0
			set_a(root_triany,key)
		else
			leaf=allocate_triany
			set_a(leaf,key)
			if key<get_a(y)
				set_b(y,leaf)
			else
				set_c(y,leaf)
			end
		end
	end
	def find_entry(key)
		t=root_triany
		loop{
			return true if key==get_a(t)
			if key<get_a(t)
				t=get_b(t)
				return false if t==0
			else
				t=get_c(t)
				return false if t==0
			end
		}
	end
	def delete_entry(key)
		left=false
		prev=nil
		t=root_triany
		loop{
			break if key==get_a(t)
			prev=t
			if key<get_a(t)
				t=get_b(t)
				left=true
				return false if t==0
			else
				t=get_c(t)
				left=false
				return false if t==0
			end
		}
		if get_b(t)>0&&get_c(t)>0
			children=inorder_internal(get_c(t))+[t]
			set_a(t,get_a(children[0]))
 
			prev=children[1]
			#left of parent of t
			if prev!=t
				set_b(prev,0)
				left=true
			else
				left=false
			end
			t=children[0]
		end
		if get_b(t)+get_c(t)>0
			n=get_b(t)+get_c(t)
			if left
				set_b(prev,n)
			else
				set_c(prev,n)
			end
		else
			if left
				set_b(prev,0)
			else
				set_c(prev,0)
			end
		end
	end
	def inorder_internal(t)
		t==0 ? [] : inorder_internal(get_b(t))+[t]
	end
	def print_preorder(t)
		return if t==0
		Kernel.print " #{get_a(t)}"
		print_preorder(get_b(t))
		print_preorder(get_c(t))
	end
	def print_inorder(t)
		return if t==0
		print_inorder(get_b(t))
		Kernel.print " #{get_a(t)}"
		print_inorder(get_c(t))
	end
	def print_postorder(t)
		return if t==0
		print_postorder(get_b(t))
		print_postorder(get_c(t))
		Kernel.print " #{get_a(t)}"
	end
	def print
		print_inorder(root_triany);puts
		print_preorder(root_triany);puts
	end
end
 
seti=SETI.new
$<.drop(1).each{|l|
	a=l.split
	if a[0]=='insert'
		seti.set_entry(a[1].to_i)
	elsif a[0]=='find'
		puts seti.find_entry(a[1].to_i) ? :yes : :no
	elsif a[0]=='delete'
		seti.delete_entry(a[1].to_i)
	elsif a[0]=='print'
		seti.print
	end
}

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

int main() {
  
  int A=0, B=0;
  
  cin >> A >> B;
 
  if(A == B) {
    
    cout << "Draw" << endl;
    
  } else if(A == 1) {
    
    cout << "Alice" << endl;
    
  } else if(B == 1) {
    
    cout << "Bob" << endl;
    
  }else if(A < B) {
    
    cout << "Bob" << endl;
    
  } else if(B < A) {
    
    cout << "Alice" << endl;
    
  }
  
  return 0;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <set>

using namespace std;
typedef long long LL;
static const double EPS = 1e-9;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n) 
bool primecheck(int n){
  FOR(i,2,n/2)
    if(n%i == 0) return false;
  return true;
}


int main(void){
  int twinprime[1000] = {0};
  int ptr=0;
  FOR(i,3,9999){
    if(primecheck(i)&&primecheck(i+2))
      twinprime[ptr++] = i;
  }
  twinprime[ptr] = 10001;
  int n;
  while(cin>>n,n){
    int i=0;
    while(true){
      if(twinprime[i]+2>n){
        cout << twinprime[i-1] << " " << twinprime[i-1] + 2<< endl;
        break;
      }
      i++;
    }
  }
}

Measured memory_bytes: 0
#include<iostream>
#include<cmath>
#include<stack>
#include<vector>
#include<cstring>
#include<algorithm>
#include<set>
#include<queue>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <complex>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cassert>
using namespace std;
typedef long long ll;
const ll inf =1e17;
#define scn(a) scanf("%d",&a)
#define scd(a) scanf("%lf",&a)
#define scl(a) scanf("%lld",&a)
#define ptf(a) printf("%d\n",&a)
#define mes(a,b) memset(a,b,sizeof(a))
#define fon(s,n) for(int i=s;i<=n;i++)
#define range(i,a,b) for(int i=a;i<=b;++i)
#define rerange(i,a,b) for(int i=a;i>=b;--i)
//#define N 100010
const int S=20;
ll gcd(ll a,ll b) { return b>0 ? gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
ll q_pow(ll a,ll b,ll mod)
{
	ll ans=1,res=a;
	while(b){
		if(b&1) ans=ans*res%mod;
		res=res*res%mod;
		b>>=1;
	}
	return ans%mod;
}
 bool cmp(const pair<string,int> &p1, const pair<string,int> &p2) {
    return p1.second > p2.second;
}
int cnt[105]={0};
int main()
{
    ll a, b, n;
    scanf("%lld%lld%lld", &a, &b, &n);
    printf("%lld\n", a*min(b-1,n)/b);
				return 0;
}
		
	



Measured memory_bytes: 3720
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <limits.h>
#include <cmath>
#include <queue>
#include <map>
#include <iomanip>
#include <random>
#include <fstream>
#define rep(i, n) for (int i = 0; i < n; i++)
#define PI 3.14159265358979323846
#define MOD 1000000007
using namespace std;
using ll = long long;

const int MAX = 1000000;

ll 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;
}

ll gcd(ll a, ll b)
{
  ll r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}

template <class T> struct cord{
  T x,y;
};

template <class T> double dist(cord<T> a, cord<T> b){
  T dx=a.x-b.x;
  T dy=a.y-b.y;
  return sqrt(dx*dx+dy*dy);
}

int main()
{

  //cout << fixed << setprecision(10);

  int a,b,c,d; cin >> a >> b >> c >> d;
  cout << max(a*b,c*d);

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) for(int sz=0;sz<int(vec.size());sz++) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

bool check(V< V<bool> > &fi) {
    bool ok = false;
    bool tate;
    for (int i = 0; i < 3; i++) {
        tate = true;
        for (int j = 0; j < 3; j++) {
            tate = tate && fi[i][j];
        }
        ok = ok || tate;
    }

    for (int i = 0; i < 3; i++) {
        tate = true;
        for (int j = 0; j < 3; j++) {
            tate = tate && fi[j][i];
        }
        ok = ok || tate;
    }

    ok = ok || (fi[0][0] && fi[1][1] && fi[2][2]);
    ok = ok || (fi[0][2] && fi[1][1] && fi[2][0]);
    return ok;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    V< V<int> > a(3, V<int>(3));
    for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) cin >> a[i][j];
    V< V<bool> > bingo(3, V<bool>(3, false));
    bool ans = false;
    int n; cin >> n;
    for (int i = 0; i < n; i++) {
        int b; cin >> b;
        for (int ii = 0; ii < 3; ii++) {
            for (int jj = 0; jj < 3; jj++) {
                if (a[ii][jj] == b) bingo[ii][jj] = true;
            }
        }
        ans = ans || check(bingo);
    }
    if (ans) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}


Measured memory_bytes: 3656
#include <stdio.h>
#define PI 3.14159265358979

int main(void) {
	double r,s,l;
	scanf("%lf",&r);
	if(r>0&&r<10000){
		s=r*r*PI;
		l=2.0*r*PI;
		printf("%f %f\n",s,l);
	}
	return 0;
}



Measured memory_bytes: 2056
//shara's here
#include <bits/stdc++.h>
using namespace std;
typedef int q;
typedef double w;
typedef string s;
typedef long long ll;
int main(){
    s ss,dd;
    int x;
    cin>>x;
    cin>>ss>>dd;
    for(int i=0;i<x;i++){
     cout<<ss[i]<<dd[i];
    }












return 0;}
/*
███████████████████████████████████████████████████
███████████████████████████████████████████████████
██████████████████████████████████▀████████████████
██████████████████████████████████░▀███████████████
██████████████████████████████▌███░░░▀▀████████████
██▀████████████████████▐██████░▐██░░░░░░▀▀█████████
██░████████████████████▐█████▌░██▌▄░░░░▄▄░▄████▀███
█▌░███████████████████▀░█████░░░█░░░▄████░░███▀▐███
█▌░▐██████████████████░░████▌░░░▀░░▀███▀▀░▐███▄████
██░▀██████████████▌▐█▐▄▄████▌░░░░░░░░░░░░░▌████████
███░███████████████▀░▄▄██▀█▐░░░░░░░░░░░░░░▐████████
███▄░██████████████▄░░░░░░▀▀▀░░░░░░░░░░░░░█▐███████
████▄░██████████████████▄▄▄▄▄▄▐▄░░░░░░░░░░░████████
█████▄█████████████████▀▀▀▀▀▀░░░░░░░░░░░░░░████████
████████████████████████▄░░░░░░░░░░░░░░░▄░░████████
██████████████████████████▄▄▄░░░░░░░░░▄█░▄█████████
████████████████████████████████▄░░░░██▄███▀░░▀████
█████████████████████████████▀█████▄███▀▀▀░░▄▄░████
████████████████████████████▀░░▀░░▀▀░░░░▄▄▄██▀░░▀▀█
███████████████████████████▌░░░░░░░░░░░███████░░░▄█
███████████████▄░▀████████▀░░░░░░▀░░░░███████▌░░░██
███▄▄████████████▄░▀██████▄░░░░░█░░░░████████░░░▀▀
░▀█████████████████▄░▀█████░░░░██░░░░▀██████░░░░░▄█
▐█▄▀█████████████████▄░▀████░░░██▌░░░▐████▀░░░░▄███
▐███▄▀▀█████████████████▄░▀▀░░░░▀██▌▄█▀▀░░░▄▄██████
▀▀▀▀▀░░░▀▀▀▀▀░░░▀▀▀▀▀▀▀▀▀▀▀░░░░░░░▀▀░░░░░░▀▀▀▀▀▀▀▀▀
*/


Measured memory_bytes: 256
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: 9628
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=1000000007
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  s=S()
  l=len(s)
  _k=I()

  dp=[[[0]*2 for _ in range(4)]for __ in range(l+1)]
  dp[0][0][0]=1

  for i in range(l):
    nd=int(s[i])
    for j in range(4):
      for k in range(2):
        for d in range(10):
          ni=i+1
          nj=j
          nk=k

          if d!=0:
            nj+=1

          if nj>_k:
            continue

          if k==0:
            if nd>d:
              nk=1
            if nd<d:
              continue

          dp[ni][nj][nk]+=dp[i][j][k]

  return dp[l][_k][0]+dp[l][_k][1]

# main()
print(main())


Measured memory_bytes: 5168
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <cstdio>


using namespace std;

const char GetKthAlphabet(string& s, int k) {
  vector<char> mins;
  mins.push_back(s[0]);
  for (int i = 1; i < s.size(); ++i) {
    bool is_inserted = false;
    for (int j = 0; j < mins.size(); ++j) {
      if (mins[j] == s[i]) {
	break;
      }
      if (mins[j] > s[i]) {
	mins.insert(mins.begin() + j, s[i]);
	is_inserted = true;
	break;
      }
    }
    if (!is_inserted) {
      mins.push_back(s[i]);
    }
    if (mins.size() > k) {
      mins.resize(k);
    }
  }
  return mins[k-1];
}

int main() {
  string s;
  int K;
  cin >> s;
  cin >> K;

  char a[2] = {'\0'};
  a[0] = GetKthAlphabet(s, 1);
  string kth = string(a);

  if (K == 1) {
    cout << kth << endl;
    return 0;
  }

  int initial = 1;

  for (int i = 2; i <= K; ++i) {
    char min_c;
    bool exists = false;
    for (int j = 0; j < s.size() - kth.size(); ++j) {
      if (s.substr(j, kth.size()) == kth) {
	if (!exists) {
	  min_c = s[j + kth.size()];
	} else {
	  min_c = (s[j + kth.size()] < min_c) ? s[j + kth.size()] : min_c;
	}
	exists = true;
      }
    }
    if (exists) {
      kth += min_c;
    } else {
      char a[2] = {'\0'};
      ++initial;
      a[0] = GetKthAlphabet(s, initial);
      kth = string(a);
    }
  }

  cout << kth << endl;
  
  return 0;
}


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

using namespace std;

int main()
{
	long long A, B, K;
	cin >> A >> B >> K;

	if (K > A)
	{
		K = K - A;
		A = 0;
		B = B > K ? B - K : 0;
	}
	else
	{
		A = A - K;
	}

	cout << A << " " << B << endl;

	return 0;
}



Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n,k = map(int,input().split())
a = []
b = []
for _ in [0]*n:
    A,B = map(int,input().split())
    a.append(A)
    b.append(B)

judgeNum = pow(2,30)-1

res = 0
for i in range(29,-1,-1):
    tmp = 0
    if (k>>i)&1 == 0:
        judgeNum -= (1<<i)
    else:
        tmpJudge = judgeNum - (1<<i)
        for e,v in zip(a,b):
            if tmpJudge | e == tmpJudge:
                tmp += v
        res = max(res,tmp)
tmp = 0
for e,v in zip(a,b):
    if k | e == k:
        tmp += v
res = max(res,tmp)

print(res)

Measured memory_bytes: 52572
#-swank
(unless (member :child-sbcl *features*)
  (quit
	:unix-status
	(process-exit-code
	  (run-program *runtime-pathname*
				   `("--control-stack-size" "128MB"
					 "--noinform" "--disable-ldb" "--lose-on-corruption" "--end-runtime-options"
					 "--eval" "(push :child-sbcl *features*)"
					 "--script" ,(namestring *load-pathname*))
				   :output t :error t :input t))))

(let* ((n (read)) (l (loop for i from 1 to n collect (read))))
  (princ (- (reduce #'max l) (reduce #'min l))))


Measured memory_bytes: 6328
N, M = map(int, input().split())
H_list = list(map(int, input().split()))
H = [1 for i in range(N)]
for i in range(M):
  A, B = map(int, input().split())
  if H_list[A-1] >= H_list[B-1]:
    H[B-1] = 0
  if H_list[A-1] <= H_list[B-1]:
    H[A-1] = 0

print(sum(H))

Measured memory_bytes: 20000
#include <stdio.h>

int main(void)
{
	unsigned long long a,b,c;
	
	scanf("%llu %llu", &a,&b);
	
	c = a*(b/2);
	if(b%2==1){
		if(a%2==0){
			c = c + (a/2);
		}else{
			c = c + (a/2)+1;
		}
	}
	
	if(a == 1 || b == 1)c=1;
	printf("%llu\n", c);
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl
#define show2(a, n, m) rep(i, n) { rep(j, m) {cout << a[i][j] << ' ';} cout << endl;} 
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<long long, long long> pll;
typedef long double ld;

const int INF = 1 << 30;
const long long INFL = 1LL << 60;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

typedef vector<ld> vld;

int main() {
	cout << fixed << setprecision(15);
	int n;
	cin >> n;
	vld p(n);
	rep(i, n) cin >> p[i];

	vector<vld> dp(n+1, vld(n+1));
	dp[0][0] = 1.0;
	rep(i, n) rep(j, n) {
		dp[i+1][j+1] += dp[i][j] * p[i];
		dp[i+1][j] += dp[i][j] * (1 - p[i]);
	}
	ld ans = 0.0;
	for(int i = n / 2 + 1; i <= n; i++) ans += dp[n][i];
	cout << ans << endl;
}


Measured memory_bytes: 141056
#include <iostream>
#include <vector>
#include <queue>
typedef long long ll;
using namespace std;
int main(){
  int n,m;
  cin >> n >> m;
  vector<vector<int>> jobs(m);
  for(int i = 0;i < n;i++){
    int a,b;
    cin >> a >> b;
    if(a > m)continue;

    jobs[m-a].push_back(b);
  }

  priority_queue<int> q;
  ll ans = 0;
  for(int i = m-1;i >= 0;--i){
    for(int b : jobs[i]){
      q.push(b);
    }
    if(!q.empty()){
      ans += q.top();
      q.pop();
    }
  }

  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 5632
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<numeric>
#include<iomanip>
using namespace std;

int main() {
	string s;
	cin >> s;
	cout << s[0] << s.length() - 2 
		<< s[s.length() - 1] << endl;
}

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

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    unsigned long ans{0}, r{0}, g{0}, b{0};
    {
        string S;
        cin >> S;
        for(unsigned long i{0}; i < N; ++i)switch(S[i]){
            case 'R':
                ++r;
                break;
            case 'G':
                ++g;
                break;
            default:
                ++b;
        }
        for(unsigned long i{0}; i < N; ++i)for(unsigned long j{i + 2}; j < N; j += 2)if((S[i] ^ S[j] ^ 'W') == S[(i + j) / 2])--ans;
    }
    cout << ans + r * g * b << endl;
    return 0;
}

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

typedef long long ll;

ll N, M;

ll solve() {
  if (N >= 2 && M >= 2) return (N - 2) * (M - 2);
  if (N == 1 && M == 1) return 1;
  return max({0ll, M - 2, N - 2});
}
int main() {
  cin >> N >> M;
  cout << solve() << endl;
  return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	var i int
	if sc.Scan() {
		if num, err := strconv.Atoi(sc.Text()); err == nil {
			i = num
		}
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	var point = map[int]int{}
	for i := 0; i < n; i++ {
		point[i+1] = nextInt()
	}
	var min int
	var initialized bool
	for p := 0; p < 100; p++ {
		mtg := p + 1
		var currMin int
		for i := 0; i < len(point); i++ {
			diff := point[i+1] - mtg
			diff *= diff
			currMin += diff
		}
		if !initialized && min == 0 {
			min = currMin
			initialized = true
		}
		if currMin < min {
			min = currMin
		}
	}
	fmt.Println(min)
}


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

int main(void){
    
    int n;
    cin >> n;
    int data[n];
    
    for(int i=0;i<n;i++) cin >> data[i];
    
    sort(data,data+n);
    
    cout << abs(data[0] - data[n-1]) <<endl;
}

Measured memory_bytes: 3600