akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, cos, radians, pi, sin
from operator import mul
from functools import reduce
from operator import mul

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


class UnionFind:
    def __init__(self, n):
        # 負  : 根であることを示す。絶対値はランクを示す
        # 非負: 根でないことを示す。値は親を示す
        self.table = [-1] * n
        self.size = [1] * n
        self.group_num = n

    def root(self, x):
        if self.table[x] < 0:
            return x
        else:
            self.table[x] = self.root(self.table[x])
            return self.table[x]

    def get_size(self, x):
        r = self.root(x)
        return self.size[r]

    def is_same(self, x, y):
        return self.root(x) == self.root(y)

    def union(self, x, y):
        r1 = self.root(x)
        r2 = self.root(y)
        if r1 == r2:
            return
        # ランクの取得
        s1 = self.table[r1]
        s2 = self.table[r2]
        if s2 <= s1:
            self.table[r2] = r1
            self.size[r1] += self.size[r2]
        else:
            self.table[r1] = r2
            self.size[r2] += self.size[r1]
        self.group_num -= 1

n = I()
P = LI()

fac = [1] * (n + 1)
inv = [1] * (n + 1)
for j in range(1, n + 1):
    fac[j] = fac[j-1] * j % mod


inv[n] = pow(fac[n], mod-2, mod)
for j in range(n-1, -1, -1):
    inv[j] = inv[j+1] * (j+1) % mod


def comb(n, r):
    if r > n or n < 0 or r < 0:
        return 0
    return fac[n] * inv[n - r] * inv[r] % mod


ret = 0
for p in P:
    if p == -1:
        ret += 1

U = UnionFind(n)
for i in range(n):
    if P[i] != -1:
        U.union(P[i] - 1, i)

L = []
for j in range(n):
    if P[j] == -1:
        L += [U.size[j]]

dp = [0] * (len(L) + 1)
dp[0] = 1
for l in range(1, len(L) + 1):
    for m in range(l, 0, -1):
        dp[m] += dp[m - 1] * L[l - 1]

if L:
    dp[1] = sum(L) - len(L)
cycle_cnt = 0
for i in range(1, len(L) + 1):
    cycle_cnt = (cycle_cnt + fac[i - 1] * dp[i] * pow(n - 1, len(L) - i, mod)) % mod

ans = (n - (U.group_num - ret)) * pow(n - 1, ret, mod) % mod
print((ans - cycle_cnt) % mod)


Measured memory_bytes: 184816
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <numeric>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = n;i >= m;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 999999999
#define MINF -999999999
#define ALL(n) n.begin(),n.end()
ll n, a = 1, b;

ll gcd(ll a, ll b) {
	if (a < b) gcd(b, a);
	ll r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}

ll lcm(ll number1, ll number2) {
	return number1 * (number2 / gcd(number1, number2));
}

int main() {
	cin >> n;
	REP(i, n) {
		cin >> b;
		a = lcm(a, b);
	}
	cout << a << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <algorithm>
#include <map>
#include <vector>
#include <list>
#include <cmath>
#include <stack>
#include <queue>
#include <climits>

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

const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x% mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res /= a;
	}
};

struct combination {
	vector<mint> fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n) return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
} comb(2000005);

mint g(int r, int c) {
	return comb(r + c + 2, r + 1) - 1;
}

int n, weight;
int w[100];
int v[100];
long long dp[110][100100];

int main()
{
	cin >> n >> weight;
	for (int i = 0; i < n; i++)
	{
		cin >> w[i] >> v[i];
	}
	for (int i = 0; i <= n; i++)
	{
		for (int j = 1; j <= 100000; j++)
		{
			dp[i][j] = INT_MAX;
		}
	}
	dp[0][0] = 0;


	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= 100000; j++)
		{
			if (j - v[i - 1] < 0 || dp[i - 1][j - v[i - 1]] + w[i - 1] > weight)
			{
				dp[i][j] = dp[i - 1][j];
			}
			else
			{
				dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i - 1]] + w[i - 1]);
			}
		}
	}

	for (int i = 100000; i > 0; i--)
	{
		if (dp[n][i] <= weight)
		{
			cout << i;
			return 0;
		}
	}
	cout << 0;
}


