akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
vector<long long> ll_vec(int n) {
    vector<long long> vec(n);
    for (int i=0; i<vec.size(); i++) cin >> vec.at(i);
    return vec;
}
void PA(vector<long long> vec) {
    for (int i=0; i<vec.size()-1; i++) cout << vec.at(i) << " ";
    cout << vec.at(vec.size()-1) << endl;
    return;
}
map<long long, long long> CL(vector<long long> vec) {
    map<long long, long long> count;
    for (long long x: vec) {
        count[x] += 1;
    }
    return count;
}



int main() {
    using ll = long long;
    using vl = vector<long long>;


    int n; cin >> n;

    vl b=ll_vec(n);

    vl ans(n);
    bool able = false;

    for (int i=0; i<n; i++) {
        ll mx=0;
        able = false;
        for (int j=0; j<b.size(); j++) {
            if (b[j] == j+1) {
                mx = j+1;
                able = true;
            }
        }
        if (able) {
            ans[i] = mx;
            b.erase(b.begin()+mx-1);
        }
        else {
            break;
        }
    }

    reverse(ans.begin(), ans.end());

    if (able) {
        for (ll x:ans) cout << x << endl;
    }
    else {
        cout << -1 << endl;
    }



}


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

using namespace std;

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

  int n, d;
  cin >> n >> d;
  int ans = 0;
  while (n--) {
    int x, y;
    cin >> x >> y;
    if (1ll * x * x + 1ll * y * y <= 1ll * d * d) ++ans;
  }
  cout << ans;

  return 0;
}


Measured memory_bytes: 3648
a = raw_input()
[N, A, B] = map(int, a.split(' '))
s = raw_input()
cnt = 0
b_cnt = 0
for each in s:
    if each == 'a':
        if cnt < A + B:
            print 'Yes'
            cnt += 1
        else:
            print 'No'
    elif each == 'b':
        if cnt < A + B and b_cnt < B:
            print 'Yes'
            cnt += 1
            b_cnt += 1
        else:
            print 'No'
    else:
        print 'No' 
        

Measured memory_bytes: 3076
#include<iostream>
#include<algorithm>
#include <vector>
#include<cmath>
#include<iomanip>
using namespace std;
typedef long long int lont;
int main() {
	int N;
	cin >> N;
	vector<int>vec(N);
	for (int ia = 0; ia < N; ia++) {
		cin >> vec.at(ia);
	}
	int  sum = 0;
	sort(vec.begin(), vec.end());
	for (int ib = 0; ib < N; ib++) {
		sum += vec.at(ib);
	}
	for (int ic = 0; ic < N; ic++) {
		if (sum % 2 != 0 && vec.at(ic) % 2 != 0) {
			sum -= vec.at(ic);
		}
		else {
			continue;
		}
	}
	cout << sum / 2 << endl;
}


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

#define int long long int
int i;
main()
{
   set<string> s;
   int k;
   cin>>k;
   for(i=0;i<k;i++)
   {
       string m;cin>>m;
       s.insert(m);
   }
   cout<<s.size()<<endl;
}


Measured memory_bytes: 19152
#include <bits/stdc++.h>
    using namespace std;
    #define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
     
    typedef long long ll;
     
    int main() {FIN
      ll n, s = 0, i;
                cin >> n;
      for (i = 1; i <= n; i++) {
      	if (i % 3 and i % 5)
          s += i;
      }
                cout << s << "\n";
      return 0;
    }

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

 
int main() {
    int n,k;
    cin>>n>>k;
    int ans=0;
    rep(i,n){
        int x;
        cin>>x;
        ans+=min(x,k-x);
    }
    cout<<ans*2<<endl;
}

Measured memory_bytes: 256
X, Y = map(int, input().split())

P_MOD = 10 ** 9 + 7

bit = []
tmp = P_MOD - 2
for i in range(64):
    if tmp < 1: break
    bit.append(tmp % 2)
    tmp >>= 1
    
def myinv(arg):
    N_bit = len(bit)
    #
    ret = 1
    arg_tmp = arg
    for i in range(N_bit):
        if bit[i] == 1:
            ret = (ret * arg_tmp) % P_MOD
        arg_tmp = (arg_tmp * arg_tmp) % P_MOD
    #
    return ret

if ((2 * X - Y) % 3 > 0) or ((2 * Y - X) % 3 > 0):
    print(0)
