akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

use std::cmp::min;

struct DepthFirstSearch {
    n: usize,
    h: Vec<i32>,
    memo: Vec<i32>,
}
impl DepthFirstSearch {
    fn rec(&mut self, step: usize) -> i32 {

        let n = self.n;

        if self.memo[step] != -1 {
            return self.memo[step];
        }

        let res = if step == n - 1 {
            0
        } else if step == n - 2 {
            (self.h[n - 1] - self.h[n - 2]).abs()
        } else {
            let val1 = self.rec(step + 1) + (self.h[step + 1] - self.h[step]).abs();
            let val2 = self.rec(step + 2) + (self.h[step + 2] - self.h[step]).abs();
            min(val1, val2)
        };
        self.memo[step]  = res;
        res

    }
}

fn main() {
    input! {
        n: usize,
        h: [i32; n],
    }
    let memo = vec![-1; n];
    let mut dfs = DepthFirstSearch{ n: n, h: h, memo: memo };
    println!("{}", dfs.rec(0));


} 


Measured memory_bytes: 8956
N, M = gets.split.map(&:to_i)
array = Array.new(N + 1) { [] }

M.times do
  a, b = gets.split.map(&:to_i)

  array[a] << b
  array[b] << a
end



queue = [1]
result = Array.new(N, nil)


while queue.size > 0 do
  room = queue.shift
  array[room].each do |child|
    next unless result[child].nil?
    queue << child
    result[child] = room
  end
end

puts "Yes"
result.shift
result.shift
result.each do |stone|
  puts stone
end


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

using namespace std;

