akhauriyash/Code-Regression huggingface dataset:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

map<lint,int> p_factorization(lint n){
    map<lint,int> soinsu;
    for(int i=2;i<=sqrt(n);i++){
        while(n%i==0){
            n/=i;
            soinsu[i]++;
        }
    }
    if(n!=1)soinsu[n]++;
    return soinsu;
}

//AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC
int main(){
    lint n;cin>>n;
    int ans=0;
    auto soinsu=p_factorization(n);
    for(auto p:soinsu){
        int kosuu=p.second;
        for(int i=1;i<1000;i++){
            kosuu-=i;
            if(kosuu<0)break;
            ans++;
        }
    }
    cout<<ans<<endl;
}


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

int main() {
  
  string S;
  cin >> S;
  
  int p = 700;
  
  if (S.at(0)=='o') {
    p += 100;    
  }
  if (S.at(1)=='o') {
    p += 100;    
  }
  if (S.at(2)=='o') {
    p += 100;    
  }
  
  cout << p << endl;   

return 0;
}

Measured memory_bytes: 3552
N = int(input())
X = list(map(int, input().split()))
sorted_X = sorted(X)
# print('X', X)
# print('median candidate', sorted_X[N // 2 - 1], sorted_X[N // 2])
for i in X:
    if i <= sorted_X[N // 2 - 1]:
        print(sorted_X[N // 2])
    else:
        print(sorted_X[N // 2 - 1])


Measured memory_bytes: 25220
#include <bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = (int)j;i <= (int)k;i ++)
#define debug(x) cerr<<#x<<":"<<x<<endl
#define pb push_back

typedef long long ll;
typedef pair<int,int> pi;
const int MAXN = (int)1e6+7;

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

    int a;
    string s;
    cin >> a >> s;
    if (a >= 3200) {
        cout << s << endl;
    }else {
        cout << "red" << endl;
    }
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::multiprecision;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define rep(I,N) for(auto I=0;I<(N);++I)
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
typedef long long ll;
typedef unsigned long long ull;
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                                      ins(T &p){for_each(all(p),in<decltype(p[0])>);}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}
inline                                              void out(double p){printf("%.10f\n",p);}
template<class T>inline                             void outs(T p){for_each(all(p),out<decltype(p[0])>);}

inline void solve(void){
  string s;
  in(s);
  if(s=="Sunny")out("Cloudy");
  if(s=="Cloudy")out("Rainy");
  if(s=="Rainy")out("Sunny");
}
int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 256
#![allow(unused_imports)]

use std::cmp;
use std::cmp::{max, min, Ordering};
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::io::stdin;
use std::ops::*;
use std::process::exit;
use std::str::FromStr;

const MOD: usize = 1000000007;

fn main() {
    let (n, k): (usize, usize) = input_two();

    let mut accu = vec![0; n + 2];
    for i in 2..n + 2 {
        accu[i] = accu[i - 1] + i - 1;
    }

    // dbg!(&accu);

    let mut ans = 0usize;
    for i in k..n + 2 {
        let t = accu[n + 1] - accu[n + 1 - i] - accu[i] + 1;
        ans += t;
        ans %= MOD;
        // dbg!(ans);
    }

    println!("{}", ans);
}

pub fn input<T: FromStr>() -> T {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().ok().unwrap()
}

pub fn input_vec<T: FromStr>() -> Vec<T> {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim()
        .split_whitespace()
        .map(|x| x.parse().ok().unwrap())
        .collect::<Vec<_>>()
}

pub fn input_lines<T: FromStr>(l: usize) -> Vec<T> {
    let mut res = Vec::new();
    for _i in 0..l {
        res.push(input());
    }
    res
}

pub fn input_lines_two<T: FromStr, U: FromStr>(l: usize) -> Vec<(T, U)> {
    let mut res = Vec::new();
    for _i in 0..l {
        res.push(input_two());
    }
    res
}

pub fn input_lines_three<T: FromStr, U: FromStr, V: FromStr>(l: usize) -> Vec<(T, U, V)> {
    let mut res = Vec::new();
    for _i in 0..l {
        res.push(input_three());
    }
    res
}

pub fn input_two<T: FromStr, U: FromStr>() -> (T, U) {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let s: Vec<&str> = buf.split_whitespace().collect();
    (
        s[0].parse::<T>().ok().unwrap(),
        s[1].parse::<U>().ok().unwrap(),
    )
}

pub fn input_three<T: FromStr, U: FromStr, V: FromStr>() -> (T, U, V) {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let s: Vec<&str> = buf.split_whitespace().collect();
    (
        s[0].parse::<T>().ok().unwrap(),
        s[1].parse::<U>().ok().unwrap(),
        s[2].parse::<V>().ok().unwrap(),
    )
}

pub fn input_four<T: FromStr, U: FromStr, V: FromStr, W: FromStr>() -> (T, U, V, W) {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let s: Vec<&str> = buf.split_whitespace().collect();
    (
        s[0].parse().ok().unwrap(),
        s[1].parse().ok().unwrap(),
        s[2].parse().ok().unwrap(),
        s[3].parse().ok().unwrap(),
    )
}


Measured memory_bytes: 3500
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#include <deque>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

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

  string S;
  cin>>S;

  deque<char> DQ;
  rep(i,S.size()) DQ.push_back(S[i]);

  int turn=0;
  int Q;
  cin>>Q;
  rep(q,Q){
    int t;
    cin>>t;
    if(t==1){
      turn=1-turn;
    }else{
      int f;
      char c;
      cin>>f>>c;
      if(f==1){
        if(turn==0) DQ.push_front(c);
        else DQ.push_back(c);
      }else{
        if(turn==1) DQ.push_front(c);
        else DQ.push_back(c);
      }
    }
  }

  string T="";
  while(!DQ.empty()){
    char d=DQ.front();
    DQ.pop_front();
    T+=d;
  }
  if(turn) reverse(T.begin(),T.end());

  cout<<T<<endl;

  return 0;
}


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

int main() {
  int n;
  cin >> n;
  ll sum = 0, dsum = 0;
  rep(i, n) {
    ll a;
    cin >> a;
    sum = (sum + a) % mod;
    dsum = (dsum + (a * a) % mod) % mod;
  }
  sum = (sum * sum) % mod;
  if (sum >= dsum)
    sum -= dsum;
  else
    sum += mod - dsum;
  sum = (sum * (ll)(5e8 + 4)) % mod;
  cout << sum << endl;
  return 0;
}


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

int main()
{
  int ans;
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); i++)
  {
    if (s[i] == '?')
      cout << 'D';
    else
      cout << s[i];
  }
  cout << endl;
}

Measured memory_bytes: 3744
// D - joisino's travel
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)
#define all(x) (x).begin(),(x).end()
#define DIST_MAX 1000000000
#define N_MAX 200
#define R_MAX 8

