akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int cl(int a, int b) {
	return (a - (a%b)) / b;//b=0だと積む
}
int up(int a, int b) {
	return cl(a + b - 1, b);//b=0だと積む
}
int ord(int a, int p) {
	if (a%p == 0) {
		return ord(a / p, p) + 1;
	}
	else {
		return 0;
	}
}
long long ruin(int a, int n, long long  p) {
	if (n == 0) {
		return (1 % p);
	}
	else {
		long long x = ruin(a, (n - (n % 2)) / 2, p);
		if (n % 2 == 0) {
			return (x*x) % p;
		}
		else {
			return (((x*x) % p)*a) % p;

		}

	}

}
long long com(int n, int r, int p) {
	if (r == 0) {
		return (1 % p);
	}
	else {
		long long x = com(n, r - 1, p);
		return (x*(n - r) / r) % p;
	}
}
long long sum(long long n, long long p) {
	if (n == 0) {
		return 0;
	}
	else {
		long long x = (n%p) + sum((n - (n%p)) / p, p);
		return x;
	}
}
int di(int a) {
	return ((a + 10) / 10) - 1;
}
int ss(int a, int b) {
	if (a >= b) {
		return 1;
	}
	else {
		return 0;
	}
}
int main()
{
	int n;
	cin >> n;
	vector<int> p;
	p = { 2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97 };
	vector<int> o(25,0);
	for (int i = 0; i < 25; i++) {
		for (int j = 1; j <= n; j++) {
			o[i] = o[i] + (ord(j, p[i]));
		}
	}
	int a75 = 0;
	int a25 = 0;
	int a15 = 0;
	int a5 = 0;
	int a3 = 0;
	for (int i = 0; i < 25; i++) {
		int x = o[i];
		a75 += ss(x, 74);
		a25 += ss(x, 24);
		a15 += ss(x, 14);
		a5 += ss(x, 4);
		a3 += ss(x, 2);
	}
	int ans = 0;
	ans += a75;
	ans += a25*(a3-1);
	ans += a15 * (a5 - 1);
	ans += (a3 - 2)*(a5*(a5 - 1)) / 2;
	cout << ans << endl;
}


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

bool isPrime(int x){
	bool ret=true;
	for(int i=2;i*i<=x;i++)if(x%i==0)ret=false;
	return ret;
}

int main(){
	int X;
	cin >> X;
	while(!isPrime(X))X++;
	cout << X << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>


int main(){
	char s[1010];
	scanf("%s",s);
	int w;
	scanf("%d",&w);
	
	for(int i=0;i>=0;i++){
		if(s[i]<'a'||s[i]>'z'){
			break;
		}
		if(i%w==0){
			printf("%c",s[i]);
		}
	}
	printf("\n");
	
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> void chmax(T& x, U y){if(x<y) x=y;}
template<class T,class U> void chmin(T& x, U y){if(y<x) x=y;}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ~ ";
	dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);

	V<int> v = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int k; cin >> k;
	cout << v[k-1] << endl;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include <iomanip>
using namespace std;

int main(){
	int n,ans=0;
	cin>>n;
	vector<int> a(100);
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a.begin(),a.end(),greater<>());
	for(int i=0;i<n-1;i++){
		if(a[i+1]!=a[i]){
			ans++;
		}
	}
	cout<<ans+1<<endl;
	
	return 0;
	
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int INF = 2e6;
ll MOD = 1e9 + 7;

int main(){
    int n, q; cin >> n >> q;
    vector<vector<int>> g(n);
    rep(i,n-1){
        int a, b; cin >> a >> b;
        a--; b--;
        g[a].pb(b);
        g[b].pb(a);
    }
    vector<int> sum(n);
    rep(i,q){
        int p, x;
        cin >> p >> x;
        p--;
        sum[p] += x;
    }

    vector<bool> vis(n,false);
    queue<int> que;
    que.push(0);
    vis[0] = true;        
    while(que.size()){
        int v = que.front();
        que.pop();
        for(auto i : g[v]){
            if(!vis[i]){
                vis[i] = true;
                que.push(i);
                sum[i] += sum[v];
            }
        }
    }
    rep(i,n) cout << sum[i] << endl;
}

Measured memory_bytes: 15604
#include<iostream>
#include<cstring>
#include<vector>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=2e5+5;
char s[N];
int mod[N];
int main(){
cin>>s;
int k=1,res=0,ans=0;
for(int i=strlen(s)-1;i>=0;i--){
    mod[res]++;
    res=(res+(s[i]-'0')*k)%2019;
    ans+=mod[res];
    k=k*10%2019;
}
cout<<ans;


return 0;
}


Measured memory_bytes: 3780
import itertools


def main():
    # n = int(input())
    h, w, k = map(int, input().split())
    # a = list(map(int, input().split()))
    # s = input()
    c = []
    for i in range(h):
        c.append(list(input()))

    total = 0
    for i in list(itertools.chain.from_iterable(c)):
        if i == "#":
            total += 1

    ans = 0
    for i in range(2**h):
        for j in range(2**w):
            count = 0
            for ii in range(h):
                for jj in range(w):
                    if (i >> ii & 1 or j >> jj & 1) and c[ii][jj] == "#":
                        count += 1
            if total - count == k:
                ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 74296
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,q,r,s,i,x,y;
    cin>>n>>q;
    int ara[n];
    memset(ara,0,sizeof ara);
    string str;
    cin>>str;
    for(i=0;i<n-1;i++)
    {
        if(str[i]=='A' && str[i+1]=='C')
            ara[i+1]=1,i++;
    }
    for(i=1;i<n;i++)
        ara[i]+=ara[i-1];

    while(q--)
    {
        cin>>x>>y;
        x--;
        y--;
        r=ara[y];
        s=ara[x];

        cout<<(r-s)<<endl;
    }
    return 0;
}


