akhauriyash/Code-Regression huggingface dataset:
import bisect
N,Q=map(int,input().split())
road=[]
pos=[]
for _ in range(N):
    s,t,x=map(int,input().split())
    road.append((s-x,t-x,x))
for _ in range(Q):
    pos.append(int(input()))
road.sort(key=lambda x:x[2])
ans=[-1]*Q
ischecked=[-1]*Q
for s,t,x in road:
    l=bisect.bisect_left(pos,s)
    r=bisect.bisect_left(pos,t)
    while l<r:
        if ischecked[l]==-1:
            ischecked[l]=r
            ans[l]=x
            l+=1
        else:
            l=ischecked[l]
for i in range(Q):
    print(ans[i])

Measured memory_bytes: 53964
//package beginner164.a;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(long testNumber, InputReader in, PrintWriter out) {
            int sheep = in.nextInt();
            int wolves = in.nextInt();
            if (wolves >= sheep) {
                out.println("unsafe");
            } else {
                out.println("safe");
            }
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}

Measured memory_bytes: 25588
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
  int n; cin >> n;
  vector<int>p(n);
  int sum = 0;
  for(int i = 0;i < n;i++){
    cin >> p[i];
    sum += p[i];
  }
  int max = *max_element(p.begin(),p.end());
  cout << sum - max/2 << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 100

int main(){
  int i,j,n,u,k,v,a[N][N];

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

  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      a[u][v]=1;
    }
  }
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(j!=0) printf(" ");
      printf("%d",a[i][j]);
    }
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int l,r;
    cin>>l>>r;
    int flag=0;
    long long int m=0,a;
    if(l+2022<r){
        r=l+2022;
    }
    for(long long i=l;i<r;i++){
       for(long long j=i+1;j<=r;j++){
        if(flag==0){
            m=(i*j)%2019;
            flag++;
            //cout<<i<<" "<<j<<endl;
        }
        else{
        a=(i*j)%2019;
        if(a<m){
            m=a;
            //cout<<i<<" "<<j<<endl;
        }
        }
    }
    }
    cout<<m<<endl;
}


Measured memory_bytes: 384
#include<iostream>
using namespace std;
const int maxn=100;
int main(){
	char a[maxn][maxn],b[maxn][maxn];
	int m,n;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			cin>>a[i][j];
		}
		
	}
	for(int i=0;i<m;i++){
		for(int j=0;j<m;j++){
			cin>>b[i][j];
		}
	}
	bool flag=false;
	for(int i=0;i<n-m+1;i++){
		for(int j=0;j<n-m+1;j++){
			if(a[i][j]==b[0][0]){
				flag=true;
				for(int k=0;k<m;k++){
					for(int z=0;z<m;z++){
						if(a[i+k][j+z]!=b[k][z]){
							flag=false;
						}
					}
				}
			}
			if(flag==true){
				cout<<"Yes";
				return 0;
			}
		}
	}
	cout<<"No";
	return 0;
} 

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

int main(){ 
  int n;
  cin >> n;
  vector<int> A(n);
  
  rep(i,n) cin >> A[i];
  
  int ans, cnt = 1;
  
  rep(i,n) {
    if (A[i] == cnt) cnt++;
  }
  
  if (cnt == 1) ans = -1;
  else ans = n - (cnt - 1);
  
  cout << ans << endl;
}


Measured memory_bytes: 1024
def gcd(x, y):
    if y == 0:
        return x
    return gcd(y, x % y)


A, B = map(int, input().split())
C = gcd(A, B)

ans = []
while C % 2 == 0:
    ans.append(2)
    C //= 2
i = 3
while C >= i * i:
    if C % i == 0:
        ans.append(i)
        C //= i
    else:
        i += 2
if C != 1:
    ans.append(C)
print(len(set(ans)) + 1)


Measured memory_bytes: 3064
import java.util.Scanner;

class Solver {

    private final int N;
    private final int[] A;

    Solver(Scanner in) {
        N = in.nextInt();
        A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = in.nextInt();
        }
    }

    void solve() {
        long counter = A[0] / 2;
        int mod = A[0] % 2;
        for (int i = 1; i < A.length; i++) {
            A[i] -= mod;
            if (A[i] < 0) mod = 0;
            else {
                counter += mod;
                counter += A[i] / 2;
                mod = A[i] % 2;
            }
        }
        System.out.println(counter);
    }
}

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

        new Solver(in).solve();

        in.close();
    }
}

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

typedef vector<bool> vb;
typedef vector<int> vi;
typedef pair<int,int> pi;

