akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define sum accumulate
#define keta setprecision
typedef long long ll;
const int INF = 100000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 998244353LL;
int main(){
	int a,b;
	std::cin >> a>>b;
	std::cout << a/b<<" "<< a%b<<" "<<fixed<<keta(8)<<(double)a/b<< std::endl;
}


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

using namespace std;

int d[3], a , c , b, g;
int main()
{
	cin >> d[0] >> d[1] >> d[2];
	for (int i = 0; i < 3; i++)
	{
		if (d[i] % 2 == 1)
		{
			cout << 0;
			return 0;
		}
	}
	if (d[0] == d[1] && d[1] == d[2] && d[0] % 2 == 0)
	{
		cout << -1;
		return 0;
	}
	while (d[0] % 2 != 1 && d[1]  % 2 != 1 && d[2] % 2 != 1)
	{
		a = d[0] / 2;
		b = d[1] / 2;
		c = d[2] / 2;
		d[0] = b + c;
		d[1] = a + c;
		d[2] = a + b;
		g++;
	}
	cout << g;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

ll n;

int main(){
	cin>>n;
	if(n%2==1) cout<<0<<endl;
	else{
		ll t=10,res=0;
		while(t<=n){
			res+=n/t;
			t*=5;
		}
		cout<<res<<endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <iostream> 
#include <string> 
using namespace std;
int main()
{
    
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        
    }
    int f=0;
    sort(a,a+n);
    for(int i=0;i<n;i++)
    {
        int temp=a[i];
        if(a[i]==a[i+1])
        {
            f=1;
            break;
        }
    }
    
    if(f==1)
    {
        cout<<"NO";
    }
    else
    cout<<"YES";
    return 0;
}










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

int main()
{
    int x;
    cin >> x;
    int a, b;
    a = x / 500;
    b = (x - a * 500) / 5;
    printf("%d\n", a * 1000 + b * 5);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fr(a,b,c) for(int a=b,__=c;a<__;a++)
using namespace std;
typedef long long ll;
ll d[100100],edg[100100],sze[100100];

vector<int> adj[100100];
int n,m;
ll mc[5];
int col[100100];

ll dfsib(int x,int c=1){
	col[x]=c;
	mc[c]++;
	for(auto a:adj[x]){
		if(col[a]){
			if(col[a]==c)return 0;
		}else{
			if(!dfsib(a,c^3))return 0;;
		}
	}
	return 1;
}

ll fdad(int x){
	if(!d[x])return x;
	return d[x]=fdad(d[x]);
}
void udad(int a,int b){
	a=fdad(a);
	b=fdad(b);
	edg[a]++;
	if(a==b)return;
	//cout<<a<<" "<<b<<endl;
	d[b]=a;
	sze[a]+=sze[b];
	
	//cout<<sze[a]<<" "<<sze[b]<<endl;
	edg[a]+=edg[b];
}

int main(){
	cin>>n>>m;
	fr(i,1,n+1)sze[i]=1;
	fr(i,0,m){
		int a,b;
		cin>>a>>b;
		adj[a].push_back(b);
		adj[b].push_back(a);
		udad(a,b);
	}
	ll ans=0;
	fr(i,1,n+1){
		if(!d[i]){
			//cout<<i<<" - "<<edg[i]<<endl;
			mc[1]=mc[2]=0;
			if(dfsib(i)){
				//cout<<mc[1]<<" "<<mc[2]<<endl;
				ans+=mc[1]*mc[2];
			}else{
				ans+=(sze[i]*(sze[i]-1))/2;
			}
			ans-=edg[i];
		}
	}	
	cout<<ans<<endl;
}

Measured memory_bytes: 8832
#import sys
N = int(input())
A,B = map(int,input().split())

plis = input().split()
res = [0,0,0]
for p in plis:
    i = int(p)
    if i <= A:
        res[0] += 1
    elif A+1 <= i and i <= B:
        res[1] += 1
    else:
        res[2] += 1

print(min(res))

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
int n;
char s[1001],st[1001];
int main()
{
   scanf("%s",s);
	if(s[0]=='a'||s[0]=='e'||s[0]=='i'||s[0]=='o'||s[0]=='u')
	{
		cout<<"vowel"<<endl;
	}
	else cout<<"consonant"<<endl;
    return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
#include <stack>
#include <map>
#include <iomanip>
using namespace std;

int64_t min(int64_t a,int64_t b) {
    if (a > b)
    {
        return b ;
    }else
    {
        return a ;
    }
}

const int MAX = 510000;
const int MOD = 1000000007;

int64_t fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main(){
    string s ;
    cin >> s ;
    vector<int> a(s.size()) ;
    for (int i = 0; i < s.size(); i++)
    {
        a.at(i) = s.at(i) - '0' ;
    }
    int num = 0 ;
    int ans = 999 ;
    for (int i = 0; i < s.size() - 2; i++)
    {
        num = a.at(i) * 100 + a.at(i+1) * 10 + a.at(i+2) ;
        ans = min(ans,abs(num - 753)) ;
    }
    cout << ans << endl ;
        
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 99999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m;i>n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(20) << S << endl
#define Vecpr(K,L1,L2,N) vector<pair<L1,L2>> K(N)
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,R) vector<vector<L>> K(N, vector<L>(M,R))
#define Lower(v,X) lower_bound(v.begin(),v.end(),X)-v.begin();
#define mod 1000000007
#define MAX 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
   lli A,B,C,L,R,N,M,K,X=0,Y=0,W,H=INF,sum=0,num=0,flag=0;string S,T,O;
   cin >> N;
   Vec(P,lli,N,0);
   rep(i,0,N)cin >> P[i];
   Sort(P);
   Y=P[N-1];
   X=Lower(P,Y/2);
   if(N>2){
      L=P[X];R=P[X-1];
      if(abs(Y/2-L)<=abs(Y/2-R))K=L;
      else K=R;
   }
   else K=P[0];
   cout << Y << " " << K << endl;
}

Measured memory_bytes: 1152
s=input()
a=int(s[:2])
b=int(s[2:])
j1=1<=a<=12
j2=1<=b<=12
if j1 and j2:
    print("AMBIGUOUS")
elif j1 and not j2:
    print("MMYY")
elif not j1 and j2:
    print("YYMM")
else:
    print("NA")

Measured memory_bytes: 38256
#include<bits//stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int h, w, mi;char s;
struct Corr {
    int x;
    int y;
    int depth;
};
queue<Corr> q;
Corr S;
bool p = false;
int bfs(vector<vector<bool>> grid) {
    // 既に探索の場所を1，探索していなかったら0を格納する配列
    vector<vector<int>> ispassed(grid.size(), vector<int>(grid[0].size(), false));
    int dx[8] = { 1, 0, -1, 0 };
    int dy[8] = { 0, 1, 0, -1 };
    S.depth = 0; S.x = 0;S.y = 0;
    q.push(S);
    while (!q.empty()) {
        Corr now = q.front();q.pop();
        if (now.x == w - 1 && now.y == h - 1) {
            p = true;
            return now.depth;
        }
        for (int i = 0; i < 4; i++) {
            int nextx = now.x + dx[i];
            int nexty = now.y + dy[i];
            // 次に探索する場所のX座標がはみ出した時
            if (nextx >= grid[0].size()) continue;
            if (nextx < 0) continue;

            // 次に探索する場所のY座標がはみ出した時
            if (nexty >= grid.size()) continue;
            if (nexty < 0) continue;
            // #の時
            if (!grid[nexty][nextx])
                continue;
            // 次に探索する場所が既に探索済みの場合
            if (ispassed[nexty][nextx]) continue;

            ispassed[nexty][nextx] = true;
            Corr next = { nextx, nexty, now.depth + 1 };
            q.push(next);
        }
    }
}
int main() {
    cin >> h >> w;
    int sq = h * w,no = 1;
    vector<vector<bool>> f(h, vector<bool>(w));
    rep(i, h) {
        rep(j, w) {
            cin >> s;
            if (s == '#') {
                f[i][j] = false;
                no++;
            }
            else
                f[i][j] = true;
        }
    }
    mi = bfs(f);
    if (!p)
        cout << -1 << endl;
    else 
        cout << sq - mi - no << endl;
}

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

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

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>

#include <vector>
#include <stack> // s.top()
#include <queue> // s.front()
#include <set>
using namespace std;

typedef long long llong;
typedef vector<int> vecint;
typedef vector<llong> vecllong;
typedef pair<llong, llong> P;

#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10

bool pairComp(const P& firstElof, const P& secondElof) {
	return firstElof.second > secondElof.second;
}

// ========================================================


int main() {

	int a, b, c;
	vecint d;
	cin >> a >> b >> c;
	d.push_back(a); d.push_back(b); d.push_back(c);
	sort(d.begin(), d.end());

	if (d[0] == 5 && d[1] == 5 && d[2] == 7)cout << "YES" << endl;
	else cout << "NO" << endl;


	





	



	return 0;
}

Measured memory_bytes: 256
N, A, B, C = map(int, input().split())
L = [int(input()) for _ in range(N)]


def dfs1(i, p1=[], p2=[], p3=[], ans=[]):
    #print(i)
    if i == N:
        if len(p1) != 0 and len(p2) != 0 and len(p3)!= 0:
            ans.append([p1, p2, p3])
        return ans
    l = L[i]
    ans = dfs1(i+1, p1+[l], p2, p3, ans)
    ans = dfs1(i+1, p1, p2+[l], p3, ans)
    ans = dfs1(i+1, p1, p2, p3+[l], ans)
    ans = dfs1(i+1, p1, p2, p3, ans)
    return ans

def dfs2(R, L=[], ans=[]):
    if len(L) == 3:
        ans.append(L)
        return ans
    for r in R:
        if not r in L:
            ans = dfs2(R, L+[r], ans)
    return ans

indexes = dfs2([0, 1, 2])

ans = int(1E18)
for (p1, p2, p3) in dfs1(0):
    S = [sum(p1), sum(p2), sum(p3)]
    for i1, i2, i3 in indexes:
        p = abs(A-S[i1]) + abs(B-S[i2]) + abs(C-S[i3]) + (len(p1)+len(p2)+len(p3) - 3)*10
        ans = min(ans, p)

print(ans)

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

int main() {
	int n;
	int score[1000];
	double mean, SD;
	while (1) {
		scanf("%d", &n);
		if (!n)break;
		mean = 0; SD = 0;
		for (int i = 0; i < n; i++) {
			scanf("%d", &score[i]);
			mean += (double)score[i];
		}
		mean /= (double)n;
		for (int i = 0; i < n; i++) {
			SD += ((double)score[i] - mean)*((double)score[i] - mean);
		}
		SD = sqrt(SD / (double)n);

		printf("%lf\n",SD);

	}
	return 0;
}


Measured memory_bytes: 2100
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<list>
#include<bitset>

#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 MOD 1000000007
#define INF 1000000000

using namespace std;

int main(void) {
	int x, y, z;
	int total = 0;
	int count = 0;

	cin >> x >> y >> z;
	total += z;

	while (1) {
		if (x - total >= y+z) {
			total += y + z;
			count++;
		}
		else {
			break;
		}
	}
	cout << count << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vector<T>>;
using vl = vector<ll>;

const ll MOD = 1e9 + 7;
const ll INF = 1e14;
const ld EPS = 1e-11;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (int i = (l); i < (r); i++)
#define reper(i, l, r) for (int i = (r)-1; i >= (l); i--)

void init() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
}
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N, K;
    cin >> N >> K;
    vl A(N);
    rep(i, N) cin >> A[i];
    vl suml;
    rep(i, N) {
        ll tmp = 0;
        repe(j, i, N) {
            tmp += A[j];
            suml.eb(tmp);
        }
    }

    ll ans = 0;
    repr(i, 41) {
        ll cnt = 0, tmp = ans + (1ll << i);
        rep(i, N * (N + 1) / 2) if ((suml[i] & tmp) == tmp) cnt++;
        // cout << tmp << " " << cnt << endl;
        if (cnt >= K) ans = tmp;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;


int main(){

	int a,b,c,k;
	cin>>a>>b>>c>>k;
  	vector<int> arr;
    arr.push_back(a);
    arr.push_back(b);
  	arr.push_back(c);
  	sort(arr.begin(), arr.end());
    for(int i=0; i<k; i++)
      arr[2] *= 2;
  	cout<<arr[2] + arr[1] + arr[0];
	return 0;

}

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

int main(){
  ll K, i;
  string S;
  cin >> K >> S;
  
  if(S.size() > K){
    S = S.substr(0, K);
    S += "...";
  }
  
  cout << S << endl;
  return 0;
}
 

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



int main() {
    int a,b,c,d,e,f;
    cin >> a>> b>>c>>d>>e>>f;
    double NOUDO = (double)e/(100+(double)e);
    set<int>W,S;
    rep(i,f){
        rep(j,f){
            int x =100*(a*i+b*j);
            if(x<=f)  W.insert(x);
        }
    }
    rep(i,f){
        rep(j,f){
            int y = c*i+d*j;
            if(y<=f) S.insert(y);
        }
    }
    double MAX = -1.0;
    int ans1,ans2;
    for(auto i:W){
     for(auto j:S){
            int T = i+j;
            if(T==0) break;
            double N = (double)j/(double)T;
            if(N<=NOUDO && T<=f) {
                if(N>MAX){
                    ans1=T;
                    ans2=j;
                    MAX = N;
                }
            }
        }
    }
    cout << ans1 <<' ' << ans2<<endl;
}

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    string s;
    cin >> s;

    int ans = 0;
    bool ok = false;
    int tmp = 0;
    s += "X";
    rep(i, s.size()) {
        if (s[i] == 'A' or s[i] == 'T' or s[i] == 'G' or s[i] == 'C') {
            if (!ok) {
                ok = true;
                tmp = 1;
            }
            else if (ok) {
                tmp++;
            }
        }
        else if (ok) {
            ans = max(ans, tmp);
            tmp = 0;
            ok = false;
        }
    }
    cout << ans << endl;
}


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

int main()
{
    double a, b;

    while( cin >> a >> b )
    {
        if( a - 35.50 < 0 && b - 71 < 0 )
            cout << "AAA";
        else if( a - 37.50 < 0 && b - 77 < 0 )
            cout << "AA";
        else if( a - 40 < 0 && b - 83 < 0 )
            cout << "A";
        else if( a - 43 < 0 && b - 89 < 0 )
            cout << "B";
        else if( a - 50 < 0 && b - 105 < 0 )
            cout << "C";
        else if( a - 55 < 0 && b - 116 < 0 )
            cout << "D";
        else if( a - 70 < 0 && b - 148 < 0 )
            cout << "E";
        else
            cout << "NA";
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3188
#[allow(unused_imports)]
use std::cmp::*;

// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}


fn main() {
    input!{
        n: isize,
        k: isize,
    }

    let a = n % k;
    let ans = min(a, k-a);
    
    println!("{}", ans);
}


Measured memory_bytes: 2144
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    while(true){
        if(n==1000){
            cout << 0 << endl;
            return 0;
        }else if(n<1000){
            int tmp = n%1000;
            cout << 1000 - tmp << endl;
            return 0;
        }else{
            n-=1000;
        }
    }
    return 0;
}

Measured memory_bytes: 3572
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

#define REP(i,n) for(int i = 0; i < n; i++)
#define ll long long
#define PI 3.141592653589

using namespace std;

void InpAr(int *array, int n){
    REP(i,n) cin >> array[i];
}

int primeCheck(int N){
    bool exist = false; //素数
    for(int i = 2; i <= sqrt(N); i++){
        if(N % i == 0) exist = true; //合成数
    }

    if(exist) return -1; //合成数
    else return 1; //素数
}

int main(void){
    int X;
    cin >> X;

    int j = X;
    while(1){
        if(primeCheck(j) == -1) j++;
        else{
            cout << j;
            break;
        }
    }
    
    
    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] ary = new int[n];
		for(int i = 0; i < n; i++){
			ary[i] = sc.nextInt();
		}
		Arrays.sort(ary);
		System.out.println(ary[n / 2] - ary[n / 2 - 1]);
	}
}


Measured memory_bytes: 50276
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
int N, M, X;

int main()
{
    cin >> N >> M >> X;
    int a[14][14];
    int c[14];
    ll ans;
    rep(i, 0, N)
    {
        cin >> c[i];
        rep(j, 0, M)
        {
            cin >> a[i][j];
        }
    }

    bool flg = true;
    ll min = LLONG_MAX;
    for (int bits = 0; bits < (1 << N); bits++)
    {
        vector<int> sum(M, 0);
        ans = 0;
        for (int i = 0; i < N; i++)
        {
            if (bits & (1 << i))
            {
                for (int j = 0; j < M; j++)
                {
                    sum[j] += a[i][j];
                }
                ans += c[i];
            }
        }
        // cout << ans << endl;
        flg = true;
        rep(j, 0, M)
        {
            if (sum[j] < X)
            {
                flg = false;
            }
        }
        if (flg)
        {
            if (ans < min)
            {
                // cout << min << endl;
                min = ans;
            }
        }
    }

    if (min == LLONG_MAX)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << min << endl;
    }
    return 0;
}


Measured memory_bytes: 3584
#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>;

 
int main(void)
{
    int x;

    cin >> x;

   if(x <30){
       cout << "No" << endl;
   }else{
       cout << "Yes" << endl;
   }

}

Measured memory_bytes: 3612
n,m=gets.split(" ").map(&:to_i) #最初のｎとｍのVALUE　をとる

a=n.times.map do                #matrixをN回やる
gets.split.map(&:to_i)          #空白段落分けて入力するためMAPとSPLIT
end
b=m.times.map do                #VECTORをm回入力
gets.to_i                       #値入力
end

a.each do |r|                   #rのなかをひとつひとつを繰り返す
    puts r.zip(b).map {|x, y| x * y }.reduce( :+)#ZIPはaとbを連動して計算をする
  end
  


Measured memory_bytes: 7076
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<iomanip>
#define pi 3.14159265358979323846
#define ll long long
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
int main(){
  int a, b;
  char c;
  cin >> a >> c >> b;
  if(c == '+'){
    cout << a + b << "\n";
    return 0;
  }
  if(c == '-'){
    cout << a - b << "\n";
    return 0;
  }
  cout << a * b << "\n";
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> vec(N);
  rep(i, N) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  int sum = 0;
  rep(i, K) {
    sum += vec.at(i);
  }
  cout << sum << endl;
}

Measured memory_bytes: 3628
#include <math.h>
#include <algorithm>
#include <set>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <string>
#include <cstring>
#include <functional>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <chrono>
#include <climits>
using namespace std ;
#define ld long double
#define int long long
#define ii pair<int,int>
#define FAST_IO ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL); clock_t beg = clock()
#define dbg(x) cerr << #x << " is " << x << endl;
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define vi vector<int >
#define pb push_back
#define endl '\n'
#define ff first
#define ss second
const int N = 3e5+7 ;
const int INF = 1e18 ;
const int MOD = 1e9 + 7 ;
string s ;

void solve(){
	int  n ;
	cin >> n ;
	vi a(n) ;
	for(auto& x : a) cin >> x ;
	set<int> st ;
	int ans = 0 ;
	st.insert(a[0]) ;
	for(int i = 0 ; i < n ; i++){
		if(a[i] <= *st.begin()) ans++ ;		
		st.insert(a[i]) ;
	}
	cout << ans << endl ;
}

int32_t main(){
	FAST_IO ;
	int t = 1 ;
//	cin >> t ;
	while(t--){
		solve() ;
	}
    cerr << "\nExecution time: " << (clock() - beg) / 1000 << '\n';
}


Measured memory_bytes: 11264
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))



