akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner scanner = new Scanner(System.in);
        long x = Math.abs(scanner.nextLong());
        long k = scanner.nextLong();
        long d = scanner.nextLong();

        long need = x / d;
        if (k <= need) {
            System.out.println(x - k * d);
            return;
        }
        k -= need;
        if (k % 2 == 1) {
            System.out.println(Math.min(Math.abs(x - (need + 1) * d), x - (need - 1) * d));
        } else {
            System.out.println(x - need * d);
        }
    }
}

Measured memory_bytes: 35712
#include<stdio.h>

int partition(int [],int,int);

int main(){
  int i,n,a[100000],q;

  scanf("%d",&n);

  for(i=0;i<=n-1;i++){
    scanf("%d",&a[i]);
  }

  q=partition(a,0,n-1);

  for(i=0;i<=n-1;i++){
    if(i==q)printf("[");
    printf("%d",a[i]);
    if(i==q)printf("]");
    if(i!=n-1)printf(" ");
  }

  printf("\n");

  return 0;
}

int partition(int a[],int p,int r){
  int temp,x,i,j;
  x=a[r];
  i=p-1;

  for(j=p;j<=r-1;j++){
    if(a[j]<=x){
      i++;
      temp=a[i];
      a[i]=a[j];
      a[j]=temp;
    }
  }

  temp=a[i+1];
  a[i+1]=a[r];
  a[r]=temp;

  return i+1;
}
      


Measured memory_bytes: 3072
#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;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;

int main(){
  string s;cin >> s;
  map<char,int> mp;
  for(int i=0;i<s.size();i++){
    mp[s[i]]++;
  }

  for(auto &i:mp){
    if(i.second&1){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


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

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

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

  sort(A, A+N, greater<int>());

  int ans = 0;
  for (int i = 0; i < K; ++i) {
    ans += A[i];
  }

  cout << ans << endl;

  return 0;
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

LL fac[SIZE], finv[SIZE], inv[SIZE];
void combInit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for( int i = 2; i < SIZE; ++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;

    }
}

LL comb(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;

}

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

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

    int n, m;
    cin >> n >> m;
    int imos[SIZE] = {};
    for( int i = 0; i < m; ++i ) {
        int l, r;
        cin >> l >> r;
        imos[l]++;
        imos[r + 1]--;

    }

    int cnt = 0;
    int res = 0;
    for( int i = 1; i <= n; ++i ) {
        cnt += imos[i];
        if( cnt == m ) ++res;

    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		String[] str = in.readLine().split("");
		short size = (short) str.length;
		for (int i = 1; i < size; i += 1) {
			if (str[i].matches("[a-z]")) {
				sb.append(str[i].toUpperCase());
			} else if (str[i].matches("[A-Z]")) {
				sb.append(str[i].toLowerCase());
			} else {
				sb.append(str[i]);
			}
		}
		System.out.println(sb);
	}
}

Measured memory_bytes: 24652
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int maxv = Integer.MIN_VALUE;
        int minv = sc.nextInt();
        for (int i = 1; i < n; i++) {
            int ri = sc.nextInt();
            maxv = Math.max(maxv, ri - minv);
            minv = Math.min(minv, ri);
        }
        System.out.println(maxv);
        sc.close();
    }
}



Measured memory_bytes: 99920
#include<bits/stdc++.h>
#define RG register
#define IL inline
#define int long long
#define DB double
using namespace std;

IL int gi() {
    char ch=getchar(); int x=0,q=0;
    while(ch<'0'||ch>'9') q=ch=='-'?1:q,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return q?-x:x;
}

const int N=2e5+10;

int n,m,ans,tot,cnt,k[N],s[N],fa[N],flag[N],head[N],size[N];

struct Edge{int next,to;}e[N<<1];
IL void make(int a,int b) {
	e[++tot]=(Edge){head[a],b},head[a]=tot;
	e[++tot]=(Edge){head[b],a},head[b]=tot;
}

int getfa(int x) {return x==fa[x]?x:fa[x]=getfa(fa[x]);}

void dfs(int x,int fx,int fl) {
	RG int i,y;
	fa[x]=fx,size[x]=flag[x]=fl;
	for (i=head[x];i;i=e[i].next)
		if ((y=e[i].to)!=fx) dfs(y,x,-fl),size[x]+=size[y];
}

