akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

const int Maxn = 100005;

int n;
map <int, int> M;
int a[Maxn];

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        int a; scanf("%d", &a);
        M[a]++;
    }
    if (M.size() > 3) { printf("No\n"); return 0; }
    for (map <int, int>::iterator it = M.begin(); it != M.end(); it++)
        for (map <int, int>::iterator it2 = M.begin(); it2 != M.end(); it2++) {
            a[0] = it->first, a[1] = it2->first;
            for (int i = 2; i < n; i++)
                a[i] = (a[i - 2] ^ a[i - 1]);
            bool ok = true;
            if (a[0] != (a[n - 2] ^ a[n - 1])) ok = false;
            if (a[1] != (a[n - 1] ^ a[0])) ok = false;
            if (ok) {
                map <int, int> A;
                for (int i = 0; i < n; i++)
                    A[a[i]]++;
                ok = M == A;
            }
            if (ok) { printf("Yes\n"); return 0; }
        }
    printf("No\n");
    return 0;
}


Measured memory_bytes: 3840
#include <iostream>
#include <cstring>

using namespace std;

int main() {
	char s[101];
	int k;
	cin >> k;
	cin >> s;
	int n = strlen(s);
	if (k < n) {
		for (int i = 0;i < k;i++) {
			cout << s[i];
		}
		cout << "...";
	}
	else cout << s;
	return 0;
}

Measured memory_bytes: 3640
#include<iostream>
#include<cstdio>
#include<cstring>
#include<bitset>

namespace guichu
{
	const int N=303;

	char s[N][N];

	std::bitset<N*2> f[N][N];

	int n,ans;

	std::bitset<N*2> g;
	int calc(int fk)
	{
		g.reset();
		for(int i=0;i<n;i++)g[i]=1;

		for(int i=0;i<n;i++)
			for(int j=i+1;j<n;j++)
			{
				int x=(i+fk)%n,y=(j+fk)%n;
				g&=f[x][y]>>j;
			}
		return g.count();
	}

	void solve()
	{
		scanf("%d",&n);
		for(int i=0;i<n;i++)
			scanf("%s",s[i]);

		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++)
				for(int d=0;d<n;d++)
					f[i][j][d]=f[i][j][d+n]=(s[i][d]==s[j][(d+i-j+n)%n]);

		ans=0;
		for(int i=0;i<n;i++)
			ans+=calc(i);

		printf("%d\n",ans);
	}
}

int main()
{
	guichu::solve();
	return 0;
}


Measured memory_bytes: 7552
#include <bits/stdc++.h>
using namespace std;
vector<pair<int,int>> dir = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int h, w, k;
	cin >> h >> w >> k;
	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	--x1; --y1; --x2; --y2;
	vector<string> grid(h);
	for (int i = 0; i < h; ++i)
		cin >> grid[i];
	auto valid = [&](const pair<int, int>& p){ return p.first >= 0 && p.first < h && p.second >= 0 && p.second < w; };
	vector<vector<int>> dist(h, vector<int>(w, 1e9));
	vector<vector<bool>> vis(h, vector<bool>(w));
	queue<pair<int, int>> q;
	q.emplace(x1, y1);
	dist[x1][y1] = 0;
	vis[x1][y1] = 1;
	while (!q.empty()){
		auto u = q.front(); q.pop();
		for (int j = 0; j < 4; ++j){
			for (int i = 1; i <= k; ++i){
				int nr = u.first + i * dir[j].first;
				int nc = u.second + i * dir[j].second;
				if (!valid({nr, nc}) || grid[nr][nc] != '.' || dist[nr][nc] <= dist[u.first][u.second]) break;
				if (vis[nr][nc]) continue;
				dist[nr][nc] = dist[u.first][u.second] + 1;
				if (nr == x2 && nc == y2){
					cout << dist[nr][nc] << '\n'; return 0;
				}
				vis[nr][nc] = 1;
				q.emplace(nr, nc);
			}
		}
	}
	cout << -1 << '\n';
}

Measured memory_bytes: 12172
# -*- coding: utf-8 -*-
n, m = map(int, input().split())
ab = [0]*m
for i in range(m):
    a, b = map(int, input().split())
    ab[i] = (b, a)
ab.sort()
count = 0
last_break = n
for abi in ab:
    if not ((count != 0) & (abi[1] <= last_break)):
        count += 1
        last_break = abi[0] - 1
print(count)

Measured memory_bytes: 17012
#include <iostream>
#include <numeric>

using namespace std;

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

typedef long long ll;







int main(){



    
    int N;
    cin>>N;

    ll a[N];

    ll sum=0;

    rep(i,N){
        cin>>a[i];
        sum+=a[i]-1;
    }

    cout<<sum<<endl;


}


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

int main(void)
{
    int n;
    cin >> n;
    string s[n];
    for (int i = 0; i < n; i++)
    {
        cin >> s[i];
    }
    int m;
    cin >> m;
    string t[m];
    for (int i = 0; i < m; i++)
    {
        cin >> t[i];
    }

    /*int ans = -m;
    int yen = 0;
    for (int i = 0; i < n-1; i++)
    {   
        yen++;
        for (int j = i+1; j < n; j++)
        {
            if (s[i] == s[j]) { yen++; }
        }
        for (int k = 0; k < m; k++)
        {
            if (s[i] == t[k]) { yen--; }
        }
        ans = max(ans, yen);
        yen = 0;
    }*/

    int ans = 0;
    int yen = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            if (s[i] == s[j]) { yen++; }
        }

        for (int k = 0; k < m; k++)
        {
            if (s[i] == t[k]) { yen--; }
        }

        ans = max(yen, ans);
        yen = 0;
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;


