akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
#define INT(x) int x; scanf("%d",&x)
#define INPUT(x) scanf("%d",&x)
#define REP1(x,n) for(int x = 0; x < n; x++)
#define REP2(x,s,e) for(int x = s; x <= e; x++)
#define BR printf("\n")
#define INF 2000000000

int main(){
    int cursor = 0;
    char S[15];
    char SS[11];
    cin >> SS;
    int len = strlen(SS);
    REP1(i,len){
        if (SS[i] == '1') {
            S[cursor] = '1';
            cursor++;
            S[cursor] = '\0';
        }else if(SS[i] == '0'){
            S[cursor] = '0';
            cursor++;
            S[cursor] = '\0';
        }else if(cursor != 0){
            cursor--;
            S[cursor] = '\0';
        }
    }
    cout << S << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] tmp = sc.nextLine().split(" ");
        int a = Integer.valueOf(tmp[0]);
        int b = Integer.valueOf(tmp[1]);
        int sum = judge(a, b);

        if (a < b) {
            b--;
        } else {
            a--;
        }
        sum += judge(a, b);
        System.out.println(sum);
    }

    public static int judge(int a, int b) {
        int res = 0;
        if (a < b) {
            res = b;
        } else {
            res = a;
        }
        return res;
    }
}


Measured memory_bytes: 21716
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <cassert>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define INF 1000000007
#define pi 3.141592653589793
using namespace std;
int saidaikouyakusuu(int a,int b){
    if(b==0) return a;
    return saidaikouyakusuu(b,a%b);
}
int saisyoukoubaisuu(int a,int b){
    return a*b/saidaikouyakusuu(a,b);
}
int n,m,cnt=0,aa[220000],ans=0,fans=0;
pair<int,int> pp[220000];
string s,sa[220000];
char c,ss[100][100],sss[100][100];
queue<int> que;
signed main(){
    cin>>n>>m>>cnt;
    rep(i,n){
        rep(j,m){
            cin>>ss[i][j];
        }
    }
    rep(i,pow(2,n)){
        rep(j,pow(2,m)){
            rep(k,n){
                rep(l,m){
                    sss[k][l]=ss[k][l];
                }
            }
            int a=i;
            rep(k,n){
                if(a%2==0){
                    rep(l,m){
                        sss[k][l]='.';
                    }
                }
                a/=2;
            }
            int b=j;
            rep(k,m){
                if(b%2==0){
                    rep(l,n){
                        sss[l][k]='.';
                    }
                }
                b/=2;
            }
            ans=0;
            rep(k,n){
                rep(l,m){
                    if(sss[k][l]=='#'){
                        ans++;
                    }
                }
            }
            if(ans==cnt){
                fans++;
            }
        }
    }
    cout<<fans<<endl;
}

Measured memory_bytes: 11000
using System;
using static System.Console;
using System.Linq;

namespace Main
{
    class main
    {
        static void Main(string[] args)
        {
            int[] tmp = ReadLine().Split(' ').Select(int.Parse).ToArray();
            WriteLine(tmp[0] >= 10 ? tmp[1] : tmp[1] + 100 * (10 - tmp[0]));
        }
    }
}

Measured memory_bytes: 13268
def f(list = [])
    sum = 0
    k = 0
    slice_list = []
    
    num_watering = list.min
    list.map!{|i| i - num_watering}
    sum += num_watering
    
    while list.size > 0 do
        if list[k] == 0 and k == 0
            list.shift
        
        elsif list[k] == 0
            sum += f(list.shift(k))
            list.shift
            k = 0
            
        elsif k == list.size-1
            sum += f(list)
            break
        else
            k+=1
        end
    end
    return sum
end




n = gets.to_i
list = gets.split.map(&:to_i)

p f(list)

Measured memory_bytes: 1788
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include <algorithm>
#include <map>
#include <string>
#include <set>

using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
#define ll long long
#define rn(i,n) for(int i=1;i<=n;i++)
#define INF 1000000010
const int mo=1e9+7;

 const int nmax=40,abmax=10,inf = 1000000;

 int a[nmax],b[nmax],c[nmax];
 int dp[nmax+1][nmax*abmax+1][nmax*abmax+1];

 int main(void){
 int n,ma,mb;
 cin >> n >> ma >> mb;

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

 for(int i = 0; i <= n; ++i){
 for(int ca = 0; ca <= nmax*abmax; ++ca){
 for(int cb = 0; cb <= nmax*abmax; ++cb){
 dp[i][ca][cb]=inf;
 }
 }
 }

 dp[0][0][0]=0;

 for(int i = 0; i < n; ++i){
 for(int ca = 0; ca <= nmax*abmax; ++ca){
 for(int cb = 0; cb <= nmax*abmax; ++cb){
 if(dp[i][ca][cb]==inf) continue;
 dp[i+1][ca][cb]=min(dp[i+1][ca][cb],dp[i][ca][cb]);
 dp[i+1][ca+a[i]][cb+b[i]]=min(dp[i+1][ca+a[i]][cb+b[i]],dp[i][ca][cb]+c[i]);
 }
 }
 }

 int ans=inf;
 for(int ca = 1; ca <= nmax*abmax; ++ca){
 for(int cb = 1; cb <= nmax*abmax; ++cb){
 if(ca*mb==cb*ma) ans=min(ans,dp[n][ca][cb]);
 }
 }

 if(ans==inf) ans=-1;
 cout << ans << endl;

 return 0;
 }