int main()
{
    int N, L;
    cin >> N >> L;
    vector<string> S(N);
    for (int i = 0; i < N; i++) {
        cin >> S[i];
    }

    sort(S.begin(), S.end());
    for (int i = 0; i < N; i++) {
        cout << S[i];
    }
    cout << endl;    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll gcd(int a,int b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(int a,int b){return a*b/gcd(a,b);}
const int INF=1e9;
const ll INFS=1e18;
const int MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);

int main() {
  int n,k;
  cin>>n>>k;
  vector<int> h(n);
  rep(i,n) cin>>h[i];
  sort(all(h));
  reverse(all(h));
  if(n<=k){
    cout<<0<<endl;
    return 0;
  }
  rep(i,k){
    h[i]=0;
  }
  ll ans=0;
  rep(i,n){
    ans+=h[i];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3988
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

constexpr ll mod = 998244353;
struct mint {
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    
    friend ostream &operator<<(ostream& os,const mint& a){
        return os << a.x;
    }

    friend istream &operator>>(istream& is,mint& a){
        ll t;
        is >> t;
        a = mint(t);
        return (is);
    }

    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M;
    cin >> N >> M;
    vvec<int> A(N,vec<int>(M));
    for(int i=0;i<N;i++) for(int j=0;j<M;j++) cin >> A[i][j];
    vec<mint> pow2(max(N,M)+1,1);
    for(int i=1;i<=max(N,M);i++) pow2[i] = pow2[i-1]*2;
    int rank = 0;
    for(int j=0;j<M;j++){
        bool update = false;
        for(int i=rank;i<N;i++) if(A[i][j]){
            swap(A[i],A[rank]);
            update = true;
            break;
        }
        if(update){
            for(int i=0;i<N;i++) if(i!=rank && A[i][j]){
                for(int k=j;k<M;k++) A[i][k] ^= A[rank][k];
            }
            rank++;
        }
    }
//    cerr << rank << "\n";
//    for(int i=0;i<N;i++) for(int j=0;j<M;j++) cerr << A[i][j] << (j!=M-1? " ":"\n");
    cout << pow2[N-1]*(pow2[M]-pow2[M-rank]) << "\n";
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(a,n) rep(i,0,n){ cout<<(i ? " ":"")<<a[i]; }cout<<endl;
#define pprint(a,m,n) rep(j,0,m){ print(a[j],n); }
const int mod = 1e9+7;
const int size=1e5;
const int INF=1e9;
int main(){
	int A,B;cin>>A>>B;
	cout<<(A+B-1)/A<<endl;
	return 0;
}


Measured memory_bytes: 3084
<?php
list( $x, $y, $z, $k ) = explode( " ", trim(fgets(STDIN)) );

$a = explode( " ", trim(fgets(STDIN)));
$b = explode( " ", trim(fgets(STDIN)));
$c = explode( " ", trim(fgets(STDIN)));
rsort( $a );
rsort( $b );
rsort( $c );

$ab =[];
for( $i=0; $i<$x; $i++ )
{
	for( $j=0; $j<$y; $j++ )
	{
		$ab[] = $a[$i]+$b[$j];
	}
}
rsort( $ab );

$max = min(3000,count($ab));
for( $i=0; $i<$max; $i++ )
{
	for( $j=0; $j<$z; $j++ )
	{
		$abc[] = $ab[$i]+$c[$j];
	}
}

rsort($abc);
$result = [];
for( $i=0; $i<$k; $i++ )
{ $result[] = $abc[$i]; }


echo implode( "\n",  $result );

Measured memory_bytes: 170460
# 天気予報
pred = input()

# 実際の天気
result = input()

# 天気予報が的中した回数をカウントする変数
count = 0

# 天気予報と実際の天気が一致したらcountを+1する
for i in range(len(pred)):
    if pred[i] == result[i]:
        count = count + 1

# 天気予報が的中した回数を出力
print(count)

Measured memory_bytes: 9032
/*問題文
1から Nの番号がついた N個の重りがあり、番号 iの重りの重さは Wiです。
ある整数 
1≤T<Nに対してこれらの重りを、番号が T以下の重り と 番号が Tより大きい重りの 2グループに分けることを考え、それぞれのグループの重さの和を S1,S2とします。
このような分け方全てを考えた時、S1 と S2の差の絶対値の最小値を求めてください。

制約
2≤N≤100
1≤Wi≤100
入力は全て整数である*/

#include<iostream>
#include<stdio.h>
#include <algorithm>

using namespace std;

int main(){
	int n,x;
	cin>>n>>x;
	int l[n];
	int d[n];
	int count=1;

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

	d[0]=0;

	for (int i = 0; i < n; ++i)
	{
		if(i<=n-1){
		d[i+1]=d[i]+l[i];
		if(d[i+1]<=x){
			count++;
		}
	}
	}

	printf("%d\n",count);
	return 0;
}




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

using namespace std;
const int MAXN = 100005;

int cnt[MAXN],dp[MAXN];

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	dp[1] = 1; dp[2] = 2;
	for(int i=3;i<MAXN;i++){
		dp[i] = dp[i/3+i%3];
	}
	int n; cin >> n;
	for(int i=0;i<n;i++){
		int a; cin >> a;
		cnt[a]++;
	}
	int ans = 0 , c = 0;
	for(int i=0;i<MAXN;i++){
		if(cnt[i]) ans++;
		if(dp[cnt[i]] == 2) c++;
	}
	if(c&1) ans--;
	cout << ans << '\n';
	return 0;
}


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

int main()
{
	int n = 0;
	long long tpmax = 0;

	cin >> n;
	vector<vector<bool>> f(n);
	vector<vector<long>> p(n);

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++) {			
			bool t;
			cin >> t;
			f[i].push_back(t);
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 11; j++) {
			long u;
			cin >> u;
			p[i].push_back(u);
		}
	}

	for (int i = 1; i < 1024; i++) {
		vector<int> k(n);
		long long tp = 0;

		for (int j = 0; j < n; j++) {
			int it = i;
			for (int u = 0; u < 10; u++) {
				k[j] += f[j][u] * (it % 2);
				it /= 2;
			}
			tp += p[j][k[j]];
		}
		if (i == 1)
			tpmax = tp;
		else if (tp > tpmax)
			tpmax = tp;
	}

	cout << tpmax << endl;

	return 0;
}

Measured memory_bytes: 256
n=int(input())
a = 1
b = 1
c = 1
m = 10**9 + 7

for i in range(n):
    a = (a*10)%m
    b = (b*9)%m
    c = (c*8)%m

d = (a - 2*b + c)%m
print(d)

Measured memory_bytes: 9100
// Problem : Crane and Turtle
// Contest : Virtual Judge - AtCoder
// URL : https://vjudge.net/problem/AtCoder-abc170_b
// Memory Limit : 1048 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")  // disable
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define lll __int128
#define lp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define vec(v, type, sz) vector<type> v(sz)
#define in(v) \
    for (auto &i : v) cin >> i
#define all(v) v.begin(), v.end()
#define prv(v)                         \
    for (auto i : v) cout << i << " "; \
    cout << "\n"
#define MOD 1000000007
#define INF 1000000000
#define INFL 1000000000000000000ll
#define fast_io                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define vi vector<int>
#define vl vector<ll>
#define vii(v, n, m, val) vector<vector<int>> v(n, vector<int>(m, val))
#define viii(v, i, j, k, val)        \
    vector<vector<vector<int>>> v(i, \
                                  vector<vector<int>>(j, vector<int>(k, val)))
#define pii pair<int, int>
#define pb push_back
#define file_io                       \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
#define testcases \
    int tcc;      \
    cin >> tcc;   \
    for (int tc = 1; tc <= tcc; tc++)
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while (!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(vector<string> __attribute__((unused)) args,
               __attribute__((unused)) int idx,
               __attribute__((unused)) int LINE_NUM) {
    cerr << endl;
}
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if (idx > 0)
        cerr << ", ";
    else
        cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss;
    ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef DB
#define debug(...) \
    debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

int main() {
    fast_io;
    int x,y; cin>>x>>y;
    int a=(4*x-y);
    if(a&1){
    	cout<<"No"; return 0;
    }
    a/=2;
    int b=x-a;
    if(a>=0 && b>=0) cout<<"Yes"; else cout<<"No";
}

Measured memory_bytes: 3604
#include<iostream>

using namespace std;

int main(){

    int n,f=0;

    cin>>n;

    for(int i=1;i<=9;i++){
        for(int j=0;j<=9;j++){
            if(i*j == n){
                f = 1;
                break;
            }
        }
    }

    if(f == 1) cout << "Yes" <<endl;
    else cout << "No" << endl;

    return 0;
}


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

int main(){
    string S; cin >> S;
    int N = S.size();

    int s[100010]; for (int i = 0; i < N; i++) {
        if ( S.at(i) == '0') s[i] = 0;
        if ( S.at(i) == '1') s[i] = 1;
    }

    int sum_0 = 0, sum_1 = 0;
    for (int i = 0; i < N; i++) {
        if (s[i] == 0) sum_0 ++; 
        else sum_1 ++;
    }

    cout << 2*(min(sum_0, sum_1)) << endl;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
vector<int> dx={1,0,-1,0},dy={0,1,0,-1};

int main(){
  int H,W,m=0;
  cin>>H>>W;
  int a[H][W];
  char s[H][W];
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>s[i][j];
      a[i][j]=(int)1e4;
    }
  }
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(s[i][j]=='.'){
        queue<pair<int,int>> q;
        q.push(pair<int,int>(i,j));
        a[i][j]=0;
        while(q.size()){
          pair<int,int> p=q.front();
          q.pop();
          for(int k=0;k<4;k++){
            int nx=p.second+dx[k],ny=p.first+dy[k];
            if(0<=nx&&nx<W&&0<=ny&&ny<H&&a[ny][nx]==(int)1e4&&s[ny][nx]=='.'){
              q.push(pair<int,int>(ny,nx));
              a[ny][nx]=a[p.first][p.second]+1;
              m=max(m,a[ny][nx]);
            }
          }
        }
        for(int y=0;y<H;y++){
          for(int x=0;x<W;x++) a[y][x]=(int)1e4;
        }
      }
    }
  }
  cout<<m<<endl;
}


