akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define F first
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 100010, M = 1010;

int a, b, c, d, e, f;
int xx, yy;

bool check(int x, int y)
{
	bool flag = false;
	for (int i = 0; i * 100 * a <= x; i ++ )
		for (int j = 0; j * 100 * b <= x - i * 100 * a; j ++ )
			if (!flag && i * a * 100 + j * b * 100 == x)
			{
				flag = true;
				break;
			}
	if (!flag) return false;
	
	flag = false;
	for (int i = 0; i * c <= y; i ++ )
		for (int j = 0; j * d <= y - i; j ++ )
			if (!flag && i * c + j * d == y)
			{
				flag = true;
				break;
			}
	return flag;
}

int main()
{
	cin >> a >> b >> c >> d >> e >> f;
	
	double res = -1;
	for (int x = 0; x <= f / 100; x ++ )
		for (int y = 0; y <= x * e; y ++ )
			if (x * 100 + y <= f && check(100 * x, y))
				if (res < (double)y / (100 * x + y))
				{
					res = (double)y / (100 * x + y);
					xx = x, yy = y;
				}
				
	cout << xx * 100 + yy << ' ' << yy << endl;
	return 0;
}

Measured memory_bytes: 256
a = list(map(int,input().split()))

A = a[0]
B = a[1]
x = int(100/8*A)

if A == B:
    while 1:
        if int(x*0.08)== int(x*0.10):
            print(x)
            break
        x+=1
        if x > 10000:
            print('-1')
            break

elif A != B:
    for i in range(x,10001):
        if int(i*8/100) == A and int(i/10) == B:
            print(i)
            break 
        elif int(i*8/100) != A and int(i/10) != B and i == 10000:
            print('-1')
            break

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
double ans=(double)0;
double solve(int n,double a,double d){
if(n==0)
    return 0;
double f=a+(2*n-1)*d/2;

double a1=((2*n+2)*a+5*d)/2/n;
double d1=(n+2)*d/n;
return f+solve(n-1,a1,d1);

}
int main(){

int n,d,x;
cin>>n>>d>>x;

ans=solve(n,d,x);
printf("%.10f\n",ans);




return 0;
}


Measured memory_bytes: 6528
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
#include <tuple>
#include <bitset>
#include <ciso646>

using namespace std;

inline bool cheak(int x, int y, int xMax, int yMax){ return x >= 0 && y >= 0 && xMax > x && yMax > y; }
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
template<class T> inline T sqr(T x) { return x*x; }

typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef long long ll;
typedef unsigned long long ull;

#define For(i,a,b)	for(int (i) = (a);i < (b);(i)++)
#define rep(i,n)	For(i,0,n)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define sz(a)		(sizeof(a))
#define Fill(a,v)	fill((int*)a,(int*)(a+(sz(a)/sz(*(a)))),v)

const int dx[8] = { 1, 0, -1, 0, 1, 1, -1, -1 }, dy[8] = { 0, -1, 0, 1, -1, 1, -1, 1 };
const int mod = 1000000007;
const int INF = 1e9 + 2;


vector<vector<short>> d;

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

	vector<int> ix(n), iy(n);

	//??§?¨???§?????¨????????????
	vector<int> ax, ay;
	map<int, int> mx, my;


	rep(i, n){
		cin >> ix[i] >> iy[i];
		rep(j, 2){
			ax.push_back(ix[i] + j - 1);
			ay.push_back(iy[i] + j - 1);
		}
	}
	ax.push_back(-INF - 1);
	ay.push_back(-INF - 1);
	ax.push_back( INF + 1);
	ay.push_back( INF + 1);

	sort(all(ax));
	sort(all(ay));

	rep(i, ax.size()){
		mx[ax[i]] = i;
	}
	rep(i, ay.size()){
		my[ay[i]] = i;
	}

	//d[x][y] 0 - x  0 - y ??????????????????????±?????????????
	d.resize(ax.size() + 1, vector<short>(ay.size() + 1, 0));
	rep(i, n){
		d[mx[ix[i]]][my[iy[i]]]++;
	}
	For(x, 1, ax.size() + 1)For(y, 1, ay.size() + 1){
		d[x][y] = d[x - 1][y] + d[x][y - 1] - d[x - 1][y - 1] + d[x][y];
	}

	rep(i, m){
		int qx1, qy1, qx2, qy2;
		cin >> qx1 >> qy1 >> qx2 >> qy2;
		int rx, ry, lx, ly;
		qx1--; qy1--;
		if (mx.count(qx1)){
			lx = mx[qx1];
		}
		else{
			mx[qx1] = -1;
			auto p = mx.find(qx1);
			lx = prev(p)->second;
			mx.erase(qx1);
		}
		if (my.count(qy1)){
			ly = my[qy1];
		}
		else{
			my[qy1] = -1;
			auto p = my.find(qy1);
			ly = prev(p)->second;
			my.erase(qy1);
		}

		if (mx.count(qx2)){
			rx = mx[qx2];
		}
		else{
			mx[qx2] = -1;
			auto p = mx.find(qx2);
			rx = next(p)->second;
			mx.erase(qx2);
		}

		if (my.count(qy2)){
			ry = my[qy2];
		}
		else{
			my[qy2] = -1;
			auto p = my.find(qy2);
			ry = next(p)->second;
			my.erase(qy2);
		}

		cout << d[rx][ry] + d[lx][ly] - d[lx][ry] - d[rx][ly] << endl;

	}
	

	return 0;
}

