akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int n;
    cin >> n;

    vector<double> p(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }

    //全部でi枚のところに1枚加える
    vector<double> a(n + 1), b(n + 1);
    a[0] = 1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= i; j++) {
            b[j] = a[j] * (1 - p[i]);
        }
        b[i + 1] = 0;
        for (int j = 0; j <= i; j++) {
            b[j + 1] += a[j] * p[i];
        }
        swap(a, b);
    }

    double s = 0;
    for (int i = n / 2 + 1; i <= n; i++) {
        s += a[i];
    }

    cout << fixed << setprecision(12) << s << endl;

    return 0;
}

Measured memory_bytes: 384
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

use std::cmp::{max, min};
use std::collections::HashMap;

fn main() {
  let mut k = read::<i64>();
  let mut s = read::<i64>();
  let mut cnt = 0;

  for i in 0..k + 1 {
    for j in 0..k + 1 {
      if s - i - j <= k && 0 <= s - i - j {
        cnt += 1;
      }
    }
  }

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



Measured memory_bytes: 4476
#define _GIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(void) {
  int A, B;
  cin >> A >> B;

  int C;

  if (A == 1) {
    if (B == 2) {
      C = 3;
    } else {
      C = 2;
    }
  } else if (A == 2) {
    if (B == 1) {
      C = 3;
    } else {
      C = 1;
    }
  } else if (A == 3) {
    if (B == 1) {
      C = 2;
    } else {
      C = 1;
    }
  }

  cout << C << endl;
 
  return 0;
}

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

int main(void){

    int A, B;

    scanf("%d%d", &A, &B);

    int c = 0;

    for(int i = A; i <= B; i++){
        if(i / 10000 == i % 10 && (i / 1000) % 10 == (i / 10) % 10){
            c++;
        }
    }

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

    return 0;
}

Measured memory_bytes: 1728
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int W = sc.nextInt();
		int H = sc.nextInt();
		int N = sc.nextInt();
		int[][] cood = new int[N][3];
		for(int i = 0;i < N;++i) {
			cood[i][0] = sc.nextInt();
			cood[i][1] = sc.nextInt();
			cood[i][2] = sc.nextInt();
		}
		sc.close();
		
		boolean[][] square = new boolean[W][H];
		for(int x = 0;x < W;++x)
			for(int y = 0;y < H;++y)
				square[x][y] = true;

		for(int i = 0;i < N;++i) {
			switch(cood[i][2]) {
			case 1:
				for(int x = 0;x < cood[i][0];++x)
					for(int y = 0;y < H;++y)
						square[x][y] = false;
				break;
			case 2:
				for(int x = cood[i][0];x < W;++x)
					for(int y = 0;y < H;++y)
						square[x][y] = false;
				break;
			case 3:
				for(int x = 0;x < W;++x)
					for(int y = 0;y < cood[i][1];++y)
						square[x][y] = false;
				break;
			case 4:
				for(int x = 0;x < W;++x)
					for(int y = cood[i][1];y < H;++y)
						square[x][y] = false;
				break;
			}
		}
		int ans = 0;
		for(int x = 0;x < W;++x)
			for(int y = 0;y < H;++y)
				if(square[x][y])
					++ans;
		System.out.println(ans);
	}
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;
// vector<vector<int>> data(3, vector<int>(4));

void solve(long long N, vector<long long> A){
	ll res = 0;
	ll i = 0;
	rep(i, N) {
		// cout << i << endl;
		ll now = -1;
		for (ll j = i; j < N; j++) {
			if (j == N-1 || A[j] < A[j+1]) {
				now = max(now, j);
				break;
			}
		}
		for (ll j = i; j < N; j++) {
			if (j == N-1 || A[j] > A[j+1]) {
				now = max(now, j);
				break;
			}
		}
		if (now != -1) i = now;
		// cout << i << endl;
		res++;
	}
	cout << res << endl;
}

int main(){	
	long long N;
	scanf("%lld",&N);
	vector<long long> A(N-1+1);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&A[i]);
	}
	solve(N, A);
	return 0;
}



Measured memory_bytes: 1792
#include <functional>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <string>
#include <cstring>
#include <math.h>
using namespace std;

int main() {
  
   string n;

   cin >> n;
  
   int max = 0;
   
   for(int i = 0;i<n.size();i++){
     
    
     if(n[i]!='A'&&n[i]!='C'&&n[i]!='G'&&n[i]!='T'){
     //  cout << max << endl;
       continue;
     }
     
     int sum = 1;
     
     //cout << sum << endl;
     
     for(int j = i+1;j<n.size();j++){
       
          if(n[j]!='A'&&n[j]!='C'&&n[j]!='G'&&n[j]!='T'){
       
            break;
          }
       
       sum++;
     }
     
     if(sum>max){
       
       max = sum;
     }
     
     
     
   }
  
   cout << max << endl;
   
   
  
   
  
  return 0;
}

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