Measured memory_bytes: 25984
#include<stdio.h>
int s[100000],a[100000];
int main(void){
  int n=0,i,r,l;
  char c;
  c=getchar();
  while(c!=EOF){
    if(c=='L')
    s[n++]=0;
    else if(c=='R')
    s[n++]=1;
    c=getchar();
  }
  r=-1;//printf("a");
  for(i=0;i<n;i++){
    if(s[i]&&r==-1)
    r=i;
    if(r!=-1&&!s[i]){
      a[i]=(i-r)/2;
      a[i-1]=(i-r)/2;
      a[i-1]+=(i-r)%2;
      a[i]++;
      r=-1;
      l=i;
    }
    else if(!s[i]){
      a[l-(i-l)%2]++;
    }
  }
  for(i=0;i<n;i++){
    printf("%d",a[i]);
    if(i!=n-1)
    printf(" ");
  }
  return(0);
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define rep0(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep1(i,n) for(long long i=1;i<=(long long)(n);i++)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main() {
  ll N,M,N1=1,M1=1;
  cin>>N>>M;
  rep1(i,N){N1*=i; N1%=1000000000+7;}
  rep1(i,M){M1*=i; M1%=1000000000+7;}
  if(abs(N-M)>=2){cout<<0<<endl;}
  else if((N+M)%2==1){cout<<(N1*M1)%(1000000000+7)<<endl;}
  else{cout<<(2*N1*M1)%(1000000000+7)<<endl;}
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi acos(-1.0)
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

const double EPS = 1e-10;

double p, e, t;

bool isin(double x){
	return fabs(x-t) <= e+EPS;
}

double calc(int k, double l, double r){
	if (k == 0){
		if (isin((l+r)/2)) return 1.0;
		else return 0.0;
	}
	if (isin(l) && isin(r)) return 1.0;
	if (l > t+e+EPS || r < t-e-EPS) return 0.0;
	double res, m = (l+r)/2;
	if (m >= t) res = (1.0-p) * calc(k-1,l,m) + p * calc(k-1,m,r);
	else res = (1.0-p) * calc(k-1,m,r) + p * calc(k-1,l,m);
	return res;
}

int main(){
	int k;
	double l, r;
	cin >> k >> l >> r >> p >> e >> t;

	printf("%.10f\n", calc(k, l, r));

    return 0;
}

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

inline int getInt(){ int s; scanf("%d", &s); return s; }

typedef long long ll;

using namespace std;

template<class T>
class IdMaker{
public:
  std::map<T,int> _m;
  int getId(const T &v){
    if(_m.find(v) == _m.end()){
      int next = _m.size();
      return _m[v] = next;
    }
    return _m[v];
  }
};

ll adj[40];
int str[40];
int memo[40];
int ans;

void solve(ll flag, int now){
  ll ff = flag;

  while(ff){
    const ll f = ff & (-ff);
    const int pos = __builtin_ctzll(f);
    if((adj[pos] & flag) == 0){
      now += str[pos];
      flag ^= f;
    }
    ff ^= f;
  }

  ans = max(ans, now);
  if(flag == 0 || now + memo[__builtin_ctzll(flag)] <= ans)
    return;

  while(flag){
    const ll f = flag & (-flag);
    const int pos = __builtin_ctzll(f);
    solve((flag ^ (1ll << pos)) & (~adj[pos]), now + str[pos]);
    flag ^= f;
  }
}

int main(){
  while(const int n = getInt()){
    IdMaker<string> idm;

    REP(i,n){
      string s; cin >> s;
      str[idm.getId(s)] = getInt();
      const int m = getInt();
      adj[idm.getId(s)] = 0;
      REP(j,m){
        string a; cin >> a;
        adj[idm.getId(s)] |= (1ll << idm.getId(a));
      }
    }

    REP(i,n) memo[i] = 0;
    REP(i,n)
      for(int j = i; j < n; j++)
        memo[i] += str[j];

    ll start = (1ll << n) - 1;
    start ^= 1;
    start &= ~adj[0];

    ans = 0;
    solve(start, str[0]);
    printf("%d\n", ans);
  }
  return 0;
}

Measured memory_bytes: 976
#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()
#define pb push_back
typedef long long ll;
typedef pair<int,int> P;

template<typename A,typename B> inline void chmin(A &a,B b){if(a>b) a=b;}
template<typename A,typename B> inline void chmax(A &a,B b){if(a<b) a=b;}
//-----------------------------------------------------------------------

const int N=1e6;
bool isPrime[N+5];

int main()
{   
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    for(int i=2;i<=N;i++) isPrime[i]=true;
    for(int i=2;i<=N;i++){
        if(!isPrime[i]) continue;
        for(int j=i*2;j<=N;j+=i){
            isPrime[j]=false;
        }
    }

    int a,d,n;
    while(cin>>a>>d>>n,a|d|n)
    {
        while(true){
            if(isPrime[a]) n--;
            if(n==0){
                cout<<a<<endl;
                break;
            }
            a+=d;
        }
    }
    
}

Measured memory_bytes: 4192
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int center = s.length()/2;
        int result = 0;
        for (int i =0;i<center;i++){
            if (s.charAt(i) != s.charAt(s.length()-i-1)){
                result++;
            }
        }
        System.out.println(result);
    }
}


Measured memory_bytes: 23764
use proconio::input;

fn main() {
    input! {
        n: usize,
    }
    let m = 1000000007;
    let mut n10 = 1usize;
    let mut n9 = 1usize;
    let mut n8 = 1usize;
    for _ in 0..n {
        n10 = (n10 * 10) % m;
        n9 = (n9 * 9) % m;
        n8 = (n8 * 8) % m;
        n10 %= m;
        n9 %= m;
        n8 %= m;
    }

    let ans = (n10 + m - (((2 * n9) % m) + m - n8) % m) % m;
    println!("{}", ans);
}


Measured memory_bytes: 2184
#include <iostream>
#include <string>
#include <vector>


int main(void){
  int s;
  std::cin >> s;
  bool hm, tm;
  int head = s/100;
  int tail = s%100;

  hm = (1<=head) && (head<=12);
  tm = (1<=tail) && (tail<=12);

  if(hm&&tm) std::cout << "AMBIGUOUS" << std::endl;
  else if(hm&&!tm) std::cout << "MMYY" << std::endl;
  else if(!hm&&tm) std::cout << "YYMM" << std::endl;
  else std::cout << "NA" << std::endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#define REP(i,n) for(int i = 0;i < (n);i++)
#define pb push_back
using namespace std;
const int INF = 1e9;
typedef long long ll;

int main(){
  string s;
  cin >> s;
  vector <ll> a;
  REP(i,s.size()){
    if(s[i] == '0'){
      a.insert(a.end(),0);
    }
    else if(s[i] == '1'){
      a.insert(a.end(),1);
    }
    else{
      if(a.size() != 0){
	a.pop_back();
      }
    }
  }
  REP(i,a.size()){
    cout << a[i];
  }
  cout << endl;
  return 0;
}


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

const int MAX_N = 3000;
const int MAX_XY = 5000;
int n;
int a[MAX_N][2];
bool b[MAX_XY][MAX_XY];

int main(){
	while(1){
		scanf("%d", &n);
		if(n == 0) break;

		for(int i=0; i<MAX_N; i++)
			for(int j=0; j<2; j++)
				a[i][j] = 0;
		for(int i=0; i<MAX_XY; i++)
			for(int j=0; j<MAX_XY; j++)
				b[i][j] = false;

		for(int i=0; i<n; i++){
			scanf("%d %d", &a[i][0], &a[i][1]);
			b[a[i][0]][a[i][1]] = true;
		}

		int ans = 0;
		for(int i=0; i<n; i++){
			for(int j=0; j<n; j++){
				int dx, dy;
				dx = a[j][0] - a[i][0];
				dy = a[j][1] - a[i][1];
				for(int k=0; k<2; k++){
					int nx, ny;
					nx = a[i][0] + (2 * k - 1) * dy;
					ny = a[i][1] - (2 * k - 1) * dx;
					if(0 <= nx && nx <= MAX_XY && 0 <= ny && ny <= MAX_XY){
						if(0<=nx+dx&&nx+dx<=MAX_XY&&0<=ny+dy&&ny+dy<=MAX_XY){
							if(b[nx][ny] == true && b[nx+dx][ny+dy] == true){
								ans = max(ans, dx * dx + dy * dy);
							}
						}
					}
				}
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 27028
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {

		//    	File file = new File("src/in.txt");
		//    	Scanner sc = new Scanner(file);

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		LinkedHashMap<String, Long> map = new LinkedHashMap<String, Long>();
		long max = 0;
		for (int i=0;i<N;i++) {
			String S = sc.next();
		    if (map.containsKey(S)) {
		        map.put(S, map.get(S) + 1);
		        if(max<map.get(S)) {
		        	max = map.get(S);
		        }
		    } else {
		        map.put(S, (long) 1);
		        if(max<1) {
		        	max=1;
		        }
		    }
		}
		ArrayList<String> s = new ArrayList<String>();
		for(String S :map.keySet()) {
			if(map.get(S)==max) {
				s.add(S);
			}
		}
		Collections.sort(s);
		for(String x : s) {
			System.out.println(x);
		}
	}
}

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

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

    vector<string> vec;
    for (int i = 0; i < s.length(); i++) {
        for (int j = 1; j <= K; j++) {
            vec.push_back(s.substr(i, j));
        }
    }

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

    int cnt = 0;
    for (int i = 0; i < vec.size(); i++) {
        if (i == 0 || vec.at(i) != vec.at(i - 1)) cnt++;
        if (cnt == K) {
            cout << vec.at(i) << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 1660
/** 
If comrades that you trust gather around you, hope can take physical form and become visible. That’s what I believe.
*/
#include <bits/stdc++.h>
using namespace std;
/**
(▀̿Ĺ̯▀̿ ̿) (ง ͠° ͟ل͜ ͡°)ง
*/
const long long INF = 1LL << 60;
const int N = 50 + 7;
const int A = 100 * 50 + 7;

using ll = long long;
ll f[N][A];
using pi = pair<int, int>;
using ppi = pair<ll, pi>;
vector<ppi> g[N];
pi c[N];
auto main() -> int {
	ios_base::sync_with_stdio(false); cin.tie(0);
    int n, m, s; cin >> n >> m >> s;
    for (int i = 1; i <= m; ++i) {
        int u, v, a, b; cin >> u >> v >> a >> b;
        g[u].emplace_back(v, make_pair(a, b));
        g[v].emplace_back(u, make_pair(a, b));
    }
    for (int i = 1; i <= n; ++i) {
        cin >> c[i].first >> c[i].second;
    }

    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j <= 100 * 50; ++j) {
            f[i][j] = INF;
        }
    }
    // time, idx, money
    priority_queue<ppi, vector<ppi>, greater<ppi>> qu;
    s = min(s, 100 * 50);
    qu.emplace(0, make_pair(1, s));
    // cerr << "here\n";
    while (!qu.empty()) {
        auto [cur_time, y] = qu.top(); qu.pop();
        // cerr << cur_time << '\n';
        auto [idx, mon] = y;
        if (cur_time > f[idx][mon]) continue;
        f[idx][mon] = min(f[idx][mon], cur_time);
        for (auto &[nxt_idx, z]: g[idx]) {
            auto& [cost, tt] = z;
            if (mon >= cost && f[nxt_idx][mon - cost] > cur_time + tt) {
                f[nxt_idx][mon - cost] = cur_time + tt;
                qu.emplace(cur_time + tt, make_pair(nxt_idx, mon - cost));
            }
        }

        auto top_up = min(100 * 50, mon + c[idx].first);
        if (f[idx][top_up] > cur_time + c[idx].second) {
            f[idx][top_up] = cur_time + c[idx].second;
            qu.emplace(f[idx][top_up], make_pair(idx, top_up));
        }
    }
    // cerr << "Done\n";

    for (int i = 2; i <= n; ++i) {
        cout << *min_element(f[i], f[i] + 100 * 50) << '\n';
    }
	return 0;
}


Measured memory_bytes: 9284
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  long long ara[n+5];
  for(int i=0;i<n;i++)cin>>ara[i];
  sort(ara,ara+n);
  long long h=-1,w=-1;
  for(int i=n-1;i>=1;i--)
  {
    if(h==-1 && ara[i]==ara[i-1])h=ara[i],i--;
    else if(h!=-1 && ara[i]==ara[i-1])
    {
      w=ara[i];
      break;
    }
  }
  if(h!=-1 && w!=-1)cout<<h*w<<endl;
  else cout<<0<<endl;
}


Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
#include <iterator>
#include <functional>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <fstream>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <cmath>
#include <list>
#include <sstream>
#include <tuple>
#include <complex>
#include <stdio.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

typedef double LD;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LD, LD> PDD;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<char> VCH;
typedef vector<LD> VLD;
typedef vector<VI> VVI;
typedef vector<VLL> VVLL;
typedef vector<VCH> VVCH;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef vector<PDD> VPDD;
#define MP make_pair
#define PB push_back
#define X first
#define Y second
#define next fake_next
#define prev fake_prev
#define left fake_left
#define right fake_right

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i,0,t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())

const LD PI = acos(-1.0);
const LL mod = 1000000007;
const LL INF = 1e9;
const LL MAXN = 100001;

int n;
VI a;
VI b;

bool can(int x)
{
	a = b;
	FOR(i, 0, n)
		if (a[i] < x)
			a[i] = 0;
		else
			a[i] = 1;

	if (a[n / 2] == a[n / 2 - 1])
		return a[n/2];

	VI ok;
	FOR(i, 0, n - 1)
		if (a[i] == a[i + 1])
			ok.push_back(i);
	
	if (SZ(ok) == 0)
		return a[0];

	VI dist(SZ(ok));
	FOR(i, 0, SZ(ok))
		if (ok[i] >= n / 2)
			dist[i] = ok[i] - n / 2;
		else
			dist[i] = n / 2 - 1 - ok[i];
	
	int best = dist[0];
	FOR(i, 1, SZ(ok))
		best = min(best, dist[i]);

	FOR(i, 0, SZ(ok))
		if (best == dist[i])
			return a[ok[i]];

	throw - 1;
}

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);

	cin >> n;
	n = 2 * n - 1;
	a.assign(n, 0);
	FOR(i, 0, n)
		cin >> a[i];

	b = a;
	int L = 0, R = n, M;
	while (R - L > 1)
	{
		M = (L + R) / 2;
		if (can(M))
			L = M;
		else
			R = M;
	}
	if (can(L))
		cout << L;
	else
		cout << R;

	//cin >> n;
	return 0;
}

Measured memory_bytes: 3668
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include<cstdio>
#include<cstring>
#include<queue>
#include<stack>
#include<cmath>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef pair<int,int> P;
typedef pair<double,double> P_f;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define reprev(i, n) for (int i = (int)n - 1; i >= 0; i--)
#define bitrep(bit,n) for(int bit=0; bit<=(1<<n);bit++)
#define MAX 100100
#define MAX_N 200100
#define MAX_T 2001001
#define SENTINEL 20010010010
#define NIL -1
static const int INF = 1 << 29;
const ll INFTY = 1LL<<50;
string S;
int main(){
cin>>S;
int i=0;
int n=S.length();
string S_5,S_6,S_7;
while(1){
    if(n-5-i<0){
        break;
    }
    S_5=S.substr(n-5-i,5);
    if(n-6-i>=0){
    S_6=S.substr(n-6-i,6);
    }
    if(n-7-i>=0)S_7=S.substr(n-7-i,7);
    if(n-5-i<=0){
        break;
    }
    if(S_5=="dream" ||S_5=="erase"){
        i+=5;
    }
    else if(S_6=="eraser")i+=6;
    else if(S_7=="dreamer")i+=7;
    else {
        cout<<"NO"<<endl;return 0;
    }

}
cout<<"YES"<<endl;
return 0;
}

Measured memory_bytes: 512
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define divup(a,b) ( ( (a) + ( (b) - 1u) ) / (b) ) // a/b の余り切り上げ
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
ll mod = 1000000007;
ll mod9 = 1000000009;

pair<ll,ll> a[200009];
ll dist[200009];
vector<vector<ll>> r(200009);

signed main(){
    ll n,m;
    cin>>n>>m;
    rep(i,m) {
        cin>>a[i].first>>a[i].second;
        r[a[i].first-1].push_back(a[i].second-1);
        r[a[i].second-1].push_back(a[i].first-1);
    }
    /* rep(i,n){
        rep(j,r[i].size()){
            if(!j) cout<<endl;
            cout<<" "<<r[i][j];
        }
    }*/
    rep(i,200009) dist[i]=-1;
    queue<ll> Q;
    dist[0]=0;
    Q.push(0);
    while(!Q.empty()){
        ll v = Q.front();
        Q.pop();
        rep(i,r[v].size()){
            if(dist[r[v][i]]!=-1) continue;
            dist[r[v][i]] = v+1;
            Q.push(r[v][i]);
        }
    }
    cout<<"Yes"<<endl;
    rep(i,n-1){
        printf("%lld\n",dist[i+1]);
    }
}


Measured memory_bytes: 19264
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

int t[16][17];
int dp[1 << 17 + 1];
int n,tmp;

int solve(int state){
    if(dp[state] != -1) return dp[state];
    if(state == (1 << n) - 1) return 0;
    int ret = 1<< 30;
    int tmptime;

    for(int i=0;i<n;i++){
        if((state & (1 << i)) == 0){ //not cleared yet
            tmptime = t[i][0];
            for(int j=1;j<=n;j++){
                if((state & (1 << (j-1))) != 0){
                    tmptime = min(tmptime, t[i][j]);
                }
            }
            ret = min(ret, tmptime + solve(state|(1 << i)));
        }
    }
    
    return dp[state] = ret;
}

int main(){
    while(cin >> n && n){
        memset(dp, -1, sizeof(dp));
        for(int i=0;i<n;i++){
            for(int j=0;j<n+1;j++){
                cin >> tmp;
                t[i][j] = tmp;
            }
        }
        cout << solve(0) << endl;
    }
}

Measured memory_bytes: 1888
import java.util.Scanner;
public class Main{
private static Scanner s;
public static void main(String[] args) {
	s = new Scanner(System.in);
	int a = s.nextInt();
	int[] b = new int[a];
	int count = 0;

	for(int i = 0;i < a;i++)
		b[i] = s.nextInt();
	int c =s.nextInt();
	int[] d = new int[c];

	for(int i = 0;i < c;i++)
		d[i] = s.nextInt();

	for(int i = 0;i < c;i++) {
		for(int j = 0;j < a;j++) {
			if(d[i] == b[j]) {
			    count++;
			break;
			}
		}
	}
	System.out.println(count);
}
}



Measured memory_bytes: 40540
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<limits.h>
using namespace std;

int main(){
  int n,m,h,i,k,l,j,in,xmax,head,end,xxmax;

  while(1){
    xxmax=0;
    head=-1;
    end=-1;
    xmax=0;
    cin >> n >> m;
    if(n == 0 && m==0)break;
    int aa[m],ans[m];
    for(i=0;i<m;i++){
      ans[i]=i+1;
      aa[i]=0;
    }
    for(i=0;i<n;i++){
      for(j=0;j<m;j++){
	cin >> in;
	if(in == 1)aa[j]+=1;
      }
    }

    for(i=0;i<m;i++){
      xmax=i;
      for(j=i;j<m;j++){
	if(aa[xmax]<=aa[j])xmax=j;
      }
  

      h=aa[xmax];
      aa[xmax]=aa[i];
      aa[i]=h;
    
      h=ans[xmax];
      ans[xmax]=ans[i];
      ans[i]=h;
  

    }

 
    
    aa[m]=INT_MAX;

    for(i=1;i<=m;i++){
      if(aa[i-1] == aa[i] && head == -1){
	head=i-1;
      }      

  if(head != -1 && aa[i-1]!=aa[i]){
    end=i-1;
   
    for(k=head;k<=end;k++){
      xxmax=k;
      for(l=k;l<=end;l++)if(ans[xxmax]>ans[l])xxmax=l;
      h=ans[xxmax];
      ans[xxmax]=ans[k];
      ans[k]=h;
    }
    head=-1;
  }
    
    }
   
   

    for(i=0;i<m;i++){
      cout <<ans[i];
      if(i!=m-1)cout << " ";
      if (i == m-1)cout << endl;
    }
    
    
  }
  return 0;
}

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

int main() {
    int arr[52] = {0};
    int a;
    cin >> a;
    while(a) {
        char type;
        int number;
        cin >> type >> number;
        if (type=='S') {            
            arr[number-1] = number;
        } else if (type=='H') {
            arr[number-1+13] = number;
        } else if (type=='C') {
            arr[number-1+13*2] = number;
        } else if (type=='D') {
            arr[number-1+13*3] = number;
        }
        a--;
    }

    for (int i=0; i<52; i++) {
        if (i/13 == 0 && arr[i]==0) cout << 'S' <<" " << (i%13+1) <<endl;
        if (i/13 == 1 && arr[i]==0) cout << 'H' <<" " << (i%13+1) <<endl;
        if (i/13 == 2 && arr[i]==0) cout << 'C' <<" " << (i%13+1) <<endl;
        if (i/13 == 3 && arr[i]==0) cout << 'D' <<" " << (i%13+1) <<endl;
    }

    return 0;
}



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

#define ll long long
#define INF_LL 1LL << 60
#define INF 99999999
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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()
{
    int A,B,C;
    cin >> A >> B >> C;

    vector<ll> keys;
    keys.push_back(B+C);
    rep(i, 100) keys.push_back(keys[keys.size()-1]+B);

    rep(i, keys.size())
    {
        if( keys[i]%A == 0 )
        {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <bitset>
#include <iomanip>
#include <cmath>
#include <queue>
using namespace std;
using PP = pair<int, int>;
const int INF = 1e9;

template <class T> T Next() { T t; cin >> t; return t; }

int n, t, a;
int main() {
  cin >> n >> t >> a;
  
  double mn = 1e9;
  int mni = 0;
  for (int i = 0; i < n; ++i) {
    int b;
    cin >> b;
    double diff = abs(a - (t - b * 0.006));
    if (diff < mn) {
      mn = diff;
      mni = i;
    } 
  }
  cout << mni + 1 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

int main() {
  int n, m; cin >> n >> m;
  vector<vector<int>> g(n+1);
  rep(i, m){
    int x, y; cin >> x >> y;
    g.at(x).push_back(y);
    g.at(y).push_back(x);
  }

  vector<int> used(n+1, -1);
  queue<int> q;
  q.push(1);
  used.at(1) = 0;
  vector<int> past(n+1, 0);

  while(!q.empty()){
    int now = q.front();
    q.pop();
    for(auto a:g.at(now)){
      if(used.at(a)!=-1) continue;
      q.push(a);
      used.at(a) = used.at(now) + 1;
      past.at(a) = now;
    }
  }

  rep(i, n){
    if(used.at(i+1)==-1){
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
  rep(i, n){
    if(i==0) continue;
    cout << past.at(i+1) << endl;
  }

  return 0;
}


Measured memory_bytes: 10636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 4e3 + 5;
char s[N];
int r[N], g[N], b[N];

int main()
{
	int n;
	scanf("%d%s", &n, s);
	for (int i = n - 1; i >= 0; i--) {
		r[i] = r[i+1] + (s[i] == 'R');
		g[i] = g[i+1] + (s[i] == 'G');
		b[i] = b[i+1] + (s[i] == 'B');
	}
	ll sum = 0;
	int t = 'R' + 'G' + 'B';
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (s[i] != s[j]) {
				char tmp = t-s[i]-s[j];
				if (tmp == 'R') sum += r[j+1];
				else if (tmp == 'G') sum += g[j+1];
				else sum += b[j+1];
				if (2*j-i >= 0 && 2*j-i < n && s[2*j-i] == tmp) sum--;
			}
		}
	}
	printf("%lld\n", sum);
	return 0;
}

Measured memory_bytes: 3776
K = int(input())
src = list(map(int,input().split()))
if src[-1] != 2:
    print(-1)
    exit()

mn = 2
mx = 3
for a in reversed(src[:-1]):
    mn2 = mn + ((a - mn%a) % a)
    mx2 = mx - (mx%a)
    if mn2 > mx2:
        print(-1)
        exit()
    mn = mn2
    mx = mx2 + a - 1
print(str(mn) + ' ' + str(mx))


Measured memory_bytes: 14252
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int L,R,d,count=0;
	cin>>L>>R>>d;
	for(int i=L;i<=R;i++)
	{
		if(i%d==0)
		count++;
	}
	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
 #include <cmath>

 using namespace std;
 typedef long long ll;

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

 long double eps = 1.0E-14;

 if(sqrt(a) + sqrt(b) + eps < sqrt(c)){
 cout << "Yes" << endl;
 } else {
 cout << "No" << endl; }

 return 0;
 }


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int n;
    cin >> n;

    ll d;
    cin >> d;
    d *= d;

    int r = 0;
    for (int i = 0; i < n; i++) {
        ll x, y;
        cin >> x >> y;

        if (x * x + y * y <= d) r++;
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 3640
package main

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

func main() {
	sc := NewScanner()

	n := sc.ReadInt64()

	total := int64(0)
	for i := int64(1); i <= n; i++ {
		if i%3 != 0 && i%5 != 0 {
			total += i
		}
	}

	fmt.Println(total)
}

// util
// *   math/simple

func Abs(x int) int {
	if x >= 0 {
		return x
	}
	return -x
}

func Min(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	min := values[0]
	for _, v := range values {
		if v < min {
			min = v
		}
	}
	return min
}

func Max(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	max := values[0]
	for _, v := range values {
		if v > max {
			max = v
		}
	}
	return max
}

func Pow(base int, exponent uint) int {
	answer := 1
	for i := uint(0); i < exponent; i++ {
		answer *= base
	}
	return answer
}

func Abs64(x int64) int64 {
	if x >= 0 {
		return x
	}
	return -x
}

func Min64(values ...int64) int64 {
	if len(values) == 0 {
		panic("no values")
	}
	min := values[0]
	for _, v := range values {
		if v < min {
			min = v
		}
	}
	return min
}

func Max64(values ...int64) int64 {
	if len(values) == 0 {
		panic("no values")
	}
	max := values[0]
	for _, v := range values {
		if v > max {
			max = v
		}
	}
	return max
}

func Pow64(base int64, exponent uint) int64 {
	answer := int64(1)
	for i := uint(0); i < exponent; i++ {
		answer *= base
	}
	return answer
}

// *   io

type Scanner struct {
	bufScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bufSc := bufio.NewScanner(os.Stdin)
	bufSc.Split(bufio.ScanWords)
	return &Scanner{bufSc}
}

func (sc *Scanner) ReadString() string {
	bufSc := sc.bufScanner
	bufSc.Scan()
	return bufSc.Text()
}

func (sc *Scanner) ReadInt() int {
	bufSc := sc.bufScanner
	bufSc.Scan()
	text := bufSc.Text()

	num, err := strconv.Atoi(text)
	if err != nil {
		panic(err)
	}
	return num
}

func (sc *Scanner) ReadInt64() int64 {
	bufSc := sc.bufScanner
	bufSc.Scan()
	text := bufSc.Text()

	num, err := strconv.ParseInt(text, 10, 64)
	if err != nil {
		panic(err)
	}
	return num
}


Measured memory_bytes: 1760
N = int(input())
A = list(map(int, input().split()))

A.sort()
if A[0] == 0:
    ANS = 0
else:
    A.sort(reverse=True)
    ANS = 1
    for a in A:
        ANS = ANS * a
        if ANS > 10 ** 18:
            ANS = -1
            break

print(ANS)

Measured memory_bytes: 21660
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int,int> P;
typedef unsigned int ui;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
int main() {
	int n;
	while (cin >> n, n) {
		vector<int> G[26]; bool f = true;
		string s, t;
		cin >> t;
		rep(i, n - 1) {
			s = t; cin >> t;
			if (!f)continue;
			int len1 = s.length();
			int len2 = t.length();
			int len = min(len1, len2);
			if (s.substr(0, len) == t.substr(0, len)) {
				if (len1 > len2)f = false;
			}
			else {
				rep(j, len) {
					if (s[j] != t[j]) {
						G[s[j] - 'a'].push_back(t[j] - 'a'); break;
					}
				}
			}
		}
		rep(i, 26) {
			int used[26] = {}; used[i] = 1;
			queue<int> q; q.push(i);
			while (!q.empty()) {
				int v = q.front(); q.pop();
				int len = G[v].size();
				rep(j, len) {
					if (G[v][j] == i) {
						f = false;
					}
					if (!used[G[v][j]]) {
						used[G[v][j]] = 1;
						q.push(G[v][j]);
					}
				}
			}
			if (!f)break;
		}
		if (f) cout << "yes" << endl;
		else cout << "no" << endl;
	}
	return 0;
}


Measured memory_bytes: 3192
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <map>

using namespace std;

int main()
{
    int n, m, p, y;
    cin >> n >> m;
    vector<vector<pair<int, int>>> info(n+1);
    map<int, pair<int, int>> map_id;

    for (int i=0; i<m; ++i){
        cin >> p >> y;
        info[p].push_back(make_pair(y, i));
    }
    for (int i=1; i<=n; ++i){
        sort(info[i].begin(), info[i].end());
    }
    for (int i=1; i<=n; ++i){
        for (int j=0; j<(int)info[i].size(); ++j){
            map_id.insert(make_pair(info[i][j].second, make_pair(i, j+1)));
        }
    }
    for (int i=0; i<m; ++i){
        pair<int, int> ppair = map_id.at(i);
        printf("%06d", ppair.first);
        printf("%06d", ppair.second);
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 11648
#define REP(i, n) for (int i = 0; i < (n); ++i)

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  int N, M, C;
  cin >> N >> M >> C;
  int b[M];
  int a[M];
  REP(i, M) { cin >> b[i]; }
  int ans = 0;
  REP(i, N) {
    REP(j, M) { cin >> a[j]; }
    int sum = C;
    REP(j, M) { sum += a[j] * b[j]; }
    if (sum > 0)
      ans++;
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}

template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}


signed main(void) {
	int n;
	cin >> n;
	vector<int>a(n);
	int maxa = 0;
	rep(i, n) {
		cin >> a[i];
		maxa = max(maxa, a[i]);
	}
	int minsub = INF;
	int aj=a[0];
	rep(i, n) {
		if (a[i] == maxa)continue;
		int sub = abs(a[i] - (double)maxa / 2);
		//print(sub);
		if (sub < minsub) { 
			aj = a[i];
			minsub = sub;
		}
	}
	cout << maxa << " " << aj;

}

Measured memory_bytes: 4048
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 998244353
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int main(){
  ll x,y;cin>>x>>y;
  ll cnt=0;
  while(x<=y){
    x*=2;
    cnt++;
  }
  cout<<cnt<<endl;
}


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

int main() {
    string s,t;
    cin>>s>>t;
    int res=1;
    for(int i=0;i<s.size();i++){
        if(s.at(i)==t.at(i)) continue;
        else res=0;
    }
    if(s.size()+1!=t.size()) res=0;
    if(res==0) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
}

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
const int inf = 1000000001;
const ll INF = 1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<<fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };


int main() {
	int n, i;
	cin >> n;
	vi p(n + 1);
	for (i = 1; i <= n; i++) {
		cin >> p[i];
	}
	int cnt = 0;
	i = 1;
	while (i != n + 1) {
		if (p[i] == i) {
			if (i != n) {
				swap(p[i], p[i + 1]);
				cnt++;
			}
			else {
				swap(p[i], p[i - 1]);
				cnt++;;
			}
		}
		i++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 640
/**
 * @brief ユーザ定義リテラル
 * @author えびちゃん
 */

#ifndef H_int_literals
#define H_int_literals

#include <cstddef>
#include <cstdint>

constexpr intmax_t  operator ""_jd(unsigned long long n) { return n; }
constexpr uintmax_t operator ""_ju(unsigned long long n) { return n; }
constexpr size_t    operator ""_zu(unsigned long long n) { return n; }
constexpr ptrdiff_t operator ""_td(unsigned long long n) { return n; }

#endif  /* !defined(H_int_literals) */

/**
 * @brief 多次元 vector の作成
 * @author えびちゃん
 */

#ifndef H_make_vector
#define H_make_vector

#include <cstddef>
#include <type_traits>
#include <vector>

namespace detail {
  template <typename Tp, size_t N>
  std::vector<Tp> make_vector(
      std::vector<size_t>& sizes,
      typename std::enable_if<(N == 1), Tp const&>::type x
  ) {
    return std::vector<Tp>(sizes[0], x);
  }
  template <typename Tp, size_t N>
  auto make_vector(
      std::vector<size_t>& sizes,
      typename std::enable_if<(N > 1), Tp const&>::type x
  ) {
    size_t size = sizes[N-1];
    sizes.pop_back();
    return std::vector<decltype(make_vector<Tp, N-1>(sizes, x))>(
        size, make_vector<Tp, N-1>(sizes, x)
    );
  }
}  // detail::

template <typename Tp, size_t N>
auto make_vector(size_t const(&sizes)[N], Tp const& x = Tp()) {
  std::vector<size_t> s(N);
  for (size_t i = 0; i < N; ++i) s[i] = sizes[N-i-1];
  return detail::make_vector<Tp, N>(s, x);
}

#endif  /* !defined(H_make_vector) */

#include <cstdio>
#include <cstdint>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <array>
#include <tuple>

std::array<size_t, 4> const di{{-1_zu, 0, 1, 0}};
std::array<size_t, 4> const dj{{0, -1_zu, 0, 1}};

int main() {
  size_t h, w;
  scanf("%zu %zu", &h, &w);

  std::vector<std::string> s(h);
  for (auto& si: s) {
    char buf[128];
    scanf("%s", buf);
    si = buf;
  }

  std::vector<std::string> t(h, std::string(w, '.'));
  for (size_t i = 0; i < h; ++i) {
    for (size_t j = 0; j < w; ++j) {
      if (s[i][j] == '#') {
        t[i][j] = '#';
      } else if (i % 4 == 1 && s[i][j] == '2') {
        t[i][j] = '.';
      } else if (i % 4 == 3 && s[i][j] == '5') {
        t[i][j] = '.';
      } else if (j % 4 == 1 && s[i][j] == '3') {
        t[i][j] = '.';
      } else if (j % 4 == 3 && s[i][j] == '4') {
        t[i][j] = '.';
      } else if ((i+j) % 4 == 0 && s[i][j] == '6') {
        t[i][j] = '.';
      } else if ((i+j) % 4 == 2 && s[i][j] == '1') {
        t[i][j] = '.';
      } else {
        t[i][j] = '#';
      }
    }
  }

  using zahyo = std::pair<size_t, size_t>;
  auto dp = make_vector({h, w}, false);
  std::queue<zahyo> q;
  q.emplace(0, 0);
  dp[0][0] = true;
  while (!q.empty()) {
    size_t i, j;
    std::tie(i, j) = q.front();
    q.pop();

    for (size_t k = 0; k < 4; ++k) {
      size_t ni = i + di[k];
      size_t nj = j + dj[k];
      if (!(ni < h && nj < w)) continue;
      if (t[ni][nj] == '#') continue;
      if (dp[ni][nj]) continue;
      dp[ni][nj] = true;
      q.emplace(ni, nj);
    }
  }

  puts(dp[h-1][w-1]? "YES": "NO");
}



Measured memory_bytes: 2840
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>

int main(){
    
    size_t n;

    std::cin >> n;

    std::vector<int> p(n);

    for(auto&& e : p){
        std::cin >> e;
    }

    for(size_t i = 0; i < n; i++){
        for(size_t j = i; j < n; j++){
            auto tmp = p;
            std::swap(tmp.at(i), tmp.at(j));

            if(std::is_sorted(tmp.begin(), tmp.end())){
                std::cout << "YES" << std::endl;
                return 0;
            }
        }
    }

    std::cout << "NO" << std::endl;
    
    return 0;
}

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

int main(){
    int n;
    while(cin >> n){
        vector<int>v(n);
        for(int i = 0; i < n; i++){
            cin >> v[i];
        }
        
        sort(v.begin(), v.end());
        bool check[1000005];
        memset(check, false, sizeof check);
        int cnt = 0;
        
        for(int i = 0; i < n; i++){
            int val = v[i];
            if(i+1 < n && v[i] == v[i+1]){
                check[v[i]] = true;
                continue;
            }
            bool f = true;
            for(int j = 1; j <= sqrt(val); j++){
                if(val%j == 0){
                    int a = j;
                    int b = val / j ;
                    if(check[a] == true || check[b] == true){
                        f = false;
                    }
                }
            }
            if(f){
                cnt++;
            }
            check[val] = true;
        }
        cout << cnt << "\n";
    }
    return 0;
}

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

using namespace std;

int main() {
    int r, D, x2000;
    cin >> r >> D >> x2000;

    int x;
    for (int i=0; i<10; i++) {
        x = r * x2000 - D;
        cout << x << endl;
        x2000 = x;
    }

    return 0;
}

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

int main()
{
    int x;
    cin >> x;
    int ans = 0;
    while (x > 499)
    {
        ans += 1000;
        x -= 500;
    }
    while (x > 4)
    {
        ans += 5;
        x -= 5;
    }
    cout << ans << endl;
}

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

using namespace std;

int N, M;
priority_queue<int, vector<int>, greater<int>> pq;
int arr[100005];
vector<pair<int, int>> v;

int main(){
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin >> N >> M;
    for(int i = 1; i<=N; i++){
        cin >> arr[i];
        pq.push(arr[i]);
    }
    sort(arr+1, arr+1+N);
    for(int i= 1; i<=M; i++){
        pair<int ,int> p;
        cin >> p.second >> p.first;
        v.push_back(p);
    }
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    int k = N;
    for(auto p : v){
        int cnt = p.second;
        while(pq.top() < p.first && cnt--){
            pq.pop();
            pq.push(p.first);
        }
    }
    long long s = 0;
    for(int i = 1; i<=N; i++){
        s += pq.top();
        pq.pop();
    }
    cout << s << endl;
}


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


int main(){
	int a,b,c,d,e;
	cin >> a >> b >> c >> d >> e;
	if(a==0){
		cout <<  1<< endl;
	}else if(b==0){
		cout <<  2<< endl;
	}else if(c==0){
		cout <<  3<< endl;
	}else if(d==0){
		cout <<  4<< endl;
	}else if(e==0){
		cout <<  5<< endl;
	}
}

Measured memory_bytes: 3624
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cin;
using std::cout;
using std::endl;

int main(void) {
    int result = 0;
    std::string s;
    cin >> s;
    int count = 0;
    for (auto x : s) {
        if (x == 'o')
            count++;
    }
    cout << 700 + count * 100 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <cmath>
using namespace std;
typedef complex<double> xy_t;
 
double cross_product(xy_t a, xy_t b) {
  return (conj(a) * b).imag();
}
 
const double eps = 1e-11;
double x[4], y[4];
int N;
int main() {
  cin >> N;
  for (int t = 0; t < N; ++t) {
    for (int i = 0; i < 4; ++i) {
      cin >> x[i] >> y[i];
    }
    xy_t a[2] = {
      xy_t(x[0], y[0]) - xy_t(x[1], y[1]),
      xy_t(x[2], y[2]) - xy_t(x[3], y[3])
    };
    bool p = abs(cross_product(a[0], a[1])) < eps;
    cout << (p ? "YES" : "NO") << endl;
  }
  return 0;
}

Measured memory_bytes: 3052
#include <iostream>
#include <cstring> // memset()
#include <cmath> // pow(a, b)
#include <string> // string stoi(string)
#include <cstdlib> // abs(int x)
#include <bitset> // bitset<int>(int)
#include <vector> 
using namespace std;

struct Edge {
  int to;
  int weight;
  // initializer to initialize the constructor by this.
  Edge(int t, int w) : to(t), weight(w) { }
};

using Graph = vector<vector<Edge>>;

int N;
vector<int> color;

void dfs(const Graph &G, int v, int cur = 0) {
  color[v-1] = cur;

  for (auto next_v : G[v]) {
    int to = next_v.to;
    int weight = next_v.weight;
    if (color[to-1] != -1) continue;
    
    if (weight % 2 == 0) {
      dfs(G, to, cur);
    } else {
      dfs(G, to, 1-cur);
    }
  }
}

int main() {
  cin >> N;
  Graph G(N+1);
  color.assign(N, -1);
  
  for (int i = 0; i < N - 1; i++) {
    int from, to, weight;
    cin >> from >> to >> weight;
    G[from].push_back(Edge(to, weight));
    G[to].push_back(Edge(from, weight));
  }

  dfs(G, 1);

  for (auto i: color) {
    cout << i << endl;
  }
}


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

using namespace std;
using llint = long long int ;

#define rep(i,c) for(int i = 0; i < (int)c; ++i)
// c 回繰り返す
const llint mod = 1000000007;
//mod　10^9 + 7

int main(){
    string S;
    cin>>S;
    bool ch=true;

    for (int i = 0; i < S.size(); i++)
    {
        if(S.size()-1-i<i) break;
        if(S[i]!=S[S.size()-i-1]) ch=false;
    }

    for (int i = 0; i <((S.size()-1)/2)-1 ; i++)
    {
        if( ((S.size()-1)/2)-1-i<i) break;
        if(S[((S.size()-1)/2)-1-i]!=S[i]) ch=false;
    }

    for(int i=((S.size()+3)/2)-1 ; i<S.size()-1;i++){
        if(S.size()-1-i<i) break;
        if (S[i]!=S[S.size()-i-1]) ch=false;
        
    }
    
    ch?cout<<"Yes"<<endl:cout<<"No"<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define COINNUM 6
#define PAY 1000

int main(void){
	const int coins[COINNUM] = {500, 100, 50, 10, 5, 1};
	int price;
	int back;
	int num;
	
	while (scanf("%d", &price), price){
		back = PAY - price;
		num = 0;
		for (int i=0; i<COINNUM; i++){
			while (back >= coins[i]){
				num++;
				back -= coins[i];
	//			printf("%d, ", coins[i]);
			}
		}
		printf("%d\n", num);
	}
	return 0;
}

Measured memory_bytes: 1028