Measured memory_bytes: 111360
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <sstream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <complex>
#include <vector>
#include <cstdio>
#include <cmath>
#include <time.h>
#define all(c) ((c).begin(),(c).end())
#define rall(c) (c).rbegin(),(c).rend()
#define sort(v,n) sort(v,v+n)
#define vsort(v) sort(v.begin(),v.end())
#define vvsort(v) sort(v.begin(),v.end(),greater<int>())
#define ll long long
#define pb(a) push_back(a)
#define fi first
#define se second
#define inf 999999999
using namespace std;
const ll MOD = 1e9 + 7;
const double PI = acos(-1.0);
//---------------------------------------------------------------------------------------------//
int n, m;
char a[60][60], b[60][60];

bool solve(int s,int t) {
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < m; j++) {
			if (a[s+i][t+j] != b[i][j]) {
				return 0;
			}
		}
	}
	return 1;
}

int main() {
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> a[i][j];
		}
	}
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < m; j++) {
			cin >> b[i][j];
		}
	}
	for (int i = 0; i < n - m + 1; i++) {
		for (int j = 0; j < n - m + 1; j++) {
			if (solve(i,j) == 1) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 256
// Problem : E - Divisible Substring
// Contest : AtCoder - AtCoder Beginner Contest 158
// URL : https://atcoder.jp/contests/abc158/tasks/abc158_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define int long long
#define db double
#define mod 1000000007
#define pb push_back
#define pp pair<int,int>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repe(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=b;i>=a;i--)
#define maxn 200005
#define ss second
#define ff first
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
int inv(int a, int b){
 return 1<a ? b - inv(b%a,a)*b/a : 1;
}
int arr[maxn];
void solve()
{
	int t=1;
	int n,p;
	cin >> n >> p;
	string str;
	cin >> str;
	if(p==2 || p==5)
	{
		int cnt = 0;
		rep(i,0,n)
		if((str[i]-'0')%p==0)
		cnt+=(i+1);
		cout << cnt;
		return;
	}
	rep(i,0,n)
	{
		arr[i]=t;
		t*=10;
		t%=p;
	}
	int v[p]={0},prev=0;
	repr(i,0,n-1)
	{
		int x = str[i]-'0';
		x*=arr[n-1-i];
		x+=prev;
		x%=p;
		v[x]++;
		prev=x;
	}
	int ans = 0;
	rep(i,0,p)
	{
		//cout << v[i] <<"\n";
		if(i==0)
		{
			ans += ((v[i])*(v[i]+1))/2;
		}
		else ans += ((v[i]-1)*v[i])/2;
	}
	cout << ans;
}
signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin >> t;
    while(t--)
    solve();
    return 0;
}


Measured memory_bytes: 5304
#include<stdio.h>
 
 
int main(){
 
  int card[4][13]={};
  int n, num, i, j;
  char m;
 
  scanf("%d", &n);
  for(i=0;i<n;i++){
    scanf(" %c %d", &m, &num);
    if(m=='S') card[0][num-1]=1;
    else if(m=='H') card[1][num-1]=1;
    else if(m=='C') card[2][num-1]=1;
    else if(m=='D') card[3][num-1]=1;
  }
 
  for(i=0;i<4;i++){
    for(j=0;j<13;j++){
      if(i==0&&card[i][j]==0) printf("S %d\n", j+1);
      else if(i==1&&card[i][j]==0) printf("H %d\n", j+1);
      else if(i==2&&card[i][j]==0) printf("C %d\n", j+1);
      else if(i==3&&card[i][j]==0) printf("D %d\n", j+1);
    }
  }
 
   
  return 0;
}


Measured memory_bytes: 2124
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;

int main() {
	string S, T;
	cin >> S >> T;
	
	uint A, B;
	cin >> A >> B;
	
	string U;
	cin >> U;
	
	A = (U == T) ? A : A - 1; 
	B = (U == S) ? B : B - 1; 	
	
	cout << A << " " << B;;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>
#include <map>
#include <set>
#include <math.h>
#include <cmath>
#define ll long long

using namespace std;

int main(){

  int A, B;
  cin >> A >> B;

  cout << A*B << endl;

  return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <climits>

using namespace std;


#define MAX 500000


long L[MAX/2+1], R[MAX/2+1];
long cnt = 0;
void merge(long A[], long l, long r, long m)
{
    long ln = m - l;
    long rn = r - m;

    for (long i = 0; i < ln; i++)
        L[i] = A[l + i];
    for (long i = 0; i < rn; i++)
        R[i] = A[m + i];

    L[ln] = INT_MAX;
    R[rn] = INT_MAX;

    long li, ri;
    li = ri = 0;

    for (long i = l; i < r; i++) {
        cnt++;
        if (L[li] <= R[ri])
            A[i] = L[li++];
        else
            A[i] = R[ri++];
    }
}


void merge_sort(long A[], long l, long r)
{
    if (r - l > 1) {
        long m = (l + r) / 2;
        merge_sort(A, l, m);
        merge_sort(A, m, r);
        merge(A, l, r, m);
    }
}


long A[MAX];
int main()
{
    long n;
    cin >> n;

    for (long i = 0; i < n; i++)
        cin >> A[i];

    merge_sort(A, 0, n);

    for (long i = 0; i < n - 1; i++) {
        cout << A[i] << " ";
    }
    cout << A[n - 1] << endl;
    cout << cnt << endl;
    return 0;
}




Measured memory_bytes: 10904
package main

import (
	"fmt"
	"math"
)

func main()  {
	var n int
	fmt.Scan(&n)

	p := make([]int, n)
	for i:=0; i<n; i++ {
		fmt.Scan(&p[i])
	}
	min := 30
	max := 0
	count := 0
	for i:=1; i<n-1; i++ {
		min = int(math.Min(float64(p[i-1]), math.Min(float64(p[i]), float64(p[i+1]))))
		max = int(math.Max(float64(p[i-1]), math.Max(float64(p[i]), float64(p[i+1]))))
		if min != p[i] && max != p[i] {
			count++
		}
	}
	fmt.Println(count)
}

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

#define PI 3.141592653589
#define ll long long int
#define ld long double
#define vi vector<int>
#define ii pair<int,int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pll pair<ll,ll>
#define vv vector
int MOD=1e9+7;
ll power(ll a, ll b){//a^b
    ll res=1;
    a=a%MOD;
    while(b>0){
        if(b&1){res=(res*a)%MOD;b--;}
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
ll min(ll a,ll b){return (a>b)?b:a;}
ll max(ll a,ll b){return (a>b)?a:b;}
bool prime[1000001];
vi primes;
void SieveOfEratosthenes(int n) 
{ 
    memset(prime, true, sizeof(prime)); 
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
    for(int p=2;p<1000001;p++)
        if(prime[p])
            primes.pb(p);
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

    int t=1;
	//cin>>t;
	//SieveOfEratosthenes(1000000);
    while(t--){
        int n;
        cin>>n;
        int a[n];
        for(int i=0;i<n;i++)
            cin>>a[i];

        int cnt=0;
        for(int i=0;i<n;i+=2)
            if(a[i]%2)
                cnt++;
        
        cout<<cnt;
    }
}

Measured memory_bytes: 3652
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <ctime>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <memory.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long double LD;
typedef long long LL;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#ifdef LOCAL
    #define DEBUG(x) { cerr << "# " << #x << ": " << x << endl;}
#else
    #define DEBUG(x)
#endif
mt19937_64 mt(time(0));
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/
const int mod = 1e9 + 7;
const int MAXN = 1e5 + 10;
LL dp[MAXN], nums[MAXN];

LL power(LL base, LL p) {
    base = base % mod;
    LL ret = 1;
    while (p) {
        if (p & 1) ret = base * ret % mod;
        base = base * base % mod;
        p >>= 1;
    }
    return ret;
}






int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cout.precision(10); cout << fixed;
#ifdef LOCAL
    freopen("../test.txt", "r", stdin);
    // freopen("../output.txt", "w", stdout);
#endif
    int n; cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> nums[i];
    }
    dp[1] = 1;
    for (int i = 2; i <= n; i++) {
        dp[i] += dp[i-1];
        dp[i] = (dp[i] + power(i, mod-2)) % mod;
    }
    LL coeff = 1;
    for (int i = 2; i <= n; i++) {
        coeff = coeff * i % mod;
    }
    LL ret = 0;
    for (int i = 1; i <= n; i++) {
        LL tmp = dp[n-i+1];
        tmp += dp[i];
        tmp = (tmp -1) % mod;
        ret = (ret + tmp*nums[i] % mod) % mod;
    }
    cout << ret*coeff % mod << endl;






/*---------------------------------------Coding Space End------------------------------------------*/
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." << endl;
#endif
    return 0;
}
/* author:  txingml */
/* picture is from hamayanhamayan(CF handle) */


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

int main(){
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  int dx=abs(A-C);
  int dy=abs(B-D);
  if(dx==0||dy==0){
    cout<<0<<endl;
    return 0;
  }
  int dz=__gcd(dx,dy);
  dx/=dz;
  dy/=dz;
  int ans=dx+dy-1;
  ans*=dz;
  cout<< ans <<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> Q;

ll mod = 1000000007;
int n, m, x, y, z, flag[100010], ans;
vector<int> road[100010];

void dfs(int p, int q)
{
	flag[p] = q;
	for (int i = 0; i < road[p].size(); i++)
	{
		if (flag[road[p][i]] != 0) continue;
		dfs(road[p][i], q);
	}
}

int main()
{
	cin >> n >> m;
	for (int i = 0; i < m; i++)
	{
		cin >> x >> y >> z;
		road[x].push_back(y);
		road[y].push_back(x);
	}
	for (int i = 1; i <= n; i++)
	{
		if (flag[i] != 0) continue;
		ans++;
		dfs(i, i);
	}
	cout << ans << endl;
	cin >> n;
}

Measured memory_bytes: 10752
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = (1 << 30) - 1;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;

void loop(int at, int mv, string S) {
	if(at == N) {
		cout << S << "\n";
		return;
	}
	S += 'a';
	rep(i, 0, mv) {
		S.back() = char('a' + i);
		loop(at + 1, mv, S);
	}
	S.back() = char('a' + mv);
	loop(at + 1, mv + 1, S);
}

void solve() {
	cin >> N;
	loop(0, 0, "");
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



Measured memory_bytes: 1536
//
// Created on 2020/08/26.
//


#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 <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
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; }
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;



int main() {
    int n;
    cin>>n;
    vector<vector<ll>>g(n,vector<ll>(n,0));

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            cin>>g[i][j];
        }
    }
    vector<vector<int>>edge(n,vector<int>());
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            if(i == j)continue;
            ll direct = g[i][j];
            bool add = true;
            for (int k = 0; k < n; ++k) {
                if(k == i || k == j)continue;
                ll via = g[i][k] + g[k][j];
                if(direct < via){
                }else if(direct == via){
                    add = false;
                }else if(direct > via){
                    cout<<-1<<endl;
                    return 0;
                }
            }
            if(add)edge[i].push_back(j);
        }
    }
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < edge[i].size(); ++j) {
            if(edge[i][j] < i)continue;
            ans += g[i][edge[i][j]];
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

int parent[100000], rank[100000];

int find_root(int x) {
  if(parent[x] == x) return x;
  return parent[x] = find_root(parent[x]);
}

void unit(int x, int y) {
  x = find_root(x);
  y = find_root(y);
  if(x == y) return;
  if(rank[x] < rank[y]) {
    parent[x] = y;
  } else {
    parent[y] = x;
    if(rank[x] == rank[y]) rank[x]++;
  }
}

int main() {
  int i;

  int n, m, x, y, z;
  scanf("%d %d", &n, &m);

  for(i = 0; i < n; i++) {
    parent[i] = i;
    rank[i] = 0;
  }

  for(i = 0; i < m; i++) {
    scanf("%d %d %d", &x, &y, &z);
    x--;
    y--;
    unit(x, y);
  }

  int num_magic = 0;
  for(i = 0; i < n; i++) {
    if(parent[i] == i) num_magic++;
  }

  printf("%d\n", num_magic);

  return 0;
}


Measured memory_bytes: 896
#![allow(unused_imports, unused_variables, dead_code)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

trait InputValue {
    fn parse(s: &str) -> Self;
}

fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);