else:
    num_a = min((2 * Y - X) // 3, (2 * X - Y) // 3)
    num_b = max((2 * Y - X) // 3, (2 * X - Y) // 3)
    if num_a < 0 or num_b < 0:
        print(0)
    else:
        ans = 1
        for i in range(num_a):
            ans = (ans * (num_b + i + 1)) % P_MOD
        for i in range(num_a):
            ans = (ans * myinv(i + 1)) % P_MOD
        #
        print(ans)


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

#define ll long long int
#define rep(i, a, n) for (ll i = a; i < n; i++)
#define repm(i, a, n) for (ll i = a; i >= n; i--)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define mod (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vd vector<double>
#define vb vector<bool>
#define vs vector<string>
#define vii vector<vector<int>>
#define vllll vector<vector<ll>>
#define ALL(a) (a).begin(), (a).end()

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

void print(bool f)
{
    cout << (f ? "Yes" : "No") << endl;
}

void Print(bool f)
{
    cout << (f ? "YES" : "NO") << endl;
}

vll sou(51), meet(51);

ll where(ll num, ll x)
{
    //cout << num << " " << x << endl;
    if (num == 0)
    {
        //cout << "L0" << endl;
        return 1;
    }
    if (x == 0)
    {
        //cout << "LE" << endl;
        return 0;
    }
    if (x == sou[num] - 1)
    {
        //cout << "RE" << endl;
        return meet[num - 1] * 2 + 1;
    }
    if (x == sou[num] / 2)
    {
        //cout << "C" << endl;
        return meet[num - 1] + 1;
    }
    if (x < sou[num] / 2)
    {
        //cout << "L" << endl;
        return where(num - 1, x - 1);
    }
    if (x > sou[num] / 2)
    {
        //cout << "R" << endl;
        return meet[num - 1] + 1 + where(num - 1, x - sou[num] / 2 - 1);
    }
}

int main(void)
{
    ll n, x;
    cin >> n >> x;

    sou[0] = 1, meet[0] = 1;
    rep(i, 0, n)
    {
        sou[i + 1] = sou[i] * 2 + 3;
        meet[i + 1] = meet[i] * 2 + 1;
    }
    cout << where(n, x - 1) << endl;
}

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

range range_add(range a, range b){
    range ret(256,0);
    int i,j;
    for(i=a.first;i<=a.second;i++){
        for(j=b.first;j<=b.second;j++){
            ret.first=(ret.first<(i+j)%256)?ret.first:(i+j)%256;
            ret.second=(ret.second>(i+j)%256)?ret.second:(i+j)%256;
        }
    }
    return ret;
}

range range_dif(range a, range b){
    range ret(256,0);
    int i,j;
    for(i=a.first;i<=a.second;i++){
        for(j=b.first;j<=b.second;j++){
            ret.first=(ret.first<(i+256-j)%256)?ret.first:(i+256-j)%256;
            ret.second=(ret.second>(i+256-j)%256)?ret.second:(i+256-j)%256;
        }
    }
    return ret;
}

range range_mul(range a, range b){
    range ret(256,0);
    int i,j;
    for(i=a.first;i<=a.second;i++){
        for(j=b.first;j<=b.second;j++){
            ret.first=(ret.first<(i*j)%256)?ret.first:(i*j)%256;
            ret.second=(ret.second>(i*j)%256)?ret.second:(i*j)%256;
        }
    }
    return ret;
}

range range_div(range a, range b){
    range ret(256,0);
    int i,j;
    for(i=a.first;i<=a.second;i++){
        for(j=b.first;j<=b.second;j++){
            if(j==0){
                throw 1;
            }
            ret.first=(ret.first<(i/j)%256)?ret.first:(i/j)%256;
            ret.second=(ret.second>(i/j)%256)?ret.second:(i/j)%256;
        }
    }
    return ret;
}

int main(void){
    vector<range> st;
    unordered_map<string, range> dic;
    int n;
    cin>>n;
    string buf;
    int a,b;
    rep(i,n){
        cin>>buf>>a>>b;
        dic[buf]=range(a,b);
    }
    cin>>n;
    try{
        rep(i,n){
            cin>>buf;
            if(isdigit(buf[0])){
                st.emplace_back(stoi(buf),stoi(buf));
            }else if(buf[0]=='+'){
                st[st.size()-2]=range_add(st[st.size()-2], st[st.size()-1]);
                st.pop_back();
            }else if(buf[0]=='-'){
                st[st.size()-2]=range_dif(st[st.size()-2], st[st.size()-1]);
                st.pop_back();
            }else if(buf[0]=='*'){
                st[st.size()-2]=range_mul(st[st.size()-2], st[st.size()-1]);
                st.pop_back();
            }else if(buf[0]=='/'){
                st[st.size()-2]=range_div(st[st.size()-2], st[st.size()-1]);
                st.pop_back();
            }else{
                st.push_back(dic[buf]);
            }
        }
        cout<<"correct\n";
        return 0;
    }catch (...){
        cout<<"error\n";
        return 0;
    }
}











Measured memory_bytes: 3292
//#pragma GCC target("avx2")
#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int n;
    cin >> n;

    vector<int> t(n), a(n), b(n);
    REP(i, n) {
        cin >> t[i] >> a[i] >> b[i];
    }

    auto m_dist = [&] (int x1, int y1, int x2, int y2) -> int {
        return abs(x1 - x2) + abs(y1 - y2);
    };

    int cur = 0;
    int cx = 0, cy = 0;
    REP(i, n) {
        int nx = a[i], ny = b[i];
        int d = m_dist(cx, cy, nx, ny);

        if (d + cur > t[i] || (t[i] - d + cur) & 1) {
            print("No");
            return 0;
        }

        cur = t[i];
        cx = nx; cy = ny;
    }

    print("Yes");
}


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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())

void printYes(){
	cout<<"Yay!"<<endl;
}
void printNo(){
	cout<<":("<<endl;
}

signed main(){

	lli x,y;
	cin>>x>>y;

	lli sum=0;
	if(x==3)sum+=100000;
	else if(x==2)sum+=200000;
	else if(x==1)sum+=300000;

	if(y==3)sum+=100000;
	else if(y==2)sum+=200000;
	else if(y==1)sum+=300000;

	if(x==1 && y==1)sum+=400000;

	cout<<sum<<endl;

	return 0;
}

Measured memory_bytes: 768
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Prac
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine();
            var pars = input.Split(' ').Select(x => int.Parse(x)).ToArray();
            if ((pars[2] - pars[4] >= 0) & (pars[2] + pars[4] <= pars[0]) & ((pars[3] - pars[4] >= 0)) & (pars[3] + pars[4] <= pars[1]))
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}

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

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define REP(i, n) FOR(i, 0, n)

using Weight = int;
struct Edge {
    int src, dst;
    Weight weight;
};
using Graph = vector<vector<Edge>>;

void add_bidirectional_edge(Graph& graph, int src, int dst, int weight) {
    graph[src].push_back((Edge){src, dst, weight});
    graph[dst].push_back((Edge){dst, src, weight});
}

