akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i, MAT.size()){
    REP(j, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

template <typename CLASS1, typename CLASS2>
class HOGE{
  public:
    CLASS1 key;
    CLASS2 value;
    HOGE(void){
      return;
    };
    HOGE(CLASS1 key, CLASS2 value){
      this->key = key;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "key : " << key << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

unordered_map<string, ll> mp;

ll min_search(vll& l, ll A, ll B, ll C){
  ll ans = INFLL;
  sort(l.begin(), l.end());
  REP(i1, l.size()){
    FOR(i2, i1+1, l.size()){
      FOR(i3, i2+1, l.size()){
        ans = min(ans, abs(l[i1]-C)+abs(l[i2]-B)+abs(l[i3]-A));
      }
    }
  }
  return ans;
}

ll merge_search(vll l, ll A, ll B, ll C){
  //sonomama
  sort(l.begin(), l.end());
  string str=to_string((int)l[0]);
  REP(i, l.size()-1){
    str += "-" + to_string((int)l[i+1]);
  }
  if(mp.find(str)!=mp.end()) return mp[str];
  ll ans = min_search(l, A, B, C);
  if(l.size()<=3) return mp[str] = ans;
  REP(i, l.size()){
    ll shift=0;
    vll l_tmp(l.size()-1, 0);
    REP(j, l.size()-1){
      if(i==j) shift=1;
      l_tmp[j] = l[j+shift];
    }
    REP(j, l.size()-1){
      l_tmp[j] += l[i];
      ans = min(ans, merge_search(l_tmp, A, B, C)+10);
      l_tmp[j] -= l[i];
    }
  }
  return mp[str] = ans;
}

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N, A, B, C;
  cin >> N >> A >> B >> C;
  vll l(N);
  REP(i, N){
    cin >> l[i];
  }

  ll ans = merge_search(l, A, B, C);

  cout << ans << "\n";


  return 0;
}


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

int main(){
  double n;cin >> n;
  double sum = 0;
  for(int i=1;i<=n;i++){
    if(i%2 != 0)sum += 1;
  }
  printf("%.9lf\n",sum/n);
  return 0;
}


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

A = list(map(int, input().split()))

A_sort = sorted(A, reverse=True)
ALL = sum(A_sort)
cnt = 0
for c in A_sort:
    if c < ALL / (4 * M):
        break

    cnt += 1
if cnt >= M:
    print('Yes')
else:
    print('No')

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

index = 0
nums = list(map(int,input().split()))

# print('{} {}'.format(n,nums))


child_sum = 0.0
while index < n:
    child_sum = child_sum + 1/nums[index]
    index = index + 1


print('{}'.format(1/child_sum))

Measured memory_bytes: 2940
//#include<MrUnknown.h>
//#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f_(i,a,b) for (int i=a;i>=b;i--)
#define f(i,a,b) for (int i=a;i<=b;i++)
const ll mod=1000000007;

ll n,a[5],b[5],f[25000005];
int main() {
//	freopen("","r",stdin);
//	freopen("","w",stdout);
	cin>>n;
	f(j,1,3) cin>>a[j];
	f(j,1,3) cin>>b[j];
	f(i,1,n) {
		f[i]=0;
		f(j,1,3) if (i-a[j]>=0) f[i]=max(f[i],f[i-a[j]]+b[j]-a[j]);
//		cout<<f[i]<<" ";
	}
//	cout<<"\n";
	n+=f[n];
	f(i,1,n) {
		f[i]=0;
		f(j,1,3) if (i-b[j]>=0) f[i]=max(f[i],f[i-b[j]]+a[j]-b[j]);
//		cout<<f[i]<<" ";
	}
//	cout<<"\n";
	n+=f[n];
	cout<<n;
	return 0;
}

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

#define all(n) n.begin(),n.end()
#define ll long long
#define int long long
#define pb push_back
#define eb emplace_back
#define endl "\n"
#define pll pair<ll,ll>

#define ff first
#define ss second

using namespace std;
const ll maxn=2e7+2;
const ll maxx=1e16;
const ll mod=998244353;
const ll mod1=998244353;

vector<ll>  ans[maxn];

ll cnt[maxn];
main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   ll n;
    cin>>n;

    ll ans=0;
    for (int i=1;i<=n;i++)
    {
        for (int j=i;j<=n;j+=i)
        {
            cnt[j]++;
        }
        ans+=i*cnt[i];
    }
    cout <<ans;




}


Measured memory_bytes: 550524
def solve():
    N,K = map(int , input().split())
    A = list(map(int , input().split()))
    max_total = 22361 # sqrt(10**6 * 500)
    total = sum(A)
    search_space = set([])

    max_d = 1
    for d in range(1, min(total, max_total) ):
        if total % d == 0:
            search_space.add(d)
            search_space.add(total // d)
    
    # print(search_space)
    
    for d in search_space:
        if total % d == 0:
            remainders = [a%d for a in A]
            remainders = sorted(remainders)
            # print(d, remainders)
            positive_rem = 0
            negative_rem = 0
            flag = True
            for rem in remainders:
                if positive_rem+rem <= K:
                    positive_rem += rem
                elif negative_rem+(d-rem) <=K:
                    negative_rem += (d-rem)
                else: 
                    flag = False
                    break

            if flag and d > max_d:
                # print(d, remainders, positive_rem, negative_rem)
                max_d = d
            
    print(max_d)
    
solve()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
  
using namespace std;
using namespace __gnu_pbds;
 
#define ll long long
#define uint unsigned int
#define ull  unsigned long long
#define pb push_back
#define mk make_pair
#define ins insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define X first
#define Y second
#define umap unordered_map
#define speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define setvalue(d,s,e,n) for(int qwe = s; qwe < e; ++qwe) d[qwe] = n
#define mset multiset
#define pqueue priority_queue
   
template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
        
const int  N = 1e3 + 314;
const int INF = 1e9;
const double PI = acos(-1);
const int MOD = 1e9 + 7;
const double eps = 1e-9;
const long long LINF = 1e18 + 3141;
int dp[N][N];
char a[N][N];
int n, m;

void solve(){
    cin >> n >> m;
    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= m; ++j)
            cin >> a[i][j];
    dp[1][1] = 1;
    for(int i = 1; i <= n; ++i){
        for(int j = 1; j <= m; ++j){
            if((i != 1 || j != 1) && a[i][j] != '#'){  
                dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD;
            }
        }
    }
    cout << dp[n][m];
}
 
int main(){
    speed();
    int t = 1;

    // cin >> t;
    while(t--)solve();
}

Measured memory_bytes: 8064
while True:
    try:
        m = int(raw_input())
        a = sorted([list(map(int, raw_input().split())) for i in range(m)])
        dax = [a[i][0]-a[0][0] for i in range(m)]
        n = int(raw_input())
        b = sorted([list(map(int, raw_input().split())) for i in range(n)])
        bx = [b[i][0] for i in range(n)]
        for i in range(n-m+1):
            for j in range(m):
                if bx[i]+dax[j] not in bx:
                    break
            else:
                print b[i][0]-a[0][0],b[i][1]-a[0][1]
                break
    except:
        break

Measured memory_bytes: 4480
#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 getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#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 ll inf =1LL << 62;
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) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

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

    int a, p; cin >> a >> p;
    cout << (p + a * 3) / 2 << endl;

    return 0;
}


