akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll H,N;
ll a[10010],b[10010];
ll dp[1010][20010];
int main(){
    cin>>H>>N;
    ll maxA=0;
    for(ll i=0;i<N;i++){
        cin>>a[i]>>b[i];
        maxA=max(maxA,a[i]);
    }
    for(ll i=0;i<N;i++){
        for(ll j=0;j<=H+maxA;j++){
            dp[i][j]=INF;
        }
        dp[i][0]=0;
    }
    
    for(ll i=0;i<N;i++){
        for(ll j=0;j<=H+maxA;j++){
            if(j<a[i]){
                dp[i+1][j]=dp[i][j];
            }else{
                dp[i+1][j]=min(dp[i][j],dp[i+1][j-a[i]]+b[i]);
            }
        }
    }
    ll ans=INF;
    for(ll i=0;i<=N;i++){
        for(ll j=H;j<=H+maxA;j++){
            ans=min(ans,dp[i][j]);
        }
    }
    cout<<ans<<endl;
    return 0;
}

        // for(ll j=0;j<=H+maxA;j++){
        //     if(dp[i][j]==INF){
        //         cout<<"INF ";
        //     }else{
        //         cout<<dp[i][j]<<" ";
        //     }
        // }cout<<endl;

Measured memory_bytes: 157056
from math import ceil

S = int(input())

tmp = ceil(pow(S,1/2))
near = pow(tmp,2)
delta = near - S
X1,Y1 = 0,0
X2,Y2 = 1,tmp
X3,Y3 = tmp,delta

print(X1,Y1,X2,Y2,X3,Y3)

def judge():
    return X3*Y2 - X2*Y3 == S

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
const int MOD = 1000000007;

bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  ll N,K,res=0,tmp=0;
  cin >> N >> K;
  if(K == 0){
    cout << N*N << endl;
    return 0;
  }
  for(int i=1;i<=N;i++){
    if(i-K >= 0)
      res += (i-K)*(N/i);
    if(N%i != 0 && (N%i-K+1 >= 0))
      res += N%i-K+1;
  }
  cout << res << endl;
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}

ll bpow(ll a, ll n,ll mod){
  int i = 0;
  ll res=1;
  while(n){
    if(n & 1)
      res = (res*a) % mod;
    a = (a*a) % mod;
    n >>= 1;
  }
  return res;
}
mat mul(mat &A, mat &B){
  mat C(A.size(),vec(B[0].size()));
    REP(i,A.size())REP(k,B.size())REP(j,B[0].size()){
    C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
  }
  return C;
}

mat pow(mat A,ll n)
{
  mat B(A.size(),vec(A.size()));
  REP(i,A.size()){
    B[i][i] = 1;
  }
  while(n > 0){
    if ( n & 1) B = mul(B,A);
    A = mul(A,A);
    n >>= 1;
  }
  return B;
}


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

int main(){
    long long a, b, x;
    cin >> a >> b >> x;
    if(a == 0){
        cout << b/x - a/x + 1;
    }else{
        cout << b/x - (a-1)/x;
    }
    return 0;
}

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

long long a[3];