// Verified: AOJ 2251 (Merry Christmas)
vector<vector<Weight>> warshall_floyd(Graph graph) {
    static const Weight inf = numeric_limits<Weight>::max() / 10;
    vector<vector<Weight>> dist(graph.size(), vector<Weight>(graph.size(), inf));
    REP(u, graph.size()) dist[u][u] = 0;
    REP(u, graph.size()) for (auto& e : graph[u]) dist[e.src][e.dst] = e.weight;
    REP(w, graph.size()) REP(u, graph.size()) REP(v, graph.size())
        dist[u][v] = min(dist[u][v], dist[u][w] + dist[w][v]);
    return dist;
}

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

    int N, M;
    while (cin>>N>>M, N|M) {
        Graph land(N), sea(N);
        REP(i, M) {
            int x, y, t; char sl;
            cin >> x >> y >> t >> sl;
            --x; --y;
            if (sl == 'L')
                add_bidirectional_edge(land, x, y, t);
            else
                add_bidirectional_edge(sea, x, y, t);
        }
        int R; cin >> R;
        vector<int> order(R);
        REP(i, R) {
            int o; cin >> o;
            order[i] = o-1;
        }

        if (R == 1) {
            cout << "0\n";
            continue;
        }

        auto dist_land = warshall_floyd(land);
        auto dist_sea  = warshall_floyd(sea);

        vector<vector<Weight>> dp(2, vector<Weight>(N, INT_MAX/10));
        dp[1][order[0]] = 0;
        REP(i, R-1) {
            int curr = i%2, prev = 1-i%2;
            int u = order[i], v = order[i+1];
            REP(q, N) {
                Weight value = dp[prev][q] + dist_land[u][v];
                REP(p, N) {
                    value = min(value, dp[prev][p] + dist_land[u][p] + dist_sea[p][q] + dist_land[q][v]);
                }
                dp[curr][q] = value;
            }
        }
        cout << *min_element(dp[(R-2)%2].begin(), dp[(R-2)%2].end()) << '\n';
    }
}

Measured memory_bytes: 3656
# n = 12
n = int(input())
# a = [757232153, 372327760, 440075441, 195848680, 354974235, 458054863, 463477172, 740174259, 615762794, 632963102, 529866931, 64991604]
a = [int(i) for i in input().split()]
# b = [74164189, 98239366, 465611891, 362739947, 147060907, 118867039, 63189252, 78303147, 501410831, 110823640, 122948912, 572905212]
b = [int(i) for i in input().split()]
c = [0 for _ in range(n)]
for i in range(n):
    c[i] = a[i] - b[i]
if sum(c) < 0:
    print(-1)
    exit()
c.sort()
count = 0
minus = 0
for i in range(n):
    if c[i] < 0:
        minus += c[i]
        count += 1
    else:
        break
for i in reversed(range(n)):
    if minus < 0:
        minus += c[i]
        count += 1
    else:
        print(count)
        exit()

Measured memory_bytes: 18356
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1111111111;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N, M;
	cin >> N >> M;

	vector<vector<int>> edge(N, vector<int>(N));
	int u, v;
	for (int i = 0; i < M; i++) {
		cin >> u >> v;
		u--, v--;
		edge[u][v] = 1;
		edge[v][u] = 1;
	}

	vector<int> per(N);
	iota(per.begin(), per.end(), 0);
	int ans = 0;
	do {

		bool flag = true;
		for (int i = 0; i < N - 1; i++) {
			if (!edge[per[i]][per[i + 1]]) {
				flag = false;
				break;
			}
		}
		ans += flag;
		if (flag) DMP(per);
	} while (next_permutation(per.begin() + 1, per.end()));

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
)

type pair struct {
	cost      int
	src, dest int
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
}

type PriorityQueue []pair

func (pq PriorityQueue) Len() int { return len(pq) }

func (pq PriorityQueue) Less(i, j int) bool {
	return pq[i].cost <= pq[j].cost
}

func (pq *PriorityQueue) Push(x interface{}) {
	item := x.(pair)
	*pq = append(*pq, item)
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	*pq = old[0 : n-1]
	return item
}

var sc = bufio.NewScanner(os.Stdin)

func next() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i

}

type Tree struct {
	me   int
	prev *Tree
}

func getTop(t *Tree) *Tree {
	if t.prev != nil {
		r := getTop(t.prev)
		t.prev = r
		return r

	}
	return t

}

func same(a *Tree, b *Tree) bool {
	t1 := getTop(a)
	t2 := getTop(b)
	return t1.me == t2.me
}

func unite(a *Tree, b *Tree) {
	getTop(a).prev = b
}

func main() {
	sc.Split(bufio.ScanWords)

	vertexs, edges := next(), next()

	// heap queue
	queue := make(PriorityQueue, 0, edges)

	// union-find tree
	nodes := make([]*Tree, vertexs)

	// O(V)
	for i := 0; i < vertexs; i++ {
		nodes[i] = &Tree{me: i, prev: nil}

	}

	// O(E log E)
	for i := 0; i < edges; i++ {

		src, dest, cost := next(), next(), next()

		if src > vertexs || dest > vertexs {
			panic("over")
		}

		p := pair{src: src, dest: dest, cost: cost}
		// O(log E)
		heap.Push(&queue, p)
	}

	results := 0

	for queue.Len() > 0 {
		item := heap.Pop(&queue).(pair)

		if !same(nodes[item.src], nodes[item.dest]) {
			results += item.cost
			unite(nodes[item.src], nodes[item.dest])
		}
	}

	fmt.Println(results)

}




Measured memory_bytes: 7312
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define MOD 1'000'000'007LL

ll pw(ll a, ll b){
	ll c = 1;
	do{
		if(b&1) c = (a*c) % MOD;
		a = a*a % MOD;
	}while(b/=2);
	return c;
}
ll inv(ll a){
	return pw(a, MOD-2);
}
ll fct(ll x){
	ll ret = 1;
	FOR(i, 1, x+1){
		ret = ret * i % MOD;
	}
	return ret;
}
ll cmb(ll x, ll y){
	ll ret =  fct(x) * inv(fct(y)) % MOD * inv(fct(x-y)) % MOD;
	DEBUG("(%lld, %lld) = %lld\n", x, y, ret);
	return ret;
}

void no(){
	printf("0\n");
	exit(0);
}