Measured memory_bytes: 1408
#include <iostream>

using namespace std;

typedef long long ll;

const int MOD = 998244353; // change if needed

struct Modint {
  ll val;
  
  Modint (ll _val = 0)
    : val(_val % MOD) {}

  Modint operator+ (Modint other) const {
    return Modint(val + other.val);
  }

  void operator+= (Modint other) {
    val += other.val;
    val %= MOD;
  }

  Modint operator- () const {
    return Modint(MOD - val);
  }

  Modint operator- (Modint other) const {
    return Modint(val + MOD - other.val);
  }

  void operator-= (Modint other) {
    val += MOD - other.val;
    val %= MOD;
  }

  Modint operator* (Modint other) const {
    return Modint(val * other.val);
  }

  void operator*= (Modint other) {
    val *= other.val;
    val %= MOD;
  }

  bool operator== (Modint other) const {
    return val == other.val;
  }

  bool operator!= (Modint other) const {
    return val != other.val;
  }
};

Modint exp (Modint a, int k) {
  if (k == 0) {
    return Modint(1);
  } else if (k % 2 == 0) {
    Modint half = exp(a, k / 2);
    return half * half;
  } else {
    return a * exp(a, k - 1);
  }
}

Modint inv (Modint a) {
  return exp(a, MOD - 2);
}

ostream& operator<< (ostream& out, Modint p) {
  out << p.val;
  return out;
}

const int MAX_N = 3e3 + 5;

int arr [MAX_N];
Modint dp [MAX_N][MAX_N];

int main () {
  ios::sync_with_stdio(false);

  int n, S;
  cin >> n >> S;

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

  dp[0][0] = exp(Modint(2), n);
  Modint i2 = inv(Modint(2));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= S; j++) {
      if (j + arr[i] <= S) {
        dp[i + 1][j + arr[i]] += i2 * dp[i][j];
      }
      dp[i + 1][j] += dp[i][j];
    }
  }
  cout << dp[n][S] << endl;
}


Measured memory_bytes: 74208
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

/// Rearranges elements in the slice
/// to the next lexicographically larger permutation.
pub fn next_perm<T: Ord>(xs: &mut [T]) -> bool {
    // `xs[i + 1..]` : desc but
    // `xs[i..]` : not desc.
    let i = match (0..xs.len())
        .rev()
        .filter(|&i| i + 1 < xs.len() && xs[i] < xs[i + 1])
        .next()
    {
        None => return false,
        Some(i) => i,
    };

    // `xs[k]` : The next greater elem in `xs[i..]`.
    let k = (i + 1..xs.len())
        .rev()
        .filter(|&k| xs[i] < xs[k])
        .next()
        .unwrap();

    // E.g. 2431 -> 3421 -> 3124 (where i = 0, k = 2).
    xs.swap(i, k);
    xs[i + 1..].reverse();

    true
}