int main()
{
    int h,w;
    cin >>h >>w;
    vector<string> a(h);
    rep(i,h) cin >>a[i];

    vector<string> r(h, string(w,'.')), b(h, string(w,'.'));

    rep(i,h)
    {
        r[i][0]='#';
        b[i][w-1]='#';
    }

    rep(i,h)
    {
        if(i%2==0)
        {
            for(int j=1; j<w-1; ++j)
            {
                r[i][j]='#';
                if(a[i][j]=='#') b[i][j]='#';
            }
        }
        else
        {
            for(int j=1; j<w-1; ++j)
            {
                b[i][j]='#';
                if(a[i][j]=='#') r[i][j]='#';
            }
        }
    }

    rep(i,h) cout << r[i] << endl;
    printf("\n");
    rep(i,h) cout << b[i] << endl;

    // printf("back\n");
    // rep(i,h)
    // {
    //     rep(j,w)
    //     {
    //         if(r[i][j]=='#' && b[i][j]=='#') printf("#");
    //         else printf(".");
    //     }
    //     printf("\n");
    // }
    return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
int main() {
  
  vector<vector<int>> bingo(3, vector<int>(3));
  for (int i=0; i<3; i++) {
    cin >> bingo[i][0] >> bingo[i][1] >> bingo[i][2];   
  }
  int N;
  cin >> N;
  vector<int> val(N);
  for (int i=0; i<N; i++){
    cin >> val[i];
  }
  
  vector<vector<bool>> ans(3, vector<bool>(3,0));
  for (int i=0; i<3; i++){
    for (int j=0; j<3; j++){
      for (int k=0; k<N; k++){
        if (bingo[i][j] == val[k]) {
          ans[i][j] = 1;
        }
      }
    }
  }
  bool A = 0;
  for (int i=0; i<3; i++){
    if (ans[i][0]==1 && ans[i][1]==1 && ans[i][2]==1){
      A = 1;
    }
    
    if (ans[0][i]==1 && ans[1][i]==1 && ans[2][i]==1){
      A = 1;
    }
  }
  if (ans[0][0] ==1 && ans[1][1] ==1 && ans[2][2] ==1){
    A = 1;
  }
  
  if (ans[0][2] ==1 && ans[1][1] ==1 && ans[2][0] ==1){
    A = 1;
  }
  
  if (A){
    cout << "Yes" << endl;
  }
  
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3616
a[200],b[200],c[1000],d[1000],n,m,i,j,k,t;main(){for(;;){scanf("%d",&n);if(n==0)break;for(i=0;i<n;i++){scanf("%d%d",&a[i],&b[i]);}scanf("%d",&m);for(i=0;i<m;i++){scanf("%d%d",&c[i],&d[i]);}for(i=0;i<m;i++){for(j=1;j<n;j++){for(k=0;k<m;k++){if(a[j]+c[i]-a[0]==c[k]){if(b[j]+d[i]-b[0]==d[k]){t++;break;}}}}if(t==n-1){printf("%d %d\n",c[i]-a[0],d[i]-b[0]);t=0;break;}t=0;}}return 0;}

Measured memory_bytes: 608
#include<cstdio>
#include<math.h>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<set>
#include<map>
#include<queue>
using namespace std;
#define Case int t;scanf("%d", &t);while(t--)
typedef long long ll;
const int Max = 1e5 + 5;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
int n, m;
ll dp[105][Max];
int w[105], v[105];

int main(){
	cin >> n >> m;
	memset(dp, INF, sizeof dp);
	for(int i = 1; i <= n; i++) cin >> w[i] >> v[i];

	for(int i = 0; i < n; i++) dp[i][0] = 0;

	int ans = 0;
	int max_v = 0, min_v = INF;
	for(int i = 1; i <= n; i++){
		max_v += v[i];
		min_v = min(min_v, v[i]);
		for(int j = min_v; j <= max_v; j++){
			dp[i][j] = min(dp[i-1][j], dp[i-1][j-v[i]] + w[i]);
			dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
			if(dp[i][j] <= m) ans = max(ans, j);
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 85636
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define int long long
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define inf 1000000000000000007
#define f first
#define s second
#define mini(c,a,b) *min_element(c+a,c+b)
#define maxi(c,a,b) *max_element(c+a,c+b)
//printf("%.12Lf\n",);
int keta(int x){
	rep(0,i,30){
		if(x<10){
			return i+1;
		}
		x=x/10;
	}
}
int gcd(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return bb;
		}	
		bb=bb%aa;
		if(bb==0){
			return aa;
		}
	}
}	
int lcm(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return x/bb*y;
		}	
		bb=bb%aa;
		if(bb==0){
			return x/aa*y;
		}
	}
}
bool p(int x){
	if(x==1)return false;
	rep(2,i,sqrt(x)+1){
		if(x%i==0&&x!=i){
			return false;
		}
	}	
	return true;
}
int max(int a,int b){
	if(a>=b)return a;
	else return b;
}
int min(int a,int b){
	if(a>=b)return b;
	else return a;
}	
int n2[41];		
int nis[41]; 
int nia[41];
int mody[41];
int nn;
int com(int n,int y){
	int ni=1;
	for(int i=0;i<41;i++){
		n2[i]=ni;
		ni*=2;
	}
	int bunsi=1,bunbo=1;
	rep(0,i,y)bunsi=(bunsi*(n-i))%mod;
	rep(0,i,y)bunbo=(bunbo*(i+1))%mod;
	mody[0]=bunbo;
	rep(1,i,41){
		bunbo=(bunbo*bunbo)%mod;
		mody[i]=bunbo;
	}
	rep(0,i,41)nis[i]=0;
	nn=mod-2;
	for(int i=40;i>=0;i-=1){
		if(nn>n2[i]){
			nis[i]++;
			nn-=n2[i];
		}
	}
	nis[0]++;
	rep(0,i,41){
		if(nis[i]==1){
			bunsi=(bunsi*mody[i])%mod;
		}
	}
	return bunsi;
}
int yakuwa(int n){
	int sum=0;
	rep(1,i,sqrt(n+1)){
		if(n%i==0)sum+=i+n/i;
		if(i*i==n)sum-=i;
	}
	return sum;
}	
bool hei(int n){
	rep(0,i,100){
		if(i*i==n){
			return true;
		}
	}
	return false;
}
int pow(int b,int a){	
	int aa=1;
	rep(0,i,a)aa*=b;	
	return aa;
}
int a[114514];
int sum[114514];
signed main(){
	ic(n)
	rep(0,i,n)cin>>a[i];
	sort(a,a+n);
	sum[0]=a[0];
	rep(1,i,n)sum[i]=sum[i-1]+a[i];
	int ans=0;
	rep(0,i,n-1){
		if(a[i+1]<=sum[i]*2)ans++;
		else ans=0;
	}
	c(ans+1)	
}


Measured memory_bytes: 1792
//gcc -std=gnu11 -O2 -o a.out Main.c -lm
//http://abc045.contest.atcoder.jp/tasks/abc045_b
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdint.h>
#include <math.h>
#include <string.h>

int main(void)
{
#define HUMAN_MAX	3
#define N_MAX		100

	int ret;
	int i,j;
	int human = 0;
	char strBuf[HUMAN_MAX][N_MAX+1];
	
	//-------------------------------------
	//Input process
	//-------------------------------------
	for(i=0; i<HUMAN_MAX; i++){
		ret = scanf("%s", (char *)&strBuf[i]);
	}

	//-------------------------------------
	//Calc process
	//-------------------------------------
	while(1){
		if(strlen(strBuf[human]) == 0){
			break;
		}
		
		char c = strBuf[human][0];
		memmove(&strBuf[human][0], &strBuf[human][1], N_MAX);
		
		human = (c - 0x61);
	}

	//-------------------------------------
	//Output process
	//-------------------------------------
	if(human == 0){
		printf("A\n");
	}else if(human == 1){
		printf("B\n");
	}else{
		printf("C\n");
	}

	return(0);
}



Measured memory_bytes: 128
// 入力
// N
// yyyy-mm-dd string int1 int2
// yyyy-mm-dd string int1 int2
// yyyy-mm-dd string int1 int2
// yyyy-mm-dd string int1 int2


#include <iostream>
#include <string>
using namespace std;

struct Data {
	int year;
	int month;
	int day;
	string name;
	int quantity;
};

int main() {
	
	char st[3];
  
  	string a;
  	cin >> a;
  
  	for(int i=0;i<3;i++){
  		st[i] = a[i];
    }
  	
  	if(st[0] == st[1] && st[1] == st[2]){
      cout << "No";
    }
  	else{
		cout << "Yes";
    }

	return 0;
}


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

int main () {
  int a, b, c, d, e;
  cin >> a >> b >> c >> d >> e;
  
  if (a == 0) {
    cout << 1 << endl;
  }
  
  else if (b == 0) {
    cout << 2 << endl;
  }
  
  else if (c == 0) {
    cout << 3 << endl;
  }
  
  else if (d == 0) {
    cout << 4 << endl;
  }
  
  else if (e == 0) {
    cout << 5 << endl;
  }
}
  
    

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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

int main()
{
    string S; cin >> S;
    string F = "";
    F += S[0]; F += S[1];
    string B = "";
    B += S[2]; B += S[3];

    bool isYYMM = false;
    bool isMMYY = false;

    if("01" <= F && F <= "12"){
        if("00" <= B && B <= "99"){
            isMMYY = true;
        }
    }
    if("01" <= B && B <= "12"){
        if("00" <= F && F <= "99"){
            isYYMM = true;
        }
    }
    if(isMMYY && isYYMM) cout << "AMBIGUOUS" << endl;
    else if(isMMYY) cout << "MMYY" << endl;
    else if(isYYMM) cout << "YYMM" << endl;
    else cout << "NA" << endl;
}

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

N = int(input())
s = input().rstrip()
for t in ['SS', 'SW', 'WS', 'WW']:
    for i in range(1, N-1):
        if (t[-1] == 'W') ^ (s[i] == 'o') ^ (t[-2] == 'S'):
            t += 'W'
        else:
            t += 'S'
    if (t[-1] == 'W') ^ (s[-1] == 'o') ^ (t[-2] == t[0]):
        continue
    if (t[0] == 'W') ^ (s[0] == 'o') ^ (t[-1] == t[1]):
        continue
    print(t)
    exit()
print(-1)


Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++) //for文マクロ
using namespace std;

