akhauriyash/Code-Regression huggingface dataset:
/*
    Problem 11
    https://atcoder.jp/contests/abc128/tasks/abc128_c
*/
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<int>> S(n); // switchとつながっているlightのlist
    vector<int> p(m);
    for (int i = 0; i < m; i++) {
        int k; cin >> k;
        for (int j = 0; j < k; j++) {
            int s; cin >> s;
            S[s - 1].push_back(i);
        }
    }
    for (int i = 0; i < m; i++) cin >> p[i];

    int ans = 0;
    // bit exhausive search
    for (int b = 0; b < (1 << n); b++) {
        vector<int> cnt(m);  // 点灯Switchの個数
        for (int i = 0; i < n; i++)
            if ((b >> i) & 1)
                for (int s : S[i]) cnt[s]++;
        // Judge
        bool can = true;
        for (int j = 0; j < m; j++) if (cnt[j] % 2 != p[j]) can = false;
        if (can) ans++;
    }
    cout << ans << '\n';
}

Measured memory_bytes: 3620
/*
    ____        __
   / __ \____  / /_  ____ _____ ___
  / /_/ / __ \/ __ \/ __ `/ __ `__ \
 / _, _/ /_/ / / / / /_/ / / / / / /
/_/ |_|\____/_/ /_/\__,_/_/ /_/ /_/
*/
#include<bits/stdc++.h>

typedef long long ll ;

#define X   first
#define Y   second
#define mp  make_pair
#define pii pair<int , int>
#define vec vector
#define vpii vector<pair<int , int>>
#define i_n   int i = 0 ; i< n ; i++
#define cn  int n ; cin>>n
#define file_io freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define cina int a[n] ; for(int i = 0 ; i < n ; i++) cin>>a[i]
#define pb push_back
#define SZ(x) ll(x.size())

using namespace std;
const int maxn = 1000*100+5 ;

int main()
{
	migmig ;
	int a , b ; 
	cin>>a>>b ; 
	if(a < b) swap(a, b) ; 
	int ans = 0 ; 
	ans+=a; 
	a-- ; 
	if(a < b) swap(a, b) ;
	ans += a ; 
	cout<<ans; 
	
}
//////
////////
///////////



Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(auto i=0;i<n;++i)
#define REPR(i,n) for(auto i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(auto i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d",&tmp);v.push_back(tmp);}}

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  int a, p;
  cin >> a >> p;

  p += a * 3;
  
  cout << p / 2 << endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#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;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
typedef long long ll;
int main()
{
  ll d; cin >> d;
  vector<ll> c(26);
  rep(i,26) cin >> c[i];
  vector<vector<ll>> s(d, vector<ll>(26));
  vector<ll> t(d);  
  rep(i,d) {
    ll smax = -1;
    rep(j,26) {
      cin >> s[i][j];
      if(smax <= s[i][j]) {
	smax = s[i][j];
	t[i] = j + 1;
      }
    }
  }

  rep(i,d) cout << t[i] << "\n";
  return 0;
}


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

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD 1000000007

int main()
{ FAST
    int a, h;
    cin >> a >>h;
    int ans = a/h;
    if(a%h != 0){
        ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF (1 << 29) * 2
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  double a, b;
  scanf("%lf%lf", &a, &b);
  printf("%d\n", (int)ceil(a / b));
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		sc.close();
		System.out.println(Math.min(N * A, B));
	}
}


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

vector<int> t[11111];
int c[11111], d[11111], x, m;
void f(int u, int v) {
	for (int w : t[v])
		if (w != u) f(v, w);
	d[v] = c[x++], m += d[v];
}
int main() {
	int n;
	cin >> n;
	for (int i = 1; i < n; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		t[a].push_back(b);
		t[b].push_back(a);
	}
	for (int i = 0; i < n; i++)
		scanf("%d", c + i);
	sort(c, c + n);
	f(0, 1);
	cout << m - d[1] << '\n';
	for (int i = 0; i < n; i++)
		cout << d[i + 1] << ' ';
	cout << endl;
	return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <vector>
#include <tuple>

using namespace std;

typedef long long ll;
#define rep(i, n) for(int i=0; i<(n); ++i)
const int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};

int H, W;
ll L;
vector<string> maze;
vector<vector<vector<ll> > > vis;

inline bool inrect(int x, int y){
    return 0 <= x && x < H && 0 <= y && y < W;
}

tuple<int, int, char> solve(){
    vis.assign(H, vector<vector<ll> >(W, vector<ll>(4, -1)));
    int x = 0, y = 0, d = 0;
    rep(i, H)rep(j, W)rep(k, 4)if(maze[i][j] == "NESW"[k]){
        x = i; y = j; d = k;
        break;
    }
    for(ll step=0; step<=L; ++step){
        if(vis[x][y][d] != -1){
            L = vis[x][y][d] + (L - step) % (step - vis[x][y][d]);
            break;
        }
        vis[x][y][d] = step;
        int nx = x + dx[d], ny = y + dy[d];
        while(!inrect(nx, ny) || maze[nx][ny] == '#'){
            (d += 1) %= 4;
            nx = x + dx[d]; ny = y + dy[d];
        }
        x = nx; y = ny;
    }
    rep(i, H)rep(j, W)rep(k, 4)if(vis[i][j][k] == L){
        x = i; y = j; d = k;
        break;
    }
    return make_tuple(x+1, y+1, "NESW"[d]);
}

int main(){
    while(cin >> H >> W >> L, H|W|L){
        maze.assign(H, "");
        rep(i, H)cin >> maze[i];
        int x, y; char d;
        tie(x, y, d) = solve();
        cout << x << ' ' << y << ' ' << d << '\n';
    }
    return 0;
}

Measured memory_bytes: 2004
import bisect
a, b, q = map(int, input().split())
s = [int(input()) for i in range(a)]
s.sort()
t = [int(input()) for i in range(b)]
t.sort()