fn main() {
    let N = read!(usize);
    let P = read![[usize]];
    let Q = read![[usize]];

    let mut A = (1..N + 1).collect::<Vec<_>>();
    let mut a = std::usize::MAX;
    let mut b = std::usize::MAX;

    for i in 0.. {
        if A == P {
            a = i;
        }

        if A == Q {
            b = i;
        }

        if !next_perm(&mut A) {
            break;
        }
    }

    let d = max(a, b) - min(a, b);
    println!("{}", d);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define int long long
#define multi_test true and false
#define all(a) (a).begin(), (a).end()
using namespace std;

void solve()
{
    int n, m, k;
    cin >> n >> m >> k;
    int cost[n];
    int arr[n][m];
    for (int i = 0; i < n; i++)
    {
        cin >> cost[i];
        for (int j = 0; j < m; j++)
        {
            cin >> arr[i][j];
        }
    }
    int ans = LONG_LONG_MAX;
    for (int val = 0; val < (1ll << n); val++)
    {
        int cur_cost = 0;
        vector<int> idea(m, 0);
        for (int i = 0; i < n; i++)
        {
            if ((val >> i) & 1)
            {
                cur_cost += cost[i];
                for (int j = 0; j < m; j++)
                {
                    idea[j] += arr[i][j];
                }
            }
        }
        // cout << cur_cost << ' ' << val << endl;
        if (all_of(all(idea), [&](int i) { return i >= k; }))
        {
            ans = min(ans, cur_cost);
        }
    }
    if (ans == LONG_LONG_MAX)
        cout << -1 << endl;
    else
        cout << ans << endl;
}

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

    int test = 1;
    if (multi_test)
        cin >> test;

    while (test--)
        solve();

    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

#define PI 3.141592653
#define RAD2DEG(R) ((R)/PI*180)

int main(void){
  double a,b,x,ans;
  cin >> a >> b >> x;
  
  x /= a; // 2Dで考える
  if (x*2<=a*b){ // 対角線より倒せる
    ans = atan2(b, 2*x/b);
  } else {
    x = x - a*b;
    ans = -atan2(2*x/a, a);
  }
  printf("%.8f\n", RAD2DEG(ans));
  return 0;
}

Measured memory_bytes: 512
/*https://atcoder.jp/contests/abc158/tasks/abc158_b*/
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
	long long a, b, n, r, d, count = 0;
	cin >> n >> a >> b;
	if (n < a + b)
	{
		if ((a == 0 ) || (a == 0 && b == 0))
		{
			cout << count;
			return 0;
		}
		else if (b == 0)
		{
			cout << n;
			return 0;
		}
		else
		{
			cout << min(n, a);
			return 0;
		}
	}
	d = n / (a + b);
	r = n % (a + b);
	count += d * a;
	if (r < a)
		count += r;
	else if (r >= a)
		count += a;
	cout << count;

}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2) % mod;
}
/*--------Library Zone!--------*/

int n, k;
int dp[105][100000];
int shu, cnt[100000];
signed main() {
	cin >> n >> k;
	for (int i = 1; i <= n;) {
		if (n / i != n / (i + 1)) {
			cnt[shu++] = 1; i++;
		}
		else {
			int memo = n / (n / i) + 1;
			cnt[shu++] = memo - i; i = memo;
		}
	}
	dp[0][1] = 1;
	int sum[100000];
	fill(sum, sum + 100000, 1);
	rep(i, k) {
		rep(j, shu + 1) {
			dp[i + 1][j] = sum[shu - j - 1] * cnt[j] % mod;
		}
		fill(sum, sum + 100000, 0);
		rep(j, shu + 1) {
			sum[j] += dp[i + 1][j];
			sum[j] %= mod;
			sum[j + 1] += sum[j];
		}
	}
	int ans = 0;
	cout << sum[shu] << endl;
}

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

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

  vector<long long> a(n);
  for (auto &i : a) cin >> i;

  long long cnt = 0, m = n * (n + 1) / 2;
  for (auto i : a) cnt += i;

  bool ans = true;
  if (cnt % m) ans = false;

  long long o = cnt / m;
  vector<long long> d;
  for (int i = 0; i < n; ++i) {
    d.push_back(a[i] - a[(i + 1) % n] + o);
  }

  cnt = 0;
  for (int i = 0; i < n; ++i) {
    if (d[i] % n || d[i] < 0) ans = false;
    cnt += d[i] / n;
  }

  if (cnt != o) ans = false;

  puts(ans ? "YES" : "NO");
}


Measured memory_bytes: 2168
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define owo(i,a, b) for(int i=(a);i<(b); ++i)
#define uwu(i,a, b) for(int i=(a)-1; i>=(b); --i)
#define senpai push_back
#define ttgl pair<int, int>
#define ayaya cout<<"ayaya~"<<endl
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
gpu_hash_table<pair<int, int>, int> mp;
#define ordered_set tree<ttgl, null_type,less<ttgl>, rb_tree_tag,tree_order_statistics_node_update>*/
 
