akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

signed main(){

  int64_t n;
  cin>>n;

  auto count = [](int64_t n){
    int res = 0;
    while(n){
      res+=n%10;
      n/=10;
    }
    return res;
  };

  if(n<1e6){
    int ans = 0;
    for(int i=0;i<=n;++i)ans = max(ans,count(i));
    cout<<(ans)<<endl;
    return 0;
  }

  int ans = 0;
  for(int i=0;i<1e6;++i)ans = max(ans,count(n-i));
  int dig = to_string(n).size()-1;
  int64_t tmp = to_string(n)[0]-'0'-1;
  for(int i=0;i<dig;++i)tmp = tmp*10+9;
  //for(int64_t i=-1e6;i+tmp<=n&&i<1e6;++i)ans = max(ans,count(i+tmp));
  ans = max(ans,count(tmp));
  cout<<(ans)<<endl;

}

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

// ----------- define --------------
#define int long long
#define vi vector<int>
#define vc vector<char>
#define ii pair<int,int>
#define fi first
#define sc second
#define all(x) (x).begin(),(x).end()
#define get_bit(x, k) ((x >> k) & 1)
// ---------------------------------

void MAIN() {
  int a, b;
  cin >> a >> b;
  if (a == 0) {
    if (b >= 0) cout << b - a << '\n';
    else cout << a - b + 1 << '\n';
  }
  else if (b == 0) {
    if (a <= 0) cout << abs(a) << '\n';
    else cout << a + 1 << '\n';
  }
  else {
    if (a * b > 0) {
      cout << abs(a - b) + (a > b) * 2 << '\n';
    }
    else {
      cout << abs(abs(a) - abs(b)) + 1 << '\n';
    }
  }
}

signed main() {
  // ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#define rep(i, n) repr((i), 0, (n))
#define repr(i, a, t) reps((i), (a), (t), 1)
#define reps(i, a, t, s) for (long long (i) = (a); (i) < (long long)(t); (i) += (s))
#define rrep(i, n) rrepr((i), (n) - 1, 0)
#define rrepr(i, a, t) rreps((i), (a), (t), 1)
#define rreps(i, a, t, s) for (long long (i) = (a); (i) >= (long long)(t); (i) -= (s))
#define each(v, c) for (auto &&(v) : (c))
using namespace std;
namespace mp = boost::multiprecision;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using ml = mp::cpp_int;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ifstream ifs;
  if (getenv("LOCAL") != nullptr) {
    ifs.open("src/_in.txt");
    cin.rdbuf(ifs.rdbuf());
  }

  string S;
  cin >> S;
  ll K;
  cin >> K;

  rep (i, S.size()) {
    ll r = ('z' - S[i] + 1) % 26;
    if (r <= K) {
      K -= r;
      S[i] = 'a';
    }
  }
  S[S.size() - 1] = 'a' + (S[S.size() - 1] + K - 'a') % 26;

  cout << S << "\n";

}

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

#define MAX_LIM 100005
using namespace std;

typedef long long ll;

int main() {
    ll n, k;

    cin >> n >> k;

    vector<ll> w(n+1, INT_MAX), v(n+1, INT_MAX);

    vector<vector<ll>> sol(n+1, vector<ll>(MAX_LIM+1, INT_MAX));

    for (ll i=1; i<=n; i++) {
        cin >> w[i] >> v[i];
    }

    for (ll i=0; i<=n; i++) {
        sol[i][0] = 0;
    }

    for (ll i=1; i<=MAX_LIM; i++) {
        sol[0][i] = INT_MAX;
    }

    for (ll i=1; i<=n; i++) {
        for (ll j=1; j<=MAX_LIM; j++) {
            if (v[i] > j) {
                sol[i][j] = sol[i-1][j];
            } else {
                if (sol[i-1][j-v[i]] != INT_MAX) {
                    sol[i][j] = min(w[i] + sol[i-1][j-v[i]], sol[i-1][j]);
                } else if (sol[i-1][j] != INT_MAX) {
                    sol[i][j] = sol[i-1][j];
                }
            }
        }
    }

    ll ans = INT_MIN;
    for (ll i=1; i<=n; i++) {
        for (ll j=1; j<=MAX_LIM; j++) {
            if (sol[i][j] == INT_MAX || sol[i][j] == 0) {
                continue;
            } else {
                if (sol[i][j] <= k) {
                    ans = max(ans, j);
                }
            }
        }
    }

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

Measured memory_bytes: 80256
#include<stdio.h>
#include<stdlib.h>
  
#define INFTY 2097152//(1<<21)
 
struct ver{
    int weight;
    int key;
    struct ver *next;
};
  
void input(int);
void create(int,int,int);
void shortestpath(void);
int set(int*);
int heap(int*);
 
int n;
int *d;
struct ver *ver;
  
int main(void){
    int i;
    int id;
  
    scanf("%d",&n);
  
    d=(int*)malloc(sizeof(int)*n);
    ver=(struct ver*)malloc(sizeof(struct ver)*n);
    for(i=0;i<n;i++){
        ver[i].weight=-1;
        ver[i].key=-1;
        ver[i].next=NULL;
    }
  
    for(i=0;i<n;i++){
        scanf("%d",&id);
        input(id);  
    }
  
    shortestpath();
  
    for(i=0;i<n;i++) printf("%d %d\n", i, d[i]);
 
    free(d);
    return 0;
}
  
void input(int id){
    int k, u, c;
    int i;
 
    scanf("%d", &k);
    for(i = 0; i < k; i++){
        scanf("%d", &u);
        scanf("%d", &c);
        create(id, u, c);
    }
 
}
  
void create(int id, int u, int c){
    struct ver *new, *work;

    new=(struct ver*)malloc(sizeof(struct ver));
    new->next = NULL;
    new->weight = c;
    new->key = u;
  
    work = &ver[id];
    while(work->next != NULL){
      work = work->next;
    }
    work->next = new;
  
}
  
void shortestpath(void){
    int S[n];
    int i;
    int s, u;
    struct ver *work;
  
    for(i = 0; i < n; i++){
        S[i] = 0;
        d[i] = INFTY;
    }
    s = 0;
    d[s] = 0;
  
    while(set(S) == 0){
        u = heap(S);
        S[u] = 1;
        work = ver[u].next;
 
        while(work != NULL){
 
            if(S[work->key] == 1){
        }else if(d[u] + work->weight < d[work->key]){
                d[work->key] = d[u] + work->weight;
            }
            work = work->next;
 
        }
    }
}
  
int heap(int *s){
    int i;
    int min = INFTY;
    int u;
   
    for(i = 0; i < n; i++){
      if(s[i] == 1){
    continue;
      }
           
      if(d[i]<min){
    min=d[i];
    u=i;
      }
 
    }   
    return u;
}
 
int set(int *s){
    int i;
  
    for(i=0;i<n;i++){
        if(s[i]==0) return 0;
    }
    return 1;
}

Measured memory_bytes: 16220
#include <iostream>
#include <vector>
#include <map>

using namespace std;

int main(){
    int N;
    while(cin >> N){
        long long s = 0;
        map<long long, int> mp;
        mp[0] = 1;
        for(int i=0;i<N;i++){
            int A; cin >> A;
            s += A;
            if(!mp.count(s)) mp[s] = 0;
            ++mp[s];
        }
        long long res = 0;
        for(auto& t : mp){
            res += t.second * (t.second - 1LL) / 2;
        }
        cout << res << endl;
    }
}

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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		long[] a = new long[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		long sum = 0;
		int negative = (int) Arrays.stream(a).filter(i -> i < 0).count();
		if (negative % 2 == 0) {
			sum = Arrays.stream(a).map(i -> Math.abs(i)).sum();
		} else {
			int min = (int) Arrays.stream(a).map(i -> Math.abs(i)).min().getAsLong();
			sum = Arrays.stream(a).map(i -> Math.abs(i)).sum() - min * 2;
		}
		System.out.println(sum);
	}

}


