akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <deque>
typedef long long ll;
#define rep(i,n) for(int i = 0;i<n;++i)
#define repnc(bit,k,n) for (int bit = (1<<k)-1;bit < (1<<n); bit = next_combination(bit))
#define repi(itr,vec) for(auto itr = vec.begin();itr!=vec.end();++itr)
using namespace std;
using Graph = vector<vector<int> >;

/* next combination */
int next_combination(int sub) {
  int x = sub & -sub, y = sub + x;
  return (((sub & ~y) / x) >> 1) | y;
}

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

void initialize(vector<vector<int> > &dep, int r, int c){
  dep = vector<vector<int> >(r);
  rep(y,r){
    rep(x,c){
      dep[y].push_back(-1);
    }
  }
  return;
}
bool out_of_area(int x, int y, int r, int c){
  return(x<0||x>=c||y<0||y>=r);
}


int main(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
  int r,c;cin >> r >> c;
  vector<vector<char> >map(r);
  vector<vector<int> >dep(r);
  deque<vector<int> >que;
  int S[2];cin>>S[1]>>S[0];S[0]--;S[1]--;
  int G[2];cin>>G[1]>>G[0];G[0]--;G[1]--;
  rep(y,r){
    rep(x,c){
      char temp;
      cin >> temp;
      map[y].push_back(temp);
    }
  }
  int ans=0;
  initialize(dep, r, c);
  dep[S[1]][S[0]]=0;
  que.push_back({S[0],S[1]});
  while(!que.empty()){
    const vector<int> cur = que.front();
    que.pop_front();
    for(int ddx = -2; ddx<=2;++ddx){
      for(int ddy = -2; ddy<=2;++ddy){
        const int xx = cur[0]+ddx;
        const int yy = cur[1]+ddy;
        if(out_of_area(xx,yy,r,c))continue;
        if(dep[yy][xx]!=-1)continue;
        if(map[yy][xx]=='#')continue;
        dep[yy][xx]=dep[cur[1]][cur[0]]+1;
        que.push_back({xx,yy});
      }
    }
    rep(i,4){
      const int x = cur[0]+dx[i];
      const int y = cur[1]+dy[i];
      if(out_of_area(x,y,r,c))continue;
      if(map[y][x]=='#')continue;
      if(dep[y][x]<=dep[cur[1]][cur[0]])continue;
      dep[y][x]=dep[cur[1]][cur[0]];
      que.push_front({x,y});

    }
  }
  ans = dep[G[1]][G[0]];
  cout << ans<< '\n';
  return 0;
}