typedef unsigned long ul;
typedef long long ll;
typedef pair<ul, ul> P; //ペア　タイプでふ

int main()
{
    string a, b;
    cin >> a >> b;
    if (a == b)
    {
        cout << "=";
    }
    else if (a < b)
    {
        cout << "<";
    }
    else
    {
        cout << ">";
    }
}

Measured memory_bytes: 256
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int i=0,n,m=0,c,a[114514]={0};
	vector<pair<int,int> >u;
	for(cin>>n;i<n;cin>>a[i++]);
	sort(a,a+n);
	for(i=0;i<n;)
	{
		for(c=1;a[i]==a[1+i++];c++);
		u.push_back(make_pair(a[i-1],c));
	}
	for(pair<int,int>x:u)m+=x.second<x.first?x.second:x.second-x.first;
	cout<<m<<endl;
	return 0;
}

Measured memory_bytes: 1784
#include<bits/stdc++.h> 
#define rep(i,a,b) for(int i=a;i<b;i++)
#define debug(x) cout<<#x<<"="<<x<<endl;
#define LL long long 
#define INF 1e10
#define pll pair<LL,LL> 
#define fi first
#define se second
using namespace std;
const int N=303;
LL g[N][N]; 


int main(void)
{
	int n;
	scanf("%d",&n);
	rep(i,0,n)
	{
		rep(j,0,n)
		{
			scanf("%lld",&g[i][j]);
		}
	}
	bool flag=true;
	rep(k,0,n)
	{
		rep(j,0,n)
		{
			rep(i,0,n)
			{
				if(g[i][j]>g[i][k]+g[k][j])
				{
					flag=false;
				}
				if(!flag)break;
			}
			if(!flag)break;
		}
		if(!flag)break;
	}
	LL res=0;
	if(flag)
	{
		rep(i,0,n)
		{
			rep(j,i+1,n)
			{
				bool f=false;
				rep(k,0,n)
				{
					if(i!=k&&j!=k&&g[i][j]==g[i][k]+g[k][j])
					{
						f=true;
						break;
					}
				}
				if(!f) res+=g[i][j];
			}
		}
		printf("%lld",res);
	}
	else
	{
		printf("-1");
	}
	return 0;
}

