akhauriyash/Code-Regression huggingface dataset:
def examB():
    H, W = LI()
    a = ["#"+S()+"#" for _ in range(H)]
    ans = "#"*(W+2)
    for i in range(H):
        ans += a[i]
    ans += "#"*(W+2)
    for i in range(H+2):
        print(ans[i*(W+2):(i+1)*(W+2)])

import sys
import copy
import bisect
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examB()


Measured memory_bytes: 38256
#include <stdio.h>
#include <stdlib.h>

int main(){
  int a,b,c,x,y;
  scanf("%d%d%d%d%d",&a,&b,&c,&x,&y);
  int num=0;
  int bignum;
  int flg;
  if(2*c<a+b){
    int diff = x-y;
    if(diff>0){
      flg = 1;
      bignum=y;
    }
    if(diff<0){
      flg = 2;
      bignum=x;
    }
    if(diff==0){
      flg = 3;
      bignum=x;
    }
    x=x-bignum;
    y=y-bignum;
    num += 2*c*bignum;

    if(flg==3){
      printf("%d\n",num);
      return 0;
    }
    if(flg==1){
      if(a<2*c){
        num+=x*a;
        printf("%d\n",num);
        return 0;
      }
      else{
        num+=2*c*x;
        printf("%d\n",num);
        return 0;
      }
    }
    if(flg==2){
      if(b<2*c){
        num+=b*y;
        printf("%d\n",num);
        return 0;
      }
      else{
        num+=2*c*y;
        printf("%d\n",num);
        return 0;
      }
    }
  }
  else{
    num+=x*a+b*y;
    printf("%d\n",num);
    return 0;
  }
  return 0;
}


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

int main(){
  int i,j,k;
  int x,y;
  int inf = 1 << 10;
  int m[200]={};
  int memo[1000005]={};
  int memo2[1000005]={};
  vector <int>  odd;
  fill(memo,memo+1000005,inf);
  fill(memo2,memo2+1000005,inf);
  for(i=1;i<201;i++) {
    m[i-1]=i*(i+1)*(i+2)/6;
    if(m[i-1]%2==1) odd.push_back(m[i-1]);
  }
  memo[0]=0;
  for(i=0;i<200;i++) {
    for(j=m[i];j<1000005;j++){
      memo[j]=min(memo[j],memo[j-m[i]]+1);
    }
  }
  memo2[0]=0;
  for(i=0;i<odd.size();i++) {
    for(j=odd[i];j<1000005;j++){
      memo2[j]=min(memo2[j],memo2[j-odd[i]]+1);
    }
  }
  int n;
  cin >> n;
  while(n!=0){
    cout << memo[n] << " " <<  memo2[n] << endl;
    cin >> n;
  }
  return 0;
}

Measured memory_bytes: 10932
fn read<T: std::str::FromStr>() -> T {
	let mut s = String::new();
	std::io::stdin().read_line(&mut s).ok();
	s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
	read::<String>().split_whitespace()
		.map(|e| e.parse().ok().unwrap()).collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
	(0..n).map(|_| read_vec()).collect()
}

pub trait LexicalPermutation {
	/// Return `true` if the slice was permuted, `false` if it is already
	/// at the last ordered permutation.
	fn next_permutation(&mut self) -> bool;
}
impl<T> LexicalPermutation for [T] where T: Ord {
	/// Original author in Rust: Thomas Backman <serenity@exscape.org>
	fn next_permutation(&mut self) -> bool {
		// These cases only have 1 permutation each, so we can't do anything.
		if self.len() < 2 { return false; }

		// Step 1: Identify the longest, rightmost weakly decreasing part of the vector
		let mut i = self.len() - 1;
		while i > 0 && self[i-1] >= self[i] {
			i -= 1;
		}

		// If that is the entire vector, this is the last-ordered permutation.
		if i == 0 {
			return false;
		}

		// Step 2: Find the rightmost element larger than the pivot (i-1)
		let mut j = self.len() - 1;
		while j >= i && self[j] <= self[i-1]  {
			j -= 1;
		}

		// Step 3: Swap that element with the pivot
		self.swap(j, i-1);

		// Step 4: Reverse the (previously) weakly decreasing part
		self[i..].reverse();

		true
	}
}

fn main() {
	let mut n: usize = read();
	let is_prime = primes(n);
	loop {
		if primes(n) {
			println!("{}", n);
			return;
		}
		n += 1;
	}
}

fn primes(a: usize) -> bool {
	// let loop_upper = a.sqrt() as usize;
	let mut is_prime = vec![true; a+1];
	for i in 2..((a+1) as usize) {
		if is_prime[i] {
			let mut j: usize = 2;
			while i * j <= a {
				is_prime[i*j] = false;
				j += 1;
			}
		}
	}
	is_prime[a]
}


Measured memory_bytes: 4352
#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>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int,int> pint;

#define DE 1
#define FI first
#define SE second
#define PB push_back
#define MP make_pair
#define ALL(s) (s).begin(),(s).end()
#define REP(i,n) for (int i = 0; i < (int)(n); ++i)
#define EACH(i,s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#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) {s<<"{ ";for(int i=0;i<P.size();++i){if(i>0)s<<", ";s<<P[i];}return s<<" }"<<endl;}
template<class T1, class T2> ostream& operator<<(ostream &s, map<T1,T2> P) {s<<"{ ";for(__typeof__(P.begin()) it=P.begin();it!=P.end();++it){if(it!=P.begin())s<<", ";s<<'<'<<it->first<<"->"<<it->second<<'>';}return s<<" }"<<endl;}



const int INF = 1<<29;

int n;
int t[20][20];

int dp[1<<19];

