akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)


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

    int N,Q;
    int K;
    cin >> N >> K >> Q;
    int A[Q];
    rep(i,Q){
        cin >> A[i];
    }

    vector<int> point(N);
    rep(i,Q){
        point.at(A[i]-1)++;
    }
    rep(i,N){
        if(K-Q+point[i]>0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }

}


Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n];
        int[] q = new int[n];
        for (int i = 0 ; i < n ; i++) {
            p[i] = sc.nextInt();
        }
        for (int i = 0 ; i < n ; i++) {
            q[i] = sc.nextInt();
        }
        int[] a = new int[n];
        for (int i = 0 ; i < n ; i++) {
            a[i] = i + 1;
        }
        int count = 0;
        while (!isSameArray(a, p)) {
            nextPermutation(a);
            count++;
        }
        for (int i = 0 ; i < n ; i++) {
            a[i] = i + 1;
        }
        int count2 = 0;
        while (!isSameArray(a, q)) {
            nextPermutation(a);
            count2++;
        }

        System.out.println(Math.abs(count2 - count));

    }

    private static void nextPermutation(int[] nums) {
        int mark = -1;
        for (int i = nums.length - 1 ; i > 0 ; i--) {
            if (nums[i] > nums[i - 1]) {
                mark = i - 1;
                break;
            }
        }
        if (mark == -1) {
            reverse(nums, 0, nums.length - 1);
            return;
        }
        int idx = nums.length - 1;
        for (int i = nums.length - 1 ; i >= mark + 1 ; i-- ) {
            if (nums[i] > nums[mark]) {
                idx = i;
                break;
            }
        }
        swap(nums, mark, idx);
        reverse(nums, mark + 1, nums.length - 1);
    }

    private static void swap(int[] nums, int i, int j) {
        int t = nums[i];
        nums[i] = nums[j];
        nums[j] = t;
    }

    private static void reverse(int[] nums, int i, int j) {
        while (i < j) {
            swap(nums, i, j);
            i++;
            j--;
        }
    }

    private static boolean isSameArray(int[] a, int[] b) {
        for (int i = 0 ; i < a.length ; i++) {
            if (a[i] != b[i]) return false;
        }
        return true;
    }

}

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

#define DEBUG(x) cout << #x << ": " << x << endl;
#define MOD 1000000007

using namespace std;

int main() {
  string t, b;
  cin >> t >> b;

  int P[t.size() + 1][b.size() + 1] = {}; // [i][j]

  for (int i = 0; i < b.size() + 1; i++) { // ??????????????????
    P[0][i] = 0; 
  }

  for (int i = 0; i < t.size() + 1; i++) { // ??????????????????
    P[i][0] = 1; 
  }

  for (int i = 1; i < t.size() + 1; i++) {
    char ti = t.at(i - 1);
    for (int j = 1; j < b.size() + 1; j++) {
      char bj = b.at(j - 1);
      if (j <= i) {
        if (ti == bj) {
          P[i][j] = (P[i - 1][j - 1] + P[i - 1][j]) % MOD;
        } else {
          P[i][j] = P[i - 1][j];
        }
      } else {
        P[i][j] = 0;
      }
      // DEBUG(i);
      // DEBUG(j);
      // DEBUG(ti);
      // DEBUG(bj);
      // DEBUG(P[i][j]);
    }
  }
  cout << P[t.size()][b.size()] << endl;
}

Measured memory_bytes: 7056
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue>
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <cctype>  // std::islower(), std::isupper(), std::tolower, std::toupper
#include <iomanip> // std::std::setprecision(X)
#include <limits>  //std::numeric_limits<int>::max(), min()

typedef long long ll;

int main (void) {

  int N; std::cin >> N;
  std::vector<ll> A(N); for(int i=0; i<N; i++) std::cin >> A[i];

  ll Amax = *std::max_element(A.begin(), A.end());
  ll Amin = *std::min_element(A.begin(), A.end());

  std::cout << std::abs(Amax - Amin) << std::endl;

  return 0;
}


Measured memory_bytes: 256
A, B, C, X, Y = map(int, input().split())
ans = A * X + B * Y
for i in range(1, max(X, Y) + 1):
  ans = min(ans, A * max(X - i, 0) + B * max(Y - i, 0) + C * 2 * i)
print(ans)


Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int K = scanner.nextInt();
    if (K > (N - 1) * (N - 2) / 2) {
      System.out.println(-1);
      return;
    }

    int m = N * (N - 1) / 2;
    int[][] edges = new int[m][2];
    int k = 0;
    for (int i = 1; i <= N; i++) {
      for (int j = i + 1; j <= N; j++) {
        edges[k][0] = i;
        edges[k][1] = j;
        k++;
      }
    }

    StringBuilder sb = new StringBuilder();
    sb.append(m - K).append('\n');
    for (int i = 0; i < m - K; i++) {
      sb.append(edges[i][0]).append(' ').append(edges[i][1]).append('\n');
    }
    System.out.print(sb.toString());
  }
}


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

class drink{
  public:
  long A, B;
  bool operator < (drink d){
    return this->A < d.A;
  }
};

int main(){
  int N, M;
  cin >> N >> M;
  drink S[N];
  
  for (int i = 0; i < N; i++){
    cin >> S[i].A >> S[i].B;
  }
  
  sort(S, S + N);
  
  int m = 0;
  long p = 0;
  for(int i = 0; i < N; i++){
    m += S[i].B;
    p += S[i].A * S[i].B;
    if (m >= M) {
      p -= S[i].A * (m - M);
      break;
    }
  }
  
  cout << p << endl;
  

}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long
#define str string
#define pll pair<ll, ll>
#define fi first
#define se second
#define pb push_back
#define SET(a, b) memset(a, b, sizeof(a))
#define pq priority_queue
using namespace std;
int main () {
	ll a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q;
	str A, B, C;
	cin >> A; a = A.length();
	for (i = 0; i < a && A[i] != 'A'; i++);
	for (j = a - 1; j >= 0 && A[j] != 'Z'; j--);
	printf("%lld\n", j - i + 1);
	return 0;
}

