akhauriyash/Code-Regression huggingface dataset:
/*package whatever //do not write package name here */

import java.io.*;
import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.util.Scanner; 
import java.util.StringTokenizer; 
import java.util.*;


class Main {
    static class FastReader{
        BufferedReader br;
        StringTokenizer st;
        public FastReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next(){
            while(st==null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }
                catch(IOException e){
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt(){
            return Integer.parseInt(next());
        }
    }
    
	public static void main (String[] args) {
		FastReader ob = new FastReader();
		int n = ob.nextInt();
		int arr[] = new int[n];
		for (int i=0;i<n ;i++ ) {
		    arr[i] = ob.nextInt();
		}
		Arrays.sort(arr);
		int min_cost=Integer.MAX_VALUE;
		for (int j=arr[0];j<=arr[n-1] ;j++ ) {
		    int sum=0;
		    for (int i=0;i<n ;i++ ) {
		        sum+=(arr[i]-j)*(arr[i]-j);
		    }
		    min_cost=Math.min(min_cost,sum);
		}
		System.out.println(min_cost);
	    
	}
}

Measured memory_bytes: 21204
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define N 2009
#define ad(x,y) (x=(x+(y))%mod)
using namespace std;

int n,m,bin[N],dp[N][N],cbn[N][N];
int main(){
	scanf("%d%d",&n,&m);
	int i,j,tmp;
	for (i=bin[0]=1; i<=n; i++) bin[i]=(bin[i-1]<<1)%mod;
	for (i=0; i<=n; i++)
		for (j=cbn[i][0]=1; j<=i; j++)
			cbn[i][j]=(cbn[i-1][j]+cbn[i-1][j-1])%mod;
	dp[0][0]=1;
	for (i=1; i<m; i++){
		tmp=0;
		for (j=i; j; j--){
			ad(tmp,dp[i-1][j]);
			ad(dp[i][j],tmp); 
			ad(dp[i][j],dp[i-1][j-1]);
		}
	}
	int ans=0;
	for (i=1; i<=m; i++)
		ad(ans,(ll)dp[m-1][i-1]*cbn[i-1+n-m][n-m]%mod*(n>m?bin[n-m-1]:1));
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 30848
#include <bits/stdc++.h>
#include <stdarg.h>
#include <assert.h>
#include <ctype.h>
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/filter/gzip.hpp>
#include <boost/iostreams/device/file_descriptor.hpp>

using namespace std;
typedef long long int lli;
typedef vector<int> iv;
typedef vector<bool> bv;
typedef vector<string> sv;
typedef vector<long long int> llv;
typedef vector<double> dv;

#define sor_(vec) sort(vec.begin(),vec.end())
#define rev_(vec) reverse(vec.begin(),vec.end())
#define rep(i,n) for(int i=0;i<static_cast<int>(n);i++)
#define reps(i,n,s) for(int i=static_cast<int>(s);i<static_cast<int>(n);i++)
#define isposi(num) if(num>0)
const long long mod = 1000000007;

template<typename TypeInt>
std::string Itoa(const TypeInt v, int base)
{
    static const char table[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    string ret;
    static numeric_limits<TypeInt> t;
    TypeInt n = v;
    if (t.is_signed) {
        if (v < 0) n *= -1;
    }

    while (n >= base) {
        ret += table[n%base];
        n /= base;
    }
    ret += table[n];
    if (t.is_signed) {
        if (v < 0 && base == 10) ret += '-';
    }
    std::reverse(ret.begin(), ret.end());

    return ret;
}

int upf(double num){
    if(num-(int)num>0)return (int)num+1;
    else return num;
}

void printm(char const *format,...){
    va_list arguments;
    va_start(arguments,format);
    unsigned index=0;
    while (format[index]!='\0') {
        if(format[index]=='%'){
            index++;
            if(format[index]=='d')printf("%d",va_arg(arguments, int));
            else if(format[index]=='c')printf("%c",va_arg(arguments, int));
            else if(format[index]=='x')printf("%x",va_arg(arguments,int));
            else if(format[index]=='o')printf("%o",va_arg(arguments,int));
            else if(format[index]=='f')printf("%f",va_arg(arguments, double));
            else if(format[index]=='s')printf("%s",va_arg(arguments, char const *));
            else if(format[index]=='p')printf("%p",va_arg(arguments,void*));
            else if(format[index]=='y')printf("Yes");
            else if(format[index]=='n')printf("No");
            else if(format[index]=='%')printf("%%");
            else assert(!"Unknown format with %.");
        }
        else printf("%c",format[index]);
        index++;
    }
    va_end(arguments);
    return;
}

struct Chara{
    int hp;
    int sp;
};
bool pairCompare(const pair<int,int>& firstElof, const pair<int,int>& secondElof)
{
    return firstElof.second > secondElof.second;
}

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string A,B;
    cin>>A>>B;
    if(A==B.substr(0,A.length())&&B.length()==A.length()+1)printm("Yes");
    else printm("No");
    return 0;
}


Measured memory_bytes: 3648
import heapq

h = []
h2 = []
N, M = [int(i) for i in input().split()]
count = dict()
count2 = dict()
for i in input().split():
    if not count.get(i):
        count[i] = 0
    count[i] += 1
for k, v in count.items():
    heapq.heappush(h, (int(k), v))

for _ in range(M):
    B, C = [int(i) for i in input().split()]
    if not count2.get(C):
        count2[C] = 0
    count2[C] += B
for k, v in count2.items():
    heapq.heappush(h2, (-k, v))
while len(h2) > 0:
    C, B = heapq.heappop(h2)
    C = -C
    while B > 0:
        if h[0][0] >= C:
            break
        m = h[0][0]
        mc = h[0][1]
        if mc > B:
            heapq.heappush(h, (C, B))
            h[0] = (m, mc - B)
        else:
            heapq.heappop(h)
            heapq.heappush(h, (C, mc))
        B -= mc
print(sum([i[0] * i[1] for i in h]))



Measured memory_bytes: 54180
n = int(input())
l = list(map(str,input()))

ans = 0
for i in range(n):
    a = l[:i]
    b = l[i:]
    tmp = []
    for j in a:
        if j in b:
            tmp.append(j)
    tmp = set(tmp)
    ans = (max(ans,len(tmp)))

print(ans)

Measured memory_bytes: 9120
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.first<<","<<p.second<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
#else
#define dbg(...) {}
#endif

int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  rep(i,n) cin>>a[i];
  a.pb(1000000009);

  int ans = 0;
  int pre = -1;
  rep(i,n){
    if(a[i] < a[i+1]) {
      ans = max(ans, i - pre - 1);
      pre = i;
    }
  }
  cout << ans <<  endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef  long long LL;
typedef  unsigned long long ULL;
typedef  double db;
typedef  long double ld;
#pragma comment(linker, "/STACK:102400000,102400000")
#define fuck(x) cout<<x<<endl
#define fuck1(x,y) cout<<x<<" "<<y<<endl
#define lson root<<1,l,mid
#define rson root<<1|1,mid+1,r
#define MP(a,b) make_pair(a,b)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define se second
#define fi first
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
const int INF = 0x3f3f3f3f3f,mod = 1e9+7;
const double eps  =1e-6,PI = acos(-1);
template<typename T> inline void read(T &x){
    x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}
const int maxn = 2e5+100;
int N;
struct node{
       int time1,del;
}ax[maxn];
bool comp(node A,node B){
     if(A.del!=B.del)return A.del<B.del;
     return A.time1<B.time1;
}
int main(){
    scanf("%d",&N);
    for(int i = 1;i<=N;i++){
        scanf("%d%d",&ax[i].time1,&ax[i].del);
    }
    sort(ax+1,ax+1+N,comp);
    int nowt = 0;
    bool flag = 0;
    for(int i = 1;i<=N;i++){
        nowt+=ax[i].time1;
        if(nowt>ax[i].del)flag = 1;
    }
    if(flag)printf("No");
    else printf("Yes");

    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long
const int INF = 1LL << 60;

signed main(){

  string s; cin >> s;

  int n = s.size();
  map<char, int> mp;
  for(int i = 0; i < n; i++){
    mp[s[i]]++;
  }

  int ans = n * (n-1) / 2;
  for(char c = 'a'; c <= 'z'; c++){
    ans -= mp[c] * (mp[c]-1) / 2;
  }
  cout << ans + 1 << endl;

  return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>
int main(void){
    int m,i,h,len;
    int count=0;
    char str[404],inc[203];
    while(1){
        scanf("%s",str);
        if(str[0]=='-'){
            break;
        }
        scanf("%d",&m);
        for(i=0;i<m;i++){
            scanf("%d",&h);
            count+=h;
        }
        len=strlen(str);
        count%=len;
        strcpy(inc,str);
        strcat(str,inc);
        strncpy(inc,str+count,len);
        printf("%s\n",inc);
        count=0;
    }
    return 0;
}


Measured memory_bytes: 2144
#coding:utf-8

N = input()
K = int(input())
dp = [[[0 for _ in range(K+2)] for _ in range(2)] for _ in range(len(N) + 1)]
# 桁数、未満フラグ、状態数
dp[0][0][0] = 1

for i in range(len(N)):
    for smaller in range(2):
        for k in range(K+1):
            # 三つ目のインデックスに条件が入る
            for x in range(10 if smaller == 1 else int(N[i]) + 1):
                dp[i + 1][smaller == 1 or x < int(N[i])][k + 1 if x != 0 else k] += dp[i][smaller][k]
print(dp[len(N)][0][K] + dp[len(N)][1][K])

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

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

void solve() {
    int N; string S; cin >> N >> S;
    vector<int> e(N+1), w(N+1);
    for (int i = 1; i <= N; i++) {
        e[i] = e[i-1];
        w[i] = w[i-1];
        if (S[i-1] == 'E') e[i]++;
        else w[i]++;
    }

    int ans = 1000000;
    for (int i = 1; i <= N; i++) {
        int tmp = w[i-1] + (e[N] - e[i]);
        ans = min(ans, tmp);
    }

    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    solve();

    return 0;
}

Measured memory_bytes: 6092
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
typedef complex<double> P;
typedef pair<P,P> L;
const double INF = 1e12;
const double EPS = 1e-10;
double cross(const P& a, const P& b) {return imag(conj(a)*b);}
double dot(const P& a, const P& b) {return real(conj(a)*b);}
int ccw(P a, P b, P c) {
  b-=a;c-=a;
  if(cross(b,c)>EPS)return +1;
  if(cross(b,c)<-EPS)return -1;
  if(dot(b,c)<-EPS)return +2;
  if(norm(b)<norm(c))return -2;
  return 0;
}
double D(P a, P b){return sqrt((a.real()-b.real())*(a.real()-b.real())+(a.imag()-b.imag())*(a.imag()-b.imag()));}
bool intersectSS(const L &s, const L &t){return ccw(s.F,s.S,t.F)*ccw(s.F,s.S,t.S)<=0&&ccw(t.F,t.S,s.F)*ccw(t.F,t.S,s.S)<=0;}
P projection(const L &l, const P &p){double t=dot(p-l.F,l.F-l.S)/norm(l.F-l.S);return l.F+t*(l.F-l.S);}
P reflection(const L &l, const P &p){return p+2.0*(projection(l,p)-p);}
int main() {
  P p[2];
  for(int i=0; i<2; i++) {
    double x,y;
    cin >> x >> y;
    p[i]=P(x,y);
  }
  int n;
  cin >> n;
  P a[n];
  for(int i=0; i<n; i++) {
    double x,y;
    cin >> x >> y;
    a[i]=P(x,y);
  }
  bool f=0;
  for(int i=0; i<n; i++) f|=intersectSS(L(p[0],p[1]),L(a[i],a[(i+1)%n]));
  set<int> s[2];
  for(int i=0; i<2; i++) {
    for(int j=0; j<n; j++) {
      int cnt=0;
      for(int k=0; k<n; k++) cnt+=intersectSS(L(p[i],a[j]),L(a[k],a[(k+1)%n]));
      if(cnt<=2) s[i].insert(j);
    }
  }
  double ans=INF;
  if(f) {
    for(int i=0; i<n; i++) {
      if(!s[0].count(i)) continue;
      double d=0;
      for(int k=0; k<n; k++) {
        int j=(i+k)%n;
        if(s[1].count(j)) ans=min(ans,D(p[0],a[i])+d+D(a[j],p[1]));
        d+=D(a[j],a[(j+1)%n]);
      }
      d=0;
      for(int k=0; k<n; k++) {
        int j=(i-k+n)%n;
        if(s[1].count(j)) ans=min(ans,D(p[0],a[i])+d+D(a[j],p[1]));
        d+=D(a[j],a[(j-1+n)%n]);
      }
    }
  } else {
    for(int i=0; i<n; i++) {
      P q=reflection(L(a[i],a[(i+1)%n]),p[1]);
      if(intersectSS(L(a[i],a[(i+1)%n]),L(p[0],q))) ans=min(ans,D(p[0],q));
      ans=min(ans,D(p[0],a[i])+D(a[i],p[1]));
    }
  }
  printf("%.10f\n",ans);
  return 0;
}


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

int main(){
    int ans=0,sum=0;
    int n;
    cin >> n;


    //cout <<fixed<<setprecision(16)<< << endl;
    cout << 3*n*n << endl;

    //if(flag==1)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    int a,b;
    Scd2(a,b);
    if( a <= 0 && b >= 0 ){
        printf ("Zero\n");
    }else if( a < 0 && (b-a+1)%2 ){
        printf ("Negative\n");
    }else{
        printf ("Positive\n");
    }

    return 0;
}



Measured memory_bytes: 256
e=enumerate
n,a=open(0)
n=int(n)
d=[0]
for j,(a,i)in e(sorted((int(a),i)for i,a in e(a.split()))[::-1]):d=[d[0]+a*(~i-j+n)]+[max(d[k+1]+a*(n+k-i-j),t+a*abs(i-k))for k,t in e(d[:j])]+[d[j]+a*abs(i-j)]
print(max(d))

Measured memory_bytes: 74868
S=gets.chomp
str = "keyence"
if(S.start_with?(str) || S.end_with?(str))
	puts "YES"
	exit(0)
end
for i in 0..str.size-2
	if(S.start_with?(str[0..i]) && S.end_with?(str[(i+1)..(-1)]))
		puts "YES"
		exit(0)
	end
end
puts "NO"


Measured memory_bytes: 3836
// Problem : A - Not
// Contest : AtCoder - AtCoder Beginner Contest 178
// URL : https://atcoder.jp/contests/abc178/tasks/abc178_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  int x;
  cin >> x;
  cout << (1 - x) << endl;
}

Measured memory_bytes: 3584
/*
	submission # - User: herp_sy
	https://atcoder.jp/contests/
*/

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

// utility of stdin,stdout
#define _CRT_SECURE_NO_WARNINGS
#define OUT cout << 
#define BR << endl
#define RET return 0
#define TLong long long
#define TBMod 1000000007

int main(int argc, char const *argv[]){
	int n,d;
	cin >> n >> d;
	OUT((n + d * 2) / (d * 2 + 1)) BR;
	RET;
}


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

class AtCoder
{
    
    public void Slove()
    {
        var inputs = Console.ReadLine().Split();
        int n = int.Parse(inputs[0]);
        int k = int.Parse(inputs[1]);
        long result = 0;
        long a = n / k;
        result += a * a * a;
        if ((k & 1) == 0)
        {
            a = n / (k / 2) - a;
            result += a * a * a;
        }
        Console.WriteLine(result);
    }
    static void Main()
    {
        var ac = new AtCoder();
        ac.Slove();
    }
}

Measured memory_bytes: 11092
"use strict";
function main(input) {
    const line = input.split("\n");
    let N = parseInt(line[0]);
    let d = line[1].split(" ").map(Number);
    console.log(combination(d, 2).reduce((pre, cur) => pre + cur[0] * cur[1], 0));
    return;
}
const combination = (nums, k) => {
    let ans = [];
    if (nums.length < k) {
        return []
    }
    if (k === 1) {
        for (let i = 0; i < nums.length; i++) {
            ans[i] = [nums[i]];
        }
    } else {
        for (let i = 0; i < nums.length - k + 1; i++) {
            let row = combination(nums.slice(i + 1), k - 1);
            for (let j = 0; j < row.length; j++) {
                ans.push([nums[i]].concat(row[j]));
            }
        }
    }
    return ans;
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 30148
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define int64 long long
#define uint64 unsigned long long
using namespace std;

int main()
{
	int64 nn, aa, bb, tt = 0;
	cin >> nn;
	vector<pair<int64, int64>> vv(nn);
	for(int64 ii = 0;ii < nn;ii++)
	{
		cin >> aa >> bb;
		vv[ii].first = bb;
		vv[ii].second = aa;
	}
	sort(vv.begin(), vv.end());
	for(int64 ii = 0;ii < nn;ii++)
	{
		tt += vv[ii].second;
		if(tt > vv[ii].first)
		{
			puts("No");
			return 0;
		}
	}
	puts("Yes");
	return 0;
}

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

using namespace std;

int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x, y;
    cin >> x >> y;
    bool found = false;
    for(int i = 0; i <= x; i++) {
        int sum = (2 * i) + (4 * (x - i));
        if(sum == y) {
            found = true;
        }
    }
    if(found) {
        cout << "Yes\n";
    }
    else {
        cout << "No\n";
    }
    return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<int> x(n);
  for(int i=0; i<n; i++) cin >> x[i];
  
  ll dist = 0;
  ll min = 1e9;
  for(int i=1; i<=100; i++){
    for(int j=0; j<n; j++){
      dist += (x[j] - i)*(x[j] - i);
    }
    if(dist < min) min = dist;
    dist = 0;
  }
  
  cout << min << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		long[] l = new long[n+1];
		l[0]=2;
		l[1]=1;
		for(int i=0;i<n+1;i++) {
			if(i==0) {
				l[i]=2;
			}else if(i==1) {
				l[i]=1;
			}else {
				l[i]=l[i-2]+l[i-1];
			}
		}
		System.out.println(l[n]);


	}

}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin >> s;
  int cnt = 0;
  for (int i = 0; i < 3; i++) {
    if (s[i] == 'R') cnt++;
    else {
      if (cnt == 0) continue;
      else break;
    }
  }
  cout << cnt;
}

Measured memory_bytes: 3648
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	int n;
	cin >> n;
	int s[n+1], sum=0;
	s[0]=0;
	for(int i=1; i<=n; i++){
		int w;
		cin >> w;
		sum+=w;
		s[i]=s[i-1]+w;
	}
	int ans=10000;
	for(int i=1; i<=n; i++) ans=min(ans, abs(sum-2*s[i]));
	cout << ans << endl;
	return 0;
}

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

int main() {
  vector<int> a(3);
  for (int i = 0; i < 3; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  cout << a[0] + a[1] + 10 * a[2] << endl;
  return 0;
}

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

int main(){
  int N;
  cin>>N;
  bool ok=0;
  while(N>=0){
    if(N%4==0){
      cout<<"Yes"<<endl;
      ok=1;
      break;
    }
    N-=7;
    }//while
  if(ok==0)cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
    #include<sstream>
    #include<vector>
    #include<iterator>
    using namespace std;
     
    int main()  
    {
    	int N, K;
    	cin >> N >> K;
     
    	long long ret = 0;
    	long long cnt = N / K;
    	ret = cnt * cnt * cnt;
    	if(K%2 == 0){
    		cnt = N/K + ((N%K) >= K/2);
    		ret += cnt * cnt * cnt;
    	}
     
    	cout << ret << endl;
     
    	return 0;
    }

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

void solve(long long N, long long A, long long B, vector<long long> X){
	long long ans = 0;
  for ( long long i = 1; i < N; i++ ) {
    if ( (X[i] - X[i-1]) * A > B ) { ans += B; } else { ans += (X[i] - X[i-1]) * A; }
  }
  cout << ans << endl;
}

int main(){	
	long long N;
	long long A;
	long long B;
	scanf("%lld",&N);
	vector<long long> X(N-1+1);
	scanf("%lld",&A);
	scanf("%lld",&B);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&X[i]);
	}
	solve(N, A, B, X);
	return 0;
}



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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
from fractions import gcd

def main():
    mod=10**9+7
    a,b,c=MI()
    d=gcd(a,b)
    if c%d==0:
        print("YES")
    else:
        print("NO")

main()


Measured memory_bytes: 63852
import java.util.*;

class Main {
        public static void main(String args[]) {
                Scanner sc = new Scanner(System.in);
                int[] prime = new int[10001];
                prime[0] = prime[1] = 1;
                for (int i = 2; i < 10001; i++) {
                        if (prime[i] == 0) {
                                int j = 2;
                                while (i * j < 10001) {
                                        prime[i * j] = 1;
                                        j++;
                                }
                        }
                }
                while (true) {
                        int N = sc.nextInt();
                        if (N == 0) {
                                return;
                        }
                        while (true) {
                                if (prime[N] == 0 && prime[N - 2] == 0) {
                                        System.out.println(N-2 + " " + N);
                                        break;
                                }
                                N--;
                        }
                }
        }
}

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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) (int)((a).size())
#define all(c) (c).begin(), (c).end()
#define debug(v) {for (auto z : v) {cerr << z << ' ';} cerr << endl;}

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	int n;
	cin >> n;
	cout << ((n+1) / 2) << endl;
}