"""
sとtのどちらを先にするか
左右どちらに走るか
の都合4パターンの最小値を選べばよい
"""

def minl(x):
    # sを選択
    idx = bisect.bisect_left(s, x)
    ret = 3*10**10
    if idx == 0:
        first = s[0] - x
        now = s[0]
        idx = bisect.bisect_left(t, now)
        if idx == 0:
            second = t[0] - now
        elif idx == b:
            second = now - t[b-1]
        else:
            second = min(now - t[idx-1], t[idx]-now)
        ret = min(ret, first+second)
    elif idx == a:
        first = x - s[a-1]
        now = s[a-1]
        idx = bisect.bisect_left(t, now)
        if idx == 0:
            second = t[0] - now
        elif idx == b:
            second = now - t[b-1]
        else:
            second = min(now - t[idx-1], t[idx]-now)
        ret = min(ret, first+second)
    else:
        for first_g in [s[idx-1], s[idx]]:
            first = abs(first_g - x)
            now = first_g
            idx = bisect.bisect_left(t, now)
            if idx == 0:
                second = t[0] - now
            elif idx == b:
                second = now - t[b-1]
            else:
                second = min(now - t[idx-1], t[idx]-now)
            ret = min(ret, first+second)
    
    # tを選択
    idx = bisect.bisect_left(t, x)
    if idx == 0:
        first = t[0] - x
        now = t[0]
        idx = bisect.bisect_left(s, now)
        if idx == 0:
            second = s[0] - now
        elif idx == a:
            second = now - s[a-1]
        else:
            second = min(now - s[idx-1], s[idx]-now)
        ret = min(ret, first+second)
    elif idx == b:
        first = x - t[b-1]
        now = t[b-1]
        idx = bisect.bisect_left(s, now)
        if idx == 0:
            second = s[0] - now
        elif idx == a:
            second = now - s[a-1]
        else:
            second = min(now - s[idx-1], s[idx]-now)
        ret = min(ret, first+second)
    else:
        for first_g in [t[idx-1], t[idx]]:
            first = abs(first_g - x)
            now = first_g
            idx = bisect.bisect_left(s, now)
            if idx == 0:
                second = s[0] - now
            elif idx == a:
                second = now - s[a-1]
            else:
                second = min(now - s[idx-1], s[idx]-now)
            ret = min(ret, first+second)
    return ret

for i in range(q):
    x = int(input())
    print(minl(x))

Measured memory_bytes: 16852
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
template <class T> void cumulative_sum( T array, size_t N );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;

template <typename T, typename K> struct P {
	T a; K b;
};
typedef struct {
	vector <int> to;
	bool is_visited = false;
} node;
typedef struct {
	int to;
	int cost;
	P <int, int> change;
} edge;

/*
 * @fn modpow
 * @brief O(logn): a^n % mod
 * @param a: 基数
 * @param n: 指数
 * @param mod: 法
 */
ll modpow( ll a, ll n, ll mod ) {
	ll res = 1;
	while (n > 0){
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int main( void ){
	int N; cin >> N;
	vector <int> vec( N, 0 );
	rep( i, 0, N ){
		int input; cin >> input;
		vec[(N-input)/2]++;
		vec[N-(N-input)/2-1]++;
	}
	rep(i,0,N){
		if (vec[i] != 2){
			cout << "0\n";
			return 0;
		}
	}
	cout << modpow(2, N/2, k_mod) << endl;
}

int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}


Measured memory_bytes: 640
use std::io::stdin;

fn main() {
    let mut st = String::new();
    stdin().read_line(&mut st).unwrap();
    let n:usize = st.trim().parse().unwrap();
    let mut st = String::new();
    stdin().read_line(&mut st).unwrap();
    let mut v:Vec<i32> = st.trim().split(" ").map(|x| x.parse().unwrap()).collect();
    let mut result:Vec<i32> = Vec::new();

    while result.len() < n {
        let mut c:usize = 0;
        let mut r:i32 = -1;
        for i in 0..n {
            if v[i] < 0 {
                c += 1;
            } else {
            	let num = (i+1-c) as i32;
                if v[i] == num {
                    r = i as i32;
                };
            };
        };
        if r >= 0 {
        	let num = r as usize;
            result.insert(0, v[num]);
            v[num] = -1;
        } else {
            result = [-1].to_vec();
            break;
        };
    };
    for i in result {
        println!("{}", i);
    };
}

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

int main() {
  int A, B;
  cin >> A >> B;
  
  int X = B - A;
  int count = 0;
  
  for (int i = 1; i < X; i++) {
    count += i;
  }
  
  cout << count - A << endl;
}

Measured memory_bytes: 256
#include <iostream>

#define NUM 1000000
using namespace std;

int main(void){
    int n[NUM];
    int num;
    bool check=false;
    
    cin >> num;
    n[0]=num;
    for (int i = 1; i <= NUM; i++){
        if(check==false){
            if(num%2==0){
                n[i]=num/2;
                num=num/2;
            }else{
                n[i]=(num*3)+1;
                num=(num*3)+1;
            }
            for (int j = 0; j < i; j++){
                if(n[i]==n[j]){
                check=true;
                cout <<i+1<<endl;
                }
            }
        }
    }
}

Measured memory_bytes: 256
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
    private static final PrintStream so = System.out;
    private static final Scanner     sc = new Scanner(System.in);

    public static void main(String[] args) {
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int max = Math.min(a, b);
        int min = Math.max(0, a + b - n);
        so.println(max + " " + min);
    }
}


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

N, M = (int(i) for i in input().split())
A = [int(i) for i in input().split()]

D = [0] * (N + 1)

temp = 0
for i in range(N):
    temp = (A[i] + temp) % M
    D[i] = temp

D.sort()

temp = 0
cc = 1
for i in range(N):
    if D[i] == D[i + 1]:
        cc += 1
    else:
        temp += cc * (cc - 1) // 2
        cc = 1
temp += cc * (cc - 1) // 2