Measured memory_bytes: 197940
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define dunk(a) cout << (a) << "\n"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n, a, b;
	cin >> n >> a >> b;
	vector<ll> x(n);
	rep(i, n) cin >> x[i];
	vector<ll> dp(n + 1);
	dp[0] = 0;
	rrep(i, n) {
		dp[i] = min(dp[i - 1] + b, dp[i - 1] + (x[i] - x[i - 1]) * a);
	}
	dunk(dp[n - 1]);
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <math.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define PI 3.14159265359
using namespace std;
using ll = long long;
using P = pair<int, int>;

ll query(ll x, vector<ll> a) {
  int n = a.size();
  ll res = 0;
  rep(i, n) {
    res += (a[i] - 1) / x;
  }
  return res;
}

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

  ll mini = 1, maxi = a[n - 1], mid;
  if (query(1, a) <= k) {
    cout << 1 << endl;
    return 0;
  }
  while (mini < maxi) {
    //cout << "mini: " << mini << ", maxi: " << maxi << endl;
    mid = (mini + maxi) / 2;
    //cout << "query(" << mid << ", a): " << query(mid, a) << endl;
    if (query(mid, a) > k) {
      mini = mid + 1;
    } else {
      maxi = mid;
    }
  }

  cout << maxi << endl;

  return 0;
}
/*
*/


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll A,B,C;

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

  cin>>A>>B>>C;
  if(C<=A+B+1) cout<<B+C<<endl;
  else{
    cout<<(A+B+1)+B<<endl;
  }

  return 0;
}


Measured memory_bytes: 256
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define shandom_ruffle random_shuffle

using ll=long long;
const int nax=57;
ll mod;

int n=50;

ll pot[nax][nax];

ll wyn;

void ff()
{
	fflush(stdout);
}

int pyt(int a, int b, int x, int y)
{
	printf("? %d %d %d %d\n", a, x, b, y);
	ff();
	int v;
	scanf("%d", &v);
	return v;
}

void szuk(int a, int b, int x, int y, int w)
{
	if (!w)
		return;
	if (a==b && x==y)
	{
		wyn+=pot[a][x];
		return;
	}
	if (a!=b)
	{
		int s=(a+b)>>1;
		int p=pyt(a, s, x, y);
		szuk(a, s, x, y, p);
		szuk(s+1, b, x, y, w-p);
	}
	else
	{
		int s=(x+y)>>1;
		int p=pyt(a, b, x, s);
		szuk(a, b, x, s, p);
		szuk(a, b, s+1, y, w-p);
	}
}

int main()
{
	int szit;
	scanf("%d%d%d%lld", &szit, &szit, &szit, &mod);
	ll trz=1;
	for (int i=0; i<n; i++)
	{
		for (int j=0; j<n; j++)
		{
			pot[i][j]=trz;
			trz=(trz*2)%mod;
		}
	}
	szuk(0, n-1, 0, n-1, 250);
	printf("! %lld\n", wyn%mod);
	ff();
	return 0;
}


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

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

map<char, string> mp;
map<string, char> mp2;

