akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

struct UnionFind {
  vector<int> par;
  vector<int> rank;
  vector<ll> Size;
  UnionFind(int n = 1) { init(n); }

  void init(int n = 1) {
    par.resize(n + 1);
    rank.resize(n + 1);
    Size.resize(n + 1);
    for (int i = 0; i <= n; ++i)
      par[i] = i, rank[i] = 0, Size[i] = 1;
  }

  int root(int x) {
    if (par[x] == x) {
      return x;
    } else {
      int r = root(par[x]);
      return par[x] = r;
    }
  }

  bool is_same(int x, int y) { return root(x) == root(y); }

  bool merge(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y)
      return false;
    if (rank[x] < rank[y])
      swap(x, y);
    if (rank[x] == rank[y])
      ++rank[x];
    par[y] = x;
    Size[x] += Size[y];
    return true;
  }

  ll size(int x) { return Size[root(x)]; }
};

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

  int n, m;
  cin >> n >> m;

  UnionFind uf(n);
  rep(i, 0, m) {
    int x, y, z;
    cin >> x >> y >> z;
    x--, y--;
    uf.merge(x, y);
  }

  set<int> groups;
  rep(i, 0, n) { groups.insert(uf.root(i)); }

  cout << (int)groups.size() << endl;
}


Measured memory_bytes: 9476
(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());
  const arr = lines.shift().split(' ');
  buildMaxHeap(arr);
  console.log(arr.reduce((s, e) => s += ' ' + e, ''));
})();

function buildMaxHeap(arr) {
  const n = arr.length;
  const maxHeapify = (i) => {
    let left, right, largest = i;
    left = 2 * i + 1;
    right = 2 * i + 2;
    if (left < n && Number(arr[left]) > Number(arr[i])) largest = left;
    if (right < n && Number(arr[right]) > Number(arr[largest])) largest = right;
    if (largest != i) {
      arr[largest] = [arr[i], arr[i] = arr[largest]][0];
      maxHeapify(largest);
    }
  };

  for (let i = Math.floor(n / 2 - 1); i >= 0; i--) maxHeapify(i);
}



Measured memory_bytes: 110524
//Xcode main は一つまで
//競プロのデバッグにでも使おう
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int N,T;
    //cout<<12<<endl;
    cin>>N>>T;
    int c[N],t[N];
    for(int rr=0;rr<N;rr++) cin>>c[rr]>>t[rr];
    int ansmin=100000;
    for(int i=0;i<N;i++){
        if(t[i]<=T) ansmin=min(ansmin,c[i]);}
    if(ansmin>=100000) cout<<"TLE"<<endl;
    else
    cout<<ansmin<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define llu unsigned long long
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
using namespace std;
const int MAX = 1e5 + 10;
const int mod = 1e9;
int N, M, Q, K;
vector<int> vec[2];
int dp[16100][4010], dest[2];
bool dflag[2];

int rec(int pos, int vi, int init, int dir){
    if(vi >= vec[dir].size()){
        if(pos == dest[dir]) dflag[dir] = true;
        return 1;
    }
    int &ret = dp[pos][vi];
    if(ret != -1) return 1;
    ret = 1;

    rec(pos + vec[dir][vi], vi + 1, 0, dir);
    if(dflag[dir]) return 1;
    if(!init) rec(pos - vec[dir][vi], vi + 1, 0, dir);
    return 1;
}

int main()
{
    int i, j, k;
    string s;
    cin >> s >> dest[0] >> dest[1];

    int pos = 0;
    int dir = 0;
    int n= s.size();

    while(pos < n){
        int cnt = 0;
        while(pos < n && s[pos] == 'F') {cnt++; pos++;}
        vec[dir].push_back(cnt);
        pos++;
        dir = !dir;
    }

    dest[0] += 8000; dest[1]+= 8000;
    memset(dp, -1, sizeof(dp));
    rec(8000, 0, 1, 0);
    if(!dflag[0]){
        printf("No\n");
        return 0;
    }
    memset(dp, -1, sizeof(dp));
    rec(8000, 0, 0, 1);
    if(!dflag[1]){
        printf("No\n");
        return 0;
    }
    printf("Yes\n");
}


Measured memory_bytes: 252800
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;

int main()
{
	int N, A, B;
	cin >> N >> A >> B;
	cout << min(A * N, B) << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <string>
#include<limits>
#include<cstdlib>
#include<functional>
#include<cassert>
#include <cstdio>
#include <stack>
#include <queue>
#define fi(p) for(int i=0;i<(p);i++)
using namespace std;
int N;
int L;
int P;
const int MAX_N = 100000;
const int MAX_W = 100000;


int A[MAX_N+1];
int B[MAX_N+1];

void solve() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int x = c - a;
	int y = d - b;
	int x3, y3, x4, y4;
	x3 = c - y;
	y3 = d + x;
	x4 = a - y;
	y4 = b + x;
	printf("%d %d %d %d\n", x3, y3, x4, y4);
	
	
}

int main()
{
	solve();

	int a;//止める用
	cin >> a;
	return 0;
}

Measured memory_bytes: 256
S = input()
s = [int(S[i:i + 1]) for i in range(len(S))]
ans = 0
v1 = s[0]
index = []
index.append(0)
for i in range(1, len(s)):
    if v1 != s[i] and len(index) != 0:
        ans += 2
        index.pop(-1)
        if len(index) != 0:
            v1 = s[index[-1]]
        else:
            v1 = 10
    else:
        index.append(i)
        v1 = s[i]
print(ans)


Measured memory_bytes: 7924
#include <stdio.h>
#include <math.h>
#include <iostream>

int main(void)
{
	using namespace std;

	double r;
	cin >> r;

	double area = r * r * M_PI;
	double circum = 2.0 * r * M_PI;

	printf("%lf %lf\n",area,circum);
	//cout << d << " " << r << " " << f << endl;

	return 0;

}

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

int main(){
	int a, m, n, ans = 0;

	cin >> m >> n;
	for(int i=0 ; i<m ; i++){
		int b = 0;
		for(int j=0 ; j<n ; j++ ){
			cin >> a;
			b += a;
		}
		ans = max( ans , b );
	}
	cout << ans << endl;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <string>

using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)

