akhauriyash/Code-Regression huggingface dataset:
def checkCapacity(W,k,P):
    ws = 0
    cnt = 1
    for wi in W:
        if wi > P: return False
        ws += wi
        if ws > P:
            cnt += 1
            ws = wi
        if cnt > k: return False
    return True

if __name__=='__main__':
    n,k = list(map(int, input().split()))
    W = list(map(int,[input() for _ in range(n)]))
    Pmax = sum(W)
    Pmin = 0
    while Pmin < Pmax:
        P = (Pmax + Pmin) // 2
        if checkCapacity(W,k,P):
            Pmax = P
        else:
            Pmin = P + 1
    print(Pmax)

Measured memory_bytes: 17840
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

using i64 = long long;
#define forn(a, e) for (i64 a = 0; a < (i64)(e); a++)
#define forr(a, s, e) for (i64 a = s; a < (i64)(e); a++)
#define fore(e, a) for (auto& e : a)

#ifdef LOCAL
#define logv(a) {cerr << #a << " = "; fore(e, a) {cerr << e << " ";} cerr << "\n";}
#define logvp(a) {cerr << #a << " = "; fore(e, a) {cerr << "(" << e.first << ", " << e.second << ") ";} cerr << "\n";}
#define logvv(a) {cerr << #a << " = \n"; fore(r, a) { fore(e, r) {cerr << e << " ";} cerr << "\n";} }
#define logvf(a, field) {cerr << #a"."#field << " = \n"; fore(e, a) { cerr << e.field << " ";} cerr << "\n"; }
#define logvff(a, f1, f2) {cerr << #a".{"#f1 << ", "#f2 << "} = \n"; fore(e, a) { cerr << "(" << e.f1 <<", " << e.f2 << ") ";} cerr << "\n"; }
#define logs(a) cerr << #a << " = " << (a) << "\n";
#define logss(a, b) cerr << #a << " = " << (a) << ", " << #b << " = " << (b) << "\n";
#define logp(a) cerr << #a << " = " << "(" << a.first << ", " << a.second << ")" << "\n";
#define cond(pred, stmt) if (pred) { stmt }
#else
#define logv(a)
#define logvp(a)
#define logvv(a)
#define logvf(a, field)
#define logvff(a, f1, f2)
#define logs(a)
#define logss(a, b)
#define logp(a)
#define cond(pred, stmt)
#endif

using iip = pair<int, int>;
using llp = pair<i64, i64>;
using ivec = vector<int>;
using llvec = vector<i64>;
using svec = vector<string>;
template<typename T> using vec = vector<T>;

template<typename T, typename Dim>
auto make_vec(T value, Dim dim) { return vector<T>(dim, value); }
template<typename T, typename Dim1, typename... Dim>
auto make_vec(T value, Dim1 dim1, Dim... dims) { return make_vec(make_vec(value, dims...), dim1); }

template<typename T>
bool uax(T& v, const T& newv) { if (v < newv) { v = newv; return true; } else return false; }
template<typename T>
bool uin(T& v, const T& newv) { if (v > newv) { v = newv; return true; } else return false; }

template<typename T>
istream& operator>>(istream& is, vector<T>& c) { for (auto& e : c) is >> e; return is; }
template<typename T, size_t N>
istream& operator>>(istream& is, array<T, N>& c) { for (auto& e : c) is >> e; return is; }

template<typename ...T>
istream& read(T&... args) { return (cin >> ... >> args); }

static mt19937 rande(123123);
template<typename T>
T rand_int(T from, T to) { uniform_int_distribution<T> distr(from, to); return distr(rande); }

// const i64 INF = 1e18;
const int INF = 2e9;
const i64 M = 1e9 + 7;
const int MXB = 20;
using bin = bitset<MXB + 1>;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    rande.seed(chrono::steady_clock::now().time_since_epoch().count());

    int n;
    while (read(n)) {
        llvec a(n);
        read(a);

        i64 ans = a[0] - 1;
        i64 c = 2;
        forr(i, 1, n) {
            if (a[i] == c) {
                c++;
            } else {
                ans += (a[i] - 1) / c;
            }
        }
        cout << ans << endl;
    }
}

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

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v),v.end()));
#define DUMP(v) REP(i, (v).size()) { cout << v[i]; if (i != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
///(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)///
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, c, k;
	cin >> n >> c >> k;
	vi t(n);
	REP(i, n) cin >> t[i];
	sort(ALL(t));
	int ans = 0, p = 0;
	while (p < n) {
		int i = p;
		while (i < n&&i - p < c&&t[i] - t[p] <= k) {
			++i;
		}
		ans++;
		p = i;
	}
	cout << ans << endl;


	return 0;
}


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

#define LL long long
typedef pair<int, int> pii;

template< typename T > inline void read(T &x)
{
    static char _c;
    static bool _f;

    x = 0;
    _f = 0;
    _c = getchar();

    while(_c < '0' || '9' < _c) {if(_c == '-') _f = true; _c = getchar();}
    while('0' <= _c && _c <= '9') {x = (x << 1) + (x << 3) + (_c & 15); _c = getchar();}
    if(_f) x = -x;
}

template < typename T > inline void Min(T &x, T y) {if(y < x) x = y;}
template < typename T > inline void Max(T &x, T y) {if(x < y) x = y;}


#define lowbit(x) ((x) & -(x))
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(l,r) ((l)+(((r)-(l))>>1))
#define fi first
#define se second
#define mk make_pair
#define pb push_back

const int INF = 0x3f3f3f3f;
const double pi = (double) acos(-1.0);
const double eps = (double) 1e-8;
const int MOD = (int) 1e9 + 7;
//const int MOD = (int) 998244353;
const int maxn = (int) 2e5 + 20;
const int maxm = (int) 1e6 + 20;

