akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
using Graph = vector<vector<int>>;
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
struct edge{ll to, cost;};
typedef pair<ll,ll> P;
struct graph{
  ll V;
  vector<vector<edge> > G;
  vector<ll> d;

  graph(ll n){
    init(n);
  }

  void init(ll n){
    V = n;
    G.resize(V);
    d.resize(V);
    rep(i,V){
      d[i] = INF;
    }
  }

  void add_edge(ll s, ll t, ll cost){
    edge e;
    e.to = t, e.cost = cost;
    G[s].push_back(e);
  }

  void dijkstra(ll s){
    rep(i,V){
      d[i] = INF;
    }
    d[s] = 0;
    priority_queue<P,vector<P>, greater<P> > que;
    que.push(P(0,s));
    while(!que.empty()){
      P p = que.top(); que.pop();
      ll v = p.second;
      if(d[v]<p.first) continue;
      for(auto e : G[v]){
        if(d[e.to]>d[v]+e.cost){
          d[e.to] = d[v]+e.cost;
          que.push(P(d[e.to],e.to));
        }
      }
    }
  }
};
int main(){
ll n,m;
cin>>n>>m;
ll a = __gcd(n,m);
ll b = n*m/a;
string s,t; cin>>s>>t;
ll c = b/m;
ll d = b/n;
string ss="",tt="";
rep(i,n){
if(i%c==0) ss+=s.at(i);
}
rep(i,m){
if(i%d==0) tt+=t.at(i);
}
if(ss==tt) cout << b << endl;
else cout << -1 << endl;}


Measured memory_bytes: 3760
oddPrevensionStep = "L"
evenPrevensionStep = "R"

count = 1
dance = True
for h in input():
    if (0 == count % 2):
        if (h == evenPrevensionStep):
            dance &= False
    else:
        if (h == oddPrevensionStep):
            dance &= False
    count += 1


if (dance):
    print("Yes")
else:
    print("No")

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

using ll = long long;
using ull = unsigned long long;
using st = string;
using db = double;
using vll = vector<long long>;
using vdb = vector<db>;
using vvll = vector<vll>;
using vst = vector<st>;
using vchar = vector<char>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
#define rep(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
ll mod = 1000000007; 
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b;return true;} return false;}
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b;return true;} return false;}

int main(){
  ll n, m;
  cin >> n >> m;
  set<ll> a;
  rep(i, 0, m){
    ll all;
    cin >> all;
    a.insert(all);
  }
  vll dp(n + 1, 0);
  dp.at(0) = 1;
  if(!a.count(1)) dp.at(1)= 1;
  rep(i, 2, n + 1){
    if(!a.count(i)) dp.at(i) = (dp.at(i - 1) + dp.at(i - 2)) % mod;
  }
  cout << dp.at(n) << endl;
}

Measured memory_bytes: 5760
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
        static long Mod = (long)1e9 + 7;
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }
        static void Solve()
        {
            var N = Sarray()[0];
            var dct = new Dictionary<long, long>();
            for (var i = 1; i <= N; ++i)
                dct = primefactorize(i, dct);
            var ans = 1L;
            foreach (var d in dct)
                ans = ans * (d.Value + 1) % Mod;
            WriteLine(ans);

        }
        static Dictionary<long, long> primefactorize(long n, Dictionary<long, long> primes)
        {
            for (long i = 2L; i * i <= n; ++i)
            {
                while (n % i == 0)
                {
                    if (!primes.ContainsKey(i)) primes[i] = 0;
                    ++primes[i];
                    n /= i;
                }
            }
            if (n != 1)
            {
                if (!primes.ContainsKey(n)) primes[n] = 0;
                ++primes[n];
            }
            return primes;
        }
    }
}

Measured memory_bytes: 28168
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>
#include <locale>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x
using namespace std;

const int INF = INT_MAX;
const long long INFL = 1LL<<40;
const double PI = atan(1)*4;
const int MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}

const int N = 100005;
ll dp[N][4];

int main() {
    int n,m;cin>>n>>m;
    vector<ll> a(n);cin>>a;
    map<int,ll> mp;
    
    ll cum=a[0];
    mp[cum%m]++;
    repsg(i,1,n){
        cum+=a[i];
        mp[cum%m]++;
    }
    
    ll ans = mp[0];
    ll cums=a[0];
    repsg(i,1,n){
        mp[cums%m]--;
        ans += mp[cums%m];
        cums+=a[i];
    }
    
    
    
    
    cout<<ans<<endl;
    return 0;
}









Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rrep(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr ll INF = (ll)1e9;
constexpr ll mod = (ll)1e9 + 7;
constexpr double PI = 3.1415926535897932;
template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}


