akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
using namespace std;

int syc(long i,long Min,long Max){
	if(Min <= i && i <= Max){
		return 1;
	}else{
		exit(1);
		//return 0;
	}
}

int main(){
	int n,m,c;
	cin >> n >> m >> c;
	
	int b[m];
	for(int i=0;i<m;i++){
		cin >> b[i];
	}
	
	int a[n][m];
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin >> a[i][j];
		}
	}
	
	int count=0,sum=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			sum += a[i][j]*b[j];
		}
		sum+=c;
		if(sum>0)count++;
		sum=0;	
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string N; cin >> N;
    int size_N = N.length();
    long sum = 0;
    int num;

    for(int i = 0; i < size_N; i++){
        char tmp = N[i];
        if(tmp == '0') num = 0;
        if(tmp == '1') num = 1;
        if(tmp == '2') num = 2;
        if(tmp == '3') num = 3;
        if(tmp == '4') num = 4;
        if(tmp == '5') num = 5;
        if(tmp == '6') num = 6;
        if(tmp == '7') num = 7;
        if(tmp == '8') num = 8;
        if(tmp == '9') num = 9;
        sum += num;
    }

    string ans;
    if(sum % 9 == 0) ans = "Yes";
    else ans = "No";
    cout << ans << endl;
}

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

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define INF 1000000000000000000
#define MAX_V 100000
typedef long long ll;
typedef pair<int, int> P;

//int cost[MAX_V][MAX_V];
ll d[MAX_V];
//bool used[MAX_V];
ll V;
struct edge {
	ll to, cost;
};
vector<edge> G[MAX_V];


// O(ElogV)
void dijkstra(ll s) {
	fill(d, d + V, INF);
	d[s] = 0;
	priority_queue<P, vector<P>, greater<P> > q;
	q.push(make_pair(0, s)); // distance, index)

	while(!q.empty()) {
		P p = q.top();
		q.pop();
		ll v = p.second;
		if(d[v] < p.first) continue;
		rep(i, 0, G[v].size()) {
			edge e = G[v][i];
			if(d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				q.push(P(d[e.to], e.to));
			}
		}
	}
}

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

	rep(i, 0, V - 1) {
		ll a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		edge e1, e2;
		e1.to = b;
		e1.cost = c;
		G[a].push_back(e1);
		e2.to = a;
		e2.cost = c;
		G[b].push_back(e2);
	}

	ll Q, K;
	cin >> Q >> K;
	dijkstra(K - 1);
	ll rsl[Q];
	rep(i, 0, Q) {
		ll x, y;
		cin >> x >> y;
		rsl[i] = d[x - 1];
		rsl[i] += d[y - 1];
	}
	rep(i, 0, Q) cout << rsl[i] << endl;

}


Measured memory_bytes: 10752
#include <bits/stdc++.h>
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w
using namespace std;

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;
 
template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+9;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int n;
string s;

bool C(int x){
	int f[100010] = {},sum = 0;
	for(int i = 0;i < n - x + 1;i++){
		if((s[i] - '0' + sum) % 2){
			f[i]++;
			sum++;
		}
		if(i - x + 1 >= 0) sum -= f[i - x + 1];
	}
	bool flag = true;
	for(int i = n - x + 1;i < x;i++){
		if((s[i] - '0' + sum) % 2) flag = false;
		if(i - x + 1 >= 0) sum -= f[i - x + 1];
	}
	return flag;
}

