akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

int main() {
	int i,n,a,b,t[100],l,j;
	
	
	scanf("%d",&n); 
	
	
	
	for(i=0;i<n;i++) {
		scanf("%d%d",&a,&b);
		
		for(j=0;j<b;j++) {
			scanf("%d",&t[j]);
			}
		j=0;	
			for(l=1;l<=n;l++) {
				if(l==t[j] &&  j!=b)  {printf("1"); j++;}
				else printf("0");
				if(l!=n) printf(" ");
				}
				printf("\n");
				
								}
				return 0;
				}


Measured memory_bytes: 2112
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

long long int ps(long long int x , long long int n){
    if(n==0) return 1;
    if(n==1) return x ;
    if(n%2) return ((x* ps(x,n-1)));
    else {
        long long int z=ps(x,n/2);
        return (z*z) ;
    }
}

bool ssort(const pair<long long int,long long int> &a,
              const pair<long long int,long long int>  &b)
{
    return (a.first < b.first);
}
bool ssort3(const pair<int,int> &a,
              const pair<int,int>  &b)
{
    if(a.first == b.first) return (a.second < b.second);
    return (a.first < b.first);
}
#define mo 998244353
long long int n,k,res;
string s;
int main()
{
    IOS;
    cout.precision(30);
    cin >> n ;
    res=-n;
    for(int i=0; i < n ;i++) {
        cin >> k;
        res+=k;
    }
    cout << res ;


}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pi 3.14159265358979323846
#define mm 1000000007
int main()
{
    IOS;
    ll a,b,c,d,e,k,count;
    cin>>a>>k;
    ll A[a];
    for(b=0;b<a;b++)
    {
        cin>>A[b];
    }
    for(b=k;b<a;b++)
    {
        if(A[b]>A[b-k])
        cout<<"Yes"<<endl;
        else
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 5172
#include <iostream>

using namespace std;
long long a , b , c , d;
int main(){
    cin >> a >> b >> c >> d;
    long long mul1 = (a < 0) ? a * min(c,d) : a * max(c,d);
    long long mul2 = (b < 0) ? b * min(c,d) : b * max(c,d);
    cout << max(mul1,mul2);
    return 0;
}

Measured memory_bytes: 3628
#include<iostream>

using namespace std;

int main()
{
	int i = 1;
	while (true)
	{
		int x;
		cin >> x;

		if (x == 0)
			break;
		else
		{
			cout << "Case " << i << ": " << x << endl;
			i++;
		}
	}
}

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

int s, d;
bool kaku_nin(int den_sya,int n){
    if(!den_sya) return true;
    int zyo_su = pow(2, den_sya);
    if(n + zyo_su > d) return false;
    for(int j=0;j<32;j++){
        if(abs(n) & (1<<j)){
            if(j && (1<<j) % zyo_su == 0) return true;
            else return false;
        }
    }
    return true;
}
int cnt(int no){
    int j=0;
    while (kaku_nin(j,no)) j++;
    return j-1;
}
int kai(int ima, int hi_you){
    if(ima == d) return hi_you;
    int den_sya = cnt(ima);
    if(ima + pow(2, den_sya) <= d){
        return kai(ima + pow(2, den_sya), hi_you+1);
    }
}
int main(){
    int N;
    cin >> N;
    while(N--){
        cin >> s >> d;
        cout << kai(s,0) << endl;
    }
}


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

int main(){
    string s;
    cin >> s;
    int cnt, ans;
    cnt = 0;
    for(int i=0; i<3; i++){
        if(s[i] == 'o'){
            cnt++;
        }
    }
    ans = 700 + 100*cnt;
    cout << ans << endl;
    return 0;
}

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

using namespace std;
const double PI = 3.14159265368979;

int main(){
  double a, b, h, m;
  cin >> a >>b >> h >> m;
  double theta1 = (60.0*h + m)/(60.0*12.0)*2.0*PI;
  double theta2 = m / 60.0*2.0*PI;
  double sqr = a*a + b*b - 2.0*a*b*cos(theta1 - theta2);
  printf("%.12lf\n", sqrt(sqr));
}



Measured memory_bytes: 4124
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int cl(int a, int b) {
	return (a - (a%b)) / b;//b=0だと積む
}
int up(int a, int b) {
	return cl(a + b - 1, b);//b=0だと積む
}
int main() {
	int n, b, c, d; int ans = 1;
	cin >> n;
	vector<int> a(n,0);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int che = 1;
	for (int i = 0; i < n; i++) {
		if (a[i] == 1) {
			che++;
		}
		else {
			che = 1;
		}
		ans = max(ans, che);
	}
	cout << ans << endl;
}


Measured memory_bytes: 3092
#include<stdio.h>

int main(void) {
  int a, b, c;
  scanf("%d %d", &a, &b);

  if (b % 10 == b) c = 10 * a + b;
  else if (b % 100 == b) {
    c = 100 * a + b;
  }
  else {
    c = 1000 * a + b;
  }

  for (int i = 0; i < 1000; i++) {
    if (c == i * i) {
      printf("Yes");
      return 0;
    }
  }

  printf("No");

  return 0;
}


Measured memory_bytes: 128
var stdin = require('fs').readFileSync('/dev/stdin', 'utf8');
var input = stdin.toString().trim().split('\n');

var S = parseInt(input[0], 10);
var h = Math.floor(S / (60 * 60));
var m = Math.floor(S % (60 * 60) / 60);
var s = Math.floor(S % 60);


console.log([h,m,s].join(':'));

Measured memory_bytes: 15600
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vd=vector<double>;
using vvd=vector<vd>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using vs=vector<string>;
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define LINF    	((ll)1ll<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			3.141592653589793

template<class S,class T>ostream& operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<setw(3)<<s; a=0;} return os;}

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	int n,m;cin>>n>>m;
	vl a(n+1,0);rep(i,n)cin>>a[i+1];
	partial_sum(all(a),a.begin());

    map<ll,ll> mp;
	rep(i,n+1){
	    a[i]%=m;
	    if(mp.find(a[i])==mp.end())mp[a[i]]=0;
	    mp[a[i]]++;
	}

	ll ans=0;
	for(auto m:mp){
	    if(m.second==1)continue;
	    ans+=m.second*(m.second-1)/2;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 4992
// -*- coding:utf-8-unix -*-

use proconio::input;
use rand::Rng;

pub fn get_time() -> f64 {
    static mut STIME: f64 = -1.0;
    let t = std::time::SystemTime::now()
        .duration_since(std::time::UNIX_EPOCH)
        .unwrap();
    let ms = t.as_secs() as f64 + t.subsec_nanos() as f64 * 1e-9;
    unsafe {
        if STIME < 0.0 {
            STIME = ms;
        }
        ms - STIME
    }
}

fn calclate_score(D: usize, s: &Vec<Vec<isize>>, c: &Vec<isize>, out: &Vec<usize>) -> isize {
    let mut sat = 0;
    let mut last = vec![0; 26];
    for d in 0..D {
        assert!(0 <= out[d] && out[d] <= 25);
        let j = out[d as usize] as usize;
        last[j] = d + 1;
        for i in 0..26 as usize {
            sat -= (d + 1 - last[i]) as isize * c[i];
        }
        sat += s[d][j];
    }
    sat
}

fn main() {
    input! {
        D: usize,
        c: [isize; 26],
        s: [[isize; 26]; D],
    }
    let mut out = vec![0 as usize; D];
    for i in 0..D {
        let mut max = 0;
        for j in 0..26 {
            max = if s[i][max] < s[i][j] { j } else { max };
        }
        out[i] = max;
    }
    let mut rng = rand::thread_rng();
    let mut max_score = calclate_score(D, &s, &c, &out);
    let mut loop_cnt = 0;
    while get_time() < 1.9 {
        let d: usize = rng.gen_range(0, D);
        let q: usize = rng.gen_range(0, 26);
        let old = out[d];
        out[d] = q;
        if max_score < calclate_score(D, &s, &c, &out) {
            max_score = calclate_score(D, &s, &c, &out);
        } else {
            out[d] = old;
        }
        loop_cnt += 1;
    }
    for x in out {
        println!("{}", x + 1);
    }
    eprintln!("score:{}, loop:{}", max_score, loop_cnt);
}


Measured memory_bytes: 2732
#include <iostream>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <cstdio>
#include <new>
#include <vector>
#include <cstdlib>
#include <string>
#include <set>

using namespace std;

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

	int sum = 1;

	if (a != b) {
		sum++;
	}

	if (a != c) {
		if (b != c) {
			sum++;
		}
	}

	cout << sum << endl;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
#define PI 3.14159265358979
//const int64_t INF = 1LL << 60;
const int INF = 1 << 29;
const int64_t MOD = 1000000007;
//const int64_t INF = 998244353;
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; }
using namespace std;
//#define P pair<int, int>
typedef pair<int, int> P;

int main(){
    int A, B;
    cin >> A >> B;
    cout << max(0, A - B * 2) << endl;
}

Measured memory_bytes: 256
a = int(input())
ar = input().split(" ")
br = [0 for i in range(a)]
n = a // 2
p = 0
if a % 2 == 0:
    t = "L"
else:
    t = "R"
for i,r in enumerate(ar):
    if i == 0:
        br[n] = r
        p += 1
    else:
        if t == "L":
            br[n-p] = r
            t = "R"
            if a % 2 != 0:
                p += 1
        else:
            br[n+p] = r
            t = "L"
            if a % 2 == 0:
                p += 1
print(" ".join(br))

Measured memory_bytes: 25668
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) (v).begin(),(v).end()
using ll = long long int;
using P = pair<int, int>;
ll MOD = 1e9 + 7;