Measured memory_bytes: 640
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <bitset>
#include <iostream>
#include <deque>
#include <functional>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <string>
#include <vector>
#include <vector>

using namespace std;

#define int long long

#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

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

#define debug(x) cerr << #x << ": " << x << endl;

const int MOD = 1e9 + 7;

signed main(void)
{
  int num;
  int n; cin >> n;
  int x; cin >> x;
  vector<int> l(n);
  for (int i = 0; i < n; ++i) {
    cin >> l[i];
  }

  num = 0;
  vector<int> d(n + 1);
  d[0] = 0;
  for (int i = 0; i < n + 1; ++i) {
    if (i > 0) {
      d[i] = d[i - 1] + l[i - 1];
    }
    if (d[i] <= x) {
      ++num;
    }
  }

  cout << num << endl;
}


Measured memory_bytes: 256
N = int(input())
words = {}
for _ in range(N):
    word = input()
    if not word in words:
        words[word] = 1
    else:
        words[word] += 1
M = int(input())
for _ in range(M):
    word = input()
    if not word in words:
        words[word] = -1
    else:
        words[word] -= 1
print(max(0,max(words.values())))

Measured memory_bytes: 3060
#include<stdio.h>
int main(void){
  int k,x;
  int i;
  scanf("%d %d",&k,&x);
  if(k==1){
    printf("%d",x);
  }else{
    printf("%d",x-k+1);
    for(i=-k+2;i<=k-1;i++){
      printf(" %d",x+i);
    }
  }
  
  return 0;
}

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

using namespace std;
#define inf 100000000000000LL
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

ll v[101], w[101];

ll dp[100001];

int main(){
	ll W;
	int i,j;
	int n;
	scanf("%d %lld",&n,&W);
	// printf("n: %d\n",n);
	int tot = 0;
	for(i=0;i<n;i++){
		scanf("%lld %lld",&w[i],&v[i]);
		tot += v[i];
	}
	
	for(i=1;i<=tot;i++){dp[i] = inf;}
	for(i=0;i<n;i++){
		// printf("i: %d w: %lld v; %lld\n",i,w[i], v[i]);
		for(j=tot;j>=v[i];j--){
			dp[j] = min(dp[j], dp[j-v[i]] + w[i]);
			// printf("dp[%d] jd: %lld\n",j,dp[j]);
		}
	}
	int ans = 0;
	for(i=1;i<=tot;i++){
		if(dp[i] <= W){ans = i;}
	}
	printf("%d\n",ans);
	return 0;
};

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

int N, K;
int L;
int D[1001][501];
int DC[1001];
int S[501];
bool used[1001];
bool notuse[1001];

bool dfs( int k ) {
    if ( k > N ) {
        return true;
    }

    if ( notuse[k] ) {
        if ( dfs( k+1 ) ) return true;
    } else {
        bool ok = true;
        for ( int i = 0; i < DC[k]; i++ ) {
            int ind = D[k][i];
            S[ind]++;
            if ( S[ind] * 8 > 3 * N ) {
                ok = false;
            }
        }
        if ( ok ) {
            used[k] = true;
            if ( dfs( k+1 ) ) return true;
            used[k] = false;
        }
        for ( int i = 0; i < DC[k]; i++ ) {
            int ind = D[k][i];
            S[ind]--;
        }
        if ( dfs( k+1 ) ) return true;
    }

    return false;
}

int main() {
    cin >> N >> K;
    L = N/2;
    for ( int i = 0; i <= N; i++ ) {
        notuse[i] = true;
        DC[i] = 0;
    }
    for ( int i = 0; i < K; i++ ) {
        for ( int j = 0; j < L; j++ ) {
            int card;
            cin >> card;
            notuse[card] = false;
            D[card][DC[card]++] = i;
        }
    }

    for ( int i = 0; i < K; i++ ) {
        S[i] = 0;
    }
    for ( int i = 0; i <= N; i++ ) {
        used[i] = false;
    }
    dfs( 1 );
    for ( int i = 1; i <= N; i++ ) {
        if ( used[i] ) {
            putchar('1');
        } else {
            putchar('0');
        }
    }
    putchar('\n');

    return 0;
}

Measured memory_bytes: 0
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int maxn = 100000 + 10;

int n, h[maxn], cnt, flag = 0;
struct enode{
  int v, n;
  enode() {}
  enode(int _v, int _n):v(_v), n(_n) {}
}e[maxn << 1];

inline void addedge(int u, int v) { cnt ++; e[cnt] = enode(v,h[u]); h[u] = cnt; }

int sum[maxn], a[maxn], sz[maxn];

void dfs1(int u, int fa) {
  sum[u] = 0;
  sz[u] = 1;
  a[u] = 0;
  int bo = 0;
  for(int i = h[u];~ i;i = e[i].n) {
    int v = e[i].v;
    if(v == fa) continue;
    dfs1(v,u);
    sz[u] += sz[v];
    bo = 1;
    if(a[v]) sum[u] ++;
  }
  if(!bo) a[u] = 1;
  else if(sum[u] > 1) {
  	a[u] = 1;
  	flag = 1;
  }
  else if(sum[u] == 0) {
    a[u] = 1;
  }
}

void dfs2(int u, int fa) {
  if(sum[u] > 1) {
  	flag = 1; 
//  	cout << u << endl;
  }
  for(int i = h[u], tmp, now;~ i;i = e[i].n) {
    int v = e[i].v;
    if(v == fa) continue;
    if(a[v]) tmp = sum[u] - 1;
    else tmp = sum[u];
    if(sz[1] - sz[v] == 1) sum[v] ++;
    else {
	  if(tmp > 1 || tmp == 0) sum[v] ++;
    }
    dfs2(v,u);
  }
}