void init() {
  mp[' '] = "101";
  mp['\''] = "000000";
  mp[','] =	"000011";
  mp['-'] =	"10010001";
  mp['.'] =	"010001";
  mp['?'] =	"000001";
  mp['A'] =	"100101";
  mp['B'] =	"10011010";
  mp['C'] =	"0101";
  mp['D'] =	"0001";
  mp['E'] =	"110";
  mp['F'] =	"01001";
  mp['G'] =	"10011011";
  mp['H'] =	"010000";
  mp['I'] =	"0111";
  mp['J'] =	"10011000";
  mp['K'] =	"0110";
  mp['L'] =	"00100";
  mp['M'] =	"10011001";
  mp['N'] =	"10011110";
  mp['O'] =	"00101";
  mp['P'] =	"111";
  mp['Q'] =	"10011111";
  mp['R'] =	"1000";
  mp['S'] =	"00110";
  mp['T'] =	"00111";
  mp['U'] =	"10011100";
  mp['V'] =	"10011101";
  mp['W'] =	"000010";
  mp['X'] =	"10010010";
  mp['Y'] =	"10010011";
  mp['Z'] =	"10010000";

  mp2["00000"] = 'A';
  mp2["00001"] = 'B';
  mp2["00010"] = 'C';
  mp2["00011"] = 'D';
  mp2["00100"] = 'E';
  mp2["00101"] = 'F';
  mp2["00110"] = 'G';
  mp2["00111"] = 'H';
  mp2["01000"] = 'I';
  mp2["01001"] = 'J';
  mp2["01010"] = 'K';
  mp2["01011"] = 'L';
  mp2["01100"] = 'M';
  mp2["01101"] = 'N';
  mp2["01110"] = 'O';
  mp2["01111"] = 'P';
  mp2["10000"] = 'Q';
  mp2["10001"] = 'R';
  mp2["10010"] = 'S';
  mp2["10011"] = 'T';
  mp2["10100"] = 'U';
  mp2["10101"] = 'V';
  mp2["10110"] = 'W';
  mp2["10111"] = 'X';
  mp2["11000"] = 'Y';
  mp2["11001"] = 'Z';
  mp2["11010"] = ' ';
  mp2["11011"] = '.';
  mp2["11100"] = ',';
  mp2["11101"] = '-';
  mp2["11110"] = '\'';
  mp2["11111"] = '?';
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  init();
  string s;
  while (getline(cin, s)) {
    string t = "";
    for (int i = 0; i < (int)s.size(); i++) {
      t += mp[s[i]];
    }
    while ((int)t.size() % 5 != 0) t += "0";
    string ans = "";
    for (int i = 0; i < (int)t.size(); i += 5) {
      ans += mp2[t.substr(i, 5)];
    }
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 3228
//minamoto
#include<bits/stdc++.h>
#define R register
#define fi first
#define se second
#define pb push_back
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
#define gg(u) for(int &i=cur[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=5e5+5,inf=0x3f3f3f3f;
struct eg{int v,nx,w;}e[N<<1];int head[N],tot=1;
inline void add(R int u,R int v,R int w){
	e[++tot]={v,head[u],w},head[u]=tot;
	e[++tot]={u,head[v],0},head[v]=tot;
}
typedef pair<int,int> pi;
vector<int>es[N];int sz[N],chs[N];vector<pi>to[N];
int cur[N],dep[N],q[N],S,T,n;
inline int min(R int x,R int y){return x<y?x:y;}
bool bfs(){
	memset(dep,-1,(T-S+1)<<2);
	memcpy(cur,head,(T-S+1)<<2);
	R int h,t,u;q[h=t=1]=S,dep[S]=0;
	while(h<=t){
		u=q[h++];
		go(u)if(e[i].w&&dep[v]==-1)dep[v]=dep[u]+1,q[++t]=v;
	}
	return ~dep[T];
}
int dfs(int u,int lim){
	if(u==T||!lim)return lim;
	int flow=0,fl;
	gg(u)if(dep[v]==dep[u]+1&&(fl=dfs(v,min(lim,e[i].w)))){
		flow+=fl,lim-=fl,e[i].w-=fl,e[i^1].w+=fl;
		if(!lim)break;
	}
	if(!flow)dep[u]=-1;
	return flow;
}
int dinic(){R int res=0;while(bfs())res+=dfs(S,inf);return res;}
int vis[N],ans[N][2],ret;
void dfs(int u){
	vis[u]=1,++ret;
	for(auto v:to[u])if(!vis[v.fi]&&!ans[v.se][0])
		ans[v.se][0]=u,ans[v.se][1]=v.fi,dfs(v.fi);
}
int main(){
//	freopen("testdata.in","r",stdin);
	scanf("%d",&n),S=0,T=n<<1;
	fp(i,1,n-1){
		scanf("%d",&sz[i]),es[i].resize(sz[i]);
		fp(j,0,sz[i]-1){
			scanf("%d",&es[i][j]);
			if(es[i][j]!=1)add(es[i][j],i+n,1);
		}
	}
	R int tc=tot;
	fp(i,2,n)add(S,i,1);
	fp(i,n+1,T-1)add(i,T,1);
	if(dinic()!=n-1)return puts("-1"),0;
	for(R int i=2;i<=tc;i+=2)if(!e[i].w)chs[e[i].v-n]=e[i^1].v;
	fp(i,1,n-1)fp(j,0,sz[i]-1)if(es[i][j]!=chs[i])
		to[es[i][j]].pb(pi(chs[i],i)),to[chs[i]].pb(pi(es[i][j],i));
	dfs(1);
	if(ret!=n)return puts("-1"),0;
	fp(i,1,n-1)printf("%d %d\n",ans[i][0],ans[i][1]);
	return 0;
}

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

int main() {
  char C;
  cin >> C;
  
  if(C == 'a' || C == 'i' || C == 'u' || C == 'e' || C == 'o')
    cout << "vowel" << endl;
  else
    cout << "consonant" << endl;

}

Measured memory_bytes: 256
N,K=map(int,input().split())
p=list(map(int,input().split()))
best=0
for i in range(K):
  best+=(p[i]+1)/2
#print(best)
temp=best
for i in range(N-K):
  temp+=(p[K+i]+1)/2
  temp-=(p[i]+1)/2
  best=max(best,temp)
print(best)

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

int main(){
  int s;
  cin>>s;
  if(s==2 || s==1){
    cout<<4<<endl;
    return 0;
  }
  int i=4;
  while(s!=4){
    if(s%2==0)
      s/=2;
    else
      s=s*3+1;
    i++;
  }
  cout<<i<<endl;
}

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

int main() {
  long long n,k;
  cin>>n>>k;
  long long ans=0;
  for(long long i=k;i<=n+1;i++){
    long long x=(2*n-i+1)*i;
    long long y=(i-1)*i;
    y/=2;
    x/=2;
    x-=y-1;
    x%=1000000007;
    ans+=x;
    ans%=1000000007;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3636
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
D, T, S = map(int, input().split())

if D / S <= T:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 65012
#!/usr/bin/python3

import math
#標準出力からの読み込み
input_a = input()
x = int(input_a)

#判定ロジック
a = 100
i = 0
while True:
    i = i + 1
    a = math.floor(a*1.01)
    if a >= x:
        print(i)
        break;

Measured memory_bytes: 9168
N = gets.chomp.to_i

to = Array.new(N) { [] }
cost = Array.new(N) { [] }


(N - 1).times do |i|
  u, v, w = gets.chomp.split.map(&:to_i)
  u -= 1
  v -= 1
  to[v].push(u)
  to[u].push(v)

  cost[v].push(w)
  cost[u].push(w)
end

ans = Array.new(N) {-1}
queue = []

ans[0] = 0
queue.push(0)

while !queue.empty?
  node = queue.shift
  to[node].each_with_index do |to_node, i|
    u = to_node
    w = cost[node][i]
    # 未訪問
    if ans[u] != -1
      next
    end
    ans[u] = (ans[node] + w) % 2
    queue.push(u)
  end
end

puts ans


Measured memory_bytes: 28668
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <array>
#include <utility>
#include <queue>
#include <tuple>
#include <map>
#include <cctype>
using namespace std;
using ll = long long;
using VI = vector<int>;

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

    if (s.size() > k) {
        s.erase(k, s.size());
        s.append("...");
        cout << s << endl;
    }
    else {
        cout << s << endl;
    }

    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
using namespace std;
int d,w;
int cell[100];

int solve(int x,int y,int width){
  //widthは塀を含む
  int max_vol=0;
  for(int height=3;y+height<=d;++height){
    int min_height=10;
    for(int i=0;i<width;++i)
      min_height=min(min(cell[x+i+(y+height-1)*w],cell[x+i+y*w]),min_height);
    for(int i=0;i<height;++i)
      min_height=min(min(cell[x+(y+i)*w],cell[x+width-1+(y+i)*w]),min_height);

    bool canCreate=true;
    int vol=0;
    for(int i=1;i<=width-2;++i)
      for(int j=1;j<=height-2;++j){
        if(min_height<=cell[x+i+(y+j)*w])
          canCreate=false;
        else
          vol+=min_height-cell[x+i+(y+j)*w];
      }
    if(canCreate){
      max_vol=max(max_vol,vol);
    }
  }
  return max_vol;
}
int main(){
  while(true){
    cin>>d>>w;
    if(d==0&&w==0)
      break;
    for(int y=0;y<d;++y)
      for(int x=0;x<w;++x){
        int e;
        cin>>e;
        cell[x+y*w]=e;
      }
    int max_vol=0;
    for(int y=0;y<d;++y)
      for(int x=0;x<w;++x)
        for(int width=3;x+width<=w;++width)
          max_vol=max(max_vol,solve(x,y,width));
    cout<<max_vol<<endl;
  }
  return 0;
}



Measured memory_bytes: 3084
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>

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

using namespace std;

int a,b,c,d,e,k;
int main(){
  cin >> a >> b >> c >> d >> e >> k;
  if ( e-a <=k){
    cout << "Yay!" << endl;
  }
  else cout << ":(" << endl;
  return 0;
}


Measured memory_bytes: 256
N,M = map(int,input().split())

mod = 10**9+7
Ans = 0

if abs(N-M) == 0:
    t = 1
    for i in range(1,N+1):
        t = (t*i)%mod
    Ans = (2*t*t)%mod
elif abs(N-M) == 1:
    t1,t2 = 1,1
    for i in range(1,N+1):
        t1 = (t1*i)%mod
    for i in range(1,M+1):
        t2 = (t2*i)%mod
    Ans = (t1*t2)%mod

print(Ans)

Measured memory_bytes: 3064
s = input()
ans = "No"
if s[0] == s[1] and s[2] == s[3] and s[0] != s[2]: 
    ans = "Yes"
elif s[0] == s[2] and s[1] == s[3] and s[0] != s[1]:
    ans = "Yes"
elif s[0] == s[3] and s[1] == s[2] and s[0] != s[1]:
    ans = "Yes"
print(ans)


Measured memory_bytes: 9024
#include<iostream>
#include<math.h>
#include<string.h>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<deque>
using namespace std;

int main(){
	int n;
	cin >> n;
	while(n){
		if(n%10==9){
			cout << "Yes" << endl;
			return 0;
		}else{
			n=n/10;
		}
	}
	cout << "No" << endl;
	return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int main(){
    int n;cin>>n;
    vl a(n+1),b(n+1,0);
    rep(i,n+1)cin>>a[i];
    if(n==0){
        if(a[0]==1)cout<<1<<endl;
        else cout<<-1<<endl;
    }
    else{
        if(a[0]!=0)cout<<-1<<endl;
        else{
            b[0]=1;
            for(int i=1;i<=n;++i){
                b[i]=min((ll)INF,2*b[i-1]-a[i]);
                if(b[i]<0||(b[i]==0&&i!=n)){
                    cout<<-1<<endl;
                    return 0;
                }
            }
            b[n]=0;
            for(int i=n-1;i>=0;--i){
                b[i]=min(a[i+1]+b[i+1],b[i]);
            }
            ll ans=0;
            rep(i,n+1)ans+=a[i]+b[i];
            cout<<ans<<endl;
        }
    }
}


Measured memory_bytes: 4776
from functools import reduce

MOD = 10**9 + 7
N, K = map(int, input().split())
cnt = [0] * (K + 1)
ans = 0
for k in range(K, 0, -1):
    temp = cnt[2*k::k]
    cnt[k] = pow(K // k, N, MOD) - (reduce(lambda x, y: (x + y) % MOD, temp) if temp else 0)
    ans += (cnt[k] * k) % MOD; ans %= MOD
print(ans)

Measured memory_bytes: 12792
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <ctime>
 
using namespace std;
 
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
 
long gcd(long a, long b){
	if (a%b==0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}
}
 
long lcm(long a, long b){
	return (a*b) / gcd(a,b);
}
 
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a < b) { a = b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a > b) { a = b; return 1; } return 0; }
 
typedef long long ll;
 
const ll INF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS = 1e-10;

int n;
int h[25];

int main(){
	cin >> n;
	
	REP(i,n){
		cin >> h[i];
	}
	
	int m = 0, cnt = 0;
	
	REP(i,n){
		if (m <= h[i]){
			cnt++;
			m = h[i];
		}
	}
	
	cout << cnt << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int h, w;
char maze[401][401] = {};
bool reached[401][401] = {};
pair<ll,ll> num[160001] = {};

void dfs(int x, int y, char last_color, int area) {
    if (x < 0 || h <= x || y < 0 || w <= y) return;
    if (reached[x][y]) return;
    if (maze[x][y] == last_color) return;
    else {
        reached[x][y] = true;
        if (maze[x][y] == '#') num[area].first++;
        else num[area].second++;
        last_color = maze[x][y];
    }
    dfs (x + 1, y, last_color, area);
    dfs (x - 1, y, last_color, area);
    dfs (x, y + 1, last_color, area);
    dfs (x, y - 1, last_color, area);
}

int main() {
    cin >> h >> w;
    rep(i, 0, h) {
        rep(j, 0, w) {
            cin >> maze[i][j];
        }
    }

    ll ans = 0;
    int area = -1;
    rep(i, 0, h) {
        rep(j, 0, w) {
            if (maze[i][j] == '#') {
                area++;
                char last_color = '.';
                dfs(i, j, last_color, area);
                ans += num[area].first * num[area].second;
            }
        }
    }

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


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

int main() {
    int h, w;
    cin >> h >> w;
    
    int grid[h][w];
    for (int i = 0; i < h; ++i)
    {
        string s;
        cin >> s;
        for (int j = 0; j < w; ++j) {
            if (s[j] == '#') grid[i][j] = 1;
            else grid[i][j] = 0;
        }
    }

    int left[h][w];
    int right[h][w];
    int up[h][w];
    int down[h][w];

    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (grid[i][j]) left[i][j] = 0;
            else if (j==0) left[i][j] = 1;
            else left[i][j] = left[i][j-1] + 1;
        }
    }

    for (int i = 0; i < h; ++i) {
        for (int j = w-1; j >= 0; --j) {
            if (grid[i][j]) right[i][j] = 0;
            else if (j == w-1) right[i][j] = 1;
            else right[i][j] = right[i][j+1] + 1;
        }
    }

    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (grid[i][j]) up[i][j] = 0;
            else if (i == 0) up[i][j] = 1;
            else up[i][j] = up[i-1][j] + 1;
        }
    }

    for (int i = h-1; i >= 0; --i) {
        for (int j = 0; j < w; ++j) {
            if (grid[i][j]) down[i][j] = 0;
            else if (i == h-1) down[i][j] = 1;
            else down[i][j] = down[i+1][j] + 1;
        }
    }

    int max_sum = 0;    
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            int s = up[i][j] + down[i][j] + left[i][j] + right[i][j] - 3;
            if (grid[i][j] == 0 && s > max_sum) max_sum = s;
        }
    }

    cout << max_sum << endl;

    return 0;
}