int main(){
	int n, x, y, z, r;
	while( cin >> z >> x >> y, x||y||z ){
		cin >> n;
		int i=0;
		for( i=0; i<n; i++ ){
			cin >> r;
			int l = min( x*x+y*y, y*y+z*z );
			l = min( l, z*z+x*x );
			cout << ((4*r*r>l)?"OK":"NA") << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include<algorithm>
#include <stdio.h>
#include <map>
#include <random>
#include <string>
#include<vector>

using namespace std;
int main() {
	int k,s;
	int count = 0;
	int z;
	
	cin >> k>>s;
	for (int i = 0; i <= k; i++) {
		
		for (int j = 0; j <= k; j++) {
			
				z = s - i - j ;
				if (z >= 0 && z <= k) {
					count++;
				}
			
		}
	}

	
	cout << count;

	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  ll sum = min(k, a);
  k -= a;
  k -= b;
  if(k > 0) sum -= k;
  cout << sum << endl;
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define contains(v, t) (find(v.begin(), v.end(), t) != v.end())
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;

int main() {
  int n;
  cin >> n;
  map<string, ll> m;
  rep(i, n) {
    string t;
    cin >> t;
    sort(t.begin(), t.end());
    m[t]++;
  }
  ll ans = 0;
  for(auto itr : m) {
    // cout << itr.first << " " << itr.second << endl;
    if (itr.second > 1) {
      ans += (itr.second * (itr.second - 1)) / 2;
    }
  }
  cout << ans;
}


Measured memory_bytes: 11136
K = int(input())
if K%2 == 0 or K%5 == 0:
    print(-1)
    exit()
temp = 7%K
for i in range(1,10**6):
    if temp%K == 0:
        print(i)
        exit()
    temp += 7*pow(10,i,K)

print(-1)
exit()

Measured memory_bytes: 63348
/**
* 氏名: 阿部寛之
* 学籍番号: 170441004
***/


#include<stdio.h>

int main(void)
{
	int a, b;
	scanf("%d %d", &a, &b);

	if (a < b)
	{
		printf("a < b\n");
	}
	else if (a > b)
	{
		printf("a > b\n");
	}
	else if (a == b)
	{
	
		printf("a == b\n");
		
	}
	return 0;
}


Measured memory_bytes: 2064
#include<iostream>
#include<cstdio>
#include<algorithm>
#define N 1000
using namespace std;
long long f[N][N];
int g[N][N];
struct node{
	int x,y,z;
}e[N*N];
int n,tot;
bool cmp(const node&a,const node&b){
	return a.z<b.z;
}
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
		for (int j=1;j<=n;j++){
			int x;
			scanf("%d",&x);
			g[i][j]=x;
			if (i<j)e[++tot].x=i,e[tot].y=j,e[tot].z=x;
		}
	sort(e+1,e+tot+1,cmp);
	long long ans=0;
	for (int i=1;i<=tot;i++)
		if (!f[e[i].x][e[i].y]||f[e[i].x][e[i].y]>e[i].z){
			f[e[i].x][e[i].y]=f[e[i].y][e[i].x]=e[i].z;
			ans+=e[i].z;
			for (int j=1;j<=n;j++)
				if (f[j][e[i].x]||j==e[i].x)
					for (int k=1;k<=n;k++)
						if (j!=k&&(f[e[i].y][k]||k==e[i].y)&&(!f[j][k]||f[j][k]>f[j][e[i].x]+f[e[i].y][k]+e[i].z))f[j][k]=f[k][j]=f[j][e[i].x]+f[e[i].y][k]+e[i].z;
		}
	bool bz=1;
	for (int i=1;i<=n;i++)
		for (int j=1;j<=n;j++)
			if (f[i][j]!=g[i][j])bz=0;
	if (bz)cout<<ans;
	else
		printf("-1");
	return 0;
}

Measured memory_bytes: 8960
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;

#define rep(i,a,b) for(auto (i)=a;i<b;i++)
#define list(i,N) for(auto (i)=0;i<N;i++)

typedef long long ll;

#define int ll
#define INF 1e9+5
#undef int
int main(){

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

#define int ll
	int N; cin >> N;
	int K; K = 2;
	int H[N]; list(i,N) cin >> H[i];
	int dp[N];
	list(i,N) dp[i]=INF;
	dp[0]=0;
	list(i,N){
		for(int j=i+1;j<=i+K;j++) dp[j] = min(dp[i]+abs(H[i]-H[j]),dp[j]);
	}
	cout << dp[N-1];
	return 0;
}


Measured memory_bytes: 1792
n=map(int,input().split()) #nは10**5だから全探索はできない

a=list(map(int,input().split()))
a.sort()
checked=[0]*(a[-1]+1)
cnt=0



for j,aa in enumerate(a):
    if checked[aa]==0:
        i=1
        if j+1<len(a) and aa==a[j+1]:
            cnt+=0
        else:
            cnt+=1
        
        

        #print(aa)
        while aa*i<a[-1]+1:
            checked[aa*i]=1
            i+=1
#print(checked)
#print(a)
print(cnt)




Measured memory_bytes: 117036
#include<bits/stdc++.h>
 
#define lol long long
#define gcd(x,y) __gcd(x,y)
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define fixed fixed<<setprecision(14)
using namespace std;
using pii=pair<int,int>;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
template <class A> inline lol abs(A &a) { return (a < 0 ? -a : a); }
bool inLine(int x,int y,int mx,int my){return (x>=0&&y>=0&&x<mx&&y<my);}
const lol inf=(1LL<<62);
const lol MOD=(1e9)+7;
const lol mod=998244353;
const int dx[]={1,0,-1,0,1,1,-1,-1};
const int dy[]={0,1,0,-1,1,-1,1,-1};
lol n,m,k,r;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  char a;
  cin>>a;
  if(a<'a') cout <<"A\n";
  else cout <<"a\n";
  return (0);
}

Measured memory_bytes: 3568
using System;
using System.Linq;
using System.Collections.Generic;
class P
{
    static void Main()
    {
        long[] XY = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        int count = 0;
        long num = XY[0];
        while (num <= XY[1])
        {
            num *= 2;
            count++;
        }
        Console.WriteLine(count);
    }
}

Measured memory_bytes: 13396
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int bit = 0;
    
    for(int i=0; i<n; i++){
      bit |= sc.nextInt();
    }
    
    System.out.println(Integer.numberOfTrailingZeros(bit));
    }
}


