akhauriyash/Code-Regression huggingface dataset:
#include <set>
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <limits>
#include <map>
#include <numeric>

#define ll long long
using namespace std;
static ll imin = std::numeric_limits<ll>::min();
static ll imax = std::numeric_limits<ll>::max();
#define rep(i, n) for(int i = 0; (i)<(n); ++(i))
#define rep1(i, n) for(int i = 1; (i)<(n); ++(i))
#define rev_rep(i, n) for(int i = (n) - 1; (i) >= 0; --(i))
#define range(a, i, b) for(int i = (a); (i) < (b); ++(i))
#define dump(x) cout << #x << ":" << x << "\n";
#define all(v) v.begin(), v.end()
#define readl(N) ll N; cin >> N
#define readlv(N, vec) vector<ll> vec(N); rep(i, N){cin >> vec[i];}
#define greater_than [](ll l, ll r){return l > r;}
template<class T1, class T2>
std::ostream& operator << (std::ostream& os, std::map<T1, T2>& mp);
template<class T1, class T2>
std::ostream& operator << (std::ostream& os, std::pair<T1, T2>& pair);
template<class T>
std::ostream& operator << (std::ostream& os, std::vector<T>& vec);
template<class T1, class T2>
std::ostream& operator << (std::ostream& os, std::pair<T1, T2>& pair){
  os << '(' << pair.first << ',' << pair.second << ')';
  return os;
}

template<class T>
std::ostream& operator << (std::ostream& os, std::vector<T>& vec){
  std::size_t n = vec.size();
  if(n == 0){
    return os;
  }
  os << " ";
  for(ll i = 0; i<n - 1; ++i){
    os << vec[i] << " ";
  }
  os << vec[n - 1];
  os << std::endl;
  return os;
}

template<class T1, class T2>
std::ostream& operator << (std::ostream& os, std::map<T1, T2>& mp){
  std::size_t n = mp.size();
  if(n == 0){
    return os;
  }
  os << " ";
  for(auto && x:mp){
    os << x << " ";
  }
  os << std::endl;
  return os;
}

template<class T>
std::ostream& operator << (std::ostream& os, std::set<T>& mp){
  std::size_t n = mp.size();
  if(n == 0){
    return os;
  }
  os << " ";
  for(auto && x:mp){
    os << x << " ";
  }
  os << std::endl;
  return os;
}

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

ll fact(ll n){
  ll res=1;
  while(n>=0){
    res*=n;
    n--;
  }
  return res;
}
    
ll pow(ll i, ll n){
  ll res=1;
  while(n>=0){
    res*=i;
    n--;
  }
  return res;
}

ll gcd(ll l, ll r){
  if(l<r){
    return gcd(r, l);
  }
  if(r == 0){
    return l;
  }
  return gcd(r, l % r);
}

#ifndef BOOST_TEST_MAIN
int main(int const argc, char const** argv){
  readl(N);
  ll res = 1;
  rep(i, N){
    ll x;
    cin >> x;
    ll g = gcd(x, res);
    res /= g;
    res *= x;
  }
  cout << res << endl;

}
#endif


Measured memory_bytes: 256
def main():
    N = int(input())
    dp = [-1]*(N + 1)
    dp[0] = 0
    multiples = [1]
    n = 9
    while n <= N:
        multiples.append(n)
        n *= 9
    n = 6
    while n <= N:
        multiples.append(n)
        n *= 6
    multiples.sort(reverse=True)
    # print(multiples)
    for ratio in reversed(multiples):
        for i in range(N + 1):
            c = dp[i]
            if c == - 1:
                continue
            if i + ratio > N:
                continue
            if dp[i + ratio] == -1 or dp[i + ratio] > c + 1:
                dp[i + ratio] = c + 1
    # print(dp)
    print(dp[N])

if __name__ == '__main__':
    main()


Measured memory_bytes: 12688
using System;

namespace agc004a
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] read = Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
            long A = read[0];
            long B = read[1];
            long C = read[2];
            long big = Math.Max(Math.Max(A,B),C);
            if(big == A){
                A = A/2-A+A/2;
            }else if(big == B){
                B = B/2-B+B/2;
            }else{
                C = C/2-C+C/2;
            }
            Console.WriteLine(Math.Abs(A*B*C));
        }
    }
}

Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
#define PII pair<int, int>
#define VI vector<int>
#define VPII vector<PII>
#define LL long long
#define LD long double
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
#define SIZ(c) (int)(c).size()
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, b, e) for(int i = (b); i <= (int)(e); ++i)
#define FORD(i, b, e) for(int i = (b); i >= (int)(e); --i)
#define ll LL
#define st f
#define nd s
#define pb PB
#define mp MP
#define eb emplace_back
#define siz(c) SIZ(c)
const int inf = 1e9+7;
const ll INF = 1e18L+7;

#define sim template<class n
sim, class s> ostream & operator << (ostream &p, pair<n, s> x)
{return p << "<" << x.f << ", " << x.s << ">";}
sim> auto operator << (ostream &p, n y) ->
typename enable_if<!is_same<n, string>::value, decltype(y.begin(), p)>::type 
{int o = 0; p << "{"; for(auto c: y) {if(o++) p << ", "; p << c;} return p << "}";}
void dor() {cerr << endl;}
sim, class...s> void dor(n p, s...y) {cerr << p << " "; dor(y...);}
sim, class s> void mini(n &p, s y) {if(p>y) p = y;}
sim, class s> void maxi(n &p, s y) {if(p<y) p = y;}
#ifdef DEB
#define debug(...) dor(__FUNCTION__, ":", __LINE__, ": ", __VA_ARGS__)
#else
#define debug(...)
#endif 

#define I(x) #x " =", (x), " "
#define A(a, i) #a "[" #i " =", i, "] =", a[i], " "

