akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>
#include <ios>
#include <cctype>
#include <cstdio>
#include <functional>
#include <cassert>

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define FORR(i,a,b) for(int i = (a) - 1;i >=(b);--i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).sizeT()
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())
#define ASSERT(cond,mes) assert(cond && mes)

using namespace std;
using ll = long long;

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())is >> v[i];
    return is;
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
    REP(i, (int)v.size())os << v[i] << endl;
    return os;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a)n = a;
    if (n > b)n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

std::vector<int> enum_div(int n) {
    std::vector<int> ret;
    for (int i = 1; i*i <= n; ++i) {
        if (n%i == 0) {
            ret.push_back(i);
            if (i != 1 && i*i != n) {
                ret.push_back(n / i);
            }
        }
    }
    return ret;
}

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

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



int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);

    int N;
    cin >> N;
    vector<int> H(N);
    cin >> H;

    vector<int> dp(N, INF);
    dp[0] = 0;
    FOR(i, 1, N) {
        chmin(dp[i], dp[i - 1] + abs(H[i] - H[i - 1]));
        if (i > 1)chmin(dp[i], dp[i - 2] + abs(H[i] - H[i - 2]));
    }

    cout << dp[N - 1] << endl;

    return 0;
}

Measured memory_bytes: 1024
/**
 *    author:  tourist
 *    created: 16.01.2020 23:12:24       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  cout << "ABC" << n << '\n';
  return 0;
}


Measured memory_bytes: 256
a,b = map(int, input().split())
if a == 1:
    print(1)
    exit()
if b == 1:
    print(1)
    exit()
if a*b%2 == 0:
    print(a*b//2)
if a*b%2 == 1:
    print(a*b//2 + 1)

Measured memory_bytes: 2940
#include <iostream>
#include <cstring>
#include <cassert>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <climits>
#include <cassert>
#include <ctime>
#include <bitset>
using namespace std;
#define MAX 1000

vector<int> Gr[MAX];
bool Use[MAX];
int N, M, E, Sol, L[MAX], R[MAX];
int ax[MAX], ay[MAX], bx[MAX], by[MAX];

bool Dfs(int X) {
  int Y;
  if (Use[X]) return 0;
  Use[X] = 1;
  for (int i = 0; i < Gr[X].size(); i++) {
    Y = Gr[X][i];
    if (R[Y] == 0 || Dfs(R[Y])) {
      L[X] = Y;
      R[Y] = X;
      return 1;
    }
  }
  return 0;
}

int main() {
  
  cin >> N;
  M=N;
  for (int i = 1; i <= N; ++i) {
    cin >> ax[i] >> ay[i];
  }
  for (int i = 1; i <= N; ++i) {
    cin >> bx[i] >> by[i];
  }
  
  for (int i = 1; i <= N; ++i) {
    for (int j = 1; j <= N; ++j) {
      if (ax[i] <= bx[j] && ay[i] <= by[j]) {
        Gr[i].push_back(j);
      }
    }
  }
  
  bool ok = 1;
  while (ok) {
    ok = 0;
    memset(Use, 0, sizeof(Use));
    for (int i = 1; i <= N; i++) {
      if (L[i] == 0 && Dfs(i)) {
        ok = 1;
        Sol++;
      }
    }
  }
  
  printf("%d\n", Sol);
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,m,ans,f[1000010],id[500010],lz[1000010],a[500010],b[500010];
vector<int>zh[500010];
void build(int x,int l,int r){
	if(l==r){
		if(l==0)f[x]=0;
		 else f[x]=-1e8;
		return;
	}
	int mid=(l+r)/2;
	build(x*2,l,mid);build(x*2+1,mid+1,r);
	f[x]=max(f[x*2],f[x*2+1]);
}
void pushdown(int x){
	if(lz[x]){
		lz[x*2]+=lz[x];lz[x*2+1]+=lz[x];
		f[x*2]+=lz[x];f[x*2+1]+=lz[x];
		lz[x]=0;
	}
}
void ins(int x,int l,int r,int t,int k,int w){
	if(l==t&&r==k){
		f[x]+=w;lz[x]+=w;
		return;
	}
	int mid=(l+r)/2;
	pushdown(x);
	if(mid>=k)ins(x*2,l,mid,t,k,w);
	 else if(t>mid)ins(x*2+1,mid+1,r,t,k,w);
	  else ins(x*2,l,mid,t,mid,w),ins(x*2+1,mid+1,r,mid+1,k,w);
	f[x]=max(f[x*2],f[x*2+1]);
}
void xiu(int x,int l,int r,int t,int w){
	if(l==r){
		f[x]=max(f[x],w);
		return;
	}
	int mid=(l+r)/2;
	pushdown(x);
	if(mid>=t)xiu(x*2,l,mid,t,w);
	 else xiu(x*2+1,mid+1,r,t,w);
	f[x]=max(f[x*2],f[x*2+1]);
}
int query(int x,int l,int r,int t,int k){
	if(l==t&&r==k)return f[x];
	pushdown(x);
	int mid=(l+r)/2;
	if(mid>=k)return query(x*2,l,mid,t,k);
	 else if(t>mid)return query(x*2+1,mid+1,r,t,k);
	  else return max(query(x*2,l,mid,t,mid),query(x*2+1,mid+1,r,mid+1,k));
}
//void get(int x,int l,int r,int t,int k)
int main(){
	int i,j,xlh,x;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d",&x);
		id[i]=x;
		if(x==1)b[i]=1;
		b[i]+=b[i-1];
	}
	scanf("%d",&m);
	for(i=1;i<=m;i++){
		scanf("%d%d",&x,&a[i]);
		zh[x].push_back(i);
	}
	build(1,0,n);
	for(i=1;i<=n;i++){
		//ins(1,0,n,0,i-1,(id[i]==0));
	//	printf("%d %d\n",i,query(1,0,n,0,i-1));
		for(j=0;j<zh[i].size();j++){
			x=zh[i][j];
			x=a[x];
			xlh=query(1,0,n,i,x)+b[x];
			xlh=max(xlh,query(1,0,n,0,i-1)+b[x]-b[i-1]);
			//printf("%d %d %d\n",i,x,xlh);
			xiu(1,0,n,x,xlh-b[x]);
		}
		ins(1,0,n,0,i-1,(id[i]==0));
		ins(1,0,n,i,i,b[i]);
		//ans=max(ans,f[1]);
	}
	ans=f[1];
	printf("%d",n-ans);
}

Measured memory_bytes: 28800
a, b, k = map(int, input().split())

if a >= k:
    ans_a = a - k
    ans_b = b

if a < k and a + b >= k:
    ans_a = 0
    ans_b = a + b - k

if a < k and a + b < k:
    ans_a = 0
    ans_b = 0

print(ans_a, ans_b)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main() {
long long N,A,B;
cin>>N>>A>>B;
cout<<((A-B)%2==0?A-B>0?(A-B)/2:(B-A)/2:(min(A, B)-1)>(N-max(A,B))?(2*N-A-B)/2+1:(A+B)/2)<<endl;
}

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

int selection(int n,int a[]) {
    int min,cnt=0;
    for(int i=0;i<n;i++) {
        min=i;
        for(int j=i;j<n;j++) {
            if(a[j]<a[min]) {
                min=j;
            }
        }
        swap(a[i],a[min]);
        if(i!=min) {
            cnt++;
        }
    }
    return cnt;
}

int main() {
    int n;cin>>n;
    int a[100];
    for(int i=0;i<n;i++) {
        cin>>a[i];
    }
    int ans=0;
    ans=selection(n,a);
    for(int i=0;i<n-1;i++) cout<<a[i]<<" ";
    cout<<a[n-1]<<endl;
    cout<<ans<<endl;
    return 0;
}

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

long long N, M,sum,t;
pair <long long, long long> p[30000];
int main(){
	while ((cin >> N >> M), N){
		sum = 0;
		for (int i = 0; i < N; i++){
			cin >> p[i].second >> p[i].first;
			sum += p[i].second*p[i].first;
		}
		sort(p, p + N);
		reverse(p, p + N);
		for (int i = 0; i < N; i++){
			if (M <= 0)break;
			int guarded = min(p[i].second, M);
			sum -= p[i].first*guarded;
			M -= guarded;
		}
		cout << sum << endl;
	}
}

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

const ll INF = 1e+18;

int main(){
    ll n, a, b;
    cin >> n >> a >> b;
    vector<ll> dp(n, INF);
    dp[0] = 0;
    int prex;
    cin >> prex;
    for(int i = 0; i < n-1; i++){
        int x;
        cin >> x;
        dp[i+1] = min(dp[i+1], dp[i] + min((x - prex) * a, b));
        prex = x;
    }
    cout << dp[n-1] << endl;
    return 0;
}

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

const int MAX = 1005;
char s[MAX][MAX];

const int mod = 1e9+7;

void max_self (int&a ,int b)
{
    a+=b;
    if(a >= mod)
    {
        a -= mod;
    }
}

int main()
{
    int h,w;
    cin >> h >> w;
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        cin >> s[i][j];
    }
    vector<vector<int>> dp(h,vector<int>(w));
    dp[0][0] = 1;
    for(int row = 0;row<h;row++)
    {
        for(int col=0;col<w;col++)
        {
            for(int r2 : {row,row+1})
            {
                int c2 = col;
                if(r2==row)
                c2 = col+1;
                if(r2<h && c2<w && s[r2][c2]=='.')
                {
                    max_self(dp[r2][c2],dp[row][col]);
                }
            }
        }
    }

    cout << dp[h-1][w-1];
}

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

int main(){
    int a,b;
    cin >> a >> b;
    
    cout << a * b << " " << 2 * a + 2 * b << endl;
}




Measured memory_bytes: 3080
inputted = list(map(int, input().split()))
N = inputted[0]
X = inputted[1]
L = list(map(int, input().split()))

x = 0
number_of_bounds = 0
for _i, Li in enumerate(L):
    number_of_bounds = _i + 1
    x += Li
    if x > X: break

if x <= X:
    number_of_bounds += 1

print(number_of_bounds)


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

using namespace std;

const long long MOD = 1e9+7;

long long dp[32005][2][105];
long long prefixSum[32005][2][105];

int N, K;

/*long long dp(int i, int mode, int k){
	printf("%d %d %d\n", i, mode, k);
	if(k == 0){
		return 1;
	}else if(memo[i][mode][k] != -1){
		return memo[i][mode][k];
	}else if(mode == 0){
		long long ans = 0;
		// mode 0 means that limit on current element is i
		for(int j = 1; j <= i; j ++){
			// the limit on the previous element is N/j
			ans += dp(j, 1, k-1);
		}
		return memo[i][mode][k] = ans%MOD;
	}else if(mode == 1){
		long long ans = 0;
		// mode 1 means that limit on current element is N/i
		
		// considering j <= sqrt(N) (j refers to mode 0)
		int limit1 = (int)(floor(sqrt(N))+1e-9);
		for(int j = 1; j <= limit1; j ++){
			// the limit on the previous element is N/j
			ans += dp(j, 1, k-1);
		}
		
		// considering N/j >= N/i, in other words, j >= i (j refers to mode 1)
		// in this case, j may not be integer, but observe that the limit is the same as if j = ceil(j)
		for(int j = i; j < limit1; j ++){
			// the limit on the previous element is j, (N/j)-N/(j+1) elements share the same number of ways
			ans += ((N/j)-(N/(j+1)))*dp(j, 0, k-1)%MOD;
		}
		
		return memo[i][mode][k] = ans%MOD;
	}else{
		throw;
	}
}*/

