akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#define MAX 100
#define INFTY 200000
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,T[MAX][MAX];

void dijkstra(){
  int minv,i,v,u;
  int d[MAX],color[MAX];

  for(i=0;i<n;i++){
    d[i] = INFTY;
    color[i] = WHITE;
  }

  d[0] = 0;
  color[0] = GRAY;
  while(1){
    minv = INFTY;
    u = -1;
    for(i = 0;i<n;i++){
      if(minv>d[i] && color[i] != BLACK){
        u = i;
        minv = d[i];
      }
    }
    if(u == -1)break;
    color[u] = BLACK;
    for(v = 0;v<n;v++){
      if(color[v] != BLACK && T[u][v] != INFTY){
        if(d[v]>d[u]+T[u][v]){
          d[v] = d[u] + T[u][v];
          color[v] = GRAY;
        }
      }
    }
  }
  for(i = 0;i<n;i++){
    printf("%d",i);
    printf(" ");
    d[i]= (d[i] == INFTY) ? -1 : d[i];
    printf("%d\n",d[i]);
  }
}

int main(){
  int i,k,c,u,v,j;

  scanf("%d",&n);
  for(i = 0;i<n;i++){
    for(j = 0;j<n;j++){
      T[i][j] = INFTY;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    for(j = 0;j<k;j++){
      scanf("%d %d",&v,&c);
      T[u][v] = c;
    }
  }
  dijkstra();

  return 0;
}


Measured memory_bytes: 2088
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;

//素因数分解 {素数、何乗}の配列、1のときは要素なしの配列
vector<pair<int,int>> primefact(ll N){
    vector<pair<int,int>> ans(0);
    ll a=2;
    while(N>=a*a){
        if(N%a==0){
            ans.push_back({a,0});
            ll A=ans.size()-1;
            while(N%a==0){
                ans.at(A).second++;
                N/=a;
            }
        }
        a++;
    }
    if(N>1)ans.push_back({N,1});
    return ans;
}

int main() {
    ll N;
    cin>>N;
    if(N==1){cout<<0<<endl;return 0;}
    vector<pair<int,int>> Nfact=primefact(N);
    ll ans=0;
    rep(i,Nfact.size()){
        int minus=1;
        int begin=Nfact.at(i).second;
        while(begin>=minus){
            begin-=minus;
            minus++;
            ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3632
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String input = br.readLine();
		int n = Integer.parseInt(input);
		
		int[] c = new int[n-1];
		int[] f = new int[n-1];
		int[] s = new int[n-1];
		
		//init
		for(int i = 0; i < n -1 ;i++){
			String[] tmpArray = br.readLine().split(" ");
			c[i] = Integer.parseInt(tmpArray[0]);
			f[i] = Integer.parseInt(tmpArray[1]);
			s[i] = Integer.parseInt(tmpArray[2]);
		}
		
		//i番目の駅からスタート
		for(int i = 0; i < n; i++){
			int time = 0;
			
			//j番目の駅に乗る
			for(int j = i; j < n - 1; j++){
				//出発時刻の最も早い電車を選ぶ
//				System.out.println("at st."+j+" time "+time);
				int soon = time;
				
				if(soon <= f[j]){
					soon = f[j];
				}
				else if(soon % s[j] == 0){
					
				}
				else {
					soon = (soon / s[j] * s[j] + s[j]);
				}
				
				time = soon + c[j];
				
			}
			
			System.out.println(time);
		}
	}

}


Measured memory_bytes: 24020
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A;
  cin >> A;
  if(A % 10 == 9) {
    cout << "Yes" << endl;
  }
  else if(A + 10 >= 100) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3560
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
//const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int a[n]; rep(i, n) cin >> a[i];
    ll sum = 0;
    int right = 0;
    int x = 0;
    ll res = 0;
    rep(left, n) {
        /*
        cout << endl;
        cout << left << endl;
         */
        while (right < n) {
            
            if (sum + a[right] > (x ^ a[right])) {
                break;
            } else {
                sum += a[right];
                x ^= a[right];
            }
            ++right;
            //cout << sum << " " << x << endl;
        }
        res += (right - left); //個数
        if (right == left) ++right;
        else {
            sum -= a[left];
            x ^= a[left];
        }
        //cout << left << " " << right << endl;
    }
    cout << res << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const long long INF = (1LL << 32);
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll>> vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl

/*--------------------template--------------------*/


int main() {
    cin >> n >> m;
    vi va(n), vb(n);
    REP(i,n) {
        cin >> va[i] >> vb[i];
    }
    sort(ALL(va));
    sort(RALL(vb));
    ll ma = va.back();
    while(m>0){
        if(vb[sum]>ma){
            m -= vb[sum];
            sum++;
            cnt++;
        }else{
            m -= ma;
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <functional>
#include <set>
#define DB cerr<<"D"<<endl
#define pb push_back
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";} template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";} template<typename T> void caut(T a){cout<<"("<<a<<") ";}
using P=pair<ll,ll>;
const ll M = 1e9+7;
void add(ll& x, ll y) {x+=y; x%=M;}
void chmax(ll& x, ll y) {if (x<y) x=y;}

int main() {
  int n; cin>>n;
  ll a[n];
  //for(int i=0;i<n;i++) a[i]=i+1;
  for(int i=0;i<n;i++) cin>>a[i];
  sort(a,a+n);
  /*
  for(int i=0;i<n;i++) {
    cout<<a[i]<<" ";
  } cout<<endl;*/
  bool b[1000001]={};
  ll an=0;
  for(int i=0;i<n;i++) {
    if (i!=0 && a[i-1]==a[i]) continue;
    bool ok=true;
    if (b[a[i]]) ok=false;
    for(ll j=a[i];j<=1000000;j+=a[i]) {
      b[j]=true;
    }
    //for(int j=0;j<=100;j++) cout<<b[j]; cout<<endl;
    if (i!=n-1 && a[i]==a[i+1]) ok=false;
    an+=ok;
  }
  cout<<an<<endl;
}

Measured memory_bytes: 6112
#include <bits/stdc++.h>
using namespace std;
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
#define LL long long
#define STEP 0.0005
// sort(a.begin(), a.end(), std::greater<int>());

int main()
{
    int n;
    cin >> n;
    vector<int> a;
    int b, c;
    rep(i, n)
    {
        int temp;
        cin >> temp;
        a.push_back(temp);
    }
    SORT(a);
    b = a[a.size() - 1];
    c = 0;
    double sa = INT_MAX;
    rep(i, n)
    {
        if (abs(b / 2.0 - a[i]) < sa)
        {
            c = a[i];
            sa = abs(b / 2 - a[i]);
        }
    }
    cout << b << " " << c << endl;
    return 0;
}


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

int main(){
int sx,sy,tx,ty;
cin>>sx>>sy>>tx>>ty;
for(int i=sy;i<ty;++i) cout<<"U";
for(int i=sx;i<tx;++i) cout<<"R";
for(int i=ty;i>sy;--i) cout<<"D";
for(int i=tx;i>sx;--i) cout<<"L";
cout<<"L";
for(int i=sy;i<=ty;++i) cout<<"U";
for(int i=sx;i<=tx;++i) cout<<"R";
cout<<"D"<<"R";
for(int i=ty;i>=sy;--i) cout<<"D";
for(int i=tx;i>=sx;--i) cout<<"L";
cout<<"U";
}

Measured memory_bytes: 3636
#include <iostream>

using namespace std;

int main()
{
     int H,N;
     cin>>H>>N;
     int A[N];
     for(int i=0;i<N;i++)
     {

        cin>>A[i];
        H=H-A[i];
             }
             if(H==0||H<0)
             {
                 cout<<"Yes";

             }
             else{
                cout<<"No";
             }
    return 0;
}


Measured memory_bytes: 640
n = int(input())
v = input().split(" ")
c = input().split(" ")

for i in range(n):
    v[i] = int(v[i])
    c[i] = int(c[i])

sum = 0

for i in range(n):
    if(v[i] > c[i]):
        sum += v[i] - c[i]

print(sum)


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define EPS 1e-9
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

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


signed main(void) {
    int n;
    cin >> n;
    vs s(n);
    map<string,int> ma;
    rep(i,n){
        cin >> s[i];
        sort(all(s[i]));
        ma[s[i]]++;
    }
    int ans = 0;
    rep(i,n)ans += ma[s[i]]-1;
    cout << ans/2 << endl;
}


Measured memory_bytes: 18176
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

s = input().split()[0]

if s[2] == s[3] and s[4] == s[5]:
    print("Yes")
else:
    print("No")





Measured memory_bytes: 38384
#include <cstdio>
#include <cmath>

#include <iostream>

#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>

#include <algorithm>

using namespace std;

int main() {
	string s;
	cin >> s;
	stack<char> st;
	for (int i = 0; i < s.size(); i++) {
		if (st.size() > 0) {
			if (s[i] == 'T' && st.top() == 'S') {
				st.pop();
			}
			else {
				st.push(s[i]);
			}
		}
		else {
			st.push(s[i]);
		}
	}
	cout << st.size() << endl;
}


Measured memory_bytes: 644
a,b,h,m = map(int, input().split())

import numpy as np
if m == 0:
    b_ang = 0
    if h == 0:
        a_ang = 0
    else:
        a_ang = np.pi * 2 * (h + m/60) / 12
else:
    a_ang = np.pi * 2 * (h + m / 60) / 12
    b_ang = np.pi * 2 / 60 * m

# print(a_ang, b_ang)
ang = np.abs(a_ang - b_ang)
# print(ang)
ang = min(ang, 2*np.pi - ang)

# print(ang)
print(np.sqrt(a**2 + b**2 - 2*a*b*np.cos(ang)))

Measured memory_bytes: 27196
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    long n = scan.nextLong();
    String ret = "";

    if (n == 0){
      System.out.println(0);
    }
    else if (n<0){
      long count = 2;
      long start = -1;
      long end = -2;
      int now = 1;
      while (end > n){
        count += 2;
        now = (int) count/2;
        end = cal1(now);
      }
      start = cal1(now-1) - 1;

      ret += "1";
      count -= 1;
      while (start > end){
        if (2*n > start + end){
          if (count%2 == 1){
            ret += "1";
          }
          else{
            ret += "0";
          }
          end = (long) (start+end)/2;
        }
        else{
          if (count%2 == 1){
            ret += "0";
          }
          else{
            ret += "1";
          }
          start = (long) (start+end)/2-1;
        }
        count -= 1;
      }
    }
    else{
      long count = 1;
      long start = 1;
      long end = 1;
      int now = 1;
      while (end < n){
        count += 2;
        now = (int) (count+1)/2;
        end = cal2(now);
      }
      start = cal2(now-1) + 1;

      ret += "1";
      count -= 1;
      while (start < end){
        if (2*n < start + end){
          if (count%2 == 0){
            ret += "1";
          }
          else{
            ret += "0";
          }
          end = (long) (start+end)/2;
        }
        else{
          if (count%2 == 0){
            ret += "0";
          }
          else{
            ret += "1";
          }
          start = (long) (start+end)/2+1;
        }
        count -= 1;
      }
    }
    System.out.println(ret);
  }

  static long cal1(int count){
    long a = fast(4, count);
    long b = (long) (a*2-2)/3;
    return -b;
  }

  static long cal2(int count){
    long a = fast(4, count);
    long b = (long) (a-1)/3;
    return b;
  }

  static long fast(long a, int b){
    long ret = 1;
    long base = a;

    while (b > 0){
      if ((b & 1) == 1){
        ret *= base;
      }
      base = base*base;
      b >>= 1;
    }
    return ret;
  }
}


Measured memory_bytes: 38572
#include<bits/stdc++.h>
#define longinf 9223372036854775807LL
#define intinf 2147483647
#define inf 998244353
#define lol long long
#define in(n,s) insert(n,s)//ノート参照
#define SYOU(x) setprecision(x)
#define abs(x,y) (max(x,y)-min(x,y))
#define mp make_pair
#define fi first
#define se second
using namespace std;
lol a,b,c,d,e=0,g,h;
int i[111110];
lol dp[100011];
    lol ka(int x){
      if(dp[x]!=-1) return dp[x];
      if(x==0) return 0;
      lol nx=longinf;
      for(int n=x-1;n>=max(0LL,x-b);n--){
    nx=min(nx,abs(i[x],i[n])+ka(n));
      }
      return dp[x]=nx;
    }
signed main(){
  cin.tie(0);
    ios::sync_with_stdio(false);
    cin >>a>>b;
    memset(dp,-1,sizeof(dp));
    dp[0]=0;
    for(int n=0;n<a;n++) cin >>i[n];
    cout <<ka(a-1)<<'\n';
    return (0);
}

Measured memory_bytes: 6144
import java.util.*;

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

    int k = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();
    String ans = "NG";

    for(int i = a; i <= b; i++){
      if(i % k == 0){
        ans = "OK";
      }
    }

    System.out.println(ans);
  }
}


