akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

int M, T, P, R;
const int PENALTY = 20;

struct team {
	int ac, time, id;
	vector<int> wrong;
	team(int id):ac(0), time(0), id(id), wrong(P, 0){}

	bool operator<(const team& t) const {
		if(ac != t.ac)
			return ac < t.ac;

		if(time != t.time)
			return time > t.time;

		return id < t.id;
	}

	bool operator==(const team& t) const {
		return ac == t.ac && time == t.time;
	}

	void accept(int p_id, int t) {
		++ac;
		time += wrong[p_id] * PENALTY + t;
	}

	void wrong_answer(int p_id) {
		++wrong[p_id];
	}
};

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

	while(cin >> M >> T >> P >> R, M) {
		vector<team> teams;
		teams.reserve(T);

		for(int i = 1; i <= T; ++i) {
			teams.push_back(team(i));
		}

		for(int i = 0; i < R; ++i) {
			int m, t, p, j;
			cin >> m >> t >> p >> j;

			if(j == 0) {
				teams[t - 1].accept(p - 1, m);
			}
			else {
				teams[t - 1].wrong_answer(p - 1);
			}
		}

		sort(teams.rbegin(), teams.rend());
		for(int i = 0; i < T; ++i) {
			cout << teams[i].id;
			if(i == T - 1) {
				cout << endl;
			}
			else {
				if(teams[i] == teams[i + 1])
					cout << '=';
				else
					cout << ',';
			}
		}
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1240
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define ff              first
#define ss              second
#define ll 				long long int
#define int             long long int
#define pb              push_back
// #define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define modp            998244353
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
#define FIO           	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl 			'\n'
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
// void aks()
// {
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
// }

map<int, int> mp;
void solve()
{
	int n; cin >> n;
	while(n%2 == 0)
	{
		mp[2]++;
		n = n/2;
	}
	for(int i = 3; i*i <= n; i+=2)
	{
		if(n%i == 0)
		{
			while(n%i == 0)
				{n = n/i;
				mp[i]++;}
		}
	}
	if (n > 2)  
        mp[n]++;
    int x = mp.size();
    int cc = 0;
    for(auto it = mp.begin(); it != mp.end(); it++)
    {
    	int i = 1;
    	int curr = it->second;
    	while(true)
    	{
    		curr = curr-i;
    		if(curr >= 0)
    		{
    			cc++;
    			i++;
    		}
    		else
    			break;
    	}
    }
    cout << cc << endl;
}
 
int32_t main()
{
	FIO
    //aks();
   // w(t)
    {
    	solve();
    }
    return 0;
}
	

Measured memory_bytes: 3656
#include<stdio.h>
main(){
	int a,b,i,j=9,high[10],tmp;
	for(b=0;b<10;b++){
	scanf("%d",&a);
		high[b]=a;
	}
	for(i=0;i<9;i++){
		for(j=9;j>i;j--){
			if(high[j]<high[j-1]){
			tmp=high[j];
			high[j]=high[j-1];
			high[j-1]=tmp;
			}
		}
	}
	printf("%d\n%d\n%d\n",high[9],high[8],high[7]);
        return 0;
}

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

int main()
{
	int n,k,i,x;
	scanf("%d %d",&n,&k);
	for (i=1;i<=n;i++) scanf("%d",&x);
	printf("%d\n",(int)ceil(1.0*(n-1)/(k-1)));
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_DEPRECATE
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define int long long int
#define SYNC std::ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define FRE freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
typedef long double ld;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii>   vii;
//typedef tree<int, null_type, less<int>, rb_tree_tag, 
//             tree_order_statistics_node_update> 
//    data_set;
#define rep(i,l,r)   for(int i=(l);i<(r);i++)
#define deb(x)     cout << (#x) << " = " << (x) << endl
#define here cout << " Hey!!\n";
#define  pb push_back
#define  F  first
#define  S  second
#define all(v) (v).begin(),(v).end()
#define sz(a) (int)((a).size())
#define sq(x) ((x)*(x))
const int MOD = 1e9+7;
const int MOD1 = 998244353;
const int N = 2e5+5;
const int INF = 1000111000111000111LL;
const ld EPS = 1e-12;
const ld PI = 3.141592653589793116;

int32_t main()
{
	SYNC
	int n; cin >> n;
	map<int,int> dp;
	int cur_sum = 0;
	for(int x, i = 0; i < n; i++) {
		cin >> x;
		dp[x]++;
		cur_sum += x;
	}
	int Q; cin >> Q;
	while(Q--)
	{
		int x, y;
		cin >> x >> y;
		cur_sum += (y-x)*dp[x];
		dp[y] += dp[x];
		dp[x] -= dp[x];
		cout << cur_sum << '\n';
	}
	return 0;
}

Measured memory_bytes: 9468
import bisect

n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0

for x in range(n):
    for y in range(x + 1, n - 1):
        ans += bisect.bisect_left(l, l[x] + l[y]) - y - 1

print(ans)

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

/**
 * Created on 2017/10/20 7:19.
 */
public class Main {
    static int N;

    static boolean isReachable(boolean used[], boolean[][] t, int pos, int cutFrom, int cutTo) {
        if (pos == cutTo) {
            return true;
        }
        used[pos] = true;
        for (int i = 0; i < N; i++) {
            if (!used[i] && t[pos][i] && !(pos == cutFrom && i == cutTo) && isReachable(used, t, i, cutFrom, cutTo)) {
                return true;
            }
        }
        return false;
    }

    public static void main(String[] args) throws IOException {
        // BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        Scanner sc = new Scanner(System.in);

        while (sc.hasNextInt()) {
            N = sc.nextInt();
            int M = sc.nextInt();
            boolean[][] t = new boolean[N][N];
            for (int i = 0; i < M; i++) {
                int a = sc.nextInt() - 1;
                int b = sc.nextInt() - 1;
                t[a][b] = t[b][a] = true;
            }
            int ans = 0;
            for (int i = 0; i < N; i++) {
                for (int j = i + 1; j < N; j++) {
                    if (!t[i][j]) {
                        continue;
                    }
                    boolean used[] = new boolean[N];
                    if (!isReachable(used, t, i, i, j)) {
                        ans++;
                    }
                }
            }
            System.out.println(ans);
        }
    }
}


Measured memory_bytes: 23636
while 1:
    try:
        weight = float(input())
    except:
        break

    if weight <= 48:
        print("light fly")
    elif 48 < weight <= 51:
        print("fly")
    elif 51 < weight <= 54:
        print("bantam")
    elif 54 < weight <= 57:
        print("feather")
    elif 57 < weight <= 60:
        print("light")
    elif 60 < weight <= 64:
        print("light welter")
    elif 64 < weight <= 69:
        print("welter")
    elif 69 < weight <= 75:
        print("light middle")
    elif 75 < weight <= 81:
        print("middle")
    elif 81 < weight <= 91:
        print("light heavy")
    else:
        print("heavy")



Measured memory_bytes: 5576
#include<iostream>
using namespace std;
using lint=long long;
int main(){
  int N; cin>>N;
  lint a[200000];
  for(int i=0;i<N;i++)
    cin>>a[i];
  for(int i=1;i<N;i++)
    a[i]+=a[i-1];
  lint Min=abs(2*a[0]-a[N-1]);
  for(int i=1;i+1<N;i++)
    Min=min(Min,abs(2*a[i]-a[N-1]));
  cout<<Min<<endl;
  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <list>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

/*
// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

// 最小公倍数
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}
*/

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

	int n;
	cin >> n;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];

	// aを昇順にしたい
	// 自身を足すこともできる

	// nは最大で50

	// 2N回以下ってのは肝なのかも

	vector<pair<ll, ll>> ans;
	// 隣り合う要素を合わせていきたい
	// 負の数があるのがきつい
	// 全部正の数にすればいいのでは？？？

	// どちらか絶対値が大きいほうの符号に合わせる
	ll plusMax = 0;
	ll minusMax = 0;
	rep(i, n) {
		if (a[i] >= 0) plusMax = max(plusMax, a[i]);
		else minusMax = max(minusMax, -a[i]);
	}
	bool adjustPlus;
	adjustPlus = (plusMax >= minusMax);
	// そのインデックスを保存する
	int theIndex;
	rep(i, n) {
		if (adjustPlus) {
			if (a[i] == plusMax) theIndex = i;
			else a[i] += plusMax;
		}
		else {
			if (a[i] == -minusMax) theIndex = i;
			else a[i] -= minusMax;
		}
	}

	rep(i, n) {
		if (adjustPlus) {
			if (a[i] != plusMax)
				ans.push_back({ theIndex + 1, i + 1 });
		}
		else {
			if (a[i] != -minusMax)
				ans.push_back({ theIndex + 1, i + 1 });
		}
	}

	if (adjustPlus) {
		rep(i, n - 1) {
			// 右側をどんどん大きくする
			//if (a[i] > a[i + 1]) {
			//	a[i + 1] += a[i];
				ans.push_back({ i + 1, i + 2 });
			//}

		}
	}
	else {
		for (int i = n - 1; i > 0; i--) {
			// 左側をどんどん小さくする
			//if (a[i - 1] > a[i]) {
			//	a[i - 1] += a[i];
				ans.push_back({ i + 1, i });
			//}
		}
	}

	cout << (int)ans.size() << endl;
	rep(i, (int)ans.size()) {
		cout << ans[i].first << " " << ans[i].second << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  int N;
  cin >> N;
  vector<int> d;
  rep(i,N){
    int a;
    cin >> a;
    d.push_back(a);
  }

  ll ret = 0;
  rep(i,N){
    REP(j,i+1,N){
      ret += d[i] * d[j];
    }
  }

  cout << ret << endl;
  
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bool mark[1000];
bool marv[1000];
int main(){
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int n;
int m;
cin>>n>>m;
char v[n][m];
for(int i=0;i<n;i++){
           for(int j=0;j<m;j++){
                      cin>>v[i][j];
           }
}
int r=0;
for(int i=0;i<n;i++){
           r=0;
           for(int j=0;j<m;j++){
                      if(v[i][j]=='#'){
                                 j=m+2;
                                 r=1;
                      }
           }
           if(r==0){
                      mark[i]=true;
           }
           
}
for(int i=0;i<m;i++){
           r=0;
           for(int j=0;j<n;j++){
           if(v[j][i]=='#'){
                      j=n+2;
                      r=1;
           }           
           }
           if(r==0){
                      marv[i]=true;
           }
}
for(int i=0;i<n;i++){
           r=0;
           for(int j=0;j<m;j++){
                      if(mark[i]==false&&marv[j]==false){
                                 cout<<v[i][j];
                                 r=1;
                      }
           }
           if(r==1){
                      cout<<endl;
           }
}
return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main (String [] args) {
		Scanner scan = new Scanner (System.in);
		int n = scan.nextInt();
		int data[] = new int[n];
		int min, count = 0, a;
		
		for (int i = 0; i < n; i++) {
			data[i] = scan.nextInt();
		}
		scan.close();
		
		for (int i = 0; i < n - 1; i++) {
			min = i;
			for ( int j = i + 1; j < n; j++) {
				if (data[min] > data[j]) min = j;
			}
			if ( i != min) {
				a = data[i];
				data[i] = data[min];
				data[min] = a;
				count++;
			}
		}
		
		for (int i = 0; i < n; i++) {
			if (i == n - 1) {
				System.out.println(data[i]);
				System.out.println(count);
			} else {
				System.out.print(data[i] + " ");
			}
		}
	}
}



Measured memory_bytes: 26500
#define LOCAL
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char c) {return to_string((string) &c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    auto c = [&](ll x){
        if(x == 1){
            bool ok = true;
            rep(i,n-1)ok &= a[i+1] > a[i];
            return ok;
        }
        map<ll,ll> mp;
        reps(i,n-1){
            if(a[i] > a[i-1])continue;
            mp[a[i]]++;
            auto itr = mp.find(a[i]);
            itr++;
            mp.erase(itr, mp.end());
            if(mp[a[i]] == x){
                ll t = a[i];
                while(mp[t] >= x){
                    mp[--t]++;
                    mp.erase(t+1);
                }
            }
        }

        return mp.count(0) == 0;
    };

    ll ok = 2e5+10;
    ll ng = 0;

    while(abs(ok - ng) > 1){
        ll x = (ok + ng) / 2;
        if(c(x))ok = x;
        else ng = x;
    }

    cout << ok << endl;
    return 0;
}

Measured memory_bytes: 1920
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define INF 9999999
#define LINF 99999999999
//#define ARRAY(type,n) (type *)malloc(sizeof(type)*n)
template<typename T>
T* ARRAY(int n){
	(T*)malloc(sizeof(T)*n);
}
template<typename T>
T** ARRAY2(int m,int n){
	T** type = (T**)malloc(sizeof(T*)*m);
	for(int i=0;i<m;i++){
		type[i]=(T*)malloc(sizeof(T)*n);
	}
	return type;
}

bool cmp(pair<ll,ll> l, pair<ll,ll> r){
	return l.first<r.first;
}

vector<ll> lnum;

vector<ll> memo;

//L_n = 2*L_(n-1) +3
ll func(int n, ll x){
	if(lnum[n]-1 <= x){
		return memo[n];
	}
	if(n==0){
		return 1;
	}
	if(x<=1){
		return 0;
	}
	ll retval = 0;
	if(x <= lnum[n-1]+1){
		return func(n-1,x-1);
	}
	retval += memo[n-1];
	retval += 1;
	if(x == lnum[n-1]+2){
		return retval;
	}
	retval += func(n-1,x-2-lnum[n-1]);
	return retval;
}


 
int main(void){
	ll n,x,tmp;
	cin>>n>>x;
	lnum.push_back(1);
	memo.push_back(1);
	rep(i,n){
		lnum.push_back(lnum[i]*2 + 3);
		memo.push_back(memo[i]*2 + 1);
	}
	cout<<func(n,x)<<endl;

	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		long x = sc.nextLong();
		long ans = cal(x);
		System.out.println(ans);
	}
	
	static long cal(long x) {
		long a = x/500;
		long b = (x%500)/5;
		long ans = a*1000 + b*5;
		return ans;
	}
	
	static class FastScanner {
		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;
	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

	    public String next() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public String nextLine() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                return reader.readLine();
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }

	        return tokenizer.nextToken("\n");
	    }

	    public long nextLong() {
	        return Long.parseLong(next());
	    }

	    public int nextInt() {
	        return Integer.parseInt(next());
	    }

	    public double nextDouble() {
	         return Double.parseDouble(next());
	     }

	    public int[] nextIntArray(int n) {
	        int[] a = new int[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextInt();
	        return a;
	    }

	    public long[] nextLongArray(int n) {
	        long[] a = new long[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextLong();
	        return a;
	    }
	}
}

Measured memory_bytes: 22868
#include <bits/stdc++.h>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <utility>
#include <algorithm>
#include <functional>
#include <vector>
#include <iostream>
typedef long long ll;
typedef int64_t in;
using namespace std;
#define INF 1000000007


int main() {
	int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    int count=0;
    for(int i=0; i<n; i++){
        int minj = i;
        for(int j=i; j<n; j++){
            if(a[j] < a[minj]){
                minj = j;
            }
        }
        if(i != minj){
            swap(a[i], a[minj]);
            count++;
        }
    }
    for(int i=0; i<n; i++){
        if(i!=n-1) cout << a[i] << " ";
        else cout << a[i];
    }
    cout << endl;
    cout << count << endl;
}


Measured memory_bytes: 3092
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        self.size = [1] * (n+1)
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    def same_check(self, x, y):
        return self.find(x) == self.find(y)
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

n, m = map(int, input().split())
uf = UnionFind(n)

for i in range(m):
    a, b = map(int, input().split())
    uf.union(a, b)

max = 1
for size in uf.size:
    if size > max:
        max = size

print(max)

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

def maxHeapify(A: list, i: int):
    H = len(A) - 1
    l = 2 * i
    r = l + 1
    if l <= H and A[l] > A[i]:
        largest = l
    else:
        largest = i
    if r <= H and A[r] > A[largest]:
        largest = r
    if largest != i:
        A[i], A[largest] = A[largest], A[i]
        maxHeapify(A, largest)
    return

def buildMaxHeap(A: list):
    H = len(A) - 1
    for i in range(H//2, 0, -1):
        maxHeapify(A, i)
    return

def main():
    H = int(input())
    A = [0] + list(map(int, input().split()))
    buildMaxHeap(A)
    for i in range(1, H+1):
        print(' {}'.format(A[i]), end='')
    print()

if __name__ == '__main__': main()


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



int main()
{
    ll h,w,x=1000000,a,b,c,y,z;
    cin>>h>>w;
    for(int i=1;i<h;i++){
        a=i*w;
        b=floor((h-i)/2.0)*w;
        c=ceil((h-i)/2.0)*w;
        y=max({a,b,c});
        z=min({a,b,c});
        x=min(x,y-z);
        b=floor(w/2.0)*(h-i);
        c=ceil(w/2.0)*(h-i);
        y=max({a,b,c});
        z=min({a,b,c});
        x=min(x,y-z);
    }
    swap(h,w);
    for(int i=1;i<h;i++){
        a=i*w;
        b=floor((h-i)/2.0)*w;
        c=ceil((h-i)/2.0)*w;
        y=max({a,b,c});
        z=min({a,b,c});
        x=min(x,y-z);
        b=floor(w/2.0)*(h-i);
        c=ceil(w/2.0)*(h-i);
        y=max({a,b,c});
        z=min({a,b,c});
        x=min(x,y-z);
    }
    cout<<x<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize(3 , "Ofast" , "inline")
using namespace std ;
typedef long long ll ;
typedef pair<int , int> PII ;
const int N = 1e5 + 10 , INF = 0x3f3f3f3f , mod = 1e9 + 7;

int main()
{
  int a , b ;
  cin >> a >> b ;
  if(a <= b) puts("unsafe") ;
  else puts("safe") ; 

  return 0 ;
}


Measured memory_bytes: 3636
/*-------enazuma11----------------*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(v) v.begin(),v.end()
#define inc(a,n) sort(a,a+n)
#define dec(a,n) sort(a,a+n,greater<int>() )
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define F first
#define S second
#define M 1000000007
 
/* int x[]={-1,-1,0,1,1,1,0,-1};
int y[]={0,1,1,1,0,-1,-1,-1};
*/
/* int x[]={-1,0,1,0};
int y[]={0,1,0,-1};
*/

void solve()
{
	ll n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	ll i,j;
	ll ans=0;
	ll c=0;
	rep(i,0,n-1){
		if(s[i]==s[i+1]){
			ans++;
		}else
		c++;
	}
	ans+=min(c,k*2);
	cout<<ans;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int t=1;
//	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 512
import java.util.*;
import java.lang.*;

public class Main{
    
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        int[] p = new int[5];
        
        for (int i = 0; i < 5; i++) {
            p[i] = sc.nextInt();
        }
        
        int k = sc.nextInt();
        
        boolean ans = true;
        
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 5; j++) {
                if (Math.abs(p[i] - p[j]) > k) {
                    ans = false;
                }
            }
        }
        
        System.out.println(ans?"Yay!":":(");

    }
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
//Remove below header file if c++ version greater than 14
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;

#define pb push_back
#define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define endl '\n'
#define deb(x) cout << #x << " "<< x << endl;
#define fo(i, n) for(int i=0; i<n; i++)
#define Fo(i, k, n) for(int i=k; i<n; i++)

struct greaterr
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};

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

ll lcm(ll a, ll b) {
	return a /gcd(a, b) *b;
}
typedef pair<int,int> pii;
const int mod = 1e9+7;

ll xorr(ll n){

    if(n%4==0)
        return n;

    else if(n%4==1)
        return 1;

    else if(n%4==2)
        return n+1;

    else
        return 0;



}


int main() {

   int n;
   cin>>n;

   vector<int> v(n);

   fo(i,n)
      cin>>v[i];

    vector<int> left(n+1,0),right(n+1,0);

    fo(i,n)
    {
        left[i+1] = __gcd(left[i],v[i]);
        right[i+1] = __gcd(right[i],v[n-i-1]);
    }

    int maxx = INT_MIN;

    fo(i,n+1)
    maxx = max(maxx,__gcd(left[i],right[n-i-1]));

    cout<<maxx;





















    return 0;

      }


Measured memory_bytes: 1408
import java.awt.*;
import java.util.*;
public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int  n = sc.nextInt();
        int arr[] = new int[1000];
        arr[0] =1;
        arr[1] = 6;
        arr[2] = 9;
        int j=2;
        for(int i=3;i<500;i++){
            arr[i] = (int)Math.pow(6,j++);
        }
        j=2;
        for(int i=500;i<1000;i++){
            arr[i] =(int) Math.pow(9,j++);
        }
        Arrays.sort(arr);
        
        int dp[] = new int[n+1];
        
        
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;
        
        for(int i=1;i<=n;i++){
            for(int jj=0;jj<=15;jj++){
                if(arr[jj]<=i){
                    if(dp[i-arr[jj]]!=Integer.MAX_VALUE){
                        dp[i] = Math.min(dp[i-arr[jj]]+1, dp[i]);
                    }
                }
            }
        }
        
        System.out.println(dp[n]);
        
    }
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repd(i,a,b) for (int i = (a); i < (b); i++)
#define INF LLONG_MAX
#define mod 1000000007
typedef long long ll;
int main(void)
{
	int N, a, b, count=1;
	cin >> N;
	vector<int> J(N);
	vector<int> P(N);
	vector<int> Q(N);
	rep(i, N) J.at(i) = i+1;
	rep(i, N) cin >> P.at(i);
	rep(i, N) cin >> Q.at(i);
	do
	{
		if(P==J) a = count;
		if(Q==J) b = count;
		count++;
	}while(next_permutation(J.begin(), J.end()));
	cout << abs(a-b) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define     mod             1000000007
#define     IOS             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define     endl            "\n" 
#define     ll              long long int 
#define     vi              vector<int> 
#define     vvi             vector<vector<int>>
using namespace std;

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


void solve(){
	
	int n;
	cin>>n;
	int xr = 0;
	vi v(n);
	for(int i=0;i<n;i++){
		cin>>v[i];
		xr = xr ^ v[i];
	}
	for(int i=0;i<n;i++){
		cout<<(xr^v[i])<<" ";
	}


}
 

int32_t main()
{

  
    IOS;

    solve();

}

Measured memory_bytes: 3940
#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define ld long double
#define ff first
#define ss second
const ll mod =   1e9 +7  ;
ll multiply(ll a, ll b ){ return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b) {     return ((a % mod) + (b % mod)) % mod; }
ll sub(ll a, ll b) { return ((a%mod) - (b % mod)+ mod) % mod ; }
////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////
void solve(){
  string s ;
  cin >> s ;
  if(s=="ABC") cout << "ARC" ;
  else cout << "ABC" ;

}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1 ;
    //cin >> t ;
    while(t--){
        solve( );
    }
}


Measured memory_bytes: 3676
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
import java.util.TreeMap;



 class Main{
	 
	 
	 
	

	public static void main(String[] args) throws IOException {
		
		
		FastScanner sc=new FastScanner();
		
		int n = sc.nextInt();
		long hi[] = new long[n+1];
		for(int i=0; i<n; i++)
			hi[i+1] = sc.nextLong();
		long dp[] = new long[n+1];
		
		dp[1] = 0;
		dp[2] = Math.abs(hi[1]-hi[2]);
		
		for(int i=3; i<n+1; i++) {
			dp[i] = Math.min(dp[i-2] + Math.abs(-hi[i]+hi[i-2]), dp[i-1] +Math.abs(-hi[i]+hi[i-1]));
		}
		
		System.out.println(dp[n]);
		
				
	}
	
	
	
	
 
	static void sort(int[] a) {
		ArrayList<Integer> l=new ArrayList<>();
		for (int i:a) l.add(i);
		Collections.sort(l);
		for (int i=0; i<a.length; i++) a[i]=l.get(i);
	}
	
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long[] readArrayLong(int n) {
        	long[] a=new long[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
        }
		long nextLong() {
			return Long.parseLong(next());
		}
		String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
	}
}


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

int main() {
  int N,i,sum = 0;
  cin >> N;
  int B[N-2];
  for(int i=0;i<N-1;i++){
  	cin >>B[i];
  }
  sum += B[N-2]+B[0];
  i = N-2;
  while(i>0){
  	if(B[i-1]>=B[i]){
    	sum += B[i];
    }
    else{
    	sum += B[i-1];	
    }
   i--;
  }
   cout << sum << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
int main(void){
int N,M,sum,i,p_count=0,a_count=0;
scanf("%d" "%d",&N,&M);
char S[M][3];
int p[M];
int flag[N],Z[N];
  for (i=0;i<N;i++){
    flag[i]=0;
    Z[i]=0;
  }
for (i=0;i<M;i++){
scanf("%d" "%s",&p[i],S[i]);
if (strcmp(S[i],"WA")==0){
	if(flag[p[i]-1]==0){
		Z[p[i]-1]++;
	}
}
else {
	if(flag[p[i]-1]==0){
		a_count++;
		flag[p[i]-1]=1;
      	p_count=p_count+Z[p[i]-1];
	}
}
}
printf("%d" " %d" ,a_count, p_count);
}

Measured memory_bytes: 1664
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include <numeric>
#include<queue>
#include<climits>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
//#define INF LLONG_MAX / 2;
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;
typedef pair<ll,int> LL_IP;

const ll INF = 1e9;

#define ARRAY_MAX 100005


typedef struct edge{

    int to;
    int cost;

}EDGE;

vector<ll> dijkstra(int n,vector<vector<EDGE> >& G,int x){

    /*最終的にdは経由点からの最短距離が格納される、その過程では暫定的な最短距離が格納され、最短距離が見つかれば、その都度更新される*/

    vector<ll> d(n,INF);/*最終的な最短距離を保持、初期化はINF*/
    d[x] = 0;
    priority_queue<LL_IP,vector<LL_IP>,greater<LL_IP> > que;/*vectorのpriority_queueで暫定的な最短距離が小さい順に取り出す*/
    que.push(LL_IP(0,x));/*経由点からダイクストラを適用するので経由点の暫定的な最短距離のコストは0*/

    while(!que.empty()){/*queが空になれば最短距離が全て探索できたことになる*/

        LL_IP p = que.top();/*最短距離の１番小さいものの取り出し*/
        que.pop();/*取り出したので調べたとみなし、queから出す*/
        int v = p.second;/*取り出した頂点の番号*/
        if(d[v] < p.first){
            /*取り出した頂点からの最短距離よりも短い経路があるので更新の必要はない*/
            continue;
        }

        for(int i = 0;i < G[v].size(); i++){
            /*取り出した頂点から辺でつながっている頂点への最短距離を調べて現在の値より短ければ更新する*/
            EDGE e = G[v][i];/*取り出した頂点からつながっている頂点を1つ取り出す*/
            if(d[e.to] > d[v] + e.cost){
                /*現在の最短距離よりも、現在の頂点を経由する経路のほうが最短距離が短い場合は最短距離を更新し、次の頂点を調べる*/
                d[e.to] = d[v] + e.cost;/*最短経路の更新*/
                que.push(P(d[e.to],e.to));/*先の頂点を調べるためqueに格納*/
            }
                    
        }
    }
    return d;
}


/*ABC070 AC解法*/
int main(){

    int n,e,r,a,b,c;
    cin >> n >> e >> r;
    vector<vector<EDGE> > G(n);/*n個の各頂点からそれ以外の頂点へのコスト*/
    REP(i,e){
        cin >> a >> b >> c;
        EDGE e1 = {b,c};
        G[a].pb(e1);/*頂点aから頂点bへのコストがc*/
    }
    /*辺の張り終わり*/

    vector<ll> d = dijkstra(n,G,r);/*経由点から各頂点への最短距離を格納した配列*/

    REP(i,n){
        if(d[i] == INF){
            cout << "INF" << endl;
        }else{
            cout << d[i] << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 14508
# -*- coding: utf-8 -*-
"""
Created on Sun Sep 20 22:44:27 2020

@author: liang
"""

A, B, C = map(int, input().split())

if A > B:
    if B > C:
        m1,m2,m3 = A, B, C
    else:
        if A > C:
            m1,m2,m3 = A, C, B
        else:
            m1,m2,m3 = C, A, B
else:
    if A > C:
        m1,m2,m3 = B, A, C
    else:
        if B > C:
            m1,m2,m3 = B, C, A
        else:
            m1,m2,m3 = C, B, A
ans = 0
ans += m1 - m2
ans += (m2-m3)//2
if (m2-m3)%2 == 1:
    ans += 2
print(ans)

Measured memory_bytes: 8692
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
int N;
string s,a;
string sw = "SW";

bool solve(int i){
	if(i==N+1){
		return a[0]==a[N] && a[1]==a[N+1];
	}

	if((a[i]=='S' && s[i]=='o')||(a[i]=='W' && s[i]=='x')){
		a[i+1]=a[i-1];
	}else{
		if(a[i-1]=='S')a[i+1]='W';
		else a[i+1]='S';
	}
	return solve(i+1);
}

int main(void){	
	cin>>N>>s;
	s += s.substr(0,1);
	a.resize(N+2);
	rep(i,2)rep(j,2){
		a[0]=sw[i];
		a[1]=sw[j];
		if(solve(1)){
			cout<<a.substr(0,N)<<endl;
			return 0;
		}
	}
	cout<<"-1"<<endl;
	return 0;
}


Measured memory_bytes: 640
<?php
fscanf(STDIN, '%s', $s);

$assets = ['dreamer','dream','eraser','erase'];
//var_dump(ltrim('dreamererrrrrrr', 'dreamer'));

while(1) {
    $no_word = 0;
    foreach ($assets as $word) {
        if (substr($s,-strlen($word)) === $word) {
            $s = substr($s, 0, strlen($s) - strlen($word));
        } else {
            $no_word++;
        }
    }
    
    if ($no_word === count($assets)) {
        break;
    }
}


if ($s === '') {
    echo "YES".PHP_EOL;
} else {
    echo "NO".PHP_EOL;
}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  string s,t;cin>>s>>t;
  ll result=0;
  rep(i, s.size()){
    if(s[i]!=t[i])result++;
  }

  cout<<result<<endl;

  return 0;
}


Measured memory_bytes: 3912
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from scipy.sparse.csgraph import floyd_warshall
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations, combinations_with_replacement
from heapq import heappop, heappush, heapify
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7

def main():
    n = int(input())
    ans = [0 for _ in range(n)]
    for x in range(1,n):
        for y in range(1,n):
            for z in range(1,n):
                if x*x+y*y+z*z+x*y+y*z+x*z >= n+1:
                    break
                ans[x*x+y*y+z*z+x*y+y*z+x*z-1] += 1
    for i in range(n):
        print(ans[i])
if __name__ == "__main__":
    main()

Measured memory_bytes: 74080
#include<stdio.h>
int main()
{
  int N,i,k,t;
  while(1){
    t=0;
    scanf("%d",&N);
    if(N==0)break;
    for(i=1;i<N;i++){
      for(k=2;k<100;k++){
	    if(i*k+0.5*k*(k-1)==N)t=t+1;
    }
    }
      printf("%d\n",t);
  }
  return 0;
}
    

Measured memory_bytes: 600
#include <bits/stdc++.h>
#include <iostream>
#include<math.h>
using namespace std;
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; }
int main()
{
    int64_t N;
    cin >> N;
    map<string, int64_t> d;
    for (int64_t i=0; i<N; i++) {
        string s;
        cin >> s;
        if (d.count(s) > 0) {
            d[s] = d[s] + 1;
        } else {
            d[s] = 1;
        }
    }

    cout << "AC x " << d["AC"] << endl;
    cout << "WA x " << d["WA"] << endl;
    cout << "TLE x " << d["TLE"] << endl;
    cout << "RE x " << d["RE"] << endl;
    return 0;
}

Measured memory_bytes: 3628
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;


ll hoge(ll&c, int s, int t, int n)
{
	if(n<=1)
	{
		c+=t-s;
		return c;
	}

	for(int i=s;i<=t;i++)
	{
		hoge(c, i, t, n-1);
	}
	return c;
}


struct Q_t
{
	int a, b, c, d;
};


void ready_i(vvi&a, vi&t, int n, int m, int idx)
{
	for(int i=t[idx-1];i<=m;i++)
	{
		t[idx]=i;
		if(idx==n)
		{
			a.push_back(t);
		}
		else
		{
			ready_i(a, t, n, m, idx+1);
		}
	}
}


void ready(vvi&a, int n, int m)
{
	vi t(n+1);

	t[1]=1;
	ready_i(a, t, n, m, 2);
}


int check(vvi&a, vector<Q_t>&q)
{
	int ans=0;
	for(auto&ma:a)
	{
		int t=0;
		for(auto&mq:q)
		{
			if(ma[mq.b]-ma[mq.a]==mq.c) t+=mq.d;
		}
		ans=max(ans, t);
	}
	return ans;
}


int main(void)
{
	int n, m, q;
	while(scanf("%d%d%d", &n, &m, &q)==3)
	{
		vector<Q_t> Q(q);

		for(int i=0;i<q;i++)
		{
			Q_t&x=Q[i];
			scanf("%d%d%d%d", &x.a, &x.b, &x.c, &x.d);
		}


		vvi A;
		A.reserve(100000);
		ready(A, n, m);
//		printf("A.size()=%u\n", A.size());

		int ans=check(A, Q);
		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 7016
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
static const int INF = 10000000;

pair<vector<int>, bool>
bellman_ford(const vector<vector<vector<int> > >& rules, const vector<int>& seed)
{
  const int N = seed.size();
  vector<int> dist(N, INF);
  for (int i = 0; i < N; i++) {
    if (seed[i]) {
      dist[i] = 1;
    }
  }

  for (int i = 0; i < N; i++) {
    for (int u = 0; u < N; u++) {
      for (vector<vector<int> >::const_iterator it = rules[u].begin(); it != rules[u].end(); ++it) {
        vector<int> v;
        for (vector<int>::const_iterator jt = it->begin(); jt != it->end(); ++jt) {
          v.push_back(dist[*jt]);
        }
        sort(v.begin(), v.end(), greater<int>());
        int d = 0;
        for (vector<int>::const_iterator jt = v.begin(); jt != v.end(); ++jt) {
          d = max(d, int(*jt + (jt - v.begin())));
        }
        dist[u] = min(dist[u], d);
      }
    }
  }

  for (int u = 0; u < N; u++) {
    for (vector<vector<int> >::const_iterator it = rules[u].begin(); it != rules[u].end(); ++it) {
      vector<int> v;
      for (vector<int>::const_iterator jt = it->begin(); jt != it->end(); ++jt) {
        v.push_back(dist[*jt]);
      }
      sort(v.begin(), v.end(), greater<int>());
      int d = 0;
      for (vector<int>::const_iterator jt = v.begin(); jt != v.end(); ++jt) {
        d = max(d, int(*jt + (jt - v.begin())));
      }
      if (d < dist[u]) {
        return make_pair(dist, false);
      }
    }
  }
  return make_pair(dist, true);
}

int main()
{
  int N, E, T;
  cin >> N >> E >> T;
  --T;
  vector<int> seed(N);
  for (int i = 0; i < N; i++) {
    cin >> seed[i];
  }
  vector<vector<vector<int> > > rules(N);
  for (int i = 0; i < E; i++) {
    int g, c;
    cin >> g >> c;
    --g;
    vector<int> r(c);
    for (int j = 0; j < c; j++) {
      cin >> r[j];
      --r[j];
    }
    rules[g].push_back(r);
  }

  const pair<vector<int>, bool> r = bellman_ford(rules, seed);
  if (r.second && r.first[T] < INF) {
    cout << r.first[T] << endl;
  } else {
    cout << "-1" << endl;
  }
  return 0;
}

Measured memory_bytes: 928
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int N;
    cin>>N;
    vector<int> h(N);
    for (int &t: h)
        cin>>t;
    vector<int> T(N);
    T[0] = 0;
    T[1] = abs(h[1] - h[0]);
    for (int i=2; i<N; i++)
        T[i] = min(T[i-2]+abs(h[i]-h[i-2]), T[i-1]+abs(h[i]-h[i-1]));
    cout<<T[N-1]<<endl;
}


Measured memory_bytes: 1024
import java.util.*;

class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    while(true){
      int n = sc.nextInt();
      int m = sc.nextInt();
      int a = sc.nextInt();
      if(n == 0 && m == 0 && a == 0){
        break;
      }
      int[][] hpq = new int[m][3];
      for(int i = 0; i < m; i++){
        for(int j = 0; j < 3; j++){
          hpq[i][j] = sc.nextInt();
        }
      }
      Arrays.sort(hpq,(aa,bb) -> Integer.compare(aa[0],bb[0]));
      int ans = a;
      for(int i = m-1; i >= 0; i--){
        if(ans == hpq[i][1]){
          ans = hpq[i][2];
        }else if(ans == hpq[i][2]){
          ans = hpq[i][1];
        }
      }
      System.out.println(ans);
    }
  }
}



Measured memory_bytes: 69916
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <typename T> bool chmax(T &a, const T &b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> bool chmin(T &a, const T &b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
const long long INFLL = 1LL << 60;
const long long MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    int xs = 0;
    rep(i, N) {
        cin >> A[i];
        xs ^= A[i];
    }
    rep(i, N) { cout << (xs ^ A[i]) << " "; }
    cout << endl;
}

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

int main(){
  int a,b;
  char op[1];
  
  while(1){
    scanf(" %d %c %d",&a,&op[0],&b);
    if(op[0]=='?')break;
    if(op[0]=='+')cout << a+b << endl;
    else if(op[0]=='-')cout << a-b << endl;
    else if(op[0]=='/')cout << a/b << endl;
    else if(op[0]=='*')cout << a*b << endl;
  }
  
  return 0;

}

Measured memory_bytes: 3216
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <random>
#include <iomanip>

using namespace std;
using P = pair<long, long>;

typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvinv(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)
#define index_of(as, x) \
  distance(as.begin(), lower_bound(as.begin(), as.end(), x))

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

const int mod = 1000000007;

struct edge {
    int to;
    long cost;
};

int n, m;
long l;

const int MAX_V = 305;
vector<edge> G[MAX_V];

P dp[MAX_V][MAX_V];

using PP = pair<pair<int, long>, long>;

void dijkstra(int s) {
    auto c = [](PP l, PP r) { return l.first.first > r.first.first || l.first.second < r.first.second; };

    priority_queue<PP, vector<PP>, decltype(c)> que(c);
    rep(i, n) {
      dp[s][i] = {INF, 0};
    }
    dp[s][s] = {0, l};
    que.push({{0, l}, s});

    while (!que.empty()) {
        PP p = que.top();
        que.pop();
        int v = p.second;
        if (dp[s][v].first < p.first.first || (dp[s][v].first == p.first.first && dp[s][v].second > p.first.second)) continue;

        for (int i=0; i<G[v].size(); ++i) {
            edge e = G[v][i];
            int newFst;
            long newSnd;
            if(dp[s][v].second < e.cost) {
              newFst = dp[s][v].first + 1;
              newSnd = l-e.cost;
            } else {
              newFst = dp[s][v].first;
              newSnd = dp[s][v].second-e.cost;
            }

            if(newSnd < 0) continue;

            if (newFst < dp[s][e.to].first || (newFst == dp[s][e.to].first && newSnd > dp[s][e.to].second)) {
                dp[s][e.to] = {newFst, newSnd};
                que.push({dp[s][e.to], e.to});
            }
        }
    }
}

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

  cin >> n >> m >> l;

  rep(i,m) {
    int a, b;
    long c;
    cin >> a >> b >> c;
    a--;
    b--;
    G[a].push_back({b, c});
    G[b].push_back({a, c});
  }

  rep(i,n) {
    dijkstra(i);
  }

  int q;
  cin >> q;
  rep(i, q) {
    int s, t;
    cin >> s >> t;
    s--;t--;
    cout << (dp[s][t].first != INF ? dp[s][t].first : -1) << endl;
  }
}


Measured memory_bytes: 4352
#include <iostream>
using namespace std;
struct Day{
    int a,b,c;
    void set(int a=0, int b=0, int c=0){
        this->a = a;
        this->b = b;
        this->c = c;
    }
    void set(Day &d){
        this->a = d.a;
        this->b = d.b;
        this->c = d.c;
    }
};

int main() {
    Day *dp, *a;
    int n;
    cin >> n;
    dp = new Day[n];
    a = new Day[n];
    for (int i=0; i<n; i++) cin >> a[i].a >> a[i].b >> a[i].c;
    dp[0].set(a[0]);

    for (int i=1; i<n; i++){
        dp[i].a = max(dp[i-1].c + a[i].a , dp[i-1].b + a[i].a );
        dp[i].b = max(dp[i-1].c + a[i].b , dp[i-1].a + a[i].b );
        dp[i].c = max(dp[i-1].a + a[i].c , dp[i-1].b + a[i].c );
    }
    cout<<max(dp[n-1].a, max(dp[n-1].b, dp[n-1].c));
}


Measured memory_bytes: 5940
h,w = map(int,input().split())
s = [list(input()) for _ in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            c = 0
            for ni, nj in [(i+1, j),(i, j+1),(i-1, j),(i, j-1)]:
                if 0 <= ni < h and 0 <= nj < w and s[ni][nj] == "#":
                    c += 1
            if c == 0:
                print("No")
                exit(0)
print("Yes")

Measured memory_bytes: 9132
def main():
    N = int(input())
    A = list(map(int, input().split()))
    ans = 0
    MOD = 10 ** 9 + 7
    for d in range(60):
        one = 0
        zero = 0
        for i in range(N):
            if A[i] & (1 << d):
                one += 1
            else:
                zero += 1

        ans += (2 ** d) * (one * zero)
        ans %= MOD

    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 122808