Measured memory_bytes: 61084
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
#define INF (long long)(1LL << 60)

bool chmin(long long& a, long long b) {
    if( a > b ) {
        a = b;
        return true;
    }
    return false;
}

bool chmax(long long& a, long long b) {
    if( a < b ) {
        a = b;
        return true;
    }
    return false;
}

int main() {
    // INPUT
    int N = 0;
    cin >> N;
    int K = 0;
    cin >> K;
    vector<long long> height(N);
    for(int i = 0; i < N; i++) {
        cin >> height[i];
    }
    vector<long long> cost(N, INF);
    cost[0] = 0;

    // SOURCE
    for( int i = 1; i < N; i++ ) {
        for( int j = 1; j <= i && j <= K; j++) {
            chmin(cost[i], cost[i-j] + abs(height[i] - height[i-j]));
        }
    }

    // OUTPUT
    cout << cost[N-1] << endl;

    return 0;
}


Measured memory_bytes: 1792
package main

import (
	"fmt"
	"math"
	"strings"
)

func main() {
	var (
		s string
	)
	fmt.Scan(&s)
	if max(strings.Count(s, "a"), strings.Count(s, "b"), strings.Count(s, "c")) == 1 {
		fmt.Println("Yes")
		return
	}
	fmt.Println("No")
}

/*  ----------------------------------------  */

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}
func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }
func floor(x int) int  { return int(math.Floor(float64(x))) }


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
//const int mod = ;

int main() {
  std::ios::sync_with_stdio(false); std::cin.tie(0);
  int r, g, b, n;
  cin >> r >> g >> b >> n;
  vl d(n + 1);
  d[0] = 1;
  for (int a : {r, g, b}) {
    for (int i = 0; i + a <= n; ++i) {
      d[i + a] += d[i];
    }
  }
  cout << d[n] << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();
        while (true) {
            int n = sc.nextInt();
            if (n == 0) {
                break;
            }
            HashMap<Character, Character> map = new HashMap<>();
            for (int i = 0; i < n; i++) {
                map.put(sc.next().charAt(0), sc.next().charAt(0));
            }
            int m = sc.nextInt();
            char[] arr = new char[m];
            for (int i = 0; i < m; i++) {
                char c = sc.next().charAt(0);
                if (map.containsKey(c)) {
                    arr[i] = map.get(c);
                } else {
                    arr[i] = c;
                }
            }
            sb.append(new String(arr)).append("\n");
        }
        System.out.print(sb);
    }
}



