akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <map>
using namespace std;

long long D, G, p[100009], x[100009], minx = (1LL << 60);

int main() {
	cin >> D >> G;
	for (int i = 1; i <= D; i++) cin >> p[i] >> x[i];

	for (int i = 0; i < (1 << D); i++) {
		int bit[11]; for (int j = 0; j < D; j++) bit[j + 1] = (i / (1 << j)) % 2;

		vector<int>vec; long long rem = G, ret = 0;
		for (int j = 1; j <= D; j++) {
			if (bit[j] == 1) { rem -= x[j]; rem -= p[j] * (100LL * j); ret += p[j]; }
			else {
				for (int k = 0; k < p[j]; k++) vec.push_back(100 * j);
			}
		}
		sort(vec.begin(), vec.end());
		reverse(vec.begin(), vec.end());

		for (int j = 0; j < vec.size(); j++) {
			if (rem > 0) { rem -= vec[j]; ret++; }
		}
		minx = min(minx, ret);
	}
	cout << minx << endl;
	return 0;
}

Measured memory_bytes: 256
/***
**   AUTHOR::ASHUTOSH MOUDGIL
***/


#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#define F first
#define S second
#define int long long
//#define ll long long
#define all(x) x.begin(),x.end()
#define rsort(x) sort(all(x)); reverse(all(x));
#define endl '\n'
#define vi vector<int>
#define vlli vector<long long>
#define pii pair<int,int>
#define mod 1000000007
#define LMAX 1e18
#define deb(x) cout<<#x<<" : "<<x<<endl;
#define PI 3.141592654
#define deb1(x) cout << #x <<"="<< x <<endl;
#define deb2(x,y) cout << #x <<"="<<x<<", "<<#y<<"="<<y <<endl;
#define deb3(x,y,z) cout << #x <<"="<<x<<", "<<#y<<"="<<y <<", "<<#z<<"="<<z<<endl;
#define deb4(x,y,z,a) cout << #x <<"="<<x<<", "<<#y<<"="<<y <<", "<<#z<<"="<<z<< ", "<<#a <<"="<<a << endl;
#define debarr(x) cout << #x<<endl;for(int i : x){cout << i <<" ";} cout <<endl;

const int N = 3e3;
double dp[N][N];
int n;
double pi;
vector<double> arr;

void mymain(){
  cin >> n;
  for(int i=0;i<n;i++){
    double d;
    cin >> d;
    arr.pb(d);
  }
  dp[0][1] = 1.0 - arr[0];
  dp[1][0] = arr[0];

  for(int i=2;i<=n;i++){
    for(int j=0;j<=i;j++){
        if(i-j>=1)
            dp[i-j][j] += dp[i-j-1][j]*arr[i-1];
        if(j>=1){
            dp[i-j][j] += dp[i-j][j-1]*(1.0-arr[i-1]);
        }
    }

  }
    double ans = 0;
    for(int i=n;i>n/2;i--){
        ans += dp[i][n-i];
    }


    cout << fixed << setprecision(10)<<ans << endl;

}

signed main(){
IOS;
///freopen("input.txt", "r", stdin);
///freopen("output.txt", "w", stdout);
int t=1;
//cin>>t;

for(int tt=0;tt<t;tt++){
   ///cout << "Case #" << tt+1 <<": ";
   mymain();
   }
return 0;
}
/*

*/


Measured memory_bytes: 70016
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  string s; cin >> s;
  int n=s.size();
  int l=0,r=n-1;
  int ans=0;
  while(l<=r){
    if(s[l]==s[r]){
      l++; r--;
    }
    else if(s[l]=='x'){
      l++;
      ans++;
    }
    else if(s[r]=='x'){
      r--;
      ans++;
    }
    else{
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;
}

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

dif_colors = [0]*3
patterns = []

for i in range(N):
    cnt = 0
    tmp_color = -1
    for j in range(3):
        if dif_colors[j] == A[i]:
            cnt += 1
            tmp_color = j
    dif_colors[tmp_color] += 1
    patterns.append(cnt)

ans = 1
for pattern in patterns:
    ans *= pattern
    ans %= 1000000007

print(ans)


Measured memory_bytes: 14056
#C
# -*- coding: utf-8 -*-


def serchBup(list,n):
    if n in list:
        return 1+serchBup(list,n+1)
    else:
        return 1
        
    
def serchBdown(list,n):
    if n in list:
        return -1+serchBdown(list,n-1)
    else:
        return -1

x,n = map(int, input().split())

if n == 0:
    print(x)
else:
    p = list(map(int, input().split()))
    p.sort()
    min = 1000000000
    ans =0

    for i in range(n):
        if abs(x-p[i])<min:
            min  = abs(x-p[i])
            ans = p[i]
            pos=i
    
    if ans in p:
        #print("True")
        tmp1=serchBup(p,ans+1)
        tmp2=serchBdown(p,ans-1)
        #print(tmp1,tmp2)
        if abs(tmp1) < abs(tmp2):
            print(ans+tmp1)
        else:
            print(ans+tmp2)
        
    else:
        print("Fasle")
        print(ans)

Measured memory_bytes: 9248
#include<iostream>
#include<map>
#include<queue>
#include<string.h>

using namespace std;

typedef pair<int,int> P;
queue<P> q;
int sx,sy;
int gx,gy;
int g;
char field[1000][1000];
int d[1000][1000];
int H,W,N;
int hp=1;
int ans=0;

int bfs(){
	memset(d,-1,sizeof(d));
	P p;
	q.push(P(sx,sy));
	d[sx][sy]=0;
	while(q.size()){
		if(q.front().first==gx&&q.front().second==gy) break;
		p=q.front();
		q.pop();
		for(int i=-1;i<=1;i++){
			for(int j=-1;j<=1;j++){
				if((i==0||j==0)&&(i!=0||j!=0)){
					if(p.first+i>=0&&p.first+i<=H-1&&p.second+j>=0&&p.second+j<=W-1&&d[p.first+i][p.second+j]<0){
						if(field[p.first+i][p.second+j]!='X'){
							q.push(P(p.first+i,p.second+j));
							d[p.first+i][p.second+j]=d[p.first][p.second]+1;
						}
					}
				}
			}
		}
		
	}
	return d[gx][gy];
}
int main(){
	cin>>H>>W>>N;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			cin>>field[i][j];
		}
	}
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(field[i][j]=='S')
			{
				sx=i;
				sy=j;
			}
			if(field[i][j]==49)
			{
				gx=i;
				gy=j;
			}
		}
	}
	ans+=bfs();
	for(int i=0;i<N-1;i++){
		for(int j=0;j<H;j++){
			for(int k=0;k<W;k++){
				if(field[j][k]==49+i)
				{
					sx=j;
					sy=k;
				}
				if(field[j][k]==50+i)
				{
					gx=j;
					gy=k;
				}
			}
		}
		while(q.size()){
			q.pop();
		}
		memset(d,-1,sizeof(d));
		ans+=bfs();
	}

	cout<<ans<<endl;
}

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