int main(){
	scanf("%d%d", &N, &K);
	
	//assert(N%2 == 0);
	
	//memset(memo, -1, sizeof(memo));
	
	int limit1 = (int)(floor(sqrt(N))+1e-9);
	int limit2 = limit1 - (N/limit1 == limit1);
	for(int i = 0; i <= limit1; i ++){
		dp[i][1][0] = dp[i][0][0] = 1;
	}
	
	for(int k = 1; k <= K; k ++){
		// do prefix sum of k-1
		prefixSum[0][0][k-1] = 0;
		prefixSum[0][1][k-1] = 0;
		for(int i = 1; i <= limit1+1; i ++){
			prefixSum[i][0][k-1] = prefixSum[i-1][0][k-1] + dp[i][1][k-1];
			prefixSum[i][1][k-1] = prefixSum[i-1][1][k-1] + (((N/i)-(N/(i+1)))*dp[i][0][k-1]%MOD);
		}
		
		// do the actual dp
		for(int i = 1; i <= limit1; i ++){
			dp[i][0][k] = (prefixSum[i][0][k-1] - prefixSum[0][0][k-1]) % MOD;
			dp[i][1][k] = (prefixSum[limit1][0][k-1] - prefixSum[0][0][k-1] + prefixSum[limit2][1][k-1] - prefixSum[i-1][1][k-1]) % MOD;
		}
	}
	
	printf("%lld", dp[1][1][K]);
}