Measured memory_bytes: 70648
#include<stdio.h>
int main(void)
{
int a,b,c;
int count;
int i;
scanf("%d %d %d",&a,&b,&c);

for(i=a;i<=b;i++)
{
if(c%i==0) count++;
}

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

return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi= vector<int>;
using vvi= vector<vi>;
using vd= vector<double>;
using vvd= vector<vd>;
using vc= vector<char>;
using vb= vector<bool>;
using vl= vector<ll>;
#define rep(i,x,n) for(int i=x; i<n; i++)
#define all(x) x.begin(), x.end()

int main(){
  bool ch=true;
  int n,a,b,time=0;
  cin >> n;
  vector<pair<int,int>>p(n);
  rep(i,0,n){
    cin >> a >> b;
    p[i]= make_pair(b,a);
  }
  sort(all(p));
  rep(i,0,n){
    time+= p[i].second;
    if(time>p[i].first){
      ch=false;
    }
  }
  if(ch){
    cout << "Yes";
  }else{
    cout << "No";
  }

  return 0;
}


Measured memory_bytes: 1792
n, m = map(int, input().split())
S = list(map(int, input()))[::-1]
L = []
now = 0
while now < n:
  if n - now <= m:
    L.append(n - now)
    break
  for i in range(m, 0, -1):
    if not S[now+i]:
      now += i
      L.append(i)
      break
  else:
    print(-1)
    exit()
print(*L[::-1])

Measured memory_bytes: 54492
#!/usr/bin/env python3

D = int(input())
c = list(map(int, input().split()))

s = []
for d in range(D):
    s.append(list(map(int, input().split())))

def get_objective_function(output):
    objective_function = 0
    last = [[-1 for i in range(26)] for d in range(D)]

    for d in range(D):
        objective_function += s[d][output[d]]

        last[d][output[d]] = d
        if d < D-1:
            for i in range(26):
                last[d+1][i] = max(last[d][i], last[d+1][i])

        for i in range(26):
            objective_function -= c[i] * (d-last[d][i])

    point = max(10 ** 6 + objective_function, 0)
    print(objective_function, point)

#output = [0, 16, 12, 13, 12]

# 最大効用での戦略
output = []
for d in range(D):
    output.append(s[d].index(max(s[d])))
for d in output:
    print(d+1)

#get_objective_function(output)

Measured memory_bytes: 9524
#include <bits/stdc++.h>
#define ll long long
#define INF 1e9
#define pb push_back
#define mp  make_pair
#define loop(a,n) for(long long i=a;i<n;i++)
#define vil vector<long long int>
#define vi vector<int>
#define sz(v) v.size()
#define setbits(x)          __builtin_popcountll(x)
#define ff first
#define ss second
using namespace std;

int nCrevenoroddfinder(int n,int r)
{
    int a=r;
    int b=n-r;
    for(int i=0;i<30;i++)
    {
        int x=1<<i;
        if((x&a)&&(x&b))
        {
            return 0;//even
        }
    }
    return 1;//odd
}

ll gcd(ll a, ll b) {
  if (a == 0)return b;
  return gcd(b % a, a);
}
bool isperfect(ll n) {
  ll y = sqrt(n);
  if (n % y == 0 && y * y == n)return true;
  return false;
}
bool comp(pair<int,int> a, pair<int,int> b) {
    if(a.first == b.first) return a.second>b.second;
  return a.first < b.first;
}
 ll powi(ll a, ll b) {
  ll ans = 1;
  while (b > 0) {
    if (b & 1)ans = (ans * a);
    b = b >> 1;
    a = (a * a);
  }
  return ans;
}
bool isprime(ll n) {
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0)return false;
  }
  return true;
}
bool prime[10000000];
void seive() {

  prime[1] = true;
  for (int i = 2; i * i < 10000000; i++) {

    if (prime[i])continue;
    for (int j = i * i; j < 10000000; j += i) {
      prime[j] = true;
    }

  }
}

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll h,w,m;
    cin>>h>>w>>m;
    ll ro[h+1]={},col[w+1]={};
    map<pair<ll,ll>,bool> vis;
    ll f=m;
    ll maxr=0,maxc=0;
    while(m--){
        ll x,y;cin>>x>>y;
        ro[x]++;col[y]++;
        vis[{x,y}]=true;
        maxr=max(maxr,ro[x]);
        maxc=max(maxc,col[y]);
    }
    ll maxi=INT_MIN;
    // sort(ro,ro+h+1);
    // sort(col,col+w+1);
    maxi=maxr+maxc;//-((vis[{h,w}]==true)?1:0);
  //  cout<<maxi;
     vil r,c;
     for(int i=1;i<=h;i++) 
     {
          if(maxr==ro[i]) r.pb(i);
     }
     for(int i=1;i<=w;i++) 
     {
         if(maxc==col[i])  c.pb(i);
     }
     ll tr=1;
   //  cout<<maxi;
     for(auto x:r){
         for(auto y:c){
             if( vis[{x,y}]==false ) {
                 tr=0;break;
             }
         }
         if(!tr) break;
     }
     cout<<maxi-tr<<endl;
}



  

Measured memory_bytes: 34944
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
#include <utility>
#include <cmath>
#include <cstdio>

using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;
LL MOD = 1000000007;

int main() {
    int N;
    cin >> N;
    vector<int> A(N, 0);
    for(int i=0; i<N; i++) {
        cin >> A[i];
    }
    LL maxim = 1000000;
    maxim *= maxim;
    vector<LL> DP(N, maxim);
    DP[0] = 0;
    for(int i=1; i<N; i++) {
        DP[i] = min(DP[i-1] + abs(A[i-1] - A[i]) , DP[i-2] + abs(A[i-2] - A[i]));
    }
    cout << DP[N-1] << endl;

    return 0;
}

Measured memory_bytes: 1536
#include <iostream>

int main(){
	double a;
	while(std::cin>>a){
		int aa=0,n=0;
		while(aa==0){
			
			n++;
			double t=a/9.8;
			
			if(5*n-5>=4.9*t*t){
				std::cout<<n<<std::endl;
				aa=1;
				
			}
		}
		
	}
	return 0;
}

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

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

    vector<pair<int, vector<int>>> ks(m);
    int s;
    vector<int> p(m);

    for (int i = 0; i < m; i++)
    {
        cin >> ks[i].first;
        for (int j = 0; j < ks[i].first; j++)
        {
            cin >> s;
            ks[i].second.push_back(s);
        }
    }

    for (int i = 0; i < m; i++)
        cin >> p[i];
    /*
    for (int i = 0; i < m; i++)
    {
        cout << ks[i].first << " ";
        for (int j = 0; j < ks[i].first; j++)
            cout << ks[i].second[j] << " ";
        cout << endl;
    }
    */
    int count = 0;
    vector<bool> swval(n);
    bool match;
    int num_sw_on = 0, sw_index;

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

        // swval = val of sw 1, 2, 3, ..., n
        for (int j = 0; j < n; j++)
        {
            swval[j] = i & (0x1 << (n-j-1));
        }

        for (int k = 0; k < m; k++)
        {
            num_sw_on = 0;
            for (int l = 0; l < ks[k].first; l++)
            {
                sw_index = ks[k].second[l] - 1;
                if (swval[sw_index] == true) 
                {
                    num_sw_on++;
                }
            }

            if (num_sw_on % 2 != p[k])
            {
                match = false;
                break;
            }

        }

        if (match) count++;

    }
        
    cout << count << endl;
}


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

int main(){
    string s, val;
    bool is_hitachi = false;
    cin >> s;
    string hi = "hi";
    rep(i, 5){
        val += "hi";
        if(val == s)is_hitachi = true;
    }
    if(is_hitachi)cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

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

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

typedef int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = 1e9+7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


ll fnc1(string& sn){
	int cn=sz(sn);
	VL dp(2), np(2);
	dp[0]=1; 
	rep(i, cn) {
		fill(all(np), 0);
		if(sn[i]=='0'){
			np[0] += dp[0];
			np[1] += dp[1] * 3;
		}else{
			np[0] += dp[0] * 2;
			np[1] += dp[0] + dp[1] * 3;
		}
		np[0] %=MD; np[1] %=MD;
		swap(np, dp);
	}
	return (dp[0]+dp[1]) %MD;
}
int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	string s;
	cin >>s;
	
	cout << fnc1(s) <<"\n";
	
}