int main() {
    //freopen( "/Users/macuser/Documents/Programming/Contest/input.in", "r", stdin );
    
    while (cin >> n) {
        if (n == 0) break;
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j <= n; ++j) {
                cin >> t[i][j];
            }
        }
        
        for (int i = 0; i < (1<<19); ++i) dp[i] = INF;
        dp[0] = 0;
        
        for (int bit = 0; bit < (1<<n); ++bit) {
            //cout << bitset<7>(bit) << " : " << dp[bit] << endl;
            
            for (int i = 0; i < n; ++i) {
                if ((bit & (1<<i))) continue;
                int nbit = bit ^ (1<<i);
                int Min = INF;
                for (int j = 0; j <= n; ++j) {
                    if (j == 0 || (bit & (1<<(j-1)))) {
                        Min = min(Min, t[i][j]);
                    }
                }
                dp[nbit] = min(dp[nbit], dp[bit] + Min);
            }
        }
        
        cout << dp[(1<<n)-1] << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3208
def min(a, b) a < b ? a : b end

n, m = gets.to_s.split.map{|i| i.to_i }

# bits = Array.new(n){|i| 2**i }
# p bits = Array.new(12){|i| 2**i } #=> [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048]
shops = Array.new(m) do
  a = gets.to_s.to_i
  c = gets.to_s.split.map{|i| i.to_i - 1 }
  [c.reduce(0){|s,t| s + (1 << t) }, a]
end

inf = 10 ** 10
state_size = 2 ** n
d = Array.new(state_size, inf)
d[0] = 0

state_max = 0
shops.each do |(bit, a)|
  state_max |= bit
  state_max.times do |k|
    new = k | bit
    d[new] = min(d[new], d[k] + a)
  end
  
end

puts d[-1] == inf ?  -1 : d[-1]

Measured memory_bytes: 2172
from sys import stdin

readline = stdin.readline


def main():
    input()
    A = tuple(map(int, readline().split()))
    B = tuple(map(int, readline().split()))
    pre = A[0]
    ans = 0
    for a, b in zip(A[1:], B):
        tmp1 = pre if pre < b else b
        b -= tmp1
        tmp2 = a if a < b else b
        ans += tmp1 + tmp2
        pre = a - tmp2
    print(ans)
    return


main()


Measured memory_bytes: 19228
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e15;

#include <math.h>
#define PI 3.14159265358979323846264338327950L
const int mxN = 1e9 + 7;

char s[100005];
long long dp[100005][13];

int minimum_Color(vector<int> a, int n) {
    multiset<int> last;

    for (int i = 0; i < n; i++) {
        auto it = last.lower_bound(a[i]);
        if (it == last.begin()) {
            last.insert(a[i]);
        }
        else {
            it--;
            last.erase(it);
            last.insert(a[i]);
        }
    }
    return last.size();
}

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)cin >> a[i];
    cout << minimum_Color(a, n);
    return 0;
}

Measured memory_bytes: 8564
#include<bits/stdc++.h>
using namespace std;
void bfe(int h,int w,char tebl[][120],int p,int q,char k){
	tebl[p][q]='0';
	if(p>0&&tebl[p-1][q]==k){
		bfe(h,w,tebl,p-1,q,k);
	}
	if(p<h&&tebl[p+1][q]==k){//した
		bfe(h,w,tebl,p+1,q,k);
	}
	if(q>0&&tebl[p][q-1]==k){//右
		bfe(h,w,tebl,p,q-1,k);
	}
	if(p<w&&tebl[p][q+1]==k){//左
		bfe(h,w,tebl,p,q+1,k);
	}
	//for(int z=0;z<h;z++){
	//	for(int x=0;x<w;x++){
	//		cout<<tebl[z][x];
	//	}
	//	cout<<endl;
	//}
	//cout<<endl;
	return;
}

int main(){
	int h,w;
	while(true){
		cin>>h>>w;
		if(h==0&&w==0){
			break;
		}
		char tebl[120][120]={};
		for(int p=0;p<h;p++){
			for(int q=0;q<w;q++){
				cin>>tebl[p][q];
			}
		}
		int ans=0;
		for(int p=0;p<h;p++){
			for(int q=0;q<w;q++){
				if(tebl[p][q]!='0'){
					ans++;
					//cout<<ans<<endl;
					bfe(h,w,tebl,p,q,tebl[p][q]);
				}
			}
		}
		cout<<ans<<endl;
	}
}


Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define mod 1000000007LL
#define eps 1e-13
// #define PI 3.141592653589793238L
#define INF 1000000011
#define INFLL 1000000000000000011LL
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define mp make_pair
#define F first
#define S second
#define pb push_back
#define fo(i,a,n) for(i = (a); i < (n); i++)
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define sws ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define gcd __gcd
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)((a).size())
#define io_file freopen("D:/Coding Problems/Contest/input_file.in", "r", stdin); freopen("D:/Coding Problems/Contest/output_file.out", "w", stdout)

ll modx(ll Base, ll exponent)
{
	ll ans = 1;
	if(Base == 1)
		return Base;
	while(exponent)
	{
		if(exponent & 1)
			ans = (ans * Base)%mod;
		Base = (Base * Base)%mod;
		exponent = exponent >> 1;
	}
	return ans;
}

ll inmodx(ll num)
{
	return (modx(num, mod-2LL));
}

bool cmp(pair < pii, int > a, pair < pii, int > b)//true for a before b
{
	if(a.F.F/300 < b.F.F/300)
		return 1;
	if(a.F.F/300 > b.F.F/300)
		return 0;
	if(a.F.S < b.F.S)
		return 1;
	if(a.F.S > b.F.S)
		return 0;
	if(a.F <= b.F)
		return 1;
	return 0;
}

const int N = (18) + 9;
const int M = (N<<2) + 9;
const int LOGN = ((int)log2(N)) + 3;
const int LOGM = ((int)log2(M)) + 3;
const int BUCK = 100;
const int SQRT = BUCK+9;

string s, temp, t1, t2;
map < pair < string, string >, ll > cnt[2];
int n, p2[N];