signed main(){
	cin >> s;
	n = s.length();
	int low = 0,up = n + 1;
	while(up - low > 1){
		int mid = (up + low) / 2;
		if(C(mid)) low = mid;
		else up = mid;
	}
	cout << low << endl;
	return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
const int maxn = 55;
typedef long long LL;
#define int LL
int readint(){
	int x=0,f=1;char s=getchar();
	#define sc (s=getchar())
	while(s<'0'||s>'9'){
		if(s=='-')
			f=-1;
		sc;
	}
	while(s>='0'&&s<='9'){
		x=(x<<3)+(x<<1)+(s^48);
		sc;
	}
	#undef sc
	return x*f;
}
int n,m,q;
int a[maxn],b[maxn],c[maxn],d[maxn];
int ans[maxn];
int maxx=0;
void compare(){
	int sum=0;
	for(int i=1;i<=q;i++){
		if(ans[b[i]]-ans[a[i]]==c[i])
			sum+=d[i];	
	}
	maxx=max(maxx,sum);
}
void dfs(int ind,int last){
	if(ind==n+1){
		compare();
		return;
	}
	for(int i=last;i<=m;i++){
		ans[ind]=i;
		dfs(ind+1,i);
		ans[ind]=0;
	}
}
signed main(){
	n=readint(),m=readint(),q=readint();
	for(int i=1;i<=q;i++){
		a[i]=readint(),b[i]=readint(),c[i]=readint(),d[i]=readint();
	}
	dfs(1,1);
	cout<<maxx;
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vb = vector<bool>;
using vs = vector<string>;
using pint = pair<int, int>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

bool f(int x) {
    int keta = 0;
    while(x > 0) {
        x /= 10;
        keta++;
    }
    if(keta % 2 == 1) return true;
    else return false;
}

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

    int ans = 0;
    rep(i, n+1) {
        if(f(i)) ans++;
    }
    
    cout << ans << endl;
    
    return 0;
}

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

short dp[5010][5010];
int main(){
	int N,M;
	cin >> N >> M;
	for(int i = 0 ; i < M ; i++){
		int x,y,c;
		cin >> y >> x >> c;
		dp[y-1][x-1] = c+1;		
	}
	for(int i = 0 ; i < N ; i++){
		for(int j = 0 ; j < N ; j++){
			dp[i+1][j] = max<int>(dp[i+1][j],dp[i][j]-1);
			dp[i+1][j+1] = max<int>(dp[i+1][j+1],dp[i][j]-1);
		}
	}
	int ans = 0;
	for(int i = 0 ; i < N ; i++){
		for(int j = 0 ; j < N ; j++){
			ans += !!dp[i][j];
		}
	}
	cout << ans << endl;
}

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




typedef long long ll;
#define MOD 1000000007
const int NUM_FAC = 2000001;
ll modfact(ll x) {
	static ll _fact[NUM_FAC + 1];
	if (_fact[0] == 0) {
		_fact[0] = 1;
		for (int i = 1; i <= NUM_FAC; ++i) _fact[i] = _fact[i - 1] * i%MOD;
	}
	return _fact[x];
}
ll modpow(ll a, ll n) {
	a %= MOD;
	if (a == 0) return 0;
	ll r = 1;
	while (n) r = r*((n % 2) ? a : 1) % MOD, a = a*a%MOD, n >>= 1;
	return r;
}
ll moddiv(ll a, ll b)
{
	ll ap_2 = modpow(b, MOD - 2);
	return (a * ap_2) % MOD;
}
ll aCb(ll a, ll b) {
	return moddiv(modfact(a), (modfact(a - b) * modfact(b)) % MOD);
}
ll aPb(ll a, ll b) {
	return moddiv(modfact(a), modfact(a - b));
}
//-----------------------------------------------------------------
ll dp[1010][1010];
int N, A, B, C, D;
ll f(ll gn, ll re) {
	if (re == 0) return 1;
	if (gn < A) return 0;

	if (0 <= dp[gn][re]) return dp[gn][re];

	ll ret = f(gn - 1, re);
	rep(i, 1, re / gn + 1) {
		if (i < C) continue;
		if (D < i) break;

		ll c = i;
		if (0 <= re - gn * c) {
			ll t = moddiv(aPb(re, gn * c), modpow(modfact(gn), c)) * f(gn - 1, re - gn * c);
			t %= MOD;
			t = moddiv(t, modfact(c));
			//printf("<%lld, %lld, %lld> = %lld\n",re, gn, c, t);
			ret = (ret + t) % MOD;
		}
	}

	return dp[gn][re] = ret;
}
//-----------------------------------------------------------------
int main() {
	cin >> N >> A >> B >> C >> D;
	rep(i, 0, 1010) rep(j, 0, 1010) dp[i][j] = -1;
	ll ans = f(B, N);
	cout << ans << endl;
}

Measured memory_bytes: 23936
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cstring>
#include <unordered_set>

#define NMAX 100001
#define MOD 1000000007
#define INF 2000000000

#define MIN(a, b) (a < b ? a : b)
#define MAX(a, b) (a > b ? a : b)

typedef unsigned long long ull;

using namespace std;

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

	ull moves = 1ULL<<63;
	for (ull i = 2; i * i <= n; ++i)
		if (n % i == 0)
			moves = MIN(moves, i + n / i - 2);

	cout << (moves != 1ULL << 63 ? moves : n - 1) << '\n';

	return 0;
}

Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
	input = input.split("\n");
	tmp = input[0].split(" ");

var sum=0;
const limitBtm = Number(tmp[1]);
const limitTop = Number(tmp[2]);

for (i=1; i <= Number(tmp[0]); i++){
    var totalEach = 0;
    for(j=0; j<tmp[0].length; j++){
        totalEach += Number(String(i).substr( j, 1 ));
    }
    if(totalEach>=limitBtm && totalEach<=limitTop){
        sum+=i;
    }
}
  
	//出力
	console.log(sum);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 8244
/* بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ */
//codeforces
#include <bits/stdc++.h>
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define mp make_pair
#define pb push_back
#define sz(v) ((int)v.size())
#define all(v) v.begin(), v.end()
void parseArray(ll* A,ll n){ for ( ll K = 0; K < n; K++){ cin >> A[K]; } }
ll modInverse(ll a, ll b){ return 1<a ? b - modInverse(b%a, a)*b/a : 1; }
ll gcd(ll a, ll b){ return b?gcd(b, a % b):a; }
ll lcm(ll a, ll b){ return (a*b)/gcd(a, b); }
ld dist(ld x, ld y, ld a, ld b){ return sqrt((x-a)*(x-a) + (y-b)*(y-b)); }
void debug(ll* a, ll n) { for ( ll k = 0; k < n; k++ ){ cerr << a[k] << " ";} cout << "\n"; }
#define PI 3.14159265358979323846
#define FF first
#define SS second

