akhauriyash/Code-Regression huggingface dataset:
#define  _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>

typedef struct Node
{
	Node *prev, *next;
	int key;
} Node, *ptrNode;

ptrNode nil;	// sential

void init() {
	nil = (ptrNode)malloc(sizeof(Node));
	nil->next = nil;
	nil->prev = nil;
}

// insert elem into head
void insert(int key) {
	ptrNode n = (ptrNode)malloc(sizeof(Node));
	n->key = key;

	// insert
	n->next = nil->next;
	nil->next->prev = n;
	nil->next = n;
	n->prev = nil;
}

ptrNode find(int key) {
	ptrNode it = nil->next;
	while (it != nil) {
		if (it->key == key)
			return it;
		it = it->next;
	}
	return NULL;
}

void delKey(int key) {
	ptrNode n;
	// find key
	if ((n = find(key)) != NULL) {
		(n->prev)->next = n->next;
		(n->next)->prev = n->prev;
		free(n);
	}
}

void delNode(ptrNode cur) {
	if (cur == nil)	return;
	(cur->prev)->next = cur->next;
	(cur->next)->prev = cur->prev;
	free(cur);
}

void delFirst() {
	delNode(nil->next);
}

void delLast() {
	delNode(nil->prev);
}

void printList() {
	int isf = 0;
	ptrNode it = nil->next;
	while (it != nil) {
		if (isf++ > 0)	printf(" ");
		printf("%d", it->key);
		it = it->next;
	}
	printf("\n");
}

int main()
{
	init();
	int n;

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

		if (cmd[0] == 'i') {
			int key;
			scanf("%d", &key);
			insert(key);
		} else {
			if (cmd[6] == '\0') {
				int key;
				scanf("%d", &key);
				delKey(key);
			}
			else if (cmd[6] == 'F')
				delFirst();
			else
				delLast();
		}
	}

	printList();

	return 0;
}

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

int main() {
  string S, y, m, d;
  cin >> S;
  
  for (int i = 0; i < 4; i++) {
    y += S.at(i);
  }
  for (int i = 5; i < 7; i++) {
    m += S.at(i);
  }
  for (int i = 8; i < 10; i++) {
    d += S.at(i);
  }
  
  int Y = stoi(y);
  int M = stoi(m);
  int D = stoi(d);
  
  bool Heisei = true;
  
  if (Y >= 2019) {
    if (M > 4) {
      Heisei = false;
    }
  }
  
  if (Heisei) {
    cout << "Heisei" << endl;
  }
  else {
    cout << "TBD" << endl;
  }
}

      
    


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
using vi = vector<int>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

int main(){
    int n;
    cin >> n;
    vector<vector<bool>> a(n,vector<bool>(10));
    rep(i,n){
        rep(j,10){
            int b;
            cin >> b;
            a[i][j] = b;
        }
    }
    vector<vi> p(n,vi(11));
    rep(i,n){
        rep(j,11){
            cin >> p[i][j];
        }
    }
    ll ans = -LINF;
    for(int i=1;i<(1<<10);i++){
        bitset<10> b(i);
        //cout << b << endl;
        ll tmp = 0;
        for(int j=0;j<n;j++){
            int cnt = 0;
            for(int k=0;k<10;k++){
                if(b.test(k) && a[j][k]){
                    cnt++;
                }
            }
            tmp += p[j][cnt];
        }
        ans = max(ans,tmp);
    }
    cout << ans << endl;
}

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

const char wall = '#';
vector<vector<char>> fields;
vector<vector<bool>> used;
vector<vector<ll>> dist;
map<P, P> before;
vector<P> history;
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0};

ll H, W;
vector<ll> A;

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return b/gcd(a,b)*b;}
bool bfs() {
  queue<P> que;
  used[0][0] = true;
  que.push(make_pair(0, 0));
  //dist[0][0] = 0;

  while (que.size() > 0) {
    P p = que.front(); que.pop();
    ll x = p.second; ll y = p.first;
    rep(i, 4) {
      ll X = x+dx[i];
      ll Y = y+dy[i];
      if (X < 0 | X >= W | Y < 0 | Y >= H) continue;
      if (fields[Y][X] == wall) continue;
      if (used[Y][X]) continue;
      que.push(make_pair(Y, X));
      before[make_pair(Y,X)] = p;
      //dist[Y][X] = dist[y][x] + 1;
      used[Y][X] = true;
      if (Y == H-1 && X == W-1) {
        P current = make_pair(Y,X);
        while (!(current.second == 0 && current.first == 0)) {
          history.push_back(current);
          current = before[current];
        }
        history.push_back(current);
        return true;
      }
    }
  }
  return false;
}

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

  cin >> H >> W;
  fields.resize(H);
  used.resize(H);

  ll white_count = 0;
  rep(i, H) {
    fields[i].resize(W);
    used[i].resize(W, false);
    rep(j, W) {
      cin >> fields[i][j];
      if (fields[i][j] != wall) white_count++;
    }
  }
  if(bfs()) {
    cout << white_count - history.size() << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}

Measured memory_bytes: 512
import heapq


def main():
    nvertices, nedges, s = map(int, input().split())
    adj = [[] for i in range(nvertices)]
    for i in range(nedges):
        u, v, w = map(int, input().split())
        adj[u].append((v, w))

    INF = float('inf')
    costs = [INF] * nvertices
    costs[s] = 0
    que = [(0, s)]
    for i in range(1, nvertices):
        que.append((INF, 1))
    cnt = 0
    while que:
        cost, u = heapq.heappop(que)
        if cost > costs[u]:
            continue
        costs[u] = cost
        for v, w in adj[u]:
            if costs[v] > costs[u] + w:
                costs[v] = costs[u] + w
                heapq.heappush(que, (costs[v], v))
        cnt += 1
        if cnt == nvertices:
            break

    for i in range(nvertices):
        print(costs[i] if costs[i] < INF else "INF")


main()

