akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main(){
    int x, N;
    int p[107];
    int flag[107];

    cin >> x >> N;

    if(N==0){
        cout << x << endl;
        return 0;
    }

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

    int itr =max(x,max_p+1);
    
    for(int i=0; i<=itr; i++){
        flag[i] = 1;
    }
    for(int i=0; i<N; i++){
        flag[p[i]] = 0;
    }

    int tmp = 0;
    int sa = 107;
    int ans =0;
    for(int i=1; i<=itr; i++){
        if(flag[i] == 1){
            tmp = abs(x-i);
            if(sa>tmp){
                sa = tmp;
                ans = i;
            }
        }
    }
    if(sa>=x){
        cout << 0 << endl;
    } else cout << ans << endl;
}

Measured memory_bytes: 3636
#include"bits/stdc++.h"

using namespace std;

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

void Main()
{
	while(1){
		int x, y;
		cin >> x >> y;
		if(x == 0 && y == 0){
			break;
		}
		cout << min(x, y) << ' ' << max(x, y) << endl;
	}
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
	return 0;
}



Measured memory_bytes: 3116
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define endl "\n"
#define all(v) v.begin(),v.end()
#define mp make_pair
#define mm(a) memset(a,0,sizeof(a))
#define rep(i,a,b) for(ll i = a; i < b; i++)
#define repn(i,a,b) for(ll i = a; i >= b; i--)
#define pb push_back
#define ff first
#define ss second
#define fto(k,m) for(auto k:m)
#define in_edges(m) repp(i, 1, m){ ll a, b; cin >> a >> b; adj[a].pb(b), adj[b].pb(a);}
#define debug(this) cerr<<"> "<<#this<<" : "<<this<<"\n"
#define MOD 1000000007
#define sz(a) ll((a).size())
#define pii 3.1415926535897
#define quick ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
// stoll(s);
int main()
{
    quick
	ll t;t=1;
    // cin >> t;
	while(t--){
        ll n; cin >>n;
        ll a[n];
        rep(i,0,n){
            cin >>a[i];
        }
        ll  k =0;
        vector<ll>ans;
        rep(i,0,n)
        {
            k^=a[i];
        }
        rep(i,0,n)
        {
            ans.pb(k^a[i]);
        }
        fto(k,ans)cout<<k<<" ";
    }
}

Measured memory_bytes: 6828
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>
#include <cctype>
#include <stack>
#include<set>


#define rep(i,p,q) for(ll i = p;i < q;++i)
#define ll long long

using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll npk(ll n, ll k) {
	ll ret = 1;
	if (n < k || n < 0)return 0;
	rep(i, 0, k) {
		ret *= (n - i);
		ret %= MOD;
	}
	if (ret < 0) ret = 0;
	return ret;
}

const long long MAX_N = 1 << 17;
long long dat[2 * MAX_N - 1];

class SegmentTree {
private:
	//node数
	long long n;

	//[a,b)の最大値を求める
	long long query(long long a, long long b, long long k, long long l, long long r) {
		if (r <= a || b <= l)return 0;

		if (a <= l && r <= b) return dat[k];
		else {
			long long vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
			long long vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
			return std::max(vl, vr);
		}
	}
public:
	SegmentTree(long long n_) {
		n = 1;
		while (n < n_) n *= 2;

		for (long long i = 0; i < 2 * n - 1; i++)dat[i] = 0;
	}

	//k番目の値をaにする
	void update(long long k, long long a) {
		k += n - 1; //葉
		dat[k] = a;
		while (k > 0) {
			k = (k - 1) / 2;
			dat[k] = std::max(dat[k * 2 + 1], dat[k * 2 + 2]);
		}
	}

	//[a,b)の最大値を求める
	long long search(long long a, long long b) {
		return query(a, b, 0, 0, n);
	}
};

//136D
bool compare(pair<ll,ll> a, pair<ll,ll> b) {
	return a.second < b.second;
}

