akhauriyash/Code-Regression huggingface dataset:
package main

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

func scanInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func scanInt64() int64 {
	sc.Scan()
	i, _ := strconv.ParseInt(sc.Text(), 10, 64)
	return i
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func scanInts64(n int) []int64 {
	res := make([]int64, n)
	for i := range res {
		res[i] = scanInt64()
	}
	return res
}

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	s, w := scanInt(), scanInt()

	if s <= w {
		fmt.Println("unsafe")
	} else {
		fmt.Println("safe")
	}
}


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

vector<pair<long long, long long> > pf(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

int main() {
    //
    int n;
    long long p;

    cin >> n >> p;

    auto f = pf(p);

    long long cnt = 1;
    for (auto P : f) {
        for (int i = 0; i < P.second / n; i++) { cnt *= P.first; }
    }

    cout << cnt;
    //
}


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

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define lfs <<fixed<<setprecision(10)<<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = n - 1; i >= (ll)(m); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main(){
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  ll n;cin>>n;
  vector<ll>a(n);
  rep(i,0,n)cin>>a[i];
  vector<ll>b(n+1);
  rep(i,0,n)b[i+1]=b[i]+a[i];
  auto dp=vec(n,n,0LL);
  rep(i,1,n){
    rep(j,0,n-i){
      ll l=j,r=j+i;
      ll minbuf=INF;
      rep(o,l,r){
        chmin(minbuf,dp[l][o]+dp[o+1][r]+b[r+1]-b[l]);
      }
      dp[l][r]=minbuf;
    }
  }
  cout<<dp[0][n-1]<<endl;
  return 0;
}

Measured memory_bytes: 1536
#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;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n,2);
  b[0] = 1;
  rep(i,n) cin >> a[i];

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

  if(n==2){
    cout << a[0] << endl;
    return 0;
  }

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

  cout << ans << endl;

  return 0;
}

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

int fnc(int x) {
  if(x%100!=0) return 0;
  return fnc(x/100)+1;
}

int main() {
  int n, D;
  cin >> D >> n;
  int cnt=0;
  for(int i=1; i>0; i++) {
    if(fnc(i)==D) cnt++;
    if(cnt==n) {
      cout << i << endl;
      return 0;
    }
  }
}

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

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int d,s,t;
	cin>>d>>s>>t;
	if(d<=s*t)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

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