Measured memory_bytes: 99672
fun main(args: Array<String>) {
    val (n, h, w) = readLine()!!.split(" ").map { it.toInt() }
    val xs = (1..n).map { readLine()!!.split(" ").map { it.toLong() } }

    val ans = xs.filter { h <= it[0] && w <= it[1] }.size
    println(ans)
}

Measured memory_bytes: 38476
#include<bits/stdc++.h>
using namespace std;
double x,nowm=100.0;
long long t;
int main(){
	scanf("%lf",&x);
	while(nowm<x){
		double tm=nowm*0.01;
		nowm+=floor(tm);
		t++;
	}
	printf("%d\n",t);
	return 0;
}


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

const long long INF = 1000000000;

typedef long long ll;

#define writeln(n) cout<<n<<"\n";

typedef pair<int, int> P;
typedef pair<string, int> Psi;





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

	string s; cin>>s;
	
	if(s =="Sunny"){
		writeln("Cloudy");
		
	}else if (s == "Cloudy") {
		writeln("Rainy");
	}else {
		writeln("Sunny");
	}
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<ll>())
#define ll long long
#define rep(i, s, g) for (ll i = (s); i < (g); i++)
#define mod 1000000007
#define vfind(v, target) find(v.begin(), v.end(), target)
#define notFound(v, target) (vfind(v, target) == v.end())

using namespace std;

int main()
{
  ll N, K; cin >> N >> K;
  vector<ll> count(N, 0);
  rep(i, 0, N) {
  	ll A; cin >> A; A--;
    count[A]++;
  }
  rvsort(count);
  rep(i, 0, K) {
  	N -= count[i];
  }
  cout << N << endl;
}

Measured memory_bytes: 1792
def combinations_count(n, k, M):
    if k == 0:
        return 1
    fn = 0
    fk = 0
    fnk = 0
    cur = 1
    M = int(1e9+7)
    for i in range(1, n+1):
        cur = (cur * i) % M
        if i == n:
            fn = cur
        if i == n-k:
            fnk = cur
        if i == k:
            fk = cur
 
    return (fn * (modpow(fk , (M-2), M)) * modpow(fnk , (M-2), M))%M

def modpow(a,b,M):
    if b == 1:
        return a % M
    if b % 2 == 1:
        return (modpow(a,(b-1)//2,M)**2 * a)%M
    return (modpow(a,b//2,M) ** 2) % M 

x,y=map(int,input().split())

if ((x+y)%3!=0 or (2<max(x,y)/min(x,y))):
    print(0)
    exit(0)

max_value=max(x,y)
min_value=min(x,y)

base_max=max_value//2
base_min=max_value%2

diff_value=min_value-base_min*2-base_max

base_max-=diff_value//3
base_min+=diff_value//3*2

print(combinations_count(base_max+base_min,min(base_max,base_min),10**9+7))

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

int main(){
 int a,b;
 cin>>a>>b;
string str = to_string(a);
   str+=to_string(b);
ll x = stoi(str);
ll u = sqrt(x);
if(u*u==x){
    cout<<"Yes"<<endl;
}
else cout<<"No"<<endl;
return 0;
}


Measured memory_bytes: 256
def main():
  a, v = map(int, input().split())
  b, w = map(int, input().split())
  t = int(input())

  if a == b:
    print("YES")
    return

  dis = abs(a - b)
  s = v - w
  dis -= s * t

  if dis <= 0:
    print("YES")
  else:
    print("NO")


main()


Measured memory_bytes: 9180
#include <iostream>

using namespace std;
int Memo[31];

void recursion(int depth, int n, int m)
{
	if (n == 0)
	{
		cout << Memo[0];
		for (int i = 1; i < depth; ++i)
		{
			cout << " " << Memo[i];
		}
		cout << endl;
	}
	if (m > n)
	{
		m = n;
	}
	for (int i = m; i >= 1; --i)
	{
		Memo[depth] = i;
		recursion(depth + 1, n - i, i);
	}
}

void solve()
{
	int n;
	while (cin >> n, n)
	{
		recursion(0, n, n);
	}
}

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

Measured memory_bytes: 1160
//参考：http://ehafib.hatenablog.com/entry/2015/12/23/164517
//インクルード
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

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

  int n;
	cin >> n;
  int buka[n];
  FOR(i, 0, n-1){
    buka[i] = 0;
  }
  FOR(i, 2, n) {
    int x;
    cin >> x;
    buka[x-1] += 1;
  }
  FOR(i, 0, n-1){
    cout << buka[i] << "\n";
  }
	//cout << x * x * x << "\n";
}


Measured memory_bytes: 3944
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
int main()
{
  int N, M;
  cin >> N >> M;
  vector<P> A, C;
  for (int i = 0; i < N; i++)
  {
    int s, t;
    cin >> s >> t;
    A.push_back({s, t});
  }
  for (int i = 0; i < M; i++)
  {
    int s, t;
    cin >> s >> t;
    C.push_back({s, t});
  }
  for (int i = 0; i < N; i++)
  {
    int ans = 1;
    int Min = 1000000000;
    int a = A[i].first, b = A[i].second;
    for (int j = 0; j < M; j++)
    {
      int c = C[j].first, d = C[j].second;
      int dist = abs(a - c) + abs(b - d);
      if (dist < Min)
      {
        Min = dist;
        ans = j + 1;
      }
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
using P = pair<int,int>;
using ll = long long;
static const int INF = 1000000000;
static const ll MOD = 1000000007;
ll gcd(ll a, ll b){return b!=0 ? gcd(b, a%b) : a;}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n){
    cin >> a[i];
    a[i]--;
  }

  vector<int> count(n, 0);
  int next = a[0];
  int pre = a[0];
  int start = 0;
  ll t = n;
  bool tmp = false;
  for(int i = 1; i <= n; ++i){
    if(count[next] == 0){
      count[next] = i;
    }
    else{
      t = i - count[next];
      start = pre;
      if(k <= count[next] - 1){
        tmp = true;
      }
      else{
        k -= count[next] - 1;
      }
      break;
    }
    pre = next;
    next = a[next];
  }

  if(!tmp)
  {
    k %= t;
    next = start;
    for(int i = 0; i < k; ++i){
      next = a[next];
    }
  }
  else{
    next = a[0];
    for(int i = 0; i < k - 1; ++i){
      next = a[next];
    }
  }

  cout << (next + 1) << endl;
  return 0;
}

Measured memory_bytes: 4784
#include <bits/stdc++.h>
#include <limits>
 
using namespace std;
typedef std::numeric_limits< double > dbl;
int main() {
    int n,i=0,j;
    double avg=0.0;
    cin>>n;
    int a[n],b[n];
    while(i<n){
       cin>>a[i]>>b[i]; 
        i++;
    }
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            if(i!=j){
            avg+=sqrt(pow((a[i]-a[j]),2)+pow((b[i]-b[j]),2));
            }
        }
    }
    cout.precision(12);
    cout<<avg/n;
    
    return 0;
}

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

#define ll long long
#define Fi first
#define Se second
#define Pb push_back
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
#define vvp vector<vector<pair<int,int>>>

const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>; //Caution!! Segmentation Fault!! Don't forget to add +1!

#define all(v) v.begin(),v.end()
#define output_s(a) printf("%s\n",(a).c_str())

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m) for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m) for(int i=(int)(n);i>=(int)(m);i--)
#define RepA(x) for(auto &item:(x))

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