inline int sig(double x) {return x < -eps ? -1 : eps < x;}
LL fp(LL a, LL n, LL MOD)
{
    if(n < 0) a = fp(a, MOD - 2, MOD), n = -n;
    LL res = 1; for(; n; n >>= 1, a = a * a % MOD) if(n & 1) res = res * a % MOD; return res;
}

int n;
LL a[maxn], b[maxn];

void work()
{
    cin >>n;
    for(int i = 0; i < n; i++) cin >>a[i];
    for(int i = 0; i < n; i++) b[a[i]]++;

    LL sum = 0;
    for(int i = 1; i <= n; i++) sum += b[i] * (b[i] - 1) / 2;

    for(int i = 0; i < n; i++)
    {
        LL c = b[a[i]];
        LL t = sum - (c * (c - 1) / 2) + ((c - 1) * (c - 2) / 2);
        cout <<t <<endl;
    }
}


int main(int argc, char **argv)
{
#ifdef yukihana0416
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // yukihana0416
//    get_prime();
//    pre();
    int tc = 1;
//    read(tc);
    for(int ca = 1; ca <= tc; ca++)
    {
//        printf("Case #%d: ", ca);
        work();
    }
    return 0;
}


Measured memory_bytes: 4736
#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
vector<string> ans;

void solve(int i, int n, string acc, set<char> x) {
    if (i == n) {
        ans.push_back(acc);
        return;
    }

    rep(j, x.size() + 1) {
        auto tmp = x;
        tmp.insert((char)('a' + j));
        solve(i + 1, n, acc + (char)('a' + j), tmp);
    }

    // if (prev == 'a') {
    //     solve(i + 1, n, acc + 'a');

    // } else {
    //     solve(i + 1, n, acc + 'a');
    //     solve(i + 1, n, acc + prev);
    //     solve(i + 1, n, acc + (char)(prev + 1));
    // }
}

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

    solve(1, n, "a", {'a'});
    for (auto x: ans) {
        cout << x << endl;
    }
}


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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end(), greater<int>());
    int alice = 0;
    int bob = 0;
    for(int i = 0; i < n; i++){
        if(i % 2) bob += a[i];
        else alice += a[i];
    }
    cout << alice - bob << endl;
    return 0;
}

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

