akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <assert.h>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

int main(){
  ll n;
  cin>>n;
  ll a = n/500;
  ll b = n%500;
  ll c = b/5;
  cout << a*1000+c*5 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <iomanip> 
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<bool> vb;
typedef vector<ull> vul;
typedef vector<pair<ll, ll>> vpl;
typedef pair<ll, ll> pl;
#define For(i, n) for(ll i = 0; i < n; i++)
#define len(n) (ll)(n).size()
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
ll dp[410][410];
ll sm[410][410];
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n;
	cin >> n;
	vl a(n);
	For(i, n) For(j, n) dp[i][j] = 1e15;
	For(i, n) {
		cin >> a[i];
		dp[i][i] = 0;
	}
	For(i, n) {
		For(j, i + 1) {
			sm[j][i] = sm[j][i - 1] + a[i];
			//cout << sm[j][i] << ' ' << j << ' ' << i << endl;
		}
	}
	For(i, n) {
		for (ll j = i; j >= 0; j--) {
			for (ll k = j; k < i; k++) {
				dp[j][i] = min(dp[j][i], dp[j][k] + dp[k + 1][i] + sm[j][i]);
			}
			//cout << dp[j][i] << ' ' << j << ' ' << i << endl;
		}
	}
	cout << dp[0][n - 1];
	return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    vi t(n);
    rep(i,n) cin>>t[i];
    int sum=0;
    rep(i,n) sum+=t[i];
    int m; cin>>m;
    rep(i,m){
        int p,x; cin>>p>>x;
        cout<<sum+(x-t[p-1])<<"\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cstdlib>
#include<iomanip>
#define rep(i,x) for(int i=0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
using ld = long double;
using ll = long long;
const ll INF = 1001001001;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
ll gcd(ll a, ll b) {//a>b
    if (a < b)swap(a, b);
    if (a % b == 0) return b;
    else return gcd(b, a % b);
}


int main() {
    ll a, b;
    cin >> a >> b;
    ll N = b - a;
    ll n = (N * N + N)/2;
    cout << n - b << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod=998244353;
int n,m;
ll jc[101010],jc_ny[101010];
ll f[220][8080];
ll Power(ll x,ll k)
{
	ll sss=1;
	while (k)
	{
		if (k%2) sss=sss*x%mod;
		x=x*x%mod;
		k/=2;
	}
	return sss;
}
ll ny(ll x){return Power(x,mod-2);}
 
struct Poly
{
	ll A[202020],B[202020],C[202020];
	ll g[202020];
	int rev[202020];
	int len,kkk;
	void NTT(ll P[],ll type)
	{
		for (int i=0;i<len;++i) if (i<rev[i]) swap(P[i],P[rev[i]]);
		for (int i=2;i<=len;i<<=1)
		{
			int num=i/2;
			g[0]=1; g[1]=Power(3,(mod-1)/i); 
			if (type==-1) g[1]=ny(g[1]);
			for (int j=2;j<num;++j) g[j]=g[j-1]*g[1]%mod;
			
			for (int j=0;j<len;j+=i)
				for (int k=0;k<num;++k)
				{
					ll x=P[j+k],y=P[j+k+num]*g[k]%mod;
					P[j+k]=(x+y)%mod;
					P[j+k+num]=(x-y+mod)%mod;
				}
		}
		if (type==-1)
		{
			ll doe=ny(len);
			for (int i=0;i<len;++i) P[i]=P[i]*doe%mod;
		}
	}
	void mul(const vector<ll>a , const vector<ll>b , vector<ll> &c)
	{
		int lena=a.size(),lenb=b.size(),lenc=lena+lenb-1; 
		len=1,kkk=0;
		while (len<=lenc) len*=2,++kkk;
		for (int i=0;i<len;++i) rev[i]=(rev[i>>1]>>1) | ((i&1)<<(kkk-1));
 
		for (int i=0;i<len;++i) A[i]=B[i]=0;
		for (int i=0;i<lena;++i) A[i]=a[i];
		for (int i=0;i<lenb;++i) B[i]=b[i];
 
		NTT(A,0); NTT(B,0);
		for (int i=0;i<len;++i) C[i]=A[i]*B[i]%mod;
		NTT(C,-1);
		c.clear();
		for (int i=0;i<lenc;++i) c.push_back(C[i]);
	}
}S;
ll C(int x,int y)
{
	if (y>x || y<0) return 0;
	if (y==x || y==0) return 1;
	return jc[x] *jc_ny[x-y]%mod *jc_ny[y]%mod;
}
void init()
{
	jc[0]=jc_ny[0]=1;
	for (int i=1;i<=100010;++i) jc[i]=jc[i-1]*i%mod,jc_ny[i]=ny(jc[i]);
}
vector<ll> F1,F2,G;
int main()
{
	init();
 
	scanf("%d%d",&n,&m);
	F1.resize(n+1); F2.resize(n+1);
	f[0][0]=1;
	for (int i=0;i<m;++i) 
	{	
		for (int j=0;j<=n;++j) F1[j]=f[i][j]*jc_ny[j]%mod;
		for (int j=0;j<=n;++j) F2[j]=jc_ny[j+2];
		F2[0]=0;
 
		S.mul(F1,F2,G);
		for (int j=0;j<=n;++j) f[i+1][j]=G[j]*jc[j+2]%mod;
 
		for (int j=0;j<=n;++j)
			(f[i+1][j]+=(C(j+1,2)+1) * f[i][j]%mod )%=mod;
	}
	ll ans=0;
	for (int i=0;i<=n;++i) ( ans+= f[m][i]*C(n,i)%mod )%=mod;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 21504
import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7
EPS = 10 ** -10

N = INT()
A = LIST()

up = False
sell = [0] * N
buy = [0] * N
for i in range(N-1):
    if not up and A[i] < A[i+1]:
        up = True
        buy[i] = 1
    if up and A[i] > A[i+1]:
        up = False
        sell[i] = 1
sell[N-1] = 1

money = 1000
stock = 0
for i in range(N):
    if buy[i]:
        d, m = divmod(money, A[i])
        stock += d
        money = m
    if sell[i]:
        money += stock * A[i]
        stock = 0
print(money)


Measured memory_bytes: 9576
import sys
# 再起回数上限変更
# sys.setrecursionlimit(1000000)

N, K = map(int, input().split())
H = list(map(int, input().split()))

H.sort()
H = H[::-1]


if len(H) <= K:
    print(0)
    sys.exit()

H = H[K:]
print(sum(H))



Measured memory_bytes: 90444
n, k = map(int, input().split())
m = n**2
mod = 10**9+7
dp = [[[0]*(m+1) for j in range(i+1)] for i in range(n+1)]
dp[0][0][0] = 1
for i in range(n):
  for j in range(i+1):
    for l in range(m+1):
      dp[i][j][l] %= mod
      if j and l+2*(j-1) <= m:
        dp[i+1][j-1][l+2*(j-1)] += dp[i][j][l]*j**2
      if l+2*j <= m:
        dp[i+1][j][l+2*j] += dp[i][j][l]*(2*j+1)
        if l+2*(j+1) <= m: 
          dp[i+1][j+1][l+2*(j+1)] += dp[i][j][l]
ans = dp[n][0][k]%mod
print(ans)

Measured memory_bytes: 100192
#include <iostream>
#include <unordered_map>

using namespace std;

typedef long long ll;

int main(int argc, char const* argv[])
{
	ll sum(0);
	unordered_map<int, int> mp;
	int N;
	cin >> N;
	int A[N];
	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
		sum += A[i];
		if (mp.find(A[i]) != mp.end())
			mp[A[i]] += 1;
		else
			mp[A[i]] = 1;
	}
	int Q;
	cin >> Q;
	int B, C;
	for (int i = 0; i < Q; i++)
	{
		cin >> B >> C;
		if (mp.find(B) != mp.end())
		{
			sum += (C - B) * mp[B];
			if (mp.find(C) != mp.end())
				mp[C] += mp[B];
			else
				mp[C] = mp[B];
			mp.erase(B);
		}
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 6988
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main() {
	unsigned long long n, a[100005] = {};
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		if (a[i]==0)
		{
			cout << 0 << endl;
			return 0;
		}
	}
	unsigned long long aMulti = 1;
	for (int i = 0; i < n; i++)
	{
		if (aMulti > 1000000000000000000/a[i])
		{
			cout << -1 << endl;
			return 0;
		}
		aMulti *= a[i];


		if (aMulti>1000000000000000000)
		{
			cout << -1 << endl;
			return 0;
		}
	}
	cout << aMulti << endl;
	return 0;
}


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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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 ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;

class UnionFind{
private:
  vector<ll> Parent; 
 public:
  UnionFind(ll N){
    Parent = vector<ll>(N, -1);
  }
  
  ll root(ll A){
    if(Parent[A] < 0) return A;
    return Parent[A] = root(Parent[A]);
  }
  
  ll size(ll A){
    return -Parent[root(A)]; 
  }
  
  bool connect(ll A, ll B){
    A = root(A);
    B = root(B);
    if(A == B){
      return false;
    }
    if(size(A) < size(B)) swap(A, B);
    Parent[A] += Parent[B];
    Parent[B] = A;
    return true;
  }
  
  bool isSame(ll A, ll B){
    return root(A) == root(B);
  }
};

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,m; cin>>n>>m;
  set<ll> s;
  UnionFind uf(m);
  rep(i,n){
    ll k; cin>>k;
    ll prev=-1;
    rep(j,k){
      ll l; cin>>l; l--;
      s.insert(l);
      if(prev==-1){
        prev=l;
        continue;
      }
      uf.connect(prev,l);
      prev=l;
    }
  }
  ll prev=-1;
  for(auto e: s){
    if(prev==-1){
      prev=e;
      continue;
    }
    if(!uf.isSame(prev,e)){
      cout<<"NO"<<endl;
      return 0;
    }
    prev=e;
  }
  cout<<"YES"<<endl;
}


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

bool isLeapYear(int year){
	if (year % 400 == 0)
		return true;
	if (year % 4 == 0){
		if (year % 100 == 0)
			return false;
		else
			return true;
	}
	return false;
}

int main(){
	int a, b, count;
	int n = 0;

	while (true){
		cin >> a >> b;
		if (a == 0 && b == 0)break;
		if (n != 0)cout << endl;

		count = 0;
		for (int i = a; i <= b; ++i){
			if (isLeapYear(i)){
				++count;
				cout << i << endl;
			}
		}
		if (count == 0)
			cout << "NA" << endl;
		++n;

	}



	return 0;
}

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

int digit(int n)
{
	int temp = 0;
	while (n > 0)
	{
		n /= 10;
		temp++;
	}
	return temp;
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n; cin >> n;
	int answer = 0;
	for (int i = 1; i < n + 1; ++i)
	{
		int z = digit(i);
		if (z % 2 != 0)
		{
			answer++;
		}
	}
	cout << answer << endl;
	return 0;
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


int main() {
    i64 N; cin >> N;
    vector<i64> A(N);
    REP(i, N) cin >> A[i];

    i64 s = A[0];
    REPS(i, N - 1) s = s ^ A[i];

    vector<i64> ans(N);
    REP(i, N) ans[i] = s ^ A[i];

    REP(i, N) cout << ans[i] << " ";
    cout << endl;

    return 0;
}

Measured memory_bytes: 6292
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define MAXN 50

int n,a,b;

int main(int argc,char const* argv[])
{
  cin >> n >> a >> b;
  if((b-a) % 2 ==0)
    {
      cout << "Alice" << endl;
    }
  else if((b-a) % 2 !=0)
    {
      cout << "Borys" << endl;
    }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>

using namespace std;


//余り
int mod=10000;
//入力
//dp[i日目の晩御飯か][この日にどのパスタを食べたか][同じパスタを何日連続で食べているか] ->その場合の食べ方の通り
//f[i日目の晩御飯か] ->食べるパスタを決めているかどうか、決めているならどのパスタか
int dp[102][5][5],f[102];
int n,k;

void solve(){
	//1日目の予定が決まっている場合
	if(f[1]!=0)dp[1][f[1]][1]=1;
	//決まっていない場合
	else dp[1][1][1]=dp[1][2][1]=dp[1][3][1]=1; 
	//2日目からn日目までのパスタの食べ方を計算する
	for(int i=2;i<=n;i++){
		//i日目の予定が決まっていない場合
		if(f[i]==0){
			//i-1日目にトマトソースを食べていないパターン
			dp[i][1][1]=(dp[i-1][2][1]+dp[i-1][2][2]+dp[i-1][3][1]+dp[i-1][3][2])%mod;
			//トマトソースを2日間連続で食べるパターン
			dp[i][1][2]=dp[i-1][1][1]%mod;
			//トマトソースのパスタ同様のことをクリームソースにも行う
			dp[i][2][1]=(dp[i-1][1][1]+dp[i-1][1][2]+dp[i-1][3][1]+dp[i-1][3][2])%mod;
			dp[i][2][2]=dp[i-1][2][1]%mod;
			//同様にバジルソースのパスタにも行う
			dp[i][3][1]=(dp[i-1][1][1]+dp[i-1][1][2]+dp[i-1][2][1]+dp[i-1][2][2])%mod;
			dp[i][3][2]=dp[i-1][3][1]%mod;
		//i日目の予定が決まっている場合	
		}else{
			//2日間連続で食べるパターン
			dp[i][f[i]][2]=dp[i-1][f[i]][1]%mod;
			//決めていたパスタをi-1日目に食べていないパターン
			for(int j=1;j<=3;j++){
				if(j!=f[i])dp[i][f[i]][1]+=(dp[i-1][j][1]+dp[i-1][j][2])%mod;

			}
		}
	}
	//答えを出力する
	printf("%d\n",(dp[n][1][1]+dp[n][1][2]+dp[n][2][1]+dp[n][2][2]+dp[n][3][1]+dp[n][3][2])%mod);
}

//入力データを受け取る
int main(void){
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		f[a]=b;
	}
	solve();
}

Measured memory_bytes: 1196
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <bitset>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using pll = pair<ll, ll>;
#define sz(x) (int)(x).size()
string s, t;

bool possible (int ix) {
	for (int i = 0; i < sz(t); i++)
		if (!(t[i] == s[ix + i] || s[ix + i] == '?')) return false;
	return true;
}

void fill() { for (char& c : s) if (c == '?') c = 'a'; }

string solve() {
	if (sz(t) > sz(s)) return "UNRESTORABLE";
	for (int i = sz(s) - sz(t); i >= 0; i--) if (possible(i)) {
		for (int j = 0; j < sz(t); j++) s[j + i] = t[j];
		return fill(), s;
	}
	return "UNRESTORABLE";
}

int main() {
	cin >> s >> t;
	cout << solve() << '\n';
}



Measured memory_bytes: 256
n,m=map(int,input().split())

par=[i for i in range(n)]
size=[1]*n

def find(x):
  if par[x]==x:
    return x
  else:
    par[x]=find(par[x])
    return par[x]
def union(a,b):
  x=find(a)
  y=find(b)
  if x!=y:
    if size[x]<size[y]:
      par[x]=par[y]
      size[y]+=size[x]
    else: 
      par[y]=par[x]
      size[x]+=size[y]
  else:
    return

for i in range(m):
  x,y,z=map(int,input().split())
  union(x-1,y-1)


ans={find(i) for i in range(n)}

print(len(ans))

Measured memory_bytes: 90584
n = int(input())
A = list(map(int,input().split()))

ass = set()
def div(x):
    for i in range(1,int(x**0.5)+1):
        if x%i == 0:
            ass.add(i)
            ass.add(x//i)
    return ass

a0 = A[0]
a1 = A[1]
div(a0)
div(a1)
ans = []
for i in ass:
    cnt = 0
    for a in A:
        if a%i == 0:
            cnt += 1
    if cnt >= n-1:
        ans.append(i)
print(max(ans))


Measured memory_bytes: 14060
#include<bits/stdc++.h>
using namespace std;
int mod = 1e9+7;
int modpow(int a, int p){
    if (p == 0) return 1;
    if (p%2 == 0) {
        int half = modpow(a, p/2);
        return (long long)half * half % mod;
    }
    else return (long long)a * modpow(a, p-1) % mod;
}
int cmb(int n, int r) {
    r = min(r, n-r);
    long long tmpM = 1, tmpD = 1;
    for (int i = 0; i<r; i++) {
        tmpM *= n-i;
        tmpD *= i+1;
        tmpM %= mod;
        tmpD %= mod;
    }
    return tmpM * modpow(tmpD, mod-2) % mod;
}
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N, M, K;
    cin >> N >> M >> K;
    long long ans = 0;
    for (int i = 1; i<N; i++) {
        ans += (long long)(N-i)*M*M*i;
        ans %= mod;
    }
    for (int i = 1; i<M; i++) {
        ans += (long long)(M-i)*N*N*i;
        ans %= mod;
    }
    ans *= cmb(N*M-2, K-2);
    ans %= mod;
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};

lint segdata[(1<<20)-1];

lint neutral(){
    return 0; //単位元
}
lint calc(lint a,lint b){
    return a|b; //演算
}
void seginit(){
    rep(i,(1<<20)-1) segdata[i]=neutral();
}
void update(lint i,lint x){ // i番目の値をxに更新
    i+=(1<<19)-1;
    segdata[i]=x;
    while(i>0){
        i=(i-1)/2;
        segdata[i]=calc(segdata[i*2+1],segdata[i*2+2]);
    }
}
lint seg(lint a,lint b,lint k,lint l,lint r){
    if(r<=a || b<=l) return neutral();
    if(a<=l && r<=b) return segdata[k];
    else{
        lint left=seg(a,b,k*2+1,l,(l+r)/2);
        lint right=seg(a,b,k*2+2,(l+r)/2,r);
        return calc(left,right);
    }
}
lint query(lint a,lint b){
    return seg(a,b+1,0,0,1<<19); //a~b(閉区間）の範囲での演算
}

int main(void){
    int N;
    cin >> N;
    lint alf[26];
    alf[0]=1;
    for(int i=1;i<26;i++) alf[i]=alf[i-1]*2;
    string S;
    cin >> S;
    rep(i,N){
        update(i,alf[S[i]-'a']);
    }
    int Q;
    cin >> Q;
    rep(i,Q){
        int q;
        cin >> q;
        if(q==2){
            lint l,r;
            cin >> l >> r;
            l--,r--;
            lint sum=query(l,r);
            lint ans=0;
            rep(j,26) if(sum&(1<<j)) ans++;
            cout << ans << endl;
        }
        else{
            lint p;
            char c;
            cin >> p >> c;
            p--;
            update(p,alf[c-'a']);
        }
    }
}

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

using namespace std;

#define llong long long int
#define ternary(condition, x, y) ((condition) ? x : y) 
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) x.begin(), x.end()
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)

const static long long int MOD = 1000000000 + 7;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};

int main (int argc, char *argv[]) {
    cin.tie(0); 
    ios::sync_with_stdio(false);

    int n, c;
    cin >> n >> c;
    int imos[31][101010] = {};
    rep(i, n) {
        int a, b, c;
        cin >> a >> b >> c;
        --a, --c;
        ++imos[c][a];
        --imos[c][b];
    }

    rep(i, c) {
        for (int j = 1; j < 101010; ++j) {
            imos[i][j] += imos[i][j - 1];
        }
    }
    rep(i, c) {
        for (int j = 0; j < 101010; ++j) {
            if(imos[i][j]) imos[i][j] = 1;;
        }
    }

    int ans = 0;
    rep(i, 101010) {
        int cnt = 0;
        rep(j, c) {
            cnt += imos[j][i];
            ans = max(ans, cnt);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 12544
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second
#define mp make_pair
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1ll << 60;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int H, W, K, now[30][30];
char C[35][35];
int ans = 0;

int Solve(int I, int J){
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      now[i][j] = C[i][j] - '0';
    }
  }

  now[I][J] = 0;
  for (int i = I; i >= 1; i--){
    now[i][J] = now[i - 1][J];
  }
  now[0][J] = 0;

  int turn = 0, score = 0;

  while(true){
    int sum = 0;
    for (int i = H - 1; i >= 0; i--){
      int cnt = 1;
      for (int j = 1; j < W; j++){
        if (now[i][j] == now[i][j - 1]){
          cnt++;
        }else{
          if (cnt >= K){
            sum += now[i][j - 1] * cnt;
            for (int k = 0; k < cnt; k++){
              now[i][j - 1 - k] = 0; 
            }
          }
          cnt = 1;
        }
      }
      if (cnt >= K){
        sum += now[i][W - 1] * cnt; 
        for (int k = 0; k < cnt; k++){
          now[i][W - 1 - k] = 0;
        }
      }
    }

    if (sum == 0) break;
    score += sum * pow(2, turn);
    turn++;

    for (int i = H - 1; i >= 0; i--){
      for (int j = 0; j < W; j++){
        if (now[i][j] == 0){
          
          int start = i;
          for (int k = i; k >= 0; k--){
            if (now[k][j] != 0) {
              start = k; break;
            }
          }

          for (int k = start; k >= 0; k--){
            now[i - start + k][j] = now[k][j];
          }
          for (int k = 0; k < i - start; k++){
            now[k][j] = 0;
          }

        }
      }
    }
  }

  ans = max(ans, score);

  return 0;
}

int main(){
  scanf("%d%d%d", &H, &W, &K);
  for (int i = 0; i < H; i++){
    scanf("%s", &C[i]);
  }

  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      Solve(i, j);
    }
  }
  printf("%d\n", ans);
  
  return 0;
}