Measured memory_bytes: 256
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String l = scanner.nextLine();
        BigDecimal d = new BigDecimal(l);
        BigDecimal a = new BigDecimal("3.0");
        BigDecimal r = d.divide(a, 10, RoundingMode.HALF_EVEN);
        BigDecimal result = r.pow(3);
        System.out.println(result);
    }
}

Measured memory_bytes: 21460
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#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 std;
using namespace __gnu_pbds; 

#define int long long
#define pb push_back
#define pf push_front
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define f first
#define s second
#define sz(x) (int)x.size()
#define endl "\n"
#define forn(i,n) for(int i=0;i<n;++i)
#define fore(i,l,r) for(int i=int(l);i<=int(r);++i)
#define rep(i,begin,end) for(__typeof(end) i=(begin);i!=(end);i++)
#define fill(a,value) memset(a,value,sizeof(a));
#define gcd(a,b) __gcd((a),(b))
#define watch1(x) cout<<(x)<<endl
#define watch2(x,y) cout<<(x)<<" "<<(y)<<endl
#define watch3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld; 
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;

const int INF = 9e18;
const int mod = 1e9 + 7;
const int N = 1e4 + 5;

vi num;
int dp[N][105][2],d;

int calc(int pos,int sum,int f)
{
    if(pos==sz(num))
        return sum==0;
    if(dp[pos][sum][f]!=-1)
        return dp[pos][sum][f];
    int ans=0,mx;
    if(!f)
        mx=num[pos];
    else
        mx=9;
    for(int dig=0;dig<=mx;dig++)
    {
        int nf=f,nsum=sum;
        if(!f && dig<mx)
            nf=1;
        nsum=(sum+dig)%d;
        ans+=calc(pos+1,nsum,nf);
        ans%=mod;
    }
    return dp[pos][sum][f]=ans;
}

int solve(string k)
{
    for(int i=0;i<sz(k);i++)
    {
        num.pb(k[i]-'0');
    }
    fill(dp,-1);
    int ans=calc(0,0,0);
    return ans;
}

void solve()
{
    string k;
    cin>>k>>d;
    int ans=solve(k);
    cout<<(ans-1+mod)%mod;
}