void warshall_floyd(vvi &D){
	rpz(relay,D.size()) rpz(from,D.size()) rpz(to,D.size())
		D[from][to] = min(D[from][to], D[from][relay] + D[relay][to]);
}

int N,M,R;
vi RR(R_MAX+1);
vvi D(N_MAX+1, vi(N_MAX+1, DIST_MAX));
ll ans_dist = DIST_MAX;

vi visited(R_MAX+1, false);

void dfs(int p, int depth, ll dist){
	// rpz(i,depth)printf(">");printf("p %d dist %d\n",p,dist);//
	// rpz(i,R+1) printf("%d ",visited[i]);puts("");

	if(depth+1 >= R+1){
		ans_dist = min(ans_dist, dist);
	}
	else{
		rp(r, 1, R+1){
			int c = RR[r];
			if(visited[r]) continue;
			visited[r] = true;
			dfs(c, depth+1, dist+D[p][c]);
			visited[r] = false;
		}
	}

}

int main(){
	cin>>N>>M>>R;
	RR.resize(R+1);
	rp(i, 1, R+1) cin>>RR[i];
	D.resize(N+1);
	rpz(i,N+1) D[i].resize(N+1);
	rpz(i, N+1) D[i][i] = 0;
	rpz(i, M) rpz(j, 3){
		int a,b,c; cin>>a>>b>>c;
		D[a][b] = D[b][a] = c;
	}
	warshall_floyd(D);
	rpz(i, N+1){D[0][i] = 0;D[i][0] = 0;}

	visited[0] = true;
	dfs(0, 0, 0);
	cout<< ans_dist <<endl;

	// for(auto e:RR){printf("%d ",e);}puts("\n--");///
	// for(auto v:D){for(auto e:v){
	// 	if(e==DIST_MAX) printf("- ");else printf("%ld ",e);
	// }puts("");}puts("---");//

}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
const ll MOD = 1e9+7;

int main(){
  int n,ma=0,sum=0;
  cin>>n;
  for(int i=0;i<n;i++){
    int p;
    cin>>p;
    sum+=p;
    ma=max(p,ma);
  }
  cout<<sum-ma/2<<endl;
  return 0;
}


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

using UnweightedGraph = vector<vector<int>>;
struct LowLink {
    const UnweightedGraph &g;
    vector<int> aps;                // articulation points
    vector<pair<int, int>> brs;     // brides
    vector<int> seen, ord, low;
    LowLink(const UnweightedGraph &g) : g(g) { }
    int dfs(int u, int p = -1, int time = 0) {
        seen[u] = true;
        ord[u] = low[u] = time++;
        bool exists = false;
        int cnt_ch = 0;
        for (auto v : g[u]) {
            if (!seen[v]) {
                ++cnt_ch;
                time = dfs(v, u, time);
                low[u] = min(low[u], low[v]);   // forward edge
                if (ord[u] < low[v]) brs.emplace_back(u, v);
                if (ord[u] <= low[v]) exists = true;
            } else if (v != p) {
                low[u] = min(low[u], ord[v]);   // back edge
            }
        }
        if ((p == -1 && cnt_ch > 1) || (p != -1 && exists)) {
            aps.emplace_back(u);
        }
        return time;
    }
    void build() {
        int N = g.size();
        seen.assign(N, 0); ord.resize(N); low.resize(N);
        aps.clear(); brs.clear();
        for (int v = 0; v < N; ++v) if (!seen[v]) dfs(v);
        for (auto &br: brs) if (br.first > br.second) swap(br.first, br.second);
        sort(brs.begin(), brs.end());
        sort(aps.begin(), aps.end());
    }
};

int main() {
    int V, E; cin >> V >> E;
    UnweightedGraph g(V);
    while (E--) {
        int s, t; cin >> s >> t;
        g[s].emplace_back(t);
        g[t].emplace_back(s);
    }
    LowLink ll(g);
    ll.build();
    //for (auto v: ll.aps) cout << v << endl;
    for (auto b: ll.brs) cout << b.first << " " << b.second << endl;
    return 0;
}


Measured memory_bytes: 4388
/**
 *    author:  Mohamad Milhem
 *    created: 2020-03-07-14.07.07
**/

#include <bits/stdc++.h>
#include <stdio.h>

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define MOD ll(1000000007)
#define debug(x) cout << '[' << #x << " is: " << x << "] " <<endl;
#define decimalpoint cout << std::fixed << setprecision(5)


