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

int main(){
    int w, d;
    while(cin >> w >> d, w){
        vector<int> h1(w + 1), h2(d + 1);
        for(int k = 0 ; k < w ; ++k){
            cin >> h1[k];
        }
        for(int k = 0 ; k < d ; ++k){
            cin >> h2[k];
        }
        sort(h1.begin(), h1.end());
        sort(h2.begin(), h2.end());
        int i = w, j = d;
        int ans = 0;
        while(i > 0 || j > 0){
            if(h1[i] == h2[j]){
                ans += h1[i];
                --i;
                --j;
            }else if(h1[i] < h2[j]){
                ans += h2[j];
                --j;
            }else{
                ans += h1[i];
                --i;
            }
        }
        cout << ans << endl;
    }
}


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

using namespace std;
using llong = long long;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	string s,t;
	cin >> s >> t;
	if(s[0] == t[2] && s[1] == t[1] && s[2] == t[0])
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 256
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

class BIT:
    '''
    a[1]~a[n]の数列を想定
    '''

    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def add(self, index, x):
        '''
        a[index]にxを加算
        '''
        while index <= self.size:
            self.tree[index] += x
            index += index & (-index)
 
    def sum(self, index):
        '''
        a[1]~a[index]の和
        '''
        s = 0
        while index:
            s += self.tree[index]
            index -= index & (-index)
        return s
 
    def search(self, value):
        '''
        sum(index)>=value を満たす最小のindex
        sum(n)<value のとき n+1 を返す
        '''
        i = 0
        s = 0
        step = 1 << (self.size.bit_length() - 1)
        while step:
            if i + step <= self.size and s + self.tree[i + step] < value:
                i += step
                s += self.tree[i]
            step //= 2
        return i + 1
        
        
def index_sort(A,reverse=False):
    x = []
    for i,a in enumerate(A):
        x.append((a,i))
    if reverse:
        return sorted(x, key=lambda x: -x[0])
    else:
        return sorted(x, key=lambda x: x[0])

      
N = I()
P = III()

bit = BIT(N)
x = index_sort(P,True)

ans = 0
for i in range(N):
    index = x[i][1]
    if index>=1:
        L = bit.sum(index)
    else:
        L = 0
    wi = bit.search(L-1) if L>=2 else 0
    xi = bit.search(L) if L>=1 else 0

    R = bit.sum(N)-bit.sum(index+1)
    yi = bit.search(L+1)
    zi = bit.search(L+2)

    ci = (xi-wi)*(yi-index-1) + (index+1-xi)*(zi-yi)
    ans += ci*x[i][0]
    bit.add(index+1, 1)

print(ans)

Measured memory_bytes: 66080
#include<iostream>
#include<math.h>

using namespace std;
using P=pair<int,int>;

int main(){
    long long n;
    cin>>n;
    int ans=0;
    int q = sqrt(n);
    for (int i = 2; i <= q; i++) {
        int cnt = 0;
        while (n % i == 0){
            n /= i;
            cnt++;
        }
        if (cnt > 0) {
            int tmp = 1;
            while (cnt >= tmp) {
                ans++;
                cnt -= tmp;
                if (cnt <= tmp) break;
                tmp++;
            }
        }
    }
	if (n > 1) ans++;
	printf("%d\n", ans);
}

Measured memory_bytes: 3712
def main():
    D = int(input())
    C = [int(x) for x in input().split()]
    S = []
    for _ in range(D):
        S.append([int(x) for x in input().split()])
    for i in range(D):
        print(S[i].index(max(S[i]))+1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 68176
import java.util.*;

public class Main {
    static int MAX = 510000;
    static int MOD = 1000000007;
    static long[] fac = new long[MAX];
    static long[] finv= new long[MAX];
    static long[] inv = new long[MAX];
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        COMinit();
        for (int i=1;i<=k;i++){
            System.out.println(HCOM(k-i+1,i-1)*HCOM(n-k-i+2,i)%MOD);
        }
    }
    static void COMinit(){
        fac[0]=1;
        fac[1]=1;
        finv[0]=1;
        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;
        }
    }
    static 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;
    }
    static long HCOM(int n, int k){
        return COM(n+k-1,k);
    }
}


Measured memory_bytes: 48496
N = int(input())

# N枚の餅のサイズを受け取る
d = []
for i in range(N):
  d.append(int(input()))
  d.sort()

count = 0
for i in range(N-1):
  if d[i] < d[i+1]:
    count += 1

print(count + 1)

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

struct node{
  int par, left, right;
};

node t[10000];

void preoder(int u){
  if(u == -1) return;
  cout << " " << u;
  preoder(t[u].left);
  preoder(t[u].right);
}

void inorder(int u){
  if(u == -1) return;
  inorder(t[u].left);
  cout << " " << u;
  inorder(t[u].right);
}

void postorder(int u){
  if(u == -1) return;
  postorder(t[u].left);
  postorder(t[u].right);
  cout << " " << u;
}