int main()
{
  set<int> ignore;
  int n, k;
  cin >> n >> k;
  FOR(i, 1, k)
    {
    int cnt;
    cin >> cnt;
    FOR(j, 1, cnt)
      {
      int a;
      cin >> a;
      ignore.insert(a);
      }
    }
  int res = 0;
  FOR(i, 1, n)if(ignore.count(i) == 0)res++;
  cout << res << endl;
}


Measured memory_bytes: 3584
// Try AtCoder
// author: Leonardone @ NEETSDKASU

fn main() {
    let mut stdin = String::new();
    std::io::Read::read_to_string(&mut std::io::stdin(), &mut stdin).unwrap();
    let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
        ($t:ty) => {
            get().parse::<$t>().unwrap()
        };
        () => {
            get!(i64)
        };
    }

    let a = get!();
    let b = get!();
    let q = get!();
    let mut xs = vec![];
    let mut ys = vec![];
    for _ in 0..a {
        xs.push(get!());
    }
    for _ in 0..b {
        ys.push(get!());
    }
    fn foo(x: i64, ys: &[i64]) -> i64 {
        use std::cmp::min;
        let res = ys.binary_search(&x);
        match res {
            Ok(_) => 0,
            Err(0) => (x - ys[0]).abs(),
            Err(i) if i < ys.len() => min((x - ys[i - 1]).abs(), (x - ys[i]).abs()),
            Err(i) => (x - ys[i - 1]).abs(),
        }
    }

    fn bar(x: i64, xs: &[i64], ys: &[i64]) -> i64 {
        let res = xs.binary_search(&x);
        match res {
            Ok(_) => foo(x, ys),
            Err(0) => {
                let c = (x - xs[0]).abs();
                c + foo(xs[0], ys)
            }
            Err(i) if i < xs.len() => {
                let c1 = (x - xs[i - 1]).abs();
                let c1 = c1 + foo(xs[i - 1], ys);
                let c2 = (x - xs[i]).abs();
                let c2 = c2 + foo(xs[i], ys);
                std::cmp::min(c1, c2)
            }
            Err(i) => {
                let c = (x - xs[i - 1]).abs();
                c + foo(xs[i - 1], ys)
            }
        }
    }

    for _ in 0..q {
        let x = get!();
        let c1 = bar(x, &xs, &ys);
        let c2 = bar(x, &ys, &xs);
        let ans = std::cmp::min(c1, c2);
        println!("{}", ans);
    }
}


Measured memory_bytes: 11256
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;
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;
}

ll M = 1000000007;
ll dp[100][(int)2e5 + 1]; //sum of utility
vector<bool> used(100, false);
int N, W;
vector<int> weight(100), utility(100);

void solve()
{

	cin >> N >> W;

	rep(i, N)
	{
		cin >> weight[i] >> utility[i];
	}
	/*rep(i,N)rep(j, W + 1)
	{
		dp[i][j] = 0;
	}*/

	//ll ans = 0;
	rep(i, N)
	{
		rep(limit, W + 1)
		{
			if (i)
			{
				if (limit >= weight[i])
				{
					dp[i][limit] = max(dp[i - 1][limit - weight[i]] + utility[i], dp[i - 1][limit]);
				}
				else
				{
					dp[i][limit] = dp[i - 1][limit];
				}
			}else{
				if (limit >= weight[i])
				{
					dp[i][limit] = utility[i];
				}
			}
		}
	}
	cout << dp[N - 1][W] << endl;
}

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


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

using namespace std;

using ll = long long;

int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  ll A = a, B = b, C = c;
  for (int i = 0;; ++i) {
    if (A & 1LL || B & 1LL || C & 1LL) {
      cout << i << endl;
      return 0;
    }
    if (i && A == a && B == b && C == c) {
      cout << -1 << endl;
      return 0;
    }
    ll aa = B / 2 + C / 2;
    ll bb = A / 2 + C / 2;
    ll cc = A / 2 + B / 2;
    A = aa, B = bb, C = cc;
  }
}

Measured memory_bytes: 256
using System;

class P
{
    static void Main()
    {
        long N = long.Parse(Console.ReadLine());
        long rootN = Convert.ToInt64(Math.Sqrt(N));
        for (long i = rootN; i >= 1; i--)
        {
            if (N % i == 0)
            {
                int length = Math.Max(i, N / i).ToString().Length;
                Console.WriteLine(length);
                break;
            }
        }
    }
}

Measured memory_bytes: 11220
#include <bits/stdc++.h>
#define int long long
#define N (int) 2e5
using namespace std;
int n, p;
string s;

int barket[N];

