akhauriyash/Code-Regression huggingface dataset:
class Log
  def initialize(enabled)
    @enabled = enabled
    @log = File.open("logA.txt", "wb") if @enabled
  end
  def close
    @log.close if @enabled
  end
  def print(str)
    @log.print(str) if @enabled
  end
end

#log = Log.new(true)
log = Log.new(false)

n_vertex, n_edge = gets.split.map(&:to_i)
edges = n_vertex.times.map { Array.new(n_vertex, -1) }
for i in 0...n_edge do
  u, v, d = gets.split.map(&:to_i)
  edges[u - 1][v - 1] = d
  edges[v - 1][u - 1] = d
end
log.print "[edges]\n"
for i in 0...n_vertex do
  log.print edges[i].join(" ") + "\n"
end
log.print "\n"

order_list = []
depot_order = []
load = []
curr_v = 0
next_v = 0
target_v = 0
len = 0
distance = 0
visited = {}
visited[0] = true

t_max = gets.to_i
t_last = (t_max.to_f * 0.95).to_i
log.print "[t_max] #{t_max} [t_last] #{t_last}\n\n"

for t in 0...t_max do
  log.print "[t=] #{t}\n"
  log.print "curr_v=#{curr_v} next_v=#{next_v} len=#{len}\n"
  
  # Read new order
  n_new = gets.to_i
  for i in 0...n_new do
    new_id, dst = gets.split.map(&:to_i)
    if order_list[new_id].nil?
      order_list[new_id] = [dst, t, -1]
      depot_order.push(order_list[new_id])
      log.print "[new order] new_id=#{new_id} dst=#{dst}\n"
    else
      log.print "Panic! Invalid new_id!\n"
    end
  end
  
  # Simulate depot
  if curr_v == 0 && distance == 0
    depot_order.each do |o|
      load.push(o)
    end
    depot_order = []
  end
  log.print "depot_order.size=#{depot_order.size} load.size=#{load.size}\n"
  
  if t < (t_max / 2)
    command = -1
  else
    if distance == 0
      target_v = -1
      len = -1
      for i in 0...n_vertex do
        if edges[curr_v][i] > 0 && !visited.include?(i)
          target_v = i
          len = edges[curr_v][i]
          break
        end
      end
      if target_v < 0
        for i in 0...n_vertex do
          if edges[curr_v][i] > 0
            target_v = i
            len = edges[curr_v][i]
            break
          end
        end
      end
      log.print "[target_v] #{target_v} [len] #{len}\n\n"
    end

    if target_v >= 0 && distance < len
      command = target_v + 1
    else
      command = -1
    end
  end
  puts command
  
  # Simulate move
  if command != -1
    if distance == 0
      next_v = target_v
    else
      if target_v != next_v
        log.print "Panic! Invalid target_v!\n"
      end
    end
    distance += 1
    if distance == len
      curr_v = next_v
      next_v = -1
      distance = 0
      visited[curr_v] = true
    end
  end
end

log.close


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

int x, y, Max;
vector <int> G[5];

void DFS(int u, int fa, int deep)
{
	Max = max(Max, deep);
	for (auto v : G[u]) if (v != fa)
		DFS(v, u, deep + 1);
}