signed main()
{
    fastio;
    int t;
    //cin>>t;
    t=1;
    while(t--)
    {
        solve();
    }
    return 0;
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,n) for(int i=(int)(n-1);i>=0;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x"=" << x <<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;

#define INF INT_MAX/3

#define MAX_N 1000000001

int main(){
	cin.sync_with_stdio(false);
	string str;
	cin >> str;

	int alphabet[26] = {};

	rep(i, str.size()) {
		alphabet[str[i] - 'a']++;
	}

	bool ok = true;
	rep(i, 26) {
		if (alphabet[i] % 2 == 1) {
			ok = false;
			break;
		}
	}
	cout << ((ok) ? "Yes" : "No") << endl;

	return 0;
}


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

int main() {
    int n, k, cnt = 0;
    ;
    cin >> n >> k;
    vector<int> a;
    while(n) {
        a.push_back(n % k);
        n /= k;
        cnt++;
    }
    reverse(a.begin(), a.end());
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3612
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end
def debug(k,v) puts "#{k}: #{v}" end
def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

#$stdin = File.open('input.txt')
puts gi>=30 ? 'Yes' : 'No'


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

int main() {

  int a,b,c,d,e;

  // nameに10を代入
  cin >>a>>b;
c=a+b;
d=a-b;
e=a*b;

if(c>=d && c>=e){
 cout<<c<<endl;
  }else if(d>=c && d>=e){
 cout<<d<<endl;
  }else if(e>=c && e>=d){
 cout<<e<<endl;
  }





}


Measured memory_bytes: 256
def main():
  n=int(input())
  h = list(map(int,input().split()))
  ans=0
  for i in range(0,n):
    flg=0
    for j in range(0,i):
      if h[i]<h[j]:
        flg=1
        break
    if flg==0:
      ans+=1
  print(ans)
main()

Measured memory_bytes: 9084
import numpy as np
from numba import njit


@njit('i8(i8)', cache=True)
def solve(x):
    count = np.zeros(x + 1, dtype=np.int64)
    for i in range(1, x + 1):
        for j in range(i, x + 1, i):
            count[j] += j
    return count.sum()


if __name__ == "__main__":
    x = int(input())
    print(solve(x))



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

typedef long long ll;

#define pb push_back
#define mkp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define clr(a, b) memset(a, b, sizeof(a))
#define forn(i, n) for(int i=0; i<(int)(n); ++i)
#define forab(i, a, b) for(int i=(int)(a); i<=(int)(b); ++i)
#define FOR(it,c) for ( __typeof((c).begin()) it=(c).begin(); it!=(c).end(); it++ )
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 2e5 + 5;
char beg[N], en[N];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifdef LOCAL
    clock_t tStart = clock();
#endif
    forn(i, N) beg[i] = '-', en[i] = '-';
    string s;
    cin >> s;
    int q;
    cin >> q;
    int x = 0, ind1 = N-1, ind2 = 0;
    forn(i, q) {
        int f;
        cin >> f;
        if(f == 2) {
            int y;
            cin >> y;
            char z; 
            cin >> z;
            if(x&1) {
              if(y == 1) y = 2;
              else y = 1; 
            }
            //  
            if(y == 1)
                beg[ind1] = z, --ind1;
            else
                en[ind2] = z, ++ind2;
        } else ++x;
    }
    string pp = "";
    for(int i=N-1; i>=0; --i) {
        if(beg[i] == '-') break;
        pp += beg[i];
    }
    reverse(all(pp));
    for(int i=0; i<N; ++i) {
        if(en[i] == '-') break;
        s += en[i];
    }
    s = pp + s;
    if(x&1)
        reverse(all(s));
    cout << s << "\n";

#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * (clock() - tStart)/ CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


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

#define File(s) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
const int N = 55, M = 105;

const int mod = 1000000007;
inline int add(int x, int y){return x+y>=mod ? x+y-mod : x+y;}
inline int sub(int x, int y){return x-y<0 ? x-y+mod : x-y;}
inline int mul(int x, int y){return 1LL * x * y % mod;}
inline void inc(int &x, int y=1){x = x+y>=mod ? x+y-mod : x+y;}
inline void dec(int &x, int y=1){x = x-y<0 ? x-y+mod : x-y;}
inline int power(int x, int y){
	int res = 1;
	for(; y; y>>=1, x = mul(x, x)) if(y & 1) res = mul(res, x);
	return res;
}
inline int inv(int x){return power(x, mod - 2);}

vector<int> G[N];
int dfn[N], low[N], idx = 0;
int stke[M], tope = 0, eid = 0;
int stkv[M], topv = 0;
int n, m, k, res = 1;

int C[M*2][M*2];
void preC(int n){
	C[0][0] = 1;
	for(int i=1; i<=n; i++){
		C[i][0] = 1;
		for(int j=1; j<=i; j++)
			C[i][j] = add(C[i-1][j], C[i-1][j-1]);
	}
}

int gcd(int x, int y){
	int t;
	while(y) t = x, x = y, y = t % y;
	return x;
}

void dfs(int x, int fa){
	dfn[x] = low[x] = ++idx;
	stkv[++topv] = x;
	for(int v : G[x]){
		if(!dfn[v]){
			stke[++tope] = ++eid;
			int eidNow = eid;
			dfs(v, x);
			low[x] = min(low[x], low[v]);
			if(low[v] >= dfn[x]){
				int ce = 0, cv = 0;
				while(stke[tope] != eidNow) --tope, ++ce;
				--tope; ++ce;
				while(stkv[topv] != v) --topv, ++cv;
				--topv; cv += 2;
				if(ce == 1) res = mul(res, k);
				else if(ce == cv){
					int sum = 0;
					for(int i=0; i<cv; i++)
						inc(sum, power(k, gcd(i, cv)));
					res = mul(res, mul(sum, inv(cv)));
				}
				else res = mul(res, C[ce + k - 1][k - 1]);
			}
		}
		else if(v != fa && dfn[v] < dfn[x]){
			low[x] = min(low[x], dfn[v]);
			stke[++tope] = ++eid;
		}
	}
}

int main(){
	scanf("%d%d%d", &n, &m, &k);
	preC(m + k);
	for(int i=1; i<=m; i++){
		int u, v; scanf("%d%d", &u, &v);
		G[u].push_back(v); G[v].push_back(u);
	}
	for(int i=1; i<=n; i++)
		if(!dfn[i]) dfs(i, i);
	printf("%d\n", res);
	return 0;
}

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

int main()
{
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    ll count = 0;

    if (k - a <= 0)
    {
        cout << k << endl;
    }
    else if (k - a > 0)
    {
        count += a;
        k -= a;
        if (k - b <= 0)
        {
            cout << count << endl;
        }
        else
        {
            k -= b;
            if (k - c < 0)
            {
                cout << count - k;
            }
            else
            {

                cout << count - c;
            }
        }
    }
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define fill( x, y ) memset( x, y, sizeof x )
#define copy( x, y ) memcpy( x, y, sizeof x )
using namespace std;

typedef long long LL;
typedef pair < int, int > pa;

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

const int MAXN = 100010;

int f[MAXN], g[MAXN], n;
vector < int > G[MAXN];

inline void dfs(int x, int fa = 0)
{
	f[ x ] = 1, g[ x ] = 0;
	for( auto y : G[ x ] ) if( y ^ fa ) dfs( y, x ), f[ x ] += g[ y ], g[ x ] += max( f[ y ], g[ y ] );
}

int main()
{
#ifdef wxh010910
	freopen( "data.in", "r", stdin );
#endif
	n = read();
	for( int i = 1, x, y ; i < n ; i++ ) x = read(), y = read(), G[ x ].pb( y ), G[ y ].pb( x );
	dfs( 1 );
	return puts( max( f[ 1 ], g[ 1 ] ) <= n / 2 ? "Second" : "First" ), 0;
}


Measured memory_bytes: 6656
using System;


	public class SelectionSort
	{
		public static void Main(string[] args)
		{
			int count=int.Parse(Console.ReadLine());			
			string data=Console.ReadLine();
			string[] num=data.Split();
			int[] target=new int[count];
			int temp;
			int sortCount=0;//?????????????????°???
			for(int d=0;d<num.Length;d++)
			{
				target[d]=int.Parse(num[d]);
			}
			
			for(int i=0;i<count-1;i++)
			{  
				int mini=i;
				for(int j=i+1;j<count;j++)
				{
					if(target[j]<target[mini])
					{
						mini=j;						
					}					
				}
				if(i!=mini)
				{
					temp=target[i];
					target[i]=target[mini];
					target[mini]=temp;
					sortCount++;
				}
			}
			Console.Write(target[0]);
			for(int k=1;k<target.Length;k++)
			{
				Console.Write(" "+target[k]);
			}
			Console.Write("\r\n");
			Console.WriteLine(sortCount);
		}
	}

Measured memory_bytes: 9204
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <queue>
#include <cmath>
#include <limits>
#include <stack>

using namespace std;

int main(){
  long n,a,countA,countB;
  long sumA,sumB;
  bool plusA,plusB;

  cin >> n;
  cin >> a;

  if(a>0){
    countA = 0;
    countB = a+1;
    sumA = a;
    sumB = -1;
    plusA = true;
    plusB = false;
  }else if(a<0){
    countA = abs(a)+1;
    countB = 0;
    sumA = 1;
    sumB = a;
    plusA = true;
    plusB = false;
  }else{
    countA = 1;
    countB = 1;
    sumA = 1;
    sumB = -1;
    plusA = true;
    plusB = false;
  }

  for(int i=1;i<n;++i){
    cin >> a;
    sumA += a;
    if(plusA){
      if(sumA>=0){
        countA += sumA+1;
        sumA = -1;
        plusA = false;
      }else{
        plusA = false;
      }
    }else{
      if(sumA>0){
        plusA = true;
      }else{
        countA += abs(sumA)+1;
        sumA = 1;
        plusA = true;
      }
    }
    sumB += a;
    if(plusB){
      if(sumB>=0){
        countB += sumB+1;
        sumB = -1;
        plusB = false;
      }else{
        plusB = false;
      }
    }else{
      if(sumB>0){
        plusB = true;
      }else{
        countB += abs(sumB)+1;
        sumB = 1;
        plusB = true;
      }
    }
  }
  cout << min(countA,countB) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
typedef long long ll;
int cmpint(const void *x, const void *y) { return *(int *)x - *(int *)y; }
int main() {
	int n,  a[100000][2];
	ll k, cnt = 0;
	scanf("%d%lld", &n, &k);
	for (int i = 0; i < n; i++) {
		scanf("%d%d", &a[i][0], &a[i][1]);
	}
	qsort(a, n, sizeof(a[0]), cmpint);
	for (int i = 0; i < n; i++) {
		cnt += a[i][1];
		if (k <= cnt) {
			printf("%d\n", a[i][0]);
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 1788
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	map<int, int> mc;
	while (n--)
	{
		int x;
		cin >> x;
		mc[x]++;
	}
	int ans = 0;
	for (auto& p : mc)
	{
		if (p.first > p.second) ans += p.second;
		else ans += p.second - p.first;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4736
n, k = list(map(int, input().split()))
flags = [False] * n
count = 0

for i in range(k):
  d = int(input())
  people = list(map(int, input().split()))
  for p in people:
    flags[p - 1] = True
for flag in flags:
  if not flag:
    count += 1
print(count)

Measured memory_bytes: 9056
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    long M = scan.nextLong();
    long[] a = new long[N];
    for(int i=0; i<N; i++) {
      a[i] = scan.nextLong();
    }
    scan.close();

    long[] ah = new long[N];
    for(int i=0; i<N; i++) {
      ah[i] = a[i] / 2;
    }

    long lcm = 1;
    for(int i=0; i<N; i++) {
      long gcdresult = gcd(lcm, ah[i]);
      lcm = lcm * ah[i] / gcdresult;
      if((lcm / ah[i]) % 2 == 0) {
        System.out.println(0);
        return;
      }
    }

    System.out.println((M+lcm) / (2*lcm));
  }

  public static long gcd(long x, long y) {
    while(x%y != 0) {
      long temp = x;
      x = y;
      y = temp % y;
    }
    return y;
  }
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef map<ll,ll>::iterator itll;
typedef long double ld;
typedef map<ll,ll> mapll;

#define con continue
#define pb push_back
#define fi first
#define se second
#define fr front()
#define one 1.0
#define inf 1000000000000000000
#define all(vl) vl.begin(),vl.end()
#define m_p make_pair 
#define sz(a) sizeof(a)
#define forn(mp,it) for(it = mp.begin();it!=mp.end();it++)
#define FOR(i,a,n) for(int i=a;i<n;i++) 
#define FORE(i,a,n) FOR(i,a,n+1)
#define Endl endl
#define eNdl endl
#define enDl endl
#define endL endl
#define PI 3.14159265358979323846

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n;
	cin>>n;
	string s;
	cin>>s;
	ll lef=0,rig = s.size()-1;
	ll ans = 0;
	while(1)
	{
		while(lef<s.size()&&s[lef] == 'R')lef++;
		while(rig>=0&&s[rig] == 'W')rig--;
		if(lef == s.size())break;
		if(rig == -1)break;
		if(lef>rig)break;
		s[lef] = 'R';
		s[rig] = 'W';
		ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3708
#include <algorithm>
#include <map>
#include <vector>
#include <iostream>
#include <stdio.h>
#include <set>
#include <string>
#include <stack>
#include <stdlib.h>
#include <math.h>
#include <iomanip>
#include <iterator>

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<ll, ll> point;

#define PI 3.1415926535897932384626433832795

int main() {
    iostream::sync_with_stdio(false);
    int n; cin>>n;
    vector<int> input(n); for (int i=0; i<n; i++) cin>>input[i];

    int ans=200*200*100+47;
    for (int i=-100; i<=100; i++) {
        int tmp=0;
        for (int j=0; j<n; j++) tmp+=(i-input[j])*(i-input[j]);
        ans=min(tmp, ans);
    }
    cout<<ans<<endl;


    return 0;
}


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

int main(){
	int N;
	cin >> N;
	bool flag = false;
	if(N % 10 == 7) flag = true;
	N /= 10;
	if(N % 10 == 7) flag = true;
	N /= 10;
	if(N == 7) flag = true;
	if(flag) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 3168
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using lli = long long int;
using i64 = int64_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (lli i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (lli i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

const i64 mod = 1e9 + 7;
i64 n, k;

struct Mat {
  vector<i64> c;

  Mat() : c(n * n) {}
 
  i64& operator()(i64 i, i64 j) { return c[n * i + j]; }
  const i64& operator()(i64 i, i64 j) const { return c[n * i + j]; }

  Mat trans() const {
    Mat a;
    for (i64 i = 0; i < n; ++i)
      for (i64 j = 0; j < n; ++j)
        a(j, i) = (*this)(i, j);
    return a;
  }
};

Mat dot(const Mat& a, const Mat& b) {
  Mat bt = b.trans(), c;
  for (i64 i = 0; i < n; ++i) {
    for (i64 j = 0; j < n; ++j) {
      for (i64 k = 0; k < n; ++k) {
        c(i, j) = (c(i, j) + a(i, k) * bt(j, k)) % mod;
      }
    }
  }
  return c;
}

Mat diag() {
  Mat a;
  for (i64 i = 0; i < n; ++i) a(i, i) = 1;
  return a;
}

Mat pow(const Mat& a, i64 n) {
  Mat b = a, c = diag();
  for (; n > 0; n >>= 1) {
    if (n & 1) c = dot(c, b);
    b = dot(b, b);
  }
  return c;
}

int main() {
  cin >> n >> k;
  Mat a;
  for (i64 i = 0; i < n; ++i) {
    for (i64 j = 0; j < n; ++j) {
      cin >> a(i, j);
    }
  }
  Mat b = pow(a, k);
  i64 ans = 0;
  for (i64 i = 0; i < n; ++i) {
    for (i64 j = 0; j < n; ++j) {
      ans = (ans + b(i, j)) % mod;
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 384
def choose(n, r, mod = 10 ** 9 + 7):
    bumbo = 1
    bunshi = 1
    for i in range(r):
        bunshi =(bunshi *  (n - i)) % mod
        bumbo = (bumbo * (i + 1)) % mod
    return bunshi * pow(bumbo, mod - 2, mod) % mod

mod = 10 ** 9 + 7
n, a, b = map(int, input().split())

ans = pow(2, n, mod)    # 全体
ans -= 1    # 花を選ばない場合をひく

# nCa を求める
nCa = choose(n, a)
nCb = choose(n, b)
ans -= (nCa + mod) % mod
ans -= (nCb + mod) % mod
ans = (ans + mod) % mod
print(ans)

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

int ball[10];
bool dfs(int point, int right, int left){
	if(point == 10) return true;
	if(right < ball[point]) return dfs(point + 1, ball[point], left);
	if(left < ball[point]) return dfs(point + 1, right, ball[point]);
	return false;
}
int main(){
	int N;
	scanf("%d", &N);
	while(N){
		for(int i = 0; i < 10; i++){
			scanf("%d", &ball[i]);
		}
		if(dfs(0, 0, 0)) printf("YES\n");
		else printf("NO\n");
		N--;
	}
}

Measured memory_bytes: 1008
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
W,H,N = readInts()
field = [[False] * W for _ in range(H)]

def fill(sy,sx,gy,gx):
    cnt = 0
    for y in range(sy,gy):
        for x in range(sx,gx):
            if field[y][x]:
                continue
            else:
                field[y][x] = True
                #print(y,x)
                cnt += 1
    return cnt
ans = 0
for i in range(N):
    x,y,a = readInts()
    if a == 1:
        ans += fill(0,0,H,x)
    elif a == 2:
        ans += fill(0,x,H,W)
    elif a == 3:
        ans += fill(0,0,y,W)
    else:
        ans += fill(y,0,H,W)
    #print(ans)
print(H*W - ans)


Measured memory_bytes: 10544
#include<string.h>
#include <iostream>
#include<cstdio>
#include <stack>
#include <vector>
using namespace std;
#define INF 0x7ffffff
typedef long long ll;
const int maxn=1e5+10;
int pre[maxn];
int dis[maxn];
int findset(int x)
{
    if(x==pre[x])   return x;
    int root=findset(pre[x]);
    dis[x]=dis[pre[x]]+dis[x];
    return pre[x]=root;
}
bool unionset(int x,int y,int w)
{
    int fx=findset(x),fy=findset(y);
    if(fx==fy)
        return w==dis[y]-dis[x];
    pre[fy]=fx;
    dis[fy]=dis[x]+w-dis[y];
    return true;
}
int n,m;
int main()
{
// Input
   scanf("%d%d",&n,&m);
   for(int i=1;i<=n;i++)
    pre[i]=i;
   bool lose=true;
   for(int i=0;i<m;i++)
   {
       int x,y,w;
   scanf("%d%d%d",&x,&y,&w);
        if(lose)
       lose=unionset(x,y,w);
   }
   if(lose) printf("Yes\n");
   else     printf("No\n");
}


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

int main() {
  int n, q, t, cnt = 0;
  cin >> n;
  int s[n];

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

  cin >> q;

  for (int i = 0; i < q; i++) {
    cin >> t;
    for (int j = 0; j < n; j++) {
      if (t == s[j]) {
        cnt += 1;
        break;
      }
    }
  }

  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B, C, D, E;
  cin >> A >> B >> C;
  D = 10 * B + C;
  E = D % 4;
  if(E == 0) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 3500
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn = 111111;
ll n, dp[maxn], a[maxn];
vector<int> G[maxn];
vector<ll> V;
ll Max(ll a, ll b) {  return a < b ? b : a; }
ll dfs(int x)
{
    if(dp[x]) return dp[x];
    dp[x] = 1;
    for(int i = 0; i < G[x].size(); i++)
    {
        int to = G[x][i];
        dfs(to);
    }
    for(int i = 0; i < G[x].size(); i++)
        V.push_back(dp[G[x][i]]);
    sort(V.begin(), V.end());
    for(int i = 0; i < V.size(); i++)
        dp[x] = Max(dp[x], V[i]+V.size()-i);
    V.clear();
    return dp[x];
}
int main()
{
    cin>>n;
    for(int i = 2; i <= n; i++) cin>>a[i];
    for(int i = 2; i <= n; i++) G[a[i]].push_back(i);
    dfs(1);
    cout<<dp[1]-1<<endl;
}


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

long int test(string &S, int i, long int x, long int y){
  
  if(i==S.size()-1){
    return x+y;
  }
  
  i++;
  
  long int s = test(S, i, x+y, S.at(i)-'0')
    +test(S, i,   x, 10*y +S.at(i)-'0');
  
  return s;
}


int main(){
  
  string S;
  cin >> S;
  
  cout << test(S, 0, 0, S.at(0)-'0');
  //cout << S.at(0)-'0'+S.at(1)-'0';
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;

int main(){
    fast;
    ll n;
    cin >> n;
    ll a[n], b[n+1] = {0};
    for(int i = 1; i < n; ++i){
        cin >> a[i];
        b[a[i]]++; 
    }
    for(int i = 1; i <= n; ++i){
        cout << b[i] << '\n';
    }
    return 0;
}
//                                     #!!{*[$um1t_Kum@r]*}!!#


Measured memory_bytes: 6772
#include <iostream>
#include <fstream>
#include <numeric>
#include <stdio.h>
#include <cmath>
#include <queue>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <deque>
#include <bitset>
#include <cstring>
#include <sstream>
#include <complex>

#define f first
#define s second
#define ll long long
#define ld double
#define pb push_back
#define all(x) x.begin(),x.end()
#define mp make_pair
#define y0 eto
#define y1 mezhdy
#define y2 nami
#define left extermination
#define right dismemberment
 
using namespace std;
 
double start_moment = 0;
double get_runtime() { return 1.0*clock()/CLOCKS_PER_SEC; }
void reset_timer() { start_moment = get_runtime(); }
double timer_time() { return get_runtime() - start_moment; }
void runtime(){cout<<fixed<<setprecision(5)<<get_runtime()<<'\n';}
 
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
template <class T>void read(vector<T> &a,ll n){T x; a.clear();for(ll i=0;i<n;i++){cin>>x;a.pb(x);}}
template <class T>void write(vector<T> &a){for(T x : a) cout<<x<<' ';cout<<'\n';}

const ll mod=1000000007;
const int N=1000006;

ll dp[N][2][2];
int n;

ll go(int pos,int have0,int have9)
{
    if(pos==n)
        return (have0 & have9);
    if(dp[pos][have0][have9]!=-1) return dp[pos][have0][have9];
    ll res=8*go(pos+1,have0,have9) + go(pos+1,1,have9) + go(pos+1,have0,1);
    res%=mod;
    return dp[pos][have0][have9]=res;
    
}

int main()
{
    ios_base::sync_with_stdio(0);
//    freopen("INPUT.txt","r",stdin);
//    freopen("OUTPUT.txt", "w", stdout);
        
    memset(dp,-1,sizeof(dp));
    cin>>n;
    cout<<go(0,0,0);
    
    
    
}


Measured memory_bytes: 81144
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl
#define debugvec(v)   rep(i, v.size()) cerr << "L" << __LINE__ << ": " << #v << "[" << i << "] = " << v[i] << endl;
#define debugvec2(v)  cerr << "L" << __LINE__ << ": " << #v << " = { "; rep(i, v.size()) cerr << v[i] << (i + 1 == v.size() ? "" : ", "); cerr << " }" << endl;
typedef long long ll;  /* 10^18 くらいまでいける */

int main(){
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  rep(i, n){
    cin >> a[i];
  }

  sort(a.begin(), a.end(), greater<int>());

  double threshold = accumulate(a.begin(), a.end(), 0.0) / (4 * m);

  if (a[m-1] < threshold){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }

  return 0;
}

Measured memory_bytes: 764
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

#define GYOU_MAX 256



int   isInt(double a) {

	if ((int)a == a) {
		return 1;
	}
	else {
		return 0;
	}
}



int main(void)
{
	
	int R, G, B, N;
	scanf("%d%d%d%d", &R, &G, &B, &N);

	int count = 0;
	double x;
	for (int i = 0;; i++) {
		if (R*i > N) {
			break;
		}

		for (int j = 0;; j++) {

			x = (double)(N - (R * i + G * j)) / B;

			//printf("%d %d %f\n", i, j, x);
			if (isInt(x)==1 && x >= 0) {
				count++;
				//printf("[%d %d %d]\n", i, j,(int) x);
			}
			if (R*i + G * j > N) {
				break;
			}
		}
	}

	printf("%d\n", count);

	
	return 0;
}

Measured memory_bytes: 128
import math
def trial_division(n):
    a = [1]
    for i in range(2,int(math.sqrt(n)) + 1):
        while n % i == 0:
            n //= i
            a.append(i)
    a.append(n)
    return a
A, B = map(int, input().split())
ans = set(trial_division(A)) & set(trial_division(B))
print(len(ans))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d,e,f;
  cin >> a >> b >> c >> d;
  if(a%d==0)
   e = a/d;
  else  e = a/d + 1;
  if(c%b==0)
   f = c/b;
  else  f = c/b +1;
  if(e<f) cout <<"No";
  else cout << "Yes";
  return 0;
}

Measured memory_bytes: 3620
#include<iostream>
#include<iomanip>
#include<stack>
#include<queue>
#include<numeric>
#include<algorithm>
#include<string>
#include<map>
#include<bitset>
#include<set>
#include<cmath>
#define int long long
const int inf=893810114514l;
const int mod=1000000007ll;
const int dd[]={0,-1,0,1,0};
using namespace std;
int p[2001];
void san(int u){
	string s;
	while(u){
		s.push_back(u%3+'0');
		u/=3;
	}
	reverse(begin(s),end(s));
	cout<<s;
}
signed main(){
	int n,m;
	cin>>n>>m;
	if(m/2<n)
		cout<<m/2<<endl;
	else
		cout<<n+(m-n*2)/4<<endl;
}

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

int main() 
{
    int a,b;
    cin >> a >> b;
    if (a*b%2==1 || a*b*2%2==1 || a*b*3%2==1)
        cout << "Yes";
    else 
        cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cstdio>
#include <cstring>
using namespace std;

int main()
{
    int n, k; cin >> n >> k;
    bool ng[10] = {};

    for (int i = 0; i < k; i++) {
        int d; cin >> d;
        ng[d] = true;
    }

    for (int i = n; ; i++) {
        ostringstream oss;
        oss << i;
        bool ok = true;
        for (int j = 0; j < oss.str().size(); j++) {
            if (ng[oss.str()[j]-'0']) {
                ok = false;
                break;
            }
        }

        if (ok) {
            cout << i << endl;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 764
from collections import Counter, defaultdict
# for use in beginner level contests where speed is key

_ = int(input())

lst = list(map(int,input().split()))

nrows = int(input())

grid = []
for _ in range(nrows):
    grid.append(list(map(int,input().split())))

c = Counter(lst)
res = sum(lst)

for old, new in grid:
    diff = new - old
    res += c[old]*diff
    print(res)
    c[new] = c[new] + c[old]
    c[old] = 0

Measured memory_bytes: 104800
from collections import deque, defaultdict, Counter
import sys
input = sys.stdin.readline

N, Q = map(int, input().split())
ab = [map(int, input().split()) for _ in range(N - 1)]
px = [map(int, input().split()) for _ in range(Q)]

# build tree
tree = defaultdict(list)
for a, b in ab:
    tree[a - 1].append(b - 1)
    tree[b - 1].append(a - 1)

dic = defaultdict(int)
for p, x in px:
    dic[p - 1] += x

ans = [0] * N
checked = [0] * N
checked[0] = 1
q = deque([0])

while q:
    n = q.popleft()
    ans[n] += dic[n]
    for u in tree[n]:
        if checked[u]:
            continue
        ans[u] += ans[n]
        checked[u] = 1
        q.append(u)
print(*ans)

Measured memory_bytes: 204624
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;

int dp[2][2000];
int main()
{
    int n, z, w;
    cin >> n >> z >> w;

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

    if (n == 1)
    {
        cout << abs(a[0] - w) << endl;
        return 0;
    }

    int min_dp0, max_dp1; 
    dp[0][n - 1] = dp[1][n - 1] = min_dp0 = max_dp1 = abs(a[n - 1] -  a[n - 2]);

    rrep(i, n - 1, 0)
    {
        int now;
        now = (i == 0)? w: a[i - 1];
        dp[0][i] = max(abs(a[n - 1] - now), max_dp1);
        now = (i == 0)? z: a[i - 1];
        dp[1][i] = min(abs(a[n - 1] - now), min_dp0);

        min_dp0 = min(min_dp0, dp[0][i]);
        max_dp1 = max(max_dp1, dp[1][i]);
        // cout << dp[0][i] << endl;
    }
    cout << dp[0][0] << endl;
    return 0;
}

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

int main(){
	/*input*/
	int a, b, c, x, y;	cin >> a >> b >> c >> x >> y;
	/*calculation*/
	int ans = 0;
	if(x >= y){
		if(a + b >= 2*c){
			ans+=y*2*c;
			if(a >= 2*c){
				ans+=2*c*(x - y);
			}else{
				ans+=a*(x - y);
			}
		}else{
			ans+=a*x+b*y;
		}
	}else{
		if(a + b >= 2*c){
			ans+=x*2*c;
			if(b >= 2*c){
				ans+=2*c*(y - x);
			}else{
				ans+=b*(y - x);
			}
		}else{
			ans+=a*x+b*y;
		}
	}
	/*output*/
	cout << ans << endl;
}


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

using namespace std;

map<int,map<int,bool> > data;
long long rem[10];
int posx[]={-1,0,1};
int posy[]={-1,0,1};
int h,w,n;

int chk(int x,int y)
{
  int r=0;

  for(int c=0;c<3;c++)
  for(int c2=0;c2<3;c2++)
  {
    if (data.find(x+posx[c])!=data.end()&&data[x+posx[c]].find(y+posy[c2])!=data[x+posx[c]].end())r++;
  }
  return r;
}

int main()
{
  int x,y;

  scanf("%d%d%d",&h,&w,&n);
  rem[0]=((long long)h-2)*(w-2);
  while(n--)
  {
    scanf("%d%d",&x,&y);
    if (data[x].find(y)==data[x].end())
    {
      for(int c=0;c<3;c++)
      for(int c2=0;c2<3;c2++)
      {
        if (x+posx[c]>1&&x+posx[c]<h&&y+posy[c2]>1&&y+posy[c2]<w)
        {
          int tmp=chk(x+posx[c],y+posy[c2]);

          rem[tmp]--;
          rem[tmp+1]++;
        }
      }
      data[x][y];
    }
  }
  for(int c=0;c<10;c++)
  printf("%lld\n",rem[c]);
}


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

const int maxn = 2e5 + 10;
int n, k, l, par1[maxn], par2[maxn];

void init() {
	for (int i = 0; i < n; i++) {
		par1[i] = i; par2[i] = i;
	}
}

int find(int x, int* par) {
	return x == par[x] ? x : par[x] = find(par[x], par);
}

void unite(int x, int y, int* par) {
	x = find(x, par);
	y = find(y, par);
	if (x != y) {
		par[x] = y;
	}
}

int main() {
	cin >> n >> k >> l;
	init();
	for (int i = 0, x, y; i < k; i++) {
		cin >> x >> y;
		unite(x, y, par1);
	}
	for (int i = 0, x, y; i < l; i++) {
		cin >> x >> y;
		unite(x, y, par2);
	}
	map<pair<int, int>, int>mp;
	for (int i = 1; i <= n; i++) {
		find(i, par1); find(i, par2);
	}
	for (int i = 1; i <= n; i++) {
		mp[{par1[i], par2[i]}]++;
	}
	for (int i = 1; i <= n; i++) {
		cout << mp[{par1[i], par2[i]}] << ' ';
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 13568
N,M= list(map(int, input().split()))
P = [list(map(int,input().split())) for i in range(M)]
Q = list(map(list, set(map(tuple, P))))
C = []
S = []
n = N -1
sum1 = 0
 
for s in range(len(Q)):
    C.append(Q[s][0])
for t in range(len(Q)):
    S.append(Q[t][1])
D = list(set(C))
if len(D) <len(S) :
    print("-1")
else:
    if N == 1 and M == 1 and Q[0][1] == 0:
        print("0")
    elif N == 1 and M == 0:
                print("0")
    else:
        for u in range(len(Q)):
            sum1 = sum1 + Q[u][1]*(10 ** (N - Q[u][0]))
        if sum1 >= (10 ** n):
            print(sum1)
        else:
            if D.count(1) >= 1:
                unko = C.index(1)
                if Q[unko][1] == 0:
                    print("-1")
                else:
                    print(sum1 + 10 ** n)
            else:
                print(sum1 + 10 ** n)

Measured memory_bytes: 3064
# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read

#n,q = map(int, readline().split())
#*a, = map(int, readline().split())

n = int(input())

cnt = 0
for i in range(n):
    a,b = map(int, readline().split())
    if a==b:
        cnt += 1
    else:
        cnt = 0
    if cnt == 3:
        print("Yes")
        break
else:
    print("No")

Measured memory_bytes: 9176
#include <iostream>
#include <cstdio>

int n,k;

int main (){
	scanf("%d%d",&n,&k);
	int ans=1;
	for (int i=1;i<=n;i++)
		ans+=std::min(ans,k);
	std::cout <<ans<<std::endl;
	return 0 ;
}

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

int main(){
  int64_t N,M;
  cin >> N >> M;
  if(M%2==0){
    for(int i=0;i<M/2;i++){
      cout << i+1 << " " << M-i+1 << endl;
      cout << M+i+2 << " " << 2*M-i+1 << endl;
    }
  }else{
    for(int i=0;i<M/2;i++){
      cout << i+1 << " " << M-i+1 << endl;
      cout << M+i+2 << " " << 2*M-i+1 << endl;
    }
    cout << (M/2)+1 << " " << (M/2)+2 << endl;
  }
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define FOR(k,m,n) for(int(k)=(m);(k)<(n);(k)++)
#define REP(k,n) FOR((k),0,(n))
using namespace std;
typedef long long ll;
typedef vector<ll> VLL;
const int MOD=1000000007;

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

    string s(100000, '\0');
    cin >> s;
    FOR(i, 0, 26){
        if (s.find('a'+i) != -1){
            continue;
        }
        char res = 'a' + i;
        cout << res << endl;
        return 0;
    }

    cout << "None" << endl;

    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
using namespace std;
typedef pair<int, int> P;
int n;
vector<P> ans;

int main(void){
    // Your code here!
    cin >> n;
    if (n % 2 == 1)
    {
        for (int i = 1; i <= n; i++)
        {
            for (int j = i + 1; j <= n; j++)
            {
                if (i + j == n) continue;
                ans.push_back(P(i, j));
            }
        }
    }
    else
    {
        for (int i = 1; i <= n; i++)
        {
            for (int j = i + 1; j <= n; j++)
            {
                if (i + j == n + 1) continue;
                ans.push_back(P(i, j));
            }
        }
    }
    cout << ans.size() << endl;
    for (int i = 0; i < ans.size(); i++)
    {
        cout << ans[i].first << ' ' << ans[i].second << endl;
    }
}


Measured memory_bytes: 384