ll modpow(ll a, ll b) {
    if (b==1) return a%MOD;
    if (b%2!=0) return a*modpow(a, b-1)%MOD;
    ll c = modpow(a, b/2);
    return (c*c)%MOD;
}

ll nCr(ll n, ll r) {
    ll x = 1, y = 1;
    rep(i, r) {
        x = x*(n-i)%MOD;
        y = y*(i+1)%MOD;
    }
    return x*modpow(y, MOD-2)%MOD;
}

int main(){
    ll n, a, b;
    cin >> n >> a >> b;
    ll ans = modpow(2, n);
    ans -= nCr(n, a);
    ans -= nCr(n, b);
    ans--;
    cout << (ans%MOD+MOD)%MOD << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

bool calc(int *a,int *b,int m,int c){
    int i,sum = 0;
    for(i=0;i<m;i++){
        sum += (*(a+i))*(*(b+i));
    }
    sum = sum+ c;
    return sum > 0;    
}
int main(){
    int n , m , c,ans = 0;
    cin >> n >> m >> c;
    int b[m],a[m];
    int i,j;
    for(i=0;i<m;i++){
        cin >> b[i];
    }
    for(j=0;j<n;j++){
        for(i=0;i<m;i++){
            cin >> a[i];
        }
        if(calc(a,b,m,c) == true){
            ans ++;
        }
    }
    cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<thread>
#define ll long long
#define ld long double
#define pi acos(-1)
#define mod 1000000007
#define show(x, y); cout << x << " " << y << endl;
using namespace std;

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

    int n, k;
    cin >> n >> k;
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    ll dp[k + 1];
    memset(dp, 0, sizeof dp);
    dp[0] = 1;
    for(int i = 0; i < n; i++){
        vector<int> pre(k+1, 0);
        for(int j = k - 1; j >= 0; j--){
            int l = j + 1;
            int r = min(k, j + a[i]);
            pre[l] = (pre[l] + dp[j]) % mod;
            if(r == k){
                continue;
            }
            pre[r + 1] = (pre[r + 1] - dp[j]);
            if(pre[r + 1] < 0){
                pre[r + 1] += mod;
            }
        }
        int sum = 0;
        for(int j = 0; j <= k; j++){
            sum = (sum + pre[j]) % mod;
            dp[j] = (dp[j] + sum) % mod;
        }
    }
    cout << dp[k];
}


Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		
		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		String[] split = s.split("");
		
		if(split[2].equals(split[3])) {
			if(split[4].equals(split[5])) {
				System.out.print("Yes");
				return;
			}
		}
		System.out.print("No");
		
	}

}


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