Measured memory_bytes: 35764
#include<iostream>
#include<string>

using namespace std;

int main () {

    while (1) {
        string card;

        cin >> card;

        if (card[0] == '-') {
            break;
        }

        int m;
        cin >> m;
        for (int i = 0; i < m; i++) {
            
            int h;
            cin >> h;

            string tmp;
            tmp = card.substr(0, h);

            // cout << tmp << endl;

            // int gomi;
            // cin >> gomi;

            int cnt = 0;
            for (int j = h; card[j] != 0; j++) {
                card[j - h] = card[j];
                cnt++;
            }
            for (int j = cnt; card[j] != 0; j++) {
                card[j] = tmp[j - cnt];
            }

        }

        cout << card << endl;
    }
    return 0;
}


Measured memory_bytes: 3184
ary = input().split(' ')
n = int(ary[0])
a = int(ary[1])
b = int(ary[2])
ans = 0
for k in range(n+1):
    s = str(k)
    cnt = 0
    for i in range(len(s)):
        cnt += int(s[i])
    if a <= cnt <= b:
        ans += k

print(ans)


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

using namespace std;
typedef long long ll;
typedef long int li;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;

int main(){

  lb res[4];
  ll n;cin>>n;
  lb x[n],y[n];
  rep(i,0,n)cin>>x[i];
  rep(i,0,n)cin>>y[i];

  CLR(res,0);
  rep(i,0,n){
    lb num=abs(x[i]-y[i]);
    res[0]+=num;
    res[1]+=pow(num,2);
    res[2]+=pow(num,3);
    chmax(res[3],num);
  }
  res[1]=sqrt(res[1]);
  res[2]=pow(res[2],1/3.0);

  rep(i,0,4)out(fixed<<setprecision(10)<<res[i]);



  return 0;
}