typedef long long ll;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

ll n, a, x[50] = {}, dp[51][51][2501] = {};

int main() {
  cin >> n >> a;
  rep(i, 0, n) cin >> x[i];
  dp[0][0][0] = 1;

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

  ll ans = 0;

  rep(i, 1, n + 1) {
    ans += dp[n][i][i * a];
  }

  cout << ans << endl;
}


Measured memory_bytes: 50048
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <iostream>
#include <numeric>
#define rep(i,n) for (int i = 0;i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
int INF = 1e9;


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


Measured memory_bytes: 3760
#!/usr/bin/env python3
import sys


def solve(N: int, a: "List[int]", b: "List[int]", c: "List[int]"):
    dp = [[0] * 3 for _ in range(N)]
    dp[0][0] = a[0]
    dp[0][1] = b[0]
    dp[0][2] = c[0]

    for i in range(1, N):
        dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a[i]
        dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + b[i]
        dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c[i]

    print(max(dp[-1]))


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int()] * (N)  # type: "List[int]"
    b = [int()] * (N)  # type: "List[int]"
    c = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
        c[i] = int(next(tokens))
    solve(N, a, b, c)


if __name__ == '__main__':
    main()


Measured memory_bytes: 58332
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	a, err := strconv.Atoi(sc.Text())
	if err != nil {
		fmt.Println(err)
	}
	return a
}

func scanInt2() (int, int) {
	return scanInt(), scanInt()
}

func pow100(a int) int {
	return int(math.Pow(100, float64(a)))
}

func main() {
	sc.Split(bufio.ScanWords)
	a, b := scanInt2()
	ans := pow100(a) * b
	if ans == pow100(a+1) {
		ans += pow100(a)
	}
	fmt.Println(ans)
}


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

typedef long long int ll;
ll powk(ll a, ll n){
    ll r = 1;
    for(ll i = 0;i < n;i++){
        r *= a;
    }

    return r;
}

int main()
{
    ll n;
    cin >> n;
    vector<ll> p(n), q(n);
    for(ll i = 0;i < n;i++){
        cin >> p[i];
    }
    for(ll i = 0;i < n;i++){
        cin >> q[i];
    }
    ll pc = 0, qc = 0;
    do{
        pc++;
    }while(next_permutation(p.begin(),p.end()));
    do{
        qc++;
    }while(next_permutation(q.begin(),q.end()));

    cout << abs(pc - qc);

    return 0;
}

Measured memory_bytes: 256
#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>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
class Solve {
public:
    void solve() {
        Int N;
        cin >> N;
        vector<Int> a(N);
        for (int i = 0; i < N; ++i) {
            cin >> a[i];
        }

        Int ans = 0;
        for (int i = 0; i < N; ++i) {
            for (int j = i + 1; j < N; ++j) {
                ans += a[i] * a[j];
            }
        }
        cout << ans << endl;
    }
};


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

    Solve().solve();


    return 0;
}