H,N = two_int()

dp = [0 for j in range(H)]

magics = []
for i in range(N):
    A,B = two_int()
    magics.append([A,B])

for i in range(H):
    temps=[]
    for [A,B] in magics:
        ind = i-A
        if ind >= 0:
            temps.append(dp[ind] + B)
        else:
            temps.append(B)
#     print(temps)
#     if i==2:
#         break
    dp[i] = min(temps)

print(dp[-1])

Measured memory_bytes: 43228
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program{
	const int mod=1000000007;
	const long o=1;
	static void Main(){
		Sc sc=new Sc();
		int[] s=sc.Ia;
		string ans="NO";
		if(s[1]*2-1<=s[0]){ans="YES";}
		Console.WriteLine("{0}",ans);
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
}

Measured memory_bytes: 13268
using System;
using System.Collections.Generic;
using System.Linq;

class program{
    public static void Main(){
        var S = int.Parse(Console.ReadLine());
        var h = S/3600;
        var m = (S % 3600) / 60;
        var s = S % 60;

        Console.WriteLine($"{h}:{m}:{s}");
    }
}


Measured memory_bytes: 17992
#include <stdio.h>

int main()
{
	int i, N, a[101];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d", &(a[i]));

	int t, diff = 0, flag[101] = {}, max, argmax;
	for (t = 1; t <= N; t++) {
		max = 0;
		argmax = 0;
		for (i = 1; i <= N; i++) {
			if (flag[i] == 0 && a[i] > max) {
				max = a[i];
				argmax = i;
			}
		}
		flag[argmax] = 1;
		if (t % 2 == 1) diff += max;
		else diff -= max;
	}
	
	printf("%d\n", diff);
	fflush(stdout);
	return 0;
}

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

int main(){
  int n,t,e,a,f=0;
  cin>>n>>t>>e;
  for(int i=0;i<n;i++){
    cin>>a;
    if((t+e)/a*a>=t-e){
      f=1;
      cout<<i+1<<endl;
      break;
    }
  }
  if(!f)cout<<-1<<endl;
  return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size() 

ll power(ll x,ll y,ll p) 
{ 
    ll res = 1;      
    x = x % p;  
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1; 
        x = (x*x) % p;   
    } 
    return res; 
} 

int main()
{
    ios_base::sync_with_stdio(false);
	ll n,i,j,k,x,y,t,m;

	cin >> x;
	if(x>=30)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
}

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

using namespace std;

const int MOD=(int)1e9+7;

int add(int a,int b)
{
    a+=b;
    if(a>=MOD)
    {
        a-=MOD;
    }
    if(a<0)
    {
        a+=MOD;
    }
    return a;
}

int mul(int a,int b)
{
    return a*(long long)b%MOD;
}


typedef long long ll;
typedef long double ld;

const int N=100+5;
const int K=(int)1e5+5;

int n,k;
int a[N];
int dp[N][K];
int s[N][K];

int ask(int i,int l,int r)
{
    if(l<0)
    {
        l=0;
    }
    if(l==0)
    {
        return s[i][r];
    }
    else
    {
        return add(s[i][r],-s[i][l-1]);
    }
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>n>>k;
    for(int i=0;i<K;i++)
    {
        s[0][i]=1;
    }
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        for(int tot=0;tot<=k;tot++)
        {
            dp[i][tot]=ask(i-1,tot-a[i],tot);
            s[i][tot]=dp[i][tot];
            if(tot>0)
            {
                s[i][tot]=add(s[i][tot],s[i][tot-1]);
            }
        }
    }
    cout<<dp[n][k]<<"\n";
    return 0;
}



