akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

struct UnionFind {
    vector<int> data;

    UnionFind(int sz) {
        data.assign(sz, -1);
    }

    bool unite(int x, int y) {
        x = find(x), y = find(y);
        if (x == y) return (false);
        if (data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return (true);
    }

    int find(int k) {
        if (data[k] < 0) return (k);
        return (data[k] = find(data[k]));
    }

    int size(int k) {
        return (-data[find(k)]);
    }
};

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

    vector<vector<int>> v(n);
    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        v[i] = {x, y, i};
    }
    sort(v.begin(), v.end());

    UnionFind uf(n);
    set<vector<int>, greater<>> mi;
    for (auto &x:v) {
        if (mi.upper_bound({x[1], x[2]}) != mi.end()) {
            auto p = *mi.upper_bound({x[1], x[2]});
            uf.unite(p[1], x[2]);
        }
        mi.insert({x[1], x[2]});
    }

    reverse(v.begin(), v.end());
    set<vector<int>> ma;
    for (auto &x:v) {
        if (ma.upper_bound({x[1], x[2]}) != ma.end()) {
            auto p = *ma.upper_bound({x[1], x[2]});
            uf.unite(p[1], x[2]);
        }
        ma.insert({x[1], x[2]});
    }
    reverse(v.begin(), v.end());

    int miY = v[0][1], miV = v[0][2];
    for (int i = 1; i < n; i++) {
        if (miY < v[i][1])uf.unite(miV, v[i][2]);
        else miY = v[i][1], miV = v[i][2];
    }

    int maY = v[n - 1][1], maV = v[n - 1][2];
    for (int i = n - 2; i >= 0; i--) {
        if (v[i][1] < maY)uf.unite(maV, v[i][2]);
        else maY = v[i][1], maV = v[i][2];
    }

    for (int i = 0; i < n; i++)cout << uf.size(i) << "\n";
    cout << flush;
    return 0;
}


Measured memory_bytes: 52636
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<pii> > graph;
queue<int> que;

int ans[MAXN];

bool visited[MAXN];

void dfs(int here,int val)
{
    visited[here] = true;

    int there;

    ans[here] = val;

    for(int i=0;i<graph[here].size();i++)
    {
        there = graph[here][i].f;
        if(visited[there])continue;
        if(graph[here][i].s&1)dfs(there,(1^val));
        else dfs(there,val);
    }
    return;
}

int main()
{
    int n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n;

    graph = vector<vector<pii> > (n+1);

    for(int i=1;i<n;i++)
    {
        cin>>x>>y>>a;
        graph[x].push_back(pii(y,a));
        graph[y].push_back(pii(x,a));
    }

    dfs(1,0);

    for(int i=1;i<=n;i++)
        cout<<ans[i]<<"\n";

    return 0;
}


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


int main(){ 


  while(1){
      int x,y;

      cin>>x>>y;
      if(x == 0 && y == 0) break; 
      
      if(x > y) swap(x,y);
      cout<<x<<" "<<y<<endl;
}   

}
 


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


using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 (ll)1 << 60
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll n, m, s, t, d[2][110000], now = INF64;
struct edge { ll to, cost; };
vector<edge> g[2][110000];

vector<ll> ans;
void ds(ll a, ll b) {
	priority_queue<P, vector<P>, greater<P> > q;
	fill(d[b], d[b] + n, INF64);
	d[b][a] = 0;
	q.push(P(0, a));
	while (!q.empty()) {
		P p = q.top();
		q.pop();
		ll v = p.second;
		if (d[b][v] < p.first) continue;
		REP(i, g[b][v].size()) {
			edge e = g[b][v][i];
			if (d[b][e.to] > d[b][v] + e.cost) {
				d[b][e.to] = d[b][v] + e.cost;
				q.push(P(d[b][e.to], e.to));
			}
		}
	}
}

int main() {
	cin >> n >> m >> s >> t;
	REP(i, m) {
		ll a, b, c, d;
		cin >> a >> b >> c >> d;
		a--; b--;
		edge a0 = { b, c }, a1 = { b,d }, b0 = { a,c }, b1 = { a,d };
		g[0][a].push_back(a0);
		g[1][a].push_back(a1);
		g[0][b].push_back(b0);
		g[1][b].push_back(b1);
	}
	ds(s - 1, 0);
	ds(t - 1, 1);
	REPR(i, n - 1) {
		ans.push_back(min(now, d[0][i] + d[1][i]));
		now = min(now, d[0][i] + d[1][i]);
	}
	reverse(ALL(ans));
	REP(i, n) {
		cout << (ll)1e15 - ans[i] << endl;
	}
}


Measured memory_bytes: 20608
n=1000000
p_list=Array.new(n+1,1)
p_list[0..1]=[nil,nil]
(2..n**(1/2.0)).each do |i|
  if p_list[i]
    (2..n/i).each do |j|
      p_list[i*j]=nil
    end
  end
end

while gets
  puts p_list[0..$_.to_i].count{|p| p}
end

Measured memory_bytes: 17884
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
//#include<ext/pb_ds/detail/standard_policies.hpp>

// common
#define endl     "\n"
#define M_PI     3.14159265358979323846

// fast input output
#define fast_io  ios_base::sync_with_stdio(false); cin.tie(NULL);  cout.tie(NULL)

// fixed float field
#define fix_prec cout.setf( std::ios::fixed, std:: ios::floatfield ); cout.precision(9);

// vector
#define vi       vector<int>
#define vvi      vector<vector<int>>
#define vpii     vector<pair<int,int>>
#define pb(v,x)  v.push_back(x)

// pair
#define pii      pair<int,int>
#define mp(a,b)  make_pair(a,b)
#define F        first
#define S        second

// sort
#define all(x)   x.begin(),x.end()

// bound
#define lb(v,x)  lower_bound(v.begin(),v.end(),x)
#define ub(v,x)  upper_bound(v.begin(),v.end(),x)

using namespace std;
//using namespace __gnu_pbds;

//typedef tree < int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update > ordered_set;
typedef long long int lli;
typedef unsigned long long int ulli;