// ===

fn main() {
    let (n, x): (usize, i64) = read();
    let a: Vec<i64> = readnc();

    let mut aa = a.clone();
    let mut left = 0;
    for i in 1..n {
        if aa[i-1] + aa[i] > x {
            let diff = aa[i-1] + aa[i] - x;
            left += diff;
            aa[i] = max(0, aa[i] - diff);
        }
    }
    println!("{}", left);
}

Measured memory_bytes: 8444
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
//#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <string>

#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
//#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <time.h>

#include <string>

bool area[100][100];

const int MAX_N = 100050;
int A, B;

int main(int argc, char **argv) {
    std::cin >> A >> B;

    for (int i = 0; i < 100; i++) {
        for (int j = 0; j < 100; j++) {
            area[i][j] = i < 50;
        }
    }
    A--;
    B--;

    for (int i = 99; i >= 51; i = i - 2) {
        for (int j = 0; j <= 98; j = j + 2) {
            if (A > 0) {
                area[i][j] = true;
                A--;
            }
        }
    }

    for (int i = 0; i <= 48; i = i + 2) {
        for (int j = 0; j <= 98; j = j + 2) {
            if (B > 0) {
                area[i][j] = false;
                B--;
            }
        }
    }

    for (int j = 99; j >= 51; j = j - 2) {
        for (int i = 0; i <= 98; i = i + 2) {
            if (A > 0) {
                area[i][j] = true;
                A--;
            }
        }
    }

    std::cout << 100 << " " << 100 << std::endl;
    for (int i = 0; i < 100; i++) {
        for (int j = 0; j < 100; j++) {
            std::cout << (area[i][j] ? '.' : '#');
        }
        std::cout << std::endl;
    }
    
    return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  int ans=0;
  cin>>n;
  for(int i=0;i<n;i++){
    int l,r;
    cin>>l>>r;
    ans+=r-l+1;
  }
  cout<<ans<<endl;
  return(0);
}