int main() {
	long long A,B,K;
	cin>>A>>B>>K;
	if(K>A+B){
		cout<<0<<" "<<0<<endl;
	}
	else if(K<=A){
		cout<<A-K<<" "<<B<<endl;
		
	}
	else{
		cout<<0<<" "<<A+B-K<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fast_io ios :: sync_with_stdio(false);
using namespace std;

int main() {
	cout << fixed << setprecision(3);
	fast_io;
	int n; cin >> n;
	string s; cin >> s;
	string r;
	char l;
	if(n != 0) {
		for (int i = 0; i < s.size(); i++) {
			if(int(s[i]) + n > int('Z')) {
				l = char(int(s[i]) + n - 26);		
			} else {
				l = int(s[i] + n);
			}
			if(r == "") {
				r = l; 
			} else {
				r += l;
			}
		}	
	} else {
		r = s;	
	}
	cout << r;
	return 0;	
}

Measured memory_bytes: 3624
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main(){
    int n;
    cin >> n;
    cout << n*(n+1)/2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>



int main() {
    int n;
    long long ans, r=0, g=0, b=0;
    std::string s;
    std::cin >> n >> s;

    for (int i=0; i<n; ++i) {
        if (s[i] == 'R') ++r;
        else if (s[i] == 'G') ++g;
        else ++b;
    }
    ans = r*g*b;

    for (int i=0; i<n; ++i) {
        for (int j=i+1; j<n; ++j) {
            int k=2*j-i;
            if (k < n && s[i] != s[j] && s[j] != s[k] && s[i] != s[k]) --ans;
        }
    }

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


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define fio ios_base::sync_with_stdio(false)
#define pdl cout << "*" << endl
#define MOD 1000000007
#define INF 1000000000
#define INFLL 1000000000000000000ll
#define pb push_back
#define ff first
#define ss second
#define long int64_t
using namespace std;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_int_distribution<> dis(0, INF<<1);
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char* name, Arg1&& arg1){ cerr << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args)
{ const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma+1, args...); }

int main()
{
	fio;
	int n, k;
	cin >> n >> k;
	cout << n - k + 1 << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int n = sc.nextInt();
			if(n==0) break;
			int[] a = new int[n];
			for(int i=0;i<n;i++) a[i] = sc.nextInt();
			int count = 0;
			int temp = 0;
			int tempB = 0;
			while(true){
				for(int i=0;i<n-1;i++){
					if(a[i]>a[i+1]){
						temp = a[i+1];
						a[i+1] = a[i];
						a[i] = temp;
						count++;
					}
				}
				if(tempB==count) break;
				tempB = count;
			}
			System.out.println(count);
		}
	}	
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void solve() {
    ll N, M, K;
    cin >> N >> M >> K;
    vector<ll> A(N), B(M), acc(N, 0), bcc(M, 0);
    rep(i, N) cin >> A[i];
    rep(i, M) cin >> B[i];
    ll ans = 0;
    acc[0] = A[0];
    rep2(i, 1, N) {
        acc[i] += acc[i - 1] + A[i];
    }
    bcc[0] = B[0];
    rep2(i, 1, M) {
        bcc[i] += bcc[i - 1] + B[i];
    }
    rep(i, N) {
        ll s = acc[i];
        if (s > K) continue;
        ll re = K - s;
        ans = max(i + 1, ans);
        ll idx = upper_bound(bcc.begin(), bcc.end(), re) - bcc.begin();
        // print(re, idx);
        ans = max(ans, i + 1 + idx);
    }
    rep(i, M) {
        ll s = bcc[i];
        if (s > K) continue;
        ll re = K - s;
        ans = max(i + 1, ans);
        ll idx = upper_bound(acc.begin(), acc.end(), re) - acc.begin();
        // print(re, idx);
        ans = max(ans, i + 1 + idx);
    }
    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;
  pair<ll, ll> ans(a * 100, 0);
  for (int i = 0; i <= f / 100 / a; i++) {
    for (int j = 0; j <= f / 100 / b; j++) {
      ll rest = f - a * 100 * i - b * 100 * j;
      if (rest < 0) continue;
      for (int k = 0; k <= rest / c; k++)
        for (int l = 0; l <= (rest - k * c) / d; l++) {
          ll w = a * 100 * i + b * 100 * j;
          ll s = c * k + d * l;
          if (e * w < s * 100) continue;
          if (ans.second * (w + s) < s * ans.first) {
            ans.second = s;
            ans.first = w + s;
          }
        }
    }
  }
  cout << ans.first << " " << ans.second << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
# define mod 1000000007
# define INF (1 << 29)
# define MAX_N 1000010
/* ちゃんと考えてわかって実装 */

int main(void){
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    for(int i=0; i<n; i++){
        cin >> b[i];
    }
    for(int i=0; i<n; i++){
        cin >> c[i];
    }

    sort(a.begin(), a.end());
    sort(c.begin(), c.end());
    /* 各 b[i] に対して、
    b[i] > a[j] となる j の個数と
    b[i] < c[k] となる k の個数を求めたらok */

    ll ans = 0;
    for(int i=0; i<n; i++){
        auto it_a = upper_bound(a.begin(), a.end(), b[i]-1);
        auto it_c = lower_bound(c.begin(), c.end(), b[i]+1);
        ans += (it_a - a.begin()) * (c.end() - it_c);
        // int num_a = distance(a.begin(), upper_bound(a.begin(), a.end(), b[i]-1));
        // int num_c = distance(lower_bound(c.begin(), c.end(), b[i]+1), c.end());
        // ans += (num_a * num_c);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	int n;
	string s;
	cin >> n >> s;
	
	int ans = 0;
	int cnt = 0;
	for(int i = 0; i < n; ++i) {
		if( s[i] == 'I' ) cnt++;
		else cnt--;
		
		ans = max(ans, cnt);
	}
	
	cout << ans << endl;
	
	return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

//-------------------------------------------------
//--Enum various numbers
//-------------------------------------------------
namespace Enum
{
    using fint = ::std::int_fast64_t;
    //素因数分解(素因数列挙)
    ::std::map<fint,int> factor(fint n)
    {
        ::std::map<fint,int> ret;
        for(fint i=2; i*i<=n; i++){
            while(n%i==0){
                ret[i]++;
                n/=i;
            }
        }
        if (n!=1) ret[n]++;
        return ret;
    }
    //約数列挙
    ::std::vector<fint> divisor(fint n)
    {
        ::std::vector<fint> ret;
        for(fint i=1; i*i<=n; i++){
            if (n%i==0){
                ret.push_back(i);
                if (i*i!=n) ret.push_back(n/i);
            }
        }
        return ret;
    }
    //商列挙(割る最小の数と商のペア)
    ::std::vector<::std::pair<fint,fint> > quotient(fint n)
    {
        ::std::vector<::std::pair<fint,fint> > ret;
        fint i=0;
        for(i=1; i*i<=n; i++){
            ret.emplace_back(i,n/i);
        }
        for(; i<=n; i++){
            fint d = n/i;
            ret.emplace_back(i,d);
            i+=(n-d*i)/d;
        }
        return ret;
    }
    //素数判定(おまけ)
    bool isprime(fint n)
    {
        for(fint i=2; i*i<=n; i++){
            if (n%i==0) return false;
        }
        return true;
    }
}

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; ll k; cin>>n>>k;
    vll a(n);
    ll sum=0;
    rep(i,n){
        cin>>a[i];
        sum+=a[i];
    }
    auto d = Enum::divisor(sum);
    sort(rall(d));
    for(auto e:d){
        vll t(n);
        ll tsum=0;
        rep(i,n) t[i] = a[i]%e;
        rep(i,n) tsum += t[i];
        sort(rall(t));
        int num = tsum/e;
        rep(i,num) tsum-=t[i];
        if (tsum<=k){
            cout<<e<<endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(void) {
  int n, k;
  cin >> n >> k;
  int ans = 1;
  for (int i = 0; i < n; i++) {
    ans = min(ans * 2, ans + k);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
const MOD: usize = 1e9 as usize + 7;
const SIZE: usize = 64;
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };

    let l: usize = sc.read();
    let r: usize = sc.read();

    // y%x == y^x
    // highest(x) == highest(y)
    //
    // dp[p][q][r]
    // p
    // x[bit], y[bit] = (0,0), (0,1), (1,1)

    let l = (0..SIZE).rev().map(|i| (l >> i) & 1).collect::<Vec<_>>();
    let r = (0..SIZE).rev().map(|i| (r >> i) & 1).collect::<Vec<_>>();

    let mut dp = vec![vec![vec![0; 2]; 2]; 2];
    dp[0][0][0] = 1;

    for bit in 0..SIZE {
        let mut next = vec![vec![vec![0; 2]; 2]; 2];
        for has_highest in 0..2 {
            for y_low_r in 0..2 {
                for x_up_l in 0..2 {
                    // (x, y) = (1, 1)
                    if y_low_r == 1 || r[bit] == 1 {
                        let next_x_up_l = if l[bit] == 0 { 1 } else { x_up_l };
                        next[1][y_low_r][next_x_up_l] += dp[has_highest][y_low_r][x_up_l];
                        next[1][y_low_r][next_x_up_l] %= MOD;
                    }

                    // (x, y) = (0, 1)
                    if has_highest == 1
                        && (y_low_r == 1 || r[bit] == 1)
                        && (x_up_l == 1 || l[bit] == 0)
                    {
                        next[1][y_low_r][x_up_l] += dp[has_highest][y_low_r][x_up_l];
                        next[1][y_low_r][x_up_l] %= MOD;
                    }

                    // (x, y) = (0, 0)
                    if x_up_l == 1 || l[bit] == 0 {
                        let next_y_low_r = if r[bit] == 1 { 1 } else { y_low_r };
                        next[has_highest][next_y_low_r][x_up_l] += dp[has_highest][y_low_r][x_up_l];
                        next[has_highest][next_y_low_r][x_up_l] %= MOD;
                    }
                }
            }
        }
        dp = next;
    }

    let mut sum = 0;
    for i in 0..2 {
        for j in 0..2 {
            for k in 0..2 {
                sum += dp[i][j][k];
            }
        }
    }
    println!("{}", sum % MOD);
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    if (A == 5 && B == 7 && C == 5){
        cout << "YES" << endl;
    }
    else if (A == 7 && B == 5 && C == 5) {
        cout << "YES" << endl;
    }
    else if (A == 5 && B == 5 && C == 7){
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}


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

struct U_F{
    vector<ll> par;
    vector<ll> rank;
private:
    vector<ll> num;
public:
    void init(ll n){
        rep(i,0,n-1){
            par.pb(i);
            rank.pb(0);
            num.pb(1);
        }
    }
    ll find(ll x){
        if(par[x]==x)return x;
        return par[x]=find(par[x]);
    }
    void unite(ll x,ll y){
        x=find(x);
        y=find(y);
        if(x==y)return;
        if(rank[x]<rank[y]){
            par[x]=y;
            num[y]=num[x]+num[y];
        }else if(rank[x]==rank[y]){
            par[y]=x;
            rank[x]++;
            num[x]=num[x]+num[y];
        }else{
            par[y]=x;
            num[x]=num[x]+num[y];
        }
    }
    bool same(ll x,ll y){
        return find(x)==find(y);
    }
    ll g_num(ll x){
        x=find(x);
        return num[x];
    }
};

int main(){fastio
    ll n,k,l;cin>>n>>k>>l;
    U_F uf[2];
    uf[0].init(n);uf[1].init(n);
    rep(i,0,k-1){
        ll p,q;cin>>p>>q;
        uf[0].unite(p-1,q-1);
    }
    rep(i,0,l-1){
        ll p,q;cin>>p>>q;
        uf[1].unite(p-1,q-1);
    }
    map<l_l,vector<ll>> mp;
    rep(i,0,n-1){
        l_l hoge=l_l(uf[0].find(i),uf[1].find(i));
        if(mp.find(hoge)==mp.end()){
            mp[hoge].pb(i);
        }else{
            mp[hoge].pb(i);
        }
    }
    ll ans[n];
    for(auto itr=mp.begin();itr!=mp.end();++itr){
        vector<ll> v=itr->second;
        ll an=v.size();
        rep(i,0,v.size()-1){
            ans[v[i]]=an;
        }
    }
    rep(i,0,n-1){
        cout<<ans[i];
        if(i==n-1){
            cout<<endl;
        }else{
            cout<<' ';
        }
    }
    
    return 0;
}





Measured memory_bytes: 34004
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <unordered_map>
#include <set>
#include <iomanip>
#include <cmath>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
constexpr int INF = 1 << 30;
constexpr int MOD = 1e9 + 7;

int n;
string s;

int main() {
  cin.tie(0); ios_base::sync_with_stdio(false);
  int h,w;cin >> h >> w;
  REP(i,h) REP(j,w) {
    cin >> s;
    if(s == "snuke") {
      cout << char('A'+j) << i + 1 << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 256
/*input
5
1 4 3 5 2
*/
#include <bits/stdc++.h>
using namespace std;
const long long md=1e9+7;
long long a[1000005],n;

int main(){
	#ifdef ONLINE_JUDGE
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	#endif
	long long q,m,k,h,ans=0,sum=0,p,x,y;
	cin>>n;
	for(int i=0;i<n;++i){
		cin>>a[i];
		--a[i];
	}
	for(int i=0;i<n;++i){
		if(a[i]==i){
			++ans;
			swap(a[i],a[i+1]);
		}
	}
	for(int i=n;--i;){
		if(a[i]==i){
			++ans;
			swap(a[i],a[i-1]);
		}
	}
	for(int i=0;i<n;++i)
		assert(i!=a[i]);
	cout<<ans;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <string>

using namespace std;

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

    int x_max = -100;
    for (int i=0; i<n; i++) {
        int new_x;
        cin >> new_x;
        x_max = max(x_max, new_x);
    }

    int y_min = 100;
    for (int i=0; i<m; i++) {
        int new_y;
        cin >> new_y;
        y_min = min(y_min, new_y);
    }

    if (x_max < y_min && x_max < y && x < y_min)
        cout << "No War" << endl;
    else
        cout << "War" << endl;
}


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

int main(){
    int a,b,c;
    cin >>a >> b >> c;
    int buffer1, buffer2;
    if(a==b){
        cout << c << endl;
    }
    else if(a==c){
        cout << b << endl;
    }
    else{
        cout << a << endl;
    }
}

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int main() {
  in(string, s);
  out(s.substr(0, 3));
}


Measured memory_bytes: 3596
<?php
	fscanf( STDIN, "%d%d%d%d%d", $W, $H, $x, $y, $r );
	if( $x+$r <= $W and 0 <= $x-$r and $y+$r <= $H and 0 <= $y-$r ) {
		print "Yes";
	} else {
		print "No";
	}
?>

Measured memory_bytes: 6524
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner stdIn=new Scanner(System.in);
		String a=stdIn.next();
		String b=stdIn.next();
		String c=stdIn.next();
		int a1=a.length();
		int b1=b.length();
		int c1=c.length();
		String e="";
		String f;
		e=a.substring(a1-1,a1);
		f=b.substring(0,1);
		if(e.equals(f)){
			e=b.substring(b1-1,b1);
			f=c.substring(0,1);
			if(e.equals(f))
				System.out.println("YES");
			else
				System.out.println("NO");
		}
		else
			System.out.println("NO");
	}
}


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

const int maxn = 1e5 + 5;
const int mod = 1e9 + 7;

int n;
int a[26];
string s;

int main() {
    cin >> n >> s;    
    for (int i = 0; i < n; i++)
        a[s[i] - 'a']++;

    long long ans = 1;
    for (int i = 0; i < 26; i++) {
        ans *= a[i] + 1;
        ans %= mod;
    }
    cout << ans - 1 << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;


int main() {
    int n;
    cin >> n;
    vector<long long>as(n);
    vector<long long>bs(n + 1);
    vector<long long>cs(n + 1);
    vector<long long>ds(n);
    for(int i = 0; i < n; i++){
        cin >> as[i]; 
    }
    bs[0] = 0;
    cs[n] = 0;
    for (int i = 1; i <= n; i++){
        bs[i] = __gcd(bs[i - 1], as[i - 1]);
    }
        for (int i = n - 1; i >= 0; i--){
        cs[i] = __gcd(cs[i + 1], as[i]);
    }
    for (int i = 0; i < n; i++){
        ds[i] = __gcd(bs[i], cs[i + 1]);
    }
    sort (ds.begin(), ds.end());
    cout << ds[n - 1] << endl;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define rep(i, ss, ee) for (int i = ss; i < ee; ++i)
using namespace std;
void solve() {
  unsigned long long N, D, x, y, ans = 0;
  cin >> N >> D;
  D *= D;
  rep(i, 0, N) {
    cin >> x >> y;
    ans += (D >= x * x + y * y);
  }
  cout << ans << endl;
}

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

Measured memory_bytes: 3616
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>

#define rep(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)

#define INF ll 1 << 60
#define MOD 1000000007

typedef  long long ll;

using namespace std;

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

int gcd(long long int a,long long int b){
    long long int r;
    if(a < b){
        int tmp;
        tmp = a;
        a = b;
        b = tmp;
    }
    while(r = a % b){
        a = b;
        b = r;
    }
    return a;
}

void Integer_factorization(long long int b,long long int n){
    long long int a = 2;
    long long int count = 0;
    long long int ans = 1;
    long long int ndash = n;
    if(b == 1) cout << n << endl;
    else{
    while(ndash >= a*a){
        if(n % a  == 0){
            count++;
            n/=a;

        if(count % b == 0){
            ans *= a;
        }
        }else{a++;count = 0;}
    }

    cout<<  ans << endl;
    }
}

void ys(){
    cout << "Yes" << endl;
}

void yb(){
    cout << "YES" << endl;
}

void ns(){
    cout << "No" << endl;
}

void nb(){
    cout << "NO" << endl;
}


void solve(void){
    string s;
    cin >> s;
    if(s[0] != 'A'){
        cout << "WA";
        return;
    } 
    bool flag = true;
    int count = 0;
    rep(i,1,s.size()){
        if(isupper(s[i])){
            if(i == 1 || i == s.size()-1 || s[i] != 'C'){
                flag = false;
            }
            count++;
        }
    }
    if(count != 1 || !flag){
        cout << "WA";
        return;
    }
        cout << "AC";
}


   

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

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();
        final int[] array = new int[n + 1];

        int all = 0;
        for (int i = 1; i < n + 1; i++) {
            array[i] = scanner.nextInt();
            all += Math.abs(array[i] - array[i - 1]);
        }

        all += Math.abs(array[n]);

        for (int i = 1; i < n; i++) {
            System.out.println(all - Math.abs(array[i] - array[i - 1]) - Math.abs(array[i + 1] - array[i]) + Math.abs(array[i - 1] - array[i + 1]));
        }

        System.out.println(all - Math.abs(array[n] - array[n - 1]) - Math.abs(array[n]) + Math.abs(array[n - 1]));
    }
}


Measured memory_bytes: 64112
import numpy as np
N, C, *L = map(int, open(0).read().split())
program = np.zeros((10**5+2,C+1),np.int32)
for s,t,c in zip(*[iter(L)]*3):
  program[s][c] += 1
  program[t+1][c] += -1
program = np.cumsum(program, axis=0)
ans = max(np.count_nonzero(a) for a in program)
print(ans)

Measured memory_bytes: 84120
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
a = []
ans = 0
for i in range(n):
    arr = list(map(int,input().split()))
    a.append(arr)
for i in a:
    tmp = c
    for j in range(m):
        tmp += i[j]*b[j]
    if tmp > 0:ans+=1
print(ans)

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

int main() {
  int N; cin >> N;
  int A[N]; for (int i =0; i<N; i++) cin >> A[i];
  
  sort(A,A+N);
  bool check = false;
  
  for (int i =0; i<N; i++) {
    if (N % 2 ==0 && i % 2 ==0 && A[i] != i + 1) check = true;
    if (N % 2 ==0 && i % 2 ==1 && A[i] != i) check = true;
    if (N % 2 ==1 && i % 2 ==0 && A[i] != i) check = true;
    if (N % 2 ==1 && i % 2 ==1 && A[i] != i + 1) check = true;
  }
  
  long ans =1;
  for (int i =0; i<N/2; i++) {
    ans *= 2; ans %= 1000000007;
  }

  if (check) cout << 0 << endl;
  else  cout << ans << endl;
  
}

Measured memory_bytes: 3928
#include <iostream>
using namespace std;
int N;

int main() {
	cin>>N;
	long long A[100001]={};
	for(int i=0;i<N;++i)cin>>A[i];
	long long sum=0;
	long long total=0;
	for(int i=0;i<N;++i){
		total+=A[i];
		if(i%2>0){
			if(total<=0){
				sum-=(total-1);
				total=1;
			}
		}else{
			if(total>=0){
				sum+=(total+1);
				total=-1;
			}
		}
	}
	long long R=sum;
	sum=0;
	total=0;
	for(int i=0;i<N;++i){
		total+=A[i];
		if(i%2>0){
			if(total>=0){
				sum+=(total+1);
				total=-1;
			}
		}else{
			if(total<=0){
				sum-=(total-1);
				total=1;
			}
		}
	}
	R=min(R,sum);
	cout << R << endl;
	return 0;
}
;


Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,W=map(int,input().split())
    w,v=[0]*n,[0]*n
    for i in range(n):
        w[i],v[i]=map(int,input().split())
    V=sum(v)
    dp=[INF]*(V+1)
    dp[0]=0
    for i in range(n):
        newdp=dp[:]
        for x in range(V+1):
            if(x+v[i]<V+1):
                newdp[x+v[i]]=min(newdp[x+v[i]],dp[x]+w[i])
        dp=newdp
    for i in range(V,-1,-1):
        if(dp[i]<=W):
            print(i)
            return
resolve()

Measured memory_bytes: 115668
N = int(input())
mati = list(map(int,input().split()))
yuu = list(map(int,input().split()))
monster = 0
for i in range(N,0,-1):
    x = mati[i] + mati[i-1]
    if x <= yuu[i-1]:
        monster += x
        mati[i],mati[i-1] = 0,0
    else:
        monster += yuu[i-1]
        if yuu[i-1] >= mati[i]:
            mati[i-1] += -(yuu[i-1]-mati[i])
            mati[i] = 0
        else:
            mati[i] = mati[i] - yuu[i-1]
print(monster)

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

inline int read()
{
	int x=0,f=1;char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=x*10+c-'0';c=getchar();}
	return x*f;
}

const int maxn = 105;
int n, tot;
int main()
{
	n = read();
	printf("%d\n", n & 1 ? (n - 1) * (n - 3) / 2 + n - 1 : n * (n - 2) / 2);
	for (int i = 1; i <= n; i ++)
		for (int j = i + 1; j <= n; j ++)
			if (i + j != n + 1 - (n & 1))
				printf("%d %d\n", i, j);
	return 0;
}

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

int main(){
    ll x,t;
    cin>>x>>t;
    if (x-t<0)
    {
        /* code */
        cout<<0<<endl;
    }
    else
    {
        cout<<x-t<<endl;
    } 
}

Measured memory_bytes: 256
import java.util.*;

public class Main {


    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        long k = sc.nextLong();
//        int[] arr = new int[n];
        long[] arr = new long[n];

        int positive = 0;
        int negative = 0;
//        int zero = 0;

        for (int i=0; i<n; i++){
            long tmp = sc.nextLong();
            if (tmp<0) negative++;
            else if (0<tmp) positive++;
            arr[i] = tmp;
        }
        Arrays.sort(arr);

//        for (int i=0; i<n; i++) System.out.println(arr[i]);


//        for (int i=0; i<n; i++) System.out.println(arr[i]);

        long[] plus = new long[positive];
        long[] minus = new long[negative];

        long zero = n-positive-negative;
        int p = 0;
        int q = 0;

        for (int i=0; i<n; i++){
            if (0<arr[i]) plus[p++] = arr[i];
            else if (arr[i]<0) minus[q++] = arr[i];
        }

//        for (int i=0; i<plus.length; i++)System.out.println(plus[i]);
//        for (int i=0; i<minus.length; i++)System.out.println(minus[i]);


        long left = -(long)1e18-1;
        long right = (long)1e18+1;


        long mid = 0;

        while (right-left>1) {
            mid = (right+left)/2;
            if (count(plus, minus, zero, mid)>=k) {
                right = mid;
            } else {
                left = mid;
            }
        }

        System.out.print(right);

    }

    public static long count(long[] posi, long[] nega, long z, long mid){
        long res = 0;
        int t = posi.length-1;
        for (int i=0; i<posi.length-1; i++){
            while (t>=0 && posi[i]*posi[t]>mid) --t;
            res += Math.max(0, t-i);
        }

        t = 0;
        for (int i=nega.length-1; i>=0; i--){
            while (t<nega.length && nega[i]*nega[t]>mid) ++t;
            res += Math.max(0, i-t);
        }

        t = 0;
        for (int i=0; i<posi.length; i++){
            while (t<nega.length && posi[i]*nega[t]<=mid) ++t;
            res += Math.max(0, t);
        }

        if (0<=mid) res += z*(posi.length+nega.length)+z*(z-1)/2;
        return res;
    }
}



Measured memory_bytes: 84992
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#define int long long
using namespace std;

int n;
int a[100010];

signed main() {
	int i;
	
	cin >> n;
	for (i = 1; i <= n; i++) cin >> a[i];
	a[n + 1] = 0;
	n += 2;
	
	int ans = 0;
	for (i = 1; i < n; i++) ans += abs(a[i] - a[i - 1]);
	
	for (i = 1; i < n - 1; i++) {
		int x = abs(a[i] - a[i - 1]) + abs(a[i + 1] - a[i]);
		int y = abs(a[i + 1] - a[i - 1]);
		cout << ans + y - x << endl;
	}
	return 0;
}

Measured memory_bytes: 2680
#include<iostream>
#include<string>
using namespace std;
int main()
{
  string s;
  cin>>s;
int i;
 int k=0;
for(i=0;i<=3;i++)
  {
    if(s[i]=='1')
      {
	k=k+1;
      }
  }
 cout<<k<<endl;
 return 0;
}



Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def main():
    N, C = map(int, input().split())
    stc = sorted([list(map(int, input().split())) for i in range(N)], key=lambda x: (x[2], x[0])) + [[1, 1, 31]]
    # print(stc)
    imos = [0] * (int(1e5) + 10)
    s, t, c = stc[0]
    pre_s, pre_t, pre_c = s, t, c
    for i in range(1, N+1):
        s, t, c = stc[i]
        if c == pre_c and pre_t == s:
            pre_t = t
        else:
            imos[pre_s] += 1
            imos[pre_t + 1] -= 1
            pre_s, pre_t, pre_c = s, t, c
    # print(imos[:100])

    ans = 0
    tmp = 0
    for i in imos:
        tmp += i
        ans = max(ans, tmp)
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 36248
//BadWaper gg
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#define inf 1e9
#define eps 1e-6
#define mp make_pair
#define N 4100
#define M 200010
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline ll read()
{
	char ch=getchar();
	ll s=0,w=1;
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
	return s*w;
}
const int mod=1e9+7;
int P=2010;
int n,f[N][N];
int A[M],B[M],fac[N<<1],inv[N<<1];
inline int Z(int x){return x>=mod?x-mod:x;}
inline int ksm(int a,int b)
{
	int ans=1;
	while(b){if(b&1)ans=1LL*ans*a%mod;b>>=1;a=1LL*a*a%mod;}
	return ans;
}
inline int C(int n,int m){return 1LL*fac[n]*inv[m]%mod*inv[n-m]%mod;}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	fac[0]=1;
	for(register int i=1;i<=(P<<2);i++)fac[i]=1LL*fac[i-1]*i%mod;
	inv[0]=inv[1]=1;
	for(register int i=2;i<=(P<<2);i++)inv[i]=1LL*inv[mod%i]*(mod-mod/i)%mod;
	for(register int i=1;i<=(P<<2);i++)inv[i]=1LL*inv[i]*inv[i-1]%mod;
	n=read();
	for(register int i=1;i<=n;i++)
	{
		A[i]=read(),B[i]=read();
		f[-A[i]+P][-B[i]+P]++;
	}
	for(register int i=-P+1;i<=P;i++)
	{
		for(register int j=-P+1;j<=P;j++)
		{
			f[i+P][j+P]=Z(f[i+P][j+P]+Z(f[i+P-1][j+P]+f[i+P][j+P-1]));
		}
	}
	int ans=0;
	for(register int i=1;i<=n;i++)ans=Z(ans+f[A[i]+P][B[i]+P]);
	for(register int i=1;i<=n;i++)ans=Z(ans+mod-C(A[i]*2+B[i]*2,2*A[i]));
	printf("%lld\n",1LL*ans*ksm(2,mod-2)%mod);
	return 0;
}


Measured memory_bytes: 69716
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)

constexpr ll MOD = 1000000007;

int main() {
  ll n, k;
  cin >> n >> k;
  ll ans = 0;
  for (ll i = k; i <= n + 1; ++i) {
    ll mn = i * (i - 1) / 2;
    ll mx = (n + (n - i + 1)) * i / 2;
    ans = (ans + mx - mn + 1) % MOD;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3476
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>  // https://boostjp.github.io/tips/math.html
#include <boost/dynamic_bitset.hpp>  // https://boostjp.github.io/tips/dynamic_bitset.html

constexpr int64_t DIV1097 = 1000000007LL;

using namespace std;

int main()
{
    int64_t N, M;
    std::cin >> N >> M;

    int64_t ans = 0;

    // S をつかってできる個数
    ans = std::min(N, M/2);

    //
    N -= ans;
    M -= ans*2;

    ans += M / 4;

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 256
package main
import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
)

func Solve() {
  var N, Q, B, C int
  var A []int
  NextInt(&N)
  NextIntSlice(&A)
  M := make(map[int]int)
  var ok bool
  for _, a := range A {
    if _, ok = M[a]; !ok { M[a] = 0 }
    M[a]++
  }
  NextInt(&Q)
  S := 0
  for k, v := range M {
    S += k * v
  }
  for i := 0; i < Q; i++ {
    NextInt(&B, &C)
    if _, ok = M[B]; !ok { M[B] = 0 }
    if _, ok = M[C]; !ok { M[C] = 0 }
    S += M[B] * (C - B)
    M[C] += M[B]
    M[B] = 0
    Write(S)
  }
}

func main() {
  Solve()
  Output()
}

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntSlice(A *[]int) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatSlice(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(S ...interface{}) {
  fmt.Fprintln(writer, S...)
}
func WriteIntSlice(A []int) {
  B := make([]interface{}, len(A))
  for i, a := range A { B[i] = a }
  Write(B...)
}
func Output() {
  _ = writer.Flush()
}
func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}
func SumInt(A ...int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}
func AbsInt(x int) int {
  if x < 0 { x = -x }
  return x
}

Measured memory_bytes: 12276
#include <iostream>

using namespace std;

int main(int argc, char **argv)
{
	int d, tmp, i;
	
	while(cin >> d){
		tmp = 0;
		i = 1;
		while((i*d)!=(600)){
			tmp += (d*i*i*d*d);
			i++;
		}
		cout << tmp << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000001
using namespace std;

int N;
int* boss,*height;

int get_boss(int id){
	if(boss[id] == id)return id;
	else{
		return boss[id] = get_boss(boss[id]);
	}
}

int is_same(int x,int y){
	return get_boss(x) == get_boss(y);
}

void unite(int x,int y){
	int boss_x = get_boss(x);
	int boss_y = get_boss(y);

	if(boss_x == boss_y)return;

	if(height[x] > height[y]){

		boss[boss_y] = boss_x;

	}else if(height[x] < height[y]){

		boss[boss_x] = boss_y;

	}else{ //height[x] == height[y]

		boss[boss_y] = boss_x;
		height[x]++;
	}
}

int main(){

	int Q,command,x,y;

	scanf("%d %d",&N,&Q);

	boss = new int[N];
	height = new int[N];

	for(int i = 0; i < N; i++){
		boss[i] = i;
		height[i] = 1;
	}

	for(int i = 0; i < Q; i++){
		scanf("%d %d %d",&command,&x,&y);

		if(command == 0){ //unite
			unite(x,y);
		}else{
			if(is_same(x,y)){
				printf("1\n");
			}else{
				printf("0\n");
			}
		}
	}

	return 0;
}

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

using namespace std;

#define IOS ios::sync_with_stdio(0);cin.tie(0);

int main(){
	IOS;
	long long a,b,c,d;
	while(cin>>a>>b>>c>>d){
		long long sum=0;
		if(a>b){
			sum=sum+b;
		}
		else{
			sum=sum+a;
		}
		if(c>d){
			sum=sum+d;
		}
		else{
			sum=sum+c;
		}
		cout<<sum<<endl;
	}
	return 0;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define mp make_pair
#define S second
#define F first
ll mod=1e9+7;
#define input_from_file  freopen("input.txt", "r", stdin);
ll ans=0;
ll dfs(vector<vector<ll>> &adj,vector<ll> &dp,ll i){
    if(adj[i].size()==0)  dp[i]=0;
    if(dp[i]!=-1) return  dp[i];
    for(auto itr:adj[i])
      dp[i]=max(dp[i],dfs(adj,dp,itr)+1);
    ans=max(dp[i],ans) ; 
  
  return dp[i];
}
int main()
{
  // input_from_file;
  ll n,k,m,u,v;
  cin>>n>>m;
  vector<vector<ll>> adj(n+1);vector<ll> dp(n+1,-1);
  for(ll i=0;i<m;i++){
    cin>>u>>v;adj[u].pb(v);
  }
  for(ll i=1;i<=n;i++)  ll x=dfs(adj,dp,i);
  cout<<ans;
  return 0;
}

Measured memory_bytes: 9216
#include<bits/stdc++.h>
#define de(x) cout<<#x<<"="<<x<<endl
#define dd(x) cout<<#x<<"="<<x<<" "
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define repd(i,a,b) for(int i=a;i>=(b);--i)
#define repp(i,a,b,t) for(int i=a;i<(b);i+=t)
#define mt(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp(u,v) make_pair(u,v)
#define sz(a) (int)a.size()
#define pb push_back
#define PI acos(-1.0)
#define qc std::ios::sync_with_stdio(false)
#define all(a) a.begin(),a.end()
using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef double db;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;

const ll mod = 1000000007;
const int N = 25;
const int M = 2e6+6;
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;

bool eq(const db &a, const db &b) { return fabs(a - b) < eps; }
bool ls(const db &a, const db &b) { return a + eps < b; }
bool le(const db &a, const db &b) { return eq(a, b) || ls(a, b); }
ll gcd(ll a,ll b) { return a==0?b:gcd(b%a,a); };
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
ll kpow(ll a,ll b) {ll res=1;a%=mod; if(b<0) return 1; for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll read(){
    ll x=0,f=1;char ch=getchar();
    while (ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//inv[1]=1;
//for(int i=2;i<=n;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
int n;
int yes[N][N];
int vis[N];
bool ok(int sta) {
	mt(vis, 0);
	rep(i, 0, n) if(sta&(1<<i)) vis[i] = 1;
	rep(i, 0, n) {
		if(sta&(1<<i)) {
			rep(j, 0, n) {
				if(yes[i][j]==1&&vis[j]==0) return false;
				if(yes[i][j]==0&&vis[j]==1) return false;
			}
		}
	}
	return true;
}
int cnt(int x) {
	int ret = 0;
	rep(i, 0, n) if(x&(1<<i)) ret++;
	return ret;
}
int main() {
	mt(yes, -1);
	scanf("%d",&n);
	rep(i, 0, n) {
		int x; scanf("%d",&x);
		while(x--) {
			int a,b;
			scanf("%d%d",&a,&b); a--;
			if(b) yes[i][a] = 1;
			else yes[i][a] = 0;
		}
	}
	int ret = 0;
	rep(i, 1, (1<<n)) {
		if(ok(i)) ret = max(ret, cnt(i));
	}
	printf("%d\n", ret);
    return 0;
}


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

//a1,a2,a3,a4,a5,a6,...が数列bの何番目に対応するかを表で書くと
// a1  a2  a3  a4  a5  a6
// 1
// 2   1
// 2   3   1
// 3   2   4   1
// 3   4   2   5   1
// 4   3   5   2   6   1
//斜めに見ると規則性があるので、この規則通りbに代入していく。  

int main() {
  int n;
  cin >> n;
  vector<long long> vec(n);
  vector<long long> b(n);
   for(int i=0;i<n;i++){
   cin >> vec[i];
  }
 int m;
 if(n%2==0){
    m=n/2-1;
 }
 else{
   m=(n-1)/2;
 }

  for(int i=0;i<n;i++){
    if(i<=m){
      b[i]=vec[n-2*i-1];
    }
    else{
      if(n%2==0){
        b[i]=vec[2*(i-m-1)];
      }
      else{
        b[i]=vec[2*(i-m)-1];
      }
    }
  }

  for(int i=0;i<n;i++){
  cout << b[i] << ' ' ;
  }

}

Measured memory_bytes: 5248