akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
const long long INF = 1LL << 60;

int main() {
  int N, K; cin>>N>>K;
  map<int, int> okashi;
  for(int i=1; i<=N; i++) okashi[i]=1; 
  for(int i=0; i<K; i++){
    int d; cin>>d;
    for(int j=0; j<d; j++){
      int A; cin>>A;
      okashi.erase(A); //お菓子を持ってる人を消す
    }
  }
  int sum=0;
  for(auto p:okashi){
    sum++;
  }
  cout<<sum<<endl;
}


Measured memory_bytes: 3632
N, M = map(int, input().split())
X = list(map(int, input().split()))
X.sort()
d = []
if N > M:
    N = M
for i in range(M - 1):
    d.append(abs(X[i + 1] - X[i]))
d.sort()
print(sum(d[:M - N]))


Measured memory_bytes: 13968
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int N=100010;
char a[N],b[N];
inline int gcd(int x,int y) {return y?gcd(y,x%y):x;}
int main() {
    int n,m,g;
    cin>>n>>m,g=gcd(n,m);
    scanf("%s%s",a,b);
    for(int i=0;i<g;i++)
	if(a[n/g*i]!=b[m/g*i]) return cout<<-1,0;
    cout<<1LL*n*m/g;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chimin(T& a, T b) {
    if (a > b) { a = b; return true; } return false;
}

template<class T> inline bool chimax(T& a, T b) {
    if (a < b) { a = b; return true; } return false;
}

const long long INF = 1LL << 60;

int main() {
    int N; cin >> N;
    if (N % 1000 == 0) cout << 0 << endl;
    else cout << 1000 - N % 1000 << endl;
}

Measured memory_bytes: 3632
#include<stdio.h>
int main(void)
{
	int n,a,b,c,d,z,w,y;
	scanf("%d",&n);
	c=n/100;
	d=n%100;
	z=d/10;
	w=d%10;
	if(c==9){
		a=c/9;
	}
	if(c==1){
		a=c*9;
	}
	if(z==9){
		b=z/9;
	}
	if(z==1){
		b=z*9;
	}
	if(w==9){
		y=w/9;
	}
	if(w==1){
		y=w*9;
	}
	printf("%d\n",a*100+b*10+y);
	return 0;
}

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

using namespace std;
using ll = long long;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define INF 9223372036854775807
#define all(x) (x).begin(), (x).end()

ll ts = 1000000007;

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

  ll n, d, x;
  cin >> n >> d >> x;

  REP(i, n) {
    ll a;
    cin >> a;

    for (int j = 0; j * a + 1 <= d; j++) {
      x++;
    }
  }

  cout << x << "\n";
}

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

int main() { /* ここに書く */
  
  int A,B,C,D,K;
  cin >> A >> B >> C >> D >> K;
  
  int ans;
  
  ans = C - A;
  ans = ans * 60;
  ans = ans + D - B;
  ans = ans - K;
  
  cout << ans << endl;
}


Measured memory_bytes: 3636
import java.util.Scanner;
 
public class Main {
	
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        final String s1 = sc.nextLine();
        final String s2 = sc.nextLine();
    	final String s3 = sc.nextLine();
                
        System.out.println(String.valueOf(s1.charAt(0)) + String.valueOf(s2.charAt(1)) + String.valueOf(s3.charAt(2)));
    }
    
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<pair<ll,ll>>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

vector<ll> dis; 
vector<bool> seen;  // 訪問済みの点
vector<int> color;

// BFSのための再帰関数
void bfs(const Graph &G, int v, ll dis) {
    seen[v] = true;
    if(dis % 2 == 0){
        color[v] = 0;
    }
    else{
        color[v] = 1;
    }
    for (auto next_v : G[v]) { 
        if (seen[next_v.first]) continue;
        bfs(G, next_v.first, dis+next_v.second); // 再帰的に値を追加していく
    }
}