Measured memory_bytes: 512
from sys import stdin

nn = input()

N=int(nn)

arr=list(map(int,input().split()))


if 0 in arr:
    print(0)
    exit()

res=1
for i in arr:
    res*=i
    if res>1000000000000000000:
        print(-1)
        exit();

print(res)

Measured memory_bytes: 21616
/*
    Code written by Talant I.D.
*/
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair <int, int> pii;
typedef tuple <int, int, int> tiii;
 
#define precision(n) fixed << setprecision(n)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define mt make_tuple
#define mod (int)1e9+7
#define eps (double)1e-9	
#define PI 2*acos(-0.0);
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define curMod 998244353

inline bool isvowel(char ch){
    ch = tolower(ch);
    return (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u');
}
 
bool isprime(int n){
	if(n < 2 || (n % 2 == 0 && n != 2))
		return false;
	for(int i = 3; i*i <= n; i += 2) 
		if(n % i == 0) return false;
	return true;
}

int main(){
    do_not_disturb
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ll a, b;
	cin >> a >> b;
	cout << a/__gcd(a, b)*b;
	
    return 0;
} // What is to be written here?


Measured memory_bytes: 256
import collections
N = int(input())
D = list(map(int, input().split()))
D_C = collections.Counter(D)
D_C = D_C.items()
D_C = sorted(D_C)

#print(D_C)
N = len(D_C)
MOD = 998244353
ans = 1

if (D[0] != 0) or (D_C[0][1] != 1):
  ans = 0
  print(ans % MOD)
  quit()
  
for i in range(N-1):
  ans = ans * (D_C[i][1] ** D_C[i + 1][1])
  if i > 0:
    if D_C[i][0] != x + 1:
      ans = 0
      print(ans)
      quit()
  x = D_C[i][0]

if D_C[N-1][0] != x + 1:
  ans = 0
print(ans % MOD)

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

struct Node{
    int key;
    Node *parent, *left, *right;
};

Node *root, *NIL;

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

    z = (Node *)malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;

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

    z->parent = y;

    if(y == NIL){
        root = z;
    }else{
        if(z->key < y->key) y->left = z;
        else y-> right = z;
    }

}

Node* treeMinimum(Node *x){
    while(x->left != NIL){
        x = x->left;
    }
    return x;
}

Node* find(int k){
    Node *x = root;
    while(x != NIL && x->key != k){
        if(k < x->key) x = x->left;
        else x = x->right;
    }
    return x;
}

Node* treeSuccessor(Node *x){
    if(x->right != NIL) return treeMinimum(x->right);
    Node *y = x->parent;
    while(y != NIL && x == y->right){
        x = y;
        y = y->parent;
    }
    return y;
}

void deleteNode(Node *z){
    Node *y; //削除する対象
    Node *x; //yの子

    //削除する接点を決める
    if(z->left == NIL || z->right == NIL) y = z;
    else y = treeSuccessor(z);

    //yの子xを決める
    if(y->left != NIL){
        x = y->left;
    }else{
        x = y->right;
    }
    
    if(x != NIL){
        x->parent = y->parent;
    }

    if(y->parent == NIL){
        root = x;
    }else{
        if(y == y->parent->left){
            y->parent->left = x;
        }else{
            y->parent->right = x;
        }
    }

    if(y != z){
        z->key = y->key;
    }

    free(y);

}

void inorder(Node *u){
    if(u == NIL) return;
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
}

void preorder(Node *u){
    if(u == NIL) return;
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}

void print(Node *u){
    inorder(u);
    printf("\n");
    preorder(u);
    printf("\n");
}

int main(){
    int m;
    cin >> m;
    char com[10];
    int k;

    rep(i,m){
        scanf("%s", com);
        if(com[0] == 'i'){
            scanf("%d", &k);
            insert(k);
        }else if(com[0] == 'f'){
            scanf("%d", &k);
            Node *x = find(k);
            if(x == NIL) cout << "no" << endl;
            else cout << "yes" << endl;
        }else if(com[0] == 'd'){
            scanf("%d", &k);
            Node *x = find(k);
            if(x != NIL){
                deleteNode(x);
            }
        }else{
            print(root);
        }
    }

    return 0;
}



Measured memory_bytes: 21872
#include <bits/stdc++.h>
using namespace std;
string s;
int c1,c2;
int main(){
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(s[i]=='1'&&i%2==0||s[i]=='0'&&i%2==1)c1++;
		else if(s[i]=='0'&&i%2==0||s[i]=='1'&&i%2==1)c2++;
	}
	cout<<min(c1,c2)<<endl;
	return 0;
}

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

#define mp       make_pair
#define mt	 make_tuple
#define pb       push_back
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    pair<int,int>      pii;
typedef    pair<long,long>    pll;

const int INF=1<<29;
const double EPS=1e-9;
const int MOD = 100000007;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
string tmp;
int main(){
  while (cin >> tmp){
    if (tmp == "#")break;
    vector<string> dir;
    for (int i = 0; i < tmp.size();){
      if (tmp[i] == 'n'){
	dir.push_back("north");
	i += 5;
      }else{
	dir.push_back("west");
	i += 4;
      }
    }
    int last = (dir[dir.size() - 1] == "west"?90:0);
    int div = 1;
    for (int i = dir.size() - 2; i >= 0; i--){
      if (dir[i] == "north"){
	last = last * 2 - 90;
      }else{
	last = last * 2 + 90;
      }
      div *= 2;
    }
    while (last % 2 == 0 && last != 0 && div != 1){
      last /= 2;
      div /= 2;
    }
    if (last == 0 || div == 1){
      printf("%d\n", last);
    }else{
      printf("%d/%d\n", last, div);
    }
  }
  
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n;
  cin >> n;
  int r[n];
  rep(i, 0, n) cin >> r[i];

  ll r_max[n];
  r_max[n - 1] = r[n - 1];
  repr(i, 0, n - 1) {
    if (r[i] > r_max[i + 1])
      r_max[i] = r[i];
    else
      r_max[i] = r_max[i + 1];
  }

  ll ans = -1e18;
  rep(i, 0, n - 1) { chmax(ans, r_max[i + 1] - r[i]); }
  cout << ans << endl;
}



