akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds; 
using namespace std;
using   ll=long long;

#define fast        	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ordered_set 	tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>

#define endl        	"\n"
#define pb          	push_back
#define mp          	make_pair
#define F           	first
#define S           	second
#define int             long long int
#define pll				pair<int , int>

#define ALL(v)      	v.begin(),v.end()
#define ALLR(v)     	v.rbegin(),v.rend()
#define pii         	3.14159265358979323
#define inf     		LLONG_MAX
#define ones(x)     	__builtin_popcount(x)
#define fill(a,b)   	memset(a,b,sizeof(a))
#define mod 			1000000007
#define hell            998244353 

ll mod_pow(ll a,ll b,ll m) 
{
    ll res = 1;
    while(b)	
    {
        if(b&1) 	
        {
        	res=(res*a) % m;
        }
        a=(a*a) % m;
        b>>=1;
    }
    return res;
}

ll mod_inverse(ll a) 
{
	return mod_pow(a , mod-2 , mod);
}

void solve()
{
	int n;
	
	cin >> n;
	
	set< int > st;
	
	for(int i = 0; i < n; ++i) {
		int x;
		
		cin >> x;
		
		if(st.find(x) != st.end()) {
			st.erase(st.find(x));
		}
		else {
			st.insert(x);
		}
	}
	
	cout << (int)(st.size());
}

signed main() {
    fast;
    
    int t = 1;
    
	//cin >> t;
    
    while(t--) {
        solve();
    }
 
    return 0;
}


Measured memory_bytes: 8220
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 20 20:47:47 2019
 
@author: Owner
"""
 
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 13 09:53:12 2019
 
@author: Owner
"""
 
from operator import itemgetter
import itertools
import collections
import bisect
 
N, M = list(map(int, input().split()))
 
A = list(map(int, input().split()))
A.sort()

A = collections.deque(A)

BC = [(0, 0)]*M
for m in range(M):
    BC[m] = tuple(map(int, input().split()))
BC.sort(key=itemgetter(1), reverse = True)
 
def main(): 
    #print(BC)
    res = 0
    for i in range(M):
        idx = 0         
        idx = bisect.bisect_left(A, BC[i][1])
        if idx == 0:
            break
        else:
            less =min(idx, BC[i][0])
            for n in range(less):
                A.popleft()
            res += BC[i][1]*less
 
    print(res+sum(A))
                
                
                
            
            
                
 
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 76440
#include<bits/stdc++.h>
using namespace std;
#define rep(n,k) for(int i = (int)n;i<k;i++)
using Int =long long int;
using Graph =vector<vector<int>>;
int main(){
    int N;cin>>N;
    Int sum1=0;
    vector<Int>num(N);
    rep(0,N){
        Int a;
        cin>>a;
        num.at(i)=a;
        sum1+=a;
    }
    Int sum2=0;
    //  1000000007
    rep(0,N){
        sum1 -=num.at(i);
        sum2 += (num.at(i)*(sum1%1000000007));
        sum2= sum2%1000000007;

        
    }
    cout<<sum2<<endl;

}

Measured memory_bytes: 4840
#include <iostream>

using namespace std;
int main(void){
	string v = "aeiou";
	char c;
	cin >> c;
	bool res = 0;
	for(char a : v){
		if(a==c)res=1;
	}
	if(res)	cout << "vowel" << endl;
	else cout << "consonant" << endl;
}

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

#define REP(i ,n) for(int i=0 ;i < n; i++)
#define REPB(i ,n) for(int i=n; i >= 0; i--)
#define FOR(i ,m ,n) for(int i=m; i < n; i++)
#define FORB(i, m, n) for(int i=m; i>= m; i--)
#define ll long long
#define pb push_back
#define popb pop_back
using namespace std;

int main(){
  int p,q; 
  vector<int> a,b;
  REP(i, 7) {
    cin >> p >> q;
    a.pb(p);
    b.pb(q);
  }
  REP(j,7) cout << (a[j] - b[j]) << endl;
  return 0;
}