Measured memory_bytes: 9244
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
char ch[100];
int main(){
	scanf("%s", ch+1);
	if(ch[1] == 'Y' && ch[2] == 'A' && ch[3] == 'K' && ch[4] == 'I')
		printf("Yes");
	else printf("No");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ll long long
#define inf 0x3f3f3f3f
#define fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N = 3e3+5;
const ll mod =   1e9+7;
ll n;string s;
ll dp[N][N],sum[N][N];
int main()
{  fast
 cin>>n;
 cin>>s;
dp[0][0]=1;
for(int i=1;i<=n;i++)
sum[0][i]=1;
for(int i=0;i<n-1;i++){
	for(int j=0;j<=i+1;j++){
		if(s[i]=='>'){
			dp[i+1][j]=((sum[i][i+1]-sum[i][j])%mod+mod)%mod;
		}
		else{
			dp[i+1][j]=sum[i][j];
		}
		sum[i+1][j+1]=(sum[i+1][j]+dp[i+1][j])%mod;
	}
}
cout<<sum[n-1][n];
}

Measured memory_bytes: 95940
#include<bits/stdc++.h>
using ll=long long;
using namespace std;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
ll MM = 1000000000; ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
ll GCD(ll x, ll y){ if(y == 0) return x; else return GCD(y, x % y);}
ll LCM(ll x, ll y){ return x / GCD(x, y) * y;}
int dh[4] = {-1, 0, 0, 1};
int dw[4] = {0, -1, 1, 0}; 
using P = pair<int, int>;
const double pi = acos(-1.0);

using Graph = vector<vector<ll>>;

struct UnionFind{
    vector<int> par;
 
    UnionFind(int n) : par(n, -1){ }
    void init(int n){ par.assign(n, -1); }
 
    int root(int x){
        if(par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
 
    bool issame(int x, int y){
        return root(x) == root(y);
    }
 
    bool unite(int x, int y){
        x = root(x); y = root(y);
        if(x == y) return false;
        if(par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
 
    int size(int x){
        return -par[root(x)];
    }
};

int main(){
  ll n,m;
  cin>>n>>m;
  ll a,b;
  UnionFind uf(n);
  rep(i,m){
    cin>>a>>b;
    a--;b--;
    uf.unite(a,b);
  }
  vector<ll>siz(n);
  rep(i,n){
    siz[uf.root(i)]++;
  }
  sort(all(siz));
  reverse(all(siz));
  cout<<siz[0]<<endl;
    
    
    
  return 0;
}


Measured memory_bytes: 5548
#include <iostream>
#include <vector>

using namespace std;

int main(){
    int n, m;
    int sum = 0;
    cin >> n >> m;
    vector<int> A(m);
    for(int i=0;i<m;++i){
        cin >> A[i];
        sum += A[i];
    } 

    if(n-sum<0) cout << "-1" << endl;
    else cout << n-sum << endl;

    return 0;


} 

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

#define fast() {ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
#define o(a) { cout << #a << ":" << (a) <<" ";}
#define ov(a) { cout << "["; \
	for(int i = 0; i < (a).size(); ++i){ \
		cout << i <<":" << a[i] <<" "; \
		if(i % 10 == 9) cout <<"\n"; \
		} \
	cout << "]"; \
}
#define ovv(a) { cout << "["; \
	for(int i = 0; i < a.size(); ++i){ \
		for(int j = 0; j < a[i].size(); ++j){ \
			cout << "(" << i <<"," <<j <<")" <<":" << a[i][j] <<" "; \
		} \
		cout << "\n"; \
	} \
	cout << "]"; \
}
#define op(a) { cout <<"[" << #a << ".fi:"<<a.first; \
					cout << " "<< #a << ".se:" << a.second <<"]"; }

#define ll long long
const int mod = 1e9 + 7;
const int nax = 1e5 + 5;


int main()
{
	fast();
	string s;
	cin >> s;
	for(int i = 0; i < s.length(); ++i){
		if(s[i] == '7')
			return cout <<"Yes", 0;
	}
	cout <<"No";

}



Measured memory_bytes: 3612
N=int(input())
a=list(map(int,input().split()))
money=1000
tip=0
buy=[]
k=0
flag=0
while N-1>k:
    if flag==0:
        for i in range(k,N-1):
            if a[i]<a[i+1]:
                tip=money//a[i]
                money-=a[i]*tip
                buy.append(a[i])
                k=i
                flag=1
                break
            k=i+1
    elif flag==1:
        for i in range(k,N-1):
            if a[i]>a[i+1]:
                money+=tip*a[i]
                tip=0
                buy.pop(0)
                k=i
                flag=0
                break
            k=i+1
print(money+tip*a[N-1])


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

int main() {
    int N, M, X;
    cin >> N >> M >> X;
    vector<int> C(N);
    vector<vector<int>> skill(N, vector<int>(M, 0));
    int min_cost = 0;
    for(int i=0;i<N;i++){
        cin >> C.at(i);
        min_cost += C[i];
        for(int j=0;j<M;j++){
            cin >> skill[i][j];
        }
    }
    // check able
    for(int i =0;i<M;i++){
        int s = 0;
        for(int j=0;j<N;j++){
            s += skill[j][i];
        }
        if(s<X){
            cout << -1 << endl;
            return 0;
        }
    }
    for(int b=0;b<(1<<12);b++){
        // check
        bool ok = true;
        int cost = 0;
        for(int i =0;i<N;i++){
            if((b>>i&1)==1) cost += C[i];
        }
        for(int i =0;i<M;i++){
            int s = 0;
            for(int j=0;j<N;j++){
                if((b>>j&1)==1){
                    s += skill[j][i];
                }
            }
            if(s<X) ok = false;
        }
        if(ok) min_cost = min(min_cost, cost);
    }
    cout << min_cost << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=1; i<=(int)(n); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    int N;
    cin>>N;
    vi X(N);
    rep(i,N) cin>>X[i];
    vi v(N);
    rep(i,N) v[i]=X[i];
    sort(all(v));
    int a=v[N/2-1];
    int b=v[N/2];
    rep(i,N) {
        if(X[i]<=a) cout<<b<<endl;
        else cout<<a<<endl;
    }
}

Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <string>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <queue>
#include <set>
using namespace std;

int main()
{
	int n;
	cin >> n;
	cout << (n >= 30 ? "Yes" : "No");
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
typedef long long ll;
#define SZ(x) ((int)(x).size())

using namespace std;



string zero_fill(int number, int n) {

	stringstream ss;
	ss << setw(n) << setfill('0') << number;
	return ss.str();
}

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

	vector<pair<pair<int, ll>,int>> P(M); //pair<pair<prefecture, year>, index>
	for (int i = 0; i < M; i++)
	{
		cin >> P[i].first.first >> P[i].first.second;
		P[i].second = i;
	}
	sort(P.begin(), P.end()); //昇順ソート(左側にある要素を優先してソートしてくれる)

	//for (int i = 0; i < M; i++)
	//{
	//	printf("[p, y, i] = [%d, %d, %d]\n", P[i].first.first, P[i].first.second, P[i].second);
	//}

	vector<string> ans(M); 
	int previous_prefecture = P[0].first.first; //前回処理した県の初期値
	int number = 1; //市が誕生した順番の初期値
	for (int i = 0; i < M; i++)
	{
		int prefecture = P[i].first.first;
		//printf("[now, prev] = [%d, %d]\n",prefecture, previous_prefecture);

		//前回処理した県とこれから処理する県が異なるときは市が誕生した順番を初期化
		if (prefecture != previous_prefecture) {
			number = 1;
		}

		//0埋め
		string first = zero_fill(prefecture, 6);
		string last  = zero_fill(number    , 6);

		//答えの配列にIDを入れる
		int index = P[i].second; //ソート前のインデックスを取得
		ans[index] = first + last;

		//次の処理のために更新
		number++; //市が誕生した順番
		previous_prefecture = prefecture; //県の番号
	}


	for (int i = 0; i < M; i++)
	{
		cout << ans[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 11136
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

string n;
int k;
ll le[100][5];
ll nongt[100][5];

int main() {
    fastio();

    cin >> n >> k;

    int m = n.size();

    le[0][0] = n[0] != '0';
    le[0][1] = max(0, n[0] - '0' - 1);
    nongt[0][1] = 1;

    forn1(i, m - 1) {
        forn(j, k + 1) {
            // use 0
            le[i][j] += le[i - 1][j] + (n[i] == '0' ? 0 : nongt[i - 1][j]);
            // use 1-9
            le[i][j + 1] += le[i - 1][j] * 9;
            if (n[i] > '0')
                le[i][j + 1] += nongt[i - 1][j] * (n[i] - '0' - 1);

            if (n[i] == '0') {
                nongt[i][j] += nongt[i - 1][j];
            } else {
                nongt[i][j + 1] += nongt[i - 1][j];
            }
        }
    }

    cout << le[m - 1][k] + nongt[m - 1][k] << endl;

    return 0;
}

Measured memory_bytes: 256
import sys

n, *H = map(int, sys.stdin.read().split())

def main():
    res = 0
    cnt = 0
    prev = 0
    for h in H + [float('inf')]:
        if h <= prev:
            cnt += 1
        else:
            res = max(res, cnt)
            cnt = 0
        prev = h
    return res
    
if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 14092
#include<bits/stdc++.h>
using namespace std;
int main() {
	bool A=0;
	char ch,ch_;
	cin>>ch;
	ch_=ch;
	while((cin>>ch)!=0) {
		if(ch_=='A'&&ch=='C') {
			cout<<"Yes";
			return 0;
		}
		ch_=ch;
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int len = s.length();
    int i,j=0;
    for(i=0;i<len;i++)
    {
        if(s[i]>='a'&&s[i]<='z')
        {
            cout << s[i];
            j++;

        }
        if(j==3)break;
    }
}


Measured memory_bytes: 3620
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, k = map(int, input().split())
    A = list(map(int, input().split()))
    res = 1
    if n == k:
        for a in A:
            res = (res * a) % mod
        print(res)
        exit()

    P, M = [], []
    for a in A:
        P.append(a) if a >= 0 else M.append(a)

    if len(P) == n:
        A.sort(reverse=True)
        for i in range(k):
            res = (res * A[i]) % mod
    elif len(M) == n:
        A.sort(reverse=True) if k % 2 else A.sort()
        for i in range(k):
            res = (res * A[i]) % mod
    else:
        P.sort(reverse=True)
        M.sort()
        B = []
        if k % 2:
            k -= 1
            b = P.pop(0)
            B.append(b)
            res = (res * b) % mod
        for i in range(0, len(P), 2):
            if i + 1 < len(P):
                B.append(P[i] * P[i + 1])
        for j in range(0, len(M), 2):
            if j + 1 < len(M):
                B.append(M[j] * M[j + 1])
        B.sort(reverse=True)
        for i in range(k // 2):
            res = (res * B[i]) % mod

    print(res)

if __name__ == '__main__':
    resolve()


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

struct Graph {
    enum Color {WHITE, GRAY, BLACK};
    vector<vector<int>> adj;
    vector<Color> color;
    vector<int> tstart;
    vector<int> tend;
    int time;
    Graph(int n) {
        adj.assign(n, vector<int>());
        color.assign(n, WHITE);
        tstart.assign(n, 0);
        tend.assign(n, 0);
        time = 0;
    }
};

void dfs(Graph& g, int u)
{
    g.color[u] = Graph::GRAY;
    g.tstart[u] = ++g.time;
    for (auto v : g.adj[u]) {
        if (g.color[v] == Graph::WHITE) {
            dfs(g, v);
        }
    }
    g.tend[u] = ++g.time;
    g.color[u] = Graph::BLACK;
}

int main()
{
    int n;
    cin >> n;
    Graph g(n);
    for (int i = 0; i < n; i++) {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            int v;
            cin >> v;
            g.adj[u - 1].push_back(v - 1);
        }
    }

    for (int i = 0; i < n; i++) {
        if (g.color[i] == Graph::WHITE) {
            dfs(g, i);
        }
    }

    for (int i = 0; i < n; i++) {
        cout << (i + 1) << " " << g.tstart[i] << " " << g.tend[i] << endl;
    }
}



Measured memory_bytes: 3144
program main
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int64):: s,i,j,n,md=1000000007,ans
    integer(int64), allocatable:: a(:,:)

    read*, s
    allocate(a(s,0:s/3))
    a(:,0) = 0
    a(1,:) = 1

    i=1
    ans=0
    do while(i*3 <= s)
        do j=2,s
            a(j,i) = mod(a(j-1,i)+a(j,i-1),md)
        end do
        n = s-3*i+1
        ans=mod(ans+a(n,i),md)
        i=i+1
    end do
    print'(i0)', ans
end program main

Measured memory_bytes: 13160
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn solve(ps: Vec<usize>) -> &'static str {
    let mut count = 0;
    for i in 1..ps.len() + 1 {
        if ps[i-1] != i {
            count += 1;
        }
    }
    if count == 2 || count == 0{
        "YES"
    } else {
        "NO"
    }


}

fn main() {
    input!{
        n: usize,
        ps: [usize; n],
    }
    println!("{}", solve(ps));
}


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

using namespace std;

const int INF=1000000;

int main()
{
    int pri[INF];
    int res[INF];
    for(int i=0;i<INF;i++)
        pri[i]=0;
    for(int i=2;i*i<INF;i++)
    {
        if(pri[i]==0)
        {
            for(int j=i*2;j<INF;j+=i)
            {
                pri[j]=1;
            }
        }
    }
    int n=0;
    for(int i=2;i<INF;i++)
    {
        if(pri[i]==0)
            n++;
        res[i]=n;
    }
    int C;
    while(cin>>C)
    {
        cout<<res[C]<<endl;
    }
}

Measured memory_bytes: 8968
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<int, int>
#define F first
//#define S second
#define mod 1000000007
#define MOD 998244353
#define INF 40000000000000000
int dx8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int dy8[8] = {1, 1, 1, 0, -1, -1, -1, 0};
int dx4[4] = {-1, 0, 1, 0};
int dy4[4] = {0, -1, 0, 1};
template <class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}

int mod_pow(int x, int n, int mm) {
    int res = 1;
    while(n > 0) {
        if(n & 1) res = res * x % mm;
        x = x * x % mm;
        n >>= 1;
    }
    return res;
}
int extgcd(int a, int b, int &x, int &y) {
    int d = a;
    if(b != 0) {
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    } else {
        x = 1;
        y = 0;
    }
    return d;
}
int mod_inverse(int a, int mm) {
    int x, y;
    extgcd(a, mm, x, y);
    return (mm + x % mm) % mm;
}
signed main() {
    int N;
    cin >> N;
    int A[N];
    rep(i, N) cin >> A[i];
    if(N % 2 == 0) {
        vector<vector<int>> dp(2, vector<int>(N, -INF));
        dp[0][0] = A[0];
        dp[1][1] = A[1];
        for(int i = 1; i < N; i++) {
            if(i > 1) chmax(dp[0][i], dp[0][i - 2] + A[i]);
            if(i > 1) chmax(dp[1][i], dp[1][i - 2] + A[i]);
            if(i > 2) chmax(dp[1][i], dp[0][i - 3] + A[i]);
            chmax(dp[1][i], dp[0][i - 1]);
        }
        cout << max(dp[1][N - 1], dp[0][N - 1]) << endl;

    } else {
        vector<vector<int>> dp(3, vector<int>(N, -INF));
        dp[0][0] = A[0];
        dp[1][1] = A[1];
        dp[2][2] = A[2];
        for(int i = 1; i < N; i++) {
            if(i > 1) chmax(dp[0][i], dp[0][i - 2] + A[i]);
            if(i > 1) chmax(dp[1][i], dp[1][i - 2] + A[i]);
            if(i > 2) chmax(dp[1][i], dp[0][i - 3] + A[i]);
            chmax(dp[1][i], dp[0][i - 1]);
            if(i > 1) chmax(dp[2][i], dp[2][i - 2] + A[i]);
            if(i > 2) chmax(dp[2][i], dp[1][i - 3] + A[i]);
            if(i > 3) chmax(dp[2][i], dp[0][i - 3] + A[i]);
            chmax(dp[2][i], dp[1][i - 1]);
        }
        cout << max(dp[0][N - 1], max(dp[1][N - 1], dp[2][N - 1]));
    }
}


Measured memory_bytes: 11124
#include<iostream>
#include<cstdlib>

#include<cmath>
#include<map>
#include<string>
#include<vector>
#include<algorithm> 

using namespace std;

# define p(s) std::cout << s << endl;
# define printIf(j,s1,s2) std::cout << (j ? s1 : s2) << endl;
# define YES(j) std::cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define rep(n,i) for(i = 0 ; i < n ; i++)

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

    int res[52][52]={};
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            char s;cin >> s;
            if(s=='#') {
                res[i-1][j-1]++;
                res[i-1][j]++;
                res[i-1][j+1]++;
                res[i][j-1]++;
                res[i][j]=-51;
                res[i][j+1]++;
                res[i+1][j-1]++;
                res[i+1][j]++;
                res[i+1][j+1]++;
            }
        }
    }
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            int a = res[i][j];
            if(a<0) cout << "#";
            else cout << a;
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int X; cin >> X;
    long long suma = 0;
    while(X >= 500){
        X -= 500;
        suma += 1000;
    }
    while(X >= 5){
        X -= 5;
        suma += 5;
    }
    cout << suma;
    return 0;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;


int dp[81][81][26005];

class EBalancedPath {
public:
    static constexpr int kStressIterations = 0;

    static void generateTest(std::ostream& test) {
    }

    void solve(std::istream& cin, std::ostream& cout) {
        int h, w;
        cin >> h >> w;
        vector<vector<int>> a(h, vector<int>(w));
        vector<vector<int>> b(h, vector<int>(w));
        vector<vector<int>> d(h, vector<int>(w));
        REP(i, h) REP(j, w) cin >> a[i][j];
        REP(i, h) REP(j, w) cin >> b[i][j];

        REP(i, h) {
            REP(j, w) {
                d[i][j] = abs(a[i][j] - b[i][j]);
            }
        }

        CLR(dp, 0);
        int offset = 13000;
        dp[0][1][offset]++;
        dp[1][0][offset]++;
        FOR(i, 1, h) {
            FOR(j, 1, w) {
                REP(k, 26000) {
                    if (dp[i - 1][j][k] > 0 || dp[i][j - 1][k] > 0) {
                        int nk = min(26000, k + d[i - 1][j - 1]);
                        dp[i][j][nk] = 1;
                        int nk2 = max(0, k - d[i - 1][j - 1]);
                        dp[i][j][nk2] = 1;
                    }
                }
            }
        }

        int res = INF;
        REP(k, 26000) {
            if (dp[h][w][k]) {
                res = min(res, abs(k - offset));
            }
        }
        cout << res << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    EBalancedPath solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 666880
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<unordered_map>
#include<unordered_set>
#include<cctype>
#include<iomanip>
#include<limits>
#include<bitset>
 
using namespace std;
typedef long long int ll; typedef pair<int, int> P; typedef unsigned long long int ull;
const ll mod = 1e9 + 7;
const int inf = 1e9 + 7;
const ll linf = 1LL << 60;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define REP(i,m,n) for(int i=(m);i<(int)n;i++)
#define all(a) (a).begin(),(a).end()
#define allg(a) (a).begin(),(a).end(),greater<>()
#define SUM(a) accumulate((a).begin(),(a).end(),0)
#define d10 std::setprecision(10)
#define d20 std::setprecision(20)
#define sz size()
#define vec vector<int>
using str = string;
const double PI = 3.14159265359;
ll gcd(ll a, ll b) { ll t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
int gcd(int a, int b) { int t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
ll recfact(ll start, ll n) {
	ll i;
	if (n <= 16) {
		ll r = start;
		for (i = start + 1; i < start + n; i++) r = r * i % mod;
		return r % mod;
	}
	i = n / 2;
	return recfact(start, i) % mod * recfact(start + i, n - i) % mod;
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}
ll fct(ll n) { return recfact(1, n); }
ll ncm(ll n, ll m) {
	if (n < m)return 0;
	ll x = (fct(n) % mod / (fct(m) * fct(n - m)) % mod) % mod;
	return x;
}
std::string sreverse(string str, int firstItr, int secondItr) {
	if (firstItr < 0 || secondItr>int(str.size() - 1))return str;
	while (firstItr < secondItr) {
		swap(str[firstItr], str[secondItr]);
		firstItr++; secondItr--;
	}
	return str;
}
std::string RunLengthEncoding(std::string str) {
	int itr = 0; std::string res;
	while (itr < int(str.size())) {
		char tmp = str[itr++];
		int length = 1;
		while (itr <int(str.size()) && str[itr] == tmp) { ++itr; ++length; }
		res.push_back(tmp);
		res += to_string(length);
	}
	return res;
}
std::string split(std::string str, size_t first_itr, bool isFront) {
	if (first_itr < 0 || first_itr > str.size()) {
		return str;
	}
	else {
		if (isFront) {
			std::string tmp;
			for (size_t i = 0; i < first_itr; i++) {
				tmp.push_back(str.at(i));
			}
			return tmp;
		}
		else {
			std::string tmp;
			for (size_t i = first_itr; i < str.size(); i++) {
				tmp.push_back(str.at(i));
			}
			return tmp;
		}
	}
}
 
 
bool dfs(int depth, int now) {
	/*if (depth == n)return !now;
	for (int i = 0; i < k; i++) {
		if (dfs(depth + 1, now ^ t[depth][i]))return true;
	}
	/**/
	return false;
}
 
 
 
int main() {
	int k, x; cin >> k >> x;
	if (k * 500 >= x)cout << "Yes" << endl;
	else cout << "No" << endl;
 
	return 0;
}

Measured memory_bytes: 256
//0103
#include<string.h>
#include<stdio.h>
int main()
{
	int n,op,f,se,t,r=0;
	char in[16];
	scanf("%d",&n);
	while(n--){
		r=0;
		op=0;
		f=0;
		se=0;
		t=0;
		while(op<3){
			scanf("%s",in);
			if(in[1] == 'I'){
				r+=t;
				t=se;
				se=f;
				f=1;
			}else if(in[1] == 'U'){
				op++;
			}else{
				r+=f+se+t+1;
				f=0;
				se=0;
				t=0;
			}
		}
		printf("%d\n",r);
	}
	return 0;
}

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

int main() {
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
  int N;
  cin>>N;
  int minus=0;
  int64_t answer=0;
  vector<int> a(N),b(N);
  rep(i,N){
    cin>>a[i];
    b[i]=max(a[i],-a[i]);
    answer+=b[i];
    if(a[i]<0)
      minus++;
  }
  sort(b.begin(),b.end());
  if(minus%2==1)
    answer-=2*b[0];
  cout<<answer;
}

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

int compar(const int *val1, const int *val2) {//昇順並び替え
    if ( *val1 < *val2 ) {
        return -1;
    } else if ( *val1 == * val2 ) {
        return 0;
    } else {
        return 1;
    }
}

int main(){
  int n;
  scanf("%d",&n);
  int d[n];
  for(int i = 0; i < n; ++i) scanf("%d",&d[i]);
  qsort(d, n, sizeof(int),(int (*)(const void *, const void *))compar);
  int answer = 1;
  for(int i = 0; i < n - 1; ++i){
    if(d[i+1] > d[i]) answer += 1;
  }
  printf("%d\n",answer);
  return 0;
}

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


int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<bool>> path(n, vector<bool>(n, false));//iとjが繋がってるならpath[i][j]=path[j][i]=true;
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    path[a][b] = path[b][a] =true;
  }
  vector<int> a(n);
  rep(i, n) a[i] = i;
  
  int ans = 0;
  do {
    if (a[0] != 0) continue;
    bool flag = true;
    rep(i, n-1) {
      if (!path[a[i]][a[i+1]])  {
        flag = false;
        break;
      }
    }
    
    if (flag) ans++;
    
  } while (next_permutation(all(a)));
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
a=sorted(list(map(int,input().split())))
d=[]
for _ in range(m):
  d+=[list(map(int,input().split()))[::-1]]
d=sorted(d)[::-1]
j=0
ans=0
flag=1
for i in a:
  if flag and d[j][0]>i:
    ans+=d[j][0]
    d[j][1]-=1
    if d[j][1]==0:j+=1
    if j==m:flag=0
  else:ans+=i
print(ans)

Measured memory_bytes: 97328
S=input()

ans = 0
temp_a = 0
prev_b = False
  
for s in S:
  if prev_b and s !='C' or prev_b==False and s=='C':
    temp_a = 0
    
  if s=='A' or s=='C':
    prev_b = False
  else:
    prev_b = True

  if s=='A':
    temp_a += 1
  elif s=='B':
    pass
  elif s=='C':
    ans += temp_a
      
print(ans)

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repf(i,a,b) for (int i = (a); i < (b); i++)
#define repi(i,a,b) for (int i = (a); i <= (b); i++)
#define repr(i,a,b) for (int i = (a); i >= (b); i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(all(x));
#define RSORT(x) sort(rall(x));
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vd = vector<double>;
using vb = vector<bool>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;
const ll inf = 1ll<<29;
const ll mod = 1000000007;
const double eps = 1e-9;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};

int main() {
  int N, M; cin >> N >> M;
  
  vvi vec(M);
  rep(i,M) {
    int k; cin >> k;
    vec[i].resize(k);
    rep(j,k) {
      cin >> vec[i][j];
      --vec[i][j];
    }
  }
  vi p(M);
  rep(i,M) cin >> p[i];

  int ans = 0;
  rep(i,1<<N) {
    bool ok = true;
    rep(j,M) {
      int c = 0;
      for (int id : vec[j]) {
        if((i>>id)&1) {
          ++c;
        }
      }
      c%=2;
      if(c!=p[j]) {
        ok = false;
      }
    }
    if(ok) {
      ++ans;
    }
  }

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

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int N=200100;
inline int read(){
	int x=0,f=0,c=getchar();
	for(;c>'9'||c<'0';f=c=='-',c=getchar());
	for(;c>='0'&&c<='9';c=getchar())
	x=(x<<1)+(x<<3)+c-'0';return f?-x:x;
}
inline void write(ll x){
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);putchar(x%10+'0');
}
int n,m,a[N];
int main(){
	int i,sm=0,ans=0;
	n=read();m=read();
	for(i=1;i<=n;i++)a[i]=read();
	sort(a+1,a+n+1);
	for(i=1;i<=n;i++)
		if(sm+a[i]<=m)sm+=a[i],ans++;
		else break;
	if(ans==n&&sm!=m)ans--;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [$t:tt]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}


#[cfg(debug_assertions)]
macro_rules! mydbg {
    //($arg:expr) => (dbg!($arg))
    ($arg:expr) => (println!("{:?}",$arg));
}


#[cfg(not(debug_assertions))]
macro_rules! mydbg {
    ($($arg:expr),*) => {};
}


use std::cmp;
use std::collections::HashMap;

fn main() {


  input! { 
         n: i64, 
         input: [chars;n]
    }

    let mut input2 : HashMap<String , i64> = HashMap::new();
    let mut result : i64 = 0;
    for item in &input{
        let mut item2 = item.to_vec();
        item2.sort();
        let item3 = item2.into_iter().collect::<String>();
        let mut score :i64 = 1;
        if input2.contains_key(&item3) {
            score = *input2.get(&item3).unwrap();
            score += 1;
        }
        
        input2.insert(item3.clone(),score);
    }
    
    for ( _ , s) in input2{
        if(s>1){
            result += (s * (s-1)) / 2;
        }
    }
  

  
  
   
   println!("{}",result);

}


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

#define cerr cout
#define F first
#define S second
#define FOR(i,a,b) for (auto i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(auto i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
typedef long long ll; typedef pair <int, int> ii; typedef vector <int> vi; const int inf = 1e9 + 7;
string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << to_string(H); debug_out(T...);}
#define pr(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)



vi f(int mask, int a, int b) {
	if (__builtin_popcount(mask) == 1) {
		return {a, b};
	}
	
	int B = -1;
	FOR (i, 0, 16) if ((mask & (1 << i)) and ((a&(1<<i)) ^ (b&(1<<i)))) {
		B = i;
		break;
	}
	assert(B != -1);
	int na = a & (~(1 << B));
	int nb = b & (~(1 << B));
	int x = -1;

	mask ^= (1 << B);

	FOR (i, 0, 16) if ((mask & (1 << i)) and (na ^ (1 << i)) != nb) {
		x = na ^ (1 << i);
		break;
	}

	vi L = f(mask, na, x);
	vi R = f(mask, x, nb);
	if (b & (1 << B)) for (int &i: R) i |= (1 << B);
	else for (int &i: L) i |= (1 << B);

	copy(R.begin(), R.end(), back_inserter(L));
	return L;
}

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

	int n=5, a=1, b=12;
	cin >> n >> a >> b;
	if (__builtin_popcount(a^b) % 2 == 0) {
		cout << "NO\n";
		return 0;
	}
	cout << "YES\n";
	vi ans = f((1 << n) - 1, a, b);
	
	for (int i: ans) cout << i << " ";
	assert(ans[0] == a);
	assert(ans.back()==b);
	FOR (i, 1, sz(ans) - 1) {
		assert(__builtin_popcount(ans[i] ^ ans[i-1]) == 1);
	}
	cout << "\n";
	
	return 0;
}

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

int main() {
    int n; cin >> n;
    vector<int> l(n);
    rep(i, n) cin >> l[i];
    int ans = 0;
    sort(l.begin(), l.end());
    rep(b, n)rep(a, b){
        int ab = l[a] + l[b];
        int right = lower_bound(l.begin(), l.end(), ab) - l.begin();
        int left = b+1;
        ans += max(0, right-left);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
from heapq import heappop, heappush


class UnionFind(object):

    def __init__(self, N):
        self.tree = [i for i in range(N)]
        self.rank = [0] * (N + 1)
        self.size = [1] * N  # 頂点iの属する連結成分の大きさ

    def find(self, x):
        if self.tree[x] == x:
            return x
        else:
            self.tree[x] = self.find(self.tree[x])  # 経路圧縮
            return self.tree[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return

        # ランクを考慮しない場合はどちらが親になっても良い
        if self.rank[x] < self.rank[y]:
            self.tree[x] = y
            self.size[y] += self.size[x]
        else:
            self.tree[y] = x
            self.size[x] += self.size[y]

        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1

    def has_same_parent(self, x, y):
        return self.find(x) == self.find(y)


def I(): return int(input())
def MI(): return map(int, input().split())
def LMI(): return list(map(int, input().split()))


N = I()
X = [None] * N
Y = [None] * N
for i in range(N):
    x, y = MI()
    X[i] = (x, i, x, y)
    Y[i] = (y, i, x, y)
X.sort()
Y.sort()

# ある頂点vから最小全域木に含まれる点をたどった先の頂点は、x軸方向で最も近いかy軸方向で最もvから近いはず
q = list()
for i in range(N - 1):
    for axis in [X, Y]:
        _, t0, x0, y0 = axis[i]
        _, t1, x1, y1 = axis[i + 1]
        cost = min(abs(x1 - x0), abs(y1 - y0))
        heappush(q, (cost, t0, t1))

uf = UnionFind(N)
ans = 0
while len(q) > 0:
    cost, t0, t1 = heappop(q)
    if not uf.has_same_parent(t0, t1):
        uf.unite(t0, t1)
        ans += cost
print(ans)


Measured memory_bytes: 58344
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    void input() {

    }

    void solve() {
        input();
        int N, M, C;
        cin >> N >> M >> C;

        vector<int> B(M);
        rep(i, 0, M) cin >> B[i];

        int ans = 0;
        for (int i = 0; i < N; ++i) {
            int val = C;
            for (int j = 0; j < M; ++j) {
                int tmp;
                cin >> tmp;
                val += B[j] * tmp;
            }
            if(val > 0) ans++;
        }
        cout << ans << endl;
    }
};


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

    Solve().solve();


    return 0;
}


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

int H;
vector<int> A;

void max_heapify(int i) {
  int l = i*2+1;
  int r = i*2+2;

  int largest;
  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]);
    max_heapify(largest);  
  }
}