int main() {
	init();

	int N; cin >> N;
	vector<ll>A(N);
	rep(i, 0, N)cin >> A[i];
	vector<ll>sum(N + 1, 0);
	rep(i, 0, N) {
		sum[i + 1] = sum[i] + A[i];
	}
	ll ans = 0;
	map<ll, ll>mp;
	rep(i, 0, N + 1) {
		mp[sum[i]]++;
	}
	for (auto p : mp) {
		ans += (p.second * (p.second - 1)) / 2;
	}
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 18744
#include<stdio.h>
int main(void)
{
	int n,k,max,s,i,j,a[100001];
	while(1){
		scanf("%d%d",&n,&k);
		if(n==0&&k==0) break;
		for(i=1;i<=n;i++) scanf("%d",&a[i]);
		max=0;
		for(i=1;i<=n;i++){
			s=0;
			if(i+k<=n){
				for(j=i;j<i+k;j++) s+=a[j];
				if(max<s) max=s;
			}
		}
		printf("%d\n",max);
	}
	return 0;
}	

Measured memory_bytes: 3108
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#include <queue>
#include <set>
#include <list>
#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

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

int main() {
	vector<int> a(6);
	rep(i, 0, 6) cin >> a[i];
	string s;
	cin >> s;
	int top = 0;
	rep(i, 0, s.length()) {
		vector<int> data(6);
		if (s[i] == 'S') data = { a[4],a[0],a[2],a[3],a[5],a[1] };
		else if (s[i] == 'N') data = { a[1],a[5],a[2],a[3],a[0],a[4] };
		else if (s[i] == 'W') data = { a[2],a[1],a[5],a[0],a[4],a[3] };
		else data = { a[3],a[1],a[0],a[5],a[4],a[2] };
		a.assign(data.begin(), data.end());
	}
	cout << a[0] << endl;
	return 0;
}


Measured memory_bytes: 3204
#include<bits/stdc++.h>
using namespace std;
#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=(b-1); i>=(a); i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
using ll = long long;
using D = double;
using LD = long double;
using P = pair<int, int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
    string s; cin >> s;
    if(s == "ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
long long arr[1000000];
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);   
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    long long i,j,k,x,y,z,n;
    cin>>n;
    for (i=0;i<n;i++)
    {
    	cin>>arr[i];
	}
	sort (arr,arr+n);
	z=0;
	for (i=0;i<n;i++)
	{
		for (j=(i+1);j<n;j++)
		{
			x=arr[i]+arr[j];
			if (arr[j]==arr[i])
			{
				continue;
			}
			for (k=(j+1);k<n;k++)
			{
				y=arr[k];
				if (y==arr[j] || y==arr[i])
				{
					continue;
				}
				if (y<x)
				{
					z++;
				}
			}
		}
	}
	cout<<z<<endl;
}

Measured memory_bytes: 3652
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> to(m, vector<int>(n));
  rep(i, m) {
    int k;
    cin >> k;
    rep(j, k) {
      int s;
      cin >> s;
      s--;
      to[i].push_back(s);
    }
  }
  vector<int> p(m);
  rep(i, m) cin >> p[i];
  int ans = 0;
  rep(bm, 1 << n) {
    bool ok = true;
    rep(i, m) {
      int cnt = 0;
      for(int j : to[i])
        if(bm & (1 << j)) cnt++;
      if(cnt % 2 != p[i]) {
        ok = false;
        break;
      }
    }
    if(ok) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt();
		int n = sc.nextInt();
		int[] values = new int[w];
		for (int i = 0; i < values.length; i++) {
			values[i] = i + 1;
		}
		for (int i = 0; i < n; i++) {
			String str = sc.next();
			String[] ab = str.split(",");
			int a = Integer.parseInt(ab[0]) - 1;
			int b = Integer.parseInt(ab[1]) - 1;
			int c;

			c = values[a];
			values[a] = values[b];
			values[b] = c;
		}
		for (int i = 0; i < values.length; i++) {
			System.out.printf("%d\n", values[i]);
		}
	}
}

Measured memory_bytes: 26352
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int H,W;
    while(true){
        cin>> H >> W ;
        if(H==0&&W==0){
            break;
        }
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                cout<<'#';
            }
            cout<<endl;
        }
        cout<<endl;
    }
}


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
//想定解に時間計算量O(NlogN)のsort関数が必要でなので、C++で書きます。C言語だと面倒
long long max(long long a,long long b){return (a > b ? a : b);}
int  main(){
    long long N,P,Q;
    scanf("%lld%lld%lld", &N,&P,&Q);
    
    long long c[500000+ 1] = {};
    long long uprange[500000 + 1] = {}; //i日目に自炊すると全体の幸福度に与える影響
    long long sum = 0; // sum := 全部食堂に行ったときの幸福度
    for(int i = 0; i < N; ++i){
        scanf("%lld",c+i);
        sum += c[i];
    }
    for(int i = 0; i < N; ++i){
        uprange[i] = -c[i] + (Q - i) * P;
    }
    //sort
    //自炊に切り替えたときに増える幸福度が大きい順にsortする
    std::sort(uprange,uprange + N,std::greater<long long>());
    
    
    long long ans = sum;
    long long crt = sum;
    long long tq = 0; // tq日自炊すると考える
    for(int i = 0; i < N; ++i){
        //1日自炊する日が増えると、それ以前に自炊していた日(ここではtq日)文のこ幸福度が増える
        crt += uprange[i] + tq * P * 2LL;
        ans = max(ans,crt);
        ++tq;
    }
    printf("%lld\n",ans);
}



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

int main(){
  int n;
  cin >> n;
  vector<long long> min_factor(n+1);
  for (long long i=0; i <= n; i++){
    min_factor[i] = i;
  }
  vector<bool> is_prime(n+1);
  for (long long i=0; i <= n; i++){
    is_prime[i] = true;
  }
  
  is_prime[0] = false;
  is_prime[1] = false;
  for (int i=4; i <= n; i += 2){
    is_prime[i] = false;
    min_factor[i] = 2;
  }
  for (int i=3; i < int(sqrt(n))+1; i += 2){
    if (not is_prime[i]){
      continue;
    }
    for (int j = i * 2; j < n + 1; j += i){
      is_prime[j] = false;
      if (min_factor[j] >= i){
        min_factor[j] = i;
      }
    }
  }
  long long a = 0;
  for (int i=1; i <= n; i++){
    map<long long, long long> ans;
    int x = i;
    while (x > 1){
      long long key = min_factor[x];
      while (x%key == 0){
        auto itr = ans.find(key);
        if( itr != ans.end() ) {
          ans[key] += 1;
        } else {
          ans[key] = 1;
        }
        x /= key;
      }
    }
    long long judge = 1;
    for (auto itr = ans.begin(); itr != ans.end(); ++itr){
      judge *= ((itr->second)+1);
    }
    a += judge*i;
  }
  cout << a << endl; 
}