Measured memory_bytes: 3152
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
	int n,m;cin >> n >> m;
	vector<string> a(n),b(m);
	rep(i,n)cin >> a[i];
	rep(i,m)cin >> b[i];
	auto check = [&](int x,int y){
		for(int i = x;i < x+m;i++){
			for(int j = y;j < y+m;j++){
				if(a[i][j] != b[i-x][j-y])return false;
			}
		}
		return true;
	};
	for(int i = 0;i + m <= n;i++){
		for(int j = 0;j + m <= n;j++){
			
			if(check(i,j)){
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3584
/*
g++ -std=c++14 -O2 -Wall a.cpp -o a && a
g++ -std=c++14 -O2 -Wall a.cpp -o a && a < in.txt > out.txt
*/

//  io
#include <fstream> //http://www.cplusplus.com/reference/fstream/fstream/
#include <iostream>
//#include <cstdio>
#include <iomanip> //http://www.cplusplus.com/reference/iomanip/
#include <limits>
//  util
#include <algorithm>
#include <cstring>
#include <string>
//#include <utility>
//#include <functional> //http://www.cplusplus.com/reference/functional/
//#include <cstdlib>
#include <cmath>
//#include <complex>
//#include <random>
//#include <bitset>
//  containers https://en.cppreference.com/w/cpp/container
#include <map>
#include <queue>
#include <set>
#include <vector>
//#include <unordered_set>
//#include <unordered_map>
//  time
//#include <ctime>
#include <chrono>
//                  https://en.cppreference.com/w/cpp/header/chrono
//                  http://www.cplusplus.com/reference/chrono/

using namespace std;
typedef vector<int> arri;
typedef vector<float> arrf;
typedef pair<int, int> pairi;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 0x7fffffffffffffff;
const ll infneg = -0x7fffffffffffffff;

// file input routed to stdinout
/*
std::ifstream inFile("input.txt");
std::ofstream outFile("output.txt");
std::cin.rdbuf(inFile.rdbuf());
std::cout.rdbuf(outFile.rdbuf());
*/

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

    int startIndex = -1;

    for (int i = 0; i < n; i++)
    {
        if (arr[i] == 1)
        {
            startIndex = i;
            break;
        }
    }

    if (startIndex == -1)
    {
        cout << -1;
        return 0;
    }

    int nextNum = 2;
    for (int i = startIndex; i < n; i++)
    {
        if (arr[i] == nextNum)
        {
            nextNum++;
        }
    }

    cout << (n - nextNum + 1);
}

Measured memory_bytes: 1024
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

int main(int argc, char **argv) {
	int h, w;
	string c;
	cin >> h >> w;
	REP(i, h) {
		cin >> c;
		cout << c << endl << c << endl;
	}
	return 0;
}


Measured memory_bytes: 384
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
    input = input.split("\n");
    // 数値の配列を作る
    const numList0 = input[0].split(' ').map(x => parseInt(x, 10));
    const a = numList0[0];
    const strList0 = input[1].split(' ');
    const s = strList0[0];

    if (a >= 3200) {
        console.log(s);
    } else {
        console.log('red');
    }
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 26052
N = int(input())
cnt = [[0]*10 for _ in range(10)]

for i in range(1, N+1):
    f = int(str(i)[0])
    l = int(str(i)[-1])
    cnt[f][l] += 1

ans = 0

for i in range(10):
    for j in range(10):
        ans += cnt[i][j]*cnt[j][i]

print(ans)

Measured memory_bytes: 67916
#include <iostream>
#include <string>
using namespace std;
int main()
{
  int H;
  int W;
  int N;
  int S=0;
  int i=0;
  
  cin >> H;
  cin >> W;
  cin >> N;
  
  
  while(S<N){
    if(H<W){
      S+=W;
      i++;
    }
    else{
      S+=H;
      i++;
    }  
  }
  cout << i;
}



Measured memory_bytes: 256
N,M=list(map(int,input().split()))
si=[0]*N
ans=0
for i in range(M):
    S=int(input())
    who=list(map(int,input().split()))
    for k in range(S):
        si[who[k]-1]+=1
for h in range(N):
  if si[h]==0:
    ans+=1
print(ans)


Measured memory_bytes: 67764
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_C&lang=jp
#??????
if __name__ == "__main__":
    n_line = int(input())
    input_list = [tuple(input().split()) for i in range(n_line)]
    l = set([])
    for c, s in input_list:
        if c == "insert":
            l.add(s)
        else:
            if s in l:
                print("yes")
            else:
                print("no")

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

int main() {
    string s, t;
    cin >> s >> t;
    vector<vector<int>> dp(s.size() + 1, vector<int>(t.size() + 1, 0));

    rep(si, s.size()) rep(ti, t.size()) {
        if (s[si] == t[ti]) {
            dp[si + 1][ti + 1] =
                max({dp[si + 1][ti], dp[si][ti + 1], dp[si][ti] + 1});
        } else {
            dp[si + 1][ti + 1] = max({dp[si + 1][ti], dp[si][ti + 1]});
        }
    }

    string ans = "";
    int si = s.size();
    int ti = t.size();
     while(si>0 && ti >0) {
        if(dp[si][ti] == dp[si-1][ti]) si--;
        else if(dp[si][ti] == dp[si][ti-1]) ti--;
        else {
            ans = s[si-1] + ans;
            si--;ti--;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 35584
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    a = list(map(int, input().split()))

    state = 0
    pre = a[0]
    count = 0
    i = 1
    for i in range(1, N):
        tmp = a[i] - pre
        if state == 0: # 状態未定
            if tmp > 0:
                state = 1
            elif tmp < 0:
                state = -1
        elif state == 1: # 単調非減少
            if tmp < 0:
                state = 0
                count += 1
        else:   # 単調非増加
            if tmp > 0:
                state = 0
                count += 1
        pre = a[i]
    count += 1
    print(count)

if __name__ == "__main__":
    main()
            

Measured memory_bytes: 14172
#pragma warning(disable:4996)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")

#include<bits/stdc++.h>

#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define f(i, a ,b) for(int i = (int)a; i <=(int)(b);i++)
#define endl "\n"
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;

using namespace std;

const int N = 1e5+5,MOD = 1000000007;
const long long int INF = 0xFFFFFFFFFFFFFFFL;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void IOS()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
   	cout.precision(10);
   	cout << fixed;
}
	
int32_t main()
{
	IOS();
	int n,d;
	cin >> n >> d;
	int ans = n/(2*d+1)+1-(n%(2*d+1) == 0);
	cout << ans;	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<int, int>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

using namespace std;
using ll = long long;
const int mod = 1e9+7;

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

  int N; cin >> N;
  int ans = 0;
  for(int k=3; k<=9; k++) {
    int tmp = k;
    int cnt = 1;
    while (tmp-- > 0) {
      cnt *= 3;
    }
    rep(i, cnt) {
      int s = i;
      int now = 0;
      int f = 1;
      bool flag3 = false;
      bool flag5 = false;
      bool flag7 = false;
      for(int j=1; j<=k; j++) {
        if (s%3 == 2) {
          now += 7*f;
          flag7 = true;
        } else if (s%3 == 1) {
          now += 5*f;
          flag5 = true;
        } else {
          now += 3*f;
          flag3 = true;
        }
        f *= 10;
        s /= 3;
      }
      if (now <= N && flag7 && flag5 && flag3) {
        //debugln(now);
        ans++;
      }
    }
  }
  cout << ans << endl;
}

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

using namespace std;

int main() {

    int n,m;
    cin >> n >> m;

    vector< vector<int> > matrix(n);

    for (int i=0; i<m; i++) { //Lendo a matriz de adjacência
        int a, b;
        cin >> a >> b;

        matrix[a-1].push_back(b-1);
        matrix[b-1].push_back(a-1);
    }

    queue<int> q;
    q.push(0);

    int resp[n+5];
    for (int i=0; i<n; i++) resp[i] = -1;

    while (!q.empty()){

        int atual = q.front();

        for (int i=0; i<matrix[atual].size(); i++){

            if (resp[matrix[atual][i]] == -1){ //Para ver se ja foi percorrida
                q.push(matrix[atual][i]);
                resp[matrix[atual][i]] = atual;
            }
        }
        q.pop();
    }

    bool ok = true;

    for (int i=1; i<n; i++) {
        if (resp[i]==-1) ok = false;
    }

    if (ok){
        cout << "Yes" << endl;
        for (int i=1; i<n; i++) {
            cout << resp[i]+1 << endl;
        }
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 10156
#include <iostream>
#include <string.h>


using namespace std;
#define int long long
const int N=200000;
int n;
int a[N+1];
int buc[N+1];
signed main(){
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i],buc[a[i]]++/*装进桶*/;
	int ans=0;
	for(int i=1;i<=n;i++)ans+=buc[i]*(buc[i]-1)/2;//不带限制时的答案
	for(int i=1;i<=n;i++)cout<<ans-(buc[a[i]]-1)<<"\n";
	return 0;
}


Measured memory_bytes: 4736
def get_one_position(number):
    return number % 10


def get_ten_div(number):
    return number // 10 * 10 + 10


if __name__ == '__main__':
    numbers = []
    ans = 0
    min_one_point = 9
    min_one_point_index = 5
    for i in range(5):
        number = int(input())
        numbers.append(number)
        if get_one_position(number) <= min_one_point and get_one_position(number) != 0:
            min_one_point = get_one_position(number)
            min_one_point_index = i

    for i in range(len(numbers)):
        if i != min_one_point_index:
            if numbers[i] % 10 == 0:
                ans += numbers[i]
            else:
                ans += get_ten_div(numbers[i])
        else:
            ans += numbers[i]

    print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
int dx1[] = {0 ,1 ,1,1,0,-1};
int dy1[] = {-1,-1,0,1,1,0 };
int dx2[] = {-1,0 ,1,0,-1,-1};
int dy2[] = {-1,-1,0,1,1 ,0 };

int main(){
  int w,h;
  int ban[111][111];
  bool used[111][111][6];
  int cnt = 0;
  cin >> w >> h;
  for(int i=0;i<=h+1;i++){
    for(int j=0;j<=w+1;j++){
      if(i==0 || j==0 || i==h+1 || j==w+1) ban[i][j] = 0;
      else cin >> ban[i][j];
      for(int z=0;z<6;z++){
	used[i][j][z] = true;
      }
    }
  }
  queue<P> que;
  que.push(P(0,0));
  while(!que.empty()){
    P p = que.front(); que.pop();
    int nowx = p.first; int nowy = p.second;
    if(ban[nowy][nowx] == 1) cnt++;
    else {
      for(int i=0;i<6;i++){
	int nx,ny;
	if(nowy%2==1){
	  nx = nowx + dx1[i];
	  ny = nowy + dy1[i];
	}
	else {
	  nx = nowx + dx2[i];
	  ny = nowy + dy2[i];
	}
	if(nowx >= 0 && nowy >= 0 && nowx <= w+1 && nowy <= h+1 && used[nowy][nowx][i]){
	  que.push(P(nx,ny));
	  used[nowy][nowx][i] = false;
	}
      }
    }
  }
  cout << cnt << endl;
}
  
    
      
		     
    

Measured memory_bytes: 1344
/* Author : Aaryan Srivastava ^__^ */ 
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second   
#define rep(i,n) for(int (i) = 0 ; i < (n) ; i++)
#define repA(i,x,y) for(int i = (x) ; i <= (y) ; i++)
#define repD(i,x,y) for(int i = (x) ; i >= (y) ; i--)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).end()
#define setval(a,val) memset(a,val,sizeof(a))
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define trav(x , a) for(auto &x : a)
#define sz(a) ((int)a.size())
typedef long long ll ; 

#define int ll

using namespace std;

const int N = 3e5 +5 ;
const int mod = 1e9 + 7 ;
const ll inf = 1e18 ;
const int SZ = 101 ;
const double eps = 1e-9 ;
using namespace __gnu_pbds;
using ordered_set =  tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ;

typedef pair<int, int> pii; 
typedef pair<int , pii> ipii ;
typedef pair<pii , int> piii ; 
typedef unsigned long long ull ;
typedef long double ld;

ll po(ll x,ll y,ll p = mod) {ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int val(char c){
    if(c == 'R') return 0; 
    if(c == 'G') return 1;
    return 2; 
}

void solve()
{
    int n ;
    string s;
    cin >> n >> s ;
    int ans = 0 ;    
    for(int i = 0 ; i < n ; ++i){
        int cnt[3] = {};
        for(int j = 0 ; j < i ; ++j){
            if(s[j] == s[i]) continue ;
            ans += cnt[3 - val(s[i]) - val(s[j])];
            int k = (i - j);
            int nidx = j - k ;
            if(nidx >= 0) ans -= ((val(s[i]) + val(s[j]) + val(s[nidx]) == 3));
            cnt[val(s[j])]++;
        }
    }
    cout << ans ;
}   

     
int32_t main(int32_t argc, char *argv[])
{
    ios::sync_with_stdio(0);    
    cin.tie(0); cout.tie(0);
    int TC = 1, t = 0;
    //cin >> TC ;
    while(t++ < TC)
    {
        //cout << "Case #" << t << ": " ;
        solve();
        cout << "\n" ;
    }
    return 0;
}

Measured memory_bytes: 3668
S = input()
res_l = []
r,l = 0,1
for i,s in enumerate(S+'R'):
#    print(i,r,l)
    if s == 'R':
        if l:
            if i:
                res_l[i-l] = r//2 + (l+1)//2
                res_l[i-l-1] = (r+1)//2 + l//2

            r,l = 1,0
        else:
            r += 1
        res_l.append(0)
    else:
        l += 1
        res_l.append(0)

res = ' '.join(list(map(str,res_l[:-1])))
print(res)



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

int H, i;
int A[20000000] = {};

void maxHeapify(int i) {
    
    int largest = 0;
    
    int l = 2 * i;
    int 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 (i = 1; i < H + 1; i ++) {
        
        cin >> A[i];
        
    }
    
    for (i = H / 2; i >= 1; i --) {
        
        maxHeapify(i);
        
    }
    
    for (i = 1; i < H + 1; i ++) {
        
        cout << " " << A[i];
        
    }
    
    cout << endl;
    
    return 0;
    
}



Measured memory_bytes: 5072
#include <iostream>
#include <queue>
#define ll long long
#define up (ll)1e10
#define MAXN 1000005
using namespace std;
struct node {
    ll num, step;
    node(){}
    node(ll n, ll s) : num(n), step(s){}
};
deque <node> q;
bool vst[MAXN];
ll k;
void slove() {
    q.push_front(node(1, 1));
    while(!q.empty()) {
        node t = q.front();
        vst[t.num] = 1;
        if(t.num == 0) {
            cout << t.step << "\n";
            return;
        }
        q.pop_front();
        if(!vst[t.num*10%k]) 
            q.push_front(node(t.num*10%k, t.step));
        if(!vst[(t.num+1)%k]) 
            q.push_back(node((t.num+1)%k, t.step+1));
    }
}

int main () {
    cin >> k;
    slove();
    return 0;
}

Measured memory_bytes: 1408
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>

using namespace std;

int vis[5005];
vector<int>G[5005];
int N,M;
vector<int>res;

void func(int v){
  if(vis[v]) return;
  vis[v] = 1;
  for(int i=0;i<G[v].size();i++) func(G[v][i]);
  res.push_back(v);
  return;
}

int main(){
  scanf("%d%d",&N, &M);
  for(int i=0;i<M;i++){
    int a,b;scanf("%d%d", &a,&b); a--; b--;
    G[b].push_back(a);
  }

  for(int i=0;i<N;i++) func(i);
  int f = 0;
  for(int i=1;i<N;i++) if(find(G[res[i]].begin(), G[res[i]].end(), res[i-1]) == G[res[i]].end()) f = 1;

  for(int i=0;i<N;i++) printf("%d\n", res[i]+1);
  printf("%d\n", f);
  return 0;
}

Measured memory_bytes: 1872
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 200000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W, K;
    cin >> H >> W >> K;
    string S[11];
    rep(i, H) cin >> S[i];
    int ans = INF;
    rep(bit, (1 << (H))) {
        int sum = 0;
        rep(i, 10) if (bit & (1 << i)) sum++;
        //cout << sum << " ";
        int tmp[11] = {};
        rep(j, W) {
            int add[11] = {};
            int k = 0;
            rep(i, H) {
                add[k] += S[i][j] - '0';
                //cout << k << " " << add[k] << endl;
                if(i < H && bit & (1 << i)) k++;
            }
            bool isadd = false;
            rep(i, k + 1) {
                if (tmp[i] + add[i] <= K) continue;
                else {
                    isadd = true;
                }
            }
            rep(i, k + 1) {
                if(!isadd)
                    tmp[i] += add[i];
                else
                    tmp[i] = add[i];
                if(tmp[i] > K) sum = INF;
            }
            sum += isadd;
        }
        ans = min(ans, sum);
        //cout << sum << endl;
    }
    assert(ans < INF);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

int a[100001], n, m;
map<int, int> f;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; ++i)
    {
        cin >> a[i];
        a[i] %= m;
    }
    for (int i = 1; i <= n; ++i)
    {
        a[i] += a[i - 1];
        a[i] %= m;
        f[a[i]]++;
    }
    ll sol = 0;
    for (int i = 1; i <= n; ++i)
        sol += f[a[i]] - 1;
    cout << sol / 2 + f[0];
}


Measured memory_bytes: 3584
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("no-stack-protector")
//#pragma GCC target("popcnt")
//#pragma GCC target("sse4")
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define rng(a) a.begin(),a.end()
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define sz(a) (int)(a.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef long double ld;











#define int long long

const int mod = 998244353;
const int maxn = 3003;
int dp[maxn][maxn];

signed main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    dp[a][b] = 1;
    for (int j = 0; j < a; j++)
        for (int i = 0; i < maxn; i++)
            dp[j][i] = 0;
     for (int j = 0; j < b; j++)
        for (int i = 0; i < maxn; i++)
            dp[i][j] = 0;
    for (int i = a; i < maxn; i++){
        for (int j = b; j < maxn; j++){
            if (i == a && j == b) continue;
            dp[i][j] = (dp[i - 1][j] * j + dp[i][j - 1] * i - dp[i - 1][j - 1] * (i - 1) * (j - 1));
            dp[i][j] = (dp[i][j] + mod*mod)%mod;
        }
    }
    cout << dp[c][d];




}


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

using namespace std;

main(){
    int N,T,more,less;
    int absol = 100000;
    cin >> N;
    int W[N];

    for(int i = 0;i < N;i++) cin >> W[i];

    for(T=0;T<=100;T++)
    {
        more = 0;
        less = 0;

        for(int i = 0;i < N;i++)
        {
            if(i<=T) less += W[i];
            if(i>T)  more += W[i];
        }

        if(abs(more-less) <= absol) absol = abs(more-less);
    }

    cout << absol << endl;

}

Measured memory_bytes: 256
N = int(input())

t = [0]*(100)
ans = 0
for k in range(1,N+1):
    if k%10 != 0:
        t[10*int(str(k)[0])+int(str(k)[-1])] += 1
for k in range(11,100):
    if k%10 != 0:
        ans += t[k]*t[10*(k%10)+k//10]
print(ans)


Measured memory_bytes: 9156
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (scanner.hasNext()) {
			String a = scanner.next();
			String b = scanner.next();

			int p1 = a.length();
			int p2 = 0;
			int ans = 0;
			while (p1 != 0 || p2 <= b.length()) {
				if (p1 != 0)
					p1--;
				else
					p2++;
				ans = Math.max(ans, slove(a, b, p1, p2));
			}
			System.out.println(ans);
		}
	}

	private int slove(String a, String b, int p1, int p2) {
		int tmp = 0;
		int res = 0;
		int len = Math.min(b.length() - p2, a.length() - p1);

		for (int i = 0; i < len; i++) {
			if (a.charAt(p1 + i) != b.charAt(p2 + i)) {
				res = Math.max(res, tmp);
				tmp = 0;
			} else
				tmp++;
		}
		return Math.max(tmp, res);
	}
}

Measured memory_bytes: 21260
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int,int>
#define PIII pair<int,pii>
#define PLL pair<ll,ll>
#define PLII pair<ll,pii>
#define VI vector<int>
#define FF first
#define SS second
#define MP make_pair
#define PB push_back
#define MX 100001
#define EPS 0.00000000001
#define MOD 1000000007
#define PI acos(-1)
#define INF 100000000
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
using namespace std;

int main()
{
    int n;
    cin>>n;
    int ans = (n/2) + (n%2);

    cout<<ans<<'\n';

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
typedef pair<int,int> PP;
typedef long long ll;
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; }
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE cout << -1 << endl;return 0
#define MM <<" "<<
#define Endl endl


signed main(void){
    int N,K,Q;
    int A[2019];
    cin >> N >> K >> Q;
    REP(i,N){
        cin >> A[i];
    }
    
    vector<pair<int,int>> c;
    vector<int> q;
    int Ans=INF;
    REP(z,N){
        int LEV=A[z];
        int e[2019]={};
        c.clear();
        q.clear();
        REP(i,N+1){
            if(i==N || A[i]<LEV){
                sort(c.begin(),c.end());
                int m=c.size();
                REP(j,m-K+1){
                    e[c[j].second]=1;
                }
                c.clear();
            }else{
                c.push_back({A[i],i});
            }
        }
        REP(i,N){
            if(e[i]!=0){
                q.push_back(A[i]);
            }
        }
        sort(q.begin(),q.end());
        int p=q.size();
        if(p<Q)continue;
        Ans=min(Ans,q[Q-1]-LEV);
        
    }
    cout << Ans << endl;
    return 0;
}



Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
using namespace std;
typedef long long ll;
int main(){
  string s;
  cin >> s;
  int one = 0;
  bool res = true;
  int k = 0;
  for(int i = 1;i <= 3;i++){
    if(s[0] == s[i])one++,k = i;
  }
  if(one != 1)res = false;
  char two;
  if(k == 1 && s[2] != s[3])res = false;
  else if(k == 2 && s[1] != s[3])res = false;
  else if(k == 3 && s[1] != s[2])res = false;
  if(res)cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define REP(i,n) for (int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
 
using namespace std;

signed main(){
    
    int n,m;
    cin >> n >> m;
    
    if(2*n >= m){
        cout << m/2;
    }else{
        cout << n + (m - 2*n)/4;
    }

    return 0;
}


Measured memory_bytes: 256
n = int(input())
ans = []
m = ord('a') - 1
x = 0
while 26 ** x <= n:
    x += 1
while x > 0:
    x -= 1
    tmp = n // (26 ** x)
    ans.append(tmp)
    n = n - tmp * (26 ** x)
for i in range(len(ans) - 1, -1, -1):
    if ans[i] == 0:
        if i == 0:
            ans[i] = ''
            continue
        ans[i] = chr(m + 26)
        j = i - 1
        while ans[j] == 0:
            ans[j] = 25
            j -= 1
        ans[j] -= 1
    else:
        ans[i] = chr(m + ans[i])
print(''.join(ans))

Measured memory_bytes: 9236
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <algorithm>
typedef long long int ll;
using   namespace std;
#define ALL(a) (a).begin(),(a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
const ll MOD = 1000000007;
 
    ll  temp
        ,N,ans=0,sum=0,fir=0,sec=-1;
        vector<ll> A;
 
int main() {
    scanf("%lld",&N);
    REP(i,N){
        scanf("%lld",&temp);
        A.push_back(temp);
    }
    sort(ALL(A));
    sum=A[0];
    REP(i,N){
        if(i==0)continue;
//cout<<sum<<":"<<A[i]<<endl;
        if(sum*2<A[i]){
                ans=i;
               // break;
                //cout<<i<<":"<<ans<<endl;
        }
             sum+=A[i];
    }
    cout<<N-ans;
}

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

int main() {
  long long n, c, k;
  cin >> n >> c >> k;

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

  sort(t, t + n);

  int count = 0;
  int temp = -1;
  while (temp < n - 1) {
    int next = t[temp + 1];
    if (temp + 1 + c < n) {
      if (t[temp + c] <= next + k) {
	temp += c;
      } else {
	for (int i = c - 1; i > 0; i--) {
	  if (t[temp + i] <= next + k) {
	    temp += i;
	    break;
	  }
	}
      }
    } else {
      if (t[n - 1] <= next + k) {
	temp = n - 1;
      } else {
	for (int i = n - 2; i >= temp + 1; i--) {
	  if (t[i] <= next + k) {
	    temp = i;
	    break;
	  }
	}
      }
    }
    count++;
  }
  
  cout << count << endl;

  return 0;
}


Measured memory_bytes: 1024
N = int(input())
H = list(map(int,input().split()))

ans = 0
tmp = 0

for i in range(N-1):
    if(H[i] < H[i+1]):
        #ans = max(ans,tmp)
        tmp = 0
    else:
        tmp += 1
    ans = max(ans,tmp)

print(ans)

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

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

const int INF = 1000000007;

int main(){
	int n;
	cin>>n;
	int x[220000]={0}, y[220000]={0};
	for(int i=0;i<n;i++){
		cin>>x[i];
		y[i] = x[i];
	}

	sort(y, y+n);
	for(int i=0;i<n;i++){
		if(x[i]<=y[n/2 - 1]) cout<< y[n/2] <<endl;
		else cout<< y[n/2 - 1] <<endl;
	}

	return 0;
}

Measured memory_bytes: 3968
import sys
readline = sys.stdin.readline

def main():
    N = int(readline())
    A = [0] + list(map(int, readline().rstrip().split())) + [0]
    s = sum([abs(A[i]-A[i-1]) for i in range(1, N+2)])
    for i in range(1, N+1):
        print(s + abs(A[i+1] - A[i-1]) - (abs(A[i+1]-A[i]) + abs(A[i]-A[i-1])))
    

if __name__ == '__main__':
    main()

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

int main(){
    string S;
    cin >> S;
    int ans = 0;
    int cnt = 0;
    for(int i = 0; i < S.size(); i++) {
        if(i%2 == 0 && S[i] != '0') {
            ans++;
        }
        else if(i%2 == 1 && S[i] != '1') {
            ans++;
        }
    }
    for(int i = 0; i < S.size(); i++) {
        if(i%2 == 0 && S[i] != '1') {
            cnt++;
        }
        else if(i%2 == 1 && S[i] != '0') {
            cnt++;
        }
    }
    cout << min(cnt,ans) << endl;
}



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

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

using namespace std;

int main() {
    int l, r, d;
    cin >> l >> r >> d;
    int ans = 0;
    for (int i = l; i <= r; i++) {
        if (i % d == 0) ans++;
    }
    cout << ans;
}


Measured memory_bytes: 3588
#include <iostream> 

using namespace std;

int main() {

	short N;
	cin >> N;
	short* music_time = new short[N];
	int sleep_time = 0;
	string* title = new string[N],X;

	for(int i = 0; i < N; i++)	cin >> title[i] >> music_time[i];
	cin >> X;
	for (int i = N - 1; title[i] != X; i--)sleep_time += music_time[i];
	cout << sleep_time << endl;
	return 0;
}

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

int par1[200010];
int par2[200010];
int rank1[200010];
int rank2[200010];
int road[2000010];
int train[200010];

void init(int n) {
	for (int i = 0; i < n; i++) {
		par1[i] = i;
		par2[i] = i;
		rank1[i] = 0;
		rank2[i] = 0;
	}
}
int find1(int x) {
	if (par1[x] == x)return x;
	else return par1[x] = find1(par1[x]);
}
int find2(int x) {
	if (par2[x] == x)return x;
	else return par2[x] = find2(par2[x]);
}
void unite1(int x, int y) {
	x = find1(x);
	y = find1(y);
	if (x == y)return;
	if (rank1[x] < rank1[y]) {
		par1[x] = y;
	} else {
		par1[y] = x;
		if (rank1[x] == rank1[y])rank1[x]++;
	}
}
void unite2(int x, int y) {
	x = find2(x);
	y = find2(y);
	if (x == y)return;
	if (rank2[x] < rank2[y]) {
		par2[x] = y;
	} else {
		par2[y] = x;
		if (rank2[x] == rank2[y])rank2[x]++;
	}
}

int n, k, l, p, q;

int main() {
	cin >> n >> k >> l;
	init(n);
	for (int i = 0; i < k; i++) {
		cin >> p >> q;
		unite1(p - 1, q - 1);
	}
	for (int i = 0; i < l; i++) {
		cin >> p >> q;
		unite2(p - 1, q - 1);
	}
	for (int i = 0; i < n; i++) {
		road[i] = find1(i);
		train[i] = find2(i);
	}
	map<pair<int, int>, int>mp;
	for (int i = 0; i < n; i++) {
		mp[pair<int, int>(road[i], train[i])]++;
	}
	for (int i = 0; i < n; i++) {
		cout << mp[pair<int, int>(road[i], train[i])] << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 17024
n, m = map(int, input().split())
c = [0] * m
for i in range(n):
    k, *a = map(int, input().split())
    # print(a)
    for e in a:
        c[e-1] += 1

ans = 0
for i in range(m):
    if c[i] == n:
        ans += 1

print(ans)

Measured memory_bytes: 3060
H, W = map(int, input().split())
a = [list(input()) for i in range(H)]
jud = [0] * W

for i in a:
    for j in range(W):
        if i[j] == '#':
            jud[j] += 1
        else:
            continue

b = [i for i in a if '#' in i]

for i in range(len(b)):
    ans = ''
    for j in range(W):
        if jud[j] != 0:
            ans += b[i][j]
        else:
            continue
    print(ans)

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

const int N=1e5+5,Mo=1e9+7;

int n,sum[N],f[N],nxt[N][3];
char s[N];

void inc(int &x,int y) {x=x+y>=Mo?x+y-Mo:x+y;}

int main() {
	scanf("%s",s+1);n=strlen(s+1);
	bool ok=0;
	fo(i,1,n-1) if (s[i]==s[i+1]) {ok=1;break;}
	if (!ok) {puts("1");return 0;}
	sum[0]=0;fo(i,1,n) sum[i]=(sum[i-1]+((s[i]=='a')?1:2))%3;
	fo(i,0,2) nxt[n][i]=n+1;
	fd(i,n-1,0) {
		fo(j,0,2) nxt[i][j]=nxt[i+1][j];
		nxt[i][sum[i+1]]=i+1;
	}
	f[0]=1;int ans=0;
	fo(i,0,n) {
		fo(j,1,2) inc(f[nxt[i][(sum[i]+j)%3]],f[i]);
		if (i&&sum[i]==sum[n]) inc(ans,f[i]);
	}
	printf("%d\n",ans);
	return 0;
}



Measured memory_bytes: 2176
// lannisters don't act like fools
#include <bits/stdc++.h>

using namespace std;
#define yah_faster_baby ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD 1000000007









void solve() {
    int x;
    map<int, int>mp;
    int count = 0;
    for (int i = 1; i <= 100; i++) {
        for (int j = 1; j <= 100; j++) {
            for (int k = 1; k <= 100; k++) {
                x = (i * i) + (j * j) + (k * k) + (i * j) + (j * k) + (i * k);
                mp[x]++;
            }
        }
    }
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
        cout << mp[i] << endl;

}



int main() {
    yah_faster_baby
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
#endif // ONLINE_JUDGE
    solve();
    return 0;
}


Measured memory_bytes: 5452
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
const Int MOD = 1000000007;
int main() {
    int N; cin >> N;
    vector<Int> A(N); for (auto &a : A) cin >> a;
    vector<Int> TWO(60);
    TWO[0] = 1;
    for (int i = 1; i < 60; i++) {
        TWO[i] = (TWO[i - 1] * 2) % MOD;
    }
    Int ans = 0;
    for (int i = 0; i < 60; i++) {
        Int d = 1LL << i;
        int cnt = 0;
        for (auto a : A) if (a & d) cnt++;
        ans = (ans + TWO[i] * cnt % MOD * (N - cnt)) % MOD;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define dum(x) cout<<#x<<'='<<x<<endl
#define ll long long
using namespace std;

int main() {

  int n;
  cin >> n;
  vector<string> v(n);
  for (int i = 0; i < n; ++i) {
    cin >> v.at(i);
  }
  bool ans = true;

  for (int i = 0; i < n - 1; ++i) {
    if (v.at(i).at(v.at(i).length() - 1) != v.at(i + 1).at(0)) {
      ans = false;
    }
  }

  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < i; ++j) {
      if (v.at(i) == v.at(j)) {
        ans = false;
      }
    }
  }


  if (ans)
  cout << "Yes" << endl;
  else
  cout << "No" << endl;
}


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

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++)
    {
        cin >>a.at(i);
    }
    
    vector<int> r_g(n + 1);
    r_g.at(n) = 0;
    for(int i = n - 1; i >= 0; i--)
    {
        r_g.at(i) = gcd(r_g.at(i + 1), a.at(i));
    }
    
    int ans = r_g.at(0);
    int g = 0;
    for(int i = 1; i <= n; i++)
    {
        ans = max(ans, gcd(g, r_g.at(i)));
        g = gcd(g, a.at(i - 1));
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;

int arr[4],n;
double dp[305][305][305];
double dfs(int a,int b,int c)
{
    if(a==0&&b==0&&c==0) return 0;
    if(dp[a][b][c]>0) return dp[a][b][c];
    double ans = 1.0*n/(a+b+c);
    if(a) ans+=(1.0*a/(a+b+c))*dfs(a-1,b,c);
    if(b) ans+=(1.0*b/(a+b+c))*dfs(a+1,b-1,c);
    if(c) ans+=(1.0*c/(a+b+c))*dfs(a,b+1,c-1);
    return dp[a][b][c] = ans;
}
int main()
{
    int d;
    scanf("%d",&n);
    for(int i = 1;i<=n;++i)
    {
        scanf("%d",&d);
        arr[d]++;
    }
    printf("%.10f\n",dfs(arr[1],arr[2],arr[3]));
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}



Measured memory_bytes: 219392
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(){
    ll n, m; cin >> n >> m;

    if(m >= 2*n){
        cout << n + (m - 2*n)/4 << endl;
    }
    else{
        cout << m/2 << endl;
    }
}

Measured memory_bytes: 256
import heapq
import sys
def input():
	return sys.stdin.readline()[:-1]

MOD = 10**9+7
class DijkstraList():
	#隣接リスト版
	#同一頂点の複数回探索を防ぐため訪問した頂点数を変数cntで持つ
	def __init__(self, adj, start):
		self.list = adj
		self.start = start
		self.size = len(adj)

	def solve(self):
		self.dist = [float("inf") for _ in range(self.size)]
		self.dist[self.start] = 0
		self.dp = [0 for _ in range(self.size)]
		self.dp[self.start] = 1
		#self.prev = [-1 for _ in range(self.size)]
		self.q = []
		self.cnt = 0

		heapq.heappush(self.q, (0, self.start))

		while self.q and self.cnt < self.size:
			u_dist, u = heapq.heappop(self.q)
			if self.dist[u] < u_dist:
				continue
			for v, w in self.list[u]:
				if self.dist[v] > u_dist + w:
					self.dist[v] = u_dist + w
					self.dp[v] = self.dp[u]
					#self.prev[v] = u
					heapq.heappush(self.q, (self.dist[v], v))
				elif self.dist[v] == u_dist + w:
					self.dp[v] += self.dp[u]
					self.dp[v] %= MOD

			self.cnt += 1
		#print(self.dp)
		return

	def distance(self, goal):
		return self.dist[goal]

	def get_dp(self, x):
		return self.dp[x]

n, m = map(int, input().split())
s, t = map(int, input().split())
s, t = s-1, t-1
adj = [[] for _ in range(n)]
for _ in range(m):
	u, v, d = map(int, input().split())
	adj[u-1].append([v-1, d])
	adj[v-1].append([u-1, d])
S, T = DijkstraList(adj, s), DijkstraList(adj, t)
S.solve()
T.solve()
ans = pow(S.get_dp(t), 2, MOD)
goal = S.distance(t)
#print(ans, goal)

for i in range(n):
	SI, TI = S.distance(i), T.distance(i)
	if SI + TI != goal:
		continue
	if SI*2 == goal:
		ans -= S.get_dp(i) * T.get_dp(i) * S.get_dp(i) * T.get_dp(i)
		ans %= MOD

	else:
		for j, d in adj[i]:
			if i>j:
				continue
			SJ, TJ = S.distance(j), T.distance(j)
			if SJ + TJ != goal or abs(SI - SJ) != d:
				continue
			if SI*2 < goal < SJ*2:
				#print(i, j, SI, SJ)
				ans -= S.get_dp(i) * T.get_dp(j) * S.get_dp(i) * T.get_dp(j)
				ans %= MOD
			elif SJ*2 < goal < SI*2:
				#print(i, j, SI, SJ)
				ans -= S.get_dp(j) * T.get_dp(i) * S.get_dp(j) * T.get_dp(i)
				ans %= MOD

print(ans)

Measured memory_bytes: 123296
#include<bits/stdc++.h>
using namespace std;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n,k,a=0;
	string s;
	cin>>n>>k>>s;
	for(int i=0;i<n;i++)
		if(s[i]==s[i+1])
			a++;
	cout<<min(n-1,a+2*k)<<endl;
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
	int n;
	while(scanf("%d",&n)==1){
		int v[n],c[n],i,sum=0;
		for(i=0;i<n;i++)
		scanf("%d",&v[i]);
		for(i=0;i<n;i++)
		scanf("%d",&c[i]);
		for(i=0;i<n;i++){
			v[i]=v[i]-c[i];
			if(v[i]>0)
			sum+=v[i];
		}
		printf("%d",sum);
	}
	return 0;
}

Measured memory_bytes: 256
N = int(input())
T = list(map(int, input().split()))
M = int(input())
PX = [list(map(int, input().split())) for _ in range(M)]
for i in range(M):
  s = 0
  for j in range(N):
    if j+1 == PX[i][0]:
      s += PX[i][1]
    else:
      s += T[j]
  print(s)


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

int main() {
  string s;
  int l, r;
  cin >> s;

  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'A') {
      l = i;
      break;
    }
  }
  for (int i = 0; i < s.size(); i++) {
    if (s[s.size() - 1 - i] == 'Z') {
      r = s.size() - 1 - i;
      break;
    }
  }

  cout << r - l + 1 << endl;
}


Measured memory_bytes: 644
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;


signed main()
{
    int a, b;
    cin >> a >> b;
    if (a % 3 == 0 || b % 3 == 0 || (a+b)%3==0){
        cout << "Possible" << endl;
    }
    else{
        cout << "Impossible" << endl;
    }

        return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long A, B;
    cin >> A >> B;

    if(A % 2 != B % 2) {
        cout << "IMPOSSIBLE" << endl;
    } else {
        cout << (A + B) / 2 << endl;
    }

    return 0;
}


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

using namespace std;

int main()
{
  string S; cin >> S;
  vector<int> a(S.size(), 0);
  for (int i = 0, len = S.size(); i < len; ++i) {
    if (S[i] == 'A' or S[i] == 'C' or S[i] == 'G' or S[i] == 'T') a[i]++;
  }

  int t = 0, ans = 0;
  for (int i = 0, len = S.size(); i < len; ++i) {
    if (a[i] == 1) {
      t++;
      ans = max(ans, t);
    }
    else t = 0;
  }

  cout << ans;
}


Measured memory_bytes: 256
N = int(input())
A = [0 for i in range(N)]
for i in range(N):
    A[i] = int(input())
B = sorted(A)
maxA = B[-1]
smaxA = B[-2]
for i in range(N):
    if A[i] == maxA:
        print(smaxA)
    else:
        print(maxA)

Measured memory_bytes: 14104
import sys
iN = int(input())
aA = [int(_)//400 for _ in input().split()]

aCol = [0]*(4800//400 +1)
for a in aA:
    aCol[a] += 1
iMin = 0
for i in range(8):
    if aCol[i]:
        iMin += 1
iMax = iMin + sum(aCol[8:])
if iMin == 0:
    iMin = 1
print(iMin,iMax)


Measured memory_bytes: 3060