int main() {
  scanf("%d", &n); cnt = 0;
  memset(h,-1,sizeof(h));
  for(int i = 1;i < n;i ++) {
    int u, v;
    scanf("%d%d", &u, &v);
    addedge(u,v);
    addedge(v,u);
  }
  dfs1(1,0);
  dfs2(1,0);
  if(!flag) puts("Second");
  else puts("First");
  return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int N,M,K;
  cin>>N>>M>>K;
  int m=1;
  while(m<M)
    m*=2;
  vector<int> A(N+1),B(M+1);
  for(int i=0;i<N;i++){
    cin>>A[i+1];
    A[i+1]+=A[i];
  }
  for(int i=0;i<M;i++){
    cin>>B[i+1];
    B[i+1]+=B[i];
  }
  int l=0;
  for(int i=N;i>=0;i--){
    int j=upper_bound(B.begin(),B.end(),K-A[i])-B.begin();
    if(j==M+1)
      l=max(l,i+M);
    else if(j!=0 || A[i]<K)
      l=max(l,i+j-1);
  }
  cout<<l<<endl;
}

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

const ll maxs = 2e5+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;

#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'

void pre(){
    
}

void solve(){
    
    ll x;
    cin >> x;
    vector<pair<ll,ll>> a;
    for(ll i=0;i<=1000;i++){
        a.pb({i*i*i*i*i,i});
        a.pb({-i*i*i*i*i,-i});
    }
    sort(a.begin(),a.end());
    for(ll i=0;i<a.size();i++){
        for(ll j=0;j<a.size();j++){
            if(a[i].ff - a[j].ff == x){
                cout << a[i].ss << " " << a[j].ss << endl;
                return;
            }   
        }
    }

}

int main(){
    IOS;
    pre();
    ll T = 1;
    //cin>>T;
    while(T--){
        solve();   
    }
    return 0;
}

Measured memory_bytes: 3716
n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))
total=1
i=a[0]-1
if a[0]==2:
    print(total)
else:
    while True:
        if a[i]==2:
            print(total+1)
            break
        elif total>n:
            print("-1")
            break
        else:
            i=a[i]-1
            total+=1

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

int main(){
  ll x; cin >> x;
  ll count = 0;
  ll sum = 100;
  while(sum < x) {
    sum = sum + (sum / 100);
    count++;
  }

  cout << count << endl;
}



Measured memory_bytes: 3632
N,M,Q = map(int,input().split())
s = [[0 for j in range(501)] for i in range(501)]

for _ in range(M):
    L,R = map(int,input().split())
    s[L][R] += 1

# 二次元累積和
for i in range(1,501):
    for j in range(1,501):
        s[i][j] += s[i-1][j] + s[i][j-1] - s[i-1][j-1]

# クエリに対してO(1)で求める
for _ in range(Q):
    p,q = map(int,input().split())
    print(s[q][q]-s[p-1][q]-s[q][p-1]+s[p-1][p-1])


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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;
using std::bitset;

#define rep(i,n)    for(int i=0; i<(int)n; i++)
#define reps(i,s,e) for(int i=s; i<(int)e; i++)
#define coutd(i) cout << std::fixed << std::setprecision(i)
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;

template<class T>
using Graph = vector<vector<T>>;

const int INT_BIG = 1<<28;

int main() {
    int K, A, B, C;
    cin >> A >> B >> C >> K;
    if (K <= A) {
        cout << K << endl;
    } else if (K <= A+B) {
        cout << A << endl;
    } else {
        cout << A - (K - A - B) << endl;
    }
}

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

int main(void){
    int A,B,M;
    cin >> A >> B >> M;
    vector<ll> a(A), b(B);
    rep(i,A) cin >> a[i];
    rep(i,B) cin >> b[i];
    ll res = *min_element(all(a)) + *min_element(all(b));
    rep(i,M){
        ll x,y,c;
        cin >> x >> y >> c;
        x--, y--;
        res = min(res, a[x] + b[y] - c);
    }
    cout << res << endl;
    
    return 0;
}


Measured memory_bytes: 1792
using System;
class Program
{
	static void Main(string[] args)
	{
		// スペース区切りの整数の入力
		string[] input = Console.ReadLine().Split(' ');
		int N = int.Parse(input[0]);
		int R = int.Parse(input[1]);
		
		GetResult(N, R);
	}
	
	static void GetResult(int N, int R){
	    int result;
	    result = N >= 10 ? R : R + 100 * (10-N);
	    Console.WriteLine(result);
	}
}

