akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <algorithm>
#include <string>
using namespace std;
int main(){
	int N; 
	cin >> N; 
        int w; 
        cin >> w; 
	int V[110] = {}; 
	int W[110] = {}; 
	for(int i = 1; i <= N; i++){
		cin >> V[i] >> W[i];   
	}
	int dp[110][10010] = {}; 
	for(int i = 1; i <= N; i++){
		for(int j = 0; j <= w; j++){
			if(j >= W[i]) {dp[i][j] = max(dp[i-1][j], dp[i-1][j-W[i]] + V[i]) ;}
			else{dp[i][j] = dp[i-1][j];} 
		}
	}
	cout << dp[N][w] << endl; 
}


Measured memory_bytes: 7424
#include<iostream>
#include<string>
using namespace std;
int a[100];
int main(){
	int n;
	while(true){
	cin>>n;
	if(n==0)
		break;
	for(int i=0;i<n;i++)
		cin>>a[i];
	int ans=0;
	for(int i=0;i<n-1;i++){
		for(int j=n-1;j>i;j--){
			if(a[j]<a[j-1]){
				int tmp=a[j];
				a[j]=a[j-1];
				a[j-1]=tmp;
				ans++;
			}
		}
	}
	cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <iomanip>
using namespace std;
#define all(x) x.begin(), x.end()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }

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

	int a, b;
	cin >> a >> b;
	int k = (a + b) / 2;
	if(abs(a - k) - abs(b - k) != 0) cout << "IMPOSSIBLE";
	else cout << k;
}

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

int main (void) {
    int n;
    int i, j;
    scanf("%d", &n);
    int d[n];
    for ( i=0; i<n; i++ )
        scanf("%d", &d[i]);

    long long ans=0;
    for ( i=0; i<n; i++ ) {
        for ( j=i+1; j<n; j++ )
            ans += d[i]*d[j];
    }

    printf("%lld\n", ans);
    return EXIT_SUCCESS;
}


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

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

from sys import stdin
nii=lambda:list(map(int,stdin.readline().split()))

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

uf=UnionFind(n)

ans=[]
num=n*(n-1)//2
for a,b in l:
  a-=1
  b-=1
  ans.append(num)
  if uf.same(a,b)==False:
    num-=uf.size(a)*uf.size(b)
    uf.union(a,b)

for i in reversed(ans):
  print(i)

Measured memory_bytes: 34820
// sutaz.cpp : Defines the entry point for the console application.
//

//#include "stdafx.h"
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
bool cmp(int i, int j)
{
	return i < j;
}
int main()
{
	int n;
	cin >> n;
	int *pole = new int[n];
	for (int i = 0; i < n; i++)
	{
		cin >> pole[i];
	}
	int moznosti = 0;
	sort(pole, pole + n, cmp);
	for (int i = 0; i < n; i++)
	{
		for (int j = i+1; j < n; j++)
		{
			for (int k = j + 1; k < n; k++)
			{
				if ((pole[i] + pole[j]) > pole[k]&&pole[i]!=pole[j]&&pole[j]!=pole[k])
				{
					moznosti++;
					//cout << pole[i] << ' ' << pole[j] << ' ' << pole[k] << endl;
				}
			}
		}
	}
	cout << moznosti << endl;

	return 0;
}



Measured memory_bytes: 3632
N = int(input())
A = [int(i) for i in input().split()]

if min(A) >= 0:
    print(N-1)
    for i in range(N-1):
        print(i+1, i+2)
elif max(A) < 0:
    print(N-1)
    for i in range(N-1):
        print(N-i, N-1-i)
else:
    if max(A) >= abs(min(A)):
        print(2*N-1)
        for i in range(N):
            print(A.index(max(A))+1, i+1)
        for i in range(N-1):
            print(i+1, i+2)
    else:
        print(2*N-1)
        for i in range(N):
            print(A.index(min(A))+1, i+1)
        for i in range(N-1):
            print(N-i, N-1-i)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ordered_set tree<long long, null_type,less<long long>, rb_tree_tag,tree_order_statistics_node_update>
//s.find_by_order(index) returns iterator to the index-th element
//in O(logn) time.



typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vii;
typedef vector<string> vss;
typedef vector<pair<ll, ll> > vpll;
typedef unordered_map<ll ,ll> mpll;
typedef unordered_map<int ,int> mpii;
typedef unordered_map<char ,ll> mpcl;
typedef pair<ll , ll> pll;
typedef complex<double> cd;
typedef vector< complex<double> > vcd;


#define fore(i,n) for(i=0;i<n;i++)
#define forz(i,s,f) for(i=s;i<f;i++)
#define forer(i,n) for(i=n-1;i>=0;i--)
#define forzr(i,s,f) for(i=s;i>=f;i--)
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ff first
#define ss second
#define pvec(i,vec) fore(i,vec.size())cout<<vec[i]<<" ";cout<<"\n";

const ll mod=1e9+7;
const ll modulo=998244353;
const double pi = 3.14159265358979323846;


ll power(ll x,ll y,ll m)//gives (x^y)%m
{
    ll ans=1;
    while (y>0)
    {
        if(y & 1)
        {
            ans=(ans*x)%m;
        }
        y=y/2;
        x=(x*x)%m;
    }
    return ans;
}

bool sortbysec(pll &a,pll &b)
{
    return(a.ss<b.ss);
}

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

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

long double logn(long double a,long double n)
{
	return(log(n)/log(a));
}

int main(int argc, char const *argv[])
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);
    
	ll te=1,test,i,j,n,m,flag,k,p,temp;
	//cin>>te;
	for(test=1;test<=te;test++)
	{
		cin>>n;

		vll a(n);
		fore(i,n)
		{
			cin>>a[i];
		}
		sort(a.begin(), a.end());
		
		ll ans=0;
		j=n-2;flag=0;
		fore(i,n-1)
		{
			if(i==0)
			{
				ans+=a[n-1];
			}
			else
			{
				ans+=a[j];
				flag++;
				if(flag==2)
				{
					j--;
					flag=0;
				}
			}
		}

		cout<<ans<<"\n";
		//cout<<"hello\n";
		//cout<<"Case #"<<test<<": ";
	}

	return 0;
}

