akhauriyash/Code-Regression huggingface dataset:
n, p = list(map(int, input().split()))
a = list(map(int, input().split()))

e = sum(x % 2 == 0 for x in a)
o = sum(x % 2 == 1 for x in a)

if n == 1:
    ans = int(a[0] % 2 == p)
elif p == 1 and o == 0:
    ans = 0
else:
    ans = max((2 ** o) // 2, 1) * 2 ** e

print(ans)


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

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int,int> pii;
typedef pair <ll,ll> pll;

#define si(a)           scanf("%d",&a)
#define sii(a,b)        scanf("%d %d",&a,&b)
#define siii(a,b,c)     scanf("%d %d %d",&a,&b,&c)

#define sl(a)           scanf("%lld",&a)
#define sll(a,b)        scanf("%lld %lld",&a,&b)
#define slll(a,b,c)     scanf("%lld %lld %lld",&a,&b,&c)

#define un(x)           x.erase(unique(all(x)), x.end())
#define xx              first
#define yy              second
#define pb              push_back
#define mp              make_pair
#define all(v)          v.begin(),v.end()
#define D(x)            cerr << #x " = " << x << '\n'
#define DBG             cerr << "Hi!" << '\n'

#define CLR(a)          memset(a,0,sizeof(a))
#define SET(a)          memset(a,-1,sizeof(a))

#define PI              acos(-1.0)

//inline int setBit(int n,int pos) { return n = n | (1 << pos); }
//inline int resetBit(int n,int pos) { return n = n & ~(1 << pos); }
//inline bool checkBit(int n,int pos) { return (bool)(n & (1 << pos)); }
//inline int countBit(ll n) { return __builtin_popcountll(n); }


//int fx[] = {+0, +0, +1, -1, -1, +1, -1, +1};
//int fy[] = {-1, +1, +0, +0, +1, +1, -1, -1}; //Four & Eight Direction

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

const int MAX = 300010;
const int INF = 0x3f3f3f3f;
//const double inf = 1.0/0.0;
//const int MOD = 1000000007;

int h[MAX];
int dp[MAX];
int n,k;

int call(int pos) {
    if(pos>=n) return 0;
    if(dp[pos]!=-1) return dp[pos];

    int ret = INF;

    for(int i=1;i<=k and pos+i<=n;i++) {
        ret = min( ret , abs(h[pos]-h[pos+i]) + call(pos+i) );
    }
    return dp[pos] = ret;
}


int main() {
//    freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    sii(n,k);
    
    for(int i=1;i<=n;i++) si(h[i]);
    
    SET(dp);
    printf("%d\n",call(1));
    
    return 0;
}



Measured memory_bytes: 6528
#include <iostream>
#include <algorithm>
#define MAX 200
using namespace std;

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

int main(void){

  int ml,mr,mu,md;
  int x[MAX];
  int y[MAX];
  int N;
  int p,q;

  while(1){

    ml = mr = mu = md = 0;

    for( int i = 0 ; i < MAX ; i++ ){       /*初期化*/
      x[i] = 0;
      y[i] = 0;
    }

    cin >> N;
    if( N == 0 )break;

    for( int i = 1 ; i < N ; i++ ){

      cin >> p >> q;

      x[i] = x[p] + dx[q];
      y[i] = y[p] + dy[q];

      mu = max( mu , y[i] );
      md = min( md , y[i] );
      mr = max( mr , x[i] );
      ml = min( ml , x[i] );

    }
    cout << mr - ml + 1 << " " << mu - md + 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
using namespace std;

void Show(int ary[], int n)
{
	for (int i = 0; i < n; i++)
	{
		if (i != 0) cout << " ";
		cout << ary[i];
	}

	cout << endl;
}

int* InsertionSort(int ary[], int n)
{
	for (int i = 1; i < n; i++)
	{
		Show(ary, n);

		int buf = ary[i];
		int j = i - 1;
		while (j >= 0 && ary[j] > buf) {
			ary[j + 1] = ary[j];
			j--;
			ary[j + 1] = buf;
		}
	}

	Show(ary, n);

	return ary;
}

int main()
{
	int n;
	int ary[100];

	cin >> n;

	for (int i = 0; i < n; i++) cin >> ary[i];

	InsertionSort(ary, n);

	return 0;
}



Measured memory_bytes: 3120
#include <bits/stdc++.h>
#define maxn 1000005
#define ll long long

int fin[maxn],suf[maxn][27],ch[maxn][27],tl=1,n;
ll ans;
std::string s[200005];
int cmp(std::string a,std::string b) { return a.length() < b.length(); }

void insert(std::string s) {
	std::reverse(s.begin(),s.end());
	int rt = 1, n = s.length();
	for (int i = 0; i <= n; ++ i) std::memset(suf[i],0,sizeof(suf[i]));
	for (int i = n-1; i >= 0; i--) {
		for(int j=0;j<26;++j)suf[i][j]=suf[i+1][j];
		suf[i][s[i]-'a']=1;
	}
	for (int p = 0; p < n; ++ p) {
		int d = s[p] - 'a';
	//	printf("%d ",d);
		for (int i = 0; i < 26; ++ i) {
			//if (fin[ch[rt][i]]) printf("[%d %d %c]",p,suf[p][i],i+'a');
			if (suf[p][i]) ans += fin[ch[rt][i]];
		} if (!ch[rt][d]) ch[rt][d] = ++tl;
		rt = ch[rt][d];
	} fin[rt] ++;// puts("");
}
			

int main() {
	scanf("%d",&n);
	for (int i = 1; i <= n; ++ i) std::cin>>s[i];
	std::sort(s+1,s+n+1,cmp);
	for (int i = 1; i <= n; ++ i) insert(s[i]);
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 218104
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<bool>> r(n, vector<bool>(n, false));
    rep(i, m){
        int a, b;
        cin >> a >> b;
        a--; b--;
        r[a][b] = true;
        r[b][a] = true;
    }
    vector<int> e(n-1);
    rep(i, n-1)e[i] = i+1;
    ll ans = 0;
    do{
        bool ok = true;
        if(!r[0][e[0]])ok = false;
        for(int i = 1; i < n-1; i++){
            if(!r[e[i-1]][e[i]])ok = false;
        }
        if(ok)ans++;
    }while(next_permutation(all(e)));
    cout << ans << endl;
}      

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

using namespace std;

const int N = 1e5 + 5 , MOD = 1e9 + 7;
bool bad[N];
int memo[N];

int solve (int n) {
    if (n <= 0) return n == 0;
    int &ret = memo[n];
    if (~ret) return ret;
    return ret = (solve(n - 2) + solve(n - 1)) % MOD;
}

int main() {

    int n , m;
    cin >> n >> m;

    vector<int> a(m);
    for (int i = 0 ;i < m ;i++) {
        cin >> a[i];
        bad[a[i]] = 1;
    }

    sort(a.begin() , a.end());

    bool can = !bad[0] && !bad[n];
    for (int i = 1 ;i <= n ;i++)
        if (bad[i] && bad[i - 1])
            can = 0;

    if (!can) {
        cout << 0;
        return 0;
    }

    a.push_back(n + 1);

    memset(memo , -1 , sizeof memo);

    int ans = 1 , prev = -1;
    for (int i = 0 ;i < a.size() ;i++) {
        ans = ans * 1ll * solve(a[i] - prev - 2) % MOD;
        prev = a[i];
    }

    cout << ans;
}

Measured memory_bytes: 2176
from bisect import bisect_right
 
def main():
    n, m, k = map(int, input().split())
    a = [int(x) for x in input().split()]
    b = [int(x) for x in input().split()]
 
    maxv = 0
    acum = [0] * (n + 1)
    bcum = [0] * (m + 1)
    for i in range(n):
        acum[i + 1] = acum[i] + a[i]
    for i in range(m):
        bcum[i + 1] = bcum[i] + b[i]
 
    for i in range(n + 1):
        if acum[i] > k:
            break
        maxv = max(maxv, i + bisect_right(bcum, k - acum[i]) - 1)
    print(maxv)
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 47504
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
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; }
const long long INF = 1LL << 60;
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

const long long LIM = 1000000000000000000LL;// 10の18乗！！

int main()
{
    int n; cin >> n;
    vector<ll> a(n);
    rep(i, n)
    {
        cin >> a[i];
        if (a[i] == 0)
        {
            cout << 0 << endl;
            return 0;
        }
    }
    ll ans = 1;
    rep(i, n)
    {
        if (LIM/ans < a[i])
        {
            cout << -1 << endl;
            return 0;
        }
        ans *= a[i];
    }
    cout << ans << endl;
}

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

int main(int argc, char** argv) {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if (argc == 2 && atoi(argv[1]) == 123456789)
        freopen("d:\\code\\cpp\\stdin", "r", stdin);

    int n, k;
    cin >> n >> k;

    vector<int> a(n);
    FOR(i, n)
        cin >> a[i];

    vector<ll> s(n);
    s[0] = a[0];
    for(int i=1; i<n; i++)
        s[i] = s[i-1] + a[i];

    vector<ll> sums;
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            if (i)
                sums.push_back(s[j]-s[i-1]);
            else
                sums.push_back(s[j]);
        }
    }


    ll ans = 0;
    for(int b=60; b>=0; b--){
        vector<ll> tmp;
        int cnt = 0;
        for(ll x : sums){
            if (x & 1ll<<b){
                cnt++;
                tmp.push_back(x);
            }
        }

        if (cnt >= k){
            sums = tmp;
            ans |= (1ll<<b);
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 6256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>

using namespace std;
 
 int main(){
     int L, R;
     cin >> L >> R;

     int rem, rem_min=2020;
     int i_rem, j_rem;
     for(int i=L;i<R+1;i++){
         for(int j=i+1;j<R+1;j++){
             i_rem=i%2019;
             j_rem=j%2019;
             rem = (i_rem * j_rem) % 2019;
             if(rem<rem_min){
                 rem_min=rem;
             }
             if (rem_min==0){
                break;
            }
         }
         if (rem_min==0){
            break;
        }
     }

     cout << rem_min <<endl;
 }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
  string S;
  long long K;
  cin >> S >> K;
  vector<int> data(S.size());
  for (int i = 0; i < S.size(); i++) {
    data.at(i) = S.at(i) - '0';
  }
  int ans;
  for (int i = 0; i < S.size(); i++) {
    if(data.at(i) == 1 && i <= K - 1) ans = 1;
    else {
      ans = data.at(i);
      break;
    }
    if (K - 1 == i) break;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int n,m,c,e[50][2],a;
bool g[50][50],v[50];
void dfs(int t){
	v[t]=true;c++;
	for(int i=0;i<n;i++)if(g[t][i]&&!v[i])dfs(i);
}
int main(){
	cin>>n>>m;
	for(int i=0;i<m;i++){
		cin>>e[i][0]>>e[i][1];
		g[e[i][0]-1][e[i][1]-1]=g[e[i][1]-1][e[i][0]-1]=true;
	}
	for(int i=0;i<m;a+=c!=n,c=0,i++){
		g[e[i][0]-1][e[i][1]-1]=g[e[i][1]-1][e[i][0]-1]=false;
		dfs(0);
		g[e[i][0]-1][e[i][1]-1]=g[e[i][1]-1][e[i][0]-1]=true;
		for(int j=0;j<n;j++)v[j]=false;
	}
	cout<<a<<endl;
	return 0;
}

Measured memory_bytes: 256
use proconio::input;

fn main() {
  input! {
    n: String,
  }
  let n: Vec<char> = n.chars().collect();
  if n[0] == '7' || n[1] == '7' || n[2] == '7' {
    println!("Yes");
  } else {
    println!("No");
  }
}


Measured memory_bytes: 2156
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n)  FOR(i, 0, n)
#define ASC(c) sort((c).begin(), (c).end())
#define DESC(c) sort((c).begin(), (c).end(), greater<int>())

#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
    int n; cin >> n;
    vector<int> a(n), b(n), c(n - 1);
    REP(i, n) cin >> a[i];
    REP(i, n) cin >> b[i];
    REP(i, n - 1) cin >> c[i];
    int ans = 0, prev = -1;
    for (auto e: a) {
        ans += b[e - 1];
        if (prev + 1 == e - 1) ans += c[e - 2];
        prev = e - 1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cassert>
#include <climits>
#define bogo_sort   std::sort
#define bozo_sort   std::stable_sort
#define alles(obj)  obj.begin(), obj.end()
#define elif        else if
#define unless(flg) if(!(flg))
#define elless(flg) else if(!(flg))
#define echo        std::cout <<
#define read        std::cin >>
#define endl        std::endl
#define fin         << '\n'
#define bash        push_back
#define makePair    std::make_pair
#define _           << ' ' <<
// type-define
#define Stack       std::stack
#define Queue       std::queue
#define Set         std::set
#define PQueue      std::priority_queue
#define Vector      std::vector
#define Pair        std::pair
#define Map         std::map
#define HashMap     std::unordered_map
#define Greater     std::greater
using String  =     std::string;
using llong   =     long long;
using boolean =     bool;
using Pii     =     Pair<int, int>;
using Vi      =     Vector<int>;
using Vii     =     Vector<Pii>;
// utils
constexpr int   dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int   dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
constexpr int   INF  = 0x3f3f3f3f;
constexpr llong LINF = 0x3f3f3f3f3f3f3f3fLL;

namespace {
    llong power ( llong x, llong n, llong mod ) {
        llong ans = 1;
        while ( n > 0 ) {
            if ( n & 1 ) ans = ( ans * x ) % mod;
            x = ( x * x ) % mod;
            n >>= 1;
        }
        return ans;
    }
    llong power ( llong x, llong n ) { return power( x, n, 1000000007 ); }
    llong gcd   ( llong x, llong y ) { return x % y ? gcd( y, x % y ) : y; }
    llong lcm   ( llong x, llong y ) { return ( x / gcd(x, y) * y ); }
    llong abs   ( llong n )          { return ( n < 0 ) ? -n : n; }
    template<class A, class B>inline bool chmax ( A &a, const B &b ) { return b > a ? a = b, true : false; }
    template<class A, class B>inline bool chmin ( A &a, const B &b ) { return b < a ? a = b, true : false; }
    boolean isMovable ( int x, int y, int w, int h ) {
        return ( x >= 0 && y >= 0 && x < w && y < h );
    }
}

namespace Rlyeh {

    signed call_of_Cthulhu( signed datum ) {

        int n, a, b;
        read n >> a >> b;
        unless ( (a+b) & 1 ) {
            echo "Alice" fin;
        }
        else {
            echo "Borys" fin;
        }

        return 0;
    }
}

signed main(){std::cin.tie(0); std::ios::sync_with_stdio(false); echo std::fixed << std::setprecision(8); int main_result = Rlyeh::call_of_Cthulhu(114514); return main_result;}


Measured memory_bytes: 256
s = input()
target = 'keyence'
s_len = len(s)
flg = 0

if s.startswith(target) or s.endswith(target):
  flg = 1
for i in range(len(target)):
  target1 = target[:i]
  target2 = target[i:]
  if s.startswith(target1) and s.endswith(target2):
    flg = 1

if flg == 1:
  print('YES')
else:
  print('NO')

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <string>

#define Rep(i, x, y) for (register int i = x; i <= y; i++)

int len;
std::string a, b;

int main()
{
    std::cin >> a;
    b = a;
    len = a.length();
    std::reverse(a.begin(), a.end());
    Rep(i, 0, len)
    {
        if (a[i] == 'b')
            a[i] = 'd';
        else if (a[i] == 'd')
            a[i] = 'b';
        else if (a[i] == 'p')
            a[i] = 'q';
        else if (a[i] == 'q')
            a[i] = 'p';
    }
    if (a == b)
        std::cout << "Yes";
    else
        std::cout << "No";
    return 0;
}

Measured memory_bytes: 512
/// Thank you tanakh!!!
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

use std::cmp;

fn main() {
    input!(
        n: usize,
        m: usize,
        x: i64,
        y: i64,
        sx: [i64; n],
        sy: [i64; m]
    );

    for z in (-100)..101 {
        let mut ok = true;
        for &x in sx.iter() {
            if x >= z {
                ok = false;
            }
        }
        for &y in sy.iter() {
            if y < z {
                ok = false;
            }
        }
        if x >= z || z > y {
            ok = false;
        }
        if ok {
            println!("No War");
            return;
        }
    }
    println!("War");
}


Measured memory_bytes: 4352
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n', '', _, String).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)
    string_chars(S, S2) (S: string, S2: [char])
    to_lower(C, C2) (C: char? C2: code?)

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).
*/

main :-
    get_number(H1),
    get_number(W1),
    get_number(H2),
    get_number(W2),
    X is (H1 - H2) * (W1 - W2),
    writeln(X).


Measured memory_bytes: 8160
#include<iostream>
#include<cstdio>
using namespace std;
int n,a[200005],l=0x7fffffff,r;
void init()
{
	cin>>n;
	for(int i=1;i<(n<<1);i++)
	{
		scanf("%d",&a[i]);
		l=min(l,a[i]);
		r=max(r,a[i]);
	}
}
int c[200005];
bool check(int x)
{
	for(int i=1;i<(n<<1);i++)
	{
		if(a[i]>=x) c[i]=1;
		else c[i]=0;
	}
	int t=0;
	for(int j=1;j<n;j++)
	if(c[n-j+1]==c[n-j]||c[n+j]==c[n+j-1])
	{t=j;break;}
	if(t==0)
	{
		c[n]=c[n]^((n-1)&1);
		return c[n];
	}
	if(c[n-t+1]==c[n-t])
	return c[n-t+1];
	else
	return c[n+t-1];
}
void play()
{
	int mid;
	while(l<r)
	{
		 mid=(l+r+1)>>1;
		 if(check(mid)) l=mid;
		 else r=mid-1;
	}
	cout<<l<<endl;
}
int main()
{
	init();
	play();
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
/*
g++ -std=c++11 -Wall -g -fsanitize=undefined -D_GLIBCXX_DEBUG nikkei2019/d.cpp
*/
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
typedef long long ll;

int dp[41][401][401];
int v[41][3];
// 薬品 i までを使ってA, Bの物質をj, kグラム含むときの値段
int MAX = 100000000;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);//おまじないでcin, cout早くする
    int n, ma, mb;
    cin >> n >> ma >> mb;
    for(int i = 1; i <= n; i++){
        cin >> v[i][0] >> v[i][1] >> v[i][2];
    }

    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= 400; j++){
            for(int k = 0; k <= 400; k++){
                dp[i][j][k] = MAX;
            }
        }
        dp[i][0][0] = 0;
    }
    
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= 400; j++){
            for(int k = 1; k <= 400; k++){
                if(j - v[i][0] < 0 || k - v[i][1] < 0){
                    dp[i][j][k] = dp[i-1][j][k];
                    continue;
                }
                dp[i][j][k] = min(dp[i-1][j - v[i][0]][k - v[i][1]] + v[i][2], dp[i-1][j][k]);
            }
        }
    }

    int ans = MAX;
    for(int i = 1; i <= 400; i++){
        int a, b;
        a = ma * i;
        b = mb * i;
        if(a > 400 || b > 400) break;

        for(int j = 1; j <= n; j++){
            if(dp[j][a][b] < ans) ans = dp[j][a][b];
        }
    }

    if(ans <= 4000) cout << ans << "\n";
    else cout << -1 << "\n";
    return 0;
}

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

