akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstring>
#include<math.h>
using namespace std;

int main(){
    int m;
    cin>>m;
    long long k;
    cin>>k;
    long long r = pow(2,m)-1;
    if(k==0){
        for(int i=0;i<=r;i++){
            cout<<i<<" "<<i<<" ";
        }
        cout<<endl;
    }
    else if(k>r){
        cout<<-1<<endl;
    }
    else if(m==1 && k==1){
        cout<<-1<<endl;
    }
    else{
        for(int i=0;i<k;i++){
            cout<<i<<" ";
        }
        cout<<k<<" ";
        for(int i=k-1;i>=0;i--){
            cout<<i<<" ";
        }
        for(int i=k+1;i<=r;i++){
            cout<<i<<" ";
        }
        cout<<k<<" ";
        for(int i=r;i>k;i--){
            cout<<i<<" ";
        }
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 1792
# -*- coding: utf-8 -*-
N = int(input())
S = input()

I_count = [i for i, x in enumerate(S) if x == 'I']
D_count = [i for i, x in enumerate(S) if x == 'D']

tmp = [0] * N
for i in I_count:
    tmp[i] = 1
for i in D_count:
    tmp[i] = -1

ans = 0
List = []
for i in range(N):
    ans += tmp[i]
    List.append(ans)

print(max(0, max(List)))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define uu unsigned
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD 1000000007
#define pi pair<int,int>
#define pl pair<ll,ll>
#define mkp make_pair
#define ss second
#define ff first
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define pb push_back
#define pf push_front
#define printcas cout<<"Case "<<cas<<": "
#define _ continue;
#define endl '\n'
#define __ cout<<endl;continue;
#define vc4d(nam,type,a,b,c,d,fix) vector<vector<vector<vector<type>>>> nam(a,vector<vector<vector<type>>>(b,vector<vector<type>>(c,vector<type>(d,fix))))
const ll oo=(1ll<<60);
int gg(){
    int x=0,w=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
    if(ch=='-')w=0,ch=getchar();
    while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
    return w?x:-x;
}

ll n,m;
bool vis[200010];
vl adj[200010];
ll dfs(ll u)
{
    vis[u]=1;ll cnt=1;
    for(auto &x:adj[u] )
    {
        if(!vis[x])
        {
            cnt+=dfs(x);
        }
    }
    return cnt;
}

int main()
{
     io;
    int T=1;
    //T=gg();
    //cin>>T;
    //for(int cas=1;cas<=T;cas++)
    while(T--)
    {
       cin>>n>>m;
       ll i,j,k,l,ans=0;
       while(m--)
       {
           cin>>k>>l;
           adj[k].pb(l),adj[l].pb(k);
       }
       for(i=1;i<=n;i++)
       {
           if(!vis[i])
            ans=max(ans,dfs(i));
       }
       cout<<ans;
    }
    return 0;
}


Measured memory_bytes: 24040
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)

struct INIT{
    INIT(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(0);
        cout << fixed << setprecision(13);
    }
}INIT;

int n;
int x[101], y[101];

int main(){
    cin >> n;
    REP(i, n){
        cin >> x[i] >> y[i];
    }
    double ans = 0.0;
    REP(i, n){
        if(x[i] == 0 && y[i] == 0)continue;
        double a = -atan2(x[i], y[i]) + 1e-9;
        double tmpx1 = 0.0, tmpy1 = 0.0, tmpx2 = 0.0, tmpy2 = 0.0;
        REP(j, n){
            double sin_theta = cos(a) * y[j] - sin(a) * x[j];
            double cos_theta = cos(a) * x[j] + sin(a) * y[j];
            if(cos_theta > 0.0){
                tmpx1 += cos_theta;
                tmpy1 += sin_theta;
            }else{
                tmpx2 += cos_theta;
                tmpy2 += sin_theta;
            }
        }
        ans = max(ans, hypot(tmpx1, tmpy1));
        ans = max(ans, hypot(tmpx2, tmpy2));
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <math.h>

int main()
{
	long a, b, c, d;
	
	scanf("%lu %lu %lu", &a, &b, &c);
	
	d=c-a-b;
	
	if(d>0 && 4*a*b<d*d){ printf("Yes"); }
	else{ printf("No"); }
	
 return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#define N 500000
int it = 0, n, tree[N + 1];

void swapInt(int *x, int *y) {
	int tmp = *x;
	*x = *y;
	*y = tmp;
}
void maxHeap(int u) {
	int left, right, largest;
	left = u * 2;
	right = u * 2 + 1;

	if (left <= it && tree[u] < tree[left]) 
		largest = left;
	else 
		largest = u;
	if (right <= it && tree[largest] < tree[right])
		largest = right;

	if (largest != u) {
		swapInt(&tree[u], &tree[largest]);
		maxHeap(largest);
	}
}
int main() {
	int i;

	scanf("%d", &n);
	for (i = 1; i <= n; i++) {
		scanf("%d", &tree[i]);
		it++;
	}

	for (i = it / 2; i >= 1; i--)
		maxHeap(i);

	for (i = 1; i <= n; i++)
		printf(" %d", tree[i]);
	printf("\n");
}

Measured memory_bytes: 2980
#include<iostream>
using namespace std;
int main()
{
	int n;
	cin >> n;

	for(int i = 1;i <= n;i++)
	{
		if(i % 3 == 0 || i % 10 == 3)
		{
			cout << " " << i;
		}
		else
		{
			int j = i;
			while(j != 0)
			{
				if((j /= 10) % 10 == 3)
				{
					cout << " " << i;
					break;
				}
			}
		}
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
 
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long int x;
  cin>>x;
  if(x%11>=1&&x%11<=6){cout<<(x/11)*2+1<<endl;}
  else if(x%11==0){cout<<(x/11)*2<<endl;}
  else{cout<<(x/11+1)*2<<endl;}
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <string>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
#define pie 3.141592653589793238
using namespace std;

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m, q;
  cin >> n >> m >> q;
  vector<vector<int>> vv(q, vector<int>(4));
  vector<int> a(n, 1);
  for(int i=0; i<q; i++){
    cin >> vv[i][0] >> vv[i][1] >> vv[i][2] >> vv[i][3];
  }
  long long temp, point=0;
  while(a[0]<=m){
    temp=0;
    for(int i=0; i<q; i++){
      if((a[vv[i][1]-1]-a[vv[i][0]-1])==vv[i][2]) temp += vv[i][3];
    }
    point = max(temp, point);
    if(a[0]==m) break;
    for(int i=n-1; i>=0; i--){
      if(a[i]<m) {
        a[i]++;
        break;
      }
      else{
        int t=0;
        for(int j=n-1; j>=0; j--){
          if(a[j]<m){
            t = j;
            break;
          }
        }
        a[t]++;
        for(int j=t+1; j<n; j++){
          a[j]=a[t];
        }
        break;
      }
    }
  }
           
  cout << point << endl;
  
  return 0;
}

Measured memory_bytes: 3656
#include <functional>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <vector> 

using namespace std;

int main() {

    vector<int> v; 
    int l;

  
  
    while(cin>>l){
      
      v.push_back(l);
      
    }

sort(v.begin(), v.end());
  
   for (int i = 0; i < v.size(); ++i){
        //std::cout << v[i]; 
   }
  
int k = v.size();
  
  int kk = v[k-1]*10 + v[k-2] + v[k-3];
  
cout << kk << endl; 
  
  return 0;
}


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

#define HEAP priority_queue
#define rep(i, n) for(int i = 0, _end_ = (n); i < _end_; ++i)
#define per(i, n) for(int i = (n) - 1; i >= 0 ; --i)
#define forn(i, l, r) for(int i = (l), _end_ = (r); i <= _end_; ++i)
#define nrof(i, r, l) for(int i = (r), _end_ = (l); i >= _end_; --i)
#define FOR(a, b) for(auto (a): (b))
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define X first
#define Y second
#define eps 1e-6
#define pi 3.1415926535897932384626433832795
#define SZ(x) (int)x.size()
#define ALL(x) x.begin(), x.end()

using namespace std;

typedef long long LL;
typedef double flt;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef pair<int,int> pii;
typedef pair<int,LL> pil;
typedef pair<LL,int> pli;
typedef pair<LL,LL> pll;
typedef vector<pil> vil;
typedef vector<pii> vii;
typedef vector<pli> vli;
typedef vector<pll> vll;

const int iinf = 1e9 + 7;
const int oo = 0x3f3f3f3f;
const LL linf = 1ll << 60;
const flt dinf = 1e60;

template <typename T> inline void scf(T &x)
{
	bool f = 0;
	x = 0;
	char c = getchar();
	while(c != '-' && (c < '0' || c > '9')) c = getchar();
	if(c == '-') f = 1, c = getchar();
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	if(f) x = -x;
	return;
}

template <typename T1, typename T2> void scf(T1 &x, T2 &y)
{
	scf(x);
	return scf(y);
}

template <typename T1, typename T2, typename T3> void scf(T1 &x, T2 &y, T3 &z)
{
	scf(x);
	scf(y);
	return scf(z);
}

template <typename T1, typename T2, typename T3, typename T4> void scf(T1 &x, T2 &y, T3 &z, T4 &w)
{
	scf(x);
	scf(y);
	scf(z);
	return scf(w);
}

inline char mygetchar()
{
	char c = getchar();
	while(c == ' ' || c == '\n') c = getchar();
	return c;
}

template <typename T> inline bool chkmax(T &x, const T &y)
{
	return y > x ? x = y, 1 : 0;
}

template <typename T> inline bool chkmin(T &x, const T &y)
{
	return y < x ? x = y, 1 : 0;
}

#ifdef King_George
#define DEBUG
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif

//---------------------------------------------------------head----------------------------------------------------

const int maxn = 2e5 + 100;

vi g[maxn];
int q[maxn], fnt, rar, n, m, d[maxn];

int main()
{
	scf(n, m);
	rep(i, m){ int u, v; scf(u, v); g[u].pb(v); g[v].pb(u); }
	memset(d, -1, sizeof d);
	q[rar++] = 1;
	d[1] = 0;
	while(fnt != rar)
	{
		int u = q[fnt++];
		for(int v: g[u]) if(!~d[v]) q[rar++] = v, d[v] = d[u] + 1;
	}
	puts(d[n] == 2 ? "POSSIBLE" : "IMPOSSIBLE");
	return 0;
}

Measured memory_bytes: 13552
N = int(input())
ary = '357'
def f(s):
    if int(s) > N:
        return 0
    cnt = 1 if all(s.count(c) > 0 for c in ary) else 0
    for c in ary:
        cnt += f(s + c)
    return cnt
    
print(f("0"))

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

using namespace std;

#define re register
#define gc getchar()
#define ll long long

inline ll read() {
	re ll x(0), f(1); re char c(gc);
	while (c > '9' || c < '0') f = c == '-' ? -1 : 1, c = gc;
	while (c <= '9' && c >= '0') x = x * 10 + c -48, c = gc;
	return x * f;
}

const int N = 1e5 + 10;

int n, siz[N], hd[N], cnt, dis[N];

struct edge {int next, to;} e[N << 1];
void add (int u, int v) {e[++cnt] = (edge) {hd[u], v}, hd[u] = cnt;}
#define QXX(u) for (int i = hd[u], v; v = e[i].to, i; i =e[i].next)
void dfs (int u) {QXX(u) dis[v] = dis[u] + 1, dfs(v);}

ll d[N];
map <ll, int> id;
vector < pair <int, int> > ed;

int main () {
	n = read();
	for (int i = 1; i <= n; ++i)
		d[i] = read(), id[d[i]] = i;
	sort (d + 1, d + 1 + n);
	for (int i = 1; i <= n; ++i)
		siz[i] = 1;
	for (int i = n; i > 1; --i) {
		int u = id[d[i]];
		int res = n - 2 * siz[u];
		// cout << i <<' '<<u<<" "<<siz[u] <<" "<<res<<"  ";
		if (res <= 0) {
			puts("-1");
			return 0;
		} ll t = d[i] - res;
		if (id.count (t) == 0) {
			puts("-1");
			return 0;
		} int pos = id[t];
		add (pos, u);
		siz[pos] += siz[u];
		// cout <<pos<<" " <<u<<"  "<<siz[pos]<<" "<<siz[u]<<'\n';
		ed.push_back (make_pair(pos, u));
	} ll sum = 0;
	dfs (id[d[1]]);
	for (int i = 1; i <= n; ++i)
		sum += dis[i];
	// cout << sum << " "<< d[1] <<'\n';
	if (sum != d[1]) {
		puts("-1");
		return 0;
	} for (int i = 0; i < (int)ed.size(); ++i)
		cout << ed[i].first << " " << ed[i].second << '\n';
	return 0;
} 
/*
7 7 1 5  6 7  2 1
6 4 1 5  3 4  2 1
5 2 1 5  1 2  2 1
4 6 2 3  5 6  3 2
3 3 2 3  1 3  4 2
2 5 3 1  1 5  7 3
6 7
3 4
1 2
5 6
1 3
1 5
*/

Measured memory_bytes: 12792
#include <iostream>
#include <cstdio>
#include <string>
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 10010;
  
int main() {
    string s;
    cin >> s;

    deque<char> dQ;
    rep(i, s.size()) {
        dQ.pb(s[i]);
    }

    ll flip = 0;  // sが反転してたら1

    ll q;
    cin >> q;
    rep(loop, q) {
        ll ty;
        cin >> ty;
        if(ty == 1) {
            flip = 1 - flip;
        }
        else {
            ll f;
            char c;
            cin >> f >> c;
            f--;
            if(flip) {
                f = 1 - f;
            }
            if(f == 0) {
                dQ.push_front(c);
            }
            else {
                dQ.pb(c);
            }
        }
    }

    if(flip) {
        reverse(all(dQ));
    }

    for(auto x : dQ) {
        cout << x;
    }
    
    cout << endl;
    re0;
}

Measured memory_bytes: 896
### N = int(input(())
N, M = map(int, input().split())
D = list(map(int, input().split()))
for i in range(N,100000):
    j = i
    while j > 0:
        if j % 10 in D:
            break
        j = int(j/10)
    if j == 0:
        break
print(i)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
 using namespace std;
int main(){
 
  string s,t;
  cin>>s>>t;
  int c=0;
  for(int i=0;i<s.size();i++){
  if(s[i]!=t[i])c++;
  }
  cout<<c<<endl;
    
}

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

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int n, k;
	cin >> n >> k;
	int a[n];
	for (int i=0; i<n; i++) cin >> a[i];
	sort(a, a+n);
	int ans = 0;
	for (int i=0; i<k; i++) ans += a[i];
	cout << ans << '\n';
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10;
#define ll long long
#define ALP 26
int n;
char s[N], t[N];
struct PAM{   
	//每个节点代表一个本质不同的回文串
	struct node {
		int Next[ALP];
		int fail;
		//以节点i最后一个字符结尾的回文串个数
		//节点i表示的回文串的长度
		//节点i表示的回文串在整串中的出现次数
		//以节点i最后一个字符结尾的回文串的长度和
		int cnt, vis, len;
		node(int _len = 0) {
			memset(Next, 0, sizeof Next);
			fail = 0;
			cnt = 0;
			vis = 0;
			len = _len;
		}
	}t[N];	
    //存放添加的字符
	int s[N];         // 存放添加的字符
    //指向添加最后一个字符后的节点
	int last;         
    //已添加字符个数
	int n;            
    //节点个数
	int p;            
 
    int newnode(int len){ // 初始化节点，w=长度
        t[p] = node(len);
        return p++;
    }
    //0为长度为偶数的回文子串的根节点
    //1为长度为奇数的回文子串的根节点
    //最后节点总数是p，但是节点标号是[0, p - 1]
    void init(){
        p = 0;
        newnode(0);
        newnode(-1);
        last = 0;
        n = 0;
        s[n] = -1; 		 // 开头放一个字符集中没有的字符，减少特判
        t[0].fail = 1;
    }
    int get_fail(int x){ // 和KMP一样，失配后找一个尽量最长的
        while(s[n-t[x].len-1] != s[n]) x = t[x].fail;
        return x;
    }
	void add(int c){
		//设置偏移量
        c -= 'A';
        s[++n] = c;
		//通过上一个回文串找这个回文串的匹配位置
		int cur = get_fail(last);
		//如果这个回文串没有出现过，说明出现了一个新的本质不同的回文串
		if(!t[cur].Next[c]){
            int now = newnode(t[cur].len + 2);//新建节点
			//如果这个回文串没有出现过，说明出现了一个新的本质不同的回文串
            t[now].fail = t[get_fail(t[cur].fail)].Next[c];
            t[cur].Next[c] = now;            
		}
        last = t[cur].Next[c];
		++t[last].cnt;
        //返回的当前字符加入后是否新增了一个本质不同的回文串
		//那么此时的p - 2就表示加入这个字符后共有多少个本质不同的回文串
    }
    void gao(char *s){
		for (int i = 1, len = strlen(s + 1), now = 1; i <= len; ++i) {
			int c = s[i] - 'A';
			while (now != 1 && (!t[now].Next[c] || s[i] != s[i - t[now].len - 1]))
				now = t[now].fail;
			if (t[now].Next[c] && s[i] == s[i - t[now].len - 1]) {
				now = t[now].Next[c];
				++t[now].vis;
			} else {
				now = 1;
			}
		}
		ll res = 0;
		for (int i = p - 1;  i >= 0; --i) {
			t[t[i].fail].cnt += t[i].cnt;
			t[t[i].fail].vis += t[i].vis;
			if (i > 1)
			res += 1ll * t[i].vis * t[i].cnt;
		}
		printf("%lld\n", res);
    }
}pam;

int main() {
	while (scanf("%s%s", s + 1, t + 1) != EOF) {
		pam.init();
		for (int i = 1, len = strlen(s + 1); i <= len; ++i) {
			pam.add(s[i]);
		}
		pam.gao(t);
	}
	return 0;
}



Measured memory_bytes: 62116
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <map>
#include <utility>
#include <vector>

#define EPS (0.0000001)

using namespace std;

int mod(int n, int k) { return n % k >= 0 ? n % k : n % k + k; }

double det(pair<double, double> p, pair<double, double> q) {
  return p.first * q.second - p.second * q.first;
}

pair<double, double> sub(pair<double, double> p, pair<double, double> q) {
  return make_pair(p.first - q.first, p.second - q.second);
}

double dot(pair<double, double> p, pair<double, double> q) {
  return p.first * q.first + p.second * q.second;
}

double norm(pair<double, double> p) {
  return sqrt(p.first * p.first + p.second * p.second);
}

double angle(pair<double, double> p, pair<double, double> q) {
  return acos(min(1.0, max(dot(p, q) / (norm(p) * norm(q)), -1.0)));
}

vector<pair<double, double>> get_convex_hull(
    const vector<pair<double, double>> &p0s) {
  const int N = p0s.size();
  vector<pair<double, double>> ps(p0s);
  sort(ps.begin(), ps.end());
  vector<pair<double, double>> res;
  for (int i = 0; i < N; i++) {
    while (res.size() > 1) {
      pair<double, double> v_cur =
                               sub(res[res.size() - 1], res[res.size() - 2]),
                           v_new = sub(ps[i], res[res.size() - 2]);
      if (det(v_cur, v_new) > 0) {
        break;
      }
      res.pop_back();
    }
    res.push_back(ps[i]);
  }

  const int t = res.size();
  for (int i = N - 2; i >= 0; i--) {
    while (res.size() > t) {
      pair<double, double> v_cur =
                               sub(res[res.size() - 1], res[res.size() - 2]),
                           v_new = sub(ps[i], res[res.size() - 2]);
      if (det(v_cur, v_new) > 0) {
        break;
      }
      res.pop_back();
    }
    res.push_back(ps[i]);
  }
  res.pop_back();
  return res;
}

int main(int argc, char *argv[]) {
  // read inputs
  int N;
  vector<pair<double, double>> ps;
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    double x, y;
    scanf("%lf %lf", &x, &y);
    ps.push_back(make_pair(x, y));
  }

  if (N == 2) {
    printf("0.5\n0.5\n");
    return 0;
  }

  // get convex hull
  vector<pair<double, double>> qs = get_convex_hull(ps);
  // for (pair<double, double> &q : qs) {
  //   printf("(%lf, %lf)\n", q.first, q.second);
  // }

  // calculate answer
  vector<double> probs(N, 0);
  for (int i = 0; i < qs.size(); i++) {
    // get points
    pair<double, double> p_cur = qs[i], p_prev = qs[mod(i - 1, qs.size())],
                         p_next = qs[mod(i + 1, qs.size())];
    // calculate angles
    pair<double, double> v_prev = sub(p_cur, p_prev),
                         v_next = sub(p_next, p_cur);
    const double theta = angle(v_prev, v_next);
    // printf("(%lf, %lf) -> (%lf, %lf): %lf\n", v_prev.first, v_prev.second,
    //        v_next.first, v_next.second, theta);
    // find index
    for (int j = 0; j < N; j++) {
      if (norm(sub(p_cur, ps[j])) < EPS) {
        probs[j] = theta / (2.0 * M_PI);
        break;
      }
    }
  }

  // print answer
  for (int i = 0; i < N; i++) {
    printf("%.10lf\n", probs[i]);
  }

  return 0;
}


Measured memory_bytes: 512
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>

using namespace std;



int main() {
    int r,g,b;

    cin>>r>>g>>b;

    int res = r*100+g*10+b;

    if(res%4 == 0)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;


    return 0;
}


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

int main(void) {
  string S;
  cin >> S;
  int ok = 0, n = S.length();
  for (int i = 0; i < n; i++) {
    ok += S[i] == 'o' ? 1 : 0;
  }
  cout << (ok + (15 - n) >= 8 ? "YES" : "NO") << endl;
  return 0;
}

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

int main()
{
    int cur_max = 0;
    int max_max = 0;
    string s;
    cin >> s;
    for (int i = 0; i < 3; i++)
    {
        if (s[i] == 'R')
        {
            cur_max += 1;
        }
        else
        {
            cur_max = 0;
        }
        if (cur_max > max_max)
        {
            max_max = cur_max;
        }
    }
    cout << max_max;
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

ll func(int N, ll X, vector<ll>& num, vector<ll>& pat)
{
	if (X <= 0)
	{
		return 0;
	}
	if (X >= num[N])
	{
		return pat[N];
	}

	auto half = num[N] / 2 + 1;
	auto sum = 0ll;
	if (X < half)
	{
		sum += func(N - 1, X - 1, num, pat);
	}
	else
	{
		sum += func(N - 1, num[N - 1], num, pat);
		++sum;
		auto sub = num[N - 1] + 2;
		sum += func(N - 1, X - sub, num, pat);
	}

	return sum;
}

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

	vector<ll> num;
	vector<ll> pat;
	num.push_back(1);
	pat.push_back(1);
	for (auto i = 0; i < N; ++i)
	{
		num.push_back(num[i] * 2 + 3);
		pat.push_back(pat[i] * 2 + 1);
	}

	cout << func(N, X, num, pat) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
using namespace std;
 
int main(){
    int a,b,c,count = 0;
    scanf("%d %d %d",&a,&b,&c);
    for(int i = a; i <= b; i++){
        if(c%i == 0) count++;
    }
    printf("%d\n",count);
}


Measured memory_bytes: 2740
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
////////////////////////////

ll po(ll i,ll p){
    if(p==0)return 1;
    else{
        i=mod(i);
        if(p==1)return i;
        if(p%2==0)return po(mod(i*i),p/2);
        return mod(i*po(i,p-1));
    }
}
ll bunbo(ll n){
    return po(n,i_5);
}
#define N 200005
ll bun[N];
ll n;
ll culc(vector<ll>v){//ダメな確率
    ll res=bun[n-1];
    ll vs=v.size();
    rep(i,0,vs-1){
        Add(res,bun[n-1-v[i]]*mod(1-bun[v[i]]));
    }
    return mod(res);
}

int main(){fastio
    cin>>n;
    rep(i,0,N-1){
        bun[i]=bunbo(po(2,i));
    }
    vector<ll>v[n+1];
    rep(z,1,n-1){
        ll a,b;cin>>a>>b;
        v[a].pb(b);v[b].pb(a);
    }
    ll pa[n+1];memset(pa,-1,sizeof(pa));
    vector<ll>chi[n+1];
    queue<ll>q;q.push(1);
    pa[1]=0;
    vector<ll>idx;
    while(!q.empty()){
        ll t=q.front();q.pop();idx.pb(t);
        for(auto x:v[t]){
            if(pa[x]==-1){
                pa[x]=t;
                chi[t].pb(x);
                q.push(x);
            }
        }
    }
    reverse(idx.begin(),idx.end());
    ll sum[n+1];rep(i,1,n)sum[i]=1;
    for(auto x:idx){
        for(auto y:chi[x]){
            sum[x]+=sum[y];
        }
    }
    //cout<<sum[1];
    ll ans=0;
    rep(i,1,n){
        if(v[i].size()==1)continue;
        vector<ll>num;
        for(auto x:chi[i])num.pb(sum[x]);
        if(sum[i]!=n)num.pb(n-sum[i]);
        ll res=culc(num);
        Add(ans,(1-res)*bunbo(2));
    }
    cout<<mod(ans)<<endl;
    
    
    return 0;
}


Measured memory_bytes: 28144
h,n=map(int,input().split())
ab=[list(map(int,input().split()))for _ in range(n)]
maxa=max([a for a,b in ab])
maxmp=pow(10,8)
dp=[maxmp]*(h+maxa) # dp[i]:ダメージをぴったりi与えるのに必要な最小魔力
dp[0]=0
for i in range(h+maxa):
  b=[dp[i-a]+b for a,b in ab if i-a>=0]
  dp[i]=min(dp[i],min(b)) if b else dp[i]
print(min(dp[h:]))


Measured memory_bytes: 45532
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace Contest
{
    class Scanner
    {
        private string[] line = new string[0];
        private int index = 0;
        public string Next()
        {
            if (line.Length <= index)
            {
                line = Console.ReadLine().Split(' ');
                index = 0;
            }
            var res = line[index];
            index++;
            return res;
        }
        public int NextInt()
        {
            return int.Parse(Next());
        }
        public long NextLong()
        {
            return long.Parse(Next());
        }
        public string[] Array()
        {
            line = Console.ReadLine().Split(' ');
            index = line.Length;
            return line;
        }
        public int[] IntArray()
        {
            return Array().Select(int.Parse).ToArray();
        }
        public long[] LongArray()
        {
            return Array().Select(long.Parse).ToArray();
        }
    }

    class HashMap<K, V> : Dictionary<K, V>
    {
        new public V this[K i]
        {
            get
            {
                V v;
                return TryGetValue(i, out v) ? v : base[i] = default(V);
            }
            set { base[i] = value; }
        }
    }

    class Program
    {
        private string S;
        private void Scan()
        {
            var sc = new Scanner();
            S = sc.Next();
        }

        public void Solve()
        {
            Scan();
            int ans = S.Length;
            for (int i = 1; i < S.Length; i++)
            {
                if (S[i] != S[i - 1])
                    ans = Math.Min(ans, Math.Max(S.Length - i, i));
            }
            Console.WriteLine(ans);
        }

        static void Main(string[] args)
        {
            new Program().Solve();
        }
    }
}

Measured memory_bytes: 11616
from math import gcd

n = int(input())
a = list(map(int, input().split()))

checker = [0 for _i in range(10**6+1)]
for i in a:
    checker[i] += 1

if all(sum(checker[i::i])<2 for i in range(2,10**6+1)):
    print('pairwise coprime')
else:
    r = a[0]
    for i in a:
        r = gcd(r, i)
    if r == 1:
        print('setwise coprime')
    else:
        print('not coprime')

Measured memory_bytes: 220824
import java.util.Scanner;

//Sum of Integers II
public class Main{

	long[][][] dp;
	
	long get(int rest, int x, int s){
		if(rest==0 && s==0)return 1;
		if(rest<0 || x<0 || s<0)return 0;
		if(dp[rest][x][s]!=-1)return dp[rest][x][s];
		long res = 0;
		for(int nx=x;nx>=0;nx--)res+=get(rest-1, nx-1, s-nx);
		return dp[rest][x][s] = res;
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		dp = new long[10][101][1001];
		for(int i=0;i<10;i++)for(int j=0;j<=100;j++)for(int k=0;k<=1000;k++)dp[i][j][k]=-1;
		for(;;){
			int n = sc.nextInt(), S = sc.nextInt();
			if((n|S)==0)break;
			System.out.println(get(n, 100, S));
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 30068
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<double,int,double> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf=sizeof(Def)==sizeof(long long)?2e18:1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n;
	cin>>n;
	map<int,int>ma;
	rep(i,n){
		int a;cin>>a;
		ma[a]++;
	}
	int out=0;
	rep(t,100010)out=max(out,ma[t]+ma[t-1]+ma[t+1]);
	cout<<out<<endl;
}








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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  sort(a.begin(), a.end());

  auto ok = [&](int idx) {
    ll size = a[idx];
    rep(i,n){
      if (i == idx) continue;
      if (a[i] > 2 * size) return false;
      size += a[i];
    }
    return true;
  };
  
  if (ok(0)) {
    cout << n << endl;
    return 0;
  }

  int l = 0, r = n;
  while (r - l > 1){
    int mid = (l + r) / 2;
    if (ok(mid)) r = mid;
    else l = mid;
  }
  cout << n - r << endl;
  return 0;
} 

Measured memory_bytes: 640
#include <iostream>

using namespace std;

int count[1000];

int main(){
  int N=0,M=0;
  cin>>N>>M;
  for(int i=0;i<M;i++){
    int city1,city2;
    cin>>city1>>city2;
    count[city1]++;
    count[city2]++;
  }
  for(int j=1;j<=N;j++)
    cout<<count[j]<<endl;
  return 0;
}


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

int main(){
  int count5 = 0;
  int count7 = 0;
  int input;
  for(int i=0;i<3;i++){
    cin >> input;
    if(input == 5) count5++;
    else if(input == 7) count7++;
  }
  if(count5==2&&count7==1) cout << "YES" << endl;
  else cout << "NO" << endl;
   
}


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

using namespace std;

int v[4];

int main()
{
    long long a,b,c,k;
    cin >> v[1] >> v[2] >> v[3] >> k;

    sort(v + 1, v + 3 + 1);

    cout << v[1] + v[2] + v[3] * (1 << k) << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long int ll;
typedef long double ld;
#define pii pair<int,int>
#define pll pair<ll,ll>
 
int main()
{
	ll n,k;

	cin >> n >> k;

	ll m = n%k;
	cout << min(abs(m-k),m) << endl;
	return 0; 
}


Measured memory_bytes: 256
n,k=(int(i) for i in input().split())

p = [int(i) for i in input().split()]

max = 0

kitai = [float((p[j]+1)/2) for j in range(n)]

max=0
ans=0
for i in range(k):
    max=max+kitai[i]
ans=max
for i in range(1,n):
    if i+k-1<n:
        max=max-kitai[i-1]+kitai[i+k-1]
        if max>ans:
            ans=max


print(ans)


Measured memory_bytes: 24676
#include <iostream>
#include <iomanip>
#include <cassert>

#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <limits>
#include <queue>
#include <unordered_map>
#include <list>
#include <set>
using namespace std;

using ll = long long;

#define rep_init(i, init, n) for(int i = (init); i < (n); ++i)
#define rep(i, n) rep_init(i, 0, n)

template<typename T>
constexpr T gcd(T a, T b)
{
	if (a < b) swap(a, b);

	if (a % b == 0) return b;
	else return gcd(b, a % b);
}

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

	vector<ll> x(N);
	rep(i, N)
	{
		cin >> x[i];
		x[i] = abs(x[i] - X);
	}

	ll D = x[0];
	rep(i, N-1)
	{
		D = gcd(D, x[i+1]);
	}

	cout << D << endl;
	
	return 0;
}

Measured memory_bytes: 3936
nums = []
while True:
    in_line = raw_input().split()
    if int(in_line[0]) == 0 and int(in_line[1]) == 0:
        break
    nums.append([int(in_line[0]),int(in_line[1])])
for n in nums:
    n.sort()
    print n[0],
    print n[1]

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

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

int main() {
  int n;
  cin >> n;
  vector<int> h(n);
  REP(i, n) cin >> h[i];
  --h[0];
  bool ok = true;
  FOR(i, 1, n) {
    if (h[i - 1] < h[i]) --h[i];
    if (h[i - 1] > h[i]) ok = false;
  }
  cout << (ok ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 640
parseInt(x)=parse(Int, x)
parseMap(x::Array{SubString{String},1})=map(parseInt, x)

function main()
	s=readline() |> chomp
	ct = 0
	nw = 0
	for i in 1:length(s)
		if s[i]=='B'
			nw += 1
		else
			ct+=nw
		end
	end
	println(ct)
end

main()

Measured memory_bytes: 122748
#include <stdio.h>

int go[100000];

int main(void)
{
	int n;
	
	while (scanf("%d", &n), n != 0){
		int i, j;
		int cnt;
		
		for (i = 0; i < n; i++) scanf("%d", go + i);
		for (i = 1; i < n; i += 2){
			if (go[i - 1] != go[i]){
				for (j = i - 1; j >= 0 && go[j] != go[i]; j--){
					go[j] = go[i];
				}
			}
		}
		for (i = cnt = 0; i < n; i++) cnt += !go[i];
		printf("%d\n", cnt);
	}
	
	return 0;
}

Measured memory_bytes: 988
from collections import deque

S = input()
Q = int(input())

D1 = deque()
D2 = deque()

rev = False

for i in range(Q):
    q = input().split()
    if int(q[0]) == 1:
        if rev == True:
            rev = False
        else:
            rev = True
    else:
        f = int(q[1])
        c = q[2]
        if f == 1:
            if not rev:
                D1.appendleft(c)
            else:
                D2.append(c)
        else:
            if not rev:
                D2.append(c)
            else:
                D1.appendleft(c)


ans = ''.join(D1)+S+''.join(D2)

if not rev:
    print(ans)

else:
    print(ans[::-1])

Measured memory_bytes: 68696
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<bitset>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int N=100000+100;
const db pi=acos(-1.0);
#define lowbit(x) ((x)&(-x))
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u],v=sq[i].to;i;i=sq[i].nxt,v=sq[i].to)
#define fir first
#define sec second
#define mkp make_pair
#define pb push_back
#define maxd 1000000007
#define eps 1e-8
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
	while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
	return x*f;
}

inline ll readll()
{
	ll x=0;int f=1;char ch=getchar();
	while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
	while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
	return x*f;
}

namespace My_Math{
	#define N 100000

	int fac[N+100],invfac[N+100];

	int add(int x,int y) {return x+y>=maxd?x+y-maxd:x+y;}
	int dec(int x,int y) {return x<y?x-y+maxd:x-y;}
	int mul(int x,int y) {return 1ll*x*y%maxd;}
	ll qpow(ll x,int y)
	{
		ll ans=1;
		while (y)
		{
			if (y&1) ans=mul(ans,x);
			x=mul(x,x);y>>=1;
		}
		return ans;
	}
	int getinv(int x) {return qpow(x,maxd-2);}

	int C(int n,int m)
	{
		if ((n<m) || (n<0) || (m<0)) return 0;
		int ans=1;
		rep(i,n-m+1,n) ans=mul(ans,i);
		rep(i,1,m) ans=mul(ans,getinv(i));
		return ans;
	}

	void math_init()
	{
		fac[0]=invfac[0]=1;
		rep(i,1,N) fac[i]=mul(fac[i-1],i);
		invfac[N]=getinv(fac[N]);
		per(i,N-1,1) invfac[i]=mul(invfac[i+1],i+1);
	}
	#undef N
}
using namespace My_Math;

int calc(int n) {return C(n+15,15);}

int solve(int n)
{
	if (n<5) return 0;
	n-=5;
	int ans=0;
	rep(i,0,11)
	{
		if (i>n) break;
		if ((n-i)&1) continue;
		int tmp=mul(C(11,i),calc((n-i)/2));
		ans=add(ans,tmp);
	}
	return ans;
}

int main()
{
	int T=read();
	while (T--)
	{
		int n=read();
		printf("%d\n",solve(n));
	}
	return 0;
}

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

int n;
vector<int> A(50);

bool calc(int i, int m){
  if(m == 0) return true;
  if(i > n) return false;

  int ans = calc(i+1, m) || calc(i+1, m - A[i]);
  return ans;
  
}

int main()
{
  cin >> n;

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

  int q;
  cin >> q;
  for(int i = 0; i < q; i++){
    int x;
    cin >> x;

    if(calc(0, x)) cout << "yes" << endl;
    else cout << "no" << endl;
    
  }

  return 0;

}



Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define FOR(i,a,n) for(int i=a,i##_len=(int)n;i<i##_len;++i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i=((int)(n)-1);i>=0;--i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)   // c++14
#define SZ(c) ((int)c.size())
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0}, DY[9]={-1,0,1,0,-1,1,1,-1,0};
const int INF=1001001001; const long long INFLL=1001001001001001001ll;
template<class T> ostream& operator << (ostream &os, const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : " "); return os; }
template<class T> istream& operator >> (istream &is, vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
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;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
    #ifdef int
        cerr<<"\x1b[7m"<<"'int' is defined as 'long long' !!!!"<<"\x1b[m"<<endl;
    #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(12)<<fixed;
    }
} before_main_function;
//------------------------------------------------------------------------------

signed main() {
    int n,m,ans=0; cin>>n>>m;
    if(n<m/2) {
        ans+=n;
        m-=2*n;
        ans+=m/4;
    }
    else {
        ans=m/2;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
# coding: utf-8
import collections
N = int(input())
A=  list(map(int,input().split()))

A.sort()

c = collections.Counter(A)
A_ = list(set(A))
ans = 0
for a in A_:
    #print(c[a],a)
    if a > c[a]:
        ans += c[a]
    else:
        ans += c[a]-a
    
print(ans)

Measured memory_bytes: 25464
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int N,M;
  cin >> N >> M;
  auto c = [](P l, P r) {
    if(l.first != r.first) {
      return l.first < r.first;
    }
    return l.second > r.second;
  };

  priority_queue<P,vp,decltype(c)> que(c);
  vp tasks(N);
  rep(i,N) {
    int a,b;
    cin >> a >> b;
    tasks[i] = P(a,b);
  }
  sort(rng(tasks));
  int ans = 0;
  int index = 0;

  rep(day,M+1) {
    while(true) {
      if(index == N) break;
      if(tasks[index].first == day) {
        que.push(P(tasks[index].second,tasks[index].first));
        index++;
      } else {
        break;
      }
    }
    if(que.empty()) continue;
    ans += que.top().first;
    que.pop();
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2168
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        String S = sc.next();
        if (S.length() <= K) {
            System.out.println(S);
        } else {
            String res = S.substring(0, K) + "...";
            System.out.println(res);
        }
        sc.close();
    }
}

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

int main() {
  int N;
  cin >> N;
  int d[110];
  for(int i = 0; i < N; i++) cin >> d[i];

  set<int> values; // values.insert するときに重複するものを取り除く
  for(int i = 0; i < N; i++) {
    values.insert(d[i]);  //values配列？のような場所にd[i]をねじ込んでいく
  }
  cout << values.size() << endl;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
aa = list(map(int, input().split()))

aa.sort()
mod = 10 **9 +7
fac = [1] * 100000
inv = [1] * 100000
for i in range(1,len(fac)):
    fac[i] = fac[i-1] * i % mod
    inv[i] = pow(fac[i], mod-2, mod)
    
def combi(m, j):
    if j > m:
        return 0
    return (fac[m] * inv[m-j] * inv[j]) % mod


ret = 0
for i, a in enumerate(aa):
    n_max = combi(i, k-1)
    n_min = combi(n - 1 - i, k-1)
    ret = (ret + (n_max - n_min) * a) % mod
print(ret)

Measured memory_bytes: 16488
A,B=map(int,input().split())
set = 0
for i in range(1,20):
  if B==1:
    set -=1
    break
  elif 1<B<A:
    break
  elif A == B:
    break
  elif ((A-1)*i)+A >= B:
    set +=1
    break
  else:
    set +=1
print(set+1)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define rep(i,x) for(int i=0;i<x; i++)

using namespace std;

int main(){
  int N;
  cin>>N;
  vector<tuple<string,int,int>> a;
  for(int i = 1; i<=N; i++){
    string s;
    int p;
    cin>>s>>p;
    p = -p;

    a.push_back(tie(s,p,i));
  }

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

  rep(i,N){
    cout<<get<2>(a[i])<<endl;
  }

}


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

const int NMAX = 5e3 + 5;
const int MMAX = 2e2 + 5;
const int LMAX = 1e1 + 4;

long long dp[NMAX], dst[NMAX];
int rmq[MMAX][LMAX][NMAX], pos[NMAX], pwr[NMAX];

inline int getmax(int p, int l, int r) {
    int k = pwr[r - l + 1];
    return max(rmq[p][k][l], rmq[p][k][r - (1 << k) + 1]);
}

void solve(int le, int ri, int m) {
    int md = (le + ri) >> 1;
    
    if (le > ri)
        return;
    
    for (int k = min(md, pos[ri + 1]); k >= pos[le - 1]; --k) {
        long long cst = dst[k] - dst[md];
        
        for (int i = 1; i <= m; ++i)
            cst += getmax(i, k, md);
        
        if (dp[md] < cst)
            dp[md] = cst, pos[md] = k;
    }
    
    solve(le, md - 1, m);
    solve(md + 1, ri, m);
    return;
}

int main(void) {
    int n, m;
    cin >> n >> m;
    
    for (int i = 2; i <= n; ++i) {
        int x;
        cin >> x;
        
        dst[i] = dst[i - 1] + x;
        pwr[i] = pwr[i >> 1] + 1;
    }
    
    for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
        cin >> rmq[j][0][i];
    
    for (int p = 1; p <= m; ++p) {
    for (int k = 1; (1 << k) <= n; ++k) {
    for (int i = 1; i <= n; ++i) {
        rmq[p][k][i] = rmq[p][k - 1][i];
                
        if (i + (1 << (k - 1)) <= n)
            rmq[p][k][i] = max(rmq[p][k][i], rmq[p][k - 1][i + (1 << (k - 1))]);
    } } }
    
    pos[0] = 1; pos[n + 1] = n; solve(1, n, m);
    cout << *max_element(dp + 1, dp + n + 1);
    
    return 0;
}

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

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

const int INF = 1e9 + 7;

using namespace std;

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

	int n;
	cin >> n;

	vector<int> a(n), b(n), c(n - 1);
	rep (i, 0, n)
		cin >> a[i];
	rep (i, 0, n)
		cin >> b[i];
	rep (i, 0, n-1)
		cin >> c[i];

	int res = b[a[0] - 1];
	rep (i, 1, n) {
		res += b[a[i] - 1];
		if (a[i] - a[i - 1] == 1)
			res += c[a[i - 1] - 1];
	}

	cout << res << endl;

	return 0;
}


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;

const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


bool f(string s){
	int n=sz(s);
	if(s[0] !='A' )  return false;
	if(count(s.begin()+2, s.begin()+n-1, 'C') !=1)return false;

	int kc = count_if(all(s),[](char x){ return 'a' <=x && x <='z';});
	if(n -2 != kc) return false;
	return true;
}

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

	string s;
	while(cin >>s) puts(f(s)? "AC":"WA");
	
	
	return 0;
}


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

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

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

  int a, b;
  cin >> a >> b;
  if (10 <= (a + b)) {
    cout << "error" << endl;
  } else {
    cout << a + b << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=1;i<=n;i++)
#define pb push_back
#define pf push_front
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
ll gcd(ll x,ll y){
	if (x<y){
		ll t=x;
		x=y;
		y=t;
	}
	return x%y==0? y:gcd(y,x%y);
}
int main()
{
	ios::sync_with_stdio(false);
	ll ans=1;
	int n;
	cin>>n;
	for (int i=0;i<n;i++){
		ll t;
		cin>>t;
		ans=ans/gcd(ans,t)*t;
	}
	cout<<ans;
}

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


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

    vector<int> v(1,1);
    for(int i = 2; i<=31; i++){
        int n = i;
        while(1){
            if(n*i<=x){
                v.push_back(n*i);
                n *= i;
            }else{
                break;
            }
        }
    }
    cout << *max_element(v.begin(), v.end()) << endl;
}

Measured memory_bytes: 256