void build_maxheap() {
  for ( int i = H/2+1; i >= 0; i-- ) {
    max_heapify(i);    
  }
}

int main() {
  cin >> H;

  A = vector<int>(H);
  for ( int i = 0; i < H; i++ ) cin >> A[i];

  build_maxheap();

  for ( int i = 0; i < H; i++ ) cout << " " << A[i];  
  cout << endl;
  
  return 0;
}



Measured memory_bytes: 4628
#include<iostream>

using namespace std;

#define int long long

signed main(){
    int n; cin >> n; int arr[n][2];
    for (int i = 0; i < n; i++){
        cin >> arr[i][0] >> arr[i][1];
    }
    int tmp = 0; bool flag = false;
    for (int i = 0; i < n; i++){
        if (arr[i][0] == arr[i][1]) tmp++;
        else tmp = 0;
        if (tmp >= 3) flag = true;
    }
    cout << (flag == true ? "Yes" : "No");
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

void _main() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << (c - b == b - a ? "YES" : "NO") << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

Measured memory_bytes: 256
//om nama sivaya
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define pb push_back
using namespace std;
void solve(){
    int x,a;
    cin>>x>>a;
    if(x<a)
    cout<<"0";
    else
    cout<<"10";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tt=1;
    //cin>>tt;
    while(tt--){
        solve();
    }
}


Measured memory_bytes: 3580
object Main extends App{
  val n = readInt
  
  val m = (1 to n).map{ x => 
    (x.toString.head,x.toString.last) 
  }.groupBy(identity).mapValues(_.size).toMap
  var cnt = 0
  m.foreach{ kv =>
    val (k,v) = kv
    val rk = (k._2,k._1)
    cnt += m(k)*m.getOrElse(rk,0)
  }
  println(cnt)
}

Measured memory_bytes: 52768
#include <bits/stdc++.h>
using namespace std;
int N;
vector<int> p, a;
bool is_primitive(int n){
    for(int j=2; j*j<=n; j++){
        if(n % j == 0) return false;
    }
    return true;
}
int main(void){
    cin >> N;
    // 素数を取り出す
    for(int i=2; i<=N; i++){
        if(is_primitive(i)){
            p.push_back(i);
        }
    }
    // 素因数の数を計算
    for(int i=0; i<p.size(); i++){
        int n = N;
        a.push_back(0);
        while(n > 1){
            n /= p[i];
            a[i] += n;
        }
    }
    // 75の作り方
    // 1. 3x5x5
    // 2. 3x25
    // 3. 15x5
    // 4. 75
    int ret = 0;
    // 1. 3x5x5
    int l = 0, m = 0;
    for(auto e: a){
        if(e >= 2) l++;
        if(e >= 4) m++;
    }
    ret += (l - m) * m * (m - 1)/ 2;
    ret += m * (m - 1) * (m - 2) / 2;

    // 2. 3x25
    l = m = 0;
    for(auto e: a){
        if(e >= 2) l++;
        if(e >= 24) m++;
    }
    ret += (l - m) * m;
    ret += m * (m - 1);

    // 3. 5x15
    l = m = 0;
    for(auto e: a){
        if(e >= 4) l++;
        if(e >= 14) m++;
    }
    ret += (l - m) * m;
    ret += m * (m - 1);

    // 4. 75
    l = m = 0;
    for(auto e: a){
        if(e >= 74) l++;
    }
    ret += l;

    cout << ret << endl;

}

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

ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(a%b==0)return b;
    return gcd(a%b,b);
}
ll lcm(ll a,ll b){
    return a/gcd(a,b)*b;
}