// constants
lli const mod  = 1e9;
lli const modl = 1e18;

void solve()
{
	int n,d,i,x,y,ans=0;
	cin>>n>>d;
	for(i=1;i<=n;i++)
	{
		cin>>x>>y;
		if(sqrt(pow(abs(x),2)+pow(abs(y),2))<=d)
			ans++;
	}
	cout<<ans;
}

int main()
{
  fast_io;
  fix_prec;
  int t=1;
  //cin>>t;
  while(t--)
  {
    solve();
    cout<<endl;     
  }
  return 0;	
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
class slove
{
private:
        int node[10];
        int route[205][205];
        int dp[1<<10][10];
        int n,m,k;
public:
    void in()
    {
        memset(route,0x3f,sizeof(route));
        scanf("%d %d %d",&n,&m,&k);
        for(int i = 0; i < k; i++)
            scanf("%d",&node[i]);
        while(m--)
        {
            int x,y,cost;
            scanf("%d %d %d",&x,&y,&cost);
            route[y][x] = route[x][y] = cost;
        }
    };
public:
    void doing()
    {

        for(int i = 1; i <= n; i++)
        {
            for(int j = 1; j <= n; j++)
            {
                for(int s = 1; s <= n; s++)
                {
                    route[j][s] = min(route[j][s],route[j][i] + route[i][s]);
                }
            }
        }
        memset(dp,0x3f,sizeof(dp));
        int maxx = dp[0][0];
        for(int i = 0; i < k; i++)
        {
            dp[(1<<i)][i] = 0;
        }
        for(int i = 1; i < 1<<k; i++)
        {
            for(int j = 0; j < k; j++)
            {
                for(int s = 0; s < k; s++)
                {
                    if(j!=s&&!(i&(1<<s)))
                    {
                        dp[i|(1<<s)][s] = min(dp[i|(1<<s)][s],dp[i][j] + route[node[j]][node[s]]);
                    }
                }
            }
        }
        for(int i = 0; i < k; i++)
        {
            maxx = min(dp[(1<<k)-1][i],maxx);
        }
        printf("%d\n",maxx);
    }
};
int main(void)
{
    slove M;
    M.in();
    M.doing();
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
#define double long double
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
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; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
#define eps 1e-12 
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N, K; cin >> N >> K;
	bool zero = 0;
	VI A, B;
	REP(i, N) {
		int a; cin >> a;
		if (a > 0)A.push_back(a);
		if (a < 0)B.push_back(-a);
		if (a == 0)zero = 1;
	}
	int tmp;
	double ans = -1;
	rSORT(A);
	rSORT(B);

	double asum[200010] = { 0 };
	double bsum[200010] = { 0 };
	int Asum[200010] = { 0 };
	int Bsum[200010] = { 0 };
	Asum[0] = Bsum[0] = 1;
	FOR(i, 0, A.size()) {
		asum[i + 1] += asum[i] + log(A[i]);
		Asum[i + 1] = Asum[i] * A[i] % mod;
	}
	FOR(i, 0, B.size()) {
		bsum[i + 1] += bsum[i] + log(B[i]);
		Bsum[i + 1] = Bsum[i] * B[i] % mod;
	}

	for (int i = 0; i <= B.size(); i += 2) {
		double cnt = bsum[i];
		int j = K - i;
		if (j > A.size() || j < 0)continue;
		cnt += asum[j];

		if (cnt > ans) {
			ans = cnt; 
			tmp = Asum[j] * Bsum[i] % mod;
		}
	}

	//cout << ans << " " << tmp << endl;
	if (ans == -1) {
		if (zero) {
			cout << 0 << endl;
			return 0;
		}
		reverse(B.begin(), B.end());
		REP(i, B.size())B[i] *= -1;

		tmp = 1;
		int j = 0;
		while (K--) {
			tmp *= B[j];
			tmp %= mod;
			j++;
			if (j >= B.size())break;
			
		}
		
		if (K!=-1) {
			j = 0;
			SORT(A);
			while (K--) {
				tmp *= A[j];
				tmp %= mod;
				j++;
			}
		}
		tmp += mod;
		tmp %= mod;
	}

	cout << tmp << endl;

	return 0;
}



Measured memory_bytes: 14388
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>

#include <cmath>

using namespace std;

int main() {
	int n, t, a;
	cin >> n >> t >> a;
	vector<int> h(n);
	for (int i = 0; i < n; i++)
	{
		cin >> h[i];
	}
	double deg = 1000;
	int ans;
	for (int i = 0; i < n; i++)
	{
		double temp = fabs(a - (t - h[i] * 0.006));
		if (temp < deg) {
			deg = temp;
			ans = i + 1;
		}
	}

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

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

int main(){

string w;
while(cin>>w){
if(w=="-"){break;}
int m;
cin>>m;

for(int i=0;i<m;i++){
int h;
cin>>h;
w=w.substr(h)+w.substr(0,h);
}
cout<<w<<endl;
}

return 0;
}


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

int main()
{
  string s;
  cin>>s;
  int cnt =700;
  if(s[0]=='o')cnt=cnt+100;
  if(s[1]=='o')cnt=cnt+100;
  if(s[2]=='o')cnt=cnt+100;
  cout<<cnt<<endl;
}

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

using namespace std;

long long f[2000010];
const int mod = 1e9 + 7;

int main() {
    
    f[0] = 1;

    for (int i = 1; i < 2000010; ++i) 
        f[i] = (i * f[i - 1]) % mod;

    int x,y;
    scanf("%d %d", &x, &y);
    
    if((x + y) % 3 != 0) return puts("0"),0;

    auto modpow = [] (long long x, long long y) {
        long long ans = 1;
        x = x % mod;
        while(y) {
            if(y & 1) ans = (ans * x) % mod;
            y >>= 1;
            x = (x * x) % mod;
        }
        return ans;
    };

    auto C = [&modpow](int n, int k) {
        long long x = f[n - k] * f[k];
        return (f[n] * modpow(x, mod - 2)) % mod;
    };


    for (long long i = 0; i <= (x + y) / 3; ++i) {
        long long j = (x + y) / 3 - i;
        if(x == 2 * j + i and y == 2 * i + j) {
            printf("%lld\n", C((x + y) / 3, i));
            return 0;
        }
    }

    puts("0");
   
    return 0;
}


Measured memory_bytes: 15872
# -*- coding: utf-8 -*-
import sys
import math
# INPUT
input = list(map(float, input().split()))

q = int(input[0])

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

while True:
  if is_prime(q):
    print(q)
    sys.exit()
  q = q + 1



Measured memory_bytes: 3060
import sys
import socket
from collections import Counter

if socket.gethostname() in ['N551J', 'F551C']:
    sys.stdin = open('b1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


def solve():
    res = 0
    n = read_int()
    a = read_int_list()
    a.sort()
    c = Counter(a)
    for i in range(n - 1, -1, -1):
        if c[a[i]] <= 0:
            continue
        c[a[i]] -= 1
        p = 1
        while not p <= a[i] < 2 * p:
            p *= 2
        comp = 2 * p - a[i]
        if c[comp] > 0:
            c[comp] -= 1
            res += 1
    return res


def main():
    res = solve()
    print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 33936
#include <iostream>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;

int main(){
    int n,tempcount=0,count=0;
    long int h[100001];
    cin >> n;
    rep(i,n) cin >> h[i];
    h[n] = 1000000001;
    for(int i=0;i<=n;i++){
        if(h[i] >= h[i+1]) tempcount += 1;
        else{
            if(count < tempcount){
                count = tempcount;
                tempcount = 0;
            }
            else tempcount = 0;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
    public static void main(String[] args){
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();
        
        int result = 0;
        
        for(int i = 1; i <= N ; i++){

            int sum = sumDigits(i);
            if(sum >= A && sum <= B){
                result += i;
            }
        }

        System.out.println(result);
    }
    
    public static int sumDigits(int n){
        int sum = 0;
        
        while(n != 0){
            sum += n % 10;
            n = n / 10;
        }
        return sum;
    }
}


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

const int maxn=1e2+7;
char str[maxn][maxn];
int n,m,ans;

bool vis[maxn][maxn];

int dx[]={1,-1,0,0},dy[]={0,0,-1,1};

void dfs(int sx,int sy){
    ans++;
    vis[sx][sy]=1;
    for(int i=0;i<4;i++){
        int xx=sx+dx[i];
        int yy=sy+dy[i];
        if(xx>=0&&xx<n&&yy>=0&&yy<m&&!vis[xx][yy]&&str[xx][yy]!='.') dfs(xx,yy);
    }
}

int main (){
    cin>>n>>m;
    memset(vis,0,sizeof(vis));

    for(int i=0;i<n;i++) scanf("%s",str[i]);


    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(str[i][j]=='#'&&!vis[i][j]){
                ans=0;
                dfs(i,j);
                if(ans==1) {cout<<"No"<<endl;return 0;}
            }
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}


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

void border(vector<string> &F, int h, int w){
  for(int i = 0; i < w + 1; i++){
    F.at(h) += "#";
  }
}

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> a(H);
  for(int i = 0; i < H; i++){
    cin >> a.at(i);
  }
  
  vector<string> frame(H + 2,"#");
  border(frame, 0, W);
  for(int i = 0; i < H; i++){
    frame.at(i + 1) += a.at(i);
    frame.at(i + 1) += "#";
  }
  border(frame, H + 1, W);

  for(string L : frame){
    cout << L << 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;

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	ll K,N;
	cin>>K>>N;

    vector<ll> A(N);

    rep(i,N){
        cin>>A[i];
    }
    ll d_max = 0;
    rep(i,N-1){
        d_max = max(d_max,A[i+1]-A[i]);
    }

    d_max = max(d_max,K-A[N-1]+A[0]);

    cout<<(K-d_max)<<"\n";
	
	return 0;
}

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

int main() {
	
	int n,k;
	cin>>n>>k;
	long long ans=0;
	long long cntzeros=0;
	long long cnth=0;
	for(int i=1;i<=n;i++)
	{
		if(i%k==0)cntzeros++;
		if(k%2==0)
		{
			if(i%k==k/2)cnth++;
		}
	}
	ans=(cntzeros*cntzeros*cntzeros)+(cnth*cnth*cnth);
	cout<<ans;
	return 0;
}

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

#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;

int main (void) {
    ll X, A, ans;
    scanf("%lld %lld", &X, &A);
    if ( X < A ) printf("0\n");
    else printf("10\n");
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main(){
   
  int j,i,k,N,v,A[1000];
   
  scanf("%d",&N);
  for( i = 0; i < N; i++){
    scanf("%d",&A[i]);
  }
   
  for(k = 0; k < N-1; k++){
    printf("%d ",A[k]);
  }
  printf("%d",A[k]);
  printf("\n"); 
  for(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;
       
    }
     
    for(k = 0; k < N-1; k++){
      printf("%d ",A[k]);
    }
    printf("%d\n",A[k]);
     
  }
   
  return 0;
}

Measured memory_bytes: 1816
#define _GLIBCXX_DEBUG
// #include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <bitset>
#include <stack>

typedef long long ll;
typedef std::vector< int > VI;

const double EPS = 1e-10;
const double PI  = acos(-1);
const ll     INF = 1 << 30;

// i グラムの砂糖水で、濃度最大
double dp[10007];
ll    water[10007];
ll    sugar[10007];

double concentration(ll water, ll sugar, ll e) {
  if (water == 0 || (double)(sugar / (double)water * 100.0) > (double)e + 1e-10) {
    return -9999.9;
  }
  return (double)(100.0 * sugar / (water + sugar));
}

int main(int argc, char* argv[])
{
  // 3 9 4 28 55 2859
  // 1860 660
  
  ll a, b, c, d, e, f;
  std::cin >> a >> b >> c >> d >> e >> f;

  for (ll i = 0; i <= f; i++) {
    dp[i] = -9999.9;
    water[i] = i;
    sugar[i] = 0;
  }
  dp[0] = -1e-10;

  for (ll i = 0; i <= f; i++) {
    //if (i == 1856) {
    //  std::cout << "hoge1 " << dp[i] << " " << water[i] << " " << sugar[i] << std::endl;
    //  std::cout << "hoge2 " << water[i] << " " << sugar[i]+c << " " << e << " " << std::endl;
    //  std::cout << "hoge3 " << concentration(water[i], sugar[i]+c, e) << " " << dp[i+c] << std::endl;
    //  std::cout << "hoge4 " << (double)((sugar[i]+c) / (double)water[i] * 100.0) << std::endl;
    //}
    // ope 1
    if (dp[i] > -1.0 && concentration(water[i] + 100*a, sugar[i], e) > dp[i+100*a]) {
      dp[i+100*a] = concentration(water[i] + 100*a, sugar[i], e);
      water[i+100*a] = water[i] + 100*a;
      sugar[i+100*a] = sugar[i];
      //std::cout << "1: " << dp[i+100*a] << " " << water[i] + 100*a << " " << sugar[i] << std::endl;
    }

    // ope 2
    if (dp[i] > -1.0 && concentration(water[i] + 100*b, sugar[i], e) > dp[i+100*b]) {
      dp[i+100*b] = concentration(water[i] + 100*b, sugar[i], e);
      water[i+100*b] = water[i] + 100*b;
      sugar[i+100*b] = sugar[i];
      //std::cout << "2: " << dp[i+100*b] << " " << water[i] + 100*b << " " << sugar[i] << std::endl;
    }

    // ope 3
    if (dp[i] > -1.0 && concentration(water[i], sugar[i]+c, e) > dp[i+c]) {
      dp[i+c] = concentration(water[i], sugar[i]+c, e);
      water[i+c] = water[i];
      sugar[i+c] = sugar[i] + c;
      //std::cout << "3: " << dp[i+c] << " " << water[i] << " " << sugar[i] + c << std::endl;
    }

    // ope 4
    if (dp[i] > -1.0 && concentration(water[i], sugar[i]+d, e) > dp[i+d]) {
      dp[i+d] = concentration(water[i], sugar[i]+d, e);
      water[i+d] = water[i];
      sugar[i+d] = sugar[i] + d;
      //std::cout << "4: " << dp[i+d] << " " << water[i] << " " << sugar[i] + d << std::endl;
    }
  }

  double ans = dp[0];
  ll    ans_water = water[0];
  ll    ans_sugar = sugar[0];
  for (ll i = 1; i <= f; i++) {
    if (dp[i] > ans) {
      ans       = dp[i];
      ans_water = water[i];
      ans_sugar = sugar[i];
    }
  }
  std::cout << ans_water+ans_sugar << " " << ans_sugar << std::endl;

  return 0;
}


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

int main(){
  //in
  int N;
  cin>>N;
  vector<int64_t> a(3*N);
  for(int i=0;i<3*N;++i) cin>>a[i];

  vector<int64_t> sc(N+1,0);
  priority_queue<int64_t,vector<int64_t>,greater<int64_t>> pq;
  for(int i=0;i<N;++i){
    sc[0] += a[i];
    pq.push(a[i]);
  }

  for(int i=1;i<=N;++i){
    int64_t te=pq.top();
    if(te<a[i+N-1]){
      sc[i]=sc[i-1]+a[i+N-1]-te;
      pq.pop();
      pq.push(a[i+N-1]);
    }
    else sc[i]=sc[i-1];
  }

  vector<int64_t> sc2(N+1,0);
  priority_queue<int64_t> pq2;
  for(int i=0;i<N;++i){
    sc2[N] += a[2*N+i];
    pq2.push(a[2*N+i]);
  }
  
  for(int i=2*N-1;i>=N;--i){
    int64_t te=pq2.top();
    if(te>a[i]){
      sc2[i-N]=sc2[i-N+1]+(a[i]-te);
      pq2.pop();
      pq2.push(a[i]);
    }
    else sc2[i-N]=sc2[i-N+1];
  }

  int64_t ans=-1e15;
  for(int i=0;i<=N;++i){
    ans = max(ans,sc[i]-sc2[i]);
    //cout<<sc[i]<<" "<<sc2[i]<<endl;
  }

  cout<<ans<<endl;

}

Measured memory_bytes: 6516
#include<bits/stdc++.h>
// もう一回写経
using namespace std;

typedef long long ll;

int main(){
 

  int N,K; cin >> N >> K;
  vector<int> P(N);
  
  for(int i = 0; i < N; i++){ cin >> P[i];}
  
  vector<int> a(N,0);
  vector<int> sum(N,0);
  
  for(int i = 1; i < N; i++){ 
    if( P[i-1] < P[i] ){ a[i]++;}
    
  }
  
  sum[0] = a[0];//== 0
  
  for(int i = 1; i < N; i++){ 
    sum[i] += sum[i-1]+a[i];
  }
  // iから始まるものがascendingだったら、sum[i+K-1]-sum[i] は K-1に等しい。
  
  bool ascend = (sum[K-1] == K-1); 
  // N-K個の組み合わせの中に、一つでもascendingな並びがあるかを調べる
  
  int ans = !ascend;
  // もし最初の一つがascendingじゃなかったら、別途独立なものとして数える必要があるため
  
  set<int> se;
  // 連続する２つが独立しているかの判定には、一番小さいものが出て、一番大きいものが入ると確かめる必要がある
  
  for(int i = 0; i < K; i++){ 
    se.insert(P[i]);
  }
  
  for(int i = 0; i < N-K; i++){
    
    bool l = (*se.begin() == P[i]);
    
    se.erase(P[i]);
    
    se.insert(P[i+K]);
    
    bool r = (*se.rbegin() == P[i+K]);
    
    if( sum[i+K]-sum[i+1] == K-1 ){ ascend = true;}
    else{
      if( !(l&&r) ){ 
        ans++;
      }
      
    }
  }
    
    cout << ans+ascend << endl;
    
    return 0;
  
} 
             
    
              
              
    
  
      
      
      
    
    
    

Measured memory_bytes: 12032
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<map>
#define maxn 100005
using namespace std;
int n;
map<int,int> cnt;
int ans1=0,ans2=0;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int x;
		scanf("%d",&x);
		cnt[x]++;

		if(cnt[x]>=2)
		{
			if(x>ans1)
			{
				cnt[x]-=2;
				ans2=ans1;

				ans1=x;
			}
			if(cnt[x]>=2 && x>ans2)
			{
				cnt[x]-=2;
				ans2=x;
			}
		}
	}

//	if(ans1==1234567891 || ans2==1234567890)
//		return printf("0\n"),0;
	printf("%lld\n",1ll*ans1*ans2);
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  int N;
  cin >> N;
  ll K;
  cin >> K;
  vector<ll> v;
  rep(i,N){
    ll a;
    cin >> a;
    v.push_back(a);
  }

  vector<int> cnt(63, 0);
  rep(i,N){
    ll a = v[i];
    int ii = 0;
    while(a > 0){
      if(a&1) cnt[ii]++;
      ii++;
      a >>= 1;
    }
  }

  ll X = 0;
  for(int i=62; i>=0; i--){
    int one = cnt[i];
    int zero = N - cnt[i];

    if(one <= zero){
      if(X + (1LL<<i) <= K) X += (1LL<<i);
    }
  }

  ll ret = 0;
  rep(i,N){
    ret += X ^ v[i];
  }

  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 1400
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long LL;

LL comb(int a, int b, int c = -1) {
  LL ar[51] = {1};
  for(int i=1; i<=a; ++i) {
    for(int j=i; j>=0; --j) {
      ar[j+1] += ar[j];
    }
  }
  if(c == -1) {
    return ar[b];
  } else {
    LL ret = 0;
    for(int i=b; i<=c; ++i) {
      ret += ar[i];
    }
    return ret;
  }
}

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  vector<LL> v(N);
  REP(i, N) {
    cin >> v[i];
  }
  sort(v.begin(), v.end(), greater<LL>());
  
  cout << fixed << setprecision(9) << (double)accumulate(v.begin(), v.begin() + A, 0LL) / A << endl;
  
  int rmin = -1, rmax;
  REP(i, N) {
    if(v[i] == v[A-1]) {
      if(rmin < 0) {
        rmin = i;
      }
      rmax = i;
    }
  }
  if(v[0] == v[A-1]) {
    B = min(B, rmax + 1);
    //cerr << rmax + 1 << " C " << A << "-" << B << endl;
    LL ret = comb(rmax + 1, A, B);
    cout << ret << endl;
  } else {
    //cerr << rmax - rmin + 1 << " C " << A - rmin << endl;
    LL ret = comb(rmax - rmin + 1, A - rmin);
    cout << ret << endl;  
  }
}

Measured memory_bytes: 256
import java.util.*;

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

		while(true){
			int n = sc.nextInt();
			int m = sc.nextInt();
			if(n==0 && m==0)break;
			
			int[] out = new int[n];
			int count = 0;
			int sum = 0;
			int i = 0;
			while(true){
				count = 0;
				while(true){
					if(out[i]==0)count++;
					if(count==m)break;
					i++;
					if(i==n)i=0;
				}
				
				out[i] = 1;
				sum++;
				if(sum==n-1)break;
			}
			
			for(int j=0;j<n;j++){
				if(out[j]==0){
					System.out.println(j+1);
					break;
				}
			}
		}
	
	}	
}

Measured memory_bytes: 20160
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
bool odd(const int &n) { return n & 1; }
bool even(const int &n) { return ~n & 1; }
template<typename T = int> T in() { T x; cin >> x; return x; }
template<typename T = int> T in(T &&x) { T z(forward<T>(x)); cin >> z; return z; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { return is >> p.first >> p.second; }
template<typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : "\n"); return os; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : " "); return os; }
template<typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << ' ' << p.second; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
// clang-format on