int main(){

  int n;
  int id, l, r;

  cin >> n;
  for(int i = 0; i < n; i++) t[i].par = -1;
  for(int i = 0; i < n; i++){
    cin >> id >> l >> r;
    t[id].left = l;
    t[id].right = r;
    if(l != -1) t[l].par = id;
    if(r != -1) t[r].par = id;
  }
  int root;
  for(int i = 0; i < n; i++) if(t[i].par == -1) root = i;

  cout << "Preorder" << endl;
  preoder(root);
  cout << endl;

  cout << "Inorder" << endl;
  inorder(root);
  cout << endl;

  cout << "Postorder" << endl;
  postorder(root);
  cout << endl;

  return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const ll MOD = 1000000007;
const double EPS = 1e-9;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;


int main(void) {

    
    int n,m;
    cin>>n>>m;
    if(n==m)fin("Yes");
    else fin("No");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> v;
  vector<string> ans;
  function<void(int, int)> dfs = [&](int cur, int mx) {
    if(cur == N) {
      string tmp(N, ' ');
      rep(i, N) tmp[i] = 'a'+v[i];
      ans.push_back(tmp);
      return;
    }
    for(int i=0; i<=mx+1; i++) {
      v.push_back(i);
      dfs(cur+1, max(mx, i));
      v.pop_back();
    }
  };
  dfs(0, -1);
  for(string s: ans) cout << s << "\n";
  return 0;
}


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

const int64_t MOD = 1000000007;
typedef int64_t ll;
typedef uint64_t ull;

#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  uint64_t g = gcd(m,n);
  if(m%g==0) return (m/g)*n;
  if(n%g==0) return (n/g)*m;
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

/* 
  //エラトステネスのふるい
  int maxNum = 100000;
  char isNotPrime[maxNum+1] = {};
  isNotPrime[0]=isNotPrime[1]=1;
  for(int i=2;i<maxNum;i++){
    if(isNotPrime[i]==1) continue;
    int num = i+i;
    while(num<=maxNum){
      isNotPrime[num]=1;
      num += i;
    }
  }
*/
// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

// 降順ソート vector<int> v;
// sort(v.begin(),v.end(),greater<int>());

signed main() {
  string s;
  cin >> s;

  bool failed = false;
  while(s.length()>=5 && false == failed){
    string last5Str = s.substr(s.length()-5);
    if(last5Str=="dream"
       ||last5Str=="erase"){
      s = s.substr(0,s.length()-5);
      continue;
    }
    if(s.length()>=6
       &&s.substr(s.length()-6)=="eraser"){
        s = s.substr(0,s.length()-6);
      continue;
    }
    if(s.length()>=7
       &&s.substr(s.length()-7)=="dreamer"){
        s = s.substr(0,s.length()-7);
      continue;
    }
    failed = true;
  }
  // dream,dreamer
  // erase,eraser
  
  if(failed) cout << "NO" << endl;
  else cout << "YES" << endl;

  return 0;
}



Measured memory_bytes: 3856
#include<iostream>
using namespace std;
#define endl '\n'

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int x1, x2, x3, x4, x5;
    int c0=0,c1=1,c2=2,c3=3,c4=4,c5=5;
    cin >> x1 >> x2 >> x3 >> x4 >> x5;
    if(x1==1||x2==1||x3==1||x4==1||x5==1){
        c1 = 6;
    }
    if(x1==2||x2==2||x3==2||x4==2||x5==2){
        c2 = 6;
    }
    if(x1==3||x2==3||x3==3||x4==3||x5==3){
        c3 = 6;
    }
    if(x1==4||x2==4||x3==4||x4==4||x5==4){
        c4 = 6;
    }
    if(x1==5||x2==5||x3==5||x4==5||x5==5){
        c5 = 6;
    }
    if(x1==0||x2==0||x3==0||x4==0||x5==0){
        c0 = 6;
    }
    if(c1!=6)
        cout << "1" << endl;
    if(c2!=6)
        cout << "2" << endl;
    if(c3!=6)
        cout << "3" << endl;
    if(c4!=6)
        cout << "4" << endl;
    if(c5!=6)
        cout << "5" << endl;
}

Measured memory_bytes: 3644
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

signed main(){
	cout<<fixed<<setprecision(10);
	
	int x[100] ={0,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};
	
	int K;
	
	cin>>K;
	
	cout<<x[K]<<endl;
	
	
	return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (n, a, b) = readLine()!!.split(" ").map(String::toInt)
    var num = 0
    for(i in 0..n) {
        val iStr = i.toString()
        var sum = 0
        for(j in 0..iStr.length - 1) {
            val iInt = iStr[j].toString().toInt()
            sum = sum + iInt
        }
        if(sum >= a && sum <= b) {
            num += i
        }
    }
    println(num)
}

Measured memory_bytes: 38664
n=int(input())
lw=[input() for i in range(n)]
used=set()
cond=True
last=lw[0][0]
for w in lw:
    if w in used or last !=w[0]:
        cond=False
        break
    used.add(w)
    last=w[-1]
print("Yes" if cond else "No")

Measured memory_bytes: 9184
n,k=map(int,input().split())
p=list(map(int,input().split()))
f=lambda x:0.5*(x+1)
pp=list(map(f,p))
t=[0]*(n+1)
for i in range(n):
    t[i+1]=t[i]+pp[i]
ans=0
for i in range(n-k+1):
    ans=max(ans,t[i+k]-t[i])
print(ans)

Measured memory_bytes: 81800
#include<stdio.h>

int main(void)
{
	int a,b,c,n;
	
	scanf("%d %d %d",&a,&b,&c);
	
	if(a>b){
		n=a;
		a=b;
		b=n;
	}
	if(b>c){
		n=b;
		b=c;
		c=n;
	}
	if(a>b){
		n=a;
		a=b;
		b=n;
	}
	printf("%d %d %d\n",a,b,c);
	
	return 0;
}