Measured memory_bytes: 256
#!/usr/bin/python
# -*- coding: utf-8 -*-

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

if A.count(0) > 0:
    print(0)
    exit()

ans = 1
for i in range(N):
    ans *= A[i]
    if ans > 10**18:
        print(-1)
        exit()

if ans <= 10**18:
    print(ans)


Measured memory_bytes: 87836
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>


using namespace std;


typedef struct _data{
public:string first;
public:int second;
public:int third;
}Data;

bool compare(Data a,Data b);


bool compare(Data a,Data b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second > b.second;
    }
}

int main() {
    int n,i,j;
    cin>>n;
    vector<Data> pairs(n);
    for(i=0;i<n;i++){
        cin>>pairs[i].first>>pairs[i].second;
        pairs[i].third=i+1;
    }
    sort(pairs.begin(),pairs.end(),compare);

    for(Data tmp:pairs){
        cout<< tmp.third << endl;
    }



    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
using Int = int64_t;
int main() {
  Int A, B, N;
  cin >> A >> B >> N;
  auto f = [](Int a, Int b, Int x) {
    return a * x / b - x / b * a;
  };
  cout << f(A, B, min(N, B - 1)) << endl;
}


Measured memory_bytes: 3616
#include <cstdlib>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <numeric>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <stack>

using namespace std;

#define sz(X) ((int)(X).size())
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define all(X) (X).begin(),(X).end()
#define FOR(i, a, n) for(int i=(a), __ ## i=(n); i<__ ## i; i++)
#define REP(I,N) FOR(I,0,N)
#define PR(X) cout<<#X<<" = "<<(X)<<" "
#define PRL cout<<endl
#define PRV(X) {cout<<#X<<" = {";REP(__prv,sz(X)-1)cout<<(X)[__prv]<<",";if(sz(X))cout<<*(X).end();cout<<"}"<<endl;}

template<class T> ostream &operator<<(ostream &os, const vector<T> &vec)
{
	os << '{';
	REP(i, sz(vec))
	{
		os << vec[i];
		if (i + 1 != sz(vec))
			os << ',';
	}
	os << '}';
	return os;
}

template<class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &par)
{
	os << '(' << par.X << ',' << par.Y << ')';
	return os;
}

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<bool> VB;
typedef vector<unsigned long long> VULL;
typedef vector<vector<int>> VVI;
typedef queue<int> QI;