signed main () {
	cin >> n >> p >> s;

	if (p == 2 || p == 5) {
		int ans = 0;
		for (int i = 0; i < n; i ++) {
			int tmp = s[i] - '0';
			if (tmp % p == 0) ans += i+1;
		}
		cout << ans << endl;
	} else {
		int sum = 0, t = 1;
		int ans = 0;
		barket[0] = 1;
		for (int i = n-1; i >= 0; i --) {
			sum = ((s[i]-'0') * t + sum) % p;
			(t *= 10) %= p;
			ans += barket[sum] ++;
//			cout << sum << endl;
		}
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 644
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii > vii;
typedef vector<pll > vll;
#define pb push_back
#define mp make_pair 
#define mod 1000000007
#define F first
#define S second
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define For(i, a, b) for(__typeof (a) i=a; i<=b; i++)
#define inp_arr(a,n) for(__typeof (n) i=0; i<n; ++i) {cin>>a[i];}
#define debug_arr(a,n) {{for(__typeof (n) i=0; i<n; ++i) {cout<<a[i]<<" ";}cout<<"\n";}}
 
ll power(ll x, ll y) 
{ 
    ll res = 1;   
    while (y > 0) { 
        if (y & 1) 
            res = (res*x)%mod; 
        y = y>>1;
        x = (x*x)%mod; 
    } 
    return res%mod; 
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    // #ifndef ONLINE_JUDGE
    // freopen("inp.txt", "r", stdin);
    // freopen("out.txt", "w", stdout); 
    // #endif

    int n;
    cin>>n;
    int a[n];
    inp_arr(a,n);

    int c =0;
    for(int i=0;i<n;i+=2) {
        if(a[i]&1)++c;
    }
    cout<<c;

    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve(){
    int x;cin>>x;
    ll ans = (x/500)*1000L;
    ans += ((x%500)/5)*5L;
    cout<<ans<<"\n";
    return;
}

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


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


void MaxSub(string s1,string s2)
{
    int l1=s1.length(),l2=s2.length();
    
    int dp[l1+1][l2+1];
    stack <char> s;
    for (int i= 0 ; i <=l1;i++)
    {
        for (int j =0;j<=l2;j++)
        {
            if ( i == 0 || j == 0)
            dp[i][j] = 0;
            else if(s1[i-1] == s2[j-1]) 
            {
                dp[i][j] = 1 + dp[i-1][j-1];
               
            }
            else
            {
                dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    //  for (int i= 0 ; i <=l1;i++)
    // {
    //     for (int j =0;j<=l2;j++)
    //     {
    //      cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }    
    int i=l1,j=l2;
    while ( i >0 && j> 0)
    {
        if (s1[i-1] == s2[j-1])
       { s.push(s1[i-1]);
         i--;
         j--;
       }
        else if ( dp[i-1][j] > dp[i][j-1])
        i--;
        else
        j--;
    }
    while(!s.empty())
    {
        cout << s.top();
        s.pop();
    }
}
int main()
{
    string s1,s2;
    cin >> s1 >> s2;
    if (s1.length() > s2.length())
    MaxSub(s1,s2);
    else
    MaxSub(s2,s1);
    return 0;
}


Measured memory_bytes: 35456
#include<stdio.h>
#include<stdlib.h>

int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

int main()
{
    int N;
    int before = 0;
    int count = 0;
    int d[100];
    // 枚数の入力
    scanf("%d", &N);
  
    // 各直径の入力
    for(int i=0;i<N;i++){
    	scanf("%d", &d[i]);
    }

    // 直径のソート
    qsort(d,N,sizeof(int),compare_int);
    
    // サイズ被りをカウント
    for(int i= 0;i<N;i++){
    	if( before == d[i] ){
    		count++;
    	}
    	before = d[i];
    }

    // 出力
    printf("%d\n",N-count);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
long long INF = 1100000000000000000;
int main(){
  int N;
  long long K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  long long tv = -INF;
  long long fv = INF;
  while (fv - tv > 1){
    long long mid = (tv + fv) / 2;
    //mid未満の個数はK個未満か？
    long long cnt = 0;
    for (int i = 0; i < N; i++){
      if (A[i] > 0){
        int tv2 = i;
        int fv2 = N;
        while (fv2 - tv2 > 1){
          int mid2 = (tv2 + fv2) / 2;
          if ((long long) A[mid2] * A[i] < mid){
            tv2 = mid2;
          } else {
            fv2 = mid2;
          }
        }
        cnt += tv2 - i;
      } else {
        int tv2 = N;
        int fv2 = i;
        while (tv2 - fv2 > 1){
          int mid2 = (tv2 + fv2) / 2;
          if ((long long) A[mid2] * A[i] < mid){
            tv2 = mid2;
          } else {
            fv2 = mid2;
          }
        }
        cnt += N - tv2;
      }
    }
    if (cnt < K){
      tv = mid;
    } else {
      fv = mid;
    }
  }
  cout << tv << endl;
}

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

using namespace std;
typedef long long ll;

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

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

  int ret = 0;
  for(int i = 0; i < n; i++) {
    ret += (s[i] != t[i]);
  }

  cout << ret << "\n";

  return 0;
}


Measured memory_bytes: 3724
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
const ll inf=1e9+7;
ll gcd(ll a, ll b) { return (b ? gcd(b, a % b) : a); }
ll lcm(ll a, ll b) { return a / (gcd(a, b)) * b; }

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

  cout<<(ceil)((b-1)/(a-1))<<endl;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::str::*;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let cin = stdin();
    let cin = cin.lock();
    let s: String = cin
        .bytes() // Bytes
        .map(|c| c.expect("failed reading char") as char)
        .skip_while(|c| c.is_whitespace()) // c が whitespace である限り skip
        .take_while(|c| !c.is_whitespace()) // c が whitespace でない限り要素を返す
        .collect();
    s.parse().ok().expect("failed parsing")
}

fn main() {
    let n: usize = read();
    let mut a = Vec::new();
    for i in 0..n {
        a.push(read::<usize>());
    }
    let mut b = a.clone();
    b.sort();
    for i in 0..n {
        if b[n - 1] == a[i] {
            println!("{}", b[n - 2]);
        } else {
            println!("{}", b[n - 1]);
        }
    }
}


Measured memory_bytes: 9724
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(ll i=0;i<=n;i++)
#define ll long long
using namespace std;
signed main() {
	ll k, s, ans = 0;
	cin >> k >> s;
	rep(i, k) {
		rep(j, k) {
			if (s - i - j <= k && s - i - j >= 0)ans++;
		}
	}
	cout << ans << endl;
	getchar(); getchar(); return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N; cin >> N;
    int f[N][10];
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < 10; j++)
        {
            cin >> f[i][j];
        }
    }
    int p[N][11];
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < 11; j++)
        {
            cin >> p[i][j];
        }
    }

    int ans = -1* (1e9+7);
    for (int bit = 1; bit < 1<<10; bit++)
    {
        int d[10];
        for (int i = 0; i < 10; i++)
        {
            if((bit >> i & 1) == 1) {
                d[i] = 1;
            }
            else d[i] = 0;
        }

        int tmp = 0;
        for (int i = 0; i < N; i++)
        {
            int cnt = 0;
            for (int j = 0; j < 10; j++)
            {
                if(d[j] == 1 && f[i][j] == 1) cnt++;
            }
            tmp += p[i][cnt];
        }
        ans = max(ans, tmp);
    }

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

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

int main() {
	string s; cin >> s;
	int len = s.size();

	bool winf = true;
	if (s[0] == s[len - 1]) {
		if ((len - 2) % 2 == 1) winf = false;
	} else {
		if ((len - 2) % 2 == 0) winf = false;
	}

	if (winf) { cout << "First" << endl; }
	else { cout << "Second" << endl; }

	return 0;
}


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

struct Solver{
    int N;
    Solver* s[3];
    int pos[3];
    bool lazy_salsa;
    
    
    Solver(int N): N(N){
        assert(N > 0);
        if(N > 1){
            for(int i=0; i<3; i++) s[i] = new Solver(N-1);
        }
        for(int i=0; i<3; i++) pos[i] = i;
        lazy_salsa = false;
    }
    
    void salsa(){
        lazy_salsa = not lazy_salsa;
    }
    
    void perform_salsa(){
        for(int i=0; i<3; i++) pos[i] = (2*pos[i]) % 3;
        if(N > 1) for(int i=0; i<3; i++) s[i]->salsa();
    }
    
    void rumba(){
        if(lazy_salsa) perform_salsa();
        lazy_salsa = false;
        
        for(int i=0; i<3; i++){
            if(pos[i] == 2 and N > 1) s[i]->rumba();
            pos[i] = (pos[i] + 1) % 3;
        }
    }
    
    int get(int x){
        if(lazy_salsa) perform_salsa();
        lazy_salsa = false;
        if(N == 1) return pos[x];
        else return pos[x%3] + 3 * s[x%3]->get(x/3);
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N;
    cin >> N;
    string T;
    cin >> T;
    
    Solver s(N);
    for(char c:T){
        if(c == 'S') s.salsa();
        else s.rumba();
    }
    
    int num = 1;
    for(int i=0; i<N; i++) num *= 3;
    
    for(int i=0; i<num; i++) cout << s.get(i) << ' ';
    cout << '\n';
    return 0;
}


Measured memory_bytes: 20816
#include <iostream>
using namespace std;
#define MAX 100000
typedef long long llong;


int n, k;
llong T[MAX];

//k辆最大运载量为p的卡车能装多少货物?
int check(llong P){
    int i = 0;
    for(int j=0; j<k; j++){
        llong s = 0;
        while(s +T[i] <= P){
            s += T[i];
            i++;
            if(i==n) return n;
        }
    }
    return i;
}


int solve(){
    llong left = 0;
    llong right = 100000 * 10000;// 货物 x 1件货物的最大重量
    llong mid;
    while(right - left>1){
        mid = (right + left) / 2;
        int v = check(mid);//mid == 检查mid==P 时能装多少货物
        if(v>=n) right = mid;
        else left = mid;
    }

    return right;
}

main(){
    cin >>n>>k;
    for(int i=0; i<n; i++){cin>>T[i];}
    llong ans = solve();
    cout << ans <<endl;
}


Measured memory_bytes: 3892
S = input()
inc = 0
dec = 0
sum = 0

def solve(i, d):
	ans = 0
	if i >= d : 
		i += 1
	elif i < d:
		d += 1
	for c in range(i):
		ans += c
	for c in range(d):
		ans += c
	return ans

for i in range(len(S)):
	if S[i] == '<':
		if dec > 0:
			sum += solve(inc, dec)
			inc = 0
			dec = 0
		inc += 1
	if S[i] == '>':
		dec += 1
#	print(i, inc, dec, sum)
sum += solve(inc, dec)

print(sum)

Measured memory_bytes: 4212
/*  ex7_1
    L40S38  */

#include <stdio.h>

typedef struct point{
    int x_elem;
    int y_elem;
}point;

point shift_point(point *top,point *diff){
    //頂点topについて、square[0]とsquare[1]の差diffの値を用いて頂点を移動させる関数
    point ans=*top;
    ans.x_elem-=diff->y_elem;
    ans.y_elem+=diff->x_elem;
    return ans;
}
int main(void){
    int i;
    point square[4],diff;
    //square[i]:問題文における(x_i+1,y_i+1)のpointのこと
    for(i=0;i<2;i++){
        scanf(" %d %d",&square[i].x_elem,&square[i].y_elem);
    }
    
    //diffにsquare[0]とsquare[1]の差を格納
    diff.x_elem=square[1].x_elem-square[0].x_elem;
    diff.y_elem=square[1].y_elem-square[0].y_elem;

    //square[2]の計算・出力
    square[2]=shift_point(&square[1],&diff);
    printf("%d %d ",square[2].x_elem,square[2].y_elem);
    
    //square[3]の計算・出力
    square[3]=shift_point(&square[0],&diff);
    printf("%d %d",square[3].x_elem,square[3].y_elem);
    return 0;
}

Measured memory_bytes: 1712
from collections import deque, Counter
N = int(input())
num_357 = [3, 5, 7]
dq = deque(num_357)
while dq:
    x = dq.popleft()
    if x <= 10**9:
        num_357.append(int(str(x) + "3"))
        num_357.append(int(str(x) + "5"))
        num_357.append(int(str(x) + "7"))
        dq.append(int(str(x) + "3"))
        dq.append(int(str(x) + "5"))
        dq.append(int(str(x) + "7"))

ans = 0
for num in num_357:
    if num <= N:
        c = {3: 0, 5: 0, 7: 0}
        for i in range(len(str(num))):
            if str(num)[i] == "3":
                c[3] += 1
            elif str(num)[i] == "5":
                c[5] += 1
            elif str(num)[i] == "7":
                c[7] += 1
        if c[3] >= 1 and c[5] >= 1 and c[7] >= 1:
            ans += 1
print(ans)


Measured memory_bytes: 14984
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

/*************** using variables **************/
int n;
string s[2];
LL ans = 0;
map<char, int> mp;
/**********************************************/

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

    cin >> n >> s[0] >> s[1];

    bool flag = false;
    REP(i, n){
        if(s[0][i] == s[1][i]){
            if(i == 0) ans = 3;
            else if(!flag)ans = ans * 2 % MOD;
            flag = false;
        }else{
            if(i == 0) ans = 6;
            else if(!flag){
                ans = ans * 2 % MOD;
            }else{
                ans = ans * 3 % MOD;
            }
            flag = true;
            i++;
        }
    }
    cout << ans << endl;
}


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

#define ll long long
#define P pair<int, int>
#define F first
#define S second

const ll mod = 1000000007LL;

void solve() {
  ll n;
  cin >> n;

  vector<ll> a(n + 1);
  for (ll i = 1; i <= n; i++) cin >> a[i];

  ll dp[n + 1][n + 1];  // Maximum sum of X - Y for this subarray
  memset(dp, 0, sizeof(dp));
  for (int i = n; i >= 1; i--) {
    for (int j = i; j <= n; j++) {
      if (i == j) {
        dp[i][j] = a[i];
        continue;
      }
      dp[i][j] = max(a[i] - dp[i + 1][j], a[j] - dp[i][j - 1]);
    }
  }
  cout << dp[1][n];
}

int main(int argc, char const *argv[]) {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int T = 1;
  while (T--) {
    solve();
  }

  return 0;
}

Measured memory_bytes: 70656
#include "bits/stdc++.h"
using namespace std;

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

Measured memory_bytes: 3072
#include <stdio.h>

int main(void) {
	int Height, Width;
	
	while(1) {
	    scanf("%d%d", &Height, &Width);
	    
	    if((Height == 0) && (Width == 0)) {
	        break;
	    }
	    for(int i = 0; i < Height; i++) {
	        for(int j = 0; j < Width; j++) {
	            printf("#");
	        }
	        printf("\n");
	    }
	    printf("\n");
	}
	return 0;
}


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

int main(){
    while(true){
        double r0,w,c,r;

        cin >> r0 >> w >> c >> r; 
        if(r0 == 0){
            break;
        }

        long long int ans = 0;

        ans = ceil((c * w - r0)/r);
        if(ans < 0){
            ans = 0;
        }

        cout << ans << endl;
    }
        

    return 0;

}


Measured memory_bytes: 3156
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<queue>
#include<climits>
#include<set>
#define ll long long
using namespace std;
int main() {
	ll n,r=0;
	cin >> n;
	vector<ll>w(n),sum(n);
	for (ll i = 0; i < n; i++) {
		cin >> w[i];
		r += w[i];
		sum[i] =r;
	}
	ll ans = LLONG_MAX;
	for (ll i = 0; i < n; i++) {
		ll s1 = sum[i];
		ll s2 = sum[n - 1] - sum[i];
		ans = min(ans, abs(s1 - s2));
	
	}
	cout << ans << endl;

}




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

int main(){
    int N;
    cin >> N;
    int count=0;
    rep (i,N){
        int x;
        cin >> x;
        if (x%2==1){
            count++;
        }
    }
    if (count%2==1){
        cout << "NO" << endl;
    }
    else {
        cout << "YES" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stdio.h>
using namespace std;

long long LCM(long long c,long long d){
	long long res=d;
	if(c%d!=0)res=LCM(d,c%d);
	return res;
}
int main() {
    clock_t cTimeStart, cTimeEnd;
    cTimeStart = clock();           // 現在時刻
    long long a,b;
    long long lcm;
    while(cin>>a>>b){
    	lcm =LCM(a,b);
       	cout << lcm<<" "<<(a*b/lcm)<<endl;;
    }

    cTimeEnd = clock();           // 現在時刻
//    cout<< "処理時間:" <<(cTimeEnd - cTimeStart)/1000 << "[ms]" << endl;

	return 0;
}

Measured memory_bytes: 1164
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  string s; readV(s);
  writeln(s.count('o') * 100 + 700);
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>

using namespace std;

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

	int A[m];

	for(i=0;i<m;i++)
	{
		cin >> A[i];
	}

	int sum=0;

	for(i=0;i<m;i++)
	{
		sum=sum+A[i];
	}

	if(sum > n)
		cout << "-1" << endl;
	
	else
		cout << n-sum << endl;

	return 0;
}


Measured memory_bytes: 3672
#include <iostream>


using namespace std;


using ll = long long;


int main()
{
    ll H;
    ll A[250 + 1];
    cin >> H;

    for (ll i = 1; i <= H; i++) {
        cin >> A[i];
    }

    for (ll i = 1; i <= H; i++) {
        cout << "node " << i << ": key = " << A[i] << ", ";
        if (i / 2 >= 1) {
            cout << "parent key = " << A[i / 2] << ", ";
        }
        if (i * 2 <= H) {
            cout << "left key = " << A[i * 2] << ", ";
        }
        if (i * 2 + 1 <= H) {
            cout << "right key = " << A[i * 2 + 1] << ", ";
        }
        cout << endl;
    }
}



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


int main(){
	string value;
	cin >> value;
	string temp;
	int a[value.length()];
	for(int i=0; i< value.length();i++){
		temp=value[i];
		a[i] = atoi(temp.c_str());
	}

	int sum=0;
	for(int i=0;i<value.length();i++){
		sum += a[i];
	}
	if(sum%9==0){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
	
	


	return 0;
}

Measured memory_bytes: 4468
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include <unordered_map>
//#include"testlib.h"
#define endl "\n"
#define all(v) v.begin(),v.end()
#define allr(s) s.rbegin(),s.rend()
#define RT(s) return cout<<s,0
#define watch(x) cout << (#x)<<" = "<<x<<endl
#define sz(s)	(int)(s.size())
#define PI acos(-1)
#define EPS 1e-8
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> row;
typedef vector<row> matrix;
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
void file() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
#else
	//freopen("street.in", "r", stdin);
	//freopen("out.txt", "w", stdout);
#endif
}
void fast() {
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
}

int main() {
	//file();
	fast();
	int a, b; cin >> a >> b;
	if ((a + b) & 1)
		cout << "IMPOSSIBLE" << endl;
	else
		cout << (a + b) / 2 << endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ms(a,b) memset(a,b,sizeof(a))
#define msn(a,n,b) for(int i=0;i<=n;i++)a[i]=b
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define fi first
#define se second
using namespace std;
mt19937 rng_32(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const int mod=1e9+7;
const int seed=233;
const double PI=acos(-1.0);
const double eps=1e-7;
const int inf=0x3f3f3f3f;
const int max_n=100005;
ll ceil(ll x,ll y){if(x==0)return 0;if(y<0)x=-x,y=-y;bool sign=x>0;x=abs(x);return sign?(x+y-1)/y:-x/y;}
ll floor(ll x,ll y){if(x==0)return 0;if(y<0)x=-x,y=-y;bool sign=x>0;x=abs(x);return sign?x/y:-(x+y-1)/y;}
namespace {
    inline int Add(int x,int y){return (x+=y)>=mod?x-mod:x;}
    inline int Sub(int x,int y){return (x-=y)<0?x+mod:x;}
    inline int Mul(int x,int y) {return 1ll*x*y%mod;}
    inline int Pow(int x,int y=mod-2){if(y==0)return 1;int res=1;while(y){if(y&1)res=1ll*res*x%mod;x=1ll*x*x%mod;y>>=1;}return res;}
}
/**********************head************************/
map<P,int> mp;
int n;
P get(int x){
    int r=x%10;
    while(x>=10)x/=10;
    return P(x,r);
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        mp[get(i)]++;
    }
    ll ans=0;
    for(int i=1;i<=n;i++){
        P p=get(i);
        swap(p.fi,p.se);
        ans+=mp[p];
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <cmath>
#include <cstring>
#include <assert.h>
#include <utility>
#include <tuple>
#include <array>
#include <bitset>
#include <cstdlib>

using int64 = long long;

using namespace std;

constexpr int INF = (1 << 30);

int N;
vector<int> as, answers, table;
vector<vector<int>> tree;

void DFS(int u, int p) {
    int i = lower_bound(begin(table), end(table), as[u]) - begin(table);
    int old_value = table[i];

    table[i] = as[u];
    answers[u] = lower_bound(begin(table), end(table), INF) - begin(table);

    for (int c : tree[u]) {
        if (c == p) continue;
        DFS(c, u);
    }

    table[i] = old_value;
}

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

    cin >> N;
    as.resize(N);
    for (int i = 0; i < N; i++) {
        cin >> as[i];
    }

    tree.resize(N);
    for (int i = 0; i < N - 1; i++) {
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        tree[u].push_back(v);
        tree[v].push_back(u);
    }

    answers.resize(N);
    table.resize(N, INF);
    DFS(0, -1);

    for (int i = 0; i < N; i++) {
        cout << answers[i] << endl;
    }

    return 0;
}



Measured memory_bytes: 27576
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef long long ll;
struct edge { ll s, t, x; };
typedef pair<ll, ll> P;
typedef pair<ll,P> event;
const ll MAX = 510000;
const ll MOD = 1000000007;
#define INF (ll)1000000000000
int main() {
  string S,T;
  cin>>S>>T;
  ll N=(ll)S.size();
  set<ll>st[26];
  ll dp[26][S.size()];
  rep(i,N){
    st[S[i]-'a'].insert(i);
  }
  rep(i,26){st[i].insert(10000000ll);}
  rep(i,N){rep(j,26){dp[j][i]=INF;}}
  rep(i,26){
    if(st[i].size()==1){continue;}
    rep(j,N){
      auto t=st[i].upper_bound(j);
      if(*t==10000000ll){dp[i][j]=min(dp[i][j],N-j+*begin(st[i]));}
      else{dp[i][j]=min(dp[i][j],(*t)-j);}
    }
  }
  ll ans=-1ll;
  rep(i,T.size()){
    if(st[T[i]-'a'].size()==1){ans=-2;break;}
    ll g=(ans+N)%N;
    ans+=dp[T[i]-'a'][g];
  }
  cout<<ans+1ll;
}


Measured memory_bytes: 28820
import java.util.Scanner;

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[][] list = new int[n + 1][n + 1];
            for (int i = 0; i < n + 1; i++) {
                if (i == n) {
                    int sum=0;
                    for (int j = 0; j < n; j++) {
                        sum+=list[n][j];
                        System.out.printf("%5d",list[n][j] );
                    }
                    System.out.printf("%5d\n",sum);                    
                } else {
                    for (int j = 0; j < n; j++) {
                        int m = sc.nextInt();
                        list[i][j] = m;
                        list[i][n] += m;
                        list[n][j] += m;
                        System.out.printf("%5d",m);
                    }
                    System.out.printf("%5d\n",list[i][n]);
                }
            }
        }
    }
}


Measured memory_bytes: 31568
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = list(map(int, input().split()))
m = min(a)
M = max(a)
from collections import Counter
c = Counter(a)
ans = True
if c[m]==1:
    if 2*m<M:
        ans = False
elif c[m]==2:
    if 2*m-1<M:
        ans = False
else:
    ans = False
if ans:
    for i in range(m+1, M+1):
        if i not in c or c[i]<=1:
            ans = False
            break
if ans:
    print("Possible")
else:
    print("Impossible")

Measured memory_bytes: 65124
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();
        int n = s.length;
        int k = sc.nextInt();
        for (int i = 0 ; i < n ; i++) {
            if (s[i] != 'a' && k > 'z' - s[i]) {
                k -=  'z' - s[i] + 1;
                s[i] = 'a';
            }
        }
        char[] al = new char[26];
        char c = 'a';
        for (int i = 0 ; i < 26; i++) {
            al[i] = c++;
        }
        s[n - 1] = al[s[n - 1] - 'a' +  k % 26];
        for (int i = 0 ; i < n ; i++) {
            System.out.print(s[i]);
        }
        System.out.println("");
    }

}