int main()
{
	while (scanf("%d%d", &x, &y) != EOF)
	{
		for (int i = 1; i <= 4; ++i) G[i].clear();
		G[x].push_back(y);
		G[y].push_back(x);
		for (int i = 1; i <= 2; ++i)
		{
			scanf("%d%d", &x, &y);
			G[x].push_back(y);
			G[y].push_back(x);
		}
		Max = 0;
		DFS(1, 1, 1);
		puts(Max == 4 ? "YES" : "NO");
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define ktya(x) sort(all(x))
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define all(aa) (aa).begin(), (aa).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 1e18
#define INFLL 1000000000000000007LL
#define SIZE 200105
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define PI (acos(-1))
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
typedef pair<pill,int> PA;
//ll MOD;
ll MOD = 1000000007;
// ll MOD=998244353;
typedef ll Weight;
struct Edge {
	int src, dst;
	ll weight;
};
int N;
vector<pair<ll,ll> > datas;

int main(){
	cin>>N;
	rep(i,N){
		ll x,l;
		cin>>x>>l;
		datas.pb(mp(x+l,x-l));
	}
	sort(all(datas));
	int rig=datas[0].second-1;
	int ans=0;
	rep(i,N){
		if(datas[i].second>=rig){
			ans++;
			rig=datas[i].first;
			//cout<<rig<<endl;
		}
	}
	cout<<ans<<endl;

}


Measured memory_bytes: 2420
//Hiia
#include <stdio.h>
#include <stdlib.h>//rannsuu
#include <time.h>
//srand((unsigned int) time(0));
#include <math.h>//koudona keisann
#include <string.h>//hairetsu
//#define N

//scanf("\n", );
//printf("\n", );

//long n,s;
//scanf("%ld %ld", &n, &s);

//for(i = 0; i < N; i++) {

//long long a [100010];
//for(int i=0;i<n;i++) scanf("%lld",&a[i]);


int main(){
  char a[100];
  scanf("%d%d%d%d%d", &a[1],&a[2],&a[3],&a[4],&a[5]);
  for(int i = 1; i < 6; i++){
    if(a[i]==0){
      printf("%d\n", i);
    }
  }

  return 0;
}


Measured memory_bytes: 1724
ENV[Z='RUBY_THREAD_VM_STACK_SIZE']||exec({Z=>'50000000'},'ruby',$0)

N = gets.to_i
@hh = gets.chomp.split.map(&:to_i)

@dparr = Array.new(N)

def dp(to, cost)
  return cost if to == 0
  return @dparr[to] if @dparr[to]

  if to - 2 < 0
    @dparr[to] = dp(to - 1, cost) + (@hh[to] - @hh[to - 1]).abs
  else
    @dparr[to] = [dp(to - 1, cost) + (@hh[to] - @hh[to - 1]).abs, dp(to - 2, cost) + (@hh[to] - @hh[to - 2]).abs].min
  end
  return @dparr[to]
end

puts dp(N- 1, 0)

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

// なんとなく、置換できる組(xi,yi)をすべて集合にまとめて
// i番目の順列Piとインデックスiがおなじ集合に属しているなら
// 順列中のiとPiは置換できると考えた
// https://atc001.contest.atcoder.jp/tasks/unionfind_a
struct unionfind{
    vector<int> par, rank;
    unionfind(int s) {
        par.resize(s);
        rank.resize(s, 0);
        for(int i = 0; i < s; ++i) par[i] = i;
    }
    int root(int x) {
        return par[x] == x ? x : par[x] = root(par[x]);
    }
    bool same(int x, int y) { return root(x) == root(y); }
    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if(x == y) return;
        if(rank[x] < rank[y]) {
            par[x] = y;
        } else {
            par[y] = x;
            if(rank[x] == rank[y]) rank[x]++;
        }
    }
};

int main()
{
    int N, M;
    scanf("%d %d", &N, &M);
    vector<int> P(N);
    unionfind List(N);
    for(int i = 0; i < N; ++i) {
        int p;
        scanf("%d", &p);
        P[i] = p-1;
    }
    for(int i = 0; i < M; ++i) {
        int x, y;
        scanf("%d %d", &x, &y);
        List.unite(x-1, y-1);
    }
    int res = 0;
    for(int i = 0; i < N; ++i) {
        if(List.same(i, P[i])) ++res;
    }
    printf("%d\n", res);
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
#include <math.h>

using namespace std;

int main()
{
	int N, K;
	string S, key, w;
	cin >> N >> S >> K;
	key = S[K - 1];
	for (int val = 0; val < N; val++) {
		w = S[val];
		if (w != key) {
			S[val] = '*';
		}
	}
	cout << S << endl;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 5 + 10)


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


def resolve():
    a, b, c = map(int, input().split())
    cnt = 0
    if a+b-1>c:
        print(b+c)
    else:
        c -= b
        cnt += b * 2

        if a < c:
            cnt += a + 1
        elif a == c:
            cnt += a
        else:
            if c > 0:
                cnt += c + 1

        print(cnt)



resolve()

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

int n, K, x[101000];

int main(void) {
  scanf("%d%d", &n, &K);
  for(int i = 1; i <= n; i++)
    scanf("%d", &x[i]);
  int ans = 1e9;
  for(int i = 1; i <= n - K + 1; i++) {
    int j = i + K - 1;
    if(x[i] >= 0) ans = min(ans, x[j]);
    else if(x[j] <= 0) ans = min(ans, -x[i]);
    else ans = min(ans, min(-x[i] + x[j] - x[i], x[j] + x[j] - x[i]));
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}
const int INF = 1e18;

signed main() {
    int K;
    cin >> K;
    if(K==2 || K==5) {
        cout << -1 << endl;
        return 0;
    }

    int res = -1;
    int t = 0;
    rep(i, 1000000) {
        t += 7;
        if(t%K==0) {
            res = i+1;
            break;
        }
        t = (t*10)%K;
    }

    cout << res << endl;

    return 0;
}

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

using namespace std;

int main(){
	int a,b;
	scanf("%d",&a);
	scanf("%d",&b);
	if(a+b==3){
		printf("3");
	}else if(a+b==4){
		printf("2");
	}else{
		printf("1");
	}
	return 0;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,R;
    cin >> N >> R;
    if(N<10) cout << R + (10-N)*100 << endl;
    else cout << R << endl;
    return 0;
}


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

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

    int a;
    bool flg = true;
    while(std::cin >> a){
        if(0 == a % 2){
            flg = flg && (0 == a % 3 || 0 == a % 5);
        }
    }

    if(flg){
        std::cout << "APPROVED" << std::endl;
    }else{
        std::cout << "DENIED" << std::endl;
    }

    return 0;
}

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

int main(){
  int64_t a, b, c, d;
  cin>>a>>b>>c>>d;
  vector<int64_t> vec(4);
  vec.at(0)=a*c;
  vec.at(1)=a*d;
  vec.at(2)=b*c;
  vec.at(3)=b*d;
  sort(vec.begin(), vec.end());
  cout<<vec.at(3)<<endl;
}

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

using namespace std;

typedef long long ll;

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;
}

vector<ll> calc_factors(const ll n) {
    vector<ll> factors;
    factors.push_back(1);
    // factors.push_back(n);
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            if (i * i != n) {
                factors.push_back(i);
                factors.push_back(n / i);
            } else {
                factors.push_back(i);
            }
        }
    }
    return factors;
}

void disp(const vector<int> &xs) {
    for (int i = 0; i < (int) xs.size(); i++) {
        cout << xs[i] << " ";
    }
    cout << endl;
}

void solve(const int N, const vector<ll> &a, vector<ll> &counter, vector<ll> &ans) {
    for (ll n = N; n > 0; n--) {
        // disp(counter);
        if (a[n] == 0) {
            if (counter[n] % 2 == 0) {
                ans[n] = 0;
            } else {
                ans[n] = 1;
                vector<ll> factors = calc_factors(n);
                for (int i = 0; i < (int) factors.size(); i++) {
                    counter[factors[i]]++;
                }
            }
        } else {
            if (counter[n] % 2 == 0) {
                ans[n] = 1;
                vector<ll> factors = calc_factors(n);
                for (int i = 0; i < (int) factors.size(); i++) {
                    counter[factors[i]]++;
                }
            } else {
                ans[n] = 0;
            }
        }

    }
}

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

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

    vector<ll> counter(N + 1, 0);
    vector<ll> ans(N + 1, -1);
    ans[0] = 0;
    solve(N, a, counter, ans);

    int num = 0;
    for (int i = 1; i <= N; i++) {
        if (ans[i] == 1) {
            num++;
        }
    }
    cout << num << endl;
    if (num > 0) {
        for (int i = 1; i <= N; i++) {
            if (ans[i] == 1) {
                cout << i << " ";
            }
        }
        cout << endl;
    }
    
    return 0;
}