int main(){
	int a[4], b = 0, c = 0;
	cin>>a[0]>>a[1]>>a[2]>>a[3];
	
	for(int i = 1; i < 4; i++){
		if(a[0] == a[i]){
			b = 1;
			
			if(i == 1){
				if(a[2] == a[3]){
					 c = 1;
				}
			}
			if(i == 2){
				if(a[1] == a[3]){
					 c = 1;
		
				}
			}
			if(i == 3){
				if(a[1] == a[2]){
					 c = 1;
	
				}
			}
		}
	}
	if(b == 1 && c == 1) cout<<"yes"<<endl;
	else cout<<"no"<<endl;
	return 0;
}



Measured memory_bytes: 3120
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
#include<set>
using namespace std;
int keta(int N){
    int i=0;
    while(N>0){
        N=N/2;
        i++;
    }
    return i;
}

int main(){
    int N;
    int A[100010];
    cin>>N;
    int res=0;
    for(int i=0;i<N;i++){
        cin>>A[i];
        res ^= A[i];
    }
    if(res==0){
        cout<<0<<endl;
        return 0;
    }
    bool used[100010]={};
    int pow2[31]={};
    pow2[0]=1;
    for(int i=1;i<31;i++){
        pow2[i]=pow2[i-1]*2;
        //cout<<i<<' '<<pow2[i]<<endl;
    }
    int ans=0;
    for(int j=keta(res);j>=0;j--){
        if(res==0){
            break;
        }
        if(j == keta(res)){
            bool flag=false;
            for(int i=0;i<N;i++){
                if(A[i]%pow2[j-1]==0 && A[i]%pow2[j]!=0 && !used[i]){
                    flag=true;
                    used[i]=true;
                    res = res^A[i]^(A[i]-1);
                    ans++;
                    break;
                }
            }
            if(!flag){
                ans=-1; break;
            }
        }
    }
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 768
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int Max = 1000000;
int main(){
    int N;
    cin >> N;
    long H[N];
    for(int i=0;i<N;i++) cin >> H[i];

    for(int i=N-2;i>=0;i--){
      if(H[i]>=H[i+1]+2){
        cout << "No" <<endl;
        return 0;
      }else if(H[i]==H[i+1]+1){
        H[i]--;
      }
    }
    cout << "Yes" <<endl;
  	
  	return 0;
}



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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n, k;
  while (cin >> n >> k) {
    vector<int> a(n);
    each (i, a) cin >> i;

    int sum = 0;
    sum += (n - 1) / (k - 1);
    if ((n - 1) % (k - 1)) ++sum;
    cout << sum << endl;
    continue;
    
    
    // int idx = 0;
    // for (int i = 0; i < n; ++i) {
    //   if (a[i] == 1) idx = i;
    // }

    // int sum = 0;
    // int rem = (n - idx + 1) % (k - 1);

    // cout << (n - idx + 1) / (k - 1) << endl;
    // cout << rem << endl;
    // cout << idx + rem << endl;
    // cout << (idx + rem) / (k - 1) << endl;
    // cout << (idx + rem) % (k - 1) << endl;

    // sum += (n - idx + 1) / (k - 1);
    // sum += (idx + rem) / (k - 1);
    // if ((idx + rem) / (k - 1)) ++sum;

    // cout << max(sum, 1) << endl;

    // cout << endl;
  }
  
  return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
int main(void)
{
  int aa, ab, ac, ad;
  scanf("%d", &aa);
  if(aa == 1)
  printf("Hello World");
  else
  {  scanf("%d", &ab);
  scanf("%d", &ac);
  ad = ab + ac;
  printf("%d", ad);}
  return 0;
}


Measured memory_bytes: 128
n=int(input())
li=list(map(int,input().split()))

ans=[]
li2=[0 for _ in range(n)]
for i in range(n,0,-1):
  count=0
  for j in range(i*2,n+1,i):
    if li2[j-1]==1:
      count+=1
  if count%2!=li[i-1]:
    li2[i-1]=1
    ans.append(i)

ans.reverse()
print(len(ans))
L=[str(a) for a in ans]
L=" ".join(L)
if len(L)!=0:
  print(L)

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)

typedef long long LL;
typedef pair<int, int> pii;

const int INTINF = int(1e9) + 1;
const LL LLINF = LL(1e18) + 1;
#define pow10(n) int(1e##n + n)

const int mod = int(1e9) + 7;

bool isok(char t4, char t3, char t2, char t1)
{
    if (t4 == 'A' and t3 == 'G' and t1 == 'C')
        return false;

    if (t4 == 'A' and t2 == 'G' and t1 == 'C')
        return false;

    if ((t4 == 'A' and t3 == 'G' and t2 == 'C') or (t3 == 'A' and t2 == 'G' and t1 == 'C'))
        return false;
    if ((t4 == 'G' and t3 == 'A' and t2 == 'C') or (t3 == 'G' and t2 == 'A' and t1 == 'C'))
        return false;
    if ((t4 == 'A' and t3 == 'C' and t2 == 'G') or (t3 == 'A' and t2 == 'C' and t1 == 'G'))
        return false;

    return true;
}

int N;
string S = "AGCT";
map<string, LL> dp[1000];

