akhauriyash/Code-Regression huggingface dataset:
n,m,x = list(map(int,input().split()))
a = list(map(int,input().split()))
num = 0
st = 0

for i in range(len(a)):
  #数直線上で初期の場所ｘの左側にある料金所をチェックする
  if a[i] < x < a[i+1]:
    st = a[i]

#振り返ってみてみるとこんなことはしなくていい。上と同様に回すのが正解。
for i in range(n+1):
  #例外処理…xが両端にあるとき０を出力する
  if st == 0:
    print("0")
    break

  if i in a:
    num += 1
  #i番目の数が与えられた配列に含まれていたら、料金所を通ったことになるのでnumに1加算
  if i == st:
    #iがstまでたどり着いた時、ｘ地点にたどり着いたことになるので探索を終了する。
    res_l = num
    #左側の料金所の数
    res_r = m - num
    #同様に右側
    print(min(res_l,res_r))
    #右左をmin()関数によって比較。小さい方を出力する。
    break
    #for文を抜ける。ちょっと軽くなるかなって…

#いい例ではないのであまり参考にしないでください。
#少なくともの改良点として、11行目の言葉そのままです。
#ｎの全探索をする必要はないです


Measured memory_bytes: 3064
//
// Created by 永徳泰明 on 2019-01-27.
//

#include <bits/stdc++.h>

typedef long long ll;

using namespace std;
#define dump(x)  cout << #x << " = " << (x) << endl;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define fill(x, y) memset(x,y,sizeof(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 999999999;

void readFromInputFile() {
#ifdef LOCAL
    static std::ifstream in("/Users/hoo/CLionProjects/for_atcoder/input");
    std::cin.rdbuf(in.rdbuf());
#endif
}

int main() {
    int n,a,b;
    cin>>n>>a>>b;

    int maxr, minr;

    maxr = min(a,b);
    minr = n-a-b > 0 ? 0 :  -(n-a-b);

    cout<<maxr<<" "<<minr<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(void){
    // Here your code !
    string str;
    cin >> str;
    int tmp = str.find("AC");
    if(tmp <= str.length()){
        cout <<"Yes" << endl;
    }else{
        cout <<"No" << endl;
    }
    return 0;
    
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
lis = [0]*n
for i in range(n-1):
    if a[i] > a[i+1]:
        lis[i] = -1
b = a[::-1]
for i in range(n-1):
    if b[i] < b[i+1]:
        if lis[n-i-1] == -1:
            pass
        else:
            lis[n-i-1] = 1
lis[-1] = -1
sw = 0
for i in range(1,n):
    if a[0] < a[i]:
        sw = 1
        break
    if a[0] > a[i]:
        sw = 0
        break
if sw == 1:
    lis[0] = 1
m = 1000
k = 0
for i in range(n):
    if lis[i] == 1:
        k += m//a[i]
        m = m%a[i]
    elif lis[i] == -1:
        m += k*a[i]
        k = 0
print(m)


Measured memory_bytes: 9252
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		var sc = new Scanner(System.in);
		var n = sc.nextInt();
		var d1 = new int[n];
		var d2 = new int[n];
		for (var i = 0; i<n; i++) {
			d1[i] = sc.nextInt();
			d2[i] = sc.nextInt();
		}
		sc.close();

		var count = 0;
		var result = false;
		for (var i = 0; i<n; i++) {
			if (d1[i] == d2[i]) {
				count++;
				if (count >= 3) {
					result = true;
				}
			} else {
				count = 0;
			}
		}
		System.out.println(result ? "Yes" : "No");
	}
}


Measured memory_bytes: 36128
import java.util.Scanner;
public class Main {
	public static void main(String[] args)throws Exception{
		Scanner stdIn=new Scanner(System.in);
		int X=stdIn.nextInt();
		long key[]=new long[501];
		for(long i=0;i<=500;i++){
			key[(int)i]=(long) Math.pow(i,5);
		}
		for(int i=0;i<=500;i++){
			for(int j=0;j<=500;j++){
				if(key[i]-key[j]==X){
					System.out.println(i);
					System.out.println(j);
					System.exit(0);
				}
				if(key[i]+key[j]==X){
					System.out.println(i);
					System.out.println(-j);
					System.exit(0);
				}
			}
		}
	}
}


Measured memory_bytes: 35888
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
const int INF = 2e9;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int n, m, a[MAXN];
bool check(int pos) {
	for (int i = 2 * pos + 1, j = 2 * n; i <= j; i++, j--)
		if (a[i] + a[j] < m) return false;
	return true;
}
int main() {
	read(n), read(m);
	for (int i = 1; i <= 2 * n; i++)
		read(a[i]);
	sort(a + 1, a + 2 * n + 1);
	int l = 0, r = n;
	while (l < r) {
		int mid = (l + r) / 2;
		if (check(mid)) r = mid;
		else l = mid + 1;
	}
	int ans = 0;
	for (int i = 1, j = 2 * l; i <= j; i++, j--)
		chkmax(ans, a[i] + a[j]);
	for (int i = 2 * l + 1, j = 2 * n; i <= j; i++, j--)
		chkmax(ans, a[i] + a[j] - m);
	writeln(ans);
	return 0;
}
//结论太神仙了

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define pb push_back
#define SZ(x) ((int)(x.size()))
#define FOR(i,s,n) for (ll i = (s); (i) < (n); ++i)
#define FORD(i,s,l) for (ll i = (s); (i) >= l; --i)
#define F first
#define S second
#define TC int __tc; cin >> __tc; FOR(case_num,1,__tc+1)
#define TEST(x,i) ((x)&(1ll<<(i)))
#define SET(x,i) ((x)|(1ll<<(i)))
#define FLIP(x,i) ((x)^(1ll<<(i)))
#define CLEAR(x,i) ((x)&~(1ll<<(i)))

const double pi = 4 * atan(1);
using namespace std;
typedef long long ll;

const ll MOD = 1000000007;
const int MAXN = 200005;

int dp[105][105];
int n;
int num[105];