int main(){
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  
  ll cr1 = (a + c - 1) / c;
  ll cr2 = b / c;
  ll dr1 = (a + d -1) / d;
  ll dr2 = b / d;
  ll low = lcm(c, d);
  ll r1 = (a + low -1) / (low);
  ll r2 = b / (low);

  ll cnt = b - a + 1 - (cr2 - cr1 + 1) - (dr2 - dr1 + 1) + (r2 - r1 + 1);
  cout << cnt << endl;
  return 0;
}


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

int sq(int a, int b){
    return (a-b)*(a-b);
}

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

    int pos[100] = {0};
    rep(i,n){
        cin >> pos[i];
    }

    vector<int> hel(100);
    rep(i,100){
        rep(j,n){
            hel[i] += sq(pos[j], i);
        }
    }

    cout << *min_element(hel.begin(), hel.end());
}

Measured memory_bytes: 256
def choose(n, k)
  if k == 0
    return 1
  else
    return choose(n, k-1) * (n - k + 1)/ k
  end
end

n, p = gets.chomp.split(" ").map{|i| i.to_i}
a = gets.chomp.split(" ").map{|i| i.to_i}

odd = 0
even = 0

a.each{|it|
  if it % 2 == 0
    even += 1
  else
    odd += 1
  end
}