print(temp)

Measured memory_bytes: 58736
#include <iostream>
 
using namespace std;
 
int main(){
  	int n;
	cin>>n;
  	if(n==1) cout<<"Hello World"<<endl;
  	else{
      int A,B;
      cin>>A;
      cin>>B;
      cout<<A+B<<endl;
    }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int n;

int main()
{

  cin >> n;
  vector<int> p(n);
  vector<int> q(n);
  vector<int> seq(n);
  rep(i, n) cin >> p[i];
  rep(i, n) cin >> q[i];
  rep(i, n) seq[i] = i+1;
  map<vector<int>, int> mp;
  do {
    mp[seq] = mp.size();
  } while(next_permutation(seq.begin(),seq.end()));
  cout << abs(mp[p] - mp[q]) << endl;
  
  return 0;
}

Measured memory_bytes: 8668
#include <bits/stdc++.h>
 
using namespace std ;
 
const int MAX = 5010 ;
 
int dp[MAX][MAX] ;
int arr[MAX] ;
int n , k;
int idx2 ;

bool check(int mid)
{
	if(arr[mid] >= k)
		return 0 ;
	memset(dp , -1 , sizeof(dp)) ;
	bitset<MAX>bit ;
	bit[0] = 1 ;
	for(int i = 0 ; i < n ; ++i)
	{
		if(i == mid || arr[i] >= k)
			continue ;
		bit |= (bit << arr[i]) ;
	}
	for(int i = k-arr[mid] ; i < k ; ++i)
		if(bit[i])
			return 0 ;
	return 1 ;
}

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>n>>k ;
	for(int i = 0 ; i < n ; ++i)
		cin>>arr[i] ;
	sort(arr , arr + n) ;
	int l = 0 , r = n-1 , ans = -1;
	while(l <= r)
	{
		int mid = (l + r) >> 1 ;
		if(check(mid))
			ans = mid , l = mid+1 ;
		else
			r = mid-1 ;
	}
	return cout<<ans+1<<"\n" , 0 ;
}

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

using ll = long long;
#define ALL(c) (c).begin(), (c).end()
const int MOD = 1000000007;

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

    int a = 0;
    int b = 0;
    for (const char c : s) {
        if (c == '(') {
            b++;
        } else {
            if (b > 0) {
                b--;
            } else {
                a++;
            }
        }
    }
    for (int i = 0; i < a; i++) {
        cout << "(";
    }
    cout << s;
    for (int i = 0; i < b; i++) {
        cout << ")";
    }
    cout << endl;
}


Measured memory_bytes: 256
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

const ll MODBASE = 1000000007LL;
const int MAXN = 300010;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

#include <atcoder/all>
using namespace atcoder;

int op(int a, int b) {
    return max(a, b);
}

int e() { return 0; }