int main(void) {
	ll n, m;
	cin >> n >> m;
	vector<pair<ll, ll>> albeit = vector<pair<ll, ll>>();
	rep(i, 0, n) {
		ll a, b;
		cin >> a >> b;
		albeit.push_back(make_pair(a, b));
	}
	sort(albeit.rbegin(), albeit.rend(),compare);
	ll day = 0;
	ll ans = 0;
	vector<ll> nt = vector<ll>(m + 1, 0);
	nt[m] = 1;
	ll mn = 0;
	SegmentTree segTree = SegmentTree(m+1);
	rep(i, 1, m + 1)segTree.update(i, i);
	for (const auto& pr : albeit) {
		ll k = segTree.search(0, m + 2 - pr.first);
		if (k != 0) {
			ans += pr.second;
			segTree.update(k, 0);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 6640
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <functional>
#include <vector>
#include <deque>
#include <utility>
#include <bitset>
#include <limits.h>
#include <time.h>
#include <functional>
#include <numeric>
#include <iostream>

using namespace std;
typedef long long ll;
typedef unsigned long long llu;
typedef double lf;
typedef unsigned int uint;
typedef long double llf;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int MOD = (int)1e9 + 7;

class modint {
  int v;
public:
  modint (): v(0) { }
  modint (ll v): v((v + MOD) % MOD) { }

  bool operator== (modint x) { return v == x.v; }
  bool operator!= (modint x) { return v != x.v; }

  modint operator+ (modint x) { return v + x.v; }
  modint operator- (modint x) { return v - x.v; }
  modint operator* (modint x) { return (ll)v * x.v; }

  modint& operator+= (const modint x) { return *this = (*this + x); }
  modint& operator-= (const modint x) { return *this = (*this - x); }
  modint& operator*= (const modint x) { return *this = (*this * x); }

  int operator* () { return v; }
};

#define debug(format, ...) printf(format, __VA_ARGS__);

const int N_ = 100500;
const int M_ = 100500;

int N, M;
int freq[N_];

int main() {
  // parity만 따지면 루트~u에 1 더해도 됨
  // 루트 아무거나 잡아도 되어야 하니, 1로 잡음.

  scanf("%d%d", &N, &M);
  for(int i = 1; i <= M; i++) {
    int a, b; scanf("%d%d", &a, &b);
    freq[a] += 1;
    freq[b] += 1;
  }

  int cnt[2] = {0, 0};
  for(int i = 1; i <= N; i++) {
    cnt[freq[i] % 2] += 1;
  }

  puts(cnt[1] <= 1 ? "YES" : "NO");

  /*
  1 2 3 4 : 불가능

  리프노드에는 반드시 그 쿼리 수만큼 더해짐.
  그러면 freq가 짝수인 게 필요

  1--..--v--u

  이런 상황이라 하자. 애초에 리프에서 짝수개만큼 더하니까, 그냥

  1--..--v
  |__u

  이렇게 바꿔도 답에 지장이 없음. 결국 홀수끼리의 문제가 되는데, 홀수인 게 하나라도 있으면 안 되나?
  */

  return 0;
}


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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int N;
ll A[100100], B[100100];

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

    std::cin >> N;

    ll s = 0, se = 0;

    for(int i=1;i<=N;++i){
        std::cin >> A[i];

        s += A[i];

        if(i % 2 == 0){
            se += A[i];
        }
    }

    B[1] = s / 2 - se;

    for(int i=1;i<N;++i){
        B[i+1] = A[i] - B[i];
    }

    for(int i=1;i<=N;++i){
        std::cout << (2ll * B[i]) << " \n"[i == N];
    }
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;

// chmax, chmin
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 <typename T>
function<T(T, T)> op_max = [](T a, T b) -> T { return max(a, b); };
template <typename T>
function<T(T, T)> op_min = [](T a, T b) -> T { return min(a, b); };

template <typename T>
function<T(T, T)> op_sum = [](T a, T b) -> T { return a + b; };

using namespace std;
//********************  dumps ************************//

template <typename T>
void dump(const T &data, vector<int> &iter)
{
  cout << data << " ";
}
template <typename T>
void dump(const vector<T> &data, vector<int> &iter)
{
  for (auto elem : data)
    dump(elem, iter);
  cout << endl;
}

template <typename T>
void dump(const vector<vector<T>> &data, vector<int> &iter)
{
  for (auto elem : iter)
  {
    cout << "[" << elem << "]";
  }
  cout << endl;
  for (int i = 0; i < data.size(); i++)
  {
    iter.push_back(i);
    dump(data[i], iter);
    iter.pop_back();
  }
  cout << endl;
}

template <typename T>
void dump(const vector<T> &data, int dummy)
{
  for (int i = 0; i < data.size(); i++)
  {
    cout << "[" << i << "] " << data[i] << endl;
  }
}
template <typename T>
void dump(const T &data)
{ // T : data, U = base type val.
  vector<int> iter;
  dump(data, iter);
}
///////////////////////////////////////////////

void solve(long long N)
{

  LL ans = 0;
  for (LL p = 2; p * p <= N; p++)
  {
    int cnt = 0;
    while (N % p == 0)
    {
      N /= p;
      cnt++;
    }
    for (int i = 1; i <= cnt; i++)
    {
      cnt -= i;
      if (cnt >= 0)
        ans++;
    }
  }
  if (N > 1)
    ans++;
  cout << ans << endl;
}

int main()
{
  cout << setprecision(10);
  long long N;
  scanf("%lld", &N);
  solve(N);
  return 0;
}


Measured memory_bytes: 3756
import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array

# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def fib(dp, n):
    if n == 0 or n == 1:
        dp[n] = 1
        return dp[n]
    if dp[n] != -1:
        return dp[n]
    dp[n] = fib(dp, n - 1) + fib(dp, n - 2)
    return dp[n]


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    fb = [-1] * (N + 1)
    print(fib(fb, N))


if __name__ == '__main__':
    main()



Measured memory_bytes: 7112
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <string>
#include <sstream>
#include <numeric>
#include <ios> // std::left, std::right

typedef long long int ll;
typedef unsigned long long int ull;

using namespace std;

int main()
{
  ll n, m = 1000000000;
  cin >> n;
  vector<ll> a(n, 0);
  int b = 1;
  for (ll i = 0; i < n; i++)
  {
    cin >> a[i];
    if (a[i] < 0)
    {
      b *= (-1);
      a[i] *= (-1);
    }
    m = min(m, a[i]);
  }

  if (b == 1)
  {
    cout << accumulate(a.begin(), a.end(), 0LL) << endl;
  }
  else
  {
    cout << accumulate(a.begin(), a.end(), 0LL) - 2 * m << endl;
  }

  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#pragma gcc optimize("ofast")
using namespace std;

#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define mod 1000000007
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0); //to synchronize the input of cin and scanf
#define INF LONG_MAX
#define PI 3.1415926535897932384626
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(x,j,n)for(int x=j;x<n;x++)
typedef vector<pair<ll,ll>> vpi;
typedef vector<ll> vi;
typedef vector<vi> vvi;


int main(){
    ll n,k; cin>>n>>k;
    vi arr(n); rep(i,0,n)cin>>arr[i];
    sort(arr.begin(),arr.end(),greater<ll>());
    ll sum = 0;
    for(ll i = k;i<n;i++)sum+=arr[i];
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
int64_t MOD=1000000007;

vector<pair<int,int>> CU(vector<int> S){
  vector<pair<int,int>> SS;
  sort(S.begin(),S.end());
  int temp=S.at(0);
  SS.push_back(make_pair(1,temp));
  for(int i=1;i<(int)S.size();i++){
    int s=SS.size();
    temp=S.at(i);
    if(S.at(i)==S.at(i-1)) SS.at(s-1).first++;
    else SS.push_back(make_pair(1,temp));
  }
  sort(SS.begin(),SS.end());
  reverse(SS.begin(),SS.end());
  return SS;
}


int main() {
  int N,o,e;
  cin>>N;
  e=N/2;
  o=(N+1)/2;
  vector<int> O(o);
  vector<int> E(e);
  for(int i=0;i<e;i++){
    cin>>O.at(i)>>E.at(i);
  }
  if(o!=e)cin>>O.at(o-1);
  vector<pair<int,int>> OO=CU(O);
  vector<pair<int,int>> EE=CU(E);
  if(OO.size()==1) OO.push_back(make_pair(0,0));
  if(EE.size()==1) EE.push_back(make_pair(0,0));
  if(OO.at(0).second!=EE.at(0).second) cout<< N-(OO.at(0).first+EE.at(0).first)<<endl;
  else cout<<N-max(OO.at(1).first+EE.at(0).first,OO.at(0).first+EE.at(1).first)<<endl;
}


Measured memory_bytes: 1972
// 標準入力
var fs = require('fs'),
length = fs.fstatSync(process.stdin.fd).size,
buffer = new Buffer(length),
bytesRead = fs.readSync(process.stdin.fd, buffer, 0, length, 0),
input = buffer.toString('utf8', 0, bytesRead).split('\n');
main();
 
function main(){
  var read = 0;
  var resultCase = 1;
  while(true){
    var maxWeight = +input[read++];
    if(!maxWeight){
      break;
    }
     
    var treasures = +input[read++];
    var pdp = new Int32Array(maxWeight + 1);
    for(var i = treasures; i--;){
      var c = input[read++].split(",");
      var tv = +c[0];
      var tw = +c[1];
 
      var dp = new Int32Array(maxWeight + 1);
      for(var w = 1; w <= maxWeight; w++){
        var pdpw = pdp[w];
        dp[w] = pdpw;
        if(w - tw >= 0){
          dp[w] = max(pdp[w-tw] + tv, pdpw);
        }
      }
      pdp = dp;
    }
 
    var resultWeight = 1001;
    var resultCost = 0;
    for(var i = 0; i <= maxWeight; i++){
      var pdpi = pdp[i];
      if(pdpi > resultCost){
        resultCost = pdpi;
        resultWeight = i;
      }
    }
     
    console.log("Case " + resultCase++ + ":\n" + resultCost + "\n" + resultWeight);
  }
}
 
function max(a, b) {
  var t = a - b;
  return a - (t & (t >> 31));
}

Measured memory_bytes: 14396
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    while True:
        n,m,k = LI()
        if n == 0:
            break
        r = [[0] * (n*m+1) for _ in range(n+1)]
        r[0][0] = 1
        for i in range(n):
            for j in range(i,n*m):
                if r[i][j] == 0:
                    break
                for kk in range(1,m+1):
                    r[i+1][j+kk] += r[i][j] / m
        t = 0
        for kk in range(n*m+1):
            c = max(kk-k,1)
            t += c * r[n][kk]
        rr.append('{:0.9f}'.format(t))

    return '\n'.join(map(str, rr))


print(main())




Measured memory_bytes: 9316
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]
  
n=int(input())

a=make_divisors(n)

b=len(a)

if b%2==0:
  c=int(b/2)-1
  x=a[c]
  y=a[c+1]
  print(x+y-2)
  
else:
  c=int((b+1)/2)-1
  x=a[c]
  print(x+x-2)

Measured memory_bytes: 64116
d=int(input())
C=list(map(int,input().split()))
S=[]
for i in range(d):
    S.append(list(map(int,input().split())))


last=[0]*26

for i in range(d):
    s=-1
    for j in range(26):
        temp=S[i][j]+C[j]*(i+1-last[j])
        if temp>s:
            s=temp
            index=j
    last[index]=i+1
    print(index+1)


Measured memory_bytes: 9396
#include <bits/stdc++.h>
using namespace std;
#define fo(i,n) for(int i = 0; i < n; i++)
#define pb push_back
#define all(c) c.begin(),c.end()



int main()
{
    int n;
    cin >> n;
    vector<int> v(n+2);
    for(int i = 2; i <=n; i++)
    {
        int x;
        cin >> x;
        v[x]++;
    }
    for(int i =1; i <= n; i++)
        cout << v[i] << endl;

}



Measured memory_bytes: 4044
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(input.readLine());
        Set<String> set = new HashSet<>();
        String value = input.readLine();
        char lastChar = value.charAt(value.length() - 1);
        set.add(value);
        for (int i = 1; i < n; i++) {
            value = input.readLine();
            if (set.contains(value) || lastChar != value.charAt(0)) {
                System.out.println("No");
                return;
            }
            set.add(value);
            lastChar = value.charAt(value.length() - 1);
        }
        System.out.println("Yes");
    }
}


Measured memory_bytes: 21332
import os
import sys
import math
import heapq
from decimal import *
from io import BytesIO, IOBase
from collections import defaultdict, deque

def r():
    return int(input())
def rm():
    return map(int,input().split())
def rl():
    return list(map(int,input().split()))

s=input()
t=input()
ans=len(t)
sl = len(s)
tl = len(t)
for i in range(sl-tl+1):
    temp=0
    for j in range(tl):
        if t[j]!=s[i+j]:
            temp+=1
    ans=min(ans, temp)
print(ans)

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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int count = 0;
		int mul = 0;
        for(int i = 1; i <= n; i++) {
			count = 0;
			for(int x = 1; x < 100; x++) {
				if((x * x + x * 2 + 3) > i) {
					System.out.println(count);
					break;
				}
				for(int y = 1; y < 100; y++) {
					for(int z = 1; z < 100; z++) {
						mul = (x * x) + (y * y) + (z * z) + (x * y) + (y * z) + (z * x);
						if(mul == i){
							count++;
						}
						if(mul > i){
							break;
						}
					}
					mul = (x * x) + (y * y) + (x + y) + x + y + 1;
					if(mul > i){
						break;
					}
				}
			}
		}
    }
}