template<typename TypeInt> //最大公約数
TypeInt GCD(TypeInt a,TypeInt b){
    if(a%b==0) return b;
    else return GCD(b,a%b);
}
template<typename TypeInt> //最小公倍数
TypeInt LCM(TypeInt a,TypeInt b){
    return a*b/GCD(a,b);
}

int IN_int(){
    int x;
    scanf("%d",&x);
    return x;
}

//----------------------library------------------------//

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

const int NMAX = 200;
bool flag;

bool comp(int x,int y){
    return abs(0-x)<abs(0-y);
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    CIN(N);
    vi A(N);
    rep(i,N) cin>>A[i];
    sort(all(A));
    printf("%d\n",A[N-1]-A[0]);

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<utility>
#include<numeric>
#include<iomanip>
#include<climits>

using namespace std;
using ll = long long;

int main() {
    int n, q;
    string s;
    cin >> n >> q;
    cin >> s;
    vector<int> ac(n);
    int countAC(0);
    ac[0] = 0;
    for (int i=1; i<n; ++i) {
        if (s[i-1] == 'A' && s[i] == 'C') {
            ++countAC;
        }
        ac[i] = countAC;
    }
    int l, r;
    for (int i=0; i<q; ++i) {
        cin >> l >> r;
        cout << ac[r-1] - ac[l-1] << endl;
    }
}


Measured memory_bytes: 1408
/*
	Copyright: razouq (c)
	Author: Anass BENDARSI
	Date: 18/09/2017 09:46:35
	flamers will **** you
*/
#include<bits/stdc++.h>
//#include<flamers.h>
#define ll long long
#define ull unsigned long long
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define POB pop_back
#define dist(a, b) sqrt(a*a + b*b)
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<pair<int, int>> vipi;
bool compare(pi p1, pi p2){
	 if(1) return true;
	 return false;
}

int main(){
//	freopen("input.in", "r", stdin);
//	freopen("output.out", "w", stdout);
	ios::sync_with_stdio(0);
	cin.tie();
	int n, a;
	cin>>n>>a;
	cout<<n*n-a<<endl;
	return 0;
}


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

int main(){
  string n;
  cin >> n;
  reverse(n.begin(), n.end());
  if(n[0] == '3')
    cout << "bon\n";
  else if((n[0] == '0')||(n[0] == '1')||(n[0] == '6')||(n[0] == '8'))
    cout << "pon\n";
  else
    cout << "hon\n";
  return 0;
}
  

Measured memory_bytes: 3624
N = int(input())
X = [[] for i in range(N)]
for i in range(N-1):
    x, y = map(int, input().split())
    X[x-1].append(y-1)
    X[y-1].append(x-1)

P = [-1] * N
DE = [0] * N
Q = [0]
while Q:
    i = Q.pop()
    for a in X[i][::-1]:
        if a != P[i]:
            P[a] = i
            DE[a] = DE[i] + 1
            X[a].remove(i)
            Q.append(a)

def lp(u, v):
    t = 0
    while u != v:
        if DE[u] > DE[v]:
            t += 1 << u-1
            u = P[u]
        elif DE[u] < DE[v]:
            t += 1 << v-1
            v = P[v]
        else:
            t += 1 << u-1
            t += 1 << v-1
            u = P[u]
            v = P[v]
    
    return t

Y = []
M = int(input())
for _ in range(M):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    Y.append(lp(a, b))

def popcnt(n):
    c = (n & 0x5555555555555555) + ((n>>1) & 0x5555555555555555)
    c = (c & 0x3333333333333333) + ((c>>2) & 0x3333333333333333)
    c = (c & 0x0f0f0f0f0f0f0f0f) + ((c>>4) & 0x0f0f0f0f0f0f0f0f)
    c = (c & 0x00ff00ff00ff00ff) + ((c>>8) & 0x00ff00ff00ff00ff)
    c = (c & 0x0000ffff0000ffff) + ((c>>16) & 0x0000ffff0000ffff)
    c = (c & 0x00000000ffffffff) + ((c>>32) & 0x00000000ffffffff)
    return c

D = {1<<i: i for i in range(50)}
Z = [0] * (1<<M)
ans = 0
CC = [0] * N
for m in range(1<<M):
    a = m & (-m)
    if a == m:
        if a == 0:
            Z[m] = 0
        else:
            Z[m] = Y[D[a]]
    else:
        Z[m] = Z[m^a] | Y[D[a]]
    
    CC[N - 1 - popcnt(Z[m])] += (1 if popcnt(m) & 1 == 0 else -1)

print(sum([2 ** i * CC[i] for i in range(N)]))

Measured memory_bytes: 49128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int h;
		Scanner in = new Scanner(System.in);
		h = in.nextInt();
		int[] heap = new int[h];
		for(int i = 0; i < h; i++) {
			heap[i] = in.nextInt();
		}
		for(int i = h/2; i >= 0; i--) {
			heap = maxHeapify(heap, i, h);
		}
		for(int n: heap) {
			System.out.print(" " + n);
		}
		System.out.println();
	}
	
	public static int[] maxHeapify(int[] a, int i, int h) {
		int l = (2 * i) + 1;
		int r = (2 * i) + 2;
		int largest;
		
		if(l < h && a[l] > a[i]) {
			largest = l;
		}
		else {
			largest = i;
		}
		if(r < h && a[r] > a[largest]) {
			largest = r;
		}
		if(largest != i) {
			int temp = a[i];
			a[i] = a[largest];
			a[largest] = temp;
			return maxHeapify(a, largest, h);
		}
		else {
			return a;
		}
	}
}