Measured memory_bytes: 764
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;

int main(){
	int n,m;
	while(cin>>n>>m,n){
		vector<int> c(n+1);
		REP(i,n)cin>>c[i+1];
		vector<int> a;
		REP(i,n+1)REP(j,n+1)a.push_back(c[i]+c[j]);
		sort(a.begin(), a.end());
		a.erase(unique(a.begin(),a.end()), a.end());
		int ans = 0;
		REP(i,a.size()){
			if(a[i] <= m){
				int t = m - a[i];
				vector<int>::iterator it = upper_bound(a.begin(), a.end(), t);
				it--;
				ans = max(ans, a[i] + *it);
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 4956
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<complex>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#include <numeric>
using namespace std;
using Complex = complex<double>;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
const double EPS = 1e-10;
double PI = acos(-1.0);
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)
 
 
//ntt
ll mod = 998244353;
ll root = 3;
ll wlist[30],iwlist[30];

ll modpow(ll a, ll n) {
	ll res = 1;
	a %= mod;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

vector<ll>dft(vector<ll>A,int N,int inverse){
	//bit reverse
	int h = 0;
	for (int i = 0; (1 << i) < N; i++)h++;
	for (int i = 0; i < N; i++) {
		int j = 0;
		for (int k = 0; k < h; k++) j |= (i >> k & 1) << (h - 1 - k);
		if (i < j) swap(A[i], A[j]);
	}
	//

	//butterfly 
	int cnt = 1;
	for (int b = 1; b < N; b *= 2) {
		ll w = (!inverse)?wlist[cnt]:iwlist[cnt];
		ll cur = 1;
		for (int j = 0; j < b; j++) {
			for (int k = 0; k < N; k += 2 * b) {
				ll s = A[j+k];
				ll t = A[j+k+b] * cur;
				A[j + k] = s + t;
				A[j+k+b] = s - t;
			}
			cur = (w * cur)%mod;
		}
		for (int i = 0; i < N; i++) {
			A[i] %= mod;
			if (A[i] < 0)A[i] += mod;
		}
		cnt++;
	}
	//

	if (inverse) {
		ll rev = modpow(N, mod - 2);
		for (int i = 0; i < N; i++)A[i] = (A[i] * rev) % mod;
	}

	return A;
}

vector<ll>ntt(vector<ll>A,vector<ll>B){
	//calculate Nth root
	ll P = mod;
	P--;
	int N = 1;
	int cnt = 0;
	while (P % 2 == 0) {
		N *= 2;
		cnt++;
		P /= 2;
		if (A.size() + B.size() <= N)break;
	}
	ll Nroot = modpow(root,P);
	ll rNroot = modpow(Nroot,N-1);
	//

	//make list of root
	ll cur = Nroot;
	ll rcur = rNroot;
	for (int i = cnt; i >= 0; i--) {
		wlist[i] = cur;
		iwlist[i] = rcur;
		cur = (cur*cur) % mod;
		rcur = (rcur*rcur) % mod;
	}
	//

	A.resize(N);
	B.resize(N);

	A = dft(A,N,0);
	B = dft(B,N,0);

	vector<ll>F(N);
	for (int i = 0; i < N; i++) {
		F[i] = (A[i] * B[i]) % mod;
	}
	return dft(F,N,1);
}
//nttここまで
 
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
 
	int N, M;
	cin >> N >> M;
	vector<ll>A(N), B(M);
	for (int i = 0; i < N; i++)cin >> A[i];
	for (int i = 0; i < M; i++)cin >> B[i];
 
	vector<ll>ans = ntt(A, B);
	for (int i = 0; i < N + M - 1; i++)cout << ans[i] << " ";
	puts("");
 
 
	return 0;
}

Measured memory_bytes: 44320
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  x <- unsafeTextToInt <$> T.getLine :: IO Int
  putStrLn $ if 30 <= x then "Yes" else "No"

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}


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

typedef long long ll;
const ll INF = 1e9, MOD = 1e9 + 7;
const double EPS = 1e-9, PI = 3.141592653589793;
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define all(v) (v).begin(), (v).end()

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n,a;
  cin >> n;
  deque<ll> dq;
  rep(i,n){
    cin >> a;
    if(i%2) dq.push_back(a);
    else dq.push_front(a);
  }
  if(n%2){
    rep(i,dq.size()) cout << dq[i] << ' ';
  }else{
    for(ll i=dq.size()-1;i>=0;i--) cout << dq[i] << ' ';
  }
  return 0;
}

Measured memory_bytes: 3840
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

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

		int[][][] buildingInfo = new int [4][3][10];
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());

		for (int i =0; i < n; i++) {
			String[] line = br.readLine().split(" ");
			int building = Integer.parseInt(line[0]);
			int floor = Integer.parseInt(line[1]);
			int room = Integer.parseInt(line[2]);
			int v = Integer.parseInt(line[3]);
			buildingInfo[building - 1][floor - 1][room - 1] += v;
		}

		String blank = " ";
		for (int i = 0; i< buildingInfo.length; i++) {
			for (int j = 0; j < buildingInfo[0].length; j++) {
				for (int k = 0; k < buildingInfo[0][0].length; k++) {
					System.out.print(blank + buildingInfo[i][j][k]);
				}
				System.out.println("");
			}
			if (i != buildingInfo.length - 1) {
				System.out.println("####################");
			}
		}
	}
}