main {
  while (true) {
    string s;
    cin >> s;
    if (s == ".") break;
    vector<int> v(3);
    function<int(int &)> dfs = [&](int &i) -> int {
      if (s[i] == '(') {
        i++;
        int e = dfs(i);
        if (s[i] == '+') {
          i++;
          cmax(e, dfs(i));
        }
        if (s[i] == '*') {
          i++;
          cmin(e, dfs(i));
        }
        i++; // ')'
        return e;
      }
      if (s[i] == '-') {
        i++;
        return 2 - dfs(i);
      }
      if (isdigit(s[i])) return s[i++] - '0';
      return v[s[i++] - 'P'];
    };
    int cnt = 0;
    for (v[0] = 0; v[0] < 3; v[0]++) {
      for (v[1] = 0; v[1] < 3; v[1]++) {
        for (v[2] = 0; v[2] < 3; v[2]++) {
          int i = 0;
          cnt += dfs(i) == 2;
        }
      }
    }
    cout << cnt << endl;
  }
}



Measured memory_bytes: 2984
#include<stdio.h>
int main(){
	int a[3];
	scanf("%d%d%d",&a[0],&a[1],&a[2]);
	int i,j;
	for(i=0;i<2;i++){
		for(j=i+1;j<3;j++){
			if(a[i]>a[j]){
				int t;
				t=a[j];
				a[j]=a[i];
				a[i]=t;
			}
		}
	}
	printf("%d %d %d\n",a[0],a[1],a[2]);
	return 0;
}