Measured memory_bytes: 167916
#include<stdio.h>
int score[10001];
int main(int argc, char const *argv[]){
	int n,s,i,max=0,j;
	scanf("%d",&n);
	score[0]=1;
	for(i=0;i<n;i++){
		scanf("%d",&s);
		for(j=max;j>=0;j--){
			if(score[j]==1){
				score[j+s]=1;
				if(max<j+s) max=j+s;
			}
		}
	}
	for(i=max;i>0;i--){
		if(score[i]==1 && i%10!=0){
			printf("%d\n",i);
			return 0;
		}
	}
	printf("0\n");
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>
#include<iterator>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, char> plc;

int p[110];

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

	int mx = 0;
	for (int i = 1; i <= 100; i++) {
		int num = 0;
		for (int j = 0; j < n; j++) {
			if (p[j] >= i) num++;
		}
		if (num >= i)mx = i;
	}
	cout << mx << endl;
	return 0;
}

Measured memory_bytes: 3096
import sys
sys.setrecursionlimit(10**9)

read=sys.stdin.read
class Unionfind():
    def __init__(self,n):
        self.parents=[-1]*n
        self.dist=[0]*n 
    
    def find(self,x):
        if self.parents[x]<0:
            return self.dist[x],x
        else:
            tmp=self.find(self.parents[x])
            self.dist[x]+=tmp[0]
            self.parents[x]=tmp[1]
        return self.dist[x], self.parents[x]
    
    def union(self,x,y,d):
        rx=self.find(x)[1]
        ry=self.find(y)[1]
        diff=self.dist[y]-self.dist[x]-d
        if rx==ry:
            if diff!=0:
                return True
            return False
        if diff<0:
            rx,ry=ry,rx
            diff=-diff
        self.parents[ry]=min(self.parents[ry],self.parents[rx]-diff)
        self.parents[rx]=ry
        self.dist[rx]=diff
        return False
    
def main():
    n,m,*lrd=map(int,read().split())
    v=Unionfind(n)
    for l,r,d in zip(*[iter(lrd)]*3):
        if v.union(l-1,r-1,d):
            print('No')
            break
    else:
        if max(-d-1 for d in v.parents if d<0) >10**9:
            print('No')
        else:
            print('Yes')
if __name__=='__main__':
    main()


Measured memory_bytes: 74252
import java.util.Scanner

import scala.collection.Searching._
import scala.annotation.tailrec
import scala.collection.immutable.Queue

class IUnionFind(val size: Int) {

  private case class Node(var parent: Option[Int], var treeSize: Int)

  private val nodes = Array.fill[Node](size)(new Node(None, 1))

  def union(t1: Int, t2: Int): IUnionFind = {
    if (t1 == t2) return this

    val root1 = root(t1)
    val root2 = root(t2)
    if (root1 == root2) return this

    val node1 = nodes(root1)
    val node2 = nodes(root2)

    if (node1.treeSize < node2.treeSize) {
      node1.parent = Some(t2)
      node2.treeSize += node1.treeSize
    } else {
      node2.parent = Some(t1)
      node1.treeSize += node2.treeSize
    }
    this
  }

  def connected(t1: Int, t2: Int): Boolean = t1 == t2 || root(t1) == root(t2)

  @tailrec
  private def root(t: Int): Int = nodes(t).parent match {
    case None => t
    case Some(p) => root(p)
  }
}


object Main {
  def check(a: Long, b: Long): Boolean = {
    if ((a + b) % 2 == 0 && (a + b) / 2 >= 0 && b - (a + b) / 2 >= 0) (true) else (false)
  }

  def solve(sc: => Scanner): Unit = {
    val A = sc.nextLong()
    var i = 1L
    var ans = 0
    while (i <= A * 10) {
      if ((A % i * 10 >= i) && check(A / i, A % i)) {
        ans += 1
      }
      i *= 10
    }
    println(ans)
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}

Measured memory_bytes: 45076
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner scan=new Scanner(System.in);
    HashMap<String,Integer> week=new HashMap<String,Integer>();
    String S=scan.nextLine();
    week.put("MON",0);
    week.put("TUE",1);
    week.put("WED",2);
    week.put("THU",3);
    week.put("FRI",4);
    week.put("SAT",5);
    week.put("SUN",6);
    
    for(int value:week.values()){
      if(value==week.get(S)){
        int ans=6-value;
        if(ans>0){
          System.out.println(ans);
         }
        else{
          System.out.println(ans+7);
       }
       break;
      }
      }
    }
}

Measured memory_bytes: 23892
import java.util.*

fun main(args : Array<String>) {
    val sc = Scanner(System.`in`)
    val a = sc.nextLong()
    val b = sc.nextLong()
    println(problem135a(a,b))
}

fun problem135a(a: Long, b: Long): String {
    if ((a % 2 == 0L && b % 2 != 0L) || (a % 2 != 0L && b % 2 == 0L)) return "IMPOSSIBLE"
    if (a == 0L || b == 0L) return "IMPOSSIBLE"
    return ((a + b) / 2).toString()
}


Measured memory_bytes: 29596
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