Measured memory_bytes: 39136
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <iomanip>
using namespace std;

int main(){
   ;
    //サンプルコード;;
    //ABC076-A;;
    ;;
    int r, g;;;
    cin >> r >> g;;;
    ;;
    cout << (2*g-r) << endl;;;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int i,n,c[4]={0};
	char str[4];

	scanf("%d",&n);

	for(i=0;i<n;i++){
		scanf("%s",str);

		if(str[0] == 'A'){
			c[0]++;
		}
		if(str[0] == 'W'){
			c[1]++;
		}
		if(str[0] == 'T'){
			c[2]++;
		}
		if(str[0] == 'R'){
			c[3]++;
		}
	}

	printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d\n",c[0],c[1],c[2],c[3]);

	return 0;
}


Measured memory_bytes: 1732
module ArrayL = ArrayLabels
module ListL = ListLabels

let dbg = Printf.printf "[debug]%s"

let max_num = 100_000_000_000

let id = fun x -> x
let tuple2 x y = (x,y)
let tuple3 x y z = (x,y,z)
let succ x = x + 1
let pred x = x - 1

let (++) n m =
  let rec aux i =
    if i = m then [m]
    else i :: aux (i+1) in
  if n > m then [] else aux n

let (++^) n m = n ++ (m-1)