Measured memory_bytes: 35428
def examB():
    S = SI()
    ans = "YES"
    if S.count("x")>=8:
        ans = "NO"
    print(ans)

from string import digits
import sys,copy,bisect,itertools,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examB()


Measured memory_bytes: 38768
# -*- coding: utf-8 -*-
"""
Created on Tue Aug 20 17:21:41 2019

@author: Owner
"""

from collections import deque

S = input()

lens = len(S)
    
def rec(i, cp, s, tot):
    if i == lens:
        #print(s)
        tmp = list(map(int, s.split("+")))
        return sum(tmp)
    
    tot += rec(i+1, cp+1, s[:i+cp]+"+"+s[i+cp:], tot) + rec(i+1, cp, s, tot)
    return tot
    

def main():    
    return print(rec(1, 0, S, 0))
             
                
                
            
            
                

    
if __name__ == '__main__':
    main()

Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;
// ------------------------------

int main() {
    ll N, A, B;
    cin >> N >> A >> B;
    ll tmp = 0;
    if ((B - A) % 2 == 0) {
        cout << B - (B + A) / 2 << endl;
    } else {
        ll left = A - 1;
        ll right = N - B;
        if (left > right) tmp = right + 1, right = N, left = A + tmp;
        else tmp = left + 1, left = 1, right = B - tmp;
        cout << right - (right + left) / 2 + tmp << endl;
    }
    return 0;
}