int main()
{
    const ll MOD = 1e9+7;
    int N;
    cin >> N;
    vector<ll> A(N);
    for(int i=0; i<N; i++) cin >> A[i];

    vector<ll> num(3, 0);
    ll ans = 1;
    for(int i=0; i<N; i++){
        int k = 0;
        for(int j=0; j<3; j++){
            if(num[j] == A[i]) k++;
        }
        ans *= k; ans %= MOD;
        for(int j=0; j<3; j++){
            if(num[j] == A[i]){
                num[j]++; break;
            }
        }
    }

    cout << ans << endl;
}

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

#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define ll long long
#define ldb long double 
#define db double
#define str string

#define fr first
#define se second
#define lb lower_bound 
#define ub upper_bound 
#define pb push_back
#define mpr make_pair

#define pi pair<int,int>
#define pll pair<ll,ll>
#define pdb pair<db,db>
#define pldb pair<ldb,ldb>

#define vi vector<int>
#define vll vector<ll>
#define vdb vector<db>
#define vldb vector<ldb>
#define vpi vector< pi >
#define vpll vector< pll >

#define mi map<int,int>
#define mll map<ll,ll>
#define mdb map<db,db>
#define mldb map<ldb,ldb>


#define forr(a,b) for (int i = (a); i < (b); ++i)
#define rrof(a,b) for (int i = (b)-1; i >= (a); --i)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)

const int md = 1e9+7;
const int MX = 2e5+5;
const ll INF = 1e18; 
const ldb PI = 4*atan((ldb)1);

ll power(ll a,ll n)
{
 ll res=1;
 while(n)
{
 if(n%2)
  res*=a;
  a*=a;
  n/=2;
}
return res;
}

ll abst(ll a)
{
 return ((a<0)?(-1*a):(a));
}

int main()
{
    ll h;
    cin>>h;
    ll sum=0;
    ll p=1;
    while(h)
    {
        sum+=p;
        p*=2;
        h/=2;
    }
    cout<<sum;
      return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(void) {
	int n, tmp, sum, suml[10];
	int i, j;

	while(true) {
		cin >> n;
		if(n == 0) { break; }
		for(i = 0; i < 10; i++) {
			suml[i] = 0;
		}
		for(i = 0; i < n; i++) {
			sum = 0;
			for(j = 0; j < n; j++) {
				cin >> tmp;
				cout.width(5);
				cout << tmp;
				suml[j] += tmp;
				sum += tmp;
			}
			cout.width(5);
			cout << sum << endl;
		}
		sum = 0;
		for(i = 0; i < n; i++) {
			cout.width(5);
			cout << suml[i];
			sum += suml[i];
		}
		cout.width(5);
		cout << sum << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include<iostream>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1 << 21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX][MAX];

int prim() {
	int u, min_value;
	int d[MAX], p[MAX], color[MAX];

	for (int i = 0; i < n; i++) {
		d[i] = INFTY;
		p[i] = -1;
		color[i] = WHITE;
	}

	d[0] = 0;

	while (true) {
		min_value = INFTY;
		u = -1;
		for (int i = 0; i < n; i++) {
			if (min_value > d[i] && color[i] != BLACK) {
				u = i;
				min_value = d[i];
			}
		}
		if (u == -1) break;
		color[u] = BLACK;
		for (int v = 0; v < n; v++) {
			if (color[v] != BLACK && M[u][v] != INFTY) {
				if (d[v] > M[u][v]) {
					d[v] = M[u][v];
					p[v] = u;
					color[v] = GRAY;
				}
			}
		}
	}
	int sum = 0;
	for (int i = 0; i < n; i++) {
		if (p[i] != -1) sum += M[i][p[i]];
	}

	return sum;
}

int main() {
	cin >> n;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			int e;
			cin >> e;
			M[i][j] = (e == -1) ? INFTY : e;
		}
	}

	cout << prim() << endl;

	return 0;
}

Measured memory_bytes: 1200
def main():
    K = int(input())
    N = 50

    q, r = divmod(K, N)
    a = [x + q for x in range(N)]  # 全体への操作をqセットでき、1セットあたり全体1増加
    for i in range(N):
        if i < r:
            a[i] += N
            a[i] -= r - 1
        else:
            a[i] -= r

    print(N)
    print(*a)


if __name__ == '__main__':
    main()

# 0,1,2,...,N-1
# N,0,1,2,...,N-2
# N-1,N,0,1,2,...,N-3
# ...
# ...0,1
# ...N,0
# ...N-1,N

# 毎回どこかが0になり、そこをN加算し、他を1引く
# 全体を一回ずつ操作するとN加算してN-1引くので、1増える


Measured memory_bytes: 3060
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <map>
#include <string>
using namespace std;
typedef long long LL;
const LL N = 1000000007;
const LL M = 5005;

LL ec = 0,hed[M],to[M << 1],nxt[M << 1];
LL dp[M][M],tmp[M],siz[M],g[M];
void add_edge(LL f,LL t){
	++ ec; to[ec] = t; nxt[ec] = hed[f]; hed[f] = ec;
}

void dfs(LL u,LL f){
	siz[u] = 1; dp[u][1] = 1;
	for(LL i = hed[u];i;i = nxt[i]){
		LL v = to[i];
		if(v == f) continue;
		dfs(v,u);
		for(LL i = siz[u];i >= 0;i --){
			for(LL j = siz[v];j >= 0;j --){
				tmp[i + j] = (tmp[i + j] + dp[u][i] * dp[v][j] % N) % N;
			}
		}
		for(LL i = 0;i <= siz[u] + siz[v];i ++){
			dp[u][i] = tmp[i];
			tmp[i] = 0;
		}
		siz[u] += siz[v];
	}
	for(LL i = 1;i <= siz[u];i ++) dp[u][0] = (dp[u][0] - dp[u][i] * g[i] % N + N) % N;
}

int main(){
	LL n,u,v;
	cin >> n;
	g[0] = 1; g[1] = 0;
	for(LL i = 2;i <= n;i ++) g[i] = (g[i - 2] * (i - 1)) % N;
	for(LL i = 1;i < n;i ++){
		cin >> u >> v;
		add_edge(u,v);
		add_edge(v,u);
	}
	dfs(1,0); cout << (N - dp[1][0]) % N << '\n';
	return 0;
}

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