int main(){
	DEBUG("%lld\n", 120 * inv(6) % MOD * inv(2) % MOD);
	DEBUG("%lld %lld\n", fct(3), fct(2));
	ll x, y; scanf("%lld%lld", &x, &y);
	if((x+y) % 3) no();
	ll w = (x+y) / 3, z = x-y;
	if((w+z) % 2) no();
	ll p = (w-z) / 2, q = (w+z) / 2;
	if(p < 0 || q < 0) no();
	assert(p * 1 + q * 2 == x);
	assert(p * 2 + q * 1 == y);
	DEBUG("p = %lld, q = %lld\n", p, q);
	printf("%lld\n", cmb(p+q, p));
}


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

int main(){
	static int m,n,k,a,b,c,d,J[1000+2][1000+2]={0},O[1000+2][1000+2]={0},I[1000+2][1000+2]={0};
	char C;
	scanf("%d%d%d",&m,&n,&k);
	for(int i=1;i<=m;i++){
		scanf("\n");
		for(int j=1;j<=n;j++){
			scanf("%c",&C);
			if(C=='J')J[i][j]++;
			else if(C=='O')O[i][j]++;
			else if(C=='I')I[i][j]++;
			J[i][j]+=J[i][j-1];
			O[i][j]+=O[i][j-1];
			I[i][j]+=I[i][j-1];
		}
		for(int j=1;j<=n;j++){
			J[i][j]+=J[i-1][j];
			O[i][j]+=O[i-1][j];
			I[i][j]+=I[i-1][j];
		}
	}
	/*for(int i=1;i<=m;i++){
		for(int j=1;j<=n;j++){
			printf("(%d,%d,%d)",J[i][j],O[i][j],I[i][j]);
		}
		printf("\n");
	}*/
	for(int i=0;i<k;i++){
		scanf("%d%d%d%d",&a,&b,&c,&d);
		printf("%d %d %d\n",J[c][d]+J[a-1][b-1]-J[a-1][d]-J[c][b-1],O[c][d]+O[a-1][b-1]-O[a-1][d]-O[c][b-1],I[c][d]+I[a-1][b-1]-I[a-1][d]-I[c][b-1]);
	}
}

Measured memory_bytes: 12896
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std;
typedef unsigned long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n,m;
    
    cin>>n>>m;
    vector<ll> high(n+1,0ll);
    set<int> count;
    
    for(int i =1; i<=n; i++){
        ll e;
        cin>>e;
        high[i] = e;
        count.insert(i);
    }
    for(;m;m--){
        int a,b;
        cin>>a>>b;
        if(high[a]>high[b]){
            count.erase(b);
        }else if(high[a]<high[b]){
            count.erase(a);
        }else{
            count.erase(a);
            count.erase(b);
        }
    }
    cout<<count.size()<<endl;
    return 0;
}


Measured memory_bytes: 8720
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] A = new int[N];
		int[] cnt = new int[N + 1];
		int[] cum = new int[2 * N + 1];
		for (int i = 0; i < N; ++i) {
			A[i] = sc.nextInt();
			++cnt[A[i]];
		}
		for (int i = 1; i <= N; ++i) {
			for (int j = 0; j < cnt[i]; ++j) {
				++cum[i - j + N];
			}
		}

		System.out.println();

		int ans = 0;
		for (int i = 1; i <= N; ++i) {
			if (cum[i + N] == 0)
				++ans;
		}
		for (int i = 0; i < M; ++i) {
			int x = sc.nextInt();
			int y = sc.nextInt();
			--x;
			int tmp = x;
			x = A[x];
			A[tmp] = y;
			--cum[N + x - (cnt[x] - 1)];
			if (cum[N + x - (cnt[x] - 1)] < 0) {
				throw new AssertionError();
			}
			if (x - (cnt[x] - 1) >= 1 && cum[N + x - (cnt[x] - 1)] == 0) {
				++ans;
			}
			--cnt[x];
			++cnt[y];
			++cum[N + y - (cnt[y] - 1)];
			if (y - (cnt[y] - 1) >= 1 && cum[N + y - (cnt[y] - 1)] == 1) {
				--ans;
			}
			System.out.println(ans);
		}

	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

Measured memory_bytes: 164796
R,C,K=map(int,input().split())
l=[[0] * C for i in range(R)]
for i in range(K):
  a,b,c=map(int,input().split())
  a-=1
  b-=1
  l[a][b]=c
dp=[0]*C
for i in range(R):
  ndp=[0]*C
  kdp=[0]*4
  for j in range(0,C):
    kdp[0]=max(kdp[0],dp[j])
    for k in range(2,-1,-1):
      kdp[k+1]=max(kdp[k+1],kdp[k]+l[i][j])
    ndp[j]=max(kdp)
  dp=ndp
print(dp[C-1])


Measured memory_bytes: 155824
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map;
import java.util.Map.Entry;
 
import java.util.PriorityQueue;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeSet;
 
public class Main {
	
	public static final long MOD = 1000000007;
	
	public static int grundy(int[] memo, int K, int[] array) {
		if(memo[K] >= 0) { return memo[K]; }
		
		TreeSet<Integer> set = new TreeSet<Integer>();
		for(final int a : array) {
			if(K < a) { continue; }
			set.add(grundy(memo, K - a, array));
		}
		
		for(int i = 0; i < K; i++) {
			if(!set.contains(i)) { return memo[K] = i; }
		}
		return memo[K] = K;
	}
	
	public static void main(String[] args) throws IOException {
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			final int K = sc.nextInt();
			
			final int[] array = new int[N];
			for(int i = 0; i < N; i++) { array[i] = -sc.nextInt(); }
			Arrays.sort(array);
			for(int i = 0; i < N; i++) { array[i] = -array[i]; }
			
			final int[] memo = new int[K + 1];
			Arrays.fill(memo, -1);
			
			
			Thread t = new Thread(null, null, "TT", 1000000000) {
				@Override public void run() {
					grundy(memo, K, array);
				}
			};
			t.start();
			try{
				t.join();
				System.out.println(grundy(memo, K, array) == 0 ? "Second" : "First");
			}catch(InterruptedException e){
				e.printStackTrace();
			}
		}
	}
 
	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;
 
		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}
 
		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}
 
		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}
 
		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}
 
		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}
 
		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 156024
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int M = sc.nextInt();
        int[] a = new int[A];
        int[] b = new int[B];
        for (int i=0;i<A;i++) {
            a[i] = sc.nextInt();
        }
        for (int i=0;i<B;i++) {
            b[i] = sc.nextInt();
        }
        int ans = 300_000;
        for (int i=0;i<M;i++) {
            int x = sc.nextInt()-1;
            int y = sc.nextInt()-1;
            int c = sc.nextInt();
            ans = Math.min(ans, a[x]+b[y]-c);
        }
        Arrays.sort(a);
        Arrays.sort(b);
        ans = Math.min(ans, a[0]+b[0]);
        System.out.println(ans);
    }
}