string code(char p1, char p2, char p3)
{
    string s = "";
    return s + p1 + p2 + p3;
}

LL rec(int depth, char p1, char p2, char p3)
{
    if (dp[depth].find(code(p1, p2, p3)) != dp[depth].end())
        return dp[depth][code(p1, p2, p3)];

    if (depth == N)
        return 1;

    LL ret = 0;
    for (auto c : S)
        if (isok(p1, p2, p3, c))
            ret = (ret + rec(depth + 1, p2, p3, c)) % mod;

    dp[depth][code(p1, p2, p3)] = ret;
    return ret;
}

void solve()
{
    cin >> N;
    cout << rec(0, '\0', '\0', '\0') << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}


Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(2000000)
n = int(input())
p = []
for i in range(n-1):
    p.append(list(map(int, input().split()))+ [1])
l = [[] for i in range(n+1)]
for pi in p: 
    l[pi[0]].append([pi[0],pi[1]])
    l[pi[1]].append([pi[1],pi[0]])
kyo = [float("inf")]*(n+1)
kyo[1] = 0
memo = [0] * (n+1)
memo[1] = 1
ruto = []
def dfs(start,ruto):
  ruto.extend(l[start])
  memo[start] = 1
  while ruto:
    a = ruto.pop()
    if memo[a[1]] == 1:
      continue
    kyo[a[1]] = kyo[a[0]] + 1
    dfs(a[1],ruto)
  return
dfs(1,ruto)

nkyo = [float("inf")]*(n+1)
nkyo[n] = 0
memo = [0] * (n+1)
memo[n] = 1
ruto = []
def dfs(start,ruto):
  ruto.extend(l[start])
  memo[start] = 1
  while ruto:
    a = ruto.pop()
    if memo[a[1]] == 1:
      continue
    nkyo[a[1]] = nkyo[a[0]] + 1
    dfs(a[1],ruto)
  return
dfs(n,ruto)
iti = 0
nko = 0
for i in range(1,n+1):
  if kyo[i] <= nkyo[i]:
    iti += 1
  else:
    nko += 1
if iti <= nko:
  print("Snuke")
else:
  print("Fennec")

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

string satu;
string dua;
string tiga;
int main(){
	cin>>satu>>dua>>tiga;
	satu[0]-=32;
	dua[0]-=32;
	tiga[0]-=32;
	cout<<satu[0]<<dua[0]<<tiga[0]<<endl;
}

Measured memory_bytes: 3564
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a < b ? a : b)
const int inf = 1000000000; // 10^9

int main(){
   char s[4];scanf("%s",s);
   int a=0,b=0,c=0;
   for(int i = 0;i < 3;i++){
      if(s[i]=='a')a++;
      else if(s[i]=='b')b++;
      else if(s[i]=='c')c++;
      else {
         printf("No");
         return 0;
      }
   }
   if(a==1&&b==1&&c==1)printf("Yes");
   else printf("No");
}

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

int main(){
    string S;
    cin>>S;
    reverse(S.begin(),S.end());
    string t1="maerd";
    string t2="remaerd";
    string t3="esare";
    string t4="resare";
    for(int i=0;i<S.size();){
        if(S.substr(i,5)==t1){
            i+=5;
        }else if(S.substr(i,7)==t2){
            i+=7;
        }else if(S.substr(i,5)==t3){
            i+=5;
        }else if(S.substr(i,6)==t4){
            i+=6;
        }else{
            cout<<"NO"<<endl;
            break;
        }
        if(i==S.size()){
            cout<<"YES"<<endl;
        }
        
    }
}

Measured memory_bytes: 512
fn solve() {
    let (h, w): (usize, usize) = (read::<usize>(), read::<usize>());
    let (sh, sw): (usize, usize) = (read::<usize>() - 1, read::<usize>() - 1);
    let (gh, gw): (usize, usize) = (read::<usize>() - 1, read::<usize>() - 1);
    let mut map = vec![];
    for _ in 0..h {
        let s: Vec<char> = read::<String>().chars().collect();
        map.push(s);
    }
    let mut que = VecDeque::new();
    que.push_back((sh, sw));
    let mut dist = vec![vec![std::usize::MAX; w]; h];
    dist[sh][sw] = 0;

    while let Some((ht, wt)) = que.pop_front() {
        let d = dist[ht][wt];
        for dh in -2..=2 {
            for dw in -2..=2 {
                if (dh, dw) == (0, 0) {
                    continue;
                }
                let nh = ht as i32 + dh;
                let nw = wt as i32 + dw;
                if (0..h as i32).contains(&nh) && (0..w as i32).contains(&nw) {
                    let nh = nh as usize;
                    let nw = nw as usize;
                    if map[nh][nw] == '.' {
                        if 2 <= dh.abs() + dw.abs() {
                            if d + 1 < dist[nh][nw] {
                                dist[nh][nw] = d + 1;
                                que.push_back((nh, nw))
                            }
                        } else {
                            if d < dist[nh][nw] {
                                dist[nh][nw] = d;
                                que.push_front((nh, nw));
                            }
                        }
                    }
                }
            }
        }
    }

    if dist[gh][gw] != std::usize::MAX {
        println!("{}", dist[gh][gw]);
    } else {
        println!("{}", -1);
    }
}

fn main() {
    let stack_size = 104_857_600;
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}

// =========
#[allow(unused_imports)]
use std::cmp::{max, min, Reverse};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::process::exit;

#[allow(dead_code)]
const MOD: usize = 1000000007;