int main(){

    FAST;


    string s;
    cin >> s;

    int q;

    cin >> q;

    string before = "";
    string after = "";
    int reverses = 0;

    while(q--){
        int n;
        cin >> n;

        if (n == 1){
//            reverse(before.begin(), before.end());
//            reverse(after.end(), after.end());
            swap(before, after);
            reverses++;
        }

        else {
            char c;
            int k;
            cin >> k;
            cin >> c;

            if (k == 1)before+= c;
            else after+= c;
        }



    }


    reverse(before.begin(), before.end());
    string ans = before;
    if (reverses & 1)reverse(s.begin(), s.end());
    ans+= s;
    ans+= after;
    cout << ans <<endl;


    return 0;
}


Measured memory_bytes: 1300
#include<bits/stdc++.h>
using namespace std;
int a[100005],f[100005],n,nf=1e9,k;
int main()
{
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++) scanf("%d",a+i);
    for(int i=1;i<=n;i++) f[i]=nf;
    for(int i=1;i<n;i++)
    for(int j=1;j<=k&&i-j>=0;j++)
    f[i]=min(f[i],f[i-j]+abs(a[i]-a[i-j]));
    printf("%d",f[n-1]);
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    string s;
    cin>>s;
    deque<char> q;
    for(char c : s) q.push_back(c);
    bool flip=false;
    int Q;
    cin>>Q;
    while(Q--){
        int t;
        cin>>t;
        if(t==1) flip=!flip;
        else{
            int f;
            char c;
            cin>>f>>c;
            if(flip) f=3-f;
            if(f==1) q.push_front(c);
            else q.push_back(c);
        }
    }
    if(flip) reverse(all(q));
    string ans;
    for(char c : q) ans+=c;
    cout<<ans<<endl;
}

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

class Program {
  static void Main() {
    var arr = Console.ReadLine().Split().Select(int.Parse).ToArray();
    int a = arr[0];
    int b = arr[1];
    int c = arr[2];
    int n = 1;
    while (true) {
      if ((n * a + c) % b == 0) {
        Console.WriteLine("YES");
        break;
      }
      n++;
      if (n * a % b == a % b) {
        Console.WriteLine("NO");
        break;
      }
    }
  }
}

Measured memory_bytes: 13268
#include <iostream>

using namespace std;

int main(void){
  int a, b, c;
  cin >> a >> b >> c;
  int min, mid, max;
  bool fa = 0, fb = 0, fc = 0;

  // decide min
  if(a <= b && a <= c) min = a, fa = 1;
  if(b <= c && b <= a) min = b, fb = 1;
  if(c <= a && c <= b) min = c, fc = 1;

  // decide max
  if(a >= b && a >= c) max = a, fa = 1;
  if(b >= c && b >= a) max = b, fb = 1;
  if(c >= a && c >= b) max = c, fc = 1;

  // decide mid
  if(fb == 1 && fc == 1) mid = a;
  if(fc == 1 && fa == 1) mid = b;
  if(fa == 1 && fb == 1) mid = c;

  // print
  cout << min << " " << mid << " " << max << endl;
  return 0;
}



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

int main(){
	int a,b,n;
	cin>>a>>b>>n;
	for(int i=0;i<(n/2);i++){
		if(a%2!=0){a--;}
		a=a/2;
		b+=a;
		if(b%2!=0){b--;}
		b=b/2;
		a+=b;
	}
	if(n%2==1){
		if(a%2!=0){a--;}
		a=a/2;
		b+=a;
	}
	cout<<a<<" "<<b<<endl;
}

Measured memory_bytes: 256
N = int(input())
dic = {}

for _ in range(N):
    i = input()
    if i in dic:
        dic[i] += 1
    else:
        dic[i] = 1

M = int(input())

for _ in range(M):
    j = input()
    if j in dic:
        dic[j] -= 1
    else:
        dic[j] = -1

print(max(0, max(dic.values())))

Measured memory_bytes: 9060
#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 <cstdint>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;

typedef pair<int, int> P;

bool ps1(const P &element1, const P &element2)
{ //first昇順
	return element1.first < element2.first;
}
bool ps2(const P &element1, const P &element2)
{ //first降順
	return element1.first > element2.first;
}
bool ps3(const P &element1, const P &element2)
{ //second昇順
	return element1.second < element2.second;
}
bool ps4(const P &element1, const P &element2)
{ //second降順
	return element1.second > element2.second;
}
int digits(int n)
{
	int count = 0;
	while (n > 0)
	{
		n /= 10;
		count++;
	}
	return count;
}
ll combination(ll n, ll r)
{
	if (r * 2 > n)
		r = n - r;
	ll dividend = 1;
	ll divisor = 1;
	for (ll i = 1; i <= r; ++i)
	{
		dividend *= (n - i + 1);
		divisor *= i;
	}
	return dividend / divisor;
}
int GCD(int x, int y)
{
	return x ? GCD(y % x, x) : y;
}
vector<int> divisor(int n)
{
	vector<int> value;
	FOR(i, 1, pow(n, 0.5) + 1)
	{
		if (i <= sqrt(n))
		{
			if (n % i == 0)
			{
				value.push_back(i);
				if (i * i != n)
				{
					value.push_back(n / i);
				}
			}
		}
	}
	return value;
}

int main()
{
	int n,m;
	cin>>n>>m;
	vector<bool>bri(m,true);
	vector<pair<int,int>>ab(m);
	int ans=0;
	rep(i,m){
		
		cin>>ab[i].F>>ab[i].S;
	}
	sort(all(ab),ps3);
	
	int b=0;
	rep(i,m){
		if(ab[i].F<b){
			bri[i]=false;
		}
		if(bri[i]){
			b=ab[i].S;
			bri[i]=false;
			ans++;
		}
	}
	cout<<ans<<endl;

	
}

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