int solve(int idx, int m) {
	if (idx == n) {
		return m == 0 ? -1000000 : 0;
	}
	int &ret = dp[idx][m];
	if (ret != -1) {
		return ret;
	}
	return ret = max(solve(idx+1,m), num[idx]+solve(idx+1,(m+num[idx])%10));
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	memset(dp,-1,sizeof dp);
	cin >> n;
	FOR(i,0,n){
		cin >> num[i];
	}
	cout << max(0,solve(0,0)) << "\n";
}


Measured memory_bytes: 3696
import copy
length, cap = map(int, input().split(" "))
dp = [0] * (cap + 1)
items = []
for _ in range(length):
    a, b = map(int, input().split(" "))
    items.append([a, b])

for item in items:
    v, w = item
    temp_dp = copy.copy(dp)
    temp_dp[w] = max(temp_dp[w], v)
    for j in range(cap):
        if temp_dp[j] and w + j <= cap:
            temp_dp[w + j] = max(temp_dp[w + j], v + temp_dp[j])
    dp = temp_dp
answer = max(dp)
print(answer)


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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] food = new int[m];
		Arrays.fill(food, 0);
		for(int i =0; i < n; i++) {
			int k = sc.nextInt();
			for(int j =0; j < k; j++) {
				food[sc.nextInt()-1]++;
			}
		}
		long count = Arrays.stream(food).filter(i -> i == n).count();
		System.out.println(count);
	}
}

Measured memory_bytes: 29184
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int x,y,z,k;cin>>x>>y>>z>>k;
    vector<long long> a(x),b(y),c(z),d(k);
    for(int i=0;i<x;i++)cin>>a[i];
    for(int i=0;i<y;i++)cin>>b[i];
    for(int i=0;i<z;i++)cin>>c[i];
    sort(a.begin(),a.end());reverse(a.begin(),a.end());
    sort(b.begin(),b.end());reverse(b.begin(),b.end());
    sort(c.begin(),c.end());reverse(c.begin(),c.end());
    priority_queue<long long> que1,que2;
    for(int i=0;i<k&&i<x;i++){
        for(int j=0;j<k&&j<y;j++){
            que1.push(a[i]+b[j]);
            //cout<<a[i]<<" "<<b[j]<<endl;
        }
    }
    
    for(int i=0;i<k;i++){
        d[i]=que1.top();que1.pop();
        //cout<<d[i]<<endl;
    }
    for(int i=0;i<k&&i<x*y;i++){
        for(int j=0;j<k&&j<z;j++){
            que2.push(d[i]+c[j]);
        }
    }
    for(int i=0;i<k;i++){
        cout<<que2.top()<<endl;
        que2.pop();
    }
}


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

int main(){
    ll n, k;
    cin>>n>>k;
    n %=k;
    if(n>llabs(n-k)){
        n=llabs(n-k);
    }
    cout<<n<<endl;
}

Measured memory_bytes: 3612
import java.io.PrintWriter

fun main(args: Array<String>) {
    PrintWriter(System.out).use { out ->
        solve(out)
        out.flush()
    }
}

fun solve(out: PrintWriter) {
    val k = readInteger()
    val (a, b) = readIntegerList()
    for (i in a..b) {
        if (i % k == 0) {
            println("OK")
            return
        }
    }
    println("NG")
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)


Measured memory_bytes: 36588
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

template <typename T>
void print_vec(const vector<T>& v, bool is_reverse=false, ll num=0){
  if(num == 0) num = (ll)v.size();
  cout << endl; cout << "i=  ";for(ll i=0; i<num; i++) cout << i << "   ";cout << endl;  
  cout << "    ";
  if(is_reverse) for(ll i=num-1; i>=0; i--){ cout<<v[i]; if(i!=0) cout<<"   ";}
  else for(ll i=0; i<num; i++){ cout<<v[i]; if(i!=num-1) cout<<"   ";}
  cout << endl;
}

// template <typename T>
// void print_pairvec(const vector<T> &v, ll num=0){
//   if(num == 0) num = (ll)v.size();
//   cout << endl; for(ll i=0; i<num; i++){ cout << v[i].first << " " << v[i].second << endl;}
// }
template <typename T>
void print_pairvec(const T &_pair, ll num=0){
  cout << endl; for(pair<ll, int> x: _pair){ cout << x.first << " " << x.second << endl;}
}