Measured memory_bytes: 896
s = input()
n = len(s)
idx = n
while idx > 0:
    flag = 0
    if idx >= 7:
        if s[idx - 7 : idx] == "dreamer":
            idx -= 7
            flag = 1
    if idx >= 6:
        if s[idx - 6 : idx] == "eraser":
            idx -= 6
            flag = 1
    if idx >= 5:
        if s[idx - 5 : idx] == "dream" or s[idx - 5 : idx] == "erase":
            idx -= 5
            flag = 1
    if idx < 5:
        break
    if not flag:
        break
if not idx:
    print("YES")
else:
    print("NO")



Measured memory_bytes: 73152
#include <cassert>
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <cstdint>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <memory>
#include <utility>
#include <limits>
 
#define rep(i, a, b) for (long long i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t  i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if(b==0)return 1;
  if ((a == 0)||(mod!=-1&&(a+mod)%mod==0))return 0;
  long long x = 1;
  while (b > 0) {
    if (b & 1)x = (mod!=-1)?(x * a) % mod:x*a;
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}

// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

using ll = long long;
using P=std::pair<long long,long long>;

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

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

  std::string s;
  std::cin>>s;

  std::vector<std::string> ans(6,"");

  rep(i,1,6)ans[i]=ans[i-1]+"hi";

  rep(i,0,6){
    if(s==ans[i]){
      std::cout<<"Yes\n";
      return 0;
    }
  }

  std::cout<<"No\n";

  return 0;
}



Measured memory_bytes: 256
//https://atcoder.jp/contests/tenka1-2019/tasks/tenka1_2019_e
/**
 * @file template.cpp
 * @brief 競技プログラミング用テンプレート
 * @author btk15049
 * @date 2019/03/08
 */
#include<bits/stdc++.h>
using namespace std;
#define TEMPLATE
#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}}star;
#define DEBUG if(0)
#endif
#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}
class reverse_range {private:struct I {int x;int operator*() {return x-1;}bool operator!=(I& lhs) {return x>lhs.x;}void operator++() {--x;}};I i, n;public:reverse_range(int n) :i({ 0 }), n({ n }){}reverse_range(int i, int n) :i({ i }), n({ n }){}I& begin() {return n;}I& end() {return i;}};
class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }reverse_range operator!(){return reverse_range(*i,*n);}};
template<typename T>inline T& unused_var(T& v){return v;}
using LL = long long;

int N;
LL a[112345];

LL b[112345];
int bs=0;

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

LL f(){
    LL g=0;
    for(int i:range(bs)){
        g=gcd(g,b[i]);
    }
    return g;
}

namespace prime{
    constexpr int sz = 112345;
    bool ip[sz];
    struct pr{
        pr(){
            ip[0]=ip[1]=false;
            for(int i:range(2,sz)){
                ip[i]=true;
            }
            for(int i:range(sz)){
                if(ip[i]){
                    for(int j=i+i;j<sz;j+=i){
                        ip[j]=false;
                    }
                }
            }
        }
    }pr_init;
    inline bool is(const int i){
        return ip[i];
    }
    vector<LL> factor(LL n){
        vector<LL> ret;
        for(LL i:range(2,sz)){
            if(n%i==0){
                ret.push_back(i);
                while(n%i==0)n/=i;
            }
        }
        if(n>1)ret.push_back(n);
        return ret;
    }
}
set<LL> ret;

int main(){
    cin >> N;
    N++;
    for(int i:range(N)){
        cin>>a[i];
        b[bs++]=abs(a[i]);
    }
    reverse(a,a+N);
    {
        auto fact=prime::factor(f());
        for(auto &it:fact){
            ret.insert(it);
        }
    }
    for(int p:range(2,N+10)){
        if(prime::is(p)==false)continue;
        //if(N<=10)cerr << p <<",";
        if(a[0]%p)continue;
        for(int i:range(min(N,p-1))){
            b[i]=0;
            for(int j=i;j<N;j+=p-1){
                b[i]+=(a[j]%p+p)%p;
            }
        }
        bs=p-1;
        //if(p==2)cerr << b[0] << endl;
        if(f()%p==0)ret.insert(p);
    }
    for(auto p:ret){
        cout<<p<<"\n";
    }
}




Measured memory_bytes: 640
import re
a = input()
regex = '^(\d)(\d)(\d)'
s1 = int(re.sub(regex, r'\1', a))
s2 = int(re.sub(regex, r'\2', a))
s3 = int(re.sub(regex, r'\3', a))
i = 0
if s1 == 1:
    i += 1
if s2 == 1:
    i += 1
if s3 == 1:
    i += 1
print(i)

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