Measured memory_bytes: 5504
#include <bits/stdc++.h>
using namespace std;
#define fst first
#define snd second
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
#define pb push_back
#define for_tests(t, tt) int t; scanf("%d", &t); for(int tt = 1; tt <= t; tt++)
#ifndef ONLINE_JUDGE
#define debug(args...) fprintf(stderr,args)
#else
#define debug(args...)
#endif //ONLINE_JUDGE
template<typename T> inline T abs(T t) { return t < 0? -t : t; }
const ll modn = 1000000007;
inline ll mod(ll x) { return x % modn; }
#define IOS() ios::sync_with_stdio(0),cin.tie(0)

const int MAXN = 300005;

int tree[MAXN*4];

void upd(int idx, int i, int j, int l, int x){
    if(i > l || j < l) return;
    if(i == j){
        tree[idx] = x;
        return ;
    }
    int m = (i+j)/2;
    upd(idx*2, i,  m, l, x);
    upd(idx*2+1, m+1, j, l, x);
    tree[idx] = max(tree[idx*2], tree[idx*2+1]);
}

int qry(int idx, int i, int j,int l, int r){
    if(i > r || j < l) return 0;
    if(i >= l && j <= r)
        return tree[idx];
    int m = (i+j)/2;
    return max(qry(idx*2, i, m, l, r),
                qry(idx*2+1, m+1, j, l, r));
}

int n, m, k;
int s[MAXN];

int main (){
	scanf("%d%d", &n, &k);
    int ans = 0;
	for(int a=0;a<n;a++){
        scanf("%d", s+a);
        int val = 1 + qry(1, 0, MAXN-1,  max(0, s[a]-k), min(MAXN-1, s[a]+k));
        ans = max(ans, val);
        //printf("s[a] %d val %d\n", s[a], val);
        upd(1, 0, MAXN-1, s[a], val);
	}
    printf("%d\n", ans);
}



Measured memory_bytes: 9024
N, A, B = map(int, input().split())
S = input()

ca, cb = 0, 0

for s in S:
    if s == "a" and ca < A + B:
        ca += 1
        print("Yes")
    elif s == "b" and ca < A + B and cb < B:
        ca += 1
        cb += 1
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 4016
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
 
int N, M;
typedef pair<int,int> pint;
 
vector<pint> A;
 
 
bool cmp(pint a, pint b) { return a.second < b.second; }
 
int main() {
    while (cin >> N >> M) {
        A.resize(M);
        for (int i = 0; i < M; ++i) cin >> A[i].first >> A[i].second;
        sort(A.begin(), A.end(), cmp);
        int res = 0;
        int cur = 0;
        for (int i = 0; i < M; ++i) {
            if (A[i].first >= cur) {
                cur = A[i].second;
                ++res;
            }
        }
        cout << res << endl;
    }
}
 
 
 
 
 
 
 
 
 
 
 
 

Measured memory_bytes: 1024
n,m = map(int,input().split())
h = list(map(int,input().split()))


E = [[] for _ in range(n)]

#辺の定義
#辺E(u,v)の重みがw
for _ in range(m):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  E[a].append(b)
  E[b].append(a)

ans = 0
for i in range(n):
	if len(E[i]) == 0:
		ans += 1
	else:
		flag =True
		for j in range(len(E[i])):
			if h[i] <= h[E[i][j]]:
				flag = False
				break
		if flag:
			ans += 1
print(ans)


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

const int INF = 1e9;

int main(){
  int N; cin >> N;
  vector<vector<int>> to(N);
  for(int i = 0; i < N-1; i++){
    int a,b; cin>> a >> b; a--; b--; 
    to[a].push_back(b); to[b].push_back(a);}
  
  vector<int> C(N); for(int i = 0; i < N; i++){ cin >> C[i];}
  sort(C.rbegin(),C.rend());
  
  queue<int> Q; Q.push(0); vector<int> visited(N,INF);
  int itr = 0; 
  long long ans = 0;
  while(!Q.empty()){
    int p = Q.front(); Q.pop();
    visited[p] = C[itr]; itr++;
    for(int i = 0; i < (int) to[p].size(); i++){
      int q = to[p][i];
      if(visited[q] != INF){ continue;}
      Q.push(q);
    }
  }
  //１回目のBFSで書く頂点に値を振り分けていく
   
  queue<int> Q2; Q2.push(0);  vector<bool> vec(N,false); vec[0] = true;
  while( !Q2.empty()){
    int p = Q2.front(); Q2.pop();
    for(int j = 0; j < (int) to[p].size(); j++){
      int q = to[p][j];
      if(vec[q]){ continue;}
      vec[q] = true; Q2.push(q);
      ans += min( visited[p], visited[q]);}
  }
                 
  
  cout << ans << endl;
  for(int i = 0; i < N; i++){ cout << visited[i] << " ";}
  
  cout << endl;
  return 0;}

Measured memory_bytes: 1024
package main

import (
	"fmt"
	"math"
)

const INF = 1 << 30

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	h := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&h[i])
	}

	dp := make([]int, n)
	dp[0] = 0
	for i := 1; i < n; i++ {
		dp[i] = INF
	}

	for i := 0; i < n-1; i++ {
		for j := 1; j <= k; j++ {
			if i+j > n-1 {
				break
			}
			cost := dp[i] + abs(h[i]-h[i+j])
			if cost < dp[i+j] {
				dp[i+j] = cost
			}
		}
	}
	fmt.Println(dp[n-1])
}


Measured memory_bytes: 7424
import java.util.Scanner;

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

        int N = scanner.nextInt();

        int streak = 0;
        for (int i = 0; i < N; i++) {
            int a = scanner.nextInt();
            int b = scanner.nextInt();

            if (a == b) {
                streak++;
            } else {
                streak = 0;
            }

            if (streak == 3) {
                System.out.println("Yes");
                return;
            }
        }

        System.out.println("No");
    }
}

Measured memory_bytes: 27168
import java.util.*;
class Main
{
  public static void main(String[] args)
  {
    Scanner sc = new Scanner(System.in);
    
    int n = sc.nextInt();
    int a = sc.nextInt();
    
    int t = 0; //500円玉の個数
    
    
    for(int i=0 ; i<=40 ; i++){
      
      int total = n - 500*i;
      if(total<0){
      	t = i-1;
      	break;
      }else if(total==0){
      	System.out.println("Yes");
      	return;
      }
      }
     
      
      if( (n-500*t)<=a){
      	System.out.println("Yes");
      }else{
      	System.out.println("No");
      }
     }
    }

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