int main(){
  int x, a, b;
  cin >> x >> a >> b;
  if(b <= a) cout << "delicious" << endl;
  else if(b > a + x) cout << "dangerous" << endl;
  else cout << "safe" << endl;

}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}
#define N 600
string s[N];

int main(){
	int n;
	cin>>n;
	rep(i, n) cin>>s[i];
	int res = INF, cnt = 0;
	rep(j, n){
		int c = 0;
		rep(i, n) if(s[i][j]!='#') c = 1;
		cnt += c;
	}
	rep(i, n){
		int a = 0;
		rep(j, n) if(s[i][j]!='#') a++;
		int b = 1;
		rep(j, n) if(s[j][i]=='#') b = 0;
		a += b;
		if(a<=n) chmin(res, a+cnt);
	}
	cout<<(res==INF?-1:res)<<endl;
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;

const ll INF=(1LL<<50);

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}


void solve(long long N, long long K, std::vector<long long> P){
  multiset<ll> s;
  vector<ll> sorted_list;
  ll prevIdx=0;
  REP(N-1){
    if(P[i]>P[i+1]){
      sorted_list.push_back(prevIdx);
      prevIdx=i+1;
    }
  }
  sorted_list.push_back(prevIdx);
  dump(sorted_list);
  REP(K){
    s.insert(P[i]);
  }
  bool not_changed=false;
  ll ans=1;
  auto is_notsorted = [&](ll i){
    auto itr=prev(upper_bound(sorted_list.begin(),sorted_list.end(),i));
    if(itr==prev(lower_bound(sorted_list.begin(),sorted_list.end(),i+K))){
      return true;
    }
    return false;
  };
  if(is_notsorted(0)){
    not_changed=true;
  }
  REP(N-K){
    bool f=false;
    auto itr = s.lower_bound(P[i]);
    if(itr!=s.begin()){
      f=true;
    }
    s.erase(itr);
    s.insert(P[i+K]);
    itr = s.upper_bound(P[i+K]);
    if(itr!=s.end()){
      f=true;
    }
    if(f&&is_notsorted(i+1)){
      if(not_changed){
        f=false;
        dump(i+1);
      }else{
        not_changed=true;
        dump(i+1);
      }
    }
    if(f){
      ++ans;
    }
  }
  cout<<ans<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> P(N-1-0+1);
    for(int i = 0 ; i < N-1-0+1 ; i++){
        scanf("%lld",&P[i]);
    }
    solve(N, K, std::move(P));
    return 0;
}


Measured memory_bytes: 12020
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define int long long
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
using namespace std;
signed main(){
    int n,l; cin>>n>>l;
    vector<int> a(n);
    vector<int> aa(n-1,0);
    rep(i,n)cin>>a.at(i);
    int m=-1;
    rep(i,n-1){
        aa.at(i)=a.at(i)+a.at(i+1);
        if(aa.at(i)>=l) m=i;
    }
    if(m==-1){
        cout<<"Impossible"<<endl;
        return 0;
    }
    cout<<"Possible"<<endl;
    int k=0;
    while(k<m){
        cout<<k+1<<endl;
        k++;
    }
    k=n-2;
    while(k>m){
        cout<<k+1<<endl;
        k--;
    }
    cout<<m+1<<endl;
}

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

#define int long long int
#define pb push_back
#define mp make_pair

#define fr(i,a,b) for(i=a;i<=b;i++)

const int N=1e5+5;

