akhauriyash/Code-Regression huggingface dataset:
# -coding: utf-8 -

a,b = input().split()

s = a+b
s = int(s)


l =[0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 441, 484, 529, 576, 625, 676, 729, 784, 841, 900, 961, 1024, 1089, 1156, 1225, 1296, 1369, 1444, 1521, 1600, 1681, 1764, 1849, 1936, 2025, 2116, 2209, 2304, 2401, 2500, 2601, 2704, 2809, 2916, 3025, 3136, 3249, 3364, 3481, 3600, 3721, 3844, 3969, 4096, 4225, 4356, 4489, 4624, 4761, 4900, 5041, 5184, 5329, 5476, 5625, 5776, 5929, 6084, 6241, 6400, 6561, 6724, 6889, 7056, 7225, 7396, 7569, 7744, 7921, 8100, 8281, 8464, 8649, 8836, 9025, 9216, 9409, 9604, 9801, 10000, 10201, 10404, 10609, 10816, 11025, 11236, 11449, 11664, 11881, 12100, 12321, 12544, 12769, 12996, 13225, 13456, 13689, 13924, 14161, 14400, 14641, 14884, 15129, 15376, 15625, 15876, 16129, 16384, 16641, 16900, 17161, 17424, 17689, 17956, 18225, 18496, 18769, 19044, 19321, 19600, 19881, 20164, 20449, 20736, 21025, 21316, 21609, 21904, 22201, 22500, 22801, 23104, 23409, 23716, 24025, 24336, 24649, 24964, 25281, 25600, 25921, 26244, 26569, 26896, 27225, 27556, 27889, 28224, 28561, 28900, 29241, 29584, 29929, 30276, 30625, 30976, 31329, 31684, 32041, 32400, 32761, 33124, 33489, 33856, 34225, 34596, 34969, 35344, 35721, 36100, 36481, 36864, 37249, 37636, 38025, 38416, 38809, 39204, 39601, 40000, 40401, 40804, 41209, 41616, 42025, 42436, 42849, 43264, 43681, 44100, 44521, 44944, 45369, 45796, 46225, 46656, 47089, 47524, 47961, 48400, 48841, 49284, 49729, 50176, 50625, 51076, 51529, 51984, 52441, 52900, 53361, 53824, 54289, 54756, 55225, 55696, 56169, 56644, 57121, 57600, 58081, 58564, 59049, 59536, 60025, 60516, 61009, 61504, 62001, 62500, 63001, 63504, 64009, 64516, 65025, 65536, 66049, 66564, 67081, 67600, 68121, 68644, 69169, 69696, 70225, 70756, 71289, 71824, 72361, 72900, 73441, 73984, 74529, 75076, 75625, 76176, 76729, 77284, 77841, 78400, 78961, 79524, 80089, 80656, 81225, 81796, 82369, 82944, 83521, 84100, 84681, 85264, 85849, 86436, 87025, 87616, 88209, 88804, 89401, 90000, 90601, 91204, 91809, 92416, 93025, 93636, 94249, 94864, 95481, 96100, 96721, 97344, 97969, 98596, 99225, 99856]


if s in l:
    print("Yes")
else:
    print("No")
"""

l = []
for i in range(1005):
    temp = i**2
    if temp <= 100100:
        l.append(temp)
    
        
k = list(set(l))

k = sorted(k)

print(k)


"""


Measured memory_bytes: 3192
q, h, s, d = map(int, input().split())
n = int(input())
h = min(q*2, h)
s = min(min(q*4, h*2), s)
d = min(min(min(q*8, h*4), s*2), d)
ans = 0
ans += n // 2 * d
ans += n % 2 * s
print(ans)


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

int main()
{
    int n=0 ;
    int i=0 ,j=0 ;
    int cmp=0 ;
    int taro_p=0 ,hanako_p=0 ;

    char taro[101] = {0} ;
    char hanako[101] = {0} ;
    char mem[101] = {0} ;

    scanf("%d",&n) ;

    for (i=0 ;i < n ;i++)
    {
        cmp=0 ;
        memset(taro ,0 ,sizeof taro) ;
        memset(hanako ,0 ,sizeof hanako) ;
        memset(mem ,0 ,sizeof mem) ;

        scanf("%s %s",taro ,hanako) ;

        if (strlen(taro) == strlen(hanako))
        {
            cmp=strcmp(taro ,hanako) ;
        }
        else
        {
            if (strlen(taro) > strlen(hanako))
            {
                strncpy(mem ,taro ,strlen(hanako)) ;
                cmp=strcmp(mem ,hanako) ;

                if (cmp==0) cmp++ ;

            }
            else
            {
                if (strlen(taro) < strlen(hanako))
                {
                strncpy(mem ,hanako ,strlen(taro)) ;
                cmp=strcmp(taro ,mem) ;

                if (cmp==0) cmp-- ;

                }
            }
        }

        if (cmp==0)
        {
            taro_p += 1 ;
            hanako_p += 1 ;
        }
        else if (cmp > 0)
        {
            taro_p += 3 ;
        }
        else if (cmp < 0)
        {
            hanako_p += 3 ;
        }

    }
    printf("%d %d\n",taro_p ,hanako_p) ;

    return 0;
}

Measured memory_bytes: 616
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S, T;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

int main() {
    cin>>N>>M;
    vec c(N, -1);
    rep(i,M){
        cin>>A>>B;
        --A;
        if((c[A] != B && c[A] != -1) || (B == 0 && A == 0 && N != 1)){
            cout<<-1<<endl;
            return 0;
        }
        c[A] = B;
    }
    rep(i,N) {
        if(c[i] == -1) c[i] = (i == 0 && N != 1);
        cout<<c[i];
    }
    cout<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define Ans(f, y, n) if(f) cout << y << endl; else cout << n << endl;
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i, v.size()){ cout << v[i] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

template<typename T> void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }

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