int main() {

  int N,A,B;
  A=0;
  B=0;
  cin>>N;
  
  vector<int>V(N);
  for(int i=0;i<N;i++){
    cin>>V.at(i);
  }
  for(int j=0;j<N-1;j++){
  for(int i=j;i<N-1;i++){
    if(V.at(i)<V.at(i+1)){
    int j=i-1;
    break;
    }
    else B++;
  }
    A=max(A,B);
    if(A>N/2-1)break;
       B=0;
  }
  cout<<A<<endl;
}

      
  

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a[7] = { 1, 3, 5, 7, 8, 10, 12 };
    int b[4] = { 4, 6, 9, 11};
    int c[1] = { 2 };
    int x, y;
    cin >> x >> y;
    if(x == y && x == 2) {
        puts("Yes");
        return 0;
    }
    for(int i = 0; i < 7; i++) {
        if(a[i] == x) {
            for(int j = 0; j < 7; j++) {
                if(a[j] == y) {
                    puts("Yes");
                    return 0;
                }
            }
        }
    }
    for(int i = 0; i < 4; i++) {
        if(b[i] == x) {
            for(int j = 0; j < 4; j++) {
                if(b[j] == y) {
                    puts("Yes");
                    return 0;
                }
            }
        }
    }
    puts("No");
}

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

int main(){
	int n, m;
	cin >> n >> m;
	vector<vector<int> > a(n,vector<int>(m));
	vector<int> b(m);
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin >> a[i][j];
		}
	}
	for(int i=0;i<m;i++){
		cin >> b[i];
	}
	for (int i=0;i<n;i++){
		int c=0;
		for(int j=0;j<m;j++){
			c+=a[i][j]*b[j];
		}
		cout << c << endl;
	}
	return 0;
}

Measured memory_bytes: 1256
a, b = map(int, input().split())

if a == b:
    print(a)
elif b - a == 1:
    print(a^b)
elif b - a == 2:
    print(a^(a+1)^(b))