int gcd(int x, int y)
{
	return y ? gcd(y, x % y) : abs(x);
}

template<class T> T sqr(T x)
{
	return x * x;
}

bool alive[400];
bool used[400][400];
PII prs[100000];

int main()
{
	ios::sync_with_stdio(false);

	int N, M;
	cin >> N >> M;

	REP(i, M)
	{
		int a, b;
		cin >> a >> b;
		a--; b--;
		prs[i] = { a, b };
	}
	
	REP(i, N)
	{
		used[i][i] = true;
		alive[i] = true;
		for (int j = M - 1; j >= 0; j--)
		{
			if (used[i][prs[j].first] && used[i][prs[j].second])
			{
				alive[i] = false;
				break;
			}
			if (used[i][prs[j].first] || used[i][prs[j].second])
				used[i][prs[j].first] = used[i][prs[j].second] = true;
		}
	}

	int res = 0;
	REP(i, N)
		if(alive[i])
		FOR(j, i + 1, N)
			if (alive[j])
			{
				res++;
				REP(k, N)
				if (used[i][k] && used[j][k])
				{
					res--;
					break;
				}
			}

	cout << res;

	return 0;
}

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

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

  int result = 0;
  for(int i=0;i<4;i++){
    if(s[i] == '+'){
      result++;
    }else{
      result--;
    }
  }

  cout << result << "\n";
  return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0xccccccc;