Measured memory_bytes: 21844
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main(){
  ll a,b;
  cin>>a>>b;
  ll c,d;
  cin>>c>>d;
  cout << c-a << endl;
  return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <math.h>

int main(void){
	int n,a,MIN=1000000,MAX=-1000000;
	long long sum=0;

	scanf("%d",&n);
	for(int i=0;i<n;i++)
{
		scanf("%d",&a);

    	if(a<MIN)  MIN=a;
	if(a>MAX)  MAX=a;
	sum+=a;
	}
	printf("%d %d %lld\n",MIN,MAX,sum);
	return 0;
}



Measured memory_bytes: 2108
#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

void solve()
{
	string str;
	getline(cin, str);
	for(int i = 0; i < str.size(); ++i)
	{
		printf("%c", toupper(str[i]));
	}
	cout << endl;
}

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

Measured memory_bytes: 0
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int num;
    double weight,height;
    while(scanf("%d,%lf,%lf",&num,&weight,&height)!=EOF)if(25<=weight/height/height)cout<<num<<endl;
    return 0;
}

Measured memory_bytes: 1228
N = int(input())
mod = int(1e+9 + 7)

options = ["A", "C", "G", "T"]
dp = [{options[i] + options[j] + options[k]: 0 for i in range(len(options)) for j in range(len(options)) for k in range(len(options))} for _ in range(N+1)]
keys = list(dp[0].keys())

dp[0]["TTT"] = 1

for i in range(N):
    for key in keys:
        for option in options:
            if key[1] == "A" and key[2] == "G" and option == "C":
                continue
            if key[0] == "A" and key[2] == "G" and option == "C":
                continue
            if key[1] == "G" and key[2] == "A" and option == "C":
                continue
            if key[1] == "A" and key[2] == "C" and option == "G":
                continue
            if key[0] == "A" and key[1] == "G" and option == "C":
                continue
            
            dp[i+1][key[1:3] + option] += dp[i][key]
            dp[i+1][key[1:3] + option] = dp[i+1][key[1:3] + option] % mod

print(sum(list(dp[-1].values()))%mod)

Measured memory_bytes: 77300
from sys import stdin

data = [int(stdin.readline().rstrip()) for _ in range(5)]
k = int(stdin.readline().rstrip())

isOK = True

for i in range(5):
    for j in range(i+1, 5):
        if abs(data[i] - data[j]) > k:
            isOK = False

if isOK:
    print("Yay!")
else:
    print(":(")


Measured memory_bytes: 38384
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    String b = sc.next();
    
    if (b.equals("A")) {
      System.out.println("T");
    }
    if (b.equals("T")) {
      System.out.println("A");
    }
    if (b.equals("C")) {
      System.out.println("G");
    }
    if (b.equals("G")) {
      System.out.println("C");
    }
  }
}

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

const int INF = 1001001001;

int main()
{
    int n, m;
    cin >> n >> m;
    vector<pair<int, int> > key;
    rep(i, m){
        int a, b;
        cin >> a >> b;
        int s = 0;
        rep(j,b){
            int c;
            cin >> c;
            --c;
            s |= 1<<c;
        }
        key.push_back(make_pair(s,a));
    }

    vector<int> dp(1<<n, INF);
    dp[0] = 0;
    rep(s, 1<<n){
        rep(i, m){
            int t = s | key[i].first;
            int cost = dp[s] + key[i].second;
            dp[t] =  min(dp[t],cost);
        }
    }

    int ans = dp.back();
    if(ans == INF) ans = -1;
    cout << ans << endl;
}

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

public class AtCoder_159_B
{
    public static void Main()
    {
        string str = Console.ReadLine();

        int n1 = str.Length;
        for (int i = 0; i < n1; i++)
        {
            if (str[i] != str[n1 - 1 - i])
            {
                Console.WriteLine("No");
                return;
            }
        }

        int n2 = (str.Length - 1) / 2;
        for (int i = 0; i < n2; i++)
        {
            if (str[i] != str[n2 - 1 - i])
            {
                Console.WriteLine("No");
                return;
            }
        }

        int n3 = (str.Length + 3) / 2;
        for (int i = n3 - 1; i < n1; i++)
        {
            if (str[i] != str[n1 - 1 - (i - n3) - 1])
            {
                Console.WriteLine("No");
                return;
            }
        }

        Console.WriteLine("Yes");
    }
}