Measured memory_bytes: 11092
#include <iostream>
using namespace std;
int main(void){
    int r,g,b;
    cin >> r >> g >> b;
    
    if(((r*100)+(g*10)+b)%4==0){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
    
    
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, '%d', $cnt);
$nums = array_map('intval', explode(' ', trim(fgets(STDIN))));
$flag = true;
for ($i=0; $i < $cnt; $i++) { 
    if ($nums[$i] % 2 !== 0) {
        continue;
    }
    if ($nums[$i] % 3 !== 0 && $nums[$i] % 5 !== 0) {
        $flag = false;
    }
}
echo $flag ? 'APPROVED' : 'DENIED';
echo "\n";

Measured memory_bytes: 4728
S_s = [input() for _ in range(3)]
turn = 0
pos = [0, 0, 0]
dic = {"a":0, "b":1, "c":2}
while 1:
    try:
        n_turn = dic[S_s[turn][pos[turn]]]
        pos[turn] += 1
        turn = n_turn
    except IndexError:
        break
print("ABC"[turn])

Measured memory_bytes: 9036
#include<stdio.h>
#include <string.h>

int main(){
	char name[1000][32],max_name[32],most_name[32];
	int i=0,j=0,count,max=0,same[1000]={0},most=0;
	
	while(scanf("%s",name[i])!=EOF){i++;}
	count=i;
	
	for(i=0;i<count;i++){
		if(max<strlen(name[i])){
			max=strlen(name[i]);
			strcpy(max_name,name[i]);
		}
	}
	
	for(i=0;i<count;i++){
		for(j=0;j<count;j++){
			if(strcmp(name[i],name[j])==0)same[i]++;
		}
	}
	for(i=0;i<count;i++){
		if(most<same[i]){
			most=same[i];
			strcpy(most_name,name[i]);
		}
	}
	
	
	printf("%s %s\n",most_name,max_name);
	
return 0;
}

Measured memory_bytes: 572
#include<bits/stdc++.h>
#define randome_generate srand(std::chrono::high_resolution_clock::now().time_since_epoch().count())
using namespace std;
int n,a[100100];
long long m,bes[200100],ben[200100];
long long cnt(int x){
	long long ret=0;
	for(int i=1;i<=n;i++)
		ret+=ben[max(0,x-a[i])];//借了#i的左手 
	return ret;
}
long long sum(int x){
	long long ret=0;
	for(int i=1;i<=n;i++)//借了#i的左手 
		ret+=(bes[max(0,x-a[i])]+1LL*a[i]*ben[max(0,x-a[i])]);
	return ret;
}
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		ben[a[i]]+=1LL;
		bes[a[i]]+=1LL*a[i];
	}
	for(int i=100000;i>=0;i--){
		ben[i]+=ben[i+1];
		bes[i]+=bes[i+1];
	}
	int l=0,r=200000,mid;
	while(l<r){
		mid=(l+r+1)/2;
		if(cnt(mid)>=m)
			l=mid;
		else
			r=mid-1;
	}
	cout<<sum(l+1)+(m-cnt(l+1))*1LL*l;
	return 0;
}


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

int n,a[1000000];
vector<pair<int,int>>v;

bool check(int d)
{
	v.clear();
	v.push_back(make_pair(0,0));
	for(int i=1;i<=n;i++)
		if(a[i]<=a[i-1])
		{
			while(v.back().first>a[i])
				v.pop_back();
			for(int j=a[i];;--j)
			{
				if(j<1)
					return false;
				int t=1;
				if(v.back().first==j)
					t=1+v.back().second,v.pop_back();
				if(t<d)
				{
					v.push_back(std::make_pair(j,t));
					break;
				}
			}
		}
	return true;
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	int l=1,r=n;
	while(l<r)
	{
		int mid=(l+r)/2;
		if(check(mid))
			r=mid;
		else
			l=mid+1;
	}
	printf("%d\n",l);
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000


int main(){
	
	int N;
	cin>>N;
	
	vector<vector<int>> A(N,vector<int>(N-1,0));
	
	for(int i=0;i<N;i++){
		for(int j=0;j<N-1;j++){
			cin>>A[i][j];
			A[i][j]--;
		}
	}
	
	vector<vector<int>> E(N*N,vector<int>());
	vector<vector<int>> rev_E(N*N,vector<int>());
	
	vector<int> jisuu(N*N,0);
	for(int i=0;i<N;i++){
		for(int j=1;j<N-1;j++){
			int a = i*N+A[i][j-1];
			int b = i*N+A[i][j];
			E[a].push_back(b);
			
			rev_E[b].push_back(a);
			
			jisuu[b]++;
			
			a = A[i][j-1]*N+i;
			b = A[i][j]*N+i;
			E[a].push_back(b);
			
			rev_E[b].push_back(a);
			
			jisuu[b]++;
			
		}
	}
	vector<int> sorted;
	queue<int> Q;
	for(int i=0;i<N*N;i++){
		if(jisuu[i]==0){
			Q.push(i);
			sorted.push_back(i);
		}
	}
	
	while(Q.size()!=0){
		int from = Q.front();
		Q.pop();
		
		for(int i=0;i<E[from].size();i++){
			int to = E[from][i];
			jisuu[to]--;
			if(jisuu[to]==0){
				sorted.push_back(to);
				Q.push(to);
			}
		}
	}
	
	if(sorted.size()!=N*N){
		cout<<-1<<endl;
		return 0;
	}
	
	vector<int> ans(N*N,0);
	
	int Ans = 0;
	
	for(int i=0;i<N*N;i++){
		int k = sorted[i];
		int maxi = 0;
		for(int j=0;j<rev_E[k].size();j++){
			int to = rev_E[k][j];
			maxi = max(maxi,ans[to]);
		}
		
		ans[k] = maxi+1;
		
		Ans = max(Ans,ans[k]);
	}
	
	cout<<Ans<<endl;
		
		
	
	return 0;
}


Measured memory_bytes: 125420
#include <iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<map>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
typedef pair<int,int> pint;
typedef long long ll;
typedef pair<int,pint> ppi;
const int inf   = 510101010;
const int mod=1e9+7;
const ll longinf=1LL<<60;

ll pow(ll n,ll k){
  ll ret=1;
  while(k>0){
    if(k%2)ret=ret*n %mod;
    n=n*n %mod;
    k/=2;
    }
  return ret;
  }

int main(){
  ll n,k;
  cin>>n>>k;
  ll dp[101][10001];
  rep(i,101)rep(j,10001)dp[i][j]=0;
  dp[k][1]=pow(k+1,n-k);
  dp[k][0]=k*pow(k+1,n-k) %mod;
  for(int i=k-1;i>0;i--){
    rep(j,i+1)rep(h,10001){
      int x=(j+h)/i;
      if(h+x<10000)dp[i][h+x]=(dp[i][h+x]+dp[i+1][h])%mod;
      }
    rep(j,10001)
      dp[i][j]=(dp[i][j]+(k-i)*dp[i+1][j])%mod;
    }
  ll ans=n*k*(k+1)/2;
  ans=ans*pow(k+1,n-1) %mod;
  rep(i,10001)ans=(ans-i*dp[1][i])%mod;
  ans=(ans+mod)%mod;
  cout<<ans<<endl;
  return 0;
  }

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

int main() {
  string a,b;
  cin>>a>>b;
  int ab=stoi(a+=b);
  bool f=true;
  for (int i=1; i<=317; i++) {
    f=(i*i==ab?true:false);
    if (f) {
      break;
    }
  }
  cout<<(f?"Yes":"No")<<endl;
  return 0;
}


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

#define EB emplace_back
#define int long long
#define F first
#define S second
#define N 100005
#define ALL(x) x.begin(),x.end()
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)