const ll LINF = 922337203685477580LL;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

struct UnionFind {
  vector<int> par; // 親を指すvector,-par[親]は木のサイズ
  UnionFind(int n):par(n, -1) {} // uniteで親を埋め込んでいく必要あり
  int root(int x) { // 親をたどる&データの整理
    if(par[x] < 0) return x;
    return par[x] = root(par[x]);
  }
  bool unite(int x, int y) { // データの結合
    x = root(x);
    y = root(y);
    if(x == y) return false;
    if(par[x] > par[y]) swap(x, y);
    par[x] += par[y];
    par[y] = x;
    return true;
  }
  bool same(int x, int y) {return root(x) == root(y);} // 所属判定
  int size(int x) {return -par[root(x)];} // 木のサイズ
};

const int N = 710;

//head

int n, m;
bitset<N> dist[N];
UnionFind uft(N<<1);
vi G[N];
vector<P> info;
bitset<N> check;
vi iin;

inline int cc(int n) {
  return n*(n-1)>>1;
}

void dfs(int i, bool parity, int ui) {
  if(parity) info[ui].first++;
  else info[ui].second++;
  for(int ne:G[i]) if(!check.test(ne)) {
    check.set(ne);
    if(parity) dfs(ne, false, ui);
    else dfs(ne, true, ui);
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    dist[a].set(b);
    dist[b].set(a);
  }
  rep(i, n) rep(j, i) if(!dist[i].test(j)) {
    G[i].emplace_back(j);
    G[j].emplace_back(i);
    uft.unite(i, j+n);
    uft.unite(j, i+n);
    if(uft.same(i, i+n) or uft.same(j, j+n)) {
      cout << -1 << endl;
      return 0;
    }
  }
  rep(i, n) if(!check.test(i)) {
    info.emplace_back(0, 0);
    check.set(i);
    dfs(i, true, info.size()-1);
  }
  rep(i, info.size()) {
    iin.emplace_back(abs(info[i].first-info[i].second));
  }
  m = iin.size();
  vector<bool> dp(n*2+1), dpp(n*2+1);
  vector<bool>::iterator now = dp.begin(), pre = dpp.begin();
  dpp[n] = true;
  rep(i, m) {
    rep(j, n*2+1) {
      now[j] = false;
      if(j >= iin[i] and pre[j-iin[i]]) now[j] = true;
      if(j <= n*2-iin[i] and pre[j+iin[i]]) now[j] = true; 
    }
    swap(now, pre);
  }
  rep(i, n+1) {
    if(pre[n-i] or pre[n+i]) {
      cout << cc((n-i)>>1) + cc(n-((n-i)>>1)) << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 4040
N,K = map(int,input().split())
mod = pow(10,9)+7
ans = 0
D = [0]
for i in range(N+1):
    D.append(D[i]+i)
for k in range(K,N+2):
    ans += (D[N+1]-D[N+1-k]-D[k]+1)%mod
print(ans%mod)

Measured memory_bytes: 19376
#include <iostream>
#include <vector>
#include <unordered_map>
#include <queue>
#include <climits>
#include <algorithm>
typedef long long ll;
typedef long double ld;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define INF INT_MAX
#define fi first
#define sec second
#define pii pair<ll,ll> 
#define vi vector< ll > 
#define vvi vector< vi > 
#define vpi vector< pii > 
#define vvpi vector< vpi > 
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define test(t) ll t;cin>>t;while(t--){solve();}
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
#define fr(i,n) for(ll i=0;i<(n);++i)
#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define per(i,a,b) for(ll i=a;i>=b;i--)
#define remin(a,b) (a=min((a),(b)))
#define remax(a,b) (a=max((a),(b)))
#define pq_max priority_queue<ll>
#define pq_min priority_queue<ll,vector<ll>,greater<ll>>
using namespace std;




int main() {
	// your code goes here
	fast;
     string s;
     cin>>s;
     if(s[s.size()-1]=='s')
     {
         cout<<s<<"es"<<endl;
     }
     else
     {
         cout<<s<<"s"<<endl;
     }
	return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
# define ll int64_t
# define str string
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define PI 3.141592653589793
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;



#define INF 2000000000
#define MAX_V 10



bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<ll,ll> a,pair<ll,ll> b){
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

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

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

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

ll lcm(ll a,ll b){
   return a/gcd(a,b)*b;
}
const ll MAX = 5100000;
const ll MOD = 1000000007;
 
ll fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

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

using graph = vector<vector<ll>>;
pair<pair<ll,ll>,ll> p[100010];



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n;
    cin>>n;
    vector<long double> a(n);
    rep(i,n) cin>>a[i];
    sort(ALL(a));
    
    if(a[0]==0){
        cout<<0<<endl;
        return 0;
    }
    long double sum=1;
    rep(i,n) {
        sum*=a[i];
        if(sum>1e18){
            cout<<-1<<endl;
            return 0;
        }
    }
    cout<<fixed<<setprecision(0)<<sum<<endl;
    return 0;
}


Measured memory_bytes: 4740
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    string S, T;
    scan(S, T);
    writeln(T, S);
}


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

using namespace std;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15);
  }
} initializer;