ans = 0

for i in 0..odd
  if (i%2 == p)
    ans += (2 ** even) * choose(odd, i)
  end
end

puts ans



Measured memory_bytes: 1788
import math

x1,y1,x2,y2=map(float,input().split())

if x1>x2:
    H=x1-x2
else:
    H=x2-x1

if y1>y2:
    W=y1-y2
else:
    W=y2-y1
    
a=math.sqrt(H**2+W**2)

print(a)



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

typedef long long ll;
const int maxn = 2e5;
int n, a[maxn + 3], b[maxn + 3], nxt[maxn + 3];
int k, p, c[maxn + 3], vis[maxn + 3], sz, ans[maxn + 3];
ll m;

void solve(int x) {
	for (int i = 1; i <= maxn; i++) {
		b[i] = 0;
	}
	for (int i = x; i <= n; i++) {
		if (!b[a[i]]) {
			ans[++sz] = a[i];
			b[a[i]] = sz;
		} else {
			int t = sz;
			sz = b[a[i]] - 1;
			for (int j = b[a[i]]; j <= t; j++) {
				b[ans[j]] = 0, ans[j] = 0;
			}
		}
	}
	for (int i = 1; i <= sz; i++) {
		printf("%d%c", ans[i], " \n"[i == sz]);
	}
}