using namespace std;


int32_t main()
{
    IOS;

    int tt=1;
    //cin>>tt;
    while(tt--)
    {
        //int n; cin>>n; int arr[n]; for(int i = 0; i<n; i++) cin>>arr[i];
		int a,b; cin>>a>>b;
		int cnt = 1;
		while (a --)
		{
			if (2*cnt < cnt + b)
			{
				cnt = 2*cnt;
			}
			else
			{
				cnt +=b;
			}
		}
		cout<<cnt;
		
		cout<<endl;
    }
    return 0;

}


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

#define ll long long int
#define fi first
#define se second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define debug(a) cout << #a << " = " << a << endl;
#define endl "\n"
#define MOD (int) 1e9+7
#define inf (int) (1e18)

const int MAXN=100005;
	
	void solve() {
        long int n;
        cin>>n;
        long int a[n];
        for(long int i=0;i<n;i++)
        	cin>>a[i];

        long int i=0;
        bool low=true;
        vector<long int > v;
        while(i<n){
           if(low){
        	while(i+1<n && a[i]>=a[i+1])
        		i++;
           } else {
           	while(i+1<n && a[i]<=a[i+1])
           		i++;
           }
           // cout<<i<<endl;
           if(i<n)
           v.push_back(a[i]);
           i++;
           low=!low;
        }
        long int curr=1000;
        n=v.size()-(low==false);
        for(long int i=0;i<n;i+=2){
            long int tp=curr/v[i];
            curr-=tp*v[i];
            curr+=tp*v[i+1];
            // cout<<curr<<" "<<v[i]<<" "<<v[i+1]<<" "<<tp<<endl;
        }
        cout<<curr<<endl;
	}
	
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long int t=1;
    // cin >> t;
    for(long int tt=1;tt<=t;tt++){
    	// cout<<"Case #"<<tt<<": ";
    	solve();
    }
    cerr << "Time : " << 1000 * ((double) clock()) / (double) CLOCKS_PER_SEC << "ms\n";
    return 0;
}

Measured memory_bytes: 3768
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <ctime>
#include <cassert>
#include <unordered_map>
#include <fstream>
#include <random>
#include <cstring>
#include <complex>
#include <bitset>

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define pb push_back

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef double ld;

vector<vector<int>> g;
vector<vector<int>> c;
vector<int> w;

int n;
ll ans = 0;

int dfs(int v, int p) {
    w[v] = 1;
    for (int i = 0; i < sz(g[v]); ++i) {
        int u = g[v][i];
        if (u == p)
            continue;
        w[v] += dfs(u, v);
        ans += min(w[u], n - w[u]) * (ll)c[v][i];
    } 
    return w[v];
}

int minn = 1e9;

void dfs1(int v, int p) {
    if (2 * (n - w[v]) > n)
        return;
    for (int i = 0; i < sz(g[v]); ++i) {
        int u = g[v][i];
        if (u == p)
            continue;
        if (2 * w[u] == n) {
            minn = c[v][i];
            return;
        }
        if (2 * w[u] > n) {
            dfs1(u, v);
            return;
        }
    }

    for (int i = 0; i < sz(g[v]); ++i)
        minn = min(minn, c[v][i]);
}

int main() {
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);


    cin >> n;
    g.resize(n);
    c.resize(n);
    for (int i = 0; i < n - 1; ++i) {
        int u, v, cost;
        cin >> u >> v >> cost;
        --u; --v;
        g[u].push_back(v);
        c[u].push_back(cost);
        g[v].push_back(u);
        c[v].push_back(cost);
    }

    w.resize(n);
    dfs(0, -1);
    dfs1(0, -1);
    ans *= 2;
    ans -= minn;
    cout << ans << endl;

    return 0;
}


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

int N, K;
char S[51];