int main(){
  string N;
  cin>>N;
  char S=N.at(N.size()-1);
  if(S=='2' || S=='5' || S=='4' ||S=='7' || S=='9'){
    cout<<"hon"<<endl;}
  if(S=='3'){cout<<"bon"<<endl;}
  if(S=='1' ||S=='0'|| S=='6'||S=='8'){cout<<"pon"<<endl;}
  
 
}


Measured memory_bytes: 3632
X=int(input())

if X<4:
    print('1')
    exit(0)

n=2
p=2
max=0
b_flag=True
while True:
    n+=1
    #print(n)
    while True:
        if n**p>X:
            break
        elif max<n**p:
            max=n**p
        p+=1

    p = 2
    b_flag=True
    if n**p>X:
        break
print(max)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int n, m, x, a, b=0, c=0;
    cin >> n >> m >> x;
    for(int i=0; i<m; i++)
    {
        cin >> a;
        if(a>x)
            b++;
        else 
            c++;
    }
    int ans=min(b,c);
    cout << ans << '\n';
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
        #define F first
        #define S second
        using ll = long long;
        const ll mod = 1000000007;
        const ll infi = 1000000000000000;
        const ll md = 998244353;
        using namespace std;
        using vl = vector<ll>;
        using pll =  pair<ll,ll>;
        
       
        void solve(){
           ll n;
           cin>>n;
           double x = 1.08,y;
           ll rate;
           for(int i=0;i<=n;i++){
               rate = x*i;
               if(rate == n){
                   cout<<i; return;
               }
           }
           cout<<":(";
        }
        int main() {
            ios_base::sync_with_stdio(false);
            cin.tie(NULL);
            solve();
            return 0;
        } 