fn read<T: std::str::FromStr>() -> T {
    use std::io::Read;
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// =========


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

#define ll     long long
#define fr     first
#define sec    second
#define rep(i,n)  for(i=0;i<n;i++)
#define vi     vector <int>
#define vc     vector <char>
#define vl     vector <ll>
#define vb     vector <bool>
#define pb     push_back
#define M      1000000007
#define ios    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define open   freopen("input.txt","r",stdin);
#define close  freopen("output.txt","w",stdout);
#define M_PI   3.14159265358979323846
#define pp     pair<int,int>
#define nn 100003

int main()
{
    ios;
    string s,t;
    cin>>s>>t;
    ll l=s.length(),i,ans=0;
    rep(i,l)
    {
        if(s[i]!=t[i])
            ans++;
    }
    cout<<ans;
    return 0;
}


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

int main() {

        std::string s;
        std::cin >> s;

        int min = std::numeric_limits<int>::max();
        for (auto i = 0; i < s.size() -2; ++i) {
                auto x = std::stoi(s.substr(i, 3));
                if (std::abs(753 - x) < min) {
                        min = std::abs(753 - x);
                }
        }

        std::cout << min << std::endl;

        return 0;
}

Measured memory_bytes: 256
//#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <numeric>
#include<bitset>

using namespace std;
#define modd 1000000007


typedef pair<long long, long long> pl;



#define ll long long




/*
class UnionFind {
public:
	vector <ll> par; 
	vector <ll> siz;
	vector <ll> gr;

	// Constructor
	UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) ,gr(sz_){
		for (ll i = 0; i < sz_; ++i) par[i] = i; 
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
		for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}

	// Member Function
	// Find
	ll root(ll x) { // 根の検索
		while (par[x] != x) {
			x = par[x] = par[par[x]]; // x の親の親を x の親とする
		}
		return x;
	}

	// Union(Unite, Merge)
	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;

		// merge technique（データ構造をマージするテク．小を大にくっつける）
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}



	bool issame(ll x, ll y) { // 連結判定
		return root(x) == root(y);
	}

	ll size(ll x) { // 素集合のサイズ
		return siz[root(x)];
	}


};*/


long long N, M, K, a, b, c, d,e, H, W,L;
long long A[200005] = {};
long long B[200005] = {};
long long C[200005] = {};
long long D[200005] = {};
long long E[200005] = {};
bool f, ff;
string S;
set <long long>sll;
pl bufpl;
vector <long long>vl;
vector <pl>vpl;
vector <string> vs;
set<ll> llset;

/*struct ST
{
	long long Kati;
	int bangou;

	bool operator<(const ST& another) const
	{
		return Kati < another.Kati;//比較
	};

};



vector <ST> vst;
ST st[200005];
ST bufst;
bitset<5000> bits;*/


long long modinv(long long aa, long long mm) {
	long long bb = mm, uu = 1, vv = 0;
	while (bb) {
		long long tt = aa / bb;
		aa -= tt * bb; swap(aa, bb);
		uu -= tt * vv; swap(uu, vv);
	}
	uu %= mm;
	if (uu < 0) uu += mm;
	return uu;
}


bool fs[2005][2005] = {};

int main() {


	cin >> N>>a;

	if (N % 500 <= a) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	
	
	
	return 0;

}


Measured memory_bytes: 2304
//abc141_e.cpp
//Sat Nov 30 18:31:09 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int zalgo(string ss){
	int a[ss.length()];
	a[0] = ss.length();
	int i=1;
	int j=0;
	int ans = 0;
	while (i<ss.length()){
		while (i+j<ss.length() && ss[j]==ss[i+j]){
			j++;
		}
		a[i] = j;
		ans = max(min(j,i),ans);
		if (j==0){
			i++;
			continue;
		}
		int k = 1;
		while (i+k<ss.length() && k+a[k]<j){
			a[i+k] = a[k];
			ans = max(min(i+k,a[k]),ans);
			k++;
		}
		i = i+k, j = j-k;
	}
	return ans;
}

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

	int ans = 0;
	for (int i=0;i<s.length();i++){
		string temps = s.substr(i);
		ans = max(ans,zalgo(temps));
	}

	cout << ans << endl;
}

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