Measured memory_bytes: 3612
n,a = map(int, input().split())
x = list(map(int, input().split()))
y = max(x)
x = [z-a for z in x]

dp = [[0]*(2*n*y+1) for _ in range(n+1)]
dp[0][n*y] = 1
for k in range(n):
    for i in range(2*n*y+1):
        res = dp[k][i]
        if i+x[k] < 0 or i+x[k] > 2*n*y:
            pass
        else:
            res += dp[k][i+x[k]]
        dp[k+1][i] = res
print(dp[-1][n*y]-1)


Measured memory_bytes: 5616
import java.util.*;

class Main{
public static void main(String[] args){
int a;
int b;
Scanner sc=new Scanner(System.in);
while(sc.hasNextInt()){
a=sc.nextInt();
b=sc.nextInt();
int d=(int)Math.log10(a+b)+1;
System.out.println(d);
}
}
}

Measured memory_bytes: 20408
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <ctime>
#include <algorithm>
#include <vector>
#include <cstring>
using namespace std;

int main(){
	string a;
	cin >> a;
	long alphabet[26];
	for(int i = 0; i < 26; i++){
		alphabet[i] = 0;
	}
	long size = a.size();
	for(int i = 0; i < size; i++){
		alphabet[a[i]-'a']++;
	}
	long ans = 1;
	for(int i = 0; i < 25; i++){
		for(int j = i + 1; j < 26; j++){
			ans += alphabet[i] * alphabet[j];
		}
	}
	printf("%ld\n", ans);
	return 0;
}

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