Measured memory_bytes: 888
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
using namespace std;
#define LL long long 
#define LD long double
char p[305];
int ans;
int main()
{
	cin>>p+1;
	int n=strlen(p+1);
	for(int i=1;i<=n/2;i++)
		if(p[i]!=p[n-i+1])ans++;
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


template<typename T>
vector<T> compress(vector<T> v){
  sort(v.begin(),v.end());
  v.erase(unique(v.begin(),v.end()),v.end());
  return v;
}

template<typename T>
map<T, Int> dict(const vector<T> &v){
  map<T, Int> res;
  for(Int i=0;i<(Int)v.size();i++)
    res[v[i]]=i;
  return res;
}


template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> x(n);
  for(Int i=0;i<n;i++) cin>>x[i];
  vector<vector<Int> > G(n);
  for(Int i=0;i<n;i++){
    Int k;
    cin>>k;
    while(k--){
      Int t;
      cin>>t;
      t--;
      G[i].emplace_back(t);
    }
  }
  vector<Int> vx;
  for(Int i=0;i<n;i++){
    vx.emplace_back(-x[i]);
    vx.emplace_back(+x[i]);
  }
  vx.emplace_back(-2e5);
  vx.emplace_back(+2e5);
  vx=compress(vx);
  auto mx=dict(vx);

  auto val=make_v<Int>(n,mx.size(),mx.size());
  auto dp1=make_v<Int>(n,mx.size(),mx.size());
  auto dp2=make_v<Int>(n,mx.size(),mx.size());
  fill_v(dp1,-1);
  fill_v(dp2,-1);
  function<Int(Int, Int, Int)> dfs=
    [&](Int v,Int a,Int b)->Int{
      Int &res=val[v][a][b];
      Int &t1=dp1[v][a][b],&t2=dp2[v][a][b];
      if(~t1) return res;
      if(G[v].empty()){
        t1=t2=1;
        return val[v][a][b]=x[v];
      }
      t1=n+1;t2=-1;
      sort(G[v].begin(),G[v].end());
      do{
        Int c=a,d=b,s1=0,s2=0,flg=0;
        for(Int u:G[v]){
          Int w=mx[-dfs(u,mx[-vx[d]],mx[-vx[c]])];
          s1+=dp1[u][mx[-vx[d]]][mx[-vx[c]]];
          s2+=dp2[u][mx[-vx[d]]][mx[-vx[c]]];
          if(w>=d){
            res=vx[w];
            flg=1;
            break;
          }else if(w>c){
            c=w;
          }
        }
        chmin(t1,s1);
        chmax(t2,s2);
        if(!flg) res=vx[c];       
      }while(next_permutation(G[v].begin(),G[v].end()));
      return res;
    };  
  dfs(0,0,mx.size()-1);
  cout<<dp1[0][0][mx.size()-1]<<" "<<dp2[0][0][mx.size()-1]<<endl;  
  return 0;
}



Measured memory_bytes: 66860
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let a: i32 = sc.read();
    let b: i32 = sc.read();
    let c: i32 = sc.read();
    let d: i32 = sc.read();
    let d1 = (a - b).abs();
    let d2 = (b - c).abs();
    let d3 = (a - c).abs();
    if d1 <= d && d2 <= d || d3 <= d {
        println!("Yes");
        return ;
    }
    println!("No");
}

//snippet from kenkoooo
pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

struct disjoint_set{
	vector<int> p;
	disjoint_set(int n): p(n, -1){ }
	bool share(int a, int b){ return root(a) == root(b); }
	int sz(int u){ return -p[root(u)]; }
	int root(int u){ return p[u] < 0 ? u : p[u] = root(p[u]); } // O(alpha(n))
	bool merge(int u, int v){
		u = root(u), v = root(v);
		if(u == v) return false;
		if(p[u] > p[v]) swap(u, v);
		p[u] += p[v], p[v] = u;
		return true;
	}
};

int main(){
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(ios::badbit | ios::failbit);
	int n, m;
	cin >> n >> m;
	disjoint_set dsu(n);
	for(auto rep = 0; rep < m; ++ rep){
		int u, v;
		cin >> u >> v, -- u, -- v;
		dsu.merge(u, v);
	}
	vector<int> flag(n);
	for(auto u = 0; u < n; ++ u){
		flag[dsu.root(u)] = true;
	}
	cout << accumulate(flag.begin(), flag.end(), 0) - 1 << "\n";
	return 0;
}

/*

*/

////////////////////////////////////////////////////////////////////////////////////////
//                                                                                    //
//                                   Coded by Aeren                                   //
//                                                                                    //
////////////////////////////////////////////////////////////////////////////////////////

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

using namespace std;

int main()
{
    long long N,S=0;
    cin>>N;
    vector<long long> A(N),ans(N,0);
    for(long long i=0;i<N;++i){
        cin>>A[i];
        S+=A[i];
    }

    for(long long i=0;i<N;++i)
        if(i==0){
            ans[i]=S;
            for(long long j=1;j<N-1;j+=2)
                ans[i] -= 2*A[j];
        }
        else
            ans[i] = 2*A[i-1]-ans[i-1];
    
    for(long long i=0;i<N;++i){
        if(0<i)
		    cout<<" ";
        cout<<ans[i];
    }
}

Measured memory_bytes: 2944
import numpy as np
inputs = open(0).readlines()
class Grid():
    def __init__(self, grid, w=0, h=0, function=lambda x: x):
        self.w = w = w if w else len(grid[0])
        self.h = h = h if h else len(grid)
        dtype = type(function(grid[0][0]))
        self.grid = np.empty((h, w), dtype=dtype)
        for i, row in zip(range(h), grid):
            for j, val in zip(range(w), row):
                self.grid[i][j] = function(val)
    
    def is_valid_x(self, x):
        return 0 <= x < self.w
    def is_valid_y(self, y):
        return 0 <= y < self.h
    def is_valid_xy(self, x, y):
        return self.is_valid_x(x) and self.is_valid_y(y) 
    
    def __iter__(self):
        return iter(self.grid)
    def __repr__(self):
        return '\n'.join([' '.join(map(str, row)) for row in self.grid])
    def __getitem__(self, x):
        return self.grid[x]
    def __setitem__(self, x, val):
        self.grid[x] = val

h, w = map(int, inputs[0].split())
*A, = map(int, inputs[2].split())
grid = Grid(np.zeros((h, w), dtype=np.int))

x = y = 0
for i, a in enumerate(A, 1):
    for j in range(a):
        grid[y, x] = i
        if y % 2 == 0:
            if x == w-1:
                y += 1
            else:
                x += 1
        else:
            if x == 0:
                y += 1
            else:
                x -= 1