int mod = 1000000007;
//int mod = 998244353;
#define Add(x, y) x = (x + (y)) % mod
#define Mult(x, y) x = (x * (y)) % mod
#define AddMult(x, y, z) x = (x + (y) * (z)) % mod



signed main(){

    int L; cin >> L;
    string s, t; cin >> s >> t;

    bools dp(L + 1, false);
    dp[L] = true;
    int n = SZ(s), m = SZ(t);
    IREP(i, L + 1) if(dp[i]){
        if(i - n >= 0) dp[i - n] = true;
        if(i - m >= 0) dp[i - m] = true;
    }

    string a1 = "", a2 = "";
    while(SZ(a1) < L){
        if(SZ(a1) + n <= L && dp[SZ(a1) + n]) a1 += s;
        else a1 += t;
    }
    while(SZ(a2) < L){
        if(SZ(a2) + m <= L && dp[SZ(a2) + m]) a2 += t;
        else a2 += s;
    }
    //debug(a1);
    //debug(a2);
    cout << min(a1, a2) << endl;

    return 0;
}


Measured memory_bytes: 1428
def _run(n, ss):
    result = {}
    for s in ss:
        result.setdefault(s, []).append(1)
    for key in ["AC", "WA", "TLE", "RE"]:
        print("{} x {}".format(key, len(result.get(key, []))))


def _main():
    n = int(input())
    ss = [str(input()) for i in range(n)]

    _run(n, ss)


if __name__ == "__main__":
    _main()


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