int main()
{
    cout << fixed << setprecision(15);
    ll N;
    cin >> N;

    Graph G(N);

    pair<ll,ll> p;
    ll a, b, c;
    REP(i, N-1){
        cin >> a >> b >> c;
        a--; b--;
        
        p.first = b;
        p.second = c;
        G[a].push_back(p);
        
        p.first = a;
        p.second = c;
        G[b].push_back(p);
    }
    
    // REP(i, N){
    //     for(auto v:G[i]){
    //         cout << v.first << ":" << v.second << endl;
    //     }
    // }

    color.assign(N, 0);
    seen.assign(N, false);

    bfs(G, 0, 0);
    REP(i, N){
        cout << color[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 9728
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn main() {
    let n = read::<usize>();
    let mut ls = read_vec::<u32>();

    ls.sort();
    let mut sum = 0;
    for i in 0..(2*n) {
        if i % 2 == 0 {
            sum += ls[i]
        }
    }
    println!("{}", sum);
}


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

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
ld EPS = 1e-12;
int INF = numeric_limits<int>::max() / 2;
ll LINF = numeric_limits<ll>::max() / 2;
int MOD = 1e9 + 7;
#define rep(i,n) for(int i = 0; i < n; i++)
#define all(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'

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

Measured memory_bytes: 256
N, M = map(int, input().split())
boxes = [1] * N
ans = {1}
for i in range(M):
    x, y = map(int, input().split())
    boxes[x - 1] -= 1
    boxes[y - 1] += 1
    if x in ans:
        if boxes[x - 1] == 0:
            ans.remove(x)
        ans.add(y)
print(len(ans))


Measured memory_bytes: 53080
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> a(n);
  for(Int i=0;i<n;i++) cin>>a[i];
  Int q;
  cin>>q;
  for(Int i=0;i<q;i++){
    Int k;
    cin>>k;
    cout<<lower_bound(a.begin(),a.end(),k)-a.begin()<<endl;
  }
  return 0;
}



Measured memory_bytes: 3600
N = int(input())
n=int(N**0.5)
cnt=0
for i in range(1,n+1):
    a=N//i
    if a-i-1>0:
        cnt+=(a-i-1)*2
    if i**2!=N:
        cnt+=1
    if a*i!=N and a!=i:
        cnt+=2
print(cnt)

Measured memory_bytes: 62828
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

// https://www.creativ.xyz/segment-tree-abstraction-979/
template<class T>
struct SegmentTree {
  ll n;
  vector<T> data;
  T identity;
  using F = function<T(T, T)>;
  F operation;
  F update;

  SegmentTree(ll n_, T identity, F operation, F update) : n(n_), identity(identity), operation(operation), update(update) {
    n = 1;
    while (n < n_) n *= 2;
    data.assign(2*n-1, identity);
  }

  void change(ll i, T x) {
    i += n-1;
    data[i] = update(data[i], x);
    while (i > 0) {
      i = (i-1)/2;
      data[i] = operation(data[i*2+1], data[i*2+2]);
    }
  }

  T query(ll a, ll b, ll k, ll l, ll r) {
    if (r <= a or b <= l) return identity;
    if (a <= l and r <= b) {
      return data[k];
    } else {
      T c1 = query(a, b, 2*k+1, l, (l+r)/2);
      T c2 = query(a, b, 2*k+2, (l+r)/2, r);
      return operation(c1, c2);
    }
  }

  T query(ll a, ll b) {
    return query(a, b, 0, 0, n);
  }

  T operator[](ll i) {
    return data[i+n-1];
  }
};

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

  ll n, q;
  cin >> n >> q;
  auto update = [](ll l, ll r) { return r; };
  auto mini = [](ll l, ll r) { return min(l, r); };
  SegmentTree<ll> st(n, (1LL<<31)-1, mini, update);

  rep(i, q) {
    ll c, x, y;
    cin >> c >> x >> y;
    if (c == 0) {
      st.change(x, y);
    } else {
      cout << st.query(x, y+1) << endl;
    }
  }
}



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

int main(){
  string S; cin >> S;
  int N = S.size();
  long long ans = 0;
  REP(bit, (1<<(N-1))){
    long long res = 0;
    long long tmp = 0;
    REP(i, N){
      tmp *= 10;
      tmp += S[i] - '0';
      if ((bit>>i) & 1) res += tmp, tmp = 0;
    }
    ans += res + tmp;
  }
  cout << ans << endl;
  return 0;
}


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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)

const int MOD = 998244353;

int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> L(K), R(K);
    REP(i, K) cin >> L[i] >> R[i];

    // dp[i][j] = j を使って i まで行く方法の個数
    vector<long long> dp(N+1, 0);
    dp[1] = 1;
    FOR(i, 2, N+1){
        REP(j, K){
            if(0 <= i-L[j]){
                dp[i] += dp[i-L[j]];
                dp[i] %= MOD;
            }
            if(0 <= i-R[j]-1){
                dp[i] -= dp[i-R[j]-1];
                dp[i] %= MOD;
            }
        }
        if(i < N) dp[i] += dp[i-1];
    }
    cout << (dp[N]+MOD)%MOD << endl;

    return 0;
}

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

int main() {
  int A, B;
  cin >> A >> B;
  int S = 0;
  for (int i = A; i < B + 1; i++){
    if (i % 10 == i / 10000 && i / 1000 % 10 == i / 10 % 10)
      S++;
  }
  cout << S << endl;

}

Measured memory_bytes: 256
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions 

#endif


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

    int N; cin >> N;
    vl A(N + 1); REP(i, N + 1) cin >> A[i];
    vl B(N); REP(i, N) cin >> B[i];

    ll ans = 0;
    REP(i,N) {
        ll left = min(A[i], B[i]);
        A[i] -= left;
        B[i] -= left;
        ans += left;

        ll right = min(A[i + 1], B[i]);
        A[i + 1] -= right;
        B[i] -= right;
        ans += right;
    }

    cout << ans << endl;

    return 0;
}

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef pair<int,int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

void Main(){
    int N; cin >> N;
    ll ans = 0;
    FOR(A,1,N+1){
        int l = 1;
        int r = N%A==0 ? N/A-1 : N/A;
        if(r<l) continue;
        ans += r-l+1;
    }
    cout << ans << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N; cin >> N;
  vector<long long> L(N);
  for (int i = 0; i < N; i++) cin >> L[i];
  
 sort(L.begin(), L.end());
 
 long long res = 0;
  
 for (int i = 0; i < N; i++) {
   int k = i;
   for (int j = i+1; j < N; j++) {
     while(k < N && L[k] < L[i] + L[j]) ++k;
     res += k - (j + 1);
   }
 }
  cout << res << endl;
  
}

Measured memory_bytes: 256
import sys
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7

N, K = LI()
P = LI()

# 最小の合計価値を算出せよ?
ans = 0
P.sort()
for i in range(K):
    ans += P[i]