print(grid)

Measured memory_bytes: 12320
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << "\n"; }
template <class T, class... Args>
void debug_out(const T &x, const Args &... args) { cout << x << " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

ll n,k;
vector<int> visited;

int dfs_sub(int i, ll cnt, ll x, const vector<int> &G) { //x回移動
  if (cnt == x) return i;
  int to = G[i];
  return dfs_sub(to, cnt+1, x, G);
}

int dfs(int i, ll cnt, const vector<int> &G) {
  if (cnt == k) return i;
  int to = G[i];
  if (visited[to] == -1) {
    visited[to] = cnt+1;
    return dfs(to, cnt+1, G);
  } 
  else { //loop
    ll span = cnt+1 - visited[to];
    k -= visited[to];
    ll res = k % span;
    return dfs_sub(to, 0, res, G);
  }
}


int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  cin >> n >> k;
  vector<int> G(n);
  rep(i,n) {
    cin >> G[i];
    G[i]--;
  }
  visited = vector<int>(n,-1);
  visited[0] = 0;
  int ans = dfs(0, 0, G);
  cout << ans+1 << endl;
  return 0;
}

Measured memory_bytes: 4792
n,m=list(map(int,input().split()))
h=list(map(int,input().split()))
dp=[float("INF") for i in range(n)]
for i in range(m):
  a,b=list(map(int,input().split()))
  if h[a-1]<h[b-1]:
    dp[a-1]=0
  elif h[b-1]<h[a-1]:
    dp[b-1]=0
  else:
    dp[a-1]=0
    dp[b-1]=0
sum=0
for i in range(n):
  if dp[i]==float("INF"):
    sum=sum+1
print(sum)
  
  

Measured memory_bytes: 20052
import java.util.Scanner;
public class Main {
    public static void main(String args[]) {
    Scanner obj = new Scanner(System.in);   
    int n=obj.nextInt();
    int m=n%10;
    if(m==2||m==4||m==5||m==7||m==9)
    {
        System.out.print("hon");
    }
    else if(m==0||m==1||m==6||m==8)
    {
        System.out.print("pon");
    }
    else
    {
        System.out.print("bon");
    }
}
}

Measured memory_bytes: 35700
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    
    vector<vector<int> >tri;
  
    int c,d,e;
    cin>>c;
    for(int i=0;i<c;i++)
    {     
        vector<int>sumit;
        for(int j=0;j<3;j++){
        cin>>e;
        sumit.push_back(e);
        }
        sort(sumit.begin(),sumit.end());
        tri.push_back(sumit);
        
    }
    sort(tri.begin(),tri.end());
    
    d = 0;
    for(int i=0;i<c-1;i++)
    {
        if(tri[i]==tri[i+1])
        d++;
    }
    cout<<d<<endl;
    
    
    
}



Measured memory_bytes: 3244
x, n = map(int, input().split())
if n ==0:
    print(x)
    
else:
    p = list(map(int, input().split()))
    p.sort()
    #print(p)
    ans = 1000
    xx = 0
    for i in range(102):
        if not i in p:
            if x-i>=0 and ans>x-i:
                ans = x-i
                xx = i
            elif i-x>0 and ans>i-x:
                ans = i-x
                xx = i
    print(xx)

Measured memory_bytes: 61876
use proconio::input;
use fixedbitset::FixedBitSet;

struct Solve {
    n: usize,
    m: usize,
    x: usize,
    c: Vec<usize>,
    a: Vec<Vec<usize>>,
}

impl Solve {
    fn new() -> Self {
        input! {
            n: usize, m: usize, x: usize,
            ca: [[usize; m+1]; n],
        }

        let mut c = Vec::with_capacity(n);
        let mut a = Vec::with_capacity(n);

        for i in 0..n {
            c.push(ca[i][0]);
            a.push(ca[i][1..m+1].to_owned());
        }

        Self { n, m, x, c, a }
    }

    fn check(&self, flag: &FixedBitSet) -> isize {
        let mut check = vec![0; self.m];
        let mut cost = 0;
        for i in 0..self.n {
            if flag[i] {
                cost += self.c[i];
                for j in 0..self.m {
                    check[j] += self.a[i][j];
                }
            }
        }
        for x in check {
            if x < self.x {
                return -1;
            }
        }
        cost as isize
    }

    fn dfs(&self, mut flag: FixedBitSet, bit: usize, enabled: bool) -> isize {
        if bit == self.n {
            return self.check(&flag);
        }

        flag.set(bit, enabled);

        let a = self.dfs(flag.clone(), bit+1, true);
        let b = self.dfs(flag.clone(), bit+1, false);

        if a == -1 && b == -1 {
            -1
        } else if a == -1 {
            b
        } else if b == -1 {
            a
        } else {
            a.min(b)
        }
    }

    fn solve(&self) -> isize {
        let flag = FixedBitSet::with_capacity(self.n);
        let a = self.dfs(flag.clone(), 0, true);
        let b = self.dfs(flag.clone(), 0, false);

        if a == -1 && b == -1 {
            -1
        } else if a == -1 {
            b
        } else if b == -1 {
            a
        } else {
            a.min(b)
        }
    }
}

fn main() {
    println!("{}", Solve::new().solve());
}


