akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
int n,m,u[2005],v[2005],id[2005][2005];
queue<int>q;
struct Tree
{
	struct Edge
	{
		int to;
		int nxt;
	}e[4005];
	int edgenum,head[2005],pa[2005][2005],dep[2005][2005],a[2005][2005];
	bool flag[2005];
	void add(int u,int v)
	{
		e[++edgenum].to=v;
		e[edgenum].nxt=head[u];
		head[u]=edgenum;
	}
	void pre(int node,int r)
	{
		for(int hd=head[node];hd;hd=e[hd].nxt)
		{
			int to=e[hd].to;
			if(to==pa[r][node])continue;
			pa[r][to]=node;
			dep[r][to]=dep[r][node]+1;
			pre(to,r);
		}
	}
	void dfs(int r,int node,int x)
	{
//		printf("dfs(%d,%d,%d)\n",r,node,x);
		if(a[r][node])
		{
//			printf("a[%d][%d]=%d,id[%d][%d]=%d\n",r,node,a[r][node],r,node,id[r][node]);
			int i=id[r][node];
			a[r][node]=x;
			if(!flag[i])flag[i]=1,q.push(i);
			return;
		}
		a[r][node]=x;
		for(int hd=head[node];hd;hd=e[hd].nxt)
		{
			int to=e[hd].to;
			if(to==pa[r][node])continue;
			dfs(r,to,x);
		}
	}
	void solve(int x)
	{
		if(!x)return;
		if(id[u[x]][v[x]]&&id[u[x]][v[x]]!=x)
		{
			u[x]=v[x]=0;
			return;
		}
//		printf("solve(%d),(%d,%d)\n",x,u[x],v[x]);
//		printf("%d\n",a[13][16]);
		id[u[x]][v[x]]=id[v[x]][u[x]]=0;
		while((a[u[x]][v[x]]&&a[u[x]][v[x]]!=v[x])||(a[v[x]][u[x]]&&a[v[x]][u[x]]!=u[x]))
		{
//			printf("a[%d][%d]:%d %d\n",u[x],v[x],a[u[x]][v[x]],a[v[x]][u[x]]);
			if(a[u[x]][v[x]]&&a[u[x]][v[x]]!=v[x])u[x]=a[u[x]][v[x]];
			if(a[v[x]][u[x]]&&a[v[x]][u[x]]!=u[x])v[x]=a[v[x]][u[x]];
//			printf("%d %d\n",u[x],v[x]);
		}
		if(u[x]==v[x]||id[u[x]][v[x]])
		{
			u[x]=v[x]=0;
			return;
		}
		int a=u[x],b=v[x];
//		printf("%d %d\n",u[x],v[x]);
		id[a][b]=id[b][a]=x;
		dfs(a,b,b);
		dfs(b,a,a);
	}
	void work(int st)
	{
		q.push(st);
		flag[st]=1;
		while(!q.empty())
		{
			int node=q.front();
			q.pop();
			solve(node);
			flag[node]=0;
		}
	}
}T;
struct Edge
{
	int to;
	int nxt;
}e[4005];
int edgenum,head[2005],ans;
void add(int u,int v)
{
	e[++edgenum].to=v;
	e[edgenum].nxt=head[u];
	head[u]=edgenum;
}
void dfs(int r,int node)
{
	for(int hd=head[node];hd;hd=e[hd].nxt)
	{
		int to=e[hd].to;
		if(T.dep[r][node]+T.dep[node][to]==T.dep[r][to])ans++,dfs(r,to);
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<n;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		T.add(u,v);
		T.add(v,u);
	}
	for(int i=1;i<=n;i++)T.pre(i,i);
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&u[i],&v[i]);
		T.work(i);
		if(!u[i])i--,m--;
//		for(int j=1;j<=i;j++)printf("(%d,%d)",u[j],v[j]);
//		printf("\n");
	}
	for(int i=1;i<=m;i++)
	{
//		printf("(%d,%d) ",u[i],v[i]);
		add(u[i],v[i]);
		add(v[i],u[i]);
	}
//	printf("\n");
	for(int i=1;i<=n;i++)dfs(i,i);
	printf("%d\n",ans/2);
	return 0;
}

Measured memory_bytes: 63104
#include<bits/stdc++.h>
using namespace std;
const int N=55;
int n,m,A[N],flag[N];
vector <int> ans;
int main(){
	scanf("%d%d",&n,&m);
	for (int i=0;i<n;i++)scanf("%d",&A[i]);
	for (int t=0;t<=m;t++){
		vector<pair<int,int>>vx;
		for (int i=0;i<n;i++){
			if (flag[i])continue;
			vx.push_back(make_pair(A[i],i));
		}
		sort(vx.begin(),vx.end(),greater<pair<int,int>>());
		memset(flag,0,sizeof flag);
		for (int i=0;i<vx.size();i++){
			int v=vx[i].second;
			A[v]--;
			if (A[v]<0){
				puts("-1");
				return 0;
			}
			ans.push_back(v);
			if (i+1==vx.size())flag[v]=1;
		}
	}
	printf("%d\n",ans.size());
	for (int i:ans)printf("%d ",i+1);
}


Measured memory_bytes: 256
#include<iostream>
#include<limits.h>

using namespace std;