using ll = long long;
using ld = long double;
const ll MOD = 998244353;
const ll root = 62;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
ll binpow(ll a,ll b){ll res=1;while(b){if(b&1)res=(res*a)%MOD;a=(a*a)%MOD;b>>=1;}return res;}
ll modInv(ll a){return binpow(a, MOD-2);}
const double PI = acos(-1);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;
const int NINF = 0xc0c0c0c0;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const ll NINFLL = 0xc0c0c0c0c0c0c0c0;
const int mxN = 200001;
int n;
ll arr[mxN];
ttgl twofive[mxN];
int cnt[19][19];
int main() {
    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    cin.tie(0)->sync_with_stdio(0);
    cin>>n;
    double a;
    ll ans = 0;
    owo(i, 0, n) {
        twofive[i] = {0, 0};
        cin>>a;
        arr[i] = llround(a*1e9);
        ll num = arr[i];
        while(num%2==0) {
            twofive[i].first++;
            num/=2;
        }
        while(num%5==0) {
            twofive[i].second++;
            num/=5;
        }
        twofive[i].first = min(twofive[i].first, 18);
        twofive[i].second = min(twofive[i].second, 18);
        //cout<<arr[i]<<" "<<twofive[i].first<<" "<<twofive[i].second<<"\n";
    }
    uwu(i, n, 0) {
        owo(j, 18-twofive[i].first, 19) {
            owo(k, 18-twofive[i].second, 19) {
                ans+=cnt[j][k];
            }
        }
        cnt[twofive[i].first][twofive[i].second]++;
        /*ans+=cnt[max(18-twofive[i].first, 0)][max(18-twofive[i].second, 0)];
        uwu(k,min(twofive[i].first, 18)+1, 0) {
            uwu(j, min(twofive[i].second, 18)+1, 0) {
                cnt[k][j]++;
            }
        }*/
        
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 6852
#include <bits/stdc++.h>
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define vll vector< ll >
//#define M 100000
#define MD 1000000007
#define pb push_back
#define rep(i,a,b) for(ll i = a; i <= b; ++i)
#define fo(i,a,b) for(int i = a; i<= b; ++i)
#define pii pair<int,int>
#define vec(a) vector<a >
#define all(a) a.begin(),a.end()
#define se second
#define fi first
#define inf 0xffffffff
#define inchar getchar_unlocked
#define outchar(x) putchar_unlocked(x)
//#define int unsigned long long
//#define endl '\n'
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long  
#define int long long
using namespace std;
//using ll = unsigned long long;
ll md=MD;
//ll M=1073741824;
ll M=998244353;
//ll exp(ll a,ll b){ll r=1;while(b>0){if(b&1){r=r*(a%md);r=(r+md)%md;}b>>=1;a=(a%md)*(a%md);a=(a+md)%md;}return (r+md)%md;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll Min(int a,int b){if(a<b)return a; return b;}
ll Max(int a,int b){if(a>b)return a; return b;}
ll power(ll a,ll b){ll ans=1;while(b>0){if(b&1)ans=(ans*a)%M;a=(a*a)%M;b=b>>1;}return ans;}
const int INF=1000000000000000000;


int32_t main()
{
	IOS;
	int t;
//	cin>>t;
	t=1;
	while(t--)
	{
		char ch;
		cin>>ch;
		if(ch>='A' && ch<='Z') cout<<"A\n";
		else cout<<"a\n";	
	}
	return 0;
}

Measured memory_bytes: 3608
#include<stdio.h>             
int main()  
{  
    int a,b,c,t;  
    scanf("%d%d%d",&a,&b,&c);  
    if(a>b)                     
    {  
        t=b;  
        b=a;  
        a=t;  
    }  
    if(a>c)                     
    {  
        t=c;  
        c=a;  
        a=t;  
    }  
    if(b>c)                    
    {  
        t=c;  
        c=b;  
        b=t;  
    }  
    printf("%d %d %d\n",a,b,c);  
    return 0;  
}  


Measured memory_bytes: 2040
//Author: A_S_M_M@sud_P@rvez
#include<bits/stdc++.h>
using namespace std;
#define    MP ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define    for0(i,n) for(int i=0;i<n;i++)
#define    forn(i,n) for(int i=1;i<=n;i++)
#define    fors(i,s) for(int i=0;i<s.size();i++)
#define    Sort(s) sort(s.begin(),s.end())
#define    gcd(a, b) __gcd(a , b)
#define    lcm(a,b) (a*(b/__gcd(a,b)))
#define    nl     "\n"
#define    End    return 0 
#define    gt     greater<int>()
#define    ll     long long 
#define    mp     make_pair
#define    pb     push_back
#define    vi     vector<int>
#define    vl     vector<ll>
#define    mod    1000000007
#define    sp(n)  fixed<<setprecision(n)
#define    pi     acos(-1)

int main()
{
MP;
    
    int n;
    cin>>n;
    int a[n];
    vi p(n+1);
    for(int i=0;i<n-1;i++)
    {
        cin>>a[i];
        p[a[i]]++;
    }
    forn(i,n){
        cout<<p[i]<<nl;
    }

End;
}


Measured memory_bytes: 4772
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s, t;
    cin >> s >> t;
    for (int i = 0; i < s.size(); i++) {
        int j = 0;
        for (; j < s.size(); j++)
            if (s[j] != t[(i+j)%s.size()]) break;
        if (j == s.size()) { cout << "Yes\n"; return 0; }
    }
    cout << "No\n";
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int n,d;
    while(cin>>d>>n,n||d){
        int a[100],e[100],r[100];
        for(int i=0;i<n;i++)cin>>a[i]>>e[i]>>r[i];
        int dp[101][101];fill_n(*dp,101*101,1<<25);
        dp[0][0]=0;
        for(int i=0;i<d;i++){
            for(int j=0;j<=100;j++){
                for(int k=0;k<n;k++){
                    if(j<r[k])continue;
                    int a_=min(i+a[k],d);
                    int e_=min(j+e[k],100);
                    dp[a_][e_]=min(dp[a_][e_],dp[i][j]+1);
                }
            }
        }
        int mi=1<<25;
        for(int i=0;i<=100;i++)mi=min(dp[d][i],mi);
        if(mi==(1<<25))cout<<"NA"<<endl;
        else cout<<mi<<endl;
    }
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    int n,d,x;
    cin >> n >> d >> x;
    int sum=x;
    vi a(n);
    rp(i,n) cin >> a.at(i);
    rp(i,n){
        sum+=(d+a[i]-1)/a[i];
    }
    print(sum);
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

Measured memory_bytes: 3596
#!/usr/bin/env python3
import sys

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


def solve(N: int):
    if N == 1:
        print(0)
        return
    divs = factorization(N)
    ans = 0
    for d in divs:
        k = d[1]
        i = 1
        while k-i >= 0:
            k -= i
            ans+=1
            i+=1
    print(ans)



    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9504
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    string A,B,C;
    cin >> A >> B >> C;
    if(A[A.size()-1]==B[0]&&B[B.size()-1]==C[0]) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

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

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}



void _main() {
        int n; cin >> n;
        vector<int> a(n); cin >> a;


        int ans = 0;
        for (int i = 0; i < n; i++) {
                if (a[i] == i + 1) {
                        swap(a[i], a[i + 1]);
                        ans++;
                }
        }

        cout << ans;
}



signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}