using namespace std;
int A[100005];
int main(){
    int n;cin >> n;
    for(int i=1;i<=n;++i)
        scanf("%d",&A[i]);
    int st=0;
    int ans=1;
    for(int i=2;i<=n;++i){
        if(st==0){
            if(A[i]>A[i-1]){
                st=1;
            }
            else if(A[i]<A[i-1]){
                st=2;
            }
        }
        else if(st==1){
            if(A[i]<A[i-1]){
                st=0;
                ++ans;
            }

        }
        else{
            if(A[i]>A[i-1]){
                st=0;++ans;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main(){

    int n;
    cin >> n;
    int h[n];
    for(int i=0;i<n;i++){
        cin >> h[i];//0~n-1
    }

    int goukei = 0;

    for(int i=0;i<n;i++){

        int max;
        max = h[0];

        if(i==0){
            goukei++;
        }
        else{
            for(int j=0;j<=i-1;j++){
                if(max<h[j]){
                    max = h[j];
                }
            }
            //cout << "max=" << max << " ";
            if(max<=h[i]){
                goukei++;
            }
        }
        //cout << goukei << " ";

    }

    cout << goukei << endl;


    return 0;
}

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

void init( char** a, int n ) {
  short i, j;

  for( i=0; i<n; i++ ) {
    for( j=0; j<n; j++ ) {
      a[i][j] = 0;
    }
  }

  return;
}

void print( char** a, int n ) {
  short i, j;

  for( i=0; i<n; i++ ) {
    for( j=0; j<(n-1); j++ ) {
      printf( "%d ", a[i][j] );
    }
    printf( "%d\n", a[i][j] );
  }

  return;
}



main() {

  int i, j;
  int n, u, k, v;
  char** a;

  scanf( "%d", &n );
  a = (char**)malloc( sizeof( char* ) * n );
  for( i=0; i<n; i++ ) {
    a[i] = (char*)malloc( sizeof( char ) * n );
  }
  
  init( a, n );
  
  for( i=0; i<n; i++ ) {
    scanf( "%d%d", &u, &k );
    
    for( j=0; j<k; j++ ) {
      scanf( "%d", &v );
      a[u-1][v-1] = 1;
    }
    
  }
  
  print( a, n );
  
  for( i=0; i<n; i++ ) {
    free( a[i] );
  }
  free( a );
  
  return 0;

} 
  

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

using namespace std;

typedef long long int64;

int main()
{
  int N, A[100001] = {};

  cin >> N;
  ++N;
  for(int i = 1; i < N; i++) cin >> A[i];

  vector< int > rev(N);
  iota(begin(rev), end(rev), 0);
  sort(begin(rev), end(rev), [&](const int &a, const int &b)
  {
    if(A[a] == A[b]) return (a < b);
    return (A[a] < A[b]);
  });
  reverse(begin(rev), end(rev));


  vector< int64 > ans(N, 0);
  int64 connect = 0;
  int sq = rev[0];
  for(int i = 0; i + 1 < N; i++) {
    int next_sa = A[rev[i]] - A[rev[i + 1]];
    ans[sq] += ++connect * next_sa;
    sq = min(sq, rev[i + 1]);
  }
  for(int i = 1; i < N; i++) {
    cout << ans[i] << endl;
  }

}

Measured memory_bytes: 2688
#include <algorithm>
#include <bits/stdc++.h>
#include<iostream>
#include<string>
using namespace std;
#define rep(i, n) for (int i = 0; i <(int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
const ll MOD=100000007;
const ll INF=1000000101001;
int main(){
    ll a,b,k;cin>>a>>b>>k;
    if(a>=k)cout<<a-k<<" "<<b<<endl;
    if(a<k&&k<=a+b)cout<<0<<" "<<b-(k-a)<<endl;
    if(a+b<k)cout<<0<<" "<<0<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define ii int
#define jmp cout<<"\n"
#define vl vector<ll>
#define pb push_back
#define printv(v) for(auto x:v) cout<<x<<" "; jmp;
#define endll "\n"
#define SORT(v) sort(v.begin(),v.end())
#define REV(x)  reverse(x.begin(),x.end())
#define ff first
#define ss second
#define iin insert
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;
ll knapSack(ll W, ll wt[], ll val[], ll n)
{
	ll dp[n + 1][W + 1];
	for (ll i = 0; i <= n; i++)
		dp[i][0] = 0;
	for (ll j = 0; j <= W; j++)
		dp[0][j] = 0;
	// if(n==0||W==0)
	// return 0;
	// if(wt[n-1]>W)
	// return knapSack(W,wt,val,n-1);
	// else
	// return max(knapSack(W,wt,val,n-1),val[n-1]+knapSack(W-wt[n-1],wt,val,n-1));
	for (ll i = 1; i <= n; i++)
	{
		for (ll j = 1; j <= W; j++)
		{
			if (wt[i - 1] > j)
				dp[i][j] = dp[i - 1][j];
			else
				dp[i][j] = max(dp[i - 1][j], val[i - 1] + dp[i - 1][j - wt[i - 1]]);
		}
	}
	return dp[n][W];

}
void solve()
{
	ll n, W;
	cin >> n >> W;
	ll w[n], val[n];
	for (ll i = 0; i < n; i++)
		cin >> w[i] >> val[i];
	cout << knapSack(W, w, val, n);

}
int main()
{
fast;
	// ll t;
	// cin >> t;
	// while (t--)
	solve();
	return 0;
}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int INF=10000000;
const int mod=1e9+7;
typedef struct node
{
    char name[105];
    int t;
}P;
P Q[100005];
int he,ta,n,ant,q,cnt;
void enqueue(P x)
{
    Q[ta]=x;
    ta=(ta+1)%100005;
}
P dequeue()
{
    P x=Q[he];
    he=(he+1)%100005;
    return x;
}
int main()
{
    P u;
    scanf("%d %d",&n,&q);
    for(int i=1;i<=n;i++)
    {
        scanf("%s %d",Q[i].name,&Q[i].t);
    }
    he=1;
    ta=n+1;
    while(he!=ta)
    {
        u=dequeue();
        cnt=min(q,u.t);
        u.t-=cnt;
        ant+=cnt;
        if(u.t>0)
            enqueue(u);
        else
            printf("%s %d\n",u.name,ant);
    }
    return 0;
}



Measured memory_bytes: 14096
#define _USE_MATH_DEFINES
#include <cmath>
#include <vector>
#include <iostream>
#include <string>

#define deg_to_rad(deg) (deg / 360) * (2 * M_PI)
#define rad_to_deg(rad) rad / (2 * M_PI) * 360

using namespace std;

int main() {
  double a, b, x, n, k, theta;
  cin >> a >> b >> x;
  n = x / a;
  
  double border = a * b / 2;
  
  if (n > border) {
    k = (n * 2 / a) - b;
    theta = rad_to_deg(atan2(a, b - k));
    printf("%.10f\n", 90 - theta);
    return 0;
  }
  
  k = n * 2 / b;
  theta = rad_to_deg(atan2(b, k));
  printf("%.10f\n", theta);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
int poww(int a,int b)
{
	int s=1;
	for(int i=0;i<b;i++)
		s=s*a;
	return s;
}
int main()
{
	int n,x;
	cin>>n;
	if(n<4)x=1;
	else{
		int m=1;
		for(int i=2;i<=n;i++){
			int t;
			for(int j=2;;j++){
				t=poww(i,j);
				if(t>n){
					if(j>2){
						t=poww(i,(j-1));
						m=max(m,t);
					}
					break;
				}
			}
		}
		x=m;
	}
	cout<<x<<endl;
	return 0;
}

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

int main(void){

  int N;
  scanf("%d", &N);

  if(N==1){
    printf("Hello World\n");
    return 0;
  }

  int A,B;
  scanf("%d", &A);
  scanf("%d", &B);

  int ans=A+B;

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

  return 0;
}



Measured memory_bytes: 128
from math import factorial

N, M, K = map(int, input().split())
mod = 10 ** 9 + 7

def Comb(N, K):
    a = factorial(N) % mod
    b = factorial(K) % mod
    c = factorial(N-K) % mod
    return (a * pow(b, mod-2, mod) * pow(c, mod-2, mod)) % mod


c = Comb(N*M-2, K-2)

ans = 0

for d in range(M):
    ans += d * (M - d) * (N ** 2)
    ans %= mod

for d in range(N):
    ans += d * (N - d) * (M ** 2)
    ans %= mod

ans *= c
ans %= mod

print(ans)

Measured memory_bytes: 72924
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
long long x,y;
int main()
{
	scanf("%lld",&x);
	y=x/500;
	y*=500;
	x-=y;
	y*=2;
	y+=x/5*5;
	printf("%lld\n",y);
	return 0;
}

Measured memory_bytes: 256
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//背反な事象にちゃんとわける
//チェックリストはマップを使う
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//例外処理は最初にする
//x = p^m + q^n...の約数の個数:(n+1)*(m+1)....
//N!のどの素因数で何回割れるか
//⇔1~Nまでの数がそれぞれどの素因数で何回割り切れるかの和
//パズルの問題->一般化して全探索
//数が大きい時のせぐふぉはコードテストで試してみる
//stack<ll> s;
//s.push(要素);s.top();s.pop();
//queue<ll> q;
//q.push(要素);q.front();q.pop();
//同じ作業繰り返す系の問題：収束先を見つける
//関係性は隣接行列で記録
//過半数：N/2.0で判定
//ある量からある量を引く系の問題：端から定義してやる
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

//円周率
const double PI = 3.14159265358979323846;
//割るやつ
const ll MOD = (pow(10, 9) + 7);

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

//a,bの最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//階乗計算
ll f(ll n) {
	if (n == 0 || n == 1) return 1;
	else return (n * f(n - 1));
}

//Nのd桁目の数
ll dignum(ll N, ll d) {
	ll x = pow(10, d);
	N %= x;
	ll y = pow(10, d - 1);
	N /= y;
	return N;
}

//Nをdで何回割れるか
ll divcnt(ll N, ll d) {
	ll ans = 0;
	while (1) {
		if (N%d == 0) {
			ans++;
			N /= d;
		}
		else break;
	}

	return ans;
}

//素数判定
bool prime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2) {
		if (num % i == 0) return false;
	}
	return true;
}

//フィボナッチ数列
vector<ll> memo(pow(10, 6) + 1);
ll fibo(ll n) {
	if (n == 1) return 1;
	else if (n == 2) return 1;
	else if (memo[n] != 0) return memo[n];
	else return memo[n] = fibo(n - 1) + f(n - 2);
}

int main() {
	ll A, B, C; cin >> A >> B >> C;

	if (A < C &&C < B)cout << "Yes" << endl;
	else if (B < C && C < A)cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
int main(void){
    double n;
    while (cin>>n) {
        if (n<=48.00) {
            cout<<"light fly"<<endl;
        } else if (n>48.00 && n<=51.00){
            cout << "fly" << endl;
        } else if (n>51.00 && n<=54.00) {
            cout << "bantam" << endl;
        } else if (n>54.00 && n<=57.00) {
            cout << "feather" << endl;
        } else if (n>57.00 && n<=60.00) {
            cout << "light" << endl;
        } else if (n>60.00 && n<=64.00) {
            cout << "light welter" << endl;
        } else if (n>64.00 && n<=69.00) {
            cout << "welter" << endl;
        } else if (n>69.00 && n<=75.00) {
            cout << "light middle" << endl;
        } else if (n>75.00 && n<=81.00) {
            cout << "middle" << endl;
        } else if (n>81.00 && n<=91.00) {
            cout << "light heavy" << endl;
        } else if (n>91.00) {
            cout << "heavy" << endl;
        }
    }
}



Measured memory_bytes: 3176
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <cmath>

using namespace std;

typedef unsigned long long ull;

vector<int> T;

struct State{
  int cost, state;
  State(int _cost, int _state){
    cost = _cost;
    state = _state;
  }
  bool const operator < (State s) const{
    return s.cost < cost;
  }
};

set<int> S;
int cx, cy;
int s, g ;

string toString(int n){
  string ret = "";
  while(n){
    ret += (n % 10) + '0';
    n /= 10;
  }
  reverse(ret.begin(), ret.end());
  return ret;
}
int dijkstra(){
  int dx[] = {-1, 1, -3, 3};
  int cost[] = {cx, cx, cy, cy};
  
  priority_queue<State> que;
  que.push(State(0, s));
  
  while(!que.empty()){
    State q = que.top(); que.pop();
    if(q.state == g) return q.cost;
    
    if(S.find(q.state) != S.end()) continue;
    S.insert(q.state);
    
    int zero;
    int tmp = q.state;
    for(int i = 8 ; i >= 0 ; i--){
      if(tmp % 10 == 0){
	zero = i;
	break;
      }
      tmp /= 10;
    }
    
    for(int i = 0 ; i < 4 ; i++){
      int pos = zero + dx[i];
      
      if(pos < 0) pos += 9;
      if(pos >= 9) pos -= 9;
      int vv = q.state;
      vv /= T[pos];
      vv %= 10;
      
      int v = q.state;
      v -= T[pos] * vv;
      v += T[zero] * vv;
      
      que.push(State(q.cost + cost[i], v));
    }

  }
  
}

int main(){
  for(int i = 1 ; i <= 100000000 ; i *= 10){
    T.push_back(i);
  }
  reverse(T.begin(), T.end());

  while(cin >> cx >> cy, cx | cy){
    S.clear();
    s = g = 0;
    int v;
    for(int i = 0 ; i < 9 ; i++){
      cin >> v;
      s *= 10;
      s += v;
    }
    for(int i = 0 ; i < 9 ; i++){
      cin >> v;
      g *= 10;
      g += v;
    }
    
    cout << dijkstra() << endl;
    
  }
  return 0;
}

Measured memory_bytes: 22136
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>
#include <bitset>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl

int main(){
  ll n;
  scanf("%lld",&n);
  ll a,count4=0,count2=0,odd=0;
  rep(i,n){
    scanf("%lld",&a);
    if(a%2){
      odd++;
    }else if(a%4==0){
      count4++;
    }else{
      count2++;
    }
  }

  if(odd==0){
    printf("Yes\n");
    return 0;
  }

  if(odd+(count2?1:0)<=count4+1){
    printf("Yes\n");
    return 0;
  }
  printf("No\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)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<char,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;

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

    int n, c, k;
    cin >> n >> c >> k;
    vector<int> t(n);
    rep(i, n){
        cin >> t[i];
    }
    sort(all(t));

    int t0 = t[0] + k;
    int cnt = 1, ans = 1;
    rep(i, n){
        if(t[i] > t0 || cnt > c){
            ans++;
            t0 = t[i] + k;
            cnt = 1;
        }
        cnt++;
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 640
package main

import "fmt"

func main() {
	var s, t string
	fmt.Scan(&s, &t)

	for i := 0; i < len(s); i++ {
		if s == t {
			fmt.Println("Yes")
			return
		}
		s = s[len(s)-1:] + s[0:len(s)-1]
	}
	fmt.Println("No")
}


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

int main(){
	int n;
	string s;
	cin >> n >> s;
	
	int tmp = 0;
	int ans = 0;
	for(int i = 0; i < n; i++){
		if(s[i] == 'I') tmp++;
		else tmp--;
		ans = max(tmp, ans);
	}
	
	cout << ans << endl;
}

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

int kodakumi(int a) {
  int r = 0;
  if (a < 2) return 0;
  for (int i = a; i != 1; i--) {
    r += (i-1);
  }
  return r;
}

int main() {
  // your code here...
  int n,m;
  scanf("%d %d", &n, &m);

  printf("%d\n", (kodakumi(n) + kodakumi(m)));
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
class Cube{
public:
  int id;
  Cube* upper;
  Cube* lower;
  Cube(int id){
    this->id = id;
    upper = NULL;
    lower = NULL;
  }
  Cube(const Cube &c){
    this->id = c.id;
    this->upper = c.upper;
    this->lower = c.lower;
  }
  bool operator == (const Cube &c) const{
    return id == c.id;
  }
};
 
bool isSatisfied(Cube &low, Cube &high){
  Cube* c = &low;
  while(1){
    if(*c == high) return true;
    if(c->upper == NULL) return false;
    c = c->upper;
  }
  /*
  Cube c = Cube(low);
  while(1){
    if(c == high) return true;
    if(c.upper == NULL) return false;
    c = Cube(*c.upper);
  }
  */
}
 
void putOff(Cube &off){
  Cube* c = &off;
  if(c->lower != NULL){
    c->lower->upper = NULL;
    c->lower = NULL;
  }
  while(c->upper != NULL){
    c = c->upper;
    c->lower->upper = NULL;
    c->lower = NULL;
  }
  /*
  Cube c = Cube(off);
  while(c.upper == NULL){
    c = Cube(*c.upper);
    (*c.lower).upper = NULL;
      c.lower = NULL;
  }
  */
}
 
void putOn(Cube &low, Cube &high){
  assert(high.upper == NULL);
  assert(high.lower == NULL);
  Cube *c = &low;
  while(c->upper != NULL){
    c = c->upper;
  }
  c->upper = &high;
  c->upper->lower = c;
 
}
 
int main(void){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int m;
  while(cin >> m, m){
    vector<Cube> cubes;
    for(int i = 0; i < m; i++){
      cubes.push_back(Cube(i+1));
    }
    int I, J;
    while(cin >> I >> J, I | J){
      if(J == 0){
        I--;
        if(cubes[I].lower == NULL) continue;
        putOff(cubes[I]);
        continue;
      }
      I--; J--;
      if(isSatisfied(cubes[J], cubes[I])) continue;
      putOff(cubes[I]);
      putOn(cubes[J], cubes[I]);
    }
    vector<int> ans;
    for(size_t i = 0; i < cubes.size(); i++){
      if(cubes[i].lower == NULL){
        int cnt = 1;
        Cube *c = &cubes[i];
        while(c->upper != NULL){
          cnt++;
          c = c->upper;
        }
      ans.push_back(cnt);
      }
    }
    sort(ans.begin(), ans.end());
    for(size_t i = 0; i < ans.size(); i++){
      cout << ans[i] << endl;
    }
    cout << "end" << endl;
  }
  return 0;
}

Measured memory_bytes: 1228
import java.util.Scanner;
public class Main {
    public static void main(String[] main){
        Scanner sc = new Scanner(System.in);
        int[] x = new int[5];
        int s = 0;
        for(int i = 0 ; i < 5 ; i++ ){
            x[i] = sc.nextInt();
            if(x[i] == 0){
                s = i + 1;
            }
        }
        System.out.println(s);
        sc.close();
    }
}

Measured memory_bytes: 35788
N=int(input())
cnt=[0,0,0,0]

for i in range(N):
	temp=input()
	if temp=="AC":
		cnt[0]+=1
	elif temp=="WA":
		cnt[1]+=1
	elif temp=="TLE":
		cnt[2]+=1
	else:
		cnt[3]+=1

print("AC x "+str(cnt[0]))
print("WA x "+str(cnt[1]))
print("TLE x "+str(cnt[2]))
print("RE x "+str(cnt[3]))

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

int main()
{
    int N;
    cin >> N;
    int a = 0;
    int count = 0;
    bool flag = true;
    for(int i=0; i<N; i++){
        cin >> a;
        if(i+1!=a){
            count += 1;
            if(count>2){
                cout << "NO" << endl;
                flag = false;
                break;
            }
        }
    }
    if(flag){
        cout << "YES" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define N 1000
#define max(a,b) ((a)>=(b)?(a):(b))

void lcs(char x[N+1], char y[N+1]){
  int c[N+1][N+1],m,n,i,j;
  m=strlen(x);
  n=strlen(y);

  for(i=0;i<=m;i++) c[i][0]=0;
  for(j=0;j<=n;j++) c[0][j]=0;
  
  for(i=1;i<=m;i++){
    for(j=1;j<=n;j++){
      if(x[i-1]==y[j-1]) c[i][j]=c[i-1][j-1]+1;
      else c[i][j]=max(c[i-1][j],c[i][j-1]);
    }
  }
  printf("%d\n",c[m][n]);
}

int main(){
  int n,i;
  char c1[N+1],c2[N+1];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s%s", c1,c2);
    lcs(c1,c2);
  }
  
  
  return 0;
}



Measured memory_bytes: 5768
import java.util.*;

public class Main {
public static void main(String args[]){

	Scanner sc = new Scanner(System.in);
	int d = sc.nextInt();
	int n = sc.nextInt();

	if (d <= 8 && n <= 8){
		System.out.println("Yay!");
	}else{
		System.out.println(":(");
	}

}

}

Measured memory_bytes: 22612
// Problem : D - Redistribution
// Contest : AtCoder - AtCoder Beginner Contest 178
// URL : https://atcoder.jp/contests/abc178/tasks/abc178_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long 	
int mod=1e9+7;
int po(int x,int y,int m)  { if (y==0) return 1; int t=po(x,y/2,m)%m; t=(t*t)%m; if (y&1) return (t*x)%m;	return t%m; }

unsigned long long power(unsigned long long x, 
                         int y, int p) 
{ 
    unsigned long long res = 1; // Initialize result 
  
    x = x % p; // Update x if it is more than or 
    // equal to p 
  
    while (y > 0) { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res * x) % p; 
  
        // y must be even now 
        y = y >> 1; // y = y/2 
        x = (x * x) % p; 
    } 
    return res; 
} 
  
// Returns n^(-1) mod p 
unsigned long long modInverse(unsigned long long n, int p) 
{ 
    return power(n, p - 2, p); 
} 
  
// Returns nCr % p using Fermat's little 
// theorem. 
unsigned long long nCrModPFermat(unsigned long long n, 
                                 int r, int p) 
{ 
    // Base case 
    if (r == 0) 
        return 1; 
  
    // Fill factorial array so that we 
    // can find all factorial of r, n 
    // and n-r 
    unsigned long long fac[n + 1]; 
    fac[0] = 1; 
    for (int i = 1; i <= n; i++) 
        fac[i] = (fac[i - 1] * i) % p; 
  
    return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; 
}

signed main() {

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

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0); 
	
	int s;
	cin>>s;
	int i=1;
	int n=s-1-2*i;
	int ans=0;
	while(n>=0 && s-3*i>=0){
		ans=(ans%mod+nCrModPFermat(n, s-3*i, mod))%mod; 
		++i;
		n=s-1-2*i;
	}
	cout<<ans<<endl;
	
	
   
   	
   
   	return 0;
}

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

using namespace std;

int N, K, a[200005];

int main () {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin >> N >> K;
  for (int i = 1; i <= N; i ++) {
    cin >> a[i];
    if (i  > K) {
      if (a[i] > a[i - K])
        cout << "Yes\n";
      else
        cout << "No\n";
    }
  }
  return 0;
}


Measured memory_bytes: 4420
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main(void) {
    int n,x;
    cin >> n >> x;
    vector<int> l;
    int ball=0;
    int res=1;
    rep(i,n){
        int tmp;
        cin >> tmp;
        ball += tmp;
        if(ball<=x)res++;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define sf(n) scanf("%d", &n)
#define pd(n) printf("%.12lf", n)
#define pf(n) printf("%d", n)
#define p() printf("\n")
#define ps() printf(" ")
#define ll long long
#define ull unsigned long long
#define MAX 1e9
const int mod = 1000 * 1000 * 1000 + 7;
#define ex 1e18
#define dbl 2e09
#define qu(q) queue<int> q
#define pqu(q) priority_queue<int> q
#define len(s) s.length()
#define sz(x) int(x.size())
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second
#define clr(x) x.clear()
#define LOG(x) std::cout << x << std::endl;
 
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = 3.14159265359;
 
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int a[105];

int main(){
   int n,m;
   cin>>n>>m;
   int sum=0;
   for(int i=0;i<n;++i){
      cin>>a[i];
      sum+=a[i];
   }
   sort(a,a+n);
   int cnt=0;
   for(int i=n-1;i>=0;--i){
      if(a[i]*(4*m)>=sum)
         cnt+=1;
   }
   cout<<(cnt>=m?"Yes":"No")<<endl;
   return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
#include <array>
#include <numeric>
#include <regex>
#include <bitset>
#include <deque>

using namespace std;
typedef long long ll;
typedef pair<int, int> p_ii;

const int INF = 1e9;
const double PI = acos(-1.0);
const ll MOD = 1e9 + 7;



int main() {
    ll x;
    cin>>x;
    ll res = x/11;
    if(x%11==0){
        res*=2;
    }else if(x%11>6){
        res++;
        res*=2;
    }else{
        res*=2;
        res++;
    }
    cout<<res<<endl;

    return 0;
}

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

int main(){
    int n;
    int k;
    int q;
    int *player;
    int number;
    cin >> n >> k >> q;
    player = new int[n];
    for(int i=0; i<n; i++){
        player[i] = k-q;
    }
    for(int i=0; i<q; i++){
        cin >> number;
        player[number-1]++;
    }
    for(int i=0; i<n; i++){
        if(player[i] > 0){
            cout << "Yes\n";
        }else{
            cout << "No\n";
        }
    }
    return 0;
}

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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
//#define MOD 1000000007
#define INF LLONG_MAX/2

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
void vin(Vi &v){REP(i,0,(v).size()) cin>>v[i];}
void vin(Vi &v,Vi &v2){REP(i,0,(v).size()) cin>>v[i]>>v2[i];}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
void accum(Vi &v){REP(i,1,(v).size()) v[i]+=v[i-1];}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}


void solve(long long r){
    cout<<r*r<<endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
signed main(){
    long long r;
    scanf("%lld",&r);
    solve(r);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define pb push_back
#define deb(x) cout<<#x<<" "<<x<<endl;
#define deb2(x, y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define deb3(x, y, z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
template<class T, class U> inline void add_self(T &a, U b){a += b;if (a >= mod) a -= mod;if (a < 0) a += mod;}
template<class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void max_self(T &x, U y) { if (y > x) x = y; }

template <typename T>void print(T v, bool show_index = false){int w = 2;if(show_index){for(int i=0; i<v.size(); i++)cout<<setw(w)<<i<<" ";cout<<endl;}for(auto i= v.begin(); i!=v.end(); i++)cout<<setw(w)<<*i<<" ";cout<<endl;}
template <typename T>void print_vv(T v){if(v.size()==0) {cout<<"Empty"<<endl; return;} int w = 3;cout<<setw(w)<<" ";for(int j=0; j<v[0].size(); j++)cout<<setw(w)<<j<<" ";cout<<endl;for(auto i= 0; i<v.size(); i++){cout<<i<<" {";for(auto j = 0; j!=v[i].size(); j++){cout<<setw(w)<<v[i][j]<<",";}cout<<"},"<<endl;}cout<<endl;}
template <class T, class U> void print_m(map<T,U> m, int w=3){if(m.empty()){cout<<"Empty"<<endl; return;}for(auto x: m)cout<<"("<<x.first<<": "<<x.second<<"),"<<endl;cout<<endl;}

int main(){
    string s;
    while(cin>>s){
        map<char, int> m;
        for(auto c: s)
            m[c]++;
        
        if(m['A']==3 || m['B']==3)
            cout<<"No"<<endl;
        else
        {
            cout<<"Yes"<<endl;
        }
        
    }
    return 0;
}

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

int main(){
  int h,w,m;
  cin>>h>>w>>m;
  map<int,int>x,y;
  set<P>se;
  rep(i,m){
    int h,w; cin>>h>>w;
    y[h]++; x[w]++;
    se.insert(P(h,w));
  }
  int mxx=0,mxy=0;
  for(auto&p:x)mxx=max(mxx,p.second);
  for(auto&p:y)mxy=max(mxy,p.second);
  vector<int>vx,vy;
  for(auto&p:x)if(p.second==mxx)vx.push_back(p.first);
  for(auto&p:y)if(p.second==mxy)vy.push_back(p.first);
  rep(i,vy.size())rep(j,vx.size()){
    if(se.find(P(vy[i],vx[j]))==se.end()){
      cout<<mxx+mxy<<endl;
      return 0;
    }
  }
  cout<<mxx+mxy-1<<endl;
}

Measured memory_bytes: 49524
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;

//
#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0, sizeof(x))
#define mm(x) memset((x), -1, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define bit(n) (1LL << (n))
#define bitset(a, b) (a) |= (1 << (b))
#define bitunset(a, b) (a) |= ~(1 << (b))
#define bitcheck(a, b) ((((a) >> (b)) & 1) == 1)
#define bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
const int INF = (int)1e18;
const int MOD = (int)1e9 + 7;
const double PI = (double)acos(-1);
const double EPS = (double)1e-10;
const int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

int N, M;
vec G[202020], ans[2];
bool vis[202020];

void dfs(int n, int num) {
  vis[n] = true;
  ans[num].pb(n);

  for (auto x : G[n]) {
    if (!vis[x]) {
      dfs(x, num);
      break;
    }
  }

  return;
}

signed main() {
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    G[a].pb(b);
    G[b].pb(a);
  }

  dfs(0, 0);
  dfs(0, 1);

  reverse(ALL(ans[0]));

  cout << ans[0].size() + ans[1].size() - 1 << endl;

  for (auto x : ans[0]) {
    cout << x + 1 << " ";
  }

  for (int i = 1; i < ans[1].size(); i++) {
    cout << ans[1][i] + 1;
    if (i != ans[1].size() - 1) cout << " ";
  }

  cout << endl;

  return 0;
}


Measured memory_bytes: 12532
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<typename T >inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }


void solve();

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

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
        solve();
    }
}

// 筆算で, その桁から取られてるか
int dp[1000005][2];

void solve() {
  string s;
  cin >> s;
  s = '0' + s;

  fill_n(*dp, 1000005 * 2, inf);
  dp[sz(s)][0] = 0;

  // k, 払うお金
  for (int i = sz(s) - 1; i >= 0; --i) rep(j, 2) rep(k, 10) {
    int x = s[i] - '0';
    int k2 = k;
    if (j) { if (k2 == 0) k2 = 9; else k2--; }

    // お釣り
    int r = k2 + (x > k2 ? 10 : 0) - x;
    
    chmin(dp[i][(j && k2 == 9) || x > k2], dp[i + 1][j] + r + k); // debuged, j && k2 == 9
  }
  cout << dp[0][0] << endl;
  // rep(i, sz(s)) { rep(j, 2) cout << dp[i][j] << " "; cout << endl; }
}


Measured memory_bytes: 9160
#include<bits/stdc++.h>
using namespace std;
typedef long long L;
int main()
{
  L n,ar[10],ans;
  scanf("%lld%lld%lld%lld%lld%lld",&n,&ar[0],&ar[1],&ar[2],&ar[3],&ar[4]);
  sort(ar,ar+5);
  ans=n/ar[0];
  if(n%ar[0])ans++;
  ans+=4;
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main () {
  int x,y,r,tmp;

  scanf("%d%d",&x,&y);

  if(x<y) {
    tmp=x;
    x=y;
    y=tmp;
  }

  r = x%y;

  while(r!=0) {
    x = y;
    y = r;
    r = x%y;
  }

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

  return 0;

}



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

typedef long long LL;

LL ans;
LL n, a, b;

int main()
{
    while(~scanf("%d%d%d", &n, &a, &b)){
        LL minx=a+b+(n-2)*a;
        LL maxx=a+b+(n-2)*b;
        ans=maxx-minx+1;
        if(a>b)ans=0;
        if(ans<0)ans=0;
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
void print() { cout << "\n"; }
template <class T> void print(const T &x) { cout << x << "\n"; }
template <class T, class... Args> void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
template <class T> void printVector(const vector<T> &v) {
    for(const T &x : v) {
        cout << x << " ";
    }
    cout << "\n";
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

using P = pair<int, int>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, q;
    cin >> n;
    vector<int> V(n), W(n);
    for(int i = 0; i < n; i++) {
        cin >> V[i] >> W[i];
    }
    int M = 1 << 10;
    vector<P> rec1[M];
    rec1[0].emplace_back(0, 0);
    rec1[0].emplace_back(W[0], V[0]);
    for(int i = 1; i < M; i++) {
        if(i >= n) {
            break;
        }
        vector<P> tmp;
        for(auto j : rec1[(i - 1) / 2]) {
            tmp.emplace_back(j.first, j.second);
            tmp.emplace_back(j.first + W[i], j.second + V[i]);
        }
        sort(ALL(tmp));
        int now = -1;
        for(auto j : tmp) {
            if(now < j.second) {
                rec1[i].emplace_back(j);
                now = j.second;
            }
        }
    }
    cin >> q;
    while(q--) {
        int v, L;
        cin >> v >> L;
        v--;
        vector<P> item;
        while(v >= M) {
            item.emplace_back(W[v], V[v]);
            v = (v - 1) / 2;
        }
        vector<P> rec2;
        int N = item.size();
        for(int bit = 0; bit < (1 << N); bit++) {
            int sumw = 0, sumv = 0;
            for(int i = 0; i < N; i++) {
                if(bit & (1 << i)) {
                    sumw += item[i].first;
                    sumv += item[i].second;
                }
            }
            rec2.emplace_back(sumw, sumv);
        }
        int ans = 0;
        for(auto j : rec2) {
            P p = P(L - j.first, INF);
            auto it = lower_bound(ALL(rec1[v]), p);
            if(it != rec1[v].begin()) {
                it--;
                chmax(ans, it->second + j.second);
            }
        }
        print(ans);
    }
}


Measured memory_bytes: 10896
fun main(args: Array<String>) {
    readLine()
    val sArray = readLine()
        ?.split(" ".toRegex())
        ?.map(String::toInt)
        ?.toIntArray()
        ?: intArrayOf()
    readLine()
    val tArray = readLine()
        ?.split(" ".toRegex())
        ?.map(String::toInt)
        ?.toIntArray()
        ?: intArrayOf()
    println(tArray.filter {sArray.bSearch(it) != -1}.count())
}

fun IntArray.bSearch(key: Int, left: Int, right: Int): Int {
    val mid = (left + right) / 2
    if (left == mid) {
        if (this[mid] == key) {
            return mid
        } else {
            return -1
        }
    }
    if (this[mid] == key) {
        return mid
    } else if (this[mid] < key) {
        return this.bSearch(key, mid + 1, right)
    } else {
        return this.bSearch(key, left, mid)
    }
}

fun IntArray.bSearch(key: Int): Int {
    return this.bSearch(key, 0, this.size)
}


Measured memory_bytes: 57444
//ΔAGC023B
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
typedef double DB;
const int N = 666;
char ch[N];
int a[N][N];
int main()
{
	int n,i,j,k,s=0,f;
	cin>>n;
	for(i=1;i<=n;i=i+1){
		cin>>ch;
		for(j=1;j<=n;j=j+1){
			a[i][j]=ch[j-1];
			a[i+n][j]=a[i][j];
			a[i][j+n]=a[i][j];
			a[i+n][j+n]=a[i][j];
		}
	}
	for(k=0;k<n;k=k+1){
		f=1;
		for(i=1;i<=n;i=i+1)
			for(j=1;j<=n;j=j+1)
				if(a[i][j+k]!=a[j][i+k])
					f=0;
		s+=f*n;
	}
	cout<<s;
	return 0;
}

Measured memory_bytes: 1792
delta = ((1, 0), (0, 1), (-1, 0), (0, -1))
def ds(here, field, count, lb, ub, min_count):
	if count == min_count:
		return min_count
	ans = min_count
	for dx, dy in delta:
		nx, ny = (here[0]+dx,here[1]+dy)
		neighbor = (nx, ny)
		while lb[0] <= nx <= ub[0] and lb[1] <= ny <= ub[1]:
			if field[ny][nx] == 1:
				if (nx, ny) != neighbor:
					field[ny][nx] = 0
					ans = ds((nx-dx,ny-dy),field, count+1, lb, ub, ans)
		    		field[ny][nx] = 1
				break
			if field[ny][nx] == 3:
				if count + 1 < ans:
					ans = count + 1
				break
			nx += dx
			ny += dy
	return ans
while 1:
	w, h = map(int,raw_input().split(" "))
	if w == h == 0: break
	board = [ map(int,raw_input().split(" ")) for _ in range(h)]
	for j in range(h):
		for i in range(w):
			if board[j][i] == 2:
				start = (i,j)
	result = ds(start, board, 0, (0,0), (w-1,h-1), 11)
	print result if result < 11 else -1

Measured memory_bytes: 4308