signed main ()
{
	RG int i,x,y,fx,fy,Fr,To,now;
	n=gi(),m=gi();
	for (i=1;i<=n;++i) fa[i]=i;
	for (i=1;i<=m;++i) {
		x=gi(),y=gi(),fx=getfa(x),fy=getfa(y);
		if (fx==fy) Fr=x,To=y;
		else fa[fx]=fy,make(x,y);
	}
	dfs(1,0,1);
	if (m==n-1) {
		if (size[1]) return puts("-1"),0;
	}
	else if (flag[Fr]==flag[To]) {
		if (size[1]&1) return puts("-1"),0;
		now=size[1]/2,ans+=abs(now);
		for (i=Fr;i;i=fa[i]) size[i]-=now;
		for (i=To;i;i=fa[i]) size[i]-=now;		
	}
	else {
		/*if (size[1]) return puts("-1"),0;
		s[cnt=1]=0;
		for (i=Fr;fa[i];i=fa[i]) s[++cnt]=-size[i];
		for (i=To;fa[i];i=fa[i]) s[++cnt]=size[i];
		sort(s+1,s+cnt+1);
		now=s[cnt/2],ans+=abs(now);
		for (i=Fr;fa[i];i=fa[i]) size[i]+=now;
		for (i=To;fa[i];i=fa[i]) size[i]-=now;*/
		if(size[1]) return puts("-1"),0;
		for(i=Fr;i;i=fa[i]) ++k[i];
		for(i=To;i;i=fa[i]) --k[i];
		int tp=1;
		for(i=1;i<=n;i++) {
			if(k[i]==1) s[++tp]=-size[i];
			if(k[i]==-1) s[++tp]=size[i];
		}
		sort(s+1,s+1+tp);
		int t=s[(tp+1)/2];ans+=abs(t);
		for(i=1;i<=n;i++) size[i]+=k[i]*t;
	}
	for (i=1;i<=n;++i) ans+=abs(size[i]);
	printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 17408
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=3e5;
int n,q,m,fa[N],a[N],b[N],c[N];
int fd(int x){return x==fa[x]?x:fa[x]=fd(fa[x]);}
main()
{
	scanf("%lld%lld%lld",&n,&m,&q);
	for(int i=1;i<=n;i++)fa[i]=i;
	for(int i=1;i<=q;i++)
	{
		scanf("%lld%lld%lld",&a[i],&b[i],&c[i]);a[i]++,b[i]++;
		if(c[i])continue;
		int x=fd(a[i]),y=fd(b[i]);if(x!=y)fa[x]=y;
	}int cnt=0,bl=0;for(int i=1;i<=n;i++)cnt+=fa[i]==i;
	for(int i=1;i<=q;i++)
	{
		if(!c[i])continue;
		int x=fd(a[i]),y=fd(b[i]);if(x==y)return puts("No"),0;bl=1;
	}//cout<<cnt<<endl;
	int l=bl?max(3ll,cnt):cnt-1,r=cnt*(cnt-1)/2,k=m-n+cnt;
	if(k>=l&&k<=r)return puts("Yes"),0;puts("No");
}


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

// stringはscanfで読み取れない？（scanfがC由来だから？）

int N;

int main() {
  
  scanf("%d", &N);

  if (N % 2 == 0) {
    printf("0.5\n");
  } else {
    printf("%f\n", (N + 1) / (2 * (double) N));
  }

  return 0;
}

Measured memory_bytes: 256
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
// #include<C:\Users\J\Desktop\AC\athead.h>
#define showa(v) for(int iii = 0; iii < v.size(); iii++){ cout << v[iii] << " ";} cout << endl;
#define show(iiii) cout << iiii << endl; 
#define shows(iiiii) cout << iiiii << " ";
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include <cmath>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <set>
#include <deque>
#include <numeric>
#include<tuple>
#include <utility>
using namespace std;

int main(){
    int n, a ,b ,c ,d;
    cin >> n >> a >> b >> c >> d;
    string s;
    cin >> s;
    int maxcd = max(c,d);

        for(int i = a-1+1; i < maxcd-1; i++){
            if(s[i] == '#' && s[i+1] == '#'){
                cout << "No"  << endl;
                return 0;
            }    
        }
        if(d < c){
            for(int i = b-1; i < d; i++){
                if((s[i-1] == '.' && s[i+1] == '.' && s[i] == '.')          
                ){
                    cout << "Yes" << endl;
                    //   show("a");
                    //   show(i);
                    return 0;
                }        
            }
                    cout << "No";
        return 0;
        }
                cout << "Yes" << endl;
                    //   show("a");
                    //   show(i);
                    return 0;
    // }
    // else{
        
    //             cout <<  "Yes";
    //     return 0;

    // }
}


Measured memory_bytes: 764
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;

int N;

int main(void){
	cin>>N;
	if(N/100==N%10)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)

	sc.Scan()
	num, _ := strconv.Atoi(sc.Text())
	var A = make([]int, num)

	sc.Scan()
	for i, v := range strings.Split(sc.Text(), " ") {
		A[i], _ = strconv.Atoi(v)
	}

	sc.Scan()

	for sc.Scan() {
		inputs := strings.Split(sc.Text(), " ")
		start, _ := strconv.Atoi(inputs[1])
		end, _ := strconv.Atoi(inputs[2])

		result := A[start]
		switch inputs[0] {
		case "0":
			for i := start + 1; i < end; i++ {
				if result > A[i] {
					result = A[i]
				}
			}
		case "1":
			for i := start + 1; i < end; i++ {
				if result < A[i] {
					result = A[i]
				}
			}
		}
		fmt.Println(result)
	}
}



Measured memory_bytes: 1164
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<climits>
#include<cstring>
#include<queue>
using namespace std;

int main(){
    int x, y;
    cin >> x >> y;
    while(x!=0 || y!=0){
        x < y ? cout << x << " " << y << endl : cout << y << " " << x << endl;
        cin >> x >> y;
    }
    return 0;
}

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

int main() {
  while(true){
    int a,b;
    cin>>a>>b;
    if(a==0&&b==0) break;
    if(a<b)swap(a,b);
    cout<<b<<" "<<a<<endl;
  }
}


Measured memory_bytes: 3068
#include<iostream>
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>

using namespace std;

class Counting {
	unsigned long long p, n;
	vector<long long> invMemo, facMemo, facInvMemo;
public:
	Counting(unsigned long long nn, unsigned long long np) {
		p = np;
		n = nn;
		invMemo.resize(n + 1);
		facMemo.resize(n + 1);
		facInvMemo.resize(n + 1);
		facMemo[0] = 1;
		facMemo[1] = 1;
		facInvMemo[0] = 1;
		facInvMemo[1] = 1;
		invMemo[0] = 0;
		invMemo[1] = 1;
		for (unsigned long long i = 2; i <= n; i++) {
			invMemo[i] = p - (p / i)*invMemo[p%i] % p;
			facMemo[i] = (facMemo[i - 1] * i) % p;
			facInvMemo[i] = (facInvMemo[i - 1] * invMemo[i]) % p;
		}
	}
	unsigned long long fac(unsigned long long k) {
		return facMemo[k];
	}
	unsigned long long facInv(unsigned long long k) {
		return facInvMemo[k];
	}
	unsigned long long choose(unsigned long long n, unsigned long long k) {
		if (!(0 <= k && k <= n))
			return 0;
		return (((facMemo[n] * facInvMemo[k]) % p)*facMemo[n - k]) % p;
	}
	unsigned long long divide(unsigned long long a, unsigned long long b) {
		return (a * invMemo[b]) % p;
	}
	unsigned long long mod(unsigned long long a) {
		a %= p;
		if (a < 0) a += p;
		return a;
	}
	unsigned long long power(unsigned long long a, unsigned long long e) {
		unsigned long long ans = 1;
		for (; e > 0; e /= 2) {
			if (e % 2 != 0)
				ans = ans * a % p;
			a = a*a%p;
		}
		return ans;
	}
};