int main() {
	scanf("%d %lld", &n, &m);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
	}
	if (m == 1) {
		solve(1);
		return 0;
	}
	for (int i = n; i; i--) {
		b[a[i]] = i;
	}
	for (int i = n; i; i--) {
		nxt[i] = b[a[i]];
		b[a[i]] = i;
		if (nxt[i] > i) {
			nxt[i] = nxt[nxt[i] + 1];
		}
	}
	c[1] = 1;
	vis[1] = 1;
	for (int i = 2; i <= n + 2; i++) {
		if (c[i - 1] == n + 1) {
			c[i] = 1;
		} else {
			c[i] = nxt[c[i - 1]] + 1;
		}
		if (m == i) {
			solve(i);
			return 0;
		}
		if (vis[c[i]]) {
			k = i - vis[c[i]];
			p = vis[c[i]];
			solve(c[(m - p) % k + p]);
			return 0;
		}
		vis[c[i]] = i;
	}
	return 0;
}

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

int main() {
	int N, M;
	cin >> N;
	vector<string> blue(N);
	rep(i, N) cin >> blue[i];
	cin >> M;
	vector<string> red(M);
	rep(i, M) cin >> red[i];

	int ans = 0;
	rep(i, N) {
		string word = blue[i];
		int score = 0;
		rep(j, N) {
			if (word==blue[j]) score++;
		}
		rep(k, M) {
			if (word==red[k]) score--;
		}
		ans = max(ans, score);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::max;
use std::io;

fn main() {
    let input = input_number();
    let n = input[0] as usize;
    let w = input[1] as usize;
    println!("{}", n * w);
}

#[allow(dead_code)]
fn update_max<T>(left: &mut T, right: T)
where
    T: std::cmp::Ord + std::clone::Clone,
{
    if *left < right {
        *left = right.clone();
    }
}

#[allow(dead_code)]
fn update_min<T>(left: &mut T, right: T)
where
    T: std::cmp::Ord + std::clone::Clone,
{
    if *left > right {
        *left = right.clone();
    }
}

#[allow(dead_code)]
fn input_number() -> Vec<i64> {
    let mut input = String::new();
    io::stdin()
        .read_line(&mut input)
        .expect("Failed to read line");
    let vec: Vec<i64> = input
        .split_whitespace()
        .map(|x| x.parse().unwrap_or(0))
        .collect();
    vec
}

#[allow(dead_code)]
fn input() -> (char, usize) {
    let mut s = String::new();
    io::stdin().read_line(&mut s).expect("");
    let mut iter = s.trim().split_whitespace();
    let c: char = iter.next().unwrap().chars().nth(0).unwrap();
    let n: usize = iter.next().unwrap().parse().unwrap();
    (c, n)
}



Measured memory_bytes: 2100