Measured memory_bytes: 3696
import io.StdIn.{readInt, readLine}
object Main extends App {
  val n = readInt
  val a = readLine
  val b = readLine
  val c = readLine

  val diff_count = (0 until n).map(i => {
    val chA = a(i)
    val chB = b(i)
    val chC = c(i)
    
    if      (chA == chB && chB == chC && chC == chA) 0
    else if (chA == chB && chB != chC && chC != chA) 1
    else if (chA != chB && chB == chC && chC != chA) 1
    else if (chA != chB && chB != chC && chC == chA) 1
    else  /*(chA != chB && chB != chC && chC != chA)*/ 2

  }).sum
  println(diff_count)
}

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

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



Measured memory_bytes: 3064
x, n = map(int, input().split())
p = list(map(int, input().split()))

d = [abs(x-i) for i in p]
if 0 not in d:
    print(x)
    exit()
else:
    cur = 1
    while True:
        if d.count(cur) == 0:
            print(x-cur)
            break
        elif d.count(cur) == 1:
            if x-cur not in p:
                print(x-cur)
                break
            else:
                print(x+cur)
                break
        else:
            cur += 1

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

int main() {
  int N,K;
  cin >> N >> K;
  vector<int> A(N);
  rep(i,N){
    cin >> A.at(i);
  }
  sort(A.begin(),A.end());
  int ans = 0;
  rep(i,K){
    ans += A.at(i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3628
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
#define int long long
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF (long long)(1e18)
#define MOD (int)(1e9+7)
#define MAX_N 103
#define MAX_V 10
#define MAX_M 101
#define min(a,b) (a>b?b:a)
#define max(a,b) (a>b?a:b)
#define yn(f) (f?"Yes":"No")
#define YN(f) (f?"YES":"NO")
#define pro "はいプロ　世界一○○が上手　○○界のtourist　○○時代の終焉を告げる者　実質○○　○○するために生まれてきた男"

signed main(){
	cout<<fixed<<setprecision(7);
	int n, a, b, count = 0;
	
	
	cin>>n>>a>>b;
	
	for(int i = 1; i <= n; i++){
		string temp = to_string(i);
		int num = 0;
		for(int j = 0; j < temp.size(); j++){
			num += temp[j] -'0';
		}
		if(a <= num && num <= b) count+=i;
	}
	
	
	cout<<count<<endl;
	
	return 0;
}

Measured memory_bytes: 256
import bisect
import array

n,m=map(int, input().split())
l={}
for i in range(n):
    a,b=map(int, input().split())
    if not a in l:
        l[a]=[b]
    else:
        l[a].append(b)

res=0
target=array.array('I', [])
for i in range(1,m+1):
    if i in l:
        for j in l[i]:
            bisect.insort_left(target, j)

    if not target:
        val=0
    else:
        val=target.pop()
    res+=val
    #print(target, max(target))

print(res)




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

#define NMAX 100010
#define MOD 1000000007
#define INF 2000000000
#define PI 3.1415926535
#define EPS 1.e10-6

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

typedef unsigned long long ull;

using namespace std;

int m1, d1, m2, d2;

int main()
{
	cin >> m1 >> d1 >> m2 >> d2;
	if (d2 < d1)
		cout << 1 << '\n';
	else
		cout << 0 << '\n';
	return 0;
}

Measured memory_bytes: 256
#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+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverseA(A.begin(),A.end());

typedef long long ll;

int main(){
  int H,N;
  cin >>H>>N;
  rep(i,N){
    int x;
    cin >>x;
    H -= x;
  }
  string ans = (H>0) ? "No" : "Yes";
  cout << ans << endl;
}

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

#define fast ios_base::sync_with_stdio(false),cin.tie(NULL)
#define int long long

#define fr first
#define se second
#define lb lower_bound 
#define ub upper_bound 
#define pb push_back
#define mpr make_pair

#define pi pair<int,int>

#define vi vector<int>

#define vpi vector< pi >

#define mi map<int,int>


#define forr(a,b) for (int i = (a); i < (b); ++i)
#define rrof(a,b) for (int i = (b)-1; i >= (a); --i)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)

const int md = 1e9+7;
const int MX = 2e5+5;
const int INF = 1e18; 


int power_md(int a,int n)
{
 int res=1;
 while(n)
{
 if(n%2)
  res=(res%md*a%md)%md;
  a=(a%md*a%md)%md;
  n/=2;
}
res%=md;
return res;
}

int power(int a,int n)
{
 int res=1;
 while(n)
{
 if(n%2)
  res*=a;
  a=a*a;
  n/=2;
}
return res;
}

int abst(int a)
{
 return ((a<0)?(-1*a):(a));
}

class cmp_set{
public:
	bool operator() (int a, int b){
		return a > b;
	}
};

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 XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

int cost[10];
int n,m;
int a[10];
string dp[10005];
bool vis[10005];

string maxs(string s1,string s2)
{
    if(s1[s1.size()-1]=='0')
     return s2;
     else if(s2[s2.size()-1]=='0')
      return s1;
      
    if(s1.size()>s2.size())
     return s1;
    else if(s2.size()>s1.size())
     return s2;
    else
    {
        for(int i=0;i<s1.size();i++)
        {
            if(s1[i]>s2[i])
             return s1;
             else if(s2[i]>s1[i])
              return s2;
           
        }
        return s1;
    }
}

string fun(int rem)
{
     string res;
    if(rem==0)
     return res;
     if(vis[rem])
      return dp[rem];
     int f=0;
    for(int j=0;j<m;j++)
    {
        if(cost[a[j]]<=rem)
        {
            f=1;
            string p=fun(rem-cost[a[j]]);
            string q;
            char ch=a[j]+'0';
            q+=ch;
            q+=p;
            res=maxs(res,q);
        }
    }
    if(f==0)
    {
        string z ="0";
        return z;
    }
    vis[rem]=true;
    return dp[rem]=res;
}

int32_t main()
{
    fast;
    for(int i=0;i<=n;i++)
     vis[i]=false;
    cost[1]=2,cost[2]=5,cost[3]=5,cost[4]=4,cost[5]=5;
    cost[6]=6,cost[7]=3,cost[8]=7,cost[9]=6;
   
   cin>>n>>m;
   
   for(int i=0;i<m;i++)
    cin>>a[i];
   string p;
   p=fun(n);
   cout<<p<<"\n";
   return 0;
}

Measured memory_bytes: 27264
using System;
using System.Collections.Generic;
using System.Linq;

class Program {
    static int ReadInt() { return int.Parse(Console.ReadLine()); }
    static int[] ReadInts() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); }
    static string[] ReadStrings() { return Console.ReadLine().Split(); }

    static void Main() {
        int n = ReadInt();

        int x = n * 800;
        int y = 200 * (n / 15);
        Console.WriteLine(x - y);
    }
}

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

using namespace std;

const int maxn = 100005;

bool f[maxn];
string s;

int main()
{
	cin >> s;	
	f[0] = 1;
	for(int i = 1;i <= s.length();i ++)
	{
		if (i >= 5)
		{
			string a = s.substr(i - 5,5);
			if (a == "dream" || a == "erase") f[i] |= f[i - 5];
		}
		if (i >= 6)
		{
			string a = s.substr(i - 6,6);
			if (a == "eraser") f[i] |= f[i - 6];
		}
		if (i >= 7)
		{
			string a = s.substr(i - 7,7);
			if (a == "dreamer") f[i] |= f[i - 7];
		}
	}
	cout << (f[s.length()] ? "YES" : "NO") << endl;
}


Measured memory_bytes: 512
import Control.Applicative ((<$>))
import Data.List (sort)
import Data.List.Split (chunksOf)
import Data.Bool (bool)

main :: IO ()
main = solve <$> map read <$> words <$> getLine >>= putStrLn

solve :: [Int] -> String
solve = bool "no" "yes" . all f . chunksOf 4 . sort
  where f = and . (tail >>= zipWith (==))



Measured memory_bytes: 3784
n,k=map(int,input().split())
a=list(map(int,input().split()))
visited=[False]*(n+1)
visited[1]=True
l=[1]
i=a[0]

for x in range(n):
    if visited[i]:break
    visited[i]=True
    l.append(i)
    i=a[i-1]

d=-1
for x in range(n):
    if l[x]==i:
        d=x
        break

f=l[:d]
b=l[d:]

if len(f)==0:
    print(b[k%len(b)])
    exit()
 
if len(b)==0:
    print(f[k%len(f)])
    exit()

if k<=d:
    print(l[k])
    exit()
 
k-=len(f)
print(b[k%len(b)])

Measured memory_bytes: 32332
#include <bits/stdc++.h>
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define sz(v) (int)(v).size()
using namespace std;
using P = pair<int, int>;
typedef long long ll;
int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	string s;
	cin >> s;
	int flag = 1;
	rep(i, sz(s))
	{
		if (flag == 0) break ;
		if (i % 2 == 0)
		{
			if (!(s[i] == 'R' || s[i] == 'U' || s[i] == 'D'))	flag = 0;
		}
		else if (i % 2 == 1)
		{
			if (!(s[i] == 'L' || s[i] == 'U' || s[i] == 'D'))	flag = 0;
		}
	}
	string ans = flag ? "Yes" : "No";
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 256
#include<functional>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<string>
#include<math.h>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
using namespace std;
const int INF=100000000;
char a[100][100];
int h,w;
void dfs(int x,int y,char f){
  if(x<0||y<0||x>=w||y>=h)return ;
  if(a[y][x]==f){
    a[y][x]='$';
  }else return ;
  dfs(x+1,y,f);
  dfs(x-1,y,f);
  dfs(x,y+1,f);
  dfs(x,y-1,f);
}

int main(){
  while(cin>>h>>w,h!=0){
    rep(i,h)rep(j,w)cin>>a[i][j];
    int count=0;
    rep(i,h){
      rep(j,w){
	if(a[i][j]!='$'){
	  dfs(j,i,a[i][j]);
	  count++;
	}
      }
    }
    cout<<count<<endl;
  }
  return 0;
}

Measured memory_bytes: 3368
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
using namespace std;
#define vel vector<long long>
#define vvel vector<vel>
#define int long long
#define rep(i,n) for(long long i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define V vector
long long p = 1000000007;
vel kai(300001, 1);
vel ink(300001, 1);
template<typename T>
V<T> uni(V<T> &list) {
	if (list.size() == 0) { return list; }
	sort(list.begin(), list.end());
	V<T> ql(1, list[0]);
	rep(i, list.size() - 1) {
		if (list[i] != list[i + 1]) { ql.push_back(list[i + 1]); }
	}
	return ql;
}
int ru(int a, int r) {
	if (r == 0) { return 1; }
	int ans = ru(a, r / 2);
	ans *= ans; ans %= p;
	if (r % 2 == 1) { ans *= a; }
	return ans % p;
}
int inv(int a) {
	return ru(a, p - 2);
}
void make_kai() {
	rep(i, 300000) { kai[i + 1] = (kai[i] * (i + 1)) % p; }
	rep(i, 300001) { ink[i] = inv(kai[i]); }
}
int com(int n, int r) {
	int ans = kai[n] * ink[r];
	ans %= p; ans *= ink[n - r]; ans %= p;
	return ans;
}
signed main() {
	int n; cin >> n;
	int a, b, c; cin >> a >> b >> c;
	int w = a * inv(a + b); w %= p;
	int l = b * inv(a + b); l %= p;
	int ans = 0;
	int all = 0;
	make_kai();
	vel rw(n+1, 1), rl(n+1, 1);
	rep(i, n) { rw[i + 1] = (rw[i] * w) % p; rl[i + 1] = (rl[i] * l) % p; }
	rep(i, n) {
		int pl = (com(n - 1 + i, i)*rw[i]) % p;
		pl *= rl[n]; pl %= p;
		ans += pl*(n+i); ans %= p;
		all += pl;
	}
	rep(i, n) {
		int pl = (com(n - 1 + i, i)*rl[i]) % p;
		pl *= rw[n]; pl %= p;
		ans += pl * (n + i); ans %= p;
		all += pl;
	}
	ans *= 100; ans %= p; ans *= inv(100 - c); ans %= p;
	cout << (ans*inv(all)) % p << endl;
	return 0;
}


Measured memory_bytes: 6528
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=101101;
int a[N];
int n,m,sum=0;
int main(){
	scanf("%d%d",&m,&n);
	for (int i=1; i<=n; i++)
		scanf("%d",&a[i]),sum+=a[i];
	if (sum>=m)	printf("Yes");
	else printf("No");
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

using pl = pair<ll,ll>;

const int N = 14348907;
pl f[N],s[N];
int ff=0, ss=0;
bool vis[N]={};

const ll INF = 101010101010101010LL;
const int SEG = 1<<24;
ll dat[2*SEG-1];

inline void init()
{
    fill(dat,dat+2*SEG-1,-INF);
    rep(i,ff) dat[SEG-1+i] = f[i].se;
    for(int i=SEG-2; i>=0; --i) dat[i] = max(dat[2*i+1],dat[2*i+2]);
}

inline ll _query(int a, int b, int k, int l, int r)
{
    if(r<=a || b<=l) return -INF;
    if(a<=l && r<=b) return dat[k];
    ll vl=_query(a,b,2*k+1,l,(l+r)/2);
    ll vr=_query(a,b,2*k+2,(l+r)/2,r);
    return max(vl,vr);
}

inline ll query(int a, int b)
{
    return _query(a,b,0,0,SEG);
}

int main()
{
    int p3[17];
    p3[0]=1;
    for(int i=1; i<17; ++i) p3[i]=p3[i-1]*3;

    int n;
    ll D,x[30],y[30];
    scanf(" %d %lld", &n, &D);
    rep(i,n) scanf(" %lld %lld", &x[i], &y[i]);

    int F = n/2, S = n-F;

    rep(i,p3[F]-1)
    {
        if(vis[i]) continue;

        int mask = i;
        int rev = 0;
        ll ax=0,ay=0,bx=0,by=0;
        rep(j,F)
        {
            if(mask%3==0)
            {
                ax += x[j];
                ay += y[j];
                rev += p3[j];
            }
            else if(mask%3==1)
            {
                bx += x[j];
                by += y[j];
            }
            else rev += p3[j]*2;
            mask /= 3;
        }

        vis[i] = vis[rev] = true;
        f[ff++] = {bx-ax,by-ay};
        f[ff++] = {ax-bx,ay-by};
    }
    f[ff++] = {0,0};

    fill(vis,vis+N,false);
    rep(i,p3[S]-1)
    {
        if(vis[i]) continue;

        int mask = i;
        int rev = 0;
        ll ax=0,ay=0,bx=0,by=0;
        rep(j,S)
        {
            if(mask%3==0)
            {
                ax += x[F+j];
                ay += y[F+j];
                rev += p3[j];
            }
            else if(mask%3==1)
            {
                bx += x[F+j];
                by += y[F+j];
            }
            else rev += p3[j]*2;
            mask /= 3;
        }

        vis[i] = vis[rev] = true;
        s[ss++] = {bx-ax,by-ay};
        s[ss++] = {ax-bx,ay-by};
    }
    s[ss++] = {0,0};

    sort(f,f+ff);
    sort(s,s+ss,greater<pl>());

    init();

    ll ans = 0;
    int lidx = 0, ridx = 0;
    rep(i,ss)
    {
        ll X = s[i].fi, Y = s[i].se;
        while(ridx<ff && X+f[ridx].fi<=D) ++ridx;
        while(lidx<ridx && X+f[lidx].fi<-D) ++lidx;

        ans = max(ans, Y+query(lidx, ridx));
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 727808
def CalcID( r, t ) :
    return r + 5*t

n = int(input())
for i in range(n):
    r,t = map(int, input().split())
    onR = r%100 == 0
    onT = t%30 == 0
    r = int(r/100)
    t = int(t/30)

    if onR and onT : print(CalcID(r, t))
    elif onR : print('{0} {1}'.format(CalcID(r,t),CalcID(r,t+1)))
    elif onT : print('{0} {1}'.format(CalcID(r,t),CalcID(r+1,t)))
    else : print('{0} {1} {2} {3}'.format(CalcID(r,t),CalcID(r+1,t),CalcID(r,t+1), CalcID(r+1,t+1)))



Measured memory_bytes: 5604
import java.io.*;
import java.lang.*;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.StringTokenizer;
import java.math.BigInteger;

public class Main {
    static InputReader in = new InputReader(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int n = in.nextInt();
        int m = in.nextInt();
        int c = in.nextInt();
        int[] arr = new int[m];
        for(int i = 0; i<m; i++){
            arr[i] = in.nextInt();
        }
        int count = 0;
        while(n-->0){
            int sum = c;
            for(int i = 0; i<m; i++){
                sum+=arr[i]*in.nextInt();
            }
            if(sum>0){
                ++count;
            }
        }
        out.println(count);
        out.close();
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            try {
                return reader.readLine();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }

        public boolean hasNext() {
            String next = null;
            try {
                next = reader.readLine();
            } catch (Exception e) {
            }
            if (next == null) {
                return false;
            }
            tokenizer = new StringTokenizer(next);
            return true;
        }

        public BigInteger nextBigInteger() {
            return new BigInteger(next());
        }
    }
}



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

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)((n)-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T>
string join(const vector<T>&v, string del=", "){ stringstream s;
    for(auto x : v) s << del << x; return s.str().substr(del.size());
}
template<typename T>
ostream& operator<<(ostream& o, const vector<T>&v){
    if(v.size()) o << "[" << join(v) << "]"; return o;
}
template<typename T>
ostream& operator<<(ostream& o, const vector<vector<T> >&vv){
    int l = vv.size();
    if(l){ o<<endl; rep(i,l) o << (i==0 ? "[ " : ",\n  " ) << vv[i] << (i==l-1 ? " ]" : ""); }
    return o;
}
template<typename T1, typename T2>
ostream& operator<<(ostream& o, const pair<T1, T2>& p){
    return o << "(" << p.first << ", " << p.second << ")";
}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");
    int n,k; cin >> n >> k;
    vl a(n);
    rep(i,n) cin >> a[i];

    auto check = [&](ll x){
        ll cnt = 0;
        rep(i,n){
            cnt += (a[i]+x-1)/x - 1;
        }
        return cnt <= k;
    };

    ll l=0, r=1e9;
    while(r-l>1){
        ll m = (l+r) / 2;
        if(check(m)) r = m;
        else l = m;
    }
    cout << r << endl;
    return 0;
}

Measured memory_bytes: 4832