Measured memory_bytes: 256
// IN the name of GOD

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int M = 1e9 + 7;

void solve () {
    int x, n;
    cin >> x >> n;
    vector <int> chk(105);
    int ans = x;
    int mini = 1e9;
    for (int i = 0; i < n; ++i) {
        int y;
        cin >> y;
        chk[y] = 1;
    }
    int l = x, r = x;
    for (int i = x; i <= 104; ++i) {
        if (!chk[i]) {
            r = i;
            break;
        }
    }
    for (int i = x; i >= 0; --i) {
        if (!chk[i]) {
            l = i;
            break;
        }
    }
    // cout << l << " " << r << "\n";
    cout << (abs(l - x) <= abs(r - x) ? l : r);
}
// 2x + 4y = z2
// x + y = z1

int main () {
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    int tt = 1;
        // scanf("%d", &tt);
    while (tt--)
        solve();
 
}

Measured memory_bytes: 3636
from sys import stdin
def main():
  from builtins import range
  readline = stdin.readline
  h, w = map(int, readline().split())
  s = [readline().rstrip('\r\n') + '#' for _ in range(h)]
  s.append('#' * w)
  ft = [[i] * i for i in range(10)]
  yoko = [[0] * w for _ in range(h)]
  for i in range(h):
    start = -1
    si = s[i]
    yokoi = yoko[i]
    for j in range(w + 1):
      if si[j] == '#':
        if start != -1:
          t = j - start
          if t < 10:
            yokoi[start:j] = ft[t]
          else:
            yokoi[start:j] = [t] * t
          start = -1
      else:
        if start == -1:
          start = j
  result = 0
  for i in range(w):
    start = -1
    for j in range(h + 1):
      if s[j][i] == '#':
        if start != -1:
          t = yoko_max + j - start - 1
          if t > result:
            result = t
          start = -1
      else:
        yji = yoko[j][i]
        if start == -1:
          start = j
          yoko_max = yji
        else:
          if yji > yoko_max:
            yoko_max = yji
  print(result)