int n;
long long a, b, ans = 0;
vector<long long> x;

int main() {
	cin >> n >> a >> b;
	x.resize(n);
	for (int i = 0; i < n; i++)
		cin >> x[i];
	for (int i = 0; i < n - 1; i++) {
		if ((x[i + 1] - x[i])*a < b) {
			ans += (x[i + 1] - x[i])*a;
		}
		else {
			ans += b;
		}
	}
	cout << ans << endl;
//	cin >> n;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<typename A,typename B>istream&operator>>(istream&is,pair<A,B> &p){is>>p.fi>>p.se;return is;}
template<typename A,typename B>ostream&operator<<(ostream&os,const pair<A,B> &p){os<<"("<<p.fi<<","<<p.se<<")";return os;}
template<typename T>istream&operator>>(istream&is,vector<T> &t){REP(i,t.size())is>>t[i];return is;}
template<typename T>ostream&operator<<(ostream&os,const vector<T>&t){os<<"{";REP(i,t.size()){if(i)os<<",";os<<t[i];}cout<<"}";return os;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    ll n;
    cin>>n;
    cout<<n*(n+1)/2-1-n+1<<endl;
    return 0;
}

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

void solve(){
  int n; cin >> n;
  vector<vector<int> > v(n + 1, vector<int>(n + 1, 0));
  for(int i = 0; i < n; i++){
    int u, k; cin >> u >> k;
    for(int j = 0; j < k; j++){
      int x; cin >> x;
      v[u][x] = 1;
    }
  }
  queue<int> q;
  vector<int> ans(n + 1, -1), c(n + 1, 0);
  q.push(1);
  ans[1] = 0;
  c[1] = 1;
  while(q.size() != 0){
    int x = q.front();
    q.pop();
    for(int i = 1; i <= n; i++){
      if(v[x][i] == 1 && c[i] == 0){
        q.push(i);
        ans[i] = ans[x] + 1;
        c[i] = 1;
      }
    }
  }
  for(int i = 1; i <= n; i++){
    cout << i << " " << ans[i] << endl;
  }
  return;
}

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



Measured memory_bytes: 3208
#include<iostream>
using namespace std;
char map1[55][55];
int c=0,n,w,h,k[11],map2[55][55]={};
 
void t(int,int,int);
void e(int,int,int);
void dfs(int,int);
  
int main(){
  int d,x1,y1,cnt=0;
  cin>>h>>w>>d>>n;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>map1[i][j];
      if(map1[i][j]=='D')x1=j,y1=i;
    }
  }
  for(int i=0;i<d;i++)cin>>k[i];
  for(int i=0;i<n;i++){
    int x,y,s;
    cin>>x>>y>>s;
    if(s==0)t(x,y,k[s]);
    else if(s==d){
      for(int j=0;j<h;j++)
        for(int l=0;l<w;l++)
          map2[j][l]++;
      e(x,y,k[s-1]);
    }else t(x,y,k[s]),e(x,y,k[s-1]);
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(map2[i][j]==n&&map1[i][j]!='#')cnt++;
    }
  }
  if(cnt>=1){
    cnt=0;
    dfs(x1,y1);
    if(c>0){
      for(int i=0;i<h;i++){
	for(int j=0;j<w;j++){
	  if(map2[i][j]==n&&map1[i][j]!='#')cnt++;
	}
      }
      if(cnt==0)cout<<"Yes"<<endl;
      else cout<<"Unknown"<<endl;
    }
    else cout<<"No"<<endl;
  }else cout<<"Broken"<<endl;
  return 0;
}

void t(int x,int y,int k){
  for(int i=0;i<=2*k;i++){
    for(int j=0;j<=2*k;j++){
      int a=y-k+i,b=x-k+j;
      if(a>=0&&a<h&&b>=0&&b<w)
        map2[a][b]++;
    }
  }
}
 
void e(int x,int y,int k){
  for(int i=0;i<=2*k;i++){
    for(int j=0;j<=2*k;j++){
      int a=y-k+i,b=x-k+j;
      if(a>=0&&a<h&&b>=0&&b<w)
        map2[a][b]--;
    }
  }
}
 
void dfs(int x,int y){
  if(x<0||x>=w||y<0||y>=h||map1[y][x]=='#'||map2[y][x]==-1)return;
  if(map2[y][x]==n)c++;
  map2[y][x]=-1;
  dfs(x+1,y),dfs(x-1,y),dfs(x,y-1),dfs(x,y+1);
}
 

Measured memory_bytes: 3156
#include <iostream>
#include <cstdio>
using namespace std;
int main() {
    double p = 3.141592653589;
    double a;
    cin >> a;
    double b = a*a*p;
    double c = 2*a*p;
    printf("%lf %lf \n", b, c);
    return 0;
}



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