Measured memory_bytes: 5512
#include <iostream>
#include <vector>
#include <cmath>

int main() {
  int N, D, count = 0;
  std::cin >> N >> D;

  long long X, Y;
  for (int i = 0; i < N; ++i) {
    std::cin >> X >> Y;
    long double dist = sqrt(X * X + Y * Y);
    if (dist <= D) count++;
  }

  std::cout << count << std::endl;
  return 0;
}


Measured memory_bytes: 3672
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


int main(){
    ll N, M;
    cin >> N >> M;

    ll ans = 0;
    ans += min(N, M / 2);
    N -= ans;
    M -= ans * 2;
    if(N == 0){
        ans += M / 4;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3556
//import java.util.Scanner;
import java.util.Scanner;
public class Main {
	public static void main(String args[]){
		Scanner var = new Scanner(System.in);
		int a = var.nextInt();
		int b = var.nextInt();
    int area=a*b;
    int length=2*a+2*b;
		System.out.println(area+" "+length);
	}
}

Measured memory_bytes: 26088
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
using namespace std;
typedef long long unsigned int ll;

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

bool isSquare(int N) {
	if (int(sqrt(N)) * int(sqrt(N)) == N) {
		return true;
	}
	else {
		return false;
	}
}

int main() {
	//入力
	int N;
	cin >> N;

	do {
		if (isSquare(N)) {
			cout << N;
			return 0;
		}
		N--;
	} while (N);

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define co cout
#define ci cin
#define sf1(n) scanf("%lld",&n);
#define sf2(n,m) scanf("%lld %lld",&n,&m);
#define sf3(n,m,p) scanf("%lld %lld %lld",&n,&m,&p);
#define en cout<<endl;
#define pb push_back
#define coy cout<< "YES"<<endl;
#define con cout<< "NO"<<endl;
#define For(a,b) for(ll a=0;a<b;a++)
#define br break;
#define i64 long long
i64 M=10000000;
//ll b[805],ans[805];
map< ll,pair<ll,ll> >mp;

int main()
{
    ll t,n,g,k,m,mx=0,mn=1e9,res,c1,x,y,c2;
    sf1(n)
    ll a[n-1],b[n],c[n];
    for(ll i=0;i<n-1;i++) ci>>a[i];
    ll sum=0;
    for(ll i=1;i<n-1;i++)
    {
        sum+=min(a[i-1],a[i]);
    }
    sum+=a[0]+a[n-2];
    co<<sum;
}



Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int A=0,B=0;
  scanf("%d" "%d",&A,&B);
  if(A>=13){
  printf("%d\n",B);
  }
  else if(A<=12&&A>=6){
    printf("%d\n",B/2);
  }
  else {
  printf("0\n");
  }
return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,i,sum=0;
    cin>>n;
    int v[n],c[n],d[i];
    for(i=0;i<n;i++){
        cin>>v[i];
    }
    for(i=0;i<n;i++){
        cin>>c[i];
        d[i]=v[i]-c[i];
    }
    sort(d,d+n,greater<int>());
    for(i=0;i<n;i++){
        if(d[i]>0){
            sum+=d[i];
        }
    }
    cout<<sum;
    return 0;
}

Measured memory_bytes: 256
(stdin => {
  // Define Function

  // Declare Variable
  const inputs = stdin.toString().trim().split('\n')
  const S = parseInt(inputs[0], 10)
  const GetHour = S => Math.floor(S / 3600)

  const GetMin = S => Math.floor((S % 3600) / 60)

  const GetSec = S => S % 60
  console.log(`${GetHour(S)}:${GetMin(S)}:${GetSec(S)}`)
})(require('fs').readFileSync('/dev/stdin', 'utf8'))



Measured memory_bytes: 15112
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<int, int>;
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 int INF = 1<<30;

int main() {
    int n, m;
    string s;
    cin >> n >> m >> s;
    vector<int> dp(n+1, INF);
    dp[n] = 0;
    queue<int> que;
    que.push(0);
    for(int i = n-1; i >= 0; --i) {
        while(1) {
            if(que.empty()) {
                cout << -1 << endl;
                return 0;
            }
            if(que.front() != INF && (int)que.size() <= m) break;
            que.pop();
        }
        if(s.at(i) == '0') dp[i] = que.front() + 1;
        que.push(dp[i]);
    }

    vector<int> ans;
    int x = 0;
    int rest = dp[0];
    while(x < n) {
        --rest;
        int i = 1;
        while(dp[x+i] != rest) ++i;
        ans.push_back(i);
        x += i;
    }
    for(int i = 0; i < (int)ans.size(); ++i) {
        if(i == (int)ans.size() - 1) cout << ans.at(i) << endl;
        else cout << ans.at(i) << " ";
    }
}

Measured memory_bytes: 1528
import java.util.*;

public class Main {

    private static char[] N;
    private static int K;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        N = sc.next().toCharArray();
        K = sc.nextInt();
        int[][][] dp = new int[N.length+1][K+1][2];
        dp[0][0][1] = 1;
        for (int i = 0; i < N.length; i++) {
            for (int j = 0; j <= K; j++) {
                for (int s = 0; s < 2; s++) {
                    if (dp[i][j][s] == 0)  continue;
                    if (s == 0) {
                        dp[i+1][j][0] = dp[i+1][j][0]+dp[i][j][0];
                        if (j+1 <= K) {
                            dp[i+1][j+1][0] = dp[i+1][j+1][0]+9*dp[i][j][0];
                        }
                    } else {
                        int a = N[i]-'0';
                        if (a == 0) {
                            dp[i+1][j][1] = dp[i+1][j][1]+dp[i][j][1];
                        } else {
                            dp[i+1][j][0] = dp[i+1][j][0]+dp[i][j][1];
                            if (j+1 <= K) {
                                dp[i+1][j+1][0] = dp[i+1][j+1][0]+(a-1)*dp[i][j][1];
                                dp[i+1][j+1][1] = dp[i+1][j+1][1]+dp[i][j][1];
                            }
                        }
                    }
                }
            }
        }
        System.out.println(dp[N.length][K][0]+dp[N.length][K][1]);
    }
}



Measured memory_bytes: 23892
const input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);let input_i=-1;const tn=():number=>{input_i++;return Number(input[input_i])};const tnn=(n:number):number[]=>{const a=[];for(let i=0;i<n;i++){a.push(tn())}return a};const ts=():string=>{input_i++;return String(input[input_i])};const tss=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(ts())}return a};const to=(...arg)=>{console.log(...arg)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const floor=(a)=>{return Math.floor(a)};const ceil=(a)=>{return Math.ceil(a)};const asc=(ar:number[])=>{const t=[...ar];return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{const t=[...ar];return t.sort((a,b)=>{return b-a})};const sw=(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length-1;i+=2){if(eval(a+op+arr[i])){return arr[i+1]}}return arr[arr.length-1]};const near=(n:number,arr:number[]):number=>{let ne=arr[0],ni=0;for(let i=1;i<arr.length;i++){if(Math.abs(n-ne)>Math.abs(n-arr[i])){ne=arr[i];ni=i}}return ni};const deduplicate=(a:any[]):any[]=>{return Array.from(new Set(a))};const gcd=(x,y)=>{while(y){[x,y]=[y,x%y]}return x};const sum=(arr)=>{return arr.reduce((a,b)=>a+b);};const isPrime=(n:number):boolean=>{if(n<2)return false;const suq=Math.sqrt(n);for(let i=2;i<=suq;i++){if(n%i==0){return false;}}return true;};
const main=()=>{
  let a=tn()
  while(true){
    if(isPrime(a)){
      to(a)
      return
    }
    a++
  }
}
main()


Measured memory_bytes: 11468
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

typedef long long ll;
//No change above here

const ll maxi = (2 * 1e6 + 3);
ll mod = (1e9 + 7);

//function for power
ll power(ll x, ll n) {
	ll res = 1;
	x %= mod;
	while (n) {
		if (n & 1)
			res = (res * x) % mod;
		x = (x * x) % mod;
		n >>= 1;
	}
	return res;
}

ll dir[4][2] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1} };