Measured memory_bytes: 1996
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
typedef long long ll;
const int N=2e5+10;
const int mod=1e9+7;
int p[N],inv[N];
// int ans[N];
int qmi(int a,int b)
{
    int ans=1;
    while(b){
        if(b&1)ans=((ll)ans*a)%mod;
        a=(ll)a*a%mod;
        b>>=1;
    }
    return ans;
}
int h[N],e[2*N],ne[2*N],idx;
void add(int a,int b)
{
    e[idx]=b,ne[idx]=h[a],h[a]=idx++;
}
int f[N];
int sz[N];
void dfs1(int u,int fa)
{
    sz[u]=1;
    for(int i=h[u];i!=-1;i=ne[i])
    {
        int j=e[i];
        if(j==fa)continue;
        dfs1(j,u);
        sz[u]+=sz[j];
    }
    f[u]=p[sz[u]-1];
    for(int i=h[u];i!=-1;i=ne[i])
    {
        int j=e[i];
        if(j==fa)continue;
        f[u]=(ll)f[u]*inv[sz[j]]%mod*f[j]%mod;
    }
}
int n;
int g[N],ans[N];
void dfs2(int u,int fa)
{
    ans[u]=(ll)f[u]*inv[sz[u]-1]%mod*p[n-1]%mod*inv[n-sz[u]]%mod*g[fa]%mod;
    for(int i=h[u];i!=-1;i=ne[i])
    {
        int j=e[i];
        if(j==fa)continue;
        g[u]=(ll)ans[u]*inv[n-1]%mod*p[n-sz[j]-1]%mod*qmi(f[j],mod-2)%mod*p[sz[j]]%mod;
        // g[u]=f[u]*inv[sz[u]-1]%mod*p[n-sz[j]-1]%mod*p[sz[j]]%mod*qmi(f[j],mod-2)%mod*g[fa]%mod*inv[n-sz[u]]%mod;
        dfs2(j,u);
    }
}
int main()
{
//    int n;
    cin>>n;
    p[0]=1,inv[0]=1;
    for(int i=1;i<=n;i++)p[i]=(ll)p[i-1]*i%mod;
    for(int i=1;i<=n;i++)inv[i]=(ll)inv[i-1]*qmi(i,mod-2)%mod;
    memset(h,-1,sizeof h);
    for(int i=1;i<n;i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        add(a,b);
        add(b,a);
    }
    dfs1(1,1);
    g[0]=1;
    dfs2(1,0);
    for(int i=1;i<=n;i++)printf("%d\n",ans[i]);
    return 0;
}

