akhauriyash/Code-Regression huggingface dataset:
class PriorityQueue
  MIN = -(1 << 60)

  attr_reader :size

  def initialize(capacity = nil, &block)
    @size = 0
    @heap = if capacity.nil?
      Array.new
    else
      # capacity には、queue のサイズとしてありえる最大の数を指定する想定。
      # @heap[1] から使用するため、配列サイズを 1つ余分に確保する。
      Array.new(capacity + 1)
    end
    @get_key = block || :itself.to_proc
  end

  def empty?
    size == 0
  end

  def pop
    return nil if @size <= 0
    max = @heap[1]
    @heap[1] = @heap[@size]
    @size -= 1
    max_heapify(1)
    max
  end

  def push(x)
    @size += 1
    i = @size
    @heap[i] = x
    while i > 1 && (@get_key.call(@heap[i / 2]) <=> @get_key.call(@heap[i])) < 0
      t = @heap[i / 2]
      @heap[i / 2] = @heap[i]
      @heap[i] = t
      i = i / 2
    end
  end

  def top
    return nil if @size <= 0
    @heap[1]
  end

  def to_a
    return [] if @size == 0
    @heap[1..@size]
  end

  private

  def max_heapify(i)
    l = 2 * i
    r = 2 * i + 1
    largest =
      l <= @size && (@get_key.call(@heap[l]) <=> @get_key.call(@heap[i])) > 0 ? l : i
    largest = r \
      if r <= @size && (@get_key.call(@heap[r]) <=> @get_key.call(@heap[largest])) > 0
    unless largest == i
      t = @heap[i]
      @heap[i] = @heap[largest]
      @heap[largest] = t
      max_heapify(largest)
    end
  end
end

N, M, R = gets.split.map(&:to_i)
r_list = gets.split.map { |a| a.to_i - 1}
graph = Array.new(N) { [] }
M.times do
  u, v, c = gets.split.map(&:to_i)
  u -= 1
  v -= 1
  graph[u].push([v, c])
  graph[v].push([u, c])
end

def shortest_path(graph, s)
  w_list = Array.new(graph.size, 1 << 60)
  w_list[s] = 0
  queue = PriorityQueue.new(graph.size) do |_, c|
    -c
  end
  queue.push([s, 0])
  while !queue.empty?
    u, w = queue.pop
    next if w > w_list[u]
    graph[u].each do |v, c|
      if w_list[u] + c < w_list[v]
        new_cost = w_list[u] + c
        w_list[v] = new_cost
        queue.push([v, new_cost])
      end
    end
  end
  w_list
end

d = {}
r_list.map do |r|
  d[r] = shortest_path(graph, r)
end

ans = 1 << 60
r_list.permutation.each do |l|
  ret = 0
  u = l[0]
  l.each do |v|
    ret += d[u][v]
    u = v
  end
  ans = ret if ret < ans
end
puts ans

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

int main() {
    int n, w;
    cin >> n;
    cin >> w;
    vector<tuple<double,double,double>> item(n);
    rep(i, n) {
        double value, weight, value_per_weight;
        cin >> value;
        cin >> weight;
        value_per_weight = value / weight;
        item[i] = make_tuple(value_per_weight, value, weight);
    }
    sort(item.rbegin(), item.rend());
    double sum_value = 0, sum_weight = 0;
    rep(i, n) {
        double value_per_weight = get<0>(item[i]);
        double value = get<1>(item[i]);
        double weight = get<2>(item[i]);
        if (sum_weight + weight <= w) {
            sum_weight += weight;
            sum_value += value;
        } else {
            sum_value += value * (w - sum_weight) / weight;
            break;
        }
    }
    printf("%.8lf\n", sum_value);
}