Measured memory_bytes: 2164
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<ll,ll>
#define poly vector<ll>
#define mem(a) memset((a),0,sizeof(a))
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int)(x.size()))
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
ll rnd(){
	ull ans=0;
	For(i,0,4)ans=ans<<15^rand();
	return ans%((ull)1<<63);
}
int main(){
	#ifdef Brollan
		freopen("1.in","r",stdin);
	#endif
	int ans=0;
	For(i,0,1){
		int t=read();
		ans+=max(4-t,0);
	}
	if(ans==6)ans=10;
	cout<<ans*100000<<endl;
}


Measured memory_bytes: 3604
#include <iostream>
using namespace std;
int main(void){
    int x,a,b;
    cin>>x>>a>>b;
    if(a>=b)cout<<"delicious"<<endl;
    else if(b-a<=x)cout<<"safe"<<endl;
    else{
        cout<<"dangerous"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cstdio>
#define F(i,n) for(int i=0;i<(int)(n);i++)
#define INF 100000000
#define ll long long

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

int prime[1000010];
bool is_prime[1000010];

void sieve(int n) {
	int p = 0;
	for (int i = 0; i <= n; i++) is_prime[i] = true;
	is_prime[0] = is_prime[1] = false;
	for (int i = 2; i <= n; i++) {
		if (is_prime[i]) {
			prime[p++] = i;
			for (int j = 2 * i; j <= n; j += i) {
				is_prime[j] = false;
			}
		}
	}
}
int main() {
	ll  b[10000],x,a1[50],a2[50],r;
	int y,q,counter;
	sieve(200000);
	while (1) {
		cin >> x >> y;
		
		if (x == -1 && y == -1)break;
		for (int i = 0; i < 50; i++) {
			a1[i] = 0;
			a2[i] = 0;
		}
		for (int i = 0; i < 10000; i++) {
			b[i] = INF;
		}
		r = 0;
		for (int i = 0;; i++) {
			if (r >= 50)break;
			if (prime[i] > x) {
				a1[r] = prime[i];
				a2[r] = prime[i];
				r++;
			}
		}
		r = 0;
		for (int i = 0; i < 50; i++) {
			for (int j = i; j < 50; j++) {
				b[r] = a1[i] + a2[j];
				r++;
			}
		}
		sort(b, b+10000);
		
		cout << b[y-1] << endl;
	}
	return 0;
}

Measured memory_bytes: 3504
n = int(input())
a = list(map(int, input().split()))
s = [0]
for i in range(n):
    s.append(s[len(s) - 1] + a[i])
d = {}
for x in s:
    try:
        d[x] += 1
    except:
        d[x] = 1
ans = 0

import math


def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


for v in d.values():
    if v >= 2:
        ans += comb(v, 2)
print(ans)


Measured memory_bytes: 41088
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  cin>>n;
  int arr[n];
  
  for(int i=0;i<n;i++)
  {
		cin>>arr[i];
  }
  
  int sum=0;
  int sumsq= 0;
  for(int i=0;i<n;i++)
  {
    sum=sum+arr[i];
    sumsq=sumsq + (arr[i]*arr[i]);
  }
  
  int sq=sum*sum;
  
  int ans= (sq - sumsq);
  ans= ans*0.5;
  
 cout<<ans<<endl;
}  


Measured memory_bytes: 256
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}


const int N = 1e5 + 10;
char s[N];
int ne[N][2] , dep[N] , rt , _;
int n;
ll L;

int main(){
  scanf("%d%lld",&n,&L);
  rt = ++_;
  rep(i,0,n) {
    scanf("%s",s);
    int len = strlen(s);
    int c = rt;
    rep(i,0,len) {
      int ch = s[i] - '0';
      if(!ne[c][ch]) {
        int t = ne[c][ch] = ++_;
        dep[t] = dep[c] + 1;
      }
      c = ne[c][ch];
    }
  }
  ll sg = 0;
  rep(i,1,_+1) rep(j,0,2) if(!ne[i][j]){
    ll t = L - dep[i];
    sg ^= t & -t;
  }
  puts(sg ? "Alice" : "Bob");
  return 0;
}


Measured memory_bytes: 1536
#include <iostream> 
#include <vector>
#include <string>
#include <math.h>
#include <stack>
#include <fstream>
using namespace std;
#define ll long long int

int main( int argc, char *argv[] ) {
  int n,ans = 0;
  cin >> n;
  for ( int i = 0; i < n; i++ ) {
    int a;cin >> a;
    ans += a;
  }
  cout << ans - n<< endl;
  return 0;
}


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

typedef long long int ll;