int n, k, a[MAXN];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> k;
    FOR(i,1,n) cin >> a[i];
    segtree<int, op, e> st(300001);
    int res = 0;
    FOR(i,1,n) {
        int l = max(0, a[i] - k);
        int r = min(300000, a[i] + k);
        int x = st.prod(l, r+1) + 1;
        res = max(res, x);
        st.set(a[i], x);
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 9828
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>

#define REP(n) for(int i = 0;i < n;i++)
#define LLREP(n) for(long long int  i = 0;i < n;i++)
typedef long long int ll;
using namespace std;
#define MAX_A 100005

int main(){

    string s; 
    cin >> s;
    int a=0,b=0,c=0;
    for(int i = 0;i < s.length();i++){
        if(s[i] == 'a'){
            a++;
        }
        if(s[i] == 'b'){
            b++;
        }
        if(s[i] == 'c'){
            c++;
        }
    }
    if(a == 1 && b == 1 && c == 1){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
////////////////////////////////////////////////
int main()
{
    int n;
    string s;
    cin >> n >> s;
    char cnt = s[0];
    int ans = 1;
    for (char c : s)
    {
        if (c != cnt)
        {
            cnt = c;
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3756
#include<bits/stdc++.h>
using namespace std;
namespace maxflow
{
	#define inf 999999999
	struct edge
	{
		int to,nxt,f;
	}e[200001];
	int head[211];
	int edge_cnt;
	int s,t;
	void init(int s1,int t1)
	{
		s=s1,t=t1;
		edge_cnt=-1;
		memset(head,-1,sizeof(head));
	}
	void add(int u,int v,int f)
	{
		e[++edge_cnt].nxt=head[u];
		e[edge_cnt].to=v;
		e[edge_cnt].f=f;
		head[u]=edge_cnt;
	}
	void add_edge(int u,int v,int f)
	{
		add(u,v,f);
		add(v,u,0);
	}
	int dep[211];
	bool bfs(int s,int t)
	{
		memset(dep,0x3f,sizeof(dep));
		queue<int>q;
		q.push(s);
		dep[s]=0;
		while(!q.empty())
		{
			int u=q.front();
			q.pop();
			for(int i=head[u];i!=-1;i=e[i].nxt)
				if(e[i].f!=0)
				{
					int to=e[i].to;
					if(dep[to]>dep[u]+1)
					{
						dep[to]=dep[u]+1;
						q.push(to);
					}
				}
		}
		return dep[t]<inf;
	}
	int dfs(int u,int flow)
	{
		if(u==t) return flow;
		int use=flow;
		for(int i=head[u];i!=-1;i=e[i].nxt)
		{
			int to=e[i].to;
			if(use&&dep[to]==dep[u]+1&&e[i].f)
			{
				int f=dfs(to,min(e[i].f,use));
				use-=f;
				e[i].f-=f;
				e[i^1].f+=f;
			}
		}
		return flow-use;
	}
	int dinic()
	{
		int maxflow=0;
		while(bfs(s,t))
			maxflow+=dfs(s,inf);
		return maxflow;
	}
}
using namespace maxflow;
int c[101][101];
int a[101][101];
vector<int>rem[101][101];
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		{
			scanf("%d",&a[i][j]);
			rem[i][(a[i][j]+m-1)/m].push_back(a[i][j]);
		}
	for(int p=1;p<=m;p++)
	{
		init(0,210);

		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=n;j++)
				if(rem[i][j].size())
					add_edge(i,j+n+1,1);
			add_edge(s,i,1);
			add_edge(i+n+1,t,1);
		}
		dinic();
	//	printf("%d\n",dinic());
		for(int i=1;i<=n;i++)
		{
			int at=0;
			for(int j=head[i];j!=-1;j=e[j].nxt)
				if(e[j].f==0&&e[j].to>n+1)
					at=e[j].to-n-1;
			c[i][p]=rem[i][at].back();
			rem[i][at].pop_back();
		}
	//	for(int t=1;t<=n;t++)
	//		printf("%d ",c[t][p]);
	//	printf("\n");
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
			printf("%d ",c[i][j]);
		printf("\n");
	}
	for(int j=1;j<=m;j++)
	{
		for(int i=1;i<=n;i++)
			for(int k=i+1;k<=n;k++)
				if(c[k][j]<=c[i][j])
					swap(c[k][j],c[i][j]);
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
			printf("%d ",c[i][j]);
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
    
using namespace std;
typedef long long ll;
    
int main()
{
    char c[3][3];
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> c[i][j];
        }
    }
    cout << c[0][0] << c[1][1] << c[2][2];

    return 0;
}


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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

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

    string s1 = "";
    if (a > b) {
        rep (i, a) {
            s1 += to_string(b);
        }
    } else {
        rep (i, b) {
            s1 += to_string(a);
        }
    }
    cout << s1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;
const int MAX_K = 1000;

ll triangle[MAX_K];
void init_triangle()
{
    rep(i, 1, MAX_K)
        triangle[i] = i * (i-1);
}

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

    int k = lower_bound(triangle, triangle+MAX_K, 2*n) - triangle;
    // cout << k << ' ' << triangle[k] << endl;
    if (triangle[k] != 2*n)
    {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;

    // make subgroup
    vector<int> subgroup[k];
    int num = 1;
    rep(i, 0, k)
    {
        rep(j, 0, k-1-i)
        {
            subgroup[i].push_back(num);
            subgroup[i+j+1].push_back(num);
            ++num;
        }
    }
    cout << k << endl;
    rep(i, 0, k)
    {
        cout << k-1 << ' ';
        for (auto s: subgroup[i])
            cout << s << ' ';
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
 
const int N = (1e5) + 5;
vector<int> adj[N];
int n, m;
 
int memo[N];
 
int DP(int u) {
	if (adj[u].size() == 0) return 0;
	int &ret = memo[u];
	if (ret != -1) return ret;
	ret = 0;
	int sz = adj[u].size();
	for (int i = 0; i < sz; ++i) {
		int v = adj[u][i];
		ret = max(ret, 1 + DP(v));
	}
	return ret;
}
 
int main() {
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; ++i) {
		int u, v; scanf("%d %d", &u, &v);
		--u; --v;
		adj[u].push_back(v);
	}
	memset(memo, -1, sizeof memo);
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		ans = max(ans, DP(i));
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define fore(i, init, n) for(long long i = init; i < n; i++)
#define FIN ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
 
const int MAXN = 1e6+5;
int n, m, u, v, r, indegree[MAXN], dp[MAXN];
vector<int> graph[MAXN], roots;
bool visited[MAXN];

int dfs(int pos) {
    if (dp[pos] != -1) return dp[pos];
    dp[pos]++;
    fore(i,0,graph[pos].size())
        dp[pos] = max(dp[pos], dfs(graph[pos][i]) + 1);
    return dp[pos];
}

int main() {
    FIN;
    cin >> n >> m;
    memset(dp, -1, sizeof dp);
    fore(i,0,m) {
        cin >> u >> v;u--;v--;
        graph[u].push_back(v);
        indegree[v]++;
    }
    
    fore(i,0,n) {
        if (indegree[i] == 0) {
            r = max(r, dfs(i));
        }
    }
    cout << r << endl;

}

/*

8 9
1 2
1 3
3 5
5 6
6 7
7 8
8 2
8 4
2 4

*/

Measured memory_bytes: 37248
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <vector>
#include <math.h>
#include <bitset>
#include <cmath>
#include <set>

#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)
#define rep_r(i,s,n)for(int i = n-1;i>=s;i--)
#define rep_re(i,s,n)for(int i = n;i>=s;i--)
using namespace std;
typedef long long ll;
static const ll MOD = 1e9 + 7;
static const ll INF = 1e25;
static const ll MAX_N = 100001;
static const ll MAX_M = 100001;

ll c[100001];
int main() {
	string s; cin >> s;
	string t = s;
	ll k; cin >> k;
	rep(i, 0, s.size()) {
		c[i] = ('z' - 'a') - (s[i] - 'a') + 1;
	}
	rep(i, 0, s.size()) {
		if (s[i] != 'a' && k - c[i] >= 0) {
			k -= c[i];
			t[i] = 'a';
			c[i] = 0;
		}
	}

	if (k > 0) {
		t[s.size() - 1] += (char)(k % 26);
	}

	cout << t << endl;
	return 0;
}

Measured memory_bytes: 1408
#include <stdio.h>          // printf(), putchar(), scanf()

int
main(int argc, char **argv)
{
	short puzzle[9][9];
	char check[9][9];
	int n;
	enum {none, done, dupli} state[9];

	scanf("%d", &n);
	for (int u = 0; u < n; ++u)
	{
		for (int y = 0; y < 9; ++y)
		{
			for (int x = 0; x < 9; ++x)
				scanf("%hd", &puzzle[y][x]);
		}

		for (int y = 0; y < 9; ++y)
		{
			for (int x = 0; x < 9; ++x)
				check[y][x] = ' ';
		}

		for (int x = 0; x < 9; ++x)
		{
			for (int i = 1; i <= 9; ++i)
				state[i - 1] = none;

			for (int y = 0; y < 9; ++y)
			{
				int t = puzzle[y][x];
				if (state[t - 1] == none)
					state[t - 1] = done;
				else
					state[t - 1] = dupli;
			}

			for (int i = 1; i <= 9; ++i)
			{
				if (state[i - 1] == dupli)
				{
					for (int y = 0; y < 9; ++y)
					{
						if (puzzle[y][x] == i)
							check[y][x] = '*';
					}
				}
			}
		}

		for (int y = 0; y < 9; ++y)
		{
			for (int i = 1; i <= 9; ++i)
				state[i - 1] = none;

			for (int x = 0; x < 9; ++x)
			{
				int t = puzzle[y][x];
				if (state[t - 1] == none)
					state[t - 1] = done;
				else
					state[t - 1] = dupli;
			}

			for (int i = 1; i <= 9; ++i)
			{
				if (state[i - 1] == dupli)
				{
					for (int x = 0; x < 9; ++x)
					{
						if (puzzle[y][x] == i)
							check[y][x] = '*';
					}
				}
			}
		}

		for (int y = 0; y < 9; y += 3)
		{
			for (int x = 0; x < 9; x += 3)
			{
				for (int i = 1; i <= 9; ++i)
					state[i - 1] = none;

				for (int i = 0; i < 9; ++i)
				{
					int tx = x + i % 3, ty = y + i / 3;
					int t = puzzle[ty][tx];
					if (state[t - 1] == none)
						state[t - 1] = done;
					else
						state[t - 1] = dupli;
				}

				for (int i = 1; i <= 9; ++i)
				{
					if (state[i - 1] == dupli)
					{
						for (int j = 0; j < 9; ++j)
						{
							int tx = x + j % 3, ty = y + j / 3;
							if (puzzle[ty][tx] == i)
								check[ty][tx] = '*';
						}
					}
				}
			}
		}

		if (u != 0)
			putchar('\n');

		for (int y = 0; y < 9; ++y)
		{
			for (int x = 0; x < 9; ++x)
				printf("%c%d", check[y][x], puzzle[y][x]);

			putchar('\n');
		}
	}

	return 0;
}

Measured memory_bytes: 1704
def roundRobin(q, process, time)
  currentTime = 0
  loop do
    break if process.empty?
    p = process.shift
    t = time.shift
    if t <= q
      currentTime += t
      puts p + " " + currentTime.to_s
    else
      t -= q
      process.push p
      time.push t
      currentTime += q
    end
  end
end


if __FILE__ == $0
  n, q = gets.split.map(&:to_i)
  process = []
  time = []
  n.times do
    p, t = gets.chomp.split
    process << p
    time << t.to_i
  end
  roundRobin q, process, time
  end

Measured memory_bytes: 13928
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
using namespace std;

typedef pair<int,int> pii;
typedef long long ll;

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int m,n;
	cin >> n >> m;
	string g[n], p[m];
	rep(i,0,n)cin >> g[i];
	rep(j,0,m)cin >> p[j];
	bool ans = false;
	rep(i,0,n-m+1){
		rep(j,0,n-m+1){
			bool valid = 1;
			rep(r,0,m){
				rep(s,0,m){
					valid &= g[i+r][j+s] == p[r][s];
				}
			}
			ans |= valid;
		}
	}
	cout << (ans ? "Yes" : "No") << '\n';
}


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

const int maxn = 2e5+5;
int n, k, a[maxn], pre[maxn];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> n >> k;
    if (k == 1) {
        cout << 0 << '\n';
        return 0;
    }
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        a[i]--;
        pre[i] = (a[i] + pre[i-1]) % k;
    }
    map<int,int> mp;
    mp[0]++;
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        int add = mp[pre[i]];
        ans += add;
        mp[pre[i]]++;
        if (i-k+1 >= 0) mp[pre[i-k+1]]--;
    }
    cout << ans << '\n';
}



Measured memory_bytes: 11264
#include<bits/stdc++.h>
#define ll long long
#define inf(x) (ll)(1e##x)
using namespace std;
template<typename tn> void read(tn &a){
	tn x=0,f=1; char c=' ';
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	a=x*f;
}
const int mod = 924844033,N = 1001000;
namespace FFT{
	const int g = 5;
	int len,maxn,r[N];
	ll g1[N],g2[N];
	ll fp(ll a,ll k){
		ll ans=1;
		for(;k;k>>=1,a=(a*a)%mod)
			if(k&1) ans=(a*ans)%mod;
		return ans;
	}
	void build(int n){
		maxn=1;len=0;while(maxn<=n) maxn<<=1,len++;
		for(int i=0;i<maxn;i++) r[i]=r[i>>1]>>1|(i&1)<<len-1;
	}
	void NTT(ll *a,int tag){
		for(int i=0;i<maxn;i++)
			if(i<r[i]) swap(a[i],a[r[i]]);
		for(int mid=1;mid<maxn;mid<<=1){
			ll wn=fp(g,(mod-1)/mid/2);
			if(tag<0) wn=fp(wn,mod-2);
			for(int l=0;l<maxn;l+=mid<<1)
				for(int i=l,w=1;i<l+mid;i++,w=wn*w%mod){
					ll x=a[i],y=a[i+mid]*w;
					a[i]=(x+y)%mod; a[i+mid]=(x-y)%mod;
				}
		}
	}
	void mul(ll *a,ll *b){for(int i=0;i<maxn;i++) a[i]=a[i]*b[i]%mod;}
	void clear(ll *a,int bg=0){for(int i=bg;i<maxn;i++) a[i]=0;}
	void turn(ll *a,ll *b,int ed=maxn){memcpy(b,a,8*ed+8);}
	void iturn(ll *a,ll *b){ll inv=fp(maxn,mod-2);for(int i=0;i<maxn;i++) b[i]=a[i]*inv%mod;}
	void mult(ll *a,ll *b,ll *c,int n,int m){
		build(n+m);clear(g1);clear(g2);
		turn(a,g1,n);turn(b,g2,m);
		NTT(g1,1);NTT(g2,1);mul(g1,g2);NTT(g1,-1);iturn(g1,c);
	}
}
ll f[N],g[N],ifac[N],fac[N];
int s[N],n,h[N];
vector<int> e[N];
void dfs(int x,int dad){
	s[x]=1;
	for(int v:e[x]) if(v!=dad){
		dfs(v,x);s[x]+=s[v];
		h[s[v]]++;
	}
	if(dad) h[n-s[x]]++;
}
int main(){
	read(n);
	for(int i=1;i<n;i++){
		int x,y;read(x);read(y);
		e[x].push_back(y);
		e[y].push_back(x);
	}
	dfs(1,0);
	fac[0]=1;
	for(int i=1;i<=n;i++) fac[i]=fac[i-1]*i%mod;
	ifac[n]=FFT::fp(fac[n],mod-2);
	for(int i=n;i;i--) ifac[i-1]=ifac[i]*i%mod;
	for(int i=0;i<=n;i++) g[i]=FFT::fp(fac[n-i],mod-2);
	for(int i=0;i<=n;i++) f[i]=fac[i]*h[i]%mod;
	FFT::mult(f,g,f,n,n);
	for(int i=1;i<=n;i++){
		ll ans=fac[n]*ifac[i]%mod*ifac[n-i]%mod*n%mod;
		ans=(ans-f[n+i]*ifac[i])%mod;
		cout<<(ans+mod)%mod<<'\n';
	}
	return 0;
}

Measured memory_bytes: 78464
import java.util.*;

public class Main
{
	public static void main(String[] args)
	{
		int a, b;
		Scanner jin = new Scanner(System.in);
		while (jin.hasNextInt())
		{
			a = jin.nextInt();
			b = jin.nextInt();
			System.out.println(a + b);
		}
	}
}


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

int main(void) {
    int a[50] = {};
    int n;
    scanf("%d", &n);
    for(int i=0; i<n; i++){
        scanf("%d", &a[i]);
    }
    int tmpI=0, tmpN = 0, f = 0;
    for(int i=1; i<=n; i++){
        if(i == a[i-1]) continue;
        if(tmpI == 0){
            tmpI = i;
            tmpN = a[i-1];
            continue;
        }
        if(i == tmpN && a[i-1] == tmpI){
            continue;
        }
        printf("NO");
        f++;
        break;
    }
    if(f==0){
        printf("YES");
    }
    
    return 0;
}


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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n,k;
	cin >> n >> k;
	long long r,s,p;
	cin >> r >> s >> p;
	string str;
	cin >> str;
	
	long long res=0;
	for(int i=0;i<k;i++){
		vector<long long> dp(3);
		if(str[i]=='r'){
			dp[2]=p;
		}
		if(str[i]=='s'){
			dp[0]=r;
		}
		if(str[i]=='p'){
			dp[1]=s;
		}
		for(int j=i+k;j<n;j+=k){
			vector<long long> ndp(3);
			if(str[j]=='r'){
				ndp[0]=max(dp[1],dp[2]);
				ndp[1]=max(dp[0],dp[2]);
				ndp[2]=max(dp[0],dp[1])+p;
			}
			if(str[j]=='s'){
				ndp[0]=max(dp[1],dp[2])+r;
				ndp[1]=max(dp[0],dp[2]);
				ndp[2]=max(dp[0],dp[1]);
			}
			if(str[j]=='p'){
				ndp[0]=max(dp[1],dp[2]);
				ndp[1]=max(dp[0],dp[2])+s;
				ndp[2]=max(dp[0],dp[1]);
			}
			dp.swap(ndp);
		}
		res+=max(max(dp[0],dp[1]),dp[2]);
		//cout << res << "\n";
	}
	cout << res << "\n";
	return 0;
}

Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <list>
#include <bitset>
#include <vector>
using namespace std;