Measured memory_bytes: 13140
#include<algorithm>
#include<iomanip>
#include<iostream>
#define ll long long
using namespace std;
int n;
int p[200020];
long double ans;
int main(){
	ios::sync_with_stdio(false);
	cin>>n;n*=2;
	for (int i=0;i<n;++i) cin>>p[i];sort(p,p+n);
	for (int i=0;i<n;++i) ans+=(long double)(p[i])/(long double)(n-1)*i;
	cout<<fixed<<setprecision(12)<<ans<<endl;
	return 0;
}

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

#define rep(i, s, n) for (Int i = s; i < (Int)(n); i++)
#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
 
double EPS = 1e-10;
Int INF = 1e18;
int inf = 1e9;
Int mod = 1e9+7;

int main() {
    while (true) {
        string s;
        Int a, b, c;
        cin >> s;
        if (s == "#") break;
        cin >> a >> b >> c;
        if (a > 31) {
            a -= 30;
            s = "?";
        } else if (a == 31) {
            if (b >= 5) {
                a -= 30;
                s = "?";
            }
        }
        cout << s << " " << a << " " << b << " " << c << endl;
    }
    return 0;
}


Measured memory_bytes: 3144
#include <iostream>
#include <string>
 
using namespace std;
 
int main()
{
  int H,W;
  cin >> H >> W;
  string S[H];
  for(int i = 0; i < H; ++i) cin >> S[i];
  int neig[8][2] = {{-1,-1},
		 {0,-1},
		 {1,-1},
		 {-1,0},
		 {1,0},
		 {-1,1},
		 {0,1},
		 {1,1}};
 
  int l = 1;
  for(int i = 0; i < H; ++i){
    for(int j = 0; j < W; ++j){
      if(S[i][j]=='.'){
        int bombcount=0;
       	for(int z=0;z<8;++z){
          int y=i+neig[z][0];
          int x=j+neig[z][1];
          if(x>=0&&y>=0&&x<W&&y<H){
           	if(S[y][x]=='#'){
             	bombcount++; 
            }
          }
        }
        string cout= to_string(bombcount);
        S[i][j]=cout[0];
      }
    }
  }
  for(int i = 0; i < H; ++i) cout<< S[i]<< '\n';
}

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

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    
    string s;
    string t;
    cin >> s;
    cin >> t;
    int cnt = 0;
    for (int i = 0; i < 3; i++) {
        if (s[i] == t[i]) {
            cnt ++;
        }
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
n,k = gets.split.map(&:to_i)
num = gets.split.map(&:to_i)
check = 0
ans = 0
res = 0
47.downto(0){|i|
  next if ans+2**i > k
  check = num.count{|j| j[i] != 0}
  ans += 2**i if check*2 < n
}
n.times{|i| res += ans ^ num[i]}
puts res


Measured memory_bytes: 8836
<?php

fscanf(STDIN, "%d%d", $h, $n);

$magic_list = [];
for ($i = 0; $i < $n; ++$i) {
    fscanf(STDIN, "%d%d", $a, $b);
    $magic_list[] = [
        'damage' => $a,
        'pp'     => $b
    ];
}

$min_pp_to_reduce_hp = [];
$max_damage = max(array_column($magic_list, 'damage'));
for ($hp = 1; $hp < $h + $max_damage; ++$hp) {
    $min_pp = null;

    foreach ($magic_list as $magic) {
        $remain_hp = $hp - $magic['damage'];
        $pp = $remain_hp <= 0 ? $magic['pp'] : $magic['pp'] + $min_pp_to_reduce_hp[$remain_hp];
        if (!isset($min_pp) || $pp < $min_pp) {
            $min_pp = $pp;
        }
    }

    $min_pp_to_reduce_hp[$hp] = $min_pp;
}

$pp_to_defeat = array_slice($min_pp_to_reduce_hp, $h - 1);
echo min($pp_to_defeat);


Measured memory_bytes: 4728
#include <cstdio>
#include <algorithm>

constexpr int MAX_N = 100, MAX_vw = 1000, MAX_W = 10000;

int N, W;
int v[MAX_N], w[MAX_W];
int dp[MAX_N + 1][MAX_W + 1];

void solve();

int main(){
    scanf("%d%d", &N, &W);
    for(int i = 0; i < N; ++i){
        scanf("%d%d", &v[i], &w[i]);
    }
    solve();
}

void solve(){
    for(int i = 0; i < N; ++i){
        for(int j = 0; j <= W; ++j){
            if(j < w[i]){
                dp[i + 1][j] = dp[i][j];
            }
            else{
                dp[i + 1][j] = std::max(dp[i][j], dp[i + 1][j - w[i]] + v[i]);
            }
        }
    }
    printf("%d\n", dp[N][W]);
}

Measured memory_bytes: 6664
import java.util.Scanner;
class Main{
 public static void main(String args[]){
Scanner sc=new Scanner(System.in);
int N= sc.nextInt();
int M= sc.nextInt();
int gcd=1;
for(int n=M/N;n>=1;n--) {
   if(M%n==0) {
	if(n*N<=M) {
	gcd=n;
	break;
	 }
    }	
 }
System.out.println(gcd);
 }
  }


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

int main(){
  long long N,K;
  cin >> N >> K;
  vector<long long> P(N),C(N);
  for(int i=0;i<N;i++){
    cin >> P[i];
    P[i]--;
  }
  for(int i=0;i<N;i++) cin >> C[i];
  
  long long ans=C[0];
  for(int i=0;i<N;i++){
    long long cnt=1,now=i,score=C[i];
    
    while(K>cnt){
      ans = max(ans,score);
      if(P[now] == i) break;
      cnt++;
      now = P[now];
      score += C[now];
    }
    ans = max(ans,score);
    
    long long left = K;
    if(left%cnt!=0 || left==cnt){
      score *= K/cnt;
      left %= cnt;
    }
    else{
      score *= K/cnt - 1;
      left = cnt;
    }
    cnt = 0;
    
    while(left>cnt){
      ans = max(ans,score);
      cnt++;
      now = P[now];
      score += C[now];
    }
    ans = max(ans,score);
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3680
//Atcoder ABC147 B

import java.util.Scanner;

public class Main {

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

		char S[] = sc.next().toCharArray();
		int length = S.length;
		char c =' ';
		char d =' ';
		int cnt = 0;

		for(int i=0;i<length/2;i++) {
			c = S[i];
			d = S[length-i-1];
			if(c!=d) {
				cnt++;
			}
		}
		System.out.println(cnt);
	}

}


Measured memory_bytes: 23764
count = 0


def main():
    input()
    A = [int(x) for x in list(input().split())]
    merge_sort(A, 0, len(A))
    print(*A)
    print(count)


def merge_sort(A, left, right):
    if left+1 < right:
        mid = (left + right) // 2
        merge_sort(A, left, mid)
        merge_sort(A, mid, right)
        merge(A, left, mid, right)


def merge(A, left, mid, right):
    global count
    n1 = mid - left
    n2 = right - mid

    # リストの左側を作成
    L = A[left:mid]

    # リストの右側を作成
    R = A[mid:right]

    # 終端追加
    L.append(float("inf"))
    R.append(float("inf"))

    i = 0
    j = 0
    for k in range(left, right):
        count += 1
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1


if __name__ == '__main__':
    main()



Measured memory_bytes: 63928
import sys
sys.setrecursionlimit(1000000)
from math import factorial, ceil, floor
from bisect import bisect_right as bsr
from operator import itemgetter as ig
from collections import defaultdict as dd
from collections import deque, Counter as cnt

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)
def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]
def nlist(n, v):
    if not n: return v.copy()
    return [nlist(n[1:], v) for _ in range(n[0])]