ll p, q;
bool valid(ll i, ll j) { return i >= 1 && i <= p && j >= 1 && j <= q; }

//declare needed things here
ll N, M, Q;
int a[52], b[52], c[52],d[52];
ll ans;
vector<int> v{0};
void dfs(int len, int cur)
{
	if (len == N)
	{
		ll temp = 0;
		for (int i = 1; i <= Q; ++i)
		{
			if (v[b[i]] - v[a[i]] == c[i])
				temp += d[i];
		}
		ans = max(ans, temp);
		return;
	}
	for (int i = cur; i <= M; ++i)
	{
		v.push_back(i);
		dfs(len + 1, i);
		v.pop_back();
	}

}
int main()
{
	IOS;
	cin >> N >> M >> Q;
	for (int i = 1; i <= Q; ++i)
		cin >> a[i] >> b[i] >> c[i] >> d[i];
	ans = 0;
	dfs(0, 1);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3548
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

struct Graph {
    struct Edge { int i; };
    struct Vertex { int v; };
    Graph(int n) : e(n, vector<Edge>()), v(n), n(n) {}
    void add_edge(int i, int j) {
        e[i].push_back({ j });
    }
    int solve() {
        int r = 0;
        for (int i = 0; i < n; i++) {
            for (auto o : e[i]) {
                int j = o.i;
                if (i < j) {
                    fill(v.begin(), v.end(), Vertex{ 0 });
                    a = i; b = j;
                    r += 1 - dfs(i);
                }
            }
        }
        return r;
    }
    int dfs(int i) {
        v[i].v = 1;
        for (auto o : e[i]) {
            int j = o.i;
            if ((i == a && j == b) || (i == b && j == a)) continue;
            if (v[j].v) continue;
            if (j == b || dfs(j)) return 1;
        }
        return 0;
    }
    vector<vector<Edge>> e;
    vector<Vertex> v;
    int n, a, b;
};

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

    Graph g(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;

        g.add_edge(a, b);
        g.add_edge(b, a);
    }

    cout << g.solve() << endl;

    return 0;
}

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

using namespace std;
set<string> st;
int main(){
    int n;
    cin>>n;
    string res;
    for(int i=1;i<=n;i++){
    	cin>>res;
    	st.insert(res);
	}
	cout<<st.size();
	return 0;
} 

Measured memory_bytes: 19228
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    int N,M,Q;
    cin >> N >> M >> Q;
    vector<vector<int> > vec(N + 1, vector<int>(N + 1));
    rep(i,N + 1){
        rep(j,N + 1){
            vec[i][j] = 0;
        }
    }
    rep(i,M){
        int l,r;
        cin >> l >> r;
        vec[l][r]++;
    }
    rep(i,N + 1){
        rep(j,N){
            vec[i][j + 1] += vec[i][j];
        }
    }
    vector<int> p(Q);
    vector<int> q(Q);
    rep(i,Q){
        cin >> p[i] >> q[i];
    }
    rep(i,Q){
        int ans = 0;
        for (int j = p[i]; j <= q[i]; j++){
            ans += vec[j][q[i]] - vec[j][p[i] - 1];
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 5000
import java.util.*;

import javax.xml.crypto.Data;
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		while(true) {
			char b = sc.next().charAt(0);
			if(b == '=') {
				System.out.println(a);
				break;
			}
			int c = sc.nextInt();
			if(b == '+') {
				a += c;
			}
			if(b == '-') {
				a -= c;
			}
			if(b == '*') {
				a *= c;
			}
			if(b == '/') {
				a /= c;
			}
		}
	}


}

Measured memory_bytes: 19528
N = int(input())
S = [input() for i in range(N)]
SE = [set(i) for i in S]

