akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(v) v.begin(), v.end()

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  
  vector<int> a(n);
  rep(i, 0, n) cin >> a.at(i);
  sort(all(a));
  
  cout << a.at(n -1) -a.at(0) << "\n";

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=1e9+7;
#define maxn 200010
int a[maxn],b[maxn],pre[maxn];
ll dp[maxn][2]={0};
int main()
{
    int n,cnt=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(int i=1;i<=n;i++)
        if(a[i]!=a[i-1])
            b[++cnt]=a[i];
    dp[1][0]=1;
    pre[b[1]]=1;
    int pos;
    for(int i=2;i<=cnt;i++)
    {
        pos=pre[b[i]];
        dp[i][0]=(dp[i-1][0]+dp[i-1][1])%mod;
        dp[i][1]=(dp[i][1]+dp[pos][0]+dp[pos][1])%mod;
        pre[b[i]]=i;
    }
    printf("%lld",(dp[cnt][0]+dp[cnt][1])%mod);
    return 0;
}


Measured memory_bytes: 5760
#include <stdio.h>

int main(){
  int i, j, n, v;
  int a[1000];

  scanf("%d",&n);//行数を入力
  for(i = 0;i < n; i++){
    scanf("%d",&a[i]);
  }
  
  for(j = 0;j < n; j++){
    printf("%d",a[j]);
    if(j < n-1){
      printf(" ");
    }
  }
  printf("\n");
  
  for(i = 1;i < n; i++){
    
    v = a[i];
    j = i-1;
    
    while(j>=0 && a[j]>v){
      a[j+1] = a[j];
      j--;
    }
    a[j+1] = v;
    
    for(j = 0;j < n; j++){
      printf("%d",a[j]);
      if(j < n-1){
	printf(" ");
      }
    }
    printf("\n");
  }

  return 0;
}



Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
namespace mine
{
    typedef long long ll;
    #define pr pair<int,int>
    #define FR first
    #define SE second
    #define MP make_pair
    #define PB push_back
    #define vc vector
    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())
    #define bin(x) (1ll<<(x))
    #define GG(x) if(x) puts("error")
    ll qread()
    {
        ll ans=0,f=1;char c=getchar();
        while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
        while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
        return ans*f;
    }
    void write(ll num)
    {
        if(num<0) putchar('-'),num=-num;
        if(num>=10) write(num/10);
        putchar('0'+num%10);
    }
    void write1(ll num){write(num);putchar(' ');}
    void write2(ll num){write(num);putchar('\n');}
    template<typename T> void chmax(T &x,const T y) {x=(x>y?x:y);}
    template<typename T> void chmin(T &x,const T y) {x=(x<y?x:y);}
    ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

    const int INF=0x3f3f3f3f;
    const int MOD=1e4+7;
    inline int mm(const int x){return x>=MOD?x-MOD:x;}
    template<typename T> inline void add(T &x,const T y){x=mm(x+y);}
    inline ll qpower(ll x,ll e)
    {
        ll ans=1;GG(e<0);
        while(e){if(e&1)ans=ans*x%MOD;x=x*x%MOD;e>>=1;}
        return ans;
    }
    ll invm(ll x){return qpower(x,MOD-2);}
    const int N=1e5+10;

    ll sum=0;bool cmp(int x,int y){
        int tx=(sum&(1ll<<x))==0,ty=(sum&(1ll<<y))==0;
        return tx>ty or (tx==ty and x>y);}
    int pp[100];

    ll a[N],bs[N];
    void insert(ll num)
    {
        for(int i=0;i<=59;i++)
        {
            int s=pp[i]; if(!(num&(1ll<<s))) continue;
            if(bs[s]) num^=bs[s]; else {bs[s]=num;break;}
        }
    }
    void main()
    {
        int n=qread();for(int i=1;i<=n;i++) a[i]=qread(),sum^=a[i];
        for(int i=0;i<60;i++) pp[i]=i;sort(pp,pp+60,cmp);
        for(int i=1;i<=n;i++) insert(a[i]);
        ll now=0;
        for(int i=0;i<=59;i++) if(bs[pp[i]] and (now&(1ll<<pp[i]))==0) now^=bs[pp[i]];
        write(now+(sum^now));
    }//(ans+MOD)%MOD
};
int main()
{
    srand(time(0));
    mine::main();
}


Measured memory_bytes: 1024
from operator import itemgetter

n = int(input())
lr = [list(map(int, input().split())) for i in range(n)] + [[0, 0]]

l_sort = sorted(lr, key=itemgetter(0), reverse=True)
r_sort = sorted(lr, key=itemgetter(1))

ans = 0
sigma = 0