main()

Measured memory_bytes: 40820
s = input()
t = input()
ans = "Yes"
l = []
for i in range(len(s)):
    if s[i] in l:
        if s[i] != t[i]:
            ans = "No"
            break
    else:
        if t[i] in l:
            ans = "No"
            break
        if s[i] == t[i]:
            l.append(s[i])
        else:
            c1 = s[i]
            c2 = t[i]
            s = s.replace(c1, 'A')
            s = s.replace(c2, 'B')
            s = s.replace('A', c2)
            s = s.replace('B', c1)
            l.append(c2)
print(ans)


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std ;
typedef  long long int ll ;
#define inf ll(1e9)
#define mod 1000000007
#define mod1 998244353
#define mod2 999983
ll power(ll a,ll n,ll m) ;
ll power(ll a,ll n,ll m)
{  if(n==0)
   return 1 ;
   ll x=power(a,n/2,m) ;
   if(n%2!=0)
    return (((a*x)%m)*(x)%m)%m ;
    else return (x*x)%m ;
}
int sieve [10000001] ;
double PI=3.14159265357 ;
int32_t main()
{ ll n,i,j,x,y,m,k,t,sum,count,cnt,b,c,d,j1,z,a,temp;
  ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
  cin>>n>>m>>k ;
  ll arr[n],brr[m] ;
  for(i=0;i<n;i++) cin>>arr[i] ;
  for(j=0;j<m;j++) cin>>brr[j] ;
  for(i=1;i<n;i++) arr[i]+=arr[i-1] ;
  for(j=1;j<m;j++) brr[j]+=brr[j-1] ;
  z=0 ;
  for(i=0;i<n;i++)
  {
      if(arr[i]>k)
        break ;
        x=arr[i] ;
     ll l,r,mid ;
     l=0 ;
     r=m-1 ;
     y=-1 ;
     while(l<=r)
     {
         mid=(l+r)/2 ;
         if(brr[mid]+x<=k)
         {
             y=mid ;
             l=mid+1 ;
         }
         else r=mid-1 ;
     }
     if(y==-1)
        {
            z=max(z,i+1) ;
           // break ;
        }
        z=max(z,i+1+y+1) ;
  }
  for(i=0;i<m;i++)
  {
      if(brr[i]>k)
        break ;
        x=brr[i] ;
     ll l,r,mid ;
     l=0 ;
     r=n-1 ;
     y=-1 ;
     while(l<=r)
     {
         mid=(l+r)/2 ;
         if(arr[mid]+x<=k)
         {
             y=mid ;
             l=mid+1 ;
         }
         else r=mid-1 ;
     }
     if(y==-1)
       { z=max(z,i+1) ;}
     //   break ; } }
        z=max(z,i+1+y+1) ;
  }
  cout<<z ;
  return 0; }