Measured memory_bytes: 4800
#include <bits/stdc++.h>
#define int long long 
#define uint unsigned long long 
#define double long double 
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define sett(c) (c).resize(unique(all(c))-(c).begin())
#define sz(a) (int)(a).size()
#define hell 1000000007
#define pi pair<int,int>
#define vi vector<int> 
#define vb vector<bool> 
#define vpi vector<pair<int,int>> 
#define x first 
#define y second 
#define endl '\n'
#define forn(i,n) for(int i = 0 ; i < n ; i++ )
#define for1(i,n) for(int i = 1 ; i < n ; i++ )
#define fore(i,a,b) for(int i = a ; (a>b)?(i>=b):(i<=b) ; (a>b)?(i--):(i++) ) 
 
using namespace std;
const int MAX = 1e6;

long long binpow(long long a, long long b) {

    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a ;
        a = a * a ;
        b >>= 1;
    }
    return res;
}

bool comp(const pi& a , const pi& b ){
        return a.y < b.y;
}

void solve(){
        int n ; cin >> n ; 
        int arr[n] ; 
        priority_queue<int>q;
        forn(i,n){
                cin >> arr[i];
                q.push(arr[i]);
        }
        forn(i,n){
                if(arr[i] == q.top()){
                        q.pop();
                        cout << q.top() << endl;
                        q.push(arr[i]);
                }else{
                        cout << q.top() << endl;
                }
        }       
}       

 
int32_t main(){
        
        ios_base::sync_with_stdio(false);
        cin.tie(nullptr);
        cout.tie(nullptr);
        cout << fixed;
        cout.precision(10);
 
#ifdef LOCAL_DEFINE
        freopen("input.txt","rt",stdin);
        freopen("output.txt","w",stdout);
#endif
 
        int t = 1;
        //cin >> t ;
        while(t--){
                solve();
        }
#ifdef LOCAL_DEFINE
        cout << "Time elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms.\n";
#endif
 
        return 0;
}


Measured memory_bytes: 4848
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let x: i32 = sc.read();
    let y: i32 = sc.read();

    if x % 2 == 0 || y % 2 == 0 {
        println!{"No"};
        return
    }

    println!("Yes");
}


Measured memory_bytes: 4352
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	
	public static void main(String[] args) throws Exception {
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String input = br.readLine();
		int count = 0;
		for(int i=0; i<input.length(); i++) {
			if(input.charAt(i) == '1') count++;
		}
		System.out.println(count);
		
		
	}

}


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