Measured memory_bytes: 10880
#include <stdio.h>

int main()
{
	int m, f, r;
	char result;

	while(1)
	{
		scanf("%d %d %d", &m, &f, &r);
		if((m == -1) && (f == -1) && (r == -1))
		{
			break;
		}

		if((m == -1) || (f == -1))
		{
			result = 'F';
		}
		else if(80 <= (m + f))
		{
			result = 'A';
		}
		else if(65 <= (m + f))
		{
			result = 'B';
		}
		else if(50 <= (m + f))
		{
			result = 'C';
		}
		else if(30 <= (m + f))
		{
			result = (50 <= r) ? 'C' : 'D';
		}
		else
		{
			result = 'F';
		}
		printf("%c\n", result);
	}
	return 0;
}


Measured memory_bytes: 2036
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, ll> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 100010;
const int MAXM = 35;
const int MAXK = 510;
const int MAXQ = 200010;

struct Edge {
    int u, v, c;
    Edge(int u = 0, int v = 0, int c = 0) : u(u), v(v), c(c) {}
};

bool cmp3(Edge a, Edge b) {
    return a.c < b.c;
}

vector<Edge> edges;

struct Point {
    int x, y, cs;
    Point(int x = 0, int y = 0, int cs = 0) : x(x), y(y), cs(cs) {}
} a[MAXN];