struct Node {
	ll n = -1;
	Node *next, *prev;
};
Node* nil = new Node();

int main() {
	ll N; cin >> N;
	nil->next = nil;
	nil->prev = nil;
	rep(i, 0, N) {
		ll a; cin >> a;
		Node* node = new Node();
		node->n = a;

		if (i % 2 == 0) {
			nil->prev->next = node;
			node->prev = nil->prev;
			nil->prev = node;
			node->next = nil;
		}
		else {
			nil->next->prev = node;
			node->next = nil->next;
			nil->next = node;
			node->prev = nil;
		}
	}

	if (N % 2 == 0) {
		Node *n = nil->next;
		while (n != nil) {
			cout << n->n;
			n = n->next;
			if (n != nil) {
				cout << " ";
			}
		}
	}
	else {
		Node *n = nil->prev;
		while (n != nil) {
			cout << n->n;
			n = n->prev;
			if (n != nil) {
				cout << " ";
			}
		}
	}
	cout << endl;

	return 0;
}

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

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

		String strText = input.readLine();
		StringBuffer sb = new StringBuffer();

		for (int index = 0; index < strText.length(); index++) {
			// 小文字の場合
			if(Character.isLowerCase(strText.charAt(index))) {
				sb.append(Character.toUpperCase(strText.charAt(index)));
			// 大文字の場合
			} else if (Character.isUpperCase(strText.charAt(index))) {
				sb.append(Character.toLowerCase(strText.charAt(index)));
			} else {
				sb.append(strText.charAt(index));
			}
		}
		System.out.println(sb.toString());
	}

}



Measured memory_bytes: 24264
#include<stdio.h>
#define MAX 100000

int parent[MAX], left[MAX], right[MAX];
int n, D[MAX];

int getDepth(int u);

void setDepth(int u, int p);

void printChildren(int u);

int main(){
  int i, j, a, b, c, l, r;
  scanf("%d", &n);
  for(i = 0 ; i < n ; i++)
    parent[i] = left[i] = right[i] = -1;
  for( i = 0 ; i < n ; i++){
    scanf("%d", &b);
    scanf("%d", &a);
    for( j = 0 ; j < a ; j++){
      scanf("%d", &c);
      if( j == 0 ) left[b] = c;
      else right[l] = c;
      l = c;
      parent[c] = b;
    }
  }
  for(i = 0; i < n; i++){
    if(parent[i] == -1) r = i;
  }

  setDepth(r, 0);

  for(i = 0; i < n; i++) printChildren(i);

  return 0;
}

int getDepth(int u){
  int a = 0;
  while(parent[u] != -1){
    u = parent[u];
    a++;
  }
  return a;
}

void setDepth(int u, int p){
  D[u] = p;
  if(right[u] != -1){
    setDepth(right[u], p);
  }
  if(left[u] != -1){
    setDepth(left[u], p+1);
  }
}

void printChildren(int u){

  int i, c;

  printf("node %d: ", u);
  printf("parent = %d, ", parent[u]);
  printf("depth = %d, ", getDepth(u));

  if(parent[u] == -1) printf("root, ");
  else if(left[u] == -1) printf("leaf, ");
  else printf("internal node, ");

  printf("[");
  c = left[u];
 for(i = 0; c != -1; i++, c = right[c]){

    if(i) printf(", ");
    printf("%d", c);
  }


  printf("]\n");
}




Measured memory_bytes: 6376
module DirectedGraph
  (* 道の表現 *)
  (Path : sig
    type t
    (* 辺の名前 *)
    type edge
    (* 長さ0の道 *)
    val nil : t
    (* 道の後ろに辺を付け足した道 *)
    val snoc : t -> edge -> t
  end) :