Measured memory_bytes: 104704
//encoding:utf-8
#include <iostream> //c++
#include<time.h> //時間にかんして
#include<stack> //スタックに関して　最新のデータから捨てる
#include<queue> //キューに関して　最古のデータから捨てる
#include<math.h>
#include<vector>
#include<algorithm> //sort とかにいる

#define ll long long
using namespace std;
int inf = INFINITY;
int main(){
  string n;
  cin>>n;
  bool ans;
  if((n[0]==n[1]&&n[1]==n[2])||(n[1]==n[2]&&n[2]==n[3])){
    ans = true;
  }
  else{
    ans = false;
  }
  if(ans){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
  return 0;
}


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

int main()
{
	int n, m; cin >> n >> m;
	
	vector<int> k(n);
	vector<vector<int>> a(0, vector<int>());

	for (int i = 0; i < n; i++) {
		cin >> k[i];
		vector<int> tmpVec(k[i]);
		for (int j = 0; j < k[i]; j++) cin >> tmpVec[j];
		a.emplace_back(tmpVec);
	}

	int ans = 0;
	for (int x = 1; x <= m; x++) {
		vector<bool> exist(n,false);
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < k[i]; j++) {
				if (x == a[i][j]) exist[i] = true;			
			}
		}

		for (int i = 0; i < n; i++) {
			if (!exist[i]) break;
			if (i == n - 1) ans++;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#ifndef ONLINE_JUDGE
#define OJ \
    freopen("input.txt", "r", stdin); \
    //freopen("output.txt", "w", stdout);
#else
#define OJ ;
#endif
#define fo(int, i, l, r) for ( int i = l ; i < r ; ++ i)
#define srtV(a) sort(a.begin(),a.end())
const ll mod = 1e9+7;
ll minv (ll x)
{
    ll p=mod-2;
    ll ans=1,xx=x;
    while(p>0)

    {
        if(p&1)
            ans=(ans*xx)%mod;
        xx=(xx*xx)%mod;
        p=p/2;
        

    }
    return ans;
}

void solve()
{
    ll n;
    cin>>n;
    vector <ll> sq(n,0ll),a(n,0ll);
    ll sum=0,sumSq=0;
    for(int i=0;i<n;++i)
    {
        cin>>a[i];
        sq[i]=(a[i]*a[i])%mod;
        sum=(sum+a[i])%mod;
        sumSq=(sumSq+sq[i])%mod;
    }

    cout<<(((((sum*sum)%mod)- sumSq +mod )%mod)*(500000004ll))%mod<<"\n";


}
signed main()
{
    OJ
    //cout<<minv(2)<<"\n";
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    //int _t;cin>>_t;while(_t--)
    solve();
    return 0;
}

Measured memory_bytes: 6360
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		String A = sc.next();
		String B = sc.next();
		String C = sc.next();
		int ans = 0;
		for(int i = 0; i < A.length(); i++) {
			if(A.substring(i, i + 1).equals(B.substring(i, i + 1)) && C.substring(i, i + 1).equals(B.substring(i, i + 1))) {
				
			} else if(A.substring(i, i + 1).equals(B.substring(i, i + 1)) || C.substring(i, i + 1).equals(B.substring(i, i + 1)) || C.substring(i, i + 1).equals(A.substring(i, i + 1))) {
				ans++;
			} else {
				ans += 2;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 23636
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
typedef long long LL;
using Graph = vector<vector<int>>;

static long long INF = (1LL<<62);

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N; cin >> N;
	vector<int> D1, D2;
	for(int i=0; i<N; i++){
		int d1, d2; cin >> d1 >> d2;
		D1.push_back(d1);
		D2.push_back(d2);
	}

	int flag = 0;
	for(int i=0; i<=N-3; i++){
		if(D1[i] == D2[i] && D1[i+1] == D2[i+1] && D1[i+2] == D2[i+2]){
			flag = 1;
			break;
		}
	}
	if(flag == 1){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}



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

using namespace std;
const int N = 100 + 3;
int n, sum, a[N];
int main() {
#ifndef ONLINE_JUDGE
//	freopen("input.in", "r", stdin);
//	freopen("output.out", "w", stdout);
#endif
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		scanf("%d", a + i);
		sum += a[i];
	}
	int res = sum, cur = 0;
	for (int i = 0; i < n; ++i) {
		cur += a[i];
		sum -= a[i];
		res = min(res, abs(cur - sum));
	}
	printf("%d\n", res);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
typedef pair<ii,ll> iii;
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RREP(i,n) for (ll i=n-1;i>=0;i--)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (ll)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=998244353;
const ll INF=0x3f3f3f3f;

ll cnt[MAXn];
ll d[MAXn];
void mul(ll &a,ll b){
    a = (a*b)%MOD;
}
ll fpow(ll a,ll b){
    ll ret = 1;
    while (b) {
        if (b&1) mul(ret,a);
        mul(a,a);
        b >>= 1;
    }
    return ret;
}
int main(){
    IOS();
    ll n;
    cin >> n;
    ll mx = 0;
    REP (i,n) {
        cin >> d[i];
        cnt[d[i]]++;
        mx = max(mx,d[i]);
    }
    if (d[0] != 0 || cnt[0] > 1) return cout << 0 << endl,0;

    ll ans = 1;
    REP1 (i,mx) mul(ans,fpow(cnt[i-1],cnt[i]));
    cout << ans << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); 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 FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define ALL(v) v.begin(), v.end()
#define PRINTALL(V) for (auto v : (V)) cout << v << " "
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
template < class T > using vec = std::vector< T >;
template < class T > void print(T &x) { cout << x << "\n"; }
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI = acos(-1.0);
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  vec<int>a(N);
  vec<int>asum(N+1);
  a[0]=0;
  REP(i,N){
    cin>>a[i];
    asum[i+1]=asum[i]+a[i];
  }

  vec<vec<int>>l(N-1,vec<int>(2));
  vec<vec<int>>r(N-1,vec<int>(2));
  int cutPos=1;
  FORS(i,2,N-2){//右隣
    int l0= asum[cutPos]-asum[0];
    int l1= asum[i]-asum[cutPos];
    int minabs=abs(l0-l1);
    l[i][0]=l0;
    l[i][1]=l1;
    while ( l0<l1 && i-cutPos>=1 ){
      l0=asum[cutPos+1]-asum[0];
      l1=asum[i]-asum[cutPos+1];
      int nowabs=abs(l0-l1);
      if (nowabs<minabs){
        l[i][0]=l0;
        l[i][1]=l1;
        cutPos++;
        minabs=nowabs;
      }else{
        break;
      }
    }
  }
    cutPos=N-1;
  for (int i=N-2;i>=2;i--){//右隣
    int r0= asum[N]-asum[cutPos];
    int r1= asum[cutPos]-asum[i];
    int minabs=abs(r0-r1);
    r[i][0]=r0;
    r[i][1]=r1;
    while ( r0<r1 && cutPos - i >=1 ){
      int r0= asum[N]-asum[cutPos-1];
      int r1= asum[cutPos-1]-asum[i];
      int nowabs=abs(r0-r1);
      if (nowabs<minabs){
        r[i][0]=r0;
        r[i][1]=r1;
        cutPos--;
        minabs=nowabs;
      }else{
        break;
      }
    }
  }
  int ans=INF;
  FORS(i,2,N-2){
    int ansnow = 
    max({l[i][0],l[i][1],r[i][0],r[i][1]})-
    min({l[i][0],l[i][1],r[i][0],r[i][1]});
    ans=min(ans,ansnow);
    /* DEBUG(i);
    DEBUG(ansnow);
    PRINTALL(l[i]);
    PRINTALL(r[i]);
    cout<<"\n";*/
  }
  print(ans);

  return 0;
}

Measured memory_bytes: 25216
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  int n, a = 0, b = 0;
  cin >> n;
  vector<int> v(n);
  for (int i=0; i<n; i++)
    cin >> v.at(i);
  
  for (int i=0; i<n-1; i++) {
    for (int j=i+1; j<n; j++) {
      if (v.at(i) < v.at(j)) {
        int tmp = v.at(i);
        v.at(i) = v.at(j);
        v.at(j) = tmp;
      }
    }
  }
  for (int i=0; i<n; i+=2)
    a += v.at(i);
  for (int i=1; i<n; i+=2)
    b += v.at(i);
  
  cout << a - b << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
#define pb push_back
#define pii pair<ll,ll>
#define pi pair<int ,int> 
#define REP(i,a,n) for(int i=a;i<n;i++)
#define rep(i,a,n) for(int i=a;i>=n;i-- )
int main() {
          
         
        int a,b,c;
        cin>>a>>b>>c;
        int check=1;
        if(a==b || a==c || b==c){check=0;}
        if(a==b && b==c)
        {
            check=1;
        }
        if(check==1)
        {
            cout<<"No";
        }
        else
        {
            cout<<"Yes";
        }
    return 0;
}

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

typedef long long ll;

int main() {
    int N, S = 0;
    cin >> N;
    int x = N;
    while (x > 0) {
        S += x % 10;
        x /= 10;
    }
    if (N % S == 0) cout << "Yes\n";
    else cout << "No\n";
}

Measured memory_bytes: 3584
#include<stdio.h>
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INFTY (1<<21)
#define N 100
int n,M[N][N];
int color[N],d[N],p[N];

int min(){

  int u, mincost, i, v,sum = 0;




  for(i = 0; i < n; i++ ){

    color[i] = WHITE;
    d[i] = INFTY;
    p[i] = -1;
  }



  d[0] = 0;

  while(1){
    mincost = INFTY;
    u = -1;
    for(i = 0; i < n; i++){
      if(mincost > d[i] && color[i] != BLACK){
    u = i;
    mincost = d[i];
      }
    }
    if(u == -1)break;
    color[u] = BLACK;
    for( v = 0; v < n; v++){
      if(color[v] != BLACK && M[u][v] != INFTY){
    if(M[u][v] < d[v]){
      d[v] = M[u][v];
      p[v] = u;
      color[v] = GRAY;
    }
      }
    }
  }
  for(i = 0; i < n; i++){
    if(p[i] != -1){
      sum += M[i][p[i]];
    }
  }
  return sum;
}
int main(){
  int i, j, sum=0;
  scanf("%d",&n);
  for(i = 0; i < n; i++ ){
    for(j = 0; j < n; j++){
      scanf("%d",&M[i][j]);
      if(M[i][j] == -1)M[i][j]=INFTY;
    }
  }
  sum = min(n);
  printf("%d\n",sum);

  return 0;
}



Measured memory_bytes: 2112
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <set>
using namespace std;
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    string ans = "No";
    if(a+b==c||a+c==b||b+c==a){
        ans = "Yes";
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    a,b=MI()
    if a==1:a=14
    if b==1:b=14
    if a==b:ans="Draw"
    elif a>b:ans="Alice"
    else:ans="Bob"
    print(ans)

main()

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
int main() {
	string a;
	cin >> a;
	int b, c;
	for (int i = 0; i < a.size(); i++) {
		if (a[i] == 'A') {
			b = i;
			break;
		}
	}
	for (int i = a.size() - 1; i >= 0; i--) {
		if (a[i] == 'Z') {
			c = i;
			break;
		}
	}
	cout << c - b+1 << endl;
}

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

#define dbg(x) cerr << #x"=" << x << endl;
typedef long long LL;
map<LL, int> mp;
LL N,P;

int main(){
	//freopen("in.txt", "r", stdin);
	while(cin >> N >> P){
		mp.clear();
		LL p = P;
		for(LL i = 2; i*i <= P; ++i){
			if(p%i == 0){
				while(p%i == 0){
					++mp[i];
					p /= i;
				}
			}
		}
		if(p!=1) ++mp[p];
		LL ans = 1;
		for(auto &x:mp){
			dbg(x.first);
			dbg(x.second);
			for(int i = 1; i <= x.second/N; ++i){
				ans *= x.first;
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <vector>
#include <cmath>
#include <cstdint>
#include <string>

using namespace std;

int main() {
  double x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  cout << fixed << setprecision(5) << hypot(x2 - x1, y2 - y1) << endl;
}

Measured memory_bytes: 3308
import           Control.Monad
import           Data.Bits
import qualified Data.ByteString.Char8 as BS
import           Data.Maybe

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

getQuery = do
  l <- words <$> getLine
  case l of
    ["1"]           -> return (1, 0, 'x')
    ["2", n, (c:_)] -> return (2, (read n :: Int), c)

main = do
  s <- getLine
  n <- getInt
  qs <- replicateM n getQuery

  let solve :: String -> String -> Int -> [(Int, Int, Char)] -> BS.ByteString
      solve h t m [] = let s' = BS.pack s
                           h' = BS.pack h
                           t' = BS.pack t
                           s'' = BS.append (BS.append h' s') (BS.reverse t')
                       in
                         if (m .&. 1) == 1 then BS.reverse s'' else s''
      solve h t m ((1,_,_):qs') = solve h t (m+1) qs'
      solve h t m ((2,f,c):qs') =
        if (f == 1 && (m .&. 1) == 0) || (f == 2 && (m .&. 1) == 1)
        then solve (c:h) t m qs'
        else solve h (c:t) m qs'

  BS.putStrLn $ solve "" "" 0 qs

Measured memory_bytes: 48764
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

typedef long long ll;

int main() {
  ll n;
  while(scanf("%lld",&n),n) {
    ll corner = 1;
    while(corner*corner<n/2) ++corner;
    ll side = n/2;
    for (ll i=1; i*i<n/2; ++i) side += (n/2+i-1)/i;
    side -= corner*corner;
    //cout << corner << " " << side << endl;
    ll ans = side*8+corner*corner*4;
    ans *= 2;
    ans += n*2*4;
    printf("%lld\n",ans);
  }
}

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

int main()
{
 int x,y,z;

 while(1){
  cin >> x >> y;
  if(x==0 && y==0)break;
  
  if(x>y){z=x;x=y;y=z;}

  cout << x << " " << y << endl;
 }
}

Measured memory_bytes: 3100
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<map>
using namespace std;

int main()
{
	string s, t, u,x;
	int dif = 'A' - 'a';
	cin >> s >> t >> u;
	s[0] += dif;
	t[0] += dif;
	u[0] += dif;
	
	cout << s[0]<< t[0]<< u[0];
}

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

#define rep(i, N) for (ll i = 0; i < N; i++)
#define rep1(i, N) for (ll i = 1; i <= N; i++)
#define repr(i, N) for (ll i = N-1; i >= 0; i--)
#define repr1(i, N) for (ll i = N; i > 0; i--)

#define MOD 1000000007

using ll = long long;
using namespace std;

typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<P> vpi;
typedef pair<ll,ll> Pl;
typedef vector<ll> vl;
typedef vector<Pl> vpl;

ll gcd(ll a, ll b){
    if(a < b) swap(a, b);
    if(b <= 0) return -1;
    ll r = a % b;
    while(r != 0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

ll lcm(ll a, ll b){
    return (a/gcd(a,b)*b);
}


int main() {
    int A,B,H,M;
    cin >> A >> B >> H >> M;
    double yA, yB, xA, xB, PI = acos(-1), ans;

    yA = A*cos(2.0*PI*M/60.0);
    xA = A*sin(2.0*PI*M/60.0);
    yB = B*cos(2.0*PI*H/12.0 + PI/6.0*M/60.0);
    xB = B*sin(2.0*PI*H/12.0 + PI/6.0*M/60.0);
    
    ans = pow((xA-xB)*(xA-xB)+(yA-yB)*(yA-yB),0.5);
    

    //string ans = ( flag ? "Yes" : "No" );
    printf("%.10lf", ans);
    //cout << ans;
    cout << "\n";
    return 0;
}


Measured memory_bytes: 4228
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
const long long INF = 1LL << 60; 
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
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; }

int main()
{
  char C; cin >> C;
  string A = "abcdefghijklmnopqrstuvwxyz";
  rep(i,26)
  {
    if(C == A.at(i)) cout << A.at(i+1) << endl;
  }
}


Measured memory_bytes: 256
#include <string>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <cmath>
#include <limits>
#include <tuple>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;

#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 all(c) c.begin(),c.end()

int main()
{
	int N;
	cin >> N;
	vector<int> A(N);
	rep(i, N) {
		cin >> A[i];
	}
	sort(A.begin(), A.end());
	deque<int> B;
	{
		auto it = A.begin();
		auto itr = A.rbegin();
		rep(i, N) {
			if (i == 0) {
				B.push_back(*it++);
			} else {
				int d = (i + 1) / 2;
				if (d % 2 == 0) {
					if (i % 2 == 0)
						B.push_back(*it++);
					else
						B.push_front(*it++);
				} else {
					if (i % 2 == 0)
						B.push_back(*itr++);
					else
						B.push_front(*itr++);
				}
			}
		}
	}
	ll ans = 0;
	rep(i, N - 1) {
		ans += abs(B[i] - B[i + 1]);
	}
	{
		auto it = A.rbegin();
		auto itr = A.begin();
		//deque<int> B;
		B.clear();
		rep(i, N) {
			if (i == 0) {
				B.push_back(*it++);
			} else {
				int d = (i + 1) / 2;
				if (d % 2 == 0) {
					if (i % 2 == 0)
						B.push_back(*it++);
					else
						B.push_front(*it++);
				} else {
					if (i % 2 == 0)
						B.push_back(*itr++);
					else
						B.push_front(*itr++);
				}
			}
		}
		ll ans2 = 0;
		rep(i, N - 1) {
			ans2 += abs(B[i] - B[i + 1]);
		}
		ans = max(ans, ans2);
	}

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define prob "gcd"
#define N 100002
#define ll long long
#define io freopen(prob".inp","r",stdin); freopen(prob".out","w",stdout);
using namespace std;
int n;
int l[N], a[N];
void read()
{
    cin >> n;
    cin >> a[1];
    l[1] = a[1];
    for(int i = 2; i <= n; i++)
    {
        cin >> a[i];
        l[i] = __gcd(l[i-1], a[i]);
    }
    int res = l[n];
    for(int i = n; i >= 1; i--)
        {
            res = max(res,__gcd(a[i + 1], l[i - 1]));
            a[i]= __gcd(a[i], a[i + 1]);
        }
        cout << res;
}
int main()
{
  //  io
    read();
}


Measured memory_bytes: 1024
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 998244353
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int main(){
  ll N;cin>>N;
  ll i,j,k,l;
  bool a=true;
  pair<ll, ll>  pairs[N];
  rep(i,N) cin>>pairs[i].second>>pairs[i].first;
  sort(pairs,pairs+N);
  ll tmp=0;
  rep(i,N){
    tmp+=pairs[i].second;
    if(tmp>pairs[i].first) a=false;
  }
  if(a) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


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

int main() {
  int N;
  cin >> N ;
  if (N % 10 == 2 || N % 10 == 4 || N % 10 == 5 || N % 10 == 7 || N % 10 == 9 ){
    cout << "hon"<< endl;
} else if ( N % 10 == 0 || N % 10 == 1 || N % 10 == 6 || N % 10 == 8){
     cout << "pon"<< endl;
} else if ( N % 10 == 3){
       cout << "bon"<< endl;
}
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T>
using vec = std::vector<T>;

int main() {
    int N,D,X;
    cin >> N >> D >> X;
    vec<int> A(N);
    rep(i,N) cin >> A[i];
    int ans = 0;
    rep(i,N){
        ++ans;
        ans+=(D-1)/A[i];
    }
    cout << ans+X << endl;
}


Measured memory_bytes: 256
from sys import stdin
import numpy as np
def main():
    #入力
    readline=stdin.readline
    h,w=map(int,readline().split())
    grid=[readline().strip() for _ in range(h)]
    grid=[[1 if grid[i][j]=="." else 0 for j in range(w)] for i in range(h)]
    grid=np.array(grid,dtype=np.int64)

    up=np.zeros((h,w),dtype="int64")
    up[0]=grid[0]
    for i in range(1,h):
        up[i]=(up[i-1]+1)*grid[i]
    
    down=np.zeros((h,w),dtype="int64")
    down[-1]=grid[-1]
    for i in range(h-2,-1,-1):
        down[i]=(down[i+1]+1)*grid[i]
    
    left=np.zeros((h,w),dtype="int64")
    left[:,0]=grid[:,0]
    for i in range(1,w):
        left[:,i]=(left[:,i-1]+1)*grid[:,i]
    
    right=np.zeros((h,w),dtype="int64")
    right[:,-1]=grid[:,-1]
    for i in range(w-2,-1,-1):
        right[:,i]=(right[:,i+1]+1)*grid[:,i]

    ans=(up+down+left+right-3).max()
    print(ans)
    
if __name__=="__main__":
    main()

Measured memory_bytes: 235528
n,m=map(int,input().split())
l=[]
x=[]
for i in range(m):
    s,t=map(int,input().split())
    l.append(s)
    l.append(t)
for i in range(1,n+1):
    y=l.count(i)
    x.append(y)
    
for i in range(n):
    print(x[i])
    

Measured memory_bytes: 3060
n, s = map(int, input().split())
import itertools
while n != 0 or s != s:
    count = 0
    a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    for j in itertools.combinations(a, n):
        x = 0
        for i in range(n):
            x += j[i]
        if x == s:
            count += 1
    print(count)
    n, s = map(int, input().split())


Measured memory_bytes: 5632
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
    long long q,h,s,d,n,ans=0;
    cin>>q>>h>>s>>d>>n;
    if(q*2<h)
        h=q*2;
    if(h*2<s)
        s=h*2;
    if(s*2<d)
        d=s*2;
    ans+=(n/2)*d;
    n%=2;
    cout<<ans+n*s<<endl;
    return(0);
}

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

int main(){
  int N, K, x, sum=0;
  cin >> N >> K;
  
  for(int i=0; i<N; i++){
    cin >> x;
    if(abs(K-x) > x)
      sum += 2*x;
    else sum += 2*abs(K-x);
  }
  cout << sum;
}

Measured memory_bytes: 3584
N = int(input())
a = list(map(int, input().split()))
b = [0]*N
for i in range(N):
    if i % 2 == 0:
        n = i//2
        b[n] = str(a[N-i-1])
    else:
        n = (i-1)//2
        b[N-n-1] = str(a[N-i-1])
print(' '.join(b))

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

bool search(int A[], int n, int key){
    int i=0;
    A[n]=key;
    while ( A[i] != key ) i++;
    return i != n;
}

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

    for (int i=0; i < n ;i++){
        int K;
        cin >> K;
        int A[K];
        for (int j=0; j < K ; j++) cin >> A[j];
        for (int j=0; j < m ; j++) {
            if ((search(A,K, j+1))){
                M[j]+=1; 
            }
        }

    }

    int sum=0;
    for (int i=0; i < m ; i++){
        if ( M[i] == n )  sum++;
    }

    cout << sum <<endl;

}

Measured memory_bytes: 256
n = int(input())
li = [0]*n
for i in range(1,100):
    for j in range(1,100):
        for k in range(1,100): 
            if i**2 + j**2 + k**2 + i*j + j*k + k*i <= n:
                li[i**2 + j**2 + k**2 + i*j + j*k + k*i -1] += 1
for i in range(n):
    print(li[i])

Measured memory_bytes: 9368
#include<cstdio>
#include<cstring>
#define retrun return
#define cpnst const
int N,X,D;
typedef long long ll;
ll V[111111],W[111111],f[111111];
ll dp[133333];
cpnst int lim=131072;
void ins(ll v,ll w)
{
	register int i;
	for(i=lim;i>=w;i--)
		if(dp[i]>dp[i-w]+v)dp[i]=dp[i-w]+v;
}
struct pii
{ll v,w,s;}P[111];
bool operator<(cpnst pii x,cpnst pii y)
{return x.w*y.v>x.v*y.w;}
ll greedy(ll VAG)
{
	register int i;
	ll ret=0;
	for(i=1;i<=N;i++)
	{
		ll K=VAG/P[i].v;
		if(K>P[i].s)K=P[i].s;
		ret+=P[i].w*K,VAG-=P[i].v*K;
	}return ret;
}
void trial(ll v,ll w,int d)
{
	register int i;
	for(i=1;i<=d;d-=i,i<<=1)ins(v*i,w*i);
	if(d)ins(v*d,w*d);
}
#include<algorithm>
int main()
{
	register int i;
	scanf("%d%d%d",&N,&X,&D);
	int DL=D;
	if(N<DL)DL=N;
	scanf("%lld",V+1),W[1]=1;
	for(i=2;i<=N;i++)
		scanf("%lld%lld",V+i,f+i),W[i]=1;
	for(i=N;i>1;i--)
		V[f[i]]+=V[i],W[f[i]]+=W[i];
	for(i=1;i<=N;i++)
		P[i]=(pii){V[i],W[i],D-DL+X*(i==1)};
	std::sort(P+1,P+N+1);
	for(i=1;i<=lim;i++)dp[i]=2e9;
	for(i=1;i<=N;i++)trial(V[i],W[i],DL);
	ll ans=0;
	for(i=0;i<=lim;i++)
	{
		if(dp[i]>X)continue;
		ll T=greedy(X-dp[i])+i;
		if(T>ans)ans=T;
	}printf("%lld\n",ans);
}
/*
Please don't let me down.
*/

Measured memory_bytes: 2748
#include<bits/stdc++.h>
using namespace std;
#define INF 100000000000
long long int dp[100005],arr[100005],n,k1;
long long int solve(long long int idx)
{
	if(idx>n)
		return INF;
	if(idx==n)
		return 0;
	if(dp[idx]!=-1)
		return dp[idx];
	long long int i,j,k,ans=INF;
	for(i=idx+1;i<=(idx+k1);i++)
    if(i<=n)
    {
     j=abs(arr[i]-arr[idx]);
     //printf("%lld %lld\n",idx,j);
     k=solve(i);
     ans=min(ans,(j+k));
    }
    dp[idx]=ans;
    return dp[idx]; 
}
int main()
{
   long long int i,j,k,ans=0;
   scanf("%lld%lld",&n,&k1);
   for(i=1;i<=n;i++)
   	dp[i]=-1;
   for(i=1;i<=n;i++)
   	scanf("%lld",&arr[i]);
   ans=solve(1);
   /*for(i=1;i<=n;i++)
   	printf("%lld ",dp[i]);
   printf("\n");*/
   printf("%lld\n",ans);
}

Measured memory_bytes: 6528
#pragma warning(disable:4996)

#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <complex>
#include <iterator>
#include <random>
#include <time.h>
#include <tuple>
#include <functional>
#include <list>
#include <limits.h>
using namespace std;

string S;
string D[4] = {"dream", "dreamer", "erase", "eraser"};

vector<int> cc;
int dp(int s) {
	if(s == S.size()) return 1;
	int &ret = cc[s];
	if(ret != -1) return ret;

	ret = 0;
	for(int i = 0; i < 4; i++) {
		if(S.size() < s + D[i].size()) continue;
		bool ok = true;
		for(int j = 0; j < D[i].size(); j++) {
			if(S[s + j] != D[i][j]) {
				ok = false;
				break;
			}
		}
		if(ok) ret |= dp(s + D[i].size());
	}
	return ret;
}

int main() {
	cin>>S;
	cc = vector<int>(S.size(), -1);
	if(dp(0)) cout<<"YES";
	else cout<<"NO";
}

Measured memory_bytes: 1920
import heapq


class PriorityQueue:
    def __init__(self):
        self.__heap = []
        self.__count = 0

    def empty(self) -> bool:
        return self.__count == 0

    def dequeue(self):
        if self.empty():
            raise Exception('empty')
        self.__count -= 1
        return heapq.heappop(self.__heap)

    def enqueue(self, v):
        self.__count += 1
        heapq.heappush(self.__heap, v)

    def __len__(self):
        return self.__count


def _3N_numbers(N: int, A: list)->int:
    # first half
    q = PriorityQueue()
    first_half = [0] * (N+1)
    for i in range(N):
        q.enqueue(A[i])
        first_half[0] += A[i]

    for k in range(N):
        q.enqueue(A[N+k])
        decrement = q.dequeue()
        first_half[k+1] = first_half[k] - decrement + A[N+k]

    # second half
    q = PriorityQueue()
    second_half = [0] * (N+1)
    for i in range(N):
        q.enqueue(-A[3*N-1-i])
        second_half[N] += A[3*N-1-i]

    for k in range(N):
        q.enqueue(-A[2*N-1-k])
        decrement = -q.dequeue()
        second_half[N-(k+1)] = second_half[N-k] - decrement + A[2*N-1-k]

    return max(f - s for f, s in zip(first_half, second_half))


if __name__ == "__main__":
    N = int(input())
    A = [int(s) for s in input().split()]
    ans = _3N_numbers(N, A)
    print(ans)


Measured memory_bytes: 37212
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <regex>
#include <set>
#include <cmath>
#include <sstream>
#include <numeric>
#include <set>

using namespace std;

int main()
{
    int a, b, c;
    std::cin >> a >> b >> c;
    if(a + b + c >= 22)
    {
        std::cout << "bust";
    }else
    {
        std::cout << "win";
    }
    

    return EXIT_SUCCESS;
}


Measured memory_bytes: 504
n,x = input().split()
n,x = int(n), int(x)
L = [int(x) for x in input().split()]

D = [0 for _ in range(n + 1)]

for i in range(1, n + 1):
  D[i] = D[i-1] + L[i-1]

res = [True if D[i] <= x else False for i in range(n + 1)]

print(sum(res))

Measured memory_bytes: 3064
//codeforces
#include <algorithm>
#include <vector>
#include <string>
#include <ctype.h>
#include <set>
#include <map>
#include<cstdio>
#include<queue>
#include<cstdlib>
#include<time.h>
#include<string>
#include<stack>
#include<cmath>
#include<iostream>
#include<cstring>
#include<complex>
#include<bitset>
#include <climits>
#include<tr1/unordered_set>
#include<tr1/unordered_map>


#include<bits/stdc++.h>

#define FOR(i,j,k) for(int i=j;i<k;i++)
#define FORD(i,j,k) for(int i=j;i>=k;i--)
#define ll long long
//Make sure no overflow problems
//#define int long long
#define pii  pair<int, int>
#define vi vector<int >
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define VAR(i,n) __typeof(n) i = (n)
#define FOREACH(i,c) for(VAR(i,(c).begin());i!=(c).end();i++)
#define FORDEACH(i,c) for( VAR(i,(c).rbegin()),i!=(c).rend();i++)
#define REP(i,n) FOR(i,0,n)
#define ld long double
const int INF = 1e9+7;
const long long INFLL = (ll)INF * (ll)INF;
const ld EPS = 10e-9;

using namespace std;

class TrieNode{
    public:
    bool isword;
    char c;
    map<char,TrieNode*> m;
    string word;
    public:
    TrieNode(){}
    TrieNode(char ch){
        c=ch;
        isword=false;
    }
};

void insert(TrieNode* root,string word){
    TrieNode* temp=root;
    for(char c:word){
        if(temp->m.find(c)==temp->m.end())
            temp->m[c]=new TrieNode(c);
        temp=temp->m[c];
    }
    temp->isword=true;
    temp->word=word;
}


#pragma GCC optimize ("Ofast")
static auto _ = [] { std::ios::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0); std::cerr.tie(0); return 0; } ();





int MOD=1e9+7;

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

    vector<vector<double>> dp(n+1,vector<double> (n+1,0));
    // r-> r coins
    // c -> c heads
    dp[0][0]=1;

    vector<double> p(n);

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

    for(int i=1;i<=n;i++){
        for(int j=0;j<=i;j++){
            if(j==0)
                dp[i][j]=dp[i-1][j]*(1-p[i-1]);
            else
                dp[i][j]=dp[i-1][j-1]*p[i-1]+dp[i-1][j]*(1-p[i-1]);
        }
    }
    double ans=0;
    for(int i=0;i<=n;i++){
      if(i>n-i)
        ans+=dp[n][i];
    }
    cout<<fixed<<setprecision(10)<<ans;

    return 0;
}


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


int main() {
  string s;
  cin >> s;
  map<string, int> days = {
    {"SUN", 7},
    {"MON", 6},
    {"TUE", 5},
    {"WED", 4},
    {"THU", 3},
    {"FRI", 2},
    {"SAT", 1}
  };
  
  cout << days.at(s) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <climits>
#include <cassert>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;
using VVI = vector<vector<long long int> >;

int main(void) {
    Int n, r;
    cin >> n >> r;
    if (n < 10) {
        cout << r + 100 * (10 - n) << endl;
    } else {
        cout << r << endl;
    }
    return 0;
}


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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    
    string s;
    cin >> s;

    if (n % 2 == 1){
        cout << "No\n";
        return 0;
    }

    for (int i = 0; i < n / 2; i++){
        if (s[i] != s[n / 2 + i]){
            cout << "No\n";
            return 0;
        }
    }

    cout << "Yes\n";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
using ll = long long;

void print_ans(bool flag){
    if(flag){
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }   
}

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    print_ans( (b - a) == (c - b) );
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

int main(){
    int n, k; cin>>n>>k;
    cout << (n - k + 1) << endl;
}

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

using namespace std;


long long lcm(long long x, long long y){
    return x / __gcd(x, y) * y;
}
int main() {
#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
#endif

    long long l, r, f, s;
    scanf("%lld %lld %lld %lld", &l, &r, &f, &s);

    long long r1 = r / f + r / s - r / lcm(f, s);
    l--;
    long long r2 = l / f + l / s - l / lcm(f, s);
    printf("%lld\n", (r - l) - (r1 - r2));
    return 0;
}

Measured memory_bytes: 256
input()
h = list(map(int, input().split(' ')))

c = 0
while any(x > 0 for x in h):
    b = False
    for i in range(len(h)):
        if h[i] > 0:
            b = True
            h[i] -= 1
        elif b:
            break
    if b:
        c += 1
print(c)

Measured memory_bytes: 3060