Measured memory_bytes: 82628
n,x=map(int,input().split())
a=list(map(int,input().split()))
ans=0
for i in range(1,n):
  if a[i]+a[i-1]>x:
    ans+=min(a[i]+a[i-1]-x,a[i])
    a[i]-=min(a[i]+a[i-1]-x,a[i])
    if a[i]+a[i-1]>x:
      ans+=a[i-1]-x
      a[i-1]-=a[i-1]-x
print(ans)

Measured memory_bytes: 14544
package main

import (
	"fmt"
)

func main() {
	var k int
	fmt.Scanf("%d %d", &k)

	fmt.Println(answer(k))
}

func answer(k int) int {
	return [32]int {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51}[k-1]
}


Measured memory_bytes: 512
#include <stdio.h>

int main()
{
	int N, A[101];
	int max, min, i;
	
	scanf("%d", &N);
	
	for (i = 0; i < N; i++) {
		scanf("%d", &A[i]);
		if ( i == 0 ) {
			max = A[i];
			min = A[i];
		} else {
			if ( max < A[i] ) {
				max = A[i];
			}
			if ( min > A[i] ) {
				min = A[i];
			}
		}
	}
	
	printf("%d", max - min);
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <limits>
#include <ctype.h> 
#include <stdio.h> 
#include <set> 
#include <iomanip>
#include <vector>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
#define L(ID) ((ID*2)+1)
#define R(ID) ((ID*2)+2)
#define M(L,R) ((L+R)/2)
#define forr(start,end) for(int i = start; i < end; i++)
#define gap ' '


const int MAXN = 1e5;
char a[MAXN];   
int n = 0;

int factorial(){
    for(int i = n-1; i > 0; --i){
        n = n * i;
    }
    return n;
}


int main() {
    ll n = 0;
    cin >> n;
    set<string> t;
    string s;
    for(int i = 0; i < n; ++i){
        cin >> s;
        t.insert(s);
    }
    cout << t.size() << endl;
    

    return 0;
} 


Measured memory_bytes: 15656
#include <iostream>
#include <stdio.h>
#include <sstream>
#include <vector>
using namespace std;

#define ll long long
#define fi first
#define se second
#define mp make_pair

#define abs(N) ((N>0)?N:-1*N)
#define min(A,B) ((A>B)?B:A)
#define max(A,B) ((A<B)?B:A)
#define print(S) (cout << S)
#define println(S) (cout << S << endl)

void vdump(vector<int> v){
  for (auto itr = v.begin(); itr != v.end(); ++itr)
  {
    print(*itr);
  }
  println("");
}

int main(int argc, char const *argv[])
{
	string str;
	ll K;
	cin >> str;
	cin >> K;
	int sz = str.length();
	ll firstN1i;
	char firstN1;

//	println(K);

	for (int i = 0; i < sz; ++i) {
		if(str[i]!='1'){
			firstN1i=i;
			firstN1=str[i];
//			println(i);
//			println(str[i]);
			break;
		}
	}
	if(firstN1i > (K-1)){
//		println("hoge");
		println(1);
	}else{
//		println("fuga");
		println(firstN1);
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	double n;
	cin>>n;
	double a,b,h;
	a=n/3;
	b=n/3;
	h=n-a-b;
	printf("%0.12f\n",a*b*h);
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a%b)

g = gcd(a[0], a[1])
for i in range(2, n):
    g = gcd(g, a[i])
print(g)

Measured memory_bytes: 14228
#include <bits/stdc++.h>
#define X first
#define Y second

using namespace std;

const int maxn = 800;
char g[maxn][maxn];
char gr[maxn][maxn];
char used[maxn];
char color[maxn];
int num[maxn];
int bal[maxn];

int n, m;

bool flag = false;

void dfs(int v, int col, int cc)
{
    used[v] = 1;
    color[v] = col;
    num[v] = cc;

    if (col) bal[cc]--;
    else bal[cc]++;

    for (int u = 0; u < n; u++)
    {
        if (u == v) continue;
        if (gr[v][u])
        {
            if (!used[u])
                dfs(u, 1 - col, cc);
            else
                if (color[u] == color[v])
                {
                    flag = true;
                }
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin >> n >> m;

    memset(gr, 1, sizeof gr);

    for (int i = 0; i < m; i++)
    {
        int u, v;
        cin >> u >> v;
        u--, v--;
        gr[u][v] = false;
        gr[v][u] = false;
    }

    vector <pair <int, int> > v;

    int cc = 0;
    for (int i = 0; i < n; i++)
    {
        if (!used[i])
            dfs(i, 0, cc);

        if (flag)
        {
            cout << -1 << '\n';
            return 0;
        }

        v.push_back({abs(bal[cc]), i});
        cc++;
    }
    int cur_bal = 0;
    sort(v.rbegin(), v.rend());
    for (auto x : v)
    {
        if (cur_bal >= 0)
        {
            if (x.X >= 0)
            {
                cur_bal -= x.X;
            }
            else
            {
                cur_bal += x.X;
            }
        }
        else
        {
            if (x.X >= 0)
            {
                cur_bal += x.X;
            }
            else
            {
                cur_bal -= x.X;
            }
        }
    }
    int half = (n - cur_bal) / 2;
    cout << (half*(half - 1))/2 + ((n - half)*(n - half - 1))/2;
    return 0;
}


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

int main() {
    string s;cin>>s;
    string t1,t2,t3,t4;
    t1 = "dream";
    t2 = "dreamer";
    t3 = "erase";
    t4 = "eraser";
    
    reverse(s.begin(), s.end());
    reverse(t1.begin(), t1.end());
    reverse(t2.begin(), t2.end());
    reverse(t3.begin(), t3.end());
    reverse(t4.begin(), t4.end());
    
    while(s.size()>0){
        string tmp;
        if(s.substr(0,t1.size()) ==t1 ) s = s.substr(t1.size());
        else if(s.substr(0,t2.size()) ==t2 ) s = s.substr(t2.size());
        else if(s.substr(0,t3.size()) ==t3 ) s = s.substr(t3.size());
        else if(s.substr(0,t4.size()) ==t4 ) s = s.substr(t4.size());
        else{
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
	return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

class G {
public:
  vector<vector<int>> p, inv, sp, sinv;
  int n, m;
  vector<int> b, c, depth;
  vector<bool> a;
  G(int nn, vector<vector<int>> &np, vector<vector<int>> &ninv) {
    n = nn;
    p = np;
    inv = ninv;
    a.resize(n);
    c.resize(n);
    for (int i = 0; i < n; i++) {
      c[i] = -1;
    }
  }
  void dfs(int i) {
    if (a[i])
      return;
    a[i] = true;
    for (int j = 0; j < p[i].size(); j++) {
      if (a[p[i][j]]) {
        continue;
      }
      dfs(p[i][j]);
    }
    b.push_back(i);
  }
  void dfs2(int i, int id) {
    if (c[i] > -1)
      return;
    c[i] = id;
    for (int j = 0; j < inv[i].size(); j++) {
      if (c[inv[i][j]] > -1)
        continue;
      dfs2(inv[i][j], id);
    }
  }
  void solve() {
    for (int i = 0; i < n; i++) {
      dfs(i);
    }
    int j = 0;
    for (int i = n - 1; i >= 0; i--) {
      if (c[b[i]] > 0)
        continue;
      dfs2(b[i], j++);
    }
    m = j;
    sp.resize(m);
    sinv.resize(m);
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < p[i].size(); j++) {
        if (c[i] == c[p[i][j]])
          continue;
        sp[c[i]].push_back(c[p[i][j]]);
        sinv[c[p[i][j]]].push_back(c[i]);
      }
    }
  }
};

bool solve() {
  int n;
  cin >> n;
  if (n == 0)
    return false;
  vector<double> ps(n);
  vector<vector<int>> p(n), inv(n);
  for (int i = 0; i < n; i++) {
    cin >> ps[i];
    ps[i] = 1 - ps[i];
    int m;
    cin >> m;
    for (int j = 0; j < m; j++) {
      int to;
      cin >> to;
      to--;
      p[i].push_back(to);
      inv[to].push_back(i);
    }
  }
  G g(n, p, inv);
  g.solve();
  vector<double> qs(g.m);
  vector<bool> c(n);
  for (int i = 0; i < qs.size(); i++)
    qs[i] = 1.0;
  for (int i = 0; i < n; i++) {
    qs[g.c[i]] *= (1 - ps[i]);
    c[g.c[i]] = true;
  }
  for (int i = 0; i < qs.size(); i++)
    qs[i] = 1 - qs[i];
  double ans = 1.0;
  for (int i = 0; i < qs.size(); i++) {
    if (g.sinv[i].size() == 0 && c[i])
      ans *= qs[i];
  }
  printf("%.9lf\n", ans);
  return true;
}

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



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

using namespace std;

typedef long long ll;

#define FOR(a, b, i) for(int i=a; i<b; i++)
#define RFOR(a, b, i) for(int i=a; i>=b; i--)
#define PB push_back
#define MP make_pair
#define MOD 1e9+7
#define newline cout<<"\n"


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

    int a, b; cin>>a>>b;
    
    ll ans;
    if(b==100) b++;
    ans = b*pow(100, a);

    cout<<ans<<endl;
    




    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

const int MAX = 500000;

int n, v_array[MAX], counts[MAX];

void update(int init_i, int ban, int* count, int* number)
{
	for (int i = 0; i < MAX; ++i)
	{
		counts[i] = 0;
	}

	for (int i = init_i; i < n; i += 2)
	{
		int value = v_array[i];
		counts[value - 1]++;
	}

	int max = 0;
	int max_v = ban;
	for (int i = init_i; i < n; i += 2)
	{
		int value = v_array[i];
		if (value != ban && counts[value - 1] > max)
		{
			max = counts[value - 1];
			max_v = value;
		}
	}

	*count = 0;
	for (int i = init_i; i < n; i += 2)
	{
		int value = v_array[i];
		if (value != max_v || value == ban)
		{
			*count += 1;
		}
	}
	*number = max_v;
}

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

	int even_odd = 0, odd_even = 0;

	{
		int count, number;
		update(0, 0, &count, &number);
		even_odd += count;
		update(1, number, &count, &number);
		even_odd += count;
	}

	{
		int count, number;
		update(1, 0, &count, &number);
		odd_even += count;
		update(0, number, &count, &number);
		odd_even += count;
	}

	printf("%d\n", std::min(even_odd, odd_even));
}

Measured memory_bytes: 2560
n,k=map(int,input().split())
D=set(map(int,input().split()))
for i in range(n,10**5+10): 
  S=list(str(i))
  a=0
  for j in range(len(S)):
    if int(S[j]) in D:
      a=1
      break
  if a==0:
    print(i)
    break

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;


int main(void) {
    int n, i, j;

    cin >> n;

    cout << n / 2 * (n / 2 - 1) * 2 + n / 2 * 2 * (n & 1) << endl;

    for (i = 1; i <= n; i++) {
        for (j = i + 1; j <= n; j++) {
            if (j != (n + 1 - n % 2) - i) {
                cout << i << ' ' << j << endl;
            }
        }
    }

    return 0;
}

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

#define TYPE(c)   remove_reference_t<decltype(c)>
#define REP(i, n) for(TYPE(n) i = 0; i < n; i++)
#define FOR(v, c) for(TYPE(c.begin()) v = c.begin(); v != c.end(); v++)
#define ALL(c)    c.begin(), c.end()
#define SORT(c)   sort(ALL(c))
#define RSORT(c)  sort(ALL(c), greater<TYPE(c)::value_type>())
#define UNIQUE(c) c.erase(unique(ALL(c)), c.end())

using namespace std;
using ll = long long;

constexpr int MOD  = (int)1e9 + 7;
constexpr int INF  = (int)1e9 + 1;
constexpr ll  LINF = (ll)1e18 + 1;
template<typename T> constexpr bool chmax(T& a, const T& b)
{ if(a < b) { a = b; return true; } else { return false; } }
template<typename T> constexpr bool chmin(T& a, const T& b)
{ if(b < a) { a = b; return true; } else { return false; } }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T>& p)
{ return os << "(" << p.first << "," << p.second << ")"; }
ostream& operator<<(ostream &os, const string& s)
{ FOR(v, s) os << *v; return os; }
template<typename T> auto operator<<(ostream& os, const T& t)
    -> typename conditional<true, ostream&, decltype(*t.begin())>::type
{ os << "["; FOR(v, t) { if(v != t.begin()) os << ","; os << *v; } os << "]"; return os; }

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

    int X;
    std::cin >> X;

    auto n = X / 100;
    auto v = X % 100;

    while(n != 0) {
        if(v >= 5) {
            v -= 5;
        }
        else if(v >= 4) {
            v -= 4;
        }
        else if(v >= 3) {
            v -= 3;
        }
        else if(v >= 2) {
            v -= 2;
        }
        else if(v >= 1) {
            v -= 1;
        }
        n--;
    }
    std::cout << (v == 0 ? 1 : 0) << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int> >;
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 9223372036854775806ll;
const int mod = 1000000007ll;
const ll  MOD = 1000000007LL;
/*メモ 
*/
int main(){
    int n;
    std::cin >> n;
    VEC(int,a,n);
    std::vector<pair<int,int>> c1(100001),c2(100001);
    rep(i,100001){
        c1[i].se=i;
        c2[i].se=i;
    }
    rep(i,n){
        if(i%2==0)c1[a[i]].fi++;
        else c2[a[i]].fi++;
    }
    sort(all(c1),greater<pair<int,int>>());
    sort(all(c2),greater<pair<int,int>>());
    if(c1[0].se==c2[0].se){
        std::cout << min(n-c1[0].fi-c2[1].fi,n-c1[1].fi-c2[0].fi) << std::endl;
    }
    else std::cout << n-c1[0].fi-c2[0].fi << std::endl;
}

Measured memory_bytes: 2176
import java.util.*;
import static java.lang.Math.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int s_n = s.length();
        for(int i = 14 - s_n; i >=0; i-- ){
            s = s + "o";
        }

        s = s.replaceAll("x", "");
        
        if(s.length()>=8){
            System.out.println("YES");
            return;
        }
        System.out.println("NO");
        
    }
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = (int)1e9+7;
const ll INF = MOD*MOD;
ll n,m,k,ans;
string s,t;
const ll powll = 1LL<<1;

bool cmp(P a, P b){
  if(a.first != b.first) return a.first < b.first;
  else return a.second > b.second;
}

int main(void){
  double a,b; cin >> a >> b;
  int ans = -1;
  bool frag = false;
  for(int i = 1; i < 1000000; i++){
    if( floor(i*0.08) == a && floor(i*0.10) == b && frag == false){
      ans = i;
      frag = true;
    }
  }
  cout << ans << "\n";
}

Measured memory_bytes: 256
#include"stdio.h"
#include"stdlib.h"
#include"string.h"
#include"ctype.h"
int main()
{
    long long a,b,c,k;
    scanf("%lld %lld %lld %lld",&a,&b,&c,&k);
    if(a<=k)
    {
        if(b<=k-a)
        {
            printf("%lld",a-k+a+b);
        }
        else
            printf("%lld",a);
    }
    else
        printf("%lld",k);

    return 0;
}


Measured memory_bytes: 1736
n,x = map(int,input().split())
if x == 1 or x == 2*n-1:
    print("No")
else:
    if x <= n:
        r = [i for i in range(1, x+n)]
        l = [i for i in range(x+n, 2*n)]
    else:
        l = [i for i in range(x-n+1, 2*n)]
        r = [i for i in range(1, x-n+1)]
    ans = l + r
    print("Yes")
    for i in range(2*n-1):
        print(ans[i])




Measured memory_bytes: 54128
#include <iostream>
#include <vector>
 
using namespace std;
 
int main(){
  int x, y;
  cin >> x >> y;
  vector<vector<int>> gs = {
    {1, 3, 5, 7, 8, 10, 12},
    {4, 6, 9, 11},
    {2}};
  
  for(auto& g : gs){
    bool contain_x = false;
    bool contain_y = false;
    for(auto& v : g){
      if(v == x) contain_x = true;
      if(v == y) contain_y = true;
    }
    if((contain_x == true) && (contain_y == true)){
      cout << "Yes" << endl;
      break;
    }else if(contain_x != contain_y){
      cout << "No" << endl;
      break;
    }
  }
  return 0;
}

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

int main(){
  string S;
  cin >> S;
  char lastnum;
  if(S.size() == 1)
    lastnum = S[0];
  else if(S.size() == 2)
    lastnum = S[1];
  else if(S.size() == 3)
    lastnum = S[2];
  
  if(lastnum == '3')
    cout << "bon" << endl;
  else if(lastnum == '0' || lastnum == '1' || lastnum == '6' || lastnum == '8')
    cout << "pon" << endl;
  else
    cout << "hon" << endl;
  
 return 0;
  
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    double W, H, x, y;
    cin >> W >> H >> x >> y;
    double ans = W * H / 2.0;
    int twoRectangle = (W/2.0 == x) && (H/2.0 == y);
    cout << fixed << setprecision(9) << ans << ' ' ;
    cout << twoRectangle << '\n';
}


Measured memory_bytes: 3772
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

Asum = [0]
Bsum = [0]
atemp = 0
btemp = 0
for i in range(N):
    atemp += A[i]
    Asum.append(atemp)
for i in range(M):
    btemp += B[i]
    Bsum.append(btemp)

ans = 0
j = M
for i in range(N+1):
    if Asum[i] > K:
        break
    while Asum[i] + Bsum[j] > K:
        j -= 1
    ans = max(ans, i+j)

print(ans)

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)

typedef long long ll;
typedef pair<ll,ll> P;

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

int main(){

	ll n;cin >> n;
	vector<ll> v(n);
	REP(i, n)cin >> v[i];

	ll ans = v[0];
	REP(i,n)ans = gcd(ans, v[i]);

	cout << ans << endl;

	return 0;
}


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

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

    vector<string> vec(2);

    string s;
    for (int i=0; i<b; i++) {
        s += to_string(a);
    }
    vec[0] = s;

    s = "";
    for (int i=0; i<a; i++) {
        s += to_string(b);
    }
    vec[1] = s;

    sort(vec.begin(), vec.end());
    cout << vec[0] << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main()
{
  int n,b,f,r,v;
  int people[5][4][11]={0};
  cin >> n;
   
  for(int i=0;i<n;i++){
    cin >> b >> f >> r >> v;
    people[b][f][r] +=v;
  }
   
  for(int i=1;i<=4;i++){
    for(int j=1;j<=3;j++){
      for(int k=1;k<=10;k++){
    if(people[i][j][k]<0){
      people[i][j][k]=0;
    }
    if(i!=0 && j!=0 && k!=0){
      cout << " " << people[i][j][k];
    }
      }
      cout << endl;
    }
    if(i!=4){
      cout << "####################" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define int long long
#define rep(i, a, n) for (int i = a; i < n; i++)
#define sz(v) (v).size()
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_taple
const int INF = 1 << 30;
using namespace std;

int N, X;
int a[51], b[51];

int dfs(int lev, int x) {
	if (lev < 0) return x > 0;
	if (x <= a[lev]+1) return dfs(lev-1, x-1);
	if (x <= a[lev]+2) return b[lev]+1;
	return b[lev]+1+dfs(lev-1, x-a[lev]-2);
}

signed main() {
	cin >> N >> X;
	a[0] = 1;
	b[0] = 1;
	rep(i, 0, 49) {
		a[i+1] = 2*a[i]+3;
		b[i+1] = 2*b[i]+1;
	}
	cout << dfs(N-1, X) << endl;
}


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

namespace ConsoleApp3
{
	class Program
	{
		static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			var q = from h in Console.ReadLine().Split()
					select int.Parse(h);
			var hList = q.ToList<int>();

			int maxCount = 0;
			int localMax = 0;
			for (int i = 0; i < n - 1; i++)
			{
				if (hList[i] >= hList[i + 1])
				{
					localMax++;
				}
				else
				{
					maxCount = Math.Max(maxCount, localMax);
					localMax = 0;
				}
			}
			maxCount = Math.Max(maxCount, localMax);
			Console.WriteLine(maxCount);
		}
	}
}


Measured memory_bytes: 27740
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
	ll n; cin >> n;
	set<ll> s;
	for(ll i = 0; i < n; i++){
		ll a; cin >> a;
		s.insert(a);
	}
	cout << s.size() << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int DerivCount(int n,int x,int count){ //いくつに分けるか不定の場合
    if(x == 0){
        return count+1;
    }else if(1 <= n && 1 <= x){
        for(int i = 0;i<n;i++){
            count = DerivCount(i,x-(i+1),count);
        }
    }
    return count;
}



int main(){

    int n,x,count;

    while(true){
        scanf(" %d %d",&n,&x);
        count = 0;
        if(n == 0 && x == 0){
            break;
        }
        //printf("%d\n",DerivCount(n,x,count));

        for(int i=0;i<n;i++){
            for(int j=i+1;j<n;j++){
                for(int k=j+1;k<n;k++){
                    if(x == i+j+k+3){
                        count++;
                    }
                }
            }
        }
        printf("%d\n",count);

    }
    return 0;
}



Measured memory_bytes: 2744
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d,e,f;
    scanf("%d/%d/%d",&a,&b,&c);
    
        if(b<=4)
        {
            cout<<"Heisei"<<endl;
        }
        else
        {
            cout<<"TBD"<<endl;
        }
    







    return 0;
}


Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}
#define int ll

void solve(){
	while (true) {
		int a, b, c;
		cin >> a >> b >> c;
		if (a == 0) return;
		pair<int, int> ans = mp(1e9, 1e9);
		int weight = 0;
		for (int i = 0; i < 1e5; ++i) {
			int right = i * a;
			if (llabs(c - right) % b == 0) {
				//chance to win
				int hoge = llabs(c - right) / b;
				pair<int, int> now = mp(i, hoge);
				if (now.first + now.second < ans.first + ans.second) {
					weight = hoge * b + i * a;
					ans = now;
				}
				else if (now.first + now.second == ans.first + ans.second && now.second * b + now.first * a < weight) {
					weight = hoge * b + i * a;
					ans = now;
				}
			}
			right = i * b;
			if (llabs(c - right) % a == 0) {
				int hoge = llabs(c - right) / a;
				pair<int, int> now = mp(hoge, i);
				if (now.first + now.second < ans.first + ans.second) {
					weight = now.second * b + now.first * a;
					ans = now;
				}
				else if (now.first + now.second == ans.first + ans.second && now.second * b + now.first * a < weight) {
					weight = now.second * b + now.first * a;
					ans = now;
				}
			}
		}
		cout << ans.first << " " << ans.second << endl;
	}
}

#undef int
int main() {
	init();
	solve();
}


Measured memory_bytes: 3220
#include "bits/stdc++.h"
#include<unordered_map>
#pragma warning(disable:4996)
using namespace std;

const int My_Inf=2147483647;
const long long int My_LInf=9223372036854775807;

int N, M, L;
vector<int>ks;
vector<long long int>sums;

long long int getmen(const int l, const int r) {
	return  (sums[ks[r] + 1] - sums[ks[l]]) / L;
}

long long int dp[2010][2010];
int main() {
	cin >> N >> M >> L;
	for (int i = 0; i < N; ++i) {
		int k; cin >> k;
		k--;
		ks.push_back(k);

	}
	sort(ks.begin(), ks.end());
	vector<int>beaus;
	for (int i = 0; i < M; ++i) {
		int s; cin >> s;
		beaus.push_back(s);
	}
	sums.push_back(0);
	long long int now = 0;
	for (int i = 0; i < M; ++i) {
		now += beaus[i];
		sums.push_back(now);
	}
	memset(dp, 0, sizeof(dp));
	for (int i = 0; i < 2010; ++i) {
		for (int j = 0; j < 2010; ++j) {
			dp[i][j] = 9999999999999999;
		}
	}
	dp[0][0] = 0;
	for (int i = 0; i < N-2; ++i) {
		for (int j = 0; j < N; ++j) {
			dp[i + 1][i] = min(dp[i + 1][i], dp[i][j] + getmen(j, i + 1));
			dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + getmen(i, i + 1));
		}
	}
	long long int ans = 9999999999999999;
	for (int i = 0; i < N-2; ++i) {
		ans = min(ans, dp[N - 2][i] + getmen(N - 2, N - 1) + getmen(i, N - 1));
	}
	cout << ans << endl;
	return 0;
}

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