sig
  (* BFSにより，重みのないグラフの最短経路を求める *)
  val bfs :
    (* 頂点数（Hashtblを用いるので目安程度） *)
    int ->
    (* 辺の名前が付いた隣接リスト *)
    ('v -> ('v * Path.edge) list) ->
    (* 始点 *)
    'v ->
    (* 最短経路を返す関数 辿り着けなければNoneを返す） *)
    ('v -> Path.t option)
end = struct
  let rec bfs_aux es d frontier t =
    try Some (Hashtbl.find d t) with
    | Not_found ->
        match !frontier with
        | [] -> None
        | _ :: _ ->
            frontier := List.fold_right (fun u ->
              List.fold_right (fun (v, e) frontier ->
                if Hashtbl.mem d v
                then frontier
                else (Hashtbl.add d v (Path.snoc (Hashtbl.find d u) e); v :: frontier))
              (es u)) !frontier [];
            bfs_aux es d frontier t

  (*
   * 終点に辿り着いた時点で探索を切り上げるが，
   * 戻り値の関数を覚えておくと，途中まで探索した結果が再利用される
   * （#trace bfs_aux すると分かりやすい）
   *)
  let bfs n es s =
    let d = Hashtbl.create n in
    Hashtbl.add d s Path.nil;
    let frontier = ref [s] in
    bfs_aux es d frontier
end

(* 距離だけ欲しい場合 *)
module G = DirectedGraph (struct
  type t = int
  type edge = unit
  let nil = 0
  let snoc t _ = t + 1
end)

let () = Scanf.scanf "%d %d %d" @@ fun n x y ->
  let es v =
    (if v = x - 1 then [(y - 1, ())] else []) @
    (if v = y - 1 then [(x - 1, ())] else []) @
    (if v = n - 1 then [] else [(v + 1, ())]) @
    (if v = 0 then [] else [(v - 1, ())]) in
  let ans = Array.make n 0 in
  for u = 0 to n - 1 do
    let d = G.bfs n es u in
    for v = u + 1 to n - 1 do
      match d v with
      | None -> ()
      | Some d -> ans.(d) <- ans.(d) + 1
    done
  done;
  for i = 1 to n - 1 do
    Printf.printf "%d\n" ans.(i)
  done

Measured memory_bytes: 6016
#include<iostream>
#include<string>
#include<queue>
using namespace std;

int main() {
  int H, W; cin >> H >> W;
  int CH, CW, DH, DW;
  cin >> CH >> CW >> DH >> DW;
  CH--; CW--; DH--; DW--;
  bool S[H*W];
  for (int i = 0; i < H; i++) {
    string s; cin >> s;
    for (int j = 0; j < W; j++) {
      S[i+H*j] = (s[j] == '.');
    }
  }
  deque<pair<int, int>> Q; Q.push_back(make_pair(CH+H*CW, 0));
  bool visited[H*W]; for (int i = 0; i < H*W; i++) visited[i] = false;
  int min_count = -1;
  while (!Q.empty()) {
    pair<int, int> U = Q.front(); Q.pop_front();
    int u = U.first;
    if (!visited[u]) {
      visited[u] = true;
      if (u == DH+H*DW) { min_count = U.second; break; }
      vector<pair<int, int>> V;
      if (u % H > 1) {
        if (u / H > 1) V.push_back(make_pair(u-2-2*H, 1));
        if (u / H > 0) V.push_back(make_pair(u-2-H, 1));
        V.push_back(make_pair(u-2, 1));
        if (u / H < W-1) V.push_back(make_pair(u-2+H, 1));
        if (u / H < W-2) V.push_back(make_pair(u-2+2*H, 1));
      }
      if (u % H > 0) {
        if (u / H > 1) V.push_back(make_pair(u-1-2*H, 1));
        if (u / H > 0) V.push_back(make_pair(u-1-H, 1));
        V.push_back(make_pair(u-1, 0));
        if (u / H < W-1) V.push_back(make_pair(u-1+H, 1));
        if (u / H < W-2) V.push_back(make_pair(u-1+2*H, 1));
      }
      if (u / H > 1) V.push_back(make_pair(u-2*H, 1));
      if (u / H > 0) V.push_back(make_pair(u-H, 0));
      if (u / H < W-1) V.push_back(make_pair(u+H, 0));
      if (u / H < W-2) V.push_back(make_pair(u+2*H, 1));
      if (u % H < H-1) {
        if (u / H > 1) V.push_back(make_pair(u+1-2*H, 1));
        if (u / H > 0) V.push_back(make_pair(u+1-H, 1));
        V.push_back(make_pair(u+1, 0));
        if (u / H < W-1) V.push_back(make_pair(u+1+H, 1));
        if (u / H < W-2) V.push_back(make_pair(u+1+2*H, 1));
      }
      if (u % H < H-2) {
        if (u / H > 1) V.push_back(make_pair(u+2-2*H, 1));
        if (u / H > 0) V.push_back(make_pair(u+2-H, 1));
        V.push_back(make_pair(u+2, 1));
        if (u / H < W-1) V.push_back(make_pair(u+2+H, 1));
        if (u / H < W-2) V.push_back(make_pair(u+2+2*H, 1));
      }
      for (auto it = V.begin(); it != V.end(); it++) {
        if (S[it->first]) {
          auto next_pair = make_pair(it->first, U.second + it->second);
          if (it->second == 1) Q.push_back(next_pair);
          else Q.push_front(next_pair);
        }
      }
    }
  }
  cout << min_count << endl;
}

Measured memory_bytes: 6456
#include <stdio.h>
#include <math.h>
#include <stdbool.h>
typedef long long int lli;
#define rept(x, s, n) for (int x = s; x < n; x++)
int main(void){

    int a;
    scanf("%d",&a);
    char s[10];
    scanf("%s",s);
    if(a>=3200){
        printf("%s",s);
    }else{
        printf("red");
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(lint i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  lint N,X,M;
  cin>>N>>X>>M;
  lint D[M];
  vector<lint> S;
  S.push_back(X);
  REP(i,M)D[i]=-1;
  D[X]=0;
  lint X_prev;
  bool skipped=false;
  FOR(i,1,N){
    X_prev=X;
    X=(X*X)%M;
    if(D[X]<0 or skipped){
      D[X]=i;
      S.push_back(S.back()+X);
    }else{
      lint l=(i-D[X]);
      lint c=(N-i)/l;
      lint s=(S.back()-(D[X]!=0?S[D[X]-1]:0));
      i+=l*c-1;
      cerr<<"l="<<l<<" c="<<c<<" s="<<s<<" i="<<i<<endl;
      S.push_back(S.back()+s*c);
      X=X_prev;
      skipped=true;
    }
  }
  cout<<S.back()<<endl;
  return 0;
}


Measured memory_bytes: 5032
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;

int main(){
    ll n,k; cin >> n >> k;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    vector<ll> sum(n+1, 0);
    rep(i,n)sum[i+1] = sum[i] + a[i];
    const int max_ = 61;
    vector<vector<bitset<max_>>> store(2);
    vector<bitset<max_>> clear;
    rep(i,n){
        for(int j = i + 1; j < n+1; j++){
            bitset<max_> bs(sum[j] - sum[i]);
            store[0].emplace_back(bs);
        }
    }
    ll ans = 0;
    rrep(i, max_){
        for(auto bs : store[i & 1]){
            if(bs[i])store[(i & 1) ^ 1].emplace_back(bs);
        }

        if(store[(i & 1) ^ 1].size() < k){
            store[(i & 1) ^ 1] = store[i & 1];
        }
        else {
            ans += pow(2, i);
        }
        store[i & 1] = clear;
    }

    cout << ans << endl;
}

Measured memory_bytes: 8304
package main

import "fmt"

var g [][]int
var r []int
var perm []int
var used []bool

const inf = int(1e9)

var mincost int

func permuntation1(pos, n int) {
	if pos == n { // この順列に対する操作を行う
		cost := 0
		for i := 0; i+1 < n; i++ {
			// fmt.Print(r[perm[i]]+1, " to ", r[perm[i+1]]+1)
			cost += g[r[perm[i]]][r[perm[i+1]]]
		}
		mincost = min(cost, mincost)
		return
	}
	for i := 0; i < n; i++ {
		if !used[i] {
			perm[pos] = i
			used[i] = true
			permuntation1(pos+1, n)
			used[i] = false
		}
	}
	return
}

func main() {
	var N, M, R int
	fmt.Scan(&N, &M, &R)
	g = make([][]int, N)
	for i := range g {
		g[i] = make([]int, N)
		for j := range g[i] {
			if i != j {
				g[i][j] = inf
			}
		}
	}
	r = make([]int, R)
	for i := range r {
		fmt.Scan(&r[i])
		r[i]--
	}
	for i := 0; i < M; i++ {
		var A, B, C int
		fmt.Scan(&A, &B, &C)
		A--
		B--
		g[A][B] = min(g[A][B], C)
		g[B][A] = min(g[B][A], C)
	}
	// ワーシャルフロイドで全点間の最短経路を計算する
	for k := 0; k < N; k++ {
		for i := 0; i < N; i++ {
			for j := 0; j < N; j++ {
				g[i][j] = min(g[i][j], g[i][k]+g[k][j])
			}
		}
	}
	// 指定された街のめぐりかたの順列を全列挙して最小距離を求める
	perm = make([]int, R)
	used = make([]bool, R)
	mincost = inf
	permuntation1(0, R)
	fmt.Println(mincost)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}


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

const int inf = 13;

void chmin (int &x, int a) {
  x = min(x, a);
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int64_t n;
  cin >> n;
  int ans = inf;
  for (int64_t i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      int f = max((to_string(i)).size(), (to_string(n / i)).size());
      chmin(ans, f);
    }
  }
  cout << ans << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
using ll = long long;
#define F first
#define S second

const int sz = 2005;
int n, z, w, a[sz];

void solve(){
    cin >> n >> z >> w;
    for(int i = 0; i < n; ++i) cin >> a[i];

    if(n==1){
        cout << abs(a[0]-w) << '\n';
    }
    else{
        cout << max(abs(a[n-1]-w), abs(a[n-1]-a[n-2])) << '\n';
    }
}

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

Measured memory_bytes: 3632
// DPL_1_D
#include <bits/stdc++.h>
#define endl "\n"
#define rep(i,n) for(int i=0;i<int(n);i++)
#define e_b emplace_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ipair;
typedef pair<ll,ll> lpair;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v) //vectorの中身を見る
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
void map_p(map<int,int>& d){cout<<"map: ";for(auto a : d){cout<<"{"<<a.first<<":"<<a.second<<"}";}cout<<endl;} //mapの中身を見る
void set_p(set<int>& d){cout<<"set: ";for(int a : d){cout<<a<<" ";}cout<<endl;} //setの中身を見る

int n;
int inf=pow(10,9)+10;
vector<int> dp(100010,inf);
vector<int> a(100010);
bool bs(int mid,int now){
    if(mid<=0) return true;
    if(n+1<=mid) return false;
    return now<=dp[mid];
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);

    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=1;i<=n;i++){
        int ng=0,ok=n+1;
        int mid=(ok+ng)/2;
        while(ok-ng>1){
            if(bs(mid,a[i])) ok=mid;
            else ng=mid;
            mid=(ok+ng)/2;
        }
        dp[ok]=a[i];
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        if(dp[i]==inf) break;
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3504
from collections import deque
n, m = map(int, input().split())

adj_list = [[] for i in range(n)]

for i in range(m):
  _, __ = map(int, input().split())
  _ -= 1
  __ -= 1
  adj_list[_].append(__)
  adj_list[__].append(_)
  
distance = [None for i in range(n)]
updated_from = [None for i in range(n)]

newly_visited = deque([0])
distance[0] = 0

while len(newly_visited) > 0:
  now = newly_visited.popleft()
  for i in adj_list[now]:
    if distance[i] is not None: continue
    newly_visited.append(i)
    distance[i] = distance[now] + 1
    updated_from[i] = now

# i に到達できてれば distance[i] ==（0 から i までの距離）
# i に到達できてなければ distance[i] == None   
    
"""
print(distance)

for i in range(n):
  # i から 0 に行く経路を求める
  now = i
  path = [now]
  while now != 0:
    now = updated_from[now]
    path.append(now)
  print(i, path) 
"""

print("Yes")
for i in range(1, n):
  print(updated_from[i] + 1)




Measured memory_bytes: 35108
fun main(args: Array<String>) {
    a97(readLineList())
}

fun readLineList(): Array<String> {
    val lineList = mutableListOf<String>()
    while (true) {
        val line = readLine()
        if (line.isNullOrBlank()) {
            break
        } else {
            lineList.add(line!!)
        }
    }
    return lineList.toTypedArray()
}
fun a97(args: Array<String>) {
    if (args.size != 1) {
        throw IllegalArgumentException()
    }
    val (a, b, c, distance) = args[0].split(" ").map { it.toInt() }
    fun abs(a: Int, b: Int): Int = if (a - b >= 0) a - b else b - a
    println(if (abs(a, c) <= distance || (abs(a, b) <= distance && abs(b, c) <= distance)) "Yes" else "No")}

Measured memory_bytes: 38208
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

vector<P> v[111111];
set<P> se;
map<P,ll> ma,m2;
ll n,m,s,t,ff=0;

void dfs(ll x,ll p) {
  rep(i,v[x].size()) {
    P q=v[x][i];
    ll y=q.S;
    if(se.count(P(x,y))) continue;
    ma[P(x,y)]-=m;
    ma[P(y,x)]-=m;
    if(y==p) continue;
    dfs(y,x);
    if(ma[P(x,y)]<=0) ff=1;
  }
}

void Main() {
  cin >> n >> m >> s >> t;
  s--,t--;
  rep(i,n-1) {
    int x,y,z;
    cin >> x >> y >> z;
    x--,y--;
    v[x].pb(P(z,y));
    v[y].pb(P(z,x));
    ma[P(x,y)]=ma[P(y,x)]=z;
    m2[P(x,y)]=m2[P(y,x)]=z;
  }
  rep(i,v[s].size()) {
    ma[P(s,v[s][i].S)]+=m;
    ma[P(v[s][i].S,s)]+=m;
  }
  rep(i,n) sort(all(v[i]));
  /*
  rep(i,n) {
    sort(all(v[i]));
    rep(j,v[i].size()) {
      P p=P(i,v[i][j]),q=P(v[i][j],i);
      ma[p]-=v[i].size()*m;
      ma[q]-=v[i].size()*m;
    }
  }
  */
  queue<ll> que;
  ll d[n],u[n],p[n];
  mem(d),mem(u);memset(p,-1,sizeof(p));
  que.push(s);
  u[s]=1;
  bool f=0;
  while(!que.empty()) {
    ll x=que.front();que.pop();
    if(x==t) f=1;
    rep(i,v[x].size()) {
      ll y=v[x][i].S;
      if(u[y]) continue;
      m2[P(x,y)]-=(v[x].size()-1)*m;
      m2[P(y,x)]-=(v[x].size()-1)*m;
    }
    rep(i,v[x].size()) {
      ll y=v[x][i].S;
      if(u[y]) continue;
      if(m2[P(x,y)]<=0) continue;
      u[y]=1;
      p[y]=x;
      que.push(y);
    }
  }
  if(!f) {
    pr("No");
    return;
  }
  vector<ll> g;
  while(t!=s) {
    g.pb(t);
    t=p[t];
  }
  g.pb(s);
  rep(x,g.size()-1) {
    int y=g[x+1];
    se.in(P(x,y));
    se.in(P(y,x));
  }
  dfs(s,-1);
  if(s!=t) dfs(t,-1);
  if(ff) pr("No");
  else pr("Yes");
  /*
  tr(it,ma) {
    if(se.count(it->F)) continue;
    P p=it->F;
    pr(p.F,p.S,it->S);
    if(it->S<0) {
      pr("No");
      return;
    }
  }
  pr("Yes");
  */
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}



Measured memory_bytes: 38312
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
  ll N,K,X,Y;
  cin>>N>>K>>X>>Y;
  if(N<=K) {
cout<<N*X<<endl;
  }
  else {
cout<<K*X+(N-K)*Y<<endl;
  }
}

Measured memory_bytes: 3640
#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 a[MAXX];

int main()
{
    _FastIO;

    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a , a + n);
    cout << a[n - 1] - a[0] << endl;
    return 0;
}


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

