akhauriyash/Code-Regression huggingface dataset:
// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = int64_t;
using ull = uint64_t;
using PLL = pair<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace init__ {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
// #include "../debug/debug.cpp"
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

ll dfs(ll cur, ll pre, const VV<ll> &edges, bool *color) {
    ll sum = 1;
    for(ll nxt : edges[cur]) if(nxt != pre) sum += dfs(nxt, cur, edges, color);
    if(sum & 1) color[cur] = true;
    return sum;
}

bool check(bool *color, const VV<ll> &edges) {
    ll cnt = 0;
    for(ll i = 0; i < edges.size(); i++) {
        cnt += color[i];
        if(color[i]) continue;
        bool ok = true;
        for(ll nxt : edges[i]) if(color[nxt]) ok = false;
        if(ok) return true;
    }
    if(edges.size() / 2 < cnt) return true;
    return false;
}

bool solve() {
    ll N;
    cin >> N;
    VV<ll> edges(N);
    for(ll i = 1; i < N; i++) {
        ll a, b;
        cin >> a >> b;
        a--; b--;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }

    bool leaves[N] = {};
    for(ll i = 0; i < N; i++) if(edges[i].size() == 1) leaves[i] = true;

    for(ll i = 0; i < N; i++) {
        ll cnt = 0;
        for(ll nxt : edges[i]) if(leaves[nxt]) cnt++;
        if(2 <= cnt) return true;
    }

    bool color[N] = {};
    dfs(0, -1, edges, color);
    return check(color, edges);
}

int main() {
    cout << (solve() ? "First" : "Second") << endl;
    return 0;
}


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


// Useful container manipulation / traversal macros
#define fori(i,a,b)    for(int i=a;i<=b;i++)
#define ford(i,a,b)   for(int i=a;i>=b;i--)
#define all(a)        a.begin(), a.end()
#define in(a,b)       ( (b).find(a) != (b).end())
#define tr(c,i)       for(auto i = (c).begin(); i != (c).end(); i++)
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define pb             push_back
#define fill(a,v)      memset(a, v, sizeof a)

typedef long long int lli;
typedef vector<int> vi;
typedef vector<long long int> vlli;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	
	
    if (fopen("input.txt", "r")) {
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    }

    vector< pair<lli, lli> > cans;
    int n, m;
    cin>>n>>m;

    while(n--){
        lli x , y;
        cin>>x>>y;

        cans.push_back({x, y});
    }

    sort(cans.begin(), cans.end());
    int  c = 0;
    lli cost = 0;

    tr(cans, it){
        if(c >= m)
            break;

        if((c + it->second) <= m){
            c += it->second;
            cost += (it->first * it->second);
        } else if((c + it->second) > m) {
            cost += (it->first * (m - c));
            c = m;
        }
        // cout<<it->first<<it->second<<'\n';
        // cout<<c<<'\n';
//        cout<< it->first << it->second << "\n";
    }

    cout<<cost;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
int main() {
 int A,B,C,D;
  cin>> A >> B>>C>>D;
  int Aoki , Taka;
  if(A%D==0) Aoki=0;
    else Aoki =1;
  if(C%B==0) Taka=0;
    else Taka =1;
  Aoki+=A/D;
  Taka +=C/B;
  if (Aoki<Taka) cout <<"No";
  else cout<<"Yes";
}


Measured memory_bytes: 3560
template<class T> void chmax(T & a, T b) { if (a < b) a = b; }

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

template <class T>
T gcd(T a, T b) {
	return b ? gcd(b, a%b) : a;
}

void solve() {
	int N; cin >> N;
	vector<int> a(N);
	rep(i, N) scanf("%d", &a[i]);
	
	vector<int> left(N + 1, 0), right(N + 1, 0);
	for (int i = 0; i < N; i++) left[i + 1] = gcd(left[i], a[i]);
	for (int i = N - 1; i >= 0; i--) right[i] = gcd(right[i + 1], a[i]);

	int res = 0;
	rep(i, N) {
		int l = left[i];
		int r = right[i+1];

		chmax(res, gcd(l, r));
	}
	cout << res << endl;
}

int main(void) {
	solve();

	return 0;
}

Measured memory_bytes: 1408
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <unordered_map>

using namespace std;
using LL = long long;

constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;

int main() {
	LL n;
	while (cin >> n&&n) {
		int count = 0;
		while (n != 1) {
			count++;
			if (n % 2 == 0)n /= 2;
			else n = n * 3 + 1;
		}
		cout << count << endl;
	}
}

Measured memory_bytes: 3076
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics

sys.setrecursionlimit(10000001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===
def main():
    n = ni()
    a = na()

    larger = [(i + 1) - a[i] for i in range(n)]
    larger_cnt = collections.Counter(larger)

    ans = 0
    for j in range(n):
        smaller = a[j] + (j + 1)
        larger_cnt[(j + 1) - a[j]] -= 1
        if smaller in larger_cnt.keys():
            if larger_cnt[smaller] != 0:
                ans += larger_cnt[smaller]

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 44116
import sys

L,R = (int(i) for i in input().split())

mod = 2019
ans = 2018

for i in range(L,R):
    for j in range(i+1,R+1):
        temp = (i*j) % mod
        if temp < ans:
            ans = temp
        if temp ==0:
            print(0)
            sys.exit()

print(ans)


Measured memory_bytes: 38896
using System;
using System.Collections.Generic;
using System.Linq;
class Program{
    static void Main(string[] args){
    var vals = Console.ReadLine().Split().Select(x => int.Parse(x)).ToList();
    int r=vals[0];
    int D=vals[1];
    int X=vals[2];
    for(int i=2001;i<=2010;i++){
        X=r*X-D;
        Console.WriteLine(X);
    }
    }
}

Measured memory_bytes: 11220
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 1; i < n; i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define P pair<int, int>
typedef long long ll;
const ll mod = 1e9+7;

//繰り返し自乗法による累乗計算
//a**n
ll pow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = pow(a, n/2);
    return res * res;
  }
  return a * pow(a, n-1);
}
//繰り返し自乗法によるmod累乗計算
//a**n (mod)
ll modpow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = modpow(a, n/2);
    return res * res % mod;
  }
  return a * modpow(a, n-1) % mod;
}
//組み合わせ
//nCa
ll com(ll n, ll a){
  ll x = 1, y = 1;
  rep(i,a){
    x *= n-i;
    y *= i+1;
  }
  ll res = x / y;
  return res;
}
//組み合わせ(mod)
//nCa (mod)
ll modcom(ll n, ll a){
  ll x = 1, y = 1;
  rep(i, a){
    x = x * (n-i) % mod;
    y = y * (i+1) % mod;
  }
  ll ans = x * modpow(y, mod-2) % mod;
  return ans;
}
//gcd 最大公約数
ll gcd(ll x, ll y){
  if(x % y == 0) return y;
  return gcd(y, x%y);
}
//lcm 最小公倍数
ll lcm(ll x, ll y){
  return x * y / gcd(x, y);
}
//ngcd n個の最大公約数
ll ngcd(vector<ll> a){
  ll res;
  res = a[0];
  for(ll i = 1; i < a.size() && res != 1; i++) {
    res = gcd(a[i], res);
  }
  return res;
}
//nlcm n個の最小公倍数
ll nlcm(vector<ll> a) {
  ll res;
  res = a[0];
  for (ll i = 1; i < a.size(); i++) {
    res = lcm(res, a[i]);
  }
  return res;
}
// 素数判定
bool isprime(ll x){
  ll i;
  if(x < 2) return false;
  else if(x == 2) return true;
  if(x % 2 == 0) return false;
  for(i = 3; i*i <= x; i += 2){
    if(x % i == 0) return false;
  }
  return true;
}
// 桁和
ll digsum(ll x){
  ll res = 0;
  while(x > 0){
    res += x % 10;
    x /= 10;
  }
  return res;
}