ans = 0
for x in range(1,10):
    for y in range(1,10):
        a_count = 0
        b_count = 0
        for z in range(1,7):
            if z == 1:
                if x == y and x <= N:
                    a_count += 1
                continue
            num_min = y + x * (10 ** (z-1))
            num_max = y + x * (10 ** (z-1)) + 10 * ((10 ** (z-2))-1)
            if num_max >= N:
                a_count += max(0,(N-num_min)//10+1)
                break
            a_count += 10 ** (z-2)
        for z in range(1,7):
            if z == 1:
                if x == y and x <= N:
                    b_count += 1
                continue
            num_min = x + y * (10 ** (z-1))
            num_max = x + y * (10 ** (z-1)) + 10 * ((10 ** (z-2))-1)
            if num_max >= N:
                b_count += max(0,(N-num_min)//10+1)
                break
            b_count += 10 ** (z-2)
        ans += a_count * b_count
print(ans)

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int N;
    cin >> N;
    int t = 0;
    vector<int> v(N + 1);
    for(int i = 0; i < N + 1; ++i) {
        cin >> v[i];

    }

    LL res = 0;
    for(int i = 0; i < N; ++i) {
        int b;
        cin >> b;
        if(b <= v[i]) {
            res += b;
            v[i] = 0;

        } else {
            b -= v[i];
            res += v[i];
            if(b <= v[i + 1]) {
                res += b;
                v[i + 1] -= b;

            } else {
                res += v[i + 1];
                v[i + 1] = 0;

            }
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 640
/*
    author: kartik8800
*/
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define fr(a,b) for(ll i = a; i < b; i++)
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define prDouble(x) cout << fixed << setprecision(10) << x 
#define triplet pair<ll,pair<ll,ll>>
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;

double dp[3001][3001];
double solve(vector<double>& ar, int i, int x)
{
    if(x == 0)
        return 1;
    if(i == 0)
        return 0;
    if(dp[i][x] > -0.9)
        return dp[i][x];
    return dp[i][x] = ar[i]*solve(ar, i-1, x-1) + (1-ar[i])*solve(ar,i-1,x);  
}

int main() {
    int n;
    cin >> n;
    memset(dp, -1, sizeof dp);
    vector<double> ar(n+1);
    fr(1,n+1)
        cin >> ar[i];    
    prDouble(solve(ar, n, (n+1)/2));
}


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

bool C(int v,int maxi,int a,int b){
	b-=(v-1)/maxi;
	ll cap=(ll)(a-v+1)*maxi;
	if(cap>=b)return true;
	return false;
}

string solve(int a,int b,int c,int d){
	int maxi=(max(a,b)+min(a,b))/(min(a,b)+1);
	int l=0,r=a+1;
	while(l+1<r){
		int mid=(l+r)/2;
		if(C(mid,maxi,a,b))l=mid;
		else r=mid;
	}
	string ans="";
	int lenf=l+((l-1)/maxi);
	for(int i=c-1;i<d;i++){
		if(i<lenf){
			if(i%(maxi+1)==maxi)ans+='B';
			else ans+='A';
		}else{
			if((a+b-i-1)%(maxi+1)==maxi)ans+='A';
			else ans+='B';
		}
	}
	return ans;
}

int main(void){
	int q;
	scanf("%d",&q);
	for(int i=0;i<q;i++){
		int a,b,c,d;
		scanf("%d%d%d%d",&a,&b,&c,&d);
		cout << solve(a,b,c,d) << endl;
	}
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
    int x, a, b;
    scanf("%d%d%d", &x, &a, &b);
    int disa = abs(x - a), disb = abs(x - b);
    if (disa > disb)
    {
        printf("B\n");
    }
    else
    {
        printf("A\n");
    }
    return 0;
}

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//template
//--------------------------------------------
template<typename T>
istream& operator >>(istream& is, vector<T>& vec) {
  for(T& x: vec) is >> x;
  return is;
}
template<typename T>
ostream& operator <<(ostream& os, const vector<T>& vec) {
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : "\t" );
  }
  return os;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<vector<T>>& vv) {
	for (int i = 0; i < vv.size(); ++i) {
		s << vv[i] << endl;
	}
	return s;
}

//main code

int main(int argc, char const* argv[])
{
	int n,m,k;
	cin >> n >> m >> k;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= m; j++) {
			if (k == n*m - (i*j+(n-i)*(m-j))) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}


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

#define N (3*100000)

int main() {
  int H, W, M, h[N], w[N], rsum[N] = {0}, csum[N] = {0}, rsummax = 0, csummax = 0, ncsummaxarg = 0, nrsummaxarg = 0, nbomb = 0;
  scanf("%d%d%d", &H, &W, &M);
  for (int i = 0; i < M; i++) {
    scanf("%d%d", &h[i], &w[i]);
    h[i]--;
    w[i]--;
    rsum[h[i]]++;
    csum[w[i]]++;
    if (rsummax < rsum[h[i]]) {
      rsummax = rsum[h[i]];
    }
    if (csummax < csum[w[i]]) {
      csummax = csum[w[i]];
    }
  }
  for (int i = 0; i < H; i++) {
    if (rsum[i] == rsummax) {
      nrsummaxarg++;
    }
  }
  for (int i = 0; i < W; i++) {
    if (csum[i] == csummax) {
      ncsummaxarg++;
    }
  }
  for (int i = 0; i < M; i++) {
    if (rsum[h[i]] == rsummax && csum[w[i]] == csummax) {
      nbomb++;
    }
  }
  if (nrsummaxarg*ncsummaxarg == nbomb) {
    printf("%d\n", rsummax+csummax-1);
  } else {
    printf("%d\n", rsummax+csummax);
  }
  return 0;
}


Measured memory_bytes: 6844
#include<stdio.h>
using namespace std;
typedef long long ll;

int n, m;
ll dp[51][51][51*51];
const ll p = 1000000007;

int main() {
    scanf("%d %d", &n, &m);

    if (m%2==1) {
        printf("0");
        return 0;
    }

    for (int i=0; i<=n; i++) {
        for (int j=0; j<i; j++) {
            for (int k=0; k<=i*i; k++) dp[i][j][k] = 0;
        }
    }

    dp[0][0][0] = 1;

    for (int i=1; i<=n; i++) {
        for (int j=0; j<i; j++) {
            for (int k=0; k<=i*i; k++) {
                ll tmp = dp[i-1][j][k];
                dp[i][j+1][k+j+1] = (dp[i][j+1][k+j+1]+tmp) % p;
                dp[i][j][k+j] = (dp[i][j][k+j]+(2*j+1)*tmp) % p;
                if (j>=1) dp[i][j-1][k+j-1] = (dp[i][j-1][k+j-1]+j*j*tmp) % p;
            }
        }
    }

    printf("%lld", dp[n][0][m/2]);

    return 0;
}

Measured memory_bytes: 50944
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;

fn main() {
    let r:u32 = read();

    println!("{}",
        if r < 1200 {"ABC"}
        else if r < 2800 {"ARC"}
        else {"AGC"}
    );

}


Measured memory_bytes: 4352
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use std::process::exit;
use std::cmp::*;
use itertools::Itertools;

fn main() {
    let a:usize=read!();
    let mut sum:usize=0;
    let mut max:usize=0;
    for _i in 0..a {
        let b:usize=read!();
        sum+=b;
        if max<b {max=b;}
    }
    println!("{}",sum-max/2)
}

Measured memory_bytes: 2136
#include <stdio.h>

int main (void)
{
	int a[10000];
	int i;

	for(i=0;i<10000;i++){
		scanf("%d", &a[i]);
		if (a[i]==0) break;
	}
	
	i=0;
	while(a[i]!=0){
		printf("Case %d: %d\n",i+1,a[i]);
		i++;
	}

	return 0;
}

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

typedef int Capacity;
struct Edge {
    int src, dst;
    Capacity cap;
    Edge(int src_, int dst_, Capacity cap_) :
        src(src_), dst(dst_), cap(cap_) { }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

struct Dinic {
    int n, s, t;
    vector<int> level, vis, iter;
    vector<vector<Capacity>> cap, flow;
    vector<vector<int>> g;
    Capacity inf;
    Dinic(int n)
        : n(n), cap(n, vector<Capacity>(n)), flow(n, vector<Capacity>(n)),
          g(n, vector<int>()), inf(numeric_limits<Capacity>::max()/8){}
    Dinic(const Graph &graph){
        *this = Dinic(graph.size());
        rep(i,n) for(auto &e : graph[i]) addEdge(e.src, e.dst, e.cap);
    }
    void addEdge(int u, int v, Capacity c){
        cap[u][v] += c; cap[v][u] += c; flow[v][u] += c;
        g[u].push_back(v); g[v].push_back(u);
    }
    Capacity solve(int s, int t){
        this->t = t, this->s = s;
        Capacity res = 0, aug = 1;
        while(aug > 0){
            levelize();
            vis.assign(n, false); iter.assign(n, 0); aug = 0;
            Capacity tmp = 1;
            while(tmp > 0) aug += (tmp = augment(s, inf));
            res += aug;
        }
        return res;
    }
    void levelize(){
        level.assign(n, inf); level[s] = 0;
        queue<int> q; q.emplace(s);
        while(q.size()){
            int v = q.front(); q.pop();
            for(const int &d : g[v]){
                if(level[d] <= level[v] + 1 || cap[v][d] - flow[v][d] == 0) continue;
                level[d] = level[v] + 1; q.emplace(d);
            }
        }
    }
    Capacity augment(int v, const Capacity &lim){
        vis[v] = true;
        if(v == t) return lim;
        for(int &i = iter[v]; i < (int)g[v].size(); i++){
            const int &d = g[v][i];
            if(vis[d] || flow[v][d] == cap[v][d] || level[v] >= level[d]) continue;
            Capacity aug = augment(d, min(lim, cap[v][d] - flow[v][d]));
            flow[v][d] += aug; flow[d][v] -= aug;
            if(aug > 0) return aug;
        }
        return 0;
    }
};

int main(){
    int N,M;
    cin >> N >> M;
    Graph g(N);
    rep(i,M){
        int a,b,c;
        cin >> a >> b >> c;
        g[a].emplace_back(a,b,c);
    }
    Dinic dinic(g);
    cout << dinic.solve(0,N-1) << endl;
}

Measured memory_bytes: 1356
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
#define inf 1e9
typedef pair<int,string > mmp;

int main(){
	while(1){
		string nn;
		getline(cin,nn);
	//	cout<<nn<<endl;
		if(nn[0]=='0')break;
		int n=0;
		for(int i=0;i<nn.size();i++){
			n*=10;
			n+=nn[i]-'0';
		}
		if(n==0)break;
		vector<mp> user(n);
		for(int j=0;j<n;j++){
			string line ;
			getline(cin,line);
	//		cout<<j<<' '<<line<<endl;
			int name=0;
	
			vector<int> s;
			int i;
			int st= 0;
			for( i=0;i<line.size();i++){
				if(line[i]==' ')break;
				name *=10;
				name += line[i]-'0';
				st = i;
			}
			int sum = 0;
		//	cout<<name<<endl;
			i++;
			//cout<<"next"<<line[st+2]<<endl;
			for(i = st+2 ;i<line.size();i++){
			//	cout<<i<<' '<<line[i]<<endl;
				if(line[i]==' '){
					s.push_back(sum);
					//cout<<sum<<endl;
			//		cout<<i<<line[i]<<sum<<endl;
					sum = 0;
					continue;
				}
				sum*=10;
				sum+= line[i]-'0';
			}
			
			//for(int i=0;i<s.size();i++)cout<<s[i]<<endl;
			s.push_back(sum);
			int res = 0;
			int cnt = 0;
			for(int i=0;i<s.size()&&cnt<10;i++){
				if(s[i]==10){
					res+=s[i]+s[i+1]+s[i+2];
					cnt++;
				}else{
					int tmp = s[i]+s[i+1];
					if(tmp==10)tmp+=s[i+2];
					res+=tmp;
					i++;
					cnt++;
				}
			}
			user[j] = mp(-res,name);
			
		}

	//	cout<<"ok "<<n<<endl;
		sort(user.begin(),user.end());
		for(int i=0;i<n;i++)cout<<user[i].second<<' '<<-user[i].first<<endl;
		//break;


	}


	return 0;
}



Measured memory_bytes: 3012
while gets do
  x1, y1, x2, y2, x3, y3, xp, yp = $_.split(/\s/).map(&:to_f)
  gx, gy = (x1 + x2 + x3)/3, (y1 + y2 + y3)/3

  def c(x1, y1, x2, y2, x, y)
    (x1 - x2) * (y - y1) - (y1- y2) * (x - x1)
  end

  r1 = c(x1, y1, x2, y2, gx, gy) * c(x1, y1, x2, y2, xp, yp) > 0
  r2 = c(x2, y2, x3, y3, gx, gy) * c(x2, y2, x3, y3, xp, yp) > 0
  r3 = c(x3, y3, x1, y1, gx, gy) * c(x3, y3, x1, y1, xp, yp) > 0
  puts (r1 && r2 && r3) ? 'YES' : 'NO'
end

Measured memory_bytes: 6144
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<ll, ll>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

class UnionFind {
public:
    vector<int> par;
    int N;
    UnionFind(int n) {
        par.resize(n, -1);
        N = n;
    }
    int Find(int n) {
        return par[n] < 0 ? n : par[n] = Find(par[n]);
    }
    bool Union(int x, int y) {
        x = Find(x);
        y = Find(y);
        if (x == y) return false;
        if (-par[x] > -par[y]) swap(x, y);
        par[y] += par[x];
        par[x] = y;
        N--;
        return true;
    }
    bool Same(int x, int y) {
        return Find(x) == Find(y);
    }
    int size(int x) {
        return -par[Find(x)];
    }
    int size() {
        return N;
    }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m;
    cin, n, m;
    UnionFind uf(n);
    REP(i, 0, m) {
        int a, b;
        cin, a, b;
        a--;
        b--;
        uf.Union(a, b);
    }
    int ans = 0;
    REP(i, 0, n) {
        int s = uf.size(i);
        chmax(ans, s);
    }
    print(ans);
    return 0;
}


Measured memory_bytes: 3960
#include<stdio.h>
int main()
{
  int N;
  int H;
  int i;
  int counter=0;
  int hight=0;
  scanf("%d",&N);
  for(i=0;i<N;i++)
  {
    scanf("%d",&H);
    if(H>=hight)
    {
      counter++;
      hight=H;
    }
  }
  printf("%d",counter);
  return 0;
}

Measured memory_bytes: 128
def merge(a, left, mid, right):
    global count
    n1 = mid - left
    n2 = right - mid
    L = a[left:left + n1] + [SENTINEL]
    R = a[mid:mid + n2] + [SENTINEL]
    i = j = 0
    for k in range(left, right):
        if L[i] <= R[j]:
            a[k] = L[i]
            i += 1
        else:
            a[k] = R[j]
            j += 1
    count += right - left
 
def merge_sort(a, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(a, left, mid)
        merge_sort(a, mid, right)
        merge(a, left, mid, right)
 
SENTINEL = 1000000001
n = int(input())
a = list(map(int, input().strip().split()))
count = 0
merge_sort(a, 0, len(a))
print(' '.join(map(str, a)))
print(count)

Measured memory_bytes: 68692
#include <iostream>
int main(){
    int S,h,m,s;
    std::cin >> S;
    h=S/3600;
    m=(S-3600*h)/60;
    s=(S-3600*h)%60;
    std::cout << h << ':' << m << ':' << s << std::endl;
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N ,count = 0;
    cin >> N;
    vector<int> data(N + 1, 0);
     for (int i = 0; i < N ; i++) {
         cin >> data.at(i + 1);
     }
     for (int i = 0; i< N; i++) {
         if (data.at(i) < data.at(i + 1)) count += (data.at(i + 1) - data.at(i));
    }
     cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#define D(c,n) (*std::max_element(c,c+n)-*std::min_element(c,c+n)+1)
int main()
{
	int N,n,x[201],y[201],i,d,z[]={-1,0,1,0,-1};
	x[0]=y[0]=0;
	while(scanf("%d",&N),N)
	{
		for(i=1;i<N;++i)scanf("%d%d",&n,&d),x[i]=x[n]+z[d],y[i]=y[n]+z[d+1];
		printf("%d %d\n",D(x,N),D(y,N));
	}
	return 0;
}

Measured memory_bytes: 0
#acb77_a
a,b=input().split()

if a=="A":
    a=1
if a=="B":
    a=2
if a=="C":
    a=3
if a=="D":
    a=4
if a=="E":
    a=5
if a=="F":
    a=6
    
if b=="A":
    b=1
if b=="B":
    b=2
if b=="C":
    b=3
if b=="D":
    b=4
if b=="E":
    b=5
if b=="F":
    b=6

if a>b: print(">")
if a<b: print("<")
if a==b: print("=")

Measured memory_bytes: 3064
class dice:
    def __init__(self,label):
        self.label = {i+1: l for i,l in enumerate(label)}
    def roll(self,op):
        l = self.label
        if   op=='N': self.label = {1:l[2], 2:l[6], 3:l[3], 4:l[4], 5:l[1], 6:l[5]}
        elif op=='E': self.label = {1:l[4], 2:l[2], 3:l[1], 4:l[6], 5:l[5], 6:l[3]}
        elif op=='W': self.label = {1:l[3], 2:l[2], 3:l[6], 4:l[1], 5:l[5], 6:l[4]}
        elif op=='S': self.label = {1:l[5], 2:l[1], 3:l[3], 4:l[4], 5:l[6], 6:l[2]}
    def yaw(self,op):
        l = self.label
        if   op=='CW' : self.label = {1:l[1], 2:l[3], 3:l[5], 4:l[2], 5:l[4], 6:l[6]}
        elif op=='CCW': self.label = {1:l[1], 2:l[4], 3:l[2], 4:l[5], 5:l[3], 6:l[6]}
    def get_label(self,i):
        return self.label[i]

if __name__ == '__main__':
    d0 = dice(list(map(int,input().split())))
    q = int(input())
    for _ in range(q):
        t,f = list(map(int,input().split()))
        for _ in range(3):
            if d0.get_label(1) == t: break
            d0.roll('E')
        if d0.get_label(1) != t:
            d0.roll('N')
            if d0.get_label(1) != t:
                for _ in range(2): d0.roll('N')
        if d0.get_label(2) != f:
            for _ in range(3):
                d0.yaw('CW')
                if d0.get_label(2) == f: break
        print(d0.get_label(3))

Measured memory_bytes: 7820
#include <bits/stdc++.h>
#include <string.h>
#include <vector>
//s#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 10000

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a; i<n; i++)
#define r0 return 0
#define INF (int)1e15
#define MOD 1000000007

#define access(i) a[i/3][i%3]
int gcd(int x, int y)
{
    if(y==0)
        return x;
    return gcd(y, x%y);
}

 long long numbers[500005];


 int main(){

 long long n;
 cin>>n;

 long long sum = 0;

 for(int i=1;i<=n;i++)
  {
    for(int j=1;j<=n;j++)
    {
        for(int k=1;k<=n;k++)
      {
      sum += gcd(gcd(i,j),k);
      }
   }
  }

  cout<<sum<<endl;

 return 0;
 }



Measured memory_bytes: 3600
#include <bits/stdc++.h>
 
#define loop(n, i) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;

using namespace std;
typedef long long ll;

set<int> ans;
string line; 
int len;

int apply(char opr, int a, int b) {
    if (opr == '+') return a + b;
    if (opr == '-') return a - b;
    if (opr == '*') return a * b;
    if (opr == '/') return a / b;
}

int reduce(stack<int>& N, stack<char>& O) {
    char opr = O.top(); O.pop();
    int v = N.top(); N.pop();
    int w = N.top(); N.pop();
    if (opr == '/' && !v) return 0;
    N.push(apply(opr, w, v));
    return 1;
}

void read(int i, stack<int> N, stack<char> O) {
    if (i == len) {
        while (O.size()) if (!reduce(N, O)) return;
        ans.insert(N.top());
        return;
    }
    if (line[i] >= '0') {
        int v = 0;
        while (i < len && line[i] >= '0') v *= 10, v += line[i++] - '0';

        N.push(v);
        read(i, N, O);
        while (!O.empty() && O.top() != '(' && reduce(N, O)) read(i, N, O);
        return;
    }
    if (line[i] == ')') {
        while (O.top() != '(') if (!reduce(N, O)) return;
        O.pop();
        read(i+1, N, O);
        while (!O.empty() && O.top() != '(' && reduce(N, O)) read(i+1, N, O);
        return;
    }
    O.push(line[i]);
    read(i+1, N, O);
    return;
}

int main()
{
    while (1) {
        ans.clear();
        cin >> line;
        len = line.length();
        if (line == "#") break;
        read(0, stack<int>(), stack<char>());
        cout << ans.size() << endl;
    }
    return 0;
}

Measured memory_bytes: 3084
import java.util.*;
public class Main {
	public static void main(String[] args){
      	
		Scanner sc = new Scanner(System.in);
		//String word_before = sc.next();
		
		int N = sc.nextInt();
		int K = sc.nextInt();
		int cnt = 0;
		while (N/K!=0) {
			N=	N/K;
			cnt++;
		}
		
		System.out.println(cnt+1);
      	sc.close();
    }
		
		
}

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

void Main() {
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    long long A, B, a, b;
    cin >> A >> B;
    a = min(A, B);
    b = max(A, B);
    if (a == b) cout << 2 * a - 2 << endl;
    else if (a + 1 == b) cout << 2 * a - 2 << endl;
    else {
      long long c = sqrt(a * b);
      if (c * c == a * b) c--;
      if (c * (c + 1) >= a * b) cout << 2 * c - 2 << endl;
      else cout << 2 * c - 1 << endl;
    }
  }
}

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



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

using namespace std;

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

int main()
{
	int K;
	string S;

	cin >> K;
	cin >> S;

	for (int i = 0; i < min(K,S.length()); i++)
	{
		cout << S[i];
	}
	if(K<S.length())
		cout << "...";

    return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int main()
{
  int N;
  cin >> N;
  vint A(N);
  vint B(N);
  cin >> A;
  REP(i,N)B[i] = A[i];
  sort(B.begin(),B.end(),greater<int>());
  int tier1 = B[0];
  int tier2 = B[1];
  
  for(auto a : A){
    if(a == tier1){
      cout << tier2 << endl;
    }else{
      cout << tier1 << endl;
    }
  }
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N,K;
    cin >> N >> K;
    cout << N - K + 1 << endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
table = [[int(i) for i in input().split()] for m in range(M)]
L=[]
R=[]
c=0
d=0
x=0
for i in range(M):
  L.append(table[i][0])
  
for i in range(M):
  R.append(table[i][1])
  
c=max(L)
d=min(R)
    


if c>d:
    print("0")
else:
    x=d-c+1
    print("%d"%x)

Measured memory_bytes: 22800
#include<iostream>
#include<vector>
#include<map>
using namespace std;

int main() {
    int N;
    cin>>N;
    int A[N];
    map<long, long> map;
    vector<int> arr;
    long ans = 0;
    for(int i=0;i<N;++i){
        cin>>A[i];
        if(map[A[i]]==0)arr.push_back(A[i]);
        map[A[i]]++;
    }
    for(int i=0;i<arr.size();++i){
        ans += map[arr[i]]*(map[arr[i]]-1)/2;
    }
    for(int i=0;i<N;++i){
        cout<<ans - map[A[i]]*(map[A[i]]-1)/2 + (map[A[i]]-1)*(map[A[i]]-2)/2<<endl;
    }
}


Measured memory_bytes: 10744
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <array>
#include <tuple>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
using namespace std;
typedef long long ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define all(v) (v).begin(),(v).end()
#define clr(a,b) memset((a),(b),sizeof(a))
#define sz size()
#define pb push_back
#define print(x) cout << x << endl
int n,m;
int x[100];

int main(){
  string s;
  cin >> s;
  rep(i,0,6){
    if(s[i] == '1')n++;
  }
  print(n);
  return 0;
}


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

using Weight = long long;
using Vertex = int;
struct Edge {Vertex from, to; Weight weight;};
using Graph = std::vector<std::vector<Edge>>;

std::vector<std::vector<Vertex>> connected_component(const Graph& G) {
  std::vector<std::vector<Vertex>> cc;
  std::vector<bool> used(G.size());
  std::function<void(int)> dfs = [&](int v) {
    cc.back().push_back(v);
    used[v] = true;
    for(const auto& e: G[v]) if(!used[e.to]) dfs(e.to);
  };
  for(Vertex v = 0; v < G.size(); ++v) if(!used[v]) {
    cc.push_back(std::vector<Vertex>());
    dfs(v);
  }
  return cc;
}

int main() {
  int N, K, L;
  cin >> N >> K >> L;

  Graph G(N);
  for(auto i=0; i<K; ++i) {
    int p, q;
    cin >> p >> q;
    --p; --q;
    G[p].push_back({p, q});
    G[q].push_back({q, p});
  }

  Graph H(N);
  for(auto i=0; i<L; ++i) {
    int r, s;
    cin >> r >> s;
    --r; --s;
    H[r].push_back({r, s});
    H[s].push_back({s, r});
  }

  auto ccg = connected_component(G);
  auto cch = connected_component(H);
  vector<int> g(N), h(N);
  for(auto i=0; i<ccg.size(); ++i) for(auto v: ccg[i]) g[v] = i;
  for(auto i=0; i<cch.size(); ++i) for(auto v: cch[i]) h[v] = i;

  vector<map<int,int>> cc(ccg.size());
  for(auto i=0; i<ccg.size(); ++i) for(auto v: ccg[i]) ++cc[i][h[v]];

  for(auto i=0; i<N; ++i) cout << (i ? " " : "") << cc[g[i]][h[i]];
  cout << endl;
}


Measured memory_bytes: 59052
using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Threading;

namespace Sweet
{
    class Program
    {
        static void Main(string[] args)
        {
            Int32 a,b;
            string str = Console.ReadLine();

            b = str.IndexOf(" ");
            a = int.Parse(str.Substring(0, b));
            b = Int32.Parse(str.Substring(b));
            //Console.WriteLine("you entered {0} 0x{0:x4}.", num);
            //string ans = string.Format("{0}", num * num * num);
            Console.WriteLine("{0} {1}", a*b, (a+b)*2);
            /*Console.WriteLine("Hello World");*/
            //Console.ReadLine();
            //Console.ReadLine();
        }
    }
}

Measured memory_bytes: 9568
#include <iostream>
using namespace std;
#define max(a, b) (((a)>(b))?(a):(b))

int main() {
    long long ai, ao, att, aj, al, as, az;
    cin >> ai >> ao >> att >> aj >> al >> as >> az;
    long long ans = ao;
    if (ai%2 == aj%2 && aj%2 == al%2) {
        ans += ai+aj+al;
    } else {
        if (ai == 0 || aj == 0 || al == 0) {
            ans += ai+aj+al-(ai%2)-(aj%2)-(al%2);
        } else {
            ans += max(
                ai+aj+al-((ai-1)%2)-((aj-1)%2)-((al-1)%2),
                ai+aj+al-(ai%2)-(aj%2)-(al%2)
            );
        }
    }
    cout << ans << '\n';
}


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

int n, m;
char ar[25][25];
int dist[25][25];

void dfs(int r, int c, int cnt) {
    if (r < 1 || c < 1 || r > n || c > m) return;
    if (ar[r][c] == '#') return;
    if (dist[r][c] <= cnt) return;
    dist[r][c] = cnt;
    for (int i = -1; i <= 1; i++) {
        for (int j = -1; j <= 1; j++) {
            if (i != 0 && j != 0) continue;
            if (i == 0 && j == 0) continue;
            dfs(r + i, c + j, cnt + 1);
        }
    }
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cin >> ar[i][j];
        }
    }    

    int ans = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (ar[i][j] == '#') continue;
            for (int r = 1; r <= n; r++) {
                for (int c = 1; c <= m; c++) {
                    dist[r][c] = 42069;
                }
            }
            dfs(i, j, 0);
            for (int ti = 1; ti <= n; ti++) {
                for (int tj = 1; tj <= m; tj++) {
                    if (dist[ti][tj] == 42069) continue;
                    ans = max(ans, dist[ti][tj]);
                }
            }
        }
    }
    cout << ans << '\n';
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 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 chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using ll = long long;
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;

long int M = 1e+9+7;
int main(void){
    int n,m;
    cin >> n >> m;
    vi h(n);//,a(m),b(m);
    vector<bool> good(n,true);
    rep(i,n){
        cin >> h[i];
    }
    int a,b;
    rep(i,m){
        cin >> a >> b;
        if(h[a-1] > h[b-1]) good[b-1]=false;
        else if(h[a-1] < h[b-1]) good[a-1]=false;
        else if(h[a-1] == h[b-1]){
             good[a-1]=false;
             good[b-1]=false;
        }
    }

    int ans=0;
    rep(i,n){
        if(good[i]) ans++;
        //cout << good[i] << " ";
    }
    //cout << endl;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3756
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int (i)=(a);(i)<(b);++(i))
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cout<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
typedef vector<int> vi;
typedef vector<lint> vl;
typedef vector<char> vc;
typedef vector<vector<int>> vii;
typedef vector<vector<lint>> vll;
typedef vector<vector<char>> vcc;

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

class CHSI {
public:
    int N, M;

    void input(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in>>N>>M;
    }

    void solve(std::istream& in, std::ostream& out){
        input(in, out);
        out<<(1<<M)*(100*N+1800*M)<<'\n';
    }
};


int main() {
	CHSI solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
x = int(input())

for i in range(1000):
    #for j in range(10)
    #print(i ** 5)
    for j in range(1000):
        #print(i ** 5 - j ** 5)
        if i ** 5 - j ** 5 == x:
            print(i, j)
            quit()
        elif i ** 5 - (-j) ** 5 == x:
            print(i, -j)
            quit()
        elif (-i) ** 5 - j ** 5 == x:
            print(-i, j)
            quit()
        elif (-i) ** 5 - (-j) ** 5 == x:
            print(-i, -j)
            quit()


Measured memory_bytes: 9128
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    string x;
    cin >> x;
    ll n = x.size();

    ll cntS = 0;
    ll ans = 0;
    rep(i, n) {
        if(x[i] == 'S') {
            cntS++;
        }
        else if(x[i] == 'T') {
            if(cntS == 0) {
                ans += 2;
            }
            else {
                cntS--;
            }
        }
    }
    
    out(ans);
    re0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i< (n); i++)
using ll = long long;
using P = pair<int, int>;
int main()
{
    while(true){
        int h,w;
        cin >> h >> w;
        if( h == 0 && w == 0) break;
        rep(i,h){
            rep(j,w){
                if(i == 0 || i == h-1 || j == 0 || j == w-1)cout<< '#';
                else cout << '.';
            }
            cout << endl;
        }
        cout << endl;
    }
return 0;
}


Measured memory_bytes: 3084
# 家に帰ったら整理して
MOD = (10**9) + 7
=begin

# X Y Z K
# A1...AX
# B1...
# C1...

X, Y, Z, K = gets.split.map(&:to_i)
A = gets.split.map(&:to_i).sort.reverse
B = gets.split.map(&:to_i).sort.reverse
C = gets.split.map(&:to_i).sort.reverse
V = Array.new

A.each_with_index do |a, i|
  B.each_with_index do |b, j|
    break if (i + 1) * (j + 1) > K

    C.each_with_index do |c, k|
      break if (i + 1) * (j + 1) * (k + 1) > K

      V << (a + b + c)
    end
  end
end

puts V.sort.reverse[0...K]
=end

# X, Y = gets.split.map(&:to_i)
# ans = 0
# num = X
# while num <= Y
#   ans += 1
#   num *= 2
# end

# p ans

=begin

N = gets.to_i

# u -> v , weight = w
# u v w
temp = []
glaph = Array.new(N) { Hash.new }
(N - 1).times do
  u, v, w = gets.split.map(&:to_i)
  glaph[u - 1][v - 1] = w
  glaph[v - 1][u - 1] = w
end

gone = Array.new(N) { true }
ans = Array.new(N)
queue = [0]

ans[0] = true
gone[0] = true

while curr = queue.shift
  glaph[curr].each do |k, v|
    if gone[k]
      gone[k] = false
      ans[k] = (v%2 == 0) ? ans[curr] : !ans[curr]
      queue << k
    end
  end
end

ans.each { |a| puts a ? '1' : '0' }

=end

# abc121D
# input
# A B
# 123 456
# output
# 435
# A..BのXOR

# a, b = gets.split.map(&:to_i)
# ans = 0
# if a%2 == 1
#   ans = ans ^ a
#   a += 1
# end
# if b%2 == 0
#   ans = ans ^ b
#   b -= 1
# end
# ans = ans ^ (((b - a + 1)/2)%2)
# p ans

# abc120D
# input
# N M
# A1 B1
# ...
# AM BM
# 6 5
# 2 3
# 1 2
# 5 6
# 3 4
# 4 5
# output
# 8
# 9
# 12
# 14
# 15

class UnionFindWithSize
  def initialize(size)
    @rank = Array.new(size) { 0 }
    @parent = Array.new(size) { |id| id }
    @union_size = Array.new(size) { 1 }
  end

  def unite(id_x, id_y)
    x_parent = get_parent(id_x)
    y_parent = get_parent(id_y)
    return if x_parent == y_parent

    ary = [@union_size[x_parent], @union_size[y_parent]]
    if @rank[x_parent] > @rank[y_parent]
      @parent[y_parent] = x_parent
      @union_size[x_parent] += ary[1]
    else
      @parent[x_parent] = y_parent
      @union_size[y_parent] += ary[0]
      @rank[y_parent] += 1 if @rank[x_parent] == @rank[y_parent]
    end
    ary
  end

  def get_parent(id_x)
    @parent[id_x] == id_x ? id_x : (@parent[id_x] = get_parent(@parent[id_x]))
  end
end

n, m = gets.split.map(&:to_i)
bridges = Array.new(m) { Array.new(2) }
uf = UnionFindWithSize.new(n)
m.times do |i|
  bridges[i] = gets.split.map {|j| j.to_i - 1 }
end
ans = []
curr_value = n * (n-1) / 2
ans << curr_value
bridges.reverse_each do |u, v|
  if diff = uf.unite(u, v)
    curr_value -= diff[0] * diff[1]
  end
  ans << curr_value
end

puts ans.reverse[1..-1]

Measured memory_bytes: 20216
n,m=map(int,input().split())
a=[]
b=[]
ans='No'
for i in range(n):
    t=list(input())
    a.append(t)
for i in range(m):
    t=list(input())
    b.append(t)
for i in range(n-m+1):
    for j in range(n-m+1):
        for k in range(m):
            if b[k]!=a[j+k][i:i+m]:
                break
        else:
            ans='Yes'
print(ans)

Measured memory_bytes: 3064
K,N=map(int,input().split())
A=list(map(int,input().split()))
A.append(K+A[0])
#print(A)
MAX=0
for i in range(len(A)):
    if MAX<A[i]-A[i-1]:
        MAX=A[i]-A[i-1]
print(K-MAX)

Measured memory_bytes: 78412
n = int(input())
s = list(input())
m = len(s)
for i in range(m):
    if ord(s[i])+n > 90:
        s[i] = chr(ord(s[i])+n-26)
    else:
        s[i] = chr(ord(s[i])+n)
for i in s:
    print(i,end="")

Measured memory_bytes: 4596
#include<bits/stdc++.h>
using namespace std;
int ara_D[100][200];
int ara[100000];
int ara1[100000];
int main()
{
    int i,j,k,l,cnt=0,a,b,c;
    scanf("%d %d %d",&ara[0],&ara[1],&ara[2]);
    for(i=0;i<3;i++)
    {
        for(j=1;j<=100;j++)
        {
            if(ara[i]==j)
            {
                ara1[j]++;
                if(ara1[j]==1)
                {
                    cnt++;
                }
                break;
            }
        }
    }
    printf("%d\n",cnt);
    return 0;
}




Measured memory_bytes: 256