akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"fmt"
	"math"
)

func min(n ...int) int {
	ans := n[0]
	for _, v := range n {
		if v < ans {
			ans = v
		}
	}
	return ans
}

func main() {
	var n, a, b, c, d, e int
	fmt.Scan(&n, &a, &b, &c, &d, &e)

	m := min(a, b, c, d, e)
	fmt.Println(int(math.Ceil(float64(n)/float64(m))) + 4)
}


Measured memory_bytes: 512
#include <iostream>
#include <string>

int main()
{
	std::string s1 ,s2;
	std::cin >> s1 >> s2;

	bool iss = true;
	for( int i = 0; i < s1.size(); i++ ) {
		if( s1[ i ] != s2[ s2.size() - i - 1 ] ) {
			iss = false;
			break;
		}
	}

	std::cout << ( iss ? "YES" : "NO" ) << std::endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }



int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(25);

  ll n;
  string s;
  cin >> n >> s;

  vector<ll> cnt(26, 1);
  rep(i, n) cnt[s[i] - 'a']++;
  ll ans = 1;
  rep(i, 26) ans = ans * cnt[i] % mod;
  ans = (ans - 1 + mod) % mod;
  cout << ans << '\n';






  
  return 0;
}

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

int main(){
  string s;
  cin >> s;
  int a,z;
  for(int i=0; i<s.length(); i++){
    if(s.at(i) == 'A'){
      a = i;
      break;
    }
  }
  for(int i=s.length()-1; i>0; i--){
    if(s.at(i) == 'Z'){
      z = i;
      break;
    }
  }
  cout << z-a+1 << endl;
}

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

int main() {
  int N; cin >> N;
  string S; cin >> S;
  int count = 0;
  for (int i = 1; i < N; i++) {
    int conpare = 0;
    set<char> first, second;
    for (int j = 0; j < i; j++)
      first.insert(S[j]);
    for (int j = i; j < N; j++)
      second.insert(S[j]);
    for (int j = 0; j < 26; j++) {
      if (first.count('a' + j) == 1 && second.count('a' + j) == 1)
        conpare++;
    }
    if (conpare > count)
      count = conpare;
  }
  cout << count << endl;
}


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

int main() {
    long long int N, A, B;
    cin >> N >> A >> B;

    if(B-A<0){
        cout << 0 << endl;
    }
    else if(N==1){
        if(A==B){
            cout << 1 << endl;
        }
        else{
            cout << 0 << endl;
        }
    }
    else{
        cout << (N-2)*(B-A) + 1 << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int maxi[1000005];
long long MOD=1000000007;
long long expo(long long a,long long b){
	if(b==0)return 1;
	long long temp=expo(a,b/2);
	if(b%2==0)return (temp*temp)%MOD;
	return (((temp*temp)%MOD)*a)%MOD;
}

int main() {
	bitset<10005> prime;
	prime.set();
	prime[0]=0;prime[1]=0;for(int i=4;i<10005;i+=2)prime[i]=0;
	vector<int> p; p.push_back(2);
	for(long long i=3;i<10005;i+=2){
		if(prime[i]){
			p.push_back(i);
			for(long long j=i*i;j<10005;j+=i){
				prime[j]=0;
			}
		}
	}

	int n;
	scanf("%d",&n);
	int arr[n];
	for(int i=0;i<n;i++){
		scanf("%d",&arr[i]);
	}
	for(int i=0;i<n;i++){
		int cur=arr[i];
		for(int j=0;j<(int)p.size();j++){
			int c=0;
			while(cur%p[j]==0){
				cur/=p[j];c++;
			}
			if(c>0){
				maxi[p[j]]=max(maxi[p[j]],c);
			}
		}
		if(cur>1){
			maxi[cur]=max(maxi[cur],1);
		}
	}
	vector<int> used;
	for(int i=0;i<1000005;i++){
		if(maxi[i]>0){
			used.push_back(i);
		}
	}

	long long ans=0;
	for(int i=0;i<n;i++){
		long long cur=1;
		for(int j=0;j<(int)used.size();j++){
			int c=0;
			while(arr[i]%used[j]==0){
				arr[i]/=used[j];c++;
			}
			if(maxi[used[j]]-c==0)continue;
			else if(maxi[used[j]]-c==1)cur*=used[j];
			else if(maxi[used[j]]-c==2)cur*=(used[j]*used[j])%MOD;
			else cur*=expo(used[j],maxi[used[j]]-c);
			cur%=MOD;
		}
		ans+=(cur%MOD);
		ans%=MOD;
	}
	printf("%lld",ans);
}

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

int main() {
  int n;
  cin >> n;
  map<string, int> mp;
  rep(i, n) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    mp[s]++;
  }
  llong ans = 0;
  for (auto it = mp.begin(); it != mp.end(); it++) {
    int s = it->second;
    ans += (llong)s * (s - 1) / 2;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 11136
import java.math.BigInteger;
import java.util.Scanner;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        int n, i, j, m, k, p, q, o, l, s, tt = 1;
        Double x,y,z;
        int ar[],br[];
        char ch;
        BigInteger an, su, u, v;
        String a,b="",c="",d;
        Scanner sc = new Scanner(System.in);
        Scanner scc = new Scanner(System.in);
        ar=new int[200001];
        br=new int[200001];
        n=sc.nextInt();
        k=50000000;
       for(i=0;i<n;i++)
       {
           o=sc.nextInt();
           if(k>o)
           {
               k=o;
           }
           ar[i]=o;
           br[i]=k;
       }
       k=0;
       for(i=1;i<n;i++)
       {
           if(ar[i]<=br[i])
           {
               k++;
           }
       }
        System.out.println(k+1);


    }
}



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

def selectionSort(a, n):
  count = 0
  for i in range(n):
    minj = i
    for j in range(i,n):
      if a[j] < a[minj]:
        minj = j
    if minj != i:
      count += 1
    a[i],a[minj] = a[minj],a[i]
  return count
  
count = selectionSort(a,n)
print(*a)
print(count)





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

int main() {
    int n;
    cin >> n;
    const int x = 10;
    const int mod = 1e9 + 7;
    auto power = [&](int64_t a, int64_t b) {
        int64_t res = 1;
        for (; b; b >>= 1, a = a * a % mod)
            if (b & 1)
                res = res * a % mod;
        return res;
    };
    int64_t ans = power(x, n) - (power(x - 1, n) + power(x - 1, n) - power(x - 2, n));
    cout << ((ans % mod) + mod) % mod << '\n';
}


Measured memory_bytes: 3616
#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(){
  int n;

  cin >> n;
  vector <int> L(n);

  rep(i,n) cin >> L[i];
  sort(L.begin(),L.end());
  long cnt = 0;
  for(int b = 0; b < n; b++){
      for(int a = 0; a < b; a++){
          int ab = L[a]+L[b];
          int r = lower_bound(L.begin(),L.end(),ab) - L.begin();
          //int l = b + 1;
          cnt += r - (b+1);
      }
  }
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define mii         map<ll int,ll int>
#define msi         map<string,ll int>
#define mis         map<ll int, string>
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define mpi         map<pair<ll int,ll int>,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define vii         vector<pair<ll int, ll int>>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
//#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;
#define N  1000000007 
#define MAXN   200005
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cout.precision(15);
ll int n,w;
cin>>n>>w;
vii v(n);
rep(i,0,n)
{
cin>>v[i].F>>v[i].S;
}
ll int dp[n+1][w+1];
rep(i,0,n+1)
{
rep(j,0,w+1)
{
if(i==0 || j==0)
dp[i][j]=0;
else
{
if(j-v[i-1].F>=0)
dp[i][j]=max(dp[i-1][j],dp[i-1][j-v[i-1].F]+v[i-1].S);
else
dp[i][j]=dp[i-1][j];
}}	
}
cout<<dp[n][w];


}