let scan fmt f = Scanf.sscanf (read_line ()) fmt f

let scan_lines n fmt f =
  List.map (fun _ -> scan fmt f) (0++^n)

let scan_matrix n m e conv =
  let arr = Array.make_matrix n m e in
  Array.iteri (fun i line ->
      let s = Scanf.Scanning.from_string @@ read_line () in
      Array.iteri (fun j _ ->
          arr.(i).(j) <- Scanf.bscanf s " %s" conv;
        ) line) arr; arr

let between n x m = n <= x && x < m

let string_to_list s =
  List.map (String.get s) (0 ++^ String.length s)

let () =
  let rec aux n i =
    if n = 1 then
      Printf.printf "\n"
    else if i * i > n then
      Printf.printf " %d\n" n
    else if n mod i = 0 then
      (Printf.printf " %d" i;
       aux (n/i) i)
    else aux n (succ i)
  in
  let n = scan "%d" id in
  Printf.printf "%d:" n;
  aux n 2



Measured memory_bytes: 2428
#include <algorithm>
typedef long long ll;

#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>

using namespace std;

template<class T>
T gcd(T a, T b){
  if(a > b) swap(a, b);
  if(a == 0) return b;
  return gcd(b % a, a);
}

int main(){
  const ll n = getInt();

  for(ll i = 1; i <= 3500; i++){
    ll aa = n;
    ll bb = 4;
    ll ii = gcd(i, aa);
    aa = aa * i / ii;
    bb = bb * i / ii;

    for(ll j = i; j <= 3500; j++){
      ll a = aa;
      ll b = bb;

      ll jj = gcd(j, a);
      a = a * j / jj;
      b = b * j / jj;

      b -= a / i;
      b -= a / j;

      if(b < 0) continue;

      ll d = gcd(a, b);
      a /= d;
      b /= d;

      if(b > a) break;

      if(b == 1){
        printf("%lld %lld %lld\n", i, j, a);
        return 0;
      }
    }
  }

  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

#define N 8
#define FREE -1
#define NOT_FREE 1

//#ifndef Boolean
#define Boolean int
//#endif
#define true 1
#define false 0

int row[N], col[N], dpos[2*N-1], dneg[2*N-1];

Boolean X[N][N];

void initialize(){
  int i;
  for(i=0; i<N; i++){
    row[i] = FREE;
    col[i] = FREE;
  }
  for(i=0; i<2*N-1; i++){
    dpos[i] = FREE;
    dneg[i] = FREE;
  }
}

void printBoard(){
  int i, j;
  for(i=0; i<N; i++){
    for(j=0; j<N; j++){
      if(X[i][j]){
	if(row[i]!=j) return;
      }
    }
  }
  for(i=0; i<N; i++){
    for(j=0; j<N; j++){
      if(row[i]==j) printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}

void recursive(int i){
  int j;
  if(i==N){
    printBoard();
    return;
  }
  for(j=0; j<N; j++){
    if(NOT_FREE==col[j]||NOT_FREE==dpos[i+j]||NOT_FREE==dneg[i-j+N-1]) continue;
    row[i] = j;
    col[j] = dpos[i+j] = dneg[i-j+N-1] = NOT_FREE;
    recursive(i+1);
    row[i] = col[j] = dpos[i+j] = dneg[i-j+N-1] = FREE;
  }
}

int main(){
  int i, j, k, r, c;
  
  initialize();

  for(i=0; i<N; i++){
    for(j=0; j<N; j++) X[i][j]=false;
  }

  scanf("%d", &k);

  for(i=0; i<k; i++){
    scanf("%d%d", &r, &c);
    X[r][c] = true;
  }

  recursive(0);

  return 0;
}



Measured memory_bytes: 2112
def calc(n):
    damage = (b * n)
    d = [max(dd - damage, 0) for dd in h]
    a_num = 0
    for i in range(len(d)):
        a_num += max(0, 1 + (d[i]-1) // (a - b))
    if a_num <= n:
        return True
    return False

n, a, b = map(int, input().split())
h = []
for _ in range(n):
    h.append(int(input()))
ans = 0
h.sort()

left = 0
right = 10000000000

while (right - left) > 1:
    middle = (left + right) // 2
    if calc(middle):
        right = middle
    else:
        left = middle
print(right)

Measured memory_bytes: 10932
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cctype>
#include <map>

const int INT_INF = 1000000000;                 // 10^9
const long long LONG_INF = 1000000000000000000; // 10^18

using namespace std;

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

    bool f = false;
    for (int i = 1; i < 10; i++)
    {
        float m = n / i;
        if (m < 10 && n % i == 0)
        {
            f = true;
        }
        if (f)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int result = 0;
    int[] a = new int[n];
    for (int i = 0; i < n; i++) {
      a[i] = scan.nextInt();
    }
    int correct = 0;
    int cmp = 1;
    for (int i = 0; i < n; i++) {
      if (a[i] != cmp) {
        result++;
      }

      if (a[i] == cmp) {
        cmp++;
        correct++;
      }
    }

    if (correct == 0) {
      System.out.println("-1");
    } else {
      System.out.println(String.valueOf(result));
    }
  }
}


Measured memory_bytes: 66888
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std ;
#define int                 long long
#define ull                 unsigned long long int
#define ld                  long double
#define vi                  vector<int>
#define vii                 vector<pair<int,int>>
#define vvi                 vector<vector<int>>
#define pii                 pair<int,int>
#define prec(x)             fixed<<setprecision(15)<<x
#define all(x)              x.begin(),x.end()
#define rall(x)             x.rbegin(),x.rend()
#define rev(x)              reverse(x.begin(),x.end())
#define mset(a,b)           memset(a,b,sizeof(a))
#define mcpy(a,b)           memcpy(a,b,sizeof(a))
#define fo0(i,n)            for(int i=0,i##end=n;i<i##end;i++)
#define fo1(i,n)            for(int i=1,i##end=n;i<=i##end;i++)
#define fo(i,a,b)           for(int i=a,i##end=b;i<=i##end;i++)
#define foe(i,x)            for(__typeof((x).end())i=(x).begin();i!=(x).end();++i)
#define fre(i,x)            for(__typeof((x).rend())i=(x).rbegin();i!=(x).rend();++i)
#define mk(arr,n,type)  	type *arr=new type[n];
#define dbg(x) cerr << #x << " is " << x << endl;
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0)
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
clock_t beg = clock();
const int inf=1e18;const int mod=1e9+7;const int N=2e5+9;
const double pi = 3.1415926535897932384626433;
void FILE_IO(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}

void JH(){
    int d=0,e=0,f=0,g=0,p=0,w=0,flag=0,ans=INT_MAX,res=0,cnt=0,sum=0;double f1=0.0,f2=0.0,f3=0.0;
    int x,n;cin>>x>>n;
    int a[n];
    set<int> s;
    fo0(i,n){
    	cin>>a[i];
    	s.insert(a[i]);
    }
    if(s.size()==0){
    	cout<<x;
    	return;
    }
    for(int i=x+102;i>=x-102;i--){
    	if(s.find(i)==s.end()){
    		if(abs(x-i)<=ans){
    			ans=abs(x-i);
    			res=i;
    		}
    	}
    }
    cout<<res;
}

int32_t main()
{
    FILE_IO();FAST_IO;int t=1;
    // cin>>t;
    while(t--){JH();}cerr<<(double)(clock()-beg)/1000<<"s ";
}

Measured memory_bytes: 3844
using System;
using System.Collections.Generic;

namespace ALDS1_3_B
{
    class Program
    {
        struct Proc
        {
            public string name;
            public int time;
        }
        static void Main(string[] args)
        {
            var queue = new Queue<Proc>();
            string[] line = Console.ReadLine().Split(' ');
            int n = int.Parse(line[0]);
            int q = int.Parse(line[1]);
            for (int i = 0; i < n; i++)
            {
                line = Console.ReadLine().Split(' ');
                queue.Enqueue(new Proc() { name = line[0], time = int.Parse(line[1]) });
            }
            RoundRobin(queue, q);
        }

        static void RoundRobin(Queue<Proc> queue, int quantum)
        {
            int timestamp = 0;
            while (queue.Count > 0)
            {
                var top = queue.Dequeue();
                timestamp += top.time < quantum ? top.time : quantum;
                if (top.time <= quantum) Console.WriteLine("{0} {1}",top.name,timestamp);
                else
                {
                    top.time -= quantum;
                    queue.Enqueue(top);
                }
            }
        }
    }
}

Measured memory_bytes: 15932
#include <iostream>
#include <vector>
//#include <string>
//#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1

int main() {
    LL n;
    LL d;
    LL x;
    cin >> n;
    cin >> d >> x;
    vector<LL> a(n);
    for(LL i=0; i<n; i++){
        cin >> a[i];
    }
    LL ans=x;
    for(LL i=0; i<n; i++){
        for(LL j=1; j<=d; j++){
            if((j-1)%a[i]==0){
                ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3648
N = int(input())
A = list( map(int,input().split()) )
B = list( map(int,input().split()) )

BeforeA = sum(A)

for i in range(N):
    # まずは同じ番号の町のモンスター倒す
    if B[i] - A[i] > 0:
        # 余力があるなら次の町のモンスター倒す
        B[i] -= A[i]
        A[i] = 0
        if A[i+1] - B[i] >0:
            A[i+1] -= B[i]
        else:
            A[i+1] = 0
    else:
        A[i] -= B[i]

AfterA = sum(A)

print(BeforeA - AfterA)

Measured memory_bytes: 19116
/* AOJ 0075
 *
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0075
 *
 */

#include <stdio.h>

int main(){
    int id;
    float w, h;


    while(scanf("%d,%f,%f", &id, &w, &h) == 3){
        if(w/(h*h) >= 25.0){
            printf("%d\n", id);
        }
    }

    return 0;
}

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

bool res[100001];

int main() {
    #ifdef DEBUG
        freopen("in.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

    int n, a, b; cin >> n >> a >> b;
    string s; cin >> s;

    int passed = 0;
    int b_rank = 1;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'a') {
            if (passed < a + b) {
                res[i] = true;
                passed++;
            }
        } else if (s[i] == 'b') {
            if (passed < a + b && b_rank <= b) {
                res[i] = true;
                passed++;
                b_rank++;
            }
        }
    }

    for (int i = 0; i < n; i++) {
        cout << (res[i] ? "Yes" : "No") << '\n';
    }

    return 0;
}


Measured memory_bytes: 976
#include<stdio.h>

int main()
{
  long n, i;
  long sum = 0;
  
  scanf("%ld", &n);
  
  for(i = 1; i <= n; i++)
  {
    if((i % 3 != 0) && (i % 5 != 0))
    {
      sum += i;
    }
  }
  
  printf("%ld", sum);
  
  return 0;
}

Measured memory_bytes: 1728
import java.util.*;
import java.math.*;
import java.text.*;

public class Main {
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		while(true){
			int n=in.nextInt();
			if(n==0) break;
			int k=2, d=1, ans=1, a=n;
			while(n>k){
				d=1;
				int t=1;
				while(n%k==0){
					n=n/k;
					t=t*k;
					d=d+t;
				}
				k++;
				if(d!=1) ans=ans*d;
			}
			if(n!=1) ans = ans*(n+1);
			if(ans>a*2) System.out.println("abundant number");
			else if(ans==a*2) System.out.println("perfect number");
			else System.out.println("deficient number");
		}
	}
}

Measured memory_bytes: 12000
// -*- coding:utf-8-unix -*-

use proconio::input;

fn main() {
    input! {
        n: usize,
        x: [i64; n],
    }

    let sum_p = x.iter().sum::<i64>() as f64;
    let p = (sum_p / n as f64).round() as i64;
    // println!("{} {}", sum_p, p);
    let mut ans = 0;
    for v in &x {
        ans += (*v - p).pow(2);
    }
    println!("{}", ans);
}


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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define INTMAX 1000000000

using namespace std;
typedef long long ll;
typedef pair<ll ,ll> P;
const ll mod = 1e9+7;
const long double EPS = 0.0000000001;

ll a,b,n;
int main(){
	cin >> n;
	if(n % 2 == 0)cout << n/2 << endl;
	else cout << (n+1)/2 << endl;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void) {
	int i, j, M, N;
	int a[100], b[100], c[100], d[100], dis[100], p[100];

	scanf("%d%d", &N, &M);
	for (i=0;i<N;i++) scanf("%d%d", &a[i], &b[i]);
	for (j=0;j<M;j++) scanf("%d%d", &c[j], &d[j]);

	for (i=0;i<N;i++) {
		dis[i] = abs(a[i]-c[0])+abs(b[i]-d[0]);
		p[i] = 0;
		for (j=1;j<M;j++) {
			if (dis[i] > abs(a[i]-c[j])+abs(b[i]-d[j])) {
				dis[i] = abs(a[i]-c[j])+abs(b[i]-d[j]);
				p[i] = j;
			}
		}
	}
	for (i=0;i<N;i++) printf("%d\n", p[i]+1);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
using namespace std;
using ll = long long;
int main(){
  int H, W;
  cin >> H >> W;
  vector<vector<int>> g(H + 5, vector<int>(W + 5));
  vector<vector<int>> dp(H + 5, vector<int>(W + 5, 1001001));
  for(int h = 0; h < H; h++) {
    for(int w = 0; w < W; w++){
      char c;
      cin >> c;
      if(c == '.'){
        g[h][w] = 1;
      }else{
        g[h][w] = 0;
      }
    }
  }
  int flag = 0;
  int ans = 0;
  if(g[0][0] == 0){
    dp[0][0] = 1;
  }else{
    dp[0][0] = 0;
  }
  for(int h = 0; h < H; h++) {
    for(int w = 0; w < W; w++){
      int i = h;
      while(i < H && g[i][w] == g[h][w]){
        dp[i][w] = min(dp[i][w], dp[h][w]);
        i++;
      }
      i = w;
      while(i < W && g[h][i] == g[h][w]){
        dp[h][i] = min(dp[h][i], dp[h][w]);
        i++;
      }
      if(g[h + 1][w] + g[h][w] == 1){
        dp[h + 1][w] = min(dp[h + 1][w], dp[h][w] + 1);
      }
      if(g[h][w + 1] + g[h][w] == 1){
        dp[h][w + 1] = min(dp[h][w + 1], dp[h][w] + 1);
      }
    }
  }
  cout << (dp[H - 1][W - 1] + 1) / 2 << '\n';

  return 0;
}

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

int main()
{
  int a, b;
  cin >> a >> b;
  int cnt = 0;
  for (int i = a; i <= b; i++)
  {
    int j1, j2, j3, j4;
    j1 = i / 10000;
    j2 = (i - j1 * 10000) / 1000;
    j3 = (i % 100) / 10;
    j4 = i % 10;
    if (j4 == j1 && j2 == j3)
    {
      cnt++;
    }
  }
  cout << cnt << endl;
}


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



int main(){
	stack<int> S1;
	stack<pair<int, int> > S2;
	char ch;
	int sum = 0;
	for (int i = 0; cin >> ch; i++ ) {
		if (ch == '\\') S1.push(i);
		else if (ch == '/' && S1.size() > 0) {
			int j = S1.top();S1.pop();
			sum += i - j;
			int a = i - j;
			while(S2.size() > 0 && S2.top().first > j) {
				a += S2.top().second; S2.pop();
			}
			S2.push(make_pair(j,a));
		}
	}

	vector<int> ans;
	int t = 0;
	while (S2.size() > 0) {ans.push_back(S2.top().second); S2.pop();}
	reverse(ans.begin(), ans.end());
	cout << sum << endl;
	cout << ans.size();
	for (int i = 0; i < ans.size(); i++ ) {
		cout << " ";
		t += ans[i];
		cout << ans[i];
	}
	cout << endl;
	return 0;
}



Measured memory_bytes: 3240
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
ll dx[4] = { 0, 1, 0, -1 };
ll dy[4] = { 1, 0, -1, 0 };
const ll INF = 1e14;
const ll MOD = 1e9 + 7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    double W, H, x, y;
    cin >> W >> H >> x >> y;
    printf("%lf %d\n", W * H / 2, 2 * x == W && 2 * y == H);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m,x,y,a,b;
int main(){
	int minb=200,maxa=-200;
	cin>>n>>m>>x>>y;
	for(int i=0;i<n;i++)
		cin>>a,maxa=max(maxa,a);
	for(int i=0;i<m;i++)
		cin>>b,minb=min(minb,b);
	for(int i=x+1;i<y;i++){
		if(maxa<i && minb>=i){
			cout<<"No War";
			return 0;
		}
	}
	cout<<"War";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
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; }
const int INF = 1e9;
const LL LLINF = 1e16;

template<int mod>
struct ModInt {
    int x;

    ModInt() : x(0) {}
    ModInt(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

    ModInt &operator+=(const ModInt &p) {
        if((x += p.x) >= mod) x -= mod;
        return *this;
    }
    ModInt &operator-=(const ModInt &p) {
        if((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }
    ModInt &operator*=(const ModInt &p) {
        x = (int)(1LL * x * p.x % mod);
        return *this;
    }
    ModInt &operator/=(const ModInt &p) {
        *this *= p.inverse();
        return *this;
    }

    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }

    ModInt inverse() const{
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) {
            t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return ModInt(u);
    }

    friend ostream &operator<<(ostream &os, const ModInt<mod> &p) {
        return os << p.x;
    }
    friend istream &operator>>(istream &is, ModInt<mod> &a) {
        long long x;
        is >> x;
        a = ModInt<mod>(x);
        return (is);
    }
};

const int mod = 1e9 + 7;
using modint = ModInt< mod >;

// A
// C
// G
// T
modint dp[110][4][4][4];
int main(){
    int n;
    cin >> n;

    rep(i, 4) dp[1][3][3][i] = 1;
    REP(i, 1, n){
        rep(j, 4)rep(k, 4)rep(l, 4)rep(m, 4){
            int add = 0;
            if(j==0 && k==2 && m==1) continue;
            if(k==0 && l==1 && m==2) continue;
            if(k==0 && l==2 && m==1) continue;
            if(j==0 && l==2 && m==1) continue;
            if(k==2 && l==0 && m==1) continue;
            dp[i+1][k][l][m] += dp[i][j][k][l];
        }
    }
    modint ans = 0;
    rep(j, 4)rep(k, 4)rep(l, 4){
        ans += dp[n][j][k][l];
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n, m;
	cin >> n >> m;
	
	vector<int> table(n + 1, 0);
	for(int i = 0; i < m; ++i) {
		int L, R;
		cin >> L >> R;
		
		table[L - 1]++;
		table[R]--;
	}
	
	for(int i = 1; i <= n; ++i) {
		table[i] += table[i - 1];
	}
	
	int ans = 0;
	for(int i = 0; i < n; ++i) {
		if( m == table[i] ) ans++;
	}
	
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define M ((int)1e9+7)
vector<int> adj[200000];
bool vis[200000];
int dfs(int node)
{
	if(vis[node])	return 0;
	int ans=1;
	vis[node]=true;
	for(int i=0;i<adj[node].size();i++)
	{
		ans+=dfs(adj[node][i]);
	}
	return ans;
}
int main() {
    // your code goes here
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
    	int a,b;
    	cin>>a>>b;
    	adj[a-1].push_back(b-1);
    	adj[b-1].push_back(a-1);
    }
    int ans=0;
    memset(vis,false,sizeof(vis));
    for(int i=0;i<n;i++)
    {
    	if(vis[i])	continue;
    	ans=max(ans,dfs(i));
    }
    cout<<ans;
    return 0;
}

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

int main() {
    int a, b;
    cin >> a >> b;
    int ans = 0;
    for (int i = a; i <= b; i++) {
        bool flag = true;
        string s = to_string(i);
        for (int j = 0; j < 2; j++) {
           if (s[j] != s[4-j]) {
               flag = false;
           } 
        }
        if (flag) ans++;
    }
    cout << ans << endl;
}

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

//Sを後ろから読んでいくと全部区別できるぜ！
//.substr(開始位置, 取り出す長さ)

int main() {
    string S;
    cin >> S;
    
    reverse(S.begin(), S.end());
    
    vector<string> divide = {"dream", "dreamer", "erase", "eraser"};
    for (int i=0; i<4; i++) reverse(divide[i].begin(), divide[i].end());
    
    bool can = false;
    
    for (int i=0; i<S.size();) {
        
        for (int j=0; j<4; j++) {
            can = S.substr(i, divide[j].size()) == divide[j];
            if (can) {
                i += divide[j].size();
                break;
            }
        }
        
        if (!can) {
            cout << "NO" << endl;
            return 0;
        }
        
    }
    
    cout << "YES" << endl;
        
}


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

lint n, a, b;

int main() {
    cin >> n >> a >> b;
    lint c = a + b;
    lint ans = 0;
    ans += (n / c) * a;
    n %= c;
    ans += min(a, n);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
using namespace std;

const int e[] = {1, 10, 9, 12, 3, 4};
const int N = 1e5+5, mod = 1e9+7;

int n, f[N][20];
char s[N];

int main()
{
    cin >> s; n = strlen(s);
    reverse(s, s+n);
    f[0][0] = 1;
    for(int i=0; i<n; ++i) if (s[i] == '?') {
        for(int j=0; j<13; ++j) for(int x=0; x<10; ++x){
            int k = (j + x*e[i%6]) % 13;
            f[i+1][k] = (f[i+1][k] + f[i][j]) % mod;
        }
    } else {
        int x = s[i] - '0';
        for(int j=0; j<13; ++j) {
            int k = (j + x*e[i%6]) % 13;
            f[i+1][k] = (f[i+1][k] + f[i][j]) % mod;
        }
    }
    cout << f[n][5];
}


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

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef vector<pii> vii;


#define mod 1000000007
#define INF 1e9+100
#define ff first
#define ss second
#define cy cout<<"YES"<<endl;
#define cn cout<<"NO"<<endl;
#define urs(r...)          typename decay<decltype(r)>::type
#define fi(i,n)                for(urs(n) i=0;i<n;i++)
#define rep(i,n)               for(urs(n) i=1;i<=n;i++)
#define pb push_back
#define gap ' '
#define endl '\n'
#define mex 300000
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>*/
main()
{
	int i,j,n,m,t;
	int r;
   cin>>n;
   int a[n+3];
   fi(i,n-1) cin>>a[i];
   map<int,int>b;
   fi(i,n-1)
   {
   	b[a[i]]++;
   }
   for(i=1;i<=n;i++) cout<<b[i]<<endl;
}


Measured memory_bytes: 17696
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	double x[n];
	string u[n];
	for(int i=0;i<n;i++){
		cin>>x[i]>>u[i];
	}
	double ans=0;
	for(int i=0;i<n;i++){
		if(u[i]=="JPY"){
			ans+=x[i];
		}
		else if(u[i]=="BTC"){
			ans+=x[i]*380000.0;
		}
	}
	cout<<ans;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        String line1 = sc.nextLine();
        String[] array = line1.split(" ");
        
        int n = Integer.parseInt(array[0]);
        int k = Integer.parseInt(array[1]);
        
        int[] sunuke = new int[n];
        
        for(int i = 0; i < k; i++)
        {
            String buf1 = sc.nextLine();
            int ninzu = Integer.parseInt(buf1);
            String buf2 = sc.nextLine();
            String[] okasimoti = buf2.split(" ");
            
            for(int j = 0; j < ninzu; j++)
            {
                int buf3 = Integer.parseInt(okasimoti[j]);
                sunuke[buf3 - 1]++;
            }
        }
        
        int count = 0;
        for(int i = 0; i < n; i++)
        {
            if(sunuke[i] == 0)
            {
                count++;
            }
        }
        
        
        System.out.println(count);
    }
}


Measured memory_bytes: 37512
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n, a, b; cin >> n >> a >> b;
  cout << min(a * n, b) << '\n';
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
p=a[:]
d=max(p)
c=0
for i in range(d):
    k=0
    for i in range(n):
        if a[i]>0:
            if k==0:
                c+=1
                k=1
            a[i]-=1
        else:
            k=0
print(c)

Measured memory_bytes: 3060
"""
AtCoder Grand Contest 041  B - Voting Judges


N個の問題があり、M人がそれぞれV問に１点足していく。同じ人が同じ問題に点は入れられない。
全員が点を入れた後、得点の大きいものからP個選ばれる。
選ばれうる可能性のある問題の個数を考える。

例えば1,2,3,4,5,6,7,8,9,10として、３人が４問に加点するのを考える。その後４問が選ばれるとする
５がえらばれうるか考えてみる。
５に３点入れて、残りは５未満に足しておけば８に並ぶので選ばれうる。
上位一位にいくより上位４位にはいる方が縛りが緩そう。１～４のどこにいてもいいので。

なので、とりあえず４位になることを目標とする。
４位になるには上位３位の10,9,8には負けててもいいが、少なくとも７に並ぶ必要がある。
また、投票者が３人なので、多くても＋３しかされない。

とりあえず５にとって最善の＋３した場合を考える。
このときに７に＋２とか６に＋３とかされて８を上回られると選ばれない。
なので、５的には、自分に最大に点を割り振って、残りは順位に影響ないところで使いつぶすのが嬉しい。

１～４について、＋３しても順位に影響ないから、これらには割り振る。
８～１０についても、５的には４位に入ることができたら問題ないので、これらについても＋３して問題ない。
ついで、６，７であるが、これが９になると５は勝てないので、こいつらには＋した結果でも８にとどまってほしい。

こんな感じで、P位になるためにある数字に最大に割り振って、残りを使いつぶす。
で、全体でM*V点持っていて、使いつぶしたときにこれを使い切っていなければ、今回でいうところの６とか７に振るしかなくなる。
そのときは選ばれる可能性がない。
みたいな？

"""
import bisect


N,M,V,P = map(int, input().split())
A = list(map(int, input().split()))

A.sort(reverse=True)

l = P - 1
r = N
while r - l > 1:
    mid = (l + r) // 2

    curr_max = A[mid] + M
    if curr_max < A[P-1]:
        r = mid
        continue

    cnt = 0
    # P位になれればよいので、P位以降に対して見る
    for i in range(P-1, N):
        if i == mid:
            continue
        # A[mid]以下の値は＋MしてOK、それ以外はcurr_maxと同じ値までは＋してよい
        cnt += min(M, max(0, curr_max - A[i]))

    # 上位P-1とA[mid]に振った分をのぞいて、都合いい感じに振ったものが、余りを上回れば、選ばれうる
    if cnt >= M * (V - P):
        l = mid
    else:
        r = mid

# lがギリギリ選ばれるもののインデックス（下限）なので、+1して要素数というか個数にする
print(l + 1)

Measured memory_bytes: 15020
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

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

    vector<vector<vector<int>>> k(4,vector<vector<int>>(3,vector<int>(10,0)));

    int a,b,c,d;
    for (int h = 0; h < n; ++h) {
        cin >> a >> b >> c >> d;
        k.at(a - 1).at(b - 1).at(c - 1) += d;
    }

    for (int e = 0; e < 4; ++e) {
        for (int f = 0; f < 3; ++f) {
            for (int g = 0; g < 10; ++g) {
                cout << " " << k.at(e).at(f).at(g);
            }
            cout << endl;
        }
        if(e != 3)
            cout << "####################" << endl;
   }

    return 0;
}

Measured memory_bytes: 3092