# バイナリインデックス木
class BIT:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
    def sum(self, i):
        s = 0
        while 0 < i:
            s += self.tree[i]
            s %= MOD
            i -= i & -i
        return s
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

# エントリーポイント
def main():
    N, K = input(int, int)
    A = input([int, N])

    MAX = 2010
    bit = BIT(MAX)
    # 最終周をカウントする
    sum1 = []
    for i, a in enumerate(A, start=1):
        bit.add(a, 1)
        sum1.append(i - bit.sum(a))
    # 繰り返し周をカウントする
    sum2 = []
    for a in A:
        sum2.append(N - bit.sum(a))
    # (1 + (K - 1))回分を集計する
    ans = 0
    for v1, v2 in zip(sum1, sum2):
        ans += K * v1 + ((K * (K - 1)) // 2) * v2
        ans %= MOD
    print(ans)

if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()


Measured memory_bytes: 3688
n,k = map(int,input().split())
A = list(map(int,input().split()))
mod = 10**9+7
plus = []
minus=[]
for i in A:
    if i>=0:
        plus.append(i)
    else:
        minus.append(i)
ok = False
if len(plus)>0:
    if n==k:
        ok = (len(minus)%2==0)
    else:
        ok = True
else:
    ok = (k%2==0)
ans = 1
if not ok:
    A.sort(key=abs)
    for i in range(k):
        ans *= A[i]
        ans %= mod
else:
    plus.sort()
    minus.sort(reverse=True)
    if k%2 == 1:
        ans *= plus.pop()
    P = []
    while len(plus) >= 2:
        P.append((plus.pop())*(plus.pop()))
    while len(minus) >= 2:
        P.append((minus.pop())*(minus.pop()))
    P.sort(reverse=True)
    for i in range(k//2):
        ans *= P[i]
        ans %= mod
print(ans)


Measured memory_bytes: 31944
import java.io.IOException;
import java.util.NoSuchElementException;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            FastScanner fs = new FastScanner();

            final int H = fs.nextInt();
            final int W = fs.nextInt();

            for (int i = 0; i < H; i++) {
                String C = fs.next();
                System.out.println(C);
                System.out.println(C);
            }
        }
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() {
        if (hasNextByte()) return buffer[ptr++];
        else return -1;
    }
    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
        while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
        return hasNextByte();
    }
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if(b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


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

using namespace std;

int main(void)  {

  int n;
  int temp;
  int divmin;
	vector<int> a;
  
  while (true)  {
    
    scanf("%d", &n);
    
    if (n == 0) { break; }
    
    divmin = 1000000;
    
    for (int i = 0; i <= n-1; i++)  {
      cin >> temp;
    	a.push_back(temp);
    }

  	sort(a.begin(), a.end());

  	for (int i = 1; i <= n-1; i++)	{
  		divmin = min(divmin, a[i] - a[i-1]);
  	}
    
    printf("%d\n", divmin);

  	vector<int>().swap(a);
  }
  
  return 0;
}


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

template<typename T>
void trace(T *a, int s, int n) {
    for (int i=s; i<n; i++) {
	cout<<a[i]<<" ";
    }
    cout<<endl;
}



typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 1e6 + 5;
const int inf = 1e9;

int n, m;
vector<int> digits;
int maxlen[maxn]; //max length when using i sticks


void relax(int& x, int y) {
    x=max(x,y);
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    int cost[10]={0,2,5,5,4,5,6,3,7,6};

    cin>>n>>m;

    for (int i=0; i<m; i++) {
	int d; cin>>d;
	digits.push_back(d);
    }

    for (int i=0; i<=n; i++) {
	maxlen[i]=-inf;
    }
    maxlen[0]=0;

    
    for (int i=0; i<=n; i++) {
	for (int d: digits) {
	    if (cost[d]+i>n) continue;
	    relax(maxlen[i+cost[d]], maxlen[i]+1);
	}
    }

    int have = n;
    string res="";
    
    while (have>0) {
	int x=0;
	for (int d: digits) {
	    if (cost[d]>have) continue;
	    if (maxlen[have-cost[d]]+1 == maxlen[have]) {
		x=max(x, d);
	    }
	}

	have -= cost[x];
	res += char('0'+x);
    }

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


Measured memory_bytes: 256
#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 pii=pair<int,int>;
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(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int 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 S>S acm(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));}

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;}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
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>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}
mt19937 _mt(chrono::steady_clock::now().time_since_epoch().count());
ll getrnd(ll l,ll r){return uniform_int_distribution<ll>(l,r-1)(_mt);}
/*
#define _cTime (chrono::system_clock::now())
#define progress (chrono::duration_cast<chrono::milliseconds>(_cTime-_sTime).count())
#define reset _sTime=_cTime
auto reset;
*/