int main()
{
	int posx=0, posy=0, tn=0;
	int N;
	cin>>N;
	int t1, xn, yn;
	for(int a=0;a<N;a++)
	{
		scanf("%d %d %d", &t1, &xn, &yn);
		int h=abs(xn-posx)+abs(yn-posy);
		if(h > (t1-tn))
		{
			cout<<"No"<<endl;
			return 0;
		}
		else if(h==(t1-tn))
		{
			tn=t1;
			posx=xn;
			posy=yn;
		}
		else if(h < (t1-tn))
		{
			int tmp=(t1-tn)-h;
			if(tmp%2==1)
			{
				cout<<"No"<<endl;
				return 0;
			}
			else
			{
				tn=t1;
				posx=xn;
				posy=yn;
			}
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    int n;cin>>n;
    if(n==1)cout<<"Hello World"<<endl;
    else{
        int a,b;cin>>a>>b;
        cout<<a+b<<endl;
    }
}

Measured memory_bytes: 256
N = int(input())
L = list(map(int,input().split()))

count = 0
subL = []

for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            
            if (L[i] != L[j] and L[j] != L[k] and L[k] != L[i]):
                if L[i] > L[j]:
                    max = L[i]
                else: max = L[j]
                if L[k] > max:
                    max = L[k]

                if L[i] < L[j]:
                    min =  L[i]
                else: min = L[j]
                if L[k] < min:
                    min = L[k]

                if min < L[i] < max:
                    mid = L[i]
                if min < L[j] < max:
                    mid = L[j]
                if min < L[k] < max:
                    mid = L[k]

                if max < mid + min:
                    count += 1

print(count)


Measured memory_bytes: 9132
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int d = sc.nextInt();
		int g = sc.nextInt() / 100;
		int[] p = new int[d];
		int[] c = new int[d];
		for (int i = 0; i < d; i++) {
			p[i] = sc.nextInt();
			c[i] = sc.nextInt() / 100;
		}
		sc.close();

		int ans = 1000;
		int end = 1 << d;
		label:
		for (int i = 0; i < end; i++) {
			int val = 0;
			int sum = 0;
			for (int j = 0; j < d; j++) {
				if ((i >> j & 1) == 1) {
					val += p[j];
					sum += p[j] * (j + 1) + c[j];
				}
			}
			if (sum >= g) {
				ans = Math.min(ans, val);
				continue;
			}
			for (int j = d - 1; j >= 0; j--) {
				if ((i >> j & 1) == 0) {
					int v = (p[j] - 1) * (j + 1);
					if (sum + v < g) {
						sum += v;
						val += p[j] - 1;
					} else {
						int rem = g - sum;
						int x = (rem + j) / (j + 1);
						val += x;
						ans = Math.min(ans, val);
						continue label;
					}
				}
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 21844
/*input
5 5 4
13 25 7 15 17
16 22 20 2 9
14 11 12 1 19
10 6 23 8 18
3 21 5 24 4
3
13 13
2 10
13 13
*/
#include <iostream>
#include <bits/stdc++.h>

using namespace std;

long long int dp[1123456]={0};
long long int pow(long long int a, long long int b, long long int mod){
	if(b==1)return a;
	if(b==0)return 1;
	long long int ret = pow(a, b/2 ,mod);
	ret = ret * ret;
	ret %= mod;
	if(b&1){
		ret=ret*a;
		ret %= mod; 
	}
	return ret;
}

int arr[312][312];
pair<int, int> pp[312*312];
int mp[312*312];
int main() {
	int h,w,d,q,l,r;
	cin>>h>>w>>d;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin>>arr[i][j];
			pp[arr[i][j]] = make_pair(i, j);
		}
	}
	for(int i=1;i<=d;i++){
		mp[i] = 0;
		for(int j=i+d;j<=h*w;j+=d){
			mp[j] = mp[j-d]+abs(pp[j].first-pp[j-d].first)+abs(pp[j].second-pp[j-d].second);
		}
	}
	cin>>q;
	while(q--){
		cin>>l>>r;
		cout<<mp[r]-mp[l]<<endl;
	}

}

Measured memory_bytes: 2560
#include <iostream>

int main()
{
    std::string s;
    std::cin >> s;

    std::string alphabets = "abcdefghijklmnopqrstuvwxyz";

    for (auto c : alphabets) {
        if (s.find(c) == std::string::npos) {
            std::cout << c << std::endl;
            return 0;
        }
    }
    std::cout << "None" << std::endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n;
	cin>>n;
	long long a,b,c;
	a=2;
	b=1;
	for(int i=0;i<n-1;i++){
		c=b;
		b=a+b;
		a=c;
		//cout<<a<<" "<<b<<endl;
	}
	cout<<b<<endl;
}

Measured memory_bytes: 256
use std::vec::*;
use std::io::*;

fn main() {
    let mut vec: Vec<u8> = Vec::new();
    let stdin = stdin();
    let mut stdinlock = stdin.lock();
    stdinlock.read_to_end(&mut vec).unwrap();
    let a = vec[0];
    let b = vec[1];
    if (a == b && a == vec[2]) {
        println!("Yes");
    } else if (b == vec[2] && b == vec[3]) {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
#!/usr/bin/env python3
class WeightedUnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
        self.weight = [0] * n

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

    def union(self, x, y, w):
        w += self.weight[x] - self.weight[y]
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
            w = -w
        self.parents[x] += self.parents[y]
        self.parents[y] = x
        self.weight[y] = w
        return

    def weig(self, x):
        self.find(x)
        return self.weight[x]

    def diff(self, x, y):
        return self.weight[y] - self.weight[x]

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

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


n, m = map(int, input().split())
UF = WeightedUnionFind(n + 1)

for i in range(m):
    l, r, d = map(int, input().split())
    if UF.same(l, r):
        if d != abs(UF.diff(l, r)):
            exit(print("No"))
    else:
        UF.union(l, r, d)
print("Yes")

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

// Shrotening
#define fst first
#define snd second
#define pb push_back
#define mp make_pair

// Loop
#define FOR(i,a,b) for(auto i=(a);i<(b);++i)
#define RFOR(i,a,b) for(auto i=(a);i>=(b);--i)

#define REP(i,a) for(long i=0;i<(a);++i)
#define RREP(i,a) for(long i=(a);i>=0;--i)

#define EACH(i,a) for(auto (i)=(a).begin(),_END=(a).end();i!=_END;++i)
#define REACH(i,a) for(auto (i)=(a).rbegin(),_END=(a).rend();i!=_END;++i)

//Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a,x) ((a).find(x)!=(a).end())
#define SORT(a) std::sort((a).begin(), (a).end())
#define UNIQUE(a) std::sort((a).begin(), a.end()), a.erase(std::unique((a).begin(), a.end()), a.end());
#define SUM(a) std::accumulate((a).begin(), (a).end(), 0);

//Setting
#define OPT std::cin.tie(0);std::ios::sync_with_stdio(false);

//debug message
bool debug = true;
#define MSG(s)   if(debug){std::cout << s << std::endl;}
#define DEBUG(x) if(debug){std::cout << "debug(" << #x << "): " << x << std::endl;}

//alias
typedef long long LL;
typedef std::vector<char> VC;
typedef std::vector<int>  VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;

typedef std::vector< VC > VC2;
typedef std::vector< VI > VI2;
typedef std::vector< VL > VL2;
typedef std::vector< VLL > VLL2;

typedef std::pair<int,int> PII;

inline int solve(int x) {
    int n = std::log10(x);
    int ans = 0;
    for(int i=0; i<=n; ++i) {
        ans += (int)(x/std::pow(10, i)) % 10;
    } 
    return ans;
}

int N;
int main() {
    std::cin >> N;
    int i, j;

    int ans = std::numeric_limits<int>::max();
    for(int i=1; i<N; ++i) {
        j = N-i;

        ans = std::min(ans, solve(i) + solve(j));
    }
    std::cout << ans << std::endl;
}

Measured memory_bytes: 512
import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

class Main {
	public static void main(String[] args) throws IOException {
		final int N = 9;
		Scanner in = new Scanner(System.in);

		PrimeGenerater gen = new PrimeGenerater(999999);

		while(in.hasNext()) {
			int d = in.nextInt();
			System.out.printf("%d\n", gen.countPrimeTo(d));
		}
	}
}

class PrimeGenerater {
	List<Integer> isPrimeTable;
	int n = 0;
	public PrimeGenerater(int n) {
		this.n = n;
		initPrimeTable();
		generatePrimeTable();
	}

	private void initPrimeTable() {
		isPrimeTable = new ArrayList<Integer>(n);
		for(int i=0;i<=n;i++) {
			isPrimeTable.add(1);
		}
	}

	private void generatePrimeTable() {
		for(int i=2;i<=n;i++) {
			if(isPrimeTable.get(i) == 0) continue;
			// Sieve of Eratosthenes
			for(int d=2;;d++) {
				int idx = i*d;
				if(idx > n) break;
				isPrimeTable.set(idx, 0);
			}
		}
	}

	public int countPrimeTo(int to) {
		int ret = 0;
		for(int i=2;i<=to;i++) {
			if(isPrimeTable.get(i) == 1) ret++;
		}
		return ret;
	}
}

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

int main()
{
	int n,a,b;

	cin >> n >> a >> b;

   if(n*a <= b){
   	cout << n*a << endl;
   }
    else {
   	cout << b << endl;
   }

	return 0;
}

Measured memory_bytes: 256
using System;

namespace AizuOnline
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            var x = Console.ReadLine().Split(' ');
            var a = Convert.ToInt32(x[0]);
            var b = Convert.ToInt32(x[1]);
            if (a > b)
            {
                Console.WriteLine("a > b");
            }
            else if (a < b)
            {
                Console.WriteLine("a < b");
            }
            else
            {
                Console.WriteLine("a == b");
            }
        }
    }
}

Measured memory_bytes: 9016
K = gets.to_i

queue = [[1, 1]]

check = Hash.new { |h, k| h[k] = Hash.new }

until queue.empty?
  v, cost = queue.shift

  next if check[v][cost]
  check[v][cost] = true

  if v == 0
    puts cost
    break
  end

  nv1 = (v + 1) % K
  nv2 = (v * 10) % K

  queue << [nv1, cost + 1]
  queue.unshift([nv2, cost]) if v != nv2
end


Measured memory_bytes: 49904
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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

int main() {

    int N;
    cin >> N;
    int a;

    REP(i, N){
        cin >> a;
        if (a % 2 == 0) if (!(a % 3 == 0 || a % 5 == 0)){
            cout << "DENIED" << endl;
            return 0;
        }
    }
    cout << "APPROVED" << endl;


    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
struct a{
  char name[2];
  int score[10],win,lose;
};
main(){
  while(1){
    int n;
    scanf("%d",&n);
    if(n==0) break;
    int j,i,top,b,con;
    struct a p[10];
    for(i=0;i<n;i++){
      p[i].win=0;
      p[i].lose=0;
      scanf("%s",p[i].name);
      p[i].name[1]='\0'; /*ÇÁ*/
      for(j=0;j<n-1;j++){
	scanf("%d",&p[i].score[j]);
	if(p[i].score[j]==0) p[i].win+=1;
	else if(p[i].score[j]==1) p[i].lose+=1; 
      }
    }

    for(i=0;i<n;i++){
      top=-1;
      b=100;
      con=-1;
      for(j=n-1;j>=0;j--){
	if(top<p[j].win){
	  top=p[j].win;
	  b=p[j].lose;
	  con=j;
	}
	else if(top==p[j].win&&b>=p[j].lose){
	  b=p[j].lose;
	  con=j;
	}
      }
      printf("%s\n",p[con].name);
      p[con].win=-2;
    }
  } 
  return 0; 
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    string s;
    cin >> s;
    int su=0;
    for(int i=0;i<s.length();i++){
        su += (int)(s[i]-'0');
    }
    int n = stoi(s);
    if(n%su==0){
        cout << "Yes" << endl;
    }else{
        cout <<"No" << endl;
    }
}


Measured memory_bytes: 256
n = int(input())
li = list(map(int,input().split()))
all_li = []
tmp = []
for i,l in enumerate(li):
    if i+1 ==l:
        if len(tmp) == 0:
            tmp.append(l)
        else:
            if tmp[-1] == l-1:
                tmp.append(l)
            else:
                all_li.append(tmp)
                tmp = [l]
    else:
        all_li.append(tmp)
        tmp = []
if len(tmp)>0:
    all_li.append(tmp)
ans = 0
for a in all_li:
    ans += len(a)//2 + len(a)%2        
print(ans)

Measured memory_bytes: 58988
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const ll mod=1e9+7;

struct UnionFind{
  vector<int> d;
  UnionFind(int n): d(n,-1) {}
  //連接していれば根の番号を返す
  //していなければ元の番号を返す
  int root(int x){
    //根ならdの値は負のサイズ
    //子なら根の値
    if(d[x] < 0) return x;
    return d[x] = root(d[x]);
  }
  bool unite(int x, int y){
    //xとyの根を計算
    x = root(x); y = root(y);
    //もし同じ根つまり同じ連結成分にあれば、なにか追加する必要はない
    if(x == y) return false;
    //大きい連結成分の根に向かって小さい連結成分の根をつなげる
    if(d[x] > d[y]) swap(x,y);
    //根となる方はサイズを負の値として保存
    d[x] += d[y];
    //子になる方は根となる番号を保存
    d[y] = x;
    return true;
  }
  bool same(int x, int y){
    //根が同じなら同じ連結成分
    return root(x) == root(y);
  }
  int size(int x){
    //xの根を計算し、それのの負の値がサイズ
    return -d[root(x)];
  }
};

int deg[100005] = {0};
vector<int> to[100005];

int main(){
  int n,m,k;
  cin >> n >> m >> k;
  UnionFind uf(n);
  rep(i,m){
    int a,b;
    cin >> a >> b;
    a--; b--;
    deg[a]++;
    deg[b]++;
    uf.unite(a,b);
  }
  rep(i,k){
    int a,b;
    cin >> a >> b;
    a--; b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  rep(i,n){
    int ans = uf.size(i)-1-deg[i];
    for(int u: to[i]){
      if(uf.same(i,u)) ans--;
    }
    printf("%d ",ans);
  }
  printf("\n");
  return 0;
}


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

using namespace std;

bool IsValidAddress(int A, int B, const string &S) {
  int n = S.length();
  if (n != A + B + 1) {
    return false;
  }

  for (int i = 0; i < n; i++)  {
    if (i == A) {
      if (S[i] != '-') {
        return false;
      }
    } else {
      if (S[i] < '0' || '9' < S[i]) {
        return false;
      }
    }
  }
  return true;
}

int main() {
  int A, B;
  string S;
  cin >> A >> B >> S;
  if (IsValidAddress(A, B, S)) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
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; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
// int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int x;
  cin >> x;
  if(x<600)cout <<8<<endl;
  else if(x<800)cout<<7<<endl;
  else if(x<1000)cout<<6 <<endl;
  else if(x<1200)cout <<5<<endl;
  else if(x<1400)cout<<4<<endl;
  else if(x<1600)cout<<3<<endl;
  else if(x<1800)cout<<2<<endl;
  else if(x<2000)cout<<1<<endl;
  return 0;
}


Measured memory_bytes: 3656
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;

void solve(){
  int a[3];
  rep(i,3)cin>>a[i];
  sort(a,a+3);
  if(a[0]%2==a[1]%2){
    if(a[0]%2==a[2]%2)cout<<(a[2]-a[1])/2+(a[2]-a[0])/2;
    else cout<<(a[2]-a[1])/2+(a[2]-a[0])/2+1;
  }
  else {
    cout<<(a[2]-a[1])/2+(a[2]-a[0])/2+2;
  }
}

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


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

class LCA {
	using pii = pair<int, int>;
	const int n;
	vector<int> depth, par, heavy, head;
	int dfs(int v, int prev, const graph& G) {
		par[v] = prev;
		depth[v] = prev != -1 ? depth[prev] + 1 : 0;
		int ma = 0, cnt = 1;
		for (auto to : G[v]) if (to != prev) {
			int c = dfs(to, v, G);
			if (c > ma) {
				ma = c;
				heavy[v] = to;
			}
			cnt += c;
		}
		return cnt;
	}
public:
	LCA(const graph& G, int rt = 0) : n(G.size()), depth(n), par(n), heavy(n, -1), head(n) {
		dfs(rt, -1, G);
		queue<int> q;
		q.push(rt);
		while (!q.empty()) {
			int h = q.front(); q.pop();
			for (int v = h; v != -1; v = heavy[v]) {
				head[v] = h;
				for (auto to : G[v]) if (to != par[v] && to != heavy[v]) {
					q.push(to);
				}
			}
		}
	}
	int calc(int u, int v) {
		while (head[u] != head[v]) {
			if (depth[head[u]] < depth[head[v]]) v = par[head[v]];
			else u = par[head[u]];
		}
		return depth[u] < depth[v] ? u : v;
	}
	int dist(int a, int b) {
		return depth[a] + depth[b] - depth[calc(a, b)] * 2;
	}
};

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int n;
	cin >> n;
	graph G(n);
	for (int i = 0; i < n; i++) {
		int k;
		cin >> k;
		for (int j = 0; j < k; j++) {
			int c;
			cin >> c;
			G[i].push_back(c);
			G[c].push_back(i);
		}
	}
	LCA lca(G);
	int q;
	cin >> q;
	while (q--) {
		int u, v;
		cin >> u >> v;
		printf("%d\n", lca.calc(u, v));
	}
	return 0;
}



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

using namespace std;

#define FORE(i, a) for (auto i = a.begin(); i != a.end(); ++i)
#define REPU(i, a, b) for (int i = (a); i < (b); ++i)
#define REPD(i, a, b) for (int i = (a); i > (b); --i)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

vector<string> split(const string &s, char c) {
	vector<string> v; stringstream ss(s); string x;
	while (getline(ss, x, c)) v.push_back(x);
	return v;
}
#define DEBUG(args...) { vector<string> _v = split(#args, ','); err(_v.begin(), args); }
void err(vector<string>::iterator it) {}
template<typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
	cerr << "[DEBUG] " << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << '\n';
	err(++it, args...);
}

typedef long long ll;
const int MOD = 1000000007;

template<class T, class U> inline T tmin(T a, U b) { return (a < b) ? a : b; }
template<class T, class U> inline T tmax(T a, U b) { return (a > b) ? a : b; }
template<class T, class U> inline void amax(T &a, U b) { if (b > a) a = b; }
template<class T, class U> inline void amin(T &a, U b) { if (b < a) a = b; }
template<class T> T gcd(T a, T b) { while (b != 0) { T c = a; a = b; b = c % b; } return a; }

const int N = 10005;
typedef pair<int, int> P;
struct E {
	int v, id;
};
vector<E> g[N];

int main(int argc, char *argv[]) {
	ios_base::sync_with_stdio(false);

	int n; cin >> n;
	vector<int> deg(n, 0), c(n), vs(n, -1);
	REPU(i, 1, n) {
		int a, b; cin >> a >> b;
		--a, --b;
		g[a].push_back((E) {b, i});
		g[b].push_back((E) {a, i});
		deg[a]++;
		deg[b]++;
	}
	REPU(i, 0, n) cin >> c[i];
	sort(ALL(c));

	priority_queue<P, vector<P>, greater<P>> que;
	REPU(i, 0, n) {
		que.push(P(deg[i], i));
	}

	int ans = 0;
	int idx = 0;
	while (!que.empty()) {
		P p = que.top(); que.pop();
		if (p.first != deg[p.second]) continue;
		int v = p.second;
		int val = c[idx++];
		ans += deg[v] * val;
		vs[v] = val;
		deg[v] = 0;
		for (E e : g[v]) if (deg[e.v] > 0) {
			deg[e.v]--;
			if (deg[e.v] > 0) {
				que.push(P(deg[e.v], e.v));
			}
		}
	}
	REPU(i, 0, n) if (vs[i] == -1) {
		vs[i] = c[idx++];
	}

	cout << ans << endl;
	REPU(i, 0, n) {
		printf("%d%c", vs[i], " \n"[i == n - 1]);
	}

	return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

int main() {
    int64_t N, M, ans = 0;
    cin >> N >> M;
    if (2 * N >= M) {
        cout << M / 2 << endl;
        return 0;
    }
    ans += N;
    M -= 2 * N;
    ans += M / 4;
    cout << ans << endl;
}

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

#define LL long long
#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()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int main() {
    int N, K;
    cin >> N >> K;
    REP(i, N) {
        int n;
        cin >> n;
    }
    int res = (N - 1)/(K - 1);
    if((N-1)%(K - 1)) {
        res++;
    }
    cout << res << endl;
    return 0;
}



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

using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;

int main()
{
  int n;
  cin >> n;
  vector<int> d(n);
  rep(i, n) cin >> d[i];
  ll ans = 0;
  for(int i = 0; i < n; ++i)
  {
    for(int j = i + 1; j < n; ++j)
    {
      ans += d[i] * d[j];
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define FORD(x,y,z) for(int x=y;x>=z;x--)
#define MSET(x,y) memset(x,y,sizeof(x))
#define FOR(x,y) for(__typeof(y.begin()) x=y.begin();x!=y.end();x++)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ size()
#define M 25
void RI(){}
template<typename... T>
void RI( int& head, T&... tail ) {
  scanf("%d",&head);
  RI(tail...);
}
using namespace std;
typedef long long LL;
int in[M];
int main()
{  
	int n;
	cin >> n;
	for(int i = 0; i < n; i++) cin >> in[i];
	int ans = 1, cur = in[0];
	for(int i = 1; i < n; i++) if(in[i] >= cur){
		 cur = in[i];
		 ans++;
	}
	cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
/*
	Created by Faisal Ahmed
*/
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
typedef long double ld;

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

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <array>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <random>
#include <bitset>
#include <cassert>
#include <tuple>
#include <list>
#include <iterator>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <complex>

using namespace std;

typedef long long ll;
typedef long double ld;

template<class htpe, class cmp>
using heap = priority_queue<htpe, vector<htpe>, cmp>;

template<class htpe>
using min_heap = heap<htpe, greater<htpe> >;

template<class htpe>
using max_heap = heap<htpe, less<htpe> >;

#define mp make_pair
#define pb push_back
#define mt make_tuple
#define ff first
#define ss second

#define forn(i, n) for (int i = 0; i < ((int)(n)); ++i)
#define forrn(i, s, n) for (int i = (int)(s); i < ((int)(n)); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

#define PYMOD(a, m) ((((a) % (m)) + (m)) % (m))

const int INF = 1791791791;
const ll INFLL = 1791791791791791791ll;


int main() {
    // Code here:

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

    int ans = 0;

    forn(ta, a + 1) {
        forn(tb, b + 1) {
            forn(tc, c + 1) {
                if (ta * 500 + tb * 100 + tc * 50 == x)
                    ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

void sort(int n, int S[n])
{
    int i, j;
    int tmp;

    for(i = 0; i < n - 1; i ++){
        for(j = n - 1; j > i; j--){
            if(S[j - 1] > S[j]){
                tmp = S[j - 1];
                S[j - 1] = S[j];
                S[j] = tmp;
            }
        }
    }
}

int main()
{
    int n;  scanf("%d", &n);
    int S[n];
    int i;
    int sum = 0;

    for(i = 0; i < n; i++){
        scanf("%d", &S[i]);
        sum += S[i];
    }

    sort(n, S);

    i = 0;
    while(sum % 10 == 0){
        if(S[i] % 10 != 0){
            sum -= S[i];
        }
        i++;
        if(i == n){
            sum = 0;
            break;
        }
    }



    printf("%d\n", sum);

    return 0;
}

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

x, y = [int(x) for x in input().split()]
ans = 0

for i in [x, y]:
    if i == 1:
        ans += 300000
    elif i == 2:
        ans += 200000
    elif i == 3:
        ans += 100000
    
if x == 1 and y == 1:
    ans += 400000

print(ans)

    


Measured memory_bytes: 38384
#include<cstdio>
#include<algorithm>
#include<functional>
using namespace std;
const int maxn=1005;
int w[maxn],v[maxn];
int seq[4][maxn];
int main(){
  int n,m;scanf("%d%d",&n,&m);
  for(int i=1;i<=n;++i)scanf("%d%d",&w[i],&v[i]);
  int base=w[1];
  for(int i=1;i<=n;++i)w[i]-=base;
  for(int i=1;i<=n;++i){
    seq[w[i]][++seq[w[i]][0]]=v[i];
  }
  for(int i=0;i<4;++i){
    sort(seq[i]+1,seq[i]+seq[i][0]+1,greater<int>());
    for(int j=2;j<=seq[i][0];++j)seq[i][j]+=seq[i][j-1];
  }
  int ans=0;
  for(int i=0;i<=seq[0][0];++i){
    for(int j=0;j<=seq[1][0];++j){
      for(int k=0;k<=seq[2][0];++k){
	for(int l=0;l<=seq[3][0];++l){
	  if((i+j+k+l)*1ll*base+j+2*k+3*l<=m){
	    ans=max(ans,(i?seq[0][i]:0)+(j?seq[1][j]:0)+(k?seq[2][k]:0)+(l?seq[3][l]:0));
	  }
	}
      }
    }
  }
  printf("%d\n",ans);
  return 0;
}


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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const ll LINF = 1e18 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

int N;
typedef pair< ll, ll > P;

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

  cin >> N;
  vector< P > d(N + 1);
  REP(i, N) {
    CIN(a);
    d[i] = make_pair(a, i);
  }
  d[N] = make_pair(0, LINF);
  
  sort(ALL(d), [](P x, P y) {
      if (x.first == y.first) return x.second < y.second;
      return x.first > y.first;
    });

  /*
  REP(i, N) {
    debug(d[i].first);
    debug(d[i].second);
  }
  */
  
  int cnt, last;
  vector< ll > ans(N, 0ll);
  cnt = last = 0;
  ll mn = LINF;
  REP(i, N) {
    
    if (cnt == 0) {
      last = i;
      mn = min(mn, d[last].second);
    }
    // debug(last);
    
    if (d[i].first - d[i + 1].first == 0) {
      cnt++;
      // last = i;
    } else {
      ans[mn] += (d[last].first - d[i + 1].first) * (i + 1);
      cnt = 0;
    }
  }

  REP(i, N) {
    cout << ans[i] << endl;
  }
  
  return 0;
}



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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i=0 ; i<N ; i++)
    cin >> A.at(i);
  
  vector<int> height(N-1);
  for (int i=0 ; i<N-1 ; i++){
    if (A.at(i) > A.at(i+1)){
      height.at(i) = A.at(i) - A.at(i+1);
      A.at(i+1) = A.at(i);
    }
    else
      height.at(i) = 0;
  }
  
  long long s = 0;
  for (int i=0 ; i<N-1 ; i++)
    s += height.at(i);
  
  cout << s << endl;
}

Measured memory_bytes: 4796
#include <cstdio>
#include <iostream>
#include <queue>
#include <cstring>
#define maxn 100
using namespace std;
const int INF=0x3f3f3f3f;
char c[maxn][maxn];

int n,m;
struct node{
    int x,y;
};
node pre[maxn][maxn];
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
int vis[maxn][maxn];
int coun=0;
void bfs(){
    queue<node>que;
    memset(vis,INF,sizeof(vis));
    node s;
    s.x=0,s.y=0;
    vis[s.x][s.y]=1;
    que.push(s);
    while(!que.empty()){
        node p=que.front();
        que.pop();
        if(p.x==n-1&&p.y==m-1) break;
        for(int i=0;i<4;i++){
            int xx=p.x+dx[i];
            int yy=p.y+dy[i];
            if(xx>=0&&yy>=0&&xx<n&&yy<m&&vis[xx][yy]==INF&&c[xx][yy]=='.'){
                node now;
                now.x=xx,now.y=yy;
                que.push(now);
                pre[xx][yy]=p;
                vis[xx][yy]=vis[p.x][p.y]+1;
            }
        }
    }
    if(vis[n-1][m-1]==INF){
        puts("-1");
        return;
    }
    printf("%d\n",n*m-vis[n-1][m-1]-coun);
}
int main()
{

    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++){
        scanf("%s",c[i]);
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(c[i][j]=='#'){
                coun++;
            }
        }
    }
    bfs();
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
int main(void) {
	
	// ?????????????????\???
	int height;
	int width;
	scanf("%d",&height);
	scanf("%d",&width);
	
	// ??¢?????¨??¨???????¨????
	int area = height * width;
	int length = 2 * height + 2 * width;
	
	printf("%d %d\n",area,length);
	
	return 0;
}

Measured memory_bytes: 1716
t = gets.to_i
t.times{
  n = gets.to_i
  h = gets.split.map(&:to_i)
  d = []
  for x in 0...(n-1)
    d += [h[x+1]-h[x]]
  end
  d_max = d.max > 0 ? d.max.abs : 0
  d_min = d.min < 0 ? d.min.abs : 0
  puts [d_max, d_min].join(" ")
}

Measured memory_bytes: 6504