akhauriyash/Code-Regression huggingface dataset:
<?php
list($h,$w)=explode(" ",trim(fgets(STDIN)));
$ans=0;
$i=0;
if($h==1){
  $a=explode(" ",trim(fgets(STDIN)));
  while($i<$w-1){
    if($a[$i]%2==1){
      ++$ans;
      ++$a[$i+1];
      $b[]="1 ".($i+1)." 1 ".($i+2);
    }
    ++$i;
  }
  echo $ans . PHP_EOL;
  echo join("\n",$b);
}elseif($w==1){
  $r=0;
  while($i<$h-1){
    $a=trim(fgets(STDIN))+$r;
    $r=0;
    if($a%2==1){
      ++$ans;
      ++$r;
      $b[]=($i+1)." 1 ".($i+2)." 1";
    }
    ++$i;
  }
  echo $ans . PHP_EOL;
  echo join("\n",$b);
}else{
  while($i<$h){
    $a[$i]=explode(" ",trim(fgets(STDIN)));
    ++$i;
  }
  $i=0;
  while($i<$h-1){
    $j=0;
    while($j<$w){
      if($a[$i][$j]%2==1){
      ++$ans;
      ++$a[$i+1][$j];
      $b[]=($i+1)." ".($j+1)." ".($i+2)." ".($j+1);
      }
      ++$j;
    }
    ++$i;
  }
  $j=0;
  while($j<$w-1){
    if($a[$i][$j]%2==1){
      ++$ans;
      ++$a[$i][$j+1];
      $b[]=($i+1)." ".($j+1)." ".($i+1)." ".($j+2);
    }
    ++$j;
  }
  echo $ans . PHP_EOL;
  echo join("\n",$b);
}

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;
typedef tuple<long long, long long, long long> tllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
bool compTuple(const tllint& arg1, const tllint& arg2) { return get<2>(arg1) > get<2>(arg2); }
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

    vector<llint> s(a+2);
    vector<llint> t(b+2);
    s[0] = -1e18;
    s[a+1] = 1e18;
    t[0] = -1e18;
    t[b+1] = 1e18;

    for(llint ia=0;ia<a;++ia) cin >> s[ia+1];
    for(llint ib=0;ib<b;++ib) cin >> t[ib+1];

    llint x, ans;
    for(llint iq=0;iq<q;++iq) {
        ans = 1e18;
        cin >> x;

        auto sb = upper_bound(s.begin(), s.end(), x);
        auto sa = sb - 1;
        auto tb = upper_bound(t.begin(), t.end(), x);
        auto ta = tb - 1;
        chmin(ans, abs(x-*ta)+abs(*ta-*sa));
        chmin(ans, abs(x-*sa)+abs(*ta-*sa));
        chmin(ans, abs(x-*tb)+abs(*tb-*sa));
        chmin(ans, abs(x-*sa)+abs(*tb-*sa));
        chmin(ans, abs(x-*ta)+abs(*ta-*sb));
        chmin(ans, abs(x-*sb)+abs(*ta-*sb));
        chmin(ans, abs(x-*tb)+abs(*tb-*sb));
        chmin(ans, abs(x-*sb)+abs(*tb-*sb));
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 4812
#include<bits/stdc++.h>
using namespace std;
struct Tree {
    int count;
    vector<int> nodeColor;
    map<pair<int, int>, int> edgesColor;
    vector<vector<int> > to;
    vector<pair<int, int> > edges;

    explicit Tree(int n) {
        nodeColor.resize(n + 1, -1);
        to.resize(n + 1);
        count = 0;
    }

    void connect(int a, int b) {
        to[a].emplace_back(b);
        to[b].emplace_back(a);
        edges.emplace_back(max(a, b), min(a, b));
    }

    void bfs(int root) {
        nodeColor[root] = 0;
        queue<int> current;
        current.push(root);
        while (!current.empty()) {
            int a = current.front();
            int color = 0;
            for (const auto b : to[a]) {
                if (nodeColor[b] == -1) {
                    ++color;
                    if (color == nodeColor[a]) ++color;
                    nodeColor[b] = color;
                    edgesColor[{max(a, b), min(a, b)}] = color;
                    current.push(b);
                }
            }
            count = max(count, color);
            current.pop();
        }
    }
};
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    auto tree = Tree(N);
    for (int i = 0; i < N-1; ++i) {
        int a, b;
        cin >> a >> b;
        tree.connect(a, b);
    }
    tree.bfs(1);
    printf("%d\n", tree.count);
    for (const auto & edge : tree.edges) {
        printf("%d\n", tree.edgesColor[edge]);
    }
    return 0;
}


Measured memory_bytes: 13432
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;

/*sortの仕方
 * ■ string s の場合
 * 昇順: sort(s.begin(), s.end())
 * 降順:  sort(s.rbegin(), s.rend())
 *
 * ■ int a[N] の場合
 * 昇順: sort(a, a+N)
 * 降順: 不明
 */

int alph2int(char character) {
    int x = character - 'a';
    return x;
}


int main(){
    int N;
    cin >> N;

    int n = (N-1)/111;
    cout << (n+1)*111 << endl;
}

Measured memory_bytes: 256
/*Shivam Bhalla */
/* f2016941@pilani.bits-pilani.ac.in */



#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <algorithm>
#include <map>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iostream>
#include <string>
#include <cmath>
#include <cassert>
#include <bits/stdc++.h>
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;
long long maxv = 1e9;