Measured memory_bytes: 2708
#include <bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
 
#define endl '\n'
#define loop(i, m, n) for (ll i = m; i < n; i++)
#define loope(i, m, n) for (ll i = m; i <= n; i++)
#define epool(i, m, n) for (ll i = m; i >= n; i--)
#define mod 1000000007
#define mod2 998244353
#define vi vector<ll>
#define pll pair<ll, ll>
#define fi first
#define se second
#define pb push_back
#define MP make_pair
#define empf emplace_front
#define empb emplace_back
#define ret(x) return cout << x,0;
#define all(v) v.begin(),v.end()
#define maxheap priority_queue<ll>
#define minheap priority_queue<ll,vector<ll>,greater<ll>>
const ll INF=1e18;
const double PI=4*atan(1);

#define SpeedForce                    \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
using namespace std;

ll mpow(ll base,ll exp);
ll POW(ll base,ll exp);
ll gcd(ll a,ll b);
ll modInverse(ll n);
ll nCr(ll n, ll r);

void solve(){
    ll n;
    cin >> n;
    map<string,ll> mp;
    loop(i,0,n){
        string s;
        cin >> s;
        mp[s]++;
    }

    cout << "AC x " << mp["AC"] << endl;
    cout << "WA x " << mp["WA"] << endl;
    cout << "TLE x " << mp["TLE"] << endl;
    cout << "RE x " << mp["RE"] << endl;

}

int32_t main(){
    SpeedForce
    ll i = 0,j = 0;


    int t;
    t=1;
    //cin >> t;
    //ll cnt=1;
    while (t--){
        //cout << "Case #" << cnt << ": ";
        //cout << fixed << setprecision(10);
        solve();
        //cout << endl;
        //cnt++;
    }
}

ll POW(ll base,ll exp){
    ll result = 1;
    while (exp > 0){
        if (exp & 1)
            result = ((ll)result * base);
        base = ((ll)base * base);
        exp >>= 1;
    }
    return result;
}

ll mpow(ll base, ll exp){
    base %= mod;
    ll result = 1;
    while (exp > 0){
        if (exp & 1)
            result = ((ll)result * base) % mod;
        base = ((ll)base * base) % mod;
        exp >>= 1;
    }
    return result;
}

ll gcd(ll a,ll b){
    if(b==0) return a;
    else return gcd(b,a%b);
}

ll modInverse(ll n) { 
    return mpow(n, mod-2); 
}
 
ll nCr(ll n, ll r){ 
   if (r==0) 
      return 1; 
    ll fac[n+1]; 
    fac[0] = 1; 
    for (int i=1 ; i<=n; i++) 
        fac[i] = (fac[i-1]*i)%mod; 
    return ((fac[n]* modInverse(fac[r]) % mod * 
            modInverse(fac[n-r]) % mod)%mod)%mod; 
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    ll n;
    cin >> n;
    ll a[n];
    ll sum = 0;
    rep(i,n){
        cin >> a[i];
        sum += a[i];
    }
    ll now = 0;
    ll ans = 100100100100100100;

    rep(i,n-1){
        now += a[i];
        ll tmp = abs(sum - now - now);
        ans = min(ans, tmp);
    }

    cout << ans << endl;
    return 0;
}
 
 


Measured memory_bytes: 1792
#include <iostream>
#include<iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(ll i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout<< "YES"<<endl;
#define No cout<< "No"<<endl;
#define Yes cout<< "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<int,int>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