print(ans)


Measured memory_bytes: 9088
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long int ll;

int main() {
	ll N;
	cin >> N;
	vector<ll> a(N);
	for (int i = 0; i < N; ++i) cin >> a[i];
	a.push_back(-1);

	ll ans = 0;
	ll cl = -1;
	ll conti = 1;
	for (int i = 0; i <= N; ++i) {
		if (a[i] == cl) ++conti;
		else {
			ans += conti / 2;
			cl = a[i];
			conti = 1;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
from sys import stdin

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))

for i in range(n-1,0,-1):
    if li[i-1]-li[i] > 1:
        print("No")
        exit()
    elif li[i-1]-li[i] == 1:
        li[i-1] -= 1
print("Yes")

Measured memory_bytes: 14396
A, B, C, D = gets.chomp.split(" ").map(&:to_i)

puts (B - A + 1) - (B / C - (A - 1) / C) - (B / D - (A - 1) / D) + (B  / C.lcm(D) - (A - 1) / C.lcm(D))


Measured memory_bytes: 1788
#include <stdio.h>
 
int main(void){
 
  char S[4], T[4];
  int i, count;
 
  scanf("%s", &S);
  scanf("%s", &T);
  for(i = 0; i <= 2 ;i++)
  {
    if(S[i] == T[i])
    count++;
  }
  printf("%d", count);
return 0;
}


Measured memory_bytes: 128
(defn abc124-D [S K]
  (let [{:keys [last-c xs]}
        (loop [e (first S)
               [c & r] S
               [n & acc0 :as acc] [0]]
          (if (not c)
            {:xs acc :last-c e}
            (if (= e c)
              (recur e r (cons (inc n) acc0))
              (recur c r (cons 1 acc)))))
        xs (if (= \1 last-c) xs (cons 0 xs))
        xs (reverse xs)
        xs (if (= \1 (first S)) xs (cons 0 xs))
        humps (/ (dec (count xs)) 2)]
    (if (>= K humps)
      (count S)
      (let [subsums (reduce
                      (fn [[sum acc] x]
                        (let [sum (+ sum x)] [sum (conj acc sum)]))
                      [0 [0]]
                      xs)
            [_ subsums] subsums
            windows (for [a (range 0 (- (count subsums)
                                        (* 2 K)) 2)]
                      [a (+ a (* 2 K))])
            cands (map (fn [[a b]] (- (nth subsums (inc b))
                                      (nth subsums a))) windows)]
        (reduce max cands)))))
(defn main-abc124-D []
  (let [_ (read) K (read)
        _ (read-line)
        S (read-line)]
    (println (abc124-D S K))))
(main-abc124-D)

Measured memory_bytes: 89876
#include<bits/stdc++.h>
 
#define ll long long 
#define in freopen("input.txt", "r", stdin)
#define out freopen("output.txt", "w", stdout)
#define skorost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) 

using namespace std ;
 
ll z , o , ans ;

ll N = 1e9 + 7 ;

int code(  ){

	int n , m ;

	cin >> n >> m ;

	for( int i = 0 ; i <= n ; i ++ ){

		for( int j = 0 ; j <= n ; j ++ ){

			if( ( i * 2 ) + ( j * 4 ) == m && i + j == n ){

				cout << "Yes" << endl ;

				return 0 ;

			}

		}

	}

	cout << "No" << endl ;

	return 0 ;

}

int main(){ skorost ;

	int tjk = 1 ;

	// cin >> tjk ;

	while( tjk -- ){

		code( ) ;

	}

}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define deb(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;
typedef long long int ll;
typedef string str;

ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;     
  
    x = x % p;   
    while (y) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1;  
        x = (x*x) % p; 
    } 
    return res; 
} 
 
ll nCrModP(ll n, ll r, ll p) 
{ 
    if (!r) 
      return 1; 
  
	ll fac[n+1]; 
   	fac[0] = 1; 
    for (ll i=1 ; i<=n; i++) 
        fac[i] = fac[i-1]*i%p; 
  
    return (fac[n]* power(fac[r], p-2,p) % p * power(fac[n-r], p-2,p) % p) % p; 
}

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

void fast(){
	ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
ll dp[10000004];
int main ()
{
	ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
	ll t,n,m,k,i,a,b,j;
	for(i=1;i<10000001;i++)
	dp[i]=1;
	for(i=2;i<10000002;i++)
	{
		
		for(j=i;j<10000002;j+=i)
			dp[j]++;
		dp[i]*=i;
		dp[i]+=dp[i-1];
	}
	// deb(dp[2],dp[3],dp[4]);
	cin >> n ;
	cout << dp[n] << "\n";
	return 0;
}

Measured memory_bytes: 81736
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define int long long
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define inf 1000000000000000007
#define f first
#define s second
#define mini(c,a,b) *min_element(c+a,c+b)
#define maxi(c,a,b) *max_element(c+a,c+b)
//printf("%.12Lf\n",c);
int keta(int x){
	rep(0,i,30){
		if(x<10){
			return i+1;
		}
		x=x/10;
	}
}
int gcd(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return bb;
		}	
		bb=bb%aa;
		if(bb==0){
			return aa;
		}
	}
}	
int lcm(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return x/bb*y;
		}	
		bb=bb%aa;
		if(bb==0){
			return x/aa*y;
		}
	}
}
bool p(int x){
	if(x==1)return false;
	rep(2,i,sqrt(x)+1){
		if(x%i==0&&x!=i){
			return false;
		}
	}	
	return true;
}
int primes[200];
int prime[1000000];
int pr[100000];
int el[314514],wl[314514];
int er[314514],wr[314514];
int a[114514];
int b[214514],c[214514];
int k[11];
int s[11][11];
int pp[11];
int ss[1919][11];
signed main(){
	ic(n) 
	rep(0,i,n)cin>>a[i];
	int ans=1145141919,sum=0;
	rep(0,j,100){
		rep(0,i,n)sum+=(a[i]-j)*(a[i]-j);
		if(sum<ans)ans=sum;
		sum=0;
	}
	c(ans)
}		

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