vl fact, finv;
ll mdpow(ll x, ll k) { 
	ll res = 1;
	while (k != 0) {
		if (k & 1) res = res*x % MOD;
		x = x*x % MOD;
		k = k >> 1;
	}
	return res;
}
ll comb(ll n, ll k) {
	if (n == 0 && k == 0)return 1;
	if (n < k || n < 0)return 0;
	return fact[n] * finv[n - k] % MOD * finv[k] % MOD;
}

struct ferm{
	ferm(ll n){
		fact.resize(n);
		finv.resize(n);
		fact[0] = 1;
		finv[0] = 1;
		rep (i,n-1) {
			fact[i + 1] = (fact[i] * (i + 1)) % MOD;
			finv[i + 1] = mdpow(fact[i + 1], MOD-2);
		}
	}
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vl v(n),sum(n);;
	rep(i,n)cin>>v[i];
	ferm(100002);
	rep(i,n){
		if(i)sum[i]=sum[i-1];
		sum[i]+=(fact[n]*mdpow((i+1),MOD-2))%MOD;
	}
	ll ans=0;
	rep(i,n){
		ll tmp=sum[i]+sum[n-i-1]-sum[0];tmp%=MOD;
		ans+=tmp*v[i];ans%=MOD;
	}
	cout<<ans<<endl;
}



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