int main(){
  ll n,m;
  cin>>n>>m;
  ll ans=n*(n-1)/2;
  ans+=(m*(m-1))/2;
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  int n;
  cin >> n;
  vi a(n);
  REP(i, n) { cin >> a[i]; }
  sort(ALL(a));
  int cur = a[0];
  int c = 1;
  int ans = 0;
  FOR(i, 1, n) {
    if (cur != a[i]) {
      if (c < cur) {
        ans += c;
      } else if (c > cur) {
        ans += c - cur;
      }
      cur = a[i];
      c = 1;
    } else {
      c++;
    }
  }
  if (c < cur) {
    ans += c;
  } else if (c > cur) {
    ans += c - cur;
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;

  if (a+b < c+d) {
    cout << "Right" << endl;
  }
  else if (a+b > c+d) {
    cout << "Left" << endl;
  }
  else {
  cout << "Balanced" << endl;
  }
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int x;
    cin >> x;
    if (x < 1200) {
        cout << "ABC" << endl;
    } else {
        cout << "ARC" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define vpii vector< pair<int,int> >
#define mii map<int,int>
#define MOD 1000000007
#define fr(i,k,n) for(int i=k;i<n;i++)
#define fl(i,k,n) for(int i=k;i>=n;i--)
using namespace std;
typedef long long ll;
int prime[100001]={};
void sieve()
{
	prime[0]=1;
	prime[1]=1;
	for(int i=0;i*i<100001;i++)
	{
		if(prime[i]==0)
		{
			for(int j=i*i;j<100001;j+=i)
			{
				prime[j]=1;
			}
		}
	}
}
ll binpow(ll a,ll b,ll m)
{
	ll res=1;
	while(b>0)
	{

	if(b&1)
	{
		res=res*a%m;
	}
	a=a*a%m;
	b>>=1;
   }
   return res;
}
void solve()
{
	int n,k;
	cin>>n>>k;
	mii m;
	for(int i=0;i<k;i++)
	{
		int d;
		cin>>d;
		for(int i=0;i<d;i++)
		{
			int x;
			cin>>x;
			m[x]++;
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		if(m[i]==0)
		ans++;
	}
	cout<<ans<<endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t=1;
//cin>>t;
while(t--)
{
solve();
}

return 0;
}




Measured memory_bytes: 3660
import java.util.Arrays;
import java.util.Scanner;

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

        Scanner sc = new Scanner(System.in);

        int num = Integer.parseInt(sc.nextLine());
        String[] cards = sc.nextLine().split(" ");

        showBubbleSortResult(cards);
        showSelectionSortResult(cards);
    }

    public static void showBubbleSortResult(String[] arrayOrg) {
        String[] array = arrayOrg.clone();

        for (int i=0; i<array.length; i++) {
            for (int j=array.length-1; j>i; j--) {
                int leftNum = Integer.parseInt(array[j-1].substring(1, 2));
                int rightNum = Integer.parseInt(array[j].substring(1, 2));

                if (leftNum > rightNum) {
                    String tmp = array[j-1];
                    array[j-1]  = array[j];
                    array[j] = tmp;
                }
            }
        }

        // show sorted result
        System.out.println(String.join(" ", array));

        // show stable or 'not stable'
        checkStable(arrayOrg, array);
    }

    public static void showSelectionSortResult(String[] arrayOrg) {
        String[] array = arrayOrg.clone();

        for (int i=0; i<array.length; i++) {
            int minj = i;
            for (int j=i; j<array.length; j++) {
                int leftNum = Integer.parseInt(array[minj].substring(1, 2));
                int rightNum = Integer.parseInt(array[j].substring(1, 2));
                if (leftNum > rightNum) { minj = j; }
            }
            String tmp = array[minj];
            array[minj]  = array[i];
            array[i] = tmp;
        }

        // show sorted result
        System.out.println(String.join(" ", array));

        // show stable or 'not stable'
        checkStable(arrayOrg, array);

    }

    public static void checkStable(String[] inArr, String[] outArr) {


        for (int i=0; i<inArr.length; i++) {
            for (int j=i+1; j<inArr.length; j++) {
                for (int a=0; a<outArr.length; a++) {
                    for (int b=a+1; b<outArr.length; b++) {
                        int numi = Integer.parseInt(inArr[i].substring(1, 2));
                        int numj = Integer.parseInt(inArr[j].substring(1, 2));

                        if (numi == numj && inArr[i].equals(outArr[b]) && inArr[j].equals(outArr[a]) ) {
                            System.out.println("Not stable");
                            return;
                        }
                    }
                }
            }
        }

        System.out.println("Stable");
    }
}


Measured memory_bytes: 60516
import math
a,b,x = [int(x) for x in input().split(' ')]
S = x/a 
#print(a,b,x,S)
if S > a*b/2:
  theta = math.degrees(math.atan(2*(a*b-S)/(a*a)))
  print(theta)
else:
  theta = math.degrees(math.atan(b*b/(2*S)))
  print(theta)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int n;
	cin>>n;
	map<int,int> c;
	for( int i=2;i<=n;i++)
	{
		int a;
		cin>>a;
		c[a]++;
	}
	for( int i=1;i<=n; i++ )
	{
		if(c.count(i))
			cout << c[i] <<endl;
		else
			cout << 0 << endl;
	}
	return 0;
}


Measured memory_bytes: 12932
import sys
input = sys.stdin.readline

N = int(input())
C = list(map(int, input().split()))
ans = 0
MOD = 10**9+7

C.sort()

for i in range(N):
    left = pow(2, 2*i, MOD)
    
    if i==N-1:
        right = 1
    else:
        right = pow(2, 2*N-2*i-3, MOD)*(N-i+1)

    ans += left*right*2*C[i]
    ans %= MOD

print(ans)

Measured memory_bytes: 79052
#include <iostream>
#include <vector>

using namespace std;

int main(void) {
	int N,M,K;
	cin >> N >> M >> K;
	vector< vector<int> > tl(N,vector<int>(N,0));
	for (int i = 0; i < M; ++i) {
		int L,R;
		cin >> L >> R;
		++tl[R-1][L-1];
	}
	for (int i = 0; i < N; ++i) {
		for (int j = 1; j < i+1; ++j) {
			tl[i][i-j] += tl[i][i-j+1]; 
		}
	}
	vector< vector<int> > memo(N,vector<int>(N));
	for (int i = 0; i < N; ++i) {
		memo[i][i] = tl[i][i];
		for (int j = i+1; j < N; ++j) {
			memo[i][j] = memo[i][j-1] + tl[j][i];
		}
	}

	for (int i = 0; i < K; ++i) {
		int p,q;
		cin >> p >> q;
		cout << memo[p-1][q-1] << endl;
	}
	return 0;
}


Measured memory_bytes: 2944
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
sum1 = 0
for i in range(N):
    sum1 += B[A[i]-1]
    if(i < N-1):
        if(A[i]+1 == A[i+1]):
            sum1 += C[A[i]-1]
print(sum1)

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

int main() {
  string A, B;
  cin >> A >> B;
  if (A.size() < B.size()) while (A.size() < B.size()) A = "0" + A;
  if (B.size() < A.size()) while (B.size() < A.size()) B = "0" + B;
  cout << ((A > B) ? "GREATER" : (A < B) ? "LESS" : "EQUAL") << "\n";
}

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

int main()
{
    string S;
    cin >> S;
    S.insert(4, " ");
    cout << S << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>

int main() {
	int n, d, x, a[100];

	int sum = 0;

	std::cin >> n >> d >> x;

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

		std::cin >> a[i];

		if(a[i] >= d) {

			sum += 1;

		}
		else if (a[i] == 1) {

			sum += d;

		}
		else {
			sum += ((d - 1) / a[i]) + 1;
		}
	}
	std::cout << sum + x << std::endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<map>
#include<stack>
#include<set>
#include<vector>
#include<functional>
using namespace std;
typedef long long LL;
inline long long read()
{
	long long kk=0,f=1;
	char cc=getchar();
	while(cc<'0'||cc>'9'){if(cc=='-')f=-1;cc=getchar();}
	while(cc>='0'&&cc<='9'){kk=(kk<<1)+(kk<<3)+cc-'0';cc=getchar();}
	return kk*f;
}
set<string>S;
string ss;
int main()
{
	int n=read();
	for(int i=1;i<=n;++i)
	{
		cin>>ss;
		S.insert(ss);
	}
	printf("%d\n",S.size());
}

Measured memory_bytes: 19248
#include <stdio.h>
#include <string.h>
#define N 100000

void pre(int);
void in(int);
void pos(int);

typedef struct{
  int parent;
  int left;
  int right;
} data;
data node[N];


int main(){
  int n,i,j,c,t,l,x,d[20],h[20],le,ri,sib[N],f1=0,f2=0,deg[N],root;
  char typ[N][20],a[] = "root",b[] = "leaf",e[] = "internal node";

  scanf("%d",&n);
  for(i = 0;i < n;i++){
    node[i].parent = node[i].left = node[i].right = sib[i] = -1;
  }
  for(i = 0;i < n;i++){
    scanf("%d%d%d",&x,&le,&ri);
    node[x].left = le;
    node[x].right = ri;
    if(le != -1){
      node[le].parent = x;
      f1++;
    }
    if(ri != -1){
      node[ri].parent = x;
      f2++;
    }
    if(le != -1 && ri != -1){
      sib[ri] = le;
      sib[le] = ri;
    }
    deg[x] = f1 + f2;
    f1 = f2 = 0;
  }

  for(i = 0; i < n; i++){
    if(node[i].parent == -1) root = i;
  }

  printf("Preorder\n");
  pre(root);
  printf("\nInorder\n");
  in(root);
  printf("\nPostorder\n");
  pos(root);
  printf("\n");
  
  return 0;
}

void pre(int u){
  if(u == -1) return;
  printf(" %d",u);
  pre(node[u].left);
  pre(node[u].right);
}

void in(int u){
  if(u == -1) return;
  in(node[u].left);
  printf(" %d",u);
  in(node[u].right);
}
void pos(int u){
  if(u == -1) return;
  pos(node[u].left);
  pos(node[u].right);
  printf(" %d",u);
}



Measured memory_bytes: 2084
using System;

namespace a
{
    class Program
    {
        static void Main(string[] args)
        {
            var _ = Console.ReadLine().Split();
            var a = int.Parse(_[0]);
            var b = int.Parse(_[1]);

            var x = a + b;
            var y = a - b;
            var z = a * b;

            var s = Math.Max(Math.Max(x,y),z);
            Console.WriteLine(s);
        }
    }
}


Measured memory_bytes: 11092
N=int(input())
a = [int(i) for i in input().split()] 
a.sort(reverse=True)
p1=a[0:N:2]
p2=a[1:N:2]
sum1=0
sum2=0
for i in p1:
	sum1+=i
for i in p2:
	sum2+=i

print(sum1-sum2)

Measured memory_bytes: 3064
#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

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

	ll n;
	cin >> n;
	vector<vector<pair<ll,ll>>> xy(n);
	REP(i, n) {
		ll a;
		cin >> a;
		REP(j, a) {
			ll x, y;
			cin >> x >> y;
			xy[i].push_back(make_pair(x - 1, y));
		}
	}

	ll ans = 0;
	REP(bit, (1 << n)) {
		ll sum = 0;
		bool flag = true;
		REP(i, n) {
			if (((1 << i) & bit) != 0) {
				for (auto j : xy[i]) {
					ll x = j.first;
					ll y = j.second;
					if (y == 0&&((1 << x) & bit) != 0) {
						flag = false;
						break;
					}
					else if(y==1&& ((1 << x) & bit) == 0){
						flag = false;
						break;
					}
				}
				sum++;
			}
			
		}
		if (flag) chmax(ans, sum);
	}

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

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

ans = N
for i in range(N+1):
    c = 0
    t = i
    while t > 0:
        c += t % 6
        t //= 6
    
    t = N - i
    while t > 0:
        c += t % 9
        t //= 9
    
    ans = min(ans, c)
print(ans)

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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)

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


int main() {
    ll n,m; cin >> n >> m;

    ll modnum = 1000000000 + 7;

    // 3パターンしかないのでは？

    // パターン1 abs(n-m) >= 2
    // どこかでかならず同じ種類がならぶところができてしまうからNG
    // 0通り
    if(abs(n-m) >= 2) {
        cout << 0 << endl;
        return 0;
    }

    // パターン2 n==m
    // ababab or bababa のどちらか
    // この場合は、 mPm * nPn * 2でいいはず
    if(n==m) {
        ll tmp = 1;
        for(ll i=n; i > 0; i--) {
            tmp *= i;
            tmp %= modnum;
        }
        tmp = tmp * tmp * 2;
        tmp %= modnum;
        cout << tmp << endl;
        return 0;
    }


    // パターン3 abs(n-m) == 1
    // ababa のパターンだけ
    // mPm * nPnでいいはず
    if(abs(n-m) == 1) {
        ll tmpn = 1;
        for(ll i=n; i > 0; i--) {
            tmpn *= i;
            tmpn %= modnum;
        }
        ll tmpm = 1;
        for(ll i=m; i > 0; i--) {
            tmpm *= i;
            tmpm %= modnum;
        }
        ll ans = (tmpm * tmpn) % modnum;
        cout << ans << endl;
        return 0;
    }

    return 0;
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010;
const double EPS=1e-9;
int dx[5]={0,1,0,-1,0};
int dy[5]={1,0,-1,0,0};
vector<int> s[100010];
bool f[100010];
int main(){
    int n,m;cin>>n>>m;
    vector<P> v;
    for(int i=0;i<m;i++){
        int a,b;cin>>a>>b;a--;b--;
        v.push_back(P(a,b));
    }
    int ans=0;
    sort(all(v));
    for(int i=0;i<m;i++){
        s[v[i].first].push_back(i);
        s[v[i].second].push_back(i);
    }
    stack<int> now;
    for(int i=0;i<n;i++){
        for(auto a:s[i]){
            if(v[a].second==i){
                if(!f[a]){
                    ans++;
                    while(!now.empty()){
                        f[now.top()]=true;
                        now.pop();
                    }
                }
            }
        }
        for(auto a:s[i]){
            if(v[a].first==i){
                now.push(a);
            }
        }
    }
    cout<<ans<<endl;
}


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

typedef struct TREE{
	int id;
	struct TREE *parent;
	struct TREE *child[2];
	int depth;
	int height;
}Tree;

void insert(Tree *root, Tree *z){
	Tree *y = NULL;
	Tree *x = root;
	while( x != NULL ){
		y = x;
		if( z->id < x->id ){
			x = x->child[0];
		}else{
			x = x->child[1];
		}
	}
	z->parent = y;
	if( y == NULL ){
		root = z;
	}else if( z->id < y->id ){
		y->child[0] = z;
	}else{
		y->child[1] = z;
	}
	return;
}

int setDepthHeight(Tree *nt, int depth){
	if( nt == NULL ){ return -1; }
	nt->depth = depth;
	int lh = setDepthHeight(nt->child[0], depth+1);
	int rh = setDepthHeight(nt->child[1], depth+1);
	nt->height = (lh>rh?lh:rh) + 1;
	return nt->height;
}

void preOrder(Tree *tr){
	if( tr == NULL ){ return; }
	printf(" %d", tr->id);
	preOrder(tr->child[0]);
	preOrder(tr->child[1]);
	return;
}

void inOrder(Tree *tr){
	if( tr == NULL ){ return; }
	inOrder(tr->child[0]);
	printf(" %d", tr->id);
	inOrder(tr->child[1]);
	return;
}

void postOrder(Tree *tr){
	if( tr == NULL ){ return; }
	postOrder(tr->child[0]);
	postOrder(tr->child[1]);
	printf(" %d", tr->id);
	return;
}

void print(Tree *root){
	inOrder(root);
	printf("\n");
	preOrder(root);
	printf("\n");
	return;
}

int main(){
	int n, id, i, j;
	char str[128];
	Tree *root = NULL, *temp = NULL;
	scanf("%d", &n);
	for( i = 0; i < n; i++ ){
		scanf("%s", str);
		if( strcmp(str, "insert") == 0 ){
			scanf("%d", &id);
			scanf("%c", &str[0]);
			temp = (Tree*)malloc(sizeof(Tree));
			temp->id = id;
			temp->parent = NULL;
			temp->child[0] = NULL;
			temp->child[1] = NULL;
			if( root == NULL ){
				root = temp;
			}else{
				insert(root, temp);
			}
		}else if( strcmp(str, "print") == 0 ){
			print(root);
		}
	}
	setDepthHeight(root, 0);
	return 0;
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int a, b;
    cin >> a >> b;

    OP((a + b) % 24);

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text.RegularExpressions;
using System.Threading;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] line1 = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
            long[] line2 = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
            long N = line1[0];
            long M = line1[1];
            List<long> list = new List<long>();
            for (long i = 0; i < M; i++)
            {
                list.Add(line2[i]);
            }
            long sum = list.Sum();
            if (N - sum < 0)
            {
                Console.WriteLine(-1);
            }
            else if (sum >= 0)
            {
                Console.WriteLine(N - sum);
            }
        }
    }
}

//文字列の入力
//string s = Console.ReadLine();
//整数の入力
//long n = long.Parse(Console.ReadLine());
//文字列配列の入力
//string[] inputStrArray = Console.ReadLine().Split(' ');
//整数配列の入力
//long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

//Console.WriteLine();
//Console.ReadKey();


Measured memory_bytes: 29528