#define I64d_OJ

//#ifdef I64d_OJ
//#define LL __int64
//#endif // I64d_OJ
#ifdef I64d_OJ
#define LL long long
#endif // I64d_OJ

typedef unsigned LL ULL;
typedef unsigned uint;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<LL,LL> pLL;
typedef vector<int> vi;

inline int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-f; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}

#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define ls rt<<1
#define rs rt<<1|1
#define MID(a,b) (((LL)(a)+(LL)(b))>>1)
#define absx(a) ((a)<0?-(a):(a))
#define MK(a,b) make_pair(a,b)
#define PB(a) push_back(a)
#define lowbit(x) ((x)&-(x))

#define lc c[x][0]
#define rc c[x][1]

template< typename T >
inline void Max(T &a,T &b){if(a<b) a=b;}
template< typename T>
inline void Min(T &a,T &b){if(a>b) a=b;}

const double pi=(double)acos(-1.0);
const double eps=(double)1e-8;
const int INF = (int) 0x3f3f3f3f;
const int MOD = (int) 1e9+7;
const int MAXN =(int) 2e5+10;
const int MAXM = (int) 3e6+10;

///--------------------START-------------------------
LL ans[MAXN];

void work(){
    ans[0]=100;
    for(int i=1;i<=3760;i++){
        ans[i]=(LL)(1.01*ans[i-1]);
    }
    LL N; scanf("%lld",&N);
    for(int i=1;i<=3760;i++){
        if(ans[i]>=N){
            printf("%d\n",i);
            break;
        }
    }
}