long long int Q, S[114514], T[114514], ls, lt, a, b, c, d;
char s[114514], t[114514];

int main(){
    scanf("%s %s %lld", s, t, &Q);
    ls = strlen(s);
    lt = strlen(t);
    for(int i = 0; i < ls; ++i){
        S[i + 1] = (S[i] + s[i] - 64) % 3;
        //cout << S[i] << " ";
    }
    //cout << S[ls] << endl;
    for(int i = 0; i < lt; ++i){
        T[i + 1] = (T[i] + t[i] - 64) % 3;
        //cout << T[i] << " ";
    }
    //cout << T[lt] << endl;
    for(int i = 0; i < Q; ++i){
        scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
        //cout << S[b] << " " << S[a - 1] << " " << T[d] << " " << T[c - 1] << endl;
        puts(((S[b] - S[a - 1] - T[d] + T[c - 1] + 114) % 3)?"NO":"YES");
    }
    return 0;
}


Measured memory_bytes: 2304
s=str(input())
d=dict()
d['A']='T'
d['T']='A'
d['C']='G'
d['G']='C'
cnt=0
ans=0
for i in range(len(s)):
    if s[i] in d.keys():
        cnt+=1
    else:
        ans=max(cnt,ans)
        cnt=0
ans=max(cnt,ans)