int main() {
  int r, g, b;
  cin >> r >> g >> b;
  cout << ((g * 10 + b) % 4 == 0 ? "YES" : "NO") << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll linf = 1e18;
const db EPS = 1e-7;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

int N;
int A[1010][1010];
vector<int> G[1000010];
bool used[1000010];
bool ap[1000010];
bool flag;
int ans = -1;
int in[1000010];
int path[1000010];

int exchange(int a, int b){
    int mx = max(a, b);
    int mn = min(a, b);
    return mx * N + mn;
}

void dfs(int v){

    if(used[v]){
        flag = true;
        return;
    }
    if(path[v] != 0) return;
    
    used[v] = true;
    path[v] = 1;
    for(auto u : G[v]){
        dfs(u);
        chmax(path[v], path[u] + 1);
    }
    used[v] = false;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N;
    for(int i = 0; i < N; ++i){
        for(int j = 1; j < N; ++j){
            cin >> A[i][j];
            A[i][j]--;
            ap[exchange(i, A[i][j])] = true;
        }
    }
    for(int i = 0; i < N; ++i){
        for(int j = 1; j + 1 < N; ++j){
            G[exchange(i, A[i][j])].push_back(exchange(i, A[i][j + 1]));
            in[exchange(i, A[i][j + 1])]++;
        }
    }
    for(int i = 0; i < N * N; i++){
        if(in[i] == 0 && ap[i]) dfs(i), chmax(ans, path[i]);
    }
    cout << (flag ? -1 : ans) << endl;
    return 0;
}


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

#define debug(x) (cerr << #x << " = " << x << endl;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c)

const int INF = 0x3F3F3F3F; 
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const double EPS = 1e-10;

inline int cmp(double x, double y = 0) 
{  
  if(fabs(x - y) < EPS)
    return 0;
  return x > y ? 1 : -1;
}

const int maxn = 2e5 + 100;

int h[maxn];
vector<int>graph[maxn];

int main()
{
  ios::sync_with_stdio(0);
  int n,m;

  cin >> n >> m;
  for(int i = 1; i <= n ; i++)
  {
    cin >> h[i];
  }

  
  for(int i = 1; i <= m ; i++)
  {
    int u,v;
    cin >> u >> v;
    graph[u].push_back(v);
    graph[v].push_back(u);
  }
  int ans = 0;
  
  for(int i = 1; i <= n ; i++)
  {
    bool isGood = true;
    for(const auto &v : graph[i])
    {
      isGood &= h[i] > h[v];
    }
    ans += isGood;
  }

  cout << ans << endl;

  return 0;
}

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

struct node {
	struct node *r;
	struct node *l;
	struct node *p;
	int key;
};
typedef struct node * Node;

#define NIL NULL

Node root;

Node searchTree(Node x,int key) {
	if (x == NIL || key == x->key) return x;
	if (key < x->key) {
		return searchTree(x->l, key);
	}
	else {
		return searchTree(x->r, key);
	}
}

void insert(int k) {
	Node y = NIL;
	Node x = root;
	Node z;

	z = malloc(sizeof(struct node));
	z->key = k;
	z->l = NIL;
	z->r = NIL;

	while (x != NIL) {
		y = x;
		if (z->key < x->key) x = x->l;
		else x = x->r;
	}

	z->p = y;
	if (y == NIL) root = z;
	else if (z->key < y->key) y->l = z;
	else y->r = z;

	return;
}

void inorder(Node x) {
	if (x == NIL) return;
	inorder(x->l);
	printf(" %d",x->key);
	inorder(x->r);
	return;
}

void preorder(Node x) {
	if (x == NIL) return;
	printf(" %d",x->key);
	preorder(x->l);
	preorder(x->r);
	return;
}

int main() {
	int i,n, key;
	char s[10];

	scanf("%d", &n);

	for (i = 0;i < n;i++) {
		scanf("%s", s);
		if (s[0] == 'i') {
			scanf("%d", &key);
			insert(key);
		} else if (s[0] == 'f'){
			scanf("%d", &key);
			if (searchTree(root, key) != NIL) printf("yes\n");
			else printf("no\n");
		} else {
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
	}


	return 0;
}

Measured memory_bytes: 19364
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  int t;
  cin>>s;
  t=s.size();
  for(int i=0;i<t;i++)
  {
    s[i]='x';
  }
  cout<<s<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>
#include <stack>

using ll = long long;
typedef unsigned long long ull;
typedef std::pair<int, int>p;

ll min(ll a, ll b) {
	if (a >= b)return b;
	else return a;
}
ll max(ll a, ll b) {
	if (a >= b)return a;
	else return b;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

const ll Z = 1000000007;
const ll INF = 1 << 30;
const ll INF2 = 9000000000000000000LL;
bool flag = true;
bool fl = false;
bool f = false;
bool used[210];
bool graph[100][100];
bool visited[8];
int abc[26] = { 0 };

int main() {
	int n, a[100], al = 0, bo = 0;
	std::cin >> n;
	for (int i = 0;i < n;i++) {
		std::cin >> a[i];
	}
	std::sort(a, a + n);
	for (int i = n - 1;i >= 0;i--) {
		al += a[i];
		i--;
		if (i == -1)break;
		bo += a[i];
		if (i == -1)break;
	}
	std::cout << abs(al - bo) << std::endl;
}

Measured memory_bytes: 256
import java.lang.reflect.Array;
import java.util.*;
public class Main {
	public static void main(String[] args){
		moduloSummation();
	}
	
	public static void moduloSummation() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i=0; i<n; i++) {
			a[i] = sc.nextInt();
		}
		int res = 0;
		for (int i=0; i<a.length; i++) {
			res += a[i] - 1;
		}
		System.out.println(res);
	}
}

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n),b(n+1); 
    for(int i=0;i<n-1;i++){
        cin >> b.at(i+1);
    }
    b.at(0) = b.at(1);
    b.at(n) = b.at(n-1);    
    int ans=0;
    for(int i=1;i<n+1;i++){
        ans += min(b.at(i),b.at(i-1));
    }
    cout << ans << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair< int , int > Pi;