///--------------------END-------------------------
int main(){
#ifdef NNever
//freopen("data.in","r",stdin);
///freopen("out.txt","w",stdout);
#endif // NNever
    work();
    return 0;
}








Measured memory_bytes: 3840
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        solve(System.in, System.out);
    }

    static void solve(InputStream is, PrintStream os) {
        // Your code here!
        Scanner scan = new Scanner(is);
        int N = scan.nextInt();
        int A[] = new int[N];

        for (int i = 0; i < N; i++) {
            A[i] = scan.nextInt();
        }

        if (N == 2) {
            os.println(Math.max(A[0], A[1]));
            return;
        }

        long zero[] = new long[N];
        long one[] = new long[N];
        long two[] = new long[N];

        int upperZero = 0;
        int upperOne = 0;
        if (N % 2 == 0){
            upperZero = N-1;
            upperOne = N;
        } else {
            upperZero = N-2;
            upperOne = N-1;
        }


        zero[0] = A[0];
        for(int i = 2; i < upperZero; i += 2) {
            zero[i] += zero[i-2] + A[i];
        }
        one[1] = A[1];
        for(int i = 3; i < upperOne; i += 2) {
            one[i] += Math.max(zero[i-3] + A[i], one[i-2] + A[i]);
        }

        two[2] = A[2];
        for(int i = 4; i < N; i += 2) {
            two[i] += Math.max(Math.max(A[i]+one[i-3], A[i]+zero[i-4]), two[i-2]+A[i]);
        }

        if(N%2 != 0)
            os.println(Math.max(Math.max(two[N-1], one[N-2]), zero[N-3]));
        else
            os.println(Math.max(one[N-1], zero[N-2]));
    }
}