int main() {
  int N;
  cin>>N;
  int k;
  cin>>k;
  vector<long long>arr(N);
  for(int i=0;i<N;i++)
    cin>>arr[i];
  sort(arr.begin(),arr.end());
  int maxi=INT_MAX;
  for(int i=0;i<N;i++){
    if(i+k-1<N && arr[i+k-1]-arr[i]<maxi)
      maxi=arr[i+k-1]-arr[i];
  }
  cout<<maxi;
  return 0;
}


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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Tapris = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

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

  int n, m;
  cin >> n >> m;
  vint x(n);
  vint cnt(m);
  map<int, int> mp;
  vector<vint> g(m);
  rep(i, n) {
    cin >> x[i];
    ++cnt[x[i]%m];
    ++mp[x[i]];
    g[x[i]%m].push_back(x[i]);
  }
  rep(i, m) {
    sort(all(g[i]));
    g[i].erase(unique(all(g[i])), g[i].end());
  }
  int ans = 0;
  ans += cnt[0]/2;
  if(m%2 == 0) ans += cnt[m/2]/2;
  reps(i, 1, (m+1)/2) {
    int a = i, b = m-i;
    if(cnt[a] < cnt[b]) swap(a, b);
    //cout<<a<<" "<<b<<" "<<cnt[a]<<" "<<cnt[b]<<endl;
    rep(j, g[a].size()) {
      if(cnt[a] == cnt[b]) break;
      int x = min(mp[g[a][j]]/2, (cnt[a]-cnt[b])/2);
      ans += x;
      cnt[a] -= x*2;
    }
    ans += cnt[b];
  }
  cout << ans << endl;

  return 0;
}


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


def answer():
    N = int(input())
    coordinates = [list(map(int, input().split())) for _ in range(N)]

    def distance(c1, c2):
        square_x = (c1[0] - c2[0]) ** 2
        square_y = (c1[1] - c2[1]) ** 2
        return (square_x + square_y) ** (1/2)

    total = [0] * N
    for i in range(N):
        for j in range(N):
            if i == j:
                continue
            total[i] += distance(coordinates[i], coordinates[j])

    print(sum(total)/N)


if __name__ == '__main__':
    answer()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
      int c=0;
    string n;
    cin>>n;
    for(int i=0;i<6;i++)
    {
          if((n[2]==n[3])and(n[4]==n[5]))
            c=1;
          
    }
    if(c==1)
      cout<<"Yes"<<endl;
    else
      cout<<"No"<<endl;
      return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<unordered_map>
#include<set>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 6;
const ll MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<int, int>
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
/* -- template -- */