#define what_is(x) cerr << #x << " is " << x << endl;
#define what_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << e << ' '; cerr << '\n'; //vector, set
#define what_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << x[i] << ' '; cerr <<  '\n'; //n first element of array
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define cerr_pair(x) '{' << x.st << ", " << x.nd << '}'
#define pwhat_is(x) cerr << #x << " is " << cerr_pair(x) << endl;
#define pwhat_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << cerr_pair(e) << ' '; cerr << '\n'; //vector, set
#define pwhat_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << cerr_pair(x[i]) << ' '; cerr <<  '\n'; //n first element of array
#define endl '\n'
// #define int long long

typedef pair<int,int> pii;
const int N = 1e5+5;
const int INF = 1e9;
const int MOD = 1e9+7;

int n, d;
int32_t main()
{
	IOS
	//freopen("input.txt", "r", stdin);
	cin >> n >> d;
	int ans = n/(2*d+1) + (n%(2*d+1)!=0);
	cout << ans << endl;
	
	return 0;
}


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

using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;

ll N, M;
int main(int argc, const char * argv[]) {
  cin >> N >> M;
  
  ll cnt = min(N, M / 2);
  N -= cnt;
  M -= 2 * cnt;
  cnt += M / 4;
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

        int N = Integer.valueOf(scanner.nextLine());
        String[] temp = scanner.nextLine().split(" ");
        int T = Integer.valueOf(temp[0]);
        int A = Integer.valueOf(temp[1]);

        int[] H = new int[N];
        for (int i = 0; i < N; i++) {
            H[i] = scanner.nextInt();
        }

        int result = -1;
        double min = 1000000;

        for (int i = 0; i < H.length; i++) {
            double sa = Math.abs(aveTemp(T, H[i]) - A);
            if (min > sa) {
                min = sa;
                result = i;
            }
        }

        System.out.println(result + 1);
    }

    public static double aveTemp(int T, int x) {
        return (double)T - (double)x * 0.006;
    }

}


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