print(ans)

Measured memory_bytes: 38384
#include <stdio.h>
#include <string.h>
 
int main(){
	int i, j;
	 char A[255], B[255], C[255];
	 scanf("%s %s %s", A, B, C);
	 
	 if (A[strlen(A)-1] == B[0] && B[strlen(B)-1] == C[0]){
	 	printf("YES\n");
	 } 
	 else {
	 	printf("NO\n");
	 }
	
	return 0;
}

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

int main(){
  int d, e;
  while(std::cin >> d >> e, d){
    double ans = 1e9;
    for (int i = 1; i <= d; i++) {
      int k = (d - i);
      ans = min(ans, abs(sqrt(i*i + k*k) - e));
    }
    printf("%.12lf\n", ans);
  }
  return 0;
}

Measured memory_bytes: 1196
N = int(input())
a = list(map(int,input().split()))
Q = int(input())
bc = [[int(i) for i in input().split()] for j in range(Q)]
 
counter = [0] * 1000000
for i in a:
    counter[i] += 1

ans = sum(a)
 
for _ in bc:
    ans = ans + counter[_[0]] * _[1] - counter[_[0]] * _[0]
    counter[_[1]] += counter[_[0]]
    counter[_[0]] = 0
    print(ans)

Measured memory_bytes: 37684
input = gets.chomp.split(" ").map(&:to_i)
n = input[0]
x = input[1]