#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i<(ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<ll,bool> p;

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

ll H, W;
vector<p> pq;
int main(){
    ios::sync_with_stdio(false);
    cin >> W >> H;
    
    int t;
    REP(i, W) {
        cin >> t;
        pq.pb(p(t,0));
    }
    REP(i, H) {
        cin >> t;
        pq.pb(p(t,1));
    }
    
    sort(pq.begin(),pq.end());
    
    H++;W++;
    
    ll ans = 0;
    for (auto x: pq) {
        ll len = x.first;
        // 縦の線？
        if (x.second && W>0) {
            ans+=W*len;
            H--;
        }
        if (!x.second && H>0) {
            ans+=H*len;
            W--;
        }
        if(W <= 0 && H <= 0) break;
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 4464
x, k, d = map(int, input().split())

if x >= 0:
  tmp = x//d
  if tmp >= k:
    x = x-k*d
    print(x)
  else:
    x = x - tmp* d
    k = k -tmp
    if k%2 == 0:
      print(x)
    else:
      print(abs(x-d))
else:
  tmp = abs(x)//d
  if tmp >= k:
    x = x+k*d
    print(abs(x))
  else:
    x = x + tmp* d
    k = k - tmp
    if k%2 == 0:
      print(abs(x))
    else:
      print(abs(x+d))    

Measured memory_bytes: 9200
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>

using namespace std;

int main()
{
	string str;
	int z, i;

	cin >> str;

	z = str.size();


	for (i = 0; i <z ; i++)
	{
		if (i%2!= 1)
		{
			cout << str[i];
		}
	}
	cout << endl;
	return 0;
}

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

using namespace std;
using ll = long long;

const int N = 200005;

int main() {
	ll n;
	scanf("%lld", &n);
	ll ans = n;
	for(ll a = 1; a * a <= n; a++) if(n % a == 0) {
		ll b = n / a;
		ans = min(ans, a - 1 + b - 1);
	}
	printf("%lld\n", ans);
}


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

int main()
{
  long long int a,b,k;
  cin>>a>>b>>k;
  if(a>=k)
    {a-=k;k=0;}
  else
   {k-=a;a=0;}
  
  if(k>0)
    b-=k;
  if(b<0)
    b=0;
  cout<<a<<" "<<b<<"\n";
  
  
  
  
  return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;


public class Main {

    public static void main(String[] args) throws Exception {
        new Main().solve();
    }

    private void solve() throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        double[] rs = new double[n];
        for (int i = 0; i < n; i++) {
            rs[i] = sc.nextInt();
        }

        double[] pos = new double[n];
        pos[0] = rs[0];
        for (int i = 1; i < n; i++) {
            double minLeft = rs[i];
            for (int j = 0; j < i; j++) {
                double dl = 2 * Math.sqrt(rs[i] * rs[j]);
                // System.out.println("dl " + j + "," + i + " = " + dl);
                minLeft = Math.max(minLeft, pos[j] + dl);
            }
            pos[i] = minLeft;
        }
        // System.out.println(Arrays.toString(pos));
        double ans = 0;
        for (int i = 0; i < n; i++) {
            ans = Math.max(ans, pos[i] + rs[i]);
        }
        System.out.printf("%.8f%n", ans);
    }

}

Measured memory_bytes: 29016
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>

using namespace std;

typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;

int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};

static const double EPS = 1e-8;

class Card{
public:
	string color;
	int num;

	Card() : color(""),num(0){}
	bool operator<(const Card& c) const{
		if(color == c.color){
			return num < c.num;
		}
		return color < c.color;
	}
};

bool check441(const vector<Card>& cards){

	map<int,int> freq_num;
	map<string,int> freq_c;
	for(int i=0;i<cards.size();i++){
		freq_num[cards[i].num]++;
		freq_c[cards[i].color]++;
	}

	if(freq_c.size() > 1) return false;
	if(freq_num.size() != 3) return false;

	vector<int> freq;
	vector<int> ord;
	for(map<int,int>::iterator it = freq_num.begin(); it != freq_num.end(); it++){
		freq.push_back(it->second);
		ord.push_back(it->first);
	}
	sort(freq.begin(),freq.end());
	sort(ord.begin(),ord.end());

	if(freq[0] != 1 || freq[1] != 4 || freq[2] != 4) return false;
	if(!(ord[1] == ord[0]+1 
		&& ord[2] == ord[1] + 1)){
			return false;
	}

	return true;

}

int main(){
	int n;

	while(~scanf("%d",&n)){

		for(int idx=0;idx<n;idx++){
			vector<Card> cards;
			int num[10];
			for(int j=0;j<9;j++){
				scanf("%d",&num[j]);
			}

			string str;
			for(int j=0;j<9;j++){
				cin >> str;
				Card c;
				c.color = str;
				c.num = num[j];

				cards.push_back(c);
			}

			sort(cards.begin(),cards.end());

			bool fail = false;

			for(int i=0;i<9;){
				int prev_num = cards[i].num;
				string prev_c = cards[i].color;

				bool isok = true;

				isok = check441(cards);

				if(isok){
					i+=9;
					continue;
				}

				isok = true;

				//3つ連続
				for(int j=0;j<2;j++){			
					if(cards[i+j+1].num == prev_num
						&& cards[i+j+1].color == prev_c){

					}
					else{
						isok = false;
						break;
					}
					prev_num = cards[i+j+1].num;
					prev_c = cards[i+j+1].color;

				}

				if(isok) {
					i+=3;
					continue;
				}

				isok = true;

				//昇順
				for(int j=0;j<2;j++){
					if(cards[i+j+1].num == prev_num + 1
						&& cards[i+j+1].color == prev_c){

					}
					else{
						isok = false;
						break;
					}

					prev_num = cards[i+j+1].num;
					prev_c = cards[i+j+1].color;
				}

				if(isok){
					i+=3;
					continue;
				}

				isok = true;

				if(i+6 >= 9){
					fail = true;
					break;
				}

				//七対子			
				for(int j=0;j<6;j+=2){
					if(cards[i+j].color == cards[i+j+1].color
						&& cards[i+j].num == cards[i+j+1].num){

					}
					else{
						isok = false;
					}
				}

				if(isok){
					i+=6;
					continue;
				}

				fail = true;
				break;
			}

			printf("%d\n",fail ? 0 : 1);
		}

	}
}

Measured memory_bytes: 1244
import array
import collections
import heapq
 
 
AdjacentVertex = collections.namedtuple("AdjacentVertex", "vertex cost")
INF = 2 ** 31 - 1
NO_VERTEX = -1
 
 
# Prim法で頂点0からの最小全域木を求める
def compute_mst_prim(max_v, adj_list):
    # pred[u]は頂点uの「ひとつ前」の頂点を表す
    pred = collections.defaultdict(lambda: NO_VERTEX)
    # uとpred[u]を結ぶ辺の重みがkey[u]に入る
    key = collections.defaultdict(lambda: INF)
    key[0] = 0
    # 二分ヒープを優先度付きキューとして用いる
    pq = [(key[v], v) for v in range(max_v)]
    heapq.heapify(pq)
    # 優先度付きキューに頂点が入っているかを示す配列
    in_pq = array.array("B", (True for _ in range(max_v)))
    while pq:
        _, u = heapq.heappop(pq)
        in_pq[u] = False
        for v, v_cost in adj_list[u]:
            if in_pq[v]:
                weight = v_cost
                if weight < key[v]:
                    pred[v] = u
                    key[v] = weight
                    heapq.heappush(pq, (weight, v))
                    in_pq[v] = True
    return (pred, key)
 
 
def main():
    max_v, max_e = map(int, input().split())
    adjacency_list = collections.defaultdict(set)
    for _ in range(max_e):
        s, t, w = map(int, input().split())
        adjacency_list[s].add(AdjacentVertex(t, w))
        adjacency_list[t].add(AdjacentVertex(s, w))
    (_, key) = compute_mst_prim(max_v, adjacency_list)
    print(sum(key.values()))
 
 
if __name__ == '__main__':
    main()


Measured memory_bytes: 50268
#include<bits/stdc++.h>
using namespace std;
int main(){
    vector<int>vec(10000);
    for(int i=0;i<10000;i++){
        cin>>vec.at(i);
        if(vec.at(i)==0){
            break;
        }
        else{cout<<"Case "<<i+1<<": "<<vec.at(i)<<endl;
        
    }
    }
}


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

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

    int ball[200000]={0};
    vector<int> b;
    for(int i=n; i>=1; i--){
        int r=0;
        for(int j=i*2; j<=n; j+=i) r=(r+ball[j-1])%2;
        if(a[i-1]!=r){
            ball[i-1]=1;
            b.push_back(i);
        }
    }

    cout<<b.size()<<endl;
    if(b.size()==0) return 0;
    bool first=true;
    for(auto it=b.begin(); it!=b.end(); it++){
        if(first) first=false;
        else cout<<" ";
        cout<<*it;
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 3192
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); 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 FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define DEBUG2(x, y) cerr << #x << ": " << x << " " << #y << ": " << y << "\n"
#define DEBUG3(x, y, z)                                                        \
  cerr << #x << ": " << x << " " << #y << ": " << y << " " << #z << ": " << z  \
       << "\n"
#define PRINTALL(V)                                                            \
  for (auto v : (V)) {                                                         \
    cerr << v << " ";                                                          \
  }                                                                            \
  cerr << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
#define pint pair< int, int >
#define ld long double
using namespace std;
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;
}
template < class T > using vec = std::vector< T >;
template < class T > void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567, INF2 = INF * INF;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int N, K;
  cin >> N >> K;
  vec< int > p(N);
  REP(i, N) cin >> p[i];
  if (N == K) {
    print(1);
    return 0;
  }
  vec< bool > e(N - 1);
  REP(i, N - 1) { e[i] = p[i] < p[i + 1]; }
  int cnt = 0;
  int val = 0;
  vec< bool > flg2(N - K + 1, false);
  REP(i, K - 1) val += e[i];
  REP(i, N - K + 1) {
    if (val == K - 1) {
      flg2[i] = true;
      cnt++;
    }
    val -= e[i];
    val += e[i + K - 1];
  }
  //  DEBUG(cnt);

  int ans = 1;
  int sameG = flg2[0];
  set< int > g;
  REP(j, K + 1) g.insert(p[j]);
  REP(i, N - K) {
    //    REP(j, K + 1) g.insert(p[i + j]);
    while (1) {
      int minV = *g.begin();
      int maxV = *g.rbegin();
      // DEBUG(minV);
      // DEBUG(maxV);
      bool ok = p[i] == minV && p[i + K] == maxV;
      if (!ok) {
        if (flg2[i + 1]) {
          sameG++;
        }
        g.erase(p[i]);
        g.insert(p[i + K + 1]);
        ans++;
        break;
      }
      if (i == N - K - 1) {
        break;
      }
      i++;
      g.erase(minV);
      g.insert(p[i + K]);
    }
  }
  // DEBUG(sameG);

  print(ans - max(0ll, sameG - 1));
}