s = SE[0]

for i in range(1,N):
  s = s & SE[i]

s = sorted(list(s))

con = [10 ** 8] * len(s)

for i in range(len(s)):
  t = s[i]
  c = 0
  for j in range(N):
    S[j] = list(S[j])
    c = S[j].count(t)
    if c < con[i]:
      con[i] = c
      
ans = ""
      
for s,c in zip(s,con):
  ans += s * c
  
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main(){
    string c;
    int a,b;
    cin >> a >> b;
    if(a>b){
        c=" > ";
    } else if(a==b){
        c=" == ";
    } else {
        c=" < ";
    }
    cout << 'a' << c << 'b' << endl;
}


Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
int n, m, ex, ey;
char a[105][105];
short dp[101][101][101][101], sr[105][105], sc[105][105];
inline void getmax(short &x, short y) {
	if (x < y) x = y;
}
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++) {
		scanf(" %s", a[i] + 1);
		for (int j = 1; j <= m; j++) {
			if (a[i][j] == 'E') {
				ex = i;
				ey = j;
				a[i][j] = '.';
			}
			sr[i][j] = sc[i][j] = (a[i][j] == 'o');
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			sr[i][j] += sr[i][j - 1];
			sc[i][j] += sc[i - 1][j];
		}
	}
	int ans = 0;
	for (int l = 0; l <= ey - 1; l++) {
		for (int r = 0; r <= m - ey; r++) {
			for (int u = 0; u <= ex - 1; u++) {
				for (int d = 0; d <= n - ex; d++) {
					ans = max(ans, (int)dp[l][r][u][d]);
					if (l + r < ey - 1) getmax(dp[l + 1][r][u][d], dp[l][r][u][d] + sc[min(n - u, ex + d)][ey - l - 1] - sc[max(d, ex - u - 1)][ey - l - 1]);
					if (l + r < m - ey) getmax(dp[l][r + 1][u][d], dp[l][r][u][d] + sc[min(n - u, ex + d)][ey + r + 1] - sc[max(d, ex - u - 1)][ey + r + 1]);
					if (u + d < ex - 1) getmax(dp[l][r][u + 1][d], dp[l][r][u][d] + sr[ex - u - 1][min(m - l, ey + r)] - sr[ex - u - 1][max(r, ey - l - 1)]);
					if (u + d < n - ex) getmax(dp[l][r][u][d + 1], dp[l][r][u][d] + sr[ex + d + 1][min(m - l, ey + r)] - sr[ex + d + 1][max(r, ey - l - 1)]);
				}
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}

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

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		String[][] r = new String[n][3];
		for (int i = 0; i < n; i++) {
			r[i][0] = sc.next();
			r[i][1] = sc.next();
			r[i][2] = String.valueOf(i + 1);
		}
		Arrays.sort(r, (x, y) -> {
			if (x[0].compareTo(y[0]) < 0) {
				return -1;
			} else if (x[0].compareTo(y[0]) > 0) {
				return 1;
			} else {
				return -Integer.compare(Integer.parseInt(x[1]), Integer.parseInt(y[1]));
			}
		});
		for (int i = 0; i < r.length; i++) {
			System.out.println(r[i][2]);
		}
		sc.close();
	}
}

Measured memory_bytes: 27220
N = int(input())
S = input()

l_black = 0
r_white = S.count('.')
ans = r_white

for i in range(N):
    if S[i] == '#':
        l_black += 1
    else:
        r_white -= 1
    ans = min(ans, l_black + r_white)

print(ans)

Measured memory_bytes: 3500
N = int(input())
R = []
Q = []
for i in range(N):
  R.append(input().split())
  R[i][1] = int(R[i][1])
for i in range(N):
  Q.append(R[i])
R.sort(key=lambda x:x[1], reverse=True)
R.sort(key=lambda x:x[0])
#print(R)
for j in range(N):
  print(Q.index(R[j]) +1)

Measured memory_bytes: 3064
def abc166c_peaks():
    n, m = map(int, input().split())
    h = list(map(int, input().split()))
    check = [1] * n
    for i in range(m):
        a, b = map(int, input().split())
        if h[a-1] <= h[b-1]:
            check[a-1] = 0
        if h[b-1] <= h[a-1]:
            check[b-1] = 0
    print(sum(check))

abc166c_peaks()

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

using namespace std;

#define fo(i,n) for(int i=0; i<n; i++)
#define Fo(i,k,n) for(int i=k; i<n; i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define clr(x) memset(x, 0, sizeof(x))
#define tr(it, a) for(auto it=a.begin(); it!=a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;

int N,M;
vi dp;
vi in_nodes;

struct Graph {
    vvi edges;

    void read() {
        edges.resize(N+1);
        Fo(i,1,M+1){
            int x,y;
            cin>>x>>y;
            edges[x].push_back(y);
            in_nodes[y]++;
        }
    }

    void dfs(int node){
        for(auto child : edges[node]){
            dp[child] = max(dp[child], dp[node]+1);
            in_nodes[child]--;
            if(in_nodes[child] == 0){
                dfs(child);
            }
        }
    }
};


int main() {
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);

    cin>>N>>M;
    dp.resize(N+1);in_nodes.resize(N+1);
    Graph graph;
    graph.read();
    Fo(i,1,N+1){
        if(in_nodes[i]==0){
            graph.edges[0].push_back(i);
            in_nodes[i]++;
        }
    }
    graph.dfs(0);
    int ans=0;
    Fo(i,1,N+1){
        if(dp[i]>ans){
            ans = dp[i];
        }
    }
    cout<<ans-1<<endl;
    
    return 0;
}

Measured memory_bytes: 9344
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] p = new int[n];
		boolean[] b = new boolean[n];
		for (int i = 0; i < n; i++) {
			p[i] = sc.nextInt()-1;
			updateJudge(p, b, i);
		}

		int cnt = 0;
		for (int i = 0; i < n-1; i++) {
			if( !b[i] ) {
				swap(p, i, i+1);
				updateJudge(p, b, i);
				updateJudge(p, b, i+1);
				cnt++;
			}
		}
		int i=n-1;
		if( !b[i] ) {
			swap(p, i, i-1);
			updateJudge(p, b, i);
			updateJudge(p, b, i-1);
			cnt++;
		}

		System.out.println(cnt);
	}

	private static void updateJudge(int[] p, boolean[] b, int i) {
		b[i] = p[i]!=i;
	}

	private static void swap(int[] p, int i, int j) {
		int t = p[i];
		p[i] = p[j];
		p[j] = t;
	}
}