signed main(){
	int n,m;
	cin>>n;
	vector<int>a(n);
	r(i,n)cin>>a[i];
	cin>>m;
	vector<int>b(m);
	r(i,m)cin>>b[i];
	cout<<lexicographical_compare(a.begin(),a.end(),b.begin(),b.end())<<endl;
}




Measured memory_bytes: 3100
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx")
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


//エラトステネスのふるい
class eratosthenes {
public:
	vector<bool> prime;

	eratosthenes(int N) {
		prime = vector<bool>(N, true);
		prime[0] = prime[1] = false;
		for (int i = 2; i * i < N + 1; i++) {
			if (prime[i]) {
				for (int j = i + i; j < N + 1; j += i) {
					prime[j] = false;
				}
			}
		}
	}
};

//アトキンのふるい
class atkin {
public:
	vector<bool> prime;
	int N, sqrtN;

	atkin(int size) {
		N = size+1; sqrtN = ceil(sqrt(N));
		prime = vector<bool>(N, false);
		int n;
		for (int z = 1; z <= 5; z += 4) {
			for (int y = z; y <= sqrtN; y += 6) {
				for (int x = 1; x <= sqrtN && (n = 4 * x * x + y * y) <= N; ++x)
					prime[n] = !prime[n];
				for (int x = y + 1; x <= sqrtN && (n = 3 * x * x - y * y) <= N; x += 2)
					prime[n] = !prime[n];
			}
		}
		for (int z = 2; z <= 4; z += 2) {
			for (int y = z; y <= sqrtN; y += 6) {
				for (int x = 1; x <= sqrtN && (n = 3 * x * x + y * y) <= N; x += 2)
					prime[n] = !prime[n];
				for (int x = y + 1; x <= sqrtN && (n = 3 * x * x - y * y) <= N; x += 2)
					prime[n] = !prime[n];
			}
		}
		for (int y = 3; y <= sqrtN; y += 6) {
			for (int z = 1; z <= 2; ++z) {
				for (int x = z; x <= sqrtN && (n = 4 * x * x + y * y) <= N; x += 3)
					prime[n] = !prime[n];
			}
		}
		for (int n = 5; n <= sqrtN; ++n)
			if (prime[n])
				for (int k = n * n; k <= N; k += n * n)
					prime[k] = false;
		prime[2] = prime[3] = true;
	}
};

