akhauriyash/Code-Regression huggingface dataset:
use std::io::Write;
use std::ops::{Add, Sub, Mul};
use std::collections::HashMap;

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn main() {
    let (x, y): (isize, isize) = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        let s = s.trim_right().to_owned();
        let mut ws = s.split_whitespace();
        let a = ws.next().unwrap().parse().unwrap();
        let b = ws.next().unwrap().parse().unwrap();
        (a, b)
    };

    println!("{}", solve(x, y));
}

fn solve(x: isize, y: isize) -> isize {
    let xx3 = 2*x - y;
    let yy3 = -x + 2*y;
    debugln!("{:?}", (xx3, yy3));
    if !(xx3 % 3 == 0 && yy3 % 3 == 0 && xx3 >= 0 && yy3 >= 0) {
        return 0;
    }

    let xx = xx3 / 3;
    let yy = yy3 / 3;

    Modulo::binom(xx + yy, xx).0
}

#[derive(Debug, Copy, Clone)]
struct Modulo(isize);

const MODULO: isize = 1000000000 + 7;

fn positive_rem(a: isize, b: usize) -> isize {
    let b = b as isize;
    let mut value = a % b;
    if value < 0 {
        value += b;
    }
    value
}

impl Modulo {
    fn new(n: isize) -> Modulo {
        Modulo(n % MODULO)
    }

    fn pow(self, p: usize) -> Modulo {
        if self == Modulo(0) {
            return Modulo(0);
        }
        if p == 0 {
            return Modulo(1);
        }

        if p % 2 == 0 {
            let half = self.pow(p / 2);
            half * half
        } else {
            self.pow(p - 1) * self
        }
    }

    fn inv(self) -> Modulo {
        self.pow((MODULO - 2) as usize)
    }

    fn binom(n: isize, k: isize) -> Modulo {
        let mut ret = Modulo::new(1);
        for i in 1..(k + 1) {
            ret = ret * Modulo::new(n - i + 1) * Modulo::new(i).inv();
            // debugln!("{:?}", ret);
        }
        ret
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn inv() {
        assert_eq!(Modulo(1), Modulo(2).inv() * Modulo(2));
        assert_eq!(Modulo(1), Modulo(3).inv() * Modulo(3));
    }
}

impl Add for Modulo {
    type Output = Modulo;

    fn add(self, other: Modulo) -> Modulo {
        Modulo((self.0 + other.0) % MODULO)
    }
}

impl Sub for Modulo {
    type Output = Modulo;

    fn sub(self, other: Modulo) -> Modulo {
        Modulo(positive_rem(self.0 - other.0, MODULO as usize))
    }
}

impl Mul for Modulo {
    type Output = Modulo;