l = gets.chomp.split(" ").map(&:to_i)

y = 0
cnt = 1

for i in 1..n do
    y = y+l[i-1]
    if y <= x 
        cnt += 1
    end
end

puts cnt

Measured memory_bytes: 1788
cards={blue: gets.to_i.times.map { gets.chomp }, red: gets.to_i.times.map { gets.chomp }}
num=cards[:blue].uniq.map {|b| cards[:blue].count{|c| c == b } - cards[:red].count{|d| d == b }}.max
puts num.negative? ? 0 : num

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

using namespace std;
using ll = long long;
using ld = long double;

const ll mod = 1e9 + 7;

vector<vector<ll>> multiply(vector<vector<ll>> a, vector<vector<ll>> b) {
    int n = a.size();
    int k = a[0].size();
    int m = b[0].size();
    vector<vector<ll>> c(n, vector<ll>(m));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            for (int z = 0; z < k; z++) {
                c[i][j] = (c[i][j] + a[i][z] * b[z][j]) % mod;
            }
        }
    }
    return c;
}

vector<vector<ll>> fast_pow(vector<vector<ll>> a, ll k) {
    vector<vector<ll>> ans = a;
    for (int i = 0; i < (int)a.size(); i++) {
        for (int j = 0; j < (int)a[0].size(); j++) {
            ans[i][j] = i == j;
        }
    }
    while (k != 0) {
        if (k % 2 == 0) {
            a = multiply(a, a);
            k >>= 1;
        } else {
            ans = multiply(ans, a);
            k--;
        }
    }
    return ans;
}