int main(){
  int a, b;
  cin >> a >> b;
  int ans = 0;
  for(int i = a; i <= b; i++){
    string s = to_string(i);
    if(s[0] == s[4] && s[1] == s[3]) ans++;
  }
  cout << ans << endl;
}



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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll n,m; cin>>n>>m;
  if(abs(n-m)>1){
    cout<<0<<endl;
    return 0;
  }
  
  ll ans=1;
  if(n==m) ans=2;
  reps(i,n){
    (ans*=i)%=MOD;
  }
  reps(i,m){
    (ans*=i)%=MOD;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
W, H, N = map(int, input().split())
a1, a2, a3, a4 = 0, W, 0, H
for _ in range(N):
    x, y, a = map(int, input().split())
    if a==1:
        a1 = max(a1, x)
    elif a==2:
        a2 = min(a2, x)
    elif a==3:
        a3 = max(a3, y)
    elif a==4:
        a4 = min(a4, y)
        
if a1 <= a2 and a3 <= a4:
    print((a2-a1) * (a4-a3))
else:
    print(0)
    
  

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

int main(){
	int a, b;
	cin>>a>>b;

	if(a < b)       cout<<"a < b"<<endl;
	else if(a > b)  cout<<"a > b"<<endl;
	else if(a == b) cout<<"a == b"<<endl;

	return 0;
}

Measured memory_bytes: 1156
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
ll dp[2][1 << 21];
int a[21][21];
int main() {
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) cin >> a[i][j];
	}
	dp[0][0] = 1;
	for (int i = 0; i < N; i++) {
		for (int bit = 0; bit < (1 << N); bit++) {
			if (dp[i & 1][bit] == 0) continue;
			for (int j = 0; j < N; j++) {
				if (bit&(1 << j) || !a[i][j]) continue;
				(dp[(i + 1) & 1][bit | (1 << j)] += dp[i & 1][bit]) %= MOD;
			}
			dp[i & 1][bit] = 0;
		}
	}
	cout << dp[N & 1][(1 << N) - 1] << endl;
}

Measured memory_bytes: 33024
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int n;
string s;
int ans;