int main(){
    string s;
    cin >> s;
    
    bool isgood = false;
    if (s[0] == s[1] && s[2] == s[3] && s[1] != s[2]) isgood = true;
    if (s[0] == s[2] && s[1] == s[3] && s[1] != s[2]) isgood = true;
    if (s[0] == s[3] && s[1] == s[2] && s[0] != s[1]) isgood = true;
    
    if(isgood){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);
	string s;
	cin >> s;
	ll x = 0, n = s.size();
	for(int i = 0;i < n;i++)
		x += (int)(s[i] - '0');
	if(x%9)
		cout << "No";
	else
		cout << "Yes";
}


Measured memory_bytes: 3780
#include<iostream>
#include<string>
#include<cstring>
using namespace std;
int main()
{	
	int num1,num2,num3,num4;
	double num5,num6;
	
	cin>>num1>>num2>>num3;
	num5=num2/num3;
	num6=num1/num3;
	
	if(num1==num2&&num2==num3){
		num4=1;
	}
	else if(num1==num2){
		num4=2;
	}
	else if(num1==num3){
		num4=2;
	}
	else if(num2==num3){
		num4=2;
	}
	else{
		num4=3;
	}
	cout<<num4;
	cout<<"\n";
	return 0;
}


Measured memory_bytes: 256
{-# LANGUAGE MultiWayIf #-}

import Control.Applicative
import Control.Monad
import Data.List

solve :: Int -> Int -> Int
solve x y
    | ax == ay = if
        | x == y    -> 0
        | otherwise -> 1
    | ax <  ay = if
        | x >= 0    -> btnA + btnB (x + btnA) y
        | otherwise -> 1 + btnA + btnB ((negate x) + btnA) y
    | ax >  ay = if
        | x <  0    -> btnA + btnB (x + btnA) y
        | otherwise -> 1 + btnA + btnB ((negate x) + btnA) y
  where
    ax = abs x
    ay = abs y
    btnA = abs (ax - ay)
    btnB i j | i == j    = 0
             | otherwise = 1

main :: IO ()
main = do
    [x, y] <- fmap read . words <$> getLine :: IO [Int]
    print $ solve x y

Measured memory_bytes: 508
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const long double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	ll n, a, b;
	cin >> n >> a >> b;

	if (a > b) {
		out(0);
		return 0;
	}

	if (n == 1) {
		if (a != b) out(0);
		else out(1);
		return 0;
	}

	ll mi = a * (n - 1) + b;
	ll ma = b * (n - 1) + a;

	out(ma - mi + 1);

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<array>
#include<algorithm>

const int INDEX_SIZE = 10;

class ContestScore {
private:
    std::array<int, INDEX_SIZE> scoreData;
public:
    void setScore(int index,int score);
    void showScoreData();
    int getTop3TotalScore();
};

void ContestScore::setScore(int index,int score){
    scoreData[index] = score;
}

void ContestScore::showScoreData(){
    for(int i : scoreData){
        std::cout << i << std::endl;
    }
}

int ContestScore::getTop3TotalScore(){
    std::sort(scoreData.begin(),scoreData.end());
    int dataSize = scoreData.size();
    return scoreData[dataSize - 1] + scoreData[dataSize - 2] + scoreData[dataSize - 3];
}

ContestScore inputContestScore();

int main(){
    
    //1stGroup
    ContestScore cs1 = ContestScore();
    cs1 = inputContestScore();

    //2ndGroup
    ContestScore cs2 = ContestScore();
    cs2 = inputContestScore();

    std::cout << cs1.getTop3TotalScore() << " " << cs2.getTop3TotalScore() << std::endl;

    return 0;
}

ContestScore inputContestScore(){
    ContestScore cs = ContestScore();
    for(int i = 0;i < INDEX_SIZE;i++){
        int input = 0;
        std::cin >> input;
        cs.setScore(i, input);
    }
    return cs;
}

Measured memory_bytes: 3132
def count_RL(S):
  RL = ['R', 'L']
  pos = [0, 0] # [end, start]
  mode = 0
  N = len(S)
  c = 0
  out = [0 for i in range(N)]
  for i in range(N):
    if S[i] == RL[mode]:
      c += 1
    else:
      pos[0] = i - 1
      out[pos[mode]] = c
      mode = (mode + 1) % 2
      pos[1] = i
      c = 1
    if i == N-1:
      out[pos[1]] = c
  return out


def distribute(out):
  N = len(out)
  obj = [0 for i in range(N)]
  i = 0
  while i < N:
    if out[i] != 0:
      a1 = out[i] // 2 # neighbor
      b1 = out[i] - a1 # self
      b2 = out[i+1] // 2
      a2 = out[i+1] - b2
      obj[i] = b1 + b2
      obj[i+1] = a1 + a2
      i += 1
    i += 1
  return obj

S = input()
out = distribute(count_RL(S))
state = ''
for v in out:
  state += ' {0}'.format(v)

print(state[1:])

Measured memory_bytes: 4860
#include<iostream>
#include<string>
using namespace std;
int main()
{
    int n, AC = 0, WA = 0, TLE = 0, RE = 0;
    cin >> n;
    string s;
    for(int i = 0; i < n; i++)
    {
        cin >> s;
        if(s == "AC")
            AC++;
        if(s == "WA")
            WA++;
        if(s == "TLE")
            TLE++;
        if(s == "RE")
            RE++;
    }
    cout << "AC x " << AC << endl;
    cout << "WA x " << WA << endl;
    cout << "TLE x " << TLE << endl;
    cout << "RE x " << RE << endl;
    return 0;
}

Measured memory_bytes: 3596