string cal(vector<int> nums, int sum, string s){
  //cout << sum << ":" << s << endl;
  string result;
  if(s.size() == 3){
    if(sum == 7){
      //cout <<"!1!"<< sum << ":" << s << endl;
      return s;
    }
    else{
      //cout <<"!2!"<< sum << ":" << s << endl;
      return "";
    }
  }
  result += cal(nums, sum + nums.at(s.size()+1), s + "+");
  if(result != ""){
    return result;
  }
  result += cal(nums, sum - nums.at(s.size()+1), s + "-");
  if(result != ""){
    return result;
  }
  return result;
}  
  

int main(){
  string str;
  vector<int> nums(4);
  cin >> str;
  for(int i = 0; i < 4; i++){
    nums.at(i) = stoi(str.substr(i,1));
  }
  string ops = cal(nums, nums.at(0), "");
  for(int i = 0; i < 4; i++){
    cout << nums.at(i);
    if(i < 3){
      cout << ops.at(i);
    }
    else{
      cout << "=7" << endl;
    }
  }
  return 0;
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int64;
#define debug(x) cerr << #x << ":" << x << endl;

int main()
{
  string S;
  cin >> S;
  int ans = 0;
  for (int i = 0; i < S.size() - 1; ++i) {
    if (S[i + 1] != S[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}


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

#define file(s) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define go(x, i) for(register int i = head[x]; i; i = nxt[i])
#define For(i, a, b) for(register int i = (a), i##_end_ = (b); i <= i##_end_; ++ i)
#define FOR(i, a, b) for(register int i = (a), i##_end_ = (b); i >= i##_end_; -- i)
#define debug(x) cout << #x << " = " << x << endl
#define mem(a, b) memset(a, b, sizeof(a))
#define cpy(a, b) memcpy(a, b, sizeof(a))
#define min(a, b) (a < b ? a : b)
#define max(a, b) (b < a ? a : b)
#define inf (0x3f3f3f3f)
#define INF (1e18)
#define pb push_back
#define mp make_pair
#define x first
#define y second
typedef unsigned long long ull;
typedef unsigned int uint;
typedef long long ll;
typedef std::pair<ll, int> PLI;
typedef std::pair<int, int> PII;
typedef double db;

using namespace std;
const int N = 1100;
int n, m;
struct Point {
	int x,y;
}A[N];
void Solve(int x,int y) {
	FOR(i, 30, 0) {
		int move = 1 << i;
		if(abs(x) >= move) {
			if(x > 0) x -= move,putchar('R');
			else x += move,putchar('L');
		}
		else if(abs(y) >= move) {
			if(y > 0) y -= move,putchar('U');
			else y += move,putchar('D');
		}
		else {
			if(abs(x) > abs(y)) {
				if(x >= 0) x -= move,putchar('R');
				else x += move,putchar('L');
			}
			else {
				if(y >= 0) y -= move,putchar('U');
				else y += move,putchar('D');
			}
		}
	}
}
		
int main() {
	scanf("%d",&n);
	int flag = -1;
	For(i, 1, n) {
		scanf("%d%d",&A[i].x,&A[i].y);
		if(flag != ((A[i].x + A[i].y) & 1)) {
			if(flag != -1) {flag = -1;break;}
			flag = (A[i].x + A[i].y) & 1;
		}
	}
	if(flag == -1) {puts("-1");return 0;}
	cout << (32 - flag) << endl;
	FOR(i, 30, 0) cout << (1 << i) << " " ;
	puts(flag ? " " : "1");
	if(!flag) for(int i = 1;i <= n;++i) ++A[i].y;
	for(int i = 1;i <= n;++i) {
		Solve(A[i].x,A[i].y);
		puts(flag ? "" : "D");
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int seg[800005],t;
void up(int st,int ed,int lv,int po,int val)
{
	int md=(st+ed)/2;
	if(st>po || ed<po)
	{
		return;
	}
	if(st==po && ed==po)
	{
		seg[lv]=val;
		return;
	}
	up(st,md,lv*2,po,val);
	up(md+1,ed,lv*2+1,po,val);
	seg[lv]=max(seg[lv*2],seg[lv*2+1]);
}
int q(int st,int ed,int lv,int po)
{
	//printf("%d %d\n",st,ed);
	int md=(st+ed)/2;
	if(st>po)
	{
		return 0;
	}
	if(st>=1 && ed<=po)
	{
		return seg[lv];
	}
	return max(q(st,md,lv*2,po),q(md+1,ed,lv*2+1,po));
}
void upp(int st,int ed,int lv,int po,int val)
{
	int md=(st+ed)/2;
	if(st>po || ed<po)
	{
		return;
	}
	if(st==po && ed==po)
	{
		//printf("e%d %d\n",st,val);
		seg[lv]=val;
		return;
	}
	upp(st,md,lv*2,po,val);
	upp(md+1,ed,lv*2+1,po,val);
	seg[lv]=min(seg[lv*2],seg[lv*2+1]);
}
int qq(int st,int ed,int lv,int po)
{
	int md=(st+ed)/2;
	if(st>po)
	{
		return 1e9;
	}
	if(st>=1 && ed<=po)
	{
		//printf("tt%d %d %d\n",st,ed,seg[lv]);
		return seg[lv];
	}
	return min(qq(st,md,lv*2,po),qq(md+1,ed,lv*2+1,po));
}
long long lr[200005],rl[200005],val[200005];
main()
{
	scanf("%d",&t);
	for(int i = 1;i <= t;i++)
	{
		scanf("%lld",&val[i]);
	}
	for(int i = 1;i <= t;i++)
	{
		lr[i]=i-q(1,t,1,val[i]);
		up(1,t,1,val[i],i);
	}
	for(int i = 0;i < 800005;i++)
	seg[i]=t+1;
	//printf("gg");
	for(int i = t;i >= 1;i--)
	{
		rl[i]=qq(1,t,1,val[i])-i;
		upp(1,t,1,val[i],i);
	}
	long long sm=0;
	for(int i = 1;i <= t;i++)
	{
		sm+=lr[i]*rl[i]*val[i];
	}
	for(int i = 1;i <= t;i++)
	{
	//	printf("%d %d\n",lr[i],rl[i]);
	}
	printf("%lld",sm);
}

Measured memory_bytes: 8064
import java.util.Scanner;

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

		Scanner scan = new Scanner(System.in);

		int a = scan.nextInt();
		int b = scan.nextInt();

		if(a > b){
			System.out.println("a > b");
		}else if(a < b){
			System.out.println("a < b");
		}else if(a == b){
			System.out.println("a == b");
		}
	}
}

Measured memory_bytes: 26132
#include<bits/stdc++.h>
using namespace std;
typedef long long unsigned int ll;

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    char s[3][13];

    Scs(s[0]);
    Scs(s[1]);
    Scs(s[2]);

    printf ("%c%c%c\n", s[0][0]-32, s[1][0]-32, s[2][0]-32);

    return 0;
}



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

using namespace std;
using ll=long long;
using ull=unsigned long long;

typedef pair<int,int>Pi;
typedef pair<long long,long long>P;
typedef pair<long long,P>PP;
typedef pair<P,P>PPP;

const long long MOD=1e9+7;
const long long INF=5e18;
const int di[4]={1,0,-1,0};
const int dj[4]={0,1,0,-1};

#define fr first
#define sc second
#define pb push_back
#define eb emplace_back
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define double long double

int n,a,ans;

void input(){
	cin>>n;
	return;
}

void solve(){
	for(int i=0;i<n;i++){
		cin>>a;
		if(a%2==0)ans++;
	}
	cout<<ans<<endl;
	return;
}

int main(){
	input();
	solve();
	return 0;
}


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

for i in range(K):
  if min(A) == N:
    ans = [N]*N
    print(*ans)
    exit()
  B = [0 for _ in range(N)]
  for j in range(N):
    left = max(0,j-A[j])
    right = min(N-1,j+A[j])
    B[left] += 1
    if right+1 <= N-1:
      B[right+1] -=1
  #print(B)
  for t in range(1,N):
    B[t] += B[t-1]
  A = B
print(*B)

Measured memory_bytes: 171032
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

vector<pii> g[100005];
vector<int> z;
pii a[100005];
bool b[100005];

int dfs(int x, int p) {
    //cout << x << ' ' << p << '\n';
    int c = 0;
    for (pii i : g[x]) if (!b[i.first]) {
        b[i.first] = 1;
        c ^= dfs(i.first, i.second);
    }
    if (p && c != a[x].second) z.push_back(p);
    //cout << x << ' ' << p << ' ' << c << ' ' << a[x].second << '\n';
    return c ^ a[x].second;
}

int main() {
    ios::sync_with_stdio(false);
    int n, m, u, v;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> a[i].first >> a[i].second;
    sort(a + 1, a + n + 1);
    //for (int i = 1; i <= n; i++) cout << a[i].second << '\n';
    for (int i = n + 1; i; i--) {
        if (a[i].second != a[i - 1].second) a[i].second = 1;
        else a[i].second = 0;
    }
    for (int i = 1; i <= m; i++) {
        int l, r;
        cin >> l >> r;
        u = (int)(lower_bound(a + 1, a + n + 1, make_pair(l, 0)) - a);
        v = (int)(lower_bound(a + 1, a + n + 1, make_pair(r + 1, 0)) - a);
        g[u].push_back({v, i});
        g[v].push_back({u, i});
        //cout << u << ' ' << v << '\n';
    }
    //for (int i = 1; i <= n; i++) cout << a[i].second << '\n';
    for (int i = 1; i <= n; i++) if (!b[i]) {
        b[i] = 1;
        if (dfs(i, 0)) {
            cout << -1;
            return 0;
        }
    }
    sort(z.begin(), z.end());
    cout << z.size() << '\n';
    for (int i : z) cout << i << ' ';
    //0111001000010
    //0100101100011
    //(1,6) (7,8) (9,12) (9,11) (4,8)
}


Measured memory_bytes: 17712
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<(n); i++)
#define int long long
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000000
using namespace std;
signed main(void){
    int p,q,r;cin>>p>>q>>r;
    cout<<min(p+q,min(q+r,r+p))<<endl;
}

Measured memory_bytes: 256
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
from fractions  import gcd
#input=sys.stdin.readline
#import bisect
x=int(input())
for a in range(-10**3,10**3):
    for b in range(-10**3,a):
        if pow(a,5)-pow(b,5)==x:
            print(a,b)
            exit()

Measured memory_bytes: 77556
import sys

n, y = map(int, input().split())
for i in range(n+1):
    for j in range(n-i+1):
        k = n - i - j
        if 10000*i + 5000*j + 1000*k == y:
            print("{} {} {}".format(i, j, k))
            sys.exit()
print('-1 -1 -1')

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;


int main()
{	
	ll n,k,a[400005],t[400005];
	bool flag[400005]={};
	vector<ll>v;
	cin>>n>>k;
	for(int i=1;i<=n;i++)cin>>a[i];
	int s=1,cnt=0,h=0;
	for(int i=1;i<=2*n;i++)
	{
		if(!flag[s])
		{
			flag[s]=true;
			cnt++;
			t[cnt]=s;
			s=a[s];
		}
		else
		{	
			h=s;
			break;
		}
	}
	bool check=false;
	for(int i=1;i<=cnt;i++)
	{
		if(t[i]==h)
		{
			check=true;
			if(k>=(i-1))k-=i-1;
			else
			{
				cout<<t[k+1]<<endl;
				return 0;
			}
		}
		if(check)
		{
			v.push_back(t[i]);
		}
	}
	k%=v.size();
	cout<<v[k]<<endl;
	return 0;
}


Measured memory_bytes: 8412
#include <iostream>
#include <vector>
#include <numeric>
#include <climits>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm> 


#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{"; for(auto nth : list){ cout << nth << " ";}cout << "}" << endl;

using namespace std;


int main() {

	while(1){
		
		int n;
		cin >> n;
		string str1,str2;
		int ans=0;

		if(n==0) break;
	
		for(int i=n;i>0;i--){
			cin >> str1;

			i--;
			if(i==0){
				break;
			}
			cin >> str2;
			
			if((str1=="lu"&&str2=="ru")||(str1=="ru"&&str2=="lu")||(str1=="ld"&&str2=="rd")||(str1=="rd"&&str2=="ld")) ans++;
		}
		
		cout << ans << endl;
		
	}
	


}

Measured memory_bytes: 1208
if __name__ == '__main__':
    M=998244353
    n,m,k=map(int,input().split())
    p,c=[m],[1]
    for i in range(1,n):
      p+=[p[-1]*(m-1)%M]
      c+=[c[-1]*(n-i)*pow(i,-1,M)%M]
    print(sum(p[n-i-1]*c[i] for i in range(k+1))%M)

Measured memory_bytes: 24836
from collections import Counter
from itertools import accumulate
from functools import reduce

N, M = map(int, input().split())
A = [int(x) for x in input().split()]

c = Counter([0] + [x % M for x in accumulate(A)])
ans = reduce(lambda x,y:x+y, [v*(v-1)//2 for v in c.values()])
print(ans)


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

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

    int sum = 0;
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
        sum += a[i];
        a[i] *= n;
    }
    int diff = 1e7;// INF
    int ans = 0;
    for(int i=0; i<n; i++){
        if(abs(a[i] - sum) < diff){
            ans = i;
            diff = abs(a[i] - sum);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3572
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <random>
#include <iomanip>

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

typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvinv(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)
#define index_of(as, x) \
  distance(as.begin(), lower_bound(as.begin(), as.end(), x))

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define concat(xs, ys) (xs).insert((xs).end(), (ys).begin(), (ys).end())

const int mod = 1000000007;

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

  int n, k;
  cin >> n >> k;

  vector<long> a(n);
  rep(i, n) {
    cin >> a[i];
  }

  vector<long> b(n+1);
  vector<long> c(n+1);
  b[0] = 0;
  c[0] = 0;
  rep(i, n) {
    b[i+1] = a[i]+b[i];
    c[i+1] = a[i] > 0 ? a[i]+c[i] : c[i];
  }

  long res = 0;
  rep(i, n-k+1) {
    long tmp = c[n] - c[i+k];
    tmp += max(0L, b[i+k] - b[i]);
    tmp += c[i] - c[0];
    res = max(res, tmp);
  }

  cout << res << endl;
}

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

int main(){
    int N,L;
    cin>>N>>L;
    int sum=0;
    for(int i=1;i<=N;i++){
        sum+=L+i-1;
    }
    int R=L+N-1,min=0;
    if(R<=0) min=R;
    else if(L>=0) min=L;
    
    cout<<(R+L)*(R-L+1)/2-min<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include <cstdint>
#include <utility>
#include <tuple>
#include <map>    
#include <queue> 
#include <set>  
#include <stack> 
#include <deque>  
#include <unordered_map> 
#include <unordered_set> 
#include <bitset>

using namespace std;

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

	sort(S.begin(), S.end());
	if (S.at(0) == S.at(1) && S.at(2) == S.at(3)&&S.at(1)!=S.at(2)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <stdio.h>

int
main()
{
        int stack[16];
        int *head;
        char buf[4];

        head = stack;
        while (fgets(buf, 4, stdin)){
                sscanf(buf, "%d", head);
                if (*head == 0) {
                        printf("%d\n", *--head);
                } else
                        head++;
        }

        return 0;
}

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

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 long long INF = 1LL << 60;

int main() {
    int N;
    long long W, weight[110], value[110];
    long long dp[110][100100] = {0};

    cin >> N >> W;
    for (int i = 0; i < N; i++) {
        cin >> weight[i] >> value[i];
    }

    for (int i = 0; i < N; i++) {
        for (int sum_w = 0; sum_w <= W; sum_w++) {
            if (sum_w - weight[i] >= 0) {
                chmax(dp[i + 1][sum_w], dp[i][sum_w - weight[i]] + value[i]);
            }
            chmax(dp[i + 1][sum_w], dp[i][sum_w]);
        }
    }

    cout << dp[N][W] << endl;
    return 0;
}

Measured memory_bytes: 86272
#include"bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
typedef pair<int, int> P;
bool rev(string s) {
	string t = s;
	reverse(t.begin(), t.end());
	return s == t;
}
signed main() {
	string s; cin >> s;
	string remx;
	rep(i, s.size())if (s[i] != 'x')remx.push_back(s[i]);
	if (rev(remx)) {
		s = "x" + s + "x";
		vector<int>cnt;
		int cx = 0;
		rep(i, s.size()) {
			if (s[i] == 'x')cx++;
			else {
				cnt.push_back(cx);
				cx = 0;
			}
		}
		cnt.push_back(cx);
		int ans = 0;
		rep(i, cnt.size() / 2) {
			ans += abs(cnt[i] - cnt[cnt.size() - 1 - i]);
		}
		cout << ans << endl;
	}
	else cout << -1 << endl;
}

Measured memory_bytes: 1656
N, M = map(int,input().split())
L = []
for i in range(M):
    p, y = map(int,input().split())
    L.append((p,y,i))
PY = sorted(L)
from collections import defaultdict
d = defaultdict(int)
ID = [None]*M
for p,y,i in PY:
    d[p] += 1
    ID[i] = d[p]
for i in range(M):
    p,y,j = L[i]
    print("{:06}{:06}".format(p, ID[i]))

Measured memory_bytes: 31564
#include <iostream>
#include <locale>
using namespace std;
int main(void){
    // Your code here!
    string a,b,c;
    cin >> a>>b>>c;
    int x,y;
    x = a.size();
    y = b.size();
    if(a[x-1] == b[0] && b[y-1] == c[0]){
        cout << "YES" <<endl;
    } 
    else {
        cout << "NO" <<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF (1<<29)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))
const int dx[] = {-1,0,0,1},dy[] = {0,1,-1,0};

typedef long long int ll;

using namespace std;

vector<int> s;
vector<int> score;
vector<int> leader;
void insort(vector<int> &v,int a){
    v.PB(s[a]);
    RREP(i,v.size()-1){
	if(v[i] > v[i+1]){
	    swap(v[i],v[i+1]);
	}else break;
    }
}
int main(){
    int n,nq;
    cin >> n >> nq;
    s = vector<int>(n);
    REP(i,n) cin >> s[i];
    score = s;
    sort(ALL(score));
    REP(i,nq){
	string query;
	int a;
	cin >> query >> a;
	a--;
	if(query == "ADD"){
	    insort(leader,a);
	}else if(query == "CHECK"){
	    a++;
	    if(leader.size() == 0){
		if(a >= n) cout << 0 << endl;
		else cout << "NA" << endl;
		continue;
	    }
	    int u = upper_bound(ALL(score),leader[leader.size()-1]) - score.begin();
	    if(a < n-u) cout << "NA" << endl;
	    else{
		int rx = a - (n - u);
		int h,l,m;
		h = leader[leader.size() - 1] + 1;
		l = 0;
		m = (h+l)/2;
		while(h-l>1){
		    int sum = 0;
		    int mini = 0;
		    REP(j,leader.size()){
			int tu = upper_bound(ALL(score),leader[j]) - score.begin();
			int tl = lower_bound(ALL(score),leader[j]-m) - score.begin();
			if(tl > mini) sum += tl - mini;
			mini = tu;
		    }
		    if(sum > rx){
			l = m;
		    }else{
			h = m;
		    }
		    m = (h+l)/2;
		}
		int sum = 0;
		int mini = 0;
		REP(j,leader.size()){
		    int tu = upper_bound(ALL(score),leader[j]) - score.begin();
		    int tl = lower_bound(ALL(score),leader[j]-m) - score.begin();
		    if(mini < tl) sum += tl - mini;
		    mini = tu;
		}
		if(sum > rx){
		    m++;
		}else{
		}
		cout << m << endl;
	    }	
	}else if(query == "REMOVE"){
	    auto p = lower_bound(ALL(leader),s[a]);
	    leader.erase(p);
	}
    }

    return 0;
}

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

string a;

void f(int p) {
	if (p == a.size()) {puts("YES"); exit(0);}
	if (a.substr(p, 5) == "dream") f(p + 5);
	if (a.substr(p, 5) == "erase") f(p + 5);
	if (a.substr(p, 7) == "dreamer") f(p + 7);
	if (a.substr(p, 6) == "eraser") f(p + 6);
}

int main()
{
	cin >> a;
	f(0);
    cout << "NO";
    return 0;
}

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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int N;
  cin >> N;
  vector<bool> is_prime(100001);
  REP(i, 100001) is_prime[i] = true;
  is_prime[0] = false;
  is_prime[1] = false;
  for (int i = 2; i * i <= 100000; ++i) {
    if (is_prime[i]) {
      for (int j = 2; i * j <= 100000; ++j) {
        is_prime[i * j] = false;
      }
    }
  }
  vector<int> ans;
  REP(i, 100001) {
    if (is_prime[i] && i % 5 == 1) ans.push_back(i);
    if (ans.size() == N) break;
  }
  REP(i, N) {
    if (i != 0) cout << " ";
    cout << ans[i];
  }
  cout << "\n";
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1ll;while(b){if(b&1)ans=ans*a%MOD;a=a*a%MOD;b>>=1;}return ans;}
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
int n;
map<ll,int> st;
ll a[maxn];
ll bin[2334];
int main()
{
//	    freopen("C:\\Users\\DH_M\\Desktop\\code_io\\in.txt.txt","r",stdin);
	//    freopen("C:\\Users\\DH_M\\Desktop\\code_io\\out.txt.txt","w",stdout);
	gbtb;
	cin>>n;
	repd(i,1,n)
	{
		cin>>a[i];
		st[a[i]]+=1;
	}
	sort(a+1,a+1+n);
	bin[0]=1ll;
	repd(i,1,33)
	{
		bin[i]=bin[i-1]*2ll;
	}
	int ans=0;

    for(int j=33;j>=0;j--)
    {
        int l=1;
        int r=n;
        while(l<r)
        {
            if(a[l]==-1||(~a[r]&&a[l]+a[r]<bin[j]))
            {
                l++;
            }else if(a[r]==-1||(a[l]+a[r]>bin[j]))
            {
                r--;
            }
            else
            {
                ans++;
                a[l]=-1;
                a[r]=-1;
            }
        }

	}
	cout<<ans<<endl;

    return 0;
}

inline void getInt(int* p) {char ch;do {ch = getchar();}
while (ch == ' ' || ch == '\n');if (ch == '-') {*p = -(getchar() - '0');
while ((ch = getchar()) >= '0' && ch <= '9') {*p = *p * 10 - ch + '0';}}
else {*p = ch - '0';while ((ch = getchar()) >= '0' && ch <= '9')
{*p = *p * 10 + ch - '0';}}}


Measured memory_bytes: 14336
def main():
  
  n,k=map(int,input().split())
  a=list(map(int,input().split()))
  
  count=lambda arr,now:sum(element<now for element in arr)
  b=[[count(a[:i],a[i]),count(a[i+1:],a[i])] for i in range(n)]

  ans=0
  prime=10**9+7
  
  for x in b:
    left=x[0]
    right=x[1]
    res=(k-1)*k//2*(right+left)+right*k
    ans+=res%prime
    
  print(ans%prime)

if __name__=="__main__":
  main()

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

void solve(int n, int m) {
  vi vec(n);
  rep(i, m) rep(j, n) {
    int a; std::cin >> a;
    vec[j] += a;
  }
  int ans = *max_element(rng(vec));
  std::cout << ans << "\n";
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  while (1) {
    int n, m; std::cin >> n >> m;
    if (n == 0 && m == 0) break;
    solve(n, m);
  }
}



Measured memory_bytes: 3136
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder_solve
{
    class Program
    {
        public const ulong mod = 1000000007;

        static void Main(string[] args)
        {
            var nk = Console.ReadLine().Split().Select(int.Parse).ToArray();
            long[] h = new long[nk[0]];
            long ans = 1000000000;
            for(int i = 0; i < nk[0]; i++)
            {
                h[i] = long.Parse(Console.ReadLine());
            }
            Array.Sort(h);
           

            for(int j = 0; j <= nk[0]-nk[1]; j++)
            {
                
                long minh = h[j];
                long maxh = h[j+nk[1]-1];
                ans = Math.Min(ans, maxh - minh);
            }
           
            
            Console.WriteLine(ans);
            
        }

        static public long Input()
        {
            return long.Parse(Console.ReadLine());
        }

        static public string[] Input2()
        {
            return Console.ReadLine().Split();
        }
        
        static public long[] Input3()
        {
            string[] data = Console.ReadLine().Split();
            long[] res = new long[data.LongLength];
            for(long i = 0; i < data.LongLength; i++)
            {
                res[i] = long.Parse(data[i]);
            }
            return res;
        }
        public static long Choose(long n, long a)
        {
            long x = 1;
            long y = 1;
            for (long i = 0; i < a; i++)
            {
                x *= n - i;
                y *= i + 1;
            }
            return x / y;
        }

        public static long Gcd(long a, long b)
        {
            long x = Math.Max(a, b);
            long y = Math.Min(a, b);
            if (x % y == 0) return y;
            else return Gcd(y, x % y);
        }
    }
}


Measured memory_bytes: 18140
#include <iostream>
#include <algorithm>
#include <iterator>

#include <vector>
#include <queue>
#include <unordered_map>

using namespace std;

int main(){
    std::string S;
    cin>>S;
    for(int i=0; i<S.size(); i++){
        if(i%2==0){
            if(S[i]=='L'){
                cout << "No" << endl;
                return 0;
            }
        }else{
            if(S[i]=='R'){
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout<<"Yes"<<endl;


    return 0;
}


Measured memory_bytes: 256