Measured memory_bytes: 256
n=int(input())
h=list(map(int,input().split()))
dp=[10**9]*n
dp[0]=0
dp[1]=abs(h[1]-h[0])
for i in range(n-1):
    dp[i+1]=min(dp[i+1],dp[i]+abs(h[i+1]-h[i]))
    if i+2<n:
        dp[i+2]=min(dp[i+2],dp[i]+abs(h[i+2]-h[i]))
print(dp[-1])

Measured memory_bytes: 20500
#include "bits/stdc++.h"
using namespace std;
#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define PI 3.1415926535
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<Pll> vPll;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<double>> vvd;
typedef vector<vector<Pi>> vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
int main(void)
{
	string s;

	cin>>s;

	int size=s.size();

	cout<<s[0]<<size-2<<s[size-1]<<endl;
}



Measured memory_bytes: 256
n, A, B, C = map(int, input().split())
l = [int(input()) for i in range(n)]
INF = 10 ** 9


def dfs(cur, a, b, c):
    if cur == n:
        return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
    ret0 = dfs(cur + 1, a, b, c)
    ret1 = dfs(cur + 1, a + l[cur], b, c) + 10
    ret2 = dfs(cur + 1, a, b + l[cur], c) + 10
    ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10
    return min(ret0, ret1, ret2, ret3)