Measured memory_bytes: 59720
#include<cstdio>
#include<cstring>
#define MAXN 50+10

char a[MAXN][MAXN],b[MAXN][MAXN];
int main(){
	int n,m;
	scanf("%d %d",&n,&m);
	getchar();
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			scanf("%c",&a[i][j]);
		}
		getchar();
	}
	for(int i=1;i<=m;i++){
		for(int j=1;j<=m;j++){
			scanf("%c",&b[i][j]);
		}
		getchar();
	}
	for(int i=1;i<=n-m+1;i++){//枚举a矩阵 
		for(int j=1;j<=n-m+1;j++){
			if(a[i][j]==b[1][1]){
				bool tmp=0;
				for(int k=1;k<=m;k++){//枚举b矩阵 
					for(int h=1;h<=m;h++){
						if(a[i+k-1][j+h-1]!=b[k][h]){
							tmp=1;
							break;
						}
					}
					if(tmp) break;
				}
				if(!tmp) {
					printf("Yes");
					return 0;
				}
			}		
		}
	}
	printf("No");
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
int main()
{
    int a,b,c,d;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    if((abs(a-b))<=d&&(abs(b-c))<=d)
        {
            printf("Yes");
        }
    else if((abs(a-c))<=d)
        {
            printf("Yes");
        }
    else
        {
            printf("No");
        }


    return 0;

}


Measured memory_bytes: 1712
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mod 1000000007
typedef long long ll;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;
    if(n==1)
        cout << "Hello World";
    else{
        int a,b;
        cin >> a >> b;
        cout << a+b;
    }
}

Measured memory_bytes: 896
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    token.parse().ok().unwrap()
}

fn main() {
    let s = input::<String>();

    let mut ans = std::i64::MAX;
    for i in 0..s.len() - 2 {
        let sub = s.chars().skip(i).take(3).collect::<String>();
        let x = sub.parse::<i64>().ok().unwrap();
        ans = std::cmp::min(ans, i64::abs(753 - x));
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <deque>
#include <stack>
#include <iomanip>
#include <cmath>


using namespace std;


typedef long long ll;
typedef long double ld;


const ll MOD = 1000000007ll;


ll modSum(ll a, ll b) {
  return ((a % MOD) + (b % MOD)) % MOD;
}


ll modProd(ll a, ll b) {
  return ((a % MOD) * (b % MOD)) % MOD;
}


ll getPowMod(ll x, ll e) {
  if (e == 0) return 1;
  if (e % 2 == 0) {
    ll tmp = getPowMod(x, e/2);
    return modProd(tmp, tmp);
  } else {
    ll tmp = getPowMod(x, e-1);
    return modProd(tmp, x);
  }
}


ll getPow(ll x, ll e) {
  if (e == 0) return 1;
  if (e % 2 == 0) {
    ll tmp = getPow(x, e/2);
    return tmp * tmp;
  } else {
    ll tmp = getPow(x, e-1);
    return tmp * x;
  }
}


bool isEven(ll x) {
  ll tmp = ((x % 2) + 2) % 2;
  return tmp == 0;
}


ll getSumOfDigitsInBase(ll n, ll b) {
  ll ret = 0;
  while (n > 0) {
    ret += n % b;
    n /= b;
  }
  return ret;
}


vector<int> getKMP(string &s) {
  int len = (int)s.size();
  vector<int> ret (len, 0);
  for (int i = 1 ; i < len ; i++) {
    int at = ret[i-1];
    while (at > 0 && s[i] != s[at]) {
      at = ret[at-1];
    }
    if (s[i] == s[at]) {
      at++;
    }
    ret[i] = at;
  }
  return ret;
}















const int MAXN = 500001;


int N;
string s;
int memo_pre[MAXN], memo_suf[MAXN];


void input() {
  cin >> s;
  N = (int)s.size();
}

void preprocess() {
}


pair<int, int> getAns() {
  bool same = true;
  for (int i = 1 ; i < N ; i++) {
    if (s[i] != s[0]) {
      same = false;
    }
  }
  if (same) {
    return {N, 1};
  }
  vector<int> pre_fault = getKMP(s);
  string r = s;
  reverse(r.begin(), r.end());
  vector<int> suf_fault = getKMP(r);
  for (int i = 0 ; i < N ; i++) {
    if (pre_fault[i] != 0 && (i+1) % (i-pre_fault[i]+1) == 0) {
      memo_pre[i] = 1;
    }
    if (suf_fault[i] != 0 && (i+1) % (i-suf_fault[i]+1) == 0) {
      memo_suf[N-1-i] = 1;
    }
  }
  if (memo_pre[N-1] == 0) {
    return {1, 1};
  }
  int count = 0;
  for (int i = 0 ; i < N-1 ; i++) {
    if (memo_pre[i] == 0 && memo_suf[i+1] == 0) {
      count++;
    }
  }
  /*
  for (int i = 0 ; i < N ; i++) {
    cerr << "pre_fault[" << i << "] = " << pre_fault[i] << "\n";
    cerr << "memo_pre[" << i << "] = " << memo_pre[i] << "\n";
  }*/
  return {2, count};
}


void solve() {
  auto p = getAns();
  cout << p.first << "\n" << p.second << "\n";  
}


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

  int T;
//  cin >> T;
  T = 1;

  for (int i = 0 ; i < T ; i++) {
    input();
    preprocess();
    solve();
  }

  return 0;
}


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

using namespace std;

int main(int argc, char const *argv[])
{
    vector<int> ns;
    int n = 0;

    cin >> n;

    while(n--) {
        int t;
        cin >> t;
        ns.push_back(t);
    }

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

    int half = ns.size()/2;

    cout << (ns[half]-ns[half-1]) << endl;
    return 0;
}

Measured memory_bytes: 892