Measured memory_bytes: 154952
#include <stdio.h>
struct dice{
    int d[6], tmp[6];
};
struct dice dice1;
struct dice dice2;
void init1(int n[6]){
    int i;
    for (i=0;i<6;i++){
        dice1.d[i]=n[i];
    }
}
void init2(int n[6]){
    int i;
    for (i=0;i<6;i++){
        dice2.d[i]=n[i];
    }
}
void throwdice(char c){
    int i;
    for(i=0;i<6;i++){
        dice1.tmp[i]=dice1.d[i];
    }
    if(c=='N'){
        dice1.d[0]=dice1.tmp[1];
        dice1.d[1]=dice1.tmp[5];
        dice1.d[2]=dice1.tmp[2];
        dice1.d[3]=dice1.tmp[3];
        dice1.d[4]=dice1.tmp[0];
        dice1.d[5]=dice1.tmp[4];
    }
    else if(c=='E'){
        dice1.d[0]=dice1.tmp[3];
        dice1.d[1]=dice1.tmp[1];
        dice1.d[2]=dice1.tmp[0];
        dice1.d[3]=dice1.tmp[5];
        dice1.d[4]=dice1.tmp[4];
        dice1.d[5]=dice1.tmp[2];
    }
    else if(c=='W'){
        dice1.d[0]=dice1.tmp[2];
        dice1.d[1]=dice1.tmp[1];
        dice1.d[2]=dice1.tmp[5];
        dice1.d[3]=dice1.tmp[0];
        dice1.d[4]=dice1.tmp[4];
        dice1.d[5]=dice1.tmp[3];
    }
    else if(c=='S'){
        dice1.d[0]=dice1.tmp[4];
        dice1.d[1]=dice1.tmp[0];
        dice1.d[2]=dice1.tmp[2];
        dice1.d[3]=dice1.tmp[3];
        dice1.d[4]=dice1.tmp[5];
        dice1.d[5]=dice1.tmp[1];
    }
    else if(c=='R'){
        dice1.d[0]=dice1.tmp[0];
        dice1.d[1]=dice1.tmp[3];
        dice1.d[2]=dice1.tmp[1];
        dice1.d[3]=dice1.tmp[4];
        dice1.d[4]=dice1.tmp[2];
        dice1.d[5]=dice1.tmp[5];
    }
}
int compare(){
    int i;
    for(i=0;i<6;i++){
        if(dice1.d[i]!=dice2.d[i]){
            return 0;
        }
    }
    return 1;
}
int main()
{
    int n[6];
    int i,j;
    int ok=0;
    for(i=0;i<6;i++){
        scanf("%d",&n[i]);
    }
    init1(n);
    for(i=0;i<6;i++){
        scanf("%d",&n[i]);
    }
    init2(n);
    for(i=0;i<4;i++){
        for(j=0;j<4;j++){
            throwdice('N');
            throwdice('E');
            throwdice('S');
            if(compare()) ok=1;
        }
        throwdice('N');    
    }
    throwdice('E');
    for(i=0;i<2;i++){
        for(j=0;j<4;j++){
            throwdice('N');
            throwdice('E');
            throwdice('S');
            if(compare()) ok=1;
        }
        throwdice('W');    
        throwdice('W');    
    }
    if(ok) puts("Yes");
    else puts("No");
    return 0;
}



Measured memory_bytes: 2692
from scipy.sparse import*
f=csgraph.johnson
n,m,l,*t=map(int,open(0).read().split())
m*=3
*_,=map(print,f(f(csr_matrix((t[2:m:3],(t[:m:3],t[1:m:3])),[n+1]*2),0)<=l)[t[m+1::2],t[m+2::2]].clip(0,n)%n-1)

Measured memory_bytes: 40868
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int K = sc.nextInt();

		double p = 0;

		for(int i=1;i<=N;i++) {
			double pi = 1;
			int temp = i;
			while(temp < K) {
				pi /= 2;
				temp *= 2;
			}
			p += pi;
		}
		p /= N;
		System.out.println(p);
    }
}

Measured memory_bytes: 21844
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())

dishes=[a,b,c,d,e]
mod_dishes=[]
time_dishes=[]
for i in dishes:
    if i%10 != 0:
        mod_dishes.append(i%10)
        time_dishes.append(i+(10-i%10))
    else:
        mod_dishes.append(10)
        time_dishes.append(i)                   
                          
x=10
for i in mod_dishes:
    if i < x:
        x = i

y = 10-x
z=0
for i in time_dishes:
    z = z + i

z = z - y
print(z)

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

using namespace std;

typedef long long ll;
typedef long double ld;

struct cplx {
  ld a, b;

  cplx (ld a = 0, ld b = 0) : a(a), b(b) {}
  
  const cplx operator + (const cplx &c) const {
    return cplx(a + c.a, b + c.b);
  }

  const cplx operator - (const cplx &c) const {
    return cplx(a - c.a, b - c.b);
  }

  const cplx operator * (const cplx &c) const {
    return cplx(a * c.a - b * c.b, a * c.b + b * c.a);
  }

  const cplx conj() const {
    return cplx(a, -b);
  }
};

const ld PI = acosl(-1);
const int N = (1 << 20) + 5;

int rev[N]; cplx w[N];