int main() {
    ios_base::sync_with_stdio(0);
    cout.tie(0); cin.tie(0);
    ll n, k;
    cin >> n >> k;
    vector<vector<ll>> a(n, vector<ll>(n));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> a[i][j];
        }
    }
    a = fast_pow(a, k);
    ll sum = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            sum = (sum + a[i][j]) % mod;
        }
    }
    cout << sum;
}

Measured memory_bytes: 384
import java.util.*


fun main(args: Array<String>) {
    val n = getInt()
    val a = getInts().sorted()
    val s = TreeSet(a)

    val m = HashMap<Int, Int>()
    a.forEach {
        m[it] = (m[it] ?: 0) + 1
    }

    var out = 0
    while (s.isNotEmpty()) {
        val jump = s.first()
        var i = jump
        if (m[i] == 1) out++
        while (s.isNotEmpty() && i <= s.last()) {
            s.remove(i)
            i += jump
        }
    }
    println(out)
}

fun getInt() = readLine()!!.toInt()
fun getInts() = readLine()!!.split(" ").map { it.toInt() }

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

using namespace std;

typedef long long ll;

const int N = 109, M = 1e5 + 9, OO = 0x3f3f3f3f;
const ll llOO = 0x3f3f3f3f;

int n, cap, w[N], v[N];