void add_cnt(int bit)
{
	int i, j;
	fo(i,0,p2[n])
	{
		t1 = t2 = "";
		fo(j,0,n)
		{
			if(p2[j]&i)
				t1 += s[j];
			else
				t2 += s[j];
		}
		cnt[bit][{t1,t2}]++;
	}
	return;
}

void solve()
{
	int i;
	ll ans = 0;
	cin >> n;
	cin >> temp;
	p2[0] = 1;
	fo(i,1,n+1)
		p2[i] = p2[i-1]<<1;
	s = "";
	fo(i,0,n)
		s += temp[i];
	add_cnt(0);
	s = "";
	for(i = n+n-1; i >= n; i--)
		s += temp[i];
	add_cnt(1);
	for(auto x : cnt[0])
		ans += (x.S*cnt[1][x.F]);
	cout << ans << '\n';
	return;
}

int main()
{
	sws;
	clock_t clk;
	clk = clock();
	// io_file;
	// srand (time(NULL));

	//Code here
	int t = 1, cs;
	cout << fixed << setprecision(9);
	// cin >> t;
	fo(cs,1,t+1)
	{
		// cout << "Case #" << cs << ": ";
		solve();
	}
	// Code ends here

	clk = clock() - clk;
	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
	return 0;
}

Measured memory_bytes: 108288
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
/* #include <regex> */

using namespace std;

/* g++ -g -std=c++11 */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int maxv = 1e5+5;
int dp[maxv]; VI G[maxv];

int dfs(const int u)
{
    int& ans = dp[u];
    if (-1 == ans) {
        ans = 0;
        FOR_ALL(v,G[u])
            ans = max(ans, dfs(*v)+1);
    }
    return ans;
}

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    int n,m;
    while (cin >> n >> m) {
        memset(dp,-1,sizeof(dp));
        FOR(i,1,n+1)
            G[i].clear();
        FOR(_,0,m) {
            int u,v; cin >> u >> v;
            G[u].push_back(v);
        }
        int ans = 0;
        FOR(i,1,n+1)
            ans = max(ans, dfs(i));
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 7424
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<deque>

using namespace std;

int N;
vector<long> X;
vector<long> sv;
long M1, M2;

int input(){
  cin >> N;
  X.resize(N);
  sv.resize(N);
  for( int i = 0; i < N; i++ ){
    cin >> X[i];
    sv[i] = X[i];
  }
  sort(sv.begin(), sv.end());
  M1 = sv[N/2-1];
  M2 = sv[N/2];
  return 0;
}

int run(){
  // cout << sv[0] << endl;
  // cout << M1 << endl;
  // cout << M2 << endl;
  for( int i = 0; i < N; i++ ){
    if( X[i] <= M1 ){
      cout << M2 << endl;
    }else if( X[i] >= M2 ){
      cout << M1 << endl;
    }
  }
  return 0;
}


int main(int argc, char *argv[]){
  input();
  run();
  return 0;
}






Measured memory_bytes: 5376
#include<iostream>
#include<algorithm>
using namespace std;
void sort(int A[], int C, int N){
	int c=0;
	for(int i=0;i<N-1;i++){
		if(A[i]>A[i+1]){
			swap(A[i],A[i+1]);
			c++;
		}
	}
	if(c==0) cout << C << endl;
	else{
		C+=c;
		sort(A,C,N);
	}
}

int main(){
	int n;
	while(cin >> n,n){
		int a[n],count=0;
		for(int i=0;i<n;i++) cin >> a[i];
		sort(a,count,n);
	}
}

Measured memory_bytes: 3100
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n,k; cin>>n>>k;
	vector<int> a(n);
	for (int i=0; i<n; i++)
		cin>>a[i];
	for (int i=k; i<n; i++) {
		cout<<(a[i]>a[i-k]?"Yes":"No")<<endl;
	}
	return 0;
}


Measured memory_bytes: 3972
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    long long int L[n + 1] = {2,1};
    for(int i = 2;i < n + 1;i++)
    {
        L[i] = L[i - 1] + L[i - 2];
    }
    cout << L[n];

    return 0;
}