int main() {
	// your code goes here
	int n,k,t;
	cin >> n >> k;
	for(int i = 0 ; i < n ; i++)
	  cin >> t;
	n--,k--;
    int quo = n/k,rem = n%k,ans = quo+(rem != 0);
    cout << ans;
	return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define mod 1000000007LL
#define IN freopen("C.in","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define MEM(ara,val) memset(ara,val,sizeof(ara))
#define INF 1000000000
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 2

using namespace __gnu_pbds;
using namespace std ;

typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<i64, i64> pii;

#define maxn 200000

i64 cum1[maxn+5] , cum2[maxn+5], a[maxn+5] , mn1[maxn+5] , mn2[maxn+5] ;

int main()
{
    int i , j , k , l , m , n ;

    scanf("%d",&n) ;

    for(i=1 ; i<=n ; i++) scanf("%lld",&a[i]) ;

    for(i=1 ; i<=n ; i++) cum1[i] = cum1[i-1] + a[i] ;

    for(i=n ; i>=1 ; i--) cum2[i] = cum2[i+1] + a[i] ;

    j = 1 ;

    for(i=2 ; i<=n ; i++)
    {
        while( 2*cum1[j] < cum1[i] ) j++ ;
        mn1[i] = min( cum1[j]-(cum1[i]-cum1[j]) , (cum1[i]-cum1[j-1])-cum1[j-1] ) ;
    }

    j = n ;

    for(i=n-1 ; i>=1 ; i--)
    {
        while( 2*cum2[j] < cum2[i] ) j-- ;
        mn2[i] = min( cum2[j] - (cum2[i]-cum2[j]) , (cum2[i]-cum2[j+1])-cum2[j+1] ) ;
    }

    i64 ans = 1000000000000000000LL ;

    for(i=2 ; i<=n-2 ; i++)
    {
        i64 sm1 = (cum1[i]-mn1[i])/2 , sm2 = (cum2[i+1]-mn2[i+1])/2 ;
        i64 lg1 = sm1+mn1[i] , lg2 = sm2+mn2[i+1] ;
  //      printf("i:%d sm1:%lld lg1:%lld sm2:%lld lg2:%lld\n",i,sm1,lg1,sm2,lg2) ;
        ans = min( ans ,  (max(lg1,lg2)-min(sm1,sm2))  ) ;
    }

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

    return 0 ;
}


Measured memory_bytes: 8064
import sys
sys.setrecursionlimit(300000)

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI0(): return map(lambda s: int(s) - 1, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
def LMI0(): return list(map(lambda s: int(s) - 1, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


A, V = MI()
B, W = MI()
T = I()


d = max(0, V - W)
if abs(A - B) - d * T <= 0:
    print('YES')
else:
    print('NO')

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

int main()
{
    ll K, N;
    cin >> K >> N;
    ll prev = 0;
    ll now = 0;
    ll maxdist = -1;
    ll first = 0;
    for (int i = 0; i < N; ++i)
    {
        if (i == 0)
        {
            cin >> prev;
            first = prev;
            continue;
        }
        cin >> now;
        maxdist = max(maxdist, now - prev);

        prev = now;
    }

    maxdist = max(maxdist, K - now + first);
    cout << K - maxdist << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define pi 3.141592653589793

ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    ll r=a%b;
    while(r!=0){
        a=b;
        b=r;
        r=a%b;
    }
    return b;
}

int main (){
    ll x,y;
    cin >> x >>y;
    if(y>x){
        if(x>=0||y<=0) cout << y-x << endl;
        else cout << min(y-x,abs(y+x)+1) <<endl;
    }
    else {
        if(x==0) cout << -y+1 <<endl;
        else if(y==0) cout << x+1 <<endl;
        else if(x<0||y>0) cout << x-y+2 <<endl;
        else cout << abs(-x-y)+1 <<endl;
        }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
using namespace std;
int main()
{
  int N;
  cin >> N;
  string W[N];
  for (int i = 0; i < N; i++)
    cin >> W[i];
  set<string> st;
  st.insert(W[0]);
  char last = W[0].at(W[0].length() - 1);
  string ans = "Yes";
  for (int i = 1; i < N; i++)
  {
    if (st.find(W[i]) != st.end())
      ans = "No";
    if (last != W[i].at(0))
      ans = "No";
    st.insert(W[i]);
    last = W[i].at(W[i].length() - 1);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<bitset>
#include<map>
//BitCount
int F(int x)
{
	int r=0;
	for(; x; x&=x-1)
		++r;
	return r;
}
std::bitset<1<<20>f;
int dp[1<<20];
int main()
{
	int n,u,k,r,i,j,x,y,z;
	while(scanf("%d%d",&n,&u),n)
	{
		f.reset();
		std::pair<int,int>a[20];
		for(i=0;i<n;++i)
		{
			scanf("%d%d",&a[i].first,&k);
			if(k)
			{
				while(k--)
				{
					scanf("%d",&r);
					a[i].second|=(1<<r);
				}
			}
			else f[1<<i]=1,dp[1<<i]=a[i].first;
		}
		for(i=1;i<=n;++i)
		{
			z=(1<<i)-1;
			while(z<(1<<n))
			{
				if(f[z])
				{
					if(dp[z]>=u){printf("%d\n",F(z));goto E;}
					for(j=0;j<n;++j)
						if(!(z&(1<<j)) && (z&a[j].second)==a[j].second)
						{
							f[z|(1<<j)]=1;
							dp[z|(1<<j)]=dp[z]+a[j].first;
						}
				}
				x=z&-z;
				y=z+x;
				z=((z&~y)/x/2)|y;
			}
		}
		E:;
	}
}

Measured memory_bytes: 0
function main(arg) {
    var N = parseInt( arg.split(/\n/)[0] );
    var p = arg.split(/\n/)[1].split(/\s/);
    var jk = [];
    //雛形の用意
    var ideal = p.slice();
    ideal.sort(sortfunc);
    //比較
    for(i=0;i<N;i++){
        if(p[i]!==ideal[i]){
            jk.push(i);
        }
    }
    if(jk.length = 2 && p[jk[0]]==ideal[jk[1]] && p[jk[1]]==ideal[jk[0]]){
        console.log("YES");
    }else{
        console.log("NO");
    }
}

function sortfunc(a,b){
    return parseInt(a)-parseInt(b);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7500
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  double a, v, b, w, t;
  cin >> a >> v >> b >> w >> t;
  double time = abs(a - b) / (v - w);
  if (0 <= time && time <= t) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 3720
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
#include <climits>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define no {cout << "Impossible"; return;}
#define mkp make_pair
#define mkt make_tuple
#define cerr if(0) cerr

map <int, int> calc;

void solve() {
    int n, sum = 0; 
    cin >> n;
    loop(i, n) {
        int x; cin >> x;
        ++calc[x];
        sum += x;
    }
    int q; cin >> q;
    loop(i, q) {
        int a, b;
        cin >> a >> b;
        sum += calc[a] * (b - a);
        calc[b] += calc[a];
        calc[a] = 0;
        cout << sum << "\n";
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //int t; cin >> t; loop(i, t)
    solve();
    return 0;
}

Measured memory_bytes: 9568
(n,m),*d = [list(map(int, s.split())) for s in open(0)]

d.sort()
l = [0] * n
for i in range(m):
    d[i] = [d[i][0]-1, d[i][1]-1]
    l[d[i][0]] += 1

p = [0] * n
p[0] = 1
for x in d:
    p[x[1]] += p[x[0]]/l[x[0]]

e = [0] * n
index = d[-1][0]
max_in_index = 0
max_reduce_e = 0

for x in d[::-1] + [[-1, -1]]:
    if index != x[0]:
        if l[index] > 1:
            max_reduce_e = max(max_reduce_e, 
                               p[index] * (e[index]/l[index] - (e[index] - max_in_index)/(l[index] - 1)))
        e[index] /= l[index]
        index = x[0]
        max_in_index = 0
    max_in_index = max(max_in_index, e[x[1]] + 1)
    e[x[0]] += e[x[1]] + 1

print(e[0] - max_reduce_e)

Measured memory_bytes: 92252
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long 
#define reus ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int main()
{
	reus;
	string s;
	cin>>s;
	if(s[1]=='B')
	cout<<"ARC"<<endl;
	else if(s[1]=='R')
	cout<<"ABC"<<endl;
	return 0;
}

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

int cmp( const void *p, const void *q ) {
    return *(int*)q - *(int*)p;
}

int main(void) {
    int n;
    scanf("%d", &n);
    int a[n], b[n];
    for(int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        b[i] = a[i];
    }
    qsort(b, sizeof(b)/sizeof(int), sizeof(int), cmp);
    
    for(int i = 0; i < n; i++) {
        if(a[i] != b[0]) {
            printf("%d\n", b[0]);
        } else {
            printf("%d\n", b[1]);
        }
    }
    return 0;
}


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

int main(void) {
  int N;
  string S;
  cin >> N >> S;
  replace(S.begin(), S.end(), 'R', '1');
  replace(S.begin(), S.end(), 'G', '2');
  replace(S.begin(), S.end(), 'B', '4');
  vector<long long> rgb(3, 0);
  for (int i = 0; i < N; i++) {
    int s = S[i] - '0';
    for (int j = 0; j < 3; j++) {
      if (s & (1 << j)) {
        rgb[j]++;
        break;
      }
    }
  }
  long long eq = 0;
  for (int i = 0; i < N - 2; i++) {
    for (int j = i + 1; j < N - 1; j++) {
      int k = j + (j - i);
      if (k >= N) continue;
      eq += !((S[i] - '0') ^ (S[j] - '0') ^ (S[k] - '0') ^ 7) ? 1 : 0;
    }
  }
  cout << rgb[0] * rgb[1] * rgb[2] - eq << endl;
  return 0;
}

Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
 
#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
 
template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod を計算する
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}
int main(){

	COMinit();

	lli n,k;
	cin>>n>>k;

	lli ans = COM(2*n-1,n-1);

	if(k>=n-1){
		cout<<ans<<endl;
		return 0;
	}

	LOG(ans);
	ans = 0;
	for(lli i=1;i<=k;i++){
		//どこから選ぶ?
		lli num = COM(n,i);

		LOG(num);
		num *= COM(n-1,i);

		ans += num;
		ans %= MOD;
		LOG(ans);
	}
	ans++;
	ans%=MOD;
	cout<<ans<<endl;




    return 0;
}

Measured memory_bytes: 12160
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rrep(i, n, g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define len(x) (int)(x).size()
#define dup(x, y) (((x) + (y)-1) / (y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int a;
  cin >> a;
  if (a % 2 == 0)
    cout << a << endl;
  else
    cout << a * 2 << endl;
}

Measured memory_bytes: 3600
import operator

n, m = map(int, input().split())
bridges = [0]
ms1 = (tuple(map(int, input().split())) for i in range(m))
ms2 = sorted(ms1, key=operator.itemgetter(1))

for i in range(m):
    if ms2[i][0] <= bridges[-1]:
        pass
    else:
        bridges.append(ms2[i][1] - 1)

if __name__ == "__main__":
    print(len(bridges)-1)    # 0 の分を除く


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

int main(void){
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	vector<ll> b(n+1, 0);
	for(int i = 0; i < n; ++i){
		cin >> a[i];
		b[i+1] = b[i] + a[i];
	}
	vector<ll> c;
	for(int i = 0; i < n; ++i){
		for(int j = i; j < n; ++j){
			c.push_back(b[j+1]-b[i]);
		}
	}
	sort(c.rbegin(), c.rend());
	for(int i = 63; i >= 0; i--){
		vector<ll> d;
		for(auto x : c){
			if((x>>i)&1){
				d.push_back(x);
			}
		}
		if(d.size() >= k){
			c = d;
		}
	}
	ll ans = c[0];
	for(int i = 0; i < k; ++i){
		ans &= c[i];
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
    string s;
    cin >> s;
    cout << s[0] << (s.length() - 2) << s[s.length() - 1] << endl;
    return 0;
}

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

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

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vector<int> w(n);
  rep (i, n) cin >> w[i];
  int minS12 = INT_MAX;
  for (int i = 1; i < n; ++i) {
    int s1 = 0;
    int s2 = 0;
    rep(j, n) {
      if (j < i) {
        s1 += w[j];
      } else {
        s2 += w[j];
      }
    }
    minS12 = min(abs(s1 - s2), minS12);
  }

  cout << minS12 << endl;

  return 0;
}


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int x = A + B - C - D;
  if (x > 0)cout << "Left" << endl;
  else if (x < 0)cout << "Right" << endl;
  else cout << "Balanced" << endl;
}

Measured memory_bytes: 256
info_num = int(input())
building = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]

for i in range(info_num):
    lst = list(map(int, input().split()))
    b, f, r, v =lst[0], lst[1], lst[2], lst[3]
    building[b-1][f-1][r-1] = building[b-1][f-1][r-1] + v


count = 0
for floor in building:
    for room in floor:
        for volume in room:
            print(" " + str(volume), end = "")
        print()
    count = count +1
    if count <=3:
        print("#" *20)


Measured memory_bytes: 5624
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
 
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}
 
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn main(){
    let i1:i32  = read();
    let i2:i32 = read();
    let ans = (i2 * 2) - i1;
    println!("{}",ans);
}

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

void solve(long long N, long long K, std::vector<long long> h)
{
    long long dp[N + 1] = {0}; /* 1-indexed */

    dp[2] = abs(h[2] - h[1]);
    for (long long i = 3; i <= N; i++)
    {
        dp[i] = dp[i - 1] + abs(h[i] - h[i - 1]);
        for (long long j = 2; j <= min(i - 1, K); j++)
        {
            dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
        }
    }

    cout << dp[N] << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long N;
    scanf("%lld", &N);
    long long K;
    scanf("%lld", &K);
    std::vector<long long> h(N + 1);
    for (int i = 1; i <= N; i++)
    {
        scanf("%lld", &h[i]);
    }
    solve(N, K, std::move(h));
    return 0;
}


Measured memory_bytes: 1792
#include<cstdio>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
using namespace std;
#define MAXN 105
#define MO 1000000007
#define PII pair<int,int>
#define LL long long
int n,a[MAXN],ans[MAXN];
bool vis[MAXN];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=n,p;i;i--)
	{
		for(int j=1,k=1;j<=n;j++)
			if(!vis[j])
			{
				if(a[j]>k)
				{
					printf("-1\n");
					return 0;
				}
				if(a[j]==k) ans[i]=a[j],p=j;
				k++;
			}
		vis[p]=1;
	}
	for(int i=1;i<=n;i++) printf("%d\n",ans[i]);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S,class T>ostream&operator<<(ostream&os,map<S,T>d){bool a=1;for(auto v:d){os<<(a?"":" ")<<v;a=0;}return os;};
template<class S>ostream&operator<<(ostream&os,set<S>d){bool a=1;for(auto v:d){os<<(a?"":" ")<<v;a=0;}return os;};
template<class S>auto&operator<<(ostream&os,vector<S>d){bool a=1;for(auto v:d){os<<(a?"":" ")<<v;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;
    cin>>n>>k;
    ll ans=0;
    while(n){
        ans++;
        n/=k;
    }
    puta(ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define sez(a) a.size()
const int maxn=2e5+100;
const int MOD=1e9+7;
const ll INF=1e18;
const ld PI=3.141592653589793;
string z[101];
int cnt[26];
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s;
    int h,w;
    cin>>h>>w;
    for(int i=0; i<h; ++i){
        cin>>z[i];
    }
    for(int i=0; i<h; ++i)
        for (int j=0; j<w; ++j){
            cnt[z[i][j]-'a']++;
        }
    if (h>w)
        swap(h,w);
    if (h==1){
        if (w%2==0){
            for(int i=0; i<26; ++i){
                if (cnt[i]&1){
                    cout<<"No";
                    return 0;
                }
            }
            cout<<"Yes";
            return 0;
        }
        else{
            int odd=0;
            for(int i=0; i<26; ++i){
                if (cnt[i]&1){
                    odd++;
                }
            }
            if (odd>1){
                cout<<"No";
                return 0;
            }
            cout<<"Yes";
            return 0;
        }
    }
    else if (h%2==0){
        if (w%2==1){
            int two=0;
            for(int i=0; i<26; ++i){
                if (cnt[i]&1){
                    cout<<"No";
                    return 0;
                }
                if (cnt[i]%4!=0){
                    two++;
                }
            }
            if (two>h/2){
                cout<<"No";
                return 0;
            }
            cout<<"Yes";
            return 0;
        }
        else{
            for(int i=0; i<26; ++i){
                if (cnt[i]%4!=0){
                    cout<<"No";
                    return 0;
                }
            }
            cout<<"Yes";
            return 0;
        }
    }
    else{
        if (w%2==0){
            int two=0;
            for(int i=0; i<26; ++i){
                if (cnt[i]&1){
                    cout<<"No";
                    return 0;
                }
                if (cnt[i]%4!=0){
                    two++;
                }
            }
            if (two>w/2){
                cout<<"No";
                return 0;
            }
            cout<<"Yes";
            return 0;
        }
        else{
            int one=0;
            int two=0;
            for(int i=0; i<26; ++i){
                if (cnt[i]&1){
                    ++one;
                }
                else if (cnt[i]%4!=0){
                    two++;
                }
            }
            if (one>1){
                cout<<"No";
                return 0;
            }
            if (two>h/2+w/2){
                cout<<"No";
                return 0;
            }
            cout<<"Yes";
            return 0;
        }
    }
}


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

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

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

#define INF INT_MAX/3

int main() {
  cin.sync_with_stdio(false);
  int n;
  string s;
  cin >> n >> s;
  int e[n + 2] = {}, w[n + 2] = {};
  repl(i, 1, n + 1) e[i] = e[i - 1] + ((s[i - 1] == 'E') ? 1 : 0);
  repr(i, n + 1, 1) w[i] = w[i + 1] + ((s[i - 1] == 'W') ? 1 : 0);
  int ans = 0;
  repl(i, 1, n + 1) maxch(ans, e[i - 1] + w[i + 1]);
  cout << n - (ans + 1) << endl;
  return 0;
}


Measured memory_bytes: 2964
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define REVERSE(a) reverse(ALL(a))
#define MOD 1000000007
using namespace std;
typedef long long ll;
//vector<vector<int>> vec(i, vector<int>(j));

vector<int> input(int N) {
    vector<int> vec(N);
    for (int i = 0; i < N; i++) {
        cin >> vec.at(i);
    }
    return vec;
}

void Main() {
    int n,ans; cin >> n;
    vector<int> A = input(n);
    bool flag = true;
    ans = 0;
    while (flag) {
        for (int i = 0; i < n; i++)
        {
            if (A[i] % 2 != 0) {
                flag = false;
                break;
            }
        }
        if (flag) {
            for (int i = 0; i < n; i++)
            {
                A[i] /= 2;
            }
            ans++;
        }
    }
    cout << ans << endl;
}

int main() {
	Main();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define int long long
int n;
int a[100007],b[100007];
pair<int,int> sv[100007];
long long sum=0,sum2=0;
signed main(){
	ios_base::sync_with_stdio(0);
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i],sum2+=i,sum+=a[i];
	for(int i=1;i<n;i++){
		b[i]=a[i+1]-a[i];
	}
	b[n]=a[1]-a[n];
	if(sum%sum2!=0){
		cout<<"NO";
		return 0;
	}
	sum2=sum/sum2;
	for(int i=1;i<=n;i++){
		b[i]-=sum2;
		if(b[i]>0 || b[i]%n!=0){
			cout<<"NO";
			return 0;
		}
	}
	cout<<"YES";
}


Measured memory_bytes: 1920
n = int(input())
s = input()

ans = 0
for i in range(1, n - 1):
  count = 0
  a = s[:i]
  b = s[i:]
  c = set()
  for j in a:
    if b.count(j) >= 1 and not j in c:
      count += 1
      c.add(j)
  ans = max(ans, count)

print(ans)

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

const int MAX_N = int(1e5);
int N;
int dups[MAX_N + 3];

void init() {
	scanf("%d", &N);
	for (int _ = 0; _ < N; ++_) {
		int from, to;
		scanf("%d%d", &from, &to);
		++dups[from-1];
		--dups[to];
	}
}

int solve() {
	for (int i = 0; i < MAX_N + 2; ++i) {
		dups[i+1] += dups[i];
	}
	for (int i = N; i >= 0; --i) {
		if (dups[i] >= i) {
			return i;
		}
	}
	return 0;
}

int main() {
	init();
	printf("%d\n", solve());
	return 0;
}

Measured memory_bytes: 1412
import sys
from random import randint
from time import time
start = time()
sys.setrecursionlimit(1000000000)
input = sys.stdin.readline


def get_sat():
    sat = 0
    when = [-1] * 26
    for i in range(d):
        sat += s[i][t[i]]
        when[t[i]] = i
        for j in range(26):
            sat -= c[j] * (i - when[j])
    return sat


d = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(d)]
t = [randint(0, 25) for i in range(d)]
ans = get_sat()
told = t[:]
while time() - start < 1.7:
    p, q = randint(0, d - 1), randint(0, 25)
    t[p] = q
    if ans <= get_sat():
        told = t[:]
    else:
        t = told[:]
for i in t:
    print(i+1)


Measured memory_bytes: 87180
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>

using std::cin;using std::cout;using std::cerr;using std::endl;

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

int x;

int main(){

	std::ios::sync_with_stdio(0);
	cin.tie(0);

	cin>>x;

	if(x <= 599){
		cout<<8;
	}
	else if(x <= 799){
		cout<<7;
	}
	else if(x <= 999){
		cout<<6;
	}
	else if(x <= 1199){
		cout<<5;
	}
	else if(x <= 1399){
		cout<<4;
	}
	else if(x <= 1599){
		cout<<3;
	}
	else if(x <= 1799){
		cout<<2;
	}
	else if(x <= 1999){
		cout<<1;
	}

	return 0;
}

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

def main():

    a,b,n = map(int,input().split())

    if n < b:
        print((a*n)//b)
        exit()

    num = n//b

    ans = (a*(b-1))//b
    print(max(ans,(a*n)//b - a * (n//b)))

if __name__ == '__main__':
    main()


Measured memory_bytes: 8968
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] P = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            int cnt = 0;
            for(int i = 0; i <N; i++)
            {
                if (P[i] != i + 1)
                    cnt++;
            }
            if(cnt <= 2)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }
        }
    }
}

Measured memory_bytes: 13268
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<long long int>b(n), a(n);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	int lb = 0, ub = a.size() - 1;
	bool isfront = true;
	for (size_t i = a.size() - 1; i >= 0 && ub >= lb; i--)
	{
		if (isfront)
		{
			b[lb] = a[i];
			lb++;
		}
		else {
			b[ub] = a[i];
			ub--;
		}
		isfront = !isfront;
	}
	for(auto elem : b)
	{
		cout << elem << " ";
	}
	cout << endl;
}

Measured memory_bytes: 5248
//
//AtCoder Regular Contest 069
//C
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

using ll = long long;
using ld = long double;

const double PI = 3.14159265358979323846;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

int main()
{
    ll n, m;
    cin >> n >> m;

    ll ans=0;
    if (m-2*n < 0){
        ans += m/2;
    }else{
        ans += n;
        m -= n*2;
        ans += m/4;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3612
N, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(N)]
INF = 10 ** 9 + 5
V = 10 ** 5 + 5
dp = [[INF] * V for _ in range(N + 1)]
dp[0][0] = 0
for i in range(N):
    for j in range(V):
        w = wv[i][0]
        v = wv[i][1]
        dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])
        if j - v >= 0:
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - v] + w)