int main() {
    int n; cin >> n;
    string s; cin >> s;
    int cnt = 0;
    for (int i = 0; i + 1 < n; i++) {
        if (s[i] != s[i + 1]) cnt++, i++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3348
#include<bits/stdc++.h>
#define title "title"
#define ll long long
#define ull unsigned ll
#define fix(x) fixed<<setprecision(x)
#define pii pair<int,int>
#define vint vector<int>
#define pb push_back
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define red(i,a,b) for(int i=(a);i>=(b);i--)
#define db double
#define ld long db
using namespace std;
void Freopen(){
	freopen(title".in","r",stdin);
	freopen(title".out","w",stdout);
}
ll read(){
	ll g=0,f=1;
	char ch=getchar();
	while(ch<'0'||'9'<ch){if(ch=='-')f=-1;ch=getchar();}
	while('0'<=ch&&ch<='9'){g=g*10+ch-'0';ch=getchar();}
	return g*f;
}
const int N=1e3+5;
int n,cnt;
ll x[N],y[N],len[N];
signed main(){
	//freopen("a","r",stdin);
	n=read();rep(i,1,n)x[i]=read(),y[i]=read();
	int re=abs(x[1]+y[1])&1;
	rep(i,2,n)if((abs(x[i]+y[i])&1)^re)return cout<<-1,signed();
	cout<<32-re<<'\n'<<1<<' ';len[++cnt]=1;
	if(re){rep(i,1,30)cout<<(len[++cnt]=(1<<i))<<' ';cout<<'\n';}
	else{rep(i,0,30)cout<<(len[++cnt]=(1<<i))<<' ';cout<<'\n';}
	rep(i,1,n){
		ll nx=0,ny=0;string s="";
		red(j,cnt,1){
			ll dx=x[i]-nx,dy=y[i]-ny;
			if(abs(dx)>abs(dy)){
				if(dx>0)nx+=len[j],s+='R';
				else nx-=len[j],s+='L';
			}else{
				if(dy>0)ny+=len[j],s+='U';
				else ny-=len[j],s+='D';
			}
		}reverse(s.begin(),s.end());cout<<s<<'\n';
	}return signed();
}

Measured memory_bytes: 3644
/**
 *    author:  dflmkwr
 */

#include <iostream>
#include <cmath>

using namespace std;

struct Point {
  double x, y;
  double s;
} P[200003];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, cnt = 0;
  double d;
  cin >> n >> d;
  for (int i = 0; i < n; i++) {
    cin >> P[i].x >> P[i].y;
    P[i].s = sqrt(pow(P[i].x, 2) + pow(P[i].y, 2));
  }
  for (int i = 0; i < n; i++)
    if (d - P[i].s >= 0) cnt++;
  cout << cnt << "\n";
  return 0;
}


Measured memory_bytes: 8452
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <bitset>
#include<iomanip>//小数点以下を精度良く表示

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define INF 2000000000
#define INF2 1000000000000000000
#define rep(i,n) for(int i=0;i<(n);i++)
typedef pair<string, string> P;
const ll MOD=1000000007;
using Graph = vector<vector<int>>;


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;
}
int up(int a, int b) {
    return (a + a % b) / b;
}