Measured memory_bytes: 82176
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
/////递归
//long long binaryPow(long long a, long long b, long long m)
//{
//	if (b == 0) return 1;
//	else if (b % 2 == 1) return a * binaryPow(a, b - 1,m)%m;
//	else
//	{
//		long long temp = binaryPow(a, b / 2,m)%m;
//		return temp * temp%m;
//	}
//}
int main()
{
	long long n, k;
	cin >> n >> k;
	for (int i = 0;; i++)
	{
		if ((pow(k, i)) <= n) continue;
		else {
			cout << i << endl; break;
		}
	}
}


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

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin>>n;
vector<int> a(n);
rep(i,n)cin>>a[i];
sort(a.begin(),a.end());
cout<<a[n-1]-a[0]<<endl;
return 0;
}

Measured memory_bytes: 256
s = input()
t = input()

def no():
    print("UNRESTORABLE")

les = len(s)-len(t)
kouho = []
if les < 0:
    no()
else:
    for i in range(les+1):
        flag =True
        for j in range(len(t)):
            if s[i+j] == "?":
                continue
            elif s[i+j] == t[j]:
                continue
            else:
                flag = False
                break
        if flag:
            kouho.append(i)
    if len(kouho) == 0:
        no()
    else:
        temp = []
        for i in range(len(kouho)):
            txt =""
            for j in range(len(s)):
                if s[j] == "?":
                    if j >= kouho[i] and j <= kouho[i]+len(t)-1:
                        txt+=t[j-kouho[i]]
                    else:
                        txt+="a"
                else:
                    txt += s[j]
            temp.append(txt)
        temp.sort()
        print(temp[0])