int main() {
	cin >> a[0] >> a[1] >> a[2];
	if (a[0] % 2 == 0 || a[1] % 2 == 0 || a[2] % 2 == 0)
		cout << "0" << endl;
	else {
		sort(a, a + 3);
		cout << a[0] * a[1] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int main(){
    
    
    int a,b,c,d,p,e,n,f,x,y=0,z=0,m,i;
    
    cin>>n>>m;
    for(i=1;i<=m;i++){
        cin>>a>>b;
        if(a<n){
            x=n-a;
            z=z+x;
        }
        
        if(y<(n-a)){
            y=n-a;
            
        }
    }
    cout<<z-y<<endl;
    
    
    return 0;
}


Measured memory_bytes: 3072
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *


S = input()
K = INT()

cnt = 0
tmp = False
for i in range(1, len(S)):
	if tmp:
		tmp = False
	elif S[i] == S[i-1]:
		cnt += 1
		tmp = True

if tmp or S[0] != S[-1]:
	print(cnt*K)
	exit()

cnt2 = 1
tmp = True
for i in range(1, len(S)):
	if tmp:
		tmp = False
	elif S[i] == S[i-1]:
		cnt2 += 1
		tmp = True

if tmp:
	print((cnt+cnt2)*(K//2) + cnt*(K%2))
else:
	print(cnt+cnt2*(K-1))




Measured memory_bytes: 5200
#include "bits/stdc++.h"
#define rep(i, j) for (int i = 0; i < j; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using ull = unsigned long long;

ll gcd(ll x, ll y);
int fac(ll n, vector<int> num);

const int INF = 1001001001;

//mint�p�̒萔 (10��9��)
const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }

int main() {
    int x, t;
    cin >> x >> t;
    int ans = x - t;

    
    if (ans < 0)
        cout << 0 << endl;
    else
        cout << ans << endl;
    return 0;
}

/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
ll gcd(ll x, ll y) {
    ll num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

/*�f��������*/
//���색�C�u����
int fac(ll n, vector<int> num) {
    ll kazu = n;
    for (int i = 2; i <= sqrt(n); i++) {
        while (1) {
            if (kazu % i != 0) break;

            kazu /= i;
            num[i]++;
        }
    }
    if (kazu == n && n != 1) return 1;
    int ans = 0;
    if (kazu != 1) ans++;
    for (int i = 2; i <= sqrt(n); i++) {
        for (int j = 1; j <= num[i]; j++) {
            num[i] -= j;
            ans++;
        }
    }
    return ans;
}

Measured memory_bytes: 3520
#define errOut(s) { std::cerr << "LINE:" << __LINE__ << " " << #s << " = " << s << std::endl; }

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

#ifndef errOut
#define errOut(s)
#endif

using Value = int64_t;

Value calc(Value x, Value y) {
    Value ret = 0;
    for (Value i = x; i <= y; i *= 2) {
        ++ret;
    }
    return ret;
}

int main() {
    Value x, y;
    std::cin >> x >> y;
    auto ret = calc(x, y);
    std::cout << ret << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n=20;
const int inf=0x3f3f3f3f;
int n,a[max_n],b[max_n];
int c[max_n];
int flip[max_n];
int p[max_n];
bool cmp(int x,int y){
    return c[x]==c[y]?x<y:c[x]<c[y];
}
typedef pair<int,int> P;
int solve(int state){
    /*
    for(int i=0;i<n;i++)cout<<c[i]<<' ';
    cout<<endl;
    */
    for(int i=0;i<n;i++)flip[i]=0;
    int res=0;
    for(int i=0;i<n;i++)p[i]=i;
    /*
    for(int i=0;i<n;i++){
        for(int j=1;j<n;j++){
            if(c[p[j]]<c[p[j-1]]){
                res++;
                flip[p[j]]^=1,flip[p[j-1]]^=1;
                swap(p[j],p[j-1]);
            }
        }
    }
    */
    for(int i=0;i<n;i++){
        for(int j=0;j<i;j++){
            if(c[i]<c[j]){
                res++;
                flip[i]^=1,flip[j]^=1;
            }
        }
    }
    sort(p,p+n,cmp);
    for(int i=0;i<n;i++){
        int j=i;
        while(j<n&&c[p[j]]==c[p[i]])j++;
        int cc=0;
        stack<int> s;
        for(int l=i;l<j;l++){
            if(flip[p[l]]==(state>>p[l]&1))continue;
            int r=l;
            while(r<j&&flip[p[r]]!=(state>>p[r]&1))r++;
            if((r-l)%2==0)res+=(r-l)/2;
            else{
                res+=(r-l)/2;
                if(!s.empty()&&(l-s.top()+1)%2==0){
                    res+=l-s.top();
                    s.pop();
                }
                else s.push(r-1);
            }
            l=r-1;
        }
        if(!s.empty())return inf;
        i=j-1;
    }
    return res;
}
int tc[max_n];
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%d",a+i);
    for(int i=0;i<n;i++)scanf("%d",b+i);
    int ans=inf;
    int state=0;
    for(int i=0;i<(1<<n);i++){
        for(int j=0;j<n;j++){
            if(i>>j&1)c[j]=b[j];
            else c[j]=a[j];
        }
        
        ans=min(ans,solve(i));
        /*
        if(solve(i)<ans){
            cout<<"fuck"<<endl;
            ans=solve(i);
            state=i;
            for(int i=0;i<n;i++)tc[i]=c[i];
        }
        */
        
    }
    
    if(ans!=inf)printf("%d\n",ans);
    else printf("-1\n");
    
    //cout<<0<<endl;
    /*
    cout<<state<<endl;
    for(int i=0;i<n;i++)cout<<tc[i]<<' ';
    cout<<endl;
    */
    return 0;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/03/04  Problem: ABC 100 D / Link: http://abc100.contest.atcoder.jp/tasks/abc100_d  ----- */

LL dp[1003][1003][2][2][2];

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	fill(****dp, ****dp + 1003 * 1003 * 2 * 2 * 2, -LINF);
	LL N, M; cin >> N >> M;
	VL x(N), y(N), z(N);
	FOR(i, 0, N) {
		cin >> x[i] >> y[i] >> z[i];
	}
	auto chmax = [](LL &a, LL b) {
		a = max(a, b);
	};

	FOR(a, 0, 2)FOR(b, 0, 2)FOR(c, 0, 2) {
		dp[0][0][a][b][c] = 0;
	}
	FOR(i, 0, N) {
		FOR(j, 0, i + 1) {
			FOR(a, 0, 2) {
				FOR(b, 0, 2) {
					FOR(c, 0, 2) {
						LL addval = (a ? x[i] : -x[i]) + (b ? y[i] : -y[i]) + (c ? z[i] : -z[i]);
						chmax(dp[i + 1][j][a][b][c], dp[i][j][a][b][c]);
						chmax(dp[i + 1][j + 1][a][b][c], dp[i][j][a][b][c] + addval);
					}
				}
			}
		}
	}



	LL ans = 0;
	FOR(a, 0, 2)FOR(b, 0, 2)FOR(c, 0, 2) {
		ans = max(ans, dp[N][M][a][b][c]);
	}
	cout << (ans) << "\n";

	return 0;
}


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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll H, W, A, B;
    cin >> H >> W >> A >> B;
    
    REP(i,0,H) {
        REP(j,0,W) {
            if((i < B && j < A) || (i >= B && j >= A)) cout << 1;
            else cout << 0;
        }
        cout << endl;
    }

    return 0;
}

/*



*/

Measured memory_bytes: 3580
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    ll x;
    cin >> x;
    if (x == 0)
    {
        cout << 1 << endl;
    }
    else
    {
        cout << 0 << endl;
    }
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>
#include <cstdint>



#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rrep(i, n) for(ll i = (ll)(n-1); i >= 0; i--)
#define repi(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rrepi(i,a,b) for(ll i=(ll)(b-1);i>=(ll)(a);i--)

#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin>>n;
  cout<<0<<endl;
  string s;
  cin>>s;
  ll l=0,r=0;
  if(s=="Female")l=1;
  if(s=="Vacant"){
    return 0;
  }

  cout<<n-1<<endl;
  cin>>s;
  if(s=="Female")r=1;
  if(s=="Vacant")return 0;
  ll li=0,ri=n-1;
  while(ri-li>1){
    ll mid=(li+ri)/2;
    cout<<mid<<endl;;
    cin>>s;
    ll f=0;
    if(s=="Vacant")return 0;
    if(s=="Female")f=1;
    if(mid%2)f^=1;
    if(f==l)li=mid;
    else ri=mid;
  }

  return 0;

}


Measured memory_bytes: 852
import java.util.*;
class Main {
    public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int W = sc.nextInt();
		int[] v = new int[N];
		int[] w = new int[N];
        for (int i = 0; i < N; i++) {
            v[i] = sc.nextInt();
            w[i] = sc.nextInt();
        }
		int[] dp = new int[W+1];
		for (int i = 0; i < N; i++) {
			for (int j = W-w[i]; j >= 0; j--) {
				dp[j+w[i]] = Math.max(dp[j+w[i]], dp[j] + v[i]);
			}
		}
		System.out.println(dp[W]);
	}
}


Measured memory_bytes: 27140
n,x = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
counter = 0
i = 0
while x > 0 and i < n:
    if i != n-1:
        if x >= a[i]:
            counter += 1
            x = x-a[i]
    else:
        if x == a[i]:
            counter += 1
            x = x-a[i]
    i += 1
print(counter)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#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 ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  ll d,a;
  cin >> n >> d >> a;
  vector<pair<ll, ll>> xh(n);
  REP(i,n){
    cin >> xh[i].first >> xh[i].second;
    xh[i].second = (xh[i].second + a - 1) / a;
  }
  sort(ALL(xh));
  ll ans = 0;
  ll bomb = 0;
  queue<pair<ll, ll>> que;
  REP(i,n){
    while(!que.empty() && que.front().first < xh[i].first){
      bomb -= que.front().second;
      que.pop();
    }
    xh[i].second -= bomb;
    if(xh[i].second<=0) continue;
    ans += xh[i].second;
    bomb += xh[i].second;
    que.push(make_pair(xh[i].first+d*2, xh[i].second));
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#include <stdio.h>
typedef long long int LL;
#define fr(i,p,n) for(LL i=p;i<n;i++)
#define fr1(i,p,n) for(LL i=p;i>=n;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define PI 3.14159265358979323846
#define MOD 1000000007
#define MOD1 998244353
#define INF 1e18
#define precise cout << std::setprecision(10) << std::fixed;

using namespace std;
 
int main()
{
        LL n,k;
        cin>>n>>k;
        LL a[n];
        LL dp[n+1];
        fr(i,0,n){
            cin>>a[i];
            dp[i]=INT_MAX;
        }
        dp[0]=0;
        dp[1]=abs(a[1]-a[0]);
        fr(i,2,n)
        {  
            if(i<k){
              fr(j,0,i){
                 dp[i]=min(dp[j]+abs(a[i]-a[j]) , dp[i]);
              }
            } 
            if(i>=k){
              fr(j,i-k,i){
                 dp[i]=min(dp[j]+abs(a[i]-a[j]) , dp[i]);
              }  
            }
        }
        cout<<dp[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 5100
#include<stdio.h>

int main(void){
	int a[10];
	int i, j, swap;

	scanf("%d %d %d %d %d", &a[0], &a[1], &a[2], &a[3], &a[4]);

	for(i = 0; i < 5; i++){
		for(j = 0; j < 4 -i; j++){
			if(a[j]<a[j+1]){
				swap = a[j];
				a[j] = a[j+1];
				a[j+1] = swap;
			}
		}
	}

	printf("%d %d %d %d %d\n", a[0], a[1], a[2], a[3], a[4]);

	return 0;
}

Measured memory_bytes: 596
import Data.Bits
import Data.List
import Data.Foldable(foldlM)
import Data.Maybe(fromJust)
import Control.Monad
import Data.Array as A ((!),accumArray)
import Data.Graph
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as VM
import Control.Monad.ST
import Data.Maybe (fromMaybe)
import qualified Data.ByteString.Char8 as BS
import Debug.Trace

toTuple :: [a] -> (a,a)
toTuple (x:y:_) = (x,y)
toTuple _ = undefined

getInt :: IO Int
getInt = fst . fromJust. BS.readInt <$> BS.getLine

getIntList :: IO [Int]
getIntList = unfoldr (BS.readInt . BS.dropWhile (== ' ')) <$> BS.getLine

getLineB :: (Read a) => IO [a] --直接入力
getLineB = map (read.BS.unpack) . BS.words <$> BS.getLine

mod' :: Int -> Int
mod' n = n `mod` 1000000007

f :: [Int] -> Int -> [Int]
f [] _ = [0]
f [_] s = [s]
f (x:y:xs) s = if x <= y then s : (f (y:xs) (s+1)) else s : (f (y:xs) 0)

main :: IO ()
main = do
  _ <- getLine
  hs <- getIntList
  print $ maximum $ f (reverse hs) 0


Measured memory_bytes: 10620
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
 
 ll mod = 1e9 + 7;

 int nmod(int n, int k){
     ll a = 1;
    for (int i = 0; i < n; i++)
    {
        a = (a*k)%mod; 
    }
     return a;
 }


int main() {
    ll n;
    cin >> n;
    ll ans;
    // ans = nmod(n,10);
    ans = (nmod(n,10)-nmod(n,9)*2+nmod(n,8)+2*mod)%mod;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3640
#include<stdio.h>
int main()
{
    int i,a,b,k=0;
    scanf("%d %d",&a,&b);
    for(i=a;i<=b;i++)
    {
        if(i%10==i/10000&&i/10%10==i/1000%10)
            k++;
    }
    printf("%d\n",k);
    return 0;
}


Measured memory_bytes: 128
n = int(input())
a = [int(i) for i in input().split()]
d = {}
for i in range(n):
    if a[i] in d:
        d[a[i]] += 1
    else:
        d[a[i]] = 1

cnt = 0
ans = 0
for k, v in sorted(d.items(), key=lambda x: x[0], reverse=True):
    if v >= 4 and cnt == 0:
        ans = k ** 2
        break
    elif v >= 2:
        if cnt == 0:
            ans = k
            cnt += 1
        else:
            ans *= k
            break
print(ans)


Measured memory_bytes: 22052
package main

import "fmt"

func min(a ...int) int {
	m := a[0]
	for i, v := range a {
		if i == 0 {
			continue
		}
		if m > v {
			m = v
		}
	}
	return m
}

func main() {
	// Code for A - Ice Tea Store
	var Q, H, S, D int
	fmt.Scanf("%d %d %d %d", &Q, &H, &S, &D)

	var N int
	fmt.Scanf("%d", &N)

	ans := (N/2)*min(8*Q, 4*H, 2*S, D) + (N%2)*min(4*Q, 2*H, S)
	fmt.Println(ans)
}


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

int main() {
  int N, X; cin >> N >> X;
  vector<int> L(N);
  rep(i, N){cin >> L.at(i);}

  vector<int> D;

  D.push_back(0);

  for (int i = 1; i < N+1; i++)
  {
    int Y = D.at(i - 1) + L.at(i - 1);
    if (Y > X)
    {
      break;
    }
    
    D.push_back(Y);
  }
  
  cout << D.size() << endl;
}

Measured memory_bytes: 256
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
typedef complex<D> P;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){ll i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}
template<typename T>vector<T> & cset(vector<T> &A,T e=T()){for(auto &I:A){I=e;} return A;}



int main(){
    ll n;
    cin>>n;
    vector<ll> A(n);
    cin>>A;
    ll mx=0;
    vector<ll> dp(n,-E);
    for(ll i=n-2;i>=0;i--){
        mx=max(mx,A[i+1]);
        dp[i]=mx;
    }
    mx=0;
    for(ll i=0;i<n;i++){
        cout<<max(mx,dp[i])<<endl;
        mx=max(mx,A[i]);
    }
    
    
    return 0;
}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int v[n];
  for(int i = 0; i < n; i++) cin >> v[i];
  int res = 0;
  for(int i = 0; i < n; i++){
    int c;
    cin >> c;
    res += max(v[i]-c, 0);
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
import math
A,B =map(int,input().split())



def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

tmp_A = set(make_divisors(A))
tmp_B = set(make_divisors(B))

tmp_set = tmp_A & tmp_B


def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True

print(sum([is_prime(one) for one in tmp_set])+1)

Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
#define deb(x) cout << #x << ':' << x << endl;
#define loop3(i, k, n) for(i=k; i<n; i++)
#define ll  long long 
#define loop(i,n) for(int i=0;i<n;i++)
#define loop2(i,n) for(int i = 1;i<=n;i+=1)
#define pb push_back
#define mp make_pair
#define v1d vector<ll> 
#define v2d vector<vector<ll>>
const int INF = 1e9 +5 ;
void max_self(ll &a,ll b)
{
    a = max(a,b);
}
int main()
{
    ll int N, W;
    cin>>N>>W;
    int i;
    v1d dp(W+1);
    loop(i,N)
    {
        ll w,v;
        cin>>w>>v;
        for(int j = W - w; j>= 0; j--)
        {
            max_self(dp[j+w],dp[j]+v);
        }
    }
    ll ans = 0;
    loop(i,W+1)
        max_self(ans,dp[i]);
    
    cout<<ans;

}

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

using namespace std;

int main() {
  int n, q;
  string s;
  cin >> n >> q >> s;

  vector<int> sum(n+100, 0);
  for (int i = 0; i <= n; i++) {
    if (s.substr(i, 2) == "AC") {
      sum[i+1] = sum[i] + 1;
    } else {
      sum[i+1] = sum[i];
    }
  }
  while (q--) {
    int l, r; cin >> l >> r;
    l--; r--;
    cout << sum[r] - sum[l] << endl;
  }
  return 0;
}

Measured memory_bytes: 1408
n, k = map(int, input().split())
s = input()
ss = []

cnt = 0

if s[0] == '0': ss.append(0)
i = 0
while i < n:
    j = i
    while j < n and s[i] == s[j]: j += 1
    ss.append(j-i)
    i = j
if s[-1] == '0': ss.append(0)

right = 2*k+1
left = 0
val = sum(ss[:right])
ans = val

#print(ss)
while right < len(ss):
    for i in [1, 2]:
        #print('for', ss[left], ss[right])
        val += ss[right]
        val -= ss[left]
        left += 1
        right += 1
    #print(left, right, val)
    ans = max(ans, val)
    
print(ans)

Measured memory_bytes: 4468
#include <bits/stdc++.h>
using namespace std;
string str = "CODEFESTIVAL2016", s;
int main() {
	cin >> s;
	int cnt = 0;
	for (int i = 0; i < str.length(); ++i) {
	    cnt += (str[i] != s[i]);
	}
	cout << cnt << endl;
	return 0;
} 

Measured memory_bytes: 256
from collections import deque

if __name__ == '__main__':
    n, q = input().split()
    n, q = int(n), int(q)
    S = [deque([]) for i in range(n)]

    for i in range(q):
        query = input().split()

        if query[0] == '0':
            S[int(query[1])].append(query[2])

        else:
            if len(S[int(query[1])]) == 0:
                pass
            elif query[0] == '1':
                print(S[int(query[1])][0])
            else:
                S[int(query[1])].popleft()


Measured memory_bytes: 20716
public class Main {


  private static void solve() {
    int n = ni();
    long[] a = nal(n);
    
    long[] left = new long[n];
    long[] right = new long[n];
    
    left[0] = a[0];
    right[n - 1] = a[n - 1];
    for (int i = 1; i < n; i ++) {
      left[i] = gcd(left[i - 1], a[i]);
    }
    for (int i = n - 2; i >= 0; i --) {
      right[i] = gcd(right[i + 1], a[i]);
    }
    
    long max = Math.max(left[n - 2], right[1]);
    for (int i = 2; i < n; i ++) {
      max = Math.max(max, gcd(left[i - 2], right[i]));
    }
    System.out.println(max);
  }
  
  
  public static long gcd(long a, long b) {
    while (b > 0){
        long c = a;
        a = b;
        b = c % b;
    }
    return a;
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

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

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


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

int main(){
    int n, q;
    cin>>n>>q;
    string s;
    cin>>s;
    vector<int> l(q);
    vector<int> r(q);
    rep(i,q){
        cin>>l[i]>>r[i];
    }
    vector<int> left(n);
    left[0]=0;
    rep2(1,i,n){
        left[i]=left[i-1];
        if(s[i-1]=='A' && s[i]=='C'){
            left[i]+=1;
        }
    }
    vector<int> right(n);
    right[n-1]=0;
    for(int i=n-2;0<=i;i--){
        right[i]=right[i+1];
        if(s[i]=='A' && s[i+1]=='C'){
            right[i]+=1;
        }
    }
  /*
    for(auto x:left)cout<<x<<" ";
    cout<<endl;
    for(auto x:right)cout<<x<<" ";
    cout<<endl;
*/
    rep(i,q){
        int ans=(l[i]==1)?left[r[i]-1]:left[r[i]-1]-left[l[i]-1];
        cout<<ans<<endl;
    }

    return 0;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;
using Int = long long;

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;

//少数点表示
//cout <<std::fixed << std::setprecision(14)

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    char b;
    cin >> b;
    switch(b){
        case 'A':
            cout << 'T';
            break;
        case 'T':
            cout << 'A';
            break;
        case 'C':
            cout << 'G';
            break;
        case 'G':
            cout << 'C';
            break;
    }



}

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

int main() {
  string n;
  cin >> n;
  int ans=0;
  rep(i,n.size()) {
    ans+=(int)(n[i]-'0');
  }
  if (ans%9==0) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3748
N=int(input())
i=1
L=[N]
M=N
while i< 1000000:
  i+=1
  if M%2==0:
    M=M/2
    L.append(int(M))
  else:
    M=3*M+1
    L.append(int(M))
  if L.count(M) ==2:
    print(i)
    break

Measured memory_bytes: 3060
#include "bits/stdc++.h"
#define MOD 1000000007
#define inf 0x3f3f3f3f3f3f3f3f
#define pi acos(-1.0)
#define ri register int
#define Abs(x) ((x) < 0 ? (-(x)) : (x))
#define int long long
const int maxn = 1e4 + 10;
inline int Max(int a, int b) { return a > b ? a : b; }
inline int Min(int a, int b) { return a > b ? b : a; }
namespace FastIO {
inline int read()
{
    int f = 1, r = 0;
    char c = getchar();
    while (!isdigit(c)) {
        if (c == '-') {
            f = -1;
        }
        c = getchar();
    }
    while (isdigit(c)) {
        r = 10 * r + c - '0';
        c = getchar();
    }
    return f * r;
}
inline void write(int x)
{
    if (x < 0)
        putchar('-'), x = -x;
    if (x > 9)
        write(x / 10);
    putchar(x % 10 + '0');
}
inline void writesp(int x) { write(x), putchar(' '); }
inline void writeln(int x) { write(x), puts(""); }
};
using namespace FastIO;
int N, K, tot, ver[maxn << 1], next[maxn << 1], head[maxn], dis[maxn], disa[maxn], disb[maxn];
inline void add(int u, int v)
{
    ver[++tot] = v, next[tot] = head[u], head[u] = tot;
}
void dfs(int u, int fa)
{
    dis[u] = dis[fa] + 1;
    for (ri i = head[u]; i; i = next[i]) {
        if (ver[i] == fa)
            continue;
        dfs(ver[i], u);
    }
}

inline int work1()
{
    int ans = inf;
    for (ri i = 1; i <= N; ++i) {
        dfs(i, 0);
        int num = 0;
        for (ri j = 1; j <= N; ++j) {
            int tmp = dis[j] - dis[i];
            if (tmp > K / 2) {
                ++num;
            }
        }
        ans = Min(ans, num);
    }
    return ans;
}
inline int work2()
{
    int ans = inf;
    for (ri i = 1; i <= N; ++i) {
        for (ri j = head[i]; j; j = next[j]) {
            int v = ver[j], u = i, num = 0;
            dfs(u, 0);
            memcpy(disa, dis, sizeof(dis));
            dfs(v, 0);
            memcpy(disb, dis, sizeof(dis));
            for (ri k = 1; k <= N; ++k) {
                int d1 = disa[k] - 1, d2 = disb[k] - 1;
                int mn = Min(d1, d2);
                if (mn > (K - 1) / 2) {
                    ++num;
                }
            }
            ans = Min(ans, num);
        }
    }
    return ans;
}
signed main()
{
    //freopen("C:\Users\hjw\Downloads\testdata (4).in", "r", stdin);
    N = read(), K = read();
    for (ri i = 1; i < N; ++i) {
        int u = read(), v = read();
        add(u, v), add(v, u);
    }
    int q;
    if (K & 1) {
        q = work2();
    } else {
        q = work1();
    }
    writeln(q);
    //system("pause");
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = m; i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greator<>()
#define d20 std::setprecision(20)
#define veci vector<int>
#define vecll vector<long long int>
#define vecb vector<bool>
#define vecd vector<double>
template <typename T>
T lcm(T a, T b)
{
	return a / __gcd(a, b) * b;
}

int main()
{
	int n;
	cin >> n;
	map<int, int> _map;
	rep(i, n - 1)
	{
		int tmp;
		cin >> tmp;
		_map[tmp]++;
	}
	for (size_t i = 1; i <= n; i++)
	{
		cout << _map[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 13000
#include <stdio.h>
#include <algorithm>
using namespace std;
int n, k, g, ans;
int t = 2048 * 128;
int p[200000];
int q[200000];
int ma[2048 * 256];
int mi[2048 * 256];
int ml[2048 * 256];
int mr[2048 * 256];
void build(int x) {
	if (x >= t) {
		ml[x] = x - t;
		mr[x] = x - t + 1;
		return;
	}
	build(2 * x + 1);
	build(2 * x);
	ml[x] = ml[2 * x];
	mr[x] = mr[2 * x + 1];
	ma[x] = max(ma[2 * x], ma[2 * x + 1]);
	mi[x] = min(mi[2 * x], mi[2 * x + 1]);
}
int smax(int l, int r, int x) {
	if (l >= r)return 0;
	if (l == ml[x] && r == mr[x]) {
		return ma[x];
	}
	if (r <= mr[2 * x])return smax(l, r, 2 * x);
	if (ml[2 * x + 1] <= l)return smax(l, r, 2 * x + 1);
	return max(smax(l, mr[2 * x], 2 * x), smax(ml[2 * x + 1], r, 2 * x + 1));
}
int smin(int l, int r, int x) {
	if (l >= r)return n;
	if (l == ml[x] && r == mr[x]) {
		return mi[x];
	}
	if (r <= mr[2 * x])return smin(l, r, 2 * x);
	if (ml[2 * x + 1] <= l)return smin(l, r, 2 * x + 1);
	return min(smin(l, mr[2 * x], 2 * x), smin(ml[2 * x + 1], r, 2 * x + 1));
}
int main() {
	scanf("%d%d", &n, &k);
	for (int i = t; i < 2 * t; i++)mi[i] = n;
	for (int i = 0; i < n; i++) {
		scanf("%d", p + i);
	}
	for (int i = 0; i < n; i++) {
		ma[i + t] = p[i];
		mi[i + t] = p[i];
	}
	build(1);
	for (int i = 0; i < n - 1; i++) {
		if (p[i] < p[i + 1])q[i] = 1;
	}
	for (int i = 1; i < n - 1; i++) {
		q[i] += q[i - 1];
	}
	ans = 1;
	if (q[k - 2] == k - 1)g = 1;
	for (int i = k; i < n; i++) {
		if (q[i - 1] - q[i - k] == k - 1) {
			if (g == 0) {
				g = 1;
				ans++;
			}
		}
		else {
			ans++;
			if (smax(i - k + 1, i, 1) < p[i] && p[i - k] < smin(i - k + 1, i, 1))ans--;
		}
	}
	printf("%d\n", ans);
}

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

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

	bool ans = true;
	for (auto& i : a) {
		cin >> i;
		if (i % 2 == 0) {
			if (!((i % 3) == 0 || (i % 5) == 0))
				ans = false;
		}
	}

	cout << (ans ? "APPROVED" : "DENIED") << endl;
}

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

/**
 * vector<int>ar(3);
 * for(auto&e:ar){
 *     scanf("%d",&e);
 * }
 * sort(ar.begin(),ar.end())
 * int sum=accumulate(ar.begin(),ar.end(),0);
 ***/

int main(){
    double pai=3.141592653589;
    int n;
    scanf("%d",&n);
    for(int i=3;i<=n;i++){
        int x=i;
        if(i%3==0){
            printf(" %d",i);
        }else{
            do{
                if(x%10==3){
                    printf(" %d",i);
                    break;
                }
                x/=10;
            }
            while(x);
        }
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 1176
n = int(input())
ans = 1
an = list(map(int,input().split()))
for i in an:
    if i == 0:
        ans = 0
if ans != 0:
    for i in range(n):
        ans = ans * an[i]
        if ans > 10**18:
            ans = -1
            break
print(ans)

Measured memory_bytes: 21636
n = int(input())
nums = [int(c) for c in str(n)]
nums.reverse()
a = [0]*2019
a[0] = 1
now = 0
pow10 = [1]*len(nums)
for i, num in enumerate(nums):
    if i < len(nums)-1:
        pow10[i+1] = pow10[i]*10 % 2019
for i, num in enumerate(nums):
    now = (now+num*pow10[i]) % 2019
    a[now] += 1
sum = 0
for i in range(2019):
    sum += a[i]*(a[i]-1)//2
print(sum)

Measured memory_bytes: 17736
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>

using namespace std;

struct Info{
	Info(){
		cost = 0;
	}
	char name[101];
	int cost;
};

struct Recipe{
	Recipe(){
		index = num = 0;
		used = false;
	}

	void setNUM(int arg_num){
		component = new int[arg_num];
	}

	void push(int id){
		component[index++] = id;
	}

	int* component;
	int menu,index;
	int num;
	bool used;
};


bool strCmp(char* base, char* comp){
	int length1 = 0,length2 = 0;
	for(int i=0;base[i] != '\0'; i++)length1++;
	for(int i=0;comp[i] != '\0'; i++)length2++;
	if(length1 != length2)return false;

	for(int i=0;base[i] != '\0'; i++){
		if(base[i] != comp[i])return false;
	}
	return true;
}

void strcpy(char* to,char* str){
	for(int i=0;str[i] != '\0';i++){
		to[i] = str[i];
		to[i+1] = '\0';
	}
}

void func(int n){

	Info info[n];
	int checkTable[n];
	for(int i = 0; i < n; i++)checkTable[i] = 0; //0:fix 1:not

	for(int i = 0; i < n; i++){
		scanf("%s %d",info[i].name,&info[i].cost);
	}

	int m;
	scanf("%d",&m);
	char tmp[101];
	Recipe recipes[m];

	for(int i = 0; i < m; i++){
		scanf("%s %d",tmp,&recipes[i].num);
		for(int k = 0; k < n; k++){
			if(strCmp(tmp,info[k].name)){
				recipes[i].menu = k;
				break;
			}
		}

		checkTable[recipes[i].menu] = 1;

		recipes[i].setNUM(recipes[i].num);

		for(int k = 0; k < recipes[i].num; k++){
			scanf("%s",tmp);
			for(int p = 0; p < n; p++){
				if(strCmp(tmp,info[p].name)){
					recipes[i].push(p);
					break;
				}
			}
		}
	}

	int count,sum;
	bool FLG;

	while(true){

		count = 0;
		for(int i = 0; i < n; i++){
			if(checkTable[i] == 1){
				count++;
			}
		}
		if(count == 0)break;

		for(int i = 0; i < m; i++){
			if(recipes[i].used == false){
				FLG = true;
				sum = 0;

				for(int k = 0; k < recipes[i].num; k++){
					sum += info[recipes[i].component[k]].cost;
					if(checkTable[recipes[i].component[k]] == 1){
						FLG = false;
						break;
					}
				}
				if(FLG){
					info[recipes[i].menu].cost = min(info[recipes[i].menu].cost,sum);
					recipes[i].used = true;
					checkTable[recipes[i].menu] = 0;
				}
			}
		}
	}

	char to_make[101];
	scanf("%s",to_make);

	for(int i = 0; i < n; i++){
		if(strCmp(info[i].name,to_make)){
			printf("%d\n",info[i].cost);
			break;
		}
	}
}

int main(){

	int n;

	while(true){
		scanf("%d",&n);
		if(n == 0)break;

		func(n);

	}

	return 0;
}

Measured memory_bytes: 2696
#include <stdio.h>
#include <stdlib.h>

#define MAX 2000001
#define VMAX 10001

void countingSort(int*, int, int*, int);

int main() {
  int i, al;
  int *arrayA, *arrayB;

  arrayA = malloc(sizeof(int)*MAX);
  arrayB = malloc(sizeof(int)*MAX);
  
  scanf("%d", &al);
  for(i=1 ; i <= al ; i++) { scanf("%d", &arrayA[i]); }

  countingSort(arrayA, al, arrayB, 10000);
  
  for(i=1 ; i <= al ; i++) {
    printf("%d", arrayB[i]);
    if(i != al) { printf(" "); }
  }
  printf("\n");
  
  return 0;
}

void countingSort(int *A, int al, int *B, int k) {
  int i, C[VMAX];
  
  for(i=0; i <= k ; i++) { C[i] = 0; }

  for(i=1; i <= al ; i++) { C[A[i]]++; }

  for(i=1; i <= k ; i++) { C[i] = C[i] + C[i-1]; }

  for(i=al; i >= 1 ; i--) {
    B[C[A[i]]] = A[i];
    C[A[i]]--;
  }
}




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

int div2(int n) {
  int sum = 0;
  while(1) {
    if(n % 2 == 0) {
      sum++;
      n /= 2;
    } else {
      break;
    }
  }
  return sum;
}

int main() {
  int n;
  cin >> n;
  int m = 0;
  int ans = 0;
  
  if(n == 1) {
    cout << 1 << endl;
    return 0;
  }
  for(int i = 0; i < n; i++) {
    if(m < div2(i+1)) {
      m = div2(i+1);
      ans = i+1;
    }
  }
    
  cout << ans << endl;
}


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

int main(){

    set<char> S;
    for(int i = 0; i < 3; i++){
        char s;
        cin >> s;
        S.insert(s);
    }

    if(S.size() == 3) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
import Foundation

let input_line = readLine()!
let start1 = input_line.startIndex.advancedBy(0)
let end1 = start1.advancedBy(2)
let start2 = input_line.startIndex.advancedBy(2)
let end2 = start2.advancedBy(2)

let first = Int(input_line.substringWithRange(Range(start: start1, end: end1)))!
let secound = Int(input_line.substringWithRange(Range(start: start2, end: end2)))!

if (0 < first && first <= 12) {  
	if(0 < secound && secound <= 12) {
    	print("AMBIGUOUS")
    } else {
    	print("MMYY") 
    }
} else {
	if(0 < secound && secound <= 12) {
    	print("YYMM")
    } else {
    	print("NA") 
    }
}

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

#define fs first
#define sc second
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

const int32_t inf = 1001001001;
const int64_t infll = 1001001001001001001ll;
const int dx[] = {0, -1, 1, 0, -1, 1, -1, 1}, dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};

template <typename T> using vector2d = vector<vector<T>>;

// clang-format off
template <typename T> void sort(vector<T> &v) { sort(all(v)); }
ostream &operator<<(ostream &os, __int128_t value) { if (ostream::sentry(os)) { __uint128_t tmp = value < 0 ? -value : value; char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[tmp % 10]; tmp /= 10; } while (tmp != 0); if (value < 0) { --d; *d = '-'; } int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); }} return os; }
istream &operator>>(istream &is, __int128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } if (in[0] == '-') value *= -1; return is; }
ostream &operator<<(ostream &os, __uint128_t value) { if (ostream::sentry(os)) { char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[value % 10]; value /= 10; } while (value != 0); int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); }} return os; }
istream &operator>>(istream &is, __uint128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } return is; }
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { os << v[0]; for (int i = 1; i < v.size(); ++i) os << " " << v[i]; return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << p.fs << " " << p.sc; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.fs >> p.sc; return is; }

struct IoSetup { IoSetup(){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup;

inline int64_t in() { int64_t x = 0; cin >> x; return x; }
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on

signed main(int argc, char *argv[]) {
  int n = in(), k = in();

  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;

    ans += min(x, abs(k - x)) * 2;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<int>vec;
    for(int i=0;i<n;i++)
    {
        int value;
        cin>>value;
        --value;
        vec.push_back(value);
    }
    int now=0,counter=0 ;
    for(;;)
    {
        if(now==1)
        {
            cout<<counter<<endl;
            break ;
        }
        if(counter>=n)
        {
            cout<<"-1\n";
            break ;
        }
        counter++;
        now=vec[now];
    }
    return 0;
}


Measured memory_bytes: 892
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <iomanip>
#include <stack>
#include <fstream>
#include <cstdint>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>

using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long n;
    while(cin >> n){
        if(n == 0)
            return 0;
        array<vector<int>, 31> sched;
        for (int i = 0; i < n; ++i) {
            int k;
            cin >> k;
            for (int j = 0; j < k; ++j) {
                int u;
                cin >> u;
                sched[u].push_back(i);
            }
        }


        int ans = [&]() {
            vector<long long> saw(n);
            for (long long i = 0; i < n; ++i) {
                saw[i] = 1ll << i;
//                cerr << i << ',' << saw[i] << '\n';
            }
            long long all_saw = 1ll << n;
            all_saw -= 1;
//            cerr << "ALL::" << all_saw << '\n';
            for (int i = 1; i < sched.size(); ++i) {
                if (sched[i].size() > 0) {
                    long long today_saw = 0;
                    for (int j = 0; j < sched[i].size(); ++j) {
                        today_saw |= saw[sched[i][j]];
                    }
                    if(today_saw == all_saw)    return i;
                    for(auto&& s: sched[i]){
                        saw[s] = today_saw;
                    }
                }
            }
            return -1;
        }();
        cout << ans << endl;
    }

}



Measured memory_bytes: 3192