ll dp[N][M];

ll solve(int i, int rem){
    if(rem < 0) return -llOO;
    if(i == n)  return 0;

    ll &ret = dp[i][rem];
    if(~ret)    return ret;

    return ret = max(solve(i + 1, rem), v[i] + solve(i + 1, rem - w[i]));
}

int main(){

    cin >> n >> cap;
    for(int i = 0;i < n;i++)
        cin >> w[i] >> v[i];

    memset(dp, -1, sizeof dp);

    cout << solve(0, cap);
}


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

using ll = long long;
using P = pair<ll, int>;

int main() {
    using star = tuple<int, ll, ll>;
    int N, d;
    cin >> N >> d;
    vector<star> v(N);
    for(int i=0; i<N; ++i) {
        int b;
        ll x, y;
        cin >> x >> y >> b;
        v[i] = make_tuple(b, x, y);
    }
    sort(v.begin(), v.end());

    ll res = 0;
    priority_queue<P> ma_x, ma_y;
    priority_queue<P, vector<P>, greater<P>> mi_x, mi_y;
    int l = 0, r = 0;
    while(true) {
        while(r < N && get<0>(v[r]) - get<0>(v[l]) <= d) {
            ma_x.push(P{get<1>(v[r]), r});
            ma_y.push(P{get<2>(v[r]), r});
            mi_x.push(P{get<1>(v[r]), r});
            mi_y.push(P{get<2>(v[r]), r});
            r++;
        }
        while(!ma_x.empty() && ma_x.top().second < l) {
            ma_x.pop();
        }
        while(!ma_y.empty() && ma_y.top().second < l) {
            ma_y.pop();
        }
        while(!mi_x.empty() && mi_x.top().second < l) {
            mi_x.pop();
        }
        while(!mi_y.empty() && mi_y.top().second < l) {
            mi_y.pop();
        }
        res = max(res, (ma_x.top().first - mi_x.top().first) * (ma_y.top().first - mi_y.top().first));

        if(r == N) {
            break;
        }
        l++;
    }
    cout << res << endl;
}

Measured memory_bytes: 20088
n = int(input())
x = [int(i) for i in input().split()]
x_sorted = sorted(x)

x_1 = x_sorted[n // 2 - 1]
x_2 = x_sorted[n // 2]

for x_ in x:
    if x_ <= x_1:
        print(x_2)
    else:
        print(x_1)

Measured memory_bytes: 26772