int main(){
    
    int n;
    cin >> n;
    
    bool key = false;
    
    for(int i=1;100*i<=n;i++){
        if(100*i<=n&&n<=105*i){
            key = true;
            break;
        }
    }
    
    if(key)cout << 1<<endl;
    else cout << 0<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define endl "\n"
#define speed() ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(x) (int)(x).size()
#define _USE_MATH_DEFINES
using namespace std;
typedef long long int lli;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int INF = 1000000000; // 10^9

int main() {
    speed();
    int N; cin >> N;
    int X[N];
    rep(i, 0, N) cin >> X[i];
    int ans = INF;
    rep(i, 1, 101) {
        int cost = 0;
        rep(j, 0, N) cost += (X[j] - i) * (X[j] - i);
        ans = min(ans, cost);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/range/algorithm/sort.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using boost::irange;
using boost::sort;
using boost::adaptors::reversed;

int main() {
    int n, x, y;
    cin >> n >> x >> y;
    vector<unordered_set<int>> w(n + 1);
    for (int i = 1; i <= n - 1; i++) {
        w[i].insert(i + 1);
        w[i + 1].insert(i);
    }
    w[x].insert(y);
    w[y].insert(x);

    vector<int> ans(n, 0);
    queue<int> q;
    for (int k = 1; k <= n; k++) {
        vector<int> dist(n + 1, -1);
        q.push(k);
        dist[k] = 0;
        while (!q.empty()) {
            int top = q.front();
            q.pop();
            for (int i : w[top]) {
                if (dist[i] != -1) continue;
                q.push(i);
                dist[i] = dist[top] + 1;
                ans[dist[i]] += 1;
            }
        }
    }

    for (int k = 1; k < n; k++) cout << ans[k] / 2 << endl;
}


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

int gcd(int a, int b) {
  return (b ? gcd(b, a%b) : a);
}


int main() {
  int A, B, C;
  cin >> A >> B >> C;
  
  int x = gcd(A, B);
  
  if (C % x) {
    cout << "NO" << endl;
  } else {
    cout << "YES" << endl;
  } 
}

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

int main(void){
    int a[1000], n, x, min, ans = 0;
     for (int i = 0; i < 2; ++i) {
         scanf("%d", &a[i]);
    }
    n = a[0];
    x = a[1];
    for (int i = 0; i < n; ++i) {
         scanf("%d", &a[i]);
    }
    min = a[0];
    for(int i=0; i<n; i++){
        if(min>a[i]) min = a[i];
        x = x - a[i];
        ++ans;
    }
    while(x>=min){
        x = x-min;
        ++ans;
    }
    printf("%d", ans);
}


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

int main() {
  int N;
  cin >> N;
  vector<int> D(N);
  for(int i = 0; i<N; i++){
    cin >> D.at(i);
  }
  vector<int64_t> count(N);
  int64_t ans = 1;
  if(D.at(0)!=0){
    cout << 0 << endl;
    return 0;
  }else{
    for(int i=1; i<N; i++){
      if(D.at(i) == 0){
        cout << 0 << endl;
        return 0;
      }else{
        count.at(D.at(i))++;
      }
    }
    sort(D.begin(),D.end());
    for(int i=1; i<N; i++){
      if(D.at(i)-D.at(i-1)>1){
        cout << 0 << endl;
        return 0;
      }
    }
    count.at(0) = 1;
    for(int i=2; i<N; i++){
      if(count.at(i)!=0){
        int64_t a = 1; 
        for(int j=0; j<count.at(i); j++){
          a *= count.at(i-1);
          a %= 998244353;
        }
        ans *= a;
        ans %= 998244353;
      }else break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1408
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// #include<ext/pb_ds/tag_and_trait.hpp>
// using namespace __gnu_pbds;
using namespace std;
using ll=long long;
#define double long double
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
// using llset=tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,b,a) for(i=b-1;i>=(ll)a;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define eb emplace_back
#define print(v) cout<<v<<endl
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define printYES cout<<"YES"<<endl
#define printNO cout<<"NO"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
// const ll mod=998244353;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas x,ddatas y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  if(n<r)return 0;
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n>0){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

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

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

int main(){
  // startupcpp();
  // int codeforces;cin>>codeforces;while(codeforces--){
  ll i,j=0,N,M,ans;
  cin>>N>>M;
  ans=N%M;
  print(min(ans,M-ans));
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <map>
using namespace std;
class Working{
    public:
    int day;
    int money;
    Working(int a, int b){
        day = a;
        money = b;
    }
};
int main(void)
{
    int N, M;
    cin >> N >> M;
    priority_queue<double, vector<double>> que;
    int loop;
    for(int i = 0; i < N; i++){
        cin >> loop;
        que.push(loop);
    }
    long long int result = 0;
    for(int i = 0; i < M; i++){
        que.push(que.top() / 2);
        que.pop();
    }
    while(!que.empty()){
        result += que.top();
        que.pop();
    }
    cout << result << "\n";
}

Measured memory_bytes: 1400
import numpy as np
N, K = map(int, input().split())
A = np.array(list(map(int, input().split())))
A = np.sort(A)

G = A[A > 0]
Z = A[A == 0]
L = A[A < 0]

l, r = 10**18, -10**18

while l-r > 1:
  # 「積がm以下になるペアの数」を調べる。
  m = (l+r) // 2

  # A[A > 0]内から条件を満たすものの数?
  Pk = np.searchsorted(A, m//G, side="right").sum()

  # A[A < 0]内から条件を満たすものの数?
  Nk = (N - np.searchsorted(A, (-m-1)//(-L), side="right")).sum()

  # 同じ要素同士の積は重複しているため、条件を満たしていたら減らす
  duplicate = np.count_nonzero(A*A <= m)

  # A[0]内から条件を満たすものの数?
  Zk = 0
  if m >= 0:
    Zk += len(Z) * N

  # 条件を満たす要素の数を合わせる
  k = Pk + Nk + Zk - duplicate
  
  # 全要素が二重になっている。重複要素を削除
  k //= 2

  # 条件を満たす要素数kがK個以上ならmを低く、Kより少ないならmを高くする
  if k >= K:
    l = m
  else:
    r = m
#lとrが一致すればmが一意に定まる
print(l)

Measured memory_bytes: 32260
K,N = map(int,input().split())
A = list(map(int,input().split()))

max_distance = 0

for i in range(N-1):
    distance = A[i+1]-A[i]
    max_distance = max(distance,max_distance)

#最初と最後の距離を計算
distance = A[0]+(K-A[N-1])
max_distance = max(distance,max_distance)

print(K-max_distance)

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

int main()
{
  long long N, M, num = 0;

  cin >> N >> M;
  vector<long long> a(M);


  for (long long  i = 0; i < M; i++)
  {
    cin >> a[i];
    num += a[i];
  }

  if(N < num)
  {
    cout << -1 << endl;
  }
  else
  {
    cout << N - num << endl;
  }

  return 0;
}

Measured memory_bytes: 3712
def main():
    x, n = [int(e) for e in input().split()]
    P = set([int(e) for e in input().split()])

    if x not in P:
        print(x)
        exit()

    d = 1
    while True:
        a = x - d
        if a not in P:
            print(a)
            exit()

        a = x + d
        if a not in P:
            print(a)
            exit()

        d += 1


if __name__ == '__main__':
    main()


Measured memory_bytes: 61896
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_set>
#include<unordered_map>
using namespace std;
typedef long long ll;
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#define all(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod
#define N 200010
ll po(ll x,ll y){
    ll res=1;
    for(;y;y>>=1){
	if(y&1)res=res*x%mod;
	x=x*x%mod;
    }
    return res;
}
ll inv(ll x){
    return po(x,mod-2);
}
ll fac[N];
ll n,x[N];
int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    fac[0]=1;
    for(ll i=1;i<N;i++)fac[i]=fac[i-1]*i%mod;
    cin>>n;
    rep(i,n)cin>>x[i];
    ll ans=0,rui=0;
    for(ll i=1;i<n;i++){
	ll d=x[i]-x[i-1];
	mad(rui,inv(i)%mod*fac[n-1]%mod);
	mad(ans,d*rui);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int main(){
	int i,c,n;
	cin >> n;
	int a[n];
	for(i=0;i<n;i++){
		cin >> a[i];
	}
	sort(a,a+n);
	n=n/2;
	c=a[n]-a[n-1];
	cout << c;
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ldb long double

struct point
{
	ll x,y;
	point(ll xx=0,ll yy=0):x(xx),y(yy) {}
}st[200010];

inline point operator -(const point &x,const point &y) { return point(x.x-y.x,x.y-y.y); }
inline ll cross(const point &x,const point &y) { return x.x*y.y-x.y*y.x; }

ll a[200010],b[200010],c[200010],A[200010],B[200010],n,top;

inline ll rd()
{
	ll x=0;char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar());
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

ldb f[200010];

int main()
{
	n=rd();
	for (int i=1;i<=n;i++) A[i]=rd();
	for (int i=1;i<=n;i++) B[i]=rd();
	int id=1;
	for (int i=2;i<=n;i++) if (A[i]>A[id]) id=i;
	for (int i=1;i<=n;i++) a[i]=A[(i+id-1)%n+1],b[i]=B[(i+id-1)%n+1];
	a[0]=a[n];b[0]=b[n];
	for (int i=2;i<=n;i++) c[i]=(c[i-1]+b[i-1])*2-c[i-2];
	top=0;
	for (int i=0;i<=n;i++)
	{
		point now(i,a[i]-c[i]);
		while (top>1&&cross(st[top]-st[top-1],now-st[top-1])>=0) top--;
		st[++top]=now;
	}
	for (int i=1;i<top;i++)
	{
		ll x=st[i].y,y=st[i+1].y;
		int l=st[i].x,r=st[i+1].x;
		for (int j=l;j<=r;j++) f[j]=(ldb)((ldb)x*(r-j)+y*(j-l))/(ldb)(r-l);
	}
	ldb ans=0;
	for (int i=1;i<=n;i++) ans+=f[i]+(ldb)c[i];
	printf("%.15Lf\n",ans/(ldb)n);
	return 0;
}

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

int main(){
 map< char , int >count;
 string str;
 while(cin>>str){

 for(int i=0;i<(int)str.size();i++){
 if(isupper(str[i])){
 str[i]=tolower(str[i]);
}
}
 for(int i=0;i<(int)str.size();i++){
 count[str[i]]++;
}
}
 for(char ch='a';ch<='z';ch++){
 cout<<ch<<" : "<<count[ch]<<endl;
}
}


Measured memory_bytes: 3140
n, y = map(int, input().split())

for i in range(n + 1):
    for j in range(n + 1):
        k = 10000 * i + 5000 * j + 1000 * (n - i - j)
        if (y == k) and (n - i - j >= 0):
            print('%d %d %d' % (i, j, n - i - j))
            exit()
print('-1 -1 -1')


Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct Node{
	int key;
	struct Node *p,*l,*r;
}Node;

Node *root,*nil;

int pre(Node *t){
	if(t == nil)return 0;
	printf(" %d",t->key);
	pre(t->l);
	pre(t->r);
}

int in(Node *t){
	if(t == nil)return 0;
	in(t->l);
	printf(" %d",t->key);
	in(t->r);
}

void insert(int key){
	Node *y = nil;
	Node *x = root;
	Node *z;
	
    z = (Node *)malloc(sizeof(Node));
	z->key = key;
	z->l = nil;
	z->r = nil;
	while(x != nil){
		y = x;
		if(z->key < x->key){
			x=x->l;
		}else{
			x=x->r;
		}
	}
	z->p = y;
	if(y == nil){
		root = z;
	}else if(z->key < y->key){
		y->l = z;
	}else{
		y->r = z;
	}
}

int main(void) {
	int n;
	char com[16];
    scanf("%d",&n);
    
    for(int i=0;i<n;i++) {
        scanf("%s",com);
        if(!strcmp(com,"insert")) {
        	int x;
            scanf("%d",&x);
            insert(x);
        } else if(!strcmp(com,"print")) {
            in(root);
            printf("\n");
            pre(root);
            printf("\n");
        }
    }
	return 0;
}


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

int main(){
  string s;
  cin >> s;
  int n = sz(s);

  string tmp = "";
  for (int i = n-1; i >= 0; i--) {
    tmp += s[i];
    if (tmp == "maerd" || tmp == "remaerd" || tmp == "esare" || tmp == "resare") tmp = "";
  }
  if (tmp.empty()) puts("YES");
  else puts("NO");
  return 0;
} 

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
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; }
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)

int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//素因数分解
vector<pair<ll, int>>factorize(ll n) {
	vector<pair<ll, int>>res;
	for (ll i = 2;i * i <= n;++i) {
		if (n % i)continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1)res.emplace_back(n, 1);
	return res;
}

int bingo[3][3];
bool flag[3][3];
int cnt[2][105];
int h, w;
int choco[1010][1010];
int s[11][11];
char a[60][60];
char b[60][60];

int main() {
	string s;
	cin >> s;
	int n = s.length();
	int a = 0, z = 0;
	rep(i, n) {
		if (s[i] == 'A') {
			a = i - 1;
			break;
		}
	}
	rep(i, n) {
		if (s[n - 1 - i] == 'Z') {
			z = n - 1 - i;
			break;
		}
	}
	int ans = max(0, z - a);
	cout << ans << endl;
	return 0;
}


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

int main(){
  string s, t, u; cin >> s >> t;
  int a, b; cin >> a >> b;
  cin >> u;
  
  if(s==u) cout << a-1 << " " << b << endl;
  else cout << a << " " << b-1 << endl;
}


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

using namespace std;

#define LL long long
#define N 5005
#define INF 0x3f3f3f3f3f3f3f3fLL

const LL mod=1000000007;

LL n,m,x,y,ans,c,tot,sum,a[N],sz[N],mx[N],head[N],fac[N],ifac[N],f[N][N];
struct edge{LL v,nxt;}e[N*2];

void add(LL x,LL y){e[++tot].v=y; e[tot].nxt=head[x]; head[x]=tot;}

void dfs(LL u,LL fa){
	sz[u]=1; mx[u]=0;
	for (LL i=head[u],v;i;i=e[i].nxt)
		if ((v=e[i].v)!=fa){
			dfs(v,u); sz[u]+=sz[v]; mx[u]=max(mx[u],sz[v]);
		}
	mx[u]=max(mx[u],n-sz[u]);
	if (mx[u]<mx[c]) c=u;
}

void getsz(LL u,LL fa){
	sz[u]=1;
	for (LL i=head[u],v;i;i=e[i].nxt)
		if ((v=e[i].v)!=fa){
			dfs(v,u); sz[u]+=sz[v];
		}
}

LL inv(LL x){return x==1?1:(mod-mod/x)*inv(mod%x)%mod;}

LL C(LL x,LL y){return fac[x]*ifac[y]%mod*ifac[x-y]%mod;}

LL P(LL x,LL y){return fac[x]*ifac[x-y]%mod;}

int main(){
	scanf("%lld",&n);
	for (LL i=1;i<n;i++){
		scanf("%lld%lld",&x,&y);
		add(x,y); add(y,x);
	}
	mx[c=0]=INF; dfs(1,0);
	for (LL i=1;i<=n;i++)
		if (i!=c && mx[i]==mx[c]){
			ans=1;
			for (LL i=1;i<=n/2;i++)
				(ans*=i)%=mod;
			printf("%lld\n",ans*ans%mod);
			return 0;
		}
	getsz(c,0);
	for (LL i=head[c];i;i=e[i].nxt)
		a[++m]=sz[e[i].v];
	sum=0;
	fac[0]=1; for (LL i=1;i<=n;i++) fac[i]=fac[i-1]*i%mod;
	ifac[n]=inv(fac[n]); for (LL i=n-1;i>=0;i--) ifac[i]=ifac[i+1]*(i+1)%mod;
	f[0][0]=1;
	for (LL i=1;i<=m;i++){
		sum+=a[i];
		for (LL j=0;j<=sum;j++)
			for (LL k=0;k<=a[i] && k<=j;k++)
				(f[i][j]+=f[i-1][j-k]*C(a[i],k)%mod*P(a[i],k)%mod)%=mod;
	}
	for (LL i=0;i<=n;i++) (ans+=f[m][i]*fac[n-i]%mod*(i&1?-1:1)+mod)%=mod;
	printf("%lld\n",ans);
	
	return 0;
}
			

Measured memory_bytes: 194432
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef unsigned long long ull;

int gcd(int a,int b) {
    if(b==0) {
        return a;
    }
    return gcd(b,a%b);
}

int main() {
    int N,X;
    cin>>N>>X;
    vi x(N);
    rep(i,N) cin>>x[i];
    vi v(N);
    rep(i,N) {
        v[i]=abs(x[i]-X);
    }
    int answer=v[0];
    for(int i=1; i<N; i++) answer=gcd(answer,v[i]);
    cout<<answer<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <tuple>
#include <bitset>
#include <random>
#define REP(i,n) for(int i=0;i<n;i++)
#define INF 1000000007
using namespace std;
using pii=pair<int,int>;



int main() {
  int sx,sy,tx,ty;
  cin>>sx>>sy>>tx>>ty;
  int dx=tx-sx,dy=ty-sy;
  string ans="";
  string right(dx,'R'),left(dx,'L'),up(dy,'U'),down(dy,'D');
  ans=ans+up+right+down+left+'L'+up+'U'+'R'+right+'D'+'R'+down+'D'+'L'+left+'U';
  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 3160
#include<bits/stdc++.h>
#define lli long long int
#define ulli unsigned long long int
#pragma GCC target ("sse4.2")
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define time cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
#define plli pair<lli,lli>
#define pslli pair<string,lli>
#define pclli pair<char,lli>
lli N=2e5+9;
vector<lli>v(N+9);
void fact()
{
    v[1]=1;
    for(lli i=2;i<=N;i++)
    {
        v[i]=v[i-1]*i;
    }
}
pair<lli,lli> fl(lli a)
{
    static lli x=0,y=0,l=0,d=0;
    x=a%10;
    while(a)
    {
        d=a;
        a/=10;
    }
    pair<lli,lli>p(d,x);
    return p;
}
int main()
{


    fast;

    lli n;
    cin>>n;
    map<plli,lli>mp;
    vector<plli>v(n+1);
    for(lli i=1;i<=n;i++)
    {
        plli p=fl(i);
        //cout<<p.first<<" "<<p.second<<"\n";
        v[i]=p;
        mp[p]++;
    }

    lli total=0;
    for(lli i=1;i<=n;i++)
    {
        plli p=fl(i);
        total+=mp[{p.second,p.first}];
    }
    cout<<total;


    return 0;

}


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

int main() {
  char c;
  cin >> c;
  string ans = "consonant";
  if(c == 'a' or c == 'e' or c == 'i' or c == 'o' or c == 'u') ans = "vowel";

  cout << ans << endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<cassert>
#include<map>
#include<set>

typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const ll INF = 5000000000000;
//typedef std::pair<int, int> P;
struct edge { int to;double cost; };
#define VMAX 1010

     ll N,K;
     ll A[300000],B,C;
     bool D[1000];
     ll P[11];
     ll ans;

int main() {
    cin>>K>>N;
    if(N==0){cout<<K;return 0;}
    EREP(i,N){
        cin>>A[i];
        D[A[i]]=true;
    }
    sort(A,A+N);
    P[0]=0,P[1]=101;
    REP(i,100){
        if(i+1<=K){
            if(!D[i+1])P[0]=i+1;
        }else{
            if(!D[i+1]){P[1]=i+1;break;}
        }
    }
    if(abs(P[0]-K)<=abs(P[1]-K)){
        cout<<P[0];
    }else cout<<P[1];
    return 0;
}


Measured memory_bytes: 3684
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;

LL dp[2][60][2600]={};
int ary[60];
int main(){
	int N,A;
	cin>>N>>A;
	for(int i=1;i<=N;i++){
		cin>>ary[i];
	}

	int in=0,ou=1;
	dp[in][0][0]=1;
	for(int i=1;i<=N;i++){
		for(int j=0;j<60;j++){
			for(int k=0;k<2600;k++){
				dp[ou][j][k]=dp[in][j][k];
			}
		}
		for(int j=0;j<i;j++){
			for(int k=0;k<A*N;k++){
				dp[ou][j+1][k+ary[i]]+=dp[in][j][k];
			}
		}
		swap(in,ou);
		/*
		for(int j=0;j<=N;j++){
			for(int k=0;k<50;k++){
				cout<<dp[in][j][k]<<" ";
			}
			cout<<endl;
		}
		cout<<endl;
		*/
	}

	LL res=0;
	for(int i=1;i<=N;i++){
		res+=dp[in][i][i*A];
	}
	cout<<res<<endl;
	return 0;
}


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

using namespace std;

using int64 = long long;

int N, W[100000], Q;
vector< int > g[100000];
int dep[100000];
int64 sub[100000];
int64 heavy[3][100000];
const int LOG = 18;

int par[LOG][100000];
int64 sz[LOG][100000];

void predfs(int idx, int p, int d) {
  par[0][idx] = p;
  dep[idx] = d;
  sub[idx] += W[idx];
  for(auto &to : g[idx]) {
    if(to == p) continue;
    predfs(to, idx, d + 1);
    sub[idx] += sub[to];
    if(heavy[0][idx] < sub[to]) {
      heavy[2][idx] = heavy[1][idx];
      heavy[1][idx] = heavy[0][idx];
      heavy[0][idx] = sub[to];
    } else if(heavy[1][idx] < sub[to]) {
      heavy[2][idx] = heavy[1][idx];
      heavy[1][idx] = sub[to];
    } else if(heavy[2][idx] < sub[to]) {
      heavy[2][idx] = sub[to];
    }
  }
}

void dfs(int idx, int p) {
  for(auto &to : g[idx]) {
    if(to == p) continue;
    dfs(to, idx);
    sz[0][to] = heavy[heavy[0][idx] == sub[to]][idx];
  }
}

int lca(int x, int y) {
  if(dep[x] > dep[y]) swap(x, y);
  for(int i = LOG - 1; i >= 0; i--) {
    if((dep[y] - dep[x]) >> i & 1) y = par[i][y];
  }
  if(x == y) return x;
  for(int i = LOG - 1; i >= 0; i--) {
    if(par[i][x] != par[i][y]) {
      x = par[i][x];
      y = par[i][y];
    }
  }
  return par[0][x];
}

int main() {
  scanf("%d", &N);
  for(int i = 0; i < N; i++) {
    scanf("%d", &W[i]);
  }
  for(int i = 1; i < N; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    --x, --y;
    g[x].emplace_back(y);
    g[y].emplace_back(x);
  }
  predfs(0, -1, 0);
  dfs(0, -1);
  for(int i = 0; i + 1 < LOG; i++) {
    for(int j = 0; j < N; j++) {
      if(par[i][j] == -1) par[i + 1][j] = -1;
      else par[i + 1][j] = par[i][par[i][j]];
      if(par[i + 1][j] == -1) continue;
      sz[i + 1][j] = max(sz[i][j], sz[i][par[i][j]]);
    }
  }

  int64 all = accumulate(W, W + N, 0LL);

  scanf("%d", &Q);
  while(Q--) {
    int a, b;
    scanf("%d %d", &a, &b);
    --a, --b;
    if(dep[a] > dep[b]) swap(a, b);
    int p = lca(a, b);

    int64 ret = 0;
    if(p != a) {

      bool ng[3] = {};
      ret = max(ret, heavy[0][a]);
      ret = max(ret, heavy[0][b]);

      for(auto c : {a, b}) {
        int xx = dep[p] + 1;
        for(int i = LOG - 1; i >= 0; i--) {
          if(((dep[c] - xx) >> i) & 1) {
            ret = max(ret, sz[i][c]);
            c = par[i][c];
          }
        }
        for(int i = 0; i < 3; i++) {
          if(ng[i]) continue;
          if(sub[c] == heavy[i][p]) {
            ng[i] = true;
            break;
          }
        }
      }
      for(int i = 0; i < 3; i++) {
        if(ng[i]) continue;
        ret = max(ret, heavy[i][p]);
      }
    } else if(p != b) {
      ret = max(ret, heavy[0][b]);
      int c = b;
      int xx = dep[a] + 1;
      for(int i = LOG - 1; i >= 0; i--) {
        if(((dep[c] - xx) >> i) & 1) {
          ret = max(ret, sz[i][c]);
          c = par[i][c];
        }
      }
      ret = max(ret, sz[0][c]);
    } else {
      ret = max(ret, heavy[0][p]);
    }

    printf("%lld\n", max(ret, all - sub[p]));
  }
}




Measured memory_bytes: 23608
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        n: usize,
        xyh: [(i64, i64, i64); n]
    }
    let mut vi = 0;
    for i in 0..n {
        if xyh[i].2 > 0 {
            vi = i;
        }
    }

    let mut ret = (0,0,0);
    for cy in 0..101 {
        for cx in 0..101 {
            let (x,y,h) = xyh[vi];
            let top = h + (x - cx).abs() + (y - cy).abs();
            let mut is_ok = true;
            for i in 0..n {
                let (x,y,h) = xyh[i];
                if h > 0 && top != h + (x - cx).abs() + (y - cy).abs() {
                    is_ok = false;
                }
                if h == 0 && top > (x - cx).abs() + (y - cy).abs() {
                    is_ok = false;
                }
            }
            if is_ok {
                ret = (cx, cy, top);
            }
        }
    }
    println!("{} {} {}", ret.0, ret.1, ret.2);
}


Measured memory_bytes: 4352
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        x: i64,
        k: i64,
        d: i64,
    }

    let x = x.abs();

    if k <= x / d {
        println!("{}", x - k * d);
        return;
    }

    let div = x / d;
    let r = k - div;
    let ans = if r % 2 == 0 {
        x - div * d
    } else {
        -(x - (div + 1) * d)
    };

    println!("{}", ans);
}


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

int main(){
  int h , w , k;
  cin >> h >> w >> k;
  int ans =0;
  vector<vector<char>> data(6,vector<char>(6));
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> data.at(i).at(j);
    }
  }
  //bit全探索
   for(int bit1 = 0; bit1 < (1<<h); bit1++){
     for(int bit2 = 0; bit2 < (1<<w); bit2++){
       int cnt = 0;
         for(int i=0;i<h;i++){
           for(int j=0;j<w;j++){
             if(bit1&(1<<i) || bit2&(1<<j)) continue;
             if(data.at(i).at(j)=='#') cnt++;
           }
         }
       if(cnt==k) ans++;
     }
   }
  
  cout << ans << endl;
}
  
  

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <cstring>
#include <sstream>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vii> vvii;

#define fastIO ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define forw(i,l,r) for(int i=(l);i<(r);i++)
#define forb(i,r,l) for(int i=(r);i>(l);i--)
#define sqr(x) (x)*(x)
#define log2i(x) 32 - __builtin_clz((x)) - 1
#define log2l(x) 64 - __builtin_clzll((x)) - 1
#define inf1 int(1e9+7)
#define inf2 0x3f3f3f3f
#define infll ll(1e18+7)
#define Pi acos(-1.0)
#define mu(x,y) trunc(exp(log((x))*(y)))
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()

int n,ans=0;
int a[21];

int main() {
    fastIO;
    //freopen(".inp","r",stdin);
    //freopen(".out","w",stdout);

    cin >> n;
    forw(i,0,n) cin >> a[i];
    forw(i,1,n-1) {
        if(a[i]>min(a[i-1],a[i+1])&&a[i]<max(a[i-1],a[i+1])) ans++;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
import sys
n,m=map(int,input().split())
ans=[0 for i in range(n)]
f=[[True] for i in range(n)]
if n==1:
    for i in range(m):
        s,c=map(int,input().split())
        if f[s-1]==False:
            if ans[s-1]!=c:
                print(-1)
                sys.exit()
        if f[s-1]:
            f[s-1]=False
        ans[s-1]=c
    
    a=map(str,ans)
    print("".join(a))
    sys.exit()

for i in range(m):
    s,c=map(int,input().split())
    if s==1 and c==0:
        print(-1)
        sys.exit()
    if f[s-1]==False:
        if ans[s-1]!=c:
            print(-1)
            sys.exit()
    if f[s-1]:
        f[s-1]=False
    ans[s-1]=c
if ans[0]==0:
    ans[0]=1
a=map(str,ans)
print("".join(a))

Measured memory_bytes: 9272