Measured memory_bytes: 256
n = int(input())
a = input().split()
d = {}
for i in range(n):
	e = int(a[i])
	if e in d:
		d[e] += 1
	else:
		d[e] = 1
q = int(input())
f = 0
for p in d:
	f += p * d[p]
for i in range(q):
	b, c = map(int, input().split())
	if b in d:
		f += (c - b) * d[b]
		print(f)
		if c in d:
			d[c] += d[b]
			d[b] = 0
		else:
			d[c] = d[b]
			d[b] = 0
	else:
		print(f)

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

int main(){
  int n;
  cin >> n;
  vector<int>h(n);
  for(int i=0; i<n; i++){
    cin >> h[i];
  }
  for(int i=n-1; i>=1; i--){
    if(h[i]<h[i-1]-1){
      cout << "No";
      return 0;
    }
    else if(h[i]==h[i-1]-1)h[i-1]--;
  }
  cout << "Yes";
  return 0;
}


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

vector<pair<ll, ll>> sequence(ll x, ll A) {
  vector<pair<ll, ll>> seq;
  if (x < A) {
    seq.emplace_back(1, x);
  } else {
    if (A > 1) {
      seq.emplace_back(1, A - 1);
    }
    seq.emplace_back(A + 1, x + 1);
  }
  return seq;
}