Measured memory_bytes: 6780
L, R = map(int,input().split())

l = L%2019
r = R%2019
ans = 0
if R-L >= 2019:
  ans = 0
else:
  if l>=r:
    ans=0
  else:
    ans = 2018
    for i in range(l,r):
      for j in range(l+1,r+1):
        ans = min(ans, (i*j)%2019)

print(ans)

Measured memory_bytes: 64884
import java.util.*;

class Main{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                while(sc.hasNext()){
                        int[][] ab = new int[2][4];
                        for(int i = 0; i < 2; i++){
                                for(int j = 0; j < 4; j++){
                                        ab[i][j] = sc.nextInt();
                                }
                        }
                        int hit = 0;
                        int blow = 0;
                        for(int i = 0; i < 4; i++){
                                if(ab[0][i] == ab[1][i]){
                                        hit++;
                                }else if(has(ab[0], ab[1][i])){
                                        blow++;
                                }
                        }
                        System.out.println(hit+" "+blow);
                }
                sc.close();
        }
        static boolean has(int[] a, int b){
                for(int i = 0; i < a.length; i++){
                        if(a[i] == b){
                                return true;
                        }
                }
                return false;
        }
}

Measured memory_bytes: 11000
#include <stdio.h>
#include <string.h>

int main(void){
    
    int n,w;
    scanf("%d",&n);
    
    int a[n];
    for(int i=0; i<n; i++)
        scanf("%d",&a[i]);
    
    for(int i=1; i<n; i++){
        for(int j=i; j>0 && a[j-1]<a[j]; j--){
            w=a[j-1];
            a[j-1]=a[j];
            a[j]=w;
        }
    }
    printf("%d",a[0]-a[n-1]);
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
	char a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p;
	cin>>a>>b>>c>>d>>e>>f>>g>>h>>i>>j>>k>>l>>m>>n>>o>>p;
	int sum=0;
	if(a!='C')sum++;
	if(b!='O')sum++;
	if(c!='D')sum++;
	if(d!='E')sum++;
	if(e!='F')sum++;
	if(f!='E')sum++;
	if(g!='S')sum++;
	if(h!='T')sum++;
	if(i!='I')sum++;
	if(j!='V')sum++;
	if(k!='A')sum++;
	if(l!='L')sum++;
	if(m!='2')sum++;
	if(n!='0')sum++;
	if(o!='1')sum++;
	if(p!='6')sum++;
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int cd[200],t[200];
int n,m,k;
void cut(){
	copy(cd,cd+k,t+2*n-k); copy(cd+k,cd+2*n,t);
}
void sfl(){
	rep(i,n)t[i*2]=cd[i],t[i*2+1]=cd[n+i];
}
int main(){
	cin>>n>>m;
	rep(i,n*2)cd[i]=i+1;
	rep(i,m)cin>>k,k?cut():sfl(),copy(t,t+2*n,cd);
	rep(i,2*n)cout<<cd[i]<<endl;
	return 0;
}

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

int main(void)
{
  int n,m,k,i,j,time,limit,count=0;
  long long int temp,*a,*b;
  
  scanf("%d",&n);
  scanf("%d",&m);
  scanf("%d",&k);
  
  a=(long long int)malloc(sizeof(long long int)*n+1);
  a[0]=0;
  for(i=1;i<=n;i++)
  {
    scanf("%lld",&temp);
    a[i]=temp+a[i-1];
  }
  
   b=(long long int)malloc(sizeof(long long int)*m+1);
  b[0]=0;
  for(i=1;i<=m;i++)
  {
    scanf("%lld",&temp);
    b[i]=b[i-1]+temp;
  }
  

  limit=m;
  for(i=0;i<=n;i++)
  {
    if(k<a[i])break;
    j=limit;
    while(b[j]>k-a[i])
    {
      j--;
    }
    limit=j;
    if(count<i+j)count=i+j;
  }
  
  printf("%d",count);
  
  free(a);
  free(b);
  
  return 0;
}
  

Measured memory_bytes: 4944
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
#define F first
#define S second
#define MK make_pair




int main(){
    int n;
    cin>>n;
    vector<ll> a;
    ll tei=0;
    ll up=0;
    ll low=0;
    for(int i=0;i<n;i++){
        ll b;
        cin>>b;
        a.push_back(b);
        if(b>i){up++;}
        if(b<i){low++;}
    }
    ll mi=abs(up-low);
    ll k=100000000000;
    while(1){
        if(abs(k)<=10){break;}
        if(mi<1){break;}
        tei+=k;
        if(k==100000000000){tei=1e10;}
        up=0;
        low=0;
        for(int i=0;i<a.size();i++){
            if((ll)a[i]>tei+i){up++;}
            if((ll)a[i]<tei+i){low++;}
        }
        if(up>low){k=abs(k)/2+1;}
        if(up<low){k=-1*abs(k)/2+1;}
        if(up==low){break;}
    }
    ll M=1e18;
    for(int i=-50;i<50;i++){
        ll sum=0;
        for(int t=0;t<a.size();t++){
            sum+=abs(a[t]-(tei+i+t));
        }
        M=min(M,sum);
    }
    cout<<M<<endl;
    
    
    
    
    
    
    return 0;
}


Measured memory_bytes: 2420
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(){
  char s[60];
  int n,count;
  scanf("%d",&n);
  scanf("%s",s);
  
 for(int i=0;i<n;i++){
   if(s[i]=='A'){
     if(s[i+1]=='B'){
       if(s[i+2]=='C'){
         count++;
       }
     }
   }
 }
  printf("%d\n",count);
  return 0;
}

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

#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (long long)(a); i <= (long long)(n); i++)
#define irrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define irrep2(i,a,n) for(int i = (int)(n); i >= (int)(a); i--)

typedef long long ll;
typedef std::vector<int> v_int;
typedef std::vector<v_int > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<v_ll > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<v_string > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<v_bool > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

const double PI = 3.1415926535897932;
const int INF = (int)1e9;
const ll LINF = 1e18;
const ll MOD = 1000000007;
const int dr[4] = {1, 0, -1, 0};
const int dc[4] = {0, 1, 0, -1};

using namespace std; 

template<typename T, typename U> inline
ostream& operator<<(ostream &o, pair<T,U> &p)
{
    return o << "{" << p.first << "," << p.second << "}";
}

template<typename T> inline
ostream& operator<<(ostream &os, vector<T> &v)
{
    int len = v.size();
    for(int i = 0; i < len; i++) { 
        os << v[i];
        if(i != len-1) { os << ","; } 
    } 
    return os;
}

int main(void)
{
    int n;
    cin >> n;
    
    v_int a(n);

    irep(i, n) {
        cin >> a[i];
    }

    sort(a.begin(), a.end());

    int max_a = INF;
    
    irep(i, n-1) {
        if(abs(a[n-1]-a[i]*2) < abs(a[n-1]-max_a*2)) {
            max_a = a[i];
        }
    }
    cout << a[n-1] << " " << max_a << endl;
    return 0;
}

/*atcoder*/


Measured memory_bytes: 3696
#include<bits/stdc++.h>
using namespace std;
const int N=2e3+10,L=1e3+10;
int n,l[N],s[L<<1];
long long sum;
void init(){scanf("%d",&n);for(int i=1;i<=n;++i) scanf("%d",&l[i]),++s[l[i] ];}
void work(){
	for(int i=2;i<=2000;++i) s[i]+=s[i-1]; sort(l+1,l+n+1); sum=0;
	for(int i=1;i<=n-1;++i) for(int j=i+1;j<=n;++j){
		sum+=(s[l[j]+l[i]-1]-s[l[j]-l[i] ]);
		if(l[i]>l[j]-l[i]&&l[i]<=l[j]+l[i]-1) --sum;
		if(l[j]>l[j]-l[i]&&l[j]<=l[j]+l[i]-1) --sum;
	}
}
void prin(){printf("%lld",sum/3);}
int main(){init(); work(); prin(); return 0;}

Measured memory_bytes: 256
#include<stdio.h>


int n, A[50];

int solve(int i,int m){
	if(m == 0) return 1;
	if(i >= n) return 0;
	int res = solve(i + 1, m) || solve(i + 1, m - A[i]);
	return res;
}



int main(){
	int q,M,i;
	scanf("%d",&n);
	for(i=0;i<n;i++) scanf("%d",&A[i]);
	scanf("%d",&q);
	for(i=0;i<q;i++){
		scanf("%d",&M);
		if(solve(0,M)) printf("yes\n");
		else printf("no\n");
	}
	
	
	
	return 0;
}

Measured memory_bytes: 1800
# 解説どおりにやるとK = 0で失敗する? 
def number_of_a(b):
	if K == 0:
		return N
	q, r = divmod(N,b)
	# for each range, we have b-K possible A's
	# in the last range, we have max(0,r-K+1) possible A's.
	s = q * max(0,b-K) + max(0,r-K+1)
	# print((b,q,r,s))
	return s
 
N, K = map(int,input().split())
s = 0; b = 1;
while b <= N:
	s += number_of_a(b)
	b += 1
print(s)

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}