int main() {
    string s;
    cin >> s;
    if (s == "hi" || s == "hihi" || s == "hihihi" || s == "hihihihi" || s == "hihihihihi")
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    print([N, N*2][N%2])


if __name__ == '__main__':
    main()


Measured memory_bytes: 10132
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>

using namespace std;

int main()
{
    long long N, M;
    long long ans= 0;

    cin >> N >> M;

    ans += min(N, M / 2);
    ans += max((long long)((M - ans * 2) / 4), 0LL);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <cstdint>
#include <chrono>

using namespace std;
#define     loop(n,i,a)     for(ll i=a;i<n;i++)
#define     loopR(n,i,a)    for(ll i=a-1;i>=n;i--)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     pii             pair<ll,ll>
#define     vi              vector<int>
#define     vll             vector<ll>
#define     vii             vector<pii>
#define     sz(x)           (int)x.size()
#define     pb              push_back
#define     endl            "\n"
#define     Endl            "\n"
#define     f               first
#define     s               second
#define     mem(dp,n)       memset(dp,n,sizeof dp)
template<typename T>void max_self(T &a,T b){a=max(a,b);}
template<typename T>void min_self(T &a,T b){a=min(a,b);}
int dx[] = { 1 , 0 ,-1 , 0 ,-1 ,-1 , 1 , 1 };
int dy[] = { 0 , 1 , 0 ,-1 ,-1 , 1 ,-1 , 1 };
int KnightI[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
int KnightJ[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
void fast(){
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
        vector<string> __attribute__ ((unused)) args,
        __attribute__ ((unused)) int idx,
        __attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
const ll mxN=4e5+10,oo=0x3f3f3f3f,MOD=1e9+7;
const long double PI = acos(-1),eps=1.0e-14;
void solve(){
    int n;
    cin>>n;
    map<string,int>mp;
    vector<string>v;
    loop(n,i,0){
        string s;
        cin>>s;
        v.pb(s);
        mp[s]++;
    }
    if(sz(mp)!=n){
        cout<<"No"<<endl;
        return;
    }
    loop(n,i,1){
        if(v[i].front()!=v[i-1].back()){
            cout<<"No"<<endl;
            return;
        }
    }
    cout<<"Yes"<<endl;
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast();
    solve();

}


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

#define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++)
#define ALL(x) x.begin(),x.end()
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

int N;
const ll INF = 2e18;

int main()
{
	scanf("%d",&N);
	vector<ll> A(N * 2);
	FOR(i,0,N){
		scanf("%lld%lld",&A [i],&A [i + N]);
	}
	int allMin = min_element(A.begin(),A.end()) - A.begin();
	int allMax = max_element(A.begin(),A.end()) - A.begin();

	ll ans = INF;
	if(abs(allMin - allMax) != N){
		map<ll,ll> mp;
		vector< pair<ll,int> > B;
		FOR(i,0,N){
			if(i == allMin){
				mp [A [i + N]]++;
				B.push_back(make_pair(A [i + N],i + N));
				continue;
			}
			if(i + N == allMin){
				mp [A [i]]++;
				B.push_back(make_pair(A [i],i));
				continue;
			}
			if(i == allMax){
				mp [A [i + N]]++;
				B.push_back(make_pair(A [i + N],i + N));
				continue;
			}
			if(i + N == allMax){
				mp [A [i]]++;
				B.push_back(make_pair(A [i],i));
				continue;
			}
			if(A [i] <= A [i + N]){
				mp [A [i]]++;
				B.push_back(make_pair(A [i],i));
			}
			else{
				mp [A [i + N]]++;
				B.push_back(make_pair(A [i + N],i + N));
			}
		}
		sort(B.begin(),B.end());
		ll res = (--mp.end())->first - mp.begin()->first;
		FOR(i,0,N){
			if(--mp [B [i].first] == 0){
				mp.erase(B [i].first);
			}
			if(B [i].second < N){
				mp [A [B [i].second + N]]++;
			}
			else{
				mp [A [B [i].second - N]]++;
			}
			chmin(res,(--mp.end())->first - mp.begin()->first);
		}
		chmin(ans,res * (A [allMax] - A [allMin]));
	}
	{
		ll rMax = -INF,rMin = INF;
		ll bMax = -INF,bMin = INF;
		FOR(i,0,N){
			if(A [i] <= A [i + N]){
				chmax(rMax,A [i]);
				chmin(rMin,A [i]);
				chmax(bMax,A [i + N]);
				chmin(bMin,A [i + N]);
			}
			else{
				chmax(rMax,A [i + N]);
				chmin(rMin,A [i + N]);
				chmax(bMax,A [i]);
				chmin(bMin,A [i]);
			}
		}
		chmin(ans,(rMax - rMin) * (bMax - bMin));
	}

	printf("%lld\n",ans);

	return 0;
}


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

#define rep(i, a) for (int i = 0; i < (a); i++ )

 
typedef pair<int,int> P;
typedef long long ll;
 
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);


vector<string> get_str(vector<string> &A, int i, int j, int N) {
    //vector<string> R(N,"");
    vector<string> R;
    rep(h,N) {
        //R[h] = A[(h+i)%N].substr(j,N);
        R.push_back(A[(h+i)%N].substr(j,N));
    }
    return R;
}


int main(){
    int N;
    cin >> N;

    vector<string> A(N,"");
    vector<string> B(N,"");
    rep(h,N) {
        rep(w,N) {
            char a;
            cin >> a;
            A[h].push_back(a);
            B[w].push_back(a);
        }
    }
    rep(i,N) {
        A[i] += A[i];
        B[i] += B[i];
    }
    int ans = 0;
    
    int i = 0;
    rep(j,N) {
        auto R1 = get_str(A,i,j,N);
        auto R2 = get_str(B,j,i,N);
        if (R1==R2) {
            ans += N;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 4400
#line 1 "/workspaces/compro/lib/template.hpp"


#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<

using namespace std;

template <class T> void say(bool val, T yes, T no) { cout << (val ? yes : no) << "\n"; }

void say(bool val, string yes = "Yes", string no = "No") { say<string>(val, yes, no); }

template <class T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}

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

// C++ 17に完全移行したら消す
// 最大公約数を求める
template <class T> T gcd(T n, T m) { return n ? gcd(m % n, n) : m; }

// 最小公倍数を求める
template <class T> T lcm(T n, T m) {
  int g = gcd(n, m);
  return n * m / g;
}

// 重複を消す。計算量はO(NlogN)
template <class T> void unique(std::vector<T> &v) {
  std::sort(v.begin(), v.end());
  v.erase(std::unique(v.begin(), v.end()), v.end());
}


#line 2 "abc172_c.cpp"

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

  int n, m;
  cin >> n >> m;
  ll k;
  cin >> k;
  vl a(n), b(m);
  REP(i, n) { cin >> a[i]; }
  REP(i, m) { cin >> b[i]; }

  vl cuma(n + 1), cumb(m + 1);
  cuma[0] = 0;
  cumb[0] = 0;
  FOR(i, 1, n + 1) { cuma[i] += cuma[i - 1] + a[i - 1]; }

  FOR(i, 1, m + 1) { cumb[i] += cumb[i - 1] + b[i - 1]; }

  int ans = 0;
  REP(i, n + 1) {
    ll res = k - cuma[i];
    if (res < 0)
      continue;
    int itr = upper_bound(ALL(cumb), res) - cumb.begin() - 1;
    chmax(ans, itr + i);
  }

  cout << ans << endl;
}


Measured memory_bytes: 9532
import queue

def Dijkstra(vertex,edges,start):
	weight = [0 if i==start else float("inf") for i in range(vertex)]
	Q = queue.PriorityQueue()
	Q.put((weight[start],start))

	while(not Q.empty()):
		cur = Q.get()
		if weight[cur[1]] < cur[0]:
			continue
		for j in range(len(edges[cur[1]])):
			if weight[edges[cur[1]][j][1]] > weight[cur[1]] + edges[cur[1]][j][2]:
				weight[edges[cur[1]][j][1]] = weight[cur[1]] + edges[cur[1]][j][2]
				Q.put((weight[edges[cur[1]][j][1]],edges[cur[1]][j][1]))
	return weight

V,E,r = map(int,input().split())
edges = [[] for i in range(V)]
for i in range(E):
	data = list(map(int,input().split()))
	edges[data[0]].append(data)
for j in range(V):
	edges[j].sort()
w = Dijkstra(V,edges,r)
for i in range(len(w)):
	if w[i]==float("inf"):
		print('INF')
	else:
		print(w[i])


Measured memory_bytes: 131680
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using pll=pair<ll,ll>;
using graph=vector<vector<int>>;
using wgraph=vector<vector<pll>>;

const ll MOD=1000000007;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int ex[8]={1,1,0,-1,-1,-1,0,1};
const int ey[8]={0,1,1,1,0,-1,-1,-1};

ll abs1(ll a){
  if(a>=0)return a;
  else return -a;
}

ll pow1(ll a,ll b,ll p=LLONG_MAX){
  ll ret=1;
  while(b!=0){
    if((b&1)==1){
      ret*=a;
    }
    a*=a;
    if(a>=p)a%=p;
    b=b>>1;
  }
  return ret;
}

int digit(ll a,ll b){
  int i=0;
  while(a!=0){
    a/=b;
    i++;
  }
  return i;
}

ll gcd1(ll a,ll b){
  if(a==0 && b==0)return 0;
  ll n;
  while(a%b!=0){
    n=a%b;
    a=b;
    b=n;
  }
  return b;
}

ll solveLinear(ll n,ll m,ll c){
  if(n==0 && m==0)return 0;
  ll a[100],b[100];
  a[0]=n;b[0]=m;
  int i=1;
  while(b[i-1]!=0){
    a[i]=b[i-1];
    b[i]=a[i-1]%b[i-1];
    i++;
  }
  n=i;
  if(c%a[n-1]!=0){
    return 0;
  }
  ll x=c/a[n-1],y=0;
  for(i=1;i<n;i++){
    ll cnt=x;
    x=y;
    y=cnt-(a[n-i-1]/b[n-i-1])*y;
  }
  return x;
}

ll modRev(ll a,ll p=MOD){
  a%=p;
  ll n=solveLinear(a,p,1);
  n%=p;
  if(n<0)return n+p;
  return n;
}

ll fact(ll n,ll p=MOD){
  if(n<0)return 0;
  int i;
  ll ret=1;
  for(i=0;i<n;i++){
    ret=ret*(i+1);
    if(ret>=p)ret%=p;
  }
  return ret;
}

ll perm(ll n,ll k,ll p=MOD){
  if(n<0 || k<0 || n<k)return 0;
  int i;
  ll ret=1;
  for(i=0;i<k;i++){
    ret=ret*(n-i);
    if(ret>=p)ret%=p;
  }
  return ret;
}

ll binom(ll n,ll k,ll p=MOD){
  if(n<0 || k<0 || n<k)return 0;
  int i;
  ll ret=1,fact=1;
  for(i=0;i<k;i++){
    ret=ret*(n-i);
    fact*=i+1;
    if(ret>=p)ret%=p;
    if(fact>=p)fact%=p;
  }
  return (ret*modRev(fact))%p;
}

void pushHeap(vector<pll>& h,pll n){
  int i=h.size();
  h.push_back(n);
  while(i!=0 && h[(i-1)/2]>h[i]){
    swap(h[i],h[(i-1)/2]);
    i=(i-1)/2;
  }
  h[i]=n;
}

pll popHeap(vector<pll>& h){
  int n=h.size()-1;
  if(n==-1)return pll(0,0);
  ll i;
  pll ret=h[0];
  swap(h[0],h[n]);
  h.pop_back();
  for(i=0;i<n;){
    int j=2*i+1;
    if(j>=n)break;
    if(j!=n-1 && h[j]>h[j+1])j++;
    if(h[i]>h[j]){
      swap(h[i],h[j]);
    }
    i=j;
  }
  return ret;
}

vector<int> ver;
void dfs(const graph &g,int v){
  ver[v]=1;
  for(auto i:g[v]){
    if(ver[i]!=0)continue;
    dfs(g,i);
  }
}

int bis(vector<int> v,int key){
  int left=-1,right=v.size();
  while(abs1(right-left)>1){
    int mid=left+(right-left)/2;
    if(v[mid]<=key)left=mid;
    else right=mid;
  }
  return left;
}

int main(){
  int i,j,cnt=0;
  int n,k;
  cin>>n>>k;
  if(k>(n-1)*(n-2)/2){
    cout<<-1<<endl;
    return 0;
  }
  cout<<n*(n-1)/2-k<<endl;
  for(i=1;i<n;i++){
    for(j=i+1;j<n;j++){
      if(cnt==(n-1)*(n-2)/2-k)break;
      cout<<i<<" "<<j<<endl;
      cnt++;
    }
  }
  for(i=1;i<n;i++){
    cout<<i<<" "<<n<<endl;
  }
}


Measured memory_bytes: 256
'use strict'

function Main(input) {
  const inputList = input.split('\n');
  const fiveHundread = inputList[0]
  const oneHundread = inputList[1]
  const fifty = inputList[2]
  const sum = Number(inputList[3])
  let count = 0;

  let tmpTotal = 0;

  for (let i=0; i<=fiveHundread; i++) {
    tmpTotal = 500 * i
    if (tmpTotal > sum) {
      break
    } else if (tmpTotal === sum) {
      count ++
      break
    }
    for (let j=0; j<=oneHundread; j++) {
      tmpTotal = 500 * i + 100 * j 
      if (tmpTotal > sum) {
        break
      } else if (tmpTotal === sum) {
        count ++
        break
      }
      for (let k=0; k<=fifty; k++) {
        tmpTotal = 500 * i + 100 * j + 50 * k
        if (tmpTotal > sum) {
          break
        } else if (tmpTotal === sum) {
          count++
          break
        }
      }
    }
  }

  console.log(count)
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7500
n, m = map(int, input().split())
memo = []
ans = 0
for i in range(m):
    a = list(map(int, input().split()))
    b = [0]*n
    for j in range(a[0]):
        b[a[j+1]-1] = 1
    memo.append(b)
clear = list(map(int, input().split()))
for i in range(2 ** n):
    now = []
    for j in range(n):
        now.append((i // (2 ** j)) % 2)
    for j in range(m):
        t = 0
        for k in range(n):
            t += memo[j][k] * now[k]
        if t % 2 != clear[j]:
            break
    else:
        ans += 1
print(ans)


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

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using ld = long double;

template <typename T>
int sz(T &x) {
  return (int)(x.size());
}


const int mod = 998244353;
const int inf = 1'000'000'007;


int power(int x, int y) {
  if (y == 0) {
    return 1;
  }
  int z = power(x, y >> 1);
  z = z * 1ll * z % mod;
  if (y & 1) {
    z = z * 1ll * x % mod;
  }
  return z;
}

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

  ll each = n * (n + 1ll) / 2;
  ll sum = accumulate(a.begin(), a.end(), 0ll);
  if (sum % each) {
    cout << "NO\n";
    return;
  }

  ll cnt = sum / each;

  for (int i = 0; i < n; ++i) {
    ll diff = cnt - (a[(i + 1) % n] - a[i]);
    if (diff < 0 || diff % n != 0) {
      cout << "NO\n";
      return;
    }
  }

  cout << "YES\n";
}

int main() {
  #ifndef LOCAL58
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);
  #endif

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

  return 0;
}


Measured memory_bytes: 3704
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		long a=sc.nextLong(),b=sc.nextLong(),x=sc.nextLong(),c=0;
		c=b/x-a/x;
		if(a%x==0){
			c++;
		}
		System.out.println(c);
	}
}

Measured memory_bytes: 23764
let n=read_int()open Array;;let a=init n(fun _->Scanf.scanf"%d "(fun e->e))and b=make n 0and c=make 10001 0;;iter(fun e->c.(e)<-c.(e)+1)a;iteri(fun i _->if i<>0then c.(i)<-c.(i)+c.(i-1))c;for i=n-1downto 0do b.(c.(a.(i))-1)<-a.(i);c.(a.(i))<-c.(a.(i))-1;done;print_int b.(0);for i=1to n-1do print_string" ";print_int b.(i);done;print_newline()

Measured memory_bytes: 36192
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define vt vector
#define pb push_back
#define pob pop_back
#define vi vt<int>
#define vvi vt<vi>
#define vii vt<ii>
#define vvii vt<vii>
typedef long long ll;
#define For(i,a,b) for(int i = a; i < b; i++)
#define foR(i,a,b) for(int i = a; i <= b; i++)
#define roF(i,a,b) for(int i = a - 1; i >= b; i--)
#define Rof(i,a,b) for(int i = a; i >= b; i--)
signed main (){
	/*
	freopen(".inp","r",stdin);
	freopen(".out","w",stdout);
	*/
	int d = 1000000000;
	int s;
	cin >> s;
	int b = s/d;
	if(s%d == 0){
		cout << "0 0 1000000000 0 0 " << b;
	}else{
		b++;
		cout << "0 1 1000000000 0 " << s%d << " " << b;
	}
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <set>
#include <map>
using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
int main() {
    int N,K,Q;
    cin >> N>>K>>Q;
    map<int, int>mp;
    rep(i, 1, N+1){
        mp[i] += K;
    }
    rep(i, 0, Q){
        int num;
        cin >> num;
        mp[num]++;
    }
    rep(i, 1, N+1){
        mp[i] -= Q;
    }
    
    for (auto& s : mp){
        if(s.second <1) {
            cout << "No" << endl;
        } else {
            cout << "Yes" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 5376
#include<stdio.h>
#include<iostream>
using namespace std;

char a,b;
int main (){
    cin >> a >> b;
    if(a == 'H' && b == 'H' || a == 'D' && b == 'D') cout << 'H' << endl;
    else cout << 'D' << endl;
    return 0;
}


Measured memory_bytes: 256
from heapq import*
(N,M),*t=[map(int,s.split())for s in open(0)]
q=[0]*10**5
v=[[]for _ in q]
z=0
for a,b in t:v[a-1]+=[b]
for i in v[:M]:
	for j in i:heappush(q,-j)
	z-=heappop(q)
print(z)

Measured memory_bytes: 58468
#include<cstdio>
#define N 55
#define mod 1000000007
#define int long long
int n;
struct mat{
	int x[N][N];
	mat operator*(const mat&a){
		mat t;
		for(int i=0;i<n;++i)for(int j=0;j<n;++j){
			t.x[i][j]=0;
			for(int k=0;k<n;++k)t.x[i][j]=(t.x[i][j]+x[i][k]*a.x[k][j]%mod)%mod;
		}
		return t;
	}
};
mat qp(mat x,int k){
	mat ans;
	for(int i=0;i<n;++i)for(int j=0;j<n;++j)ans.x[i][j]=i==j;
	for(;k;k>>=1,x=x*x)if(k&1)ans=ans*x;
	return ans;
}
mat x;
int k;
signed main(){
	scanf("%lld%lld",&n,&k);
	for(int i=0;i<n;++i)for(int j=0;j<n;++j)scanf("%lld",&x.x[i][j]);
	x=qp(x,k);
	int ans=0;
	for(int i=0;i<n;++i)for(int j=0;j<n;++j)ans=(ans+x.x[i][j])%mod;
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <utility>
#include <typeinfo>
using namespace std;

#define MOD 1000000007
#define INF 1e9+7
#define INF_LONG 1e18
#define rep(i, n) for(int i=0; i<n; ++i)
#define rrep(i, m, n) for(int i=m; i<n; ++i)
typedef long long ll;

#define MAX_N 200000
#define MAX_M 100000
#define MAX_V 100
#define MAX_E 100
#define MAX_Q 100000

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

int ddx[] = {-1, 0, 1, 0, -1, 1, -1, 1};
int ddy[] = {0, -1, 0, 1, 1, 1, -1, -1};

ll gcd(ll x, ll y) {
  if(y==0) return x;
  else return gcd(y, x%y);
}

ll lcm(ll x, ll y) {
  return (x*y)/gcd(x, y);
}

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

int main() {

  ll n, max = -1, cnt;
  cin >> n;
  string s[n];
  rep(i, n) cin >> s[i];

  sort(s, s+n);
  //最大値の探索
  string str = s[0];
  cnt = 1;
  for(int i=1; i<n; ++i) {
    if(str==s[i]) {
      ++cnt;
    }else {
      if(max<cnt) max = cnt;
      cnt = 1;
      str = s[i];
    }
  }

  if(max<cnt) max = cnt;

  str = s[0];
  cnt = 1;
  for(int i=1; i<n; ++i) {
    if(str==s[i]) {
      ++cnt;
    }else {
      if(max==cnt) cout << str << endl;
      cnt = 1;
      str = s[i];
    }
  }

  if(max==cnt) cout << str << endl;

  return 0;
}


Measured memory_bytes: 14336
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

//AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC
int main(){
    string s;cin>>s;
    int p=0,g=0;
    for(char c:s){
        if(c=='p')p++;
        else g++;
    }
    cout<<(g-p)/2<<endl;
}


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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;

constexpr int MOD = 1000000007;

#define ODD 1
#define EVEN 2
#define BOTH 3

int check_ok(const vi& a) {
    bool odd = false, even = false;
    for (int ai : a) {
        if (ai % 2 == 0) {
            even = true;
        } else {
            odd = true;
        }
        if (odd && even) { return BOTH; }
    }
    return odd ? ODD : EVEN;
}

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }

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

ll lcm(const vi& a, ll m) {
    ll l = a[0];
    rep(i, 1, a.size()) {
        l = lcm(l, a[i]);
        if (l > m) { return 0; }
    }
    return l;
}

int calc(const vi& a, ll m) {
    ll l = 1;
    l = lcm(a, m);
    return l != 0 ? (m / l + 1) / 2 : 0;
}

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

    int n, m;
    cin >> n >> m;

    vi a(n);
    rep(i, 0, n) {
        int tmp;
        cin >> tmp;
        a[i] = tmp / 2;
    }

    while (check_ok(a) == EVEN) {
        rep(i, 0, n) { a[i] /= 2; }
        m /= 2;
    }

    if (check_ok(a) == BOTH) {
        cout << 0 << endl;
        return 0;
    }

    cout << calc(a, m) << endl;
    return 0;
}

Measured memory_bytes: 640
class UnionFind:
    def __init__(self, n):
        self.parent = [-1] * n

    def root(self, x):
        """頂点xの根を求める"""
        if self.parent[x] < 0:
            return x
        else:
            self.parent[x] = self.root(self.parent[x])
            return self.parent[x]

    def merge(self, x, y):
        """頂点xを含む集合と頂点y含む集合を結合する"""
        x = self.root(x)
        y = self.root(y)
        if x != y:
            if self.parent[x] > self.parent[y]:
                x, y = y, x
            self.parent[x] += self.parent[y]
            self.parent[y] = x
        return

    def is_same(self, x, y):
        """頂点xと頂点yが同じ集合に属するかどうかを返す"""
        return self.root(x) == self.root(y)

    def get_size(self, x):
        '''頂点xを含む集合の要素数を返す'''
        return -self.parent[self.root(x)]


n, m = map(int, input().split())
info = [list(map(int, input().split())) for i in range(n)]

li = [[] for i in range(m)]
for i in range(n):
    for num in info[i][1:]:
        li[num - 1].append(i)

uf = UnionFind(n)
for li_ in li:
    for i in range(len(li_) - 1):
        if not uf.is_same(li_[i], li_[i + 1]):
            uf.merge(li_[i], li_[i + 1])

if uf.get_size(0) == n:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 38304
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1, (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

int main(){
    vector<int> group = {0,2,0,1,0,1,0,0,1,0,1,0};
    int x, y;
    cin >> x >> y;
    if(group[x-1] == group[y-1]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define int long long 
#define F first
#define S second
 
const int N = 2e5+10;
const int LN = 60;
 
vector< vector<int> > sparse(2,vector<int> (N) );
 
signed main()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
       
  int n,q,s,k;
  cin >> n;
  cin >> k;
    
  q = 1;  
    
  int a[n+1];
  pair<int,int> que[q];
    
  for(int i=1;i<=n;i++) cin >> a[i];
    
  for(int i=0;i<q;i++)
  {
      que[i].F = i+1;
      que[i].S = k;  
  }
    
  for(int i=1;i<=n;i++)  sparse[0][i] = a[i]; 
   
  for(int i=1;i<=LN;i++)
  {
      for(int j=0;j<q;j++)
          if((1LL<<(i-1)) & que[j].S) que[j].F = sparse[(i-1)&1][que[j].F];
          
      for(int j=1;j<=n;j++)    
          sparse[i&1][j] = sparse[(i-1)&1][sparse[(i-1)&1][j]];  
  }
    
  for(int i=0;i<q;i++) cout << que[i].F << "\n";  
}

Measured memory_bytes: 8036
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <string>
#include <limits>
#include <algorithm>
#include <map>
#include <sstream>
#include <unordered_map>
#include <set>

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
static ull tenq = 1000000000;
static ull mod = tenq + 7;

using namespace std;

template<typename T>
T gcd(T a, T b) {
  if (a > b) {
    T tmp = b;
    b = a;
    a = tmp;
  }
  while (a > 0){
    T tmp = b % a;
    b = a;
    a = tmp;
  }
  return b;
}

template<typename T>
T lcm(T a, T b) {
  return a / gcd<T>(a, b) * b;
}


int main()
{
  ll N;
  cin >> N;
  vector<ll> as(N);
  for (auto i = 0; i < N; i++) cin >> as[i];
  ll res = as[0];
  for(auto i = 1; i < N; i++) {
    res = gcd(res, as[i]);
  }

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
long long dp[52][52];
long long calc(int a,int b){
	if(~dp[a][b])return dp[a][b];
	if(a==0||b==0){
		return dp[a][b]=0;
	}
	if(a==1){
		return dp[a][b]=b;
	}
	return dp[a][b]=min(inf,calc(a-1,b-1)+calc(a,b-1)+1);
}
int main(){
	int T;scanf("%d",&T);
	for(int i=0;i<52;i++)for(int j=0;j<52;j++)dp[i][j]=-1;
	for(int i=0;i<52;i++){
		for(int j=0;j<52;j++){
			calc(i,j);
		}
	}
	while(T--){
		long long a;
		int b;
		scanf("%lld%d",&a,&b);
		for(int i=0;i<52;i++){
			if(dp[b][i]>=a){
				printf("%d\n",i);break;
			}
		}
	}
}

Measured memory_bytes: 2760
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

template <typename T>
struct SegTree {
  ll n, ofst;
  vector<T> arr;

  SegTree(const ll _n) {
    n = 1;
    while (n < 2 * _n) n <<= 1;
    arr.resize(n, 0);
    ofst = n >> 1;
  }

  void update(ll i, T x) {
    i += ofst;
    arr[i] = x;
    while (true) {
      i /= 2;
      if (i == 0) break;
      arr[i] = min(arr[2 * i], arr[2 * i + 1]);
    }
  }

  T get(ll l, ll r) {
    T ret = INF;
    l += ofst, r += ofst + 1;
    while (l < r) {
      if (l % 2 == 1) {
        chmin(ret, arr[l]);
        l++;
      }
      l /= 2;
      if (r % 2 == 1) {
        chmin(ret, arr[r - 1]);
        r--;
      }
      r /= 2;
    }
    return ret;
  }
};


int main() {
  // ios_base::sync_with_stdio(0), c
  cout << fixed << setprecision(15);

  ll n, x;
  cin >> n >> x;

  SegTree<ll> st(2*n);
  
  rep(i, n){
    ll a;
    cin >> a;
    st.update(i, a);
    st.update(i + n, a);
  }

  ll ans = INF;
  rep(i, n){
    ll tmp = i * x;
    rep(j, n){
      tmp += st.get(j + n - i, j + n);
    }
    chmin(ans, tmp);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3680
#include<iostream>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

class question {
public:
	string S;
	void ans() {
		cin >> S;
		char dir[4] = { 'N','W','S','E' };
		int num[4] = { 0 };
		REP(i, S.size()) {
			REP(j, 4) {
				if (S[i] == dir[j]) num[j]++;
			}
		}
		string res = "Yes";
		if ((num[0] && !num[2]) || (!num[0] && num[2]) || (num[1] && !num[3]) || (!num[1] && num[3])) {
			res = "No";
		}
		cout << res << "\n";
	}

};

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	question q;
	q.ans();
	
	return 0;
}


Measured memory_bytes: 256