int main() {
	long n;
	cin >> n;
	long sum = 0;
	for (long i = 0; i < n; i++) {
		sum += i + 1;
	}
	for (long i = 0; i < n / 3; i++) {
		sum -= 3 * (i + 1);
	}
	for (long i = 0; i < n / 5; i++) {
		sum -= 5 * (i + 1);
	}
	for (long i = 0; i < n / 15; i++) {
		sum += 15 * (i + 1);
	}
	cout << sum << endl;


	return 0;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> V(N);
    rep(i, N) cin >> V[i];

    int ans = 0;
    rep(l, N + 1) {
        rep(r, N + 1 - l) {
            int k = K - l - r;
            // cout << l << " " << r << endl;
            if (k < 0 || (l + r) <= 0) continue;
            vector<int> num;
            int sum = 0;
            rep(i, l) {
                num.push_back(V[i]);
                sum += V[i];
            }
            rep(i, r) {
                num.push_back(V[N - i - 1]);
                sum += V[N - i - 1];
            }
            sort(all(num));
            rep(i, min(k, (int)num.size())) {
                if (num[i] < 0) {
                    sum -= num[i];
                }
            }
            chmax(ans, sum);
        }
    }

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

Measured memory_bytes: 256
#! env/bin/local python3
# -*- coding:utf-8 -*-

s = input()
ls = len(s)


def is_kaibun(s):
    rs = s[::-1]
    if s == rs:
        return True
    else:
        return False


flag = False
if is_kaibun(s):
    if is_kaibun(s[:(ls-1)//2]):
        if is_kaibun(s[(ls+3)//2-1: ls]):
            flag = True

print('Yes' if flag else 'No')




Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <limits>
#include <sstream>
#include <fstream>
#include <climits>
#include <map>
#include <numeric>
#include <functional>
#include <utility>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;

int main(void) {
  int n;
  cin >> n;
  vector<int> h(n);
  rep(i, n) cin >> h[i];

  int mx = 0;
  int cnt = 0;
  rep(i, n) {
    if (h[i] >= mx) {
      cnt++;
      mx = h[i];
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<set>
#include<algorithm>
#include<list>
#include<queue>

#define MAX 110

using namespace std;

class Node{
public:
  set<int> con;
};

class State{
public:
  int pos;
  State(int pos):pos(pos){
    len = 1;
  }
  int len;
  bool vis[MAX];
};

int BFS(int st, const vector<Node> &G){
  int ret = 1;
  queue<State> q;
  State init(st);

  fill(init.vis,init.vis+MAX,false);
  init.vis[st]=true;
  q.push(init);

  while(!q.empty()){
    bool NG=false;
    State now = q.front();
    q.pop();

    ret = max( ret, now.len );

    const set<int> &S = G[now.pos].con;
    for(set<int>::iterator its = S.begin();
	its != S.end();
	++its){
      int nx = *its;
      if( !now.vis[ nx ] ){
	State next = now;
	next.pos = nx;
	next.vis[nx] = true;
	next.len++;
	q.push( next );
      }
    }
  }
  return ret;
}

typedef vector<Node> graph;
typedef list< vector<int> > forest;

void MakeForest(const graph &g, bool exist[MAX], forest &f){
  bool vis[MAX]={false};
  for(int x=0;x<MAX;++x){
    if(!vis[x]&&exist[x]){
      queue<int> q;
      bool tvis[MAX]={false};
      q.push(x);
      tvis[x]=true;
      while(!q.empty()){
	int now=q.front();q.pop();const set<int> &C=g[now].con;
	for(set<int>::iterator its=C.begin();its!=C.end();++its){
	  if(!tvis[*its]){tvis[*its]=true;q.push(*its);}
	}
      }
      vector<int> tmp;
      f.push_back( tmp );
      for(int i=0;i<MAX;++i){
	if(tvis[i]){
	  vis[i]=true;
	  f.back().push_back( i );
	}
      }
    }
  }
}

int Backtrack(int pos, int now, int &bans, bool vis[], int memo[], const graph &G){
  const set<int> &C = G[pos].con;
  int ret = now;
  if(vis[pos]){return now;}
  vis[pos]=true;
  if(now+memo[pos]<=bans)return bans;
  for(set<int>::iterator itc=C.begin();itc!=C.end();++itc){
    int nx = *itc;
    //if( !vis[nx] ){
      bans=max(bans,now+1);
      //vis[nx]=true;
      ret=max(ret,Backtrack(nx,now+1,bans,vis,memo,G) );
      //vis[nx]=false;
      bans=max(bans,ret);
      //}
  }
  vis[pos]=false;
  return ret;
}

int main()
{
  while(true){
    int ans = 2;
    int n;
    cin >> n;
    if( n == 0 )break;
    graph G(MAX);
    forest F;
    bool exist[MAX]={false,};
    for(int i = 0;  i < n ; ++i){
      int a,b;
      cin >> a >> b;
      exist[a]=exist[b]=true;
      G[a].con.insert(b);
      G[b].con.insert(a);
    }

    MakeForest(G,exist,F);

    int memo[MAX];
    for(int i=0;i<MAX;++i){
      memo[i]=MAX*MAX;
    }
    for(forest::iterator itf=F.begin();itf!=F.end();++itf){
      if((*itf).size()<=ans)continue;
      for(int i = 0; i < (*itf).size(); ++i){
	int st=(*itf)[i];
	bool vis[MAX]={false,};
	//vis[st]=true;
	int btret = Backtrack( st, 0, ans, vis, memo, G );
	memo[st]=btret;
	ans=max(ans,btret);
      }
    }
    cout << ans << endl;
  }
  return 0;
}

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

struct node{
	char name[11];
	int time;
	struct node *next;
	struct node *prev;
};

typedef struct node *NodePointer;

NodePointer nil;

void init(){
	nil = malloc(sizeof(struct node));
	nil->next = nil;
	nil->prev = nil;
}

void deleteNode(NodePointer t){
	t->prev->next = t->next;
	t->next->prev = t->prev;
	free(t);
}

void backInsert(char name[],int time){
	NodePointer x;
	x = malloc(sizeof(struct node));
	strcpy(x->name,name);
	x->time = time;
	x->next = nil;
	x->prev = nil->prev;
	x->prev->next = x;
	nil->prev = x;
}

void deleteFirst(){
	NodePointer t = nil->next;
	if(t == nil){
		return;
	}
	deleteNode(t);
}

int main(int argc, char **argv)
{
	char name[11];
	int time = 0;
	int q = 0;
	int n = 0;
	int i = 0;
	int count = 0;

	scanf("%d%d",&n,&q);

	init();
	for(i = 0;i < n;i++){
		scanf("%s", name);
		scanf("%d", &time);
		backInsert(name,time);
	}
	
	NodePointer t = nil->next;

	i = 0;
	while(t != nil){
		i++;
		count++;
		t->time--;
		if(t->time == 0){
			printf("%s %d\n", t->name, count);
			deleteFirst();
			i = 0;
		}
		else if(i == q){
			backInsert(t->name,t->time);
			deleteFirst();
			i = 0;
		}
		t = nil->next;
	}

	free(nil);
	return 0;
}


Measured memory_bytes: 4188
#include<bits/stdc++.h>
#define M 1000000007
#define pi ld(acos(-1.0))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n) for(int i=1;i<(int)(n);i++)
#define repp(i,a,b)  for(int i=a;i<=(int)(b);i++)
#define Repp(i,a,b)  for(int i=a;i>=(int)(b);i--)
#define cs ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fi first
#define se second
#define ii pair<int,int>
#define bye(x) {cout<<x;return 0;}
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
    cs
    int n;cin>>n;
    vector<ll> v(n);
    for(auto &i:v) cin>>i;
    ll ans=0,t=1;
    rep(i,60) {
        ll a=0,b=0;
        rep(j,n) {
            if(v[j]&1) a++;else b++;
            v[j]>>=1;
        }
        ans+=(((a*b)%M)*t)%M;
        t<<=1;t%=M;ans%=M;
    }
    cout<<ans;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#pragma gcc optimize("ofast")
using namespace std;

#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define mod 1000000007
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0);
#define INF LONG_MAX
#define PI 3.1415926535897932384626
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(x,j,n)for(int x=j;x<n;x++)
typedef vector<pair<ll,ll>> vpi;
typedef vector<ll> vi;
typedef vector<vi> vvi;

ll modexp(ll a,ll b,ll m)
{
	ll r=1;
	a=a%m;
	while(b>0)
	{
	if(b&1)
		r=(r*a)%m;
	b=b/2;
	a=(a*a)%m;
	}
	return r%m;
}

int main() {
    ll a,b; cin>>a>>b;
    if(a>9||b>9)cout<<-1<<endl;
    else cout<<a*b<<endl;
    return 0;
}
/*
1
5 1
1 2
2 3
3 4
3 5
2 2 5 2
*/


Measured memory_bytes: 256
#include <vector>
#include <iostream>

using namespace std;

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

int main() {
  int n, m, q;
  cin >> n >> m;
  UnionFind uf(n);
  for (int i = 0; i < m; ++i) {
    int s, t;
    cin >> s >> t;
    uf.unionSet(s, t);
  }
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int s, t;
    cin >> s >> t;
    if (uf.findSet(s, t)) {
      cout << "yes" << endl;
    } else {
      cout << "no" << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3112
#include <functional>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <tuple>
#include <set>
#include <map>

#define FOR0(var, max) for (ul (var) = 0; (var) < (max); ++(var))
#define FORi(var, min, max) for (ul (var) = (min); (var) < (max); ++(var))
#define FORi_INV(var, min, max) for (ul (var) = (max) - 1; (var) + 1 > (min); --(var))
#define FORITER(var, iter) for (auto (iter) = (var).begin(); (iter) != (var).end(); (iter)++)
#define FORITER_INV(var, iter) for (auto (iter) = (var).rbegin(); (iter) != (var).rend(); (iter)++)

#define LTLT(a, b, c) (((a) < (b)) && ((b) < (c)))
#define LELT(a, b, c) (((a) <= (b)) && ((b) < (c)))
#define LTLE(a, b, c) (((a) < (b)) && ((b) <= (c)))

using namespace std;

using uc = unsigned char;
using ui = unsigned int;
using ul = unsigned long long int;

using sc = signed char;
using si = signed int;
using sl = signed long long int;

template <class T>
T gcd(T a, T b) {
  while (b) {
    T t = a % b;
    a = b;
    b = t;
  }
  return a;
}

const static ui NMAX = 12;
const static ui MMAX = 1000;
const static ui AiMAX = 100000;
const static ui BiMAX = NMAX;
const static ui CiMAX = NMAX;
const static ui DPMAX = AiMAX * MMAX + 1;

static ui N, M;
static ui Ai[MMAX];
static ui Bi[MMAX];
static ui Ci[MMAX];

static sl dp[MMAX + 1][1 << NMAX];

void solve(void) {
  FOR0(i, M) {
    FOR0(j, 1ULL << N) {
      dp[i][j] = DPMAX;
    }
  }
  dp[0][0] = 0;
  FOR0(i, M) {
    FOR0(j, 1ULL << N) {
      dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
      dp[i + 1][j | Ci[i]] = min(dp[i + 1][j | Ci[i]], dp[i][j] + Ai[i]);
    }
  }
  sl res = DPMAX;
  FOR0(i, M) {
    res = min(res, dp[i][(1 << N) - 1]);
  }
  if (res == DPMAX) {
    cout << -1 << endl;
  } else {
    cout << res << endl;
  }
}

int main(void) {
  cin >> N >> M;
  ui t = 0;
  FOR0(i, M) {
    cin >> Ai[i] >> Bi[i];
    Ci[i] = 0;
    FOR0(j, Bi[i]) {
      cin >> t;
      Ci[i] |= 1 << (t - 1);
    }
  }
  solve();
  return 0;
}

Measured memory_bytes: 32256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}



//head



int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vi t(n+2), v(n+2);
	rep(i, n) {
		cin >> t[i+1];
		t[i+1] <<= 1;
	}
	rep(i, n) {
		cin >> v[i+1];
		v[i+1] <<= 1;
	}
	vi tt(n+3);
	rep(i, n+2) tt[i+1] = t[i] + tt[i];

	vi time(tt[n+2]+1, INF);
	rep(i, n+2) {
		rep(j, time.size()) {
			if(tt[i] <= j and j <= tt[i+1]) {
				chmin(time[j], v[i]);
			} else if(tt[i] > j) {
				chmin(time[j], v[i] + tt[i] - j);
			} else {
				chmin(time[j], v[i] + j - tt[i+1]);
			}
		}
	}

	double ans = 0;
	rep(i, tt[n+2]) {
		ans += double(time[i] + time[i+1])/2;
	}
	cout << fixed << setprecision(6) << ans/4 << endl;
}

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

bool is_prime(int n)
{
    if (n < 2)
        return false;
    if (n == 2)
        return true;
    if (n % 2 == 0)
        return 0;
    for (int i = 3; i < n; i++)
    {
        if (n % i == 0)
            return false;
    }
    return true;
}

int main()
{
    int n, ans, i;
    cin >> n;
    i = n;
    while (true)
    {
        if (is_prime(i))
            break;
        i++;
    }
    cout << i << endl;
}

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

int main() {
  long long m, s = 0; cin >> m;
  vector<int> v(m);
  for(int i = 0; i < m; i++)
    cin >> v.at(i);
  sort(v.begin(), v.end());
  for(int i = 0; i < m - 2; i++){
    for(int j = i + 1; j < m - 1; j++){
      auto p = lower_bound(v.begin(), v.end(), v.at(i)+v.at(j));
      int d = distance(v.begin(), p) - j - 1;
      s += d;
    }
  }
  cout << s << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <sstream>
#include <iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define nout(ans) cout << (ans) << "\n"
#define sout(ans) cout << (ans) << " "
using namespace std;

const double pi = 3.14159265359;
const ll INF = 1e12;
const ll MOD = 1e9 + 7;
const ll N = 1e5 + 5;
/*
Decimal Places: cout << fixed << setprecision(n) << ans << endl

String to integer:
stringstream dark(s);
int x = 0; dark >> x;
*/

bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
    return i.second < j.second;
}


int n, a[23], b[23], c[23], ans=0;

void solve()
{
    cin >> n;
    for (int i=0; i<n; i++) cin >> a[i];
    for (int i=0; i<n; i++) cin >> b[i];
    for (int i=0; i<n; i++) cin >> c[i];
    ans+=b[a[0]-1];
    for (int i=1; i<n; i++) {
        ans+=b[a[i]-1];
        //nout(ans);
        if (a[i]==a[i-1]+1) ans+=c[a[i-1]-1];
    }nout(ans);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    //cin >> t;
    for (int i=1; i<=t; i++)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
import Control.Monad
dist a b c d = abs(a-c)+abs(b-d)

main = do
  [n,m] <- map read.words <$> getLine 
  ab <- replicateM n $ map read . words <$> getLine :: IO [[Int]]
  cd <- replicateM m $ map read . words <$> getLine :: IO [[Int]]
  sequence $  do 
    [a,b] <- ab
    return $ print $ snd $ minimum $  do 
      ([c,d],i) <- zip cd [1..]
      return (dist a b c d,i)
    


Measured memory_bytes: 1020
from math import factorial,sqrt
# from itertools import permutations as permus
# from fractions import gcd
# from collections import deque,Counter

# import numpy as np
# import scipy as scp

# 入力の受け取り
a,b,c = map(int,input().split())

def check():
    if a+b >= c:
        return False
    if 4*a*b < (c-(a+b))**2:
        return True
    else:
        return False

if check():
    ans = "Yes"
else:
    ans = "No"
print(ans)
# print("{:.10f}".format(ans))


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

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl "\n"

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

    return gcd(b, a%b);
}

const ll L = 1e5+5;

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

    vector <ll> a;

    for(ll i=0; i<n; i++)
    {
        ll t;
        cin >> t;

        a.pb(t);
    }

    ll cnt = 0;

    for(ll i=1; i<n-1; i++)
    {
        vector <ll> v = {a[i-1], a[i], a[i+1]};
        sort(all(v));

        if(v[1] == a[i])
        {
            cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef string command;
typedef int Direction;
enum Dir{UP,RIGHT,DOWN,LEFT};
Direction dx[]={ 0, 1, 0,-1};
Direction dy[]={ 1, 0,-1, 0};
string getDirString(Direction dir){
	if(dir==UP)return "UP";
	else if(dir==RIGHT)return "RIGHT";
	else if(dir==DOWN)return "DOWN";
	else if(dir==LEFT)return "LEFT";
}
class Point{
public:
	int x;
	int y;
	Direction dir;
	Point(int _x,int _y){
		x=_x;y=_y;
	}
	void print2(){
		cout<<"("<<x<<","<<y<<")"<<getDirString(dir)<<endl;
	}
	void print(){
		cout<<x<<" "<<y<<endl;
	}
};
Point Robot=Point(1,1);
int w,h;

void move(int correction){
	int num;
	cin>>num;
	Robot.x=Robot.x+dx[Robot.dir]*num*correction;
	Robot.y=Robot.y+dy[Robot.dir]*num*correction;
	if(Robot.x<1)Robot.x=1;
	if(Robot.x>w)Robot.x=w;

	if(Robot.y<1)Robot.y=1;
	if(Robot.y>h)Robot.y=h;
}
bool isMove(command com){
	if(com=="FORWARD"){
		move(1);
		return true;
	}
	else if(com=="BACKWARD"){
		move(-1);
		return true;
	}
	return false;
}

bool isDir(command com){
	if(com=="LEFT"){
		Robot.dir=(Robot.dir+3)%4;
		return true;
	}
	else if(com=="RIGHT"){
		Robot.dir=(Robot.dir+1)%4;
		return true;
	}
	return false;
}
bool isStop(command com){
	if(com=="STOP"){
		return true;
	}
	return false;
}
void init(){
	Robot.x=1;
	Robot.y=1;
	Robot.dir=UP;
}


int
main(){

	for(;cin>>w>>h&&(w||h);){
		init();
		//Robot.print2();
		for(;true;){
			command com;
			cin>>com;
	//		cout<<"command["<<com<<"]"<<endl;
			if(isStop(com))break;
			else if(isMove(com));
			else if(isDir(com));
			else{}
		//	Robot.print2();
		}
		Robot.print();
//		cout<<"------------"<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
 
using namespace std;
 
typedef long long ll;
 
const ll INF = 1e9, MOD = 1e9 + 7;

ll n, d[5001][5001], A, B;

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

	for (ll i = 1; i <= n; i++)
	{
		ll a;

		scanf ("%lld", &a);

		for (ll j = 0; j <= n; j++)
		{
			if (j < a) d[i][j] = d[i-1][j] + A;
			else if (j == a) d[i][j] = d[i-1][j];
			else d[i][j] = d[i-1][j] + B;
			if (j) d[i][j] = min (d[i][j], d[i][j-1]);
		}
	}

	cout << d[n][n];
}

Measured memory_bytes: 195584
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma warning(disable:4996)
#include <stdio.h>
#include <string>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <list>
#include <set>
#include <map>
#include <iomanip> 
#include <ctime>
#include <numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const double PI = 3.14159265358979323846;
const int MAX = 1e10;
const int MOD = 1e9+7;

const int MAX_N = 100005;



int main(int argc, char *args[]) {
	ll h; cin >> h;
	ll sum = 0;
	ll x = 1;
	while (h) {
		sum += x;
		x *= 2;
		h /= 2;
	}
	cout << sum << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int min(int a,int b){
  if(a>b){
    return b;
  }else{
    return a;
  }
}
int main(){
  char str[200001] = {};
  int i = 0;
  int j = 0;
  int n = 0;
  char stack[200001] = {};
  int stackcnt = 0;
  
  scanf(" %s",str);
  for(i=0;i<200001;i++){
    if(str[i] != '\0'){
      n++;
    }else{
      break;
    }
  }
  for(i=0;i<n;i++){
    if(stackcnt == 0 || stack[stackcnt-1] == 'T' || (stack[stackcnt-1] == 'S' && str[i] == 'S')){
      stack[stackcnt] = str[i];
      stackcnt++;
    }else {
      stackcnt--;
    }
  }
  
       
  printf("%d",stackcnt);
  return 0;
}
      

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    string s, t;
    ll q;
    cin >> s >> t >> q;
    ll ns = len(s), nt = len(t);
    vector<ll> sdp(ns + 1, 0), tdp(nt + 1, 0);
    rep(i, ns) {
        sdp[i + 1] = sdp[i] + ((s[i] == 'B') ? 2 : 1);
    }
    rep(i, nt) {
        tdp[i + 1] = tdp[i] + ((t[i] == 'B') ? 2 : 1);
    }
    rep(i, q) {
        ll a, b, c, d;
        cin >> a >> b >> c >> d;
        a--; b--; c--; d--;
        ll sc = sdp[b + 1] - sdp[a];
        ll tc = tdp[d + 1] - tdp[c];
        if (abs(sc - tc) % 3 == 0) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 2512
import java.util.Scanner;
public class Main {
	public static int f(int a,int b) {
		if(a%2==1||b==1) {
			return 1;
		}
		return 0;
	}
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		String a=scan.next();
		int A=0,B=0,C=0,D=0,E=0,F=0,G=0,H=0,I=0,J=0,K=0,L=0,
				M=0,N=0,O=0,P=0,Q=0,R=0,S=0,T=0,U=0,V=0,W=0,
				X=0,Y=0,Z=0;
		int fig=0;
		for(int i=0;i!=a.length();i++) {
			char b=a.charAt(i);
			switch(b) {
			case 'a':A++;break;
			case 'b':B++;break;
			case 'c':C++;break;
			case 'd':D++;break;
			case 'e':E++;break;
			case 'f':F++;break;
			case 'g':G++;break;
			case 'h':H++;break;
			case 'i':I++;break;
			case 'j':J++;break;
			case 'k':K++;break;
			case 'l':L++;break;
			case 'm':M++;break;
			case 'n':N++;break;
			case 'o':O++;break;
			case 'p':P++;break;
			case 'q':Q++;break;
			case 'r':R++;break;
			case 's':S++;break;
			case 't':T++;break;
			case 'u':U++;break;
			case 'v':V++;break;
			case 'w':W++;break;
			case 'x':X++;break;
			case 'y':Y++;break;
			case 'z':Z++;break;
			}
		}
		fig=f(A,fig);
		fig=f(B,fig);
		fig=f(C,fig);
		fig=f(D,fig);
		fig=f(E,fig);
		fig=f(F,fig);
		fig=f(G,fig);
		fig=f(H,fig);
		fig=f(I,fig);
		fig=f(J,fig);
		fig=f(K,fig);
		fig=f(L,fig);
		fig=f(M,fig);
		fig=f(N,fig);
		fig=f(O,fig);
		fig=f(P,fig);
		fig=f(Q,fig);
		fig=f(R,fig);
		fig=f(S,fig);
		fig=f(T,fig);
		fig=f(U,fig);
		fig=f(V,fig);
		fig=f(W,fig);
		fig=f(X,fig);
		fig=f(T,fig);
		fig=f(Z,fig);
		if(fig==1) {
			System.out.println("No");
		}
		else {
			System.out.println("Yes");
		}
	}
	}

Measured memory_bytes: 21844
import java.util.*;


public class Main {
	
	static int cnt(int[] a, int x){
		int cnt = 0;
		for(int i=0; i<a.length; i++)
			if(a[i] == x) cnt++;
		return cnt;
	}
	
	static int max(int[] a){
		int m = a[0];
		for(int i:a)
			if(m < i) m = i;
		return m;		
	}
	
	static int[] Idx(int[] a,int c,int m){
		int[] idx = new int[c];
		int j=0;
		for(int i=0; i<100; i++)
			if(a[i] == m) idx[j++] = i;
		return idx;
	}

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int[] data = new int[100];
		int[] jd = new int[100];
		for(int i=0; sc.hasNext(); i++){
			data[i] = sc.nextInt();
		}
		for(int i=0; i<100; i++){
			jd[i] = cnt(data,i+1);
		}
	    for(int i: Idx(jd,cnt(jd,max(jd)),max(jd))) System.out.println(i+1);
		
		

	}

}

Measured memory_bytes: 12000
#include<stdio.h>

void name_transformation(int year, int month, int day);

int main(void)
{
    int a, b, c;/*aは年、 bは月、cは日*/
    while((scanf("%d %d %d\n",&a, &b, &c)) != EOF){
        name_transformation(a, b, c);
    }
    return 0;
}

void name_transformation(int year, int month, int day)
{
    int gengou;
    if (year >= 1989){
        if( year > 1989){
            gengou = year - 1988;
            printf("heisei %d %d %d\n", gengou, month, day);
         }else {
            if (month >= 1){
                 if ( month > 1){
                    printf("heisei 1 %d %d\n", month, day);
                }else {
                    if( day >= 8){
                        printf("heisei 1 1 %d\n", day);
                    }else{
                        printf("showa 64 1 %d\n", day);
                    }
                }
            }
         }        
    }else if(year >= 1926){
        if( year > 1926){
            gengou = year - 1925;
            printf("showa %d %d %d\n", gengou, month, day);
         }else {
            if (month == 12){
                 if ( day >= 25){
                    printf("showa 1 12 %d\n", day);
                }else {
                    printf("taisho 15 12 %d\n", day);
                }
            }
         }            
    }else if (year >= 1912){
        if (year > 1912){
            gengou = year - 1911;
            printf("taisho %d %d %d\n", gengou, month, day);
         }else {
            if (month >= 7){
                 if ( month > 7){
                    printf("taisho 1 %d %d\n", month, day);
                }else {
                    if (day >= 30){
                        printf("taisho 1 7 %d\n", day);
                    }else{
                        printf("meiji 45 7 %d\n", day);
                    }
                }
            }
         }        
     }else if (year >= 1868){
        if (year > 1868){
            gengou = year - 1867;
            printf("meiji %d %d %d\n", gengou, month, day);
        }else {
            if (month >= 9){
                 if ( month > 9){
                    printf("meiji 1 %d %d\n", month, day);
                 }else {
                    if (day >= 8){
                        printf("meiji 1 9 %d\n", day);
                    }else{
                        printf("pre-meiji\n");
                    }
                }
            }
        }        
    }else{
        printf("pre-meiji\n");
    }
}
    
    
    
   

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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

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

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}



int main(){
int N;
ll C;
cin >> N >> C;

vector<ll> x(N + 1), v(N + 1), vc(N + 1);
x[0] = 0;
v[0] = 0;
for(int i = 1; i < N + 1; i++){ 
     cin >> x[i] >> v[i];     
}

//v(カロリー)の累積和
vc[0] = v[0];
for(int i = 1; i < N + 1; i++){ 
     vc[i] = vc[i - 1] + v[i];
}

//右回りの（カロリー）- （距離）の累積和
vector<ll> r(N + 1);
r[0] = 0;
for(int i = 1; i <= N; i++){ 
     r[i] = max(r[i - 1], vc[i] - x[i]);
}

//左回りの累積和
vector<ll> l(N + 1);
l[N] = vc[N] - vc[N - 1] - (C - x[N]);
for(int i = N - 1; i >= 1; i--){ 
    l[i] = max(l[i + 1], vc[N] - vc[i - 1] - (C - x[i]));
}

ll ans = 0;
REP(i, N + 1){
    //ケース1
    ll tmp = vc[i] - x[i];
    if(tmp > ans) ans = tmp;

    //ケース2
    if(i < N){
        tmp = vc[i] - 2 * x[i] + l[i + 1];
        if(tmp > ans) ans = tmp;
    }
}

for(int i = N; i >= 1; i--){
    //ケース3
    ll tmp = vc[N] - vc[i - 1] - (C - x[i]);
    if(tmp > ans)ans = tmp;

    //ケース4
    tmp = vc[N] - vc[i - 1] - 2 * (C - x[i]) + r[i - 1];
    if(tmp > ans)ans = tmp;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
const int INF=999999999;
int main() {
 string s;
 cin>>s;int a,b;
 for(int i=0;i<s.size();i++){
     if(s[i]=='A'){a=i;break;}
 }
 reverse(s.begin(),s.end());

 for(int i=0;i<s.size();i++){
     if(s[i]=='Z'){b=i;break;}
 }
 reverse(s.begin(),s.end());
 string z=s.substr(a,s.size()-b-a);
 cout<<z.size()<<endl;

 return 0;}

Measured memory_bytes: 772
#include <bits/stdc++.h>
using namespace std; 
int main(){
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    string S;
    cin >> S;
    int ans = 0;
    if (S[0]==S[1] && S[1] ==S[2]){
        if (S[0]=='R') ans = 3;
    }
    else if (S[0]==S[1] && S[1]=='R') ans = 2;
    else if (S[1]==S[2] && S[2] =='R') ans = 2;
    else if (S[0]=='R' || S[1]=='R' || S[2]=='R') ans = 1;
    cout << ans <<"\n";
}

Measured memory_bytes: 3616
#include <stdio.h>
#define min(a, b) ((a)>(b) ? (b) : (a))

int main(){
  int n, m, x;  scanf("%d%d%d", &n, &m, &x);
  int left = 0, right = 0;
  for(int i=0; i<m; i++){
    int t;  scanf("%d", &t);
    if(t > x)  right++;
    else  left++;
  }
  printf("%d\n", min(right, left));
  return 0;
}


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

int main() {
	int N,M,sum=0,count=0;
	int A[110];
	cin>>N>>M;
	for(int i=0;i<N;i++){
		cin>>A[i];
		sum+=A[i];
	}
	for(int i=0;i<N;i++){
		if(A[i]>=(double)sum/(4*M))count++;
	}
	if(count>=M)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
	
}

//2WAわからん


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
int32_t main()
{
    int n,q;cin>>n;
	int a[n],sum=0;
	map<int,int>m;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		sum+=a[i];
		m[a[i]]++;
	}
	cin>>q;
	int c,b;
	while(q--)
	{
		cin >> b >> c;
		if(m.find(b)!=m.end())
		{
			int tmp=m[b];
			sum-= b*tmp;
			sum+= c*tmp;
			cout<<sum<<endl;
			m.erase(b);
			m[c]+=tmp;
		}
		else
		cout<<sum<<endl;
		
	}
	return 0;
}

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

typedef vector<int> vi;
typedef vector<bool> vb;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<bool> > vvb;
typedef map<int, bool> mib;

typedef long long ll;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vpll;

typedef vector<string> vs;

typedef long double ld;

#define _GLIBCXX_DEBUG

#define REP(i,n) for (int i = 0; i < (n); ++i)
#define REPD(i,n) for (int i = (n-1); i >= 0; --i)
#define FORE(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORED(i, s, n) for (int i = (s); i >= (int)(n); i--)
#define debug(x) cerr << #x << ": " << x << '\n'
#define debug2(x, y) cerr << #x << ": " << x << ", " << #y << ": " << y << '\n'
#define debug3(x, y, z) cerr << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << '\n'
#define debugs(s) cerr << s << "\n"
#define hyphen() cerr << "--\n"

#define ALL(vec) (vec).begin(), (vec).end()
#define REVALL(vec) (vec).rbegin(), (vec).rend()

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

#define fst first
#define snd second
#define pb push_back
#define mk(x,y) make_pair((x),(y))

// http://ehafib.hatenablog.com/entry/2015/12/23/164137
int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
int qpm(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
// gcd : O(logN)
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; }

#define sz(v) int(v.size())

// x1, x2ライブラリとの被りを避ける
#define x1 x192837465
#define x2 x123456789
#define y1 y192837465
#define y2 y123456789

// typo
#define itn int
#define reutrn return
#define reutnr return
#define srting string

#define make(type, x) type x; cin>>x;
#define make2(type, x, y) type x, y; cin>>x>>y;
#define make3(type, x, y, z) type x, y, z; cin>>x>>y>>z;
#define make4(type, x, y, z, t) type x, y, z, t; cin>>x>>y>>z>>t;

int ctoi(const char c){
    if('0' <= c && c <= '9') return (c-'0');
    return -1;
}


const int MOD = (int)1e9 + 7;
const int INF = numeric_limits<int>::max();

signed main() {
    make2(int, N, P);

    // Pのn乗根までしかありえない → 相当小さそう。
    // P = (ans * ans * ans * ...) * ans * rest

    if (N == 1) {
        cout << P << endl;
        return 0;
    }

    // P % ans^N == 0
    int ans = 1;
    FORE(cand, 2, P) {
        int prod = 1;
        bool isOK = true;
        REP(i, N) {
            prod *= cand;

            if (prod > P) {
                isOK = false;
                break;
            }
        }

        if (!isOK) {
            break;
        }

        if (P % prod == 0) {
            ans = cand;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3584
N = int(input())

for i in range(N):
    if i == 0:
        P = list(map(int, input().split()))  # Pは各行列の次元
        continue
    P.append(int(input().split()[1]))

# dpテーブルの用意 minを取るときはinf埋めしておくと処理が楽になるしバグが見つかりやすい
#dp[i][j]は(Mi...Mj)のminコストを入れる
INF = 2**32-1
dp = [[INF]*N for _ in range(N)]

#dpテーブルの対角成分を0で初期化
#dp[s][s]はMsのminコストを表す（Msは単独の行列）
for ij in range(N):
    dp[ij][ij] = 0

# 最終的に求めたいのはdp[0][N]だが、計算途中で繰り返すそれぞれの行列積をdpに入れておくことで効率化
for l in range(1, N):  # l は対象とする行列の個数を表す
    for i in range(N):
        j = i+l   # Mj はMiから何個の行列を考えるかで決まる
        if j >= N:  # 計算するのはインデックスはN-1まで
            continue
        for k in range(i, j):  # (Mi...Mk)(Mk+1...Mj) のようにどこでMkで区切るかを動かす
            dp[i][j] = min(dp[i][k] + dp[k+1][j] + P[i] * P[j+1]*P[k+1], dp[i][j]) # 
print(dp[0][-1])


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

int main()
{
	string s;
	cin >> s;
	if (s[0] == s[1])
	{
		if( s[2] == s[3] && s[0]!=s[2])
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}
	else
	{
		if ((s[0] == s[2] && s[1] == s[3]) || (s[0] == s[3] && s[1] == s[2]))
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}
}



Measured memory_bytes: 3628
# -*- coding: utf-8 -*-
# n = map(int, input().split())
n = int(input())
# 文字列の入力
# 出力

num = 0
for i in range(1, n+1):
  if len(str(i)) % 2 == 1:
    num = num +1
    
print("{}".format(num))

Measured memory_bytes: 2940
//author rhythmicankur
                                                                  //god_is_almighty
#pragma GCC optimize("O3")
#pragma GCC target ("sse4")
#include<bits/stdc++.h>
#define f 		first
#define s 		second
#define int     long long
#define ll      int
#define ld 		long double
#define pb 		push_back
#define eb 		emplace_back
#define mk 		make_pair
#define vi 		vector<int>
#define pii 		pair<int,int>
#define pip             pair<int,pii>
#define vpi 		vector<pii>
#define sbcount(x) __builtin_popcountll(x)
#define REP(i,n) for (int i = 1; i <= n; i++)
#define trav(a, x)      for(auto& a : x)
#define all(x)          x.begin(), x.end()
#define fill(a,val)	memset(a,val,sizeof(a))
#define 	PI acos(-1)
#define coud(a,b) cout<<fixed << setprecision((b)) << (a)
#define M1 	998244353
#define M2 	1000000007
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); } 
#define test4(x,y,z,a) 		    cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<"  |  "<<#a<<": "<<a<<endl;
#define test1(x)                cerr<<#x<<": "<<x<<endl
#define test2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define test3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
ll power(ll a,ll b,ll m=M2){ll answer=1;while(b){if(b&1)answer=(answer*a)%m;b/=2;a=(a*a)%m;}return answer;}
using namespace std;
void ctrl(){cout<<"Control"<<endl;}
int make_num(string p){stringstream geek(p); int x = 0; geek >> x;return x;}
string make_str(int x){ostringstream str1; str1 << x; string geek = str1.str(); return geek;}
int h,w,k;


signed main()
{	ios::sync_with_stdio(0);
	cin.tie(0); 
	cin.exceptions(cin.failbit);
	int n;
    cin>>n;
    int s=0;
    int A[n];
    for(int i=0;i<n;i++)cin>>A[i];

    sort(A,A+n);

   priority_queue<pii>q;
   q.push({A[n-1],A[n-1]});
   for(int i=n-2;i>=0;i--)
   {
       auto tp = q.top();
       q.pop();
       s += tp.f;
       q.push({A[i],tp.f});
       q.push({A[i],tp.s});
   }
   cout<<s;


return 0;
}

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

string dS="..##";
string dT=".#.#";

signed main(){
    int N;
    cin>>N;

    string S="",T="";
    bool flag=false;
    rep(i,N){
        bool ok=false;
        if(!flag){
            rep(j,4){
                string SS=S+dS[j];
                string TT=T+dT[j];
                cout<<SS<<endl<<TT<<endl;
                string ret;
                cin>>ret;
                if(ret=="F")continue;

                ok=true;
                S=SS;
                T=TT;
                break;
            }
        }
        if(ok)continue;
        flag=true;
        rep(j,4){
            string SS=dS[j]+S;
            string TT=dT[j]+T;
            cout<<SS<<endl<<TT<<endl;
            string ret;
            cin>>ret;
            if(ret=="F")continue;
            ok=true;
            S=SS;T=TT;
            break;
        }
        assert(ok);
    }
    return 0;
}


Measured memory_bytes: 596
import math

if __name__ == '__main__':

	n,d = map(int,input().split())
	
	cnt = 0
	for i in range(n):
		x,y = map(int,input().split())
		tmp = math.sqrt(x*x + y*y)
		if tmp <= d:
			cnt += 1
	print(cnt)


Measured memory_bytes: 9180
n=list(map(int, input().split()))
n.sort(reverse = True)
count=0
while True:
    if n[1]>=n[0]:
        break
    n[1]+=2
    count+=1
while True:
    if n[2]>=n[0]:
        break
    n[2]+=2
    count+=1
n.sort(reverse=True)
if len(set(n))==1:
    print(count)
elif n.count(n[0])==2:
    print(count-1)
else:
    print(count+1)

Measured memory_bytes: 3064
import std.algorithm;
import std.bigint;
import std.concurrency;
import std.container;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;


auto solve(long X, long Y, long Z, long K, long[] A, long[] B, long[] C) {
    alias Vec3 = Tuple!(size_t, size_t, size_t);
    alias Cake = Tuple!(long, "value", Vec3, "pos");
    
    A = A.sort!"a > b".array;
    B = B.sort!"a > b".array;
    C = C.sort!"a > b".array;

    auto heap = make!(RedBlackTree!(Cake, "a > b"));
    auto done = make!(RedBlackTree!Vec3);
    
    heap.insert(Cake(A[0] + B[0] + C[0], Vec3(0, 0, 0)));
    done.insert(Vec3(0, 0, 0));

    const calcValue = (Vec3 v) => A[v[0]] + B[v[1]] + C[v[2]];

    foreach (_; 0 .. K) {
        auto c = heap.front;
        heap.removeFront;
        writeln(c.value);

        auto na = Vec3(c.pos[0] + 1, c.pos[1], c.pos[2]);
        if (c.pos[0] + 1 < X && !(na in done)) {
            heap.insert(Cake(calcValue(na), na));
            done.insert(na);
        }
        
        auto nb = Vec3(c.pos[0], c.pos[1] + 1, c.pos[2]);
        if (c.pos[1] + 1 < X && !(nb in done)) {
            heap.insert(Cake(calcValue(nb), nb));
            done.insert(nb);
        }
        
        auto nc = Vec3(c.pos[0], c.pos[1], c.pos[2] + 1);
        if (c.pos[2] + 1 < X && !(nc in done)) {
            heap.insert(Cake(calcValue(nc), nc));
            done.insert(nc);
        }
    }
}


void main() {
    auto input = stdin.byLine.map!split.joiner;

    long X;
    X = input.front.to!long;
    input.popFront;

    long Y;
    Y = input.front.to!long;
    input.popFront;

    long Z;
    Z = input.front.to!long;
    input.popFront;

    long K;
    K = input.front.to!long;
    input.popFront;

    long[] A = new long[](cast(size_t) (X));
    foreach (i; 0 .. cast(size_t) (X)) {
        A[i] = input.front.to!long;
        input.popFront;
    }

    long[] B = new long[](cast(size_t) (Y));
    foreach (i; 0 .. cast(size_t) (Y)) {
        B[i] = input.front.to!long;
        input.popFront;
    }

    long[] C = new long[](cast(size_t) (Z));
    foreach (i; 0 .. cast(size_t) (Z)) {
        C[i] = input.front.to!long;
        input.popFront;
    }

    static if (is(ReturnType!solve == void))
        solve(X, Y, Z, K, A, B, C);
    else
        solve(X, Y, Z, K, A, B, C).writeln;
}


Measured memory_bytes: 3324
import math

EPS = 0.0000000001


def calc(a, b, theta):
    if a * math.tan(math.radians(theta)) <= b:
        return a * a * b - a * a * a * math.tan(math.radians(theta)) / 2
    else:
        return b * b / math.tan(math.radians(theta)) * a / 2


def solve():
    a, b, x = map(int, input().split())

    ok = 90
    ng = 0
    for _ in range(1000):
        mid = (ok + ng) / 2
        if calc(a, b, mid) < x:
            ok = mid
        else:
            ng = mid

    print(ok)


if __name__ == '__main__':
    solve()

Measured memory_bytes: 3064
from collections import defaultdict
N,K = map(int,input().split())
A = list(map(lambda x:bin(int(x))[2:],input().split()))
l = 0
for i in range(N):
    l = max(l,len(A[i]))
count = defaultdict(lambda:0)
for i in range(N):
    for j in range(len(A[i])):
        if A[i][-j-1] == '1':
            count[j] += 1
l = max(count.keys())

def rec(x):
    if x=='':
        return 0
    if '0' not in x:
        res = 0
        for i in range(len(x)):
            res += max(count[i],N-count[i])*2**i
        return res
    if x[0] == '1':
        return max(rec('1'*(len(x)-1))+count[len(x)-1]*2**(len(x)-1),rec(x[1:])+(N-count[len(x)-1])*2**(len(x)-1))
    else:
        return rec(x[1:])+count[len(x)-1]*2**(len(x)-1)
ans = rec(bin(K)[2:])
for i in range(len(bin(K)[2:]),l+1):
    ans += count[i]*2**i
print(ans)

Measured memory_bytes: 22164
#include<string>
#include<iostream>
using namespace std;
int
main(void)
{
  int a,b,c,sum;
  cin >> a >> b >> c >> sum;
  int ans = 0;

  for (int i = 0; i <= a; i++){
    for (int j = 0; j <= b; j++){
      for (int k =0; k<= c; k++){
        if ((500 * i + 100 * j + 50 * k) == sum) ans++;
      }
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
def main():
    H, W = map(int, input().split())

    if H % 3 == 0 or W % 3 == 0:
        ans = 0
    else:
        ans1 = choco(H, W)
        ans2 = choco(W, H)
        ans = min(ans1, ans2)

    print(ans)

def choco(h, w):
    i = 1
    min_ = float('inf')
    max_ = 4
    diff = float('inf')
    while i <= w / 2:
        w2 = w - i
        s1 = h * i
        s2 = h * (w2 // 2)
        s3 = h * ((w2 + 1) // 2)
        min_ = min(s1, s2, s3)
        max_ = max(s1, s2, s3)
        if max_ - min_ < diff:
            diff = max_ - min_

        s2 = h // 2 * w2
        s3 = (h + 1) // 2 * w2
        min_ = min(s1, s2, s3)
        max_ = max(s1, s2, s3)
        if max_ - min_ < diff:
            diff = max_ - min_

        i += 1

    return diff

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;
import java.util.Arrays;

public class Main {
	public static void main(final String[] args){
    
    final Scanner sc = new Scanner(System.in);
    final List<Integer> list = new ArrayList<>();
    final List<Integer> list2 = new ArrayList<>();
    //final List<Long> list3 = new ArrayList<>();

    int n = sc.nextInt();
    int count = 0;

    for(int a = 1 ; a <= n - 1 ; a++){
        count += ( n - 1 ) / a;
    }

    System.out.println(count);

    

   

    

    




    







}
}

Measured memory_bytes: 35884