else:
    if a % 2 == 0:
        a_num = 0
        a_index = a
    else:
        a_num = a
        a_index = a+1
    if b % 2 == 1:
        b_num = 0
        b_index = b
    else:
        b_num = b
        b_index = b-1
    if ((b_index - a_index + 1) // 2) % 2 == 1:
        r = 1
    else:
        r = 0
    print(a_num ^ b_num ^ r)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<math.h>
#include<unordered_map>
using namespace std;
typedef long long ll;
const long double pi = 3.14159265358979323846264338327950288;
int main() {
	ll x;
	cin >> x;
	ll b = floor(x / 11.0);
	ll a= b* 11;
	b *= 2;
	if (a>=x) {
		cout << b << endl;
	}
	else if (a + 6 >= x) {
		cout << b + 1 << endl;
	}
	else {
		cout << b + 2 << endl;
	}
	cin >> x;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <ctime>
#include <climits>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 999999999

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int const MOD = 1000000007;

namespace std {
    bool operator<(const P a, const P b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int main() {
    string s; cin >> s;
    if(s.length() == 2) {
        if(s[0] == s[1]) {cout << 1 << " " << 2 << endl; return 0;}
        else {cout << -1 << " " << -1 << endl; return 0;}
    }
    else {
        rep(i,2,s.length()) {
            if(s[i-2] == s[i-1] || s[i-1] == s[i] || s[i-2] == s[i]) {
                cout << i-1 << " " << i+1 << endl;
                return 0;
            }
        }
    }
    cout << -1 << " " << -1 << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> ii;
#define F first
#define S second
#define sqr(x) (x)*(x)
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,x,y) for(int i=x;i<(y);++i)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
/* start */

const double PI = acos(-1);

signed main(){
    int r;
    cin >> r;
    cout << 2*r*PI << "\n";
}

Measured memory_bytes: 3784
#include<stdio.h>
int main(void){
	int i,j,n,m,judge,cost[1000],game[1000],chosen;
	scanf("%d%d",&n,&m);
	for(i=0; i<n; i++){
		scanf("%d",&cost[i]);
		game[i]=0;
	}
	for(i=0; i<m; i++){
		scanf("%d",&judge);
		j=0;
		while(cost[j]>judge){
			j++;
		}
		game[j]++;
	}
	chosen=0;
	for(i=1; i<n; i++){
		if(game[chosen]<game[i]){
			chosen=i;
		}
	}
	printf("%d\n",chosen+1);
	return 0;
}

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

#define Solved int main()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define forn(i, n) for(int i = 1; i <= n; i++)
#define rep(i, x, y) for(int i = x; i <= y; i++)
#define sz(x) (int)x.size()
#define pii pair<int, int>
#define ll long long
#define ull unsigned long long
#define ld long double
#define mii map<int, int>
#define all(x) x.begin(), x.end()
#define lb lower_bound
#define ub upper_bound
using namespace std;

inline ll bip(ll x,ll n,ll mod){ll res=1;while(n){if(n&1){res=(res*x)%mod;}x=(x*x)%mod;n>>=1;}return res;}

const int maxn = 1e9;
const ll inf = 1e18;
const int mod = 998244353;
//const int mod = 1e9 + 7;
const int N = 1e5 + 10;

string s, t;
int dp[3011][3011];

void solve() {
    cin >> s >> t;

    s = ' ' + s;
    t = ' ' + t;
    for (int i = 1; i <= s.size(); i++) {
        for (int j = 1; j <= t.size(); j++) {
            if (s[i] == t[j]) {
                dp[i][j] = dp[i - 1][j - 1] + 1;
            }
            else {
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            }
        }
    }

    int i = s.size() - 1, j = t.size() - 1;
    string ans = "";
    while (i && j) {
        if (s[i] == t[j]) ans += s[i], i--, j--;
        else {
            if (dp[i][j] == dp[i - 1][j]) i--;
            else j--;
        }
    }

    reverse(all(ans));
    for (int i = 0; i < ans.size(); i++)
        cout << ans[i];
}

Solved {
    SpeedForce;
	int tt = 1;
    //cin >> tt;
	while (tt--) {
		solve();
		cout << '\n';
	}

}


Measured memory_bytes: 35584
#include <stdio.h>
int main(void){
    int N, i, j, cnt = 0;
    
    scanf("%d", &N);
    
    for(i = 0; i <= N / 4; i++){
        for(j = 0; j <= (N - 4 * i) /  7; j++){
            if((i * 4) + (j * 7) == N){
                printf("Yes\n");
                return 0;
            }
        }
    }
    printf("No\n");
    return 0;
}


Measured memory_bytes: 1636
import           Control.Monad
import qualified Data.Array.IO               as IO
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

-- compulte a^n `mod` p
modpow :: Int -> Int -> Int -> Int
modpow a n p =
  let modpow' a n res | n == 0    = res
                      | otherwise =
                          modpow' (a*a`mod`p)
                                  (n `shiftR` 1)
                                  (if (n .&. 1) == 1 then res * a `mod` p else res)
  in modpow' a n 1

main = do
  [n, k] <- getIntList

  d <- VM.new (k+1)
  VM.set d (0::Int)

  let p = 10^9 + 7 :: Int

  forM_ [k,(k-1)..1] $ \x -> do
    let c = modpow (k `div` x) n p
    VM.write d x c
    when (k `div` x >= 2) $
      forM_ [2..(k `div` x)] $ \i -> do
        t <- VM.read d (i*x)
        c' <- VM.read d x
        VM.write d x ((c' - t) `mod` p)

  d' <- V.freeze d

  VM.write d 0 0
  forM_ [1..k] $ \i -> do
    t <- VM.read d 0
    VM.write d 0 ((i * (d' V.! i) `mod` p + t) `mod` p)

  ans <- VM.read d 0
  print ans

Measured memory_bytes: 6460
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int main(){
    //~ freopen("file.in", "r", stdin);
    int n;
    scanf("%d",&n);
    ll ans=0;
    while(n--){
		int l,r;
		scanf("%d%d",&l,&r);
		ans+=(r-l+1);
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((ll)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define pb push_back
#define mp make_pair
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
typedef long long ll;
ll INF = 1e18;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
using namespace std;
using Data = pair<ll, vector<ll>>;

int main(){
  ll x,y,z,k; cin >> x >> y >> z >> k;
  vector<ll> A(x),B(y),C(z);
  rep(i,x) cin >> A[i];
  rep(i,y) cin >> B[i];
  rep(i,z) cin >> C[i];
  
  sort(all(A), greater<ll>());
  sort(all(B), greater<ll>());
  sort(all(C), greater<ll>());
  priority_queue<Data> q;
  set<Data> se;
  q.push(Data(A[0]+B[0]+C[0], vector<ll>({0,0,0})));
  
  rep(i,k){
    Data top = q.top(); q.pop();
    ll a = top.second[0];
    ll b = top.second[1];
    ll c = top.second[2];
    cout << top.first << endl;
    if(a+1<x){
      auto data = Data(A[a+1]+B[b]+C[c], vector<ll>({a+1,b,c}));
      if(!se.count(data))
        se.insert(data), q.push(data);
    }
    if(b+1<y){
      auto data = Data(A[a]+B[b+1]+C[c], vector<ll>({a,b+1,c}));
      if(!se.count(data))
        se.insert(data), q.push(data);
    }
    if(c+1<z){
      auto data = Data(A[a]+B[b]+C[c+1], vector<ll>({a,b,c+1}));
      if(!se.count(data))
        se.insert(data), q.push(data);
    }
  }
  




  return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename T1, typename T2>
inline void chmin(T1 &a, T2 b) {
  if (a > b) a = b;
}
template <typename T1, typename T2>
inline void chmax(T1 &a, T2 b) {
  if (a < b) a = b;
}

const ll MAX = 2020;
ll dpL[MAX][MAX] = {};
ll dpR[MAX][MAX] = {};
ll dpU[MAX][MAX] = {};
ll dpD[MAX][MAX] = {};

int main() {
  ll h, w;
  cin >> h >> w;
  vector<string> st(h);
  for (ll i = 0; i < h; i++) cin >> st[i];

  for (ll i = 0; i < h; i++) {
    for (ll j = 0; j < w; j++) {
      if (st[i][j] == '#') continue;
      dpL[i][j] = (j ? dpL[i][j - 1] : 0) + 1;
      dpU[i][j] = (i ? dpU[i - 1][j] : 0) + 1;
    }
  }
  for (ll i = h - 1; i >= 0; i--) {
    for (ll j = w - 1; j >= 0; j--) {
      if (st[i][j] == '#') continue;
      dpR[i][j] = (j + 1 < w ? dpR[i][j + 1] : 0) + 1;
      dpD[i][j] = (i + 1 < h ? dpD[i + 1][j] : 0) + 1;
    }
  }

  ll ans = 0;
  for (ll i = 0; i < h; i++)
    for (ll j = 0; j < w; j++)
      if (st[i][j] == '.')
        chmax(ans, dpL[i][j] + dpR[i][j] + dpU[i][j] + dpD[i][j] - 3);

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


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef tuple<int, int> duo;
const int dx[] = {0, 0, 0, 1, -1, 1, 1, -1, -1};
const int dy[] = {0, 1, -1, 0, 0, 1, -1, 1, -1};
const int Mod = 1000000000 + 0;
//{{{ templates
#define TT_ template<typename T>inline
#define TTF_ template<typename T,typename F>inline
TT_ T sq(T x){return x*x;}
TT_ T In(){T x;cin>>x;return x;}
TT_ void Out(T&x){cout<<x;}
TT_ void sort(T&v){sort(begin(v),end(v));}
TT_ void revs(T&v){reverse(begin(v),end(v));}
TT_ void uniq(T&v){sort(v);v.erase(unique(begin(v),end(v)),end(v));}
TT_ int ubnd(T&v,typename T::value_type&x){return upper_bound(begin(v),end(v),x)-begin(v);}
TT_ int lbnd(T&v,typename T::value_type&x){return lower_bound(begin(v),end(v),x)-begin(v);}
TTF_ void inpt(T&v,int n,F f){for(v.reserve(n);n--;v.emplace_back(f()));}
TTF_ void show(T&v,F f,string d=" ",string e="\n"){int i=0;for(auto&x:v)i++&&(cout<<d),f(x);cout<<e;}
TT_ typename T::iterator minel(T&v){return min_element(begin(v),end(v));}
TT_ typename T::iterator maxel(T&v){return max_element(begin(v),end(v));}

inline void fast_io(){ios::sync_with_stdio(0);cin.tie(0);}
inline int in(){int x;scanf("%d",&x);return x;}
inline ll pow_mod(ll a,ll k,ll m){ll r=1;for(;k>0;a=a*a%m,k>>=1)if(k&1)r=r*a%m;return r;}
inline ll mod_inv(ll a,ll p){return pow_mod(a,p-2,p);}
//}}} priority_queue queue deque front stringstream max_element min_element insert count make_tuple

const int px[] = {2, 2, 2, -2, -2, -2, 1, 0, -1, 1, 0, -1};
const int py[] = {1, 0, -1, 1, 0, -1, 2, 2, 2, -2, -2, -2};

bool invalid(int x, int y){
  return 0 > x || x >= 10 || 0 > y || y >= 10;
}

int main()
{
  int fx, fy;
  while (fx = in(), fy = in(), fx || fy){
    int n = in();
    int field[11][10][10] = {};
    field[0][fy][fx] = 1;
    for (int t = 1; t <= n; t++){
      int sx, sy;
      sx = in(), sy = in();
      for (int d = 0; d < 9; d++){
       int nx = sx + dx[d], ny = sy + dy[d];
       if (invalid(nx, ny)) continue;
       for (int dd = 0; dd < 12; dd++){
         int nnx = nx + px[dd], nny = ny + py[dd];
         if (invalid(nnx, nny)) continue;
         field[t][ny][nx] += field[t - 1][nny][nnx];
       }
      }
    }
    int tot = 0;
    for (int x = 0; x < 10; x++){
      for (int y = 0; y < 10; y++){
        tot += field[n][y][x];
      }
    }
    if (tot == 0) puts("NA");
    else puts("OK");
  }
  return 0;
}

Measured memory_bytes: 1156
--https://www.lua.org/pil/11.4.html
local List = {}
function List.new ()
  return {first = 0, last = -1}
end

function List.pushleft (list, value)
  local first = list.first - 1
  list.first = first
  list[first] = value
end

function List.pushright (list, value)
  local last = list.last + 1
  list.last = last
  list[last] = value
end

function List.popleft (list)
  local first = list.first
  if first > list.last then return false end
  local value = list[first]
  list[first] = nil
  list.first = first + 1
  return value
end

function List.popright (list)
  local last = list.last
  if list.first > last then return false end
  local value = list[last]
  list[last] = nil
  list.last = last - 1
  return value
end

-------------------------------------------------------------------

local n,m=io.read("n","n")
local cave={}
for i=1,n do
    cave[i]={}
end
for i=1,m do
    local a,b=io.read("n","n")
    cave[a][b]=true
    cave[b][a]=true
end

local dist={}
local prev={}
for i=1,n do
    dist[i]=-1
    prev[i]=-1
end
dist[1]=0

local que=List.new()
List.pushright(que,1)
while true do
    local a=List.popleft(que)
    if not a then break end
    for next,_ in pairs(cave[a]) do
        if dist[next]==-1 then
            dist[next]=dist[a]+1
            prev[next]=a
            List.pushright(que,next)
        end
    end
end

print("Yes")
for i=2,n do
    print(prev[i])
end


Measured memory_bytes: 25300
use List::Util qw/max/;

chomp (my $n = <STDIN>);
my ($w, $x, $y, $z);
for my $i (1..$n) {
  chomp (my $s = <STDIN>);
  $w++ while $s =~ /AB/g;
  if (substr($s, 0, 1) eq "B") {
    if (substr($s, -1, 1) eq "A") {
      $x++;
    } else {
      $y++;
    }
  } elsif (substr($s, -1, 1) eq "A") {
    $z++;
  }
}
if ($x > 1) {
  $w += $x - 1;
  $x = 1;
}
if (max($x, $y, $z) == $y) {
  $w += $x;
  $w += $z;
} elsif (max($x, $y, $z) == $z) {
  $w += $x;
  $w += $y;
}
print "$w\n";

Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main(void){
    int N, x;
    long long int a[100000], b[100000]={};

    cin >> N >> x;

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

    for (int i = 0; i < N - 1; ++i) {
        b[i] = a[i]+a[i+1]-x;
    }

    unsigned long long int result=0;

    for (int i = 0; i < N - 1; ++i) {
        if (b[i]>0){
            result+=b[i];
            // cout <<"b["<< i <<"]:"<< b[i]<<"\n"
            //      <<"result:"<< result<< "\n";
            b[i+1]-=(b[i]<a[i+1]?b[i]:a[i+1]);
        }
    }

    cout << result;

    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int n;
  cin>>n;
  int mod=n%10;
  if(mod==3){
    cout<<"bon"<<endl;
  }else if(mod==0 || mod==1 || mod==6 || mod==8){
    cout<<"pon"<<endl;
  }else{
    cout<<"hon"<<endl;
  }
  return 0; 
}

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

int main()
{
    int n;
    cin >> n;
    int s = 0;
    vector<int> a(n+1);
    rep(i, n)
    {
        cin >> a.at(i);
    }
    sort(a.begin(), a.end(), greater<int>());
    for (int i = 0; i < n; i += 2)
    {
        s += a.at(i);
        s -= a.at(i + 1);
    }
    cout << s << endl;
}

Measured memory_bytes: 256