Measured memory_bytes: 78336
#include<bits/stdc++.h>
#define N 10005
#define rank raljfds
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P2;
 
class UF{
public:
  int V;
  vector<int> par, rank, mil;
  UF(){}
  UF(int V):V(V),par(V),rank(V,0),mil(V,-1){for(int i=0;i<V;i++) par[i]=i;}
 
  int find(int x){
    assert(x<V);
    if(par[x]==x) return x;
    return par[x]=find(par[x]);
  }
   
  void unite(int x,int y){
    x=find(x), y=find(y);
    if(x==y)return;
    
    if(mil[x]!=-1) mil[y]=mil[x];
    if(mil[y]!=-1) mil[x]=mil[y];
    
    if(rank[x]<rank[y]){
      par[x]=y;
    }
    else{
      par[y]=x;
      if(rank[x]<rank[y]) rank[x]++;
    }
  }
   
  bool same(int x,int y){return find(x)==find(y);}
   
  void add_mil(int num){
    mil[num]=num;
  }
   
  int get_mil(int x){
    return mil[find(x)];
  }
};
 
int n,t,k;
vector<P2> G;
UF uf;
 
int solve(){
   
  uf=UF(n);
   
  int milnum;
   
  for(int i=0;i<t;i++){
 
    cin>>milnum;
     
    uf.add_mil(milnum-1);
  }
   
  vector<int> ans;
   
  for(int idx=0;idx<G.size();idx++){
     
    int cost=G[idx].first;
    int A=G[idx].second.first;
    int B=G[idx].second.second;
    
    if(!(uf.get_mil(A)!=-1&&uf.get_mil(B)!=-1)) uf.unite(A,B);
    else ans.push_back(cost);
    
  }
 
  sort(ans.begin(),ans.end());
 
  int res=0;

  for(int i=0;i<k;i++) res+=ans[i];
   
  return res;
}
 