Measured memory_bytes: 3064
from itertools import combinations

s = input()
n = int(s)
l = len(s)
k = int(input())


if k == 1:
	print(9 * (len(s)-1) + int(s[0]))

elif k == 2:
	if len(s) == 1:
		print(0)
	elif len(s) == 2:
		print(n - 9 - n//10)
	else:
		ans = 81 * (l-1) * (l-2) // 2
		for i in range(1, 10):
			for x in range(l-1):
				for j in range(1, 10):
					if i * (10**(l-1)) + j * (10**x) <= n:
						ans += 1
		print(ans)

else:
	if len(s) < 3:
		print(0)
	elif len(s) == 3:
		ans = 0
		for i in range(100, n+1):
			if "0" not in list(str(i)):
				ans += 1
		print(ans)
	else:
		ans = 729 * (l-1) * (l-2) * (l-3) // 6
		ans += (int(s[0])-1) * (l-1) * (l-2) * 81 // 2
		for x, y in combinations(range(l-1), 2):
			for z in range(81):
				j, k = (z//9) + 1, (z%9) + 1
				if int(s[0]) * (10**(l-1)) + j * (10**x) + k * (10**y) <= n:
					ans += 1
		print(ans)

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

struct dice {
	int top;
	int bottom;
	int north;
	int east;
	int south;
	int west;
};


class Dice {
	public:
		void init(int i, int j, int k, int l, int m, int n);
		void order(char order);
		void print_top();
	private:
		struct dice dice_s;
		void north();
		void east();
		void south();
		void west();
};

void Dice::init(int i, int j, int k, int l, int m, int n)
{
	dice_s.top = i;
	dice_s.bottom = n;
	dice_s.south = j;
	dice_s.east = k;
	dice_s.west = l;
	dice_s.north = m;

}

void Dice::order(char order)
{

		switch(order) {
			case 'E':
				east();
				break;
			case 'W':
				west();
				break;
			case 'N':
				north();
				break;
			case 'S':
				south();
				break;
			default:
				break;
		}

}

void Dice::east()
{
	int top = dice_s.top;
	int bottom = dice_s.bottom;
	int east = dice_s.east;
	int west = dice_s.west;

	dice_s.top = west;
	dice_s.bottom = east;
	dice_s.east = top;
	dice_s.west = bottom;


}
void Dice::west()
{
	int top = dice_s.top;
	int bottom = dice_s.bottom;
	int east = dice_s.east;
	int west = dice_s.west;

	dice_s.top = east;
	dice_s.bottom = west;
	dice_s.east = bottom;
	dice_s.west = top;


}
void Dice::north()
{
	
	int top = dice_s.top;
	int bottom = dice_s.bottom;
	int north = dice_s.north;
	int south = dice_s.south;

	dice_s.top = south;
	dice_s.bottom = north;
	dice_s.south = bottom;
	dice_s.north = top;

}
void Dice::south()
{
	int top = dice_s.top;
	int bottom = dice_s.bottom;
	int north = dice_s.north;
	int south = dice_s.south;

	dice_s.top = north;
	dice_s.bottom = south;
	dice_s.south = top;
	dice_s.north = bottom;

}

void Dice::print_top()
{
	cout << dice_s.top << '\n';

}


int main()
{
	class Dice dice1;
	int first,second,third,forth,fifth,sixth;
	char order;

	cin >> first >> second >> third >> forth >> fifth >> sixth;

	dice1.init(first, second, third, forth, fifth, sixth);

	while(cin >> order) {

		dice1.order(order);


	}
		dice1.print_top();


	return 0;
}


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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    int n, m;
    cin >> n >> m;
    vector<ll> x(m), y(m-1);
    ll sum = 0;
    rep(i, m) {
        cin >> x[i];
    }
    if (n >= m) {
        cout << 0 << endl;
        return 0;
    }
    sort(x.begin(), x.end());
    rep(i, m-1) {
        y[i] = abs(x[i]-x[i+1]);
        sum += y[i];
    }
    sort(y.rbegin(), y.rend());
    rep(i, n-1) {
        sum -= y[i];
    }
    cout << sum << endl;
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  ll n, a, b;
  cin>>n>>a>>b;
  if((b-a)%2==0){
    cout<<(b-a)/2<<'\n';
    return 0;
  }
  ll ans=min({b-1, n-a, (b-a+1)/2+n-b, (b-a+1)/2+a-1});
  cout<<ans<<'\n';
  return 0;
}


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

int main(){
    int n;
    cin >> n;
    long long l[2];
    l[0] = 2;
    l[1] = 1;
    for (int i = 2; i <= n; i++){
        l[i % 2] = l[0] + l[1];
    }
    cout << l[n % 2] << endl;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n int
	var s string
	fmt.Scan(&n, &s)
	target := "ABC"

	save := 0
	count := 0
	for i := 0; i < n; i++ {
		if s[i] == target[save] {
			save++
			if save >= 3 {
				save = 0
				count++
			}
		} else {
			if s[i] == target[0] {
				save = 1
			} else {
				save = 0
			}
		}
	}
	fmt.Println(count)
}


Measured memory_bytes: 512
import sys
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split()) 
DBG = True # and False