Measured memory_bytes: 24776
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,k;cin >> a >> b >> c >> k;
  int f = 0;
  while(a >= b){
    b *= 2;f++;
  }
  while(b >= c){
    c *= 2;f++;
  }
  cout << ((f <= k) ? "Yes\n":"No\n");
}

Measured memory_bytes: 3620
def c_repsept():
    K = int(input())

    if (K % 2 == 0 or K % 5 == 0):
        return -1  # repsept の因数に 2, 5 はない

    repsept = 7 % K
    count = 1
    while repsept % K !=0:
        repsept = ((repsept * 10) + 7) % K
        count += 1
    return count

print(c_repsept())

Measured memory_bytes: 9088
#include<iostream>
 #include<algorithm>
 #include<cmath>
 #include<iomanip>
 #include<string.h>
 #include<cmath>
 #include<map>
 #include<vector>
using namespace std;
typedef long long ll;
char s[4005];
bool vis[105];

int main()
{
    int n,k,d,mid;
    cin>>n>>k;
    for(int i=0;i<k;i++)
    {
        cin>>d;
        while(d--)
        {
            cin>>mid;
            vis[mid]=1;
        }
    }
    
    int count=0;
    for(int i=1;i<=n;i++)
    {
        if(vis[i]==0) count++;
    }
    cout<<count;
    return 0;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define Would
#define you
#define please

int main() {

	int N, K;
	cin >> N >> K;
	long long kotae = 0;

	if (K % 2 == 1) {
		kotae = pow((N / K), 3);
	}
	else {
		int amari = 2 * N / K - 2 * (N / K);
		kotae = pow((N / K), 3) + pow((N / K + amari), 3);
	}
	cout << kotae << "\n";
	Would you please return 0;
}

Measured memory_bytes: 384
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
typedef long long ll;
const int INF = 1001001001;

int main() {
    int r;

    cin >> r;

    cout << r*r << endl;

    return 0;
    
}

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

int main(int argc, char const *argv[]){
    while(true){
        string s;
        getline(cin, s);
        if(s=="0") break;
        int ans=0;
        rep(i, s.size()) {
            ans += s[i] - '0';
        }
        cout << ans << endl;
    }

    return 0;
}



Measured memory_bytes: 3144
S=input()
S+='R'
A=[0]*len(S)
R=0
L=0
count=0

for i in range(len(S)-1):
    count+=1
    if S[i]=='R' and S[i+1]=='L':
        R=i
        L=i+1
    if S[i]=='L' and S[i+1]=='R':
        if count%2==0:
            A[R]=count//2
            A[L]=count//2
        else:
            if (i-R)%2==1:
                A[R] = count // 2
                A[L] = count // 2+1
            else:
                A[R] = count // 2+1
                A[L] = count // 2
        count=0

for i in range(len(A)-1):
    print(A[i], end=" ")

Measured memory_bytes: 4864
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>

using namespace std;

typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;

int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};

static const double EPS = 1e-8;

class Dice{
	int top;
	int left;
	int right;
	int bottom;
	int front;
	int rear;

public:
	Dice(){
		top = 1;
		front = 2;
		left = 3;
		bottom = 6;
		right = 4;
		rear = 5;
	}
	void rotateDice(string dir){
		if(dir == "north"){
			//top2fr
			//fr2bot
			//bot2rear
			//rear2top

			int tmp_front = top;
			int tmp_bottom = front;
			int tmp_rear = bottom;
			int tmp_top = rear;

			front = tmp_front;
			bottom = tmp_bottom;
			rear = tmp_rear;
			top = tmp_top;
		}

		else if(dir == "south"){
			//top2fr
			//fr2bot
			//bot2rear
			//rear2top

			int tmp_front = bottom;
			int tmp_bottom = rear;
			int tmp_rear = top;
			int tmp_top = front;

			front = tmp_front;
			bottom = tmp_bottom;
			rear = tmp_rear;
			top = tmp_top;
		}
		else if(dir == "west"){
			int tmp_bottom = left;
			int tmp_top = right;
			int tmp_left = top;
			int tmp_right = bottom;

			bottom = tmp_bottom;
			top = tmp_top;
			left = tmp_left;
			right = tmp_right;
		}

		else if(dir == "east"){
			int tmp_bottom = right;
			int tmp_top = left;
			int tmp_left = bottom;
			int tmp_right = top;

			bottom = tmp_bottom;
			top = tmp_top;
			left = tmp_left;
			right = tmp_right;
		}
	}