Measured memory_bytes: 11136
#include <iostream>
#include <vector>
#define rep(i, n)for(int i=0; i<n; i++)
using ll = long long int;
using namespace std;

int main(int argc, char const *argv[])
{
    int n, k;
    cin >> n >> k;
    vector<int> money(n); 
    rep(i, n) cin >> money[i];

    rep(i, n-1){
        for(int j=i+1; j<n; j++) {
            if(money[i]>money[j]){
                int tmp = money[i];
                money[i] = money[j];
                money[j] = tmp;
            }
        }
    }

    int ans = 0;
    rep(i, k) ans += money[i];
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3596
n, m = map(int, input().split())
A = [int(input()) for i in range(m)]
mod = 1000000007

A = set(A)

dp = [0]*(n+1)
dp[0] = 1

for i in range(n):
    if i in A:
        continue
    if i+1 <= n and i+1 not in A:
        dp[i+1] += dp[i]
        dp[i+1] %= mod
    if i+2 <= n and i+2 not in A:
        dp[i+2] += dp[i]
        dp[i+2] %= mod
#print(dp)
print(dp[-1]%mod)


Measured memory_bytes: 56664
#include<bits/stdc++.h>
#define pb push_back
#define mk make_pair
#define ll long long
#define vi vector<ll>
#define ss second
#define ff first
#define pii pair<int,int>
#define mii map<int,int>
#define mod 1000000007
#define w(x) int x; cin>>x; while(x--)
#define ps(x,y) fixed<<setprecision(y)<<x;
#define fo(i, j, k, in) for (ll i=j ; i<k ; i+=in)
#define re(i, j) fo(i, 0, j, 1)
#define pi 3.1415926535897932384626433832795
#define all(cont) cont.begin(), cont.end()
#define countbit(x) __builtin_popcount(x)
#define mod 1000000007
#define lo lower_bound
#define de(n) ll n;cin>>n;
using namespace std;
ll ab(ll a,ll b)
{
    if(a>b)
    return a-b;
return b-a;
}
ll factor(ll n)
{
    ll ans=0;
    for(ll j=1;j*j<=n;j++)
    {
        if(n%j==0)
        {
            if(j*j==n)
            ans++;
            else
            {
                ans+=2;
            }
        }
    }
    return ans;
}
ll power(ll x, ll y,ll p)  
{  
    int res = 1;
    x = x % p; 
    if (x == 0) return 0;
    while (y > 0)  
    {   
        if (y & 1)  
            res = (res*x) % p;  
   
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}
ll pow(ll x,ll y) 
{ 
    int res = 1; 
   
    while (y > 0) 
    { 
        if (y & 1) 
            res = res*x; 
   
        y = y>>1; 
        x = x*x;   
    } 
    return res; 
}
void cp()
{
    ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); 
    #ifndef ONLINE_JUDGE  
    freopen("input.txt", "r", stdin);  
    freopen("output.txt", "w", stdout); 
  
#endif
}
vector<ll> get_prime_factors_less_than(ll n){
    vector<ll> factor;
    vector<ll> prime(n,1);
    prime[0]=0,prime[1]=0;
    for(ll i = 2 ; i <= n ; i++){
        if(prime[i]==1){
            for(ll j=i*i;j<=n;j=j+i) prime[j]=0; 
            factor.push_back(i);
        }
    }
    return factor;
}
ll digit(ll n)
{
    ll q=0;
    while(n>0)
    {
        q++;
        n/=10;
    }
    return q; 
}
ll sq(ll n)
{
    return n*n;
}
ll NR(ll n, ll r) 
{ 
    long long p = 1, k = 1; 
    if (n - r < r) 
        r = n - r; 
  
    if (r != 0) { 
        while (r) { 
            p *= n; 
            k *= r; 
  
            // gcd of p, k 
            long long m = __gcd(p, k); 
            p /= m; 
            k /= m; 
  
            n--; 
            r--; 
        } 
    } 
  
    else
        p = 1; 
  
    // if our approach is correct p = ans and k =1 
    return p ;
}
int main() 
{
    cp();
    de(n);
    string s;
    cin>>s;
    if(s.length()>n)
    {
        re(i,n)
        cout<<s.at(i);
        cout<<"...";
    }
    else
    {
        cout<<s;
    }
    
    return 0;
}

Measured memory_bytes: 3652
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

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

int main() {
    int N; cin >> N;
    int A[N]; REP(0, i, N) cin >> A[i];
    int B[N]; REP(0, i, N) B[i] = A[i];
    sort(B, B + N, greater<int>());
    REP(0, i, N) {
        if (A[i] == B[0]) cout << B[1] << endl;
        else cout << B[0] << endl;
    }
    return 0;
}


Measured memory_bytes: 3200
from collections import Counter

a = input()
a = map(int,input().split())
a = Counter(a)
li = []
for i,v in sorted(a.items(),key = lambda x: x[0],reverse = True):
    if(v >= 2 and v < 4):
        li.append(i)
    elif(v >= 4):
        li.extend([i,i])
    if(len(li) >= 2):
        print(li[0]*li[1])
        exit()
print(0)

Measured memory_bytes: 24104
import java.io.*;
import java.util.*;

public class Main{
	public static void main(String args[]){
		try{
			new Main();
		}catch(IOException err){
			err.printStackTrace();
		}
	}

	public Main() throws IOException{
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		List<Integer> Ans = new ArrayList<Integer>();
		String line;
		String c;
		String[] num1, num2, num3;
		int n1, n2, n3;

		while((line = in.readLine()) != null){
			if(line.length() == 0){
				break;
			}

			if(!line.contains("X")){
				Ans.add(-1);
				continue;
			}

			n1 = 0;
			n2 = 0;
			n3 = 0;
			String[] dst = line.split("\\+");
			n1 = dst[0].length();
			dst = dst[1].split("=");
			n2 = dst[0].length();
			n3 = dst[1].length();

			num1 = new String[n1];
			num2 = new String[n2];
			num3 = new String[n3];

			for(int i=0; i<line.length(); i++){

				if(i < n1){
					num1[n1-i-1] = line.substring(i, i+1);
				}

				else if(i >= n1+1 && i< n1+n2+1){
					num2[n2-i+n1] = line.substring(i, i+1);
				}

				else if(i>=n1+n2+2){
					num3[n3-i+n1+n2+1] = line.substring(i, i+1);
				}
			}

			for(int i=0; i<=9; i++){
				if(isOK(num1, num2, num3, i)){
					Ans.add(i);
					break;
				}

				if(i==9){
					Ans.add(-1);
				}
			}
		}

		for(int i=0; i<Ans.size(); i++){
			if(Ans.get(i) == -1){
				System.out.println("NA");
			}
			else{
				System.out.println(Ans.get(i));
			}
		}
	}

	public boolean isOK(String[] num1, String[] num2, String[] num3, int x){
		int a, b, c;
		int d = 0;
		int e = 0;
		if(x==0 && (
				(num1[num1.length-1].equals("X") && num1.length != 1) ||
				(num2[num2.length-1].equals("X") && num2.length != 1) ||
				(num3[num3.length-1].equals("X") && num3.length != 1) )){
			return false;
		}

		while(true){
			if(d >= num1.length) a = 0;
			else a = (num1[d].equals("X")) ? x : Integer.parseInt(num1[d]);
			if(d >= num2.length) b = 0;
			else b = (num2[d].equals("X")) ? x : Integer.parseInt(num2[d]);
			if(d >= num3.length) c = 0;
			else c = (num3[d].equals("X")) ? x : Integer.parseInt(num3[d]);

			if(d >= num1.length && d >= num2.length && d >= num3.length) break;

			if((a+b+e)%10 != c){
				//System.out.println(Integer.toString(a) + " : " + Integer.toString(b) + " : " + Integer.toString(e) + " : " + Integer.toString(c));
				return false;
			}
			else{
				e = (a+b+e) / 10;
				d++;
			}
		}

		return true;
	}
}

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

template<typename T> T calc(T h,T w){ return (h+1)*(w+1); }
template<typename T> T LargestRectangle(vector<T>& v)
{
   int N=v.size();
   vector<int> l(N),r(N);
   stack<int> S;
   for(int i=0;i<N;i++){
      while(!S.empty() and v[S.top()]>=v[i]) S.pop();
      l[i]=(S.empty()? 0:S.top()+1); S.push(i);
   }
   S=stack<int>();
   for(int i=N-1;i>=0;i--){
      while(!S.empty() and v[S.top()]>=v[i]) S.pop();
      r[i]=(S.empty()? N:S.top()); S.push(i);
   }
   T res=0;
   for(int i=0;i<N;i++) res=max(res,calc(v[i],r[i]-l[i]));
   return res;
}

int main()
{
   int H,W; cin>>H>>W;
   vector<string> s(H);
   for(int i=0;i<H;i++) cin>>s[i];

   int ans=max(H,W);
   vector<int> cnt(W-1);
   for(int i=0;i<H-1;i++){
      for(int j=0;j<W-1;j++){
         int parity=0;
         for(int dy=0;dy<2;dy++) for(int dx=0;dx<2;dx++) if(s[i+dy][j+dx]=='#') parity^=1;
         if(parity) cnt[j]=0; else cnt[j]++;
      }
      ans=max(ans,LargestRectangle(cnt));
   }
   cout<<ans<<endl;
   return 0;
}


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

int main(){
  string s;
  cin>>s;
  for(int i=0;i<3;++i){
    if(s[i]=='1'){
      s[i]='9';
    }else{
      s[i]='1';
    }
  }
  cout<<s<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {

	int k, sum = 0, a, b, c, x, y, r;

	scanf("%d", &k);

	for (a = 1; a <= k; a++)
		for (b = 1; b <= k; b++)
			for (c = 1; c <= k; c++) {

				if (a>b) {
					x = a;
					y = b;
				}
				else {
					x = b;
					y = a;
				}

				r = x % y;
				while (r != 0) {
					x = y;
					y = r;
					r = x % y;
				}

				if (y>c) {
					x = y;
					y = c;
				}
				else {
					x = c;
				}

				r = x % y;
				while (r != 0) {
					x = y;
					y = r;
					r = x % y;
				}
				sum += y;
			}
	printf("%d", sum);

	return 0;
}

Measured memory_bytes: 1736
'use strict';
(function(stdin) {
  var lines  = stdin.toString().split('\n');
  var result = (function(data) {
  	var result = [];
  	var index = 0;
  	while(true) {
  		var cols = data[index++].split(' ').map(Number);
  		if (cols.every(function(v){
  			return v === 0;
  		})) break;

  		result.push(cols.sort(function(a,b){
  			return a - b;
  		}).join(' '));
  	}
  	return result.join('\n');
  }(lines
  ));
  console.log(result);
}(require('fs').readFileSync('/dev/stdin', 'utf8')));

Measured memory_bytes: 11084
#include <cstdio>
#include <cstdint>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <utility>
#include <tuple>

template <class Tp>
Tp& amax(Tp& dst, const Tp& src) {
  if (dst < src) dst = src;
  return dst;
}

int main() {
  size_t N, K;
  scanf("%zu %zu", &N, &K);

  using sushi = std::pair<intmax_t, intmax_t>;

  std::priority_queue<sushi> q;
  for (size_t i = 0; i < N; ++i) {
    intmax_t t, d;
    scanf("%jd %jd", &t, &d);
    q.emplace(d, t);
  }

  constexpr intmax_t inf = 1e14;
  std::vector<intmax_t> f(N+1, -inf);
  std::priority_queue<sushi> s;
  std::map<intmax_t, intmax_t> count;
  intmax_t cur = 0;
  for (size_t i = 0; i < K; ++i) {
    intmax_t t, d;
    std::tie(d, t) = q.top();
    q.pop();
    ++count[t];
    cur += d;
    s.emplace(-d, t);
  }

  f[count.size()] = cur;

  while (!q.empty()) {
    while (!s.empty()) {
      intmax_t t, d;
      std::tie(d, t) = s.top();
      d = -d;
      s.pop();
      if (count[t] > 1) {
        --count[t];
        cur -= d;
        break;
      }
    }
    if (s.empty()) break;

    while (!q.empty()) {
      intmax_t t, d;
      std::tie(d, t) = q.top();
      q.pop();
      if (count.find(t) != count.end()) continue;
      count[t] = 1;
      cur += d;
      s.emplace(-d, t);
      break;
    }

    amax(f[count.size()], cur);
  }

  intmax_t res = 0;
  for (size_t i = 1; i <= N; ++i)
    res = amax<intmax_t>(res, f[i]+i*i);

  printf("%jd\n", res);
}


Measured memory_bytes: 8048
#include <bits/stdc++.h>
#define mem(dp,a) memset(dp,a,sizeof(dp))
#define HRX 1e18
#define INF 1000000007
#define pb(x) push_back(x)
#define m_p(x,y) make_pair(x,y)
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repush_back(i,a,b) for(ll i=a;i>=b;i--)
#define f(n) for(ll i=0;i<n;i++)
#define r(n) for(ll j=0;j<n;j++)
#define hs ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
typedef long long int ll;

int main()
{
  hs;
  string s;
  cin>>s;
  ll cnt[26];
  mem(cnt,0);
  f(s.length())
  {
    cnt[s[i]-'A']++;
  }
  ll ans=0;
  f(26)
  {
    if(cnt[i]==2)
        ans++;
  }
  if(ans==2)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		int t = sc.nextInt();
		
		System.out.println((t/a)*b);
		
	}
}


Measured memory_bytes: 23124
#include<cstdio>
#include<algorithm>

using namespace std;

typedef long long ll;
typedef pair<ll, int> P;

struct edge{ int u, v; ll cost; };

bool cmp(const edge& e1, const edge& e2){
	return e1.cost < e2.cost;
}

int p[100000], r[100000];

int find(int x){
	if(p[x] == x) return x;
	return p[x] = find(p[x]);
}

void unite(int x, int y){
	x = find(x); y = find(y);
	if(x == y) return;
	if(r[x] < r[y]) p[x] = y;
	else{
		p[y] = x;
		if(r[x] == r[y]) r[x]++;
	}
}

bool same(int x, int y){
	return find(x) == find(y);
}

int n;
P xs[100000], ys[100000];
edge es[200000];

int main(){
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		ll x, y; scanf("%lld %lld", &x, &y);
		xs[i] = P(x, i); ys[i] = P(y, i);
		p[i] = i;
	}
	sort(xs, xs + n); sort(ys, ys + n);
	for(int i = 0; i < n - 1; i++){
		es[2 * i] = (edge){xs[i].second, xs[i + 1].second, xs[i + 1].first - xs[i].first};
		es[2 * i + 1] = (edge){ys[i].second, ys[i + 1].second, ys[i + 1].first - ys[i].first};
	}
	sort(es, es + 2 * (n - 1), cmp);
	ll res = 0;
	for(int i = 0; i < 2 * (n - 1); i++){
		if(!same(es[i].u, es[i].v)){
			unite(es[i].u, es[i].v);
			res += es[i].cost;
		}
	}
	printf("%lld\n", res);
	return 0;
}