print(dfs(0, 0, 0, 0))


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

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

    int num[200000] = {};

    for (int i = 1; i < n; ++i) num[a[i]-1]++;

    for (int i = 0; i < n; ++i) cout << num[i] << endl;


}


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

using namespace std;

int main()
{
    // 行列入力
    int n, m;

    cin >> n >> m;

    int A[n][m], B[m], C[n];

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            cin >> A[i][j];
        }
    }

    for (int i = 0; i < m; i++)
    {
        cin >> B[i];
    }

    for (int i = 0; i < n; i++)
    {
        C[i] = 0;
    }

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            C[i] += A[i][j] * B[j];
        }
    }

    for (int i = 0; i < n; i++)
    {
        cout << C[i] << endl;
    }
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define rep1(i,n) for(int i=1; i<(int)n; i++)
#define repa(i,a,n) for(int i=(a); i<(int)(n); i++)
#define all(vec) vec.begin(),vec.end()
#define COUT(x) cout<<(x)<<endl
#define YES(x) cout<<(x?"YES":"NO")<<endl
#define Yes(x) cout<<(x?"Yes":"No")<<endl
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using psi = pair<string, int>;
const int dx[4] = {1, 0,-1, 0};
const int dy[4] = {0, 1, 0,-1};
const int mod = 1e9+7;
int gcd(int a, int b){if(a%b == 0){return(b);}else{return(gcd(b, a%b));}}
int lcm(int a, int b){return a / gcd(a, b)*b;}
//cout << fixed << setprecision(15);
int N, M, K, H, W, L, R, X;
string S, T;