int32_t main()
{
     
     int a,b,ans,temp;
     
     cin>>a>>b;
     
     ans=a*b;
     temp=(a+b)-1;
     ans-=temp;
     cout<<ans;
     
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef vector<double> Vec;
typedef vector<Vec> Mat;
typedef pair<ll,ll> P;
typedef pair<double,ll> Pd;
typedef pair<double,double> PD;
typedef priority_queue<P,vector<P>,greater<P> > P_queue;
typedef priority_queue<Pd,vector<Pd>,greater<Pd> > Pd_queue;

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e15;
const double DEL=1e-6;


#define _GLIBCXX_DEBUG
#define REP(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());
#define ADD(a,b) a=(a+b)%mod
#define MUL(a,b) a=(a*b)%mod

ll N,K;
vec p,c;

void input(){
    cin>>N>>K;
    c.resize(N);
    rep(i,N){
        ll x; cin>>x; x--;
        p.pb(x);
    }
    rep(i,N) cin>>c[i];
}

ll memo_k[5001], memo_score[5001];
ll ANS=-INF;

ll dfs(ll x, ll k, ll score){
    if(k!=K) ANS=max(ANS,score);
    if(!k) return score;
    if(memo_k[x]<0){
        memo_k[x]=k; memo_score[x]=score;
        return dfs(p[x],k-1,score+c[p[x]]);
    }
    if(2*(memo_k[x]-k)<=k){
        ll kk=memo_k[x]-k, ss=-memo_score[x]+score;
        return dfs(x,kk+(k%kk),score+ss*((k/kk)-1));
    }
    return dfs(p[x],k-1,score+c[p[x]]);
}

void init(){
    rep(i,N) memo_k[i]=-1;
    rep(i,N) memo_score[i]=0;
    return;
}

int main(){
    input();
    vec ans(N,0);
    rep(i,N){
        init();
        ans[i]=dfs(i,K,0);
    }

    cout<<ANS<<endl;


}

Measured memory_bytes: 3860
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int INF = 987654321;
const ll MOD = 1e9+7;

int n; 
vl a;
vl psum;

ll diffL(int i, int a) {
    return abs(psum[i-1]-2*psum[a-1]);
}

ll diffR(int i, int b) {
    return abs(psum[n]-2*psum[b-1]+psum[i-1]);
}

int main(void) {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//freopen("in.txt", "r", stdin);
    cin >> n;
    a.resize(n+1);
    psum.resize(n+1);
    rep(i,1,n+1) {
        cin >> a[i];
    }
    rep(i,1,n+1) {
        psum[i] = psum[i-1] + a[i];
    }
    ll ret = 1e18;
    int a = 2;
    int b = 4;
    rep(i,3,n) {
        if(b==i) b++;
        while(a+1 < i && diffL(i,a+1) < diffL(i,a)) {
            a++;
        }
        while(b+1 <= n && diffR(i, b+1) < diffR(i,b)) {
            b++;
        }
        //cout << a << ", " << i << ", " << b << endl;
        vl cand(4);
        cand[0] = psum[a-1];
        cand[1] = psum[i-1] - psum[a-1];
        cand[2] = psum[n] - psum[b-1];
        cand[3] = psum[b-1] - psum[i-1];
        sort(all(cand));
        ret = min(ret, cand[3]-cand[0]);
    }
    cout << ret << endl;
	return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int X,Y,Z;
  cin >> X >> Y >> Z;
  int ans = 0;
  while((ans+1) * Y + (ans+2) * Z <= X) {
    ans++;
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  ll a;
  string b;
  cin >> a >> b;
  ll c = stoi(b.substr(0,1)) * 100;
  if(b.size() >= 3)
    c += stoi(b.substr(2,1)) * 10;
  if(b.size() >= 4)
    c += stoi(b.substr(3,1));

  cout << (a * c) / 100 << endl;
  return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
string S[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};

int main() {
  string s;
  int num = 0;
  cin >> s;
  rep(i, 7) {
    if(s == S[i]) {
      num = i;
    }
  }
  cout << 7 - num << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

int main()
{
	int n;
	scanf("%d", &n);
	int r = n % 10;
	switch (r) {
	case 2:
	case 4:
	case 5:
	case 7:
	case 9:
		printf("hon\n");
		break;
	case 0:
	case 1:
	case 6:
	case 8:
		printf("pon\n");
		break;
	case 3:
		printf("bon\n");
		break;
	}
	return 0;
}


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

int main(){
    ll x,y; cin >> x >> y;
    rep(i,0,x+1){
        if(i*2+(x-i)*4 == y){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main(){
string S;
string T;
cin>>S>>T;
int a=S.size();
int count=0;
for(int i=0; i<a; i++){
    if(S.at(i)!=T.at(i)){
        count++;
    }
}
cout<<count<<endl;
}

Measured memory_bytes: 3916
#include <cstdio>
#include <queue>
#include <vector>
#include <algorithm>
#include <utility>
#include <climits>
#include <cstdlib>

using namespace std;

#define NDEBUG

#ifndef NDEBUG
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...)
#endif

int N;

const char *solve(int (&balls)[10]) {
    for (int trial = 0; trial < (1 << 10); trial++) {
        int left_top = 0, right_top = 0;
        int i;
        for (i = 0; i < 10; i++) {
            int dir = ((trial >> i) & 1);
            int ball = balls[i];
            if (dir) { // left
                if (left_top == 0) {
                    left_top = ball;
                    continue;
                }
                if (left_top > ball) {
                    break;
                }
                left_top = ball;
            } else { // right
                if (right_top == 0) {
                    right_top = ball;
                    continue;
                }
                if (right_top > ball) {
                    break;
                }
                right_top = ball;
            }
        }
        if (i == 10) {
            return "YES";
        }
    }
    return "NO";
}

int main() {
    scanf(" %d", &N);
    debug("===\n");
    debug("%d\n", N);
    for (int i = 0; i < N; i++) {
        int balls[10];
        for (int j = 0; j < 10; j++) {
            scanf(" %d", &balls[j]);
        }
        for (int j = 0; j < 10; j++) {
            debug("%d ", balls[j]);
        }
        debug("\n");
        printf("%s\n", solve(balls));
    }
}

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

int main(){
	int i,x[100],y[100],n;
	double p_1=0.0,p_2=0.0,p_3=0.0,p_inf=0.0;
	char input[512],*p;
	
	fgets(input,sizeof input,stdin);
	sscanf(input,"%d",&n);
	
	fgets(input,sizeof input,stdin);
	p=strtok(input," ");
	x[0]=atoi(p);
	for(i=1;i<n;i++){
		p=strtok(NULL," ");
		x[i]=atoi(p);
	}
	
	fgets(input,sizeof input,stdin);
	p=strtok(input," ");
	y[0]=atoi(p);
	for(i=1;i<n;i++){
		p=strtok(NULL," ");
		y[i]=atoi(p);
	}
	
	for(i=0;i<n;i++){
		p_1+=fabs((double)x[i]-(double)y[i]);
		p_2+=pow(fabs((double)x[i]-(double)y[i]),2);
		p_3+=pow(fabs((double)x[i]-(double)y[i]),3);
		
		if(p_inf<=fabs((double)x[i]-(double)y[i])){
			p_inf=fabs((double)x[i]-(double)y[i]);
		}
		
	}
	p_2=sqrt(p_2);
	p_3=cbrt(p_3);
	
	printf("%f\n%f\n%f\n%f\n",p_1,p_2,p_3,p_inf);
	
	return 0;
}

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

using namespace std;
const int MAX = 2000000;

int H,A[MAX+1];

void maxHeapify(int i){
    int l,r,largest;
    l = 2 * i;
    r = 2 * i +1;

    if (l <= H && A[l] > A[i]){
        largest = l;
    } else {
        largest = i;
    }
    if (r <= H && A[r] > A[largest]){
        largest = r;
    }

    if(largest != i){
        swap(A[i],A[largest]);
        maxHeapify(largest);
    }
}

int main(){
    cin >> H;
    for (int i = 1; i <= H ; ++i) {
        cin >> A[i];
    }

    for (int i = H ; i >= 1 ; i--) {
        maxHeapify(i);
    }
    for (int i = 1; i <= H ; ++i) {
        cout << " " << A[i];
    }
    cout << endl;
    return 0;
}

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

int main(){
    int N;
    bool Y_exist = false;
    cin >> N;
    for(int i = 0; i < N ; i++){
        string in;
        cin >> in;
        if(in == "Y"){
            Y_exist = true;
            break;
        }
    }

    if(Y_exist == true) cout << "Four" << endl;
    else cout << "Three" << endl;
}

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

int main() {
  int a,b,c,d;
  cin >> a>> b>> c>> d;
  if (a==1 || b==1 || c==1 ||d==1){
    if (a==7 || b==7 || c==7 ||d==7){
      if (a==4 || b==4 || c==4 ||d==4){
        if (a==9 || b==9 || c==9 ||d==9){
          cout << "YES" <<endl;
        }
        else{
          cout << "NO" <<endl;
        }
      }
      else{
        cout << "NO" <<endl;
      }
    }
    else{
      cout << "NO" <<endl;
    }
  }
  else{
  cout << "NO" <<endl;
  }
}


Measured memory_bytes: 256
import java.util.*;

class Main {
	public static void main(String args[]) {

		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		in.nextLine();
		for (int i = 0; i < N; i++) {
			long rest=in.nextLong();
			long buy=in.nextLong();
			long min=in.nextLong();
			long add=in.nextLong();
			if(buy>rest||buy>add) {
				System.out.println("No");
				continue;
			} else if(buy<min && add>=buy) {
				System.out.println("Yes");
				continue;
			}
			long dif=gcd(add, buy);
			long restMin = rest%dif;
			if(restMin<min) {
				restMin += dif*((min-restMin)/dif);
			}
			if(restMin<=min) {
				restMin += dif;
			}
			if(restMin<buy) {
				System.out.println("No");
			}else {
				System.out.println("Yes");
			}
		}
		in.close();
	}
	static long gcd (long a, long b) {return b>0?gcd(b,a%b):a;}
}


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

using namespace std;

int nums[10000];

int main() {
  int n;
  while (cin >> n, n) {
    for (int i = 0; i < n; i++) { cin >> nums[i]; }
    sort(nums, nums + n);
    int sum = 0;
    for (int i = 1; i < n - 1; i++) { sum += nums[i]; }
    cout << sum / (n - 2) << endl;
  }
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <iomanip>
#include <cmath>

using namespace std;


int N;
vector<int> X, Y;

int main()
{
	cin >> N;
	
	X = vector<int>(N);
	Y = vector<int>(N);
	for (int i = 0; i < N; i++) {
		cin >> X[i];
		cin >> Y[i];
	}

	double sum = 0;
	for (int i = 0; i < N-1; i++) {
		for (int j = i+1; j < N; j++) {
			double db = sqrt((X[i] - X[j])*(X[i] - X[j]) + (Y[i] - Y[j])*(Y[i] - Y[j]));
			sum += (double)db * 2 / N;
		}
	}


	cout << fixed << setprecision(10) << sum << endl;

	return 0;


}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static int max(int a, int b){return (a > b ? a : b);}
    public static int min(int a, int b){return (a < b ? a : b);}
    public static int gcd(int a, int b){return (b > 0 ? gcd(b, a % b) : a);}
    public static int lcm(int a, int b){return a / gcd(a, b) * b;}
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int cnt = 0;
        List<Long>A = new ArrayList<Long>();
        for(int i = 0; i < N; i++){
            Long a = sc.nextLong();
            if(a < 0){
                cnt ^= 1;
                a = -a;
            }
            A.add(a);            
        }        
        Collections.sort(A);
        if(cnt > 0)A.set(0, -A.get(0));
        Long ans = 0L;
        for(int i = 0; i < A.size(); i++)ans += A.get(i);
        System.out.print(ans);
    }
}


Measured memory_bytes: 65236
H, W = (int(i) for i in input().split())
e = [input() for i in range(H)] 

new_e = []
for row in e:
    if row.count("#") > 0:
        new_e.append(row)

use_col = []
for row in new_e:
    for col in range(W):
        if row[col] == "#" and col not in use_col:
            use_col.append(col)
            
for row in new_e:
    x=""
    for col in sorted(use_col):
        x += row[col]
    print(x)



Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main(void)
{
  int w = 0, h = 0, x = 0, y = 0, r= 0;
  cin >> w >> h >> x >> y >> r;

  bool inRect = false;
  if (0 <= (x-r) && (x+r) <= w
      && 0 <= (y-r) && (y+r) <= h) {
    inRect = true;
  }

  cout << (inRect ? "Yes" : "No") << endl;
  
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define END getchar();getchar();return 0

signed main() {
	string s;
	cin >> s;
	int ans = 0;
	for (int i = 1; i < s.size(); i++) {
		if (s[i] != s[i - 1]) {
			ans++;
		}
	}
	cout << ans << endl;

	END;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int x1,x2,x3,x4,x5;
  cin>>x1>>x2>>x3>>x4>>x5;
  if(x1==0)
  cout<<1<<endl;
  else if(x2==0)
  cout<<2<<endl;
  else if(x3==0)
  cout<<3<<endl;
  else if(x4==0)
  cout<<4<<endl;
  else if(x5==0)
  cout<<5<<endl;
}

Measured memory_bytes: 3544
s = list(input())
t = list(input())

n = len(s)
m = len(t)

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

for i in range(n):
    for j in range(m):
        if s[i] == t[j]:
            dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1)
        dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i + 1][j])
        dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j + 1])

ans = ''
i = n
j = m
while i > 0 and j > 0:
    if dp[i][j] == dp[i-1][j]:
        i -= 1
    elif dp[i][j] == dp[i][j-1]:
        j -= 1
    else:
        ans = s[i-1] + ans;
        i -= 1
        j -= 1

print(ans)

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

int main(void){
	int R0,W0,C,R;
	while(cin>>R0>>W0>>C>>R, R0|W0|C|R)
	{
		cout<<max(0,(C*W0-R0+R-1)/R)<<endl;
	}
	return 0;
}

Measured memory_bytes: 3060
def main():
    A, B, C, X, Y = map(int, input().split())
    ans = 10 ** 10

    for k in range(max(X, Y) + 1):
        total = 2 * C * k + A * max(0, X - k) + B * max(0, Y - k)
        if total < ans:
            ans = total

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9180
#include <cstdio>
#include <string>
#include <algorithm>
#include <iostream>
#define px(str) cout<<(str)<<endl,exit(0);
#define pe(str) return cout<<(str)<<endl,0;
#define IF(a,b,c) ((a)?(b):(c))
#define re(i,n) for(int i=0;i<(n);i++)
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define db(a) cout<<"debug:"<<(a)<<endl;
using namespace std;

int main(int argc, char** argv) {
	int n;
	cin >> n;
	int *a=new int[n+1];
	re(i, n) {
		cin >> a[i + 1];
		a[i + 1] /= 10;
	}
	int now = 1;
	int f = 0;
	while (now) {
		int m = a[now] + now, t = 0;
		for (int i = now + 1; i <= now + a[now]; i++) {
			if (i >= n) { f = 1; break; }
			if (m<a[i] + i) {
				m = a[i] + i;
				t = i;
			}
		}
		if (f)break;
		if (t == 0)pe("no");
		now = t;
	}

	now = n;
	f = 0;
	while (now) {
		int m = -a[now] + now, t = 0;
		for (int i = now - 1; i >= now - a[now]; i--) {
			if (i <= 1) { f = 1; break; }
			if (m>-a[i] + i) {
				m = -a[i] + i;
				t = i;
			}
		}
		if (f)break;
		if (t == 0)pe("no");
		now = t;
	}
	pe("yes");
	return 0;
}



Measured memory_bytes: 4272
#include<bits/stdc++.h>
#define lint long long
#define st first
#define nd second

using namespace std;

//int t;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	//cin>>t;
	//while(t--){}
	
	int n; cin>>n;
	
	lint cont=0;
	map<lint,lint> freq;
	for(lint i=1;i<=n;i++){
		lint x;
		cin>>x;
		cont += freq[i-x];
		freq[x+i]++;
	}
	cout<<cont<<"\n";
	return 0;	
}