int main() {
  cin >> N >> K;
  for (int i = 0; i < N; i++) cin >> S[i];

  if (S[K - 1] == 'A') S[K - 1] = 'a';
  if (S[K - 1] == 'B') S[K - 1] = 'b';
  if (S[K - 1] == 'C') S[K - 1] = 'c';

  for (int i = 0; i < N; i++) cout << S[i];
  cout << endl;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

ll N;
string X;
ll calc(ll n) {
  if (n<=0) return 0;
  ll result = 0;
  rep(i,N) result = (result*2+(X[i]-'0')) % n;
  return result;
}

ll pcal(ll n) {
  ll result = 0;
  while (n) {
    ll tn = n, pcnt = 0; while (tn) { pcnt += tn%2; tn/=2; }
    n %= pcnt;
    result++;
  }
  return result;
}

int main() {
  cin >> N >> X;

  ll count = 0; rep(i,N) count += X[i]=='1';
  ll to[2] = {calc(count-1), calc(count+1)};
  // debug(to,to+2);
  ll p2[2][N];
  if (count-1>0) rep(i,N) p2[0][i] = i==0 ? 1%(count-1) : p2[0][i-1] * 2 % (count-1);
  rep(i,N) p2[1][i] = i==0 ? 1 : p2[1][i-1] * 2 % (count+1);

  // debug(p2[0],p2[0]+N); debug(p2[1],p2[1]+N);

  rep(i,N) {
    if (X[i]=='1'&&count==1) { cout << 0 << endl; continue; }
    ll c1 = X[i]=='0' ? (to[1]+p2[1][(N-1)-i]) % (count+1) : ((to[0]-p2[0][(N-1)-i])%(count-1)+(count-1)) % (count-1);
    ll result = 1 + pcal(c1);
    cout << result << endl;
  }
  return 0;
}

Measured memory_bytes: 6816
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;

/**
 * @author Don Li
 */
public class Main {
    void solve() {
        int N = in.nextInt(), M = in.nextInt();
        int[] A = new int[N], B = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = in.nextInt();
            B[i] = in.nextInt();
        }
        
        Integer[] ids = new Integer[N];
        Arrays.setAll(ids, i -> i);
        Arrays.sort(ids, Comparator.comparingInt(i -> A[i]));
        
        long ans = 0;
        for (int i = 0; i < N && M > 0; i++) {
            int delta = Math.min(M, B[ids[i]]);
            M -= delta;
            ans += (long) A[ids[i]] * delta;
        }
        out.println(ans);
    }
    
    public static void main(String[] args) {
        in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(System.out);
        new Main().solve();
        out.close();
    }
    
    static FastScanner in;
    static PrintWriter out;
    
    static class FastScanner {
        BufferedReader in;
        StringTokenizer st;
        
        public FastScanner(BufferedReader in) {
            this.in = in;
        }
        
        public String nextToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(in.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        public int nextInt() {
            return Integer.parseInt(nextToken());
        }
        
        public long nextLong() {
            return Long.parseLong(nextToken());
        }
        
        public double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }
}


Measured memory_bytes: 48412
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define rep(i,n); for(long long i = 0;i < (n);i++)
using ll = long long;
using P = pair<long long,long long>;
template <class T> using vec = vector<T>;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll x,n; cin >> x >> n;
    vec<ll> p(n); rep(i,n)cin >> p[i];
    sort(p.begin(),p.end());
    vec<ll> q;
    rep(i,105)q.push_back(-i-1);
    ll now=0
    rep(i,105){
        if(now<n && p[now] == i){
            now++;
            continue;
        }
        q.push_back(i);
    }
    rep(i,q.size()){
        if(q[i]>x){
            if(abs(x-q[i-1]) <= abs(x-q[i]))cout << q[i-1] << endl;
            else cout << q[i] << endl;
            return 0;
        }
    }
}

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

int main(void){
    // Your code here!
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;
    
    bool isIn = true;
    if (x-r < 0) isIn = false;
    if (x+r > W) isIn = false;
    if (y-r < 0) isIn = false;
    if (y+r > H) isIn = false;
    
    if (isIn) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}



Measured memory_bytes: 3116
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<stack>
#include<cassert>
#define F first
#define S second
#define mp make_pair
#define pii pair<int,int>
#define pb push_back
#define mem(x,y) memset(x,y,sizeof x)
#define sqr(x) ((x)*(x))
using namespace std;
typedef long long ll;
typedef double db;
const int INF=2e9,M=100010;
const db eps=1e-8;
inline void read(int &x)
{
    x=0; int f=1; char ch=getchar();
    while( (ch<'0' || ch>'9') && ch!='-') ch=getchar(); if(ch=='-') {f=-1; ch=getchar();}
    while(ch>='0' && ch <='9') x=x*10+ch-'0',ch=getchar();
    x*=f;
}
inline void read(ll &x)
{
    x=0; int f=1; char ch=getchar();
    while( (ch<'0' || ch>'9') && ch!='-') ch=getchar(); if(ch=='-') {f=-1; ch=getchar();}
    while(ch>='0' && ch <='9') x=x*10+ch-'0',ch=getchar();
    x*=f;
}
//==========================head template==========================
const int N=210;
int n,m,s,t;

int head[N],nxt[M],fr[M],to[M],cap[M],lst=1;
inline void adde(int x,int y,int c) {nxt[++lst]=head[x]; fr[lst]=x; to[lst]=y; cap[lst]=c; head[x]=lst;}
inline void add(int x,int y) {adde(x,y,1); adde(y,x,0);}

queue<int> que; bool inq[N]; int step[N];
int cur[N];
inline bool bfs() {
    que.push(s);
    mem(step,0); step[s]=1;
    while(!que.empty()) {
        int p=que.front(); que.pop();
        for(int i=head[p];i;i=nxt[i]) {
            int v=to[i];
            if(cap[i] && !step[v]) {
                step[v]=step[p]+1;
                que.push(v);
            }
        }
    }
    return step[t]!=0;
}
int dfs(int u,int flow) {
    if(!flow || u==t) return flow;
    for(;cur[u];cur[u]=nxt[cur[u]]) {
        int v=cur[u];
        if(step[to[v]]==step[u]+1 && cap[v]) {
            int f=dfs(to[v],min(flow,cap[v]));
            if(f) {
//				printf("v=%d fr=%d to=%d\n",v,fr[v],+to[v]);
                cap[v]-=f; cap[v^1]+=f;
                return f;
            }
        }
    }
    return 0;
}