int main() {
    int N, A, B; cin >> N >> A >> B;
    if((B - A) % 2) {
        cout << "Borys" << endl;
    }else {
        cout << "Alice" << endl;
    }
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	int L=1,R=N;
	FOR(i,M) {
		cin>>x>>y;
		L=max(L,x);
		R=min(R,y);
	}
	
	if(R<L) cout<<0<<endl;
	else cout<<(R-L+1)<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<cmath>


using namespace std;

#define rep(i,N) for(int i=0;i<N;i++) //0から
#define REP(i,N) for(int j=i;j<N;j++) //iから

typedef long long ll;




ll binary_search(vector<ll> a, ll n, ll key){
    ll right = n, left = -1;
    ll md = (right + left) / 2;

    while(right - left > 1){
        if(a[md] <= key){
            right = md;
        }else{
            left = md;
        }
        md = (right + left) / 2;
    }
    if(left == -1) return -1; //無い場合
    return right;
}

vector<ll> prime;
void Prime(ll n){ //線形篩,素数列挙
    vector<ll> p(n,0);
    p[0]=1;
    p[1]=1;
    for(ll i=2;i<n;i++){
        if(p[i]==0){
            prime.push_back(i);
            p[i]=i;
        }
        ll k=prime.size();
        for(ll j=0;j<k && i*prime[j]<n && prime[j]<=p[i];j++){
            p[i*prime[j]]=prime[j];
        }
    }
}

#define MOD ((ll)1e+9 + 7)




//cout<<fixed<<setprecision(10);
int main(){
    int n,m;
    cin>>n>>m;
    vector<int> L(m),R(m+1);
    rep(i,m){
        cin>>L[i]>>R[i];
        L[i]--;
    }
    vector<int> cnt(n+1,0);
    rep(i,m){
        cnt[L[i]]++;
        cnt[R[i]]--;
    }
    rep(i,n){
        cnt[i+1]+=cnt[i];
    }
    int ans=0;
    rep(i,n){
        if(cnt[i]==m){
            ans++;
        }
    }
    cout<<ans<<endl;

    return 0;
}



Measured memory_bytes: 4260
#include <stdio.h>
#include <vector>
#include <iostream>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;


int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n, k, q;
    cin >> n >> k >> q;
    
    vi a(n+1);
    for (int i=0;i<q;i++) {
        int tmp;
        cin >> tmp;
        a[tmp-1]++;
    }

    for (int i=0;i<n;i++) {
        if (k - (q - a[i]) > 0){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}


Measured memory_bytes: 1024
/**********************************************************************************

https://atcoder.jp/contests/abc144/tasks/abc144_c

for(int i=1; i*i<= n; i++) Eta use korle hobe na;

sqrt of n er closest divisor ber kora lagbe

so use: for(int i=sqrt(1.0*n); i>=1; i--)

*************************************************************************************/

#include<bits/stdc++.h>

using namespace std;

/*****************MACRO*****/

#define input freopen("in.txt","r",stdin)
#define output freopen("out.txt","w",stdout)

#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define min4(a,b,c,d) min(min(a,b),min(c,d))
#define max4(a,b,c,d) max(max(a,b),max(c,d))
#define count_one(a) __builtin_popcount(a)  // Returns the number of set bits(1) in a number(a). In long long use __builtin_popcountll(a)
#define parity(i)   __builtin_parity(i)  //even parity 0 and odd parity 1
#define blz(a)   __builtin_clz(a) //Returns the number of leading zeroes in a number(a)
#define btz(a)   __builtin_ctz(a) //Returns the number of trailing zeroes in a number(a)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define int long long
#define ll long long
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

/*******CONSTANT***********/
#define INF (1<<30) //infinity value
#define EPS 1e-9
#define MOD 10000007
#define SIZ 1005
#define PI (acos(-1))



void solve()
{
    int n;
    cin>>n;

    for(int i=sqrt(1.0*n); i>=1; i--)
    {
        if(n%i==0){
            ///then lowest a peye gesi where a*b= n
            int a= i;
            int b= n/i;
            ///cout<<"a="<<a<<" b="<<b<<"\n";
            cout<<a+b-2<<"\n";
            break;

        }
    }
}











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

    int tc,cn;
    tc=1;

    ///cin>>tc;

    for(cn=1;cn<=tc;cn++)
    {

        solve();

    }

    return 0;
}


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

int main(){
	string s;
	cin >> s;
	vector<bool> al(26);
	rep(i, 26) al.at(i) = false;

	rep(i, s.size()){
		al.at(s.at(i)-'a') = true;
	}

	rep(i, 26){
		if(!al.at(i)){
			cout << (char)(i+'a') << endl;
			return 0;
		}
	}
	cout << "None" << endl;
}


Measured memory_bytes: 512
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


# --------------------------------------------

dp = None


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def lcm(n, m):
    return (n * m) // gcd(n, m)


def main():
    N = int(input())
    T = [int(input()) for _ in range(N)]

    ans = 1

    for i in range(N):
        ans = lcm(ans, T[i])

    print(ans)


main()


Measured memory_bytes: 4688
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define fr(i,n,m) for(ll i=n;i<m;i++)
int main()
{
    ll n, k;
    scanf("%lli %lli",&n, &k);
    ll c=0,ch=0;
    fr(i,1,n+1){
        if (i%k == 0) {
            c++;
        }
    }
    fr(i,1,n+1){
        if (i%k == k/2 && k%2 == 0) {
            ch++;
        }
    }
    ll ansc = c*(c-1)*(c-2)+3*c*(c-1)+c;
    ll ansch = ch*(ch-1)*(ch-2)+3*ch*(ch-1)+ch;
    ll ans = ansc+ansch;
    printf("%lli",ans);
    return 0;
}

Measured memory_bytes: 1692
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <stack>
#define Endl endl
#define mp make_pair
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define over(A) {cout<<A<<endl;exit(0);}
#define all(A) A.begin(),A.end()
#define ceil(a,b) ((a-1)/b+1)
#define srand() mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rand(l,r) uniform_int_distribution<int>(l,r)(rng)
typedef unsigned long long ull;
const int inf=1039074182;
using namespace std;

ll n;
ll a,b,c,aa,bb,cc;

ll tradeBy2(ll n,ll a,ll b)
{
//	cout<<n<<" "<<a<<" "<<b<<endl;
	if(a<b)
	{
		return n/a*b+n%a;
	}
	else
	{
		return n/b*a+n%b;
	}
}

ll _(ll n,ll b,ll bb,ll c,ll cc)
{
//	cout<<n<<endl;
	ll ans=0;
	for(int i=0; i<=n; i++)
	{
		ll val=i/bb*b+i%bb+(n-i)/cc*c+(n-i)%cc;
		ans=max(ans,val);
	}
	return ans;
}

int main()
{
	cin>>n>>a>>b>>c>>aa>>bb>>cc;
	bool fa=(a<aa);
	bool fb=(b<bb);
	bool fc=(c<cc);
	int cnt=fa+fb+fc;
	if(cnt==3 || cnt==0)
	{
		ll aaa=0;
		for(int i=0;i<n+1;i++)
		{
			for(int j=0;j<n-i+1;j++)
			{
				ll val=tradeBy2(i,a,aa)+tradeBy2(j,b,bb)+tradeBy2(n-i-j,c,cc);
				aaa=max(aaa,val);
			}
		}
		cout<<aaa<<endl;
		return 0;
	}
	if(cnt==2)
	{
		ll ans=0;
		for(int i=0;i<n+1;i++)
		{
			for(int j=0;j<n-i+1;j++)
			{
				ll val=0;
				if(fa && fb)
				{
					val=tradeBy2(i,a,aa)+tradeBy2(j,b,bb)+n-i-j;
					ans=max(ans,max(val,val/cc*c+val%cc));
				}
				if(fb && fc)
				{
					val=tradeBy2(i,b,bb)+tradeBy2(j,c,cc)+n-i-j;
					ans=max(ans,max(val,val/aa*a+val%aa));
				}
				if(fa && fc)
				{
					val=tradeBy2(i,a,aa)+tradeBy2(j,c,cc)+n-i-j;
					ans=max(ans,max(val,val/bb*b+val%bb));
				}
			}
		}
		cout<<ans<<endl;
		return 0;
	}
	if(cnt==1)
	{
//		return 1;
		ll ans=0;
		if(fa)
		{
			n=n/a*aa+n%a;
			ans=_(n,b,bb,c,cc);

		}
		if(fb)
		{
			n=n/b*bb+n%b;
			ans=_(n,a,aa,c,cc);
		}
		if(fc)
		{
			n=n/c*cc+n%c;
			ans=_(n,a,aa,b,bb);
		}
		cout<<ans<<endl;
		return 0;
	}
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main(){
  int a, b;
  cin >> a >> b;
  if(a>=13)
    cout << b << endl;
  else if(a<=12 && a>=6)
    cout << b/2 << endl;
  else if(a<=5)
    cout << 0 << endl;
}

Measured memory_bytes: 256
n = int(input())
t, a = list(map(int, input().split()))
hs = list(map(int, input().split()))

min_diff = 9999999999999
ans = -1

for i in range(0, n):
    tmp = abs(a - (t - hs[i] * 0.006))
    if tmp < min_diff:
        min_diff = tmp
        ans = i + 1
print(ans)

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

using namespace std;

#define reps(i, n, m) for (int i = (int) (n); i < (int) (m); i++)
#define rep(i, n) reps(i, 0, (n))
#define ALL(v) (v).begin(), (v).end()

int main() {
    bitset<64> a(0);
    vector<bitset<64>> m;
    int n; cin >> n;
    rep(i, n) {
        bitset<64> t(0);
		int k; cin >> k;
		while (k--) {
			int tt; cin >> tt;
			t.set(tt);
		}
        m.push_back(t);
    }
    int Q; cin >> Q;
    while (Q--) {
        int q; cin >> q;
        if (q == 0) {
            int i; cin >> i;
            cout << a.test(i) << endl;
        } else if (q == 1) {
            int i; cin >> i;
            a |= m[i];
        } else if (q == 2) {
            int i; cin >> i;
            a &= ~m[i];
        } else if (q == 3) {
            int i; cin >> i;
            a ^= m[i];
        } else if (q == 4) {
            int i; cin >> i;
            cout << ((a & m[i]) == m[i]) << endl;
        } else if (q == 5) {
            int i; cin >> i;
            cout << (a & m[i]).any() << endl;
        } else if (q == 6) {
            int i; cin >> i;
            cout << (a & m[i]).none() << endl;
        } else if (q == 7) {
            int i; cin >> i;
            cout << (a & m[i]).count() << endl;
        } else if (q == 8) {
            int i; cin >> i;
            cout << (a & m[i]).to_ulong() << endl;
        }
    }
    
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
#define bit(n,k) ((n>>k)&1) //*n no k bit me 1 or 0*/

const int mx=100010;
const ll mod=1e9+7;

int main(){
  int k;
  cin >> k;
  queue<ll> q;
  REP(i,1,10) q.push(i);
  queue<ll> p=q;
  queue<ll> r;
  REP(i,1,10){
  while(!p.empty()){  
    ll tmp = p.front(); p.pop();
    ll num = tmp%10;
    if(num!=0){ q.push(tmp*10+num-1); r.push(tmp*10+num-1);}
                q.push(tmp*10+num);   r.push(tmp*10+num);
    if(num!=9){ q.push(tmp*10+num+1); r.push(tmp*10+num+1);}
  }
  swap(p,r);
  }

  vector<ll> a;
  while(!q.empty()){
    ll tmp = q.front(); q.pop();
    a.emplace_back(tmp);
  }
  sort(a.begin(),a.end());

  ll ans = a[k-1];
  cout << ans << endl;
  return 0;
}

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

int main()
{
	int n;
	cin>>n;
	int a,k=1;
	bool flag=false;
	for(int i=0;i<n;i++){
		cin>>a;
		if(a==1)flag=true;
		if(a==k)k++;
	}
	if(!flag)cout<<"-1\n";
	else cout<<n-k+1<<"\n";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(int i = 0; i < (int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }

void solve()
{
    int a, b; cin >> a >> b;
    string s = "";
    string t = "";
    for(int i = 0; i < b; i++)
    {
        s += a + '0';
    }
    for(int i = 0; i < a; i++)
    {
        t += b + '0';
    }
    if(s < t) cout << s << endl;
    else cout << t << endl;
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

Measured memory_bytes: 256
h;w;f(y){y=w/3;return w%3-1|y<h?fmax(h/2,y)+y+1:h+y;}main(){scanf("%d%d",&h,&w);printf("%.f",h%3&&w%3?fmin(fmin(h%2?h:h/2,w%2?w:w/2),fmin(f(),(h^=w^=h^=w,f()))):0);}

Measured memory_bytes: 128
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll LINF = 1e18;
 
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"[";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"]";return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&p)
{o<<"{"<<p.first<<", "<<p.second<<"}";return o;}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj)
{o<<"{";for(auto itr=obj.begin();itr!=obj.end();++itr)o<<(itr!=obj.begin()?", ":"")<<*itr;o<<"}";return o;}
 
int main()
{
	ll n,s;
	cin >> n;
	cin >> s;
	ll k = sqrt(n);
	for(ll i=2; i<=k; i++){
		ll t = n;
		ll sum = 0;
		while(t > 0){
			sum += t % i;
			t /= i;
		}
		if(s == sum){
			cout << i << endl;
			return 0;
		}
	}
 
	for(ll i=k; i>0; i--){
		ll d = s - i;
		ll b = (n-d)/i;
		if(d >= 0 && (n-d)%i == 0 && i < b && d < b ){
			cout << b << endl;
			return 0;
		}
	}
	cout << (n==s ? n+1 : -1) << endl;
	return 0;
}

Measured memory_bytes: 256
/*
このコード、と～おれ!
Be accepted!
  ∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

//保留所有权利。
#include<iostream>
#include<stdio.h>//printするよ
#include<vector>
#include<algorithm>//辞書順はnext_permutationだよ
#include<set>
#include<string>
#include<sstream>
#include<string.h>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swapで数値交換するよ
//END OF LIBRARIES.
#define rt "\n"//改行を最速化させるよ
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(s,n) rep(i,n)cin>>s[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())
#define reve(s) reverse(s.begin(),s.end())
#define asas int ans=0
#define llcncn llint cnt=0
#define llasas llint ans=0
#define cncn int cnt=0
#define smsm int sum=0
#define str srting
#define v vector
#define please return
#define AC 0//おまじないだよ
#define Rapid cin.tie(0);ios::sync_with_stdio(false)
//END OF DEFINE.
using namespace std;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;
//printf("%02d:%02d:%02d\n", h, m, s);・・・2文字は埋める・h、m、ｓ
//END OF TYPEDEF.

//最大公約数（GCD）を求めるよ
//最小公倍数（LCM）は＜＜　A × B ÷ GCD　 ＞＞で求まるよ

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}
long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}
unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}
/*
  for A以上B未満でI探索 for (int I = A; i <= B; i++)

  string s = to_string(i);　iをstringでsに変換

  char　小文字のほうが32大--------------------大文字と小文字の境=93

  大文字→小文字 文字列のn文字目を大文字で出力→ (char)toupper(a[0])

  int i = sqrt (n) で、ｎの平方根(9に対する3)をiに入れる

  pow(a,b) → aのb乗を求める

  s1.erase(n) 文字列s1の、n文字目以降削除
  */
int a=0, b=0, c = 0;
string s = "";

int main(void) {
	//vector,set,map,stack,queue,deque,priority_queue

	int n, k;
	cin >> n >> k;
	int cnt = 0;
	while (true) {
		n /= k;
		if (n != 0)cnt++;
		if (n == 0) {
			cnt++;
			break;
		}
	}
	cout << cnt << rt;

	please AC;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(long long (i)=0;(i)<(n);(i)++)
#define ll long long
#define pr_qu priority_queue
#define vec(name,size,common) vector<ll> (name)((size),(common))
 
 
 
 
 
int main(){

  string s;
  cin>>s;

  vector<ll> a(s.size(),0);

char m;
ll mc,co=0;
  for(ll i=0;i<s.size();i++){
    if(i==0){
      m=s.at(i);
      mc=i;
      co++;
    }else{
      if(m!=s.at(i)){
        if(s.at(i)=='R'){
          a.at(mc)=co;
          co=1;
          m=s.at(i);
        }else{
          a.at(i-1)=co;
          co=1;
          m=s.at(i);
          mc = i;
        }
      }else{
        co++;
      }
    }
    if(i==(s.size()-1)){
        a.at(mc)=co;
    }
  }


ll l=0,r=0,d;
    for(ll i=1;i<s.size();i++){
      l=0;r=0;
      if(d==i){
        continue;
      }else{
      if(a.at(i-1)!=0){
        l += a.at(i-1) - (a.at(i-1)/2);
        l += a.at(i)/2;
        r += a.at(i-1)/2;
        r += a.at(i) - (a.at(i)/2);
        a.at(i-1) = l;
        a.at(i) = r;
        d = i+1;
      }
    }
    }

    for(ll i=0;i<s.size();i++){
      cout<<a.at(i)<<" ";
    }
    
}

Measured memory_bytes: 1408
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

long calc(int[] xs) {
    long sum = 0;
    long[long] d = [0: 1];
    foreach (x; xs) {
        sum += x;
        d[sum]++;
    }

    return d.values.map!(e => e * (e - 1) / 2).sum;
}

void main() {
    readint;
    auto xs = readints;
    writeln(calc(xs));
}


Measured memory_bytes: 26636
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "


// CHECK THE LIMITS
typedef long long ll;

const int MOD = 1000000007;
const ll INFLL = 1e18;
const int INF = 1e9;
const int NMAX = 1000001;

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

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string s1,s2;
    cin >> s1 >> s2;
    int n,m;
    cin >> n >> m;
    string s3;
    cin >> s3;
    if(s3==s1)
      n--;
    else
      m--;
    cout << n << " " << m;


    return 0;
}

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

int main(void){
  int N;
  cin >> N;
  
  string dollarN = "No";
  
  for (int a = 0; a <= 25; a++){
    for (int b = 0; b <= 15; b++ ) {
      int total = 4 * a + 7 * b;
      if (total == N){
        dollarN = "Yes";
        break;
      }
    }
  }
  
  
  cout << dollarN << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ull, ull> UP;
typedef tuple<int, int, int> T;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int gcd(int a, int b) {
	if (a < b)swap(a, b);
	int k = a % b;
	if (k == 1)return 1;
	if (k == 0)return b;
	int ans = gcd(b, k);
	return ans;
}
int digisum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}

ll s[1001];

int main() {
	int a, b;
	cin >> a >> b;
	cout << (b - a) * (b - a + 1) / 2 - b << endl;
}



Measured memory_bytes: 256
#!/usr/bin/env python3
#ABC119 B

n = int(input())

bit = 0
jpy = 0

for i in range(n):
    x,u = input().split()
    if u == 'JPY':
        jpy += float(x)
    elif u == 'BTC':
        bit += float(x)
print(jpy + 380000*bit)


Measured memory_bytes: 38384
input()
vs=list(map(int, input().split(" ")))
k = 0
for i in range(0, len(vs)-1):
	if vs[i] - vs[i+1] >= 2:
		k = 100
		break
	if vs[i] - vs[i+1] == 1:
		k += 1
		if k >= 2:
			break
	elif vs[i+1] - vs[i] >= 1:
		k = 0
if k > 1:
	print("No")
else:
	print("Yes")


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

#ifdef LOCAL
#define debug(var) cerr << #var << " = " << var << endl;
#else
#define debug(var)
#endif

void init() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

const int N = 1e5+23;

int n, a, b; 
int h[N];

bool check(long long t) {
	int c = t;
	for (int i = 0; i < n; ++i) {
		if (h[i]-t*b <= 0) break;
		c -= (h[i]-t*b+(a-b-1))/(a-b);
		if (c < 0) return false;
	}
	return true;
}

void solve() {
	scanf("%d%d%d", &n, &a, &b);
	for (int i = 0; i < n; ++i) {
		scanf("%d", h+i);
	}
	sort(h, h+n, greater<int>());
	int lo = 0, hi = 1e9+1;
	while (lo+1 < hi) {
		int mid = (lo+hi)/2;
		if (check(mid)) hi = mid;
		else lo = mid;
	}
	printf("%d", hi);
}

int main() {
	init();
	int t = 1; //scanf("%d", &t);
	while (t--) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
#include<stdlib.h>
#define NIL NULL

struct node{
  struct node *right;
    struct node*left;
    struct node *parent;
  int key;
};
  typedef struct node *Node;

Node root;

void insert(int k)
{
  Node y = NIL;
  Node x = root;
  Node z;


  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while( x != NIL )
    {
      y = x;
      if( z->key < x->key )
	{
	  x = x->left;
	}
      else
	{
	  x = x->right;
	}

    }
  z->parent = y;
  if( y == NIL )
    {
      root = z;
    }
  else
    {
      if( z->key < y->key )
	{
	  y->left = z;
	}
      else
	{
	  y->right = z;
	}
    }
}


void inoder(Node u)
{
  if( u != NIL )
    { 
  inoder(u->left);
  printf(" %d",u->key);
  inoder(u->right);
    }
}

void preoder(Node u)
{
  if( u!= NIL )
    {
  printf(" %d", u->key);
  preoder(u->left);
  preoder(u->right);
    }
}
    
    
Node treeSearch(Node u, int k){
  if(u==NIL || k==u->key)
    {
      return u;
    }
  if(k<u->key)
    {
      return treeSearch(u->left,k);
    }
  else return  treeSearch(u->right,k);
}
    
  



int main()
{
  char com[20];
  int n,x,i;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%s",com);
      if ( com[0] == 'f' )
	{
	  scanf("%d", &x);
	  Node t = treeSearch(root, x);
	  if ( t != NIL ) printf("yes\n");
	  else printf("no\n");
	}
      else if( com[0]=='i')
	{
	  scanf("%d",&x);
	  insert(x);
	}
      else if( com[0]=='p')
	{
	  inoder(root);
	  printf("\n");
	  preoder(root);
	  printf("\n");
	}
    }
  return 0;
}












	



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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t,n,a,b;
	t = 1;
	while(t--) {
	 cin >> n >> a >> b;
	 if(abs(n - a) <= abs(n - b))
	  cout << 'A' << endl;
	 else
	  cout << 'B' << endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <queue>
#include <string>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int> ;
using vl = vector<ll>;

ll dp[2010][701];

int main(){
    rep(i,2010){
        rep(j,700){
            dp[i][j] = 0;
        }
    }
    ll mod = 1e9+7;
    ll s;
    dp[3][0] = 1;

    cin >> s;
    reps(i,4,2010){
        rep(j,700){
            dp[i][j] = dp[i-1][j];
            if(i >= 3 && j >= 1){
                dp[i][j] = (dp[i][j] + dp[i-3][j-1]) % mod;
            }
        }
    }


    ll ans = 0;
    rep(i,700){
        ans = (ans+dp[s][i]) % mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 14624
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod = 998244353;

ll r(ll x, ll y) {
  if (y == 0) return 1;
  else if (y % 2 == 0) return r(x, y/2) * r(x, y/2) % mod;
  else return x * r(x, (y-1)/2) % mod * r(x, (y-1)/2) % mod;
}

int main() {
  int k;
  string s;
  cin >> k >> s;
  int n = s.size();
  for (int i = 0; i < min(k, n); i++) {
    cout <<s[i];
  }
  if (n > k) cout <<"...";
  cout <<endl;
}

Measured memory_bytes: 3632
S = input()
N = [0 for i in range(len(S))]
#R
r = 0
for i, s in enumerate(S):
  if s == "R":
    r += 1
  else:
    N[i] += r // 2
    N[i-1] += r // 2 + r % 2
    r = 0
#L
l = 0
for i, s in enumerate(S[::-1]):
  if s == "L":
    l += 1
  else:
    N[-(i+1)] += l // 2
    N[-i] += l // 2 + l % 2
    l = 0
print(" ".join(list(map(str, N))))

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

ans, delta_ans = 0, 0
l, r = 0, 0
xor_sum, plus_sum = A[0], A[0]

while True:
    if xor_sum == plus_sum:
        delta_ans += 1
        ans += delta_ans
        if r == N-1:
            break
        else:
            r += 1
        xor_sum ^= A[r]
        plus_sum += A[r] 
    else:
        delta_ans -= 1
        xor_sum ^= A[l]
        plus_sum -= A[l]
        l += 1

print(ans)
	


Measured memory_bytes: 25684
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int n;
void dfs(string s,int cnt,char c){
  if(cnt==n){
    cout << s << endl;
    return;
  }
  for(char i='a';i<=c+1;i++){
    dfs(s+i,cnt+1,max(c,i));
  }
}
int main(){
  cin >> n;
  dfs("a",1,'a');
}


Measured memory_bytes: 1536
ans = ''
N = int(input())
if N % 2 == 0:
	ans = '0' + ans
else:
	ans = '1' + ans
	N -= 1
 
t = -2
 
while N != 0:
	if N - t == 0:
		ans = '1' + ans
		break
	if N % (abs(t) * 2) == 0:
		ans = '0' + ans
	else:
		ans = '1' + ans
		N -= t
	t *= -2
 
print(ans)

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

#define PI 3.14159265358979323846264338327950L

int main(void){
  int a,b,h,m;
  scanf("%d%d%d%d",&a,&b,&h,&m);
  
  long double rad = PI * 2 * ((long double) h / 12.0 + ((long double)m /60.0) / 12.0 - (long double)m/60.0);
  long double rsq = (long double)(a*a+b*b) -(long double)(2*a*b)*cosl(rad);
  printf("%20.20Lf\n",sqrtl(rsq));
  return 0;
}

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

int main(){
  int N, A[100], v, j, k;
  
  cin >> N;
  for ( int i = 0; i < N; i++ ){
    cin >> A[i];
    cout << A[i];
    if ( i != N-1 ) cout << " ";
    else cout << "\n";
  }

  for ( int i = 1; i < N; i++ ){
    v = A[i];
    j = i - 1;
    while ( j >= 0 && A[j] > v ){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;

    for ( k = 0; k < N; k++ ){
      cout << A[k];
      if ( k != N-1 ) cout << " ";
      else cout << "\n";
    }
  }

  return 0;
}


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


int main() {
	std::string str = "", res = "";
	std::getline(std::cin, str);

	int i = 0, c = 0;
	while (1) {
		if (str[i] == ',' || str[i] == '.' || str[i] == ' ') {
			if(3 <= c && c <= 6)
				res += str.substr(i - c, c) + " ";

			c = 0;
		} else {
			c++;
		}

		if (str[i] == '\0')
			break;

		i++;
	}

	std::cout << res.substr(0, res.size() - 1) << std::endl;

	return 0;
}

Measured memory_bytes: 3040
N,M,X = map(int,input().split())
CA = []
for i in range(N):
    CA.append(list(map(int,input().split())))
xx = []    
ans = []
for i in range(2**N):
    ans.append(((bin(i))[2:]).zfill(N))
tmp = [0]*(M+1)
cost = []
for a in ans:
    for i in range(N):
        if a[i] == '0':
            for j in range(M+1):
                tmp[j] += CA[i][j]
    xx.append(tmp)
    tmp = [0]*(M+1)
aa = 0
for L in xx:
    for i in range(1,M+1):
        if L[i] >= X:
            aa += 1
    if aa == M:
        cost.append(L[0])
    aa = 0

if len(cost) == 0:
    print('-1')
else:
    print(min(cost))

Measured memory_bytes: 11668
score_hash, s = {}, []
while line = gets
  _p, _s = line.split(',').map(&:to_i)
  break if _p.zero? && _s.zero?

  s << _s
  score_hash[_p] = _s
end

s.sort_by! { |_s| -_s }.uniq!

while q = gets
  puts s.index(score_hash[q.to_i]) + 1
end

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

double dp[3005][3005];  // dp[i][j] i枚目まで見てj枚が表の確率

int main() {
    int n;
    double p[3005];
    cin >> n;
    REP(i,n) cin >> p[i];
    dp[0][0] = 1.0;
    REP(i,n){
        REP(j,n+1){
            dp[i+1][j] = dp[i][j]*(1-p[i]) + dp[i][j-1]*p[i];
        }
    }
    double ans = 0;
    for(int i=n/2+1;i<=n;i++){
        ans += dp[n][i];
    }
    printf("%.12lf\n",ans);
    return 0;
}


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  int R = a+b;
  int L = c+d;

  if (R > L){
    cout << "Left" << endl;
  } else if (R == L){
    cout << "Balanced" << endl;
  } else if (R < L){
    cout << "Right" << endl;
  }
}

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  long long dp[2][n][16];
  for (int i = 0; i < 16; i++) {
    dp[0][n - 1][i] = i;
    dp[1][n - 1][i] = i;
  }

  for (int i = 0; i < 2; i++) {
    for (int j = n - 2; j >= 0; j--) {
      int j1 = 0;
      int j2 = 0;
      long long c1 = a[j];
      long long c2 = a[j + 1];
      while (c1 <= c2 && j1 < 16) {
        dp[i][j][j1] = dp[i][j + 1][0] + j1;
        c1 *= 4;
        j1++;
      }
      while (j2 < 16 && c2 < c1) {
        c2 *= 4;
        j2++;
      }
      while (j1 < 16) {
        if (j2 > 15) {
          dp[i][j][j1] = dp[i][j + 1][15] + (j2 - 15) * (n - 1 - j) + j1;
        }
        else {
          dp[i][j][j1] = dp[i][j + 1][j2] + j1;
        }
        j1++;
        j2++;
      }
    }
    reverse(a, a + n);
  }

  long long ans = 2 * dp[0][0][0];
  for (int i = 1; i < n; i++) {
    long long steps = dp[0][i][0] * 2 + dp[1][n - i][0] * 2 + i;
    ans = min(ans, steps);
  }
  cout << ans;
}


Measured memory_bytes: 51072
<?php

$n = trim(fgets(STDIN));
$k = trim(fgets(STDIN));
$x = explode(' ', trim(fgets(STDIN)));

$s = 0;
for($i=0; $i<$n; $i++){
  $a = abs(0-$x[$i]);
  $b = abs($k-$x[$i]);
  $s += min($a,$b)*2;
}

echo $s;
  
?>

Measured memory_bytes: 4604
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner  scan=new Scanner(System.in);
         int x;
        for(int i=1; i<=10000; i++){
             x=scan.nextInt();
             if(x==0)
                 break;
            System.out.println("Case "+ i+": "+x);
        }
         
    }
 
}


Measured memory_bytes: 42768
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
using namespace std;
#define INF 110000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,int> P;

int main(){
  ll count=0;
  int K,S;
  cin>>K>>S;

  for(int i=0;i<=K;i++){
    for(int j=0;j<=K;j++){
      if(S-i-j<=K && S-i-j>=0) count++;
    }
  }
  cout<<count<<endl;
}


Measured memory_bytes: 256
A, B, C, D = map(int, input().split())

c = C
d = D

gcd = 0
while gcd == 0:
  if c > d:
    k = c
    c = d
    d = k # 必ず c <= d になる
  if d%c == 0:
    gcd = c
  else:
    d = d%c

# 最小公倍数（lcm）
lcm = int(C*D/gcd)

wareru = B//C + B//D - B//lcm - (A-1)//C - (A-1)//D + (A-1)//lcm
ans = B-A+1-wareru
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll N, K;
  cin>>N>>K;
  int A[N];
  for(int i=0;i<N;++i) {
    cin>>A[i];
    A[i]--;
  }
  map<int, int> amap;
  int now = 0;
  int dist, cycle, point;
  int ans=-1;
  for(int i=1;i<=K;++i) {
    if(amap[now]>0) {
      point = now;
      dist = amap[now]-1;
      cycle = i-dist-1;
      break;
    }
    amap[now] = i;
    now = A[now];
    if(i==K) ans = now;
  }
  if(ans>-1) {
    cout<<ans+1<<endl;
    return 0;
  }
  K -= dist;
  K %= cycle;
  now = point;
  for(int i=0;i<K;++i) {
    now = A[now];
  }
  ans = now;
  cout<<ans+1<<endl;
}



Measured memory_bytes: 11892
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first.first
#define yy first.second
#define __V vector
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define oit ostream_iterator
#define mod 1000000007ll
using namespace __gnu_pbds;
using namespace std;
void doin() {
	cin.tie();
	cout.tie();
	ios::sync_with_stdio(0);
#ifdef LOCALc
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
template<typename T, typename l>
void getv(T& a, int n, l f) {
	a.resize(n);
	for (auto& i : a)
		cin >> i, f(i);
}
template<typename T>
void getv(T& a, int n) {
	a.resize(n);
	for (auto& i : a)
		cin >> i;
}
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef int _I;
typedef pair<_I, _I> pi;
typedef pair<ld, ld> pd;
typedef map<_I, _I> mii;
typedef __V <_I> vi;
typedef __V <char> vc;
typedef __V <ld> vd;
typedef __V <vd> vvd;
typedef __V <pi> vpi;
typedef __V <__V<_I>> vvi;
typedef __V <__V<char>> vvc;
typedef __V <__V<pi>> vvpi;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n;
pair<string, int> a[10000];
vi v;
int main() {
	doin();
	cin >> n;
	v.resize(n);
	for(int i = 0; i < n; i++) v[i] = i;
	for(int i = 0; i < n; i++) cin >> a[i].first >> a[i].second;
	sort(all(v), [a](const int& i,const  int& j) {
		return a[i].first < a[j].first || (a[i].first == a[j].first && a[i].second > a[j].second);
	});
	for(auto i : v) cout << i+1 << "\n";
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<stdlib.h>
#include<queue>
#include<map>
#include<vector>
#include<cmath>
#include<fstream>
#include <set>
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
const int  MAXN =1e5+10;
const long long  mod = 1e14 ;
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int inf= 0x3f3f3f3f;
#define eps 1e-8
#define PI 3.1415926535898
#define lowbit(x) (x&(-x))
using namespace std ;
//getline(cin,s);
//set<ll>::iterator it;
//map<int,int>::iterator it;
typedef long long ll;
unsigned long long  a[MAXN];
int main()
{
	int n,flag=1;unsigned long long  ans=1000000000000000000;
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%llu",&a[i]);
	sort(a+1,a+1+n);
    if(a[1]==0)
    {
    	printf("0\n");
    	return 0;
	}
	for(int i=2;i<=n;i++)
	{
		if(ans/a[i-1]<a[i])
		{
			flag=0;
			break;
		}
		a[i]*=a[i-1];
	}
	if(flag)
	{
		printf("%llu\n",a[n]);
	} 
	else printf("-1\n");
	return 0;
}

Measured memory_bytes: 4536
//
//  main.cpp
//  CoderTest
//
//  Created by yuya on 2019/07/25.
//  Copyright © 2019 yuya. All rights reserved.
//

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;


int main()
{
    
    string S,T;
    cin >> S >> T;
    
    int flag = 0;
    for(int i=0;i<S.size();i++)
    {
        for(int j=0;j<S.size();j++)
        {
            if( S[j] != T[(i+j) % S.size()] )
            {
//                cout << i << " " << j << " " << S[i] << " " << T[(i+j) % S.size()] << endl;
                break;
            }
            if( j == S.size() - 1)
            {
                flag = 1;
                break;
            }
        }
        if(flag == 1) break;
    }
    
    if(flag == 1) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}


Measured memory_bytes: 256
//
//  atcoder.cpp
//
//
///
#include <bits/stdc++.h>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
#include <boost/multi_array.hpp>
#include <boost/math/common_factor.hpp>
#include <boost/algorithm/string.hpp>

#define REP(i, N) for(int i=0; i<(N); i++)
#define REC(f, ...) (void)0; const auto f = [&](const auto f, __VA_ARGS__)
using namespace std;
using namespace boost::math;

using ll = long long;
namespace bst = boost;
template<typename T> class in {
    T value;
public:
    in() { cin >> value; }
    operator const T&() const { return value; }
    operator T&() { return value; }
    in& operator=(T source) { value = source; return *this; }
};
template<> class in<string> : public string {
public:
    in() { cin >> *this; }
};
template<class T> class inseq : public T {
public:
    template<typename... Arg> inseq(Arg... arg) : T(forward<Arg>(arg)...) { for (auto&& i : *this) cin >> i; }
};
template<class T> using invec = inseq<vector<T>>;

auto solve() {
  in<int> A, B;


  return (B >= A ? "unsafe" : "safe");
}

template<typename T> void plot(const T& func) { cout << func() << endl; }
template<> void plot<void()>(void(&func)()) { func(); }
template<> void plot<double()>(double(&func)()) { cout << setprecision(9) << func() << endl; }

int main() {
  plot(solve);

  return 0;
}


Measured memory_bytes: 3624