Measured memory_bytes: 7296
#include <stdio.h>
#include <stdlib.h>


int main()
{
  int n,  q ,C=0,i,j;

  scanf("%d",&n);
  int S[n];
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  int T[q];
  for(i=0;i<q;i++){
    scanf("%d",&T[i]);
  }
  

    for(i=0;i<q;i++){
      for(j=0;j<n;j++){
	
	if(S[j]==T[i]){
	  C++;
	  break;
	}
	
      }
    }


  
  printf("%d\n",C);

  return 0;
}


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

typedef long long ll;

int main()
{
  ll n, a[300000];

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

  sort(a, a+n*3);

  ll ans = 0;
  for(int i = 3*n-2; i >= n; i -= 2){
    ans += a[i];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2560
#include <stdio.h>
int main(void){
    // Your code here!
    int n;
    scanf("%d",&n);
    double nn=0;
    nn=(double)n;
    
    int w;
    w=nn/1.08;
    
    if((int)((double)w*1.08)==n){
        printf("%d\n",w);
    }else if((int)((double)(w+1)*1.08)==n){
        printf("%d\n",w+1);
    }else{
        printf(":(\n");
    }
}

Measured memory_bytes: 1728
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<iomanip>
#include<utility>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<map>
#include<string>
#include<cctype>
#include<cmath>
using namespace std;
int main()
{
	int  a,b;
	char s;
	cin >> a >> s >> b;
	if(s=='+')
	{
		cout << a+b;
	} 
	if(s=='-')
	{
		cout << a-b;
	} 
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define X real()
#define Y imag()
using namespace std;
typedef long long ll;
typedef long double ld;

int a[101010];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	for (int i=0;i<n;i++){
		cin>>a[i];
	}
	int mi=n;
	int ma=0;
	for (int i=0;i<n;i++){
		mi=min(mi, a[i]);
		ma=max(ma, a[i]);
	}
	if (mi==ma){
		if (mi==n-1){
			cout<<"Yes"<<endl;
		}
		else{
			if (mi*2<=n){
				cout<<"Yes"<<endl;
			}
			else{
				cout<<"No"<<endl;
			}
		}
		return 0;
	}
	if (ma-mi!=1){
		cout<<"No"<<endl;
		return 0;
	}
	int uq=0;
	for (int i=0;i<n;i++){
		if (a[i]==mi) uq++;
	}
	int nuq=ma-uq;
	if (nuq<1){
		cout<<"No"<<endl;
		return 0;
	}
	if (nuq*2+uq<=n){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
}

Measured memory_bytes: 640
import java.util.*;
import java.lang.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		String S = sc.next();
		int Q = sc.nextInt();
		String[] front = new String[Q];
		String[] back = new String[Q];
		for( int i=0; i<Q; i++ ){
			front[i] = "A";
			back[i] = "A";
		}
		int F = 0,B = 0;
		int count = 0;
		for( int i=0; i<Q; i++ ){
			int a = sc.nextInt();
			if( a==1 ){
				count++;
			}
			if( a==2 ){
				int b = sc.nextInt();
				String ss = sc.next();
				if( b==1 ){
					if( count%2==0 ){
						front[F] = ss;
						F++;
					}else{
						back[B] = ss;
						B++;
					}
				}
				if( b==2 ){
					if( count%2==0 ){
						back[B] = ss;
						B++;
					}else{
						front[F] = ss;
						F++;
					}
				}
			}
		}
		if( count%2!=0 ){
			StringBuffer sb = new StringBuffer(S);
			String STR = sb.reverse().toString();
			for( int i=B-1; i>=0; i-- ){
				System.out.print(back[i]);
			}
			System.out.print(STR);
			for( int i=0; i<F; i++ ){
				System.out.print(front[i]);
			}
		}else{
			for( int i=F-1; i>=0; i-- ){
				System.out.print(front[i]);
			}
			System.out.print(S);
			for( int i=0; i<B; i++ ){
				System.out.print(back[i]);
			}
		}
	}
}


Measured memory_bytes: 168780