Measured memory_bytes: 5228
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
// #define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ in >> p.first >> p.second; return in; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
template <char d = ' ', class T>
ostream& operator << (ostream& out, vector<T>& v){ for(auto& e : v){ out << e << d; } return out; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> as(n), bs(n);
    cin >> as >> bs;
    if(as == bs){
        cout << 0 << '\n';
        return 0;
    }
    vector<vector<char>> atable(n, vector<char>(51));
    for(size_t i = 0; i < as.size(); i++){
        auto& a = as[i];
        atable[i][a] = 1;
    }
    int maxK = -1;
    // for(int i = 1; i < 50; i++){
    // for(int ii = 1; ii < 50; ii++){ for(int i = 1; i <= ii; i++){
    for(int ii = 1; ii < 50; ii++){
        for(int i = ii; i >= 1; i--){
    // for(int ii = 50; ii >= 1; ii--){ for(int i = 1; i <= ii; i++){
        for(int j = 0; j < n; j++){
            for(int k = 0; k < 51; k++){
                if(atable[j][k]){
                    atable[j][k % i] = 1;
                }
            }
        }
        }
        bool ok = true;
        for(int j = 0; j < n; j++){
            ok &= atable[j][bs[j]];
        }
        if(!ok){ continue; }
        // prints(i);
        maxK = ii;
        // maxK = i;
        break;
    // } }
    }
    if(maxK == -1){
        cout << -1 << '\n';
        return 0;
    }
    set<int> rems;
    for(int i = maxK - 1; i >= 1; i--){
        rems.insert(i);
        vector<vector<int>> atable(n, vector<int>(51));
        for(size_t j = 0; j < as.size(); j++){
            auto& a = as[j];
            atable[j][a] = 1;
        }
        for(int jj = maxK; jj >= 1; jj--){ for(int j = 1; j <= jj; j++){
        // for(int jj = 1; jj <= maxK; jj++){ for(int j = 1; j <= jj; j++){
            if(rems.count(j)){ continue; }
            for(int k = 0; k < n; k++){
                for(int l = 0; l < 51; l++){
                    if(atable[k][l]){
                        atable[k][l % j] = 1;
                    }
                }
            }
        } }
        if(i == 1){ prints(atable); }
        bool ok = true;
        for(int j = 0; j < n; j++){
            ok &= atable[j][bs[j]];
        }
        // printd(i, ok);
        if(!ok){
            rems.erase(i);
        }
    }
    prints(maxK, rems);
    ll ans = (1ll << (maxK + 1)) - 2;
    for(auto& e : rems){
        ans -= 1ll << e;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	int max=0,sum=0,maxn;
	vector<int> a(5),lag(5);
	for(int i=0;i<5;i++){
		cin >> a[i];
		if(a[i]%10 == 0)lag[i] = 0;
		else lag[i] = 10 - a[i]%10;
		
		if(lag[i] >= max){
			max = lag[i];
			maxn = i;
		}
	}
	
	for(int i=0;i<5;i++){
		sum += a[i];
		
		if(i != maxn)sum += lag[i];
	}
	cout << sum << endl;
	//cout << a[maxn] << endl;
	
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>

using namespace std;

#define INF 1 << 29
#define LL long long int

LL const MOD = 1000000007;

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

    LL n,m,q;
    cin >> n >> m >> q;

    vector<vector<LL>> total(n+1,vector<LL>(n+1,0)); 

    for(int i = 0; i < m; i++){
        LL l,r;
        cin >> l >> r;
        total[l][r]++;
    }

    vector<LL> a(q),b(q);

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

    for(int i = 0; i < n+1; i++){
        for(int j = 1; j < n+1; j++){
            total[i][j] += total[i][j-1];
        }
    }

    for(int i = n-1; i >= 0; i--){
        for(int j = 0; j < n+1; j++){
            total[i][j] += total[i+1][j];
        }
    }


    for(int i = 0; i < q; i++){
        cout << total[a[i]][b[i]] << endl;
    }

    
    return 0;
}

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

void solve(long long N, long long K, std::vector<long long> A) { cout << ceil((N - 1.0) / (K - 1.0)) << endl; }

int main() {
    long long N;
    scanf("%lld", &N);
    long long K;
    scanf("%lld", &K);
    std::vector<long long> A(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &A[i]);
    }
    solve(N, K, std::move(A));
    return 0;
}


Measured memory_bytes: 4068
#include<bits/stdc++.h>
//补题
using namespace std;
const int N=1e5+5;
int pa[N],cnt[N],fr[N];
 int n,m,k;
int search(int x){
    //if(pa[x]!=x) pa[x]=search(pa[x]);//这一句速度竟然能差 50倍？？
    //if(pa[x]!=pa[pa[x]]) pa[x]=search(pa[x]);
    return pa[x]==x?pa[x]:pa[x]=search(pa[x]);
    
}
void uion(int x,int y){
    int a=search(x);
    int b=search(y);
    if(a!=b){
        pa[a]=b;
        cnt[b]+=cnt[a];   
     }
}
int main()
{   
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    while(cin>>n>>m>>k)
    { 
        for(int i=1;i<=n;i++){
            pa[i]=i; cnt[i]=1; fr[i]=0;
        }
        int x,y;
        while(m--) {
            cin>>x>>y;
            fr[x]++;fr[y]++;
            uion(x,y);
        }
        for(int i=1;i<=n;i++){
            cnt[i]=cnt[search(i)];
        }
        while(k--)
        {
            cin>>x>>y;
            int a=search(x);
            int b=search(y);
            if(a==b){
                cnt[x]--; cnt[y]--;
            }
        }
        for(int i=1;i<=n;i++)
            cout<<cnt[i]-fr[i]-1<<' ';
        cout<<endl;
    
    }

    return 0;
}

Measured memory_bytes: 2688
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();
        Map<Integer,Integer> map = new HashMap<Integer,Integer>();
        boolean ans = true;
        int num = 0;

        for(int i = 0; i < m ; i++){
            int k = scan.nextInt();
            int v = scan.nextInt();

            if(map.containsKey(k)){
                if(!(map.get(k).equals(v))) ans = false;
            }
            else if(n > 1 && k == 1 && v == 0){ans = false; break;}
            else{
                map.put(k,v);
            }
        }

        scan.close();

        if(ans){
            for(int j = 1; j <= n; j++){
                if(map.containsKey(j)){
                    int k = (int)map.get(j);
                    if(n == 3){
                        if(j == 1) num += k * 100;
                        else if(j == 2) num += k * 10;
                        else num += k;
                    }
                    else if(n == 2){
                        if(j == 1) num += k * 10;
                        else num += k;
                    }
                    else{num += k;}
                }
                
                else if(j < n){
                    if(n == 3 && j == 1) num += 100;
                    if(n == 2 && j == 1) num += 10;
                }
            }
            System.out.println(num);
        }

        else{num = -1; System.out.println(num);}
    }
}

Measured memory_bytes: 25044
import java.io.*;
import java.math.*;
import java.util.*;
 
public class Main {
	static final long MOD = 1000000007L;
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter pw = new PrintWriter(System.out);
		