signed main(){
  cin >> S;
  int a=0, b=0, c=0;
  rep(i,S.size()){
    if(S[i] == 'a') a++;
    else if(S[i] == 'b') b++;
    else if(S[i] == 'c') c++;
  }
  YES(abs(a-b)<=1 && abs(b-c)<=1 && abs(a-c)<=1);
  return 0;
}


Measured memory_bytes: 3752
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,k;
	cin>>n>>k;
	long long sum=0;
	long long h[n];
	for(int i=0;i<n;i++)
	cin>>h[i];
	//if(k>=n)
	//cout<<0<<"\n";

		sort(h,h+n);
		for(int i=0;i<n-k;i++)
		sum+=h[i];
		cout<<sum<<"\n";
	
	
	
}

Measured memory_bytes: 1792
h, w = map(int, input().split())
maplist = []
h2 = h
for i in range(h):
    k = [x for x in input()]
    for j in range(len(k)):
        if k[j] == "#":
            maplist.append(k)
            break
        if j == len(k)-1:
            h2 -= 1
deletelist = []
for i in range(w):
    for j in range(h2):
        if maplist[j][i] == "#":
            break
        if j == h2-1:
            deletelist.append(i)
deletelist = reversed(deletelist)
for i in deletelist:
    for j in range(h2):
        maplist[j].pop(i)
for i in range(h2):
    print("".join(maplist[i]))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 5;

int main(){
 //   freopen("input.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    if(s[0] == s[2]) cout << "Yes";
    else cout << "No";
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		StringBuffer sb = new StringBuffer(S);
		char[] s = sb.reverse().toString().toCharArray();
		int N = S.length();
		long[][] dp = new long[N+1][13];
		int[] m = {1, 10, 9, 12, 3, 4};
		if(s[0] == '?') {
			for(int i = 0; i < 10; i++)
				dp[1][i] = 1;
		}
		else
			dp[1][Character.getNumericValue(s[0])] = 1;
		for(int i  = 1; i < N; i++) {
			if(s[i] != '?') {
				int a = Character.getNumericValue(s[i]) * m[i%6] % 13;
				for(int j = 0; j < 13; j++) {
					dp[i+1][(j+a) % 13] += dp[i][j];
				}
			}
			else {
				for(int j = 0; j < 10; j++) {
					int a = j * m[i%6] % 13;
					for(int k = 0; k < 13; k++) {
						dp[i+1][(k+a) % 13] += dp[i][k];
					}
				}
			}
			for(int j = 0; j < 13; j++)
				dp[i+1][j] %= 1000000007;
		}
		System.out.println(dp[N][5]);

	}

}