int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n, m;
	cin >>n >>m;
	VL h(n);
	rep(i, n) cin >>h[i];
	vector<VI> r(n);
	rep(i, m){
		int a, b;
		cin >>a >>b;
		r[a-1].push_back(b-1);
		r[b-1].push_back(a-1);
	}
	
	ll ans = 0;
	rep(i, n){
		ll cr = h[i];
		bool ok=true;
		for(auto x: r[i]){
			if(h[i] <= h[x]) ok=false;
		}
		if(ok) ans++;
	}
	
	cout << ans <<"\n";
	return 0;
}


Measured memory_bytes: 9068
#include <stdio.h>

int main (){
	 
	 int N,x;
	 scanf("%d",&N);
	 if(N%2!=0){
	 	x=N*2;
	 	printf("%d\n",x);
	 }
	 else{
	 	printf("%d\n",N);
	 }

	 return 0;	
}

Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する

struct BIT{
    vector<int> bit;
    int n;
    /*
     * 1 ~ nまでのBITを作る
     */
    BIT(int n){
        bit.resize(n+1,0);
        this->n = n;
    }
    int sum(int i){
        int s = 0;
        while(i > 0){
            s += bit[i];
            i -= i & -i;
        }
        return s;
    }
    void add(int i,int x){
        while(i <= n){
            bit[i] += x;
            i += i & -i;
        }
    }
};