int main(){
 
  int T=1;
   
  while(1){
 
    cin>>n>>t>>k;
    if(!n&&!t&&!k) break;
 
    int a,b,cost;
     
    for(int i=0;i<n-1;i++){
       
      cin>>a>>b>>cost;
       
      a--, b--;
 
      G.push_back(P2(cost,P(a,b)));
    }
     
    sort(G.begin(),G.end(),greater<P2>());
     
    cout<<"Case "<<T<<": ";
     
    cout<<solve()<<endl;
 
    G.clear();
     
    T++;
  }
   
  return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()      //昇順
#define RALL(obj) (obj).rbegin(), (obj).rend()   //降順
#define print(obj) cout << obj << endl
#define scan(obj) cin >> obj

typedef long long ll;

using namespace std;

int main(void){
    int a[4] = {};
    rep(i, 3){
        int temp1, temp2;
        cin >> temp1 >> temp2;
        a[temp1 - 1]++, a[temp2 - 1]++;
    }
    rep(i, 4){
        if(a[i] >= 3 || a[i] == 0){
            print("NO");
            return 0;
        }
    }
    print("YES");
}

Measured memory_bytes: 256
N = int(input())
list = []
for i in range(1, N + 1):
    if i % 3 == 0 and i % 5 == 0:
        "FizzBuzz"
    elif i % 3 == 0:
        "Fizz"
    elif i % 5 == 0:
        "Buzz"
    else:
        list.append(i)
print(sum(list))

Measured memory_bytes: 29928
import math
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

a,b = map(int,input().split())
g = math.gcd(a,b)
l = factorization(g)
l = list(map(lambda x:x[0],l))
lenl = len(l) if l != [1] else 0
print(lenl+1)

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

const ll MAX_P = 100001;
bool ps[MAX_P];

void sieve() {
  rep(i,MAX_P) {
    ps[i] = true;
  }
  ps[0] = false;
  ps[1] = false;
  rep(i,MAX_P) {
    if(ps[i]) {
      for(ll k=2; k*i<MAX_P; k++)
        ps[i] = false;
    }
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  ll n,m;
  cin>>n>>m;
  ll g = 1;
  if(n==1) {
    cout << m << endl;
    return 0;
  }
  for(ll k=1; k*k<=1e9; k++)  {
    if(m%k==0) {
      if(m>=n*k) {
        g = max(g,k);
      }
      if(m>=n*(m/k)) {
        g = max(g,m/k);
      }
    }
  }
  cout << g << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long N;
    cin >> N;
    map<ll, ll> a;
    for(size_t i=0;i<N; i++)
    {
        ll A;
        cin >> A;
        a[A]++;
    }
    ll elim = 0;
    for (auto e : a)
    {
        if(e.first == e.second) continue;
        else
        {
            if(e.second > e.first) elim += e.second - e.first;
            else elim += e.second;
        }
    }
    cout << elim << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 9612
n = int(input())
a = list(map(int,input().split()))

sorted_list = sorted(a,reverse = True)

Alice,Bob = 0,0 #アリスとボブの点数の宣言

for i in range(n):
    if i % 2 == 0:
        Alice += sorted_list[i]
    else:
        Bob += sorted_list[i]

ans = Alice - Bob
print(ans)


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

int main() {
	int e,x = 0,y = 0,z = 0,ans,n,i,j;
	while(1){
		ans = 10000000;
		cin >> e;
		if(e == 0)break;
		i = 1;
		while(1){
		if(i*i*i > e)break;
		i++;
		}
		i--;
		for(;i >= 0;i--){
			n = e;
			n -= i*i*i;
			z = i;
			if(n == 0){
				ans = min(ans,z);
				continue;
			}
		for(j = 0;j*j <= n;j++);
		j--;
		n -= j*j;
		y = j;
		if(n == 0){
			ans = min(ans, z+y);
			continue;
		}
		x = n;
		ans = min(ans,x+y+z);
		//cout << x << " " << y  << " " << z <<endl;
		}
		j = 1;
		while(1){
		if(j*j > e)break;
		j++;
		}
		j--;
		for(;j >= 0;j--){
			n = e;
			n -= j*j;
			if(n == 0){
				ans = min(ans,j);
			}
			else{
				ans = min(ans,j+n);
			}
		//cout << n << " " << j <<endl;
		}
	cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
from math import *
from cmath import rect

def dft(f,x):
  if len(f)==1:
    return
  f0,f1=f[0::2],f[1::2]
  dft(f0,x)
  dft(f1,x)
  z=rect(1,x*2*acos(-1)/len(f))
  n=1+0j
  for i in range(len(f)):
    f[i]=f0[i%len(f0)]+n*f1[i%len(f1)]
    n=n*z

def pm(p,q):
  siz=1
  while len(p)+len(q)>siz:
    siz*=2
  np=[]
  nq=[]
  for i in range(len(p)):
    np.append(rect(p[i],0))
  for i in range(len(q)):
    nq.append(rect(q[i],0))
  while len(np)<siz:
    np.append(0+0j)
  while len(nq)<siz:
    nq.append(0+0j)
  dft(np,1)
  dft(nq,1)
  for i in range(siz):
    np[i]=np[i]*nq[i]
  dft(np,-1)
  EPS=0.1
  for i in range(siz):
    np[i]=int(np[i].real/siz+EPS)
  return np

H,W,K=map(int,input().split())
C=[input() for i in range(H)]
DP=0
X=[]
P=0

def poly(x):
  r=[0]*x
  r.append(1)
  r[0]+=1
  return r

def knapsack(L):
  if len(L)==1:
    return poly(L[0])
  a=knapsack(L[:len(L)//2])
  b=knapsack(L[len(L)//2:])
  return pm(a,b)[:K+1]

for i in range(1,1<<H):
  X=[0]*W
  for j in range(H):
    if i&(1<<j):
      for k in range(W):
        if C[j][k]=='#':
          X[k]+=1
  DP=knapsack(X)
  if len(DP)>K:
    P+=DP[K]
print(P)

Measured memory_bytes: 75964
#include<bits/stdc++.h>
#define mp make_pair
#define fi first
#define se second
#define debug(x) cerr<<#x<<" = "<<(x)<<endl
#define eps 1e-8
#define pi acos(-1.0)
using namespace std;
void test(){cerr<<"\n";}
template<typename T,typename... Args>void test(T x,Args... args){cerr<<x<<" ";test(args...);}
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int MAXN=(int)1e5+5;
const int MOD=(int)1e9+7;
int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<(a-c)*(b-d)<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i < n; i++)
#define repd(i, n) for (int i = n-1; i > -1; i--)
#define repran(i, a,b) for (int i = a; i<b;i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> P;
int main()
{
    int n, p;
    cin >> n>> p;
    string s;
    cin >> s;
    vector<ll> div(p, 0);
    ll k = 0, base = 1;
    ll ans = 0;
    if (p == 2 or p==5){
        rep(i, n){
            if (stoi(s.substr(i, 1))%p==0){
                ans += i+1;
            }
        }
        cout << ans << endl;
        return 0;
    }
    repd(i, n){
        k += stoll(s.substr(i, 1))*base;
        k%=p;
        div[k]++;
        base *= 10;
        base %= p;
    }
    ans = div[0];
    rep(i, p){
        if (div[i]==0) continue;
        ans += (div[i]*(div[i]-1))/2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3760
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
using namespace std;
#define int long long



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

    int k,n; cin >> k >> n;
    vector<int> a(n),b(n);
    for(int i = 0;i < n;i ++) cin >> a.at(i);

    for(int i = 1;i < n;i ++) b.at(i) = a.at(i) - a.at(i-1);
    b.at(0) = a.at(0) + (k - a.at(n-1));

    int m = 0;
    for(int i = 0;i < n;i ++){
        m = max(m,b.at(i));
    }

    cout << k - m << endl;
}


Measured memory_bytes: 3456
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef long double ld;

using Graph = vector<vector<ll>>;

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; }

#define MAX_N 2010

const long long INF = 1LL << 60;

//境界値に注意！！！

int main() {
    ll n;
    cin >> n;
    for (ll i=0;i<n;i++){
        char x;
        cin >> x;
        if (x=='Y'){
            cout << "Four" << endl;
            return 0;
        }
    }
    cout << "Three" << endl;
    return 0;
}


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

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

	vector<pair<int, int>> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i].first;
		a[i].second = i + 1;
	}

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

	for (int i = 0; i < n; ++i) {
		cout << a[i].second << " ";
	}

	return 0;
}


Measured memory_bytes: 1536
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}
	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	m := getNextInt(scanner)
	seg := Segment{}
	seg.init(n)
	for i := 0; i < n; i++ {
		seg.maximize(i, getNextInt(scanner))
	}
	for i := 0; i < m; i++ {
		seg.maximize(seg.top(), seg.bucket[seg.h-1][0]>>1)
	}

	var ans int64
	for i := 0; i < n; i++ {
		ans += int64(seg.bucket[0][i])
	}

	fmt.Fprintln(writer, ans)
	writer.Flush()
}

// Segment ...
type Segment struct {
	n, h, i, chunk int
	unit           []int
	bucket         [][]int
}

func (seg *Segment) init(n int) {
	seg.n = n
	seg.unit = make([]int, 1)
	seg.unit[0] = 1
	seg.bucket = make([][]int, 1)
	seg.bucket[0] = make([]int, n)

	chunk := 2
	for i := 0; n > 1; i++ {
		n = (n-1)/chunk + 1
		seg.bucket = append(seg.bucket, make([]int, n))
		seg.unit = append(seg.unit, seg.unit[i]*chunk)
	}
	seg.h = len(seg.unit)
	seg.chunk = chunk
}

func (seg *Segment) maximize(index, value int) {
	seg.bucket[0][index] = value
	for seg.i = 0; seg.i < seg.h-1; seg.i++ {
		s := index - index%seg.chunk
		t := s + seg.chunk
		if t > len(seg.bucket[seg.i]) {
			t = len(seg.bucket[seg.i])
		}
		parent := index / seg.chunk
		max := 0
		for i := s; i < t; i++ {
			if max < seg.bucket[seg.i][i] {
				max = seg.bucket[seg.i][i]
			}
		}
		seg.bucket[seg.i+1][parent] = max
		index /= seg.chunk
	}
}

func (seg *Segment) top() int {
	index := 0
	for seg.i = seg.h - 2; seg.i >= 0; seg.i-- {
		s := index * seg.chunk
		t := s + seg.chunk
		if t > len(seg.bucket[seg.i]) {
			t = len(seg.bucket[seg.i])
		}
		for i := s; i < t; i++ {
			if seg.bucket[seg.i][i] == seg.bucket[seg.i+1][index] {
				index = i
				break
			}
		}
	}

	return index
}


Measured memory_bytes: 4480
"""
N=int(input())

print(800*N-int(N/15)*200)
"""
"""
N=int(input())
S=input()

max_n=0
temp=0
for strng in S:
	if strng=="I":
		temp+=1
		if max_n<temp:
			max_n=temp
	else:
		temp-=1
print(max_n)
"""
"""
N=int(input())

Q=1000000007
p=1
for i in range(1,N+1):
	p*=i
	p=p%Q
print(p%Q)
"""

"""
n=int(input())
S=[input() for i in range(n)]
alphabet_dict={chr(97+i):100 for i in range(26)}
for s in S:
	temp={chr(97+i):0 for i in range(26)}
	for i in s:
		temp[i]+=1

	for key in alphabet_dict.keys():
		if alphabet_dict[key]>temp[key]:
			alphabet_dict[key]=temp[key]
result=""
for item in alphabet_dict.items():
	for i in range(item[1]):
		result+=item[0]
if result=="":
	print("\n")
else:
	print(result)
"""

(N,M) = [int(i)for i in input().split()]

if N>int(M/2):
	print(int(M/2))
else:
	hoge=int(M/2)-N
	print(N+int(hoge/2))



Measured memory_bytes: 3060
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin >> n;
    vi a(n); for(auto& e : a) cin >> e;

    bool ok = true;
    rrep(i, n-1){
        if(a[i] > a[i+1]){
            a[i]--;
            if(a[i] > a[i+1]){
                ok = false;
                break;
            }
        }
    }

    cout << (ok ? "Yes":"No") << endl;

    return 0;
}


Measured memory_bytes: 640
#include <string.h>
#include <iostream>
#include <algorithm>

using namespace std;



int calc(int num1, int num2, int op){
  if(op == 0) return num1 + num2;
  return num1 - num2;
}


void solve(int *num){
  //
  char buf[3];
  for (int i = 0; i < 2; ++i) {
    int num1 = calc(num[0], num[1], i);
    if(i == 0) buf[0] = '+';
    else buf[0] = '-';

    for (int j = 0; j < 2; ++j) {
      int num2 = calc(num1, num[2], j);
      if(j == 0) buf[1] = '+';
      else buf[1] = '-';

      for (int k = 0; k < 2; ++k) {
        int num3 = calc(num2, num[3], k);
        if(k == 0) buf[2] = '+';
        else buf[2] = '-';

        if(num3 == 7){
          printf("%d%c%d%c%d%c%d=7\n", num[0], buf[0], num[1], buf[1], num[2], buf[2], num[3]);
          return;
        }
      }
    }
  }

}

int main() {
  // 入力
  string S;
  cin >> S;

  //
  int num[4];
  for (int i = 0; i < 4; ++i) {
    num[i] = stoi(S.substr(i, 1));
  }
  solve(num);

  

  return 0;
}

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

int a[364364], b[364364];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	string s;
	cin>>n>>s;
	REP(i, n){
		if(s[i]=='E'){
			a[i+1]=a[i]+1;
			b[i+1]=b[i];
		}
		else{
			a[i+1]=a[i];
			b[i+1]=b[i]+1;
		}
	}
	int ans=1<<30;
	REP(i, n){
		int e=a[n]-a[i+1];
		ans=min(ans, e+b[i]);
	}
	cout<<ans<<'\n';
	return 0;
}

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

namespace Atcoder
{

    class Program
    {
        static void Main(string[] args)
        {
            int[] abc = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int x = abc[1] + abc[2] - abc[0];
            Console.WriteLine(Math.Min(abc[1],abc[2]) + " " + Math.Max(0,x));
        }
    }
}

Measured memory_bytes: 13268
# ALDS1_1_A.py
def insertionSort(a,n):
    for i in range(N):
        v = a[i]
        j = i-1
        while j>=0 and a[j]>v:
            a[j+1]=A[j]
            j-=1
        a[j+1] = v
        print(" ".join([str(_) for _ in a]))
N = int(input())
A = list(map(int,input().split()))
insertionSort(A,N)


Measured memory_bytes: 5604
#include<bits/stdc++.h>
#define endl '\n';
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------

// snukeさんのmodint
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

// mint N;

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

// combination c(N);
// mint ans = c(N,n);
// cout << ans.x << endl;
// Nとnはll型(mintではない)
// -------------------------------------------------------------


int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  cout << 180*(N-2) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int n, m, A[100][100], b[100], c;

	scanf("%d %d\n", &n, &m);
	for (int i = 0; i < n; i++) {
		for (int j = 0;j < m;j++) {
			scanf("%d ", &A[i][j]);
		}
		scanf("\n");
	}
	for (int j = 0; j < m; j++) {
		scanf("%d\n", &b[j]);
	}
	
	for (int i = 0; i < n; i++) {
		c = 0;
		for (int j = 0;j < m;j++) {
			c += (A[i][j] * b[j]);
		}
		printf("%d\n", c);
	}
	return 0;
}

