akhauriyash/Code-Regression huggingface dataset:
#-swank
(unless (member :child-sbcl *features*)
  (quit
   :unix-status
   (process-exit-code
    (run-program *runtime-pathname*
                 `("--control-stack-size" "128MB"
                   "--noinform" "--disable-ldb" "--lose-on-corruption" "--end-runtime-options"
                   "--eval" "(push :child-sbcl *features*)"
                   "--script" ,(namestring *load-pathname*))
                 :output t :error t :input t))))
(defmacro dp (name args memo-size &body body)
  (let ((memo (gensym)))
    `(let ((,memo (make-array ,memo-size :initial-element nil)))
       (defun ,name ,args
         (or (aref ,memo ,@args)
             (setf (aref ,memo ,@args)
                   ,@body))))))

(defun split (x str)
  (let ((pos (search x str))
        (size (length x)))
    (if pos
        (cons (subseq str 0 pos)
              (split x (subseq str (+ pos size))))
        (list str))))

(defmacro collect-times (time body)
  `(loop repeat ,time collect ,body))

(defun read-times (time)
  (collect-times time (read)))

(defmacro aif (expr then else)
  `(let ((it ,expr))
     (if it ,then ,else)))

(defmacro awhen (expr &rest then)
  `(aif ,expr (progn ,@then) nil))

(defun comulative (function list &key base)
  (if base
      (comulative function (cons base list))
      (do ((lst (cdr list) (cdr lst))
           (acc (list (car list))))
          ((null lst) (reverse acc))
        (push (funcall function (car acc) (car lst)) acc))))

(defun binary-search (function left right
                      &optional
                        (eps 1)
                        (average-function (lambda (x y) (ash (+ x y) -1))))
  (if (<= (abs (- left right)) eps)
      right
      (let ((mid (funcall average-function left right)))
        (if (funcall function mid)
            (binary-search function left mid eps average-function)
            (binary-search function mid right eps average-function)))))

(defun arithmetic-mean (&rest body)
  (/ (apply #'+ body) (length body)))

(defvar +MOD+ (+ (expt 10 9) 7))

(defun mapa-b (fn a b &optional (step 1))
  (do ((i a (+ i step))
       (result nil))
      ((> i b) (nreverse result))
    (push (funcall fn i) result)))

(defun map0-n (fn n)
  (mapa-b fn 0 n))

(defun map1-n (fn n)
  (mapa-b fn 1 n))

(defun read-string (&optional (stream *standard-input*))
  (labels ((is-empty (x)
             (or (char= x #\space) (char= x #\newline))))
    (loop for char = (read-char stream)
          with result
          when (is-empty char)
            do (return (concatenate 'string (nreverse result)))
          do (push char result))))

(defun main (k lst &aux (heights (sort (copy-list lst) #'<)))
  (loop for i in heights
        for j in (nthcdr (1- k) heights)
        minimize (- j i)))

(let ((n (read))
      (k (read)))
  (princ (main k (read-times n))))


Measured memory_bytes: 62520
#include<bits/stdc++.h>
using namespace std;
int main() {
  map<char,int>a;
  char c;
  string s;
  cin>>s;
  for (int i=0;i<s.size();++i) ++a[s[i]];
  for (map<char,int>::iterator i=a.begin();i!=a.end();++i) {
    if (i->second&1) return puts("No"),0;
  }
  puts("Yes");
}

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

int64_t MOD;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

int main(){
    int N, K;
    cin >> N >> K >> MOD;
    // 末尾に0があると見なして考えるので長さを1増やしておく
    N++;

    // pow[i][j] = i**j mod MOD の前計算
    int64_t pow[302][302] = {0};
    for(int i=1; i<=301; i++){
        pow[i][0] = 1;
        for(int j=1; j<=301; j++) pow[i][j] = pow[i][j-1] * i % MOD;
    }

    // sub[i][j] = 1~iから重複を許してj個選ぶ組み合わせそれぞれについて積を取った合計
    int64_t sub[302][302] = {0};
    sub[0][0] = 1;
    for(int i=1; i<=301; i++) for(int j=0; j<=301; j++) for(int k=0; j+k<=301; k++) add(sub[i][j+k], sub[i-1][j] * pow[i][k]);

    // 本命のDP
    int64_t dp[302][302] = {0};
    dp[0][1] = 1;
    for(int i=1; i<=301; i++) for(int j=0; j<=301; j++) for(int k=0; j+k<=301; k++) add(dp[i][j+k], dp[i-1][j] * sub[j][k]);

    cout << dp[K][N] << endl;
    return 0;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  ll sx[n], sy[n], cx[m], cy[m];
  REP(i, n) cin >> sx[i] >> sy[i];
  REP(i, m) cin >> cx[i] >> cy[i];
  ll d, md, mi;
  REP(i, n) {
    md = LLONG_MAX;
    REP(j, m) {
      d = abs(sx[i] - cx[j]) + abs(sy[i] - cy[j]);
      if (d < md) {
        md = d;
        mi = j;
      }
    }
    cout << mi + 1 << endl;
  }
  return 0;
}

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

using namespace std;

#define max(a,b) (a>b? a:b)
#define min(a,b) (a<b? a:b)
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define ONLINE_JUDGE

#pragma GCC Optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment (linker,"/stack:200000000")

typedef long long ll;

bool Finish_read;

template<class T>inline void read(T &x){Finish_read=0;x=0;T f=1;char ch=getchar();while(!isdigit(ch)){if(ch=='-')f=-1;if(ch==EOF)return;ch=getchar();}while(isdigit(ch))x=x*10+ch-'0',ch=getchar();x*=f;Finish_read=1;}
template<class T>inline void print(T x){if(x/10!=0)print(x/10);putchar(x%10+'0');}
template<class T>inline void writeln(T x){if(x<0)putchar('-');x=abs(x);print(x);putchar('\n');}
template<class T>inline void write(T x){if(x<0)putchar('-');x=abs(x);print(x);}

int main() {
#ifndef ONLINE_JUDGE
    FO(FileName)
#endif
    int a,b,x;
    read(a),read(b),read(x);
    if(x<a||a+b<x)
        puts("NO");
    else
        puts("YES");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define pdi pair<db,int>
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define eps 1e-8
#define mo 974711
#define MAXN 200005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;char c = getchar();T f = 1;
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 + c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
int A,B;
int d[15][15];
int f[105][105],tot,gx[105],gy[105],S,T;
pii p[305 * 305];
int val[305 * 305],cnt;
int check(int x,int y) {
    int res = 1000000;
    for(int i = 0 ; i <= 100 ; ++i) {
	for(int j = 0 ; j <= 100 ; ++j) {
	    res = min(res,f[i][j] + i * x + j * y);
	}
    }
    return res;
}
void Solve() {
    read(A);read(B);
    for(int i = 1 ; i <= A ; ++i) {
	for(int j = 1 ; j <= B ; ++j) {
	    read(d[i][j]);
	}
    }
    for(int i = 0 ; i <= 100 ; ++i) {
	for(int j = 0 ; j <= 100 ; ++j) {
	    for(int k = 1 ; k <= A ; ++k) {
		for(int h = 1 ; h <= B ; ++h) {
		    f[i][j] = max(f[i][j],d[k][h] - k * i - h * j);
		}
	    }
	} 
    }
    for(int i = 1 ; i <= A ; ++i) {
	for(int j = 1 ; j <= B ; ++j) {
	    if(check(i,j) != d[i][j]) {
		puts("Impossible");
		return;
	    }
	}
    }
    puts("Possible");
    S = ++tot;
    gx[0] = S;
    for(int i = 1 ; i <= 100 ; ++i) {
	gx[i] = ++tot;
	p[++cnt] = mp(gx[i - 1],gx[i]);
	val[cnt] = -2;
    }
    T = ++tot;
    gy[0] = T;
    for(int i = 1 ; i <= 100 ; ++i) {
	gy[i] = ++tot;
	p[++cnt] = mp(gy[i],gy[i - 1]);
	val[cnt] = -1;
    }
    for(int i = 0 ; i <= 100 ; ++i) {
	for(int j = 0 ; j <= 100 ; ++j) {
	    p[++cnt] = mp(gx[i],gy[j]);
	    val[cnt] = f[i][j];
	}
    }
    out(tot);space;out(cnt);enter;
    for(int i = 1 ; i <= cnt ; ++i) {
	out(p[i].fi);space;out(p[i].se);space;
	if(val[i] < 0) {
	    if(val[i] == -2) {puts("X");}
	    else puts("Y");
	}
	else {out(val[i]);enter;}
    }
    out(S);space;out(T);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


Measured memory_bytes: 512
h,w=map(int,input().split())
cnt=0
s=[input() for _ in range(h)]
for x in s:
	cnt+=x.count(".")
ans=0
inf=10**8
dp=[[inf]*w for _ in range(h)]
dp[0][0]=0
from collections import deque
queue=deque([(0,0)])
d=((0,1),(0,-1),(1,0),(-1,0))
while queue:
	r=queue.popleft()
	for x in d:
		xx=r[0]+x[0];yy=r[1]+x[1]
		if 0<=xx<h and 0<=yy<w:
			if s[xx][yy]=="." and dp[xx][yy]==inf:
				dp[xx][yy]=dp[r[0]][r[1]]+1
				queue.append((xx,yy))
if dp[-1][-1]==inf:
	print(-1)
	exit()
print(cnt-dp[-1][-1]-1)


Measured memory_bytes: 3316
#include <stdio.h>

int main()
{
    int i=0,ai,bi;
    long double a,b;
    long double f;
    scanf("%Lf %Lf",&a,&b);
    ai=(int)a/b;
    bi=(int)a%(int)b;
    f=a/b;
    printf("%lld %lld %Lf\n",ai,bi,f);
    return 0;
}


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

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

    cout << min(a, b) << ' ' << max(0, (a + b) - n) << endl;
    return 0;
}


Measured memory_bytes: 3640
#include<iostream>
using namespace std;
int main()
{
    int a[10],b[10],i,j,k,A,B,C,D,E,l,sum=0,max,s=0;
    for(i=0; i<5; i++)
    {
        cin>>a[i];
        b[i]=a[i]%10;
    }
    max=0;
    for(i=0; i<5; i++)
    {
        if(b[i]==0)
        {
            sum=sum+a[i];
            b[i]=-1;
            s++;
        }
    }
    s=5-s;
    while(s--)
    {
        max=0;
        for(i=0; i<5; i++)
        {
            if(max<b[i])
            {
                max=b[i];
                l=i;
            }
        }
        b[l]=-1;
        if(s!=0)
            sum=sum+a[l]+(10-max);
        else if(s==0)
            sum=sum+a[l];
    }

    cout<<sum<<endl;
    return 0;
}


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

using LL = long long;

#define ALL(a) begin((a)), end((a))
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define RFOR(i, a, b) for (int(i) = (a); (i) > (b); (i)--)
#define debug(x) cout << #x << " : " << x << '\n'

const int INF = 1e9;
const int MOD = 1e9 + 7;
const LL LINF = 1e16;

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

  int N, M;
  cin >> N >> M;
  vector<string> A(N), B(M);
  string temp;
  FOR(i, 0, N) { cin >> A[i]; }
  FOR(i, 0, M) { cin >> B[i]; }

  int sub = N - M;
  bool flag;

  FOR(i, 0, sub + 1) {
    FOR(j, 0, sub + 1) {
      flag = true;

      FOR(ii, 0, M) {
        FOR(jj, 0, M) {
          if (A[i + ii][j + jj] != B[ii][jj]) {
            flag = false;
          }
        }
      }

      if (flag) {
        cout << "Yes" << '\n';
        return 0;
      }
    }
  }

  cout << "No" << '\n';
  return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


def solve():
    a,b,c,n = [int(x) for x in input().split()]
    cnt = 0
    for i in range(0,n+1,a):
        for j in range(0,n+1,b):
            if i + j == n or (
                i + j < n and (
                    (n - (i + j)) % c == 0
                )):
                cnt += 1
    print(cnt)


    

t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""

1 + k



"""


Measured memory_bytes: 9400
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;

long long int INF = 1e18;
long long int mod = 1000000007;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
ll bit[500005];
//↓,→,↑,←

#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(15)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl

ll rui(ll abc,ll bed){
    //abcのbed乗を計算する
    if(bed==0){return 1;}
    else{
        ll ced = rui(abc,bed/2);
        ced *= ced;
        ced %= mod;
        if(bed%2==1){ced*=abc; ced%=mod;}
        return ced;
    }
}
ll gcd(ll number1,ll number2){
	if(number1 > number2){
		swap(number1,number2);
	}
	if(number1 == 0 || number1 == number2){
		return number2;
	}else{
		return gcd(number2 % number1,number1);
	}
}

ll i,j,k,ii,jj,r,l;
ll n,m,num,sum,ans;
ll a,b,c,d,e,g,h,w;
ll x[500005],y[500005],z[500005];
bool dp[10000];
char s[500005];

ll bitsum(ll i){
	ll s = 0;
	while(i>0){
		//p("hoi");
		s += bit[i];
		i -= i & -i;
	}
	return s;
}
void bitadd(ll b,ll x){
	while(b <= n){
		//p("hoi");
		bit[b] += x;
		b += b & -b;
	}
}

int main(){
	cin >> n;
	if(n < 1200){
		p("ABC");
	}else if(n < 2800){
		p("ARC");
	}else{
		p("AGC");
	}

 
 
	return 0;
}

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

int main() {
  ll n,k;
  cin >> n >> k;
  vector<ll>a(n);
  rep(i,0,n) cin >> a[i];
  sort(a.begin(),a.end());
  ll sum = 0;
  rep(i,0,k) sum += a[i];
  cout << sum << endl;
}

Measured memory_bytes: 3584
from collections import defaultdict
def main():
    N = int(input())
    A = list(map(int, input().split()))
    d = defaultdict(int)
    for i in range(N):
        if A[i] % 2 == 0:
            if A[i] % 4 == 0:
                d[2] += 1
            else:
                d[1] += 1
        else:
            d[0] += 1
    
    if d[1] == 0:
        if d[0] - 1 <= d[2]:
            print('Yes')
            exit()
    else:
        if d[0] <= d[2]:
            print('Yes')
            exit()

    print('No')

    


if __name__ == "__main__":
    main()

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

namespace cplib {
    struct UnionFind {
        std::vector<int> par, size;
        
        UnionFind(int n): par(n), size(n) {
            for (int i = 0; i < n; i++) {
                par[i] = i;
                size[i] = 1;
            }
        }

        int root(int i) {
            if (par[i] == i) {
                return i;
            } else {
                par[i] = root(par[i]);
                return par[i];
            }
        }
        bool is_same(int i, int j) {
            return root(i) == root(j);
        }
        void unite(int i, int j) {
            if (!is_same(i, j)) {
                if (size[i] < size[j]) {
                    std::swap(i, j);
                }
                size[root(i)] += size[root(j)];
                par[root(j)] = root(i);
            }
        }
        int get_size(int i) {
            return size[root(i)];
        }
    };
}

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

    cplib::UnionFind uf(n);
    for (int i = 0; i < q; i++) {
        int c, x, y;
        std::cin >> c >> x >> y;
        if (c == 0) {
            uf.unite(x, y);
        } else {
            std::cout << (int)uf.is_same(x, y) << std::endl;
        }
    }

    return 0;
}



Measured memory_bytes: 3188
#include <iostream>
#include <cstdio>
#include <functional>
#include <vector>
#include <map>
#include <algorithm>

int main()
{
    int N = 1;

    std::cin >> N;
    typedef std::map<int, int> data_type; // number of students, id

    data_type come_in;
    int a; // number of students;
    for (int i = 0; i < N; ++i)
    {
        std::cin >> a;
        come_in[a - 1] = i + 1;
    }

    // Output
    for (int i = 0; i < N; ++i)
    {
        printf("%d", come_in[i]);
        if (i == N - 1)
        {
            printf("\n");
        }
        else
        {
            printf(" ");
        }
    }
    return 0;
}


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

using namespace std;

int main(){
    int N,K,ans=1000000000;
    cin >> N >> K;
    vector<int> x(N);
    for(int i=0;i<N;i++){
        cin >> x[i];
    }

    for(int i=K-1;i<N;i++){
        if(0<x[i] && x[i-K+1]<0){
            ans = min(2*min(abs(x[i]),abs(x[i-K+1]))+max(abs(x[i]),abs(x[i-K+1])),ans);
        }else{
            ans = min(ans,max(abs(x[i]),abs(x[i-K+1])));
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 768
#include <stdio.h>
int main(void) {
    int num,i,x1,x2,y1,y2,z1,z2,w1,w2;
    while (scanf("%d",&num)!=EOF&&num!=0) {
        for (i=0; i<num; i++) {
            scanf("%d%d%d%d%d%d%d%d",&x1,&y1,&z1,&w1,&x2,&y2,&z2,&w2);
            printf("%d %d %d %d\n",x1*x2-y1*y2-z1*z2-w1*w2,x1*y2+y1*x2+z1*w2-w1*z2,x1*z2+z1*x2-y1*w2+w1*y2,x1*w2+w1*x2+y1*z2-z1*y2);
        }
    }
    return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
    ll n,i,j,w;
    cin>>n>>w;
    ll weight[n],val[n];
    ll dp[n+1][w+1];
    for(i=0;i<n;i++)
    {
        cin>>weight[i]>>val[i];
    }
    for(i=0;i<=n;i++)
    {
        dp[i][0]=0;
    }
    for(i=1;i<=w;i++)
    dp[0][i]=0;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=w;j++)
        {
            if(weight[i-1]<=j)
            dp[i][j]=max(dp[i-1][j],val[i-1]+dp[i-1][j-weight[i-1]]);
            else
            dp[i][j]=dp[i-1][j];
        }
    }
    cout<<dp[n][w]<<endl;
}


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

int main() {
  char a;
  cin >> a;
  if(a == 'a' || a == 'i' || a == 'u' || a == 'o' || a == 'e')
    cout << "vowel" << endl;
  else
    cout << "consonant" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
int main(void){
  int n;
  double mid;
  int a[100000];
  std::cin >> n;
  for(int i=0;i<n;i++){
    std::cin >> a[i];
  }
  std::sort(a,a+n);
  mid = (double)a[n-1]/2;
  int min = a[n-1];
  int mina;
  for(int i=0;i<n;i++){
    if(min > abs(mid-a[i])){
      min = abs(mid-a[i]);
      mina = a[i];
    }
  }
  printf("%d %d\n",a[n-1],mina);
  return 0;
}
  
  

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
using namespace std;

  int main(){
int n;
cin>> n;
cout << n%9 << endl;
return 0;}

Measured memory_bytes: 256
module Main where
import qualified Control.Monad as C
import qualified Data.Char as C
import qualified Data.List as L
import qualified Data.Map as M
import qualified Data.Array as A

int = read :: String -> Int
getWord :: IO String
getWord = do
  c <- getChar
  if C.isSpace c
  then
    return []
  else do
    ws <- getWord
    return (c:ws)
getInt = fmap int getWord
replace pred a = map (\x -> if pred x then a else x)

main = interact $ printer . solver . parser
parser = map int . tail . words
printer = (++"\n") . show

solver xs = sum [ x*y | (x,i)<-zs, (y,j)<-zs, i<j]
  where
    zs = zip xs [1..]

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

int main(){
  int n,R;
  int minn,maxn;

  cin >> n;

  cin >> R;

  minn = R;

  maxn = -1e9;
  
  for(int i=1;i<n;++i){
    cin >> R;

    maxn = max(maxn, R - minn);
    
    minn = min(minn, R);
  }

  cout << maxn << endl;
  
  return 0;
}



Measured memory_bytes: 3100
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    n,ma,mb=MI()
    inf=10**9
    abc=[LI() for _ in range(n)]
    dp=[[[inf]*(n*10+1) for _ in range(10*n+1)] for _ in range(n+1)]
    dp[0][0][0]=0
    for i,(a,b,c) in enumerate(abc):
        for j in range(n*10+1):
            for k in range(n*10+1):
                pre=dp[i][j][k]
                if pre==inf:continue
                dp[i+1][j][k]=min(dp[i+1][j][k],pre)
                dp[i+1][j+a][k+b]=min(dp[i+1][j+a][k+b],pre+c)
    ans=inf
    for i in range(1,105):
        a=i*ma
        b=i*mb
        if a>n*10 or b>n*10:break
        ans=min(ans,dp[n][a][b])
    if ans==inf:print(-1)
    else:print(ans)

main()

Measured memory_bytes: 59488
// Problem : E - Red Scarf
// Contest : AtCoder - AtCoder Beginner Contest 171
// URL : https://atcoder.jp/contests/abc171/tasks/abc171_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sort(a) sort(all(a))
#define ff first
#define ss second
#define vi vector<int>
#define pii pair<int, int>
#define vll vector<ll>
#define pll pair<ll,ll>
#define mod (int)1e9+7
#define FAST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define repf(i,a,b) for(i=a;i<b;i++)
#define repb(i,a,b) for(i=a;i>=b;i--)
#define N 100005
int main()
{
	FAST
    int t=1;
    //cin>>t;
    while(t--)
    {
		ll n,i;
		cin>>n;
		vll a(n);
		ll x=0;
		repf(i,0,n)
		{
			cin>>a[i];
			x^=a[i];
		}
		repf(i,0,n)
		cout<<(x^a[i])<<" ";
    }
    return 0;
} 


Measured memory_bytes: 4708
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,e) for(int i = a;i < e;++i)
using LL = long long;

int main() {

	int a, b; 
	
	cin >> a >> b;
	int ans = max({ a + b,a - b,a*b });
	cout << ans << endl;


}




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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
typedef double DOUBLE;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9 + 10;
const ll MOD = 1e9 + 7;

const int MAXN = 2e5 + 5;

int a[MAXN];

void solve(){
	int n;
	scanf("%d", &n);
	int avg = 0;
	REP(i, 0, n) {
		scanf("%d", &a[i]);
		a[i] *= n;
		avg += a[i];
	}
	avg /= n;
	int mini = 0;
	REP(i, 0, n) {
		if (abs(a[i] - avg) < abs(a[mini] - avg)) {
			mini = i;
		}
	}
	printf("%d\n", mini);
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


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

int main()
{
    long long int h,n,sum=0;
    cin>>h>>n;
    for (long long int i=0; i<n; i++)
    {
        long long int a;
        cin>>a;
        sum=(sum+a)%(1000000000+7);
    }
    if (sum>=h)
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
}

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

const int maxn = 2e5 + 20;

int n;
char S[maxn], T[maxn];
int ans;

int main() {
	scanf("%s%s", S, T);
	n = strlen(S);
	for(int i = 0; i < n; i++) {
		if(S[i] != T[i]) ans++;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 4216
#include <stdio.h>
 
int main (void)
{
    int n,i,X[100];
     
    scanf("%d/n",&n);
     
    for(i = 0;i < n;i++){
 
    scanf("%d\n",&X[i]);
 
    }
     
    for(i=0;i<n;i++){
         
        printf("%d",X[n-i-1]);
         
        if(i<n-1){
        printf(" ");
        }
         
 
    }
     
        printf("\n");
    return 0;
 
}


Measured memory_bytes: 2036
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long h;
  cin>>h;
  if(h == 1){
    cout<<1<<endl;
    return 0;
  }
  if(h % 2 != 0)h--;
  long double height = log2(h);
  long long res = 1;
  for(int i = 0; i <= height; ++i){
    res *= 2;
  }
  cout<<res - 1<<endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input()) # n >= 2
h = list(map(int, input().split())) # h_i >= 1

cost2 = 0;
cost1 = abs(h[1] - h[0]);

for i in range(2, n):
    cost = min(cost1 + abs(h[i] - h[i - 1]), cost2 + abs(h[i] - h[i - 2]))
    cost2, cost1 = cost1, cost

print(cost1)

Measured memory_bytes: 13980
N=gets.to_i
P = gets.split.map(&:to_i)

aj = 0
fj = false
N.times{|i|
  if P[i] == i+1 then
    if !fj then
      aj += 1
      fj = true
    else
      fj = false
    end
  else
    fj = false
  end
}

puts aj


Measured memory_bytes: 8068
MOD = 10**9+7

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def main():
    X, Y = list(mi())
    if 4*X-Y >= 0 and (4*X-Y)%2 == 0 and (4*X-Y)//2<= X:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()

Measured memory_bytes: 61648
MODE = "stdio"
#require 'matrix'
#include Math
line = Array.new

if(defined? MODE)
  line = STDIN.read.split("\n")
else
  tmp = '1 1 +'.split("\n")
  tmp.each{|s|
    line << s.strip
  }
end


arr = line[0].split(" ")
stack = []
arr.each do |i|
  case i
  when "+"
    stack.push(stack.pop+stack.pop)
  when "-"
    stack.push(-stack.pop+stack.pop)
  when "*"
    stack.push(stack.pop*stack.pop)
  else
    stack.push(i.to_i)
  end
#  p stack
end

puts stack.pop

Measured memory_bytes: 8668
#include<cstdio>
#include<cstring>

int main(void) {
    char s[100000];
    scanf("%s",s);

    int i=0, j=strlen(s)-1;
    int a=0;
    for(; i<j; i++, j--) {
        if(s[i] == s[j]) continue;
        if(s[i] == 'x') { a++, j++; continue; }
        if(s[j] == 'x') { a++, i--; continue; }
        printf("-1\n");
        return 0;
    }
    printf("%d\n", a);
    return 0;
}

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

int main() {
    int d, t, s;
    cin>>d >>t >>s;
    if(s*t>=d) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 3644
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner s=new Scanner(System.in);
  int omo[]=new int[4];
  for(int i=0;i<4;i++)
    omo[i]=s.nextInt();
  if(omo[0]+omo[1]<omo[2]+omo[3])
    System.out.print("Right");
  else if(omo[0]+omo[1]>omo[2]+omo[3])
    System.out.print("Left");
  else
    System.out.print("Balanced");
}
}

Measured memory_bytes: 21716
N = int(input())
B = []
B = list(map(int, input().split()))

A = 0

for i in range(N):
    if i == 0:
        A += B[0]
    elif i < len(B):
#         print(i, B[i-1], B[i])
        A += min(B[i-1], B[i])
    elif i == N-1:
        A += B[i-1]
        
print(A)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int main(){

    int A,B,N,M,H,W;
    int i,j,k;
    int min = 1000000000;
    int max = 0;
    int a,b,c,d;
    int count=0,count_two=0,v;
    string S[50];

    cin >> a >> b;

    for(i=1;i<=a;i++){
        for(j=1;j<=12;j++){
            if(i==a && j==b){
                if(i==j)count++;
                break;           
            }
        if(i == j)count++;
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define all(v) (v).begin() , (v).end()

using namespace std;

typedef vector<int> vi;
typedef long long  ll;

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

map<int,int> m;

int main()
{
    int n;
    cin>> n;
    for(int i=0;i<n;++i){
        int num;
        cin>>num;
        if(!m.count(num)){
            m[num] = 1;
        }else{
            m[num]++;
        }
    }
    map<int,int>::iterator it;
    int ans = 0;
    for(it = m.begin() ; it != m.end() ; ++it){
        int base = it -> first , frq = it -> second;
        if(frq < base){
            ans += frq;
        }
        else if (frq > base){
            ans += frq - base;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
int n; long long a[55], ret;
int main() {
	cin >> n;
	for(int i = 0; i < n; i++) cin >> a[i];
	while(true) {
		int ptr = max_element(a, a + n) - a;
		if(a[ptr] < n) break;
		for(int j = 0; j < n; j++) {
			if(j != ptr) a[j] += a[ptr] / n;
		}
		ret += a[ptr] / n;
		a[ptr] %= n;
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i, a, b) for(int i = (a);i < (b);++i)
#define FORR(i, b, a) for (int i = (b) - 1;i >= 0;--i)
#define REP(i, n) for(int i = 0;i < (n);++i)
#define REPR(i, n) for(int i = (n) - 1;i >= 0;--i)
#define ITER(itr, v) for(auto itr = v.begin();itr != v.end();++itr)
#define SORT(v) sort(v.begin(), v.end())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;




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

	double L;
	cin >> L;
	cout << fixed << setprecision(10) << pow(L / 3, 3) << endl;

	return 0;
}

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

/*............................*/

#define uint uint64_t
#define mx 100001
#define ll long long int
#define ull unsigned long long int
#define pii pair<int, int>
#define pll pair<long long int, long long int>
#define mp make_pair
#define pb push_back
#define inf INT_MAX
#define pi acos(-1)
#define eps 1e-8
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b) / __gcd(a, b)
#define input(ara, n)          \
   for (int i = 0; i < n; i++) \
   scanf("%d", &ara[i])
#define inputl(ara, n)                   \
   for (long long int i = 0; i < n; i++) \
   scanf("%lld", &ara[i])
#define pf(a) printf("%d\n", a);
#define pfl(a) printf("%lld\n", a);
#define pfi(a) printf("%d ", a);
#define pfll(a) printf("%lld ", a);
#define sc(a) scanf("%d", &a)
#define scc(a, b) scanf("%d %d", &a, &b)
#define sccdbl(a, b) scanf("%lf %lf", &a, &b)
#define sccc(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define scccdbl(a, b, c) scanf("%lf %lf %lf", &a, &b, &c)
#define scl(a) scanf("%lld", &a)
#define sccl(a, b) scanf("%lld %lld", &a, &b)
#define scccl(a, b, c) scanf("%lld %lld %lld", &a, &b, &c)
using namespace std;
vector<pii> node[100001];
bool visited[100001];
ll color[100001];
void dfs(ll u)
{
   visited[u] = true;
   for (ll i = 0; i < node[u].size(); i++)
   {
      ll v = node[u][i].first;
      ll w = node[u][i].second;
      if (!visited[v])
      {
         if (w % 2 == 0)
         {
            color[v] = color[u];
         }
         else
         {
            color[v] = 1 - color[u];
         }
         dfs(v);
      }
   }
}
int main()
{
   // int t;
   // sc(t);
   // while (t--)
   // {

   // }
   ll n, u, v, w;
   scl(n);
   for (ll i = 0; i < n - 1; i++)
   {
      scccl(u, v, w);
      node[u].pb(mp(v, w));
      node[v].pb(mp(u, w));
   }
   color[1] = 1;
   dfs(1);
   for (ll i = 1; i <= n; i++)
   {
      pfl(color[i]);
   }
   return 0;
}


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

int main(){
    int a;
    cin>>a;
    int b;
    cin>>b;
    int c;
    cin>>c;
    int count=0;

    for(int i=a;i<=b;++i){
        
        if(c%i==0)
          ++count;
    }
    cout<<count<<endl;
    
}



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

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

typedef long long ll;
const ll MOD = 1e9 + 7;

int main() {
  ll H;
  int N;
  std::cin >> H >> N;

  ll sum = 0;
  rep(i, N) {
    int A;
    std::cin >> A;
    sum += A;
  }

  if(sum >= H) {
    std::cout << "Yes" << '\n';
  } else {
    std::cout << "No" << '\n';
  }


}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a, b, c, i, count;
	a = b = c = i = count = 0;
	scanf("%d %d %d", &a, &b, &c);
	
	for (i = a; i <= b; i++)
	{
		if (c % i == 0)
		{
			count = count + 1;

		}
	}

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

	return 0;

}


Measured memory_bytes: 2104
S = input()
N = len(S)
for i in range(N - 1):
    if S[i] == S[i + 1]:
        print(i + 1, i + 2)
        exit(0)

for i in range(N - 2):
    if S[i] == S[i + 2]:
        print(i + 1, i + 3)
        exit(0)

print(-1, -1)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define dbg(x) cout<< #x << ": " << x << "\n";
using namespace std;
#define inf 1e9+7
#define PI  3.14159265358979323846264338327950L
#define pii pair<ll,ll> 




int  main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int a,b,d;
	cin>>a>>b>>d;
	int cnt=0;
	for(int i=a; i<=b; ++i){
		if(i%d==0) cnt++;
	}
	cout<<cnt;
}
    

	




Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a , b , c , d ;
  cin >> a >> b >> c >> d ;
  if (a + b > c + d){
    cout << "Left" << endl ;
  }
  else if (a + b < c + d){
    cout << "Right" << endl ;
  }
  else {
   cout << "Balanced" << endl ;
  } 
}

Measured memory_bytes: 256
// AUTHOR: ROSHAN SRIVASTAVA
// WEBSITE: https://www.youtube.com/channel/UC6uQdd7kLLOdlHSVklhV7Cw

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007


int dp[3009][3009];
int n, m;
string s, t;

int solve(int idx, int jdx) {
    if(idx == n || jdx == m)
        return 0;
    
    if(dp[idx][jdx] != -1)
        return dp[idx][jdx];

    int ans;

    if(s[idx] == t[jdx])
        ans = 1 + solve(idx + 1, jdx + 1);
    else 
        ans = max(solve(idx + 1, jdx), solve(idx, jdx + 1));

    return dp[idx][jdx] = ans;

}

int main(){


#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    memset(dp, -1, sizeof dp);

    cin>>s>>t;
    n = s.length();
    m = t.length();

    int l = solve(0, 0);
    // cout<<l<<endl;

    char lcs[l + 1];
    lcs[l] = '\0';

    int i = 0, j = 0;
    int idx = 0;

    while(i < n && j < m) {

        if(s[i] == t[j])  {
            lcs[idx] = s[i];
            i++; j++; idx++;
        } else if (dp[i + 1][j] > dp[i][j + 1]) i++;
        else j++;
    }
    cout<<lcs<<endl;

    return 0;
}

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

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;

typedef unsigned long long LL;

LL N;
vector<LL> D;

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	string S;
	cin >> S;
	LL n=0, w=0, s=0, e=0;
	for(int i=0; i<S.size(); i++){
		if(S[i] == 'N'){ n++; }
		if(S[i] == 'W'){ w++; }
		if(S[i] == 'S'){ s++; }
		if(S[i] == 'E'){ e++; }
	}
	if(n == 0 && s != 0){
		printf("No\n");
		return 0;
	}
	else if(n != 0 && s == 0){
		printf("No\n");
		return 0;
	}
	else if(w == 0 && e != 0){
		printf("No\n");
		return 0;
	}
	else if(w != 0 && e == 0){
		printf("No\n");
		return 0;
	}
	printf("Yes\n");
	return 0;
}

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

	int D;
    cin >> D;
    if (D==25){
    	cout << "Christmas";
    }

      if (D==24){
      	cout << "Christmas Eve";
      }

      if (D==23){
      	cout << "Christmas Eve Eve";
      } 
     if (D==22){
     	cout << "Christmas Eve Eve Eve";
     }

  cout << endl;
}

Measured memory_bytes: 256
# coding: utf-8
import sys


# 標準入力
data = tuple(map(int, sys.stdin.readline().strip().split(' ')))
aPizza = data[0]
bPizza = data[1]
cPizza = data[2]
x = data[3]
y = data[4]

cost = 0

# x y の枚数が
if (x != 0 and y != 0):
    sheets = (x if x < y else  y)
    if (aPizza + bPizza > cPizza * 2):
        cost = cost + cPizza * 2 * sheets
    else:
        cost = cost + (aPizza + bPizza) * sheets
    x = x - sheets
    y = y - sheets


if (x != 0):
    if (aPizza > cPizza * 2):
        cost = cost + cPizza * 2 * x
    else:
        cost = cost + aPizza * x

if (y != 0):
    if (bPizza > cPizza * 2):
        cost = cost + cPizza * 2 * y
    else:
        cost = cost + bPizza * y



# 標準出力
print(cost)



Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
using namespace std;
int main(){
	while(1){
		char c;
		scanf("%c",&c);
		if(c=='\n') { cout << endl; return 0;}
		char d = c;
		if(islower(c)) d = toupper(c);
		else if(isupper(c)) d = tolower(c);
		cout << d;
	}
}

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

int main() {
  int n;
  cin>>n;
  int a[n+1];
  for (int i=1; i<=n; i++) cin>>a[i];

  set<int> p;
  for (int i=1; i<=n; i++) {
    if (i == a[a[i]]) {
      p.insert(i);
      p.insert(a[i]);
    }
  }
  cout<<p.size() / 2<<endl;
}

Measured memory_bytes: 5376
import java.util.*;

public class Main {
	public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
		int[][] a = new int[2][n];

		for (int i = 0; i < 2; i++) {
			for (int j = 0; j < n; j++) {
				a[i][j] = sc.nextInt();
			}
		}

    int max = 0;

    for (int i = 0; i < n; i++) {
			int sum = 0;
			for (int j = 0; j <= i; j++) {
				sum += a[0][j];
			}
			for (int j = i; j < n; j++) {
				sum += a[1][j];
			}
			max = Math.max(sum, max);
    }

    System.out.println(max);
  }
}


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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    long long D, T, S;
    cin >> D >> T >> S;
    if (D <= T * S) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;
using ll = long long;

#define int ll
#define INF 1e18
signed main(){
    int N; cin >> N;
    if(N == 1)return puts("1")*0;
    vector<string>v(N);
    for(auto && e: v) cin >> e;
    vector<vector<int>>d(N,vector<int>(2,INF));
    map<char,int>map;
    vector<vector<pii>>edge(N);
    for(int i = 0; i < v.size();i++){
        char pre = v[i].front();
        if(map[pre] != 0){
            int index = map[pre] - 1;
            edge[index].push_back(pair<int,int>(i,0));
        }
        if(i != v.size() -1){
            edge[i].push_back(pair<int, int>(i+1,1));
            map[pre] = i+1;
        }
    }
    priority_queue<vector<int>,vector<vector<int>>,greater<vector<int>>>que;
    que.push({0,0,0});
    while(!que.empty()){
        auto top = que.top();
        que.pop();
        int dist = top.front() ;int idx = top[1]; int isSame = top[2];
        if(dist > d[idx][isSame]) continue;
        for(auto e : edge[idx]){
            int next = e.first;
            int ncost= e.second;
            if(v[idx].front() == v[next].front()){
                if(d[next][1] > dist){
                    d[next][1] = dist;
                    que.push({d[next][1],next,1});
                }
            } else {
                if(d[next][0] > dist + ncost){
                    d[next][0] = dist + ncost;
                    que.push({d[next][0],next,0});
                }
            }
        }
    }
    cout << min(d[N-1][0],d[N-1][1]) + 1 << endl;
    
}





Measured memory_bytes: 20488
s = list(input())

A_lst = []
for i in range(0, len(s)):
    if s[i] == "A":
        A_lst.append(i)

Z_lst = []
for i in range(0, len(s)):
    if s[i] == "Z":
        Z_lst.append(i)
        
A = min(A_lst)
Z = max(Z_lst)



ans = 0

for i in range(A, Z + 1):
    ans += 1
    
print(ans)

Measured memory_bytes: 12804
import numpy as np

N = int(input())
A = list(map(int, input().split())) 

FLAG = True
if(min(A) == 0):
    prod = 0
else:
    prod = 1
    for a in A:
        prod *= a
        if(prod > 1000000000000000000):
            print(-1)
            FLAG = not FLAG
            break

if FLAG:
    print(prod)

Measured memory_bytes: 40184
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

def cmb(n, r):
	if n - r < r: r = n - r
	if r == 0: return 1
	if r == 1: return n

	numerator = [n - r + k + 1 for k in range(r)]
	denominator = [k + 1 for k in range(r)]

	for p in range(2,r+1):
		pivot = denominator[p - 1]
		if pivot > 1:
			offset = (n - r) % p
			for k in range(p-1,r,p):
				numerator[k - offset] /= pivot
				denominator[k] /= pivot

	result = 1
	for k in range(r):
		if numerator[k] > 1:
			result *= int(numerator[k])

	return result

n,m = map(int,input().split())
MOD = 10**9+7

l = factorization(m)

ans = 1

if m == 1:
	print(ans)
else:
	for _,c in l:
		ans = ans * cmb(c+n-1,c) % MOD

	print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <algorithm>
#include <math.h>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define INF 999999999
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using llong = long long;
using namespace std;

int main(){
    llong n,d;
    cin >> n >> d;
    if(n%(d*2+1) == 0) cout << n/(d*2+1) << endl;
    else cout << n/(d*2+1)+1 << endl;
}

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

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

using namespace std;

struct Edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    Edge(int t, int w) : to(t), weight(w) { }
};

//using Graph = vector<vector<Edge>>
using Graph = vector<vector<int>>;

// header area

int main() {
    int N, K;

    cin >> N >> K;
    int d;
    vector<int> A(N, 0);
    for (int i = 0; i < K; i++) {
        cin >> d;
        for (int j = 0; j < d; j++) {
            int a;
            cin >> a;
            A[a - 1]++;
        }
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (A[i] == 0)ans++;
    }

    cout << ans;
}

Measured memory_bytes: 3624
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define FIO ios_base::sync_with_stdio(false); cin.tie(0);
#define trav(x,a) for (auto& x: a)
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define mem(a,v) memset((a), (v), sizeof (a))
#define endl "\n"
#define case(t) cout << "Case #" << (t) << ": "
#define reada(a, n) for (int _i = 0; _i < (n); _i++) read(a[_i])
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define st first
#define nd second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int mod = 1e9 + 7;
const int inf = 1e9 + 7;
const int N = 1e6 + 5;
const double eps = 1e-9;

template<class T> void read(T& x) { cin >> x; }
template<class X, class Y> void read(pair<X,Y>& a) { read(a.first), read(a.second); }
template<class T> void read(vector<T>& x) { trav(y, x) read(y); }
template<class T, class... O> void read(T& x, O&... y) { read(x), read(y...); }

string to_string(const char& x) { return string(1,x); }
string to_string(const char*& x) { return (string)x; }
string to_string(const string& x) { return x; }
template<class T, class U> string to_string(const pair<T,U>& x) { return to_string(x.first) + " " + to_string(x.second); }
template<class T> string to_string(const vector<T>& x) { string ret = ""; bool f = 0; trav(y, x) ret += (!f ? "" : " ") + to_string(y), f = 1; return ret; }
void print() { cout << endl; }
template<class T> void pr(const T& x) { cout << to_string(x); }
template<class T, class... O> void print(const T& x, const O&... y) { pr(x); if (sizeof...(y)) pr(" "); print(y...); }

int main() {
  FIO
  int n; read(n);
  ll ans = 0;
  for (int a = 1; a < n; a++) {
    int md = n % a;
    if (md == 0) {
      ans += n / a - 1;
    } else {
      ans += n / a;
    }
  }
  print(ans);
  return 0;
}


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

import sys
import math
import itertools

debug = False

def log(text):
    if debug:
        print(text)


def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        lines.append(input())
        (n, m, x) = [int(e) for e in lines[0].split(' ')]
        for _ in range(n):
            lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]
        (n, m, x) = [int(e) for e in lines[0].split(' ')]

    ca_list = []
    for i in range(1, n+1):
        ca_list.append([int(e) for e in lines[i].split(' ')])
        
    return (n, m, x, ca_list)


def solve(n, m, x, ca_list):


    result = 100000 * n + 1
    for p in itertools.product([0,1], repeat=n):

        index_set = set([i for i, b in enumerate(p) if b == 1])
        ca_list_tmp = [e for i, e in enumerate(ca_list) if i in index_set]

        if debug:
            log("index_set=%s" % index_set)
            log("ca_list_tmp=%s" % ca_list_tmp)
        
        total_c = 0
        total_a = [0 for _ in range(m)]
        r = True 
        for ca in ca_list_tmp:
            total_c = total_c + ca[0]

            for i in range(1, m + 1):
                total_a[i-1] = total_a[i-1] + ca[i]

        for i in range(m):
            if total_a[i] < x:
                r = False
                break
            
        if r:
            if total_c < result:
                result = total_c

    if result == 100000 * n + 1:
        result = -1

    return  result


def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':

    main()

Measured memory_bytes: 74988
#include<iostream>
using namespace std;
bool a[200010],b[200010];
int main()
{
	int n,m;
	cin>>n>>m;
	int x,y;
	for(int i=0;i<n+1;i++)
	{
		a[i]=false;
		b[i]=false;
	}
	for(int i=0;i<m;i++)
	{
		cin>>x>>y;
		if(x==1)
		b[y]=true;
		if(x==n)
		a[y]==true;
		if(y==1)
		b[x]==true;
		if(y==n)
		a[x]=true;
	}
	for(int i=1;i<=n;i++)
	if(a[i]&&b[i])
	{
		cout<<"POSSIBLE"<<endl;
		return 0;
	}
	cout<<"IMPOSSIBLE"<<endl;
	return 0;
}

Measured memory_bytes: 768
n,k=[int(i) for i in input().split()]
h=[int(input()) for i in range(n)]
h.sort()
ans=10**9
for i in range(n-k+1):
  if h[i+k-1]-h[i]<=ans:
    ans=h[i+k-1]-h[i]
print(ans)

Measured memory_bytes: 7436