signed main() {
	cin >> n >> s;
	for (int i = 0; i < n - 2; i++) {
		if (s.substr(i, 3) == "ABC")ans++;
	}
	cout << ans<< endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<map>
using namespace std;
map<int,int> m;
int main()
{
	int n,p,x;
	int i,j;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>x;
		m[x]++;
	}
	cin>>p;
	while(p--)
	{
		cin>>x;
		if(m.count(x)) 
		{
			m[x]--;
			if(m[x]<0)
			{
			 printf("NO\n");
			return 0;
		    }
		}
		else
		{
			printf("NO\n");
			return 0;
		 } 
	}
	printf("YES\n");
 } 

Measured memory_bytes: 9600
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9 + 7;
using namespace std;

ll fact(int k) {
  ll ret = 1;
  for (int i = 1; i <= k; ++i) {
    ret *= i;
    ret %= MOD;
  }
  return ret;
}

int main() {
  int n, m;
  cin >> n >> m;
  ll ans = 0;
  if (abs(n - m) == 0)
    ans = 2 * fact(n) * fact(m) % MOD;
  else if (abs(n - m) == 1)
    ans = fact(n) * fact(m) % MOD;
  cout << ans << endl;
}

Measured memory_bytes: 256
nm = STDIN.gets.chomp.split(' ').map(&:to_i)

inputs = []

nm[1].times do
  inputs << STDIN.gets.chomp.split(' ').map(&:to_i)
end

low = inputs[0][0]
high = inputs[0][1]
inputs.each do |array|
  low = array[0] if low < array[0]
  high = array[1] if high > array[1]
end

puts [*low..high].length

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

int main() {
    int sx,sy,tx,ty;
    cin >> sx >> sy >> tx >> ty;

    for(int i=0;i<ty-sy;i++) cout << 'U';
    for(int i=0;i<tx-sx;i++) cout << 'R';
    for(int i=0;i<ty-sy;i++) cout << 'D';
    for(int i=0;i<tx-sx+1;i++) cout << 'L';
    for(int i=0;i<ty-sy+1;i++)cout << 'U';
    for(int i=0;i<tx-sx+1;i++)cout << 'R';
    cout << 'D'<<'R';
    for(int i=0;i<ty-sy+1;i++) cout <<'D';
    for(int i=0;i<tx-sx+1;i++) cout << 'L';
    cout << 'U' << endl;
}

Measured memory_bytes: 256
import math
a = list(map(int, input().split()))
N = a[0]
A = a[1]
B = a[2]
if N%(A+B)!=0:
    repTimes = math.floor(N//(A+B))
    bB = repTimes*A
    if N%(A+B) > A:
        extra = A
    else:
        extra = N%(A+B)
    bB += extra
else:
    repTimes = math.floor(N//(A+B))
    bB = repTimes * A
print(bB)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
using namespace std;
int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (a < b) {
		if (c < d)
			cout << a + c << "\n";
		else
			cout << a + d << "\n";
	} else {
		if (c < d)
			cout << b + c << "\n";
		else
			cout << b + d << "\n";
	}
}

Measured memory_bytes: 3560
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  (n : _) <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  mapM_ putStrLn . map (map toLEL) . f n $ 0

f :: Int -> Int -> [[Int]]
f 1 m = map pure [0..m]
f n m = concatMap (map <$> (:) <*> f (pred n) . max m . succ) [0..m]

toLEL :: Int -> Char
toLEL = toEnum . (fromEnum 'a' +)

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n


Measured memory_bytes: 12924
//Robs Code

/***********HEADER***************/
#include <iostream>
#include <bitset>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#include <list>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <iomanip>

/***********MACROS***************/
#define int long long int
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define endl "\n"
#define pb push_back
#define _1 first
#define _2 second
#define pii pair<int,int>

using namespace std;

const int N = 1e5 + 1;
int n,m,i,j,k,l,x,y,z,cnt[3],sum[3];

/***********MAIN**************/
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int n;
	cin >> n;
	set<string> st;
	for(int i =0 ;i<n;i++){
		string s;
		cin >> s;
		st.insert(s);
	}
	cout << st.size();
}
//........

Measured memory_bytes: 19172
#include <bits/stdc++.h>
#define rep(i, l, r) for(register int i = l; i < r; i++)
#define hrp(i, l, r) for(register int i = l; i <= r; i++)
#define rev(i, r, l) for(register int i = r; i >= l; i--)
#define pb push_back
#define int ll
#ifndef JOEON
#define D(...)
#define R(x, l)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
template<typename tn> inline tn next(void);
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v);
signed main(void)
{
	#ifdef JOEON
//		freopen("C:\Users\Joeon\Desktop\IN.txt", "r", stdin);
//		freopen("C:\Users\Joeon\Desktop\OUT.txt", "w", stdout);
	#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, a, b;
	cin>>n>>a>>b;
	hrp(i, a, b) if (!(i%n)) { cout<<"OK"<<endl; return 0;}
	cout<<"NG"<<endl;
	return 0;
}
template<typename tn> inline tn next(void)
{
	tn k;
	cin>>k;
	return k;
}
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v)
{
	rep(i, 0, v.size()) os<<v[i]<<' ';
	return os;
}

Measured memory_bytes: 3648
object Main extends App {
  import scala.io.StdIn._