int main(){
    string s;
    cin >> s;
    int data[200] = {0};
    for (int i = 0; i < s.length(); i++) {
        data[s[i]]++;
    }
    for (int i = 0; i < s.length(); i++) {
        if (data[s[i]] % 2 != 0) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF = 1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define trep(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(), (x).end()
int main()
{
    lint a = 0;
    lint b = 0;
    int n;
    cin >> n;
    vi v(n);
    vector<lint> s(n);
    rep(i, n)
    {
        cin >> v[i];
    }
    s[0] = v[0];
    rep(i, n) //0番目を正と仮定
    {
        if (i > 0)
        {
            s[i] = s[i - 1] + v[i];
        }
        if (i % 2 == 0)
        {
            if (s[i] <= 0)
            {
                a += 1 - s[i];
                s[i] = 1;
            }
        }
        else
        {
            if (s[i] >= 0)
            {
                a += s[i] + 1;
                s[i] = -1;
            }
        }
        
    }
    s[0] = v[0];
    rep(i, n) //0番目を負と仮定
    {
        if (i > 0)
        {
            s[i] = s[i - 1] + v[i];
        }
        if (i % 2 == 0)
        {
            if (s[i] >= 0)
            {
                b += s[i] + 1;
                s[i] = -1;
            }
        }
        else
        {
            if (s[i] <= 0)
            {
                b += 1 - s[i];
                s[i] = 1;
            }
        }
    }
    cout << min(a, b) << endl;
    return 0;
}

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

using namespace std;

typedef long long int llint;

int main() {
	int K, N;
	cin >> K >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	int m = A[0] + (K - A[N - 1]);
	for (int i = 1; i < N; i++) {
		m = max(A[i] - A[i - 1], m);
	}
	cout << K - m << endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Solve s= new Solve();
		s.solve();

	}

}

class Solve{
	 Scanner sc = new Scanner(System.in) ;

	 void solve() {

		 double w = sc.nextDouble();
		 double h = sc.nextDouble();
		 double x = sc.nextDouble();
		 double y = sc.nextDouble();

		double res=w*h/2;
		int ans=0;
		if(w/2==x&&h/2==y) {
			ans=1;
		}
		System.out.print(String.format("%.6f", res));
		System.out.println(" "+ans);




	 }
	 }

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

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

int main(){
	int W,H,C;
	cin>>W>>H>>C;
	
	int sq=0;
	
	sq=W/gcd(W,H);
	sq*=H/gcd(W,H);
	
	cout<<sq*C<<endl;
	
	return 0;
}

Measured memory_bytes: 3100
n = int(input())
h = [int(i) for i in input().split()]

h_unique = list(set(h))
#print(h_unique)

check = [1] + [0]*(n) + [1]
h = [-1] + h + [-1]
ans = 0
split = 0
for i in range(max(h)):
  if i in h_unique:
    for j in range(len(h)):
      if h[j] == i:
        check[j] = 1
        if check[j-1] == 0 and check[j+1] == 0:
          split += 1
        elif check[j-1] == 1 and check[j+1] == 1:
          split -= 1
  ans += split+1
  #print(split)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using boost::multiprecision::cpp_int;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ll,pair<ll, ll>> lpll;
typedef pair<ll, int> pli;
typedef pair<int, int> pii;

#define deg_to_rad(deg) (((deg)/360)*2*PI)

const ll LINF = LLONG_MAX;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;

const ld PI = (acos(-1));
const ld EPS = 0.0000000001;
// cout << fixed << setprecision(10) << middle << endl;

int main() {
    // input, ready
    int N;
    cin >> N;
    // output
    if (N%1000==0) cout << 0 << endl;
    else cout << 1000-N%1000 << endl;

    return 0;
}


Measured memory_bytes: 3632
using System;
using System.Collections.Generic;
using System.Text;
using static System.Math;
using static System.Console;

namespace AtTest.D_Challenge
{
    class ABC_035
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int[] ks=ReadInts();
            int k=ks[0];
            int s=ks[1];
            int res=0;
            for(int i=0;i<=k;i++)
            {
                for(int j=0;j<=k;j++)
                {
                    if(i+j<=s&&s-i-j<=k)
                    {
                        res++;
                    }
                }
            }
            WriteLine(res);
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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

int main()
{
  int N;
  cin >> N;
  
  int A[N];
  int count = 0;
  for(int i = 0; i < N; i++)
  {
    cin >> A[i];
  }
  
  bool loop = true;
  while(loop)
  {
    for(int i = 0; i < N; i++)
    {
      if(A[i] % 2 != 0)
      {
        loop = false;
        break;
      }
      else
        A[i] /= 2;
    }
    
    if(loop)
      count++;
  }
  
  cout << count << endl;
}

Measured memory_bytes: 256
def dfs(fld, check, n, m, depth)
  ok = true
  n.times do |r|
    m.times do |c|
      if check[r][c] == depth && fld[r][c] == '*'
        q = []
        mem = n.times.map{ [] }
        check[r][c] = depth + 1
        q << [r, c]
        mem[r] << c
        until q.empty?
          r, c = q.shift
          (-1..1).each do |yy|
            (-1..1).each do |xx|
              next if yy == 0 && xx == 0
              y = r + yy; x = c + xx
              if check[y][x] != depth + 1 && fld[y][x] == '*'
                check[y][x] = depth + 1
                q << [y, x]
                mem[y] << x
              end
            end
          end
        end
        a = 0; h = -1
        mem.each_with_index do |m, i|
          if m.size > 2
            a += m.size
            h == -1 ? h = i : h = i - h + 1
          elsif m.size == 2
            m[0], m[1] = m[1], m[0] if m[0] > m[1]
            (m[0]+1...m[1]).each{ |k| check[i][k] = depth + 2 }
          end
        end
        s = a * h / 2
        $ret[s] ||= 0
        $ret[s] += 1
        ok = false
      end
    end
  end
  return true if ok
  return true if dfs(fld, check, n, m, depth + 2)
end

l = false
while n = gets.to_i
  break if n == 0
  if l
    10.times{ print '-' }
    puts
  end
  l = true
  fld = n.times.map{ gets.chomp.split('').unshift(' ').push(' ') }
  m = fld.map{ |f| f.size }.max
  fld.each{ |f| (m - f.size).times{ f.push(' ') } }
  fld = [ [' '] * m, *fld, [' '] * m ]
  $ret = {}
  check = (n+2).times.map{ [0] * m }
  dfs(fld, check, n+2, m, 0)
  $ret.sort.each{ |k, v| puts "#{k} #{v}" }
end

Measured memory_bytes: 10132
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func vi(n int, args ...int) []int {
	res := make([]int, n)
	if len(args) == 0 {
		return res
	}
	v := args[0]
	if v == 0 {
		return res
	}
	for i := 0; i < n; i++ {
		res[i] = v
	}
	return res
}

func vvi(n int, args ...int) [][]int {
	res := make([][]int, n)
	m := n
	if len(args) > 0 {
		m = args[0]
	}
	v := 0
	if len(args) > 1 {
		v = args[1]
	}
	for i := 0; i < n; i++ {
		res[i] = vi(m, v)
	}
	return res
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

func sn(n int64) int64 {
	ans := int64(0)
	for n > 0 {
		ans += n % 10
		n /= 10
	}
	return ans
}

func nsn(n int64) float64 {
	return float64(n) / float64(sn(n))
}

func main() {
	defer stdout.Flush()

	k := readInt()
	x := int64(1)
	d := int64(1)
	for i := 1; i <= k; i++ {
		println(x)
		if nsn(x+10*d) < nsn(x+d) {
			d *= 10
		}
		x += d
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
    
int main(){
    int n,m;
    cin >> n >> m;
    int cnt = 0;
    int sum = 0;
    vector <int> a(n);
    rep(i,n){
        cin >> a[i];
        sum +=  a[i];
    }
    rep(i,n){
        if(a[i]*4*m >= sum){
            cnt ++;
        }
    }
    if(cnt >= m) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3628
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int H = sc.nextInt();
    int A = sc.nextInt();
    int ans = 0;
    for (int i=1;H>0;i++){
      H -= A;
      ans = i;
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 22996
import sys, re
from math import ceil, floor, sqrt, pi, factorial#, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    a, b = i_map()

    if a > b:
        a-= 1

    print(a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 59372