akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

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

template<class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template<class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
    t = v;
}
template<class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v){
    for (auto &e : t) fill(e, v);
}

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }

#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }




long long N;

long long solve() {
    if (N % 2 == 1) return 0;
    N /= 2;

    long long res = 0;
    while (N) {
        res += N / 5;
        N /= 5;
    }
    return res;
}


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

    while (cin >> N) {
        cout << solve() << endl;
    }
}


















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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	double xa1;
	while (cin >> xa1) {
		double ya1, xa2, ya2, xb1, yb1, xb2, yb2;
		cin >> ya1 >> xa2 >> ya2 >> xb1 >> yb1 >> xb2 >> yb2;

		if (xb2 < xa1 || yb2 < ya1 || xa2 < xb1 || ya2 < yb1) {
			cout << "NO" << endl;
		}
		else cout << "YES" << endl;
	}
	return 0;
}

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

#define MAXN 1000001 

int spf[MAXN]; 
vector<int> a;
int hash1[MAXN] = { 0 }; 

void sieve() { 
	spf[1] = 1; 
	for (int i = 2; i < MAXN; i++) 
		spf[i] = i; 


	for (int i = 4; i < MAXN; i += 2) 
		spf[i] = 2; 
 
	for (int i = 3; i * i < MAXN; i++) { 

		if (spf[i] == i) { 
			for (int j = i * i; j < MAXN; j += i) 
				if (spf[j] == j) 
					spf[j] = i; 
		} 
	} 
} 


void getFactorization(int x) 
{ 
	int temp; 
	while (x != 1) { 
		temp = spf[x]; 
		if (x % temp == 0) { 

			// Storing the count of 
			// prime factors in hash 
			hash1[spf[x]]++; 
			x = x / spf[x]; 
		} 
		while (x % temp == 0) 
			x = x / temp; 
	} 
} 

bool check(int x) 
{ 
	int temp; 
	while (x != 1) { 
		temp = spf[x]; 

		
		if (x % temp == 0 && hash1[temp] > 1) 
			return false; 
		while (x % temp == 0) 
			x = x / temp; 
	} 
	return true; 
} 