void prepare (int &n) { 
  int sz = __builtin_ctz(n);
  for (int i = 1; i < n; ++i) rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (sz - 1));
  w[0] = 0, w[1] = 1, sz = 1; 
  while (1 << sz < n) {
    ld ang = 2 * PI / (1 << (sz + 1));
    cplx w_n = cplx(cosl(ang), sinl(ang));
    for (int i = 1 << (sz - 1); i < (1 << sz); ++i) {
      w[i << 1] = w[i], w[i << 1 | 1] = w[i] * w_n; 
    } ++sz;
  }
}

void fft (cplx *a, int n) { 
  for (int i = 1; i < n - 1; ++i) { 
    if (i < rev[i]) swap(a[i], a[rev[i]]);
  }
  for (int h = 1; h < n; h <<= 1) {
    for (int s = 0; s < n; s += h << 1) {
      for (int i = 0; i < h; ++i) {
        cplx &u = a[s + i], &v = a[s + i + h], t = v * w[h + i];
        v = u - t, u = u + t;
      }
    }
  }
}

static cplx f[N], g[N], u[N], v[N];

void multiply (ll *a, ll *b, int n, int m) {
  int sz = n + m - 1; 
  while (sz & (sz - 1)) sz = (sz | (sz - 1)) + 1;
  prepare(sz);
  for (int i = 0; i < sz; ++i) f[i] = cplx(i < n ? a[i] : 0, i < m ? b[i] : 0);
  fft(f, sz);
  for (int i = 0; i <= (sz >> 1); ++i) {
    int j = (sz - i) & (sz - 1); 
    cplx x = (f[i] * f[i] - (f[j] * f[j]).conj()) * cplx(0, -0.25); 
    f[j] = x, f[i] = x.conj(); 
  }
  fft(f, sz); 
  for(int i = 0; i < sz; ++i) a[i] = f[i].a / sz + 0.5; 
}

const int MOD = 200003;

bitset <N> vis;
int n; ll a[N], inv[N];

int main() {
  ll cur = 1;
  for (int i = 0; i < MOD - 1; ++i) {
    inv[cur] = i;
    cur = cur * 2 % MOD;
  }
  cin >> n;
  ll ans = 0;
  while (n--) {
    int x;
    scanf("%d", &x);
    if (x) ++a[inv[x]];
    ans -= ((ll) x * x % MOD);
  }
  multiply(a, a, MOD, MOD);
  cur = 1;
  for (int i = 0; i < MOD + MOD; ++i) {
    ans += a[i] * cur;
    cur = cur * 2 % MOD;
  }
  ans >>= 1;
  cout << ans << '\n';
  return 0;
}



Measured memory_bytes: 175408
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
using namespace std;

#define N 150
int inf=99999999;
int e[N][N];
int mark[N];
int m;
void init(int n)
{
    for(int i=0; i<=n; i++)
        for(int j=0; j<=n; j++)
        {
            if(i==j)e[i][j]=0;
            else
                e[i][j]=inf;
        }
}

void floyd(int n)
{
    for(int i=0; i<=n; i++)
        for(int j=0; j<=n; j++)
            for(int k=0; k<=n; k++)
            {
                    if(e[j][k]>e[j][i]+e[i][k])
                    {
                        e[j][k]=e[j][i]+e[i][k];
                    }
            }
}

int main()
{
    while(scanf("%d",&m),m!=0)
    {
        int n=-1;
        int a,b,c;
        init(150);
        memset(mark,0,sizeof(mark));
        while(m--)
        {
            scanf("%d%d%d",&a,&b,&c);
            e[a][b]=e[b][a]=c;
            if(a>n)n=a;
            if(b>n)n=b;
            mark[a]=1;
            mark[b]=1;
        }

        floyd(n);
        int ans1,ans2;
        ans1=ans2=inf;
        for(int i=0; i<=n; i++)
        {
            int sum=0;
            if(mark[i]==1)
            {

                for(int j=0; j<=n; j++)
                {
                    if(mark[j]==1&&e[i][j]!=inf)
                    {
                        sum+=e[i][j];
                    }
                }
            }
            if(sum<ans2)
            {
                ans2=sum;
                ans1=i;
            }
        }
        printf("%d %d\n",ans1,ans2);
    }
    return 0;
}

Measured memory_bytes: 3192
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);
		double n = sc.nextDouble();
		double out = 0;

		if(n % 2 == 0) {
			out = 0.5;
		}else {
			double i = Math.ceil(n/2);
			out = i / n;
		}

		sc.close();
		System.out.println(out);

	}
}

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

using namespace std;

struct node{
  int x, hour;
  node(){}
  node(int x, int hour):x(x), hour(hour){}
  bool operator < (const node& u) const {
    return hour < u.hour;
  }
};

struct edge{
  int u, v, cost;
  edge(){}
  edge(int u, int v, int cost):u(u), v(v), cost(cost){}
  bool operator < (const edge& e) const {
    return cost < e.cost;
  }
};

struct UnionFind{
  vector<int> data;
  UnionFind(int sz)
  {
    data.assign(sz, -1);
  }
  int find(int k)
  {
    if(data[k] < 0) return k;
    return data[k] = find(data[k]);
  }
  void unite(int x, int y)
  {
    x = find(x), y = find(y);
    if(x != y){
      if(data[x] > data[y]) swap(x, y);
      data[x] += data[y];
      data[y] = x;
    }
  }
  bool same(int x, int y)
  {
    return find(x) == find(y);
  }
  int size(int k)
  {
    return -data[find(k)];
  }
};