	int tellTop() const{
		return top;
	}
};

int main(){
	int n;
	while(~scanf("%d",&n)){
		if(n==0) break;
		Dice d;
		for(int i=0;i<n;i++){
			char buf[8];
			scanf("%s",buf);
			d.rotateDice(buf);
		}

		printf("%d\n",d.tellTop());
	}
}

Measured memory_bytes: 1232
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
int main() 
{
    int n,a,b,f=0;
    cin>>n>>a>>b;
    for(int i=a;i<=b;i++)
    {
        if(i%n==0)
        {f=1;break;}
    }
    if(f==1)
    cout<<"OK";
    else
    cout<<"NG";
}

    

Measured memory_bytes: 3636
import java.util.Scanner;

class Main {

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

  private static Scanner sc = new Scanner(System.in);

  private void run() {
    int a = Integer.parseInt(sc.next());
    int b = Integer.parseInt(sc.next());
    int c = Integer.parseInt(sc.next());
    int d = Integer.parseInt(sc.next());
    int e = Integer.parseInt(sc.next());
    int k = Integer.parseInt(sc.next());

    if (b - a > k || c - a > k || d - a > k || e - a > k || c - b > k || d - b > k || e - b > k || d - c > k || e - c > k || e - d > k) {
      System.out.println(":(");
    } else {
      System.out.println("Yay!");
    }
  }
}


Measured memory_bytes: 27032
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

vector<LL> s;
LL n, k;

bool countMask(LL mask) {
	LL ret = 0;
	//ANDを取れば、maskの1立ってるところが残り、0のところは消える
	for (auto x : s) {
		if ((x&mask) == mask) {
			ret++;
		}
	}

	if (ret >= k) {
		return true;
	}
	else {
		return false;
	}
}

int main() {

	//入力受け取り
	cin >> n >> k;
	vector<LL> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	//部分和の列挙

	//一番目の区切り決めて
	for (int i = 0; i < n; i++) {
		LL tmp = 0;
		//二番目の区切りを決める
		for (int j = i; j < n; j++) {
			tmp += a[j];
			s.push_back(tmp);
		}
	}

	//大きい桁から順番に、k個以上取れるか試す。
	//取れたら答えにそのビットを立てる。
	//以降試すときは、ビットを立てまま試すのがミソ
	LL mask = 0;
	for (int i = 40; i >= 0;i--) {
		LL tmp = mask | (1LL << i);
		if (countMask(tmp)) {
			mask |= (1LL << i);
		}
	}

	cout << mask << endl;


	return 0;
}

Measured memory_bytes: 6516
import java.util.*;
class Main{
  public static void main(String args[]){
  Scanner scn = new Scanner(System.in);
  int a = scn.nextInt();
  int b = scn.nextInt();
  if(a < 10 && b < 10){
    System.out.println(a*b);
  }else{
    System.out.println(-1);
  }
}
}

Measured memory_bytes: 21844
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REP_FROM(i, j, n) for (int i = (j); i < (n); ++i)

#define MOD 1000000007

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

struct UnionFind {
  vector<int> par;

  UnionFind(int n) : par(n, -1) {}
  void init(int n) { par.assign(n, -1); }

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

  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y)
      return;
    if (par[x] > par[y])
      swap(x, y);
    par[x] += par[y];
    par[y] = x;
  }

  bool same(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
  int size(int x) { return -par[root(x)]; }
};

signed main() {
  ios::sync_with_stdio(false);
  long long  n, m;
  string s;
  cin >> n >> m;
  long long a[m], b[m];
  REP(i, m) { cin >> a[i] >> b[i]; }
  UnionFind tree(n + 1);

  long long current = n * (n - 1) / 2;
  long long ans[m + 1];
  ans[m] = current;
  REP(i, m) {
    int j = m - i - 1;
    ans[j] = current;
    if (tree.same(a[j], b[j]))
      continue;
    long long lft = tree.size(a[j]);
    long long rgt = tree.size(b[j]);
    tree.unite(a[j], b[j]);
    current -= lft * rgt;
    ans[j] = current;
  }
  REP(i, m) { cout << ans[i + 1] << endl; }
  return 0;
}


Measured memory_bytes: 4096
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
using namespace std;
int main()
{
  int n,m;
  cin>>n>>m;

  int num=m/n;
  int ans;
  for(int i=num;i>=1;i--)
  {
    //iが最大公約数であると仮定
    //半端な分がiで割り切れれば良い
    if((m-i*n)%i==0)
    {
      ans=i;
      break;
    }
  }
  cout<<ans<<endl;

}

Measured memory_bytes: 256
def resolve():
    S = input()
    T = input()

    ans = 1000
    for i in range(len(S) - len(T) + 1):
        x = 0
        for j in range(len(T)):
            if S[i+j] != T[j]:
                x += 1
        ans = min(ans, x)
    print(ans)