for i in range(V):
    if dp[N][i] <= W:
        MV = i    
print(MV)

Measured memory_bytes: 152964
/*BISMILLAH
THE WHITE WOLF
NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/

#include<bits/stdc++.h>
using namespace std;

#define io ios_base::sync_with_stdio(false)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vll vector<long long>
#define pb push_back
#define mod 100000007
#define pii pair<int, int>
#define PI 2*acos(0.0)

int main()
{
    io;
    int n, m;
    cin>>n >>m;
    vi adj[n+1];
    while(m--)
    {
        int x, y;
        cin>>x >>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    int ans[n+1], dis[n+1];
    memset(dis, -1, sizeof(dis));
    queue<int> q;
    q.push(1);
    dis[1] = 0;
    while(!q.empty())
    {
        int act = q.front();
        q.pop();
        for(auto x: adj[act])
        {
            if(dis[x] == -1)
            {
                dis[x] = dis[act] + 1;
                q.push(x);
                ans[x] = act;
            }
        }
    }
    for(int i = 1; i <= n; i++)
        if(dis[i] == -1)
            return cout <<"No\n", 0;
    cout<< "Yes\n";
    for(int i = 2; i <=n; i++)
        cout<< ans[i] <<"\n";
    return 0;
}


Measured memory_bytes: 10852
#include <iostream>

int main()
{
	int a, b, c;
	char s;
	for (;;) {
		std::cin >> a >> b >> c;
		if (a == -1 && b == -1 && c == -1) break;
		else if (a == -1 || b == -1) s = 'F';
		else if (a + b >= 80) s = 'A';
		else if (a + b >= 65) s = 'B';
		else if (a + b >= 50 || c >= 50) s = 'C';
		else if (a + b >= 30) s = 'D';
		else s = 'F';
		std::cout << s << '\n';
	}
}

Measured memory_bytes: 3076
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <list>
#include <cmath>
#include <stack>
#include <iomanip>

using namespace std;
typedef long long ll;
using Pll = pair<ll,ll>;

const ll INF = 1LL<<60;
const ll MOD = 1000000007;

//cout << fixed << setprecision(10);

vector<vector<ll>> Tree;
ll N,K;
queue<ll> que;
vector<ll> dist;
ll ans;
ll trank=0;

void bfs(){
    while(!que.empty()){
        ll tmp=que.front();
        que.pop();
        dist[tmp]=1;
        ll ct=0;
        trank++;
        for(ll e : Tree[tmp]){
            if(dist[e]!=-1)continue;
            else{
                que.push(e);
                ll minus=(trank<2)?trank:2;
                ans=(ans*(K-minus-ct))%MOD;
                ct++;
            }
        }
        
    }
}

int main() {
    cin >> N >> K;
    ans=K;
    Tree.assign(N,vector<ll>());
    dist.assign(N,-1);
    for(int i=0;i<N-1;i++){
        ll a,b;
        cin >> a >> b;
        a--;b--;
        Tree[a].push_back(b);
        Tree[b].push_back(a);
    }
    que.push(0);
    bfs();
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 8052
#include "bits/stdc++.h"
#define esc(ret) cout << (ret) << endl,quick_exit(0)
#define fcout(d) cout << fixed << setprecision(d)
#define repU(i,s,t) for(int i = (int)(s); i <= (int)(t); ++i)
#define repD(i,s,t) for(int i = (int)(s); i >= (int)(t); --i)
#define rep(i,n) repU(i,0,(n) - 1)
#define rep1(i,n) repU(i,1,(n))
#define all(v) begin(v),end(v)
#define vct vector
#define prique priority_queue
#define l_bnd lower_bound
#define u_bnd upper_bound
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define mkp make_pair
#define mkt make_tuple
#define fir first
#define sec second
#define qceil(n,d) ((n) > 0 ? ((n) - 1) / (d) + 1 : (n) / (d))
#define parity(a,b) ((a) & 1 == (b) & 1)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int,int> pii;
typedef pair<db,int> pdi;

const pii dir[] = { {1,0},{0,1},{-1,0},{0,-1},{1,1},{-1,1},{-1,-1},{1,-1} };
const int mod = 1e9 + 7;
const int inf32 = (1 << 30) - 1;
const ll inf64 = (1LL << 62) - 1;

int N,a;
prique<int> que;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	cin >> N;
	rep(i,N){
		cin >> a;
		que.push(a);
	}
	int l = que.top(),tmp,ans = 0;
	while(!que.empty()){
		int cnt = 0;
		while(!que.empty() && (tmp = que.top()) == l){
			++cnt;
			que.pop();
		}
		ans += cnt < l ? cnt : (cnt - l);
		l = tmp;
	}
	esc(ans);
}




Measured memory_bytes: 892
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<String>().len();
    for i in 0..n {
        print!("x");
    }
    println!("");
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
using ll = long long;
using VI = vector<int>;
int main(){
  int a,b,c,d;cin >> a >> b >> c >> d;
  const int lower = max(a,c);
  const int upper = min(b,d);

  cout << max(0,upper-lower) << endl;
  return 0;
}


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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

long long gcd(long long x, long long y){return x % y == 0 ? y : gcd(y, x%y);}
long long lcm(long long a, long long b){return a / gcd(a,b) * b;}

void Main(){
    int n; cin >> n;
    int ans = 1;
    REP(_,n){
        int a; cin >> a;
        ans = lcm(ans,a);
    }
    cout << ans << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}


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

int main(){
  int a,b,c;
  ll k;
  cin>>a>>b>>c>>k;
  if (k%2==0) cout << a-b;
  else cout << b-a;
}

Measured memory_bytes: 3620