inline int Dinic() 
{
    int ret=0;
    while(bfs()) {
//    	puts("?");
        int f=0;
        for(int i=1;i<=n+2;i++) cur[i]=head[i];
        do {
            ret+=f;
            f=dfs(s,INF);
        }while(f);
    }
    return ret;
}
struct P {
	int x,y;
	inline void in() {
		read(x); read(y);
	}
}r[N],b[N];
int main()
{
    read(n); s=n*2+1; t=s+1;
    for(int i=1;i<=n;i++) {
    	r[i].in();
	}
    for(int i=1;i<=n;i++) {
    	b[i].in();
	}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			if(r[i].x<b[j].x && r[i].y<b[j].y) {
				add(i,j+n); //printf("%d %d\n",i,j);
			}
	for(int i=1;i<=n;i++) {
		add(s,i);
		add(i+n,t);
	}
	n*=2;
    int ans=Dinic();
//    if(!ans) {puts("No Soluti??on!"); return 0;}
    printf("%d\n",ans);
//	printf("%d\n",e);
//    for(int i=2;i/2<=e;i+=2) {
////		printf("%d %d\n",cap[i],cap[i+1]);  
//        if(!cap[i]) printf("%d %d\n",fr[i],to[i]-m);
//    } 
    return 0;
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main(int argc, char const *argv[])
{
	int a, b, c;
	cin >> a >> b >> c;
	int ans = 0;
	if (b>=c) {
		ans += b+c;
	}
	else {
		ans += 2*b;
		c -= b;
		ans += min(a+1, c);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

static const int N = 1000;

void trace(int A[], int n){
  int i;
  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int main(){
  int n, i, j,key;
  int A[N+1];
  scanf("%d", &n);

  for ( i = 1; i <= n; i++ ) scanf("%d", &A[i]);
  
  trace(A, n);
  for(j=2;j<=n;j++){
    key=A[j];
    i=j-1;
    while(i>0 && A[i]>key){
      A[i+1]=A[i];
      i=i-1;
      A[i+1]=key;
    }
    trace(A, n);
  }
 
  return 0;
}

Measured memory_bytes: 608
#include <stdio.h>

void closs(double a1[2], double b1[2],
            double a2[2], double b2[2],double ans[2]);

int main(void)
{
    int i, n;
    double p1[2], p2[2], p3[2], p4[2], ans[2];
    scanf("%d",&n);
    for (i = 0; i < n; i++) {
        scanf("%lf%lf%lf%lf %lf%lf%lf%lf", 
            &p1[0], &p1[1], &p2[0], &p2[1], &p3[0], &p3[1], &p4[0], &p4[1]);
        closs(p1, p2, p3, p4, ans);
        printf("%.9lf %.9lf\n", ans[0], ans[1]);
    }
    return 0;
}

void closs(double a1[2], double b1[2],
            double a2[2], double b2[2],double ans[2]) 
{
    //a1-b1 & a2-b2 の交点
    double s1, s2;

    s1 = ((b2[0] - a2[0])*(a1[1] - a2[1]) 
            - ((b2[1] - a2[1])*(a1[0] - a2[0]))) / 2;

    s2 = ((b2[0] - a2[0])*(a2[1] - b1[1]) 
            - ((b2[1] - a2[1])*(a2[0] - b1[0]))) / 2;

    ans[0] = a1[0] + (b1[0] - a1[0])*s1/(s1 + s2);
    ans[1] = a1[1] + (b1[1] - a1[1])*s1/(s1 + s2);
}

Measured memory_bytes: 668
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define ff first
#define ss second
#define INF (ll) (1e9)
#define mod (ll) (1e9 + 7)
#define endl "\n"
#define tt ll testcase; cin>>testcase; while(testcase--)
 
const int mxn = 1*(1e5) + 5;
ll n, m;
 
void solve(){
	cin >> n;
	ll a[n];
	for(int i=0; i<n; i++) cin >> a[i];

	ll dp[n][n] = {};
	for(int l=n-1; l>=0; l--) {
		for(int r=l; r<n; r++) {
			if(r == l) {
				dp[l][r] = a[l];
			} else {
				dp[l][r] = max(a[l] - dp[l+1][r], a[r] - dp[l][r-1]);
			}
		}
	}
	cout << dp[0][n-1];
}

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

Measured memory_bytes: 73900
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    ll a[n];
    ll ma = 0;
    int id = 0;
    vector<pair<int, int> > v;
    for(int i=0;i<n;i++){
    	cin >> a[i];
    	if(abs(ma) <= abs(a[i])){
    		id = i;
    		ma = a[i];
    	}
    }
    for(int i=0;i<n;i++){
    	if(i != id){
    		v.push_back({id + 1, i + 1});
    		a[i] += a[id];
    	}
    }
    if(a[id] >= 0LL){
    	for(int i=1;i<n;i++){
    		v.push_back({i, i+1});
    	}
    }else{
    	for(int i=n-2;i>=0;i--){
    		v.push_back({i+2, i+1});
    	}
    }
    cout << v.size() << endl;
    for(auto& i: v){
    	cout << i.first << " " << i.second << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<math.h>
using namespace std;

int main()
{
	double a;
	cin >> a;
	printf("%5f %5f", pow(double(a), 2.0)*3.14159265358979323846264338327950288, 2 * double(a)*3.14159265358979323846264338327950288);
    return 0;
}

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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair


int main() {
  int x, y, z, k;
  cin >> x >> y >> z >> k;
  vl a(x), b(y), c(z);
  rep (i, x) cin >> a[i];
  rep (i, y) cin >> b[i];
  rep (i, z) cin >> c[i];

  vl ab;
  rep (i, x) rep (j, y) ab.push_back(a[i] + b[j]);

  sort(all(ab));
  reverse(all(ab));
  sort(all(c));
  
  ll ok = 0, ng = 30000000001LL;
  while (ok + 1 < ng) {
    ll mid = (ng + ok) / 2;
    ll num = 0;
    rep (i, x*y) {
      num += z - (lower_bound(all(c), mid - ab[i]) - c.begin());
      if (num >= k) break;
    }
    if (num >= k) ok = mid;
    else ng = mid;
  }

  //DEBUG(ok);
  vl ans;
  rep (i, x * y) {
    for (auto itr = lower_bound(all(c), ok + 1 - ab[i]); itr != c.end(); itr++) {
      ans.push_back(*itr + ab[i]);
    }
  }

  while (ans.size() < k) {
    ans.push_back(ok);
  }

  sort(all(ans));
  reverse(all(ans));
  rep (i, k) cout << ans[i] << endl;
  
}


Measured memory_bytes: 10480
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define rep(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main () {
  int n, m;
  cin >> n >> m;
  priority_queue<int> q;
  rep(i,n) {
    int a;
    cin >> a;
    q.push(a);
  }
  rep(i,m) {
    int a = q.top(); q.pop();
    q.push(a/2);
  }
  ll ans = 0;
  rep(i,n) {
    ans += q.top(); q.pop();
  }
  cout << ans << endl;
}

Measured memory_bytes: 892
#include <algorithm>
#include <iostream>

using namespace std;


int main(){
    
    int nums[3];

    cin >> nums[0] >> nums[1] >> nums[2];
    sort(nums, nums+3);

    for(int i=0; i<3; i++){
        if(i!=2){
            cout << nums[i] << " ";
        }if(i==2){
            cout << nums[i] << endl;
        }
    }

    return 0;
}




Measured memory_bytes: 3100
#include<iostream>
#include<queue>
#include<string>
#include<stack>
#include<cstdio>
#include<algorithm>

using namespace std;

int main(void)
{
  int i;
  int n;
  long long int sum=1;

  cin>>n;

  for(i=1;i<=n;i++)
    {
      sum*=i;
    }

  cout<<sum<<endl;

}

Measured memory_bytes: 1156
n = int(input())
p = list(map(int,input().split()))
ans = 0
for i in range(n-2):
  a = [p[i],p[i+1],p[i+2]]
  if p[i]<p[i+1]<p[i+2] or p[i]>p[i+1]>p[i+2]:
    ans += 1
print(ans)

Measured memory_bytes: 3064
from math import inf

n = int(input())
h = list(map(int, input().split()))

costs = [inf]*n
costs[0] = 0

for i in range(n):
	for j in (i+1, i+2):
		if j < n:
			costs[j] = min(costs[j], costs[i]+abs(h[i]-h[j]))
print(costs[-1])

Measured memory_bytes: 20896
input()
array = [int(x) for x in input().split()]
print(' '.join(list(str(x) for x in array)))
for i in range(1, len(array)):
    key = array[i]
    j = i - 1
    while j >= 0 and array[j] > key:
        array[j + 1] = array[j]
        j -= 1
    array[j + 1] = key
    print(' '.join(list(str(x) for x in array)))

Measured memory_bytes: 7712
#include<iostream>
#include<vector>
using namespace std;
typedef pair<int,string> P;

int n;
string t[20];
vector<int> u[20];
int cnt[31];
P ans[20];

void init(){
  for(int i=0;i<20;i++)u[i].clear();
  for(int i=0;i<31;i++)cnt[i]=0;
}

int main(){
  while(1){
    cin>>n;
    if(n==0)break;
    init();
    for(int i=0;i<n;i++){
      int size;
      cin>>t[i]>>size;
      u[i].resize(size);
      for(int j=0;j<size;j++){
	cin>>u[i][j];
	cnt[u[i][j]]++;
      }
    }
    P ans;
    for(int i=0;i<n;i++){
      P p;
      p.second=t[i];
      p.first=0;
      for(int j=0;j<(int)u[i].size();j++)
	p.first+=max(1,n-cnt[u[i][j]]+1);
      if(i)ans=min(ans,p);
      else ans=p;
    }
    cout<<ans.first<<" "<<ans.second<<endl;
  }
  return 0;
}

Measured memory_bytes: 1220
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

  public static void main(String[] args) {
    InputReader in = new InputReader(System.in);
    PrintWriter out = new PrintWriter(System.out);

    int n = in.nextInt();
    int t = in.nextInt();

    int min = Integer.MAX_VALUE;

    for (int i = 0; i < n; i++) {
      int ci = in.nextInt();
      int ti = in.nextInt();

      min = (ti <= t) ? Math.min(min, ci) : min;
    }

    out.println((min == Integer.MAX_VALUE) ? "TLE" : min);

    out.close();
  }

  static class InputReader {

    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream), 32768);
      tokenizer = null;
    }

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

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

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

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

  static void print(int[] arr) {
    Arrays.stream(arr).forEach(i -> System.out.print(i + " "));
    System.out.println();
  }

  public static int[] mergeSort(int[] a) {
    if (a.length <= 1)
      return a;

    int mid = a.length / 2;
    int[] left = new int[mid];
    int[] right = new int[a.length - mid];

    for (int i = 0; i < mid; ++i)
      left[i] = a[i];

    for (int i = mid; i < a.length; ++i)
      right[i - mid] = a[i];

    return merge(mergeSort(left), mergeSort(right));
  }

  public static int[] merge(int[] l, int[] r) {
    int[] merged = new int[l.length + r.length];

    int i = 0, j = 0, k = 0;
    while (i < l.length && j < r.length) {
      if (l[i] <= r[j])
        merged[k++] = l[i++];
      else
        merged[k++] = r[j++];
    }

    while (i < l.length)
      merged[k++] = l[i++];
    while (j < r.length)
      merged[k++] = r[j++];

    return merged;
  }
}

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

int main(){
  int N;
  cin >> N;
  int sum = 0, l, r;
  for (int i = 0;i < N; i++){
    cin >> l >> r;
    sum += r - l + 1;
  }
  cout << sum << endl;
}


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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;

#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)

int main (void) {
    int N,K;
    string S;
    cin>>N>>S>>K;
    string ans;
    char t = S[K-1];
    REP(i,N) {
        if (S[i] != t) {
            ans.pb('*');
        }
        else {
            ans.pb(S[i]);
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

class Solution {
public:
	void solve() {
		int h, w, k;
		cin >> h >> w >> k;
		vector<string> ss(h);
		int ans = 0;
		for (int i = 0; i < h; i++) cin >> ss[i];
		for (int i = 0; i < (1 << h); i++) {
			for (int j = 0; j < (1 << w); j++) {
				int cnt = 0;
				for (int k = 0; k < h; k++) {
					for (int l = 0; l < w; l++) {
						if (ss[k][l] == '#' && !((1 << k) & i) && !((1 << l) & j)) cnt++;
					}
				}
				if (cnt == k) ans++;
			}
		}
		cout << ans << "\n";

		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

Measured memory_bytes: 3644