Measured memory_bytes: 26236
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;

int main() {
  
  int a,b,c,d,x;
  string s,ss,sss;
  
  int ans = 0;
  string anss = "";
  
  cin >> s;
  
  int ab [] = {0 , 1 , 3 , 1 , 2 , 1 , 2 , 1 , 1 , 2 , 1 , 2 , 1};
  int result3 = std::max({a, b, c});
//--------------------------------------------------------------------------------

  if(s[1] == s[2] && s[0] == s[1] || s[1] == s[2] && s[3] == s[1]) anss = "Yes";
  else anss = "No";
  
  cout << anss << endl;

}

Measured memory_bytes: 256
#include <cmath>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
int main() {
	string s;
	cin >> s;
	ll zerocount = 0;
	ll onecount = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '1') {
			onecount++;
		}
		else {
			zerocount++;
		}
	}
	cout << 2 * min(onecount, zerocount) << endl;
	return 0;
}


Measured memory_bytes: 512
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
signed main(){
  init_io();
  ll h,w,k,ans=1000000000;
  cin >> h >> w >> k;
  string s[h];
  for(int i=0;i<h;i++){
    cin >> s[i];
  }
  for(ll i=0;i<(1ll<<(h-1));i++){
    ll cnt=0;
    vector<ll> x;
    for(ll j=0;j<h;j++){
      if((1ll<<j)&i){
        x.push_back(0);
        cnt++;
      }
    }
    x.push_back(0);
    for(int j=0;j<w;j++){
      bool div = false;
      ll idx=0,tsum=0;
      for(ll p=0;p<h;p++){
        x[idx] += (s[p][j]=='1');
        tsum += s[p][j]=='1';
        if(x[idx]>k) div = true;
        if(tsum>k) cnt = 1000000000;
        if((1ll<<p)&i){
          idx++;
          tsum = 0;
        }
      }
      if(div){
        cnt++;
        for(auto &p:x){
          p=0;
        }
        idx = 0;
        for(ll p=0;p<h;p++){
          x[idx] += (s[p][j]=='1');
          if((1ll<<p)&i){
            idx++;
            tsum = 0;
          }
        }
      }
    }
    ans = min(ans,cnt);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
float x1, y1, x2, y2, x3, y3, xp, yp;
main()
{
	while(~scanf("%f%f%f%f%f%f%f%f", &x1, &y1, &x2, &y2, &x3, &y3, &xp, &yp)) {
		float xg = (x1+x2+x3)/3;
		float yg = (y1+y2+y3)/3;

		puts(
			((x2-x1)*(yg-y1)-(y2-y1)*(xg-x1))*((x2-x1)*(yp-y1)-(y2-y1)*(xp-x1))>0 &&
			((x3-x2)*(yg-y2)-(y3-y2)*(xg-x2))*((x3-x2)*(yp-y2)-(y3-y2)*(xp-x2))>0 &&
			((x1-x3)*(yg-y3)-(y1-y3)*(xg-x3))*((x1-x3)*(yp-y3)-(y1-y3)*(xp-x3))>0

			? "YES" : "NO");
	}
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
    using namespace std;

    int main(){
      int N;
      cin >> N;
      int count=0;
      while(N>111*count){
        count++;
      }
      cout << 111*count << endl;
      return 0;}


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

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

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define fr(i,a,b) for(int i=a;i<b;i++)

void seive(ll n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
    for(ll i=2;i*i<=n;i++)
    {
        if(prime[i]==true)
        {
            for(ll j=i*i;j<=n;j+=i)
            {
                prime[j]=false;
            }
        }
    }

}




int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    char c;
    cin>>c;
    if(isupper(c))
    {
        cout<<"A";
    }
    else
    {
        cout<<"a";
    }
    
    
    
    return 0;
}


Measured memory_bytes: 3616
while True:
    m, f, r = map(int, input().split())
    if m == f == r == -1:
        break
    if m == -1 or f == -1:
        print('F')
        continue
    if m + f >= 80:
        print('A')
    if 65 <= m + f < 80:
        print('B')
    if 50 <= m + f < 65:
        print('C')
    if 30 <= m + f < 50:
        if r >= 50:
            print('C')
        else:
            print('D')
    if m + f < 30:
        print('F')

Measured memory_bytes: 7628
#include <bits/stdc++.h>
using namespace std;
class Tree{
  private:
  using ptr_t=Tree*;
  ptr_t a,c,g,t;
  bool x;
  public:
  Tree()
  : a(nullptr), c(nullptr), g(nullptr), t(nullptr){}
  void insert(string::iterator first, string::iterator last){
    if(first==last){
      x=true;
    } else{
      switch(*first){
        case 'A': xinsert(a,first,last); break;
        case 'C': xinsert(c,first,last); break;
        case 'G': xinsert(g,first,last); break;
        default:/*case 'T':*/ xinsert(t,first,last); break;
      }
    }
  }
  void xinsert(ptr_t &acgt, string::iterator first, string::iterator last){
    if(acgt==nullptr) acgt=new Tree;
    acgt->insert(++first,last);
  }
  bool find(string::iterator first, string::iterator last){
    if(first==last){
      return x;
    } else{
      switch(*first){
        case 'A': return xfind(a,first,last);
        case 'C': return xfind(c,first,last);
        case 'G': return xfind(g,first,last);
        default:/*case 'T':*/ return xfind(t,first,last);
      }
    }
  }
  bool xfind(ptr_t &acgt, string::iterator first, string::iterator last){
    if(acgt==nullptr) return false;
    return acgt->find(++first,last);
  }
};
int32_t main(){
  size_t n; cin>>n;
  Tree tree;
  string cmd,x;
  for(size_t i=0; i<n; ++i){
    cin>>cmd>>x;
    if(cmd.size()==6) tree.insert(begin(x),end(x));
    else cout<<(tree.find(begin(x),end(x))?"yes\n":"no\n");
  }
}



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

int main() {
    int a, b, k;
    cin >> a >> b >> k;
    for (int i = 0; i < k; i++) {
        if (i % 2) {
            b >>= 1;
            a += b;
        } else {
            a >>= 1;
            b += a;
        }
    }
    cout << a << ' ' << b << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
# define ll  long long
	typedef pair<int, int > pii;
	const int NN = 1e3+10;
 	int grid[NN][NN];
    bool visited[NN][NN];
 	int n,m,a,b,c,d;
 	int dx[]={-1,0,1,0};
 	int dy[]={0,1,0,-1};
 	bool isValid(int x, int y){
 		return x>=0 && x<n && y >=0 && y<m;
 	}
	int main() {

		#ifndef ONLINE_JUDGE
	        freopen("input.txt","r",stdin);
	        // freopen("output.txt","w",stdout);
	    #endif
	    ios::sync_with_stdio(false);
	    cin.tie(0);
	    cout.tie(0);
		cin>>n>>m>>a>>b>>c>>d;
		a--; b--; c--; d--;
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				char cc;
				cin>>cc;
				grid[i][j]=(cc=='.');
			}
		}

		deque<pair<pii,int> > q;
		q.push_back({{a,b},0});
		memset(visited, 0,sizeof(visited));
		while(!q.empty()){
		
			auto x=q.front();
			q.pop_front();
			pii k= x.first;
			if(!isValid(k.first, k.second)){
				continue;
			}
			if(k.first == c && k.second ==d){
				cout<<x.second<<endl;
				return 0;
			}
			if(visited[k.first][k.second]){
				continue;
			}
			else{
				visited[k.first][k.second]=1;
				for(int i=0;i<4;i++){
					int nx =k.first +dx[i];
					int ny= k.second+dy[i];
					if(isValid(nx,ny) && !visited[nx][ny]&& grid[nx][ny]){
						
			
					
						q.push_front({{nx,ny},x.second});
					}
				}

				for(int i=-2;i<=2;i++){
					for(int j=-2;j<=2;j++){
						int nx=k.first+i;
						int ny=k.second+j;
						if(isValid(nx,ny) && !visited[nx][ny]&& grid[nx][ny]){
							q.push_back({{nx,ny},x.second+1});
						}
					}
				}
			}
		}
		cout<<-1<<endl;


		
	}

	


Measured memory_bytes: 9188
#include<iostream>
#include<map>
#include<vector>
 
using namespace std;
void dfs(const vector<vector<long>>& graph, const map<pair<long, long>,long>& dist,vector<int>& color,long now, long from, long res) {
	
    color[now] = res % 2;
 
	for (auto e : graph[now]) {
		if (e == from) continue;
 
		dfs(graph, dist,color, e, now, res + dist.at(make_pair(now, e)));
	}
}
 
int main() {
	long N; cin >> N;
 
	vector<vector<long>> graph(N);
	map<pair<long, long>, long> dist;
	vector<int> color(N);
 
	for (int i = 0; i < N - 1; ++i) {//入力。
		long a, b, d; cin >> a >> b >> d; a--; b--;
		graph[a].push_back(b);
		graph[b].push_back(a);
		dist.insert(make_pair(make_pair(a, b), d));
		dist.insert(make_pair(make_pair(b, a), d));
	}
 
	//頂点0を根にする
	color[0] = 0;
 
	dfs(graph, dist, color, 0, -1, 0);
 
	for (int i = 0; i < N; i++) cout << color[i] << endl;
}

Measured memory_bytes: 22144
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;



void main() {
    readln.split.retro.joiner.writeln;
}














void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


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

#define big ((long long)(1e9)+7)

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main()
{
  ll n;
  cin >> n;
  vector<pair<int ,int > > A;
  for(int i = 0;i < n;i++)
  {
    int a;
    cin >> a;
    A.push_back(make_pair(a,i+1));
  }
  sort(A.begin(),A.end());

  // for(int i = 0;i < n;i++)
  // { 
  //   cout << A[i].first << " " << A[i].second << endl;
  // }

  for(int i = 0;i < n;i++)
  { 
    cout << A[i].second << " ";
  }
}


Measured memory_bytes: 1780
#include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define dump(x) cout<<" "<<#x<<"="<<x
#define pdump(p) cout<<" "<<#p<<"=("<<p.fst<<","<<p.snd<<")"
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std; using lint = long long; using ld = long double;
using pii = pair<int, int>; using pll = pair<lint, lint>;

int main(void) {
    int n;
    cin >> n;
    vector<int> p(n);
    repeat (i, n) cin >> p[i];
    sort(p.begin(), p.end(), greater<int>());
    int ans = 0;
    repeat (i, n) {
        if (i == 0) ans += (p[0] / 2);
        else ans += p[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
const int mod = 1e9+7;

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for(int i = 0; i < N; ++i) cin >> A[i];
  vector<int> dp(K+1,0);
  dp[0] = 1;
  for(int i = 0; i < N; ++i){
    vector<int> dp_(K+1,0);
    int s = 0;
    for(int j = 0; j <= K; ++j){
      s += dp[j], s %= mod;
      if(j > A[i]) s += mod - dp[j-A[i]-1], s %= mod;
      dp_[j] += s, dp_[j] %= mod;
    }
    dp = dp_;
  }
  cout << dp[K] << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;

int main() {
    int x;
    cin >> x;
    int happy = 0;
    happy += (x / 500) * 1000;
    happy += ((x % 500) / 5) * 5;
    cout << happy << endl;
}

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

int main()
{
    string s;
    cin >> s;
    int n = s.length();
    int l1 = (n - 1) / 2;
    int l2 = (n + 3) / 2;
    bool flag = true;
    for (int i = 0; i < n / 2; i++)
    {
        if (s[i] != s[n - i - 1])
        {
            flag = false;
            break;
        }
    }
    if (flag)
    {
        for (int i = 0; i < l1 / 2; i++)
        {
            if (s[i] != s[l1 - i - 1])
            {
                flag = false;
                break;
            }
        }
    }
    if (flag)
    {
        for (int i = l2 - 1; i < (n+1)/ 2 + l1/2; i++)
        {
            if (s[i] != s[n - i - 1])
            {
                flag = false;
                break;
            }
        }
    }
    if (flag)
        cout << "Yes";
    else
        cout << "No";
}


Measured memory_bytes: 256
<?php
list($a,$b,$C)=explode(' ',trim(fgets(STDIN)));

$C=pi()*$C/180;

$h=$b*sin($C);
$c=sqrt(pow($a-$b*cos($C),2)+pow($h,2));

echo $a*$h/2,PHP_EOL,$a+$b+$c,PHP_EOL,$h;

Measured memory_bytes: 15608
#!/usr/bin/perl
use Data::Dumper;

my @d = ();
$#d = 1000000;

my ($k) = map { $_ - 0 } split(/\s+/,<STDIN>);

if( $k % 2 == 0 ){
  print "-1\n";  exit(0);
}

if( $k == 1 or $k == 7 ){
  print "1\n"; exit(0);
}

my $j = 7;
my $s = 0;
for(my $i=0;$i<1000000;$i++){
  $s = ( $s + $j ) % $k;
  if( $s == 0 ){
    my $ans = $i + 1;
    print "$ans\n";
    exit(0);
  }
  $j = ( $j * 10 ) % $k;
}

print "-1\n";




Measured memory_bytes: 14076
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
[k,q]=i2()
d=i2()
for i in range(q):
  [n,x,m]=i2()
  di=[]
  dz=[]
  for i in d:
    di.append(i%m)
    if i%m==0:
       dz.append(1)
    else:
       dz.append(0)
  x=((n-1)//k)*sum(di[:k])+x%m
  if (n-1)%k:
    x+=sum(di[:(n-1)%k])
  ans=n-1-x//m-((n-1)//k)*sum(dz[:k])
  if (n-1)%k:
   ans-=sum(dz[:(n-1)%k])
  print(ans)

Measured memory_bytes: 96988
#include<map>
#include<set>
#include<cmath>
#include<ctime>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define lb(x) x&-x
#define il inline
#define ll long long
#define llu unsigned long long
#define mem(x) memset(x,0,sizeof(x))
#define mem3(x) memset(x,0x3f,sizeof(x))
#define ccA() puts("耐心冷静查代码")
#define cc() puts("谁知盘中餐，粒粒皆辛苦")
#define fo(i,a,b) for(register int i=a;i<=b;++i)
#define fd(i,a,b) for(register int i=a;i>=b;--i)
#define fk(i,j) for(register int i=fir[j];i;i=nxt[i])
#define fv(i,q) for(int i=0;i<q.size();i++)
using namespace std;
inline ll read(){
    ll x=0,f=1;char c;
    for(c=getchar();c<'0'||c>'9';f=((c=='-')?-1:f),c=getchar());
    for(;c>='0'&&c<='9';x=x*10+c-'0',c=getchar());
    return x*f;
}
inline void write(ll a){
    if(a==0){putchar('0');return;}
    if(a<0)putchar('-'),a=-a;
    char c1[120];
    ll h=0;
    while(a)c1[++h]=a%10+'0',a/=10;
    fd(i,h,1)putchar(c1[i]);
    return;
}
inline void write_(ll a){write(a);putchar(' ');}
inline void writeln(ll a){write(a);putchar('\n');}
//-----------------------------------------------------------------
const int N=1e2;
int n,a[N][N],d,ans,us,pd;

int main(){
	n=read(),d=read();
	fo(i,1,n){
		fo(j,1,d){
			a[i][j]=read();
		}
	}
	fo(i,1,n){
		fo(j,i+1,n){
			us=0;
			fo(k,1,d){
				us+=(a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
			}
			pd=(int)sqrt(us);
//			write_(i),write_(j),write_(us),writeln(pd);
			if(pd*pd==us)ans++;
		}
	}
	write(ans);
	return 0;
}

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

int main() {
  int h, w;
  cin >> h >> w;

  vector<string> a(h);

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


  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      
      if (a[i][j] == '#') {
        cout << '#';
        if (j == w - 1) cout << endl;
        continue;
      }

      int cnt = 0;
      for (int x = -1; x <= 1; x++) {
        for (int y = -1; y <= 1; y++) {
          if ((i + x) < 0 || (i + x) >= h || (j + y) < 0 || (j + y) >= w) continue; 
          if (a[i + x][j + y] == '#') cnt++;
         }
       }

      cout << cnt;
      if (j == w - 1) cout << endl;
    }
  }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rem(i,m,n) for(int i=m; i<(n); i++)
#define eps (1e-7)
#define inf (1e9)
#define pi (acos(-1))
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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

    ll x, y;
    cin >> x >> y;
    int count = 0;
    while(x <= y)
    {
        count++;
        x *= 2;
    }
    cout << count << "\n";

    return 0;
}

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

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

int main()
{
    int x1, y1, x2, y2, x3, y3, x4, y4;
    cin >> x1 >> y1 >> x2 >> y2;


    x3 = x2 + (y1 - y2);
    y3 = y2 + (x2 - x1);
    x4 = x3 + (y2 - y3);
    y4 = y3 + (x3 - x2);

    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;

    return 0;
}

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

const double PI = 3.14159265358979323846;
//using namespace boost::multiprecision;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 1e15;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<string, vector<string>, greater<string> > PQ_ASK;

struct Triangle {
    int parent;
    vector<int> children;
};

class Tree {
    vector<vector<int>> edges;
public:
    Tree(int n) : edges(n) {}

    void edge(int i, int j) {
        edges[i].push_back(j);
        edges[j].push_back(i);
    }

    void root(int r, vector<Triangle> &leafs) {
        queue<int> vs;
        vs.push(r);
        vector<bool> check(edges.size(), false);
        check[r] = true;
        while (!vs.empty()) {
            int k = vs.front();
            Triangle triangle;
            triangle.parent = k;

            for (int i : edges[k]) {
                if (check[i]) continue;
                check[i] = true;
                triangle.children.push_back(i);
                vs.push(i);
            }
            vs.pop();
            leafs.push_back(triangle);
        }
//        reverse(leafs.begin(), leafs.end());
    }
};

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

    Tree tree(n);

    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        tree.edge(a, b);
    }

    vector<ll> counter(n, 0);
    rep(i, q) {
        int p;
        ll x;
        cin >> p >> x;
        p--;
        counter[p] += x;
    }

    vector<Triangle> leafs;
    tree.root(0, leafs);

    for (Triangle &t : leafs) {
        for (int child : t.children) {
            counter[child] += counter[t.parent];
        }
    }

    for (ll c : counter) cout << c << ' ';

}


Measured memory_bytes: 29160