		int N = sc.ni();
		int M = sc.ni();
		int K = sc.ni();
		int[][] grid = new int[N][M];
		for (int i = 0; i < K; i++) {
			int r = sc.ni()-1;
			int c = sc.ni()-1;
			int v = sc.ni();
			grid[r][c] = v;
		}
		long[][][] dp = new long[N][M][4];
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < M; j++) {
				if (i==0&j==0) {
					dp[0][0][0] = 0;
					dp[0][0][1] = grid[0][0];
					continue;
				}
				for (int k = 1; k < 4; k++) {
					long v = 0;
					long w = 0;
					if (i>0) {
						v = dp[i-1][j][k];
						if (k==1) {
							for (int m = 0; m <= 3; m++) {
								v = Math.max(v, dp[i-1][j][m]+grid[i][j]);
							}
						}
					}
					if (j > 0) {
						w = Math.max(dp[i][j-1][k], dp[i][j-1][k-1]+grid[i][j]);
					}
					dp[i][j][k] = Math.max(v, w);
				}
			}
		}
		long ans = 0;
		for (int k = 1; k <= 3; k++)
			ans = Math.max(dp[N-1][M-1][k],ans);
		pw.println(ans);
		pw.close();
	}
	
    static class FastScanner { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastScanner() { 
            br = new BufferedReader(new InputStreamReader(System.in)); 
        } 
  
        String next() { 
            while (st == null || !st.hasMoreElements()) { 
                try { 
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        }
        
        int ni() { 
            return Integer.parseInt(next()); 
        }
  
        long nl() { 
            return Long.parseLong(next()); 
        } 
  
        double nd() { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() {
            String str = ""; 
            try { 
                str = br.readLine(); 
            } catch (IOException e) {
                e.printStackTrace(); 
            } 
            return str;
        }
    }
}

Measured memory_bytes: 670104
#include <iostream>
#include <stdio.h>
using namespace std;

int main()
{
  int M;
  int i, j, sum;
  
 cin >> M;
  
  i = M / 500;
  j = (M- 500 * i) / 5;
  
  sum = i * 1000 + j *5;
  
  cout << sum;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	int n, a, sum = 1; cin >> n >> a;
	if (a == 1) {
		cout << 0 << endl;
		cin >> n; return 0;
	}
	for (int h = 1; h < 30; h++) {
		sum += n - 1;
		if (sum >= a) {
			cout << h << endl;
			cin >> n; return 0;
		}
	}
	cin >> n;
}

Measured memory_bytes: 256
<?php
  $n = trim(fgets(STDIN));
  $a = explode(" ",trim(fgets(STDIN)));
  $c = 0;
  $hen = array_fill(1,$n,0);
  $len = [];
  for($i=0; $i<$n; $i++){
      $hen[$a[$i]]++;
      if($hen[$a[$i]] == 2){
          $c++;
          $len[] = $a[$i];
          $hen[$a[$i]] = 0;
      }
  }
//   print_r($len);
  rsort($len);
  if($c > 1){
      echo $len[0]*$len[1];
  }else{
      echo "0";
  }
  

Measured memory_bytes: 23796
//Aleksander Łukasiewicz
#include<bits/stdc++.h>
using namespace std;

#define x first
#define y second
#define pb push_back
#define mp make_pair

typedef long long LL;
typedef pair<int,int> PII;
typedef vector<int> VI;

const int INF = 1000000009;
const int MAXN = 2*1000;

int cnt[MAXN + 3];

int main(){
    int n, x, y;
    scanf("%d %d %d", &n, &x, &y);
    for(int i=1; i<=n; i++)
        for(int j=i+1; j<=n; j++){
            int d = j - i;
            d = min(d, abs(i-x) + 1 + abs(y - j));
            d = min(d, abs(i-y) + 1 + abs(x - j));
            cnt[d]++;
        }
    for(int i=1; i<=n-1; i++)
        printf("%d\n", cnt[i]); 
    
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <algorithm>
#include <set>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#define REP(i, n) for(int i=0; i<n; i++)
#define REPR(i, n) for(int i=n; i>0; i--)
#define FOR(i, m, n) for(int i=m; i<n; i++)
#define FORR(i, m, n) for(int i=m; i>=n; i--)
#define INF 1999999999
#define VSORT(v) sort(v.begin(), v.end())
#define pb(a) push_back(a)
using namespace std;
typedef long long ll;

#ifdef INPUT
stringstream input(R"(
314159265 35897932 384626433
)");
#define cin input
#endif

int main()
{
    ll k,a,b;
    cin >> k >> a >> b;
    ll count = 1;

    if (b-a<=1 || k<=a) {
        count += k;
    }
    else if ((k-(a-1))%2==0) {
        count = count+a-1+(b-a)*(k-(a-1))/2;
    }
    else if ((k-(a-1))%2==1) {
        count = count+a-1+(b-a)*(k-(a-1)-1)/2+1;
    }
    
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>
#include <fstream>

using namespace std;

struct before_main{before_main(){cin.tie(0); ios::sync_with_stdio(false);}} before_main;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

int main() {

  int N, M; cin >> N >> M;
  vector<int> A(M);
  rep(i, M) cin >> A[i], A[i]--;

  vector<int> score(N);

  rep(i, M) {
    int X = 0;
    rep(j, N) {
      int x; cin >> x; x--;
      if(x == A[i]) score[j]++;
      X += x != A[i];
    }
    score[A[i]] += X;
  }

  rep(i, N) {
    cout << score[i] << endl;
  }
  
  return 0;
}

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

int main(){
  int A,B,M;
  cin >> A >> B >> M;
  
  vector<int> a(A);
  vector<int> b(B);
  
  for(int i=0;i<A;i++){
    cin >> a[i];
  }
  for(int i=0;i<B;i++){
    cin >> b[i];
  }
  
  vector<vector<int>> ju(M,vector<int>(3));
  
  for(int i=0;i<M;i++){
    for(int j=0;j<3;j++){
      cin >> ju[i][j];
    }
  }
  
  int c=200000;
  
  for(int i=0;i<M;i++){
    c=min(c,a[ju[i][0]-1]+b[ju[i][1]-1]-ju[i][2]);
  }
  
  sort (a.begin(),a.end());
  sort (b.begin(),b.end());
  
  c=min(c,a[0]+b[0]);
  
  cout << c << endl;
}


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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

int n , ans;
string s;
string a[7] = {"SUN" , "MON" , "TUE" , "WED" , "THU" , "FRI" , "SAT"};

int main()
{
    _FastIO;
    cin >> s;
    for(int i = 0; i < 7; i++){
        if(a[i] == s){
            cout << 7 - i << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
                                                                                                
  
int main(void){
                                                                                                
   
    char s[5];
   
      
    scanf("%s", &s);
   
    if( s[0] == s[1] && s[1] == s[2] ) printf("Yes\n");

    else if( s[1] == s[2] && s[2] == s[3] ) printf("Yes\n");

    else printf("No\n");
   

    return 0;
                                                          
}

Measured memory_bytes: 128
def kaijo(n):
    if(n==1):
        return 1
    else:
        return n*kaijo(n-1)

N = int(input())
pt = []
for _ in range(N):
    pt.append([int(x) for x in input().split()])

sum_dist = 0

for i in range(N):
    for j in range(N):
        if(i==j):continue
        sum_dist += ((pt[i][0]-pt[j][0])**2+(pt[i][1]-pt[j][1])**2)**0.5*kaijo(N-1)


print(sum_dist/kaijo(N))

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


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

  ll sum = 1000000000001;
  for( ll i=1; i*i<=N; i++ ) {
    if ( N % i == 0 ) {
      sum = min( sum, i + (N/i) );
    }
  }
  
  cout << sum-2 << endl;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}



var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}


func main() {
		
	divide := []string{"dream", "dreamer", "erase", "eraser"}
	

	var s string
	s = readLine()

	end := len(s)
	can := false
	strLen := 0
	for i := len(s)-1; i >=0; i--  {
		st := s[i:end]
	
		for j := 0; j < len(divide); j++ {
			if st == divide[j] {
				//fmt.Println(reverse(st))
				can = true
				strLen += len(divide[j])
				end = i
				i--
				
				break
			}
		}
		
	}
	
	if can && strLen == len(s) {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}

	

}


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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;

const long long INF = 1LL << 60;

int main()
{
    int N;
    cin >> N;
    
    vector<int> A(N), As(N);
    rep(i, N) {
        cin >> A[i];
        As[i] = A[i];
    }

    sort(As.begin(), As.end());
    reverse(As.begin(), As.end());

    rep(i, N) {
        if (A[i] == As[0]) {
            cout << As[1];
        }
        else {
            cout << As[0];
        }
        cout << endl;
    }
    return 0;
}

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

typedef long long ll;
ll MOD = 1000000007;

int main()
{
    int n, cnt = 0;
    cin >> n;
    vector <int> a(n, 0);
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 1; i < n-1; i++) {
        if ((a[i-1] < a[i] && a[i] < a[i+1]) || (a[i-1] > a[i] && a[i] > a[i+1])) cnt++;
    }

    cout << cnt << endl;
    return 0;
}


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

using namespace std;

int main() {

	long long n, c, k;
	cin >> n >> c >> k;

	vector<long long> T;
	int tmp;
	for (int i = 0; i < n; i++) {
		cin >> tmp;
		T.push_back(tmp);
	}

	sort(T.begin(), T.end());
	queue<int> q;
	for (int i = 0; i < n; i++) {
		q.push(T[i]);
	}
	
	int ans = 0;

	while (q.size()) {
		int x = q.front() + k;
		ans++;
		int count = 0;
		while (q.size() && count < c && q.front() <= x) {
			q.pop();
			count++;
		}
	}
	
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 1400
#include<iostream>
#include<cstdio>
#include<queue>
#include<string>
#include<stack>
#include<algorithm>
#include<cstring>
#include<map>
using namespace std;
int sta=0;
int sw[20];
int n,m;
int dfs(int k,int i)
{
	if(i==n+1)return sta==k?1:0;
	return dfs(k^sw[i],i+1)+dfs(k,i+1);
}
int main()
{
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		int k;cin>>k;
		for(int j=1;j<=n;j++)
			sw[j]<<=1;
		while(k--)
		{
			int c;
			cin>>c;
			sw[c]+=1;
		}
	}
	int mi[20];
	mi[0]=1;
	for(int j=1;j<=m;j++)
	{
		cin>>mi[j];
	}
	for(int j=1;j<=m;j++)
	{
		sta<<=1;
		sta+=mi[j];
	}
	cout<<dfs(0,1);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORD(i, b, a) for (int i = b; i >= a; --i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPD(i, n) for (int i = n - 1; i >= 0; --i)
#define FORE(i, v) for (__typeof(v.begin()) i = v.begin(); i != v.end(); ++i)

#define sz(v) (int) v.size()
#define fi first
#define se second
#define all(v) v.begin(), v.end()

#define sqr(x) ((x) * (x))
#define EPS 1e-9
#define INF 1000000007ll
#define long long long

const int N = 1e5 + 10;

int n, c, k;
int t[N];

int main() {
//    freopen("input.in", "r", stdin);
//    freopen("output.out", "w", stdout);

    scanf("%d%d%d", &n, &c, &k);
    FOR(i, 1, n) scanf("%d", &t[i]);

    sort(t + 1, t + n + 1);
    int j = 1, ans = 0;
    for (int i = 1; i <= n; ) {
        while (t[j] - t[i] <= k && j - i + 1 <= c && j <= n) j++;
        ans++;
        i = j;
    }
    printf("%d", ans);

    return 0;
}



Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;

int main()
{
    int k, x;
    cin >> k >> x;

    rep(i, x - k + 1, x + k)
        cout << i << ' ';
    cout << endl;
    return 0;
}

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long double ld;
typedef long long ll;
const int MOD =  1000000007;
const int IINF = INT_MAX;
const ll INF = 1LL << 60;


int main() {
    int n; cin >> n;
    V<P<ll, ll> > v(n);
    for(int i = 0; i < n; i++){
        ll x, l; cin >> x >> l;
        v[i] = make_pair(x + l, x - l);
    }

    sort(ALL(v));

    int ans = 0;
    ll pre = -1e9;
    for(int i = 0; i < n; i++){
        if(pre <= v[i].second){
            ans++;
            pre = v[i].first;
        }
    }
    cout << ans << endl;



    return 0;
}


Measured memory_bytes: 4840
PROGRAM ROT_N
      IMPLICIT NONE
      integer(16) :: n
      character(10**4) :: s
      integer(16) :: a,z,len,i,ch
      character(:),allocatable :: ans
      
      read*,n
      read*,s
      
      
      len = len_trim( s )
      
      allocate( character(len) :: ans )
      
      a = ichar( 'A' )
      z = ichar( 'Z' )
      
      DO i = 1,len
        ch = ichar( s(i:i) )
        ch = ch + n
        if( ch>z )then
          ch = ch - 26
        end if
        ans(i:i) = char( ch )
      END DO
      
      print*,trim( ans )
      
      END PROGRAM

Measured memory_bytes: 640
n,m=gets.chomp.split.map(&:to_i)
s=Array.new(n+2,0)
m.times do
  l,r=gets.chomp.split.map(&:to_i)
  s[l]+=1
  s[r+1]-=1
end
1.upto(n+1) do |i|
  s[i] += s[i-1]
end 
puts s.count(m)


Measured memory_bytes: 2556
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, ll> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 3010;
const int MAXM = 100010;
const int MAXK = 510;
const int MAXQ = 200010;

int a[MAXN], n;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
  cin >> n;
  FOR(i,1,n) cin >> a[i];
  int s = -n;
  FOR(i,1,n) s += a[i];
  cout << s;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
using namespace std;
ll n;
ll m;
const ll N = 1e5 + 10;
ll p[N];
ll sz[N];
ll ans[N];
ll fs(ll x)
{
        return p[x]==x ? x : p[x] = fs(p[x]);
}
bool ms(ll x, ll y)
{
        x = fs(x);
        y = fs(y);
        if(x==y) return false;
        sz[x] += sz[y]; sz[y]=0;
        ans[x] += ans[y]; ans[y]=0;
        p[y] = x;
        return true;
}
vector< tuple<ll,ll,ll> > e;
int main()
{
        ios_base::sync_with_stdio(false);
        cin.tie(NULL); cout.tie(NULL);
        cin >> n >> m;
        for(ll i=1;i<=n;i++) {
                cin >> sz[i];
                p[i]=i;
        }
        for(ll i=1;i<=m;i++) {
                ll u,v,w;
                cin >> u >> v >> w;
                e.pb(make_tuple(w,u,v));
        }
        sort(e.begin(), e.end());
        for(auto i : e) {
                ll u,v,w;
                tie(w,u,v) = i;
                //cout << u << " " << v << " " << w << endl;
                if(ms(u,v) == false) {
                        if(w > sz[fs(u)]) {
                                ans[fs(u)]++;
                        }
                }else {
                        if(w <= sz[fs(u)]) ans[fs(u)] = 0;
                        else ans[fs(u)]++;
                }
        }
        for(ll i=1;i<=n;i++) {
                if(p[i] == i) {
                        cout << ans[i] << "\n";
                }
        }
        return 0;
}


Measured memory_bytes: 6388
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define MOD (int) (1e9+7)
#define INF (int) 2e9
#define LLINF (ll) 2e18

int dp[15][15];

int main(){
    int n;
    cin >> n;

    vector<pair<string, char>> sc;

    sc.emplace_back(make_pair("a", 'a'));

    rep(ii, n-1){
        vector<pair<string, char>> stmp;
        for(auto st: sc){
            int num = st.second -'a';
            for (int i = 0; i < num+2; i++){
                string ssss = st.first;
                ssss += (char)('a'+i);
                stmp.emplace_back(make_pair(ssss, max((char)('a'+i), st.second)));
            }
        }
        sc = stmp;
    }


    rep(i, sc.size()){
        cout << sc[i].first << endl;
    }
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 10984
import std.stdio, std.string, std.complex, std.algorithm, std.conv;

alias Complex!real z;

void main()
{
    foreach(_; 0 .. readln.chomp.to!int)
    {
        auto f = readln.split.map!(to!real);
        z a = z(f[0], f[1]),
          b = z(f[2], f[3]),
          c = z(f[4], f[5]);
        z p = (a * a.conj * (b - c) + b * b.conj * (c - a) + c * c.conj * (a - b)) / 
              (a.conj * (b - c) + b.conj * (c - a) + c.conj * (a - b));

        writefln("%.3f %.3f %.3f", p.re, p.im, (p - a).abs);
    }
}

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

#define say(obj) (cout << (obj) << endl)
#define endline (cout << endl)
#define all(container) (container).begin(), (container).end()
#define sortall(container) (sort((container).begin(), (container).end()))
#define yn(cond) ((cond) ? (cout << "yes" << endl) : (cout << "no" << endl))
#define Yn(cond) ((cond) ? (cout << "Yes" << endl) : (cout << "No" << endl))
#define YN(cond) ((cond) ? (cout << "YES" << endl) : (cout << "NO" << endl))

typedef long long       ll;

typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef vector<double>  vd;
typedef vector<bool>    vb;
typedef vector<char>    vc;
typedef vector<string>  vs;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;
typedef vector<vi>		vvi;
typedef vector<vll>		vvll;
typedef vector<vd>		vvd;
typedef vector<vb>		vvb;
typedef vector<vc>		vvc;
typedef vector<vs>		vvs;
typedef vector<pii>     vpii;
typedef vector<pll>     vpll;

typedef struct edge_ {
	ll to, cost;
	edge_(ll to, ll cost) : to(to), cost(cost) {}
} edge;

typedef struct point_ {
	ll x, y;
	point_(ll x = 0, ll y = 0) : x(x), y(y) {}
} point;

template <typename T>
using mat2d = vector<vector<T>>;

constexpr double	PI = 3.14159265358979323846;
constexpr int		INF = (int)1e7;
constexpr ll		MOD = (ll)1e9 + 7;
constexpr double	EPS = 1e-7;
constexpr int		dy4[4] = { 0, 1, 0, -1 };
constexpr int		dx4[4] = { 1, 0, -1, 0 };
constexpr int		dy8[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };
constexpr int		dx8[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };

template <typename T>
T getSum(std::vector<T>& v) {
	T ret = 0;
	for (T& x : v) ret += x;
	return ret;
}

template <typename T>
istream& operator >> (istream & is, vector<T> & vec) { for (T& x : vec) is >> x;  return is; }
template <typename S, typename T>
istream& operator >> (istream & is, pair<S, T> & p) { is >> p.first >> p.second; return is; }
istream& operator >> (istream & is, point & p) { is >> p.x >> p.y;          return is; }

template <typename T>
ostream& operator << (ostream & os, const vector<T> & vec) { for (const T& x : vec) os << x << " "; return os; }
template <typename T>
ostream& operator << (ostream & os, const vector<vector<T>> & mat) { for (const vector<T>& m : mat) os << m << endl; return os; }
template <typename S, typename T>
ostream& operator << (ostream & os, const pair<S, T> & p) { os << "{" << p.first << " : " << p.second << "}"; return os; }
template <typename T>
ostream& operator << (ostream & os, const set<T> & s) { for (const T& x : s) os << x << " "; return os; }
ostream& operator << (ostream & os, const edge e) { os << "{to: " << e.to << ", cost: " << e.cost << "}"; return os; }
ostream& operator << (ostream & os, const point & p) { os << "(" << p.x << " " << p.y << ")"; return os; }

/******************************************************************************/
/**********************         Don't make WA !!         **********************/
/******************************************************************************/



int main()
{
	int N, K;
	string S;
	cin >> N >> K >> S;

	S[K - 1] = S[K - 1] - ('A' - 'a');
	   
	say(S);



	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys


def input():
    return sys.stdin.readline()


def all_search(s, i, i_sum: int, temp):
    n = int(s[i])

    if i == len(s)-1:
        # ベースケース
        i_sum += temp + n
        return i_sum
    else:
        ret = all_search(s, i+1, i_sum, (temp+n)*10) + all_search(s, i+1, i_sum+temp+n, 0)
        return ret




def resolve():
    s = input().rstrip()

    print(all_search(s, 0, 0, 0))



if __name__ == "__main__":
    resolve()



Measured memory_bytes: 38384
S = input()
MOD = 10**9+7
dp = [[0 for i in range(3)] for q in range(4)]
for c in S:
    if c == 'A':
        dp[0][0] += 1
    elif c == 'B':
        dp[0][1] += dp[0][0]
        dp[1][1] += dp[1][0]
    elif c == 'C':
        dp[0][2] += dp[0][1]
        dp[1][2] += dp[1][1]
        dp[2][2] += dp[2][1]
    else:
        #as 'C'
        dp[1][2] += dp[0][1]
        dp[2][2] += dp[1][1]
        dp[3][2] += dp[2][1]
        #as 'B'
        dp[1][1] += dp[0][0]
        dp[2][1] += dp[1][0]
        #as 'A'
        dp[1][0] += 1

q = S.count('?')
ans = 0
for use_q in range(4):
    if use_q > q: break
    ans += (dp[use_q][-1] % MOD) * pow(3, q - use_q, MOD)
    ans %= MOD
print(ans)

Measured memory_bytes: 3316
import java.util.Scanner

import scala.collection.Searching._
import scala.annotation.tailrec
import scala.collection.immutable.{NumericRange, Queue}
import scala.collection.mutable
import scala.io.StdIn.readLine

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 solve(sc: => Scanner): Unit = {
    println(sc.next.charAt(0).toString + sc.next.charAt(1).toString + sc.next.charAt(2).toString)
  }

  def gcd(i: Long, j: Long): Long = {
    if (i < j) (gcd(j, i)) else (if (j == 0) (i) else (gcd(j, i % j)))
  }

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

Measured memory_bytes: 25548
n, q = list(map(int, input().split()))
# NG: [set()] * n <- all points same set
edge = [set() for _ in range(n)]
for _ in range(n - 1):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    edge[a].add(b)
    edge[b].add(a)

opr = [0] * n
for _ in range(q):
    p, x = list(map(int, input().split()))
    p -= 1
    opr[p] += x

score = [-1] * n
q = [(0, 0)]
while q:
    # print(*q)
    node, w = q.pop()
    w += opr[node]
    score[node] = w
    # print(*score)
    for child in edge[node]:
        if score[child] == -1:
            q.append((child, w))

print(*score)

Measured memory_bytes: 90748
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std;

struct Node{
    int key;
    Node *prev,*next;
};
Node *nil;/*番兵を作成*/

void init(){
    nil = (Node *)malloc(sizeof(Node));
    nil->next = nil;
    nil->prev = nil;
}
void insert(int key){
    Node *x = (Node *)malloc(sizeof(Node));
    x->key = key;
    x->next = nil->next;
    nil->next->prev=x;
    nil->next = x;
    x->prev = nil;
}

Node* listserch(int key){
    Node *cur = nil->next;
    while(cur != nil && cur->key != key){
        cur = cur->next;
    }
    return cur;
}

void deleteNode(Node *t){
    if(t == nil) return; // tが番兵（要素を持たない場合は何もしない)
    t->prev->next = t->next; 
    t->next->prev = t->prev;
    free(t);
}

void deleteFirst(){
    deleteNode(nil->next);
}
void deleteLast(){
    deleteNode(nil->prev);
}
void printList(){
    Node *cur = nil->next;
    int isf = 0;
    while(1){
        if(cur == nil) break;
        if(isf++ > 0) printf(" ");
        printf("%d",cur->key);
        cur = cur->next;
    }
    printf("\n");
}

void deleteKey(int key){
    deleteNode(listserch(key));
}

int main(){
    int key,i,n;
    int size =0;
    char com[20];
    int np=0,nd = 0;
    scanf("%d",&n);
    init();
    for(i=0;i<n;i++){
        scanf("%s%d",com,&key);
        if(com[0] =='i'){
            insert(key);
            np++;
            size++;
        }
        else if(com[0] =='d'){
            if(strlen(com) > 6){
                if(com[6] == 'F') deleteFirst();
                else if(com[6] == 'L') deleteLast();
            }else
            {
                deleteKey(key); nd++;      
            }
            size--;
        }
    }
    printList();
    return 0;
}


Measured memory_bytes: 34452
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, double> PII;
typedef complex<double> P;
static const double EPS = 1e-8;
static const int INF = (int)1e8;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) for (int i=0; i<(int)(n); ++i)
#define FOREQ(i,k,n) for (int i=(k); i<=(int)(n); ++i)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FIND(m,w) ((m).find(w)!=(m).end())
int w,h;
int grid[100][100];
string grid_str[100];
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
bool upon[1000][1000];
int countofcube[1000];
double countofx[1000];
int cnt;
void makegrid(int n,int x,int y,char c){
  grid_str[y][x] = '.';
  grid[y][x] = n;
  REP(r,4){
    int nx = x + dx[r];
    int ny = y + dy[r];
    if(nx>=0&&nx<w&&ny>=0&&ny<h&&grid_str[ny][nx]==c){
      makegrid(n,nx,ny,c);
    }
  }
}
PII countgv(int n){
  PII ret(countofcube[n],countofx[n]);
  REP(i,cnt){
    int u = i+1;
    if(upon[u][n]){
      PII p = countgv(u);
      ret.first+=p.first;
      ret.second+=p.second;
    }
  }
  return ret;
}
bool dfs(int n){
  int minx=INF;
  int maxx=-1;
  REP(y,h)REP(x,w)if(grid[y][x]==n&&(y==h-1||(grid[y+1][x]!=grid[y][x]&&grid[y+1][x]!=0))){
    minx = min(minx,x);
    maxx = max(maxx,x+1);
  }
  REP(i,cnt){
    int u = i+1;// 1-origin
    if(upon[u][n]){
      if(!dfs(u)) return false;
    }
  }
  PII pii = countgv(n);
  //printf("%d:%d,%lf\n",n,pii.first,pii.second);
  //printf("%d:%d->%d\n",n,minx,maxx);
  //printf("%lf\n",pii.second/pii.first);
  if((double)minx*pii.first<pii.second&&pii.second<(double)maxx*pii.first) return true;
  else return false;
}

int main(void){
  while(cin>>w>>h,w){
    memset(grid,0,sizeof(grid));
    memset(upon,0,sizeof(upon));
    memset(countofcube,0,sizeof(countofcube));
    memset(countofx,0,sizeof(countofx));
    cnt = 0;
    REP(y,h)cin>>grid_str[y];
    REP(y,h)REP(x,w){
      if(grid_str[y][x]!='.'){
        makegrid(++cnt,x,y,grid_str[y][x]);
      }
    }
    //cnt<=1000ツづーツ可シツ津ィ
    if(cnt>1000) abort();
    //upon[ツ湘」][ツ可コ]
    REP(y,h-1)REP(x,w){
      if(grid[y][x]!=0&&grid[y+1][x]!=0&&grid[y][x]!=grid[y+1][x]){
        upon[grid[y][x]][grid[y+1][x]] = true;
      }
    }
    REP(y,h)REP(x,w){
      if(grid[y][x]!=0){
        int u = grid[y][x];
        countofcube[u]++;
        countofx[u]+=(double)x+0.5;
      }
    }
    /*
    REP(i,cnt){
      int u = i+1;
      printf("%d/%d\n",countofx[u],countofcube[u]);
    }
    */
    REP(x,w)if(grid[h-1][x]!=0){
      if(dfs(grid[h-1][x])) cout<<"STABLE"<<endl;
      else cout << "UNSTABLE" << endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
 using namespace  std;
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
const double pi=3.1415926535897932384626433832;
const long long mod=1e9+7;
//long long primeset[5000000]={};
typedef complex<double> cd;
typedef long long ll;
typedef double ld;
//#define For(i,0,n) for(long long i = 0 ; i<n ;i++) 
cd fast_exp(cd a, long long b)
{
	if (b == 0)
		return 1;
	
	cd res = fast_exp(a, b / 2);
		
	res = res * res;
	
	if (b % 2 == 1)
		res = res * a;
	
	return res;
}

long long fastexpon(long long a,long long b,long long mod)
{
	if(b==0)
		return 1;
	
	long long res=fastexpon(a,b/2,mod);
	
	res=(res*res)%mod;
	if(b%2==1)
		res= (res * a)%mod;

	return res;
}


//TEMPLATE ENDS HERE!!!! ------------------------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------------------------------------------















struct custom
{
	bool operator()(ll a, ll b)
	{
		return a > b;
	}
};

// struct triplet{

// 	ll a;
// 	ll b;
// 	ll c;
// };
int main()
 {
		
		// ios_base::sync_with_stdio(false);
		// cin.tie(NULL);
		// cout.tie(NULL);
 		
 	ll x,y,z,maxk;
 	cin>>x>>y>>z>>maxk;
 	ll a[x+1],b[y+1],c[z+1];
 	map <pair<pair<ll,ll>,ll>,ll> is_there;
 	vector <pair<pair<ll,ll>,ll>> allposs;
 	
 	for(ll i=1 ; i<=x ;i++)
 	cin>>a[i];
 	for(ll i=1 ; i<=y ;i++)
 	cin>>b[i];
 	for(ll i=1 ; i<=z ;i++)
 	cin>>c[i];
 	sort(a+1,a+x+1,greater<>());
 	sort(b+1,b+y+1,greater<>());
 	sort(c+1,c+z+1,greater<>());
 	for(ll i=1 ; i<=x ; i++ )
 		{
 			if(i>maxk)
 				break;
 			for(ll j=1 ; j<=y ;j++)
 			{
 				if(i*j > maxk)
 					break;
 				for(ll k=1;k<=z ;k++)
 				{
 					if(i*j*k> maxk)
 						break;
 					else
 					{
 						pair<pair<ll,ll>,ll> trip;
 						trip.ff.ff = i;
 						trip.ff.ss=j;
 						trip.ss=k;

 						if(!is_there[trip])
 						{
 							allposs.pb(trip);
 							is_there[trip]++;
 						}
 					}
 				}
 			}
 		}
 	vector <ll> ans;
 	for(ll i=0 ;i<allposs.size();i++)
 	{
 		ll m1 = allposs[i].ff.ff;
 		ll m2 = allposs[i].ff.ss;
 		ll m3 =allposs[i].ss;
 		ans.pb(a[m1]+b[m2]+c[m3]);
 	}

 	sort(ans.begin(),ans.end(),greater<>());

 	for(ll i=0 ;i<maxk ;i++)
 	cout<<ans[i]<<'\n';			


	//cout<<'\n'<<"time elapsed: "<<clock()*1000.0 / CLOCKS_PER_SEC<<" ms"<<'\n';
	return 0;
}

Measured memory_bytes: 13232
#include<iostream>

int main(){
	int h,w;
	while(1){
		std::cin>>h>>w;
		if(h == 0 && w == 0)break;
		if(h > 0){
			for(int i = 0; i < w; ++i){
				std::cout<<"#";
			}
			std::cout<<std::endl;
		}
		for(int i = 0; i < h - 2; ++i){
			std::cout<<"#";
			for(int j = 0; j < w - 2; ++j){
				std::cout<<".";
			}
			if(w > 1)
			std::cout<<"#"<<std::endl;
		}
		if(h > 1){
			for(int i = 0; i < w; ++i){
				std::cout<<"#";
			}
			std::cout<<std::endl;
		}
		std::cout<<std::endl;
	}
	return 0;
}

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

int main() {
  string S;
  cin >> S;
  int N = S.size();
  
  int countC = 0;
  int countF = 0;
  for (int i = 0; i < N; i++){
    if (S.at(i) == 'C'){
      countC++;
    }
    else if (countC > 0 && S.at(i) == 'F'){
      countF++;
    }
  }
  if (countF > 0){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}
   

Measured memory_bytes: 3616
#127
r, D,x_20000  = list(map(int, input().split()))

x = [0] * 11

for j in range(0,11):
    if j == 0 :
        x[j] = x_20000
    else :
        x[j] = x[j - 1] * r - D
        print(x[j])

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

int main() {
    cin.tie(0)->sync_with_stdio(false);

    ll a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;

    if ((v - w) * t >= abs(a - b)) cout << "YES" << '\n';
    else cout << "NO" << '\n';
    return 0;
}

Measured memory_bytes: 3636
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input():
    return sys.stdin.readline().rstrip()

def main():
    H,W=map(int,input().split())
    h,w=map(int,input().split())
    print(H*W-h*W-H*w+h*w)

if __name__ == '__main__':
    main()

Measured memory_bytes: 38256
# prime_number?

n=int(input())

from math import sqrt
from random import randint

def isprime(num): # O(sqrt(n))
	root=int(sqrt(n))
	for i in range(2,root+1):
		if num%i==0:
			return(False)
	return(True)

def isprime_(num, n=1): # O(k+n)未満 (ミラー・ラビンテスト)
	q = num
	if q == 2:
		return(True)
	if q ==1 or q&1 == 0:
		return(False)
	d = (q-1)>>1
	while d&1 == 0:
		d >>= 1
	for i in range(n):
		a = randint(1,q-1)
		t = d
		y = pow(a,t,q)
		while t != q-1 and y != 1 and y != q-1: 
			y = pow(y,2,q)
			t <<= 1
		if y != q-1 and t&1 == 0:
			return(False)
	return(True)

def dividers(num, sort=True):
	root=int(sqrt(n))
	l=[]
	m=[]
	for i in range(1,root+1):
		if num%i==0:
			l.append(i)
			if i<root:
				m.append(int(num/i))
	if sort:
		l.extend(sorted(m))
		return(l)
	else:
		l.extend(m)
		return(l)

def decomposit(num):
	root=int(sqrt(n))
	l=[]
	i=2
	while i<root+1:
		if num%i==0:
			j=0
			while(num%i==0):
				j+=1
				num=num/i
			l.append([i,j])
			root=int(sqrt(n))
		i+=1
	if num!=1:
		l.append([int(num),1])
	return(l)

l={}
for i in range(n+1):
	if isprime_(i):
		l[i]=0

for i in range(1,n+1):
	for j in decomposit(i):
		l[j[0]]+=j[1]

d=1
for i in l.values():
	d*=i+1

d%=10**9 +7
print(d)












Measured memory_bytes: 5224