int main() 
{
    int a, b, c, x, xmax=20000;
    cin >> a >> b >> c >> x;
    int sum = 0;
    for (int i=0; i<=a; i++)
        for (int j=0; j<=b; j++)
            for (int k=0; k<=c; k++)
                if (i*500+j*100+k*50 == x)
                    sum++;
    cout << sum;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
const int N=25;
int a[N],b[N],c[N];
int main(){
	int n,i;
	scanf("%d",&n);
	for(i=1;i<=n;i++) scanf("%d",&a[i]);
	for(i=1;i<=n;i++) scanf("%d",&b[i]);
	for(i=1;i<n;i++) scanf("%d",&c[i]);
	
	int ans=0;
	for(i=1;i<=n;i++){
		ans+=b[a[i]];
		if(i!=1 && a[i-1]+1==a[i]) ans+=c[a[i-1]];
	}
	
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;
int main(){
  int N;
  cin>>N;
  string s;
  cin>>s;
  int answer=0;
  for(int i=0;i<N;i++){
    if(i==0){
      answer+=1;
    }
    if(i>0&&s[i]!=s[i-1]){
      answer+=1;
    }
  }
  cout<<answer<<endl;
  
  return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<string.h>
using namespace std;
#define ll long long
#define maxn  500000
int c[maxn],a[maxn];
char s[40];
int b[40];
int k=1,p;
int  mul(int  a[],int b[])
{   int lenx=k;
    int leny=p;
    int t=0;
    for(int i=1;i<=lenx;i++)
      {  t=0;
        for(int j=1;j<=leny;j++)
          { c[i+j-1]+=a[i]*b[j]+t;
            t=c[i+j-1]/10; c[i+j-1]%=10;
		  }
		  c[i+leny]=t;
	  }
	  int lenc=lenx+leny;
	  while(c[lenc]==0&&lenc>1)
	   lenc--;
	  return lenc;
} 
int main ()
{   int n;
    cin>>n;
     c[1]=1;
     int ans=1;
    while(n--)
    {   scanf("%s",s);
        //printf("%s\n",s);
        if(s[0]=='0') ans=0;
        if(ans==0) {k=0;continue;}
        if(k>19) continue;
       for(int i=1;i<=k;i++)
          {
		  a[i]=c[i];
	      c[i]=0;
		  }
       p=strlen(s); 
       //cout<<"ssa"<<p<<endl;
	   for(int i=1;i<=p;i++)
          {b[i]=s[p-i]-'0';}
          //cout<<endl;
	   k=mul(a,b);
	   }
	  /* for(int i=k;i>=1;i--)
	  cout<<c[i];
	  cout<<endl;*/
	  if(ans==0) cout<<0;
	  else
	  {
	if(k>19)  cout<<-1;
	else if(k==19)
	{   int flag=1;
	   for(int i=1;i<=18;i++)
	     if(c[i]!=0) {flag=0;break;}
	    if(c[19]!=1) flag=0;
	    if(flag)
	    {   for(int i=k;i>=1;i--)  printf("%d",c[i]);
	       
		}
		else  printf("-1");
	}
	else
	{    for(int i=k;i>=1;i--)
	      cout<<c[i];
		}
	  }
}


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

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

int cmp(const void *a,const void *b){
  int64 t= *(int64 *)a-*(int64 *)b;
  if(t==0) return 0;
  return t<0?-1:1;
}

void run(void){
  int n,m;
  scanf("%d%d",&n,&m);
  int64 *x=(int64 *)calloc(n,sizeof(int64));
  int64 *y=(int64 *)calloc(n,sizeof(int64));
  int64 *z=(int64 *)calloc(n,sizeof(int64));
  int i;
  for(i=0;i<n;i++){
    scanf("%lld%lld%lld",x+i,y+i,z+i);
  }
  int64 max=0;
  int64 *array=(int64 *)malloc(sizeof(int64)*n);
  for(i=0;i<8;i++){
    int j;
    for(j=0;j<n;j++) array[j]=0;
    for(j=0;j<n;j++){
      array[j]+=((i&0x01)?-1:1)*x[j];
      array[j]+=((i&0x02)?-1:1)*y[j];
      array[j]+=((i&0x04)?-1:1)*z[j];
    }
    qsort(array,n,sizeof(int64),cmp);
    int64 sum=0;
    for(j=0;j<m;j++){
      sum+=array[n-1-j];
    }
    max=MAX(max,sum);
  }
  printf("%lld\n",max);
  return;
}

int main(void){
  run();
  return 0;
}

Measured memory_bytes: 256
/**
 *    Author:  "Robin Singh" !!!
 *    BrainyIsTheNewSexy     (CodeForces)
 *    rob_in_1               (Other OJs)
**/
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define ff first
#define ss second
#define mp make_pair
#define szz(v) ((int)(v).size())  
#define fr(i, j, k) for(int i = j; i < k; i++)     
#define bk(i, j, k) for(int i = j-1; i >= k; i--)
#define frit(it, a) for(__typeof((a).begin()) it = a.begin(); it != a.end(); ++it)
#define mem(ptr)  memset(ptr, 0, sizeof ptr)
#define str string 
#define rtn return 
#define nl "\n"
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector <int> vi;
typedef vector <long long> vll;
typedef vector < pair<int,int> > vpii;
typedef vector < pair<ll, ll> > vpll;
const long long mod = 1e9+7;
const long double eps = 1e-9;
const long long INF = (1LL<<61);
const int inf = (1<<30);
const int nn = 1e6+5;
//---------------------------------------------*DEBUGGING*--------------------------------------------------------->]
#define dbg( args...) { vector<string> _v = split( #args, ','); err( _v.begin(), args); cerr << '\n'; }
vector<string> split( const string& s, char c) { vector<string> v; stringstream ss( s); string x; 
while ( getline( ss, x, c)) v.emplace_back(x); return move(v); }
void err( vector<string>::iterator it) { } 
template<typename T, typename... Args>
void err( vector<string>::iterator it, T a, Args... args) {
    cerr << it -> substr( ( *it)[0] == ' ', it -> length()) << " = " << a << '\t'; err( ++it, args...); }
//----------------------------------------------------------------------------------------------------------------->]
//*****************************************!Template Ends Here!*****************************************************]

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    int a[n], b[m];
    fr(i, 0, n) cin >> a[i];
    fr(i, 0, m) cin >> b[i];
    sort(a, a+n);
    sort(b, b+m);
    int l = a[n-1]+1, r = b[0];
    fr(i, l, r+1){
        if(x < i && y >= i){
            cout << "No War";
            rtn 0;
        }
    }
    cout << "War";
    return 0;
}

//->INTUITIONS are not to be ignored. They represent data processed too fast for the conscious mind to comprehend !!

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

int main() {
  int N, A, Q;
  cin >> N >> A;
  
  Q = N % 500;
    
  if (Q <= A) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }

}

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

using namespace std;
typedef long long ll;

// #define DEBUG

int main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    int n, k, x, y;
    cin >> n;
    // set<int> workspace;
    multiset<int> workspace;

    for (int i = 0; i < n; i++)
    {
        cin >> k;
        if (k == 0)
        {
            cin >> x;
            workspace.insert(x);
            cout << workspace.size() << "\n";
        }
        else if (k == 1)
        {
            cin >> x;
            cout << workspace.count(x) << "\n";
            // auto z = workspace.find(x);
            // cout << ((z == workspace.end()) ? 0 : 1) << "\n";
        }
        else if (k == 2)
        {
            cin >> x;
            workspace.erase(x);
        }
        else if (k == 3)
        {
            cin >> x >> y;
            for (auto itr = workspace.lower_bound(x); itr != workspace.upper_bound(y); itr++)
                cout << *itr << "\n";
        }
    }
    return 0;
}

