akhauriyash/Code-Regression huggingface dataset:
use proconio::input;

fn main() {
    input! {
        a: i32,
        b: i32,
        c: i32,
        x: i32,
    };
    let mut cnt = 0;
    for i in 0..a+1 {
        for j in 0..b+1 {
            for k in 0..c+1 {
                if x == 500 * i + 100 * j + 50 * k {
                    cnt += 1;
                }
            }
        }
    }
    println!("{}", cnt);
}


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

int main(){
  int n,a;
  bool flag = true;
  cin >> n;
  for(int i=0; i<n; i++){
    cin >> a;
    if(a%2 == 0 && a%6>0 && a%10>0){
      flag = false;
      break;
    }
  }
  if (flag) {
    cout << "APPROVED" << endl;
  } else {
    cout << "DENIED"   << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.lang.Math;
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		double a = Double.parseDouble(scan.next());
		double b = Double.parseDouble(scan.next());
		double c = Double.parseDouble(scan.next());
		double d = Double.parseDouble(scan.next());
		System.out.println(String.format("%6f",Math.sqrt((c-a)*(c-a)+(d-b)*(d-b))));
	}

}

Measured memory_bytes: 17160
<?php
fscanf(STDIN, "%d", $N);
fscanf(STDIN, "%s", $S);
$a = str_split($S);
$ans = 0;
$last = array_pad(array(), 10, -1);
$sum[$N] = $last;
for ($i = $N; $i > 0; $i--) {
    $last[$a[$i - 1]] = $i;
    $sum[$i - 1] = $last;
}
for($i = 0; $i < 1000; $i++) {
    $x1 = intdiv($i, 100);
    $y1 = $sum[0][$x1];
    if ($y1 === -1) continue;
    $x2 = intdiv($i, 10) % 10;
    $y2 = $sum[$y1][$x2];
    if ($y2 === -1) continue;
    $x3 = $i % 10;
    $y3 = $sum[$y2][$x3];
    if ($y3 === -1) continue;
    $ans++;
}
printf("%d",$ans);


Measured memory_bytes: 27128
s = list(input())
Y = 0
M = 0
intS = []
for i in range(len(s)):
    intS.append(int(s[i]))



if 0 < 10*intS[0]+intS[1] <= 12:
    M = 1

if 0 < 10*intS[2]+intS[3] <= 12:
    Y = 1

if M == 1 and Y == 0:
    print("MMYY")

elif M == 0 and Y == 1:
    print("YYMM")

elif M == 1 and Y == 1:
    print("AMBIGUOUS")

else:
    print("NA")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std ;