//1オリジンで座圧する
//vector<int> zaatsu(vector<int> v){
//    map<int,int> mp;
//    vector<int> w = v;
//    sort(all(w));
//    int cnt = 0;
//    rep(i,0,w.size()){
//        if(mp.find(w[i]) == mp.end() ){
//            mp[w[i]] = ++cnt;
//        }
//    }
//    vector<int> ret(v.size());
//    rep(i,0,v.size()){
//        ret[i] = mp[v[i]];
//    }
//    return ret;
//}

template <typename T>
vector<int> zaatsu(vector<T> v){
    map<T,int> mp;
    vector<T> w = v;
    sort(all(w));
    int cnt = 0;
    rep(i,0,w.size()){
        if(mp.find(w[i]) == mp.end() ){
            mp[w[i]] = ++cnt;
        }
    }
    vector<int> ret(v.size());
    rep(i,0,v.size()){
        ret[i] = mp[v[i]];
    }
    return ret;
}

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

    int N,K;
    cin >> N >> K;
    vector<ll> a(N);
    rep(i,0,N){
        cin >> a[i];
        a[i] -= K;
    }

    vector<ll> b;
    b.push_back(0);
    rep(i,0,a.size()){
        b.push_back(b.back() + a[i]);
    }

    vector<int> za = zaatsu(b);


    ll ans = 0LL;
    BIT bit(N+1);
    rep(i,0,za.size()){
        ans += 1LL*bit.sum(za[i]);

        bit.add(za[i],1);
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 19824
def divisor(n):
    ass = []
    for i in range(1,int(n**0.5)+1):
        if n%i == 0:
            ass.append(i)
            ass.append(n//i)
    return ass #sortされていない

# テスト
N = int(input())
#print(divisor(N))
div = divisor(N)
ans = 0
for a in div:
    b = N // a
    A = str(a)
    B = str(b)
    ans = max(len(A),len(B))
print(ans)

Measured memory_bytes: 39152
#include <sstream>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <string>
#include <queue>
#include <bitset>
using namespace std;

#define int long long
#define FOR(i, a, b) for (int i = (a), _##i = (b); i <= _##i; ++i)
#define FORD(i, a, b) for (int i = (a), _##i = (b); i >= _##i; --i)
#define REP(i, a) for (int i = 0, _##i = (a); i < _##i; ++i)
#define REPD(i,n) for(int i = (n)-1; i >= 0; --i)

#define DEBUG(X) { cerr << #X << " = " << (X) << endl; }
#define PR(A, n) { cerr << #A << " = "; FOR(_, 1, n) cerr << A[_] << ' '; cerr << endl; }
#define PR0(A, n) { cerr << #A << " = "; REP(_, n) cerr << A[_] << ' '; cerr << endl; }

#define sqr(x) ((x) * (x))
#define ll long long
#define double long double
typedef pair<int, int> II;
#define __builtin_popcount __builtin_popcountll
#define SZ(x) ((int)(x).size())
#define ALL(a) (a).begin(), (a).end()
#define MS(a,x) memset(a, x, sizeof(a))
#define next ackjalscjaowjico
#define prev ajcsoua0wucckjsl
#define y1 alkscj9u20cjeijc
#define left lajcljascjljl
#define right aucouasocjolkjl
#define y0 u9cqu3jioajc

#define TWO(X) (1LL<<(X))
#define CONTAIN(S,X) ((S) & TWO(X))

int rand16() {
    return rand() & (TWO(16) - 1);
}
int my_rand() {
    return rand16() << 15 | rand16();
}

double safe_sqrt(double x) { return sqrt(max((double)0.0, x)); }
int GI(int& x) { return scanf("%lld", &x); }

const int BLACK = 1;
const int WHITE = 0;

const int MN = 100111;
vector<int> ke[MN];
int n;
int color[MN];

void dfs(int u, int fu) {
    int cnt = 0;
    color[u] = BLACK;
    for(int v : ke[u]) if (v != fu) {
        ++cnt;
        dfs(v, u);

        if (color[v] == BLACK) color[u] = WHITE;
    }
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout << (fixed) << setprecision(9) << boolalpha;
    while (cin >> n) {
        FOR(i,1,n) ke[i].clear();
        FOR(i,2,n) {
            int u, v; cin >> u >> v;
            ke[u].push_back(v);
            ke[v].push_back(u);
        }
        memset(color, -1, sizeof color);
        dfs(1, -1);

        int nWhite = 0, nBlack = 0;
        FOR(i,1,n) if (color[i] == WHITE) ++nWhite; else ++nBlack;

        if (nBlack > n / 2) cout << "First"; else cout << "Second";
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 7168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    if(K == 1) {
        cout << 0 << endl;
        return 0;
    }
    cout << (N - (K - 1)) - 1 << endl;
    return 0;
}


Measured memory_bytes: 256
class Stack:
    data_list = []
    def push(self, a):
        self.data_list.append(a)
    def pop(self):
        return self.data_list.pop()

data = input()
lines = data.strip().split()
stack = Stack()
for line in lines:
    if line == '+':
        num = int(stack.pop()) + int(stack.pop())
        stack.push(num)
    elif line == '-':
        num = int(stack.pop()) - int(stack.pop())
        stack.push(-1*num)
    elif line == '*':
        num = int(stack.pop()) * int(stack.pop())
        stack.push(num)
    else:
        stack.push(line)

print(stack.pop())


Measured memory_bytes: 5596
alf = list(str('abcdefghijklmnopqrstuvwxyz'))
n = int(input())
s = str(input())
ans = 0
for i in range(len(s)):
    x = s[:i]
    y = s[i:]
    count = 0
    for j in alf:
        if j in x and j in y:
            count += 1
    if count > ans:
        ans = count
print(ans)

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

int main(){
  int n,x; cin>>n>>x;
  int s=0,c=0;
  
  for(int i=0;i<n;i++){
    int l;
    cin>>l;
    s = s + l;
    if(s>x) break;
    c += 1;
  }
  
  cout<<c+1<<endl;
  return 0;
  

}

Measured memory_bytes: 256
N,M=map(int,input().split())
mod=10**9+7
broken=[True for _ in range(N+1)]
for i in range(M):
    broken[int(input())]=False

dp=[0 for _ in range(N+1)]
dp[0]=1
for i in range(N+1):
    if broken[i]==False:
        continue
    else:
        if i==0:
            continue
        elif i==1:
            dp[i]=1
        else:
            dp[i]=(dp[i-1]+dp[i-2])%mod
print(dp[N])

Measured memory_bytes: 7832
#include <bits/stdc++.h>
#define FI first
#define SE second
#define PB push_back
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define co(i) cout<<(i)<<endl
#define fcout cout<<fixed<<setprecision(10)
#define uni(i) i.erase(unique(i.begin(), i.end()), i.end());
#define all(i) i.begin(),i.end()
#define pint pair<int, int>
#define vint vector<int>
using namespace std;

const int INF=1e9+7;
const int MOD=1e9+7;
//const int MOD=998244353;

int main(){
	int n,k; cin>>n>>k;
	int h[100000];
	int dp[100000]={};
	FOR(i,0,n){
		cin>>h[i];
	}
	dp[0]=0;
	FOR(i,1,n){
		int m=INF;
		FOR(j,0,k){
			if(i-j-1>=0) m=min(m,abs(h[i]-h[i-j-1])+dp[i-j-1]);
		}
		dp[i]=m;
	}
	co(dp[n-1]);
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define eb emplace_back
#define precision(n) cout << fixed << setprecision(n);
#define fast {ios_base::sync_with_stdio(false);cin.tie(NULL);}
int main()
{
    fast;
   int n,x,k;
   cin>>n>>x>>k;
   if(n%x==0)
   {
       cout<<(n/x)*k<<endl;
   }
   else
   {
       cout<<(n/x+1)*k<<endl;
   }
    return 0;
}


Measured memory_bytes: 3608