if __name__ == "__main__":
    resolve()

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

using namespace std;

#define MAX_N 100000
int a[MAX_N];
int n;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    int i;
    for(i = 0; i < n; ++i){
        cin >> a[i];
    }
    sort(a, a + n);
    int counts = 0;
    i = 0;
    while(i < n){
        int j = i + 1;
        while(j < n && a[j] == a[i]){
            ++j;
        }
        counts += (j - i) & 1;
        i = j;
    }
    cout << counts << '\n';
    return 0;
}


Measured memory_bytes: 640
def main():
    n = int(input())
    a = list(map(int,input().split(' ')))
    cost = 100**2*100
    for i in range(-100,101):
        tmp = 0
        for j in a:
            if tmp >= cost:
                break
            tmp += (j-i)**2
        if cost > tmp:
            cost = tmp

    print(cost)

main()

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

/*BigInteger
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/rational.hpp>
namespace xxx = boost::multiprecision;
using Bint = xxx::cpp_int;
using Real = xxx::number<xxx::cpp_dec_float<1024>>;
*/

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

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

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

// bit_macro
#define Bit(n) (1LL << (n))
#define Bitset(a, b) (a) |= (1LL << (b))
#define Bitunset(a, b) (a) &= ~(1LL << (b))
#define Bitcheck(a, b) ((((a) >> (b)) & 1LL) == 1LL)
#define Bitcount(a) __builtin_popcountll((a))

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

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

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

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

signed main() {
  int N;
  cin >> N;
  string s[3];
  for (int i = 0; i < 3; i++) cin >> s[i];

  int ans = 0;
  for (int i = 0; i < N; i++) {

    vector<char> v;
    for (int k = 0; k < 3; k++) {
      v.push_back(s[k][i]);
    }
    sort(ALL(v));
    UNIQUE(v);

    int tmp = v.size();
    if (tmp == 2) ans++;
    if (tmp == 3) ans += 2;
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <deque>
#include <string>

using namespace std;

int main()
{
    int K; cin >> K;
    string sdigits[10];
    char cdigits[10];
    for(int i=0;i<10;i++){
        sdigits[i] = '0'+i;
        cdigits[i] = '0'+i;
    }
    deque<string> n;
    for(int i=1;i<10;i++){
        n.push_back(sdigits[i]);
    }

    int c = 0;
    string s;
    while(!n.empty()){
        c++;
        s = n.front(); n.pop_front();
        for(int i=0;i<=9;i++){
            if(abs(s[s.size()-1]-cdigits[i])<= 1){
                n.push_back(s+sdigits[i]);
            }
        }
        if(K==c){
            cout << s;
            break;
        }

    }



    return 0;
}


Measured memory_bytes: 13824
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
long double b;
ll a;
int main(){
	ios::sync_with_stdio(0);
	cin>>a>>b;
	ll ans=(ll)(a*b);
	cout<<ans;
	re 0;
}

Measured memory_bytes: 3764
K,N = map(int,input().split())
listA = list(map(int,input().split()))

listB = []
## last - first ##
sum = max(listA) - min(listA)
listB.append(sum)

## n - (n-1) ##
for i in range(1,N):
  out = listA[i] - listA[i-1]
  out = K - out
  listB.append(out)


print(min(listB))

Measured memory_bytes: 26420
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n; cin >> n;
  vector<int>h(n); for (int i = 0; i < n; i++) cin >> h[i];
  vector<int>dp(n + 1, 0);
  dp[2] = dp[1] + abs(h[1] - h[0]);
  for (int i = 3; i <= n; i++) {
    dp[i] = min(dp[i-1] + abs(h[i-1] - h[i-2]), dp[i-2] + abs(h[i-1] - h[i-3]));
  }
  cout << dp[n] << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
using namespace std;
 
int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    int tmp = 0;
    rep(i, 0, N) {
        cin >> A[i];
        tmp = tmp ^ A[i];
    }
    if (tmp){
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int sz = 5e5+5;

typedef pair <int,int> pii;
#define x first
#define y second

int a[sz], col[sz], bit[sz], ans[sz];
vector <pii> quers[sz];

int query(int x) {
   int res = 0;
   while(x < sz) {
      res += bit[x];
      x += x & (-x);
   }
   return res;
}

void upd(int x, bool f) {
   while(x) {
      if(f) bit[x]++;
      else bit[x]--;
      x -= x & (-x);
   }
}

int main() {
   int n, q;
   cin >> n >> q;
   for(int i=1; i<=n; i++) scanf("%d", &a[i]);
   for(int i=1; i<=q; i++) {
      int l, r;
      scanf("%d %d", &l, &r);
      quers[r].emplace_back(l, i);
   }
   for(int i=1; i<=n; i++) {
      int c = a[i];
      if(col[c]) upd(col[c], 0);
      col[c] = i;
      upd(col[c], 1);
      for(auto it : quers[i]) ans[it.y] = query(it.x);
   }
   for(int i=1; i<=q; i++) printf("%d\n", ans[i]);
}


Measured memory_bytes: 33152
#include <bits/stdc++.h>
using namespace std;
int s(int x,int y)
{
    if(x<=y)
	return y-x;
    else
	return x-y+2;
}
int main()
{
    int x,y;
    scanf("%d %d",&x,&y);
    printf("%d\n",min(s(x,y),min(s(-x,y)+1,min(s(x,-y)+1,s(-x,-y)+2))));
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=1e3+10;
const int mod=1e9+7;
char g[N][N];
int dp[N][N];
int h,w;

int main(){
    cin>>h>>w;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            cin>>g[i][j];
            dp[j][0]=0;
        }
        dp[0][i]=0;
    }
    
    dp[1][1]=1;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            if(g[i][j]!='#' and (i>1 or j>1)){
                dp[i][j]=(dp[i][j-1] + dp[i-1][j])%mod;
            }
        }
    }
    cout<<(dp[h][w])%mod<<'\n';
    return 0;
}