Measured memory_bytes: 79232
#include <vector>
#include <iostream>
#include <string>

using namespace std;

int main()
{
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    vector<pair<int, int>> query(q);
    for(int i = 0; i < q; i++)
    {
        int l , r;
        cin >> l >> r;
        query[i] = {l - 1, r - 1};
    }
    vector<int> cum(n, 0);
    for(int i = 0; i < n - 1; i++)
    {
        if(s[i] == 'A' && s[i + 1] == 'C')
        {
            cum[i + 1] = cum[i] + 1;
        }else{
            cum[i + 1] = cum[i];
        }
    }
    for(int i = 0; i < q; i++)
    {
        cout << cum[query[i].second] - cum[query[i].first] << endl;
    }
}

Measured memory_bytes: 2176
// https://atcoder.jp/contests/abc081/tasks/abc081_a
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    cout << count(ALL(s), '1') << endl;

    return 0;
}


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

int main() {
  int H, W;
  cin >> H >> W;

  vector<char> out((H + 2) * (W + 2), '#');
  string txt;

  for (int j = 0; j < H; j++) {
    cin >> txt;

    for (int i = 0; i < W; i++) {
      out.at((W + 2) * (j + 1) + i + 1) = txt.at(i);
    }
  }

  for (int k = 0; k < (H + 2) * (W + 2); k++) {
    cout << out.at(k);
    
    if ((k + 1) % (W + 2) == 0) {
      cout << endl;
    }
  }
    cout << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<functional>
#include <random>
#include<iostream>
#include<iomanip>
using namespace std;

int main() {
	int N, M;
	cin >> N >> M;
	if (N == M) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
}

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

long long md(pair<long long,long long> x,pair<long long,long long> y){
    return max(x.first,y.first)-min(x.first,y.first)+max(x.second,y.second)-min(x.second,y.second);
}

int GCD(int x,int y){
    int temp;
    if(x<y){
        temp=x,x=y,y=temp;
    }
    if(y<1){
        return -1;
    }
    if(x%y==0){
        return y;
    }
    return GCD(x,x%y);
}

int main(){
    int a;
    cin >> a;
    cout << a*a << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn = 3e5+10;
#ifdef LOCAL
    #define eprintf(...) fprintf(stderr,__VA_ARGS__)
#else
    #define eprintf(...) 42
#endif // LOCAL
using ll = long long;
int const mask = (1<<12);
ll const inf = 1e17;
ll dp[1020][mask + 5];
int n,m,a[1020],x;
int msk[1020];

int main(){
    scanf("%d%d",&n,&m);
    for(int i=0;i<=m;i++)
        for(int j=0;j<mask;j++)
            dp[i][j] = inf;
    for(int i=1;i<=m;i++){
        int b;
        scanf("%d%d",&a[i],&b);
        int mk = 0;
        while(b -- ){
            scanf("%d",&x);
            mk |= (1 << (x - 1));
        }
        msk[i] = mk;
        eprintf("mk = %d\n",mk);
    }
    dp[0][0] = 0LL;
    for(int i=1;i<=m;i++){
        for(int j=0;j<mask;j++){
            dp[i][j] = min(dp[i-1][j],dp[i][j]);
            dp[i][j|msk[i]] = min(dp[i][j|msk[i]],dp[i-1][j] + a[i]);
            dp[i][j|msk[i]] = min(dp[i][j|msk[i]],dp[i-1][j|msk[i]]);
        }
        if(i == 3)eprintf("here :%lld %lld\n",dp[i][(1<<n) - 1],dp[i-1][13]);
    }
    //cout << dp[1][1] <<'\n';
    printf("%lld\n",dp[m][(1<<n)-1] == inf ? -1LL:dp[m][(1<<n)-1]);
}
/*
    Good Luck
        -Lucina
*/


Measured memory_bytes: 32384
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}


int main() {
    int a,b;
    cin >> a >> b;
    string ch_a = to_string(a);
    string ch_b = to_string(b);
    string line_a,line_b;

    REP(i,a) {
        line_b += ch_b;
    }

    REP(i,b) {
        line_a += ch_a;
    }

    vector<string> v;
    v.push_back(line_a);
    v.push_back(line_b);

    sort(ALL(v));

    cout << v[0] << endl;

    return 0;
}


Measured memory_bytes: 256
// g++ -std=c++11 temp.cpp
#include <bits/stdc++.h>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

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

#define INF INT_MAX/3

#define MAX_N 1000

string S;
int n,s,w,e;

int main(){
	cin>>S;
	rep(i,S.length()){
		if(S[i]=='N')n++;
		else if(S[i]=='S')s++;
		else if(S[i]=='W')w++;
		else if(S[i]=='E')e++;
	}
	if((n!=0&&s==0)||(n==0&&s!=0)||(w!=0&&e==0)||(w==0&&e!=0)) cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
	return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
using namespace std;

int main() {
    
    long long sum = 0;
    int N;
    cin >> N;
    
    for ( int i = 0; i < N; i++ ) {
        long long t;
        cin >> t;
        sum += t;
    }
    
    cout << (sum%2 ?  "NO": "YES") << endl;
    
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace MinPro2019C
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            long[] KAB = Console.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray();
            long K = KAB[0];
            long A = KAB[1];
            long B = KAB[2];

            if (B - A < 2)
            {
                Console.WriteLine(1 + K);
                return;
            }

            long ans = 0;
            long lest = K;
            if (lest >= A + 1)
            {
                ans += B;
                lest -= A + 1;
            }
            else
            {
                Console.WriteLine(K + 1);
                return;
            }

            ans += lest / 2 * (B - A) + lest % 2;
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
int main(){
int a=0;
int c=0;
string S; cin>>S;
for(int i=0; i<S.size();i++){
if(S.at(i)=='S')
a++;
else{
if(a>0)
a--;
else
c++;}}
cout<<a+c<<endl;}


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

int main() {
	int N;
  int A[110];
  cin >> N;
  for(int i=0; i <N; i++) cin >> A[i];
  sort(A, A+N, greater<int>());
  int sum1 = 0;
  int sum2 = 0;
  for(int i=0; i<N; i++){
    if(i % 2 == 0) {
    	sum1 += A[i];
           
    } else {
     	sum2 += A[i];   
     }
  }

  cout << sum1 - sum2 << endl;
}


Measured memory_bytes: 256
// module dcomp.scanner;

class Scanner {
	import std.stdio : File, readln, stdin;
	import std.conv : to;
	import std.range : front, popFront, array, ElementType;
	import std.array : split;
	import std.traits : isSomeString, isDynamicArray;
	import std.algorithm : map;
	File f;
	this(File f = stdin) {
		this.f = f;
	}
	string[] buf;
	bool succ() {
		while (!buf.length) {
			if (f.eof) return false;
			buf = readln.split;
		}
		return true;
	}
	int read(Args...)(auto ref Args args) {
		foreach (i, ref v; args) {
			if (!succ()) return i;
			alias VT = typeof(v);
			static if (!isSomeString!VT && isDynamicArray!VT) {
				v = buf.map!(to!(ElementType!VT)).array;
				buf.length = 0;
			} else {
				v = buf.front.to!VT;
				buf.popFront();
			}
		}
		return args.length;
	}
}
/+ dub.sdl:
	name "A"
	dependency "dcomp" version="~master"
+/

int main() {
	import std.stdio, std.algorithm;
// 	import dcomp.scanner;
	auto sc = new Scanner();
	string s;
	sc.read(s);
	int mi = 0, sm = 0;
	foreach (c; s) {
		if (c == 'S') {
			sm++;
		} else {
			sm--;
		}
		mi = min(mi, sm);
	}
	writeln(mi * -2);
	return 0;
}


Measured memory_bytes: 764
#include <stdio.h>
 
#define MAX_N 100002
 
typedef struct { char *p; int tm; } Q;
Q que[(MAX_N<<1)+2]; int top, end;
char name[MAX_N][20];
 
char buf[20], *p;
int in()
{
    int n = 0;
    while (*p >= '0') n = 10*n + (*p++ & 0xf);
    p++;
    return n;
}
 
int main()
{
    int  n, q, tm, i;
    Q  t;
 
    fgets(p=buf, 20, stdin);
    n = in(), q = in();
    for (i = 0; i < n; i++) {
        fgets(p=name[i], 20, stdin);
        while (*p > ' ') p++; *p++ = 0;
        que[i].p = name[i], que[i].tm = in();
    }
 
    tm = 0, top = 0, end = n;
    while (top != end) {
        t = que[top]; if (++top == MAX_N) top = 0;
        if (t.tm <= q) {
            printf("%s %d\n", t.p, tm+t.tm);
            tm += t.tm;
        } else {
            t.tm -= q;
            que[end] = t; if (++end == MAX_N) end = 0;
            tm += q;
        }
    }
    return 0;
}




Measured memory_bytes: 5224
n = int(input().rstrip())

def divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

ans = 0
for item in divisors(n):
    if item < n**0.5 + 1:
        continue
    ans += item - 1

print(ans)

Measured memory_bytes: 3272
#include <iostream>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;

const int N = (int)1e5;
ll fact[2*N+1];
ll inv_fact[2*N+1];

ll modPow(ll a, ll b) {
	if (b == 0) return 1;
	if (b & 1) return a * modPow(a, b-1) % MOD;
	return modPow(a*a % MOD, b >> 1);
}

ll choose(int a, int b) {
	ll div = inv_fact[b] * inv_fact[a-b] % MOD;
	return fact[a] * div % MOD;
}

ll chance(ll a_prob, ll b_prob, int n) {
	ll res = 0;
	for (int b_wins = 0; b_wins < n; ++b_wins) {
		ll mult1 = modPow(a_prob, n) * modPow(b_prob, b_wins) % MOD;
		ll mult2 = (n+b_wins) * choose(n-1+b_wins, b_wins) % MOD;
		res += mult1 * mult2 % MOD;
	}
	return res % MOD;
}

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

	int n, a, b, c;
	cin >> n >> a >> b >> c;

	fact[0] = 1;
	for (int i = 1; i <= 2*n; ++i) fact[i] = fact[i-1] * i % MOD;
	for (int i = 0; i <= 2*n; ++i) inv_fact[i] = modPow(fact[i], MOD-2);

	ll mult = 100 * modPow(100-c, MOD-2) % MOD;
	ll a_prob = a * modPow(a+b, MOD-2) % MOD;
	ll b_prob = b * modPow(a+b, MOD-2) % MOD;

	ll res = 0;
	res += chance(a_prob, b_prob, n);
	res += chance(b_prob, a_prob, n);
	res = res * mult % MOD;
	cout << res << '\n';
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define forn(low,high,i) for(i = low;i < high;i++)
#define forrev(high,low,i) for(i = high; i >= low;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define line cout << __LINE__;
#define prv(a) for(auto x : a) cout << x << ' ';cout << '\n';
#define prvp(a) for(auto x : a) cout << "{" << x.ff << ',' << x.ss << "}";cout << '\n';
#define decimal_digits cout << fixed << setprecision(15);
#define dbg2(a,b) cerr << #a << " = " << a << " " << #b << " = " << b << '\n';        
#define debug(x) cerr << __LINE__ << ' ' << #x << " = " << x << '\n';

typedef unordered_map<int,int> umi;
typedef unordered_map<ll,ll> uml;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

const int inf = 1e9;
const ll INF = 1e18;
const int mod = 1e9 + 7;
const int bit32 = log2(inf) + 3;
const int bit64 = log2(INF) + 3;

inline int add(int a, int b){a += b; if(a >= mod) a -= mod; return a;}
inline int sub(int a, int b){a -= b; if(a < 0) a += mod; return a;}
inline int mul(int a, int b){return (int)((long long) a * b % mod);}
inline int modexpo(int a, int b){int res = 1; while(b > 0){ if(b & 1) res = mul(res, a); a = mul(a, a); b /= 2;} return res;}
inline int divide(int a, int b){ return mul(a, modexpo(b, mod - 2));}

clock_t time_p = clock();

void ktj(){
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (float)(time_p)/CLOCKS_PER_SEC << "\n";
}

int main(){
  fastio

  ll n, k, i, j;
  cin >> n >> k;
  ll a[n], c[n];
  pll b[n];
  ll sum = 0;
  forn(0, n, i){
    cin >> a[i];
    sum += a[i];
  }
  forn(0, n, i){
    cin >> b[i].ff;
    c[i] = b[i].ff;
    b[i].ss = i;
  }
  sort(a, a + n);
  sort(b, b + n);
  reverse(b, b + n);
  forn(0, n, i){
    a[i] *= b[i].ff;
  }

  if(sum <= k){
    cout << 0 << '\n';
  }else{
    ll l = 0, r = INF, m;
    ll ans = r;
    while(l <= r){
      m = (l + r) >> 1;
      ll now = 0;
      forn(0, n, i){
        if(a[i] > m){
          ll j = b[i].ss;
          ll r = c[j];
          ll t = (a[i] - m + r - 1) / r;
          now += t;
        }
      }
      if(now <= k){
        ans = m;
        r = m - 1;
      }else{
        l = m + 1;
      }
    }
    cout << ans << '\n';
  }

  ktj();
}


Measured memory_bytes: 6528
/***********************************************************
	When you are inspired by passion 
	and you want to live for the current moment

	When your every thought and action
	has the power to become the story of your future

	When difficulties stand to demolish your Glory
	Just remember that Life is a 'Golden adverse Story'

	Withstand it to acheive your passion and dreams
	more amazingly more easily.

	Why then? When writing the story of your Life
	You want to Let someone else hold your pen

					huzaifa242©

***********************************************************/
#include <bits/stdc++.h>
using namespace std;
#define int int32_t
#define MAX 100005
#define x first 
#define y second

int seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline int rnd(int l=0,int r=INT_MAX)
{return uniform_int_distribution<int>(l,r)(rng);}

template <typename T,typename G>
ostream& operator << (ostream& out, const pair<T,G> &a) 
{return out<<"( "<<a.x<<", "<<a.y<<")";}

template <typename T>
ostream& operator << (ostream& out, const vector<T> &a) 
{out<<"[ ";for(const auto &i:a)out<<i<<", ";return out<<"]"<<endl;}

template <typename T>
ostream& operator << (ostream& out, const set<T> &a) 
{out<<"{ ";for(const auto &i:a)out<<i<<", ";return out<<"}"<<endl;}

template <typename T,typename G>
ostream& operator << (ostream& out, const map<T,G> &a) 
{out<<"< ";for(const auto &i:a)out<<i<<", ";return out<<">"<<endl;}

template<typename T, size_t N>
typename enable_if<!is_same<typename remove_cv<T>::type, char>::value,
ostream&>::type operator<<(ostream& out, T(&a)[N])
{out<<"[ ";for(size_t i=0;i<N;++i)out<<a[i]<<", ";out <<"]"<<endl;return out;}

void debug_out(){cerr<<endl;} 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{cerr<<(H)<<" ";debug_out(T...);}
 
#ifdef LOCAL
#define debug(...) cerr<<"#"<<#__VA_ARGS__<<":\n",debug_out(__VA_ARGS__)
#else
#define debug(...) 24
#endif

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int n,k,i;
	cin>>n>>k;
	vector<int> a(n);
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a.begin(),a.end());
	long long sum=0;
	for(i=0;i<k;i++)
		sum+=a[i];
	cout<<sum<<"\n";
	return 0;
}


Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = "";
		long j = 1;
		for(long i = 2; n != 0; i *= 2) {
			if(n % i != 0) {
				n -= j;
				s = "1" + s;
			}
			else 
				s = "0" + s;
			j *= -2;
		}
		if(s.isEmpty()) s = "0";
		System.out.println(s);
	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <set>
#include <cstring>
#define pb push_back
#define tam 520004
#define offset 320000
#define se second
#define fi first
#define pitem item*
#define ptr tre*
#define forr(i,p,n) for(int i=p;i<n;i++)
using namespace std;
typedef long long ll;
const ll MOD=1000000007 ;
ll mult(ll a,ll b, ll p=MOD){return ((a%p)*(b%p))%p;}
ll add(ll a, ll b, ll p=MOD){return (a%p + b%p)%p;}
typedef pair<ll,ll> ii;
typedef pair<ll,ii> iii;
ll n,w;
ll dp[102][303][102];
ll peso[302],valor[302];
ll f(int pos,int suma,int cuantos)
{
    if (pos==n)
    {
        ll auxval=cuantos;auxval*=peso[0];auxval+=suma;
        if (auxval<=w)
            return 0;
        return -1e10;
    }
    if (dp[pos][suma][cuantos]!=-1)
        return dp[pos][suma][cuantos];
    return dp[pos][suma][cuantos]=max(f(pos+1,suma+peso[pos]-peso[0],cuantos+1)+valor[pos],
    f(pos+1,suma,cuantos));
}
int main()
{
    cin>>n>>w;
    forr(i,0,n)
    {
        cin>>peso[i]>>valor[i];

    }
    memset(dp,-1,sizeof dp);
    cout<<f(0,0,0)<<endl;
}


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


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

    i64 ans = 0;
    ans += (x / 500) * 1000;
    x = x % 500;

    ans += (x / 5) * 5;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
(defun is-like-coffee (l)
  (and (eql (nth 2 l) (nth 3 l))
       (eql (nth 4 l) (nth 5 l))))

(let ((str (read-line)))
  (if (is-like-coffee (coerce str 'list))
      (princ "Yes")
      (princ "No")))

Measured memory_bytes: 9956
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)  
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define RVSORT(v) sort(v.rbegin(), v.rend());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int gcd(int a,int b){return b?gcd(b,a%b):a;}

ll modpow(ll n,ll k){
  if(k == 1){
    return n;
  }else if(k == 0){
    return 1;
  }else if(k%2==0){
    ll memo = modpow(n,k/2)%MOD;
    return memo*memo%MOD;
  }else{
    return n * modpow(n,k-1)%MOD;
  }
}

int main(){

  string s;cin>>s;
  int n = s.size();

  ll dp[n][13];

  REP(i,n){
    REP(j,13){
      dp[i][j] = 0;
    }
  }

  if(s[n-1]=='?'){
    REP(i,13){
      if(i<10){
        dp[0][i] = 1;
      }
    }
  }else{
    int t = s[n-1] - '0';
    REP(i,13){
      if(i==t){
        dp[0][i] = 1;
      }
    }
  }
  int bai = 1;

  for(int i=1;i<n;i++){
    bai = bai*10%13;
    if(s[n-1-i]=='?'){
      REP(j,13){
        REP(k,10){
          int t = k * bai % 13;
          dp[i][(j+t)%13] += dp[i-1][j];
        }
      }
    }else{
      int t = (s[n-1-i] - '0') * bai % 13;
      REP(j,13){
        dp[i][(j+t)%13] += dp[i-1][j];
      }
    }
    REP(j,13){
      dp[i][j] %= MOD;
    }
  }

  cout<<dp[n-1][5]%MOD<<endl;
 

  return 0;
}

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

int main() {
int X,N;
  cin >> X >> N;
  if(N == 0){
  	cout << X << endl;
  }
  else{
  	vector<int> kazu(N);
    map<int,int> kaka;
    for(int i = 0; i < N; i++){
      	cin >> kazu[i];
      	kaka[kazu[i]] = kazu[i];
    }
    for(int i = 0; i < 100; i++){
    	if(!kaka.count(X-i)){
        	cout << X-i << endl;
          	break;
        }
      	if(!kaka.count(X+i)){
        	cout << X+i << endl;
          	break;
        }
    }
    
  }

}

Measured memory_bytes: 3576
# 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>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 100000000000000;
const double PI = acos(-1);

int num[100100];
bool isc[100100];

int main() {
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		num[i] = 1;
		isc[i] = false;
	}
	isc[1] = true;
	int x, y;
	for (int i = 1; i <= m; i++) {
		cin >> x >> y;
		if (isc[x])isc[y] = true;
		num[x]--;
		num[y]++;
		if (num[x] == 0)isc[x] = false;
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		if(isc[i])ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 768
<?php
// From https://qiita.com/yoshikyoto/items/6924478283dbdd549e4b
class Scanner {
    private $arr = [];
    private $count = 0;
    private $pointer = 0;
    public function next() {
        if($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }
    public function hasNext() {
        return $this->pointer < $this->count;
    }
    public function nextInt() {
        return (int)$this->next();
    }
    public function nextDouble() {
        return (double)$this->next();
    }
}
// From https://qiita.com/yoshikyoto/items/6924478283dbdd549e4b
list($N,$K)=sscanf(trim(fgets(STDIN)),"%d %d");
$sc = new Scanner();
$cnt=0;
for($i=0;$i<$N;$i++){
    $n = $sc->nextInt();
    if($n >= $K){
        $cnt++;
    }
}
printf($cnt);

Measured memory_bytes: 12792
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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

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

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

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

//----------------------------------------------------------------


int main(){
string s;
cin>>s;
set<char>set;
for(int i=0;i<s.size();i++){
    set.insert(s.at(i));
}
if(set.size()==1){
    cout<<"No"<<endl;
}else{
    cout<<"Yes"<<endl;
}
}









Measured memory_bytes: 256
class UnionFind:
    def __init__(self, n):
        self.n = n
        self.p = [e for e in range(n)]
        self.rank = [0] * n
        self.size = [1] * n

    def same(self, u, v):
        return self.find_set(u) == self.find_set(v)

    def unite(self, u, v):
        u = self.find_set(u)
        v = self.find_set(v)

        if u == v:
            return

        if self.rank[u] > self.rank[v]:
            self.p[v] = u
            self.size[u] += self.size[v]
        else:
            self.p[u] = v
            self.size[v] += self.size[u]
            if self.rank[u] == self.rank[v]:
                self.rank[v] += 1

    def find_set(self, u):
        if u != self.p[u]:
            self.p[u] = self.find_set(self.p[u])

        return self.p[u]

    def update_p(self):
        for u in range(self.n):
            self.find_set(u)

    def get_size(self, u):
        return self.size[self.find_set(u)]


n = int(input())
a = [0] + list(map(int, input().split())) + [n + 1]

idx = [0] * (n + 2)
for i, e in enumerate(a):
    idx[e] = i

uf_l = UnionFind(n + 2)
uf_r = UnionFind(n + 2)

ans = 0
for num in range(n, 0, -1):
    i = idx[num]
    ans += num * (uf_l.get_size(i) * uf_r.get_size(i))
    uf_l.unite(i, i + 1)
    uf_r.unite(i, i - 1)

print(ans)



Measured memory_bytes: 43196
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
int main() {
  long long n,a[10000]={},b[10000]={},cnta=0,cntb=0;
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> a[i];
  }
  for(int i=0; i<n; i++) {
    cin >> b[i];
    if(a[i]>b[i]) {
      cntb+=a[i]-b[i];
    }
    else {
      cnta+=(b[i]-a[i])/2;
    }
  }
  if(cnta>=cntb) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 384
n, k = gets.split.map(&:to_i)
MOD = 10 ** 9 + 7

@ans = 0

k.upto(n+1) do |x|
    #a = (0..x-1).inject(:+)
    #b = (n-x+1..n).inject(:+)
    
    #n-x+1 * n
    #puts "#{b} #{a} #{b-a+1}"
    #puts "#{n} - #{x} * #{x} #{(n-x+1) * x + 1}"
    
    
    @ans = (@ans + (n-x+1) * x + 1) % MOD
end

puts @ans

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

ll dp[105][4][2];

int main() {
string s;
cin >> s;
int n = s.size();
int K;
cin >> K;
dp[0][0][0] = 1;

for(int i=0; i<n; i++){
   for(int j = 0;j<4; j++){
     for(int k = 0; k<2;k++){
        int nd = s[i]-'0';
         for(int d = 0;d<=9;d++){
               int ni = i+1;  int nj = j; int nk = k;
               if(d != 0) nj++;
               if(nj > K) continue;
              if(k ==0){
                     if(nd < d) continue;
                     if(nd > d ) nk = 1;
                    }
                dp[ni][ nj][nk] += dp[i][j][k];
                }
         }
    }
}
ll ans = dp[n][K][0]+dp[n][K][1] ;
cout << ans << endl;
return 0;
}


Measured memory_bytes: 3608
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <queue>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rrep(i,n) for(int i = 1; i <= n; ++i)
using namespace std;
typedef pair<int,int> P;
const int INF = 1000000000;


int c,a,n;



int main(){
	int q;
	scanf("%d",&q);
	rep(i,q){
		scanf("%d%d%d",&c,&a,&n);
		int ans = 0,temp;
		
		temp = min(c,min(a,n));
		ans += temp;
		a-=temp;
		c-=temp;
		
		temp = min(c/2,a);
		ans += temp;
		c -= temp*2;
		
		ans  += c/3;
		
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1028
A = int(input())
B = int(input())
C = int(input())
X = int(input())
ans = 0
for a in range(A+1):
  for b in range(B+1):
    for c in range(C+1):
      if 500*a+100*b+50*c == X:
        ans = ans + 1
      
print(ans)

Measured memory_bytes: 3188
#include <iostream>

using namespace std;

 int main(void) {

	 int n, a, b, c, x;
	 int y;
	 int cnt;

	 while (1){

		 cin >> n >> a >> b >> c >> x;
		 if (n == 0 && a == 0 && b == 0 && c == 0 && x == 0) break;

		 cnt = 0;
		 for (int i = 0; i < n; i++){
			 cin >> y;
			 while (y != x&&cnt <= 10000){
				 x = (a*x + b) % c;
				 cnt++;
			 }
			 if (i != n - 1){
				 x = (a*x + b) % c;
				 cnt++;
			 }
		 }
		 if (cnt <= 10000) cout << cnt << endl;
		 else cout << "-1" << endl;
	 }

	 return 0;
	
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define FAST std::ios::sync_with_stdio(0);
#define FOUT freopen(".out", "w", stdout);
#define FIN freopen(".in", "r", stdin);
#define MOD 1000000007
#define KKK 1073741824
#define pb push_back
#define mp make_pair
#define PB pop_back
#define S second
#define SZ size
#define F first
using namespace std;
long long dp[3333][3333];
int n,i,j;
string s;
int main() {
    FAST;
    cin>>n;
    cin>>s;
    s=" "+s;
    dp[1][1]=1;
    for(i=2;i<=n;i++){
        for(j=1;j<=i;j++){
            if(s[i-1]=='<') 
                dp[i][j]=(dp[i-1][j-1]+dp[i][j-1])%MOD;
            else
                dp[i][j]=(dp[i-1][i-1]-dp[i-1][j-1]+dp[i][j-1]+MOD)%MOD;
        }
    }
    cout<<dp[n][n]<<endl;
 
    return 0;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define pii pair<int,int>
#define all(x) begin(x), end(x)
#define loop(i,n) for(int i=0; i<n; i++)
#define rep(i,a,b,c) for(int i=a; i<b; i+=c)
#define brep(i,a,b,c) for(int i=a; i>b; i-=c)
#define tc(t) int t; cin>>t; while(t--)
#define sz(v) int((v).size())
#define pb push_back


using namespace std;

void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {std::cout << x;}
void __print(unsigned x) {std::cout << x;}
void __print(unsigned long x) {std::cout << x;}
void __print(unsigned long long x) {std::cout << x;}
void __print(float x) {std::cout << x;}
void __print(double x) {std::cout << x;}
void __print(long double x) {std::cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i : x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
template <typename T> inline void inp(T &any) {cin >> any;} template <typename T, typename... U>inline void inp(T &a, U &...b) {cin >> a; inp(b...);}
#define rin(args...) ll args; inp(args);
#ifndef ONLINE_JUDGE
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#define matdeb(mat,row,col) cout << #mat << "::" << endl; printmat(mat,row,col); printpartition;
#define debugv(v,n) cout << #v << ":" << endl; printv(v,0,n-1); printpartition;
#else
#define debug(x...)
#define matdeb(mat,row,col)
#define debugv(v,n)
#endif

const int maxm = 1000000000 + 7;

const ll MOD = 1e9 + 7;
const int INF = 55;
ll dp [INF] [INF * INF];

double startTime;
double getCurrentTime() {
  return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}


//----------->CODE BEGINS --------------->




int main()
{

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  IOS;

  ll n,m;
  cin>>n>>m;

  // for 1 n = 2m

  ll ans = 0;

  if(m>=n*2)
  {
    ans += n;
  }

  else
  {
    cout<<m/2<<endl;
    return 0;
  }

  m -= n*2;

 
  ans += m/4;

  cout<<ans<<endl;
}


Measured memory_bytes: 3560
#include <stdio.h>
int main(void){
    
    int w,a,b,c;
    
    scanf("%d%d%d",&w,&a,&b);
    
    if(b<a){
        c=a-b-w;
    }
    else{
        c=b-a-w;
    }
    
    if(c>0)
    printf("%d\n",c);
    else
    printf("0\n");
}


Measured memory_bytes: 1628
#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
int main()
{
    int d;
    string a,b,c;
    double q;
   while(cin>>a>>b){
        c=a+b;
   d=0;
    for(int i=0;i<c.length();i++)
        {d=d*10+c[i]-'0';
        //cout<<d<<endl;
        }
    q=sqrt(d);
    if(q==ceil(q))
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
   }
}


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

using namespace std;
int main()
{
    long long N;
    cin >> N;
    std::multiset<long long> v;
    std::multiset<long long> pow2;

    for (long long i = 2; i < 10e12; i *= 2)
    {
        pow2.insert(i);
    }

    for (long long i = 0; i < N; i++)
    {
        long long tmp;
        cin >> tmp;
        v.insert(tmp);
    }

    //sort(v.begin(), v.end());
    //v.sort();

    long long ans = 0;

    /*
    std::cout
        << std::boolalpha
        << std::binary_search(v.begin(), v.end(), 3, greater<long long>())
        << std::endl;
        */

    while (v.size() >= 2)
    {
        long long pairOne = *v.rbegin();
        v.erase(v.find(pairOne));
        long long pairTwo;

        auto iterPow2 = upper_bound(pow2.begin(), pow2.end(), pairOne);
        pairTwo = *iterPow2 - pairOne;

        auto iterTwo = v.find(pairTwo);
        if (iterTwo != v.end())
        {
            v.erase(iterTwo);
            ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int mod=1e9+7;
int dp[3001][3001],pref[3001][3001];
int add_self(int &a,int b)
{
    a=(a+b)%mod;
}
int main()
{
    int n;
    string s;
    cin>>n;
    cin>>s;
    //dp[i][last_no]
   // int dp[]
   dp[0][1]=1;
    for(int i=1;i<n;i++)
    {
       for(int k=1;k<=i;k++)
       {
           pref[i-1][k]=(pref[i-1][k-1]+dp[i-1][k])%mod;
       }
       
        for(int k=1;k<=i+1;k++)
        {
            int L,R;
            if(s[i-1]=='<')
            {
                 L=1;
                 R=k-1;

            }
            else
            {
                L=k;
                R=i;
            }
            if(L<=R)
            add_self(dp[i][k],(pref[i-1][R]-pref[i-1][L-1]+mod)%mod);
            // for(int j=L;j<=R;j++)
            // {
            //     add_self(dp[i][k],dp[i-1][j]);
            // }
            
        //      for(int j=1;j<=i;j++)
        // {
        //     if(check(k,s[i-1],j))
        //     {
        //         dp[i][k]+=dp[i-1][j];
        //     }

        // }

        }

    }
    int sum=0;
    for(int j=1;j<=n;j++)
    {
        add_self(sum,dp[n-1][j]);
    }
    cout<<sum<<endl;
}

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

int main(){
    int a, b;
    cin >> a >> b;
    int x1, x2, x3;
    x1 = a+b;
    x2 = a-b;
    x3 = a*b;
    int aux = max(x1, x2);
    aux = max(aux, x3);
    cout << aux << endl;
}

Measured memory_bytes: 256
import sys
h, w = map(int, input().split())

s = [["." for _ in range(w+2)]] + [["."]+list(input())+["."] for _ in range(h)] + [["." for _ in range(w+2)]]
for r in range(1, h+1):
  for c in range(1, w+1):
    if s[r][c] == ".":
      s[r][c] = str([s[r+dr][c+dc] for dr in [-1, 0, 1] for dc in [-1, 0, 1]].count("#"))
for r in range(1, h+1):
  print("".join(s[r][1:w+1]))


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define BUF (200005)
#define ll long long 
int n;
ll s[23][BUF];
ll  a[23];
int main(void){
	cin >> n;
	for(int i=1;i<=n;i++){
		ll tmp;
		cin >> tmp;
		for(int j=0;j<22;j++){
			s[j][i] = s[j][i-1] + (tmp>>j)%2;
		}
	}
	ll ans = 0;
	for(int i=1;i<=n;++i){
		int low = i;
		int hi = n+1;
		while(low+1<hi){
			int mid = (low+hi)/2;
			int f=0;
			for(int j=0;j<22;++j){
				a[j] = s[j][mid] - s[j][i-1];
				if(a[j]>1){
					hi = mid;
					f=1;
				}
			}
			if(f) continue;
			low = mid;
		}
		ans += low - i + 1; 
	}
 
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 35072