template <typename T>
void print_vec2(const vector<vector<T>>& v){
  cout << endl; cout << "       ";
  for(ll i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(ll i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(ll j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}

int cost(vector<int> vec, int length){
  int res = 0, sum = 0;
  res += ((int)vec.size()-1) * 10;//合成魔法を使う
  for(int x : vec) sum += x;
  res += abs(length - sum);
  // cout << "  res: " << res << endl;
  return res;
}
int main(){
  int N, A, B, C;
  cin >> N >> A >> B >> C;
  vector<int> bamb(N);
  for(int i=0; i<N; i++) cin >> bamb[i];

  const int INF = 1e9+1;
  int ans = INF;
  const int NUM = 16;
  // 4進数全探索
  // 8本をそれぞれをa, b, cノどれに使うか,あるいは使わないかの4通りで全探索 (4^8 = 2^16 = 65536通り) 
  for(int i=0; i<(1<<NUM); i++){
    bitset<NUM> bit(i);// 
    vector<int> a, b, c;
    for(int j=0; j<N; j++){
    if(bit[j] == 0  &&  bit[j+N] == 0) a.push_back(bamb[j]);
    if(bit[j] == 0  &&  bit[j+N] == 1) b.push_back(bamb[j]);
    if(bit[j] == 1  &&  bit[j+N] == 0) c.push_back(bamb[j]);
    // if(bit[j] == 1  &&  bit[j+1] == 1) ;
    }
    if((int)a.size()==0) continue;
    if((int)b.size()==0) continue;
    if((int)c.size()==0) continue; //これがないと 入力例3でcが0の長さの木から+1を100回くりかえす
    int yen = 0;
    yen += cost(a, A);
    yen += cost(b, B);
    yen += cost(c, C);
    ans = min(ans, yen);

    // if(yen == 110){
    //   cout << " A: " << A; cout << " a: "; print_vec(a);
    //   cout << " B: " << B; cout << " b: "; print_vec(b);
    //   cout << " C: " << C; cout << " c: "; print_vec(c);
    // }
    // if(yen == 110) cout << " ans: " << ans << " i: " << i << " bit: " << bit << " yen: " << yen << endl;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define Max(a, b) (a > b ? a : b)
#define Min(a, b) (a < b ? a : b)
#define ii pair<int, int>
#define fi first
#define se second
const int MAX = 300000; //2 * 10^5
const int MOD = 1000000007; //10^9 + 7
const int OO = 0x3f3f3f3f; // 0x3f3f3f3f;

int n;
vector<int> G[MAX];

int dfs(int v, int p)
{
	int ans = v * (n - v + 1);
	for(int &u : G[v])
		if(u != p)
		{
			int i = v, j = u;
			if(i > j) swap(i, j);
			ans -= (i * (n - j + 1));
			ans += dfs(u, v);
		}
	return ans;
}

int32_t main()
{
	cin >> n;
	for(int i = 1; i < n; i++)
	{
		int u, v;
		cin >> u >> v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	cout << dfs(1, -1) << '\n';

	return 0;
}

Measured memory_bytes: 32504
//Code by 27.
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<queue>
#include<map>
#include<stack>
#include<fstream>
#include<stdlib.h>
#include<set>
#include<climits>
#include<cmath> 
#include<memory.h> 
#include<sstream>
#include<time.h>
using namespace std;
const long long BIGER=1000000000000000;
const int BIG=1000000000;
const int MOD=1000000007;
int main()
{
	string st;
	cin>>st;
	for(int i=0;i<8;i++)
	{
		int t=0;
		t+=st[0]-'0';
		if((i>>0)&1)
		{
			t+=st[1]-'0';
		}
		else
		{
			t-=st[1]-'0';
		}
		if((i>>1)&1)
		{
			t+=st[2]-'0';
		}
		else
		{
			t-=st[2]-'0';
		}
		if((i>>2)&1)
		{
			t+=st[3]-'0';
		}
		else
		{
			t-=st[3]-'0';
		}
		if(t==7)
		{
			cout<<st[0];
			if((i>>0)&1)
			{
				cout<<"+";
			}
			else
			{
				cout<<"-";
			}
			cout<<st[1];
			if((i>>1)&1)
			{
				cout<<"+";
			}
			else
			{
				cout<<"-";
			}
			cout<<st[2];
			if((i>>2)&1)
			{
				cout<<"+";
			}
			else
			{
				cout<<"-";
			}
			cout<<st[3];
			cout<<"=7";
			break;
		}
	}
	return 0;
}

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

int main() {
	int a, b;
 	 cin >> a >> b;
 	 string str;

 	 int x;
 	 x = a*b;

 	 if(x/2 == (x-1)/2 ){
 		 str="Odd";
 	 }
 	else{
	 str="Even";
 	}

 	cout << str << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAX = 1e6;

bool isPrime[MAX + 1];

void prime() {
    fill(isPrime + 2, isPrime + MAX + 1, true);

    for (int i = 4; i <= MAX; i += 2)
        isPrime[i] = false;

    for (int i = 3; i * i <= MAX; i += 2)
        if (isPrime[i])
            for (int j = i * i; j <= MAX; j += i * 2)
                isPrime[j] = false;
}

void solve() {
    ll n; cin >> n;
    int ans = 0, cnt = 0;

    while (n % 2 == 0)
    {
        n /= 2;
        cnt++;
    }
    for (int i = 1; true; i++)
    {
        if (cnt >= i)
        {
            cnt -= i;
            ans++;
        }
        else break;
    }

    for (int i = 3; i <= MAX; i += 2)
    {
        if (isPrime[i])
        {
            cnt = 0;
            while (n % i == 0)
            {
                n /= i;
                cnt++;
            }
            for (int j = 1; true; j++)
            {
                if (cnt >= j)
                {
                    cnt -= j;
                    ans++;
                }
                else break;
            }
        }
    }

    if (n > MAX) ans++;
    cout << ans;
    return;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    prime();
    solve();
    return 0;
}

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

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

    int N, K; cin >> N >> K;
    vector<int> h(N);
    for (int i = 0; i < N; i++) cin >> h[i];
    sort(h.begin(), h.end());

    int ans = 1 << 30;
    for (int i = 0; i < N-K+1; i++) {
        ans = min(ans, h[i+K-1] - h[i]);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<'\n';
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b;
    cin>>a>>b;
    if(a>=13){
      cout<<b<<endl;
    }else if(6<=a && a<=12){
      cout<<b/2<<endl;
    }else{
      cout<<0<<endl;
    }
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace ABC132C
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] d = Console.ReadLine().Split().Select(int.Parse).OrderBy(e => e).ToArray();

            int center = (n / 2)-1;
            int res = 0;
            //for (int i = d[center]; i <= d[center+1]; i++)
            //{
            //    if (d.Where(e => e<i).Count() == d.Where(e => e >= i).Count())
            //    {
            //        res++;
            //    }
            //}
            Console.WriteLine(d[center+1] - d[center]);
        }
    }
}


Measured memory_bytes: 22112
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = vector<T>;
using vvi = vector<vector<int>>;

int main(){

  int N;
  cin >> N;

  int x1 = N/1.08;
  int x2 = x1 + 1;
  
  if(int(x1*1.08) == N)
    cout << x1 << endl;
  else if(int(x2*1.08) == N)
    cout << x2 << endl;
  else
    cout << ":(" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int a[4],b[4];
  while(cin >>a[0]>>a[1]>>a[2]>>a[3]>>b[0]>>b[1]>>b[2]>>b[3]){
    int hit = 0,blow = 0;
    for(int i=0; i<4; i++){
      if(a[i] == b[i]){hit++; a[i] = 10; b[i] = 11;}
    }
    for(int i=0; i<4; i++){
      for(int j=0; j<4; j++){
	if(a[i] == b[j]){blow++; a[i] = 10; b[j] = 11;}
      }
    }
    cout <<hit<<" "<<blow<<endl;
  }
  return 0;
}

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

int dist[101];
int p[101];
int mx[101];
vector<int> e[101];
void dfs(int x,int f,int dep){
	mx[dep] = max(mx[dep],(int) e[x].size()-1 + (f==0?1:0));
	for(int it:e[x])
		if(it!=f)
			dfs(it,x,dep+1);
}

long long int solve(int u,int v,int dep){
	memset(mx,0,sizeof mx);
	dfs(u,v,0);
	dfs(v,u,0);
	long long int ans = 1;
	for(int i=0;i<dep;i++)
		ans*=mx[i];
	return ans;
}

long long int gao(int u,int dep){
	dfs(u,0,0);
	long long int ans = 1;
	for(int i=0;i<dep;i++)
		ans*=mx[i];
	for(int it:e[u])
		ans=min(ans,solve(u,it,dep)*2);
	return ans;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	for(int i=1,u,v;i<n;i++)
		cin>>u>>v,e[u].emplace_back(v),e[v].emplace_back(u);
	queue<int> q;
	dist[1]=true,q.emplace(1);
	int last;
	while(!q.empty()){
		int x = q.front();q.pop();
		last=x;
		for(int it:e[x])
			if(!dist[it])
				dist[it]=true,q.emplace(it);
	}
	memset(dist,-1,sizeof dist);
	dist[last]=0;
	q.emplace(last);
	while(!q.empty()){
		int x = q.front();q.pop();
		last = x;
		for(int it:e[x])
			if(dist[it]==-1)
				p[it]=x,dist[it]=dist[x]+1,q.emplace(it);
	}
	int d = dist[last];
	int u = last;
	for(int i=0;i<d/2;i++)
		u=p[u];
	if(d&1){
		cout<<(d+1)/2<<' '<<2*solve(u,p[u],d/2)<<endl;
	}
	else{
		cout<<d/2+1<<' '<<gao(u,d/2)<<endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <bitset>

using namespace std;
typedef long long ll;

/////////////         modの計算

ll mod = 998244353;

ll mod_adjust(ll a) {//	余りをとる(0～mod-1に調整する)
	if (a > mod) {
		return a % mod;
	}
	if (a < 0) {
		a *= -1;
		a %= mod;
		return mod - a;
	}
	return a;
}
ll mod_add(ll a, ll b) {//	足し算
	ll k = mod_adjust((ll)a); k += mod_adjust((ll)b);
	k = mod_adjust(k);
	return (ll)k;
}
ll mod_sub(ll a, ll b) {//	引き算
	return mod_add(a, -b);
}
ll mod_multi(ll a, ll b) {//	掛け算
	ll k = mod_adjust((ll)a);
	k *= mod_adjust((ll)b);
	k = mod_adjust(k);
	return (ll)k;
}
ll mod_inv(ll a) {//	逆元
	ll k = (ll)mod_adjust((ll)a);
	if (k == 0) { return 0; }
	if (k == 1) { return 1; }
	ll p = mod, q = k, m = 0, n = 1, r, c;

	while (q > 1) {
		r = p % q;
		c = p / q;
		c = mod_adjust(m - n * c);
		p = q, m = n, q = r, n = c;
	}
	return (ll)mod_adjust(n);
}
ll mod_div(ll a, ll b) {//	割り算
	return mod_multi(a, mod_inv(b));
}
ll mod_pow(ll x, ll n) {//	累乗(logNオーダーなので速い)
	x = (ll)mod_adjust((ll)x);
	n = n % (mod - 1);
	if (n < 0) {
		return mod_pow(mod_div(1, x), -n);
	}
	if (n == 0) {
		return 1;
	}
	if (n == 1) {
		return (ll)mod_adjust((ll)x);
	}
	if (n % 2 == 0) {
		ll k = mod_pow(x, n / 2);
		return mod_multi(k, k);
	}
	else {
		ll k = mod_pow(x, n / 2);
		return mod_multi(mod_multi(k, k), x);
	}
}


int main() {
	ll N;
	cin >> N;
	ll* D = new ll[N];
	for (ll i = 0; i < N; i++) {
		D[i] = 0;
	}
	for (ll i = 0; i < N; i++) {
		ll d; cin >> d;
		if (i == 0 && d != 0) { cout << 0 << endl; return 0; }
		if (i != 0 && d == 0) { cout << 0 << endl; return 0; }
		D[d]++;
	}

	if (D[0] != 1) {
		cout << 0 << endl;
		return 0;
	}
	ll ans = 1;
	ll sum = 1;
	for (ll i = 1; i < N; i++) {
		ans = mod_multi(ans, mod_pow(D[i - 1], D[i]));
		sum += D[i];
		if (sum == N) { break; }
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
   ll a,b;
   cin>>a>>b;
   string s1="",s2="";
   for(int i=0;i<b;i++)
   {
       s1+=(to_string(a));
   }
   
   for(int i=0;i<a;i++)
   {
       s2+=(to_string(b));
   }
   if(s1<s2)
   cout<<s1;
   else
   cout<<s2;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define rep3(i, s, n) for (int i = s; i > (int)(n); i--)
#define all(obj) obj.begin(), obj.end()
#define db(x) cerr << #x << ":" << x << " "
#define dbl(x) cerr << #x << ":" << x << "\n"
#define dbv(vec) cerr << #vec << ":"; for (auto e : vec) cerr << e << " "; cout << "\n"
#define dbvv(vv) cerr << #vv << ":\n"; for (auto vec : vv) { for (auto e : vec) cerr << e << " "; cerr << endl; }
#define YN(f) cout << (f ? "YES" : "NO") << endl
#define Yn(f) cout << (f ? "Yes" : "No") << endl
#define yn(f) cout << (f ? "yes" : "no") << endl
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;

int main() {
	int K, N; cin >> K >> N;
	vector<int> A(N); rep(i, N) cin >> A.at(i);
	A.push_back(K + A[0]);
	dbv(A);
	vi B; rep(i, N) B.push_back(A[i + 1] - A[i]);
	dbv(B);
	int ans = K - *max_element(all(B));
	cout << ans << endl;	
}

Measured memory_bytes: 2828
#include <iostream>
#include <cstdlib>
#include <queue>
#include <vector>
#include <tuple>

using namespace std;

int main()
{
        int h, w;
        cin >> h >> w;
        queue<pair<int,int>> queue;
        vector<vector<int>> dmap;
        for (int i = 0; i < h; i++) {
                char c;

                dmap.emplace(dmap.end(), w, -1);
                for (int j = 0; j < w; j++) {
                        cin >> c;
                        if (c == '#') {
                                queue.push(make_pair(i, j));
                                dmap[i][j] = 0;
                        }
                }
        }

        int ans = -1;
        while (!queue.empty()) {
                int i,j;
                tie(i, j) = queue.front();
                queue.pop();

                ans = dmap[i][j];
                for (int di = -1; di <= 1; di++) {
                        for (int dj = -1; dj <=  1; dj++) {
                                if (di*dj != 0) continue;
                                int ii = i+di;
                                int jj = j+dj;
                                if (ii >= 0 && ii < h &&
                                    jj >= 0 && jj < w &&
                                    dmap[ii][jj] == -1) {
                                        dmap[ii][jj] = dmap[i][j] + 1;
                                        queue.push(make_pair(ii,jj));
                                }
                        }
                }
        }
        cout << ans << endl;
        return 0;
}


Measured memory_bytes: 12432
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(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 main() {
    string s, t;
    cin >> s >> t;
    ll m = s.size();
    ll n = t.size();
    reverse(s.begin(), s.end());
    reverse(t.begin(), t.end());
    string ans = s;
    string res = s;
    bool clear = false;
    for (ll i=0; i<(m); i++){
        if (clear) break;
        for (ll j=0; j<(n); j++){
            if (i+j>=m){
                res = s;
                break;
            }
            if (res[i+j]!=t[j] && res[i+j]!='?'){
                res = s;
                break;
            }
            res[i+j] = t[j];
            if (j==n-1){
                clear = true;
                ans = res;
                break; break;
            }
        }
    }
    if (!clear){
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
    reverse(ans.begin(), ans.end());
    rep1(i, m) if (ans[i] == '?') ans[i] = 'a';
    cout << ans << endl;
    //printf("%.12f", ans);
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    ll n, m, a, b;
    cin >> n >> m;
    vector<pair<ll,ll>> arr;
    for(int i = 0; i < n; i++) {
        cin >> a >> b;
        arr.push_back({a, b});
    }
    sort(arr.begin(), arr.end());
    ll cost = 0;
    for(int i = 0; i < n; i++) {
        if (arr[i].second <= m) {
            m -= arr[i].second;
            cost += arr[i].first * arr[i].second;
        } else {
            cost += arr[i].first * m;
            break;
        }
    }
    cout << cost << endl;

    return 0;
}




Measured memory_bytes: 2420
#include<stdio.h>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int n,a[105],i;
    while(~scanf("%d",&n))
    {
        int sum=0,sum1=0;
        for( i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
            sum+=a[i];
        }
        for( i=1;i<=n;i++)
        {
            sum1+=a[i];
            if(sum1>=sum-sum1)
               break;
        }
       if(sum1==sum-sum1)
        printf("0\n");
       else
       {
           int sum3=sum1-a[i];
           int Min=min(sum1-(sum-sum1),(sum-sum3)-sum3);
           printf("%d\n",Min);
       }
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
int arr[100000][3];
int dp[100000][3];
 
int32_t main()
{
	FIO;
	int n; cin>>n;
	for(int i = 0; i<n; i++)
		for(int j = 0; j<3; j++)
			cin>>arr[i][j];
 
	dp[0][0] = arr[0][0];
	dp[0][1] = arr[0][1];
	dp[0][2] = arr[0][2];
 
	for(int i = 1; i<n; i++)
	{	
		dp[i][0] = arr[i][0] + max(dp[i-1][1], dp[i-1][2]);
		dp[i][1] = arr[i][1] + max(dp[i-1][0], dp[i-1][2]);
		dp[i][2] = arr[i][2] + max(dp[i-1][0], dp[i-1][1]);
	}
 
	int ans = max({dp[n-1][0], dp[n-1][1], dp[n-1][2]});
  
  	cout << ans;
 
	return 0;
}


Measured memory_bytes: 8284
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fill(name, val) memset(name, val, sizeof(name));
#define mop(a, op, b)    (a%mod op b%mod)%mod
#define vll vector<ll>
#define vvll vector<vll>
#define mod 1000000007LL

/*	Author: 🆉🅴🅽🅾🅻🆄🆂	*/

ll n, x, y, dp[100001][2];	vvll g;
ll calc(ll i, ll pi, bool allowed){
	if(dp[i][allowed] != -1)	return dp[i][allowed];
	ll w = 1, b = allowed;
	for(auto x : g[i]){
		if(x == pi)	continue;
		w = mop(w, *, calc(x, i, 1));
		b = mop(b, *, calc(x, i, 0));
	}
	return dp[i][allowed] = mop(w, +, b);
}
int main(){
	fill(dp, -1);
	cin>>n;	g.resize(n+1);
	for(ll i = 1; i < n; i++){
		cin>>x>>y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	cout<<calc(1, 0, 1);
}

// Time: O(N)
// Space: O(N)

Measured memory_bytes: 18428
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,s,n) for(int i = s; i < n; i++)
#define all(a) (a.begin(),a.end())
typedef long long ll;
using Graph = vector<vector<int>>;
const int INF = 1000000007;
int main(){
  int n,k;
  cin >> n >> k;
  vector<int>v(n);
  rep(i,n)cin >> v[i];
  sort(v.begin(),v.end());
  int ans = 0;
  rep(i,k)ans += v[i];
  cout << ans << endl;
  return 0;
}


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

using namespace std;

#define INF 1000007
#define MOD 1000000007
#define int long long
#define maxn 100
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)

typedef std::pair<int, int> P;

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

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

int mpow(int N, int P, int M) //繰り返し自乗法
{
    if (P == 0)
        return 1;
    if (P % 2 == 0) {
        int t = mpow(N, P / 2, M);
        return t * t % M;
    }
    return N * mpow(N, P - 1, M) % M;
}

int counter(int x) //bit計算
{
    if (x == 0)
        return 0;
    return counter(x >> 1) + (x & 1);
}

vector<bool> prime(maxn + 1, true); //素数テーブル
void prime_table(void) {
    prime[0] = false;
    prime[1] = false;
    for (int i = 2; i * i <= maxn; i++) {
        if (!prime[i]) {
            continue;
        }
        for (int j = i + i; j <= maxn; j += j + i) {
            prime[j] = false;
        }
    }
}

bool IsPrime(int num) //素数判定
{
    if (num < 2)
        return false;
    else if (num == 2)
        return true;
    else if (num % 2 == 0)
        return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2) {
        if (num % i == 0) {
            return false;
        }
    }

    return true;
}

vector<int> divisor(int n) //約数列挙
{
    vector<int> ret;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i - 1);
            if (i * i != n) {
                ret.push_back((n / i) - 1);
            }
        }
    }
    sort(ret.begin(), ret.end());
    return (ret);
}

signed main() {
    int X,Y,Z;
    cin >> X >> Y >> Z;
    swap(X,Y);
    swap(X,Z);
    cout << X <<" "<<  Y << " " <<Z<<endl;

}


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


typedef long long ll;
struct LazySegmentTree
{
public:
	int n;
	vector<ll> node, lazy;

	LazySegmentTree(vector<ll> v)
	{
		int sz = (int)v.size();
		n = 1; while (n < sz) n *= 2;
		node.resize(2 * n - 1, 1e18);
		lazy.resize(2 * n - 1, 1e18);

		for (int i = 0; i < sz; i++) node[i + n - 1] = v[i];
		for (int i = n - 2; i >= 0; i--) node[i] = min(node[i * 2 + 1], node[i * 2 + 2]);
	}

	void lazyEvaluate(int k, int l, int r)
	{
		node[k] = min(node[k], lazy[k]);

		if (r - l > 1)
		{
			lazy[k * 2 + 1] = min(lazy[k * 2 + 1], lazy[k]);
			lazy[k * 2 + 2] = min(lazy[k * 2 + 2], lazy[k]);
		}
		//lazy[k] = 1e18;
	}

	void update(int a, int b, ll x, int k = 0, int l = 0, int r = -1)
	{
		if (r < 0) r = n;

		lazyEvaluate(k, l, r);
		if (b <= l || r <= a) return;
		if (a <= l && r <= b)
		{
			lazy[k] = min(lazy[k], x);

			lazyEvaluate(k, l, r);
		}
		else
		{
			update(a, b, x, 2 * k + 1, l, (l + r) / 2);
			update(a, b, x, 2 * k + 2, (l + r) / 2, r);
			node[k] = min(node[2 * k + 1], node[2 * k + 2]);
			//cerr<<k<<" "<<node[k]<<endl;
		}
	}

	ll find(int a, int b, int k = 0, int l = 0, int r = -1)
	{
		if (r < 0) r = n;
		lazyEvaluate(k, l, r);
		//cerr << l << " " << r<<" "<<a<<" "<<b << endl;
		if (b <= l || r <= a) return 1e18;
		if (a <= l && r <= b) return node[k];
		ll vl = find(a, b, 2 * k + 1, l, (l + r) / 2);
		ll vr = find(a, b, 2 * k + 2, (l + r) / 2, r);
		
		//cerr<<vl<<" "<<vr<<endl;
		node[k] = min(node[2 * k + 1], node[2 * k + 2]);
		return min(vl, vr);
	}
};

int main()
{
	int N, M; cin >> N >> M;
	vector<vector<pair<int, int>>>LR(N);
	for (int i = 0; i < M; i++)
	{
		int l, r, c;
		cin >> l >> r >> c;
		//r++;
		LR[l-1].push_back(make_pair(r, c));
	}

	vector<ll>DP(N);
	for (int i = 0; i < N; i++)DP[i] = 1e18;
	DP[0] = 0;
	LazySegmentTree lst(DP);

	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < LR[i].size(); j++)
		{
			lst.update(i, LR[i][j].first, lst.find(i, i+1) + LR[i][j].second);
		}
	}

	long long ans = lst.find(N - 1, N);
	if(ans == 1e18)ans = -1;
	cout<<ans<<endl;

	return 0;
}

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

int n,arr[1000000],arr2[1000000];

int main(){
	scanf("%d",&n);
	for(int i=0;i<n-1;i++){
		scanf("%d",&arr[i]);
	}
	arr2[0]=arr[0];
	for(int i=0;i<n;i++){
		if(i==n-1){
			arr2[i+1]=arr[i];
		}else{
			if(arr[i]<arr2[i]){
				arr2[i]=arr[i];
			}
			arr2[i+1]=arr[i];
		}
	}
	int sum;
	for(int i=0;i<n;i++){
//		printf("%d",arr2[i]);
		sum+=arr2[i];
	}
	printf("%d",sum);
	
	return 0;
} 

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

int main()
{
    ll L,R;
    cin>>L>>R;
    int ans = 2019;
    int l = L%2019;
    int r = R%2019;
    if(R-L > 2020)
    {
        cout<<0<<endl;
        return 0;
    }
    for (int i = l; i < r; i++)
    {
        for(int j = i+1;j<=r;j++)
        {
            ans = min(ans,(i*j)%2019);
        }
    }
    
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=100010;
int N,M,V,P;
int a[maxn];
bool chk(int mid){
    int lim=a[mid]+M;
    ll res=1ll*M*(V-(N-mid+1)-(P-1));
    for(int i=mid-1;i>=P;--i){
        if(lim-a[i]<0)return 0;
        res-=lim-a[i];
    }
    if(res>0)return 0;
    else return 1;
}
void solve(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin>>N>>M>>V>>P;
    for(int i=1;i<=N;++i)cin>>a[i];//scanf("%d",a+i);
    sort(a+1,a+N+1,greater<int>());
    int l=1+P,r=N,mid,ans=P;
    while(l<=r){
        mid=l+r>>1;
        if(chk(mid))l=(ans=mid)+1;
        else r=mid-1;
    }
    cout<<ans<<endl;
}
int main(){
    solve();

    return 0;
}

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

int main(){
  ll n, m, a;
  cin >> n >> m;

  rep(i, m){
    cin >> a;
    n-=a;
  }

  if(n<0){
    cout << "-1" << endl;
  }
  else{
    cout  << n << endl;
  }

  return 0;
}

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

void lcs( string X,string Y, int m, int n )  
{
	int dp[m+1][n+1];
	for(int i=0;i<m+1;i++)
	{
		for(int j=0;j<n+1;j++)
		{
			if(i==0 || j==0)
				dp[i][j]=0;
			else
			{
				if(X[i-1]==Y[j-1])
				{
					dp[i][j]=1+dp[i-1][j-1];
					
				}
					
				else
					dp[i][j]=max(dp[i-1][j], dp[i][j-1]);		
			}			
			
		}
	}
	 // Following code is used to print LCS 
   int index = dp[m][n]; 
  
   // Create a character array to store the lcs string 
   char lcs[index+1]; 
   lcs[index] = '\0'; // Set the terminating character 
  
   // Start from the right-most-bottom-most corner and 
   // one by one store characters in lcs[] 
   int i = m, j = n; 
   while (i > 0 && j > 0) 
   { 
      // If current character in X[] and Y are same, then 
      // current character is part of LCS 
      if (X[i-1] == Y[j-1]) 
      { 
          lcs[index-1] = X[i-1]; // Put current character in result 
          i--; j--; index--;     // reduce values of i, j and index 
      } 
  
      // If not same, then find the larger of two and 
      // go in the direction of larger value 
      else if (dp[i-1][j] > dp[i][j-1]) 
         i--; 
      else
         j--; 
   } 
  
   // Print the lcs 
   cout<< lcs; 
	cout<<endl;
	
	
}


/* Driver code */
int main()  
{  
   	string s,t;
	   cin>>s>>t;
	
      
    int m = s.length();  
    int n = t.length();  
      
    lcs( s,t, m, n ) ;  
      
    return 0;  
}

Measured memory_bytes: 35456
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <iostream>
#include <stdio.h>
#include <vector>
#include <functional>
#include <unordered_set>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <queue>
#include <stack>
#include <bitset>

using namespace std;

const int MOD = 998244353;

void Add(int& a, int b) {
	a += b;
	if (a >= MOD)
		a -= MOD;
}

const int N = 2e3 + 1;
int dp[2 * N][2 * N];
int cnt[2 * N][2];

int main()
{
	string s;
	cin >> s;
	int n = s.length();
	dp[0][0] = 1;
	for (int i = 1; i <= n; ++i) {
		char ch = s[i - 1];
		if (ch == '0') {
			cnt[i][0] = 2;
		} else if (ch == '1') {
			cnt[i][0] = cnt[i][1] = 1;
		} else {
			cnt[i][1] = 2;
		}
	}
	for (int i = 1; i <= 2 * n; ++i) {
		cnt[i][0] += cnt[i - 1][0];
		cnt[i][1] += cnt[i - 1][1];
	}
	for (int i = 0; i < 2 * n; ++i) {
		for (int red = 0; red <= i; ++red) {
			if (cnt[i + 1][1] >= (i + 1) - red) {
				Add(dp[i + 1][red], dp[i][red]);
			}
			if (cnt[i + 1][0] >= red + 1) {
				Add(dp[i + 1][red + 1], dp[i][red]);
			}
		}
	}
	int answer = 0;
	for (int red = 0; red <= 2 * n; ++red) {
		Add(answer, dp[2 * n][red]);
	}
	cout << answer << "\n";
	return 0;
}

Measured memory_bytes: 61440
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		if(64 <= N) {
			System.out.println(64);
		} else if(32 <= N) {
			System.out.println(32);
		} else if(16 <= N) {
			System.out.println(16);
		} else if(8 <= N) {
			System.out.println(8);
		} else if(4 <= N) {
			System.out.println(4);
		} else if(2 <= N) {
			System.out.println(2);
		} else {
			System.out.println(1);
		}
	}
}

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

int main(){
    int N,M;
    while(cin >> N >> M, N&&M){
        vector<int> taro,hana;
        int sumT = 0, sumH = 0, s;
        for(int i=0;i<N;i++){
            cin >> s;
            taro.emplace_back(s);
            sumT += s;
        }
        for(int i=0;i<M;i++){
            cin >> s;
            hana.emplace_back(s);
            sumH += s;
        }

        int a = -1,b = -1, MIN = 1e9;
        bool flg = false;
        for(int i=0;i<N;i++){
            for(int j=0;j<M;j++){
                int T = sumT - taro[i] + hana[j];
                int H = sumH - hana[j] + taro[i];
                //cout << T << " " << H << endl;
                if(T == H){
                    int card = taro[i] + hana[j];
                    if(MIN > card){
                        a = taro[i];
                        b = hana[j];
                        MIN = card;
                        flg = true;
                    }
                }
            }
            //if(flg) break;
        }

        if(!flg) cout << -1 << endl;
        else cout << a << " " << b << endl;
    }
}


Measured memory_bytes: 3056
import heapq

N, M = map(int, input().split())
item_list = list(map(lambda x: int(x)*(-1), input().split()))
heapq.heapify(item_list)

# 割引は出来るだけする
for i in range(M):
	temp_min = heapq.heappop(item_list)
	heapq.heappush(item_list, (-1)*(-temp_min//2))
print(-sum(item_list))

Measured memory_bytes: 14380
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
//const ll MOD=998244353;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);

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; }

//二項係数
const int MAX = 2010000;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long C(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 前処理 COMinit();
// 計算例 cout << COM(100000, 50000) << endl;

int main()
{
  COMinit();
  ll N,K; cin>>N>>K;
  if(N==K) {cout<<1<<endl; rep(i,K-1) cout<<0<<endl; return 0;}
  for(int i=1;i<=K;i++){
    ll T=2*C(N-K-1,i-1)+C(N-K-1,i);
    if(i>1) T+=C(N-K-1,i-2);
    T%=MOD;
    cout<<C(K-1,i-1)*T%MOD<<endl;
    //cout<<C(0,0)<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 50716
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int h=sc.nextInt();
        int w=sc.nextInt();
        boolean po[][]=new boolean[h][w];
        ArrayList<int[]>oder=new ArrayList<>();
        for(int i=0;i<h;i++){
            String s[]=sc.next().split("",0);
            for(int j=0;j<w;j++){
                po[i][j]=s[j].equals("#");
                if(s[j].equals("#"))oder.add(new int[]{j,i});
            }
        }
        
        boolean b=false;
        int count=0,count2=0;
        oder.add(new int[]{-1,-1});
        while(true){
            int[]o=oder.get(count2);
            count2++;
            if(o[0]==-1&&o[1]==-1){
                if(!b)break;
                b=false;
                count++;
                oder.add(new int[]{-1,-1});
            }   
            else{
                if(o[0]!=w-1){
                    if(!po[o[1]][o[0]+1]){
                        oder.add(new int[]{o[0]+1,o[1]});
                        po[o[1]][o[0]+1]=true;
                        b=true;
                    }
                }
                if(o[0]!=0){
                    if(!po[o[1]][o[0]-1]){
                        oder.add(new int[]{o[0]-1,o[1]});
                        po[o[1]][o[0]-1]=true;
                        b=true;
                    }
                }
                if(o[1]!=h-1){
                    if(!po[o[1]+1][o[0]]){
                        oder.add(new int[]{o[0],o[1]+1});
                        po[o[1]+1][o[0]]=true;
                        b=true;
                    }
                }
                if(o[1]!=0){
                    if(!po[o[1]-1][o[0]]){
                        oder.add(new int[]{o[0],o[1]-1});
                        po[o[1]-1][o[0]]=true;
                        b=true;
                    }
                }
                
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 87324
import java.util.*;

public class Main {
  public static void main(String[] args) {
    String text = new Scanner(System.in).nextLine();
    
    int length = 0;
    for (int ix = 0; ix < text.length(); ix++) {
	  for (int check = ix; check < text.length(); check++) {
        if (!isAcgt(text.charAt(check))) break;
        length = Math.max(length, 1 + (check - ix));
      }
    }
    
    System.out.println(length);
  }
            
  static boolean isAcgt(char letter) {
   return letter == 'A'
     || letter == 'C'
     || letter == 'G'
     || letter == 'T';
  }
}

Measured memory_bytes: 23124
// Stone Monument

#include <iostream>

using namespace std;

int main(){
	int a, b;
	cin >> a >> b;

	int dif = b - a, towerb = 0;

	for (int i = 1; i <= dif; ++i)
		towerb += i;

	cout << towerb - b << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
using namespace std;

int main()
{
   string a , b;
   cin >> a >> b;

   int ans=0 ;
   for(int i=0 ;i<a.size() ;i++)
   {
       if(a[i] != b[i]) ans++ ;
   }

      cout << ans ;

    return 0;
}

Measured memory_bytes: 3884
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  scanf("%d",&n);
  vector<double>dp(n+1);
  dp[0]=1;
  for(int j=0 ; j<n ; j++){
    double x;
    cin>>x;
    for(int i = j+1 ; i>=0 ; i--){
      dp[i]=(i==0 ? 0 : dp[i-1])*x + dp[i]*(1-x);
    }
  }
  double sum = 0;
  for(int i=n;i>=(n+1)/2;i--){
    sum = sum + dp[i];
  }
  cout<<setprecision(10)<<sum;
  return 0;
}


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

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if(a+b>=c-1){
    cout << b+c<<endl;
    // you can eat all c 
  }
  else {
    cout << a+b*2+1<<endl;
    // you can eat a+b+1 c's 
  }  
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int a, b, c;
    cin>>a>>b>>c;
    if(a<=b && a<=c)
    {
        if(b<=c) cout<<a<<" "<<b<<" "<<c;
        else cout<<a<<" "<<c<<" "<<b;
    }
    else
    if(b<=a && b<=c)
    {
        if(a<=c) cout<<b<<" "<<a<<" "<<c;
        else cout<<b<<" "<<c<<" "<<a;
    }
    else
    if(c<=a && c<=b)
    {
        if(a<=b) cout<<c<<" "<<a<<" "<<b;
        else cout<<c<<" "<<b<<" "<<a;
    }
    cout<<"\n";
    return 0;
}


Measured memory_bytes: 3080
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip>
using namespace std;
#define int long long

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

    int n; cin >> n;
    string s; cin >> s;

    vector<int> counte(n),countw(n);

    if(s.at(0) == 'E') counte.at(0) = 1;
    else countw.at(0) = 1;
    for(int i = 1;i < n;i ++){
        counte.at(i) = counte.at(i-1);
        countw.at(i) = countw.at(i-1);
        if(s.at(i) == 'E') counte.at(i) ++;
        else countw.at(i) ++;
    }

    int ans = 100000000000;
    ans = min(ans,counte.at(n-1)-counte.at(0));
    ans = min(ans,countw.at(n-2));

    for(int i = 1;i < n-1;i ++){
        ans = min(ans,countw.at(i-1) + counte.at(n-1)-counte.at(i));
    }

    cout << ans << endl;
}

Measured memory_bytes: 5396