int main() {
	// your code goes here
	int itr, n, it;
	cin >> n;
	it = n-2;
	ll a[n];
	for(auto i = 0;i < n; ++i)cin >> a[i];
	sort(a,a+n);
	ll ans = a[n-1];
	itr = n-2;
	while(itr > 0){
		//cout << ans << " " << itr << " " << it << endl;
		if(itr > 2){
			ans += a[it] * 2;
			--it;
			itr = itr - 2;
			continue;
		}
		ans += a[it];
		--itr;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5188
N = int(input())

memo = []

memo = [1,1] + [0] * (N - 1)

def f(n):
    if memo[n] == 0:
        memo[n] = f(n-1) + f(n-2)
        return(memo[n])
    if memo[n] != 0:
        return(memo[n])

print(f(N))


Measured memory_bytes: 5600
#include <iostream>
#include<string>
#include<cmath>
using namespace std;
int main()
{/*一日目*/
	//値が１０でわりきれるか
	int n;cin >> n;
	switch (n%10) {
	case 3:
		cout << "bon";
		break;
	case 0:
		cout << "pon";
		break;
	case 1:
		cout << "pon";
		break;
	case 6:
		cout << "pon";
		break;
	case 8:
		cout << "pon";
		break;
	default:
		cout << "hon";
		break;
	}
}


Measured memory_bytes: 3600
#include<stdio.h>

int main(){
  char S[200000];
  scanf("%s", S);

  int c1 = 0, c0 = 0;

  int i = 0;
  
  while(S[i] == 49 || S[i] == 48){
    if(S[i] == 49) c1++;
    else if(S[i] == 48) c0++;
    i++;
  }

  if(c1 > c0) printf("%d\n", c0 * 2);
  else printf("%d\n", c1 * 2);

  return 0;
}



Measured memory_bytes: 256
import java.util.Scanner

fun main(args :Array<String>){
    val cin = Scanner(System.`in`)

    while(true){
        val a = cin.nextInt()
        val op = cin.next()
        val b = cin.nextInt()
	
	val result = when(op){
	    "+" -> a + b
	    "-" -> a - b	
	    "*" -> a * b
	    "/" -> a / b
	    else -> 0
	}

	if(op == "?"){
	    break
	}else{
	    println(result)
	}
    }
}


Measured memory_bytes: 25620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, char> i_c;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int f(char moji){
    return (int)moji - (int)'a';
}
int mp[200500][30];
int main() {
    //cout.precision(10);
    string a;
    cin >> a;
    a = "S" + a + "G";
    int n = a.size();
    unordered_map<char, int> last;
    for(char moji = 'a'; moji <= 'z'; moji++){
        last[moji] = n + 1;
    }
    for(int i = n; i >= 0; i--){
        for(char moji = 'a'; moji <= 'z'; moji++){
            mp[i][f(moji)] = last[moji];
        }
        last[a[i]] = i;
    }
    unordered_map<int, char> shortest;
    unordered_map<int, int> length;
    length[n + 1] = 0;
    for(int i = n; i >= 0; i--){
        shortest[i] = 'a';
        length[i] = length[mp[i][f('a')]];
        for(char moji = 'b'; moji <= 'z'; moji++){
            if(length[mp[i][f(moji)]] < length[i]){
                shortest[i] = moji;
                length[i] = length[mp[i][f(moji)]];
            }
        }
        length[i]++;
        //cout << i << " " << shortest[i] << " " << length[i] << endl;
    }
    //cout << shortest[0] << " " << length[0] << endl;
    int index = 0;
    for(int i = 0; i < length[0]; i++){
        cout << shortest[index];
        index = mp[index][f(shortest[index])];
        //cout << index << endl;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 40376
#include <iostream>
#include <utility>
#include <queue>
using namespace std;
typedef pair<int,int> P;
P a;
priority_queue< int > pq;
int n;
string s;
int main(){
	while(1){
		cin >>s;
		if(s=="insert"){
			cin >>n;
			pq.push(n);
		}else if(s=="extract"){
			cout <<pq.top() <<endl;
			pq.pop();
		}else if(s=="end"){
			break;
		}

	}
}

Measured memory_bytes: 6952
#include <iostream>
#include <string>
using namespace std;
int dp[110][110];

string f(string x, string y){
    int m = x.length(), n=y.length();

    for(int j=0; j<=n; j++)
        dp[0][j] = 0;
    for(int i=0; i<=m; i++)
        dp[i][0] = 0;

    for(int i=1; i<=m; i++){
        for(int j=1; j<=n; j++){
            if(x[i-1] == y[j-1])
                dp[i][j] = dp[i-1][j-1] + 1;
            else
                dp[i][j] = 0;
        }
    }

    string ans = "";
    for(int i=1; i<=m; i++){
        for(int j=1; j<=n; j++){
            if(dp[i][j] > ans.length())
                ans = x.substr((i-dp[i][j]+1) -1, dp[i][j]);
        }
    }
    return ans;
}

int main() {
    int n;
    string s, t;
    cin >> n >> s >> t;
    string temp = s + t;
    cout << temp.length() - f(s, t).length() << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;

#define INF (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

int main(void)
{
    ll n,a,b;
    cin >> n >> a >> b;
    ll k = n / (a + b);
    ll m = n % (a + b);
    ll ans = k * a;
    ans += (m < a) ? m : a;
    cout << ans << endl;
    
}


Measured memory_bytes: 256
import java.util.*;
     
public class Main{
      
     public static void main(String[] args){  
     
     	Scanner sc = new Scanner(System.in);
       
        String result = "APPROVED";
       
        int n = sc.nextInt();
       
        for(int i=0;i<n;i++){
         
          int a = sc.nextInt();
          
          if (a %2 ==0 && a%3!=0 && a%5 !=0){
 		   result = "DENIED";
  			}
          
        }
       
        	System.out.print(result);
        	
     }
}

Measured memory_bytes: 23252
import sys
input=sys.stdin.readline
n=int(input())
a=[[0]*3 for _ in range(n)]
for i in range(n):
    a[i]=list(map(int,input().split()))
dp=[[0]*3 for _ in range(n+1)]
for i in range(n):
    for j in range(3):
        for k in range(3):
            if j!=k:
                dp[i+1][j]=max(dp[i][k]+a[i][k],dp[i+1][j])
res=0
for i in range(3):
    if res<dp[n][i]:
        res=dp[n][i]
print(res)

Measured memory_bytes: 74732
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<tuple>
#include<ctime>
#include<functional>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p; 
#define rep(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))

int main(){
    string s;
    cin>>s;
    if(s[0]==s[1] || s[1]==s[2] || s[2]==s[3]) cout<<"Bad"<<endl;
    else p("Good");
}

Measured memory_bytes: 3640
#include <iostream>
#include <string>

int solve(std::string slimes)
{
    int result = 1;
    char color = slimes[0];
    for (auto i = 1; i < slimes.size(); ++i)
    {
        if (color != slimes[i])
        {
            ++result;
            color = slimes[i];
        }
    }

    return result;
}

int main()
{
    int n;
    std::cin >> n;

    std::string s;
    std::cin >> s;

    std::cout << solve(s) << std::endl;
    return 0;
}


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

bool ans=false;

int main(){
    string s;cin>>s;
    for(int i=0;i<s.length()-1;i++){
        if(s.substr(i,2)=="AC")ans=true;
    }
    ans ? cout<<"Yes"<<endl : cout<<"No"<<endl;
    return 0;
}

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

int main() {  
  int n;
  cin >> n;
  vector<int> a(n),b(n);
  for (int i = 0; i < n; i++){
	cin >> a[i];  
  }
  b = a;
  sort(b.begin(),b.end());
  for(int i = 0; i < n; i++) {
  	if(a[i] == b[n-1]) cout << b[n-2] << endl;
    else cout << b[n-1] << endl;
  }
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
#define P printf
#define S scanf
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define PII pair<int,int>
#define x first
#define y second
#define eb emplace_back
#define pb push_back
#define heap priority_queue
#define Q queue
#define V vector
#define T top
#define F front
#define mod 1000000007
#define ll long long
using namespace std;
struct A{
    ll i,j;
    bool operator <(const A& o) const{
        return i+j<o.i+o.j;
    }
};
A point[5050];
ll dp[5050],fac[300010],ifac[300010];
ll MOD(ll a){
    return ((a%mod)+mod)%mod;
}
ll bpow(ll a,ll b){
    ll i,ans=1,res=a;
    for(i=1;i<=b;i<<=1,res=MOD(res*res)){
        if(i&b) ans=MOD(ans*res);
    }
    return ans;
}
ll inv(ll a){
    return bpow(a,mod-2);
}
ll cnr(ll n,ll r){
    return fac[n]*ifac[r]%mod*ifac[n-r]%mod;
}
int main(){
    int i,j,r,c,n;
    fac[0]=ifac[0]=1;
    for(i=1;i<=300000;i++){
        fac[i]=MOD(i*fac[i-1]);
        ifac[i]=inv(fac[i]);
    }
    S(" %d %d %d",&r,&c,&n);
    for(i=1;i<=n;i++){
        S(" %lld %lld",&point[i].i,&point[i].j);
    }
    sort(point+1,point+1+n);
    for(i=n;i>0;i--){
        ll I=r-point[i].i,J=c-point[i].j;
        dp[i]=cnr(I+J,I);
        for(j=n;j>i;j--){
            if(point[i].i<=point[j].i && point[i].j<=point[j].j){
                ll II=point[j].i-point[i].i,JJ=point[j].j-point[i].j;
                dp[i]=MOD(dp[i]-cnr(II+JJ,II)*dp[j]%mod);
            }
        }
    }
    ll ans=cnr(r+c-2,r-1);
    for(i=1;i<=n;i++){
        ans=MOD(ans-cnr(point[i].i+point[i].j-2,point[i].i-1)*dp[i]%mod);
    }
    P("%lld",ans);
    return 0;
}


Measured memory_bytes: 4992
use std::io;

fn main() {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let mut iter = buf.split_whitespace();
	let s:i32 = match iter.next().unwrap().parse() {
		Ok(n) => n,
		Err(_) => panic!(""),
	};
	let w:i32 = match iter.next().unwrap().parse() {
		Ok(n) => n,
		Err(_) => panic!(""),
	};
	if w >= s {println!("unsafe"); }else { println!("safe"); }
}

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

#define f(i,x,y)			for(int i=x; i<y; i++)
#define mp 					make_pair
#define F 					first
#define S 					second

int main()
{
	int n;
	cin>>n;
	int a[n][3];	
	f(i,0,n)
		cin>>a[i][0]>>a[i][1]>>a[i][2];

	vector <vector <int> > dp(n,vector <int> (3));
	dp[0][0] = a[0][0];
	dp[0][1] = a[0][1];
	dp[0][2] = a[0][2];

	f(i,1,n)
	{
		f(j,0,3)
		{
			dp[i][j] = a[i][j] + max(dp[i-1][(j+1)%3], dp[i-1][(j+2)%3]);
		}
	}
	cout<<max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]));

	return 0;
}

Measured memory_bytes: 6912
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
typedef struct pair<ll,int> P;



int main() {
	int n,yen;
	cin>>n>>yen;

	for(int z=0;z*1000<=yen&&z<=n;++z){
		for(int y=0;y*5000+z*1000<=yen&&(z+y)<=n;++y){
			for(int x=0;z*1000+y*5000+x*10000<=yen&&(x+y+z)<=n;++x){
				if((z*1000+y*5000+x*10000==yen)&&((x+y+z)==n)){
					cout<<x<<" "<<y<<" "<<z<<endl;
					return 0;
				}
			}
		}
	}
	cout<<"-1 -1 -1"<<endl;
	return 0;
}


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

using namespace std;

const int MOD = 1000000007;

long long int fact(long long int n) {
	return (n == 1 ? 1 : n * fact(n - 1) % MOD);
}

long long int solve(long long int n, long long int m) {
	if (abs(n - m) > 1) {
		return 0;
	} else if (abs(n - m) == 0) {
		return 2 * fact(n) * fact(m) % MOD;
	} else {
		return fact(n) * fact(m) % MOD;
	}
}

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

	cout << solve(n, m) << endl;
	return 0;
}

Measured memory_bytes: 1792
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           int                         long long
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);




using namespace std;

const int inf=1e18;
const int mod=1e9+7;
const int M=100009;

inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}
inline int ad(int x,int y){int ret=(x%mod+y%mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline int sub(int x,int y){int ret=((x%mod)-(y%mod)+mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline int gun(int x,int y){int ret=((x%mod)*(y%mod))%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}


 main()

{
    fast
    int n;
    cin>>n;
    int ev=0,od=0,x;
    f(i,1,n)
    {
        cin>>x;
        if(x%2==0)ev++;
        else od++;
    }
    ev+=(od/2);
    od=od%2;
   if(od==0)
   {
       cout<<"YES"<<endl;
   }
   else if(od==1)
   {
       if(ev==0)cout<<"YES"<<endl;
       else cout<<"NO"<<endl;
   }
    return 0;
}


Measured memory_bytes: 256
use std::cmp::min;

macro_rules! extract {
    (String, $iter:expr) => {
        $iter.next().unwrap().trim().to_owned()
    };
    ($t:tt, $iter:expr) => {
        $iter.next().unwrap().trim().parse::<$t>().unwrap()
    };
}

macro_rules! read_split_impl {
    ( $e:expr, $( $t:tt ),* ) => {{
        let mut s = String::new();
        $e.read_line(&mut s).unwrap();
        let s = s.trim_right();
        let mut iter = s.split_whitespace();
        ( $(extract!($t, iter)),* )
    }};
}

macro_rules! read_split {
    ( $( $t:tt ),* ) => {
        read_split_impl!(std::io::stdin(), $($t),* )
    };
}

fn index_of_factorial(n: u64, base: u64) -> u64 {
    let mut power = base;
    let mut result = 0;
    loop {
        let q = n / power;
        if q == 0 {
            break;
        }
        result += q;
        if let Some(p) = power.checked_mul(base) {
            power = p;
        } else {
            break;
        }
    }
    result
}

fn solve(n: u64) -> u64 {
    if n % 2 == 0 {
        let n = n / 2;
        let n2 = index_of_factorial(n, 2);
        let n5 = index_of_factorial(n, 5);
        min(n2 + n, n5)
    } else {
        let n2 = index_of_factorial(n, 2);
        let n5 = index_of_factorial(n, 5);

        let m = n / 2;
        let m2 = index_of_factorial(m, 2);
        let m5 = index_of_factorial(m, 5);
        min(n2 - m2 - m, n5 - m5)
    }
}

fn main() {
    let n = read_split!(u64);

    print!("{}", solve(n));
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
string X;
stack<int> sta;
int child=0;
int main(){
	cin>>X;
	for(int i=0;i<X.size();i++){
		if(X[i]=='S')
			sta.push(1);
		else{
			if(!sta.empty()){
				child+=2;
				sta.pop();
			}
		}
	}
	cout<<X.size()-child<<endl;
	return 0;
}


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

int main(){
  int N = 0;
  set<string> S;
  cin >> N;
  for(int i = 0; i < N; i++){
    string str;
    cin >> str;
    S.insert(str);
  }
  cout << S.size() << endl;
}

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

long long gcd(long long m,long long n){
    if(n==0){
        return m;
    }
    return gcd(n,m%n);
}

int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    vector<int> c(1000005);

    rep(i,n){
        cin>>a[i];
        c[a[i]]++;
    }

    bool pairwise=true;
    for(int i=2;i<1000005;i++){
        int cnt=0;
        for(int j=i;j<1000005;j+=i) cnt+=c[j];
        if(cnt>1){
            pairwise=false;
            break;
        }
    }

    if(pairwise){
        cout << "pairwise coprime" << endl;
    }
    else{
        int g=0;
        rep(i,n) g=gcd(g,a[i]);
        if(g==1){
            cout << "setwise coprime" << "\n";
        }
        else cout << "not coprime" << "\n";
    }
}

Measured memory_bytes: 11116
#include <math.h>

#include <algorithm>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
using ll = long long;

int main() {
  ll n;
  cin >> n;
  ll buf = n + 1;
  for (int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      buf = min(buf, i + n / i);
    }
  }
  cout << buf - 2;

  return 0;
}


Measured memory_bytes: 256
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
	static void solve(){//Here is the main function
      ArrayList<Integer> one = nextIntArray();
      int K = one.get(0);
      int S = one.get(1);
      int output = 0;
      for(int i = 0; i <= K; i++){
        for(int j = 0; j <= K; j++){
          int Z = S - (i + j);
          if(Z >= 0 && Z <= K){
            output++;
          }
        }
      }
      myout(output);
	}
	//Method addition frame start


  
	//Method addition frame end
}


Measured memory_bytes: 32980
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(int i=0;i<n;i++)
#define int long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
#define mod 1000000007
#define inf 1e15
using namespace std;
typedef pair<int, int>P;
void yes() { cout << "Yay!" << endl; }
void no() { cout << ":(" << endl; }
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y)* mod_pow(kai(y, y), mod - 2, mod) % mod;
}
struct edge { int to, cost; };
string s[55];
int a[55][26];
int ans[26];
signed main() {
	int n;
	cin >> n;
	rep(i, n)cin >> s[i];
	rep(i, n) {
		rep(j, s[i].size()) {
			a[i][s[i][j] - 'a']++;
		}
	}
	rep(i, 26) {
		int memo = inf;
		rep(j, n) {
			memo = min(memo, a[j][i]);
		}
		ans[i] = memo;
	}
	rep(i, 26) {
		if (ans[i] == 0)continue;
		for (int j = 0; j < ans[i]; j++)cout << (char)(i + 'a');
	}
	cout << endl;
	ggr
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
  using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define endl "\n"
  #define ll long long
  #define int long long 
  #define float double
  #define double long double
  #define max(a,b) (a>b?a:b)
  #define min(a,b) (a<b?a:b)
  #define mkp make_pair
  #define pb push_back
  #define inf INT_MAX
  
  void pairsort(int a[], int b[], int n)
  {
      pair<int, int> pairt[n];
      for (int i = 0; i < n; i++) 
      {
          pairt[i].first = a[i];
          pairt[i].second = b[i];
      }
      sort(pairt, pairt + n);
      for (int i = 0; i < n; i++) 
      {
          a[i] = pairt[i].first;
          b[i] = pairt[i].second;
      }
  }
   int binomialCoeff(int n, int k) 
  { 
       int res = 1; 
    
      // Since C(n, k) = C(n, n-k) 
      if ( k > n - k ) 
          k = n - k; 
    
      // Calculate value of [n * (n-1) *---* (n-k+1)] / [k * (k-1) *----* 1] 
      for (int i = 0; i < k; ++i) 
      { 
          res *= (n - i); 
          res /= (i + 1); 
      } 
    
      return res; 
  } 
  void printVector(vector<ll> v) {
    for(int i=0;i<v.size();i++)
      {
        cout << v[i];
      }
 
    }
  int divisor(int num)
  { int div=0;
    for (int i = 1; i <= num; i++)
    {
      /* code */
      if(num%i==0)
        div++;
    }
      return div;
    
  }
  int sub(int a, int b)
  {
    if(a>=b)
      return a-b;
    else
      return b-a;
 
  }
  int32_t main()
  { 
      IOS
      int n,k;
      cin>>n>>k;
      int a[n];
      float exp[n];
      for(int i=0;i<n;i++)
      { cin>>a[i];
        exp[i]=(float)a[i]*(a[i]+1)/2*((float)1/a[i]);
      }
    //   for(int i=0;i<n;i++)
    //   cout<<exp[i]<<"  ";
      double sum=0.0;
      for(int i=0;i<k;i++)
      {
          sum+=exp[i];
      }
      double ans=sum;
      for(int i=k;i<n;i++)
      {
          sum += exp[i] - exp[i - k]; 
          //cout<<sum<<"  ";
          ans=max(sum,ans);

      }
      cout<<fixed<<setprecision(6)<<ans;
      return 0;
  }


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

#define ll long long

void solve()
{
    ll n;
    cin >> n;
    vector<ll> a(n);

    for(ll i = 0; i < n; i++)
    {
        cin >> a[i];
    }

    ll i = 0;
    ll sum = 1000;

    while(i < n - 1)
    {
        while(i < n - 1 && a[i + 1] <= a[i])
        {
            i++;
        }

        if(i == n - 1)
        {
            break;
        }

        ll buy = i;
        i++;

        while(i < n && a[i] >= a[i - 1])
        {
            i++;
        }

        ll sell = i - 1;

        ll temp = sum / a[buy];
        sum -= temp * a[buy];
        sum += temp * a[sell];
    }

    cout << sum;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    // ll t;
    // cin >> t;
    
    // while(t--)
    // {
        solve();
    // }

    return 0;
}


Measured memory_bytes: 3660
/* input
5
 -1 2 3 1 -1
 2 -1 -1 4 -1
 3 -1 -1 1 1
 1 4 1 -1 3
 -1 -1 1 3 -1
*/



#include<stdio.h>

#define MAX 100
#define INFTY (1 << 21)

#define WHITE 0
#define GRAY 1
#define BLACK 2

int prim(void);


int n;
int M[100][100];


int main(void){
  int i,j;
  int a;
  
  scanf("%d",&n);

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

      if(a == -1){
	M[i][j] = INFTY;
      } else {
	M[i][j] = a;
      }

    }
  }

  printf("%d",prim());
  puts("");

  return 0;
}




int prim(void){
  int i,v;
  int u,mincost;
  int d[MAX],p[MAX];
  int color[MAX];
  int sum = 0;

  for(i = 0;i < n;i++){
    d[i] = INFTY;
    p[i] = -1;
    color[i] = WHITE;
  }

  d[0] = 0;

  while(1){
    mincost = INFTY;
    u = -1;
    
    for(i = 0;i < n;i++){
      if(d[i] < mincost && color[i] != BLACK){
	u = i;
	mincost = d[i];
      }
    }

    if(u == -1){
      break;
    }
    color[u] = BLACK;
    
    for(v = 0;v < n;v++){
      if(color[v] != BLACK && M[u][v] != INFTY){
	if(M[u][v] < d[v]){
	  d[v] = M[u][v];
	  p[v] = u;
	  color[v] = GRAY;
	}
      }
      
    }
  }

  for(i = 0;i < n;i++){
    if(p[i] != -1){
      sum += M[i][p[i]];
    }
  }
  
  return sum;
}



Measured memory_bytes: 2104