const ll mod = 1000000007;
int main(){
	FASTIO;
  ll n; cin >> n;
  ll ans = 1;
  ll x = 1;
  ll y = 1;
  for ( int k = 0; k < n; k++ ){
    ans *= 10;
    ans %= mod;
    x *= 9;
    x %= mod;
    y *= 8;
    y %= mod;
  }
  ans = (ans - (x * 2 - y + mod) % mod + mod) % mod;
  cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3692
/*
[abc127] F - Absolute Minima
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int NONE = 1e9 + 1;
const int MAX_Q = 2e5;
const int MAX_BIT_IDX = MAX_Q;

template <typename T>
class BIT {
public:
    T b[MAX_BIT_IDX + 1];
    int n;
    void init(int num) {
        n = num;
        for (int i = 0; i <= n; i++) {
            b[i] = 0;
        }
        return;
    }
    T sum(int i) {  // i : [0, n), returns sum of [0, i)
        T s = 0;
        for (; i > 0; i -= i & -i) {
            s += b[i];
        }
        return s;
    }
    void add(int i, T x) {  // i : [0, n)
        for (i += 1; i <= n; i += i & -i) {
            b[i] += x;
        }
        return;
    }
};

int Q;
bool ty[MAX_Q];
int a[MAX_Q], b[MAX_Q];
BIT<ll> bit1, bit2;

void solve() {
    vector<int> ca(Q);
    for (int i = 0; i < Q; i++) {
        ca[i] = a[i];
    }
    sort(ca.begin(), ca.end());
    ca.erase(unique(ca.begin(), ca.end()), ca.end());
    for (int i = 0; i < Q; i++) {
        if (a[i] != NONE) {
            a[i] = lower_bound(ca.begin(), ca.end(), a[i]) - ca.begin();
        }
    }

    bit1.init(Q);
    bit2.init(Q);
    int cnt = 0;
    ll sb = 0;
    for (int i = 0; i < Q; i++) {
        if (ty[i]) {
            // answer
            int ng = -1;
            int ok = Q;
            while (ok - ng > 1) {
                int m = (ok + ng) / 2;
                if (bit1.sum(m + 1) >= (cnt + 1) / 2) {
                    ok = m;
                } else {
                    ng = m;
                }
            }

            int x = ca[ok];
            ll cnt_x = bit1.sum(ok) - (bit1.sum(Q) - bit1.sum(ok));
            ll sa = -bit2.sum(ok) + (bit2.sum(Q) - bit2.sum(ok));
            ll fx = sb + 1LL * x * cnt_x + sa;

            cout << x << " " << fx << endl;
        } else {
            // update
            cnt++;
            bit1.add(a[i], 1);
            bit2.add(a[i], ca[a[i]]);
            sb += b[i];
        }
    }
}

int main() {
    cin >> Q;
    for (int i = 0; i < Q; i++) {
        int tmp_ty;
        cin >> tmp_ty;
        ty[i] = (tmp_ty == 2);
        if (ty[i]) {
            a[i] = b[i] = NONE;
        } else {
            cin >> a[i] >> b[i];
        }
    }
    solve();

    return 0;
}


Measured memory_bytes: 8448
#include<cstdio>
#include<cmath>
#include<climits>
#include<algorithm>
#include<sstream>
#include<iostream>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<list>
#include<map>
#include<vector>

using namespace std;


#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long
#define MOD 1000000007

#define IMIN INT_MIN;
#define IMAX INT_MAX;


int main(){
	int N, A, B;
	cin >> N >> A >> B;
	cout << min(N*A, B) << endl;


	return 0;
}



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

typedef int64_t Int;
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << endl; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << std::endl;
}

int main() {
    string s, t;
    cin >> s >> t;
    t.pop_back();
    print(s == t ? "Yes" : "No");
    return 0;
}

Measured memory_bytes: 3588
// Input macro
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

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

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

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

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

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

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

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

// Test Code
macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
    // "2\n3 1\n" => "2",
    "3\n2 7 4\n" => "5",
    "4\n20 18 2 18" => "18",
}

fn main() {
    println!("{}", solve(&stdin!()));
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        n: u32,
        v: [u32; n],
    }
    
    let mut v = v;
    v.sort_by(|a, b| a.cmp(b).reverse());

    let mut alice = 0;
    let mut bob = 0;

    for (i, &x) in v.iter().enumerate() {
        if i % 2 == 0 {
            alice += x;
        } else {
            bob += x;
        }
    }

    (alice - bob).to_string()
}

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

#define vi vector<int>
 
#define ff first
#define ss second
 
#define pb push_back
#define MOD 1000000007
//const int nax = 1e6+5;
#define inf 4e18
 
#define display(v) for(int i =0;i<v.size();++i)cout << v[i] << " "
#define all(v) v.begin(),v.end()
int sqr(int x){return x*x;}
inline int add(int a, int b){ int c = a + b; if(c >= MOD) c -= MOD; return c; }
inline int mul(int a, int b){ return (a * 1ll * b) % MOD; }
inline int sub(int a, int b){ int c = a - b; if(c < 0) c += MOD; return c; }
const int nax = 300*1000 + 10;

int32_t main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int x ; cin>>x;
    cout << 1-x;
   

    return 0;
}
    

// Химаншу
// check overflow
// special case n == 1



Measured memory_bytes: 3644
n = int(input())
h = list(map(int, input().split()))[::-1]

for i in range(1,n):
  if h[i] - h[i-1] > 1:
    print("No")
    exit()
  elif h[i] - h[i-1] == 1:
    h[i] -= 1
print("Yes")

Measured memory_bytes: 14276
#include<iostream>
#include<cmath>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<cstdlib>
#include<queue>
#include<list>
#include<cctype>
#include<algorithm>
const int INF=1e9;
using namespace std;

int main(){
    string s, t;
    cin>>s;
    t=s;
    reverse(s.begin(),s.end());
    if(s==t) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <string>
#include <functional>
#include <cassert>
#include <cmath>

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i+1<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			int x=i^j;
			int cnt=0;
			while(x>0)
			{
				x/=2;
				cnt++;
			}
			printf("%d ",cnt);
		}puts("");
	}
	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<cstdlib>
using namespace std;


string strlower(string str){
    for(int i=0, l=str.size();i<l;i++){
        if(str[i]>='A'&&str[i]<='Z')str[i]+=('a'-'A');
    }
    return(str);
}


int main(){
    string input = "";
    string search = "";

    cin >> search;
    int ans=0;
    while(cin >> input){
        if(input == "END_OF_TEXT")break;
        if(strlower(input)==strlower(search))ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3184
import numpy as np

if __name__ == '__main__':
    x = int(input())
    if x < 600:
        print(8)
        exit()
    if x < 800:
        print(7)
        exit()

    if x < 1000:
        print(6)
        exit()
    if x < 1200:
        print(5)
        exit()
    if x < 1400:
        print(4)
        exit()
    if x < 1600:
        print(3)
        exit()
    if x < 1800:
        print(2)
        exit()
    if x < 2000:
        print(1)
        exit()


Measured memory_bytes: 27064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=50+5,M=1e6+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a) memset(a,0,sizeof a)
#define lx x<<1
#define rx x<<1|1
#define reg register
#define PII pair<int,int>
#define fi first 
#define se second
int a[N],n,k;
ll dp[N][3000],ans;
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	 dp[0][0]=1;
	for(int i=1;i<=n;i++)
		for(int j=i;j>=1;j--)
		for(int k=2500;k>=a[i];k--) dp[j][k]+=dp[j-1][k-a[i]];
	for(int i=1;i<=n;i++) ans+=dp[i][i*k];
		printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4816
use std::io;
use std::str::FromStr;

static MOD: i64 = 1_000_000_007;

fn input_tuple() -> (i64, i64) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<i64> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1])
}

fn input_vec() -> Vec<i64> {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.split_whitespace().map(|s| s.parse().unwrap()).collect()
}

fn binary_power(x: i64, n: i64) -> i64 {
    if n == 0 {
      return 1;
    }
    if n % 2 == 0 {
      return (binary_power(x, n / 2) % MOD).pow(2) % MOD;
    } else {
      return binary_power(x, n - 1) % MOD * x % MOD;
    }
}
  
fn inverse_mod(n: i64) -> i64 {
    binary_power(n, MOD-2)
} 
fn combination(fact: &Vec<i64>, n: i64, m: i64) -> i64 {
    if m > n {
        return 0;
    }
    fact[n as usize] * inverse_mod(fact[(n-m) as usize]) %MOD * inverse_mod(fact[m as usize]) % MOD
}

fn main() {
    let (n, k) = input_tuple();
    let mut a_vec = input_vec();
    a_vec.sort();
    let mut fact: Vec<i64> = Vec::new();
    fact.push(1);
    for i in 1..(n+1) {
        fact.push(fact[i as usize - 1] * i % MOD);
    }

    let mut sum = 0;
    for i in 0..n {
        sum += combination(&fact, i, k - 1) * a_vec[i as usize] % MOD;
        sum -= combination(&fact, n - i - 1, k - 1) * a_vec[i as usize] % MOD;
        sum %= MOD;
        // println!("{}", sum);
    }
    println!("{}", sum);
}


Measured memory_bytes: 4296
#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 n,k,r,s,p,ans=0;
  cin >> n >> k >> s >> p >> r;
  
  string str;
  cin >> str;
  
  rep(i,k){
    if(str.at(i) == 'r') ans += r;
    if(str.at(i) == 'p') ans += p;
    if(str.at(i) == 's') ans += s;
  }
  for(int i = k; i < n; i++){
    if(str.at(i) == str.at(i-k)) str.at(i) = 'd';
    if(str.at(i) == 'r') ans += r;
    if(str.at(i) == 'p') ans += p;
    if(str.at(i) == 's') ans += s;
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        long K = Long.parseLong(sc.next());
        int Q = Integer.parseInt(sc.next());

        int[] A = new int[Q];
        for (int i = 0; i < Q; i++) {
            A[i] = Integer.parseInt(sc.next());
        }

        // 合っている人のみ抽出
        int[] challenger = new int[N];
        for (int i = 0; i < Q; i++) {
            int acPerson = A[i];
            challenger[acPerson - 1]++;
        }

        // 最大点数で初期化
        long[] amount = new long[N];
        for (int i = 0; i < N; i++) {
            amount[i] = K;
        }

        // 合ってるポイント分減算して減らす
        for (int i = 0; i < N; i++) {
            int acCount = challenger[i];
            int minusPoint = Q - acCount;

            amount[i] -= minusPoint;
        }

        for (int i = 0; i < N; i++) {
            System.out.println(amount[i] > 0 ? "Yes" : "No");
        }
    }
}



Measured memory_bytes: 50592
import sys
import numpy as np 
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix

'''
Aが最短距離を表す、というのはSnukeの推測でしかない。
なので、Aを、A[v, u]が辺の重みを表しているgraphとして捉え、floyd_warshallで実際に最短距離を求め、Bとする。

B[v, u] < A[v, u]が存在したらAが最短距離を表すという推測は間違っていたことになる。
もしB[v, u] == B[v, w] + B[w, u](ただし w ≠ v, w ≠ u)となるようなwが存在したら、
Aのgraphでedge(v, u)はなくても良いことになるので、A[v, u] = A[u, v] = 0として辺を消す。(仮に辺を消しても、shortest_dist(v, u)には影響しないため)

最後に残った辺々だけをつなげてできるグラフの合計の辺の重みが答えとなる
'''

n = int(sys.stdin.readline().rstrip())
A = np.array(sys.stdin.read().split(), dtype=np.int64).reshape(n, n)

def main():
    B = floyd_warshall(csr_matrix(A), directed=False).astype(np.float64)
    if np.any(B < A):
        return -1
        
    np.fill_diagonal(B, np.inf)
    
    for v in range(n-1):
        for u in range(v+1, n):
            detours = B[v] + B[u]
            if np.any(detours == B[v, u]):
                A[v, u] = A[u, v] = 0

    return np.sum(A) // 2

if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 24364
#include<cstdio>
using namespace std;
int main(){
  int a,b;
  scanf("%d %d",&a,&b);
  if(a<=0&&b>=0)
    printf("Zero\n");
  else if(b<0&&(a-b)%2==0)
    printf("Negative\n");
  else
    printf("Positive\n");
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;

int main() {
	//HogeFuga
    int N;
    vector<int> mochiCascade;
    
    cin >> N;
    
    for ( int i = 0 ; i < N ; i++ ) {
        int d;
        cin >> d;
        mochiCascade.push_back(d);
    }
    
    sort(mochiCascade.begin(),mochiCascade.end());
    
    int count = 1;
    
    for (int i = 0 ; i < N - 1 ; i++) {
        if ( mochiCascade.at( N - 1 - i ) > mochiCascade.at( N - 2 - i ) ) {
            count++;
        }
    }
    
    cout << count << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main{
    public static void main(String[] args) {
        Scanner scn=new Scanner(System.in);
        String x=scn.next();
       System.out.println(Integer.parseInt(String.valueOf(x.charAt(0)))+Integer.parseInt(String.valueOf(x.charAt(1)))+Integer.parseInt(String.valueOf(x.charAt(2))));
    }
}

Measured memory_bytes: 23636
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = 0
for i in range(n - 1):
    if a[i] + 1 == a[i + 1]:
        ans += c[a[i] - 1]
ans += sum(b)
print(ans)


Measured memory_bytes: 3060
def main():
    buf = input()
    buflist = buf.split()
    N = int(buflist[0])
    M = int(buflist[1])
    cakelist = []
    for i in range(N):
        buf = input()
        buflist = buf.split()
        cakelist.append(list(map(int, buflist)))
    highest = 0
    for i in range(0b111+1):
        cake = cakelist
        x_factor = 1
        y_factor = 1
        z_factor = 1
        if i & 0b100:
            x_factor = -1
        if i & 0b010:
            y_factor = -1
        if i & 0b001:
            z_factor = -1
        cake = list(reversed(list(sorted(list(map(lambda x:x[0]*x_factor + x[1]*y_factor + x[2]*z_factor, cake))))))
        score = sum(cake[0:M])
        if score > highest:
            highest = score
    print(highest)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include<iostream>
#include<cstdio>
#define MN 100000
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int n,a[MN+5];
inline int gcd(int x,int y){return y?gcd(y,x%y):x;}
int main()
{
	n=read();
	for(int i=1;i<=n;++i) a[i]=read();
	for(int t=1;;t^=1)
	{
		int evennum=0,oddnum=0,odd=0;
		for(int j=1;j<=n;++j) 
			if(a[j]&1) ++oddnum,odd=a[j];
			else ++evennum;
		if(evennum&1) return 0*puts(t?"First":"Second");
		else if(oddnum==1&&odd>1)
		{
			int g=0;
			for(int j=1;j<=n;++j) 
			{
				if(a[j]&1) --a[j];
				g=gcd(a[j],g);
			}
			for(int j=1;j<=n;++j) a[j]/=g;
		}
		else return 0*puts(t?"Second":"First");
	}
	return 0;
}


Measured memory_bytes: 640
import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	int H, W;
	Deque<Cell> queue;
	int[][] field;
	int result;

	static class Cell {
		int h, w;

		Cell(int h, int w) {
			this.h = h;
			this.w = w;
		}
	}

	void calc() {
		while (!this.queue.isEmpty()) {
			Cell cell = this.queue.pollFirst();
			List<Cell> neighbors = this.getNeighbors(cell);
			for (Cell n : neighbors) {
				this.queue.addLast(n);
			}
		}
	}

	List<Cell> getNeighbors(Cell cell) {
		List<Cell> neighbors = new ArrayList<>();
		int[][] neighborIndexes = new int[4][2];
		neighborIndexes[0][0] = cell.h - 1;
		neighborIndexes[0][1] = cell.w;
		neighborIndexes[1][0] = cell.h + 1;
		neighborIndexes[1][1] = cell.w;
		neighborIndexes[2][0] = cell.h;
		neighborIndexes[2][1] = cell.w - 1;
		neighborIndexes[3][0] = cell.h;
		neighborIndexes[3][1] = cell.w + 1;
		for (int i = 0; i < 4; ++i) {
			int w = neighborIndexes[i][1];
			int h = neighborIndexes[i][0];
			if (h >= 0 && h < H) {
				if (w >= 0 && w < W) {
					if (this.field[h][w] < 0) {
						this.field[h][w] = this.field[cell.h][cell.w] + 1;
						neighbors.add(new Cell(h, w));
						this.result = Math.max(this.result, this.field[h][w]);
					}
				}
			}
		}
		return neighbors;
	}

	Main(int H, int W, List<String> lines) {
		this.H = H;
		this.W = W;
		this.field = new int[H][W];
		this.queue = new ArrayDeque<>();
		for (int h = 0; h < H; ++h) {
			Arrays.fill(this.field[h], -1);
			String line = lines.get(h);
			for (int w = 0; w < W; ++w) {
				if (line.charAt(w) == '#') {
					this.field[h][w] = 0;
					this.queue.addLast(new Cell(h, w));
				}
			}
		}
		this.result = 0;
		calc();
		show();
	}

	void show() {
		System.out.println(this.result);
	}

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		String[] tokens = in.readLine().split(" ");
		int H = Integer.parseInt(tokens[0]);
		int W = Integer.parseInt(tokens[1]);
		List<String> lines = new ArrayList<>();
		for (int h = 0; h < H; ++h) {
			lines.add(in.readLine());
		}
		Main ins = new Main(H, W, lines);

	}
}

Measured memory_bytes: 127172
function Main(arg)
{
  var S = arg.split("\n")[0].split(" ")[0];
  var T = arg.split("\n")[0].split(" ")[1];
  var a = arg.split("\n")[1].split(" ")[0]-0;
  var b = arg.split("\n")[1].split(" ")[1]-0;
  var u = arg.split("\n")[2];

  if (u == S) a--;
  else b--;

  console.log(a + " " + b);
  return;
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
h = int(input())
c = 0
while h > 1:
    h = h//2
    c +=1
#    print(h)
c = c + 1
#print(c)
r = 1
re = 1
for _ in range(1,c):
    r *= 2
#    print(r)
    re +=r
print(re)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
typedef long long int lli;
using namespace std;
#pragma region DEBUG
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#pragma endregion DEBUG
#define MOD 1000000007
#define MAX 500005
#define endl "\n"
lli dp[2005][2005];
long long binpow(long long a, long long b, long long m) {
    m = MOD;
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);    
   // freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout)
    lli t;
    //cin>>t;
    t = 1;
    while(t--){
       // lli n;
        lli n;
        cin>>n;
        for(lli i = 3; i<=n; i++)
            dp[1][i] = 1;
        for(lli i = 2; i<=n/3+2; i++){
            for(lli j = 3*i; j<=n; j++){
                for(lli k = 3;; k++){
                  //  debug(j-k);
                    if(j-k < 3*(i-1))
                        break;
                   // debug(i,j,i-1,j-k, dp[i-1][j-k]);
                    dp[i][j] += dp[i-1][j-k];
                    dp[i][j] %= MOD;
                }
            }
        }
       // cout<<dp[2][7]<<endl;
        lli ans = 0;
        for(lli i = 1; i<=n; i++){
            ans += dp[i][n];
            ans %= MOD;
        }
        cout<<ans<<endl;
        
    }
}

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

#define EB emplace_back
#define int long long
#define F first
#define S second
#define N 500005
#define all(x) x.begin(),x.end()
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)


using namespace std;


int32_t main()
{
    IOS;

    int tt=1;
	//cin >> tt;
	while (tt--)
	{
		string s; cin >> s;
		int n = s.size();
		n = s[n - 1] - '0';
		if(n == 2 or n == 4 or n == 5 or n == 7 or n == 9) cout << "hon";
		else if(n == 3) cout << "bon";
		else cout << 	"pon";
		
	}
    return 0;
}


Measured memory_bytes: 3604
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
	public class Program
	{
		static void Main(string[] args)
		{

			string s = Console.ReadLine();

			DateTime date = DateTime.Parse(s);

			Console.WriteLine(date <= DateTime.Parse("2019/4/30") ? "Heisei" : "TBD") ;

		}
	}
}


Measured memory_bytes: 11608
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

const int bound = 200100;
ll fact[bound], fact_inv[bound];

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

void init(){
	fact[0] = 1;
	int b = bound-10;
	for( int i = 0; i < b; ++i ){
		fact[i+1] = fact[i]*(i+1) % mod;
	}
	fact_inv[b] = power(fact[b], mod-2);
	for( int i = b-1; i >= 0; --i ){
		fact_inv[i] = fact_inv[i+1]*(i+1) % mod;
	}
}

ll comb( ll n, ll r ){
	if( n < r or r < 0 ) return 0;
	return ( fact[n]*fact_inv[r] ) % mod * fact_inv[n-r] % mod;
}

int main(){
	init();
	ll n, k; cin >> n >> k;
	ll ans = 0;
	for( ll x = 1; x <= min(k, n-1); ++x ){
		ans += ( comb(n, x) * comb(n-1, n-x-1) ) % mod;
		if( x == 2 ) ans += 1;
		ans %= mod;
	}
	cout << ans << endl;
}

Measured memory_bytes: 6704
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<29
#define LINF LLONG_MAX/3
#define mp make_pair
#define pb push_back
#define EB emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int w,h;

void solve(){
    char c[32][32];
    rep(i,h) scanf("%s",c[i]);

    int sx,sy;
    rep(i,h) rep(j,w) if(c[i][j]=='o'){
        sx = i;
        sy = j;
        break;
    }

    int g[512][512];
    rep(i,512) rep(j,512) g[i][j]=INF;
    rep(i,512) g[i][i]=0;

    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(c[i][j]=='x') continue;
            int v = i*w+j;
            for(int k=0;k<4;k++){
                int nx=i+dx[k],ny=j+dy[k];
                if(nx<0||ny<0||nx>=h||ny>=w) continue;
                if(c[nx][ny]=='x') continue;
                int nv = nx*w+ny;
                g[v][nv] = 1;
                g[nv][v] = 1;
            }
        }
    }

    int V = h*w;
    for(int k=0;k<V;k++){
        for(int i=0;i<V;i++){
            for(int j=0;j<V;j++){
                g[i][j] = min(g[i][j],g[i][k]+g[k][j]);
            }
        }
    }

    vector<ll> as;
    rep(i,h) rep(j,w){
        int v = i*w+j;
        if(c[i][j]=='*') as.pb(v);
    }

    sort(all(as));

    assert(as.size()<=10);
    ll ans = INF;
    do{
        ll tmp=0;
        int now = sx*w+sy;
        for(int i=0;i<sz(as);i++){
            tmp += g[now][as[i]];
            now = as[i];
            if(g[now][as[i]]==INF){
                cout << -1 << endl;
                return;
            }
        }
        //if(tmp==0){
        //    //cerr << "error" << endl;
        //    exit(1);
        //}
        ans = min(tmp,ans);
    }while(next_permutation(all(as)));
    if(ans==INF) cout << -1 << endl;
    else cout << ans << endl;
}

int main(){
    while(cin>>w>>h){
        if(w==0 and h==0) break;
        solve();
    }
}

Measured memory_bytes: 4136
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc *bufio.Scanner

func init() {
	sc = bufio.NewScanner(os.Stdin)
	buffsize := 1000000
	buff := make([]byte, buffsize)
	sc.Buffer(buff, buffsize)
	sc.Split(bufio.ScanWords)
}

func loadint() (result int) {
	sc.Scan()
	result, _ = strconv.Atoi(sc.Text())
	return
}

func main() {
	n := loadint()
	t := loadint()
	a := loadint()
	h := make([]int, n)
	for i := 0; i < n; i++ {
		h[i] = loadint()
	}
	nearIndex := 0
	nearDiff := 100000000000000
	for i := 0; i < n; i++ {
		diff := a*1000 - (t*1000 - h[i]*6)
		if diff < 0 {
			diff = -diff
		}
		if diff < nearDiff {
			nearDiff = diff
			nearIndex = i
		}
	}
	fmt.Println(nearIndex + 1)
}


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


public class Main {
	private	static	BufferedReader	m_stdin = null;

	static {
		m_stdin = new BufferedReader(new InputStreamReader(System.in));
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		while (parseMatrix());
	}

	private static boolean parseMatrix() {
		boolean	loop = false;
		String	line = null;

		try {
			line = m_stdin.readLine();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			line = null;
		}

		if (line != null) {
			if (!line.isEmpty()) {
				String[]	lines = line.split(" ");
				double[]	da    = { Double.parseDouble(lines[0]), Double.parseDouble(lines[1]) };
				double[]	db    = { Double.parseDouble(lines[2]), Double.parseDouble(lines[3]) };
				double[]	dc    = { Double.parseDouble(lines[4]), Double.parseDouble(lines[5]) };
				double[]	dp    = { Double.parseDouble(lines[6]), Double.parseDouble(lines[7]) };
				int			n1    = getCrossSign(da, db, dp);
				int			n2    = getCrossSign(db, dc, dp);
				int			n3    = getCrossSign(dc, da, dp);

				if ((n1 == n2) && (n2 == n3)) {
					System.out.println("YES");
				}
				else {
					System.out.println("NO");
				}

				loop = true;
			}
		}

		return loop;
	}

	private static int getCrossSign(double[] da, double[] db, double[] dp) {
		double[]	dab = { db[0] - da[0], db[1] - da[1] };
		double[]	dap = { dp[0] - da[0], dp[1] - da[1] };
		return ( getCross(dab, dap) >= 0.0 ) ? 1 : -1;
	}

	private static double getCross(double[] d1, double[] d2) {
		return d1[0] * d2[1] - d1[1] * d2[0];	// x1*x2 + y1*y2
	}
}

Measured memory_bytes: 17004
#include <iostream>	
#include <time.h>
#include <vector>
#include <stdio.h>
#include <memory.h>
#include <string>
#include <map>
#include <algorithm>
#include <bitset>
#include <queue>
#include <set>
#include <time.h>
#include <assert.h>
#include <sstream>
//#include <unordered_map>
#include <bitset>
#include <utility>
#include <iomanip>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <math.h>
using namespace std;
typedef long long ll;

ll n,a[100010],b[100010];

int main() {
    ll ans=0;
    scanf("%lld",&n);
    for(int i=0;i<n;++i)
        scanf("%lld%lld",a+i,b+i);
    ll cnt=0;
    for(int i=n-1;i>=0;--i){
        a[i]+=cnt;
        if(a[i]>b[i]){
            ll x=a[i]%b[i];
            cnt+=b[i]-(x?x:b[i]);
            ans+=b[i]-(x?x:b[i]);
        }else if(a[i]){
            cnt+=b[i]-a[i];
            ans+=b[i]-a[i];
        }
    }
    printf("%lld",ans);
    
    return 0;
}

Measured memory_bytes: 1792
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};
fn main() {
    input! {//
        n:usize,
    }
    let mut g = G::new(n);
    g.dfs(vec![], 'a');
    for s in g.ans {
        for &c in s.iter() {
            print!("{}", c);
        }
        println!();
    }
}
struct G {
    n: usize,
    ans: Vec<Vec<char>>,
}
impl G {
    fn new(n: usize) -> G {
        G {
            n: n,
            ans: Vec::<Vec<char>>::new(),
        }
    }
    fn dfs(&mut self, st: Vec<char>, mx: char) {
        if st.len() == self.n {
            // self.ans.push(st);
            for &c in st.iter() {
                print!("{}", c);
            }
            println!();
        } else {
            let cc = charconv(mx, 'a');
            for ch in 0..=cc {
                let mut nx = st.clone();
                nx.push(('a' as u8 + ch as u8) as char);
                self.dfs(nx, if ch == cc { (mx as u8 + 1) as char } else { mx });
            }
        }
    }
}

pub fn charconv(c: char, base: char) -> usize {
    return (c as u8 - base as u8) as usize;
}


Measured memory_bytes: 2176
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <random>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;

typedef
tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> orderedSet;

#define pb push_back
#define F first
#define S second
#define all(a) (a).begin(), (a).end()

#define for1(i0, l0, r0) for (int i0 = l0; i0 < r0; ++i0)
#define for2(i0, l0, r0) for (int i0 = l0; i0 <= r0; ++i0)
#define forn(i0, n0) for (int i0 = 0; i0 < n0; ++i0)
#define forn1(i0, n0) for (int i0 = 1; i0 < n0; ++i0)
#define forr(i0, n0) for (int i0 = n0; i0 >= 0; --i0)
#define forr1(i0, r0, l0) for (int i0 = r0; i0 > l0; --i0)
#define forr2(i0, r0, l0) for (int i0 = r0; i0 >= l0; --i0)

#define Sort(a) sort(all(a))
#define Reverse(a) reverse(all(a))

typedef long double ld;
#define ui unsigned int
#define ull unsigned long long

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<string, string> pss;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<bool> vb;
typedef vector<string> vs;

typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pdd> vpdd;

typedef vector<vi> vvi;
typedef vector<vd> vvd;
typedef vector<vll> vvll;
typedef vector<vb> vvb;

#define vpss vector<pss>
#define vvs vector<vs>
#define vvpii vector<vpii>
#define vvpll vector<vpll>
#define vpt vector<pt>
#define vvvi vector<vvi>
#define vsi vector<set<int>>
#define ss second
#define ff first

#define printvi(arr) for (int x0 : arr) cout << x0 << ' '; cout << '\n';
#define printvll(arr) for (ll x0 : arr) cout << x0 << ' '; cout << '\n';
#define printpair(pair0) cout << pair0.F << ' ' << pair0.S << '\n';
#define printvp(arr) for (auto pair0 : arr) printpair(pair0);
#define initArray(arr, N0, X0) memset(arr, X0, N0 * sizeof(int))
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void init() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cout.precision(16);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
}

void solve() {
    vi a(3);
    forn(i, 3) cin >> a[i];
    Sort(a);
    cout << (a[0] + a[1] == a[2] ? "Yes" : "No") << '\n';
}

bool multitest = false;

int main() {
    init();
    int t = 1;
    if (multitest) cin >> t;
    forn(i, t) solve();
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;


int getScore(vector<int> &A, vector<int> &a, vector<int> &b, vector<int> &c, vector<int> &d) {
  int score = 0;
  for (int i = 0; i < a.size(); i++) {
    if (A[b[i] - 1] - A[a[i] - 1] == c[i]) {
      score += d[i];
    }
  }
  return score;
}
void dfs(vector<int> &A, vector<int> &a, vector<int> &b, vector<int> &c, 
  vector<int> &d, int min_val, int max_val, int idx, int &max_score) {
  int n = A.size();
  if (idx == n) {
    max_score = max(max_score, getScore(A, a, b, c, d));
  } else {
    for (int j = min_val; j <= max_val; j++) {
      A[idx] = j;
      dfs(A, a, b, c, d, j, max_val, idx + 1, max_score);
    }
  }
}
int main() {
  int  N, M, Q;
  cin >> N >> M >> Q;
  vector<int> a(Q), b(Q), c(Q), d(Q);
  for (int i = 0; i < Q; i++) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  vector<int> A(N, 1);
  int max_score = 0;
  dfs(A, a, b, c, d, 1, M, 0, max_score);
  cout << max_score << endl;
  return 0;
}

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

namespace ABC178
{
    class Program
    {
        static void Main(string[] args)
        {
            b();
        }

        public static void b()
        {
            long[] a = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
            long b = a[0] * a[2];
            long c = a[0] * a[3];
            long d = a[1] * a[2];
            long e = a[1] * a[3];
            long m = Math.Max(b, Math.Max(c, Math.Max(d, e)));
            Console.WriteLine(m);

        }
    }
}


Measured memory_bytes: 28240
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstdio>
#include <cmath>
#include <map>
#include <set>
#include <utility>
#include <stack>
#include <cstring>
#include <bitset>
#include <deque>
#include <string>
#include <list>
#include <cstdlib>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 100000 + 100;
typedef long long ll;
typedef long double ld;

int main()
{
	ll q, h, s, d;
	ll n;
	while (cin >> q >> h >> s >> d)
	{
		cin >> n;
		h = min(h, 2 * q);
		s = min(s, 2 * h);
		d = min(d, 2 * s);
		ll ans = (n / 2) * d + (n % 2) * s;
		cout << ans << endl;
	}
}

Measured memory_bytes: 256
H,N=map(int,input().split())
ABC=[]
for _ in range(N):
  a,b=map(int,input().split())
  ABC.append((a,b,a/b))
ABC=sorted(ABC, key=lambda x:x[2], reverse=True)
A=[ABC[i][0] for i in range(N)]
B=[ABC[i][1] for i in range(N)]
dp=[[float('inf')]*(H+1) for i in range(N+1)]
for i in range(N+1):
  dp[i][0]=0
  
for i in range(N):
  for j in range(1,H+1):
    if j-A[i]>=0:
      dp[i+1][j]=min(dp[i][j],dp[i+1][j-A[i]]+B[i])
    else:
      dp[i+1][j]=min(dp[i][j],dp[i+1][0]+B[i])
print(dp[N][H])
#print(dp)

Measured memory_bytes: 364332
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <set>
using namespace std;
using ll = long long;
int main(void){
    int n;
    cin >> n;
    vector<int> a(n);
   ll max_num = 0;
    ll min_num = 100000;
    for(int i=0;i<n;i++){
        cin >> a[i];
        if(a[i]>max_num){
            max_num = a[i];
        }
        if(a[i]<min_num){
            min_num = a[i];
        }
    }
    ll ans = 10000000;
    for(int i=min_num;i<=max_num;i++){
        ll temp = 0;
        for(int j=0;j<n;j++){
                temp+=(a[j]-i)*(a[j]-i);
        }
        ans=min(ans,temp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256