Measured memory_bytes: 3412
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <fstream>

using namespace std;

#define ll long long
#define INF 2000000000
#define LINF 9000000000000000000
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define du(x) cout<<#x<<'='<<x<<endl
#define du2(x,y) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<'\n'<<endl
#define du3(x,y,z) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<' '<<#z<<'='<<z<<'\n'<<endl
#define darr(arr,n) rep(i,(n-arr)){cout<<*(arr+i)<<' ';}cout<<endl
#define ddarr(arr,a,b) rep(i,a){rep(j,b){cout<<*(arr+i*b+j)<<' ';}cout<<endl;}
#define ddd ifstream in("Text.txt");cin.rdbuf(in.rdbuf());

int a[110];

int main() {
    int N;
    cin >> N;
    rep(i, N)cin >> a[i];

    int cou = 0;
    rep(i, N - 1) {
        if (a[i] == a[i + 1]) {
            cou++;
            a[i + 1] = 1000000;
        }
    }
    cout << cou << endl;


}

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

int main(){

  int n, candies;
  cin >> n >> candies;

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

  int ans = 0;
  for(int i=0; candies > 0; i++){
    candies -= children[i];
    if(candies >= 0) ans++;
    if(i == n-1 && candies >= 0){
      if(candies != 0) ans--;
      break;
    }
  }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_X 200005

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long FINV(int n){
    if (n < 0) return 0;
    return finv[n];
}

ll dp[MAX_X];

int main() {
    int n, x;
    cin >> n >> x;
    int a[n];
    rep(i,n)cin >> a[i];
    sort(a,a+n);

    COMinit();

    int ite = lower_bound(a,a+n,x+1) - a;
    ite = n - ite;

    dp[x] = COM(n, ite) * fac[ite] % MOD;

    drep(i,MAX_X){
        if(dp[i] == 0)continue;
        if(i < a[0])break;
        drep(j,n){
            if(a[j] > i)continue;
            int after = i % a[j];
            int nn = 0;
            int kk = 0;
            rep(k,n){
                if(a[k] <= i){
                    nn++;
                    if(after < a[k])kk++;
                }
            }
            nn--;
            kk--;
            // cout << i << ' ' << a[j] << ' ' << after << ' ' << kk << ' ' << dp[i] * COM(nn, kk) << endl;
            dp[after] += dp[i] * COM(nn, kk) % MOD * fac[kk];
            dp[after] %= MOD;
        }
    }

    ll ans = 0;
    rep(i,a[0]){
        ans += dp[i] * i;
        ans %= MOD;
    }

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



Measured memory_bytes: 12544
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; i++)
#define RFOR(i, a, n) for (ll i = (ll)n - 1; i >= (ll)a; i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define bra(first, second) '(' << first << ',' << second << ')'
constexpr ll MOD = 1000000007;
//constexpr ll MOD = 998244353;
ll INF = 1001001001001001001;
long double EPS = 1e-9;
long double PI = 3.141592653589793238;
template <typename T>
void remove(std::vector<T> &vector, unsigned int index)
{
   vector.erase(vector.begin() + index);
}

using Graph = vector<vector<tuple<ll, ll, ll>>>;

// MOD確認
 
int main(){
   ll N,D;cin >> N >> D;
   ll ans = 0;
   rep(i,N){
      ll x,y;
      cin >> x >> y;
      if(D * D >= x * x + y * y) ans++;
   }
   cout << ans << endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define int long long
#define sz(x) (int)x.size()
#define mp make_pair
#define fi first
#define se second
#define io ios_base::sync_with_stdio(false),cin.tie(NULL)
using namespace std;
#define INF 1e7

signed main()
{
	io;
	int s;
	cin >> s;
	if(s==2)
	{
		cout << 0;
		return 0;
	}
	else if(s==1)
	{
		cout << 0;
		return 0;
	}
	else if(s==3)
	{
		cout << 1 ;
		return 0;
	}
	else if(s==4)
	{
		cout << 1;
		return 0;
	}
	int dp[s+1];
	dp[0]=0;
	dp[1]=0;
	dp[2]=0;
	dp[3] = 1;
	dp[4] = 1;
	dp[5] = 1;


	for(int i=6;i<s+1;i++)
	{
		dp[i]=0;
		for(int j=3;j<=i-3;j++)
		{
			dp[i] =(dp[i]%hell+dp[i-j]%hell)%hell;
		}
		dp[i]+=1;
		dp[i]= dp[i]%hell;

	}
	cout << dp[s];

}
 
	
		



Measured memory_bytes: 3584
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include<set>
#include<map>
using namespace std;
#define rep(i,n) for(int i=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int i=(m);(i)<(n);(i)++)
typedef long long ll;

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int rc=0,bc=0;
    rep(i,n){
        if(s[i]=='R')rc++;
        else if(s[i]=='B') bc++;
    }
    if(rc>bc)cout << "Yes" << endl;
    else cout<< "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

using namespace std;

int main(void) {
  int r;
  cin >> r;
  cout << 3*r*r << endl;
  return 0;
}


Measured memory_bytes: 888
n=int(input())
a=[]
for i in range(n):
	x,y=input().split()
	a.append([int(y),x])
from copy import copy
b=copy(a)

def partition(A,p,r):
	x=A[r][0]
	i=p-1
	for j in range(p,r):
		if A[j][0]<=x:
			i+=1
			A[i],A[j]=A[j],A[i]
	A[i+1],A[r]=A[r],A[i+1]
	return i+1

def Quick(A,p,r):
	if p<r:
		q=partition(A,p,r)
		Quick(A,p,q-1)
		Quick(A,q+1,r)

def Merge(A, left, mid, right):
	n1 = mid - left
	n2 = right - mid
	L=[[0,"ST"]for _ in range(n1+1)]
	R=[[0,"ST"]for _ in range(n2+1)]
	for i in range(n1):
		L[i] = A[left + i]
	for i in range(n2):
		R[i] = A[mid + i]
	L[n1][0] = 10**10
	R[n2][0] = 10**10
	i = 0
	j = 0
	for k in range(left,right):
		if L[i][0] <= R[j][0]:
			A[k] = L[i]
			i+=1
		else:
			A[k] = R[j]
			j+=1

def MergeSort(A, left, right):
	if left+1 < right:
		mid = (left + right)//2
		MergeSort(A, left, mid)
		MergeSort(A, mid, right)
		Merge(A, left, mid, right)
MergeSort(a,0,n)
Quick(b,0,n-1)
print("Stable" if a==b else "Not stable")
for i in range(n):
	print(b[i][1],b[i][0])




Measured memory_bytes: 27692
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DEBUG 0
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) if(DEBUG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DEBUG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
using ll = long long; using ull = unsigned long long; using pii = pair<int, int>;
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
static const int MOD = 1e9 + 7;

signed main() {
	int a[110][110] = {};
	int b[110][110] = {};
	for (int n; cin >> n&&n;) {
		memset(a, 0, sizeof(a));
		memset(b, 0, sizeof(b));
		rep(i, 0, n)rep(j, 0, n)cin >> a[i][j];
		rep(i, 0, n) {
			int m = INF;
			rep(j, 0, n)if (m > a[i][j])m = a[i][j];
			rep(j, 0, n)if (m == a[i][j])b[i][j]++;
		}
		rep(j, 0, n) {
			int M = -INF;
			rep(i, 0, n)if (M < a[i][j])M = a[i][j];
			rep(i, 0, n)if (M == a[i][j])b[i][j]++;
		}
		rep(i, 0, n)dumpc(b[i]);
		bool flag = true;
		rep(i, 0, n)rep(j, 0, n)if (b[i][j] == 2) { cout << a[i][j] << endl; flag = false; i = n; break; }
		if (flag)cout << 0 << endl;
	}
	return 0;
}

Measured memory_bytes: 3160
def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    a += [a[-1]]*k

    dp = [10**10]*(n+k)
    dp[0] = 0
    for i in range(n-1):
        for j in range(1, k+1):
            dp[i+j] = min(dp[i+j], dp[i]+abs(a[i+j]-a[i]))

    print(dp[n-1])


main()

Measured memory_bytes: 52448
#include<iostream>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++) cin>>a[i];
  double ans=0;
  for(int i=0;i<n;i++)
  {
    ans+=1*1.0/a[i];
  }
  cout<<1*1.0/ans<<endl;
  return 0;
}

Measured memory_bytes: 256
MOD = 2019
L, R = map(int, input().split())
mod_l = L % MOD
mod_r = R % MOD

if R - L >= 2019:
    print("0")
else:
    ans = 2018
    for i in range(mod_l, mod_r):
        for j in range(i+1, mod_r+1):
            _ans = (i * j) % MOD
            if ans > _ans:
                ans = _ans
    print(ans)


Measured memory_bytes: 9068
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <deque>
using ll = long long;
using namespace std;


int main(){
    int n, i = 1;
    cin >> n;
    while(n>0){
        n -= i;
        i++;
    }
    cout << i-1 << endl;
    return 0;
}


Measured memory_bytes: 256
fn main() {
    let mut inputline = String::new();
    std::io::stdin().read_line(&mut inputline).ok();
    let (x,a) = {
        let mut inpuline  = inputline.split_whitespace();
        (inpuline.next().unwrap().parse::<i32>().unwrap(),
        inpuline.next().unwrap().parse::<i32>().unwrap(),)
    };
    if x < a {
        println!("0");
    }else{
        println!("10");
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <bitset>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int popcount(int n) {
    int ret = 0;
    while (n > 0) {
        if ((n & 1) == 1) ret++;
        n >>= 1;
    }
    return ret;
}

int f(int x) {
    if (x == 0) return 0;
    return f(x % popcount(x)) + 1;
}

int main() {
    int N;
    cin >> N;
    string X;
    cin >> X;

    bitset<200000> target(X);
    vector<int> ans(N);
    int initial_pop = target.count();
    REP(b, 2) {
        int new_pop = b == 0 ? initial_pop + 1 : initial_pop - 1;
        if (new_pop <= 0) continue;

        int base = 0;
        RREP(i, N) {
            base = (base << 1) + target.test(i);
            base %= new_pop;
        }
        int diff = 1;
        REP(i, N) {
            if (target.test(i) == b) {
                int r = b == 0 ? (base + diff) : (base - diff + new_pop);
                r %= new_pop;
                ans[N - i - 1] = f(r) + 1;
            }
            diff = (diff << 1) % new_pop;
        }
    }
    REP(i, N) cout << ans[i] << endl;
    return 0;
}

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

void solve(){

	int a,b,c ;
	cin>>a>>b>>c ;

	vector<int> v(3) ;

	v[0]=a ;
	v[1]=b ;
	v[2]=c ;

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

	int sum=0 ;

	rep(i,2){
		sum+=v[i] ;
	}

	cout<<sum ;
	
}


int main(){

		int y ;

		y=1 ;
		//cin>>y ;

		while(y--){
 
			solve() ;

		}

}

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

using namespace std;

int main(){

    int n;
    cin>>n;
    vector<int>v[n];

    for(int i = 0; i < n; i++){

        int x, y, z;
        cin>>x>>y>>z;
        v[i].push_back(x);
        v[i].push_back(y);
        v[i].push_back(z);
    }

    for(int i = n-2; i >= 0; i--){

        v[i][0] += max(v[i+1][1], v[i+1][2]);
        v[i][1] += max(v[i+1][0], v[i+1][2]);

        v[i][2] += max(v[i+1][1], v[i+1][0]);

    }

    cout<<max(v[0][0], max(v[0][1], v[0][2]))<<endl;


}


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

#define fast ios::sync_with_stdio(false); cin.tie(0)
#define fi first
#define se second
#define eb emplace_back
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define pre(a) cout<<fixed; cout.precision(a);
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll INF = 1e18;
const int inf = 1e9;

int n, m;
int a[1010];
int b[1010];
int dp[1010][10010];

int main() {
	fast;

	cin >> n >> m;

	for(int i=1; i<=m; i++) {
		cin >> a[i] >> b[i];

		int key = 0;
		for(int j=0; j<b[i]; j++) {
			int t;
			cin >> t;
			t--;
			key |= (1<<t);

		}
		b[i] = key;
	}

	for(int j=0; j<(1<<n); j++) dp[0][j] = inf;
	dp[0][0] = 0;

	for(int i=1; i<=m; i++) {
		for(int j=0; j<(1<<n); j++) {
			dp[i][j] = inf;
			dp[i][j] = min(dp[i-1][j], dp[i-1][j ^ (j & b[i])] + a[i]);
		}
	}

	if(dp[m][(1<<n)-1] >= inf) cout << -1;
	else cout << dp[m][(1<<n)-1];
}

Measured memory_bytes: 38272
#include <bits/stdc++.h>
using namespace std;
#define psi pair<int,string>
int main()
{
    int n,m;
    cin>>n>>m;

    vector <int> ac(n),wa(n);   //ベクター型配列2つでacしているかwaが何回かを保持(最初は0で初期化→1でacとフラグを立てる)

    for(int i=0;i<m;i++)
    {
        int x;
        string k;
        cin>>x>>k;
        x = x-1;
        if(ac[x])
        {
            continue;
        }
        if(k=="AC")
        {
            ac[x]=1;
        }
        else
        {
            wa[x]++;
        }
    }

    int AC=0,WA=0;
    for(int i=0;i<n;i++)
    {
        AC += ac[i];
        if(ac[i])
        {
            WA += wa[i];
        }
    }

    cout<<AC<<" "<<WA<<endl;
    return 0;
}

Measured memory_bytes: 1024
#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>
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)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int dpa[100010];//最後がA
int dpb[100010];
int dpc[100010];

    int main(){
      int n;
      cin >> n;
      int a[n],b[n],c[n];
      rep(i,n)cin >> a[i] >> b[i] >> c[i];
      dpa[0]=a[0];
      dpb[0]=b[0];
      dpc[0]=c[0];
      for(int i=0;i<=n-2;i++){
       dpa[i+1]=max(dpb[i],dpc[i])+a[i+1];
       dpb[i+1]=max(dpa[i],dpc[i])+b[i+1];
       dpc[i+1]=max(dpb[i],dpa[i])+c[i+1];
      }
      cout << max(dpa[n-1],max(dpb[n-1],dpc[n-1])) << endl;
      return 0;}


Measured memory_bytes: 2560
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

void integerFactorization(int n, vector<pair<int, int> >& factor)
{
    factor.clear();
    int a = 2;
    while(a * a <= n){
        int b = 0;
        while(n % a == 0){
            ++ b;
            n /= a;
        }
        if(b > 0)
            factor.push_back(make_pair(a, b));
        ++ a;
    }
    if(n > 1)
        factor.push_back(make_pair(n, 1));
}

long long extgcd(long long a, long long b, long long &x, long long &y) {
    long long g = a;
    if(b != 0){
        g = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    }else{
        x = 1;
        y = 0;
    }
    return g;
}

long long mod_inverse(long long a, long long m)
{
    long long x, y;
    extgcd(a, m, x, y);
    return (x % m + m) % m;
}

const int MOD = 1000000007;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    map<int, int> cnt;
    for(int i=0; i<n; ++i){
        cin >> a[i];
        vector<pair<int, int> > v;
        integerFactorization(a[i], v);
        for(const auto& p : v)
            cnt[p.first] = max(cnt[p.first], p.second);
    }

    long long tmp = 1;
    for(const auto& p : cnt){
        for(int i=0; i<p.second; ++i){
            tmp *= p.first;
            tmp %= MOD;
        }
    }

    long long ans = 0;
    for(int i=0; i<n; ++i){
        ans += tmp * mod_inverse(a[i], MOD);
        ans %= MOD;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cmath>
#include <climits>
#include <iomanip>
#include <queue>
#include <stack>

using namespace std;

typedef long long ll;

int main() {
    double a, b, h, m; 
    cin >> a >> b >> h >> m;
    double y = a*a + b*b - 2*a*b*cos(2*M_PI*m/60.0-M_PI/6.0*(h+m/60));
    y = sqrt(y);
    cout << std::fixed << std::setprecision(15) << y << endl;
    return 0;
}

Measured memory_bytes: 4228
#include<iostream>
using namespace std;
int main() {

	int S, h, m, s,a;

	cin >> S;
	h = S / 3600;
	a =S - 3600 * h;
	m = a / 60;
	s = a - m * 60;

	cout << h << ":" << m << ":" << s << endl;

	return 0;
}


Measured memory_bytes: 3096
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

#define REP(i,n)for (int i=0;i<(n);i++)
#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ll long long
using namespace std;

int main(){
	vector<int>v(3);
	REP(i,3)cin>>v[i];
	sort(ALL(v));
	if(v[0]==5&&v[1]==5&&v[2]==7)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
l=[]
l.append(1)
for i in range(2,100001):
    T=list(str(i))
    if len(T)%2!=0:
        l.append(1+l[i-2])
    else:
        l.append(0+l[i-2])
n=int(input())
print(l[n-1])


Measured memory_bytes: 7064
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<int, int>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

using namespace std;
using ll = long long;
const ll mod = 1e9+7;

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

  int n, m; cin >> n >> m;
  vector<int> vec(n);
  rep(i, m) {
    int a, b; cin >> a >> b;
    a--; b--;
    vec.at(a)++; vec.at(b)++;
  }
  rep(i, n) {
    cout << vec.at(i) << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M;
  cin >> N >> M;
  vector<int> X(M);
  for(int i=0;i<M;i++) cin >> X.at(i);
  
  sort(X.begin(),X.end());
  vector<int> Y(M-1);
  for(int i=0;i<M-1;i++) Y.at(i) = X.at(i+1) - X.at(i);
  sort(Y.begin(),Y.end());
  long long ans = 0;
  for(int i=0;i<M-N;i++) ans += Y.at(i);
  
  cout << ans << endl;
}

Measured memory_bytes: 4060
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str

def isRotStr(S):
    for i in range(len(S)//2):
        if S[i] != S[len(S)-i-1]:
            return False
    return True

def solve(S: str):
    N = len(S)
    print(YES if isRotStr(S) and isRotStr(S[0:(N-1)//2]) and isRotStr(S[(N+2)//2:N]) else NO)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int dp[400][400];
int main(void){
    int n,ma,mb;
    cin>>n>>ma>>mb;
    for(int i=0;i<401;i++){
        for(int j=0;j<401;j++){
            dp[i][j]=1<<30;
        }
    }
    dp[0][0]=0;
    for(int i=0;i<n;i++){
        int a,b,c;
        cin>>a>>b>>c;
        for(int j=400-a;j>=0;j--){
            for(int k=400-b;k>=0;k--){
                if(dp[j][k]==1<<30)continue;
                dp[j+a][k+b]=min(dp[j][k]+c,dp[j+a][k+b]);
            }
        }
    }
    int ans=1<<30;
    for(int i=1;i<401;i++){
        for(int j=1;j<401;j++){
            if(i*mb==j*ma){
                ans=min(ans,dp[i][j]);
            }
        }
    }
    if(ans==1<<30)cout<<-1<<endl;
    else cout<<ans<<endl;
}


Measured memory_bytes: 896
n, d = gets.strip.split.map(&:to_i)

arr = []

n.times do |a|
    arr << gets.strip.split.map(&:to_i)
end

ans = 0

(0..(n - 1)).each do |i|
    ((i + 1)..(n - 1)).each do |j|
        norm = 0
        (0..(d - 1)).each do |k|
            diff = arr[i][k] - arr[j][k]
            norm += diff * diff
        end

        flag = false
        (0..norm).each do |k|
            flag = true if k * k == norm
        end
        ans += 1 if flag
    end
end

puts ans



Measured memory_bytes: 14336
#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>

using namespace std;

string divide[4] = {"dream","dreamer","erase","eraser"};

int main()
{
    string S;
    cin >> S;
    
    // 後ろから解くかわりにすべての文字列を「左右反転」する
    reverse(S.begin(), S.end());
    for (int i = 0; i < 4; ++i) reverse(divide[i].begin(), divide[i].end());
    
    bool can = true;
    for (int i=0; i<S.size();)
    {
        bool can2 = false;
        for (int j=0; j<4; ++j)
        {
            string d = divide[j];
            if(S.substr(i,d.size())==d)
            {
                // cout << "yes" << endl;
                can2 = true;
                i += d.size();
            }
        }
        if(!can2)
        {
            can = false;
            break;
        }
    }

    // cout << S << endl;
    // for (int i=0; i<4; ++i) cout << divide[i].size() << endl;
    if (can) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 512
main = do
 let primes = 2:3:[x|i<-[1..], j<-[-1,1], let x = 6*i+j, isPrime x]
      where isPrime n = null [i|i<-takeWhile (\x -> x*x <= n) primes, rem n i == 0]
 getContents >>= mapM_ (putStrLn . show . prime_number primes . read) . lines
  where prime_number ps n = length (takeWhile (<= n) ps)

Measured memory_bytes: 10160
<?php
$n=trim(fgets(STDIN));
$s=trim(fgets(STDIN));
$k=trim(fgets(STDIN));
$k=$s[$k-1];
$i=0;
while($i<$n){
  if($s[$i]==$k){
    echo $k;
  }else{
    echo "*";
  }
  ++$i;
}

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

int main(){
    int a,b;
    cin>>a>>b;
    if(a==1)a=14;
    if(b==1)b=14;
    if(a>b) cout<<"Alice"<<endl;
    else if(a<b) cout<<"Bob"<<endl;
    else cout<<"Draw"<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
	
	int N,M;
	scanf("%d %d", &N, &M);
	int A[100];
	int total = 0, selected = 0;
	for(int i = 0; i < N; i++){
		scanf("%d", &A[i]);
		total += A[i];
	}
	
	for(int i = 0; i < N; i++){
		if( (float)A[i] >= (float)total/(float)(4*M) ){
			selected++;
		}
		if ( selected == M ){
			printf("Yes"); break;
		}
		/*if( N-i-1 < M-selected ){
			printf("No"); break;
		}*/
	}
	
	if( selected < M ){
		printf("No");
	}
}

Measured memory_bytes: 128
import java.util.Scanner;
public class Main{

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt(); //n人の参加者
		int k = stdIn.nextInt(); //所持ポイント数※10^9の範囲であるためlongを使うべきかも
		int q = stdIn.nextInt(); //q個の問題
		int[] a = new int[n]; 
		
		for(int i = 0; i < n; i++) {
			a[i] = k-q;
		}
		
		for(int i = 0; i < q; i++) {
			int seikaisya = stdIn.nextInt()-1;
			a[seikaisya]++;
		}
		
		for(int i = 0; i < n; i++) {
			if(a[i]<=0) {
				System.out.println("No");
			}else {
				System.out.println("Yes");
			}
		}





	}

}


Measured memory_bytes: 66828
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
  int n; cin >> n;
  long long k; cin >> k;
  vector<int> v(n + 1);
  const int N = 62;
  vector<vector<int>> jump(N, vector<int>(n + 1));
  for(int i = 1; i <= n; ++i) {
    cin >> v[i];
    jump[0][i] = v[i];
  }
  for(int i = 1; i < N; ++i) {
    for(int j = 1; j <= n; ++j) {
      jump[i][j] = jump[i - 1][jump[i - 1][j]];
    }
  }
  long long at = 1;
  for(int i = 0; i < N; ++i) {
    if((k & (1LL << i))) {
      at = jump[i][at];
    }
  }
  cout << at << endl;
}

Measured memory_bytes: 53416
#include <iostream>

using namespace std;

typedef unsigned long long ull;

int main()
{
	ull h, w;
	cin >> h >> w;

	if (h == 1 || w == 1)
	{
		cout << 1 << endl;
		return 0;
	}

	ull sum = h * w;

	cout << (sum / 2) + (sum % 2) << endl;
}

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

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> divisors(n + 1);
	long long sum = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = i; j <= n; j += i) {
			divisors[j]++;
		}
		sum += 1ll * i * divisors[i];
	}
	cout << sum << '\n';
}



Measured memory_bytes: 42268
s=input()
S=list(s)
count=1
a=[]
a.append(S[0])
S.remove(S[0])
x=''
for i in range(len(S)):
    x+=S[i]
    if a[len(a)-1]!=x:
        a.append(x)
        x=''
        count+=1
    else:
        continue
print(len(a))


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


int main()
{
    string s, t;
    cin>>s>>t;
    int count = 0;
    for(int i=0; i<s.length(); i++)
    {
        if(s[i] != t[i])
            count++;
    }
    cout<<count;
}


Measured memory_bytes: 3844
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ans = 0;
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= n; j++){
                for(int k = 1; k <= n; k++){
                    ans += gcd(gcd(i,j),k);
                }
            }
        }
        System.out.print(ans);

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


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

int main(void)
{
    long long N, A;
    long long multi = 1;
    long long ans = 0;
    cin >> N;
    vector<long long> vec;
    vector<long long> logvec;
    
    for (auto i = 0; i < N; i++) {
        cin >> A;
        vec.push_back(A);
        logvec.push_back(log10(A));
    }
    
    sort(vec.begin(), vec.end());
    sort(logvec.begin(), logvec.end());
    
    if (vec[0] == 0) {
        cout << 0 << endl;
        return 0;
    }
    
    // for (auto i : vec) {
    //     multi *= i;
    //     if (multi > powl(10, 18)) {
    //         cout << -1 << endl;
    //         return 0;
    //     }
    // }
    
    for (auto i = 0; i < N; i++) {
        multi *= vec[i];
        ans += logvec[i];
        
        if (multi > 1000000000000000000) {
            cout << -1 << endl;
            return 0;
        }
        
        
        
        if (ans >= 18) {
            if (multi == 1000000000000000000) {
                continue;
            }
            cout << -1 << endl;
            return 0;
        }
        
        
    }
    
    cout << multi << endl;
}


Measured memory_bytes: 5340
//2017-11-9
//miaomiao
//
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

#define pb push_back
#define For(i, a, b) for(int i = (a); i <= (int)(b); ++i)

const int oo = 0x3f3f3f3f;

#define N (1000+5)
#define M (5000+5)

void Get(int &now, int av){
	if(now > av) now = av;
}

int fa[N], rv[N], Mno[N], f[N][M];
vector<int> G[N];

#define v G[now][i]

void Dfs(int now){
//	printf("now = %d\n", now);
	For(i, 0, G[now].size()-1) Dfs(v);
	int nn = G[now].size();

	if(!nn) return;
	For(i, 1, nn) For(j, 0, 5000) f[i][j] = oo;
	
	f[0][0] = 0;
	For(i, 0, nn-1) For(j, 0, rv[now]) if(f[i][j] < oo){
		if(rv[v]+j <= rv[now]) Get(f[i+1][rv[v]+j], f[i][j] + Mno[v]);
		if(Mno[v]+j <= rv[now]) Get(f[i+1][Mno[v]+j], f[i][j] + rv[v]);
	}

	Mno[now] = oo;
	For(j, 0, rv[now]) Get(Mno[now], f[nn][j]);
//	printf("Mno[%d] = %d\n", now, Mno[now]);

	if(Mno[now] == oo){puts("IMPOSSIBLE"); exit(0);}
}

#undef v

int main(){
	int n;
	scanf("%d", &n);
	
	For(i, 2, n){
		scanf("%d", &fa[i]); G[fa[i]].pb(i);
	}
	For(i, 1, n) scanf("%d", &rv[i]);
	
	Dfs(1);
	puts("POSSIBLE");

	return 0;
}

Measured memory_bytes: 19840