bool cmp(Point a, Point b) {
    return a.x < b.x;
}

bool cmp2(Point a, Point b) {
    return a.y < b.y;
}

int n, lab[MAXN];

int getRoot(int u) {
    while (lab[u] > 0) u = lab[u];
    return u;
}

void unionPair(int u, int v) {
    int x = lab[u] + lab[v];
    if (lab[u] < lab[v]) {
        lab[v] = u;
        lab[u] = x;
    }
    else {
        lab[u] = v;
        lab[v] = x;
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n;
    FOR(i,1,n) {
        cin >> a[i].x >> a[i].y;
        a[i].cs = i;
    }
    sort(a+1, a+n+1, cmp);
    FOR(i,1,n-1) edges.emplace_back(Edge(a[i].cs, a[i+1].cs, a[i+1].x - a[i].x));

    sort(a+1, a+n+1, cmp2);
    FOR(i,1,n-1) edges.emplace_back(Edge(a[i].cs, a[i+1].cs, a[i+1].y - a[i].y));

    sort(ALL(edges), cmp3);

    FOR(i,1,n) lab[i] = -1;
    ll res = 0;

    // FOR(i,0,SZ(edges)-1) {
    //     cout << edges[i].u << ' ' << edges[i].v << ' ' << edges[i].c << endl;
    // }

    FOR(i,0,SZ(edges)-1) {
        int u = getRoot(edges[i].u);
        int v = getRoot(edges[i].v);
        if (u != v) {
            unionPair(u, v);
            res += edges[i].c;
        }
    }

    cout << res;
    return 0;
}

Measured memory_bytes: 6132
main(N){
    int a=1000000,b=-a,t;
    long long c=0;
    for(scanf("%d",&N);N--;c+=t){
        scanf("%d",&t);
        if(a>t)a=t;
        if(b<t)b=t;
    }
    printf("%d %d %lld\n",a,b,c);
}

Measured memory_bytes: 1824
n, m = map(int, input().split(' '))
cnt = 0
circles = [x for x in range(n)]

def find(x):
  if circles[x] == x:
    return x
  root = find(circles[x])
  circles[x] = root
  return root

for _ in range(m):
  a, b = map(int, input().split(' '))
  if find(a - 1) != find(b - 1):
    circles[find(a - 1)] = find(b - 1)
    
print(sum(1 for i, j in enumerate(circles) if i == j) - 1)

Measured memory_bytes: 13120
#include <iostream>
#include<string.h> 
#include <vector>
#include <cmath>
#include <string>
#include <stack>
#include <algorithm>
using namespace std;
int main (){
	int a, b, c, ans;
	cin >> a >> b >> c;
	ans = a+b+c;
	if (ans>=22){
		cout << "bust";
	}
	else {
		cout << "win";
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int f[7] = {2,3,5,7,11,13,17};
const int em[7] = {8,5,3,2,2,2,2};
int c[7];
int q[399],a[399];
int n,res;
void dfs(int x){
	if(x == 7){
		int cur = 0;
		map<int,int> Map;
		for(int i=1; i<=n; i++){
			bool ff = true;
			int W = q[i];
			for(int j=0; j<7; j++){
				int f2 = 0;
				while(W%f[j] == 0)f2 ++, W/=f[j];
				if(f2 > c[j]){
					ff = false;
					break;
				}
			}
			if(!ff)continue;
			if(W == 1){
				cur += a[i];
				continue;
			}
			Map[W] += a[i];
		}
		for(auto p : Map){
			cur += max(p.second, 0);
		}
		res = max(cur, res);
		return;
	}
	for(int j=0; j<=em[x]; j++){
		c[x] = j;
		dfs(x+1);
	}
}
int main(){
	scanf("%d",&n);
	for(int i=1; i<=n; i++)
		scanf("%d%d",&q[i],&a[i]);
	dfs(0);
	printf("%d\n",res);
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr

using namespace std;

int main(){

    int n,a;
    cin >> n;
    cin >> a;

    n = n % 500;

    cout << (a >= n ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int w,h,x,y,r;
        w=sc.nextInt();
        h=sc.nextInt();
        x=sc.nextInt();
        y=sc.nextInt();
        r=sc.nextInt();
        if((x-r)<0||(x+r)>w||(y-r)<0||(y+r)>h)
        	System.out.println("No");
        if((x-r)>=0&&(x+r)<=w&&(y-r)>=0&&(y+r)<=h)
        	System.out.println("Yes");
        sc.close();
        }
}


Measured memory_bytes: 26396
class SegmentTree:
    def __init__(self, a: list, e: 'default' = 0, f: 'function' = max):
        size = len(a)
        n = 1 << (size - 1).bit_length()
        seg = [e] * (n * 2 - 1)
        for i, a_ in enumerate(a, n - 1):
            seg[i] = a_
        for i in range(n - 2, -1, -1):
            seg[i] = f(seg[i * 2 + 1], seg[i * 2 + 2])
        self.size = size
        self.n = n
        self.seg = seg
        self.a = a
        self.e = e
        self.f = f

    def update(self, k, x):
        n = self.n
        seg = self.seg
        f = self.f

        k += n - 1
        seg[k] = x
        while k > 0:
            k = (k - 1) // 2
            seg[k] = f(seg[k * 2 + 1], seg[k * 2 + 2])

    def query(self, a, b, k=0, l=0, r=-1):
        if r < 0:
            r = self.n
        if r <= a or b <= l:
            return self.e
        if a <= l and r <= b:
            return self.seg[k]
        m = (l + r) // 2
        vl = self.query(a, b, k * 2 + 1, l, m)
        vr = self.query(a, b, k * 2 + 2, m, r)
        return self.f(vl, vr)


n = int(input())
h = tuple(map(int, input().split()))
a = tuple(map(int, input().split()))

dp = [0] * (n + 1)
# dp[j] := 末尾jの単調増加列の美しさの総和の最大値

seg = SegmentTree(a=dp, e=0, f=max)

for h_, a_ in zip(h, a):
    # i本目を取って末尾にするとき
    max_ = seg.query(0, h_) + a_
    seg.update(h_, max_)
print(seg.query(0, n + 1))

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

int main()
{
    string s;
    cin >> s;
    vector<string> str = {"dream", "dreamer", "erase", "eraser"};
    reverse(all(s));
    rep(i, 4)
    {
        reverse(all(str[i]));
    }

    string ans = "NO";
    for (int i = 0; i < s.size();)
    {
        bool ok = false;
        rep(j, 4)
        {
            if (s.substr(i, str[j].size()) == str[j])
            {
                i += str[j].size();
                ok = true;
            }
        }
        if (!ok)
        {
            break;
        }
        if (i == s.size())
        {
            ans = "YES";
        }
    }

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


Measured memory_bytes: 3704
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

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

        int[] map = new int[100 + 1];

        for (int i = 0; i < map.length; i++) map[i] = 0;

        while (sc.hasNext()) map[Integer.parseInt(sc.next())]++;

        List<Integer> maxIndex = new ArrayList<>();
        int max = Integer.MIN_VALUE;

        for (int i = 0; i < map.length; i++) {
            if (map[i] >= max) {
                max = map[i];
            }
        }

        for (int i = 0; i < map.length; i++) {
            if (map[i] == max) maxIndex.add(i);
        }

        maxIndex.forEach(System.out::println);
    }
}

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

using namespace std;

#define N 305
#define int long long

int dp[N][N][N];
string s;

int find(int l, int r, int x)
{
    if(l>r || x<0)
        return 0;

    if(dp[l][r][x]!=-1)
        return dp[l][r][x];

    if(l==r)
    {
        return dp[l][r][x]=1;
    }

    int x1 = find(l+1,r,x);
    x1 = max(x1, find(l,r-1,x));
    
    if(s[l]==s[r])
    {
        x1 = max(x1, 2+find(l+1,r-1,x));
    }
    else if(x>0){
        x1 = max(x1, 2+find(l+1,r-1,x-1));
    }

    //cout<<l<<" "<<r<<" "<<x<<" "<<x1<<endl;
    return dp[l][r][x]=x1;

}

int32_t main()
{
    for(int i=0;i<N;i++)
    {
        for(int j=0;j<N;j++)
        {
            for(int k=0;k<N;k++)
            {
                dp[i][j][k] = -1;
            }
        }
    }

    cin>>s;
    int x;
    cin>>x;
    int n = s.length();
    cout<<find(0,n-1,x)<<endl;

    return 0;
}


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


int main(void){


int test [10000];


    for(int i = 1; i <= 10000; i++){

       cin >> test[i];
       
       if(test[i] == 0){
           break;
       }
       cout << "Case" << " " << i  <<": " << test[i] << std::endl;
    }
}


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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define ture ture
#define flase false
#define falg flag

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;//llの最大9*10^18
const int INF = pow(2, 30) - 1;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

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

    ll A,B,H,M;
    string S;
    cin >> A>>B>>H>>M;

    double A_kakudo = (H +M / 60.0) * 2.0 * M_PI / 12.0;
    double B_kakudo = M * M_PI / 30.0;

    //cout << A_kakudo << " " << B_kakudo << endl;

    double kakudo = min(abs(A_kakudo - B_kakudo), 2.0* M_PI - abs(A_kakudo - B_kakudo));

    //cout << cos(kakudo) << endl;

    double c = sqrt(A * A + B * B - 2.0 * A * B * cos(kakudo));

    if(kakudo<0.0000001){
        cout << setprecision(12) << abs(A - B) << endl;
    }
    else if(cos(kakudo)>0.99999999){
        cout << setprecision(12) << abs(A + B) << endl;
    }
    else{
        cout << setprecision(12) << c << endl;
    }
    
}


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

#ifdef LOCAL
#define debug(var) cerr << #var << " = " << var;
#else
#define debug(var)
#endif

void init() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

void solve() {
	long long n, m; cin >> n >> m;
	if (2*n >= m) {
		cout << min(n, m/2);
		return;
	}
	cout << (m/2-n)/2+n;
}

int main() {
	init();
	int t = 1; //scanf("%d", &t);
	while (t--) {
		solve();
	}
	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;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, M; cin >> N >> M;
    int C = 100*N + 1800*M;
    cout << C*(1 << M) << endl;
    return 0;
}

Measured memory_bytes: 256
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)



N = int(input())
ans = 0

for i in range(1, N+1):
    for j in range(i, N+1):
        for k in range(j, N+1):
            n = len(set([i, j, k]))
            if n == 3:
                ans += gcd(i, j, k) * 6
            elif n == 2:
                ans += gcd(i, j, k) * 3
            else:
                ans += gcd(i, j, k)
print(ans)

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

using namespace std;

typedef long long LL;

#define mod 1000000007
#define INF 1145141919
#define INF_LL 1145141919810364

#define MAX_N 1005

double Xs, Ys, Xg, Yg;
int N;
double X[MAX_N], Y[MAX_N], R[MAX_N];

void input()
{
  cin >> Xs >> Ys >> Xg >> Yg;
  cin >> N;
  for (size_t i = 0; i < N; i++) {
    cin >> X[i] >> Y[i] >> R[i];
  }
}

double dist[MAX_N];
double solve()
{
  X[N] = Xs; Y[N] = Ys; R[N] = 0.0;
  X[N+1] = Xg; Y[N+1] = Yg; R[N+1] = 0.0;
  fill(dist, dist+MAX_N, INF_LL);
  dist[N] = 0.0;
  priority_queue<pair<double, int>, vector<pair<double, int>>, greater<pair<double, int>>> que;
  que.push(make_pair(0.0, N));
  while(que.size()){
    auto p = que.top();
    que.pop();
    if(dist[p.second] < p.first){
      continue;
    }
    for (size_t i = 0; i < N+2; i++) {
      if(i == p.second){
        continue;
      }
      double nextCost = dist[p.second] + max(0.0, sqrt(pow(X[i] - X[p.second], 2) + pow(Y[i] - Y[p.second], 2)) - R[i] - R[p.second]);
      if(dist[i] > nextCost){
        dist[i] = nextCost;
        que.push(make_pair(nextCost, i));
      }
    }
  }
  return dist[N+1];
}

int main()
{
  input();

  printf("%.10f\n", solve());

  return 0;
}


Measured memory_bytes: 4464
#include<bits/stdc++.h>
  using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define endl "\n"
  #define ll long long
  #define int long long 
  #define double long double
  #define max(a,b) (a>b?a:b)
  #define min(a,b) (a<b?a:b)
  #define mkp make_pair
  #define pb push_back
  #define inf INT_MAX

  int32_t main()
  { 
  
  
    IOS
    int n;
    cin>>n;
    switch(n)
    {
      case 22:
       cout<<"Christmas Eve Eve Eve";
       break;
       case 23:
       cout<<"Christmas Eve Eve";
       break;
       case 24:
       cout<<"Christmas Eve";
       break;
       case 25:
       cout<<"Christmas";
       break;

    }
    return 0;
   
}

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

int main(int argc, char const *argv[])
{
    int n; cin >> n;
    vector<char> s(n,'0');
    vector<int> left_black(n,0);
    vector<int> right_white(n,0);
    
    cin >> s[0];
    left_black[0] += (s[0]=='#')? 1: 0;
    for(int i=1;i<n;++i){
        cin >> s[i];
        left_black[i]= left_black[i-1];
        if(s[i]=='#') ++left_black[i];
    }
    right_white[n-1] = 0;
    for(int i=n-2;i>=0;--i) {
        right_white[i] = right_white[i+1];
        if(s[i+1]=='.') ++right_white[i];
    }
    

    int best = min(left_black[n-1], right_white[0]);
    //cout << "all white: " << left_black[n-1] << endl;
    //cout << "all black: " << right_white[0] << endl;
    for(int i=1;i<n-1;++i) {
        best = min(best, left_black[i] + right_white[i]);
        //cout << i << " " << left_black[i] + right_white[i] << endl;
    }
    cout << best << endl;

    return 0;
}

Measured memory_bytes: 2048
import math
 
K = int(input())
 
lis = tuple([i for i in range(1,K+1)])
a = 0
 
for i in lis:
    for j in lis:
        i_j= math.gcd(i,j)
        for k in lis:
            i_j_k = math.gcd(i_j,k)
            a += i_j_k
print(a)

Measured memory_bytes: 9172
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long 
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back 
#define mp make_pair
#define inf 2000000009
#define mod 1000000007
using namespace std;

int main()
{ 
    fast;
  
  ll n;
  cin>>n;

    
    ll a[n];
    for(ll i=0;i<n;i++)
      cin>>a[i];

    for(ll i=0;i<n;i++)
      a[i]*=-1;

    for(ll i=1;i<n;i++)
    {
      if(a[i]>a[i-1])
        a[i]--;
    }
    bool f=1;

    for(ll i=1;i<n;i++)
      if(a[i]>a[i-1])
      {
        f=0;
        break;
      }


      if(f)
        cout<<"Yes"<<endl;
      else cout<<"No"<<endl;
  }

Measured memory_bytes: 1024