for i in range(n // 2 + 1):
	sigma += 2 * (l_sort[i][0] - r_sort[i][1])
	if sigma > ans:
		ans = sigma

print(ans)

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

int main(){
    int n;
    cin >> n;
    double ans;
    if(n % 2 == 1) {
        ans = (double)(n/2 + 1)/n;
    }else{
        ans = (double)n/2/n;
    }
    printf("%.10f\n",ans);
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
int n,a[100000];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    sort(a+1,a+1+n);
    printf("%d\n",a[n]-a[1]);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<algorithm>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

int main(void) {
    int a,b,c;
    cin>>a>>b>>c;

    int sum = 0;
    while(true) {
    if(a == b && b == c) {
        break;
    }
    if(a < b) {
        swap(a,b);
    }
    if(a < c) {
        swap(a,c);
    }
    if(b < c) {
        swap(c,b);
    }
    if(b == c) {
        sum += a - b;
        b = a;
        c = a;
    } else {
        c += 2;
        sum++;
    }
    
    }

    cout<<sum<<endl;

    return 0;
}
    



Measured memory_bytes: 888
#include<iostream>

using namespace std;

int main(){
    long long N = 0;
    long long ans = 0;
    cin >> N;
    for (long long i = 1; i <= N;i++)
    {
        if(i%3!=0 && i%5!=0){
            ans += i;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define int ll
using pint = pair<int,int>;
using Graph = vector<vector<int>>;
void YN(bool flg) {cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg) {cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg) {cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define out(n) cout << n << '\n'
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 1e10; //10^10
const double PI = acos(-1.0L);
/*mod逆元*/long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}
template< typename T >T mod_pow(T x, T n, T p=MOD) {T ret = 1;while(n > 0) {if(n & 1) (ret *= x) %= p;(x *= x) %= p;n >>= 1;}return ret;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n >>= 1; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}

//----------------ライブラリとか----------------

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);

    int n; string s; cin >> n >> s;
    int ans = -INF;
    FOR(i,1,n){
        string x = s.substr(0,i);
        string y = s.substr(i);
        set<int> st; int tmp = 0;
        REP(j,x.size()) st.insert(x[j]);
        REP(j,y.size()) if(st.count(y[j])){tmp++; st.erase(y[j]);}
        chmax(ans,tmp);
    }
    out(ans);

    return 0;
}

Measured memory_bytes: 256
from math import inf


def merge(A, left, mid, right):
    global count

    L = A[left: mid]
    R = A[mid: right]

    L.append(inf)
    R.append(inf)

    i = 0
    j = 0

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


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


def main():
    global count
    n = int(input())
    A = list(map(int, input().split()))

    merge_sort(A, 0, n)
    print(count)


if __name__ == "__main__":
    count = 0
    main()



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


#define fi first
#define se second
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define el '\n'

using namespace std;
using ll = long long;
using pii = pair<int, int>;

const int N = 2e5 + 10;

int n;
string s;
int dp[N];

ll base[2];

ll fpow(ll a, ll b, ll mod){
    ll ret = 1;
    while (b){
        if (b & 1){
            ret = (ret * a) % mod;
        }
        a = a * a % mod;
        b >>= 1;
    }
    return ret;
}



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

    dp[0] = 0;
    for (int i=1;i<N;i++){
        int cnt = __builtin_popcount(i);
        dp[i] = 1 + dp[i % cnt];
    }

    cin >> n >> s;
    ll cnt = 0;
    for (auto x : s){
        if (x == '1') cnt++;
    }
    // base -1
    if (cnt > 1){
        for (ll i=n - 1;i>=0;i--){
            if (s[i] == '1') base[0] = (base[0] + fpow(2, n - 1 - i, cnt - 1)) % (cnt - 1);
        }
    } 
    // base +1
    if (cnt < n){
        for (ll i=n - 1;i>=0;i--){
            if (s[i] == '1') base[1] = (base[1] + fpow(2, n - 1 - i, cnt + 1)) % (cnt + 1);
        }
    }

    for (int i=0;i<n;i++){
        ll p = n - 1 - i;
        ll ans = 1;
        if (s[i] == '1'){ // base -1
            if (cnt == 1){
                cout << 0 << el;
                continue;
            }
            ll temp = (base[0] - fpow(2, p, cnt - 1) + (cnt - 1)) % (cnt - 1);
            ans += dp[temp];
        } else{
            ll temp = (base[1] + fpow(2, p, cnt + 1) + (cnt + 1)) % (cnt + 1);
            ans += dp[temp];
        }
        cout << ans << el;
    }

    return 0;
}

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

int main() {
    int N, A, B;
    string S;
    cin >> N >> A >> B >> S;

    int confirm = 0, bcnt = 0;
    for (int i = 0; i < N; i++) {
        if (S.at(i) == 'a' && confirm < A + B) {
            cout << "Yes" << endl;
            confirm++;
        }
        else if (S.at(i) == 'b' && confirm < A + B) {
            if (bcnt < B) {
                cout << "Yes" << endl;
                bcnt++;
                confirm++;
            }
            else {
                cout << "No" << endl;
                bcnt++;
            }
        }
        else {
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 3756
while(True):
  a,op,b = map(str,input().split())
  if op == "?":
    break
  else:
    a = int(a)
    b = int(b)
    if op == "+":
      print(a+b)
    elif op == "-":
      print(a-b)
    elif op == "*":
      print(a*b)
    elif op == "/":
      print(a//b)


Measured memory_bytes: 5596
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <limits.h>
#include <bitset>
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
const int MOD = 1000000007;
const int INF = LLONG_MAX/3;
int dp[1100][5000];
signed main(){
    int n;
    cin>>n;
    int m;
    cin>>m;
    for(int i=0;i<1100;i++){
        for(int j=0;j<5000;j++){
            dp[i][j]=INF;
        }
    }
    dp[0][0]=0;
    for(int i=1;i<=m;i++){
        int a;
        cin>>a;
        int b;
        cin>>b;
        bitset<13> s;
        for(int j=0;j<b;j++){
            int k;
            cin>>k;
            s.set(k-1);
        }
        for(int j=0;j<4096;j++){
            bitset<13> t=j;
            if(dp[i-1][j]!=INF){
                dp[i][(s|t).to_ulong()]=min(dp[i-1][j]+a,dp[i][(s|t).to_ulong()]);
                dp[i][j]=min(dp[i-1][j],dp[i][j]);
            }
            else dp[i][j]=min(dp[i-1][j],dp[i][j]);
        }
    }
    if(dp[m][(int)pow(2,n)-1]!=INF)cout<<dp[m][(int)pow(2,n)-1]<<endl;
    else cout<<-1<<endl;
    return 0;
}


Measured memory_bytes: 43264
N = int(input())
A = sorted(list(map(int,input().split())))

ans_list = []
p = []
n = []

# 最大にプラス、最小にマイナスを割り当てる
p.append(A[-1])
n.append(A[0])

# 正ならプラスを負ならマイナスを割り当てる
for a in A[1:-1]:
    if a >= 0:
        p.append(a)
    elif a < 0:
        n.append(a)

# プラスが１つになるまで消す
while len(p) != 1:
    x = n.pop()
    y = p.pop()
    n.append(x-y)
    ans_list.append((x, y))

# マイナスがなくなるまで消す
while len(n) != 0:
    x = p.pop()
    y = n.pop()
    p.append(x-y)
    ans_list.append((x,y))

# 残ったものが最大値
M = p[0]
print(M)
for x, y in ans_list:
    print(x, y)

Measured memory_bytes: 20200
#include <stdio.h>
#define Max 100001
int main(void)
{
	int i,j,k,n;
	int data[Max]={0};
	long long temp=0,max=-10000000;
	while(1){
		scanf("%d",&n);
		if(n==0) break;
		for(i=0;i<n;i++){
			scanf("%d",&data[i]);
		}
		for(i=0;i<n;i++){
			temp=0;
			for(j=i;j<n;j++){
				temp+=data[j];
				if(max<temp) max=temp;
			}
		}
		printf("%lld\n",max);
		max=-10000000;
	}
	return 0;
}

Measured memory_bytes: 996
#include<bits/stdc++.h>
using namespace std;
 
int A,B,C,D;
 
int main()
{
    scanf("%d%d%d%d",&A,&B,&C,&D);
    printf("%d\n",max(0,min(B,D) - max(A,C)));
    return 0;
}

Measured memory_bytes: 256
from itertools import combinations

def getval():
    n,k = map(int,input().split())
    a = list(map(int,input().split()))
    return n,k,a

def main(n,k,a):
    arr = []
    locmax = 0
    for i in a:
        arr.append(locmax)
        locmax = max(locmax,i)

    ans = 2**60
    for c in combinations(range(1,n),k-1):
        cost = 0
        prev = a[0]
        for i in c:
            if a[i]<=prev:
                cost += max(prev,arr[i])+1-a[i]
            prev = max(max(prev,arr[i])+1,a[i])
        ans = min(ans,cost)
    if k==1:
        ans = 0
    print(ans)

if __name__=="__main__":
    n,k,a = getval()
    main(n,k,a)   

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

int main()
{
    string a, b;
    cin >> a >> b;
    string s = a+b;

    int number = atoi(s.c_str());

    int x = sqrt(number);
    if(x*x == number)
        cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    int n,k;
    cin >> n >> k;
    int min_pos=1;
    int min=10000000;
    rp(i,n){
        int a;
        cin >> a;
        if(chmin(min,a)) min_pos=i+1;
    }
    print((n-1+k-2)/(k-1));
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

Measured memory_bytes: 256
import sys
import math
from collections import deque
import heapq
import itertools
from decimal import Decimal
import bisect
from operator import itemgetter
MAX_INT = int(10e18)
MIN_INT = -MAX_INT
mod = 1000000000+7
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

def tami(now, ContestType):
  res = c[ContestType] * (now - LastDay[ContestType])
  return res

D = I()
c = IL()
s = [IL() for i in range(D)]

LastDay = [0]*26
for i in range(1,D+1):
  tmp = ["", 0]
  for j in range(26):
    Dscore = tami(i, j)
    if Dscore > tmp[1]:
      tmp = [j, Dscore]
  print(tmp[0]+1)
  LastDay[tmp[0]] = i

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

//Made with <3 by MinumCoklatPanas
typedef long long ll;
const int INF = 1e9;
const ll INFF = 1e18;
const int MAXN = 510;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
const double INFD = 1E9;
const double EPS = 1e-9;

int f(int x,int y,int z)
{
    int sum = x * x + y * y + z * z + x * y + x * z + y * z;
    return sum;
}

pair<int,int> akar(int x,int y,int n)
{
    int a = 1;
    int b = x + y;
    int c = x * x + y * y + x * y - n;
    int D = b * b - 4 * a * c;
    if (D < 0) return {-1,-1};
    pair<int,int> res;
    //plus
    double tmp = (-b + sqrt(1.0 * D)) / 2.0;
    // cout << tmp << " ";
    if (f(x,y,(int)tmp) == n)
        res.first = (int)tmp;
    else
        res.first = -1;
    
    tmp = (-b - sqrt(1.0 * D)) / 2.0;
    // cout << tmp << endl;
     if (f(x,y,(int)tmp) == n)
        res.second = (int)tmp;
    else
        res.second = -1;
    return res;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    // cout << f(1,1,-2) << endl;
    // return 0;
    // auto tmp = akar(2,2,17);
    // return 0;
    int n;
    cin >> n;
    for (int i = 1 ; i <= n ; i++)
    {
        int ans = 0;
        for (int x = 1 ; x * x <= i ; x++)
            for (int y = 1 ; y * y <= i ; y++)
            {
                auto root = akar(x,y,i);
                // cout << x << " " << y << ": " << root.first << " " << root.second << endl;
                ans += (root.first >= 1);
                ans += (root.second >= 1);
            }
        cout << ans << endl;
        // cout << i << ": " << ans << endl;
        // cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define fastIO ios::sync_with_stdio(0), cin.tie(0);
#define endl '\n'
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int MAX = 1e5 + 5;
vector<int> G[MAX];
bool vis[MAX];
void dfs(int s, int cnt, int &mndis) {
    //cout << s << " " << cnt << endl;
    if (s == 1) {
        mndis = min(cnt, mndis);
    }
    vis[s] = 1;
    for (auto u : G[s]) {
        if (!vis[u]) dfs(u, cnt + 1, mndis);
    }
}
int main() {
#ifdef LOCAL
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#else
    fastIO;
#endif
    int n;
    cin >> n;
    forn(i, n) {
        int v;
        cin >> v;
        v--;
        G[i].pb(v);
    }
    memset(vis, 0, sizeof vis);
    int dis = 1e9;
    dfs(0, 0, dis);
    if (dis != 1e9) {
        cout << dis << endl;
        return 0;
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 10624
#include<stdio.h>

int main(){
  int i,j,k,t,q;
  int n,cnt;
  int A_size[10000];

  cnt = 0;
  
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",A_size+i);
  
   scanf("%d",&q);
   for(j=0;j < q;j++){
    scanf("%d",&t);
    for(k=0;k < n;k++)
      if(A_size[k] == t){
	cnt++;
	break;
      }
   }
  
    printf("%d\n",cnt);
    return 0;

}



Measured memory_bytes: 2048
from enum import Enum
import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

def isprime(x):
    if x==2:
        return True
    if x < 2 or x%2==0:
        return False
    i=3
    while True:
        if i > math.sqrt(x):
            break
        if x % i ==0:
            return False
        i += 2
    return True

try_num=int(input())
num_prime=0
for i in range(try_num):
    test_num=int(input())
    if isprime(test_num):
        num_prime += 1

print("%d"%(num_prime))



Measured memory_bytes: 6384
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };  // i<4:4way i<8:8way
int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int h,w,m;
    cin >> h >> w >> m;
    vector<pair<int,int>> p;
    vector<int> cnth(h),cntw(w);
    set<pair<int,int>> st;
    int ans = 0;
    rep(i,m){
        int a,b;
        cin >> a >> b;
        a--;b--;
        cnth[a]++;
        cntw[b]++;
        p.push_back({a,b});
        st.insert({a,b});
    }
    vector<pair<int,int>> wc;
    for(int i=0;i<w;i++){
        wc.push_back({cntw[i],i});
    }
    sort(wc.rbegin(),wc.rend());
    for(int i=0;i<h;i++){
        // ある行を決めた後にどの列を爆破するか決めるんだけど
        // 予め列ごとに個数を出しておく
        int tmp = cnth[i];
        int p = 0;
        while(wc[p+1].first == wc[p].first && p + 1 < w && st.count({i,wc[p].second})){
                p++;
        }
        tmp += wc[p].first;
        if(st.count({i,wc[p].second}))tmp--;
        chmax(ans,tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 28216
n,k=list(map(int,input().split()))
m=list(map(int,input().split()))

s=sum(m[:k])
mx=s
for i in range(1,n-k+1):
    s-=m[i-1]
    s+=m[i+k-1]
    mx=max(mx,s)
print((mx+k)/2)
    
    
    

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

int main(){
    int N;
    cin >> N;
    int a[N];
    for (int i = 0; i < N; i++){
        cin >> a[i];
    }
    int max_a, min_a;
    min_a = 10000;
    max_a = 0;
    for (int i=0; i<N; i++){
        max_a = max(a[i], max_a);
        min_a = min(a[i], min_a);
    }
    cout << max_a - min_a << endl;

    return 0;
}

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

typedef long long ll;
typedef long double ld;

#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

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

int main(){

    ll D;

    cin >> D;

    cout << "Christmas";
    rep(i, 25- D)
        cout << " Eve";
    
    cout << endl;

    return 0;
}

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



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

    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif

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

    int f=0;

    for(int i=a*b;i>=0;i-=a){
        if(i%b==c){
            f=1;
            break;
        }
    }
    if(f) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;

}


Measured memory_bytes: 3588
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
//typedef __int64 LL;
typedef vector<int> ivec;
typedef vector<string> svec;

string s[55];
int a[30];
int b[30];
int main(){
	int n;
	int ans=0;
	cin>>n;	
	for(int i=0;i<n;i++)cin>>s[i];
	for(int i=0;i<30;i++)a[i]=1000000000;
	for(int i=0;i<n;i++)
	{
	        for(int j=0;j<30;j++)b[j]=0;
		for(int j=0;j<s[i].size();j++)
		{
			int temp=s[i][j]-96;
			b[temp]++;
		}
		for(int j=0;j<30;j++)
		{
			a[j]=min(a[j],b[j]);
		}
	}
	
        for(int i=1;i<=26;i++){
		for(int j=0;j<a[i];j++)
		{
			printf("%c",i+96);
		}
	}	
	//cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int a[225816],b[225816];
vector<int> ans;

int main(void){
	int n,i,j,t,m;
	cin >> n;
	for(i=1; i<=n; ++i){
		cin >> a[i];
	}
	for(i=n; i>0; --i){
		t = 0;
		for(j=i*2; j<=n; j+=i){
			t += b[j];
		}
		t %= 2;
		b[i] = (t^a[i]);
	}
	for(i=1; i<=n; ++i){
		if(b[i]){
			ans.push_back(i);
		}
	}
	m = ans.l_ength();
	cout << m << endl;
	if(!m){
		return 0;
	}
	for(i=0; i<m; ++i){
		cout << ((i)?" ":"") << ans[i];
	}
	cout << endl;
	return 0;
}


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

int main() {
    ll x,y;
    cin >> x >> y;
    if(x*y>0){
        if(y>=x) cout << y-x << endl;
        else cout << x-y+2 << endl;
    }
    else if(x*y==0){
        if(y<0 || x>0) cout << abs(x+y)+1 << endl;
        else cout << abs(x+y) << endl;
    }
    else{
        x = abs(x),y=abs(y);
        if(y>=x) cout << y-x+1 << endl;
        else cout << x-y+1 << 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 repd(i,a,b) for (int i = (a); i < (b); i++)
typedef long long ll;
int main(void)
{
	int n, m, a, b;
	vector<int> A;
	vector<int> B;
	cin >> n;
	rep(i, n)
	{
		cin >> a;
		A.push_back(a);
	}
	cin >> m;
	rep(i, m)
	{
		cin >> b;
		B.push_back(b);
	}
	
	rep(i, min(n, m))
	{
		if (A[i] > B[i])
		{
			cout << 0 << endl;
			exit(0);
		}
		else if (A[i] < B[i])
		{
			cout << 1 << endl;
			exit(0);
		}
	}
	if (n >= m)
	{
		cout << 0 << endl;
	}
	else
	{
		cout << 1 << endl;
	}
}


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

int main() {
	string s;
	cin >> s;
	
	int ctn = 0;
	rep(i, 3){
		if(s[i] == 'o'){
			ctn++;
		}
	}
	
	cout << 700 + ctn * 100 << endl;
	
}

Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <bitset>
using namespace std;

int GCD(int x, int y) {
	if (y == 0) return x;
	return GCD(y, x % y);
}

int main() {
	int ans = 0;
	int N;
	cin >> N;
	vector <int> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A.at(i);
	}
	
	vector <int> L(N), R(N);
	for (int i = 0; i < N; i++) {
		if (i != 0) {
			L.at(i) = GCD(L.at(i - 1), A.at(i));
		}
		else {
			L.at(i) = A.at(i);
		}
	}
	for (int i = N - 1; 0 <= i; i--) {
		if (i != N - 1) {
			R.at(i) = GCD(R.at(i + 1), A.at(i));
		}
		else {
			R.at(i) = A.at(i);
		}
	}

	for (int i = 0; i < N; i++) {
		if (i == 0) {
			ans = max(R.at(i+1), ans);
		}
		else if (i == N - 1) {
			ans = max(L.at(i - 1), ans);
		}
		else {
			ans = max(GCD(L.at(i - 1), R.at(i + 1)), ans);
		}
	}
	
	cout << ans << endl;

	return 0;
}

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

int main() { 
  int N;
  cin>>N;
  int A=0;
  for (int i = 0; i < N; i++) {
  int r,l;
    cin>>l>>r;
   A+=((r-l)+1);
    
} 
  cout<<A<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
int main(){
  int n;
  cin>>n;
  int array[105]={0},cnt[105]={0};
  int ma=0;
  for(int i=0;i<n;i++){
    cin>>array[i];
    ma=max(ma,array[i]);
    cnt[array[i]]++;
  }
  if(ma%2==0){
    if(cnt[ma/2]!=1){
      cout<<"Impossible"<<endl;
      return 0;
    }
    for(int i=0;i<ma/2;i++){
      if(cnt[i]>0){
        cout<<"Impossible"<<endl;
        return 0;
      }
    }
    for(int i=ma/2+1;i<=ma;i++){
      if(cnt[i]<2){
        cout<<"Impossible"<<endl;
        return 0;
      }
    }
  }
  else{
    if(cnt[ma/2+1]!=2){
      cout<<"Impossible"<<endl;
      return 0;
    }
    for(int i=0;i<=ma/2;i++){
      if(cnt[i]>0){
        cout<<"Impossible"<<endl;
        return 0;
      }
    }
    for(int i=ma/2+1;i<=ma;i++){
      if(cnt[i]<2){
        cout<<"Impossible"<<endl;
        return 0;
      }
    }
  }
  cout<<"Possible"<<endl;
  return 0;
}


Measured memory_bytes: 256
def isBingo(a):
    for i in range(3):
        if a[i][0] == a[i][1] and a[i][0] == a[i][2] and a[i][0] == -1:
            return 'Yes'
        elif a[0][i] == a[1][i] and a[0][i] == a[2][i] and a[0][i] == -1:
            return 'Yes'
    if a[0][0] == a[1][1] and a[0][0] == a[2][2] and a[0][0] == -1:
        return 'Yes'
    elif a[0][2] == a[1][1] and a[0][2] == a[2][0] and a[0][2] == -1:
        return 'Yes'
    else:
        return 'No'
    
a = []
for i in range(3):
    a.append(list(map(int, input().split())))
n = int(input())
b = []
for i in range(n):
    b.append(int(input()))

for i in range(n):
    for j in range(3):
        if b[i] in a[j]:
            a[j][a[j].index(b[i])] = -1

print(isBingo(a))

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

#define ll long long
#define PI acos(-1.0)
#define FOR(I, A, B) for (int I = (A); I < (B); ++I)

int main() {
  int N;
  string str;
  cin >> N;
  vector<int> s(4, 0);
  for (int i = 0; i < N; ++i) {
    cin >> str;
    if (str == "AC") {
      s[0]++;
    } else if (str == "WA") {
      s[1]++;
    } else if (str == "TLE") {
      s[2]++;
    } else {
      s[3]++;
    }
  }

  cout << "AC x " << s[0] << endl;
  cout << "WA x " << s[1] << endl;
  cout << "TLE x " << s[2] << endl;
  cout << "RE x " << s[3] << endl;
}

Measured memory_bytes: 3632
#include<iostream>
using namespace std;
int main(){
  int n,k;
  cin >> n >> k;
  
  bool okasi[n];
  for (int i=0; i<n; i++)
  {
    okasi[i] = false;
  }
  for (int i=0; i<k; i++)
  {
    int x;
    cin >> x;
    for(int j=0; j<x; j++)
    {
      int y;
      cin >> y;
      okasi[y-1]=true;  
    }
  }
  
  int it =0;
  for (int i=0; i<n; i++)
  {
    if(!okasi[i])
      it++;
  }
  cout << it;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main ()
{

int W , H, i, j, k, N, h[10000][2];
i  = 0;
k = 0;
do{

	cin >> W >> H;
	h[i][0] = W;
	h[i][1] = H;
	i++;
	k++;
	
}while(W != 0 && H != 0);

for (i = 0; i < k-1;i++)
{

	if(h[i][0] != 0 && h[i][1] != 0)
		{
			for(j = 0;j < h[i][0];j++)
				{	
						for(N = 0;N < h[i][1];N++)
						{	if(j == 0 || j == h[i][0] - 1 || N == 0 || N == h[i][1] - 1)
							{
							cout << "#";
							}
							else
							{
								cout << ".";
							}
						}
						cout  << endl;
				}
		
		cout  << endl;
		}
}

return 0;
}



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

int main(void){
    char c[4][4];
    int i;
    for(i=0;i<3;i++){
        scanf("%s",c[i]);
    }
    for(i=0;i<3;i++){
        printf("%c",c[i][i]);
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#define int long long
using namespace std;

const int INF = 1e9;

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, k;
    cin >> n >> k;
    vector <int> h(n), dp(n, INF);
    for(int &x : h) cin >> x;

    dp[n - 1] = 0;
    for(int i = n - 2; i >= 0; i--) {
        for(int j = i + 1; j < n && j <= i + k; j++) {
            dp[i] = min(dp[i], dp[j] + abs(h[j] - h[i]));
        }
    }

    cout << dp[0] << "\n";
}

Measured memory_bytes: 4776
s = gets.chomp.freeze
n = s.length

array_plus = (1..(n-1)).to_a

ans = s.to_i
array_plus.each do |plus_num|
  combination = (0..(n-2)).to_a.combination(plus_num).to_a
  ans_temp = 0

  combination.each do |comb|
    s_temp = "#{s}"
    k = 0
    (n-1).times do |j|
      if comb.include?(j)
        s_temp.insert(j+1+k, "+")
        k += 1
      end
    end

    array_s_temp = s_temp.split("+").map(&:to_i)
    array_s_temp.each do |ss|
      ans_temp += ss
    end

  end
  ans += ans_temp
end

puts ans


Measured memory_bytes: 14276
<?php
fscanf(STDIN, "%d", $a);
fscanf(STDIN, "%d", $b);
fscanf(STDIN, "%d", $c);
fscanf(STDIN, "%d", $d);
fscanf(STDIN, "%d", $e);
fscanf(STDIN, "%d", $k);

if($e - $a > $k){
    echo ':(';
}else{
    echo 'Yay!';
}
?>

Measured memory_bytes: 4728
#include "bits/stdc++.h"
using namespace std;

#define EPS (1e-10)
class P{                    //???
public:
    double x,y;
    
    P(double _x=0,double _y=0):x(_x),y(_y){};
    P operator + (P &p     ){ return P( x+p.x , y+p.y ); }  //??????
    P operator - (P &p     ){ return P( x-p.x , y-p.y ); }  //??????
    P operator * (double k ){ return P( x*k   , y*k    ); } //??????
    P operator / (double k ){ return P( x/k   , y/k    ); } //??????
    
    bool operator == (const P &p){ return ( fabs(x-p.x)<EPS && fabs(y-p.y)<EPS ); }
//    bool operator < (const P &p)const{ return ( x!=p.x ? x<p.x:y<p.y ); }
    
    double norm(){ return x*x+y*y; }        //?????????
    double abs() { return sqrt(norm()); }   //??§??????
    
};
struct L{P p1,p2;};         //??´???
typedef vector<P> Polygon;  //????§???¢
typedef P Vector;           //????????????

double dot  (Vector a,Vector b){ return a.x*b.x+a.y*b.y; }
double cross(Vector a,Vector b){ return a.x*b.y-a.y*b.x; }

int ccw(P p0,P p1,P p2){    //AOJ_BOOK_P386
    Vector a = p1 - p0;
    Vector b = p2 - p0;
    
    if( cross(a,b) > EPS  ) return 1 ;      //COUNTER_CLOCKWISE
    if( cross(a,b) < -EPS ) return -1;      //CLOCKWISE
    if( dot(a,b)   < -EPS ) return 2;       //ONLINE_BACK
    if( a.norm()   < b.norm() ) return -2;  //ONLINE_FRONT
    
    return 0;                               //ON_SEGMENT;
}

//??????????????????
bool intersect(P p1,P p2,P p3,P p4){ return ( ccw(p1,p2,p3)*ccw(p1,p2,p4)<=0 && ccw(p3,p4,p1)*ccw(p3,p4,p2)<=0 ); }



int main(){
    int x0,y0,x1,y1;
    cin>>x0>>y0>>x1>>y1;
    P P0(x0,y0), P1(x1,y1);
    
    int q;
    cin>>q;
    for(int i=0;i<q;i++){
        int x,y;
        cin>>x>>y;
        int res = ccw(P0,P1,P(x,y));
        if(res==1)cout<<"COUNTER_CLOCKWISE"<<endl;
        if(res==-1)cout<<"CLOCKWISE"<<endl;
        if(res==2)cout<<"ONLINE_BACK"<<endl;
        if(res==-2)cout<<"ONLINE_FRONT"<<endl;
        if(res==0)cout<<"ON_SEGMENT"<<endl;
    }
}

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

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

using namespace std;

int main(){
    int a, b;
    cin >> a >> b;
    int res = a + b;
cout << (res >= 10 ? "error" : to_string(res));
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <map>
#include <queue>
using namespace std;
#define F first
#define S second
const int INF=100000000;

int n;

void dfs(int sum,vector<int> sq){
	int q=sq.size();
	if(sum==n){
		for(int i=0; i<q; ++i){
			cout << sq[i];
			if(i==q-1) cout << endl;
			else cout << " ";
		}
		return;
	}
	for(int i=n-sum; i>0; --i){
		if(q==0||sq[q-1]>=i){
			vector<int> tmp=sq;
			tmp.push_back(i);
			dfs(sum+i,tmp);
		}
	}
}

int main(){
	while(cin>>n){
		if(n==0) break;
		dfs(0,vector<int>());
	}
	return 0;
}

Measured memory_bytes: 1224
from collections import deque

n = int(input())
aa = list(map(int, input().split()))
bb = deque()
left = True
for a in aa:
    if left:
        bb.append(a)
    else:
        bb.appendleft(a)
    left = not left

if not left:
    bb.reverse()
print(*list(bb))



Measured memory_bytes: 25412
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <array>
#include <tuple>
#include <random>

using namespace std;
typedef long long int ll;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

#define const INF 10000000000

ll a, b, c, n, x, y, z, w, h, ans = 0, cnt = 0, max = 0;
string s;

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

    cin >> s;
    rep(i, 2, s.size() - 1){
        if(s[i] == 'C'){
            cnt++;
        }else if(s[i] < 'a' || s[i] > 'z'){
            cout << "WA" << endl;
            return 0;
        }else{
            continue;
        }
    }
    if(s[1] < 'a' || s[1] > 'z'){
        cout << "WA" << endl;
        return 0;
    }
    if(s.back() < 'a' || s.back() > 'z'){
        cout << "WA" << endl;
        return 0;
    }
    if(cnt == 1 && s.front() == 'A' && s.back() != 'C'){
        cout << "AC" << endl;
    }else{
        cout << "WA" << endl;
    }
}



Measured memory_bytes: 256
//Robs Code
/***********HEADER***************/
#include <iostream>
#include <bitset>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#include <list>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <set>
#include <queue>
#include <map>
/***********MACROS***************/
#define int long long int
#define fri(l,k) for (i=l;i<=k;i++)
#define frj(l,k) for (j=l;j>=k;j--)
#define fij(a,b,l,k) for(i=a;i<=b;i++) for(j=l;j<=k;j++)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define endl "\n"
#define pb push_back
#define _1 first
#define _2 second
#define pii pair<int,int>
using namespace std;
int n,m,i,j,l,k,x,y,a,b,cnt[3],sum[3];
/***********MAIN**************/
int v[(int)3e3+20];
int dp[(int)3e3+20][(int)3e3+20][3];
int brute(int i,int j,int player){
	if(i > j){
		return 0;
	}
	if(dp[i][j][player] != -1){
		return dp[i][j][player];
	}
	int ans = 0;
	if(player == 1){
		ans = max(v[i]+brute(i+1,j,player^3),v[j]+brute(i,j-1,player^3));
	}else{
		ans = min(-v[i]+brute(i+1,j,player^3),-v[j]+brute(i,j-1,player^3));
	}
	dp[i][j][player] = ans;
	return ans;
}
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>v[i];
	}
	memset(dp,-1,sizeof dp);
	cout<<brute(0,n-1,1);
	return 0;
}
//.........

Measured memory_bytes: 214144
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        sc.close();

        System.out.println(a * b + " " + 2 * (a + b));
    }
}


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

using ll = long long;

int main()
{
    ll a, b, c; cin >> a >> b >> c;
    if(a+b > c)
    {
        cout << b+c;
    }
    else
    {
        ll res = 0;
        ll t = min(b, c);
        res += 2*t;
        b -= t; c -= t;

        if(c == 0) res += b;
        else res += min(a+1, c);

        cout << res; 
    }
    


    return 0;
}


Measured memory_bytes: 256
n = int(input())
song = []
for i in range(n):
    song.append(input().split(" "))
all_song = song.copy()
x = input()
last = 1
time = 0
num = len(song)
for song in song:
    if last == num:
        break
    if song[0] == x:
        for song in all_song[last:]:
            time += int(song[1])
        break
    last += 1
print(time)


Measured memory_bytes: 3060
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <numeric>
#include <cassert>
#include <cmath>
#include <map>
#include <set>
#include <iostream>

using namespace std;
typedef unsigned int uint;
typedef long long LL;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> PII;
typedef vector<PII > VPII;
typedef vector<VPII> VVPII;

#define FOR(k,a,b) for(int k(a); k < (b); ++k)
#define REP(k,a) for(int k=0; k < (a); ++k)
#define ABS(a) ((a)>0?(a):-(a))
#define EPS 1e-9

int main(int argc, char** argv) {
#ifdef HOME
	freopen("in.txt", "rb", stdin);
	freopen("out.txt", "wb", stdout);
#endif
	int N;
	scanf("%d", &N);
	vector<int> v(N);
	LL su = 0;
	REP(i, N)
	{
		scanf("%d", &v[i]);
		su += v[i];
	}
	printf("%s\n", ((su & 1) ? "NO" : "YES"));
	return 0;
}


Measured memory_bytes: 768
# standart input
# n = int(input())
# a = list(map(int, input().split()))

N = 13
MOD = 10 ** 9 + 7

s = input()[::-1]

dp = [0 for i in range(N)]
nextdp = [0 for i in range(N)]
zeros = [0 for i in range(N)]
dp[0] = 1

r = 1
for i, si in enumerate(s):
    nextdp = zeros[:]

    for j in range(10):
        jj = j
        if si == "?":
            pass
            # c = (j * 10 ** i) % N
        elif j == 0:
            jj = int(si)
        else:
            break

        for k in range(N):
            l = (k + r * jj) % N
            nextdp[l] = (nextdp[l] + dp[k]) % MOD

    dp = nextdp
    r = r * 10 % N

print(dp[5])


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

int main(){
    ll n;
    cin >> n;
    ll ans = 0;
    for(ll i = 1; i <= n-1;i++){
        ans += (n-1)/i;
    }
    cout << ans << endl;
}

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

int PrimeNumber(int n){
    if(n == 2)
        return 1;
    else if(n < 2 || n % 2 == 0)
        return 0;
    else{
        int i = 3;
        while(i <= sqrt(n)){
            if(n % i == 0)
                return 0;
            i = i + 2;
        }
        return 1;
    }
}

int main(void){
    int N, n;
    int cnt = 0;
    cin >> N;
    for(int i = 0; i < N; ++i){
        cin >> n;
        cnt += PrimeNumber(n);
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3008
#include <bits/stdc++.h>
#include <cstdio>
#include <chrono>
#include <random>
using namespace std;

#define DRACARYS ios_base::sync_with_stdio(false);cin.tie(NULL);cin.exceptions(cin.failbit);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define what_is(x) cerr << #x << " is " << x << endl;
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define PI 3.14159265
const long long int MAXN = 1e5+10;
const long long int MINN = 1e5+10;
const long long int inf = 1e9+10;

typedef long long ll; 
typedef long double ld; 
typedef pair<int, int> pii;
typedef vector<int> vi; 
typedef stack<int> st;

int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    DRACARYS
    int n,a[MAXN],dp[MAXN],k;
    cin>>n>>k;
    repA(i,1,n) cin>>a[i];
    dp[1]=0;
    repA(i,2,k+1){
        int m=inf;
        repD(j,i-1,1) m=min(m,dp[j]+abs(a[i]-a[j]));
        dp[i]=m;
    }
    repA(i,k+2,n){
        int m=inf;
        repD(j,i-1,i-k) m=min(m,dp[j]+abs(a[i]-a[j]));
        dp[i]=m;
    }
    cout<<dp[n]<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define sz(c)      int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
using namespace std;
using ll = long long;



int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);

	int a,b;
	cin>>a>>b;
	if (a<=5) {
		cout<<0<<endl;
	} else if (a<=12) {
		cout<<b/2<<endl;
	} else {
		cout<<b<<endl;
	}
}


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



int main(void){
	int N, D;
	int num;

	cin >> N;
	cin >> D;
	if (N % (2 * D + 1) == 0){
		num = N / (2 * D + 1);
	}
	else{
		num = (N / (2 * D + 1)) + 1;
	}
	cout << num << endl;

	return 0;
}

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

class Edge {
public:
	int u, v, w;
	Edge(int _u, int _v, int _w) : u(_u), v(_v), w(_w) {};
};

int main() {
	int L;
	cin >> L;
	vector<Edge> v;
	int N = 1;
	while ((1 << N) <= L) N++;
	for (int i = 1; i < N; i++) {
		v.push_back(Edge(i, i + 1, 0));
		v.push_back(Edge(i, i + 1, 1 << N - i - 1));
	}
	int range = (1 << N - 1) - 1;
	while (range < L - 1) {
		int gap = L - 1 - range;
		int n = N - 2;
		while (n > 0 && (1 << n) > gap) n--;
		if (n != 0) {
			v.push_back(Edge(1, N - n, range + 1));	
			range += (1 << n);
		} else {
			v.push_back(Edge(1, N, L - 1));
			range = L - 1;
		}		
	}
	int M = v.size();
	cout << N << " " << M << "\n";
	for (int i = 0; i < M; i++) cout << v[i].u << " " << v[i].v << " " << v[i].w << "\n";
	
	return 0;
}


Measured memory_bytes: 256
/**
 *    Coded by : lucky_21
 *               --------Lokesh Singh
**/

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

#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define     F           first
#define     S           second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<int,int>
#define     all(x)      x.begin(),x.end()
#define     fix         fixed<<setprecision(10)
#define     rep(i,a,b)  for(int i=int(a);i<=int(b);i++)
#define     repb(i,b,a) for(int i=int(b);i>=int(a);i--)
#define     FastIO      ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)

typedef double db;
typedef long long ll;

const int N=105;
const int mod=1e9+7;

bool c[N][N];
int h,w,dp[N][N][2];
int dfs(int i,int j,bool prev){
    if(i==h and j==w) return c[i][j]?!prev:0;
    if(i>h or j>w) return 1e9;
    int &cache=dp[i][j][prev];
    if(cache!=-1) return cache;
    if(c[i][j]){
        return cache=!prev+min(dfs(i,j+1,1),dfs(i+1,j,1));
    }
    return cache=min(dfs(i,j+1,0),dfs(i+1,j,0));
}
signed main(){
    FastIO;
    cin>>h>>w;
    rep(i,1,h) rep(j,1,w){
        char k;
        cin>>k;
        c[i][j]=(k=='#');
    }
    memset(dp,-1,sizeof dp);
    cout<<min(dfs(1,1,0),1+dfs(1,1,1));
    return 0;
}


Measured memory_bytes: 384
#-*-coding:utf-8-*-

def main2():
    k,s = map(int,input().split())
    counter=0
    for x in range(k+1):
        for y in range(k+1):
            if 0<=s-x-y <=k:
                counter+=1
    print(counter)

if __name__=="__main__":
    main2()

Measured memory_bytes: 2940