#define endl "\n"
#define int long long int 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int32_t main()
{
    /*#ifndef ONLINE_JUDGE 
    freopen("input.txt","r",stdin) ;
    freopen("output.txt","w",stdout) ;
    #endif */
    string s; 
    cin >>s ;
    int len = s.size();
    unordered_map<char,bool> check ;
    check['A'] = true ;
    check['C'] = true ;check['G'] = true ;check['T'] = true ;
    int ans = 0 ;
    for(int i = 0 ; i < len ; i++ )
    {
        int j = i ;
        int tempans = 0 ;
        while(j < len && check[s[j]])
        {
            j++;
        }
        ans = max(ans,j-i) ;
        i = j ;
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
using namespace std;
typedef long long LL;
const int inf = 1 << 30;
const LL INF = 1LL << 60;
const int MaxN = 2e5;
//const double PI = 3.1415926535897932384626;
const double PI = acos(-1);

LL sx, sy, tx, ty;
int n, tot;
double res;
struct point
{
	LL x, y;
}tmp[MaxN + 5];

bool cmpx(point a, point b) {
	if(a.x == b.x) return a.y < b.y;
	else return a.x < b.x;
}

int len;
LL a[MaxN + 5], d[MaxN + 5];

int bin_search(LL x) {
	int l = 0, r = len;
	int mid = 0, ans = 0;
	while(l <= r) {
		mid = (l + r) >> 1;
		if(d[mid] >= x) ans = mid, r = mid - 1;
		else l = mid + 1;
	}
	return ans;
}

void get_LIS(bool c)
{
	len = 0;
	d[len] = -INF;
	if(c == 1) {
		for(int i = 1; i <= tot; i++) 
			a[i] = tmp[i].y;
	}
	else {
		for(int i = 1; i <= tot; i++)
			a[i] = tmp[tot - i + 1].y;
	}
	for(int i = 1; i <= tot; i++) {
		if(a[i] > d[len]) d[++len] = a[i];
		else {
			int pos = bin_search(a[i]);
			d[pos] = a[i];
		}
	}
}

int main()
{
	tot = 0;
	res = 0.0;
	scanf("%lld %lld %lld %lld", &sx, &sy, &tx, &ty);
	if(sx > tx) {
		swap(sx, tx); swap(sy, ty);
	}
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) {
		LL x, y;
		scanf("%lld %lld", &x, &y);
		if((min(sx, tx) <= x && x <= max(sx, tx)) && (min(sy, ty) <= y && y <= max(sy, ty)))
			tmp[++tot].x = x, tmp[tot].y = y;
	}
	sort(tmp + 1, tmp + tot + 1, cmpx);
	if(sy > ty) {
		get_LIS(0);
	}
	else if(sy <= ty) {
		get_LIS(1);
	}
	int num = min(abs(tx - sx), abs(ty - sy)) + 1;
	if(len == num) {
		res = (100.0 * (abs(tx - sx) + abs(ty - sy)) - 20.0 * (LL)len) + (LL)(len - 1) * 5 * PI + 10 * PI;
	}
	else {
		res = (100.0 * (abs(tx - sx) + abs(ty - sy)) - 20.0 * (LL)len) + (LL)len * 5 * PI;
	}
	printf("%.15lf\n", res);
	return 0;
}

Measured memory_bytes: 6400
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 500
#define MAXV 1000000000
using namespace std;
int M[MAXN+5][MAXN+5];
int main()
{
	int H,W,h,w;
	scanf("%d %d %d %d",&H,&W,&h,&w);
	if(H%h==0&&W%w==0)
	{
		printf("No\n");
		return 0;
	}
	int k=(MAXV-1)/(w*h-1);
	for(int i=1;i<=H;i++)
		for(int j=1;j<=W;j++)
			if(i%h==0&&j%w==0)
				M[i][j]=-k*(h*w-1)-1;
			else
				M[i][j]=k;
	printf("Yes\n");
	for(int i=1;i<=H;i++)
	{
		for(int j=1;j<=W;j++)
			if(j==1)
				printf("%d",M[i][j]);
			else
				printf(" %d",M[i][j]);
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define rrep(i,n) for(int (i)=1;i<=(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define MOD 1000000007
#define INF 1e18
#define int long long
#define endl "\n"
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};

int n, m, k;
int a[200020], b[200020];

signed main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
	
	cin >> n >> m >> k;
	rrep(i, n) cin >> a[i], a[i] = a[i-1] + a[i];
	rrep(i, m) cin >> b[i], b[i] = b[i-1] + b[i];

	int ans = 0;
	rep(i, n+1) {
		if(a[i] <= k) {
			int cur = upper_bound(b+1, b+m+1, k-a[i]) - b - 1 + i;
			chmax(ans, cur);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6748
N = int(input())
a = [[int(i) for i in input().split()] for j in range(N)]

total = 0
a = sorted(a,key=lambda x:(x[1],x[0]))

for i in range(N):
    total += a[i][0]
    if total > a[i][1]:
        print("No")
        exit()

print("Yes")   

Measured memory_bytes: 55388
#include <bits/stdc++.h>
#include <algorithm>
#include <string>
#include <math.h>
using ll = long long;
using namespace std;
ll ans;
#define rep(i,n) for(int i=0;i<n;i++)
string S;
int saiki(ll koremade,int digit,ll tyokuzen);
int main(){
  	ans=0;
  	cin>>S;
  	saiki(0,1,S[0]-'0');
  	
  	cout<<ans<<endl;
  	return 0;
  
}
int saiki(ll koremade,int i,ll tyokuzen){
	if(i==S.size()){
    	ans=ans+koremade+tyokuzen;
      	//cout<<koremade<<" "<<i<<endl;
      	
      	return 0;
    }else{
      	//cout<<koremade<<" "<<i<<" "<<tyokuzen<<endl;
      	saiki(koremade+tyokuzen,i+1,S[i]-'0');	
      	saiki(koremade,i+1,tyokuzen*10+S[i]-'0');
    }
}

Measured memory_bytes: 256
n = int(input())

l = [1] + [pow(6,i) for i in range(1,15)] + [pow(9,i) for i in range(1,10)]
l.sort()
dp = [10**10] * (n+1)
dp[0] = 0
for li in l:
  for i in range(n - li + 1):
    dp[i + li] = min(dp[i + li], dp[i] + 1)
print(dp[n])

Measured memory_bytes: 40048
#include <iostream>
#include <utility>
using namespace std;
typedef pair<int, int> P;

int main()
{
    while(true){
        int h;
        cin >> h;
        if(h == 0) break;
        int p[22][5];
        int ans = 0;
        for(int i = 0; i < h; i++){
            for(int j = 0; j < 5; j++){
                cin >> p[h - 1 - i][j];
                ans += p[h - 1 - i][j];
            }
        }
        for(int i = h; i < 20; i++){
            for(int j = 0; j < 5; j++) p[i][j] = 0;
        }
        while(true){
            bool del[12][5];
            bool end = true;
            for(int i = 0; i < h; i++){
                for(int j = 0; j < 5; j++) del[i][j] = false;
            }
            for(int i = 0; i < h; i++){
                for(int j = 0; j < 3; j++){
                    if(p[i][j] != 0 && p[i][j] == p[i][j + 1] && p[i][j] == p[i][j + 2]){
                        end = false;
                        for(int k = j; k < j + 3; k++) del[i][k] = true;
                        int a = p[i][2];
                        if(a == p[i][3]){
                            del[i][3] = true;
                            if(a == p[i][4]) del[i][4] = true;
                        }
                    }
                }
            }
            if(end) break;
            for(int j = 0; j < 5; j++){
                int l = 0;
                for(int i = 0; i < h; i++){
                    while(del[l][j]) l++;
                    p[i][j] = p[l][j];
                    l++;
                }
                for(int i = h; i < 20; i++){
                    p[i][j] = 0;
                }
            }
        }
        for(int i = 0; i < h; i++){
            for(int j = 0; j < 5; j++) ans -= p[i][j];
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< long long > vll;
typedef pair< int,int > ii;
typedef long long ll;
#define F first
#define S second
#define mem(a) memset(a,0,sizeof(a))
#define sz(a) int(a.size())
#define pb push_back
#define all(c) c.begin(),c.end()
#define tr(container,it) for(auto it=container.begin();it!=container.end();it++)
#define present(container, element) (container.find(element) != container.end())
#define vpresent(container, element) (find(all(container),element) != container.end()) //for vectors

int main()
{
    /*freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    freopen("error.txt","w",stderr);*/
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
  cin>>n;
 int x;double sum=0.0;
  for(int i=0;i<n;i++)
  {
    cin>>x;
    sum+=(1.0/x);
  }
  cout<<fixed<<setprecision(12)<<(1.0/sum);
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;


void energy_drink_collector()
{
  int n, m;
  cin >> n >> m;
  vector<pair<int,int>> ab(n);
  for (int i = 0; i < n; ++i) cin >> ab[i].first >> ab[i].second;

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

  long long int total_fee = 0;
  for (int i = 0; i < n && m > 0; ++i)
  {
    total_fee += (long long int)ab[i].first * (long long int)min(m, ab[i].second);
    m -= min(m, ab[i].second);
  }

  cout << total_fee << "\n";
}


void get_AC()
{
  int n, q;
  string S;
  cin >> n >> q >> S;

  vector<int> cnt(n + 1);
  for (int i = 0; i < n; ++i)
  {
    if (i + 1 < n && S[i] == 'A' && S[i + 1] == 'C') cnt[i + 1] = cnt[i] + 1;
    else cnt[i + 1] = cnt[i];
  }

  for (int i = 0; i < q; ++i)
  {
    int l, r;
    cin >> l >> r;
    cout << cnt[r - 1] - cnt[l - 1] << "\n";
  }
}


void five_transportations()
{
  long long int n;
  cin >> n;
  long long int v_min = 1000000000000000, tmp;
  for (int i = 0; i < 5; ++i) 
  {
    cin >> tmp;
    v_min = min(v_min, tmp);
  }

  cout << (n - 1)/ v_min + 5;
}


void coloring_colorfully()
{
  string s;
  cin >> s;

  int cnt_01 = 0, cnt_10 = 0;
  for (int i = 0; i < s.size(); ++i)
  {
    if (i % 2 == 0)
    {
      if (s[i] != '0') ++cnt_01;
      else ++cnt_10;
    }
    else
    {
      if (s[i] != '1') ++cnt_01;
      else ++cnt_10;
    }
  }

  cout << min(cnt_01, cnt_10) << "\n";
}


//skip
void gcd_on_blackboard()
{

}


void dice_and_coin()
{
  int n, k;
  cin >> n >> k;

  double res = 0;
  for (int i = 1; i <= n; ++i)
  {
    double tmp = 1.0 / n;
    int point_now = i;
    while (point_now < k)
    {
      point_now *= 2;
      tmp /= 2;
    }
    res += tmp;
  }
  cout << setprecision(10) <<res << "\n";
}

//skip
void prison()
{

}

//skip
void switches()
{

}


void typical_stairs()
{
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  for (int i = 0; i < m; ++i) cin >> a[i];

  vector<bool> broken(n);
  for (int i = 0; i < m; ++i) broken[a[i]] = true;

  vector<int> f(n + 1);
  f[0] = 1;
  if (!broken[1]) f[1] = 1;
  for (int i = 0; i < n + 1; ++i)
  {
    if (i == 0 || i == 1) continue;
    if (!broken[i]) f[i] = f[i - 1] + f[i - 2];
    f[i] %= 1000000007;
  }
  cout << f[n] % 1000000007 << "\n";
}


void rectangle_cutting()
{
  int w, h, x, y;
  cin >> w >> h >> x >> y;

  int is_center = 0;
  if (w == 2 * x && h == 2 * y) is_center = 1;

  cout << (double)w * h / 2 << " " << is_center << "\n";
}


int main()
{
  //energy_drink_collector();
  //get_AC();
  //five_transportations();
  //coloring_colorfully();
  //gcd_on_blackboard();
  //dice_and_coin();
  //prison();
  //switches();
  //typical_stairs();
  rectangle_cutting();
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <climits>

using namespace std;

#define int long long
constexpr int INF = LLONG_MAX / 3;

struct edge {
  int cost, to;
};

using Graph = vector<vector<edge>>;

int bellman_ford(Graph const& gr) {
  int V = gr.size();
  int E = 0;
  for (auto& es : gr)
    E += es.size();
  vector<int> dists(V, INF);
  dists[0] = 0;
  int count = 0;
  bool updated = true;
  for (int i = 0; i < 10000; i++) {
    updated = false;
    for (int j = 0; j < V; j++) {
      for (auto&& e : gr[j]) {
        int nd = dists[j] + e.cost;
        if (dists[e.to] <= nd) continue;
        if (e.to == V - 1) count++;
        updated = true;
        dists[e.to] = nd;
      }
    }
    if (!updated) break;
  }
  if (count > E) return INF;
  return dists[V - 1];
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  Graph gr(n);
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--; b--;
    gr[a].push_back({-c, b});
  }
  auto dist = bellman_ford(gr);
  if (dist == INF)
    cout << "inf" << endl;
  else
    cout << (-dist) << endl;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define inRange(x,a,b) ((a <= x && x <= b) || (a <= x+360 && x+360 <= b))

struct holiday{
    int from, to, s;
};

int diff(int from, int to){
    if(from > to)   to += 360;
    return to-from;
}

int main(){
    int n;
    cin >> n;
    vector<holiday> v;
    int m, d, V, s;
    for(int i = 0; i < n; i++){
        cin >> m >> d >> V >> s;
        v.push_back(holiday({30*(m-1)+d, 30*(m-1)+d+V-1, s}));
    }
    int ans = 1<<30;
    for(int i = 1; i <= 360; i++){
        int tmp = 0;
        for(int j = 0; j < n; j++){
            if(inRange(i,v[j].from,v[j].to)){
                tmp = max(tmp, v[j].s);
            }else{
                tmp = max(tmp, max(0, v[j].s-min(diff(v[j].to, i), diff(i, v[j].from))));
            }
        }
        ans = min(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3180
#include <iostream>

using namespace std;

int main(){

  int n, a, b;

  while(cin >> n >> a >> b){

    if((n*a) < b) cout << n*a <<endl;

    else if((n*a) > b) cout << b <<endl;

    else cout << b <<endl;

  }
  return 0;
}


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

vector<pair<int, string>> calc(int l, int r, vector<int> const& a) {
    if(l + 1 == r) {
        return {make_pair(a[l], to_string(a[l]))};
    } else {
        vector<pair<int, string>> res;
        for(int m = l + 1; m < r; ++m) {
            auto b = calc(l, m, a), c = calc(m, r, a);
            for(auto& x : b) for(auto& y : c) {
                res.emplace_back(x.first + y.first, "(" + x.second + "+" + y.second + ")");
                res.emplace_back(x.first - y.first, "(" + x.second + "-" + y.second + ")");
                res.emplace_back(x.first * y.first, "(" + x.second + "*" + y.second + ")");
            }
        }
        return res;
    }
}

string solve(vector<int> a) {
    sort(begin(a), end(a));
    do {
        auto res = calc(0, a.size(), a);
        for(auto& r : res) {
            if(r.first == 10) return r.second;
        }
    } while(next_permutation(begin(a), end(a)));
    return "0";
}

int main() {
    int a, b, c, d;
    while(cin >> a >> b >> c >> d, a) {
        vector<int> v = {a, b, c, d};
        cout << solve(v) << endl;
    }
}


Measured memory_bytes: 3236
#include <bits/stdc++.h>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
int main(){
    int n;
    cin >> n;
    vector<int> p(n);
    vector<int> q(n);
    rep(i,n) cin >> p[i];
    rep(i,n) cin >> q[i];
    vector<int> a(n);
    rep(i,n) a[i]=i+1;
    map<vector<int>,int> mp;
    do{
        mp[a]=mp.size();
    }while(next_permutation(a.begin(),a.end()));
    int ans=abs(mp[p]-mp[q]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5248
#include <iostream>
#include <math.h>
#include <string>

#define MIN(x, y) (x < y ? x : y)
#define MAX(x, y) (x > y ? x : y)

using namespace std;

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

	for(int i = 0; i < s.length(); i+=2){
		cout << s[i];
	}
	cout << endl;
}


Measured memory_bytes: 512
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <complex>

using namespace std;
using pii = pair<int, int>;
using ll = long long;

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

	int n;
	cin >> n;
	vector<pii> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i].first;
		a[i].second = i + 1;
	}
	sort(a.begin(), a.end());
	for (int i = 0; i < n; i++) cout << a[i].second << " ";
	return 0;
}


Measured memory_bytes: 1664
#include<iostream>
#include<math.h>
using namespace std;

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

    int i, max=-1;
    int tmp;
    for(i=0;i<s.length()-2;i++){
        tmp = stoi(s.substr(i,3));
        if(abs(max-753) > abs(tmp-753)){
            max = tmp;
        }
    }

    cout << abs(max - 753);

    return 0;
}

Measured memory_bytes: 256
open Hashtbl
let n = Scanf.scanf " %d" @@ (+) 0
let ws = Array.init n @@ fun _ -> Scanf.scanf " %s" @@ fun s -> s
let h = create n
let rec check i c =
  if i >= n then true
  else
    let w = ws.(i) in
    if w.[0] <> c then false
    else if mem h w then false
    else (add h w 1; check (i + 1) w.[String.length w - 1])
let _ = print_endline @@ if check 0 ws.(0).[0] then "Yes" else "No"

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

typedef long long LL;
const int N = 1e5 + 10;
int n, Q, top; LL q[N], w[N], w0[N];

template <class T> inline void in(T &x) {
	x = 0; int f = 1; char ch = getchar();
	for (; ch<'0' || ch>'9';) {if (ch=='-') f=-1; ch = getchar();}
	for (; ch>='0' && ch<='9';) x = x*10 + ch-'0', ch = getchar();
	x *= f;
}

int main() {
	LL l, x; in(n), in(Q), q[0] = n;
	for (int i = 1; i <= Q; ++i) {
		for (in(x); top >= 0 && q[top] >= x;) --top;
		q[++top] = x;
	}
	w[top] = 1;
	for (int j, i = top; ~i; --i) {
		for (l = q[j = i]; l > q[0];) {
			j = lower_bound(q, q + j, l) - q - 1;
			w[j] += l / q[j] * w[i], l %= q[j];
		}
		w0[l] += w[i];
	}
	for (int i = q[0]; i; --i) w0[i] += w0[i + 1];
	for (int i = 1; i <= n; ++i) printf("%lld\n", w0[i]);
	return 0;
}

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

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 DEBUG

int main()
{
	ios::sync_with_stdio(false); cin.tie(0);
	int a, b;
	cin >> a >> b;

	string sa = to_string(a);
	string sb = to_string(b);
	string s = sa + sb;
	int num = stoi(s);

	rep(i, 100100)
	{
		if(i * i == num)
		{
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

#define Pr(f,...) printf(f,##__VA_ARGS__),fflush(stdout)

typedef long long ll;

const int N=2e5+50,P=2333;

int mul(int a,int b){ return 1ll*a*b%P; }
int add(int a,int b){ a+=b; return a>=P?a-P:a; }
int sub(int a,int b){ a-=b; return a<0?a+P:a; }

string s; 
ll n,ans=1,c[26];

int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
	freopen("dat.in","r",stdin);
	freopen("my.out","w",stdout);
#endif
	cin>>s;
	n=s.length();
	ans+=n*(n-1)/2;
	for (auto i:s)++c[i-'a'];
	lop(i,0,26)ans-=c[i]*(c[i]-1)/2ll;
	printf("%lld\n",ans);
	return 0; 
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	string s, t;
	cin >> s >> t;

	vector<vector<int>> si(26);
	for (int i = 0; i < s.size(); ++i) {
		si[int(s[i] - 'a')].push_back(i + 1);
	}
	bool ok = true;
	for (int i = 0; i < t.size(); ++i) {
		if (si[int(t[i] - 'a')].size() == 0) {
			ok = false;
		}
	}
	if (!ok) {
		cout << -1 << endl;
		return 0;
	}
	
	int now = 0;
	Int cnt = 0;
	for (int i = 0; i < t.size(); ++i) {
		int idx = t[i] - 'a';
		int next = upper_bound(si[idx].begin(), si[idx].end(), now) - si[idx].begin();
		if (next == si[idx].size()) {
			++cnt;
			next = 0;
		}
		now = si[idx][next];
	}

	Int ans = cnt * (Int)(s.size()) + now;
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1216
n, a, c = gets.split(" ").map(&:to_i)
ary = gets.split(" ").map(&:to_i)
count = 0
n.times do 
    sum = 0
    t = gets.split(" ").map(&:to_i)
    (0..a-1).each do |n|
        sum += ary[n]*t[n]
    end
    sum += c  
    count += 1 if sum >0
end
puts count

Measured memory_bytes: 1788
#include <iostream>

using namespace std;
int i,a[4],ans;
char ch;
int main()
{
    for(i=1;i<=3;i++)
    {
        cin>>ch;
        if(ch=='R')
            a[i]=1;
    }

    if(a[1] || a[2] || a[3])
        ans=1;
    if(a[1] && a[2])
        ans=2;
    if(a[2] && a[3])
        ans=2;
    if(a[1] && a[2] && a[3])
        ans=3;

    cout<<ans;
    return 0;
}


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

using namespace std;

#define REP(i, n) for(int i=0; i<n; i++)

string s1, s2;
int main() {
    while(1) {
        cin >> s1;
        if (s1 == ".") break;
        cin >> s2;

        int error = 0;
        int ap = 0;
        int i=0, j=0;
        while (1) {
            if (i==s1.size()-1 || j==s2.size()-1) {
                if (s1[i]==s2[j] && i==s1.size()-1 && j==s2.size()-1) break;
                if (error==0 && ap%2==1) {
                    if (s1[s1.size()-1]!=s2[s2.size()-1]) {
                        error=2; break;
                    }
                    int apc = 0;
                    for(int k=i; k<s1.size(); k++) {
                        if (s1[k]=='"') apc++;
                    }
                    for(int k=j; k<s2.size(); k++) {
                        if (s2[k]=='"') apc++;
                    }
                    if (apc>2) {
                        error = 2; break;
                    } else {
                        error = 1; break;
                    }
                }
                error=2; break;
            }

            if (s1[i] == s2[j]) {
                if (s1[i]=='"') ap++;
                i++; j++; continue;
            }

            if (ap%2==0 || error==1) {
                error = 2; break;
            }
            
            error++;
            while(1) {
                if (s1[i]!='"') i++;
                if (s2[j]!='"') j++;
                if (s1[i]=='"' && s2[j]=='"') break;
            }
        }

        if (error==0) {
            cout << "IDENTICAL" << endl;
        } else if (error == 1) {
            cout << "CLOSE" << endl;
        } else {
            cout << "DIFFERENT" << endl;
        }
    }
    
}



Measured memory_bytes: 3152
s = input()
Q = int(input())

rev_count = 0
sbf=''
saf=''
for i in range(Q):
    que = input()
    if que[0] == '1':
        rev_count +=1
    elif que[0] == '2':
        if (rev_count + int(que[2]))%2 == 0:
            saf = saf + que[4]
        else:
            sbf = que[4] + sbf

print(sbf+s+saf if rev_count %2 == 0 else (sbf+s+saf)[-1::-1])


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007

vector<pair<ll,ll>> primefactorize(ll n){
  vector<pair<ll,ll>> res;
  for(ll i = 2;i*i <= n;i++){
    if(n%i)continue;
    res.push_back(make_pair(i,0));
    while(!(n%i)){
      res.back().second++;
      n /= i;
    }
  }
  if(n != 1)res.push_back(make_pair(n,1));
  return res;
}

int main(){
  
  ll n;
  cin >> n;
  ll res = 0;
  for(ll i = 2;i*i < n;i++){
    if(n%i)continue;
    if((n/(i-1)) == (n%(i-1)))res += (i-1);
    if((n/(n/i-1)) == (n%(n/i-1)))res += (n/i-1);
  }
  if(n != 2)res += n-1;
  cout << res << endl;
  





  return 0;
}

Measured memory_bytes: 256
NT = list(map(int, input().split()))
Min = 1001
for i in range(NT[0]):
  Data = list(map(int, input().split()))
  if Data[1] <= NT[1]:
    if Data[0] < Min:
      Min = Data[0]
if Min == 1001:
  print("TLE")
else:
  print(Min)


Measured memory_bytes: 2940
/*************************************************************************
  > File Name: e.cpp
  > Author: Samuel
  > Mail: enminghuang21119@gmail.com
  > Created Time: Tue Mar 17 19:15:18 2020
*************************************************************************/

#include <bits/stdc++.h>
using namespace std;

int h, n, mx;
long long dp[200010];
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> h >> n;
    for (int i = 1; i <= h + 10000; i++)
        dp[i] = 1LL << 60;
    for (int i = 0; i < n; i++) {
        int atk, mana;
        cin >> atk >> mana;
        mx = max(mx, atk);
        for (int j = 0; j < h; j++)
            dp[j + atk] = min(dp[j + atk], dp[j] + mana);
    }
    long long ans = 1LL << 60;
    for (int i = 0; i < mx; i++) {
        ans = min(ans, dp[i + h]);
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

int main() {

  int i,j,k,v,N,A[100],count=0;

  while(1) {
  scanf("%d",&N);
  if(N<1 || 100<N) printf("error\n");
  else break;
  }
  
  while(1) {
    for(i=0; i<N; i++) {
      scanf("%d",&A[i]);
      if(A[i]<0 || 1000<A[i]) count++;
    }
    if(count == 0) break;
    else printf("error\n");
    count =0;
  }
  
  for(i=0; i<N; i++){
    k = 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; k++){
      printf("%d",A[k]);
      if(k == N-1) {
	printf("\n");
	break;
      }
      printf(" ");
    }
  }
  return 0;
}

Measured memory_bytes: 604
def min(a, b)
   (a < b) ? a : b
end

n = gets.chomp.to_i

tmp = gets.chomp
b_nums = tmp.split(" ")
b_nums.map! do |b|
  b.to_i
end
#b_nums << b_nums[-1]

result = b_nums[0] + b_nums[-1]

idx = 1
while idx < n-1 do
  result += min(b_nums[idx-1], b_nums[idx])
  idx += 1
end

puts result



Measured memory_bytes: 1788
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>

using namespace std;
#define MAXN 100000
#define rint register int
#define gc() getchar()
inline int read(rint ans = 0, rint sgn = ' ', rint ch = gc())
{
	for(; ch < '0' || ch > '9'; sgn = ch, ch = gc());
	for(; ch >='0' && ch <='9';(ans*=10)+=ch-'0', ch = gc());
	return sgn-'-'?ans:-ans;
}
int first[MAXN+5], cur[MAXN+5], fa[2][MAXN+5], in[2][MAXN+5], c[MAXN+5], w[MAXN+5], to[MAXN+5], n, tot;
struct Edge{int to,nex,w; Edge(){} Edge(int _to, int _nex, int _w):to(_to),nex(_nex),w(_w){}}e[(MAXN<<2)+5]; bool book[(MAXN<<2)+5];
inline void Add(int a, int b, int w){e[tot] = Edge(b,first[a],w), first[a] = tot++, e[tot] = Edge(a,first[b],w), first[b] = tot++;}
void DFS(int p){for(rint u = cur[p]; ~u; u = cur[p]) if(cur[p]=e[u].nex, !book[u] && !book[u^1]) !e[u].w ? to[e[u^1].to] = e[u].to, ++c[e[u].to], --c[e[u^1].to] : 0, book[u] = true, DFS(e[u].to);}
int main()
{
	n = read(), memset(first,-1,-~n<<2); for(rint k = 0, i; k < 2; k++) for(i = 1; i <= n; ++in[k][fa[k][i++]=max(read(),0)]);
	for(rint i = 1; i <= n; i++) if((in[0][i]+in[1][i])&1){puts("IMPOSSIBLE"); return 0;} puts("POSSIBLE");
	for(rint i = 1; i <= n; Add(i,fa[0][i],0), Add(i,fa[1][i],1), i++); memcpy(cur,first,-~n<<2), DFS(1); for(rint i = 1; i <= n; printf("%d ",c[i]), i++); putchar('\n'); return 0;
}

Measured memory_bytes: 12160
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<string.h>
#include <iomanip>
#include <sstream>
using namespace std;

int main() {
  int N, M;
  int ans = 0;
  string X;

  cin >> N;

  vector<int> t(N);
  vector<string> s(N);
//  vector<pair<int,int>> AB(N);
  for(int i = 0; i < N; i++){
    cin >> s[i] >> t[i];
  }
  cin >> X;

  int lastindex = 0;
  for(int i = 0; i < N; i++){
    if(s[i] == X){
      lastindex = i;
      break;
    }
  }
  lastindex++;
  for(int i = lastindex; i < N; i++){
    ans += t[i];
  }


  cout << ans << endl;

}


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

using namespace std;
typedef long long ll;
#define MOD 1000000007
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

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

    vector<string> s(n);
    for(int i=0; i<n; i++) cin >> s[i];

    map<string, int> mp;
    int mx = 0;
    for(int i=0; i<n; i++) {
        mp[s[i]]++;
        mx = max(mx, mp[s[i]]);
    }

    vector<string> v;
    for(auto p: mp) {
        if(p.second == mx) v.push_back(p.first);
    }

    sort(v.begin(), v.end());
    for(auto x: v)
        cout << x << endl;

    return 0;
}

Measured memory_bytes: 29040
d=[0]*13
d[0]=1
s=input()
for k,t in enumerate(s[::-1]):
    if t=='?':
        d2=[0]*13
        for i in range(10):
            u=i*pow(10,k,13)
            for i in range(13):
                d2[(i+u)%13]+=d[i]
    else:
        u=int(t)*pow(10,k,13)
        d2=[0]*13
        for i in range(13):
            d2[(i+u)%13]+=d[i]
    for i in range(13):
        d[i]=d2[i]%(10**9+7)
print(d[5])

Measured memory_bytes: 43500
H,W=map(int,input().split())
S=[input() for i in range(H)]
ans=1
for i in range(H):
  for j in range(W):
    if(S[i][j]=='#'):
      if(i==0 and j==0):
        if(S[i+1][j]=='.' and S[i][j+1]=='.'):
          ans=0
      elif(i==0 and j==W-1):
        if(S[i+1][j]=='.' and S[i][j-1]=='.'):
          ans=0
      elif(i==0):
        if(S[i+1][j]=='.' and S[i][j+1]=='.' and S[i][j-1]=='.'):
          ans=0
      elif(i==H-1 and j==0):
        if(S[i-1][j]=='.' and S[i][j+1]=='.'):
          ans=0
      elif(i==H-1 and j==W-1):
        if(S[i-1][j]=='.' and S[i][j-1]=='.'):
          ans=0
      elif(i==H-1):
        if(S[i][j+1]=='.' and S[i-1][j]=='.' and S[i][j-1]=='.'):
          ans=0
      elif(j==0):
        if(S[i+1][j]=='.' and S[i][j+1]=='.' and S[i-1][j]=='.'):
          ans=0
      elif(j==W-1):
        if(S[i+1][j]=='.' and S[i-1][j]=='.' and S[i][j-1]=='.'):
          ans=0
      else:
        if(S[i+1][j]=='.' and S[i][j+1]=='.' and S[i-1][j]=='.' and S[i][j-1]=='.'):
            ans=0
if(ans):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3192
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    void run() {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long[] io = new long[5];

        int p = -1;
        for (int i = 0; i < 5; i++) {
            io[i] = sc.nextLong();
            if (p < 0 || io[p] > io[i]) {
                p = i;
            }
        }
        long ans = (n + io[p] - 1) / io[p];
        System.out.println(ans + 4);
    }

    void debug(Object...os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 21844
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int ans = Integer.MAX_VALUE;
		for (int i = 1; i <= N / 2; i++) {
			int a = i;
			int b = N - i;
			int sum = calcEachDigit(a) + calcEachDigit(b);
			ans = Math.min(ans, sum);

		}
		System.out.println(ans);
		sc.close();
	}

	private static int calcEachDigit(int x) {
		int t = x;
		int sum = 0;
		while (t > 0) {
			sum += t % 10;
			t /= 10;
		}
		return sum;
	}
}

Measured memory_bytes: 21844
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 1000000000
#define INF 9223372036854775807
#define MOD 998244353
#define mod 998244353
#define INT_MAX_ 2147483647
#define EPS (1e-10)
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define rep(i,n)for (ll i = 0; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
#define me memset
#define bit(n,k) ((n>>k)&1)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp1(pair<ll,ll> a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi>b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_t=clock();
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //-------------------------------
    int n;cin>>n;
    while(n){
        V<int>s(n);
        for(int i=0;i<n;i++)cin>>s[i];
        sort(all(s));
        int sum=0;
        for(int i=1;i<n-1;i++){
            sum+=s[i];
        }
        cout<<sum/(n-2)<<endl;
        cin>>n;
    }
    //-------------------------------  
    //fclose(stdin);
    //fclose(stdout);
    //ll end_t=clock();cout<<"time="<<end_t-begin_t<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------



















































Measured memory_bytes: 3180
#include<bits/stdc++.h>
using namespace std;
int n;
double p[3005],f[3005][3005],ans;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%lf",&p[i]);
	f[0][0]=1;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<=i;j++)//j heads
		{
			if(j>0) f[i][j]+=f[i-1][j-1]*p[i];
			if(j<i) f[i][j]+=f[i-1][j]*(1-p[i]);
		}
	}
	for(int i=n/2+1;i<=n;i++) ans+=f[n][i];
	printf("%.12lf\n",ans);
	return 0;
}

Measured memory_bytes: 68992
#include <bits/stdc++.h>
using namespace std;
typedef tuple<int, int, int> tp;
typedef long long LL;
typedef long double LD;
typedef pair<int, int> pii;
typedef pair<int, LL> pil;
typedef pair<LL, int> pli;
typedef pair<LL, LL> pll;
typedef pair<pii, int> piipi;
typedef pair<int, pii> pipii;
typedef pair<pii, pii> piipii;
typedef pair<LL, pii> plpii;
typedef pair<LD, LD> pdd;
typedef pair<LD, int> pdi;
typedef pair<LD, LL> pdl;
typedef pair<int, LD> pid;
typedef pair<LL, LD> pld;
const int mod = 1e9 + 7;
const int hf = 999983;
const int N = 1e6;

int n, m;
vector<int> g[100005];
vector<LL> pref[100005], suff[100005];
map<int, int> idx[100005];
map<int, LL> dp[100005];
int par[100005];
bool up[100005];

void update(int u){
    up[u] = 1;
    int sz = g[u].size();
    for(int i=1;i<sz;i++) pref[u][i] = (pref[u][i]*pref[u][i-1])%m;
    for(int i=sz-2;i>=0;i--) suff[u][i] = (suff[u][i]*suff[u][i+1])%m;
}

void dfs_down(int u, int p){
    par[u] = p;
    pref[u].resize(g[u].size());
    suff[u].resize(g[u].size());

    dp[u][p] = 1;
    for(int i=0;i<g[u].size();i++){
        int v = g[u][i];
        idx[u][v] = i;
        if(v == p) continue;
        dfs_down(v, u);

        pref[u][i] = (dp[v][u]+1)%m;
        suff[u][i] = (dp[v][u]+1)%m;
        dp[u][p] = (dp[u][p]*(dp[v][u]+1))%m;
    }
    if(u == 1) update(1);
}

void dfs_up(int u, int p){
    if(dp[u].count(p)) return;
    if(!up[u]){
        int v = par[u];
        dfs_up(v, u);
        pref[u][idx[u][v]] = (dp[v][u]+1)%m;
        suff[u][idx[u][v]] = (dp[v][u]+1)%m;
        par[u] = 0;
        update(u);
    }

    if(p == 0) dp[u][p] = pref[u][g[u].size()-1];
    else{
        dp[u][p] = 1;
        if(idx[u][p]-1 >= 0) dp[u][p] = (dp[u][p]*pref[u][idx[u][p]-1])%m;
        if(idx[u][p]+1 < g[u].size()) dp[u][p] = (dp[u][p]*suff[u][idx[u][p]+1])%m;
    }
}

int main(){
    scanf("%d%d", &n, &m);
    for(int i=2;i<=n;i++){
        int a, b;
        scanf("%d%d", &a, &b);
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs_down(1, 0);
    up[1] = 1;
    for(int i=1;i<=n;i++){
        if(i != 1) dfs_up(i, 0);
        printf("%lld\n", dp[i][0]);
    }
}


Measured memory_bytes: 61824
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;

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

        int N = sc.nextInt();
        int K = sc.nextInt();
        int ans = 0;
        ArrayList<Integer> list = new ArrayList<Integer>();
        
        for(int i=0; i<N; i++){
            list.add(sc.nextInt());
        }

        Collections.sort(list);

        for(int i=N-K; i<N; i++){
            ans += list.get(i);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23764
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      String[] line;
      MyList list = new MyList();

      for(int i=0; i<n; i++) {
        line = br.readLine().split(" ");
        switch( line[0] ) {
          case "insert" :
            list.insertFirst( Integer.parseInt(line[1]) );
            break;
          case "deleteFirst" :
            list.deleteFirst();
            break;
          case "deleteLast" :
            list.deleteLast();
            break;
          case "delete" :
            list.delete( Integer.parseInt(line[1]) );
            break;
        }
      }

      System.out.println ( list.getAllElements() );
    }
  }
}

class Node {
  Node next,prev;
  int key;

  public Node(int key) {
    this.key = key;
  }
}

class MyList {
  Node nil;
  Node current;
  int size;

  public MyList() {
    nil = new Node(0);
    nil.next = nil.prev = nil;
    size = 0;
  }

  public String getAllElements() {
    StringBuilder buf = new StringBuilder(size*5);

    if(size > 0){
      current = nil.next;
      for(int i=0; i<size; i++){
        buf.append(current.key).append(" ");
        current = current.next;
      }
    }
    buf.setLength(buf.length()-1);

    return buf.toString();
  }
  public void insertFirst(int x) {
    if(size == 0) {
      current = new Node(x);
      nil.next = current;
      nil.prev = current;
      current.prev = nil;
      current.next = nil;
      size++;
    }
    else {
      Node add = new Node(x);
      
      current.prev.next = add;
      add.prev = current.prev;

      add.next = current;
      current.prev = add;

      current = add;
      size++;
    }
  }
  public void deleteFirst() {
    nil.next = current.next;
    current.next.prev = current.prev;

    current = current.next;
    size--;
  }
  public void deleteLast() {
    current = nil.prev;

    nil.prev = current.prev;
    current.prev.next = current.next;

    current = nil.next;
    size--;
  }
  public void delete(int x) {
    Node target = findFirst(x);

    if(target == nil) current = current.next;
    else {
      current.prev.next = target.next;
      current.next.prev = target.prev;
      current = nil.next;
      size--;
    }
  }
  private Node findFirst(int x) {
    while(current != nil) {
      if(current.key == x) break;
      current = current.next;
    }

    return current;
  }
}


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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
ostream &operator<<(ostream &os, pair<ll, ll>&p){
  return os << p.first << " " << p.second;
}  
ll MAX_V = 2e5 + 5;
vector<ll>t(MAX_V);
pair<ll,ll> dfs(ll k,vector<vector<ll>>&g){
  t[k]=1;
  P ret;
  ll maxbuf=0;
  ll cnt=0;
  for(ll i=0;i<g[k].size();i++){
    if(t[g[k][i]]==0){
      auto p=dfs(g[k][i],g);
      ret.fi+=p.fi;
      ret.se+=p.se;
      chmax(maxbuf,p.fi-p.se);
      cnt++;
    }
  }
  //cout<<k spa maxbuf spa ret<<endl;
  if(cnt==0)return MP(1,0);
  if(cnt==1)return ret;
  if(cnt>=2)ret.fi-=maxbuf;
  if(ret.fi>=1)ret.se=ret.fi;
  return ret;
}
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n;cin>>n;
  vector<vector<ll>>g(n);
  ll r=0;
  rep(i,0,n-1){
    ll a,b;cin>>a>>b;
    g[a].PB(b);
    g[b].PB(a);
    
  }
  rep(i,0,n)if(g[i].size()>=3)r=i;
  auto p=dfs(r,g);
  cout<<max(1LL,p.se)<<endl;
  return 0;
}

Measured memory_bytes: 14976
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <climits>

using namespace std;

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

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

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

    bool consistent = true;
    if (n%2==0) {
        int prev = -1;
        for (int i = 0; i < a.size(); i += 2) {
            if (a[i] - prev != 2 || a[i+1] != a[i]) { // safe to access a[i+1]
                consistent = false;
                break;
            }
            prev = a[i];
        }
    } else {
        int prev = 0;
        for (int i = 1; i < a.size(); i += 2) {
            if (a[i] - prev != 2 || a[i+1] != a[i]) {
                consistent = false;
                break;
            }
            prev = a[i];
        }
    }

    if (!consistent) {
        cout << 0 << endl;
        return 0;
    }

    int ans = 1;
    for (int i = 0; i < n / 2; i++) ans = ans * 2 % (1000000000 + 7);
    cout << ans << endl;

    return 0;
}

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

int main(){
    vector<int> vec(3);
    for (int i=0; i<3; i++){
        cin >> vec[i];
    }
    sort(begin(vec), end(vec));
    int ans=0;
    ans += (vec[1] - vec[0]) / 2;
    vec[0] += ans * 2;
    if (vec[0] != vec[1]){
        vec[2] += 1;
        ans += 1;
    } 
    ans += vec[2] - vec[1];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;
using ll = long long;
using ull = long long;
int main() {
	ll n, A, B, C, D, dif;
	scanf("%lld %lld %lld %lld %lld", &n, &A, &B, &C, &D);
	dif = abs(A - B);
	if (D * (n - 1) < dif) {
		printf("NO\n");
	}
	else if (C * (n - 1) <= dif && dif <= D * (n - 1)) {
		printf("YES\n");
	}
	else {
		bool can = false;
		for (int i = 1; i < n; i++) {
			if (C * (n - (1 + i)) - D * i <= dif && dif <= D * (n - (1 + i)) - C * i) {
				can = true;
				printf("YES\n");
				break;
			}
		}
		if (!can)
			printf("NO\n");
	}
}

Measured memory_bytes: 128
A,B,C,D=map(int,input().split())
dp=[[0 for _ in range(D+1)] for _ in range(C+1)]
dp[A][B]=1
p=998244353

for i in range(A,C):
    dp[i+1][B]=(B*dp[i][B])%p##-(i+j-A-B)
for j in range(B,D):
    dp[A][j+1]=(A*dp[A][j])%p##-(i+j-A-B)
for i in range(A,C):
    for j in range(B,D):
        dp[i+1][j+1]=((j+1)*dp[i][j+1]+(i+1)*dp[i+1][j]-i*j*dp[i][j])%p
        #print(dp)
        #input()

print(dp[C][D])

Measured memory_bytes: 146916