int main()
{
  int N, M;
  while(cin >> N >> M, N || M){
    vector<node> V;
    vector<edge> E;
    for(int i = 0; i < N; i++){
      int h; cin >> h;
      V.push_back(node(i, h));
    }
    for(int i = 0; i < M; i++){
      int a, b, c; cin >> a >> b >> c; a--, b--;
      E.push_back(edge(a, b, c));
    }
    sort(V.rbegin(), V.rend());
    sort(E.begin(), E.end());
    vector<bool> exist(N, true);
    int dis = N;
    for(int i = N-1; i >= 0; i--){
      if(i < N-1 || V[i].hour != V[i+1].hour){
	UnionFind msp(N);
	for(int j = 0; j < M; j++){
	  if(exist[E[j].u] && exist[E[j].v] && !msp.same(E[j].u, E[j].v)){
	    msp.unite(E[j].u, E[j].v);
	  }
	}
	if(msp.size(V[0].x) == i+1) dis = i;
	else break;
      }
      exist[V[i].x] = false;
    }
    UnionFind uf(N);
    long long ans = 0LL;
    for(int i = dis; i < N; i++){ 
      exist[V[i].x] = true;
      if(i < N-1 && V[i].hour == V[i+1].hour) continue;
      for(int j = 0; j < M; j++){
	if(exist[E[j].u] && exist[E[j].v] && !uf.same(E[j].u, E[j].v)){
	  uf.unite(E[j].u, E[j].v);
	  ans += E[j].cost;
	}
      }
    }	
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1684
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

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

		String inputValue = br.readLine();
		String[] inputData = inputValue.split(" ");

		int width = Integer.parseInt(inputData[0]);
		int height = Integer.parseInt(inputData[1]);
		int x = Integer.parseInt(inputData[2]);
		int y = Integer.parseInt(inputData[3]);
		int r = Integer.parseInt(inputData[4]);

		if(r <= x && x <= (width - r) && r <= y && y <= (height - r)){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}

}

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

int top = 0, S[1000];

void push(int x) {
  S[++top] = x;
}

int pop(void) {
  top--;
  return S[top+1];
}

int main(void) {
  int a, b;
  top = 0;
  char s[100];
  while(scanf("%s",s) != EOF) {
    if(s[0] == '+') {
      a = pop();
      b = pop();
      push(a + b);
    } else if(s[0] == '-') {
      b = pop();
      a = pop();
      push(a - b);
    } else if(s[0] == '*') {
      a = pop();
      b = pop();
      push(a * b);
    } else {
      push(atoi(s));
    }
  }
  printf("%d\n",pop());

  return 0;
}


Measured memory_bytes: 2100
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <string.h>
using namespace std;
#define N 200
#define M 10000
#define R 1000
#define INF 1000000

int main(){
  while(1){
    int n,m,r;
    int sea[N][N];
    int land[N][N];
    int dp[R][N];
    int z[R];

    scanf("%d%d",&n,&m);
    if(!n&&!m)break;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
        if(i==j){
          sea[i][j] = 0;
          land[i][j] = 0;
        }else{
          sea[i][j] = INF;
          land[i][j] = INF;
        }
      }
    }
    for(int i=0;i<m;i++){
      int x,y,t;
      char s;
      scanf("%d %d %d %c",&x,&y,&t,&s);
      if(s=='S'){
        sea[x-1][y-1] = t;
        sea[y-1][x-1] = t;
      }else{
        land[x-1][y-1] = t;
        land[y-1][x-1] = t;
      }
    }
    scanf("%d",&r);
    for(int i=0;i<r;i++){
      scanf("%d",&z[i]);
      z[i]--;
    }

    for(int k=0;k<n;k++){
      for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
          sea[i][j] = min(sea[i][j],sea[i][k]+sea[k][j]);
          land[i][j] = min(land[i][j],land[i][k]+land[k][j]);
        }
      }
    }

    for(int i=0;i<n;i++){
      dp[0][i] = sea[z[0]][i] + land[i][z[0]];
      for(int j=1;j<r;j++){
        dp[j][i] = INF;
      }
    }
    for(int i=1;i<r;i++){
      for(int j=0;j<n;j++){
        for(int k=0;k<n;k++){
          dp[i][j] = min(
            dp[i][j],
            dp[i-1][k]+land[z[i-1]][k]+sea[k][j]+land[j][z[i]] );
          if(k==j) dp[i][j] = min(dp[i][j],dp[i-1][j]+land[z[i-1]][z[i]]);
        }
      }
    }
    int ans = INF;
    for(int i=0;i<n;i++){
      ans = min(ans,dp[r-1][i]);
    }
    cout << ans << endl;
  }
  return 0;
}

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

#define int long long
#define F first
#define S second
//2 1 1 1
//3 1
int32_t main() {
	ios::sync_with_stdio(false);
	int n, m, v, p;
	cin >> n >> m >> v >> p;
	v = n - v;
	int a[n], maax[n + 1] = {}, sum[n + 1] = {}, ans = 0;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	map <int, int> frst;
	sort(a, a + n, greater<int>());
	for (int i = 0; i < n; i++)
		cerr << a[i] << ' ';
	cerr << endl;
	for (int i = 0; i < n; i++) {
		if (!frst[a[i]])
			frst[a[i]] = i + 1;
		int f = frst[a[i]] - 1;
		if (i >= p - 1) {
			sum[i + 1] = sum[i] + a[i];
			maax[i + 1] = max(maax[i], a[i]);
		}
		if (f < p) {
			ans++;
			continue;
		}
		int s = sum[f];
		int mx = maax[f];
		if (max(mx - a[i], (s - (f - p + 1) * a[i] + v - 1) / v) <= m)
			ans++;

	}
	cout << ans << endl;
}



Measured memory_bytes: 8832
A, B, C, D = input()

op = ['+', '-']
for i in range(2):
    for j in range(2):
        for k in range(2):
            s = A + op[i] + B + op[j] + C + op[k] + D
            if eval(s) == 7:
                print(s + '=7')
                exit()

Measured memory_bytes: 3060
#include <cstdio>
#include <algorithm>
using namespace std;

int main(){
	int inf, mat, sci, eng;
	int S, T;
	
	scanf("%d%d%d%d", &inf, &mat, &sci, &eng);
	S = inf + mat + sci + eng;
	scanf("%d%d%d%d", &inf, &mat, &sci, &eng);
	T = inf + mat + sci + eng;
	
	printf("%d\n", max(S, T));
	
	return 0;
}

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

long long cnt;
int l;
int A[10000000];
int n;
vector<int> G;