Measured memory_bytes: 256
q,h,s,d=map(int,input().split())
n=int(input())
n*=4
j=4*(2*q<h)+2*(2*h<s)+(4*q<s)
if j%4==0:
  if 2*s<d:
    print(s*(n//4))
  else:
    print(d*(n//8)+s*((n%8)//4))
  
if j==2 or j==3:
  if 4*h<d:
    print(h*(n//2))
  else:
    print(d*(n//8)+h*((n%8)//2))

if j==5 or j==7:
  if q*8<d:
    print(q*n)
  else:
    print(d*(n//8)+q*(n%8))

Measured memory_bytes: 38384
#include<bits/stdc++.h>
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------

int main(){
    ll N,A,B;
    cin >> N >> A >> B;
    vector<ll> H(N);
    for(int i=0; i<N; i++){
        cin >> H[i];
    }
    ll ng=0,ok=1e9;
    while(ok-ng>1LL){
        ll mid = (ng+ok)/2LL;
        ll cnt = 0;
        for(int i=0; i<N; i++){            
            if(mid*B < H[i]){
                cnt += (H[i]-mid*B+A-B-1LL)/(A-B);
            }
        }
        if(cnt <= mid){
            ok = mid;
        }else{
            ng = mid;
        }
    }
    cout << ok << enld;
    return 0;
}

Measured memory_bytes: 1024
import math
A, B, H, M = list(map(int, input().split()))

arg_h = (H+M/60)/12 *2*math.pi
arg_m = M/60 * 2 * math.pi

print(math.sqrt(pow(A, 2) +pow(B, 2) -2*A*B*math.cos(arg_h-arg_m)))


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

int main(){
	int n, k;
	cin >> n >> k;
	int d[10];
	for(int i = 0; i < 10; i++) d[i] = 0;
	for(int i = 0; i < k; i++){
		int a;
		cin >> a;
		d[a] = 1;
	}
	while(1){
		int c = n;
		int bad = 0;
		while(c > 0){
			if(d[c % 10]) bad = 1;
			c /= 10;
		}
		if(!bad){
			cout << n << endl;
			break;
		}
		n++;
	}
}

Measured memory_bytes: 256
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<complex>
#include<iostream>
#include<algorithm>
#define N 2001
#define LL long long
#define add_edge(u,v) nxt[++cnt]=head[u],head[u]=cnt,to[cnt]=v
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
char ch;bool fs;void re(int& x)
{
	while(ch=getchar(),ch<33);
	if(ch=='-')fs=1,x=0;else fs=0,x=ch-48;
	while(ch=getchar(),ch>33)x=x*10+ch-48;
	if(fs)x=-x;	
}
using namespace std;
const int mod=1000000007;
int inv[N*N],ifac[N*N],fac[N*N];
int n,k,f[N][N];
int C(int n,int m)
{
	return 1ll*fac[n]*ifac[m]%mod*ifac[n-m]%mod;
}
int main()
{
	re(n),re(k);
	if(k==1)
	{
		puts("1");
		return 0;
	}
	inv[0]=inv[1]=ifac[0]=fac[0]=1;
	for(int i=1;i<=n*k;++i)
	{
		if(i>1)inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
		fac[i]=1ll*i*fac[i-1]%mod;
		ifac[i]=1ll*inv[i]*ifac[i-1]%mod;
	}
	f[0][0]=1;
	for(int i=1;i<=n;++i)
		for(int j=0;j<=i;++j)
			f[i][j]=(f[i-1][j]+(j?1ll*C(n-i+(n-j+1)*(k-1)-1,k-2)*f[i][j-1]:0))%mod;
	printf("%d\n",1ll*f[n][n]*fac[n]%mod);
}

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

int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    rep(i, N){
        cin >> a[i];
    }
    bool flag = false;
    int ans = 0;
    while(1){
        rep(i, N){
            if(a[i] % 2 == 0){
                a[i] /= 2;
                ans++;
                flag = true;
            }
        }
        if(flag == false){
            cout << ans << endl;
            return 0;
        }else{
            flag = false;
        }
    }

return 0;}

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

int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		if(i%10==3 || i%3==0 || (i/10)%10==3|| (i/100)%10==3 || (i/1000)%10==3)cout<<" "<<i;
	}
	cout<<endl;
	
	return 0;
}


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

#if ((_WIN32 || __WIN32__) && __cplusplus < 201103L)
#define lld I64d
#else
#define lld lld
#endif

//{{{
using namespace std;
typedef long long LL;
typedef vector<int> VI;
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define clr(a, b) memset(a, b, sizeof(a))
// clang-format off
#define debug(args...) {vector<string> _v = split(#args, ','); err(_v.begin(), args); cerr<<endl;}
vector<string> split(const string& s, char c) {vector<string> v; stringstream ss(s); string x; while
(getline(ss, x, c)) v.push_back(x); return v;} void err(vector<string>::iterator) {}
template<typename T, typename... Args> void err(vector<string>::iterator it, T a, Args... args)
{cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", "; err(++it, args...);}
// clang-format on
//}}}

const int N = 1e5 + 10;
int T;
int n;

const int mod = 1e9 + 7;
struct E
{
    int v, next;
} edge[N << 1];
int head[N], e;
void addedge(int u, int v)
{
    edge[e].v = v;
    edge[e].next = head[u];
    head[u] = e++;
}

int dp[N][2];

int dfs(int u, int f)
{
    int son = 0;
    for (int i = head[u]; ~i; i = edge[i].next)
    {
        int v = edge[i].v;
        if (v == f) continue;
        son += dfs(v, u);
    }

    if (son == 0)
    {
        dp[u][0] = 1;
        dp[u][1] = 1;
        return 1;
    }

    LL v0 = 1;
    LL vall = 1;
    for (int i = head[u]; ~i; i = edge[i].next)
    {
        int v = edge[i].v;
        if (v == f) continue;
        v0 = v0 * dp[v][0] % mod;
        vall = vall * (dp[v][0] + dp[v][1]) % mod;
    }
    dp[u][0] = vall;
    dp[u][1] = v0;
    return son + 1;
}

int main()
{
#ifdef LOCAL
    freopen("in", "r", stdin);
// freopen("out", "w", stdout);
#endif

    while (cin >> n)
    {
        clr(head, -1), e = 0;
        int u, v;
        for (int i = 1; i < n; i++)
        {
            cin >> u >> v;
            addedge(u, v);
            addedge(v, u);
        }
        dfs(1, -1);
        LL ans = (dp[1][0] + dp[1][1]) % mod;
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 11912
#include<iostream>
#include<string>
#include<stdio.h>
using namespace std;
int main(){
    string a;
	getline(cin,a);
	int i=0,count=0;
	bool t=false;
	while(true){
		if(a[i]==' '||a[i]=='.'||a[i]==','){
			if(count>2&&count<7){
				if(t==true)
					cout<<" ";
				t=true;
				for(int j=i-count;j<i;j++){
					cout<<a[j];
				}
			}
			count=0;
		}
		else
			count++;
		i++;
		if(i==a.size())
			break;
	}
	cout<<endl;
    return 0;
}
 

Measured memory_bytes: 1172
use std::io;

fn main() {
    let mut line = String::new();
    io::stdin().read_line(&mut line).unwrap();

    let mut iter = line.split_whitespace().map(|i| i.parse::<usize>().unwrap());
    let r = iter.next().unwrap();
    let c = iter.next().unwrap();

    let mut rows = Vec::new();
    for _ in 0..r {
        let mut line = String::new();
        io::stdin().read_line(&mut line).unwrap();
        let mut row = line.split_whitespace()
            .map(|i| i.parse::<i32>().unwrap()).collect::<Vec<_>>();
        let sum = row.iter().sum();
        row.push(sum);
        rows.push(row);
    }

    let sum_row = rows.iter().fold(vec![0; c + 1].into_iter(), |acc, x| {
        acc.zip(x.iter()).map(|(a, b)| a + b).collect::<Vec<_>>().into_iter()
    }).collect();
    rows.push(sum_row);

    for row in rows {
        for c in 0..c+1 {
            if c != 0 { print!(" "); }
            print!("{}", row[c]);
        }
        print!("\n");
    }
}



Measured memory_bytes: 5056
# coding: utf-8
# Your code here!


import sys
#sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 

n = int(input())
d = [int(i) for i in readline().split()]

ans = 0
for i in range(n):
    for j in range(i+1,n):
        ans += d[i]*d[j]
        

print(ans)

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

#define _LL long long

int main()
{
    string s, t;
    cin >> s;
    cin >> t;

    int ans = 0;
    for( int i = 0; i < (int)s.length(); i++)
    {
        if( s[i] != t[i] ) ans++;
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 3860
#include "bits/stdc++.h"
#define ll long long
#define lld long double
#define MOD 1000000007
#define inf 1000000000000000000ll
#define pii pair<int,int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll power(ll x,ll y, ll md=inf){ll res = 1;x%=md;while(y){if(y&1)res = (res*x)%md;x *= x; if(x>=md) x %= md; y >>= 1;}return res;}
 
using namespace std;


#define endl '\n'
#define int ll

signed main() {
	fast;

	int h,w;
	cin>>h>>w;

	pii v[200002];
	for(int i=0;i<h;i++) cin>>v[i].f>>v[i].s;

	map<int,int> mp;
	for(int i=1;i<=w;i++) mp[i] = 0;

	map<int,int> mini = {{0,w}};

	for(int i=0;i<h;i++) {
		int l = v[i].f;
		int r = v[i].s;

		auto it = mp.lower_bound(l);
		int mn = inf;

		while(it!=mp.end() && it->f <= r) {
			mn = min(mn, r+1-(it->f)+(it->s));
			auto it1 = it++;
			auto it2 = mini.find(it1->s);
			if(it2->s==1) mini.erase(it2);
			else it2->s --;
			mp.erase(it1);
		}

		if(r+1<=w && mn<inf) {
			if(it!=mp.end() && it->f == r + 1) {
				if(it->s > mn) {
					auto it1 = mini.find(it->s);
					if(it1->s ==1) mini.erase(it1);
					else it1->s --;
					mini[mn]++;
					it->s = mn;
				}
			}
			else {
				mp.insert({r+1,mn});
				mini[mn]++;
			}
		}

		if(mini.size()) cout<<mini.begin()->f+i+1<<endl;
		else cout<<-1<<endl;

	}
}

Measured memory_bytes: 19260
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>

static const int MOD = 1000000007;
using ll = int64_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> p) {
    return os << "(" << p.first << "," << p.second << ")";
}

template <class T>
ostream& operator<<(ostream& os, vector<T> v) {
    os << "{";
    for (int i = 0; i < v.size(); ++i) {
        if(i) os << ",";
        os << v[i];
    }
    return os << "}";
}

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for (auto &&i : v) scanf("%d", &i);
    vector<pair<int, int>> vvv;
    vvv.reserve(n);
    for (int i = 0; i < n; ++i) {
        vvv.emplace_back(v[i], i);
    }
    for (int q = 0; q < n; ++q) {
        auto vv = vvv;
        int c1 = q;
        vector<int> ans;
        ans.emplace_back(c1);
        vv[c1].first--;
        bool valid = true;
        for (int i = 0; i < k+1; ++i) {
            sort(vv.begin(), vv.end(), greater<>());
            if(vv.back().second == c1){
                for (int j = 0; j < n-1; ++j) {
                    ans.emplace_back(vv[j].second);
                    vv[j].first--;
                }
                c1 = vv[n-2].second;
            }else {
                for (int j = 0; j < n; ++j) {
                    if(vv[j].second != c1){
                        ans.emplace_back(vv[j].second);
                        vv[j].first--;
                    }
                }
                c1 = vv.back().second;
            }
        }
        for (auto &&i : vv) {
            if(i.first < 0){
                valid = false;
            }
        }
        if(valid){
            cout << ans.size() << "\n";
            for (int i = 0; i < ans.size(); ++i) {
                if(i) cout << " ";
                cout << ans[i]+1;
            }
            return 0;
        }
    }
    puts("-1");
    return 0;
}


Measured memory_bytes: 256
from decimal import *
N = int(input())
a = list(map(int, input().split()))
c = a.copy()
for i in range(len(a)):
    c[i] = a[i] - i - 1

c.sort()
if len(a) % 2 == 1:
    b = c[len(a) // 2]
else:
    b = (c[len(a) // 2] + c[len(a) // 2 - 1]) / 2

greef1 = 0
for i in range(len(a)):
    greef1 += abs(a[i] - i - 1 - b)
print(int(greef1))

Measured memory_bytes: 27140
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
    int n, d[110];
    cin >> n;
    for (int i = 0; i < n; i++) cin >> d[i];

    int a[110] = {};
    for (int i = 0; i < n; i++) {
        a[d[i]]++;
    }

    int cnt = 0;
    for (int i = 0; i < 110; i++) {
        if (a[i]) cnt++;
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b,c,d,m1,m2;
	cin >> a >> b >> c >> d;
	
	m1 = a * b;
	m2 = c * d;
	if(m1 > m2)cout << m1 << endl;
	else cout << m2 << endl;
	return 0;
}


Measured memory_bytes: 256
H, W = map(int, input().split())
S = [input() for _ in range(H)]
l = [[0] * (W+2) for _ in range(H+2)]
u = [[0] * (W+2) for _ in range(H+2)]
r = [[0] * (W+2) for _ in range(H+2)]
d = [[0] * (W+2) for _ in range(H+2)]

for i in range(1, H+1):
    for j in range(1, W+1):
        if S[i-1][j-1] != '#':
            l[i][j] += l[i][j-1] + 1
            u[i][j] += u[i-1][j] + 1
        if S[-i][-j] != '#':
            r[-i-1][-j-1] += r[-i-1][-j] + 1
            d[-i-1][-j-1] += d[-i][-j-1] + 1

ans = 0
for i in range(1, H+1):
    for j in range(1, W+1):
        ans = max(ans, l[i][j]+u[i][j]+r[i][j]+d[i][j]-3)

print(ans)


Measured memory_bytes: 178692
from heapq import*
def m():
 n=int(input())
 A=[]
 for _ in[0]*n:
  e=list(map(int,input().split()))
  A+=[zip(e[2::2],e[3::2])]
 d=[0]+[float('inf')]*n
 H=[(0,0)]
 while H:
  u=heappop(H)[1]
  for v,c in A[u]:
   t=d[u]+c
   if d[v]>t:
    d[v]=t
    heappush(H,(t,v))
 print('\n'.join(f'{i} {d[i]}'for i in range(n)))
m()


Measured memory_bytes: 40088
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>

#define rep(i,n) for(int i = 0; i < n; i++)
#define ENDL "\n"
#define print(i) std::cout << (i) << "\n"

#define int long long // at least int64 > 9*10^18
#define all(v) v.begin(), v.end()

signed main() {
	int k,x;
	std::cin >> k >> x;
	for(int i=x-k+1;i<x+k;i++) {
		std::cout << i << ' ';
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,m;
	cin>>n;
	map<int,long long int>a;
	map<int,long long int>b;
	long long int z=0;
	for(int i=0;i<n;i++)
    {
        cin>>m;
        if(a.count(m+i))
        a[m+i]++;
        else
        a[m+i]=1;
        if(b.count(-m+i))
        b[i-m]++;
        else
        b[i-m]=1;
    }
    map<int, long long int>::iterator iter;
    for(iter = a.begin(); iter != a.end(); iter++)
    {
        if(b.count(iter->first))
        z+=(iter->second)*b[iter->first];
    }
    cout<<z<<endl;
    a.clear();
    b.clear();
	return 0;
}


Measured memory_bytes: 26644
#include<stdio.h>
#include<string.h>
  
int N,Q,A,m,i,j,f[2005]={1};
  
int main()
{
    scanf("%d",&N);
    for(i=0;i<N;i++)
    {
        scanf("%d",&A);
        for(j=2000;j>=0;j--)
            if(j+A<2001&&f[j])
                f[j+A]=1;
    }
    scanf("%d",&Q);
    for(i=0;i<Q;i++)
    {
        scanf("%d",&m);
        puts(f[m]?"yes":"no");
    }
    return 0;
}

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define pb(n) push_back(n);
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807

int f[4],hogem[4] = {5,7,5,6},cnt;
string s,hoge[4] = {"maerd","remaerd","esare","resare"};

main() {
    cin >> s;
    repm(i,s.size()) {
        rep(j,4) {
            if (f[j] == -1) continue;
            if (s[i] != hoge[j][f[j]]) f[j] = -1,cnt++;
            else {
                f[j]++;
                if (f[j] == hogem[j]) {
                    rep(k,4) f[k] = 0;
                    cnt = 0;
                    break;
                }
            }
            if (cnt == 4) {
                cout << "NO" << endl;
                return 0;
            }
        }
    }
    cout << "YES" << endl;
}


Measured memory_bytes: 512
-- candles.hs ---

-- author: Seong Yong-ju <sei40kr@gmail.com>

main :: IO ()
main = do
  [n, k] <- map (read :: String -> Int) . words <$> getLine
  xs <- map (read :: String -> Integer) . take n . words <$> getLine
  print $ minimum $ zipWith (curry f) xs (drop (k - 1) xs)
  where
    f (l, r)
      | r < 0 = -l
    f (l, r)
      | 0 < l = r
    f (l, r) = min (-l * 2 + r) (-l + r * 2)


Measured memory_bytes: 75132
#include <bits/stdc++.h>
using namespace std;
long long test,n,a;
double b;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    //cin>>test;
    test=1;
    while (test--)
    {
       cin>>a>>b;
       long long x=b*100+0.5;
       x=a*x/100;
       cout<<x;
    }
    
}    




Measured memory_bytes: 3656
#include<cstdio>
#include<cstring>
int main(){
 int a,j,b[10];
 while(1){
  scanf("%d",&a);
 if(a==0) return 0;
 memset(b,0,sizeof(int)*10);
 for(int i=0;i<a;i++){
  scanf("%d",&j);
  b[j]++;
 }
 for(int i=0;i<10;i++){
  if(b[i]==0){
  printf("-\n");
 continue; 
 }
  for(int s=0;s<b[i];s++){
    printf("*");
  }
  printf("\n");
 }
 }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;
 
int n;
 
int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> n;
	ll cnt = 0, last = 0;
	FOR(i, n) {
		ll a;
		cin >> a;
		if (last == 1 && a > 0) {
			a--;
			cnt++;
		}
		cnt += a/2;
		last = a % 2;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>

#define P 1000000007

int comp(const void *a, const void *b){return *(int*)a-*(int*)b;}

int p[2][1000000];
int main(void){
	int h, w, i, j, k;
	char s[1000][1001];
	scanf("%d%d", &h, &w);
	for(i=0; i<h; i++){
		scanf("%s", s+i);
	}

	int r[2]={0,0};
	for(i=0; i<h; i++){
		for(j=0; j<w; j++){
			if(s[i][j]=='#') p[1][r[1]++]=i*w+j;
		}
	}
	for(k=0; ; k++){
		if(r[(k+1)&1]==0) break;
		while(r[(k+1)&1]>0){
			int x=p[(k+1)&1][--r[(k+1)&1]];
			int *q = p[k&1];
			int i=x/w, j=x%w;
			//printf("(%d, %d)\n", i, j);
			if(i!=0 && s[i-1][j]!='#'){q[r[k&1]++]=(i-1)*w+j; s[i-1][j]='#';}
			if(i!=h-1 && s[i+1][j]!='#'){q[r[k&1]++]=(i+1)*w+j; s[i+1][j]='#';}
			if(j!=0 && s[i][j-1]!='#'){q[r[k&1]++]=i*w+j-1; s[i][j-1]='#';}
			if(j!=w-1 && s[i][j+1]!='#'){q[r[k&1]++]=i*w+j+1; s[i][j+1]='#';}
		}
	}
	printf("%d\n", k-1);
}


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

void solve()
{
	int n;
	cin>>n;
	string s;
	cin>>s;
	ll ans = 0,l = 0, r = s.length()-1;
	while(l<r)
	{
		while(l<s.length()&&s[l]!='W')
			l++;
		while(r>=0&&s[r]!='R')
			r--;
		if(l>=r)
			break;
		ans++;
		swap(s[l],s[r]);
		l++;
		r--;
	}
	cout<<ans<<endl;
}

int main()
{
	ll t =1 ;
	// cin>>t;
	while(t--)
	{
		solve();
	}
}

Measured memory_bytes: 3724
a,b,c = map(int,input().split())

fcount = 0
scount = 0

if a == 5 :
  fcount += 1
elif a == 7:
  scount += 1

if b == 5 :
  fcount += 1
elif b == 7:
  scount += 1

if c == 5 :
  fcount += 1
elif c == 7:
  scount += 1

if fcount == 2 and scount == 1:
  print("YES")
else :
  print("NO")




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

int main() {
	int n, k;
	cin >> n >> k;
	double ans = 0.0;
	for(int i = 1; i <= n; i++) {
		double now = 1.0 / n;
		if(i < k) {
			int tmp = i;
			while(tmp < k) {
				tmp *= 2;
				now /= 2;
			}
		}
		ans += now;
	}
	printf("%.10f\n", ans);
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(200000)
from collections import defaultdict
from bisect import bisect_left


def read():
    N = int(input().strip())
    A = list(map(int, input().strip().split()))
    return N, A


def prime_factorization(n, primes):
    """
    nの素因数分解を求める
    """
    prime_factors = defaultdict(int)
    if n < 2:
        return prime_factors
    for p in primes:
        if p * p > n:
            break
        while n % p == 0:
            prime_factors[p] += 1
            n //= p
    if n > 1:
        prime_factors[n] = 1
    return prime_factors


def sieve(n):
    """
    n以下の素数を昇順に列挙する
    """
    is_prime = [True for i in range(n+1)]
    primes = []
    for i in range(2, n+1):
        if is_prime[i]:
            primes.append(i)
            for j in range(i+i, n+1, i):
                is_prime[j] = False
    return primes


def solve(N, A):
    A.sort()
    AMAX = max(A)
    ans = 0
    is_div = [True for i in range(AMAX+1)]
    for i in range(N):
        a = A[i]
        if is_div[a]:
            if not ((i > 0 and A[i] == A[i-1]) or (i < N-1 and A[i] == A[i+1])):
                ans += 1
            for j in range(a, AMAX+1, a):
                is_div[j] = False
    return ans


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


Measured memory_bytes: 33860
n,l=map(int,input().split())
t=[l+i for i in range(n)]
tot = sum(t)
ans = tot - t[0]
mn = float('inf')
for i in range(n):
	tmp = tot-t[i]
	if abs(tmp-tot)<mn:
		mn = abs(tmp-tot)
		ans = tmp
		
print(ans)


Measured memory_bytes: 9096
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;

int N;
vector<int> A;
vector<int> sorted;
vector<long long> suffix_sums;

long long count_between(int before, int now) {
    int first = lower_bound(sorted.begin(), sorted.end(), before) - sorted.begin();
    int second = lower_bound(sorted.begin(), sorted.end(), now) - sorted.begin();
    long long first_half = suffix_sums[first] - suffix_sums[second];
    long long second_half = (long long) (N - second) * now;
    return first_half + second_half - (long long) (N - first) * before;
}

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

    cin >> N;
    A.resize(N);

    for (int &a : A)
        cin >> a;

    sorted = A;
    sort(sorted.begin(), sorted.end());
    suffix_sums.assign(N + 1, 0);

    for (int i = N - 1; i >= 0; i--)
        suffix_sums[i] = suffix_sums[i + 1] + sorted[i];

    vector<long long> answers(N, 0);
    int maximum = 0;

    for (int i = 0; i < N; i++)
        if (A[i] > maximum) {
            answers[i] = count_between(maximum, A[i]);
            maximum = A[i];
        }

    for (int i = 0; i < N; i++)
        cout << answers[i] << (i < N - 1 ? ' ' : '\n');
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define pb push_back
#define REP(i, n) for (signed long long i = 0; i < (n); i++)
#define MOD 998244353
#define INF 98765431219876543
#define bitcnt(a) (ll) __builtin_popcount((a))
#define lb(a, b) lower_bound((a).begin(), (a).end(), (b))
#define ub(a, b) upper_bound((a).begin(), (a).end(), (b))
using namespace std;

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

ll gcd(ll a, ll b) {
  if (a == 0 || b == 0) {
    return 0;
  }
  while (a % b) {
    a = a % b;
    swap(a, b);
  }
  return b;
}

int main() {
  ll n, x;
  cin >> n >> x;
  vector<ll> v;
  REP(i, n) {
    ll a;
    cin >> a;
    v.pb(abs(a - x));
  }
  ll g = *v.begin();
  REP(i, n) {
    g = gcd(g, v[i]);
  }
  cout << g << endl;
}

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

#define rep(i, n) for (int i = 1; i <= n; ++i)

using namespace std;

const int N = 1010;

int p[N];

int main() {
	int n, k;
	cin >> n >> k;
	
	rep(i, n) cin >> p[i];
	
	sort(p + 1, p + n + 1);
	
	int res = 0;
	for (int i = 1; i <= k; ++i) res += p[i];
	
	cout << res << '\n';
	
	return 0;
}

Measured memory_bytes: 3636
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {
    public static void main(String... args) {
        Scanner sc = new Scanner(System.in);

        Deque<Integer> stack = new ArrayDeque<>();

        while (sc.hasNextInt()) {
            int n = sc.nextInt();
            if (n == 0) System.out.println(stack.poll());
            else stack.push(n);
        }

        while (stack.size() != 0) {
            System.out.println(stack.poll());
        }
    }
}


Measured memory_bytes: 26040
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#define ll long long
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long

#define INF 999999999

using namespace std;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
// input
int a,b,c,x,y;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> a >> b >> c >> x >> y;


    int min_total = 2147483647;

    REP(i,100001){
        int prime = (i * 2 * c) + max(0,x-i) * a + max(0,y-i) * b;


        min_total = min(min_total,prime);

    }

    cout << min_total << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b)
{
    if(b==0)return a;
    return gcd(b,a%b);
}
int main()
{
    int k,sum=0;cin>>k;
    for(int i=1;i<=k;i++)
    {
        for(int j=1;j<=k;j++)
        {
            int r=gcd(i,j);
            for(int n=1;n<=k;n++)
            {
                sum+=gcd(r,n);
            }
        }
    }
    cout<<sum;
    return 0;
}

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



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

    int cnt0 = 0;
    int cnt1 = 0;
    n = size(s);
    rep(i, n)
    {
        if (s.at(i) == '0') cnt0++;
        if (s.at(i) == '1') cnt1++;
    }
    if (cnt0 > cnt1) cout << cnt1*2 << endl;
    else cout << cnt0*2 << endl;

    return 0;
}


Measured memory_bytes: 3672
#!/usr/bin/env python3
#
# Author: Tetsuya Ishikawa <tiskw111@gmail.com>
# Date  : June 30, 2020
##################################################### SOURCE START #####################################################

N = int(input().strip())
An = list(map(int, input().strip().split()))

An = sorted(An, reverse=True)

p1 = sum(An[0::2])
p2 = sum(An[1::2])

print(p1 - p2)

##################################################### SOURCE FINISH ####################################################
# vim: expandtab tabstop=4 shiftwidth=4 fdm=marker


Measured memory_bytes: 9176
N, M, X = list(map(int,input().strip().split(' ')))
A = list(map(int,input().strip().split(' ')))

C = [0 for i in range(N)]
for j in range(len(A)):
    C[A[j]-1] = 1
C_left = C[:X-1]
C_right = C[X:]
result = min(sum(C_left),sum(C_right))
print(result)


Measured memory_bytes: 3060
#include <stdio.h>


int main(){
	int hundou[10]={1,2,4,8,16,32,64,128,256,512};
	int b[10]={};
	int w,i,kai;
	//for(i=0; i<10; i++)printf("%d\n",b[i]);
	 while(scanf("%d",&w)!=EOF){
		//printf("%d\n",w);
		for(i=0; i<10; i++){
			b[i]=0;
	 	}
	 	for(i=9; i>=0; i--){
	 		if(w>=hundou[i]){
	 			w-=hundou[i];
	 			b[i]=1;
	 			//printf("w:%d\n", w);
	 			if(w==0)break;
	 		}
	 	}
	 	kai=0;
	 	for(i=0; i<10; i++){
	 		if(b[i]){
	 			if(!kai)kai=1;
	 			else printf(" ");
	 			printf("%d",hundou[i]);
	 		}
	 	}
	 	printf("\n");
	}

	return 0;
}

Measured memory_bytes: 600
#include <iostream>
using namespace std;
#define HOUR 3600
#define MINUTE 60

int S, h, m, s;

int main(){

	
	do {
		cin >> S;
	} while (S < 0 || S>86400);

		h = S / HOUR;
		m = ( S - (HOUR * h) ) / MINUTE;
		s = S - ((HOUR * h) + (MINUTE * m));


		cout << h << ":" << m << ":" << s << endl;




	return 0;
}

Measured memory_bytes: 1168
def prime_factors(n):
  seeds = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]
  factors = []
  i = 0
  while i<=len(seeds)-1:
    if n % seeds[i]:
      i += 1
    else:
      n //= seeds[i]
      factors.append(seeds[i])
  return factors

def solve():
  N = int(input())
  
  factors = []
  for i in range(1, N+1):
    factors.extend(prime_factors(i))
  
  import collections
  c = collections.Counter(factors)
  lenc = len(c)
  
  n_1 = 0
  c1 = []
  for k, v in c.items():
    if v >= 74:
      n_1 += 1
      c1.append(k)
      
  # 14/4
  n_2 = 0
  c2=[]
  for k, v in c.items():
    if v < 14:
      continue
    for k2, v2 in c.items():
      if k == k2 or v2 < 4:
        continue
      n_2 += 1
      c2.append((k, k2))
     
  # 24/2
  n_3 = 0
  c3=[]
  for k, v in c.items():
    if v < 24:
      continue
    for k2, v2 in c.items():
      if k == k2 or v2 < 2:
        continue
      n_3 += 1
      c3.append((k, k2))
            
  # 4/4/2
  n_4 = 0
  c4=[]
  for k, v in c.items():
    if v < 2:
      continue
    for k2, v2 in c.items():
      if k == k2 or v2 < 4:
        continue
      for k3, v3 in c.items():
        if k == k3 or k2<=k3 or v3<4:
          continue
        n_4 += 1
        c4.append((k, k2, k3))
  print(n_1+n_2+n_3+n_4)
solve()

Measured memory_bytes: 3316
#include <iostream>
using namespace std;
typedef long long ll;

int main()
{
    int m;
    cin >> m;
    ll s = 0, t = 0;
    for(int i = 0; i < m; i++){
        ll d, c;
        cin >> d >> c;
        s += c;
        t += d * c;
    }
    cout << s - 1 + (t - 1) / 9 << endl;
}


Measured memory_bytes: 3620