akhauriyash/Code-Regression huggingface dataset:
function main (arg) {
	arg = arg.trim().split(' ');
  	var k = Number(arg[0]), x = Number(arg[1]), out = [];
	var min = x-k+1; var max = x+k-1;
  	for (min; min <= max; min++){
    	out.push(min);
    }
  console.log(out.join(' '))
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 11468
#include <bits/stdc++.h>
#define INF (1LL<<60)
#define MOD7 1000000007LL
#define PREP(i, s, x) for(ll (i) = (s); (i) < (x); (i) ++)
#define MREP(i, s, x) for(ll (i) = (s); (i) >= (x); (i) --)
#define REP(i, x) PREP(i, 0, x)
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

int main(){
    ll n, x;
    while(true){
        cin >> n >> x;
        if(n == 0 && x == 0){
            return 0;
        }
        ll ans = 0;
        PREP(i, 1, n + 1){
            PREP(j, i + 1, n + 1){
                PREP(k, j + 1, n + 1){
                    if (i + j + k == x){
                        ans++;
                    }
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3080
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int h = sc.nextInt();
		System.out.println((a + b) * h / 2);
		sc.close();
	}
}

Measured memory_bytes: 22740
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        long[] a = new long[n];
        long[] ruiseki = new long[n];
        a[0] = scanner.nextLong();
        ruiseki[0] = a[0];
        long mod = 1000000007;
        for (int i = 1; i < n; i++) {
            a[i] = scanner.nextLong();
            ruiseki[i] = ruiseki[i - 1] + a[i];
        }
        long ans = 0;
        for (int i = 0; i < n - 1; i++) {
            long other = (ruiseki[n - 1] - ruiseki[i]) % mod;
            long v = other * a[i] % mod;
            ans += v;
            ans %= mod;
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 64100
# -*- coding: utf-8 -*-
# B - Popular Vote
# 標準入力の取得
N,M = list(map(int, input().split()))
A = list(map(int, input().split()))

# 商品を降順にソートし、M番目の商品の得票数と1/4Mを比較
total_votes = sum(A)
sorted_A = sorted(A, reverse=True)
if sorted_A[M-1] >= total_votes/(4*M):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#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  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int N;cin >> N;
    vector<int> h(N);
    rep(i,N)cin >> h[i];
    int dp[N+1];
    rep(i,N+1)dp[i] = 1<<30;
    dp[0] = 0;
    rep(i,N){
        if(i == 0)continue;
        else if(i == 1)dp[i] = abs(h[1] - h[0]);
        else{
            chmin(dp[i],(dp[i-2] + abs(h[i] - h[i-2])));
            chmin(dp[i],(dp[i-1] + abs(h[i] - h[i-1])));
        }
    }
    int ans = dp[N-1];
    cout << ans << endl;
}



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

#define rep(i, n) for(int i=0; i<n; ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
#define ll long long int

int main(){
   int n, m, k;
   cin>>n>>m>>k;
   int a[200000], b[200000];
   rep(i, n) cin>>a[i];
   rep(i, m) cin>>b[i];

   int r=k;
   int ai=0, bi=0;
   ll mx=0;
   while(ai<n && r-a[ai]>=0){
      r-=a[ai];
      ai++;
   }

   while(bi<m && r-b[bi]>=0){
      r-=b[bi];
      bi++;
   }

   mx=max(mx, (ll)ai+bi);

   for(; ai>0; ){
      r+=a[ai-1];
      ai--;

      while(bi<m && r-b[bi]>=0){
         r-=b[bi];
         bi++;
      }
      mx=max(mx, (ll)ai+bi);
   }

   cout << mx << endl;
   return 0;
}


Measured memory_bytes: 5148
<?php

function input() {
    return trim(fgets(STDIN));
}

function input_array() {
    return explode(' ', input());
}

function ex_intval($mixed_array) {
    return array_map(function($mixed) {
        return (int)$mixed;
    }, $mixed_array);
}

$N = (int)input();
$info_array = [];
for ($i = 0; $i < $N; $i++) {
    $info_array[$i] = ex_intval(input_array());
    if ($info_array[$i][2] !== 0) {
        list($onex, $oney, $oneh) = $info_array[$i];
    }
}

for ($cx = 0; $cx <= 100; $cx++) {
    for ($cy = 0; $cy <= 100; $cy++) {
        $H = $oneh + abs($cx - $onex) + abs($cy - $oney);
        $status = true;
        for ($k = 0; $k < $N; $k++) {
            if ($info_array[$k][2] !== max(0, $H - abs($cx - $info_array[$k][0]) - abs($cy - $info_array[$k][1]))) {
                $status = false;
                break;
            }
        }
        if ($status) {
            echo "{$cx} {$cy} {$H}\n";exit;
        }
    }
}

Measured memory_bytes: 4856
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define rrep(i, a, b) for (int i = (a); i < (b); ++i)
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using tl = tuple<ll, ll, ll>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll n, k; cin>>n>>k;
    vector<LP> dt(n); cin>>dt;
    rep(i, n) swap(dt[i].fi, dt[i].se);
    sort(rrng(dt));

    vector<bool> used(n + 1);
    vl dub;
    ll kind = 0;
    ll deli = 0;
    rep(i, k) {
        if (used[dt[i].se]) dub.push_back(dt[i].fi);
        else kind++;
        used[dt[i].se] = true;
        deli += dt[i].fi;
    }
    ll cur = deli + kind * kind;
    ll ans = cur;
    rrep(i, k, n) {
        if (used[dt[i].se] || dub.empty()) continue;
        used[dt[i].se] = true;

        deli = deli - dub.back() + dt[i].fi;
        dub.pop_back();
        kind++;
        cur = deli + kind * kind;
        chmax(ans, cur);
    }
    cout<<ans<<endl;
}

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

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if (a>=b && a>=c) cout << 10*a+b+c << endl;
  else if (b>=a && b>=c) cout << 10*b+a+c << endl;
  else cout << 10*c+a+b << endl;
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> inline T bis(T ok, T ng, function<bool(T)> f, T eps = 1) { while (abs(ok - ng) > eps) { T mi = (ok + ng) / 2; (f(mi) ? ok : ng) = mi; } return ok; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int H, N;
  cin >> H >> N;
  int sum = 0;
  rep(i, N) {
    int a;
    cin >> a;
    sum += a;
  }
  if (sum >= H) yes(); no();
}


Measured memory_bytes: 256
from functools import cmp_to_key
n, l = map(int, input().split())
ss = {}
for i in range(n):
    s = input()
    ss[s] = ss.get(s, 0) + 1
ans = ""
ma = ""
for s in sorted(ss):
    if s[::-1] == s:
        ans += s * (ss[s]//2)
        ss[s] -= 2*(ss[s]//2)
        if ss[s] > 0 and len(ma) < len(s):
            ma = s
    else:
        rev = s[::-1]
        if rev in ss:
            cnt = min(ss[s], ss[rev])
            ans += s * cnt
            ss[s] -= cnt
            ss[rev] -= cnt
print(ans + ma + ans[::-1])

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

ll n, k;
vector<ll> a, f;
bool check(ll tl){
    ll need = 0;
    rep(i, n){
        if(a[i] * f[i] > tl){
            need += a[i] - (tl / f[i]);
        }
    }

    return need <= k;
}


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

    cin >> n >> k;
    a.resize(n);
    f.resize(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> f[i];

    sort(a.begin(), a.end());
    sort(f.begin(), f.end(), greater<ll>());

    // rep(i, n) cout << a[i] << " ";
    // cout << endl;
    // rep(i, n) cout << f[i] << " ";
    // cout << endl;

    ll ok = 1100000000000;
    ll ng = -1;
    while(ok-ng > 1){
        ll mid = (ok + ng) / 2;
        if(check(mid)) ok = mid;
        else ng = mid;
    }

    cout << ok << endl;

    return 0;
}

Measured memory_bytes: 6364
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_set>
using namespace std;
#define inf 999999999
#define loop(i, a, b) for (int i = (a), i##len = (b); i < i##len; ++i)
#define rep(i, n) loop(i, 0, n)
#define lin long long

int n;
int a[100002];

int main(void)
{
    cin >> n;
    a[0] = 0;
    rep(i,n)
    {
        cin >> a[i+1];
    }
    a[n+1] = 0;

    lin total = 0;
    int current = 0;
    rep(i,n+2)
    {
        total += abs(current - a[i]);
        current = a[i];
    }

    rep(i, n)
    {
        lin res = total
            - abs(a[i+1] - a[i]) 
            - abs(a[i+2] - a[i+1]) 
            + abs(a[i+2] - a[i]);
        cout << res << endl;
    }

    return 0;
}


Measured memory_bytes: 1664
#include<iostream>
using namespace std;
int main()
{
  string s;
  cin >>s;
  int a = 0;
  if(s[0] == '1') ++a;
  if(s[1] == '1') ++a;
  if(s[2] == '1') ++a;
  cout << a << endl;
  return 0;
}


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

class Main{
    final static long MOD = 1000000007;
    FastScanner sc = new FastScanner();

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve(){

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        //long n = sc.nextLong();
        //String s = sc.next();
        // int[] array = new int[n];
        //
        // for(int i = 0; i < n; i++){
        //     array[i] = sc.nextInt();
        // }

        if(a==c) System.out.println(0);
        else System.out.println(1);

    }

    long gcd(long a, long b){ // return aとbの最大公約数
        if(b == 0){
          return a;
        }
        return gcd(b, a % b);
    }

    long pow_mod(long a, long r){ // return a^r (mod MOD)
        long sum = 1;
        while(r > 0){
            if((r & 1) == 1){
                sum *= a;
                sum %= MOD;
            }
            a *= a;
            a %= MOD;
            r >>= 1;
        }
        return sum;
    }

}



class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte(){
        if(ptr < buflen){
            return true;
        }else{
            ptr = 0;
            try{
                buflen = in.read(buffer);
            }catch(IOException e){
                e.printStackTrace();
            }
            if(buflen <= 0){
                return false;
            }
        }
        return true;
    }
    private int readByte(){ if(hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c){ return 33 <= c && c <= 126;}
    public boolean hasNext(){ while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next(){
        if(!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)){
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong(){
        if(!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if(b == '-'){
            minus = true;
            b = readByte();
        }
        if(b < '0' || '9' < b){
            throw new NumberFormatException();
        }
        while(true){
            if('0' <= b && b <= '9'){
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt(){
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble(){ return Double.parseDouble(next());}
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}

int main() {
  ll a, b, c, x;
  cin >> a >> b >> c >> x;
  ll ans = 0;
  rep(i, a+1) {
    rep(j, b+1) {
      rep(k, c+1) {
        if (x == 500*i+100*j+50*k) ans++;
      }
    }
  }
  cout << ans << endl;
}

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

const int64_t MOD = 998244353;

int64_t power_mod(int64_t num, int64_t power){
    int64_t prod = 1;
    num %= MOD;
    while(power > 0){
        if(power&1) prod = prod * num % MOD;
        num = num * num % MOD;
        power >>= 1;
    }
    return prod;
}

int main(){
    int N, M, A[300][300];
    cin >> N >> M;
    for(int i=0; i<N; i++) for(int j=0; j<M; j++) cin >> A[i][j];

    int rank = 0;
    for(int j=0; j<M; j++){
        int pivot = -1;
        for(int i=rank; i<N; i++){
            if(A[i][j]){
                pivot = i;
                break;
            }
        }
        if(pivot >= 0){
            if(pivot != rank) for(int k=0; k<M; k++) swap(A[pivot][k], A[rank][k]);
            for(int i=rank+1; i<N; i++){
                if(A[i][j]) for(int k=0; k<M; k++) A[i][k] ^= A[rank][k];
            }
            rank++;
        }
    }

    int64_t ans = (MOD + power_mod(2, N+M-1) - power_mod(2, N+M-rank-1)) % MOD;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, N) for (int i=0; i<(int)N; i++)
#define rep1(i, N) for (int i=1; i<(int)N; i++)

using namespace std;

int n;
string s;

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

  int counter = 0;
  rep(i, n-2) {
    if(s.substr(i, 3) == "ABC") counter++;
  }
  
  cout << counter;
   
}


Measured memory_bytes: 256
def solve(C,H,W,tate,yoko,sum):
    for h in range(H):
        if 2**h & tate != 0:
            for w in range(W):
                if C[h][w] == "#":
                    sum -= 1

    for w in range(W):
        if 2**w & yoko != 0:
            for h in range(H):
                if C[h][w] == "#":
                    sum -= 1

    for h in range(H):
        for w in range(W):
            if 2**h & tate != 0 and 2**w & yoko != 0 and C[h][w] == "#":
                sum += 1

    return sum

def main():
    H,W,K = map(int,input().split())
    C = [input() for _ in range(H)]

    sum,ans = 0,0
    for h in range(H):
        for w in range(W):
            if C[h][w] == "#":
                sum += 1

    for i in range(2**H):
        for j in range(2**W):
            if solve(C,H,W,i,j,sum) == K:
                ans += 1

    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 9264
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
    int N, tmp, index = 0, answer = 0;
    bool flag = false;

    cin >> N;
    vector<int> d(N);
    for (int count = 0; count < d.size(); count++)
    {
        cin >> tmp;
        if (count == 0)
        {
            d.at(0) = tmp;
        }
        else
        {
            for (index = 0; index < count; index++)
            {
                if (tmp == d.at(index))
                {
                    flag = true;
                    break;
                }
            }
            if (!flag)
            {
                d.at(index) = tmp;
            }
            flag = false;
        }
    }
    for (int count = 0; count < d.size(); count++)
    {
        if (d.at(count) != 0)
        {
            answer++;
        }
    }

    cout << answer << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b,c,d,e,k;
    std::cin >>a ;
    std::cin >>b ;
    std::cin >>c ;
    std::cin >>d ;
    std::cin >>e ;
    std::cin >>k ;
    if((e-a)<=k) std::cout << "Yay!" << std::endl;
    else std::cout << ":(" << std::endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;

int main(){
  int n;
  cin >> n;
  int a, b;
  int count = 0;
  bool flag = false;
  rep(i, n){
    cin >> a >> b;
    if (a == b) count++;
    else count = 0;
    if (count == 3){
      flag = true;
      break;
    }
  }
  if (flag) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <string>
using namespace std;
string str,tmp;
int solve(string judge)
{
      for(int i=0;i<judge.length();i++){
            if(str[0]!=judge[i])continue;
            for(int j=i+1;j<judge.length();j++)
            {
                  if(j>=judge.length())break;
                  if(str[1]!=judge[j])continue;
                  for(int k=2;;k++){
                        if(k==str.length())return 1;
                        if(i+(j-i)*k>=judge.length() || str[k]!=judge[i+(j-i)*k])break;
                  }
            }

      }
      return 0;
}

int main()
{
      int x,ctn = 0;
      cin >> x >> str;
      for (int i = 0;i < x ; i++){
            cin >> tmp;
            ctn += solve(tmp);
      }
      cout << ctn << endl;
      return 0;
}

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

#define int long long 

int32_t main()
{
	int n=0;
	cin>>n;
	vector<int> v(n,0);
	vector<int> wt(n,0);
	int w;
	cin>>w;

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

	vector<vector<int>> dp(n+1,vector<int>(w+1));
	
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=w;j++)
		{
			if(i==0 or j==0) dp[i][j]=0;
			else if(wt[i-1]<=j) dp[i][j]=max(v[i-1]+dp[i-1][j-wt[i-1]],dp[i-1][j]);
			else dp[i][j]=dp[i-1][j];
		}
	}

	cout<<dp[n][w];
	
	return 0;
}

Measured memory_bytes: 80256
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define endl "\n"

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



int n, a[11], s, b;

signed main() {
	cin >> n;
	rep(i,n) cin >> a[i];
	s = accumulate(a,a+n,0);
	b = *max_element(a,a+n);
	s -= b;
	cout << (b<s ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<string>
#include<cstdlib>
#include<cctype>
#include<unordered_map>
#include<sstream>
#include<numeric>
#include<stack>
// #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1LL<<60;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};

// intやllをstringに変換
template<typename T> inline string toString(const T &a){
  ostringstream oss;
  oss << a;
  return oss.str();
};
// ----------------------------------------------------------------------------

int main(){
  int N;
  cin >> N;
  vector<int> h(N);
  for(int i=0; i<N; i++){
    cin >> h[i];
  }
  int ans = *min_element(h.begin(),h.end());
  for(int i=0; i<N-1; i++){
    if(h[i] > h[i+1]){
      ans += h[i]-h[i+1];
    }
    if(i == N-2){
      ans += h[N-1]-*min_element(h.begin(),h.end());
    }
  }
  cout << ans << endl;
  return 0;
}


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

if n == 0:
    if a[0] == 1:
        print(1)
    else:
        print(-1)
else:
    if a[0] == 1:
        print(-1)
    else:
        lefts = [sum(a)]
        for i in range(1, len(a)):
            lefts.append(lefts[-1] - a[i])

        b = [0] * (n + 1)
        b[0] = 1

        for i in range(1, n + 1):
            b[i] = min(b[i-1] * 2 - a[i], lefts[i])

        if min(b) < 0:
            print(-1)
        else:
            print(sum(b) + sum(a))


Measured memory_bytes: 673704
#include <iostream>
#include <utility>
#include <string>

struct Dice
{
  int numbers[6];

  Dice (int n1, int n2, int n3, int n4, int n5, int n6) {
    numbers[0] = n1;
    numbers[1] = n2;
    numbers[2] = n3;
    numbers[3] = n4;
    numbers[4] = n5;
    numbers[5] = n6;
  }

  void move(char dir){
    if (dir == 'N') {
      setNum(numbers[1], numbers[0], numbers[2], numbers[5], numbers[3], numbers[4]);
    }
    if (dir == 'S') {
      setNum(numbers[4], numbers[5], numbers[2], numbers[0], numbers[3], numbers[1]);
    }
    if (dir == 'W') {
      setNum(numbers[2], numbers[4], numbers[5], numbers[1], numbers[0], numbers[3]);
    }
    if (dir == 'E') {
      setNum(numbers[3], numbers[4], numbers[0], numbers[1], numbers[5], numbers[2]);
    }
  }

  void roll(std::string dir){
    if (dir == "vertical") {
      setNum(numbers[1], numbers[0], numbers[2], numbers[5], numbers[3], numbers[4]);
    }
    if (dir == "horizontal") {
      setNum(numbers[0], numbers[2], numbers[1], numbers[3], numbers[4], numbers[5]);
    }
  }

  void setNum(int top, int north, int east, int south, int west, int bottom) {
    numbers[0] = top;
    numbers[4] = north;
    numbers[2] = east;
    numbers[1] = south;
    numbers[3] = west;
    numbers[5] = bottom;
  }
};

int main() {
  int n1, n2, n3, n4, n5, n6;
  std::cin >> n1 >> n2 >> n3 >> n4 >> n5 >> n6;
  Dice dice(n1, n2, n3, n4, n5, n6);
  int n;
  std::cin >> n;
  while (n--) {
    int a, b;
    std::cin >> a >> b;
    if (a == dice.numbers[2] || a == dice.numbers[3]) {
      dice.roll("horizontal");
    }
    while (a != dice.numbers[0]) {
      dice.roll("vertical");
    }
    while (b != dice.numbers[1]) {
      dice.roll("horizontal");
    }
    std::cout << dice.numbers[2] << "\n";
  }
}


Measured memory_bytes: 3156
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    k,n=map(int,input().split())
    A=[int(_) for _ in input().split()]
    max_len=(k-A[-1])+A[0]
    for i in range(n-1):
        max_len=max(max_len,A[i+1]-A[i])
    print(k-max_len)

if __name__=='__main__':
    main()

Measured memory_bytes: 72180
n = int(input())
a, b = map(int, input().split())
p = list(map(int, input().split()))
res = [0] * 3
for item in p:
    if item <= a:
        res[0] += 1
    elif (item >= (a + 1)) and (item <= b):
        res[1] += 1
    elif item >= (b + 1):
        res[2] += 1
print(min(res))


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

int main(void){
    // Your code here!
    int N;
    cin >> N;
    vector<string> s(N);
    for (int i = 0;i < N ; i++) cin >> s.at(i);
    int M;
    cin >> M;
    vector<string> t(M);
    for (int i = 0;i < M ; i++) cin >> t.at(i);
    int res = 0;
    for (int i = 0;i < N ; i++) {
        int re = 0;
        for ( int j= 0;j < N ; j++){
            if (s.at(i) == s.at(j)) re++;
        }
        for ( int j= 0;j < M ; j++){
            if (s.at(i) == t.at(j)) re--;
        }
        res = max(res,re);
    }
    cout << res << endl;
}

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

using namespace std;

typedef long long ll;

struct node{
	ll val;
};

node t[(1 << 19) + 5];

void update(int root, int l, int r, int idx, ll val){
	if(l > r)
		return;
	if(l == r){
		t[root].val = val;
		return;
	}
	int mid = (l + r) / 2;
	if(idx <= mid){
		update(root * 2, l, mid, idx, val);
	}
	else{
		update(root * 2 + 1, mid + 1, r, idx, val);
	}
	t[root].val = max(t[root * 2].val, t[root * 2 + 1].val);
}

ll query(int root, int l, int r, int s, int e){
	if(l > r || l > e || r < s)
		return 0;
	if(l >= s && r <= e)
		return t[root].val;
	int mid = (l + r) / 2;
	ll q1 = query(root * 2, l, mid, s, e), q2 = query(root * 2 + 1, mid + 1, r, s, e);
	return max(q1, q2);
}

int n;
ll a[200005], h[200005], dp[200005];

int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for(int i = 1 ; i <= n ; ++i){
	cin >> h[i];
}
for(int i = 1 ; i <= n ; ++i){
	cin >> a[i];
}
for(int i = 1 ; i <= n ; ++i){
	dp[i] = query(1, 1, n, 1, h[i] - 1) + a[i];
	update(1, 1, n, h[i], dp[i]);
}
cout << *max_element(dp + 1, dp + n + 1) << endl;

return 0;
}



Measured memory_bytes: 9088
#include <iostream>

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int h, w;
	while(true) {
		cin>>h>>w;
		if(h==0&&w==0) break;
		for(int i=0; i<h; i++) {
			for(int j=0; j<w; j++) {
				if((i+j)&1) cout<<'.';
				else cout<<'#';
			}
			cout<<'\n';
		}
		cout<<'\n';
	}
	return 0;
}



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

int main() {
  int N; cin >> N;
  string str = "";
  while (N != 0) {
    /* N を 2 で割ったあまりを求める */
    int r = N % 2;
    if (r < 0) r += 2; // N がマイナスだと r がマイナスになったりするので 2 を足す

    /* N から余りを取り除いて -2 で割る */
    N = (N - r) / (-2);

    /* 答えに追加 */
    str += (char)('0' + r);
  }
  /* 向きが逆なので反転 */
  reverse(str.begin(), str.end());
  if (str == "") str = "0"; // N = 0 のときは空文字列になってしまうので例外処理
  cout << str << endl;
}


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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i) os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1) printEoln();
  if (suc == 2) printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U>
void chmax(T &a, U b) {
  if (a < b) a = b;
}

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

template <class T>
T Sq(const T &t) {
  return t * t;
}

signed main() {
  int A = read(), B = read(), ans;
  if (A < B) swap(A, B);
  print(max(A + A - 1, A + B));
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;
#define vi vector<int>
#define vl vector<long long>
#define vvi vector< vector<int> >
#define vvl vector< vector<ll> >
#define vp vector<P>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPD(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORD(i, a, b) for (int i = (int)(a); i >= (int)(b); i--)
#define INF 1e18
#define INFTY 1e9
const int mod = 1000000007;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

template<class T> bool chmax(T &a, const T & b) {
    if (a<b) {
        a = b;
        return true;
    }
    return false;
}

template<class T> bool chmin(T &a, const T & b) {
    if (a>b) {
        a = b;
        return true;
    }
    return false;
}

//cout << fixed << setprecision(10) << y << endl;
struct edge {int to, cost;};
vector< vector<edge> > es;

int gcd(int a, int b) {
    int r = a % b;
    if (r == 0) return b;
    return gcd(b, r);
}

ll lcm(ll a, ll b) {
    return a/gcd(a, b)*b;
}

int main() {
    ll n;
    cin >> n;
    vl a(n);
    REP(i, n) cin >> a[i];
    ll q;
    cin >> q;
    ll sum = 0;
    map<ll, ll> mp;
    REP(i, n) {
        sum += a[i];
        if (mp.find(a[i]) != mp.end()) {
            mp[a[i]] += 1;
        } else {
            mp[a[i]] = 1;
        }
    }

    REP(i, q) {
        ll b, c;
        cin >> b >> c;
        if (mp.find(b) == mp.end()) {
            cout << sum << endl;
            continue;
        }
        if (mp[b] == 0) {
            cout << sum << endl;
            continue;
        }
        if (mp.find(c) == mp.end()) {
            mp[c] = mp[b];
            sum += c*mp[c];
            sum -= b*mp[c];
            mp[b] = 0;
        } else {
            mp[c] += mp[b];
            sum += c*mp[b];
            sum -= b*mp[b];
            mp[b] = 0;
        }
        cout << sum << endl;
    }
    
    return 0;
}

Measured memory_bytes: 8648
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (ll i = 0; i < n; i++)
#define IREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i < b + 1; i++)
#define all(v) v.begin(), v.end()
#define SENTINEL 2000000000
#define NIL -1
using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template <class T>inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}

int main()
{
    int n;ll k;
    cin >> n >> k;
    vector<int> a(n);
    REP(i,n){
        cin >> a[i];
        a[i]--;
    }
    int now=0;
    vector<bool> v(n,false);
    v[now]=true;
    while(1){
        now=a[now];
        if(v[now]){
            break;
        }
        else{
            v[now]=true;
        }
    }
    int to_start=0;
    int tmp=0;
    while(tmp!=now){
        tmp = a[tmp];
        to_start++;
    }
    tmp=a[now];
    vector<int> ans;
    ans.push_back(now);
    while(tmp!=now){
        ans.push_back(tmp);
        tmp=a[tmp];
    }
    if(k<to_start){
        int tmp2=0;
        REP(i,k){
            tmp2=a[tmp2];
        }
        cout << tmp2+1 << endl;
        return 0;
    }
    k-=to_start;
    k%=ans.size();
    cout << ans[k]+1 << endl;
}

Measured memory_bytes: 4988
#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 <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
//#include <cctype>
#include <cstring>
//#include <ctime>
#include <iterator>
#include <bitset>
//#include <numeric>
//#include <list>
//#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


namespace{
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;

void mainmain(){
	int n;
	while(cin>>n,n){
		vector<pair<double,int> > v;
		rep(i,n){
			int a;
			double b,c;
			cin>>a>>c>>b;
			c/=100.0;
			v.PB(mkp(abs(22.0-b/c/c),a));
		}
		sort(ALL(v));
		cout<<v[0].S<<endl;
	}
}



}
main() try{
    mainmain();
}
catch(...){
}

Measured memory_bytes: 1272
import java.util.*; 
public class Main
{
    public static void main(String args[])
    {
        Scanner in=new Scanner(System.in);
        int k;
        k=in.nextInt();
        int a,b,i,num;
        a=in.nextInt();
        b=in.nextInt();
        num=a;
        for(i=num;i<=b;i++,num++)
        {
            if(i%k==0)
            {
                System.out.println("OK");
                System.exit(0);
            }
        }
        System.out.println("NG");
    }
}

Measured memory_bytes: 35668
N, M, X, Y = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]

x = sorted(x)
y = sorted(y)
#print(x[N-1])
#print(y[M-1])

for Z in range(Y+1):
    if X < Z and Y >= Z:
        if x[N-1] < Z:
            if y[0] >= Z:
                print('No War')
                exit()

print('War')


Measured memory_bytes: 3060
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
stf = 0

for i in range(N):
    stf += B[A[i] - 1]
    if A[i] - 1 == A[i - 1] and i > 0: 
        stf += C[A[i]-2]
        
        
print(stf)


Measured memory_bytes: 9136
import copy
import itertools

h,w,k = map(int, input().split())

field = []
for i in range(h):
  field.append(list(input()))
  
total = 0
for i in itertools.product([0,1], repeat=h):
  for j in itertools.product([0,1], repeat=w):
    count = 0
    temp = copy.deepcopy(field)
    for l in range(h):
      if i[l] == 1:
        temp[l] = ['.'] * w
    for l in range(w):
      if j[l] == 1:
        for m in range(h):
          temp[m][l] = '.'
    for l in range(h):
      count += temp[l].count('#')
    if count == k:
      total += 1
      
print(total)

Measured memory_bytes: 9352
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	int N = getint();

	int a = 0, b = 0, c = 0;
	ll kotae = 1;
	const int mod = 1e9 + 7;
	rep(i, N) {
		int m = getint();
		int cnt = (a == m) + (b == m) + (c == m);
		kotae *= cnt;
		if (!cnt) {
			printf("0");
			return 0;		
		}
		if (a == m) a++;
		else if (b == m) b++;
		else c++;
		if (kotae >= 3e18) kotae %= mod;
	}
	
	printf("%lld", kotae% mod);


	Would you please return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


const ll MOD = (ll)(1e9 + 7);
map<ll, ll> memo;

// #{ (a,b) | 0 <= a+b <= N && (a|b)==a }
ll rec(ll N) {
  if (memo.count(N) >= 1) return memo[N];
  if (N == 0) return 1;
  ll res = 0;
  // (a,b) == (0, 0)
  res += rec(N/2);
  // (a,b) == (1, 0)
  res += rec((N-1) / 2);
  // (a,b) == (1, 1)
  if (N >= 2) res += rec((N-2) / 2);
  res %= MOD;
  return memo[N] = res;
}
int main2() {
  memo.clear();
  ll N; cin >> N;
  ll ans = rec(N);
  cout << ans << endl;
  return 0;
}

int main() {
  // for (int n = 0; n <= 10; n++) {
    // cout << n << " " << rec(n) << endl;
  // }


  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


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

def calc_half(x):
    return x / 2

def check_even(x):
    return x % 2

def func(x, count):
    even_res = list(map(check_even, x))
    if 1 in even_res:
        return count
    x2 = list(map(calc_half, x))
    count += 1
    return func(x2, count)

count = func(a, 0)
print(count)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;


int main() {
    int M1, D1, M2, D2;
    cin >> M1 >> D1 >> M2 >> D2;
    if (M1 != M2) {
        cout << 1 << endl;
    }
    else {
        cout << 0 << endl;
    }
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;

int main(){
  int x, y; cin >> x >> y;

  cout << x + y / 2 << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef vector<vector<int> > Graph;
typedef pair<int, int> P; 
// MOD
//const int mod = 1000000007;
typedef long long ll;
long long INF = 1<<30;
long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
//int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
 
 
mint f(int n) {
  if (n == 0) return 1;
  mint x = f(n/2);
  x *= x;
  if (n%2 == 1) x *= 2;
  return x;
}
 
mint choose(int n, int a) {
  mint x = 1, y = 1;
  rep(i,a) {
    x *= n-i;
    y *= i+1;
  }
  return x / y;
}

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double PI=3.14159265358979323846;
bool seen[100][100];

bool memo[110];
bool flag;

int dist[100][100];

bool compare_f(pair<int, int> &x, pair<int, int> &y) {
  return x.second< y.second;
}


struct Unionfind{
    vector<int> par;

    Unionfind(int n) : par(n, -1){}

    int root(int x){
        if(par[x] < 0) return x;
        else return par[x] = root(par[x]);
    } 

    bool issame(int x, int y){
        return root(x) == root(y);
    }

    bool merge(int x, int y){
        x = root(x); y = root(y);
        if(x == y) return false;
        if(par[x]>par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x){
        return -par[root(x)];
    }
};

P s(int x){
    int a = x%10;
    int b = 0;
    while(x){
        b = x;
        b/=10;
    }
    return P(a, b);
}


int main() {
  int n=5;
  rep(i, n){
    int a; cin >> a;
    if(a == 0){
      i++;
      cout << i << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3676
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<iomanip>
#include<map>
#include<cstring>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vi vector<int>
#define vivi vector<vi>
const int INF = int(1e9);
typedef long long int ll;

/* -- template -- */
int main(){
    ll N;cin >> N;
    ll minv = N - 1;
    for(ll i = 1;i <= int(sqrt(N));++i){
        if(N % i == 0){
            minv = min(minv, (N / i) + i - 2);
        }
    }
    cout << minv;
}


Measured memory_bytes: 256