Measured memory_bytes: 2716
#include <stdio.h>
 
#define MAX 100000
 
int list[MAX] = {0};
 
void init(){
    int i;
    for(i = 0; i < MAX; i++){
        list[i] = i;
    }
}
 
int find(int n){
    if (n == list[n]) return n;
    return list[n] = find(list[n]);
}
 
int unit_friend(int a,int b){
    if (find(a) == find(b)) return 1;
    else return 0;
}
 
void unit(int a,int b){
    a = find(a);
    b = find(b);
     
    if (a == b)return;
     
    list[b]=a;
}
 
int main(void){
    int num, friend, i, s, t, q;
    init();
    scanf("%d%d", &num, &friend);
    for(i = 0; i < friend; i++){
        scanf("%d%d", &s, &t);
        unit(s,t);
    }
    scanf("%d", &q);
    for(i = 0; i < q; i++){
        scanf("%d%d", &s, &t);
        if (unit_friend(s,t) == 1) printf("yes\n");
        else printf("no\n");
    }
    return 0;
}

Measured memory_bytes: 2108
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define mod 1000000007
int main() {
    int n;
    cin >> n;
    string s1,s2;
    cin >> s1 >> s2;
    int i = 0;
    ll ret = 1;
    int mark = 0;
    //0: 空白   1: 横横  2: 縦
    while (i < n) {
        if ((i + 1 < n)&&(s1[i] == s1[i + 1])) {
            if (mark == 0) {
                ret *= 6;
            }
            else if (mark == 1) {
                ret *= 3;
            }
            else {
                ret *= 2;
            }
            i += 2;
            mark = 1;
        }
        else {
            if (mark == 0) {
                ret *= 3;
            }
            else if (mark == 1) {
                ret *= 1;
            }
            else {
                ret *= 2;
            }
            i++;
            mark = 2;
        }
        ret %= mod;
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 3596