int main() {
    int n;
    cin >> n;
	a.resize(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	
	sieve();
	for (int i = 0; i < n; i++) 
	    getFactorization(a[i]); 
	    
	bool ok = true;
	for (int i = 0; i < n; i++) { 
	    if (!check(a[i])) { 
	        ok = false;
	        break;
	    }
	}
	if (ok) {
	    cout << "pairwise coprime" << "\n";
	}
	else {
	    int result = a[0]; 
	   
        for (int i = 1; i < n; i++) { 
            result = gcd(a[i], result); 
  
            if(result == 1) 
            { 
               break;
            }  
        } 
        if (result == 1) {
            cout << "setwise coprime" << "\n";

        } else {
            cout << "not coprime" << "\n";

        }
	}
	return 0; 
} 



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

using namespace std;

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

const int INF = 1000000000; //
const ll LINF = (ll) 4000000000000000000; //
const ll MOD = (ll) 1000000007; //
const double PI = acos(-1.0); //

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define repll(i,n) for(ll i=0;i<(ll)(n);i++)
#define repll2(i,n) for(ll i=1;i<=(ll)(n);i++)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())

//------------------------------------------------------

int main() {
    int n;
    cin >> n;
    int a[n];
    int Max = 0;
    int Min = INF;

    rep(i, n) {
        cin >> a[i];
        Max = max(Max, a[i]);
        Min = min(Min, a[i]);
    }

    if (Max - Min > 1) {
        Yes(false);
    } else if (Max - Min == 0) {
        Yes(Max == n - 1 || 2 * Max <= n);
    } else {
        int x, y;
        x = y = 0;

        rep(i, n) {
            if (a[i] == Min) x++;
            else y++;
        }

        Yes(x < Max && y >= 2 * (Max - x));
    }

    return 0;
}


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

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $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")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;
type I = usize;

fn main() {
    input!{
      n: usize,
      s: chars,
    }
    let mut white = 0;
    let mut black = 0;
    let mut ws = vec![0; n];
    let mut bs = vec![0; n];
    for i in 0..n {
        if s[i] == '.' {
            white += 1;
        } else {
            black += 1;
        }
        ws[i] += white;
        bs[i] += black;
    }
    let mut ans = min(white, black);

    for i in 0..n {
        // iまでwhite
        let mut tmp = bs[i];
        tmp += (ws[n-1] - ws[i]);
        ans = min(ans, tmp);
    }
    println!("{}", ans);
}


Measured memory_bytes: 6396
#include <algorithm>
#include <climits>
#include <iomanip>
#include <iostream>
#include <queue>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;
  auto cmp = [](const auto&lhs , const auto&rhs) { return lhs.first > rhs.first; };
  priority_queue<pair<int64_t, int>, vector<pair<int64_t, int>>, decltype(cmp)> que(cmp);
  vector<int> P(A);
  rep(i, A) { cin >> P[i]; }
  sort(P.begin(), P.end(), greater<int>());
  vector<int> Q(B);
  rep(i, B) { cin >> Q[i]; }
  sort(Q.begin(), Q.end(), greater<int>());
  vector<int> R(C);
  rep(i, C) { cin >> R[i]; }
  sort(R.begin(), R.end(), greater<int>());

  int64_t answer = 0;
  rep(i, X) {
    answer += P[i];
    que.emplace(P[i], 0);
  }
  rep(i, Y) {
    answer += Q[i];
    que.emplace(Q[i], 1);
  }
  rep(i, C) {
    if(X == 0 && Y == 0) break;
    int64_t taste;
    int rg;
    tie(taste, rg) = que.top();
    que.pop();
    if(taste >= R[i]) break;
    if(rg == 0 && X > 0) {
      answer -= taste;
      answer += R[i];
      X--;
    } else if(rg == 1 && Y > 0) {
      answer -= taste;
      answer += R[i];
      Y--;
    }
  }
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 7536
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main(){

	int A,B,C;
  	cin >> A >> B >> C;
  	
  	int ans = max(0, (C - (A-B)));
  
  	cout << ans << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cassert>
#include <limits>
#include <numeric>
#include <type_traits>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <complex>
#include <climits>

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)

ll gcd(ll a, ll b) {
  while (a && b) {
    if (a >= b) a %= b;
    else b %= a;
  }
  return a + b;
}
ll ketasum(ll n) { //桁の数字全ての和を返す 例: 112 -> 4
	ll sum=0;
	if (n<0) return 0;
	while (n>0) {
		sum += n%10;
		n /= 10;
	}
	return sum;
}

typedef pair<ll, ll> pair_t;

bool comp(const pair_t &a, const pair_t &b) {
        return a.first < b.first;
}

void sort2vectors(vector<ll> &av, vector<ll> &bv)
{ // ふたつの配列をまとめてそーと A[2,1] B[3,4] -> 1,4 2,3
        ll n = av.size();
        vector<pair_t> p(n);
        vector<ll> av2(n), bv2(n);
        for (ll i = 0; i < n; i++)
                p[i] = make_pair(av[i], bv[i]);
        sort(p.begin(), p.end(), comp);
        for (ll i = 0; i < n; i++) {
                av2[i] = p[i].first;
                bv2[i] = p[i].second;
        }
        av = av2;
        bv = bv2;
}
ll facctorialMethod(ll k){ //階乗
	ll s;
	if(k > 1){
		s = k*facctorialMethod(k-1);
	} else {
		s = 1;
	}
	return s;
}
vl primes(ll n){
	vl x(n);
	REP(i, n){
		x[i] = 0;
	}
	for(ll i = 2; i < sqrt(n) + 2; i++){
		while(n % i == 0){
			n /= i;
			x[i-1] += 1;
		}
	}
	if(n > 1){
		x[n-1] += 1;
	}
	return x;
}
const ll mod = 1000000007;
int main(){
	ll A, B, C, D;
	cin >> A >> B >> C >> D;
	ll lcm = floor( ((long double)C*(long double)D)/(long double)gcd(C, D) );
	ll kari1 = floor((long double)B/(long double)C);
	ll kari2 = floor((long double)B/(long double)D);
	ll kari3 = floor((long double)B/(long double)lcm);
	ll kari4 = floor((long double)(A-1)/(long double)C);
	ll kari5 = floor((long double)(A-1)/(long double)D);
	ll kari6 = floor((long double)(A-1)/(long double)lcm);
	ll ans1 = B - kari1 - kari2 + kari3;
	ll ans2 = A - 1 - kari4 - kari5 + kari6;
	cout << ans1 - ans2<< endl;
}


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

int main() {
	int n;
	cin >> n;
	while(n){
	    if(n%10==7){
	        cout << "Yes" << endl;
	        return 0;
	    }
	    n/=10;
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3596
s = input()
ans = float("INF")
from string import ascii_lowercase
for c in ascii_lowercase:
  cnt = 0
  st = s[:]
  while True:
    snew = ""
    if len(set(st))==1:
      break
    for i in range(len(st)-1):
      if st[i]==c or st[i+1]==c:
        snew += c
      else:
        snew += st[i]
    cnt+=1
    st = snew[:]
  ans = min(ans, cnt)
print(ans)

Measured memory_bytes: 3768
pub fn read_parameters<T>() -> Result<Vec<T>, String>
where
    T: std::str::FromStr,
{
    let mut line = String::new();
    std::io::stdin()
        .read_line(&mut line)
        .map_err(|err| format!("{:?}", err))?;

    let xs = line.trim().split_whitespace();
    let mut result = Vec::new();

    for x in xs {
        let ans = x.parse::<T>().map_err(|_| format!("{}", "parse error"))?;
        result.push(ans);
    }
    Ok(result)
}

fn main() {
    // let (a, b) = read_parameters::<isize>().map(|xs| (xs[0], xs[1])).unwrap();
    let mut i = 0;
    loop {
        let x = read_parameters::<usize>().unwrap();
        let x = x[0];
        i += 1;
        if x == 0 {
            break;
        }
        println!("Case {}: {}", i, x);
    }
}



Measured memory_bytes: 5044
#include<stdio.h>
int main()
{
	char s[20],kong;
	int i=0,a,b,x,flag=1;
	scanf("%d %d\n",&a,&b);
	scanf("%c",&kong);
	while(kong!='\n'){
		s[i]=kong;
		i++;
		scanf("%c",&kong);
	}
	if((a+b+1)!=(i)){
		flag=0;
	}
	if(s[a]!='-'){
		flag=0;
	}
	for(x=0;x<a;x++){
		if(s[x]<48 || s[x]>57 || s[x]==45){
			flag=0;
		}
	}
	for(x=i-1;x>a;x--){
		if(s[x]<48 || s[x]>57 || s[x]==45){
			flag=0;
		}
	}
	if(flag==1){
		printf("Yes");
	}else{
		printf("No");
	}
}

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

using namespace std;

//void chimin(int &a,int b){
  //  if(a>b)a=b;
//}

int n,A,B,C;
vector<int >l;

int dfs(int i,int a, int b,int c){
    if(i==n){
        if(!a||!b||!c)return 100000;
        return abs(a-A)+abs(b-B)+abs(c-C);
    }
    int res =dfs(i+1,a,b,c);
    res=min(res,dfs(i+1,a+l[i],b,c)+(a?10:0));
    res=min(res,dfs(i+1,a,b+l[i],c)+(b?10:0));
    res=min(res,dfs(i+1,a,b,c+l[i])+(c?10:0));
    return res;
}

int main()
{
    cin >> n >> A >> B >> C;
    l.resize(n);
    for(int i=0;i<n;i++){
        cin >> l[i];
    }
    cout << dfs(0,0,0,0)<< endl;
    return 0;
}


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

int dp[1010][1010][16];

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

int main() {
	int H, W; cin >> H >> W;
	for (int i = 0; i < 1010; ++i)for (int j = 0; j < 1010; ++j)for (int k = 0; k < 16; ++k){
		dp[i][j][k] = 1e9;
	}
	dp[5][5][0] = 0;
	vector<vector<int>>field(H + 8, vector<int>(W + 8));
	for (int i = 0; i < H; ++i) {
		string st; cin >> st;
		for (int j = 0; j < W; ++j) {
			if (st[j] != '.') {
				field[i + 5][j + 5] = st[j] - '0';
			}
		}
	}
	for (int nowy = 5; nowy < H + 6; ++nowy) {
		for (int nowx = 5; nowx < W +6; ++nowx) {
			for (int n = 0; n < 16; ++n) {
				const int eat_ld = n & 1;
				const int eat_d = (n & 2) >> 1;
				const int eat_r = (n & 4) >> 2;
				const int eat_ru = (n & 8) >> 3;
				if (1e9 <= dp[nowy][nowx][n])continue;
				vector<vector<char>>baseeats(4, vector<char>(4));
				baseeats[2][0] = eat_ld;
				baseeats[2][1] = eat_d;
				baseeats[1][2] = eat_r;
				baseeats[0][2] = eat_ru;
				baseeats[1][1] = true;
				for (int way = 0; way < 2; ++way) {
					const int  nextx = nowx + dx[way];
					const int nexty = nowy + dy[way];
					const int ax = 1 + dx[way];
					const int ay = 1 + dy[way];
					for (int w = 0; w < 4; ++w) {
						int nexteat_ld = baseeats[2 + dy[way]][0 + dx[way]];
						int nexteat_d = baseeats[2 + dy[way]][1 + dx[way]];
						int nexteat_r = baseeats[1 + dy[way]][2 + dx[way]];
						int nexteat_ru = baseeats[0 + dy[way]][2 + dx[way]];
						int eat_sum = 0;
						if (!baseeats[ay][ax]) {
							if (ay == 2 + dy[way] && ax == 0 + dx[way])nexteat_ld = true;
							if (ay == 2 + dy[way] && ax == 1 + dx[way])nexteat_d = true;
							if (ay == 1 + dy[way] && ax == 2 + dx[way])nexteat_r = true;
							if (ay == 0 + dy[way] && ax == 2 + dx[way])nexteat_ru = true;
							eat_sum += field[nexty][nextx];
						}
						for (int v = 0; v < 4; ++v) {
							if (v == w)continue;
							else {
								if (!baseeats[ay + dy[v]][ax + dx[v]]) {
									if (ay + dy[v]== 2 + dy[way] && ax + dx[v] == 0 + dx[way])nexteat_ld = true;
									if (ay + dy[v]== 2 + dy[way] && ax + dx[v] == 1 + dx[way])nexteat_d = true;
									if (ay + dy[v]== 1 + dy[way] && ax + dx[v] == 2 + dx[way])nexteat_r = true;
									if (ay + dy[v]== 0 + dy[way] && ax + dx[v] == 2 + dx[way])nexteat_ru = true;
									eat_sum += field[nexty + dy[v]][nextx + dx[v]];
								}
							}
						}
						int n = dp[nowy][nowx][eat_ld+2*eat_d+4*eat_r+8*eat_ru] + eat_sum;
						dp[nexty][nextx][nexteat_ld+2*nexteat_d+4*nexteat_r+8*nexteat_ru] = min(dp[nexty][nextx][nexteat_ld + 2 * nexteat_d + 4 * nexteat_r + 8 * nexteat_ru], n);
					}
				}
			}
		}
	}
	int ans = 1e9;
	for (int l = 0; l < 16; ++l) {
		ans = min(ans, dp[H + 4][W + 4][l]);	
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 70756
import itertools
import math
n,d = map(int,input().split())
x_list = [list(map(int,input().split())) for _ in range(n)]
x_c = itertools.combinations(x_list,2)
count = 0
for x in x_c:
    x1 = x[0]
    x2 = x[1]
    tmp = 0
    for i in range(d):
        tmp += (x1[i]-x2[i])**2
    tmp = math.sqrt(tmp)
    if tmp.is_integer():
        count += 1
print(count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
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; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define FOR(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define ld long double
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
const long long dx[4]={1,0,-1,0};
const long long dy[4]={0,1,0,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    int n; cin >> n;
    if(n%2==0) cout<<0.5000000<<endl;
    else{
        cout<<(ld)(n+1)/(ld)2/(ld)n<<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n, m;
    cin >> n >> m;
    priority_queue<long long> a;
    for(int i=0; i<n; ++i){
        long long tmp;
        cin >> tmp;
        a.push(tmp);
    }

    for(int i=0; i<m; ++i){
        long long b=a.top()/2;
        a.pop();
        a.push(b);
    }
    long long ans=0;
    while(!a.empty()){
        ans += a.top();
        a.pop();
    }
    cout << ans << endl;
}

Measured memory_bytes: 1400
s=input()

list=[0 for _ in range(len(s) + 1)]

def inc(n):
    if n < 0 or len(s) < n + 1:
        return
    if '<' == s[n]:
        if list[n] >= list[n + 1]:
            list[n + 1] += list[n] - list[n + 1] + 1
    elif '>' == s[n]:
        if list[n] <= list[n + 1]:
            list[n] += list[n + 1] - list[n] + 1

for i in range(0, len(s), 1):
    inc(i)

for i in range(len(s) - 1, -1, -1):
    inc(i)

print(sum(list))


Measured memory_bytes: 24004
#include<bits/stdc++.h>
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;

vector<int> v,a,b,c,d;
int n,m,q,mx=0;

int dfs(int i,int j){
  if(i==n){
    int sum=0;
    rep(k,q)if(v[b[k]]-v[a[k]]==c[k])sum+=d[k];
    return sum;
  }
  rep(k,m-j+1){
    v[i]=j+k;
    mx=max(mx,dfs(i+1,v[i]));
  }
  return mx;
}
  
  
int main(){
  cin>>n>>m>>q;
  a=vector<int>(q);
  b=vector<int>(q);
  c=vector<int>(q);
  d=vector<int>(q);
  v=vector<int>(n);
  rep(i,q)cin>>a[i]>>b[i]>>c[i]>>d[i],a[i]--,b[i]--;

  cout<<dfs(0,1);
}
  


Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MOD=1e9+7;
static const ll MAX=101010;

/*
 for(i=0; i<N; i++)
   cin >> a[i];
*/

int dp[88][88][88*(88+88)*2];

int main(void) {
  ll i, j, k, l;
  
  ll H, W;
  cin >> H >> W;
  ll a[88][88], b[88][88], c[88][88];
  ll BD=82*(82+82);
  
  for(i=0; i<H; i++) for(j=0; j<W; j++) cin >> a[i][j];
  for(i=0; i<H; i++) for(j=0; j<W; j++) cin >> b[i][j];
  
  for(i=0; i<H; i++)
    for(j=0; j<W; j++)
      c[i][j]=abs(a[i][j]-b[i][j]);
  
  memset(dp, 0, sizeof(dp));
  
  dp[0][0][BD+c[0][0]]=1;
  dp[0][0][BD-c[0][0]]=1;
  for(i=0; i<H; i++) {
    for(j=0; j<W; j++) {
      for(k=0; k<85*(85+85)*2; k++) {
        if(dp[i][j][k]) {
          chmax(dp[i+1][j][k+c[i+1][j]], dp[i][j][k]);
          chmax(dp[i+1][j][k-c[i+1][j]], dp[i][j][k]);
          chmax(dp[i][j+1][k+c[i][j+1]], dp[i][j][k]);
          chmax(dp[i][j+1][k-c[i][j+1]], dp[i][j][k]);
        }
      }
    }
  }
    
  ll ans=INF;
  for(k=0; k<85*(85+85)*2; k++) {
    if(dp[H-1][W-1][k]) chmin(ans, abs(k-BD));
  }
  
  pt(ans);
}




Measured memory_bytes: 937472
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}
template<class T=ll>struct Graph{
	int n;
	vector<vector<tuple<ll,T>>>edge;
	Graph(int N=1):n(N){edge.resize(n);}
	void add(ll f,ll t,T c,bool d=false){
		edge[f].emplace_back(t,c);
		if(!d)edge[t].emplace_back(f,c);
	}
	void view(){
		rep(i,n)for(auto&e:edge[i])
			puta(i,"=>",get<0>(e),", cost :",get<1>(e));
	}
};
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,k=0;;
	cin>>n;
	vl v(n);
	Graph<ll> g(n);
	vb use(n,false);
	vl a(n-1),b(n-1);
	map<pll,ll> mp;
	rep(i,n-1){
		cin>>a[i]>>b[i];
		a[i]--;b[i]--;
		if(a[i]>b[i])swap(a[i],b[i]);
		g.add(a[i],b[i],0);
		mp[pll(a[i],b[i])]=0;
	}
	queue<pll> q;
	q.push(pll(0,0));
	while(!q.empty()){
		ll cnt=1;
		ll t,p;
		tie(t,p)=q.front();q.pop();
		use[t]=true;
		for(auto x:g.edge[t]){
			ll to=get<0>(x);
			if(use[to])continue;
			if(cnt==p)cnt++;
			chmax(k,cnt);
			mp[pll(min(to,t),max(to,t))]=cnt;
			//puta(pll(min(to,t)+1,max(to,t)+1),cnt);
			q.push(pll(to,cnt));
			cnt++;
		}
	}
	cout<<k<<endl;
	rep(i,n-1)puta(mp[pll(a[i],b[i])]);

}


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

#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define ANS(ans) cout << (ans) << endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;

// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) for (long long i = 0; i < (n); ++i)

int main() {
  ll x;
  cin >> x;
  ll now = 100;
  int ans = 0;
  while (now < x) {
    now *= 1.01;
    ans++;
  }
  ANS(ans);
  return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	int n;
	cin >> n;
	vector<string> s;
	for(int i=0; i<n; ++i){
		string s0;
		cin >> s0;
		vector<string> sarr(10);
		sort(s0.begin(), s0.end());
		s.push_back(s0);
	}
	sort(s.begin(), s.end());

	long long int r=0, r0=0;
	string sb=s[0];
	for(int i=0; i<n; ++i){
		if(s[i]==sb) {
			++r0;
		}else if(s[i]!=sb){
			r+=r0*(r0-1)/2; r0=1;
		}
		sb=s[i];
	}
	r+=r0*(r0-1)/2;

	cout << r << endl;
	return 0;

}



Measured memory_bytes: 5748
# -*- coding: utf-8 -*-

def main():
    a_500 = int(input())
    b_100 = int(input())
    c_50 = int(input())
    x = int(input())
    count = 0

    for a in range(a_500 + 1):
        if ((500 * a) > x):
            continue
        for b in range(b_100 + 1):
            if ((500 * a) > x):
                continue
            for c in range(c_50 + 1):
                if ((500 * a) > x):
                    continue
                if (((500 * a) + (100 * b) + (50 * c)) == x):
                    count += 1

    print(count)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
# -*- coding: utf-8 -*-

a,b = map(str,input().split())

n = int(a + b)

check = 0
for i in range(1,1000):
    if n == i**2:
        check = 1
        break
    else:
        pass

if check == 1:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
#include<stdio.h>

int main(void){
    char s[5], tmp;
    scanf("%s", s);
    tmp = s[0];
    for(int i=1; i<4; i++){
        if(tmp == s[i]){
            printf("Bad\n");
            break;
        }
        else {
            if(i == 3)printf("Good\n");
            else tmp = s[i];
        }
    }
    return 0;
}


Measured memory_bytes: 128
//Bokan ga bokka--nn!!
//Daily Lunch Special Tanoshii !!
//これは、頭が悪く競プロが世界で一番できないHIR180が
//IOI2014日本代表になるまでのN日間の記録である。
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
#define f first
#define s second
#define rep(i,x) for(int i=0;i<x;i++)
int zip[1005*505],num[1005];
int main()
{
	srand((unsigned int)time(NULL));
	while(1)
	{
		int n,lim;
		scanf("%d%d",&n,&lim); if(!n) return 0;
		int id=0;
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&num[i]);
		}
		num[0]=0;
		for(int i=0;i<=n;i++)
		{
			for(int j=i;j<=n;j++)
			{
				zip[id++]=num[i]+num[j];
			}
		}
		sort(zip,zip+id);
		int ret=0;
		for(int i=0;i<id&&lim>=zip[i];i++)
		{
			int x=upper_bound(zip,zip+id,lim-zip[i])-zip;
			if(!x) break;
			ret=max(ret,zip[i]+zip[x-1]);
		}
		printf("%d\n",ret);
	}
}

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

int main() {
  int N, K; cin >> N >> K;
  vector<int> p(N);
  for(int i = 0; i<N;i++) cin >> p[i];
  sort(p.begin(), p.end());
  int sum = 0;
  for(int i = 0; i<K;i++){
    sum += p[i];
  }
  cout << sum << endl;
}


Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#include<queue>
#define ll long long
#define itn int
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
using namespace std;

ll N,M,K,A,B,C,ans=0,cnt=0;
string S,T;
vector<int> P,Q;
vector<pair<int,int>> PP;
bool CAN=false,CAN2=true;



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




int main(){
  cin>>A>>B;
  N=gcd(A,B);
  
  if(N==1){
    cout<<1<<endl;
    return 0;
  }
  
  for(ll i=2; i<=N; ++i){
    while(N%i==0){
      N/=i;
      CAN=true;
    }
    if(CAN){
      ans++;
      CAN=false;
      CAN2=false;
    }
    if(i*i>N){
      if(N!=1) ans++;
      break;
    }
    if(N==1) break;
  }
  
  
  if(CAN2){
    cout<<2<<endl; //Nが素数
    return 0;
  }
  cout<<ans+1<<endl;
}

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

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

    int ans = 0;
    rep(i, n - 1) if (s[i] == s[i + 1]) ans++;

    cout << min(ans + 2 * k, n - 1) << endl;
    return 0;
}


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

#define mp make_pair
#define eb emplace_back
#define ff first
#define ss second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#ifdef ONPC
mt19937 rnd(228);
#else
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#endif


const int MAXN = 100;
//#define int long long
const int INF = 1e9;

void solve(){
  int n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];

  ll ans = a[0] - 1LL;
  ll cur = 2LL;
  for (int i = 1; i < n; i++){
    if (a[i] == cur) cur++;
    else if (a[i] > cur){
      ans += (a[i] - 1) / cur;
    }
  }

  cout << ans << '\n';
}

signed main()
{
    #ifdef FILEIO
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    solve();

    return 0;
}


Measured memory_bytes: 3992
#include<iostream>
using namespace std;
void b()
{

}
void a()
{
    int a,b;
    cin >>a>>b;
    if(a<10 && b<10)
    cout << a*b;
    else cout << -1;
    return;

}
int main(void){
    a();
    //b();
    //c();
    //d();
    return 0;
}

Measured memory_bytes: 256
N, A = map(int, input().split())
x = list(map(int, input().split()))

dp = [[[0 for _ in range(3000)] for _ in range(N+1)] for _ in range(N+1)]


dp[0][0][0] = 1
#iまでを使い、k枚使って、合計がsになる組み合わせ
for i in range(1, N+1):
    for k in range(N+1):
        for s in range(3000):
            dp[i][k][s] = dp[i-1][k][s]
            if s - x[i-1] >= 0 and k >= 1:
                dp[i][k][s] = dp[i-1][k][s] + dp[i-1][k-1][s-x[i-1]]

ans = 0
for k in range(1, N+1):
    ans += dp[N][k][k*A]

print(ans)

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

using namespace std;

long long _();
int main() { _(); return 0; }
#define main _
#define int long long 

int main()
{
    ios_base::sync_with_stdio(false);
    string s;
    cin >> s;
    cout << (s[2] == s[3] && s[4] == s[5] ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

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

using ll = long long;
using namespace std;

template<typename T>
struct BIT {
  int n;
  vector<T> d;
  BIT(int n=0):n(n),d(n+1) {}
  void add(int i, T x=1) {
    for (i++; i <= n; i += i&-i) {
      d[i] += x;
    }
  }
  T sum(int i) {
    T x = 0;
    for (i++; i; i -= i&-i) {
      x += d[i];
    }
    return x;
  }
};

ll N;
ll A[100010];
std::vector<ll> crds;
std::map<ll, ll> mp;
bool fl[100010];

int main()
{
  scanf( "%lld", &N );
  
  rep( i, N )
  {
    scanf( "%lld", A+i );

    crds.emplace_back( A[i] );
  }

  std::sort( all(crds) );

  rep( i, N )
    mp[crds[i]] = i;

  rep( i, N )
    fl[mp[A[i]]] = i&1;

  ll cnt = 0;
  rep( i, N )
    cnt += (fl[mp[crds[i]]] != (i&1));

  printf( "%lld\n", cnt/2 );

  return 0;
}

Measured memory_bytes: 8180
import java.util.*;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		double A = sc.nextDouble();
		double B = sc.nextDouble();
		int ans = -1;
		for (int i = 1; i <= 10000; i++) {
			double x = (double)i;
			//System.out.println((int)(x*1.08/1));
			if (((int)(x*1.08)/1)-x == A&& (int)((x*1.1)/1)-x == B) {
				ans = (int)x;
				break;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 24916
/*
problem's name:
statue:
writer:Patrick_y
*/
#include <iostream>
#include <map>
#include <vector>
#include <cstring>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <string>
#include <stack>
#include <set>
#include <deque>
#include <cctype>
#include <sstream>
#include <math.h>
#include <stdio.h>
#include <time.h>
#define mp make_pair
typedef long long ll;
using namespace std;
const int INF=20050208;
/*------------main part------------*/



string s_i(int a)
{
	string s;
	int tmp=a;
	while(tmp>0)
	{
		s+=tmp%10+'0';
		tmp/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
int main()
{
	int n;
	cin>>n;
	int ans=INF;
	for(int i=1;i<n;i++)
	{
		int a=i;
		int b=n-a;
		string aa=s_i(a);
		string bb=s_i(b);
		int sum=0;
		for(int j=0;j<aa.size();j++)
		{
			sum+=aa[j]-'0';
		}
		for(int j=0;j<bb.size();j++)
		{
			sum+=bb[j]-'0';
		}
		ans=min(ans,sum);
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApp3
{
    class Program
    {
        static void Main(string[] args)
        {
            Main main = new Main();
            main.Calc();
        }
    }
    class Main { 

        public void Calc()
        {
            var input = Console.ReadLine().Split().Select(int.Parse).ToList();
            if (input[0] == input[1]) Console.WriteLine("Yes");
            else Console.WriteLine("No");
            Console.ReadLine();
        }
    }
}


Measured memory_bytes: 13268
(defun solve (n h)
  (let ((costs (make-array n :element-type 'fixnum)))
    (loop for i from 0 below n
          do (setf (aref costs i)
                   (min (+ (aref costs (max (- i 1) 0))
                           (abs (- (aref h (max (- i 1) 0))
                                   (aref h i))))
                        (+ (aref costs (max (- i 2) 0))
                           (abs (- (aref h (max (- i 2) 0))
                                   (aref h i)))))))
    (aref costs (1- n))))

#-swank
(let* ((n (read))
       (h (make-array n :element-type 'fixnum)))
  (loop for i from 0 below n
        do (setf (aref h i) (read)))
  (format t "~A~%" (solve n h)))


Measured memory_bytes: 60132
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <bitset>

#include <iostream>
#include <algorithm>
#include <cmath>
#include <iterator>
#include <iomanip>
#include <random>
#include <numeric>

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

using namespace std;
// using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<double,double> pd;
typedef priority_queue<int, vector<int>, greater<int> > min_heap;

// template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const double PI = 4*atan(1);
const ll INF = 1e18;
const int MX = 100001;

const ll mod = 1e9 + 7;
const int maxp = 5e5 + 5;
const int maxn = 5e5 + 5;
ll fac[maxn];

ll reduce(ll a) {
    return ((a % mod) + mod) % mod;
}

ll add(ll a, ll b) {
    return reduce(a + b);
}

ll prod(ll a, ll b) {
    return (((a * b) % mod) + mod) % mod;
}

ll modpow(ll a, ll pw) {
    if (pw == 0) return 1;
    if (pw % 2 == 1) return prod(a, modpow(a, pw - 1));
    ll res = modpow(a, pw / 2);
    return prod(res, res);
}

ll inv(ll a) {
    return modpow(a, mod - 2);
}

ll binom(ll a, ll b) {
  ll num = fac[a];
  ll den = prod(fac[a - b], fac[b]);
  return prod(num, inv(den));
}

void process_fac() {
  fac[0] = 1;
  for (int i = 1; i < maxp; i++) {
    fac[i] = prod(fac[i - 1], i);
  }
}

int n, m;

ll ff(int a, int b) {
    return prod(fac[b], inv(fac[b - a]));
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    process_fac();

    ll ans = 0;
    ll mul = 1;
    for (int i = 0; i <= n; i++) {
        ll fres = ff(n - i, m - i);
        // cout << "fres: " << fres << "\n";
        // cout << "binom: " << binom(n, i) << "\n";
        ll inter = prod(binom(n, i), mul * fres);
        // cout << "mul * fres: " << mul * fres << "\n";
        // cout << "prod2: " << prod(1, -1) << "\n";
        // cout << reduce(-1) << "\n";
        // cout << "inter: " << inter << "\n";
        ans = add(ans, inter);
        mul = -mul;
    }
    // cout << "ans: " << ans << "\n";
    for (int i = 0; i < n; i++) {
        ans = prod(ans, m - i);
    }
    cout << ans << "\n";


}
/*
    Potential bugs:
    - Not resetting the arrays properly
    - Out of bounds
*/

Measured memory_bytes: 7460
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
#define pb push_back

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;
}
constexpr int mod = 1e9+7;
constexpr int inf = 3e18;

struct Brock{
	int w,s,v;
	bool operator<(Brock &a){
		return w+s<a.w+a.s;
	}
};
int N;
Brock A[1005];
int dp[1005][100005];
signed main(){
	cin>>N;
	rep(i,N)cin>>A[i].w>>A[i].s>>A[i].v;
	sort(A,A+N);
	rep(i,N){
		rep(j,100002){
			chmax(dp[i][j+1],dp[i][j]);
			chmax(dp[i+1][j],dp[i][j]);
			if(j<=A[i].s)
				chmax(dp[i+1][min(j+A[i].w,10001ll)],dp[i][j]+A[i].v);
		}
	}
	int ans=0;
	rep(i,10002)chmax(ans,dp[N][i]);
	cout<<ans<<endl;
}


Measured memory_bytes: 784920
import re
import doctest


class IO_for_Contest(object):
    @staticmethod
    def my_input():
        # return raw_input()
        return input()

    @staticmethod
    def read_from_input():
        return IO_for_Contest.read_n_int(3)

    @staticmethod
    def read_line():
        return IO_for_Contest.my_input().strip()

    @staticmethod
    def read_int():
        return int(IO_for_Contest.my_input().strip())

    @staticmethod
    def read_n_int(n):
        return list(map(
                int,
                re.split('\s+', IO_for_Contest.my_input().strip())))[: n]


def solve():
    a = IO_for_Contest.read_from_input()
    a.sort()
    if is_legal(a):
        print('YES')
    else:
        print('NO')


def is_legal(a):
    return len(a) == 3 and a[0] == 5 and a[1] == 5 and a[2] == 7

if __name__ == '__main__':
    # doctest.testmod()
    solve()

Measured memory_bytes: 8096
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Edge=pair<int,int>;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
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;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  ll N,ans=0;
  cin>>N;
  vector<ll> A;
  REP(i,N){
    ll a;
    cin>>a;
    A.PB(a);
  }
  SORT(A);
  REVERSE(A);
  
  for(int i=1; i<N; ++i){
    ans+=A[i/2];
  }
  
  co(ans);
  return 0;
}


Measured memory_bytes: 5336
h,w=gets.split.map(&:to_i)
s=[]
dp=[]
h.times do
  s << gets.chomp
  dp << []
end
if s[0][0]=="."
  dp[0][0]=0
else
  dp[0][0]=1
end
1.upto(w-1) do |j|
  if s[0][j]==s[0][j-1]
    dp[0][j]=dp[0][j-1]
  else
    dp[0][j]=dp[0][j-1]+1
  end
end
1.upto(h-1) do |i|
  if s[i][0]==s[i-1][0]
    dp[i][0]=dp[i-1][0]
  else
    dp[i][0]=dp[i-1][0]+1
  end
  1.upto(w-1) do |j|
    if s[i][j]==s[i-1][j]
      ii=dp[i-1][j]
    else
      ii=dp[i-1][j]+1
    end
    if s[i][j]==s[i][j-1]
      jj=dp[i][j-1]
    else
      jj=dp[i][j-1]+1
    end
    if ii<jj
      dp[i][j]=ii
    else
      dp[i][j]=jj
    end
  end
end
puts (dp[-1][-1]+1)/2


Measured memory_bytes: 1916
#include <stdio.h>

int main(){
	int t;
	char s[50];
	int ac=0,tle=0,wa=0,re=0;
	scanf("%d",&t);
		for(int i=0;i<t;i++){
			scanf("%s",s);
		if(s[0]=='A'){
			ac++;
			}
		else if(s[0]=='W'){
				wa++;
			}
		else if(s[0]=='T'){
				tle++;
			}
		else if(s[0]=='R'){
				re++;
			}
		}	
			printf("AC x %d\n",ac);
			printf("WA x %d\n",wa);
			printf("TLE x %d\n",tle);
			printf("RE x %d\n",re);
     return 0;
}

Measured memory_bytes: 2152
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;
typedef vector<int> vi;
#define MAX(X,Y) ((X)>(Y)?(X):(Y))

int main(void){
  int n, k, s, mx;
  vi vec;
  while(true){
    cin >> n >> k;
    if (n==0 && k==0) break;
    for (int i=0; i<n; i++){
      int t; cin >> t;
      vec.push_back(t);
    }
    mx = s = accumulate(vec.begin(), vec.begin()+k, 0);
    for (int i=k; i<n; i++){
      s = s-vec[i-k]+vec[i];
      mx = MAX(mx, s);
    }
    cout << mx << endl;
  }
  return 0;
}



Measured memory_bytes: 3520
#include<iostream>
using namespace std;
int main()
{
	int pow3[16], c[16];
	int n, m, i, j, k, d, x, y, p;

	pow3[0] = 1;
	for (i = 1; i <= 15; i++){
		pow3[i] = pow3[i - 1] * 3;/*i枚#0から#2または#2から#0へ移動するのに必要なステップ数*/
	}
	while (1)
	{
		cin >> n >> m;
		if (n == 0 && m == 0)
			break;
		for (i = 0; i != 3; ++i){
			cin >> j;
			for (int l = 0; l != j; l++)
			{	
				cin >> k;
				c[n - k] = i;/*番号付け替え,ハノイの塔に変換。大きいコップを小さい円盤にする*/
			}
		}
		p = 0;//全ての円盤が0の位置にあると仮定する
		x = 0;
		for (i = n - 1; i >= 0; --i){//
			d = abs(p - c[i]);//移動させる円盤の距離を求める。
			/*n = 3の時、i = 2で円盤2を#1に移動させるには円盤1と円盤0を#2に移動させる*/
			x += pow3[i] * d;
			if (d == 1){
				p = 2 - p;/*反対側に移動,距離がd = 1ならば0~i-1番の円盤を反対側に移動する。*/
			}
		}
		y = pow3[n] - 1 - x;
		if (x > y){
			x = y;
		}
		if (x > m)
			cout << -1 << endl;
		else
			cout << x << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N, K, R, S, P;
    cin >> N >> K;
    cin >> R >> S >> P;
    string T;
    cin >> T;
    int ans = 0;
    for (int i = 0; i < (int)T.size(); ++i) {
        if (i >= K && T[i] == T[i-K]) {
            T[i] = '?';
        }
        if (T[i] == 'r') {
            ans += P;
        } else if (T[i] == 's') {
            ans += R;
        } else if (T[i] == 'p') {
            ans += S;
        }
    }
    printf("%d\n", ans);
    return 0;
}


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

int main() {
    int n;
    string s;
    cin >> n >> s;
    vector<int> d(n + 1);
    for (int i = 1; i < n + 1; ++i) {
        d[i] = d[i - 1] + (s[i - 1] == '.');
    }
    int ans = 1001001001;
    for (int i = 0; i < n + 1; ++i) {
        ans = min(ans, (i - d[i]) + (d[n] - d[i]));
    }
    cout << ans << endl;
}


Measured memory_bytes: 1412
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <cstring>
#include <utility>
#include <vector>
#include <climits>
#include <cstdio>
#include <cmath>
#include <unordered_map>
using namespace std;

void solve()
{
	int n,k;
	cin>>n;
	int ans,arr[n][3],dp[n];
	for(int i=0;i<n;i++) {cin>>arr[i][0]>>arr[i][1]>>arr[i][2];}
	for(int i=1;i<n;i++)
	{
		arr[i][0]+=max(arr[i-1][1],arr[i-1][2]);
		arr[i][1]+=max(arr[i-1][0],arr[i-1][2]);
		arr[i][2]+=max(arr[i-1][1],arr[i-1][0]);
	}
	cout<<max(arr[n-1][0],max(arr[n-1][1],arr[n-1][2]))<<'\n';
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 1408