ll findMaximumProduct(const ll len, const ll as, const ll bs) {
  ll L = 0, R = len - 1;
  while (R - L > 10) {
    ll m = (R - L) / 3;
    ll l = L + m, r = R - m;
    if ((as + l) * (bs - l) < (as + r) * (bs - r)) {
      L = l;
    } else {
      R = r;
    }
  }
  ll mx = 0;
  for (ll x = max(0ll, L - 10); x <= min(len - 1, R + 10); x++) {
    mx = max(mx, (as + x) * (bs - x));
  }
  return mx;
}

ll findMaximumProduct(const vector<pair<ll, ll>>& seqA,
                      const vector<pair<ll, ll>>& seqB) {
  vector<ll> indA(seqA.size() + 1, 0), indB(seqB.size() + 1, 0);
  for (int i = 1; i <= seqA.size(); i++)
    indA[i] = indA[i - 1] + (seqA[i - 1].second - seqA[i - 1].first + 1);
  for (int i = 1; i <= seqB.size(); i++)
    indB[i] = indB[i - 1] + (seqB[i - 1].first - seqB[i - 1].second + 1);
  ll mx = 0;
  for (int i = 0; i < seqA.size(); i++) {
    for (int j = 0; j < seqB.size(); j++) {
      ll s = max(indA[i], indB[j]), t = min(indA[i + 1], indB[j + 1]);
      if (s < t) {
        ll as = seqA[i].first + (s - indA[i]),
           bs = seqB[j].first - (s - indB[j]);
        mx = max(mx, findMaximumProduct(t - s, as, bs));
      }
    }
  }
  return mx;
}