def ddprint(x):
  if DBG:
    print(x)

n = inn()
print(((n+1)//2)/n)


Measured memory_bytes: 3060
import sys
N = int(input())
a_ls = list(map(int, input().split()))

Maxabs = 0
indofmaxabs = -1
for i in range(N):
    if Maxabs < abs(a_ls[i]):
        Maxabs = abs(a_ls[i])
        indofmaxabs = i
if Maxabs == 0:
    print(0)
    sys.exit()

print(2*(N-1))
# 符号を統一
for i in range(N):
    if not i == indofmaxabs:
        print(indofmaxabs+1,i+1)

# 階段にする
if a_ls[indofmaxabs] >= 0:
    for i in range(N-1):
        print(i+1,i+2)
else:
    for i in range(N-1,0,-1):
        print(i+1,i)



Measured memory_bytes: 62400
N,A,B = gets.split(/\s/).map {|s|s.to_i}
S = gets.chomp

tuuka = 0
kaigai = 0
S.size.times do |i|
  if S[i]=="a" then
    if tuuka < A+B then
      puts "Yes"
      tuuka += 1
    else
      puts "No"
    end
  elsif S[i]=="b" then
    if tuuka < A+B && kaigai < B then
      puts "Yes"
      tuuka += 1
      kaigai += 1
    else
      puts "No"
    end
  else
    puts "No"
  end
end

Measured memory_bytes: 2300
import java.util.*;
import java.io.*;

class Main {
	public static void main(String... args) {
		int x1 = IN.nextInt();
		int y1 = IN.nextInt();
		int x2 = IN.nextInt();
		int y2 = IN.nextInt();
		
		int x3 = x2 + (y1 - y2);
		int y3 = y2 + (x2 - x1);
		int x4 = x1 + (y1 - y2);
		int y4 = y1 + (x2 - x1);
		puts(x3 + " " + y3 + " " + x4 + " " + y4);
		flush();
	}

	static final Scanner IN = new Scanner(System.in);
	static final PrintWriter OUT = new PrintWriter(System.out);
	static <T> void puts(T arg) { OUT.println(arg); }
	static void flush() { OUT.flush(); }
}


Measured memory_bytes: 24148
#include <cstdio>
#include <cstring>
#include <cstdlib>

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

int h1(int key) { return key % M; }
int h2(int key) { return 1 + (key % (M - 1)); }

int getChar(char ch) {
    switch (ch) {
        case 'A':
            return 1;
        case 'C':
            return 2;
        case 'G':
            return 3;
        case 'T':
            return 4;
    }
    return 0;
}

long long getKey(char str[]) {
    long long sum = 0, p = 1, i;
    for ( i=0; i < strlen(str); i++) {
        sum += p * (getChar(str[i]));
        p *= 5;
    }
    return sum;
}

int insert(char str[]) {
    long long key, i, h;
    key = getKey(str);
    for ( i=0;; i++ ) {
        h = (h1(key) + i * h2(key)) % M;
        if (strcmp(H[h], str) == 0) return 1;
        else if ( strlen(H[h]) == 0 ){
            strcpy(H[h], str);
            return 0;
        }
    }
    return 0;
};

bool find(char str[]) {
    long long key, i, h;
    key = getKey(str);
    for ( i=0;; i++ ) {
        h = (h1(key) + i * h2(key)) % M;
        if (strcmp(H[h], str) == 0) return true;
        else if (strlen(H[h]) == 0) return false;
    }
    return false;
}

int main()
{
    int n;
    scanf("%d", &n);

    char order[10], str[L];
    for (long long i=0; i < M; i++) H[i][0] = '\0';
    for (int i=0; i<n; i++) {
        scanf("%s %s", order, str);
        if (strcmp(order, "insert") == 0) {
            int x = insert(str);
        } else if (strcmp(order, "find") == 0) {
            bool x = find(str);
            if (x) {
                printf("yes\n");
            } else {
                printf("no\n");
            }
        }
    }

    return 0;
}

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

int main(){
  ll a, b, c, d; cin >> a >> b >> c >> d;
  bool turn = true;
  while(1){
    if(turn) c -= b;
    else a -= d;
    if(a <= 0 || c <= 0) break;
    turn = !turn;
  }
  string res = turn ? "Yes" : "No";
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3572
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    def ZAlgorithm(S):
        n = len(S)
        res = [0] * n
        res[0] = n
        i = 1
        j = 0
        while i < n:
            while i + j < n and S[j] == S[i + j]:
                j += 1
            res[i] = j
            if j == 0:
                i += 1
                continue
            k = 1
            while i + k < n and k + res[k] < j:
                res[i + k] = res[k]
                k += 1
            i += k
            j -= k
        return res

    n = int(input())
    S = input()

    res = 0
    for i in range(n):
        T = S[i:]
        LCP = ZAlgorithm(T)
        for j in range(len(T)):
            l = min(LCP[j], j)
            res = max(res, l)
    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 78932
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 50;
const int MAX_M = 1225;
const int MAX_K = 10;
const int MAX_L = 7;
const int MAX_BITS = (1 << MAX_L);

const int INF = 1 << 30;

/* typedef */

typedef pair<int,int> pii;
typedef vector<pii> vpii;

struct Stat {
  int i, b, d;
  Stat(int _i, int _b, int _d) { i = _i, b = _b, d = _d; }
  bool operator<(const Stat& s) const { return d > s.d; }
};

/* global variables */

int n, m, l, k;
int st, gl, gbits;
int bis[MAX_N];

vpii nbrs[MAX_N];
int dists[MAX_N][MAX_BITS][MAX_K];

/* main */

int main() {
  for (;;) {
    cin >> n >> m >> l >> k;
    if (n == 0) break;

    gbits = (1 << l) - 1;

    for (int i = 0; i < n; i++) {
      nbrs[i].clear();
      bis[i] = -1;
      for (int b = 0; b <= gbits; b++)
	for (int j = 0; j < k; j++) dists[i][b][j] = INF;
    }

    for (int i = 0; i < m; i++) {
      int u, v, c;
      cin >> u >> v >> c;
      u--, v--;
      nbrs[u].push_back(pii(v, c));
      nbrs[v].push_back(pii(u, c));
    }

    cin >> st >> gl;
    st--, gl--;

    for (int i = 0; i < l; i++) {
      int bi;
      cin >> bi;
      bi--;
      bis[bi] = i;
    }

    int sb = (bis[st] >= 0) ? (1 << bis[st]) : 0;
    
    priority_queue<Stat> q;
    q.push(Stat(st, sb, 0));
    dists[st][sb][0] = 0;
    
    int distk = -1;
    
    while (! q.empty()) {
      Stat u = q.top();
      q.pop();

      int udk = dists[u.i][u.b][k - 1];
      if (u.d > udk) continue;
      
      if (u.i == gl && u.b == gbits && u.d == udk) {
	distk = u.d;
	break;
      }

      vpii& nbru = nbrs[u.i];
      for (vpii::iterator vit = nbru.begin(); vit != nbru.end(); vit++) {
	int vi = vit->first;

	int vb = u.b;
	if (bis[vi] >= 0) vb |= (1 << bis[vi]);

	int vd = u.d + vit->second;
	int *dpt = dists[vi][vb];
	
	if (dpt[k - 1] > vd) {
	  dpt[k - 1] = vd;
	  for (int ki = k - 1; ki > 0 && dpt[ki] < dpt[ki - 1]; ki--) {
	    int tmp = dpt[ki]; dpt[ki] = dpt[ki - 1]; dpt[ki - 1] = tmp;
	  }
	  q.push(Stat(vi, vb, vd));
	}
      }
    }

    if (distk < 0)
      cout << "NA" << endl;
    else
      cout << distk << endl;
  }

  return 0;
}

Measured memory_bytes: 4244
#include <stdio.h>
int main(){
    int n;
    scanf("%d",&n);
    if(n<2) printf("1\n");
    if(n>=2 && n<4) printf("2\n");
    if(n>=4 && n<8) printf("4\n");
    if(n>=8 && n<16)printf("8\n");
    if(n>=16 && n<32)printf("16\n");
    if(n>=32 && n<64)printf("32\n");
    if(n>=64)printf("64\n");

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
string s;
int n;
bool ok = true;
int main(){
	cin >> s;
	n = s.size();
	rep(i,n/2) if(s[i] != s[n-1-i] || s[i] != s[n/2-1-i]) ok = false;
	puts(ok ? "Yes" : "No");
}

Measured memory_bytes: 256
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include<bits/stdc++.h>

using namespace std;
 
#define  GODSPEED       ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(15);
#define  f              first                 
#define  s              second
#define  newl           cout<<"\n";
#define  pb             push_back  
#define  mset(a,x)      memset(a,x,sizeof(a))
#define  debv(a)        for(auto it: a)cout<<it<<" ";newl;
#define  deb1(a)        cout<<a<<"\n";
#define  deb2(a,b)      cout<<a<<" "<<b<<"\n";
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<"\n";
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
#define  uniq(a)        a.resize(unique(a.begin(), a.end()) - a.begin());
#define  all(a)         a.begin(),a.end()           
 
typedef  long long             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  vector<pll>           vpll;

const ll   N     =  3e5+5;
const ll   mod   =  1e9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;
const ll   LEVEL =  log2(N)+1;

ll test = 1, n, a[N], ans = 0;

void solve(){
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = 2; i <= n; i++){
		if(a[i] >= a[i-1]) continue;
		ans += a[i-1]-a[i];
		a[i] = a[i-1];
	}
	deb1(ans)
}

int main(){
	GODSPEED;
	//cin>>test;
	for(int i = 1; i <= test; i++){
		solve();
	}
	#ifndef ONLINE_JUDGE
	cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
	#endif
}

Measured memory_bytes: 5176
#include <map>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define L
#define LL long long
using namespace std;

inline int gi() {
  char cj = getchar();
  int ans = 0, f = 1;
  while (cj < '0' || cj > '9') { if (cj == '-') f = -1; cj = getchar();}
  while (cj >= '0' && cj <= '9') ans = ans * 10 + cj - '0', cj = getchar();
  return f * ans;
}

int n, m;

int main() {
  //freopen("K-City.in", "r", stdin);
  //freopen("K-City.out", "w", stdout);
  n = gi(), m = gi();
  printf("%d\n", (n - 1) * (m - 1));
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<math.h>
#define ll long long
using namespace std;
ll b[100005];
int main()
{
    int n;
    scanf("%d",&n);
    
    ll a[100005],i;
    
    for(i=0; i<n; i++)
        scanf("%lld",&a[i]);
    memset(b,0,sizeof(b));
    if(n>=1e5)
        a[-2]=0;
    if(a[0]!=0)
            printf("0\n");
    else
    {
        ll ans=1;
        for(i=0;i<n;i++)
            b[a[i]]++;
        for(i=1;i<n;i++)
        {
            ans*=b[a[i]-1];
            ans%=998244353;
        }

        printf("%lld\n",ans);
    }
    return 0;
}


Measured memory_bytes: 1792
N = int(input())
H = list(map(int, input().split())) + [10**9+1]

step = [0]*len(H)
i = 0

while(True):
    count = 0
    start = i
    if i == len(H)-1:
        break
    while H[i] >= H[i+1]:
        count += 1
        i += 1
    step[start] = count
    i += 1

print(max(step))

    


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

using namespace std;

int main() {
  string s1, s2, s3;
  cin >> s1 >> s2 >> s3;
  cout << (char)toupper(s1[0]) << (char)toupper(s2[0]) << (char)toupper(s3[0]) << endl;
}

Measured memory_bytes: 256
h,w=map(int,input().split())
l=[[i for i in input()] for j in range(h)]
INF=float('inf')
dp=[[INF for j in range(w)] for i in range(h)]
dp[0][0]=0
if l[0][0]=="#":
    dp[0][0]+=1
if l[-1][-1]=="#":
    dp[0][0]+=1
for i in range(1,w):
    if l[0][i-1]==l[0][i]:
        dp[0][i]=dp[0][i-1]
    else:
        dp[0][i]=dp[0][i-1]+1
for i in range(1,h):
    for j in range(w):
        if l[i-1][j]==l[i][j]:
            dp[i][j]=dp[i-1][j]
        else:
            dp[i][j]=dp[i-1][j]+1
        if j==0:
            continue
        if l[i][j-1]==l[i][j]:
            dp[i][j]=min(dp[i][j],dp[i][j-1])
        else:
            dp[i][j]=min(dp[i][j],dp[i][j-1]+1)
print(dp[-1][-1]//2)

Measured memory_bytes: 42864
def x(n):
    if n == 1:
        return 0
    elif n % 2 == 0:
        return x(n/2) + 1
    else:
        return x(n*3 + 1) + 1

while True:
    n = int(input())
    if n == 0:
        break
    print(x(n))


Measured memory_bytes: 5612
#include <iostream>
using std::cout;
using std::endl;
using std::cin;

void swap(int &a, int &b)
{
    int temp = a;
    a = b;
    b = temp;
}

int main()
{
    int a, b, c;
    
    while (cin >> a >> b >> c) {
        if (a > b) {
            swap(a, b);
        }
        if (a > c) {
            swap(a, c);
        }
        if (b > c) {
            swap(b, c);
        }
        cout << a << " " << b << " " << c << endl;
    }


    return 0;
}


Measured memory_bytes: 3056
#include <stdio.h>

int main(void)
{
	int a, b, c; 
	
	scanf("%d %d %d", &a, &b, &c);
	
	int i;
	int count = 0;
	
	for(i = a; i <= b; i++){
		if(c % i == 0){
		count += 1;
		}
	}
	
	printf("%d\n",count);
	
	return 0;
}

Measured memory_bytes: 2720