Measured memory_bytes: 52856
import java.util.*

fun main(args : Array<String>) {
    val (h, w, k) = readLine()!!.split(" ").map { it.toInt() }
    val cc = Array(h) { readLine()!! }

    val hEntries = createEntryList(h)
    val wEntries = createEntryList(w)

    fun count(he: String, we: String): Int {
        var cnt = 0
        cc.forEachIndexed { hIdx, hLine ->
            if(he[hIdx] == '0') {
                hLine.forEachIndexed { wIdx, c ->
                    if (we[wIdx] == '0' && c == '#') cnt++
                }
            }
        }
        return cnt
    }


    var ans = 0
    hEntries.forEach { he ->
        wEntries.forEach { we ->
            if (count(he, we) == k) ans++
        }
    }

    println(ans)
}

fun createEntryList(len: Int): List<String> {
    val entries = mutableListOf<String>()
    val bfs = Stack<String>()
    bfs.push("0")
    bfs.push("1")

    while(bfs.isNotEmpty()) {
        val item = bfs.pop()

        if (item.length == len) {
            entries.add(item)
            continue
        }

        bfs.push("${item}0")
        bfs.push("${item}1")
    }

    return entries
}

Measured memory_bytes: 36908
#include <iostream>
#include <vector>
#include <string.h>
#include <stack>
#include <queue>
#include <algorithm>
#include <climits>
#include <cmath>
#include <map>
#include <set>
#include <assert.h>
#include <sstream>
#define REP(i,n) for(ll i=0;i<(n);i++)
#define MOD 1000000007
#define int long long
#ifdef int
const long long INF = LLONG_MAX / 10;
#else
const int INF = 1010101010;
#endif
using namespace std;
typedef long long ll;
typedef vector<vector<ll>> mat;
typedef pair<int, int> P;
//typedef pair<double, double> P;

#ifdef LOCAL
#define dump(...)                                         \
    do {                                                  \
        std::ostringstream os;                            \
        os << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; \
        print_to(os, ", ", "\n", __VA_ARGS__);            \
        std::cerr << os.str();                            \
    } while (0)
#define dump_(a)                                          \
    do {                                                  \
        std::ostringstream os;                            \
        os << __LINE__ << ":\t" << #a << " = [";          \
        print_to_(os, ", ", "]\n", all(a));               \
        std::cerr << os.str();                            \
    } while (0)
#else
#define dump(...)
#define dump_(...)
#endif

template <typename T>
void print_to(std::ostream &os, const char *, const char *tail, const T &fst) {
    os << fst << tail;
}
template <typename Fst, typename... Rst>
void print_to(std::ostream &os, const char *del, const char *tail, const Fst &fst, const Rst &... rst) {
    os << fst << del;
    print_to(os, del, tail, rst...);
}
template <typename Iter>
void print_to_(std::ostream &os, const char *del, const char *tail, Iter bgn, Iter end) {
    for (Iter it = bgn; it != end;) {
        os << *it;
        if (++it != end) {
            os << del;
        } else {
            os << tail;
        }
    }
}
template <typename Fst, typename... Rst>
void println(const Fst &fst, const Rst &... rst) {
    print_to(std::cout, "\n", "\n", fst, rst...);
}
template <typename Fst, typename... Rst>
void print(const Fst &fst, const Rst &... rst) {
    print_to(std::cout, " ", "\n", fst, rst...);
}
template <typename Iter>
void println_(Iter bgn, Iter end) {
    print_to_(std::cout, "\n", "\n", bgn, end);
}
template <typename Iter>
void print_(Iter bgn, Iter end) {
    print_to_(std::cout, " ", "\n", bgn, end);
}

// const int MOD = 1000000007;
namespace trush {
    int _ = (std::cout.precision(10), std::cout.setf(std::ios::fixed), std::cin.tie(0),
             std::ios::sync_with_stdio(0), 0);
}

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

int N;
int A[15];

int dfs(int i, int pro)
{
    if (i == N) {
        if (pro % 2 == 0) return 1;
        else return 0;
    }

    int res = 0;
    for (int j=-1; j<=1; j++) {
        res += dfs(i + 1, pro * (A[i] + j) % 2);
    }

    return res;
}