  val Array(n, k)  = readLine.trim.split(' ').map(_.toInt)
  val digit = calMaxDigit(n)
  val edges = makeGraph(n)
  println(edges.length)
  if (edges.nonEmpty) println(edges.map(s ⇒ s"${s._1} ${s._2}").mkString("\n"))
  for (_ ← 0 until k){
    var result = 0
    var response = "No"
    var count = 0
    while(response != "Yes" && count <= digit) {
      println(1 << (digit - count))
      response = readLine.trim
      if (response == "No") result *= 2
      else result = (result * 2) + 1
      count += 1
    }
    if (response != "Yes") {
      println(result)
      readLine()
    }
  }
  def calMaxDigit(n: Int): Int = {
    if (n != 1) calMaxDigit(n / 2) + 1
    else 0
  }
  def makeGraph(n: Int, digit: Int = 1, result: List[(Int, Int)] = Nil): List[(Int, Int)] = {
    if (digit <= n){
      makeGraph(n, digit << 1, (1 to n).filter(i ⇒ i != digit && (i & digit) != 0).map((digit, _)).toList ++ result)
    }else result
  }
  implicit class Scope[T](val value: T) extends AnyVal {
    @inline
    def let[A](func: T ⇒ A): A = func(value)
  }
}


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

int main()
{
  int t[5] = {0, 6000, 4000, 3000, 2000};
  for (int i = 0; i < 4; i++){
    int n, a;
    cin >> a >> n;
    cout << t[a] * n << endl;
  }

  return 0;
}

Measured memory_bytes: 1160
def ABC124C_ColoringColorfully():
    S = list(input().strip())

    slen = len(S)
    ans  = 0
    for i in range(1, slen):
        if S[i] == S[i - 1]:
            ans += 1
            if S[i] == '0':
                S[i] = '1'
            else:
                S[i] = '0'
    
    print(ans)

def main():
    ABC124C_ColoringColorfully()

if __name__ == "__main__":
    main()


Measured memory_bytes: 3956
n,k = map(int,input().split())
k = min(n-1, k)
MOD = 10**9 + 7
N = 3*10**5

fact = [1]*(N+1)
rfact = [1]*(N+1)
r = 1
for i in range(1, N+1):
  fact[i] = r = r * i % MOD
rfact[N] = r = pow(fact[N], MOD-2, MOD)
for i in range(N, 0, -1):
  rfact[i-1] = r = r * i % MOD

# nPk (mod MOD) を求める
def perm(n, k):
  return fact[n] * rfact[n-k] % MOD

# nCk (mod MOD) を求める
def comb(n, k):
  return fact[n] * rfact[k] * rfact[n-k] % MOD

ans = 0
for i in range(0, k+1):
    if i == 0:
        zero_pt = 1
    else:
        zero_pt = comb(n, i)
    rest = i
    sikiri = n - i - 1
    if sikiri == 0:
        plus_pt = 1
    else:
        plus_pt = comb(rest + sikiri, sikiri)
    ans += zero_pt * plus_pt
    ans %= MOD
print(ans)



Measured memory_bytes: 26740
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include "bits/stdc++.h"
using namespace std;