Measured memory_bytes: 39316
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reps(i,a,b) for(int i= a; i < b; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int x;
  cin >> x;
  if (x >= 30) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int N,K,q;
  cin >> N >> K >> q;
  vi A(q);
  vi cnt(N,0);
  rep(i,q) {
    cin >> A[i];
    cnt[A[i]-1]++;
  }
  rep(i,N) {
    if(cnt[i] > q-K) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define INF 10000000
using ll = long long ;
ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}
template< int id > struct CompTupleBy
{
  template<class T> 
  bool operator()( const T& a, const T& b ) const {
    return std::get<id>(a) < std::get<id>(b);
  }
};

using namespace std;

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

    int n;
    cin >> n;
    vector<int> P(n);
    vector<int> Q(n);
    vector<int> tmp(n);
    rep(i,n){
        tmp[i]= i+1;
    }
    rep(i,n){
        cin >> P[i];
    }
    rep(i,n){
        cin >> Q[i];
    }
    int tmp1,tmp2;
    if (P==Q){
        cout << 0 << endl;
        return 0;
    }
    int cnt=0;
    do{
        cnt++;
        // rep(i,n){
        //     cout << tmp[i] << " ";
        // }
        // cout << endl;
        if (tmp==P){
            tmp1 = cnt;
        }
        if (tmp==Q){
            tmp2 = cnt;
        }
    }while(next_permutation(tmp.begin(),tmp.end()));
    cout << abs(tmp2-tmp1) << endl;




        
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int n;
  char ch[256];
  
  while(1) {
    for (int i=0; i<256; i++)
      ch[i]=i;
  
    cin >> n;
    
    if (n==0)
      break;

    for (int i=0; i<n; i++) {
      char a, b;
      cin >> a >> b;
      ch[a]=b;
    }
    int m;
    cin >> m;
    
    for (int i=0; i<m; i++) {
      char tmp;
      cin >> tmp;
      cout << ch[tmp];
    }
    cout << endl;
  }
}

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

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define rep(i, x, y) for(decltype(y) i = (x) - ((x) > (y)); i != (y) - ((x) > (y)); i += 1 - 2 * ((x) > (y)))
#define trav(i,a) for(auto& (i) : (a))
#define all(a) (a).begin(),(a).end()
#define sz(a) int((a).size())
#define clr(a,x) memset((a),(x),sizeof(a)) // array (0,-1)
#define dbg(x) cerr << "STDERR => " << __LINE__ << ": " << #x << " = " << (x) << "  :(\n";
#define eb emplace_back
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline void cpuTime() { cerr << "cpu time : " << double(clock())/CLOCKS_PER_SEC << "\n"; return; }
using ll = long long;
using ull = unsigned long long;
using F = float;
using D = double;
using vi = vector<int>;
using pii = pair<int,int>;



void solve(){

    int a,b;
    cin >> a >> b;

    cout << (b+a-3)/(a-1) << "\n";

    return;
}

/*
 read the question carefully ( what're the exact constraints? )
 look out for SPECIAL CASES (n=1?) and OVERFLOW (ll vs int?) ARRAY OUT OF BOUNDS
 Check datatypes
*/
int main(){

    fast_io;
    int t=1;
    // cin >> t;

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

    cpuTime();
return 0;
}




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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll X, Y, Z;
    cin >> X >> Y >> Z;
    cout << Z << " " << X << " " << Y << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


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

int main() {
    string s; cin >> s;
    rep(i,0,s.size()){
        rep(j,i+1,s.size()){
            if(s[i] == s[j]){
                cout << "no" << endl;
                return 0;
            }
        }
    }
    cout << "yes" << endl;
}

Measured memory_bytes: 256
a, b, k = map(int, input().split())
for i in range(k):
    if i % 2 == 0:
        if a % 2 == 1:
            a -= 1
        b += a // 2
        a = a // 2
    else:
        if b % 2 == 1:
            b -= 1
        a += b // 2
        b = b // 2
print(a, b)

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

ll solve(vector<ll> &v, ll i)
{
  if(i == 0) return 2;
  if(i == 1) return 1;
  ll n1, n2;
  if(v.at(i-1)) n1 = v.at(i-1);
  else
  {
    n1 = solve(v, i-1);
    v.at(i-1) = n1;
  }
  
  if(v.at(i-2)) n2 = v.at(i-2);
  else
  {
    n2 = solve(v, i-2);
    v.at(i-2) = n2;
  }
  return n1 + n2;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  
  ll n;
  cin >> n;
  vector<ll> v(n, 0);
  cout << solve(v, n) << endl;
  return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
typedef long l;
typedef long long ll;

void swap (ll *x, ll *y);
ll partition (ll array[], ll left, ll right, ll a[]);
void quick_sort (ll array[], ll left, ll right, ll a[]);

int main(void){
  l i;
  l n;
  ll time=0;
  int tf=1;
  scanf("%ld",&n);
  ll a[n+1], b[n+1];

  // a[0]=0;
  // b[0]=0;
  for(i=0; i<n; i++){
    scanf("%lld %lld", &a[i], &b[i]);
  }

  quick_sort(b, 0, n-1, a);


  for(i=0; i<n; i++){
    time+=a[i];
    if(i!=n-1){
      while(b[i]==b[i+1]){
        time+=a[i+1];
        // printf("i=%ld time=%lld B[i+1]=%lld\n", i, time, B[i+1]);
        if(time>b[i+1]){
          tf=0;
          break;
        }
        i++;
      }
    }
    if(time>b[i]){
      tf=0;
      break;
    }
    if(tf==0) break;
  }

  if(tf==1){
    printf("Yes\n");
  }else{
    printf("No\n");
  }

  return 0;
}

void swap (ll *x, ll *y) {
  ll temp;    // 値を一時保存する変数

  temp = *x;
  *x = *y;
  *y = temp;
}

/***
* pivotを決め、
* 全データをpivotを境目に振り分け、
* pivotの添え字を返す
***/
ll partition (ll array[], ll left, ll right ,ll a[]) {
  ll i, j, pivot;
  i = left;
  j = right + 1;
  pivot = left;   // 先頭要素をpivotとする

  do {
    do { i++; } while (array[i] < array[pivot]);
    do { j--; } while (array[pivot] < array[j]);
    // pivotより小さいものを左へ、大きいものを右へ
    if (i < j) {
      swap(&array[i], &array[j]);
      swap(&a[i], &a[j]);
    }
  } while (i < j);

  swap(&array[pivot], &array[j]);   //pivotを更新
  swap(&a[pivot], &a[j]);

  return j;
}

/* クイックソート */
void quick_sort (ll array[], ll left, ll right, ll a[]) {
  ll pivot;

  if (left < right) {
    pivot = partition(array, left, right, a);
    quick_sort(array, left, pivot-1, a);   // pivotを境に再帰的にクイックソート
    quick_sort(array, pivot+1, right, a);
  }
}


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

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

    vector<int> vec(N);

    for (int i = 0; i < N; i++){
        cin >> vec.at(i);
    }

    sort(vec.begin(),vec.end());
    reverse(vec.begin(), vec.end());

    int sum = 0;

    for (int i = 0; i < N; i++){
        if ((i % 2) == 0){
            sum += vec.at(i);
        }
        if ((i % 2) == 1){
            sum -= vec.at(i);
        }
    }
     cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char const *argv[]) {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (abs(c-a)<=d) cout << "Yes" << endl;
  else if (abs(c-b)<=d and abs(b-a) <= d) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
inline int read(){
	char c=getchar();int t=0,f=1;
	while((!isdigit(c))&&(c!=EOF)){if(c=='-')f=-1;c=getchar();}
	while((isdigit(c))&&(c!=EOF)){t=(t<<3)+(t<<1)+(c^48);c=getchar();}
	return t*f;
}
int k,nx[505],mp[505][505];
signed main(){
	k=read();
	if(k<=500){
		printf("%d\n",k);
		for(int i=1;i<=k;i++){
			for(int j=1;j<=k;j++){
				printf("%d ",i);
			}
			puts("");
		}
	}
	else{
		int n=500,N=0;
		for(int i=1;i<=n;i++)nx[i]=i+1;
		nx[n]=1;printf("500\n");k-=n;
		for(int i=1;i<=n;i++){
			int a=++N,b=k?++N:N;
			k-=b-a;
			for(int x=1,y=i;x<=n;x++,y=nx[y]){
				mp[x][y]=x&1?a:b;
			}
		}
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++)printf("%d ",mp[i][j]);
			puts("");
		}
	}
	return 0;
}


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