    fn mul(self, other: Modulo) -> Modulo {
        Modulo((self.0 * other.0) % MODULO)
    }
}

impl PartialEq for Modulo {
    fn eq(&self, &other: &Self) -> bool {
        self.0 == other.0
    }
}

impl Eq for Modulo {}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX 100
 
int main()
{
    int n, pos = 0;
    char ch;
    vector<int> v[MAX];
 
    while (scanf("%d%c", &n, &ch) != EOF) {
	v[pos].push_back(n);
	if (ch == '\n') {
	    pos++;
	}
    }
  
    int dp[MAX][MAX];
    dp[0][0] = v[0][0];
    for (int i = 1; i < pos; i++) {
	for (int j = 0; j < (int)v[i].size(); j++) {
	    if (i <= pos / 2) {
		if (!j) {
		    dp[i][j] = v[i][j] + dp[i-1][j];
		} else if (j == (int)v[i].size()-1) {
		    dp[i][j] = v[i][j] + dp[i-1][j-1];
		} else {
		    dp[i][j] = v[i][j] + max(dp[i-1][j-1], dp[i-1][j]);
		}
	    } else {
		dp[i][j] = v[i][j] + max(dp[i-1][j],dp[i-1][j+1]);
	    }
	}
    }
    cout << dp[pos-1][0] << endl; 
    return 0;
}

Measured memory_bytes: 3196
n, k = (int(x) for x in input().split())
ans = 0
if n >= k:
    lim = k
    ans += (n - k + 1)/n
else: lim = n + 1
for i in range(1, lim):
    num = i
    cnt = 0
    while num < k:
        num *= 2
        cnt += 1
    ans += (0.5 ** cnt) / n
print(ans)

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

int main(void) {
	int A, B;
	string post_number;

	cin >> A >> B;
	cin >> post_number;
	bool ok = false;
	for (int i = 0; i < post_number.length(); i++) {
		if (i != A && post_number[i] == '-') {
			ok = false;
			break;
		}
		else if (i == A && post_number[i] == '-') {
			ok = true;
		}
	}
	if (ok) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define repn(i, n) for(int i = 1; i <= (int)n; ++i)
#define pb push_back
#define lb lower_bound
#define mp make_pair
#define ite iterator
#define max2(x, y) ((x) > (y)) ? (x) : (y)
#define max3(x,y,z) max2((x), max2((y),(z)))
#define max4(v,w,x,y) max2(max2((v),(w)), max2((x),(y)))
#define min2(x, y) ((x) > (y)) ? (y) : (x)
#define min3(x,y,z) min2((x), min2((y),(z)))
#define min4(v,w,x,y) min2(min2((v),(w)), min2((x),(y)))
#define ul unsigned long
#define ull unsigned long long
#define INF 1000000007
#define MOD 1000000007
#define fs first
#define sd second

template<typename T>
bool elem(set<T> st, T val){
	return (st.find(val) != st.end());
}

template<typename T>
void printv(vector<T> vt){
    rep(i, vt.size() - 1)
        cout << vt[i] << " ";
    cout << vt[vt.size() - 1] << endl;
}

typedef vector<int> vint;
typedef vector<ul> vul;
typedef vector<ull> vull;
typedef pair<int, int> pii;

int main(void){
    vint a;
    int d;
    while(cin >> d) a.pb(d);
    sort(a.begin(), a.end(), greater<int>());
    rep(i, 3)
        cout << a[i] << endl;
    return 0;
}

Measured memory_bytes: 1216
#include <iostream>
#include <cstdio>
#include <set>
using namespace std;

int main(){
    long long n, m;

    cin >> n >> m;

    multiset<long long> s;

    for(long long i = 0; i < n; i++){
        long long a;
        cin >> a;
        s.insert(a);
    }

    multiset<long long>::iterator it;
    for(long long i = 0; i < m; i++){
        it = s.end();
        it--;
        long long maxv = *it;
        s.erase(it);
        maxv = maxv/2;
        s.insert(maxv);
    }

    

    long long sum = 0;
    multiset<long long>::iterator it2;
    for(it2 = s.begin(); it2 != s.end(); it2++){
        sum += *it2;
    }

    cout << sum << endl;

    return 0;
}

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

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

  vector<int> d(N);
  for (int i = 0; i < N; i++) cin >> d[i];

  sort(d.begin(), d.end());

  int count = 0;
  int old = 0;
  for (int t : d) {
    if (old < t) {
      count++;
      old = t;
    }
  }

  cout << count << endl;
}

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

#define INF 1e9
#define LLINF 1e18
#define pi 3.14159265358979323
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

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


int main() {
    string s;
    cin >> s;
    if (s.size() % 2 != 0) {
        cout << "No" << endl;
        return 0;
    }
    rep(i, s.size()) {
        if (i % 2 == 0 && s.at(i) != 'h') {
            cout << "No" << endl;
            return 0;
        }
        else if (i % 2 == 1 && s.at(i) != 'i') {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 3636
n = int(input())
A = list(map(int, input().split()))

n2, n4 = 0, 0
for a in A:
    if a % 4 == 0:
        n4 += 1
    elif a % 2 == 0:
        n2 += 1

if n2 != 0:
    n -= (n2-1)
print('Yes' if n4 >= n//2 else 'No')


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

using namespace std;


int main()
{
    long long n,i,ans=1,f=0;
    cin>>n;
    long long a[n+2];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    for(i=n-1;i>0;i--)
    {
        if(a[i-1]==a[i])
        {
            ans*=a[i];
            f++;
            i--;
            if(f==2)
            {
                break;
            }
        }
    }
    if(f!=2)
    {
        cout<<0<<endl;
    }
    else
    {
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 1024
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( stdin . lock ( ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        n: i64, l: i64
    }

    let mut taste = vec![];
    for i in 0..n {
        taste.push(l + i);
    }
    taste.sort_by_key(|t| t.abs());
    let mut total = 0;
    for i in 1..n {
        total += taste[i as usize];
    }
    println!("{}", total);
}

Measured memory_bytes: 4352
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c==' '||c=='\n')c=_buff.get();return c;}
const double pi=acos(-1);
const double dlt1=20-5*pi;
const double dlt2=10*pi-20;
int xa,ya,xb,yb,n;
pair<int,int> a[200111];
int cnt[200111];
void change(int x,int v)
{
	for(int i=x;i<=200011;i+=i&(-i))cnt[i]=max(cnt[i],v);
}
int query(int x)
{
	int mx=0;
	for(int i=x;i>0;i-=i&(-i))mx=max(mx,cnt[i]);
	return mx;
}
int v[200111],vn;
int dp[200111];
double solve()
{
	double ans=(xb-xa+yb-ya)*100ll;
	if(n==0)return ans;
	bool ok=1;
	for(int i=1;i<n;i++)ok&=a[i].SS<a[i+1].SS;
	if(ok&&(min(xb-xa+1,yb-ya+1)==n))
	{
		ans+=dlt2;
		ans-=(n-1)*dlt1;
		return ans;
	}
	for(int i=1;i<=n;i++)
	{
		v[vn++]=a[i].SS;
	}
	sort(v,v+vn);
	for(int i=1;i<=n;i++)
	{
		a[i].SS=lower_bound(v,v+vn,a[i].SS)-v+1;
	}
	int mx=0;
	for(int i=1;i<=n;i++)
	{
		dp[i]=query(a[i].SS)+1;
		change(a[i].SS,dp[i]);
		mx=max(mx,dp[i]);
	}
//	cerr<<"mx="<<mx<<endl;
	return ans-mx*dlt1;
}
int main()
{
	getii(xa,ya);
	getii(xb,yb);
	if(xa>xb)
	{
		swap(xa,xb);
		swap(ya,yb);
	}
	bool flag=0;
	if(ya>yb)
	{
		flag=1;
		ya=100000000-ya;
		yb=100000000-yb;
	}
	int nn;
	geti(nn);
	for(int i=1;i<=nn;i++)
	{
		getii(a[i].FF,a[i].SS);
		if(flag)a[i].SS=100000000-a[i].SS;
		if(xa<=a[i].FF&&a[i].FF<=xb&&ya<=a[i].SS&&a[i].SS<=yb)
		{
			a[++n]=a[i];
		}
	}
	sort(a+1,a+n+1);
//	cerr<<"n="<<n<<endl;
//	for(int i=1;i<=n;i++)cerr<<a[i].FF<<" "<<a[i].SS<<endl;
	double ans=solve();
	printf("%.18lf\n",ans);
	return 0;
}

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

/*色の区別は必要ない？*/
/*一回の操作で1以上の同色連続部分を除去できるので、1色になるまで除去*/

string S;
vector<int> ser;

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

  int i = 0;
  while(i < L){
    int j = 0;
    while(S[i+j] == S[i] && i + j < L) j++;
    ser.push_back(j);
    i += j; j = 0;
  }

  cout << ser.size() - 1 << endl;
  return 0;
}

  

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using ld = long double;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

const int64 mod = 1e9+7;


int main(void){
	int32 N;
	cin >> N;
	vector<int64> a(N);
	REP(i, N) cin >> a[i];
	vector<int64> cost1(N+1, 0), cost2(N+1, 0);
	int64 prev = INF;
	{
		vector<int64> b(a);
		stack<int32> st;
		REP(i, N){
			if(i > 0) cost1[i] = cost1[i-1];
			cost1[i]++;
			a[i] *= -2;
			if(i == 0){
				st.emplace(i);
			}else{
				while(a[i-1] > a[i]){
					a[i-1] *= 4;
					int32 j = st.top(); st.pop();
					if(j != i-1) a[j] *= 4;
					cost1[i] += (i-j)*2;
					if(j == 0 || a[j-1] <= a[j]*4) st.emplace(j);
				}
				if(a[i-1] <= a[i]*4) st.emplace(i);
			}
		}
		a = b;
	}
	prev = -INF;
	{
		vector<int64> b(a);
		stack<int32> st;
		for(int32 i = N-1;i >= 0;i--){
			if(i < N-1) cost2[i] = cost2[i+1];
			if(i == N-1){
				st.emplace(i);
				continue;
			}else{
				while(a[i] > a[i+1]){
					a[i+1] *= 4;
					int32 j = st.top(); st.pop();
					if(j != i+1) a[j] *= 4;
					cost2[i] += (j-i)*2;
					if(j == N-1 || a[j]*4 <= a[j+1]) st.emplace(j);
				}
				if(a[i]*4 <= a[i+1]) st.emplace(i);
			}
		}
		a = b;
	}
	int64 res = min(cost2[0], cost1[N-1]);
	REP(i, N-1){
		res = min(res, cost1[i]+cost2[i+1]);
	}
	cout << res << endl;
}


Measured memory_bytes: 6528
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n;
	cin >> n;
	vi a(n);
	int pos = 0, neg = 0;
	int mx = -1e9, mn = 1e9;
	int mxInd = -1, mnInd = -1; 
	rep(i, n){
		cin >> a[i];
		if(a[i] < 0) neg++;
		else pos++;
		if(a[i] > mx){
			mx = a[i];
			mxInd = i;
		}
		if(a[i] < mn){
			mn = a[i];
			mnInd = i;
		}
	}
	vector<pi> ans;
	if(!neg){
		for(int i = 1; i < n; i++) ans.pb(mp(i - 1, i));
	}
	else if(!pos){
		for(int i = n - 2; i >= 0; i--) ans.pb(mp(i + 1, i));
	}
	else{
		if(mx > abs(mn)){
			rep(i, n) if(a[i] != mx) ans.pb(mp(mxInd, i));
			for(int i = 1; i < n; i++) ans.pb(mp(i - 1, i));
		}
		else{
			rep(i, n) if(a[i] != mn) ans.pb(mp(mnInd, i));
			for(int i = n - 2; i >= 0; i--) ans.pb(mp(i + 1, i));
		}
	}
	cout << ans.size() << endl;
	for(pi x : ans) cout << x.fi + 1 << " " << x.se + 1 << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 256
// practice with Dukkha, coached by rainboy
#include <algorithm>
#include <iostream>

using namespace std;

const int N = 2 + 3 + 3 + 3 + 4 + 4 + 4, A = 4, MD = 1000000007;

int tt[N][A], n;
bool eof[N];

void build(string *ss, int m) {
	static int ii[26];
	ii['A' - 'A'] = 0;
	ii['C' - 'A'] = 1;
	ii['G' - 'A'] = 2;
	ii['T' - 'A'] = 3;
	n = 2;
	for (int h = 0; h < m; h++) {
		int l = ss[h].length();
		int i = 1;
		for (int k = 0; k < l; k++) {
			int a = ii[ss[h][k] - 'A'];
			int &j = tt[i][a];
			if (j == 0)
				j = n++;
			i = j;
		}
		eof[i] = true;
	}
	fill(tt[0], tt[0] + A, 1);
	static int ff[N], qu[N];
	int head = 0, cnt = 0;
	ff[1] = 0, qu[head + cnt++] = 1;
	while (cnt) {
		int i = qu[cnt--, head++];
		int e = ff[i];
		for (int a = 0; a < A; a++) {
			int &j = tt[i][a];
			int f = tt[e][a];
			if (j == 0)
				j = f;
			else
				ff[j] = f, qu[head + cnt++] = j;
		}
	}
}

int main() {
	int l; cin >> l;
	string ss[6] = { "AGC", "ACG", "GAC", "AGGC", "AGTC", "ATGC" };
	build(ss, 6);
	static int dp[N], dq[N];
	dp[1] = 1;
	while (l--) {
		for (int i = 1; i < n; i++) {
			int x = dp[i];
			if (x == 0 || eof[i])
				continue;
			for (int a = 0; a < A; a++) {
				int j = tt[i][a];
				dq[j] = (dq[j] + x) % MD;
			}
		}
		for (int i = 0; i < n; i++)
			dp[i] = dq[i], dq[i] = 0;
	}
	int ans = 0;
	for (int i = 1; i < n; i++)
		if (!eof[i])
			ans = (ans + dp[i]) % MD;
	cout << ans << '\n';
	return 0;
}


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

int main(){
  int N; cin >>N;
  vector<int> X(N);
  for(int i=0; i<N; i++){
    cin >>X[i];
  }
  
  sort(X.begin(),X.end());
  
  long mini=1e10;
  //cout <<mini;
  for(int i=X[0]; i<X[N-1]+1; i++){
    long tmp=0;
    for(int j=0; j<N; j++){
      tmp += (X[j] - i) *(X[j] - i);
    }
    mini=min(tmp,mini);
  }
  
  cout <<mini <<endl;
  
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int k,n,a[200050]={0},max=-1;
	scanf("%d%d",&k,&n);
	for(int i=0;i<n;i++)
	scanf("%d",&a[i]);
	sort(a,a+n);
	for(int i=0;i<n-1;i++)
	if(a[i+1]-a[i]>max)
	max=a[i+1]-a[i];
	if(a[0]+k-a[n-1]>max)
	max=a[0]+k-a[n-1];
	printf("%d",k-max);
	return 0;
 } 

Measured memory_bytes: 1024
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

template <typename T, T N>
class UnionFind {
    T parent_[N];
    T rank_[N];
    T size_[N];

public:
    UnionFind();
    T Root(T idx);
    bool IsSame(T x, T y);
    void Unite(T x, T y);
    T GetSize(T idx);
};

template <typename T, T N>
UnionFind<T, N>::UnionFind()
{
    for (T i = 0; i < N; i++) {
        parent_[i] = i;
        rank_[i] = 0;
        size_[i] = 1;
    }
}

template <typename T, T N>
T UnionFind<T, N>::Root(T idx)
{
    return parent_[idx] == idx ? idx : parent_[idx] = Root(parent_[idx]);
}

template <typename T, T N>
bool UnionFind<T, N>::IsSame(T x, T y)
{
    return Root(x) == Root(y);
}

template <typename T, T N>
void UnionFind<T, N>::Unite(T x, T y)
{
    x = Root(x);
    y = Root(y);
    if (x == y) {
        return;
    }

    if (rank_[x] < rank_[y]) {
        parent_[x] = y;
        size_[y] += size_[x];
    } else {
        parent_[y] = x;
        size_[x] += size_[y];
        if (rank_[x] == rank_[y]) {
            rank_[x]++;
        }
    }
}

template <typename T, T N>
T UnionFind<T, N>::GetSize(T idx)
{
    return size_[Root(idx)];
}

long long pow_mod(long long n, long long p, long long m)
{
    if (p == 0) {
        return 1;
    }

    if (p % 2 == 0) {
        long long t = pow_mod(n, p / 2, m);
        return t * t % m;
    }
    return n * pow_mod(n, p - 1, m) % mod;
}

long long nCr_mod(long long n, long long r)
{
    long long x = 1;
    for (long long i = n - r + 1; i <= n; i++) {
        x *= i;
        x %= mod;
    }

    long long a = 1;
    for (long long i = 1; i <= r; i++) {
        a *= i;
        a %= mod;
    }

    long long y = pow_mod(a, mod - 2, mod) % mod;

    return x * y % mod;
}

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

    std::vector<long long> h(n);
    for (int i = 0; i < n; i++) {
        std::cin >> h[i];
    }

    long long ans = 0;
    while (*std::max_element(h.begin(), h.end())) {
        for (int i = 0; i < n; i++) {
            if (h[i]) {
                for (int j = i; j < n && h[j]; j++) {
                    h[j]--;
                }

                ans++;
                break;
            }
        }
    }

    std::cout << ans << std::endl;
}


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

map<int,int> mp;

int main(){
  int N,M;
  cin >> N >> M;
  for(int i=0;i<M;i++){
    int a,b;
    cin >> a >> b;
    mp[a]++;
    mp[b]++;
  }
  for(auto p:mp){
    if(p.second%2){
      puts("NO");
      return 0;
    }
  }
    puts("YES");
    return 0;
}

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

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(lol i=0;i<lol(n);i++)
#define REPD(i,n) for(lol i=n-1;i>=0;i--)
#define FOR(i,a,b) for(lol i=a;i<=lol(b);i++)
#define FORD(i,a,b) for(lol i=a;i>=lol(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) lol(x.size()) //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//最大値最小値
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

char NumToCh(lol num);
vector<char> c;
int nums;

int main()
{
    lol n; cin >> n;
    lol a[12], k;
    lol index;

    a[0] = 0;
    FOR(i, 1, 12)
    {
        a[i] = pow(26, i) + a[i - 1];
        if(n <= a[i])
        {
            k = n - a[i - 1] - 1;
            index = i;
            break;
        }
    }
    REP(i, index)
    {
        c.push_back(NumToCh(k % 26));
        k = k / 26;
    }
    REPD(i, index)
        cout << c[i];
    cout << endl;
    return 0;
}

char NumToCh(lol num)
{

    int i = (int)'a';
    return (char)(i + num);

}

Measured memory_bytes: 4016
#include<stdio.h>
int main(){
	int n=0,i=0,Min=0,Max=0;
	int a[10001]={};
	long Sum=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	Min=Max=a[0];
	for(i=0;i<n;i++){
		Min=a[i]<Min?a[i]:Min;
		Max=a[i]<Max?Max:a[i];
		Sum+=a[i];
	}
	printf("%d %d %li\n",Min,Max,Sum);
}

Measured memory_bytes: 1832
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;


public class Main{
	
	public static void main(String[] args){
		
		Scanner sc = new Scanner(System.in);
		List<Double> list = new ArrayList<Double>();
		while(sc.hasNextDouble()) {
			double d = sc.nextDouble();
			if(d == 0) break;
			list.add(d);
		}
		sc.close();
		
		Collections.sort(list, new Comparator<Double>() {
			public int compare(Double o1, Double o2){
				if(o1 < o2) return -1;
				else if(o1 == o2) return 0;
				else return 1;
			}});
		
		double result = list.get(list.size()-1) - list.get(0);
		System.out.println(result);
	}
	
}

Measured memory_bytes: 18908
#include <iostream>
#include <string>

int main() {
    std::string s, t, u;
    int a, b;
    std::cin >> s >> t >> a >> b >> u;

    if(s == u) {
        std::cout << a - 1 << " " << b << std::endl;
    } else {
        std::cout << a << " " << b - 1 << std::endl;
    }
}


Measured memory_bytes: 256
import sys
mod=10**9+7 ; inf=float("inf")
from math import sqrt, ceil
from collections import deque, Counter, defaultdict #すべてのkeyが用意されてる defaultdict(int)で初期化
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP,Decimal  #変換後の末尾桁を0や0.01で指定
  #Decimal((str(0.5)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))
from functools import lru_cache
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#ソート、"a"+"b"、再帰ならPython3の方がいい
#######ここから天ぷら########


n,k=map(int,input().split())
P=list(map(int,input().split()))
P=[i-1 for i in P]
C=list(map(int,input().split()))
ans=-inf
for i in range(n):
    now=i
    total=0
    roop= 0
    po=deque([0])
    for kai in range(1,k+1):
        now=P[now]
        total += C[now]
        roop+=1
        po.append(total)
        ans=max(ans, total)
        if now == i:
            la= kai;break

    else: continue
    if total<0 : continue
    po=list(po)
    ans=max(ans, total* (k//roop) + max(po[:k%roop+1]), total*(k//roop-1) + max(po))
    #print(total, roop,po ,ans)
print(ans)

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

int main() {
    string text = "";
    string tmp = "";
    int count = 0;
    int n;

    while (true) {
        cin >> text >> count;
        if (text == "-") { break; }

        for (int i = 0; i < count; i++) {
            tmp = "";
            cin >> n;
            for (int j = n; j < text.size()+n; j++) {
                tmp += text.at(j%text.size());
            }
            text = tmp;
        }

        cout << text << endl;
    }
}


Measured memory_bytes: 3136
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void solve(void)
{

  string str; cin>>str;
  int N = 15, K = str.size();
  int cnt = 0;
  for (int i = 0; i < K; i++)
  {
    if(str[i] == 'o')cnt++;
  }
  if(N - K + cnt >= 8)
  {
    cout<<"YES"<<endl;
  }
  else
  {
    cout<<"NO"<<endl;
  }
  
  
  return;
}
int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int h[] = new int[n];
		for(int i = 0; i < n; ++i)h[i] = sc.nextInt();
		sc.close();
		int ans = 1;
		int max = h[0];
		for(int i = 1; i < n; ++i) {
			if(max <= h[i]) {
				max = h[i];
				++ans;
			}
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

const LL mod = 1e9 + 7;
const int N = 3010;

inline LL power(LL a, LL n, LL mod)
{
	LL Ans = 1;
	while (n)
	{
		if (n & 1) Ans = Ans * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return Ans;
}

int a[N], X[N], Y[N];
int n, q;

LL dp[N][N];

int main()
{
	LL inv2 = power(2, mod-2, mod);
	
	cin >> n >> q;
	for (int i = 1; i <= n; i++) scanf("%d", a + i);
	for (int i = 1; i <= q; i++) scanf("%d%d", X + i, Y + i);
	
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++) dp[i][j] = a[i] < a[j] ? 1 : 0;
	
	int cur = 0;
	for (int i = 1; i <= q; i++)
	{
		cur ^= 1;
		int a = X[i], b = Y[i];
		dp[a][b] = dp[b][a] = 1LL * inv2 * (dp[a][b] + dp[b][a]) % mod;
		for (int j = 1; j <= n; j++)
			if (j != a && j != b)
			{
				dp[j][a] = dp[j][b] = 1LL * inv2 * (dp[j][a] + dp[j][b]) % mod;
				dp[a][j] = dp[b][j] = 1LL * inv2 * (dp[a][j] + dp[b][j]) % mod;
			}
	}
	
	LL Ans = 0;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j < i; j++) Ans = (Ans + dp[i][j]) % mod;
	cout << Ans * power(2, q, mod) % mod << endl;
	
	return 0;
}

Measured memory_bytes: 74332
#include <bits/stdc++.h>
//#include <atcoder/all>
#define rep(i, n) for (int i = 0; i < (n); ++i)
// using namespace atcoder;
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
//マクロ
// forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
// Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
// xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end()  // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())       // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))    //最大値を求める
#define MIN(x) *min_element(ALL(x))    //最小値を求める
//定数
#define INF 1000000000000  // 10^12:極めて大きい値,∞
#define inf 2147483647     // int値の最大値
#define MOD 1000000007     // 10^9+7:合同式の法
#define MAXR 100000        // 10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back                             // vectorヘの挿入
#define MP make_pair                             // pairのコンストラクタ
#define F first                                  // pairの一つ目の要素
#define S second                                 // pairの二つ目の要素
#define CST(x) cout << fixed << setprecision(x)  //小数点以下の桁数指定
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int gcd(int a, int b) {
    if (b == 0)
        return a;
    else
        return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
//各桁の和
int sumDight(int x) {
    int sum = 0;
    while (x > 0) {
        sum += (x % 10);
        x /= 10;
    }
    return sum;
}
//回文数
int divideReverse(int x) {
    int reverse = 0;
    int r;
    while (x > 0) {
        r = x % 10;
        reverse = reverse * 10 + r;
        x /= 10;
    }
    return reverse;
}


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

    int n;
    vector<int> a(n+5);
    cin >> n;
    rep(i, n) cin >> a[i];

    sort(ALL(a));
    reverse(ALL(a));
    int suma = 0;
    int sumb = 0;
    for (int i = 0; i < n;i+=2){
        suma += a[i];
        sumb += a[i + 1];
    }
    cout << suma - sumb << endl;
}


Measured memory_bytes: 3672
use proconio::input;

fn main() {
    input! {
        (n, k): (usize, u128),
        aa: [usize; n]
    };

    let mut v = vec![0; n + 1];
    v[1] = 1;
    let mut bs = 0; // ループの開始
    let mut sa = 0; // ループの開始町
    let mut loopc = 0;
    let mut a = 1;
    for i in 1.. {
        a = aa[a-1];
        if v[a] > 0 {
            bs = i;
            sa = a;
            loopc = i - v[a] + 1;
            break;
        }

        v[a] = i + 1;
    }

    let mut c = 0;

    if k > bs {
        c = (k - bs) % loopc;
        a = sa;
    } else {
        c = k;
        a = 1;
    }

    for _ in 0..c {
        a = aa[a-1];
    }

    println!("{}", a);

/*
    v = [0, 1, 3, 5, 0, 4, 2]

    aa[1-1] -> 6
    a = 6

    aa[6-1] -> 2
    a = 2

    aa[2-1] -> 5
    a = 5

    aa[5-1] -> 3
    a = 3

    aa[3-1] -> 2
    a = 2

    aa[2-1] -> 5
    a = 5

    v[5] = 4

   loopc = 6 - 4 + 1 = 3
   bs = 2
   sa = 5
*/

/*
    6 5 2 5 3 2


    6 2 5 3 2 5 3 2

    k = 10


   5 3 2 5 3 2 | 5 3

   k = 8

   8 % 3 = 2

  ans = 3
*/

}


Measured memory_bytes: 8088
#include<bits/stdc++.h>
#define mod 1000000009
#define int long long
#define garou ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
int pow(int p,int r){
	int ans=1;
	while(r>0){
     if(r&1){
		 ans=((ans%mod)*(p%mod))%mod;
	 }
	 r=r>>1;
     p=((p%mod)*(p%mod))%mod;
	}
	return ans;
}
signed main() {
	 garou;
	 int k;
     cin>>k;
     queue<int> q;
     vector<int> v;
     for(int i=1;i<=9;i++){
         q.push(i);
         v.push_back(i);
     }
     while(q.front()<=3234566667){
     int a=q.front();
     q.pop();
  if(a%10!=0){
      int b=a*10+(a%10)-1;
      v.push_back(b);
      q.push(b);
  }
  int b=a*10+(a%10);
  v.push_back(b);
  q.push(b);
  if(a%10!=9){
      int b=a*10+(a%10)+1;
      v.push_back(b);
      q.push(b);
  }
     }
     cout<<v[k-1];
}

Measured memory_bytes: 8804
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

int main(){
  int n; cin >> n;
  string ans;
  if(n == 0){
    cout << 0 << endl;
    return 0;
  }
  while(1){
    if(n%2 == 0){
      ans += '0';
      n /= -2;
    }
    else{
      ans += '1';
      n--;
      n /= -2;
    }

    if(n == 1){
      ans += '1';
      break;
    }
  }

  reverse(all(ans));
  cout << ans << endl;
}

Measured memory_bytes: 256
open Batteries
let () =
  let a,b,c = Scanf.scanf "%s %s %s " (fun a b c -> a,b,c) in

  Printf.printf "%s\n" @@
  if 
    (String.sub a (String.length a - 1) 1) = (String.sub b 0 1) &&
    (String.sub b (String.length b - 1) 1) = (String.sub c 0 1)
  then "YES" else "NO"


Measured memory_bytes: 1152
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <stack>

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

typedef long long ll;

using namespace std;

int N, K, C;
char input[200000 + 5];
vector<int> left_most;
vector<int> right_most;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	scanf("%d %d %d", &N, &K, &C);
	scanf("%s", input);
	
	int before = -1 -C;

	for (int i = 0; input[i]; ++i)
	{
		if (input[i] == 'o' && i >= before + C + 1)
		{
			before = i;
			left_most.push_back(i);
		}
	}

	before = N + C;

	for (int i = N - 1; i >= 0; --i)
	{
		if (input[i] == 'o' && i <= before - C - 1)
		{
			before = i;
			right_most.push_back(i);
		}
	}

	reverse(right_most.begin(), right_most.end());

	if (left_most.size() == K && right_most.size() == K)
	{
		for (int i = 0; i < K; ++i)
		{
			if (left_most[i] == right_most[i]) printf("%d\n", left_most[i] + 1);
		}
	}

	return 0;
}

Measured memory_bytes: 3444
#include <iostream>
#include <thread>

using namespace std;

int sign(int x){
    if (x > 0)
        return 1;
    else if (x < 0)
        return -1;
    
    return 0;
}

int d(int x, int y){
    return y - x;
}

void solve(int x, int y, int &best, int c){
    
    if (x <= y)
        best = min(best, d(x, y) + c);
}

int main(){
    int x, y;
    cin >> x >> y;
    
    int best = numeric_limits<int>::max();
    
    solve(x, y, best, 0);
    solve(-x, y, best, 1);
    solve(x, -y, best, 1);
    solve(-x, -y, best, 2);
    
    cout << best << endl;
    
    return 0;
}

Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;

const int MOD=1e9+7;
const int MAXN=405;
typedef long long ll;

int n,c;
int a[MAXN],b[MAXN];
ll sum[MAXN][MAXN],t[MAXN],d[MAXN][MAXN];

ll ksm(ll x,int y){
    ll cnt=1ll;
    while(y){
        if(y&1) cnt=(cnt*x)%MOD;
        x=(x*x)%MOD;
        y>>=1ll;
    }
    return cnt;
}

int main(){
    scanf("%d%d",&n,&c);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for(int i=1;i<=n;i++)
        scanf("%d",&b[i]);
    for(int i=1;i<=n;i++){
        sum[i][0]=b[i]-a[i]+1;
        for(int j=a[i];j<=b[i];j++)
            t[j]=1;
        for(int j=1;j<=c;j++){
            ll now=0;
            for(int k=a[i];k<=b[i];k++)
                t[k]=(t[k]*k)%MOD,now=(t[k]+now)%MOD;
            sum[i][j]=now;
            //printf("sum[%d][%d]:%lld\n",i,j,now);
        }
    }
    for(int i=0;i<=c;i++)
        d[1][i]=sum[1][i];
    for(int i=2;i<=n;i++)
        for(int j=0;j<=c;j++)
            for(int k=0;k<=j;k++)
                d[i][j]=(d[i][j]+(d[i-1][j-k]*sum[i][k])%MOD)%MOD;
    printf("%lld",d[n][c]);
}


Measured memory_bytes: 2816
#include <cstdio>
int N ;
int F [100][14];
int P [100][15];
int main ()
{
scanf ("%d" ,&N );
for ( int i =0; i < N ; i ++)
{
for ( int j =0; j <10; j ++) scanf ("%d" ,&F[ i ][ j ]);
}
for ( int i =0; i < N ; i ++) for ( int j =0; j <11; j ++) scanf ("%d" ,&P[ i ][ j ]);
int res = -(1 <<30);
for ( int b =1; b <(1 <<10); b ++)
{
int cc =0;
for ( int i =0; i < N ; i ++)
{
int c =0;
for ( int j =0; j <10; j ++) if (( b >> j &1)&& F [ i ][ j ]) c ++;
cc += P [ i ][ c ];
}
if ( res < cc ) res = cc ;
}
printf ("%d\n " , res );
}

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

d = int(input())
C = list(map(int,input().split()))
S = [list(map(int,input().split())) for i in range(d)]
T = [int(input()) for i in range(d)]
c = 26
m = int(input())
Q = [list(map(int,input().split())) for i in range(m)]

ans = 0
L = [[-1] * c for i in range(d)]

for i in range(d):
    T[i] -= 1

for i in range(d):
    L[i] = L[i-1][:]
    ans += S[i][T[i]]
    L[i][T[i]] = i
    for j in range(c):
        ans -= C[j] * (i - L[i][j])

# print("fans",ans)
# print(L)

for i in range(m):
    # print(*T)
    dd = Q[i][0]-1
    q = Q[i][1]-1
    ans -= S[dd][T[dd]]
    ans += S[dd][q]
    for j in range(dd, d):
        # print("j",j)
        if T[j] == q:
            # print("break")
            break
        ans += C[q] * (j - L[j][q])
        ans -= C[q] * (j - dd)
        L[j][q] = dd
    
    old = T[dd]
    T[dd] = q

    for j in range(dd, d):
        # print("j",j)
        if T[j] == old:
            # print("break")
            break
        oldl = L[j-1][old] if j > 0 else -1
        ans += C[old] * (j - dd)
        ans -= C[old] * (j - oldl)
        L[j][old] = oldl
    
    print(ans)



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

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


Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#define MOD 1000000007
#define SIZE 100005
 
using namespace std;
typedef long long int ll;
 
ll inv[SIZE],fac[SIZE],finv[SIZE];
void make()
{
	fac[0]=fac[1]=1;
	finv[0]=finv[1]=1;
	inv[1]=1;
	for(int i=2;i<SIZE;i++)
	{
		inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
		fac[i]=fac[i-1]*(ll) i%MOD;
		finv[i]=finv[i-1]*inv[i]%MOD;
	}
}
ll C(int a,int b)
{
	if(a<b) return 0;
	return fac[a]*(finv[b]*finv[a-b]%MOD)%MOD;
}
int id[SIZE];
 
int main()
{
	make();
	int n;
	scanf("%d",&n);
	memset(id,-1,sizeof(id));
	int s,t;
	for(int i=0;i<=n;i++)
	{
		int a;
		scanf("%d",&a);a--;
		if(id[a]==-1) id[a]=i;
		else
		{
			s=id[a];
			t=i;
		}
	}
	for(int i=1;i<=n+1;i++)
	{
		ll ret=C(n+1,i);
		ret-=C(s+(n-t),i-1);
		if(ret<0) ret+=MOD;
		
		printf("%lld\n",ret);
	}
	return 0;
}

Measured memory_bytes: 3840
#include<stdio.h>


int main(){

  int c1, c5, c10, c50, c100, c500, s;

  scanf("%d %d %d %d %d %d", &c1, &c5, &c10, &c50, &c100, &c500);

  s = c1*1 + c5*5 + c10*10 + c50*50 + c100*100 + c500*500;

  if(s >= 1000)
    printf("1\n");
  else
    printf("0\n");

  


  return 0;
}

Measured memory_bytes: 584
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut 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! 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")
    };
}

fn main() {
    input! {
        a: f32,
        b: f32,
    }

    let r1 = (a / 0.08).ceil();
    let r2 = (b / 0.10).ceil();

    let res = r1.max(r2);

    if (res * 0.08).floor() != a || (res * 0.10).floor() != b {
        println!("-1")
    } else {
        println!("{}", res);
    }
}


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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

int N;
int num[16];

int calc(int bit)
{
	bool e[25]={0};
	e[0]=e[24]=1;

	for (int i = 1; i <= 12; ++i) {
		int c = bit % 2;
		bit /= 2;
		if (!num[i]) continue;
		if (num[i] == 2) {
			e[i] = e[24-i] = 1;
		} else {
			if (c == 0) {
				e[i] = 1;
			} else if (c == 1) {
				e[24-i] = 1;
			}
		}
	}

	int la = 0;
	int mi = 24;

	for (int i = 1; i <= 24; ++i) {
		if (e[i]) {
			mi = min(mi, i - la);
			la = i;
		}
	}

	return mi;
}

int main() {
	cin >> N;
	num[0] = 1;

	rep(i, N) {
		int x;
		cin >> x;

		if (x == 0 || num[x] == 2) {
			puts("0");
			return 0;
		}

		++num[x];
	}

	int ret = 0;
	rep(i, 1<<12) {
		ret = max(ret, calc(i));
	}

	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define re return
#define all(a) a.begin(),a.end()
#define int long long
using namespace std;
const int dx[4]={-1,1,0,0};
const int dy[4]={0,0,-1,1};
signed main()
{
	int x;
	cin>>x;
	if (x>=30)  cout<<"Yes";
	else  cout<<"No";
	re 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
 
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

int main(){
    ll n;cin>>n;
    ll s[n];rep(i,n)cin>>s[i];
    sort(s,s+n);
    ll ans=1;
    rep(i,n-1){
        if(s[i]*2<s[i+1]){
            ans=1;
        }
        else ans++;
        s[i+1]+=s[i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;

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

    vector<int> cnt(N + 1);
    for (int i = 0; i <= N; i++) {
        cnt[i] = 0;
    }

    for (int i = 2; i <= N; i++) {
        int res = i;
        for (int j = 2; j <= i; j++) {
            while (res % j == 0) {
                res /= j;
                cnt[j]++;
            }
        }
    }

    long long ans = 1;
    int amari = pow(10, 9) + 7;
    for (int i = 0; i <= N; i++) {
        ans *= cnt[i] + 1;
        if (ans >= amari) {
            ans %= amari;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;

int main(){
	ll N,M;
	cin>>N>>M;
	for(ll i(M/N);i>=1;--i){
		if( (M-i*N)%i == 0 ){
			cout << i << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cfloat>
#include <algorithm>
#include <numeric>
#include <vector>
#include <iterator>
#include <set>
#include <map>
using namespace std;

const double PI=acos(-1);

int main(){
    long n, a, cnt = 0;
    cin >> n;
    map<long, long> l;
    for(int i = 0; i < n; i++){
        cin >> a;
        l[a]++;
    }
    for(auto i : l){
        if(i.second%2 == 1) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 6528
#include <iostream>
#include <string>
#include <set>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	int N; cin >> N;
	vector<int> T(N + 1, 0), X(N + 1, 0), Y(N + 1, 0);
	bool ok = 1;
	for (int i = 1; i <= N; ++i) {
		cin >> T[i] >> X[i] >> Y[i];
		int dt = T[i] - T[i - 1];
		int dx = abs(X[i] - X[i - 1]);
		int dy = abs(Y[i] - Y[i - 1]);
		if (dx + dy <= dt && dt % 2 == (dx + dy) % 2) {}
		else ok = 0;
	}
	cout << (ok ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3796