// getline(cin,s);
// a = strtok(s, ",");  ","で分解
// for (int i = 0; i < n; i++)


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

int main() {
	int N, X[110] = {}, count = 0;
	bool P[110] = {};
	for (int i = 2; i <= 100; i++) {
		P[i] = true;
		for (int j = 2; j < i; j++) {
			if (i % j == 0) P[i] = false;
		}
	}
	cin >> N;
	for (int i = 2; i <= N; i++) {
		int Y = N;
		if (P[i]) {
			while (Y != 0) {
				X[i] += Y / i;
				Y /= i;
			}
		}
	}
	int P74 = 0, P24 = 0, P14 = 0, P4 = 0, P2 = 0;
	for (int i = 2; i <= N; i++) {
		if (X[i] >= 74) P74++;
		if (X[i] >= 24) P24++;
		if (X[i] >= 14) P14++;
		if (X[i] >= 4)  P4++;
		if (X[i] >= 2)  P2++;
	}
	count += P74;
	count += P24 * (P2 - 1);
	count += P14 * (P4 - 1);
	count += P4 * (P4 - 1) / 2 * (P2 - 2);
	cout << count;
}

Measured memory_bytes: 256
let rec gcd n m =
  if m = 0 then n
  else gcd m (n mod m)

let () = Scanf.scanf "%d\n" @@ fun n ->
  let as_ = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun a -> a in
  Printf.printf "%d\n" @@ Array.fold_left gcd 0 as_


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

using namespace std;

int main()
{
  int D; cin >> D;
  if (D == 25) {
    cout << "Christmas" << endl;
  } else if (D == 24) {
    cout << "Christmas Eve" << endl;
  } else if (D == 23) {
    cout << "Christmas Eve Eve" << endl;
  } else {
    cout << "Christmas Eve Eve Eve" << endl;
  }
}

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

int main()
{
  int HT, ST, HA, SA;
  cin >> HT >> ST >> HA >> SA;
  int x = 1;
  while (1)
  {
    if (x == 1)
    {
      HA = HA - ST;
      if (HA <= 0)
      {
        cout << "Yes";
        return 0;
      }
      x = 0;
    }
    else if (x == 0)
    {
      HT = HT - SA;
      if (HT <= 0)
      {
        cout << "No";
        return 0;
      }
      x = 1;
    }
  }
}


Measured memory_bytes: 3652
MOD =  (10e8+7).to_i

$pascal = [
  [1],
  [1,1]
]

def pascal(n,i)
  return 1 if n==0
  return $pascal[n][i] if $pascal[n] && $pascal[n][i]

  if n==i || i==0
    $pascal[n] ||= []
    $pascal[n][i] = 1
  else
    $pascal[n] ||= []
    $pascal[n][i] = ((pascal(n-1, i-1) + pascal(n-1, i)))%MOD
  end

  return $pascal[n][i]
end

N,K = readline.strip.split.map(&:to_i)


dp = []

(1..K).to_a.each do |i|

  if i > N-K+1
    p 0
  else
    p ( pascal(N-K+1, i) * pascal(K-1, i-1))%MOD
  end

end




Measured memory_bytes: 8956
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.nextLine();
        int s = 0;

        for (int i = 1;i <= n;i += 2){
            s++;
        }
        System.out.println((double)s / n);
    }
}

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