bool judge(int area){
  //式変形だね!!
  //area - y = (2y + 1)x
  //(area - y) % (2y + 1)
  //適当に80000でどう？
  for(int y = 1; y < min< int >(80000, area); y++){ 
    if((area - y) % (2 * y + 1) == 0) return true;
  }
  return false;
}

int main(){
  int N, room[100000];

  scanf("%d", &N);
  for(int i = 0; i < N; i++){
    scanf("%d", &room[i]);
  }
  int ret = 0;
  for(int i = 0; i < N; i++){
    ret += !judge(room[i]);
  }
  printf("%d\n", ret);
}

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

int main(void)
{
	char A[1024];
	int a, b;
	scanf("%d %d", &a, &b);
	if (a * 500 >= b)
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}

	return 0;
}

Measured memory_bytes: 128
#include<iostream>

using namespace std;

void dfs(int n,int s,int k);

int ans=0;

int main(){
	int n,sum;
	while(cin>>n>>sum , n||sum){
		ans=0;
		dfs(n,sum,0);
		cout<<ans<<endl;
	}
}

void dfs(int n,int sum,int k){
	if(n<0){
		return ;
	}
	if(n==0){
		if(sum==0){
			ans++;
		}
	}
	else{
		if(9<k){
			return ;
		}
		for(int i=k;i<=9;i++){
			dfs(n-1,sum-i,i+1);
		}
	}
}

Measured memory_bytes: 1160
N, K = map(int,input().split())
v = list(map(int,input().split()))
ans = [0]
for i in range(1,min(K,N)+1):
    for a in range(i+1):
        b = i-a
        if b == 0:
           get = v[:a]
        else:
            get = v[:a]+v[-b:]
        get.sort()
        for j in range(min(K-i,len(get))):
            p = get.pop(0)
            if p >= 0:
                A = p + sum(get)
                break
        else:
            A = sum(get+[0])
        ans.append(A)
print(max(ans))

Measured memory_bytes: 3064
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    a,b=input().split()
    n=int(a+b)
    for base in range(1,400):
        if base**2==n:
            print("Yes")
            exit()
    print("No")

main()

Measured memory_bytes: 3060