void insert(int A[],int n,int g){
  int i,j,v;
  for(i=g;i<n;i++){
    v=A[i];
    j=i-g;
    while(j>=0 && A[j]>v){
      A[j+g]=A[j];
      j=j-g;
      cnt++;
    }
      A[j+g]=v;
  }
}

void shellsort(int A[],int n){
  int i,j;
  for(i=1;;){
    if(i>n)break;
    G.push_back(i);
    i=3*i+1;
  }
  for(j=G.size()-1;j>=0;j--){
    insert(A,n,G[j]);
  }
}
int main(){
  int i,j;

  cin >> n;
  for(i=0;i<n;i++){
    cin >> A[i];
  }
  cnt=0;
  
  shellsort(A,n);

  cout<<G.size()<<endl;
  for(i=G.size()-1;i>=0;i--){
    cout << G[i];
    if(i){
    cout << " ";
    }
  }
  cout << endl;
  cout << cnt<<endl;

  for(i=0;i<n;i++){
    cout << A[i]<< endl;
  }
}

Measured memory_bytes: 5304
#include <iostream>
using namespace std;
int main()
{
	int N, K, sum = 0;
  	cin >> N >> K;
  	for (int i = 0; i < N; i++){
    	int x; cin >> x;
      	if (x < K - x) {
        	sum += x * 2;
        } else {
        	sum += (K - x) * 2;
        }
    }
  	cout << sum;
}

Measured memory_bytes: 256
N, T = [int(i) for i in input().split()]
S = [[int(i) for i in input().split()] for j in range(N)]
cost = 5000

for i in S:
    if i[1] > T:
        continue
    else:
        if i[0] < cost:
            cost = i[0]

if cost == 5000:
    print("TLE")
else:
    print(cost)

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

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

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

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

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

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

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

// fn minus(a: Vec<isize>, b:Vec<isize>) -> Vec<isize> {
//     let mut z = vec![0,0,0];
//     for (i, (aval, bval)) in a.iter().zip(&b).enumerate() {
//         z[i] = aval - bval;
//     }
//     z
// }

use std::collections::HashMap;
fn main() {
    // let c: char = 'a';
    // let num: i32 = c as i32 -96;
    // println!("{}", num);  // 5
    input! {
      n: usize,
      a: [usize; n],
      q: usize,
      b: [(usize, usize); q],
    }
    let mut map = HashMap::new();
    let mut sum: usize = a.iter().sum();

    for i in a {
        let count = map.entry(i).or_insert(0);
        *count += 1;
    }
    for (i, j) in b {
        let s = map.get(&i);
        if s == None {
           println!("{}", sum); 
        } else {
        let value:usize = *s.unwrap();
        sum -= value * (i - j);
        let count = map.entry(j).or_insert(0);
        *count += value;
        map.remove(&i);
        println!("{}", sum);
        }
    }
}


Measured memory_bytes: 9500
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
#include<map>
#include<set>
using namespace std;

int main() {
    int a, b, c;
    cin >> a>> b>> c;
    if (a < b) swap(a, b);
    if (b < c) swap(c, b);
    if (a < b) swap(a, b);
    if ((2*a-b - c) % 2 == 0) cout << (2 * a - b - c) / 2 << endl;
    else cout << (2 * a - b - c + 3) / 2 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = 1001002003004005006ll;
const int inf = 1001001001;
const int mod = 1000000007;

vector<P> g[100005];
vector<int> ans(100005, 0);
vector<bool> vi(100005, 0);

void dfs(int s, int tmp = 0) {
	vi[s] = true;
	ans[s] = tmp;
	for (auto& c : g[s]) {
		if (vi[c.first]) continue;
		if (c.second % 2 != 0) dfs(c.first, tmp ^ 1);
		else dfs(c.first, tmp);
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	rep(i, n - 1) {
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		g[a].emplace_back(b, c);
		g[b].emplace_back(a, c);
	}
	dfs(0);
	rep(i, n) {
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 8448
#include<bits/stdc++.h>
using namespace std;
     
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define INF 999999999999999999
#define endl "\n"
#define MOD 1000000007
 
 
 
void func(){
 
ll n;
cin>>n;

ll a[n+1]={0};

for(int i=1;i<n;i++){
  ll t;
  cin>>t;
  a[t]++;
}

for(int i=1;i<=n;i++)
cout<<a[i]<<endl;
}
 
 
 
 
    
int main(){
            ios_base::sync_with_stdio(false);
            cin.tie(0);
            cout.tie(0);
     
         /* #ifndef ONLINE_JUDGE
          freopen("input.txt", "r" , stdin);
          freopen("output1.txt", "w" , stdout);
          #endif*/
     
       ll t=1;
       //cin>>t;
       while(t--)
       func();
}

Measured memory_bytes: 5236
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#define _USE_MATH_DEFINES
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775808;

int main() {
    int N, M;
    cin >> N >> M;
    int a[N + 1];
    fill(a, a + N + 1, 1);
    bool b[N + 1];
    fill(b, b + N + 1, false);
    b[1] = true;
    for (int i = 0; i < M; i++) {
        int x, y;
        cin >> x >> y;
        if (b[x]) {
            b[y] = true;
        }
        a[x]--;
        a[y]++;
        if (a[x] == 0) {
            b[x] = false;
        }
    }
    int ans = 0;
    for (int i = 1; i < N + 1; i++) {
        if (b[i]) {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 768
#include <iostream>
#include <string>
using namespace std;
signed main() {
	string a, b; cin >> a >> b;
	if (a.size() < b.size())return 0;
	for (int i = 0; i < a.size() - b.size() + 1; i++)if (a.substr(i, b.size()) == b)cout << i << endl;
	cin >> a;
}


Measured memory_bytes: 3172
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner stdIn=new Scanner(System.in);
		for(int i=1;;i++){
			int x=stdIn.nextInt();
			if(x<1)break;
			System.out.println("Case "+i+": "+x);
		}
	}
}


Measured memory_bytes: 44820