int main() {
  long int N,x,y,z,ans;
  cin>>N;
  ans=0;
  vector<long int> a(N);  
  for(long int i=0;i<N;i++){
    cin>>y;
    a.at(i)=y-i-1;
  }
  sort(a.begin(),a.end());
  z=(N/2);
  x=a.at(z);
  for(long int k=0;k<N;k++){
    ans+=abs(a.at(k)-x);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1792
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf = 10^^6;

void main() {
    int r;
    scan(r);

    writeln(r < 1200 ? "ABC" : r < 2800 ? "ARC" : "AGC");
}



















void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
#https://atcoder.jp/contests/abc141/tasks/abc147_a
import sys
#import collections

#n= int(input())
#s= input()
tmp = input().split()
a,b,c = list(map(lambda a: int(a), tmp))

if(a+b+c>21):
	print("bust")
else:
	print("win")

Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fi first
#define se second
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	//modcalc();

	int n, m;
	cin >> n >> m;
	vector<int> a(m), b(m);
	vector<vector<int>> graph(n, vector<int>());
	rep(i, m) {
		cin >> a[i] >> b[i];
		a[i]--; b[i]--;
		graph[a[i]].pb(b[i]);
		graph[b[i]].pb(a[i]);
	}
	vector<int> ans1, ans2;
	vector<bool> flag(n);
	int pl = a[0];
	flag[a[0]] = true;
	flag[b[0]] = true;
	bool check = true;
	while (check) {
		bool x = false;
		for (int i : graph[pl]) {
			if (!flag[i]) {
				pl = i;
				flag[i] = true;
				ans1.pb(i);
				x = true;
				break;
			}
		}
		if (!x) check = false;
	}
	pl = b[0];
	check = true;
	while (check) {
		bool x = false;
		for (int i : graph[pl]) {
			if (!flag[i]) {
				pl = i;
				flag[i] = true;
				ans2.pb(i);
				x = true;
				break;
			}
		}
		if (!x) check = false;
	}
	vector<int> ans;
	for (int i = ans1.size() - 1; i >= 0; i--) ans.pb(ans1[i]);
	ans.pb(a[0]); ans.pb(b[0]);
	for (int i = 0; i < ans2.size(); i++) ans.pb(ans2[i]);
	cout << ans.size() << endl;
	for (int i : ans) cout << i + 1 << ' ';
	cout << endl;
}

Measured memory_bytes: 10484
#include <stdio.h>

/*
挿入ソート
*/

void trace(int A[], int n){
    // 1行半角スペースで書き出し
    for (int i = 0; i < n; i++){
        printf("%d", A[i]);
        if (i != n-1){
            printf(" ");
        }
        else {
            printf("\n");
        }
    }
}

void insertionSort(int A[], int n){
    int v;
    int j;

    for (int i = 1; i < n; i++){
        v = A[i];
        j = i - 1;

        while(j >= 0 && A[j] > v){
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        trace(A, n);
    }
}

int main(){
    // 1行読む
    int n;
    scanf("%d", &n);

    // 1行半角スペースで読む
    int A[100];
    for (int i = 0; i < n; i++){
        scanf("%d", &A[i]);
    }

    // 出力用の関数
    trace(A, n);

    // 挿入ソートのロジック部分の関数
    insertionSort(A, n);

    return 0;
}



Measured memory_bytes: 2112
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <cstdint>
#include <iomanip>
#include <set>
#include <map>
#include <unordered_map>
#include <cassert>
using ll = long long;
#define rep(i,n) for(int i=0; i<(n); i++)
#define fast_io(); std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);

int main(){
    int n; std::cin >> n;
    std::vector<int> p(n);
    rep(i,n){
        std::cin >> p[i];
    }

    int ans = 0, min_p=1145141919;
    rep(i,n){
        min_p = std::min(min_p, p[i]);
        if(min_p==p[i]) ans++;
    }
    std::cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 4048
#pragma warning(disable:4996)
#include<stdio.h>
#include<string.h>
#define LEN 100005

//任务用结构体存储
typedef struct pp {
	char name[100];
	int t;
}P;

P  Q[LEN];
int head, tail, n;

void enqueue(P x) {
	Q[tail] = x;
	tail = (tail + 1) % LEN;
}

P dequeue() {
	P x = Q[head];
	head = (head + 1) % LEN;
	return x;
}

int min(int a, int b) { return a < b ? a : b; }

int main() {
	int elaps = 0, c;
	int i, q;
	P u;
	scanf("%d %d", &n, &q);

	//将任务添加至队列
	for (i = 1; i <= n; i++) {
		scanf("%s", Q[i].name);
		scanf("%d", &Q[i].t);
	}
	head = 1; tail = n + 1;
	/*for (i = 0; i <= n; i++) {
		printf("%s", Q[i].name);
		printf("%d", Q[i].t);
	}*/
	//模拟
	while (head != tail) {
		u = dequeue();
		c = min(q, u.t);//计算这个时间片需要执行的时间，如果这个任务所剩余时间小于时间片，则执行剩余的时间
		u.t -= c;//计算执行了这次后任务剩余时间
		elaps += c;
		if (u.t > 0) enqueue(u);
		else {
			printf("%s %d\n", u.name, elaps);
		}
	}
	return 0;
}


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

int dy[6] = {0, -1, -1, 0, 1, 1};
int dx[2][6] = {{-1,-1,0,1,0,-1},{-1,0,1,1,1,0}};
int a[110][110], f[110][110], w, h;

bool check(int y, int x){
	if(y < 0 || h+1 < y)return 1;
	if(x < 0 || w+1 < x)return 1;
	return 0;
}

int solve(int y, int x){
	if(check(y, x))return 0;
	if(a[y][x])return 1;
	if(f[y][x])return 0;
	f[y][x] = 1;
	
	int ans = 0;
	for(int i = 0;i < 6;i++){
		ans += solve(y+dy[i], x+dx[y%2][i]);
	}
	return ans;
}
int main(){
	scanf("%d%d", &w, &h);
	rrep(i,h)rrep(j,w)scanf("%d", &a[i][j]);
	int ans = solve(0, 0);
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 3524
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
LL fac[SIZE],fac_sum[SIZE],dp[SIZE],dp_sum[SIZE];
int main(){
    int N,H,D;
    R(N,H,D);
    fac[0]=1;
    FOR(i,1,N){
        fac[i]=fac[i-1]*i%MOD;
        fac_sum[i]=(fac_sum[i-1]+fac[i])%MOD;
    }
    dp_sum[1]=dp[1]=fac[N];
    FOR(i,2,H){
        int low=max(i-D,1);
        dp[i]=(dp_sum[i-1]-dp_sum[low-1])*fac_sum[N]%MOD;
        ADD(dp_sum[i],dp[i]+dp_sum[i-1]);
    }
    LL an=0;
    ADD(an,dp_sum[H]-dp_sum[H-D]);
    W(an);
    return 0;
}


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

int main(){
	int n;
	cin >> n;
	vector<int> l(n);
	rep(i,n) cin >> l[i];
	int counts = 0;
	for(int i = 0; i < n - 2; i++){
		for(int j = i + 1 ; j < n -1; j++){
			if(l[i] == l[j]) continue;
			for(int k = j+1; k < n; k++){
				if(l[k] == l[j]) continue;
				if(l[k] == l[i]) continue;
				if(l[k] + l[j] <= l[i] || l[i] + l[j] <= l[k] || l[i] + l[k] <= l[j]) continue;
				else counts++;
			}
		}
	}
	cout << counts << endl;
}

Measured memory_bytes: 3556
'use strict';
(function(input){
  input=input.trim().split(/\s+/).map(x=>x-0);
  const N=input.shift();
  const A=input;
  A[-1]=0;
  const dp=new Array(N+1).fill(0).map((x,i)=>new Array(N+1-i).fill(0));
  //dp[i][j]は添字jからi個連続で取った部分列に対するX-Yの値。
  //dp[N][0]が答
  for(let i=1;i<=N;i++)
    for(let j=0;j<=N-i;j++)
      dp[i][j]=Math.max(A[i+j-1]-dp[i-1][j],A[j]-dp[i-1][j+1]);
  const ans=dp[N][0];
  //console.log(dp);
  console.log(ans);
})(require('fs').readFileSync('/dev/stdin','utf8'));

Measured memory_bytes: 99264