int main() {
	atkin p(100000000);
	int N, ans = 0;
	cin >> N;
	for (int i = 0; i < N; i++) {
		int tmp;
		cin >> tmp;
		if (p.prime[tmp])ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 14852
n = int(input())
worklist = []
for i in range(n):
    alist=list(map(int,input().split()))
    worklist.append(alist)

worklist.sort(key=lambda x: x[1])
timecount = 0
count = 0

for i in range(n):
    timecount += worklist[i][0]
    if timecount > worklist[i][1]:
        count += 1

if count == 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 46792
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=0;
		int x = sc.nextInt();
		while(x!=0){
			n++;
			System.out.println("Case "+n+": "+x);
			x = sc.nextInt();
		}
	}
}

Measured memory_bytes: 33076
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=200010;
const ll mod=1e9+7;

int main(){  
  char n;
  cin >> n;
  if(n=='A'){ cout << 'T' << endl; return 0;}
  if(n=='T'){ cout << 'A' << endl; return 0;}
  if(n=='C'){ cout << 'G' << endl; return 0;}
  if(n=='G'){ cout << 'C' << endl; return 0;}

  
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main{

    public static final int FIRST_NUMBER = 0;
    public static final int SECOND_NUMBER = 1;

    public static void main(String[] args) throws NumberFormatException, IOException {

	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

	// ???????????°
	int vertical = Integer.parseInt(br.readLine());
	// ?¨?????????°
	int horizontal = Integer.parseInt(br.readLine());

	// ???????????????????´?????????°??????????????????
	List<int[]> changeRequests = new ArrayList<>();
	for (int i = 0; i < horizontal; i++) {
	    String[] changeRequestStr = br.readLine().split(",");
	    int[] changeRequest = new int[2];
	    changeRequest[FIRST_NUMBER] = Integer.parseInt(changeRequestStr[FIRST_NUMBER]);
	    changeRequest[SECOND_NUMBER] = Integer.parseInt(changeRequestStr[SECOND_NUMBER]);
	    changeRequests.add(changeRequest);
	}

	// ?????\???????????????????´???????????????????????????????
	int[] outputArray = getDrawedArray(changeRequests, vertical, horizontal);

	// ???????????????????????????????????¨????????????????????????????????????1??????????????????
	for (int i = 1; i < outputArray.length; i++) {
	    System.out.println(outputArray[i]);
	}

    }

    /**
     * ?????? ???????????????????????????????????\??????????????????
     * 
     * @param changeRequests
     * @param vertical
     * @param horizontal
     * @return ?????\?????????
     */
    private static int[] getDrawedArray(List<int[]> changeRequests, int vertical, int horizontal) {
	// ?????\?????????????????????????????????????????????
	// ?????????????????????????????¨?????\????????????????????´???????????????outputArray[0]????????¨?????????
	int[] outputArray = new int[vertical + 1];
	for (int i = 1; i < outputArray.length; i++) {
	    outputArray[i] = i;
	}

	// ?????????????????????????£????????????\????????????
	for (int[] changeRequest : changeRequests) {
	    int mediator = 0;
	    mediator = outputArray[changeRequest[FIRST_NUMBER]];
	    outputArray[changeRequest[FIRST_NUMBER]] = outputArray[changeRequest[SECOND_NUMBER]];
	    outputArray[changeRequest[SECOND_NUMBER]] = mediator;

	}

	return outputArray;

    }

}

Measured memory_bytes: 24520
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <cstring>
#include <cstdio>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define F first
#define S second
int n,k,a[100005],ans;
int main(void){
    cin>>n>>k;
    if(n==k)cout<<1<<endl;
    else{
        n--;
        k--;
        cout<<(n+k-1)/k<<endl;
    }
}

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

int to10(const string &s) {
  int x = 0;
  for(int i = 0; i < s.size(); ++i) {
    int d;
    if(isdigit(s[i])) d = s[i] - '0';
    else d = 10 + s[i] - 'a';
    x = x * 16 + d;
  }
  return x;
}

vector<int> conv(const string &s) {
  vector<int> res(3);
  res[0] = to10(s.substr(1,2));
  res[1] = to10(s.substr(3,2));
  res[2] = to10(s.substr(5,2));
  return res;
}

int norm(vector<int> a, vector<int> b) {
  int res = 0;
  for(int i = 0; i < 3; ++i) {
    int sub = a[i] - b[i];
    res += sub * sub;
  }
  return res;
}


int main() {
  vector<string> name;
  vector<vector<int> > v;
  name.push_back("black");
  v.push_back(conv("#000000"));
  name.push_back("blue");
  v.push_back(conv("#0000ff"));
  name.push_back("lime");
  v.push_back(conv("#00ff00"));
  name.push_back("aqua");
  v.push_back(conv("#00ffff"));
  name.push_back("red");
  v.push_back(conv("#ff0000"));
  name.push_back("fuchsia");
  v.push_back(conv("#ff00ff"));
  name.push_back("yellow");
  v.push_back(conv("#ffff00"));
  name.push_back("white");
  v.push_back(conv("#ffffff"));
  string s;
  while(cin >> s && s != "0") {
    vector<int> x = conv(s);
    int k = 0;
    for(int i = 1; i < v.size(); ++i) {
      if(norm(x, v[i]) < norm(x, v[k])) {
        k = i;
      }
    }
    cout << name[k] << endl;
  }
  return 0;
}

Measured memory_bytes: 1212
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define RFOR(i,a,b) for(int i=(b-1); i>=(a); i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
using ll = long long;
using D = double;
using LD = long double;
using P = pair<int, int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
    int k; cin >> k;
    string s; cin >> s;
    int n = s.size();
    if(n <= k){
        cout << s << endl;
    }
    else{
        string ans = s.substr(0, k);
        ans += "...";
        cout << ans << endl;
    }
}


Measured memory_bytes: 3632
"use strict"
function main(arg) {
    var data = arg.trim().split("\n")[0].split(" ").map(Number)
    var n = data[0]
    var d = data[1]
    console.log(Math.ceil(n / (d * 2 + 1)))
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

int N, S, CNT = 0;

void dfs(int i, int sum, int total){
	if(total == N && sum == S){
		CNT++;
		return;
	}
	if(i == 10 || total == N){
		return;
	}
	
	dfs(i+1,sum+i,total+1);
	dfs(i+1,sum,total);
}

int main(){
	
	while(cin >> N >> S){
		if(N == 0 && S == 0) break;
		
		CNT = 0;
		dfs(0,0,0);
		cout << CNT << endl;
		
	}
	
	return 0;
}

Measured memory_bytes: 3012
#include <bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
   	
int main() {
	int n, k, sum = 0;
	cin >> n >> k;

	int p[n];

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

	sort(p, p+n);

	for (int i = 0; i < k; i++)
	{
		sum = sum + p[i];
	}

	cout << sum;

	return 0;
}

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

int main () {
  int n, m;
  string s[110], t[110];

  cin >> n;
  for (int i = 0; i < n; i++) cin >> s[i];
  cin >> m;
  for (int i = 0; i < m; i++) cin >> t[i];
  
  int max_count = 0;
  for (int i = 0; i < n; i++) {
    int count = 0;
    for (int j = 0; j < n; j++) {
      if (s[j] == s[i]) count++;
    }
    for (int j = 0; j < m; j++) {
      if (t[j] == s[i]) count--;
    }
    max_count = max(max_count, count);
  }
  cout << max_count << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#define mm(a,x) memset(a,x,sizeof(a))
#define sync std::ios::sync_with_stdio(false);std::cin.tie(0)
#define ll long long
using namespace std;
int n,m,x;
int a[15][15];
ll sum[15],tmp[15];
ll res=0x3f3f3f3f;
void dfs(int i)
{
    res=min(res,tmp[0]);
    bool flag=true;
    for(int j=1;j<=m;++j)
    {
        if(tmp[j]-a[i][j]<x)
            flag=false;
    }
    if(flag)
    {
        for(int j=0;j<=m;++j)
            tmp[j]-=a[i][j];
        res=min(res,tmp[0]);
    }
    for(int j=i+1;j<=n;++j)
        dfs(j);
    if(flag)
    {
        for(int j=0;j<=m;++j)
            tmp[j]+=a[i][j];
    }
}
int main(void)
{
    sync;
    cin>>n>>m>>x;
    for(int i=1;i<=n;++i)
    {
        for(int j=0;j<=m;++j)
        {
            cin>>a[i][j];
            sum[j]+=a[i][j];
        }
    }
    for(int i=1;i<=m;++i)
        if(sum[i]<x)
        {
            cout<<-1<<endl;
            return 0;
        }
    for(int i=1;i<=n;++i)
    {
        for(int j=0;j<=m;++j)
            tmp[j]=sum[j];
        dfs(i);
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 3660
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

// 最小公倍数
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}

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

	ll n, m;
	cin >> n >> m;
	string s, t;
	cin >> s >> t;
	
	// sとtの一部が同じ文字になることを確かめる
	// sとtどちらも関与しない文字はなんでもいい←無視する

	ll l = lcm(n, m);

	int rate = 0;

	map<int, char> mp;

	if (n > m) {
		// mを先にやる
		rep(i, n) {
			mp[i * l / n] = s[i];
		}
		rep(i, m) {
			if (mp[i * l / m] == 0) {
				continue;
			}
			else {
				if (mp[i * l / m] != t[i]) {
					cout << -1 << endl;
					return 0;
				}
			}
		}
	}
	else {
		rep(i, m) {
			mp[i * l / m] = t[i];
		}
		rep(i, n) {
			if (mp[i * l / n] == 0) {
				continue;
			}
			else {
				if (mp[i * l / n] != s[i]) {
					cout << -1 << endl;
					return 0;
				}
			}
		}
	}

	cout << l << endl;
	return 0;
}

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

int main(){
    string T;
    cin >> T;

    int flag=0;
    int D=0,PD=0;
    int leng = T.length();
    for(int i=0;i<=leng;i++){
        char t = T[i];
        if(t==80){ //P
            if(flag==2){
                T[i-1]=68;
            }
            flag=1;
        }
        else if(t==68){ //D
            if(flag==2){
                T[i-1]=80;
            }   
            flag=0;
        }
        else if(t == NULL){
            if(flag!=2){
                break;
            }
            T[i-1] = 68;
        }
        else{
            if(flag==1){
                T[i]=68;
                flag=0;
            }
            else if(flag==2){
                T[i-1]=80;
              	T[i]=68;
              	flag=0;
            }
            else{
                flag=2;
            }
        }
    }
    cout << T <<endl;
}

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

int main() {
    long n, k;
    cin >> n;
    cin >> k;

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

    long l = 0, r = *max_element(a.begin(), a.end());
    long m;
    while(r - l > 1) {
        m = (l + r) / 2;

        long count = 0;
        for(int i = 0; i < n; i++) {
            count += a[i] / m;
            if(a[i] % m == 0) {
                count --;
            }
        }
        if(count <= k) {
            r = m;
        } else {
            l = m;
        }
    }
    cout << r << endl;

    return 0;
}

Measured memory_bytes: 4764
S = input()
N = len(S)

dp = [0] * (N+1)
base = 2019
for i, s in enumerate(S, 1):
    dp[i] = (dp[i-1]*10 + int(s)) % 2019

digit = 1
for i in range(N):
    j = N - i
    dp[j] *= digit
    dp[j] %= base
    digit *= 10
    digit %= base

ans = 0
d = {}
for r in dp:
    if r in d:
        ans += d[r]
        d[r] += 1
    else:
        d[r] = 1

print(ans)

Measured memory_bytes: 16152
# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read

n,*ab = map(int,read().split())


a = []
b = []
M = iter(ab)
for ai,bi in zip(M,M):
    a.append(ai)
    b.append(bi)

a.sort()
b.sort()

if n%2:
    mid = n//2
    print(b[mid] - a[mid]+1)


else:
    mid = n//2
    x = b[mid-1]+b[mid] - a[mid-1]-a[mid]
    print(x+1)

    



Measured memory_bytes: 54584
#include <stdio.h>

int G[10000];
int cnt=0,c=0;

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

void shellSort(long A[],int n){
  int m,i;
  m=1;
  while(1){
    if(m>n)break;
    G[c]=m;
    m=m*3+1;
    c++;
  }
  for(i=c-1;i>=0;i--){
    insertionSort(A,n,G[i]);
  }
}

int main(){
  int i,n;
  long A[1000000];
 
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%ld",&A[i]);
  }

  shellSort(A,n);

  printf("%d\n",c);
  for(i=c-1;i>=0;i--){
    printf("%d",G[i]);
    if(i>0)printf(" ");
  }
  printf("\n");
  printf("%d\n",cnt);
  for(i=0;i<n;i++){
    printf("%ld\n",A[i]);
  }
  return 0;
}



Measured memory_bytes: 9540
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<random>
#include<deque>
#include<cstdio>
#include<fstream>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 2000100;
const int mod = (int)pow(10, 9) + 7;
const ll INF = 1LL << 60;
#define rep(i,n) for(ll i=(ll)0;i<(ll)n;++i)
#define ALL(x) x.begin(),x.end()
#define pp pair<ll,ll>
#define ppp pair<pp,ll>
#define fi first
#define se second
#define pb push_back
#define fix(n) fixed<<setprecision(n)
#define itr vector<ll>::iterator
#define print(s) cout<<s<<endl
#define inp(s) cin>>s
string yn(bool b) { return (b ? "Yes" : "No"); }
string YN(bool b) { return (b ? "YES" : "NO"); }
ll x;
string s[] = { "fri","sat","sun","mon","tue","wed","thu" };
int main(){
	cin >> x;
	cout << s[(x+6) % 7] << endl;
	return 0;
}


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

int main(){
  int n;
  cin >> n;
  for(int i = 0; i < 30; i++){
    for(int j = 0; j < 30; j++){
      if(i * 4 + 7 * j == n){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <bits/stdc++.h>
#include <cstdlib>
#include <math.h> 
using namespace std;
typedef pair<int, int> pi; 
#define ll long long int
#define inf 1e6
int main(){
	string s;
	cin>>s;
	int score=0,gain=0;
	for(int i=0;i<s.length();i++)
	{
		if(s[i]=='p')
		{
			if(gain)
			--gain;
			else
			{--score,++gain;}
		}
		else
		{
			if(gain)
			{++score,--gain;}
			else
			{++gain;}
		}
	}
	cout<<score<<'\n';
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
template<class T>bool chmax(T &a, const T &b) {if(a<b) {a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if(b<a) {a=b; return 1;} return 0;}
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;
//for(i=0; i<N; i++) cin >> a[i];


ll h[MAX*3]={}, w[MAX*3]={};

int main(void) {
  ll i, j, k;
  
  ll H, W, M;
  cin >> H >> W >> M;
  
  vector<ll> a(H), b(W);
  for(i=0; i<M; i++) {
    cin >> h[i] >> w[i];
    h[i]--; w[i]--;
    a[h[i]]++;
    b[w[i]]++;
  }
  
  ll ma=*max_element(a.begin(), a.end());
  ll mb=*max_element(b.begin(), b.end());
  
  ll A=0, B=0;
  for(i=0; i<H; i++) if(a[i]==ma) A++;
  for(i=0; i<W; i++) if(b[i]==mb) B++;
  
  
  ll C=0;
  for(i=0; i<M; i++) if(a[h[i]]+b[w[i]]==ma+mb) C++;
  
  pt(ma+mb-(C==A*B));
  
  
}




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

using namespace std;
int n, m,x,y;
const int inf=1e9;
int a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51} ;
inline int read() {
	char ch = getchar();
	int x = 0, f = 1;
	while (ch < '0' || ch > '9')
		f = (ch == '-' ? -1 : 1), ch = getchar();
	while (ch >= '0' && ch <= '9')
		x = x * 10 + ch - 48, ch = getchar();
	return x * f;
}
int main() {
	cin>>n;
	cout<<a[n-1];
	return 0;
}

Measured memory_bytes: 256
/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
I'm working for the day I will surpass you
https://www.a2oj.com/Ladder16.html
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class Main
   {
      static long MOD = 1000000007L;
      public static void main(String omkar[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         int K = Integer.parseInt(st.nextToken());
         long[] dp = new long[K+1];
         dp[K] = 1;
         for(int x=K-1; x >= 1; x--)
         {
            int choices = K/x;
            dp[x] = power(choices, N, MOD);
            //inclusion exclusion
            int dex = 2*x;
            while(dex <= K)
            {
               dp[x] -= dp[dex];
               dp[x] += MOD;
               dp[x] %= MOD;
               dex += x;
            }
         }
         long res = 0L;
         for(int x=1; x <= K; x++)
         {
            res += dp[x]*x;
            res %= MOD;
         }
         System.out.println(res);
      }
      public static long power(long x, long y, long p) 
      { 
          long res = 1L;      
          x = x % p;  
          while (y > 0) 
          { 
              if((y & 1)==1) 
                  res = (res * x) % p; 
              y = y >> 1;  
              x = (x * x) % p;  
          } 
          return res; 
      } 
   }

Measured memory_bytes: 33560
#include <stdio.h>
#include <stdlib.h>
#include "time.h"
#include "unistd.h"
#include "string.h"
#include <math.h>
int ans=0;
int main(int argc, char* argv[]){
	long long int a, b = 0, c = 0;
	scanf("%lld %lld",&a,&b);
	long long int d[a],e=0;
	for (int i = 0; i < a; i++) {
		scanf("%lld",&d[i]);
		c+=d[i];
	}
	double bi=b;
	for (int i = 0; i < a; i++) {
		if (d[i]>=c/(4*bi)) {
			e++;
		}
	}
	if (b<=e) {
		printf("Yes\n");
	}else{
		printf("No\n");
	}
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define int long long
#define PB push_back
#define MP make_pair
#define fi first
#define se second
using namespace std;
static const int inf = 1ll<<60;
typedef pair<int,int> pii;

struct edge{
    int to,cost;
    edge(){}
    edge(int p1,int p2){
        to=p1;
        cost=p2;
    }
};


int N,M,K;
vector<edge> G[3005];
double d[3005];

void dijkstra(int s){
    priority_queue<pii,vector<pii>,greater<pii> > que;
    d[s]=0;
    que.push(pii(0,s));
    while(!que.empty()){
        pii p=que.top();
        que.pop();
        int v=p.se;
        if(p.fi>d[v])continue;
        for(int i=0;i<G[v].size();++i){
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(pii(d[e.to],e.to));
            }
        }
    }
}

double ans=0.0;

signed main(){
    cin>>N>>M>>K;
    for(int i=0;i<M;++i){
        int a,b,c;
        cin>>a>>b>>c;
        a--;b--;
        G[a].PB(edge(b,c));
        G[b].PB(edge(a,c));
    }
    fill(d,d+3000,inf);
    for(int i=0;i<K;++i){
        int shop;
        cin>>shop;
        shop--;
        dijkstra(shop);
    }
    for(int i=0;i<N;++i){
        for(int j=0;j<G[i].size();++j){
            edge e=G[i][j];
            int D=abs(d[i]-d[e.to]);
            ans=max(ans,max(d[i],d[e.to])+(e.cost-D)/2.0);
        }
    }
    cout<<round(ans)<<endl;
}

Measured memory_bytes: 7080