int main() {
    int N;
    int a[3];
    cin >> N;
    for (int i = 0; i < 3; i ++) {
        a[i] = N % 10;
        N = N / 10;
    }

    string ans;

    if (a[0] == a[2]) {
        ans = "Yes";
    } else {
        ans = "No";
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
using namespace std;
const int maxn=1e5+5;
long long dp[maxn];
long long w[maxn],v[maxn];
int main()
{
   int n,m;
   cin>>n>>m;
   memset(dp,0,sizeof(dp));
   for(int i=1;i<=n;++i){
       cin>>w[i]>>v[i];
   }
   for(int i=1;i<=n;++i){
       for(int j=m;j>=0;--j){
           if(j-w[i]>=0) dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
       }
   }
   cout<<dp[m]<<endl;
   return 0;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(void){
    int N,K;
    cin >> N >> K;
    int B[101];
    int DP[101][4][4];

    for(int i=0;i<=100;i++){
        B[i]=0;
    }
    for(int i=1;i<=K;i++){
        int temp_A,temp_B;
        cin >> temp_A >> temp_B;
        B[temp_A]=temp_B;
    }
    
    
    for(int i=1;i<=3;i++){
        for(int j=1;j<=3;j++){
            for(int d=1;d<=N;d++){
                DP[d][i][j]=0;
            }
        }
    }    
    if(B[N-1]==0){
        for(int i=1;i<=3;i++){
            if(B[N]==0){
                for(int j=1;j<=3;j++){
                    DP[N-1][i][j]=1;
                }
            }
            else{
                DP[N-1][i][B[N]]=1;
            }
        }
    }
    else{
        if(B[N]==0){
            for(int j=1;j<=3;j++){
                DP[N-1][B[N-1]][j]=1;
            }
        }
        else{
            DP[N-1][B[N-1]][B[N]]=1;
        }
    }

    for(int d=N-2;d>=1;d--){
        if(B[d]==0){
            for(int i=1;i<=3;i++){
                for(int j=1;j<=3;j++){
                    if(i==j){
                        DP[d][i][j]=(DP[d][i][j]+DP[d+1][j][1]+DP[d+1][j][2]+DP[d+1][j][3]-DP[d+1][j][j]) % 10000;
                    }
                    else{
                        DP[d][i][j]=(DP[d][i][j]+DP[d+1][j][1]+DP[d+1][j][2]+DP[d+1][j][3]) % 10000;
                    }
                }
            }
        }
        else{
            for(int j=1;j<=3;j++){
                if(B[d]==j){
                    DP[d][B[d]][j]=(DP[d][B[d]][j]+DP[d+1][j][1]+DP[d+1][j][2]+DP[d+1][j][3]-DP[d+1][j][j]) % 10000;
                    
                }
                else{
                    DP[d][B[d]][j]=(DP[d][B[d]][j]+DP[d+1][j][1]+DP[d+1][j][2]+DP[d+1][j][3]) % 10000;
                }
            }
        }
        
    }

    int sum=0;
    for(int i=1;i<=3;i++){
        for(int j=1;j<=3;j++){
            sum+= DP[1][i][j];
        }
    }
cout << sum % 10000 << endl;

    return 0;
}



Measured memory_bytes: 3128
mod=1e9+7,dp[1<<21];
n,a,I,J,x,y,i,j;
main()
{
	for(*dp=scanf("%d",&n);~scanf("%d",&a);j=++j%n)
	{
		
		for(I=J=j?J:J*2+1;I<1<<n;)
		{
			x=I&a<<j;
			dp[I]=(dp[I]+!!x*dp[I&~x])%mod;
			x=I&-I,y=I+x;
			I=(I&~y)/x/2|y;
		}
	}
	printf("%d",dp[J]);
}

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a,s,d,f;
    cin >> a >> s >> d >> f;
    
    cout << (((a+s) < (d+f)) ? "Right" : (((a+s) > (d+f))? "Left" : "Balanced"))<< endl;
}


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

//#define DEBUG

using namespace std;

int64_t sol[3001][3001];
int64_t MOD = 998244353;

template <class T>
void print_vect(std::vector<T> v){
    for(int i = 0 ; i < v .size(); i++) cout << v[i] << " ";
    cout << endl;
}


void solve(){
    int A, B, C, D;
    cin >> A >> B >> C >>  D;
    sol[A][B] = 1;
    for(int i = B + 1 ; i <= D; i++){
        sol[A][i] = sol[A][i - 1] * A;
        sol[A][i] %= MOD;
    }
    for(int i = A+ 1 ; i <= C ;i++){
        sol[i][B] = sol[i-1][B] * B;
        sol[i][B] %= MOD;
    }
    for(int i = A + 1 ; i <= C ; i++){
        for(int j = B + 1 ; j <= D ; j++){
            sol[i][j] = sol[i-1][j] * j + sol[i][j-1] * i - ( i - 1) *( j - 1) * sol[i-1][j-1];
            sol[i][j] =  (MOD + sol[i][j] % MOD) % MOD;
        }
    }
    cout << sol[C][D] << endl;
}

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/

    #ifdef DEBUG
    int TEST_CASES = 4;
    while(TEST_CASES--){
    #endif // DEBBUG

    solve();

    #ifdef DEBUG
    }
    #endif // DEBUG
    
    return 0;
}


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

using namespace std;
typedef long long ll;

#define out(ans) cout << ans << endl
#define in(n) cin >> n
#define floop(i, N) for (ll i = 0; i < N; i++)
#define floop1(i, N) for (ll i = 1; i <= N; i++)
#define floopi(i, j, N) for (ll j = i + 1; j < N; j++)

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

constexpr int inf = 1e9;
constexpr ll linf = 1e18;

void solve();

int main()
{
    solve();
}

void solve()
{
    ll n, k;
    in(n);
    in(k);
    ll ans = 0;
    while (n > 0)
    {
        n /= k;
        ans++;
    }
    out(ans);
}

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

using namespace std;

const int N = 1e5 + 5;
const long long INF = 1e18 + 5;
const int MAXN = 1e6;
const int base = 317;

typedef long long ll;

const ll bs = 1e5 + 1;
const ll mod = 1e9 + 7;

int a, b, c, ans;

main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> a >> b >> c;
    int x = min(b, c);
    ans += x * 2;
    b -= x;
    c -= x;
    x = min(a, c);
    ans += x;
    a -= x;
    c -= x;
    cout << ans + b + (c > 0);
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int iinf = 1 << 29;
const long long linf = 1ll << 61;

#define modp(x, y) (((y) + (x) % (y)) % (y))
template<typename T> inline T gcd(T x, T y) { if(x < y) swap(x, y); T mod = x % y; if(mod == 0) return y; return gcd(y, mod); }
template<typename T> inline T lmc(T x, T y) { return x / gcd(x, y) * y; }

int main(int argc, char* argv[])
{
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);
	printf("%d\n", min( { a + b, a + c, b + c } ));

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
  string N;
  int index = 0, sum = 0;
  
  cin >> N;
  
  while (index < N.length()) {
    sum += N[index] - '0';
    index++;
  }
  
  cout << (sum % 9 == 0 ? "Yes" : "No") << endl;
  
  return 0;
}