Measured memory_bytes: 8492
#include<iostream>
int main(){
	int a;
	long long int dp[101][101]={0};
	int x[101];
	std::cin>>a;
	for(int i=1; i<=a; i++)std::cin>>x[i];
	dp[1][x[1]]=1;
	
	for(int j=2; j<a; j++){
		for(int s=0; s<=20; s++){
			if(s+x[j]<=20 && s-x[j]>=0){
				dp[j][s]=dp[j-1][s-x[j]]+dp[j-1][s+x[j]];
			}
			else if(s+x[j]<=20 && s-x[j]<0){
				dp[j][s]=dp[j-1][s+x[j]];
			}
			else if(s+x[j]>20 && s-x[j]>=0){
				dp[j][s]=dp[j-1][s-x[j]];
			}
		}
	}
	std::cout<<dp[a-1][x[a]]<<std::endl;
	
	
	
	return 0;
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const LL Maxn = 100000 + 100;
LL N;
LL A[Maxn];
int main()
{
#ifdef hk_cnyali
	freopen("B.in", "r", stdin);
	freopen("B.out", "w", stdout);
#endif
	scanf("%lld", &N);
	for (LL i = 1; i <= N; ++i)
		scanf("%lld", &A[i]);
	LL Min = 2, Max = 2;
	for (LL i = N; i >= 1; --i)
	{
		Min = (Min - 1) / A[i] * A[i] + A[i];
		Max = Max / A[i] * A[i] + A[i] - 1;
	}
	if (Min > Max)
	{
		cout<<-1<<endl;
		return 0;
	}
	cout<<Min<<" "<<Max<<endl;
	return 0;
}

Measured memory_bytes: 1024
#!/usr/bin/env python3
# N,M = map(int,sys.stdin.readline().split())
# A = list(map(int,sys.stdin.readline().split()))
# A = [sys.stdin.readline() for _ in range(N)]
# A = [list(map(int,sys.stdin.readline())) for _ in range(N)]
# A = [int(sys.stdin.readline()) for _ in range(N)]
# S = sys.stdin.readline().rstrip()
# N = int(sys.stdin.readline())
import sys,bisect,math
from functools import reduce
sys.setrecursionlimit(15000)

N = int(sys.stdin.readline())
A = list(map(int,sys.stdin.readline().split()))

def lcm(x,y):
  return x*y // math.gcd(x,y)

print(reduce(lcm,A))


Measured memory_bytes: 6364
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <set>
#include <map>
#include <cassert>
#include <fstream>
#include <iomanip>

using namespace std;
int n, m;
vector<int> elem;
vector<int> erank;

int dfs(int num)
{
    if (elem[num] == num)
    {
        return num;
    }
    else
    {
        elem[num] = dfs(elem[num]);
        return elem[num];
    }
}

void unite(int a, int b)
{
    a = dfs(a);
    b = dfs(b);
    
    
    if (a == b)
    {
        return;
    }
    else
    {
        if (erank[a] < erank[b])
        {
            elem[a] = b;
        }
        else
        {
            if (erank[a] == erank[b])
            {
                erank[a]++;
            }
            elem[b] = a;
        }
    }
}

int main() {
    
    
    int n, m;
    cin >> n >> m;
    
    elem = vector<int>(n, 0);
    erank = vector<int>(n, 0);
    
    for (int i = 0; i < n; ++i)
    {
        elem[i] = i;
    }
    
    for (int i = 0; i < m; ++i)
    {
        int x, y, z;
        cin >> x >> y >> z;
        x--;
        y--;
        unite(x, y);
    }
    set<int> s;
    for (int i = 0; i < n; ++i)
    {
        s.insert(dfs(i));
    }
    
    cout << s.size() << endl;
    
    
    return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
   
using namespace std;
     
#define PB(x) push_back(x)
#define ALL(x) (x).begin(), (x).end()
#define ALLR(x) (x).rbegin(), (x).rend()
#define MP(x) make_pair(x);
    
#define debug(x) cerr << #x << '=' << x << endl;
#define debug2(x, y) cerr << #x << '=' << x << ' ' << #y << '=' << y << endl;
#define debugn(a) for (int x: a) cerr << x << ' '; cerr << endl;
#define debugm(a, n, m) for (int i = 0; i < n; i++, cout << endl)           \
						for (int j = 0; j < m; j++) cout << a[i][j] << ' ';

#define int long long
     
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<pair<int, int>> vii;
typedef vector<string> vs;
typedef unsigned long long ull;

const int INF = LONG_LONG_MAX;
const int NINF = LONG_LONG_MIN;
const int mmod = 1000000007;

int n, q;

vi adj[1000000];
int counter[1000000];
bool visited[1000000];

void dfs(int v) {
	visited[v] = true;
	for (int x: adj[v]) {
		if (!visited[x]) {
			counter[x] += counter[v];
			dfs(x);
		}
	}
}

int32_t main()
{
	cin >> n >> q;
	
	for (int i = 0; i < n-1; i++) {
		int a, b;
		cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	memset(counter, 0, sizeof counter);
	for (int i = 0; i < q; i++) {
		int p, x;
		cin >> p >> x;
		counter[p] += x;
	}
	memset(visited, 0, sizeof visited);
	dfs(1);
	for (int i = 1; i <= n; i++)
		cout << counter[i] << ' ';
	cout << endl;
}


Measured memory_bytes: 47104
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int size=1e5;
const int inf=1e9;
int main(){
	int N; long K;cin>>N>>K;
	long A[N],B[N];
	rep(i,0,N) cin>>A[i]>>B[i];
	long ans = 0, res = 0; long t = 0;
	for(int i = 29; i >= 0; i--){
		if(K & (1<<i)){
			res = 0;
			rep(j,0,N){
				res += B[j];
				for(int k = 29; k >= i; k--){
					if( (A[j] & (1<<k)) > (t & (1<<k)) ){ res -= B[j]; break; }
				}
			}ans = max(ans, res);
			t = t | (1<<i);
		}
	}
    res = 0;
    rep(j,0,N){
        res += B[j];
        for(int k = 29; k >= 0; k--){
            if( (A[j] & (1<<k)) > (K & (1<<k)) ){ res -= B[j]; break; }
        }
    }ans = max(ans, res);
    cout<<ans<<endl;
}

Measured memory_bytes: 1792
/**
*	created: 19.09.2020 00:25:33
**/
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
// #define endl '\n'
#define int long long
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define rrep(i,n) for (int i = (int)(n - 1); i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
using ll = long long;
using P = pair<int,int>;
const long double pi = acos(-1.0);
const int MAX = 1000010;
const int INF = 1ll << 60;
const int MOD = 1000000007;
// const int MOD = 998244353;
template<typename T> inline bool chmax(T &a, T b) {if (a < b) {a = b; return 1;} return 0;}
template<typename T> inline bool chmin(T &a, T b) {if (b < a) {a = b; return 1;} return 0;}
template<typename T> T pow(T a, ll n) {T r(1); while(n) {if (n & 1) r *= a; a *= a; n >>= 1;} return r;}
struct faster_io {faster_io() {cin.tie(0); ios_base::sync_with_stdio(false);}} faster_io_;

// Dijkstra's Algorithm（単一始点最短経路問題）
struct graph {
    struct edge {
        int to, cost;
        edge(int t, int c) : to(t), cost(c) {}
    };
    int n;
    vector<vector<edge>> G;
    vector<int> d, pre;
    graph(int i) : n(i), G(i), d(i,INF), pre(i) {}
    void add_edge(int s, int to, int cost) {
        G[s].push_back(edge(to,cost));
    }
    void dijkstra(int s) {
        rep(i,n) {d[i] = INF; pre[i] = 0;}
        d[s] = 0;
        priority_queue<P, vector<P>, greater<P>> que;
        que.push(P(0,s));
        while(!que.empty()){
            P p = que.top(); que.pop(); int v = p.second;
            if(d[v] < p.first) continue;
            for(auto e : G[v]) if(d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost; pre[e.to] = v;
                que.push(P(d[e.to],e.to));
            }
        }
    }
};

signed main() {
    int n; cin >> n;
    graph g(n);
    rep(i,n-1) {
        int a, b, c; cin >> a >> b >> c;
        a--; b--;
        g.add_edge(a,b,c);
        g.add_edge(b,a,c);
    }
    int q, k;
    cin >> q >> k;
    k--;
    g.dijkstra(k);
    rep(i,q) {
        int a, b; cin >> a >> b;
        a--; b--;
        cout << g.d[a] + g.d[b] << endl;
    }
    return 0;
}

Measured memory_bytes: 14784
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int g = sc.nextInt();
        int b = sc.nextInt();
        int n = sc.nextInt();
        long ans = 0;
        for (int i = 0; r * i <= n; i++) {
            int need = n - r * i;
            for (int j = 0; j * g <= need; j++) {
                if ((need - j * g) % b == 0) {
                    ans++;
                }
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 22868
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=100005;
int n;
int a[N];
int cnt[N],num[N],tot;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	if(a[1]==a[n]&&a[1]==0)
	{
		printf("Yes");
		return 0;
	}
	a[0]=-1;
	for(int i=1;i<=n;i++)
	{
		if(a[i]!=a[i-1]) tot++,num[tot]=a[i],cnt[tot]=1;
		else cnt[tot]++;
		if(tot>3)
		{
			printf("No");
			return 0;
		}
	}
	if(n%3!=0)
	{
		printf("No");
		return 0;
	}
	if(tot==3)
	{
		if((num[1]^num[2]^num[3])==0&&cnt[1]==cnt[2]&&cnt[2]==cnt[3]) printf("Yes");
		else printf("No");
	}
	else if(tot==2)
	{
		if((cnt[1]==n/3&&cnt[2]==n/3*2)||(cnt[1]==n/3*2&&cnt[2]==n/3)) printf("Yes");
		else printf("No");
	}
	else printf("No");
	return 0;
}

Measured memory_bytes: 4152