int main()
{
	int n;
	cin >> n;
	for (int i = 1; i < n+1; i++)
	{
		int x = i;
		if (x % 3 == 0)
		{
			cout << " " << i;
		}
		else 
		{
			while (true)
			{
				if (x % 10 == 3)
				{
					cout << " " << i ;
					break;
				}
				
				x = x / 10;
				if (x == 0)
				{
					break;
				}
				
			}
		}
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3088
import java.util.Scanner;

public class Main {
  
  	private final static Scanner sc = new Scanner(System.in);
    public static void main (String [] args) {
      int N = sc.nextInt();
      long K = sc.nextInt();
      long Q = sc.nextInt();
      long [] array = new long[N];
      for(int i = 0; i < Q; i++) {
        array[sc.nextInt() -1]++;
      }
      for(int i = 0; i < N; i++) {
        if((K + array[i] - Q) > 0) {
          System.out.println("Yes");
        } else {
          System.out.println("No");
        }
      }
   }
}


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

#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

const int M = 1e5+10;
const int MOD = 1e9 + 7;

vector<int> cur(M,0),nex(M,0);

void solve()
{
   int n,k;
    cin >> n >> k;
    
   int a[n+1];
    
    for(int i=1;i<=n;i++) cin >> a[i];
    
   cur[k] = 1;
    
   for(int i=1;i<=n;i++)
   {
       for(int j=1;j<M;j++) cur[j] = (cur[j] + cur[j-1])%MOD;
       
       for(int j=0;j<M;j++)
       {
           nex[j] = cur[min(M-1,j + a[i])];
           
           if(j>0) nex[j] = (nex[j] - cur[j-1] + MOD)%MOD;
       }
       
       swap(cur,nex);
   }
    
   cout << cur[0];   
}

signed main()
{
    fast;
    solve();
}

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

typedef int64_t ll;

ll g(ll A) {
  if(A % 4 == 0) return A;
  if(A % 4 == 1) return 1;
  if(A % 4 == 2) return A + 1;
  if(A % 4 == 3) return 0;
}

int main(){
  ll A, B;
  cin >> A >> B;
  ll ret = g(B) ^ g(A - 1);
  cout << ret << endl;
  return 0;
}



Measured memory_bytes: 256
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws FileNotFoundException {

		Scanner scan = new Scanner(System.in);
		// Scanner scan = new Scanner(new
		// File("D:\\UserArea\\J0124567\\Downloads\\0534-input.txt"));

		while (scan.hasNext()) {

			int n = scan.nextInt();
			if (n == 0)
				break;
			Chs chs = new Chs(n);
			for (int i = 0; i < n; i++)
				chs.add(scan.nextInt());
			System.out.println(chs.rem());
		}

		scan.close();
		System.exit(0);

	}
}

class Chs {
	public Chs(int n) {
		col = new int[n + 1];
		rep = new int[n + 1];
		N = n;
	}

	public int rem() {
		// this.print();

		int max = 0;
		for (int i = 1; i <= last; i++) {
			int x = this.erase(i);
			if (x > max)
				max = x;
		}
		return N - max;
	}

	private void print() {
		for (int i = 1; col[i] > 0; i++)
			System.out.println(i + ": Col " + col[i] + " Rep " + rep[i]);
	}

	private int erase(int i) {
		int max = 0;
		if (rep[i] == 1) {
			if (col[i - 1] == col[i + 1] && rep[i - 1] + rep[i + 1] >= 3) {
				int x = rep[i - 1] + rep[i + 1] + 1 + this.next(i - 2, i + 2);
				if (x > max)
					max = x;
			} else {
				if (rep[i - 1] >= 3) {
					int x = rep[i - 1] + 1 + this.next(i - 2, i + 1);
					if (x > max)
						max = x;
				}
				if (rep[i + 1] >= 3) {
					int x = rep[i + 1] + 1 + this.next(i - 1, i + 2);
					if (x > max)
						max = x;
				}
			}
		} else {
			if (rep[i - 1] >= 3) {
				int x = rep[i - 1] + 1;
				rep[i]--;
				x += this.next(i - 2, i);
				rep[i]++;
				if (x > max)
					max = x;
			}
			if (rep[i + 1] >= 3) {
				// System.out.print(i+" ");
				int x = rep[i + 1] + 1;
				rep[i]--;
				x += this.next(i, i + 2);
				rep[i]++;
				if (x > max)
					max = x;
			}
		}
		return max;
	}

	private int next(int low, int hi) {
		int x = 0;
		for (int i = 0; col[low - i] == col[hi + i] && col[low - i] > 0; i++)
			if (rep[low - i] + rep[hi + i] >= 4)
				x += rep[low - i] + rep[hi + i];
		return x;
	}

	public void add(int c) {
		if (col[last] == 0 || col[last] == c) {
			col[last] = c;
			rep[last]++;
		} else {
			col[++last] = c;
			rep[last]++;
		}
	}

	int last = 1;
	int[] col;
	int[] rep;
	int N;
}

Measured memory_bytes: 43316
#include <cstdlib>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;

template<class T> inline void chmin(T& a, const T& b) { if(b < a) a = b; }

const int INF = 100;
int n;
vector<string> a, b;
string from, to;
map<unsigned long long, int> memo;

inline unsigned long long hash(const string& s) {
	const unsigned long long base = 1000000007;
	long long res = 0;
	for(int i = 0; i < s.size(); ++i) {
		res *= base;
		res += s[i];
	}

	return res;
}

int dfs(string s) {
	if(s == to)
		return 0;

	if(s.size() >= to.size())
		return INF;

	const unsigned long long h = hash(s);
	if(memo.count(h))
		return memo[h];

	int res = INF;
	for(int i = 0; i < n; ++i) {
		int pos = 0;
		string next = s;
		while((pos = next.find(a[i], pos)) != string::npos) {
			next = next.substr(0, pos) + b[i] + next.substr(pos + a[i].size());
			pos += b[i].size();
		}
		if(s != next)
			chmin(res, dfs(next));
	}

	return memo[h] = res + 1;
}

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

	while(cin >> n, n) {
		a.clear();
		a.resize(n);
		b.clear();
		b.resize(n);
		for(int i = 0; i < n; ++i)
			cin >> a[i] >> b[i];

		cin >> from >> to;
		memo.clear();
		const int ans = dfs(from);
		cout << (ans >= INF ? -1 : ans) << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1260
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e3+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a,b) memset(a,b,sizeof a)
#define lx x<<1
#define rx x<<1|1
#define reg register
#define PII pair<int,int>
#define fi first
#define se second
#define pb push_back
#define il inline
int a[N];
int main(){
	int n,s=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i],s+=a[i];
	}
	int ans=0;
	if(s%10){
		cout<<s<<endl;
	}
	else {
		for(int i=1;i<=n;i++){
			if((s-a[i])%10) ans=max(ans,s-a[i]); 
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 3644
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    INF = 10**9 + 1
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]

    N,M = LI()
    x = []; y = []
    A = []
    D = []
    for _ in range(N):
        a,b,c = LI()
        A.append((a,b,c))
        x.append(a); x.append(b)
        y.append(c); y.append(c)
    for _ in range(M):
        d,e,f = LI()
        D.append((d,e,f))
        x.append(d); x.append(d)
        y.append(e); y.append(f)

    x.append(-INF); x.append(INF); x.append(0)
    y.append(-INF); y.append(INF); y.append(0)
    x.sort(); y.sort()
    lx = len(x); ly = len(y)
    fld = [[0] * ly for _ in range(lx)]
    for a,b,c in A:
        j = bisect.bisect_left(y,c)
        for i in range(bisect.bisect_left(x,a),bisect.bisect_left(x,b)):
            fld[i][j] = 1
    for d,e,f in D:
        i = bisect.bisect_left(x,d)
        for j in range(bisect.bisect_left(y,e),bisect.bisect_left(y,f)):
            fld[i][j] = 1

    q = []
    i = bisect.bisect_left(x,0)
    j = bisect.bisect_left(y,0)
    q.append((i,j))
    fld[i][j] = 1
    ans = 0
    while q:
        i,j = q.pop()
        ans += (x[i+1]-x[i]) * (y[j+1]-y[j])
        for di,dj in ((0,1),(1,0),(0,-1),(-1,0)):
            if 0 < i+di < lx-1 and 0 < j+dj < ly-1:
                if fld[i+di][j+dj] == 0:
                    fld[i+di][j+dj] = 1
                    q.append((i+di,j+dj))
            else:
                print('INF')
                exit(0)

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 512000
#include<bits/stdc++.h>
using namespace std;
#define ll long long int

int main(){
    string s,t;
    cin>>s>>t;
    ll ans=LLONG_MAX;
    for(ll i=0;i<=(ll)s.size()-(ll)t.size();i++){
        ll cnt=0;
        for(ll j=0;j<(ll)t.size();j++){
            if(s[j+i]!=t[j])  cnt++;
        }
        ans=min(ans,cnt);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3600
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(a+b==c+d)
		puts("Balanced");
	else if(a+b<c+d)
		puts("Right");
	else 
		puts("Left");
	return 0;
}

Measured memory_bytes: 256