Measured memory_bytes: 3736
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

	int N, M;
	cin >> N >> M;
	string res(N, '?');
	bool ok = true;
	REP(i, M) {
		int s, c;
		cin >> s >> c;
		--s;
		if (res[s] != '?' && res[s] != '0' + c) {
			ok = false;
		} else {
			res[s] = '0' + c;
		}
	}
	if (N > 1 && res[0] == '0') {
		ok = false;
	}
	if (!ok) {
		cout << -1 << endl;
	} else {
		REP(i, N) {
			if (res[i] == '?') {
				if (i == 0 && N > 1) {
					res[i] = '1';
				} else {
					res[i] = '0';
				}
			}
		}
		cout << res << endl;
	}

	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <bits/stdc++.h> 

using namespace std;

string s;

int main(){
    cin >> s;
    int greatCount = 0;
    int lessCount = 0;
    long long total = 0;
    int lastLessThan = 0;
    for(int i = 0; i < s.length(); i++){
        if(s.at(i) == '<'){
            if(greatCount > 0){
                lessCount = 0;
                greatCount = 0;
                lastLessThan = 0;
            }
            lessCount++;
            total += lessCount;
            lastLessThan = lessCount;
        }
        if(s.at(i) == '>'){
            if(lessCount > 0){
                lessCount = 0;
                greatCount = 0;
            }
            greatCount++;
            total += greatCount - 1;
            if(greatCount > lastLessThan){
                total++;
            }
        }
    }
    cout << total << endl;
    return 0;
}

Measured memory_bytes: 900
N,M = map(int,input().split())
k_1 = []
k_2 = []
for i in range(M):
  l,r = map(int,input().split())
  k_1.append(l)
  k_2.append(r)
if max(k_1)<=min(k_2):
  print(min(k_2)-max(k_1)+1)
else:
  print(0)


Measured memory_bytes: 11016
#include <stdio.h>

#define s(a,b) {int tmp;tmp=a;a=b;b=tmp;}

int main(){
	int l[30];
	int i,w,n,a,b;
	for(i=0;i<30;i++)l[i]=i+1;
	scanf("%d",&w);
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d,%d",&a,&b);
		s(l[a-1],l[b-1]);
	}
	for(i=0;i<w;i++)printf("%d\n",l[i]);
	return 0;
}

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

using namespace std;
                                                    