signed main()
{
    cin >> N;
    REP(i,N) {
        cin >> A[i];
    }

    cout << dfs(0, 1) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL n,a,b,c,d;int t;map<LL,LL>s;
LL dfs(LL n=1e18){
	if(!n)return 0;
	if(s.count(n))return s[n];
	LL&ans=s[n];
	ans=(1e15)/n<d?1e15:n*d;
	ans=min(ans,dfs(n/2)+a+(n%2)*d);
	ans=min(ans,dfs(n/3)+b+(n%3)*d);
	ans=min(ans,dfs(n/5)+c+(n%5)*d);
	ans=min(ans,dfs(n/2+1)+a+(2-n%2)*d);
	ans=min(ans,dfs(n/3+1)+b+(3-n%3)*d);
	ans=min(ans,dfs(n/5+1)+c+(5-n%5)*d);
	return ans;
}
void work(){
	cin>>n>>a>>b>>c>>d;
	s.clear();
	cout<<dfs(n)<<endl;
}
int main(){
	cin>>t;
	while(t--)work();
}

Measured memory_bytes: 4608
using System;
using System.Numerics;

namespace CodingForces
{
    static class Program
    {
        static void Main(string[] args)
        {
            BigInteger a = BigInteger.Parse(Console.ReadLine());
            BigInteger b = BigInteger.Parse(Console.ReadLine());

            if (a > b)
                Console.WriteLine("GREATER");
            else if (b > a)
                Console.WriteLine("LESS");
            else
                Console.WriteLine("EQUAL");
        }
    }
}


Measured memory_bytes: 13268
package main

import "fmt"

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

	e := make([]int, n)
	w := make([]int, n)
	for i, r := range s {
		if i > 0 {
			e[i] = e[i-1]
			w[i] = w[i-1]
		}
		if r == 'E' {
			e[i]++
			continue
		}
		w[i]++
	}

	ans := 1000000
	for i := 0; i < n; i++ {
		lw := 0
		if i > 0 {
			lw = w[i-1]
		}
		le := 0
		if i < n-1 {
			le = e[len(e)-1] - e[i]
		}
		if v := lw + le; v < ans {
			ans = v
		}
	}
	fmt.Println(ans)
}


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

int main(){
  int N;
  int ans = 0;
  cin >> N;
  string S;
  cin >> S;

  for(int i = 0; i < 1000; i++) {
    int c[3] = { i / 100, (i / 10) % 10, i % 10};
    int f = 0;
    for(int j = 0; j < N; j++) {
      if(S[j] == '0' + c[f]) f++;
      if(f == 3) break;
    }
    if(f == 3) ans++;

  }
  cout << ans;
    return 0;
}

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



int main()
{
	int A,B,C,D;

	cin >> A >> B >> C >> D;

	while (1) {
		C = C - B;

		if (C <= 0) {
			cout << "Yes";
			return 0;
		}
		A = A - D;

		if (A <= 0) {
			cout << "No";
			return 0;
		}
		


	}





	



}

Measured memory_bytes: 3612
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;


void main() {
    int h, w, n;
    //scan(h, w, n);
    scan(h);
    scan(w);
    scan(n);
    h = max(h, w);
    auto ans = (n + h - 1) / h;
    writeln(ans);
}




void scan(T...)(ref T args) {
    auto line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x > arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x < arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

void yes(bool ok, string y = "Yes", string n = "No") {
    return writeln(ok ? y : n);
}


Measured memory_bytes: 256
// I'm a f*cking looser
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fasino ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
#define asc(A) sort(A.begin(),A.end())
#define dsc(A) sort(A.begin(),A.end(),greater<ll>())
int main()
{
    fasino
    //#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin); 
    //#endif
    int x,n,tnp;
    cin>>x>>n;
    vector<int> A(n);
    set<int> st;
    for(int i=0;i<n;i++){
        cin>>A[i];
        st.insert(A[i]);
    }
    asc(A);
    if(n==0){
        int integer = x;
        cout<<x<<'\n';
        return 0;
    }
    int ans = INT16_MAX, integer;
    for(int i=min(A[0]-1,x-1);i<=max(A[n-1]+1,x+1);i++){
        if(st.find(i)==st.end()){
            if(abs(i-x)<ans){
                ans = abs(i-x);
                integer = i;
            }
            else if(abs(i-x)==ans){
                integer = min(i,integer);
            }
        }
    }
    cout<<integer;
    return 0;
}

Measured memory_bytes: 3660
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		String c1 = sc.next();
		String c2 = sc.next();
		if (c1.charAt(0) == c2.charAt(c2.length() - 1) && c2.charAt(0) == c1.charAt(c1.length() - 1)
				&& c1.charAt(1) == c2.charAt(1))
			System.out.println("YES");
		else
			System.out.println("NO");
		sc.close();
	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define rep(i,k,n) for(int i=k;i<=n;i++)
#define rep2(i,k,n) for(int i=k;i>=n;i--)
using namespace std;
typedef long long ll;
typedef double db;
const int N=105;
int n,W,v[N],w[N],f[N][505],ans=0;

int main(){
	scanf("%d%d",&n,&W);
	rep(i,1,n)scanf("%d%d",&w[i],&v[i]);
	rep(i,0,n-1){
		int k=w[i+1]-w[1];
		rep2(num,i,0){
			rep(j,0,300){
				f[num+1][j+k]=max(f[num+1][j+k],f[num][j]+v[i+1]);
			}
		}
	}
	rep(i,1,n){
		rep(j,0,300){
			if(1ll*W >= 1ll*i*w[1] + j){
				ans=max(ans,f[i][j]);
			}
		}
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 512
#include <stdio.h>

int main(){
    int n, i, sum=0, x;

    scanf("%d", &n);

    x = n;

    while(x != 0){
        sum += x % 10;
        x /= 10;
    }

    if(n % sum == 0)
        printf("Yes\n");
    else
        printf("No\n");
    
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int a,b,c,d,e,f,g,h,i;
  
  cin>>a>>b>>c>>d>>e;
  f=d-e;
  g=d+e;
  h=c-e;
  i=c+e;
  if(f>=0 && g<=b && h>=0 && i<=a){
    cout<<"Yes"<<"\n";
  }
  else{
    cout<<"No"<<"\n";
  }

  return 0;
}



Measured memory_bytes: 3208