int main() {
  int Q;
  while (cin >> Q) {
    for (int q = 0; q < Q; q++) {
      ll A, B;
      cin >> A >> B;
      ll C = A * B;
      ll ok = 0, ng = C + 100;
      while (ng - ok > 1) {
        ll x = (ok + ng) / 2;
        assert(x > 0);
        auto seqA = sequence(x, A);
        auto seqB = sequence(x, B);
        reverse(seqB.begin(), seqB.end());
        for (auto& b : seqB) {
          swap(b.first, b.second);
        }
        if (findMaximumProduct(seqA, seqB) < C) {
          ok = x;
        } else {
          ng = x;
        }
      }
      cout << ok << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <list>
#include <cstring>
#include <stack>
   
using namespace std;

#define mod 1000000007
   
int main()
{
    string s1, s2;
    cin >> s1 >> s2;
    int result[1001][1001] = {};
    for(int i = 0; i <= s1.length(); i++){
        result[i][0] = i;
    }
    for(int i = 0; i <= s2.length(); i++){
        result[0][i] = i;
    }
    for(int i = 1; i <= s1.length(); i++){
        for(int j = 1; j <= s2.length(); j++){
            result[i][j] = result[i - 1][j - 1];
            if(s1[i - 1] != s2[j - 1]) result[i][j]++;
            result[i][j] = min(result[i][j], min(result[i - 1][j] + 1, result[i][j - 1] + 1));
        }
    }
    // for(int i = 0; i <= s1.length(); i++){
    //     for(int j = 0; j <= s2.length(); j++){
    //         cout << result[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    cout << result[s1.length()][s2.length()] << endl;
    return 0;
}

Measured memory_bytes: 5108
#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#pragma GCC optimize ("O3")
	#define NDEBUG
#endif
// #define _USE_MATH_DEFINES
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { os << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

const array<int, 4> dx = {0, 1, 0, -1};
const array<int, 4> dy = {1, 0, -1, 0};


typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;

void ios_init(){
	cout.setf(ios::fixed);
	cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);
}

int main()
{
	ios_init();
	double n;
	while(cin >> n) {
		cout << int(n + 1) / 2  / n << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

unsigned long euclidean_gcd(unsigned long a, unsigned long b)
{
    if (a < b)
        return euclidean_gcd(b, a);

    unsigned long r;
    while ((r = a % b))
    {
        a = b;
        b = r;
    }
    return b;
}

int main()
{
    long a, b, c, d;
    cin >> a >> b >> c >> d;
    a -= 1;
    long m = c * d / euclidean_gcd(c, d);

    long c1 = (b / c) - (a / c);
    long c2 = (b / d) - (a / d);
    long c3 = (b / m) - (a / m);

    cout << (b - a - (c1 + c2 - c3)) << "\n";
}

Measured memory_bytes: 256
fn main() {
    proconio::input! {
        w: i64,
        h: i64,
        n: usize,
        xyas: [(i64, i64, i64); n],
    }
    let lmax = xyas
        .iter()
        .filter(|(_, _, a)| *a == 1)
        .map(|(x, _, _)| *x)
        .max()
        .or(Some(0))
        .unwrap();
    let rmin = xyas
        .iter()
        .filter(|(_, _, a)| *a == 2)
        .map(|(x, _, _)| *x)
        .min()
        .or(Some(w))
        .unwrap();
    let dmax = xyas
        .iter()
        .filter(|(_, _, a)| *a == 3)
        .map(|(_, y, _)| *y)
        .max()
        .or(Some(0))
        .unwrap();
    let umin = xyas
        .iter()
        .filter(|(_, _, a)| *a == 4)
        .map(|(_, y, _)| *y)
        .min()
        .or(Some(h))
        .unwrap();
    let ans = std::cmp::max(0, rmin - lmax) * std::cmp::max(0, umin - dmax);
    println!("{}", ans);
}


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

//半分全列挙
int main(){
    int X,Y,Z,K;
    cin >> X >> Y >> Z >> K;
    vector<ll> a(X),b(Y),c(Z);

    rep(i,X) cin >> a[i];
    rep(i,Y) cin >> b[i];
    rep(i,Z) cin >> c[i];

    //aとbを全部求める
    vector<ll> ab;
    rep(i,X){
        rep(j,Y){
            ab.push_back(a[i] + b[j]);
        }
    }
    sort(c.begin(),c.end(),greater<ll>());
    sort(ab.begin(),ab.end(),greater<ll>());
    vector<ll> res;
    rep(i,min((int)c.size(),K)){
        rep(j,min((int)ab.size(),K)){
            res.push_back(c[i] + ab[j]);
        }
    }
    sort(res.begin(),res.end(),greater<ll>());
    rep(i,K)cout << res[i] << endl;
    return 0;
}

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

const long mod = 1000000007;

long f(long m, long n) {
    if (n == 0) return 1;
    if (n % 2 == 1) return m * f(m, n - 1) % mod;
    long r = f(m, n / 2) % mod;
    return r * r % mod;
}

int main() {
    long m, n;
    cin >> m >> n;
    cout << f(m, n) << endl;
}


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

using namespace std;
#define set_precision(ans,l) cout << fixed << setprecision(l)<<ans;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repb(i, a, b) for (int i = a; i >= b; i--)
#define vi vector<int>
#define vl vector<long long int>
#define Vi vector<vector<int>>
#define vpi vector<pair<int,int>>
#define seti set<int>
#define setl set<ll>
#define dseti set<int, greater<int>>
#define dsetl set<ll, greater<ll>>
#define mseti multiset<int>
#define msetl multiset<ll>
#define dmseti multiset<int, greater<int>>
#define dmsetl multiset<ll, greater<ll>>
#define sortA(arr) sort(arr.begin(), arr.end())
#define dsortA(arr) sort(arr.begin(), arr.end(), greater<ll>())
#define ssort(arr) stable_sort(arr.begin(), arr.end())
#define nth(v,n) nth_element(v.begin,v.begin+n-1,v.end())
#define dnth(v,n) nth_element(v.begin,v.begin+n-1,v.end(), greater<ll>())
#define init(a)  memset((a),0,sizeof(a))
#define pi pair<int,int>
#define pb push_back
#define pl pair<ll,ll>
#define ll long long
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007
long double EPS = 1e-9;

/*struct comp {
  bool operator() (const int& lhs, const int& rhs) const
  {return lhs<rhs;}
};*/

ll cel(ll a,ll b){return((a-1)/b+1);} 
ll gcd(ll a, ll b){
    if (a < b)swap(a, b);
    return (b == 0)? a: gcd(b, a % b);
}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
ll po(ll x,ll y){
    ll ans=1;
    while(y){
        if(y&1){ans=(ans*x)%mod;}
        y>>=1;x=(x*x)%mod;
    }
    return ans;
}

int main()
{
    FIO;
    ll n,t,x,y,m,k,ans=0;
    cin>>n;vl v(n),pre(n,0);
    rep(i,0,n){cin>>v[i];}
    pre[0]=v[0];
    rep(i,1,n){pre[i]=pre[i-1]+v[i];}
    rep(i,0,n-1){
        ans=(ans+(v[i]*((pre[n-1]-pre[i])%mod))%mod)%mod;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 6376
/**********************************************************************
   File abc163_a.cpp
   Author  harunaya
   Date   2020-05-11(Mon)
   note   
**********************************************************************/

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define PI 3.14159265359
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> a(m);
	rep(i,m) {
		cin >> a.at(i);
	}
  int sum = 0; // 宿題を終わらせるのにかかる日数
	rep(i,m) {
		sum += a.at(i);
	}

	int ans = n - sum;
	if (ans >= 0) {
		cout << ans << endl;
	}
	else {
		cout << -1 << endl;
	}
}

Measured memory_bytes: 3668
#ifdef Prateek
  #include "Prateek.h"
#else
  #include <bits/stdc++.h>
  using namespace std;
  #define debug(...) 42
#endif
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int n;
   string s;
   cin >> n >> s;
   int cR = count(all(s),'R');
   int cW = n-cR;
   int ans = min(cR,cW);
   debug(ans);
   int curR = 0, curW = 0;
   f(i,0,n){
      curW += (s[i] == 'W');
      curR += (s[i] == 'R');
      int req = i+1-curR;
      int rem = cR-curR;
      if(req <= rem){
         ans = min(ans,rem);
      }else{
         ans = min(ans,rem+i+1-req);
      }
   }
   cout << ans << '\n';
   return 0;
} 

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    string A, B;
    cin >> A >> B;
    if (A.size() > B.size()) {
        cout << "GREATER" << endl;
    } else if (A.size() < B.size()) {
        cout << "LESS" << endl;
    } else if (A > B) {
        cout << "GREATER" << endl;
    } else if (A < B) {
        cout << "LESS" << endl;
    } else {
        cout << "EQUAL" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;



public class Main {


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		HashMap<Integer, ArrayList<Edge>> map = new HashMap<>();
		for (int i=1;i<=n;i++) {
			map.put(i, new ArrayList<Edge>());
		}
		for (int i=0;i<n-1;i++) {
			int u = sc.nextInt();
			int v = sc.nextInt();
			int w = sc.nextInt();
			Edge e = new Edge();
			e.from = u;
			e.to = v;
			e.w = w;
			map.get(u).add(e);
			map.get(v).add(e);
		}
		
		HashMap<Integer, Integer> color = new HashMap<>();
		
		dfs(map, color, 1, 0);
		
		for (int i=1;i<=n;i++) {
			System.out.println(color.get(i));
		}
	}
	
	static void dfs(HashMap<Integer, ArrayList<Edge>> map, HashMap<Integer, Integer> color, int v, int c) {
		color.put(v, c);
		for (Edge e:map.get(v)) {
			int u = e.from+e.to-v;
			if (!color.containsKey(u)) {
				dfs(map, color, u, (c+e.w)%2);
			}
		}
	}



}

class Edge {
	int from;
	int to;
	int w;
}





Measured memory_bytes: 119436
#include <iostream>
#include <string>
#include <math.h>
#include <map>
#include <stdio.h>
#include <ctype.h>
#include <algorithm>
#include <stdlib.h>
#include <stack>
#include <queue>
#include <bitset>
#include <memory.h>

using namespace std;



int main() {
    
    double x;
    while(cin>>x){
        if(x<=48.00)cout<<"light fly";
        else if(x<=51.00)cout<<"fly";
        else if(x<=54.00)cout<<"bantam";
        else if(x<=57.00)cout<<"feather";
        else if(x<=60.00)cout<<"light";
        else if(x<=64.00)cout<<"light welter";
        else if(x<=69.00)cout<<"welter";
        else if(x<=75.00)cout<<"light middle";
        else if(x<=81.00)cout<<"middle";
        else if(x<=91.00)cout<<"light heavy";
        else cout<<"heavy";
        cout<<endl;
    }
}

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

/*vector<int> p(n);
cin >> p[i]*/

int main(){

    int h, n;
    int num=0;
    cin >> h >> n;
    vector<int> p(n);
    for(int i=0; i<n; i++) cin >> p[i];

    for(int i=0; i<n; i++){
        num += p[i];
    }

    if(num >= h) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 640
import java.util.*;


class Main{
    static long mod = 1000000007;
    public static void main(String argv[]) {
        Scanner sc = new Scanner(System.in);
        final long A = sc.nextLong();
        final long B = sc.nextLong();
        final long C = sc.nextLong();
        final long D = sc.nextLong();
        long count=B-A+1;

        count = count - (A%C == 0 ? B/C - A/C + 1 : B/C - A/C);
        count = count - (A%D == 0 ? B/D - A/D + 1 : B/D - A/D);
        long mi = Math.min(C, D);
        long ma = Math.max(C, D);
        long tmp = 0;
        while((tmp=ma%mi)!=0){
            ma = mi;
            mi = tmp;
        }
        long CD = C*D/mi;
        count = count + (A%CD == 0 ? B/CD - A/CD + 1 : B/CD - A/CD);
        System.out.println(count);
    }
}

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

using namespace std;

void solve()
{
	int n;
	cin >> n;
	
	string s;
	cin >> s;
	
	int res = 0;
	
	for(int i = 0; i < s.size() - 2; i++)
		if(s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C')
			res++;
	
	cout << res << '\n';
}

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

Measured memory_bytes: 256
input = gets.strip

words = %w[dream dreamer erase eraser]

until input.empty?
  reduced = false
  words.each do |w|
    wc = w.length # wordの長さ
    if input.slice(-wc, wc) == w
      reduced = true
      input = input.slice(0..-wc - 1)
    end
  end
  break unless reduced
end

puts input.empty? ? 'YES' : 'NO'

Measured memory_bytes: 61584
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
const ll INF = 1LL << 60;

int main(){
	int n, a, b; cin >> n >> a >> b;
	cout << min(n*a, b) << endl;
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,a,b) for(int i=(int)(a-1);i>=b;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define INF INT_MAX/3

int main() {
  cin.sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> v;
  v.pb(1);
  int i = 6;
  while(i <= n) v.pb(i), i *= 6;
  i = 9;
  while(i <= n) v.pb(i), i *= 9;
  sort(all(v));
  int cnt[n + 1];
  rep(i, n + 1) cnt[i] = INF;
  cnt[0] = 0;
  rep(i, v.size()) {
    rep(j, n + 1) {
      if (cnt[j] < INF && j + v[i] < n + 1) minch(cnt[j + v[i]], cnt[j] + 1);
    }
  }
  cout << cnt[n] << endl;
  return 0;
}


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

bool search(long A[], long n, long key){
	long i = 0;
	A[n] = key;
	while (A[i] != key) i++;
	return i != n;
}

int main(){
	long n, A[10001], q, key, sum = 0;
	cin >> n;
	for (long i = 0; i < n; i++) cin >> A[i];
	cin >> q;
	for (long i = 0; i < q; i++){
		cin >> key;
		sum += search(A, n, key);
	}
	cout << sum << endl;
	return 0;
}

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

int const N = 100000;
set<int> g[N + 1];
bool vis[N + 1];

void no() { printf("No\n"); exit(0); }
void yes() { printf("Yes\n"); exit(0); }

void er(int a, int b) { g[a].erase(b); g[b].erase(a); }

int go(int v, int p = 0){
	vis[v] = true;
	for (auto it = g[v].begin(); it != g[v].end(); ++it){
		if (*it == p)continue;
		if (vis[*it]){
			int an = *it;
			er(v, *it);
			return an;
		}
		int t = go(*it, v);
		if (t == 0)return 0;
		er(v, *it);
		if (t == v)t = 0;
		return t;
	}
}

int main(){
	int n, m;
	scanf("%d%d", &n, &m);
	f(i, 0, m){
		int a, b;
		scanf("%d%d", &a, &b);
		g[a].insert(b);
		g[b].insert(a);
	}
	f(i, 1, n + 1)if (g[i].size() & 1)no();
	int fr4 = 0, fr6 = 0;
	f(i, 1, n + 1)if (g[i].size() == 4)++fr4;
	else if (g[i].size() > 4)++fr6;
	if (fr4 > 2 || fr6)yes();
	f(it, 0, 3){
		bool ok = false;
		f(i, 1, n + 1)vis[i] = false;
		f(i, 1, n + 1)if (!g[i].empty()){
			ok = true;
			go(i);
			break;
		}
		if (!ok)no();
	}
	yes();
}

Measured memory_bytes: 19712
import java.util.Scanner;

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

		int s = sc.nextInt();
		int w = sc.nextInt();
		if (s <= w)
			System.out.println("unsafe");
		else
			System.out.println("safe");
	}

}


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

int main() {
  int N, sum,c1,c2,c3,c4,c5,LA;
  string A, B, C;
  cin >>A>>B>>C;
  sum =1;
  N = A.size();
  
 cout<<"A"<<B.at(0)<<"C"<<endl;
/*  	if(A=="a"||A=="e"||A=="i"||A=="o"||A=="u"){
    cout<<"vowel"<<endl;
    }
    else{
    cout<<"consonant"<<endl;
    }
 
*/

}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
const ll INF = 1000000000;
const int MAX_V = 10;
using namespace std;
using P = pair<int, int>;

struct edge {
  ll to, cost;
};

int V;
vector<vector<edge>> G(MAX_V);
vector<vector<ll>> d(MAX_V, vector<ll>(MAX_V, INF));

// 始点sから各頂点への最短距離
void dijkstra(int s) {
  // greater<P> を指定することで昇順（距離が小さい順)にする
  priority_queue<P, vector<P>, greater<P>> que;

  d[s][s] = 0;
  que.push(P(0, s));

  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[s][v] < p.first) continue;

    for (int i = 0; i < G[v].size(); i++) {
      edge e = G[v][i];
      if (d[s][e.to] > d[s][v] + e.cost) {
        d[s][e.to] = d[s][v] + e.cost;
        que.push(P(d[s][e.to], e.to));
      }
    }
  }
}

int main() {
  int H, W;
  cin >> H >> W;
  REP(i, 10) REP(j, 10) {
    int c;
    cin >> c;
    edge e;
    e.to = j, e.cost = c;
    G[i].emplace_back(e);
  }

  vector<vector<int>> A(H, vector<int>(W));
  REP(i, H) REP(j, W) cin >> A[i][j];
  REP(i, 10) dijkstra(i);

  ll ans = 0;
  REP(i, H) REP(j, W) {
    int s = A[i][j];
    if (s == -1 || s == 1)
      continue;
    else
      ans += d[s][1];
  }

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

Measured memory_bytes: 384
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
struct point { int d; long long vl; };
int N, M, K, A, B, C, S[3009]; long long T;
int main() {
	cin >> N >> M >> K >> A >> B >> C >> T;
	for (int i = 0; i < M; i++) cin >> S[i], S[i]--;
	vector<point> v;
	for (int i = 0; i < M - 1; i++) {
		int pl = S[i] + (T - 1LL * S[i] * B >= 0 ? (T - 1LL * S[i] * B) / A : 0) + 1, pr = (T - 1LL * S[i + 1] * B >= 0 ? S[i + 1] : S[i + 1] + 1);
		if (pl < pr) v.push_back(point{ pr - pl, T - 1LL * S[i] * B - (1LL * (T - 1LL * S[i] * B) / A + 1) * C });
	}
	for (int i = 0; i < K - M; i++) {
		int cost = 0, pos = -1;
		for (int j = 0; j < v.size(); j++) {
			if (v[j].vl >= 0) {
				int res = min((long long)v[j].d, v[j].vl / A + 1);
				if (cost < res) {
					pos = j;
					cost = res;
				}
			}
		}
		if (pos == -1) break;
		v[pos].d = max(v[pos].d - v[pos].vl / A - 1, 0LL);
		v[pos].vl -= (v[pos].vl / A + 1) * C;
	}
	int ret = N - 1;
	for (point i : v) ret -= i.d;
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 3228
import sys

N = int(input())

R = []
for i in range(N):
    a, b = [int(x) for x in input().split()]
    R.append((a, b))

B = []
for i in range(N):
    c, d = [int(x) for x in input().split()]
    B.append((c, d))

R.sort(key=lambda x: x[1], reverse=True)
B.sort(key=lambda x: x[0])

ans = 0
used_idx = []
for b in B:
    idx = -1
    for i, r in enumerate(R):
        if b[0] > r[0] and b[1] > r[1]:
            if used_idx.count(i) == 0:
                idx = i
                break
    if idx != -1:
        used_idx.append(idx)
        ans += 1
        # print("{},{}".format(b, ma_r))

print(ans)



Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n,m;
	cin >> n >> m;
	vector<int> ac(n,0), wa(n,0);
	REP(i,m){
		int p;
		string s;
		cin >> p >> s;
		p--;
		if(s=="AC"){
			ac[p]=1;
		}else if(s=="WA" && ac[p]==0){
			wa[p]++;
		}
	}
	int ac_sum = 0;
	int wa_sum = 0;
	REP(i,n){
		ac_sum += ac[i];
		wa_sum += (ac[i]==1 ? wa[i] : 0);
	}

	cout << ac_sum << " " << wa_sum << '\n';
	return 0;
}



Measured memory_bytes: 1024