int main() {                     
	int n, m, maxi = 0;
	cin >> n >> m;
	int r = 0;
	vector<int> num(n + 1);
	for (int i = 0; i < n; ++i) {
	 	int c;
	 	cin >> c;
	 	if (num[c] == 0)
	 		++r;   
	 	++num[c];
	 	if (maxi < c)
	 		maxi = c;
	}

	int ans = 0, k = 0;        
	if (r <= m) {
		cout << 0;
	} else {              
	    sort(num.begin(), num.end());
			int p = 0;
			for (;num[p] == 0; ++p);

			while (r > m && p <= n) {
				ans += num[p];
				++p;
				--r;
			}
			cout << ans;
	}

}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
vector<vector<int>>G;
vector<bool>seen;
vector<int>cont;
void dfs(int v,int p=-1){
  seen[v]=true;

  for(auto nv:G[v]){
    if(seen[nv])continue;
    if(nv==p)continue;
    cont[nv]+=cont[v];
  
    dfs(nv,v);
  }
}
int main(){
  int N,Q;
  cin>>N>>Q;
  G.resize(N);
  seen.assign(N,false);
  cont.assign(N,0);
  for(int i=0;i<N-1;i++){
    int a,b;
    cin>>a>>b;
    a--,b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  for(int i=0;i<Q;i++){
    int dot,num;
    cin>>dot>>num;
    cont[--dot]+=num;
  }
  dfs(0);
  for(int i=0;i<N;i++){
    cout<<cont[i]<<" ";
  }
}

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

int main() {
    string S, op;
    cin >> S;

    for (int i = 0; i < 1 << 3; ++i) {
        int sum = S[0] - '0';
        for (int j = 0; j < 3; ++j) {
            if (i & (1 << j)) {
                sum += S[j + 1] - '0';
                op[j] = '+';
            }
            else {
                sum -= S[j + 1] - '0';
                op[j] = '-';
            }
        }
        if (sum == 7) break;
    }

    cout << S[0] << op[0] << S[1] << op[1] << S[2] << op[2] << S[3] << "=7" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long A,B,C,D,E,F,G,H,I,J,K,L,M,N,T,W,X,Y;
  string S;
  cin >> N >> M;
  vector<long long> vec(M),vec2(M),vec3(M);
  for (int i=0;i<M;i++) {
    cin >> A >> B;
	vec.at(i)=vec2.at(i)=A*10000000000+B;
  }
  sort(vec2.begin(),vec2.end());
  for (int i2=0;i2<M;i2++) {
    
	int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
    int right = M-1; // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

    /* どんな二分探索でもここの書き方を変えずにできる！ */
    while (right - left > 1) {
        int mid = left + (right - left) / 2;

        if (vec.at(i2)<=vec2.at(mid)) right = mid;
        else left = mid;
    }

    /* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
    vec3.at(i2)=right;
	
  }
  for (int i3=0;i3<M;i3++) {
    if (i3==0) {vec2.at(0)=(vec2.at(0)-vec2.at(0)%10000000000)/10000+1;}
	else {
      //cout << vec2.at(i3)/1000000000 << vec2.at(i3-1)/1000000000 << endl;
	  if (vec2.at(i3)/10000000000==vec2.at(i3-1)/1000000) {vec2.at(i3)=vec2.at(i3-1)+1;}
	  else {vec2.at(i3)=(vec2.at(i3)-(vec2.at(i3)%10000000000))/10000+1;}
	}
  }
  for (int i4=0;i4<M;i4++) {
    if (vec2.at(vec3.at(i4))<100000000000) {cout << 0;} 
    if (vec2.at(vec3.at(i4))<10000000000) {cout << 0;} 
    if (vec2.at(vec3.at(i4))<1000000000) {cout << 0;} 
    if (vec2.at(vec3.at(i4))<100000000) {cout << 0;} 
    if (vec2.at(vec3.at(i4))<10000000) {cout << 0;} 
    cout << vec2.at(vec3.at(i4)) << endl;
  }
}

Measured memory_bytes: 3840
#include<iostream>
#include<cstdio>
using namespace std;
int n,A[30];
int solve(int i, int m){
    if( m == 0)return 1;
    if(i >= n)return 0;
    int res = solve(i + 1, m) || solve(i+1, m-A[i]);
    return res;
}
int main(){
    int  q;
    cin >>n;
    for (int i=0; i<n; i++){
        cin >>A[i];
    }
    cin >>q;
    int m;
    for(int i=0; i<q; i++){
        cin>>m;
        if(solve(0,m)) cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }
    return 0;
}



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

int main(){

  cin.tie(0); //cin高速化
  ios::sync_with_stdio(false); //cin高速化
  
  int n;
  cin >> n;
  int ans = 0;
  
  if(n%2==0){
    ans = n;
  }else{
    ans = n*2;
  }
  
  cout << ans << endl;
  return 0;
}
    

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

int main(){
  int N,Q,l,r,output;
  int AC_count[102400]={};
  int count = 0;
  string S = "";
  cin >> N >> Q;
  cin >> S;
  for(int i=0; i<N-1; i++){
    if(S[i]=='A'){
        if(S[i+1]=='C'){
          count++;
        }
    }
    AC_count[i+1]= count;
  }
  for(int loop=0; loop<Q; loop++){
    cin >>l >>r;
    output = AC_count[r-1] - AC_count[l-1];
    cout << output << endl;
  }
  return 0;
}

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

const int64_t MOD = 1000000007;
typedef int64_t ll;
typedef uint64_t ull;

#define INF LLONG_MAX

#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

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

  int k;
  cin >> k;

  list<string> candidate;
  for(char c='a';c<='z';c++){
    if(candidate.size()>k) break;
    int pos=0;
    string searchStr = "";
    searchStr += c;
    
    while(true){
      pos = s.find_first_of(searchStr, pos);
      if(pos==string::npos) break;
      int localC = 0;
      for(int i=1;i+pos<=s.length();i++){
      	candidate.push_back(s.substr(pos,i));
        localC++;
        if(localC>k)break;
      }
      pos++;
    }
    candidate.sort();
    candidate.unique();
  }
  int count = 0;
  for(auto cand:candidate){
    count++;
    if(count==k){
      cout << cand << endl;
      break;
    }
  }

  return 0;
}



Measured memory_bytes: 5324
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " ";
#define INF 10000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    string s;
    cin >> s;
    s=s.substr(0, s.size() - 8);
    out(s);
}

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

public class Main {

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

    void solve() {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long M = sc.nextLong();
        long ans = 0;
        if (N * 2 <= M) {
            M -= 2 * N;
            ans += N;
        } else {
            M = M / 2;
            System.out.println(M);
            return;
        }
        M = M / 4;
        ans += M;
        System.out.println(ans);

    }
}


Measured memory_bytes: 23252
#include <iostream>
#include <fstream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#pragma comment(linker, "/STACK:400000000")

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(it=X.begin();it!=X.end();it++)
#define iss istringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define pi pair<int,int>
#define pb push_back
#define sec second
#define sh(i) (1LL<<i)
#define sst stringstream
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>

int dy[5],dx[5],ans;

#define id(y,x) (y*4+x)

int f(int y,int x,int mask){
    if(y==4)return 1;
    if(x==4)return f(y+1,0,mask);
    if(mask>>id(y,x)&1)return f(y,x+1,mask);
    int res=0;
    rep(i,4){
        int ny=y+dy[i],nx=x+dx[i];
        if(ny<0 || 4<=ny || nx<0 || 4<=nx
           || mask>>id(ny,nx)&1)continue;
        res+=f(y,x+1,mask|1<<id(ny,nx));
    }
    return res;
}

int main(){
	while(cin>>dx[0] && dx[0]<4){
        cin>>dy[0];
        rep2(i,1,4)cin>>dx[i]>>dy[i];
        ans=0;
        cout<<f(0,0,0)<<endl;
    }
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
using namespace std;
#define Fast_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
int n;
vector<vector<int>> a;
const int m = 1e9 + 7;
const int mask = 1 << 21;
int dp[mask][22];
int solve(int women, int i) {

	if (women == 0) {
		return 1;
	}
	if (~dp[women][i])
		return dp[women][i];
	int ans = 0;
	for (int j = 0; j < n; j++) {
		if ((women >> j) & 1) {
			if (a[i][j]) {
				women = women xor (1 << j);
				ans = (ans + solve(women, i + 1)) % m;
				women = women xor (1 << j);
			}
		}
	}
	return dp[women][i] = ans;
}

int32_t main() {
	Fast_IO
	cin >> n;
	a = vector<vector<int>>(n, vector<int>(n));
	memset(dp, -1, sizeof(dp));
	for (auto &it : a)
		for (auto &i : it)
			cin >> i;
	int men = 0, women = 0;
	for (int i = 0; i < n; i++) {
		men = men | (1 << i);
		women = women | (1 << i);
	}
	cout << solve(women, 0);
}

Measured memory_bytes: 364092
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a, b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define show(x) cout <<#x<<" = "<<(x)<<endl
#define spair(p) cout <<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define sset(s) cout<<#s<<":";each(i,s)cout <<" "<<i;cout<<endl

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 1000000;

int prime[MAX_N];
bool is_prime[MAX_N];

int sieve(int n)
{
	int p = 0;
	for(int i=0;i<=n;i++){
		is_prime[i] = true;
	}
	is_prime[0] = is_prime[1] = false;
	for(int i=2;i<=n;i++){
		if(is_prime[i]){
			prime[p++] = i;
			for(int j=2*i;j<=n;j+=i){
				is_prime[j] = false;
			}
		}
	}
	return p;
}


int main()
{
    sieve(1000000);
    while(1){
        int a,d,n;
        cin >> a >> d >> n;
        if(n == 0){
            break;
        }
        int cnt = 0;
        int ans = a;
        while(1){
            if(is_prime[ans]){
                cnt++;
                if(cnt == n){
                    cout << ans << "\n";
                    break;
                }
            }
            ans += d;
        }
    }
    return 0;
}

Measured memory_bytes: 4344
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793

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

    int m; cin >> m;
    vector<int> ans;
    for(int i = 0; i < m; i++){
        auto w = v;
        int p, x;
        cin >> p >> x;
        w[p-1] = x;
        ans.emplace_back(accumulate(w.begin(), w.end(), 0));
    }
    for(auto i: ans)
        cout << i << endl;
}


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

int main(){
        double x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;

        cout << fixed  << pow(pow((x2 - x1), 2.0) + pow((y2 - y1), 2.0), 1.0 / 2.0) << endl;
        return 0;
}


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

using namespace std;

#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define PB push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

long double EPS = 1e-9;

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

	int n, k; cin >> n >> k;
	vi v(n); FOR(i, n) cin >> v[i];

	int p = 0;
	int last = v[p];

	for(int i = k; i < n; i++){
		int now = v[i];
		if(now > last)
			cout << "Yes\n";
		else
			cout << "No\n";
		last = v[++p];
	}

	return 0;
}


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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define ALL(c) (c).begin(), (c).end()

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    rep(i, v.size()) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

int main() {
    string T;
    cin >> T;
    int n = T.size();

    V<pii> vec;
    for (auto _c : T) {
        int c = _c - '0';
        if (vec.size() == 0 || vec.back().fi != c) {
            vec.eb(c, 1);
        } else {
            vec.back().se++;
        }
    }

    debug(vec);

    ll one = 0;
    for (auto p : vec) {
        if (p.fi) {
            one += p.se;
        }
    }

    /// 111..1 -> 000..0
    ll ans = one / 2 * (one / 2 + 1) + (one % 2 ? (one + 1) / 2 : 0);
    debug(one, ans);

    ll zero = n - one;
    ll cur_zero = 0;
    ll f = 0;

    for (auto p : vec) {
        if (p.fi) {
            ans += zero * (p.se / 2);
            if (p.se & 1) {
                ans += ((cur_zero + 1 - f) / 2 + (zero - cur_zero));
            }
        } else {
            cur_zero += p.se;
        }
        f = (f + p.se) % 2;
        debug(ans);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5432
s = input()
l = len(s)
s = 'F' + s
x,y = map(int,input().split())
raw = [1]
for i in range(1,l+1):
  if s[i] == 'F':
    if s[i-1] == 'F':
      raw[-1] += 1
    else:
      raw.append(1)
  if s[i] == 'T':
    if s[i-1] == 'T':
      raw.append(0)
l2 = len(raw)
a = []
b = []
for i in range(l2):
  if i == 0:
    x -= raw[i]-1
  elif i % 2 == 0:
    a.append(raw[i])
  else:
    b.append(raw[i])
#print(raw)
#print(a,x)
#print(b,y)
nowa = {0}
for aa in a:
  lasta = nowa
  nowa = set()
  for aaa in lasta:
    nowa.add(aaa+aa)
    nowa.add(aaa-aa)
nowb = {0}
for bb in b:
  lastb = nowb
  nowb = set()
  for bbb in lastb:
    nowb.add(bbb+bb)
    nowb.add(bbb-bb)
#print(nowa,nowb)
#print(x,y)
if x in nowa and y in nowb:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 50012