akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
using Graph = vector<vector<int> >;
using GraphC = vector<vector<char> >;
const int INF = 100000000;
typedef pair<int, int> P;
const int MAX_N = 1000000;

int A, B;

int main() {
	
	cin >> A >> B;
	int ans = 0;
	for (int i = A; i <= B; i++)
	{
		bool ok = true;
		string tmp = to_string(i);
		int N = tmp.size(); N--;
		for (int j = 0; j <= N; j++)
		{
			
			if (tmp.at(j)!= tmp.at(N))
			{
				ok = false;
				break;
			}
			N--;
		}
		if (ok)
		{
			ans++;
		}
		
	}
	cout << ans << endl;
}

Measured memory_bytes: 3636
n=int(input())
L=[[] for _ in range(n)]
ans=0
for i in range(n):
    L[i]=sorted(list(input()))
L=sorted(L)
tmp=1
ans=0
for i in range(n-1):
    if L[i]==L[i+1]:
        tmp+=1
    else:
        ans+=tmp*(tmp-1)//2
        tmp=1
ans+=tmp*(tmp-1)//2
print(ans)

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

using namespace std;

typedef long long ll;

int main() {
  int n, q; ll k;
  cin >> n >> k >> q;
  vector <ll> p(n, 0);
  ll tobe = 0;
  for(int i = 0; i < q; i++) {
    int x; cin >> x;
    x--;
    tobe -= 1;
    p[x] += 1;
  }
  for(int i = 0; i < n; i++) {
    if(p[i] + k + tobe > 0) {
      puts("Yes");
    } else {
      puts("No");
    }
  }
}


Measured memory_bytes: 1408
#include<iostream>
#include<vector>
#include<utility>
#include<math.h>
#define MOD 1000000007
#define lli long long
using namespace std;

bool cmp(pair<int,double> left,pair<int,double> right){
	return left.second<right.second;
}
lli fac[2001], inv[2001], finv[2001];

void COMinit(){
	fac[0]=fac[1]=1;
	inv[0]=inv[1]=1;
	finv[0]=finv[1]=1;
	for(int i=2;i<2001;i++){
		fac[i]=fac[i-1]*i%MOD;
		inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
		finv[i]=finv[i-1]*inv[i]%MOD;
	}
}

lli COM(lli n,lli k){
	COMinit();
	if(n<0||k<0||n<k)return 0;
	return (fac[n]*finv[n-k]%MOD)*finv[k]%MOD;	
}

int main(){
	int n,k;
	cin >>n >>k;
	for(int i=1;i<=k;i++){
		cout << (lli)(COM(n-k+1,i)*COM(k-1, i-1))%MOD <<'\n';
	}
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> piipi;
typedef pair<pii, pii> piipii;

#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define eb emplace_back
int a[5005], b[5005][205];
int l[5005], r[5005];
ll sum[5005];
ll dp[5005][5005];
int main(){
    int n, m;
    scanf("%d%d", &n, &m);
    for(int i=2;i<=n;i++){
        scanf("%d", &a[i]);
        sum[i] = sum[i-1] + a[i];
    }   
    for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) scanf("%d", &b[i][j]);
    for(int j=1;j<=m;j++){
        stack<int> st;
        for(int i=1;i<=n;i++){
            while(!st.empty() && b[st.top()][j] < b[i][j]) st.pop();
            if(st.empty()) l[i] = 0;
            else l[i] = st.top();
            st.push(i);
        }
        while(!st.empty()) st.pop();
        for(int i=n;i>=1;i--){
            while(!st.empty() && b[st.top()][j] <= b[i][j]) st.pop();
            if(st.empty()) r[i] = n+1;
            else r[i] = st.top();
            st.push(i);
        }
        for(int i=1;i<=n;i++){
            l[i]++, r[i]--;
            dp[l[i]][i] += b[i][j];
            dp[l[i]][r[i]+1] -= b[i][j];
            dp[i+1][i] -= b[i][j];
            dp[i+1][r[i]+1] += b[i][j];
        }
    }
    ll ans = 0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            dp[i][j] += dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1];
            if(i <= j) ans = max(ans, dp[i][j] - (sum[j] - sum[i]));
        }
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 203392
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <bitset>
#include <cmath>
#define ll long long
#define intinf 0x7f7f7f7f
#define llinf 0x7f7f7f7f7f7f7f7f
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define ALL(x) for(int i=head[x];i;i=e[i].u)
#define pii pair<int,int> 
#define mp make_pair
#define fi first
#define se second
using std::map;
using std::set;
using std::vector;
using std::bitset;
using std::sqrt;
using std::pair;
int n,k,s;
signed main() {
  scanf("%d %d %d",&n,&k,&s);
  if(s==1e9) {
    rep(i,1,k) printf("%d ",s);
    rep(i,1,n-k) printf("1 ");
  }
  else {
    rep(i,1,k) printf("%d ",s);
    rep(i,1,n-k) printf("%d ",s+1);
  }
}

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

int main(){
	ll x;

	cin >> x;

	ll cnt = 0;
	ll money = 100;
	while(1){
		cnt++;
		money = money * 1.01;
		if(money >= x){
			break;
		}
	}

	cout << cnt;
	return 0;
}


Measured memory_bytes: 3636
N = int(input())
A = list(map(int, input().split()))
import numpy
B = numpy.array(A)
b = numpy.average(A)
ans = 0
dif = abs(A[0] - b)
for i in range(1, N):
    a = abs(A[i] - b)
    if a < dif:
        dif = a
        ans = i
print(ans)

Measured memory_bytes: 27188
#include<iostream>
#include<cmath>

using namespace std;

int main(void){
    int a,b,c;
    cin >> a >> b >> c;
    if(a==b&&a!=c){
        cout << "Yes";
    }else if(a==c&&a!=b){
        cout << "Yes";
    }else if(b==c&&a!=b){
        cout << "Yes";
    }else{
        cout << "No";
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		// 整数の入力
		int n = sc.nextInt();

		int h[] = new int[n];

		/* 配列に読み込み */
		for(int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
		}

		int i = 1;
		int j = 1;

		while(i < n) {
			if(h[i-1] <= h[i]) {
				i++;
				continue;
			} else {
				if(j > i) {
					System.out.println("No");
					System.exit(0);
				} else {
					i = j++;

					h[i-1]--;

					if(i > 1 && h[i-2] > h[i-1]) {
						h[i-1]++;
					}
				}
			}
		}

		System.out.println("Yes");

        sc.close();
	}
}

Measured memory_bytes: 50852
#include<bits/stdc++.h>
using namespace std;
int x[22];
int a,b,c;
int y[22][22];
int ans=1e9;
int sum;
int check[22];
void dfs(int i)
{
	if(i>a){
		for(int j=1;j<=b;j++)
			if(check[j]<c)
				return ;
		ans=min(ans,sum);
		return ;
	}
	dfs(i+1);
	sum+=x[i];
	for(int j=1;j<=b;j++)
		check[j]+=y[i][j];
	dfs(i+1);
	sum-=x[i];
	for(int j=1;j<=b;j++)
		check[j]-=y[i][j];
}
int main()
{
	cin>>a>>b>>c;
	for(int i=1;i<=a;i++){
		cin>>x[i];
		for(int j=1;j<=b;j++)
			cin>>y[i][j];
	}
	dfs(1);
	if(ans==1e9)
		cout<<-1<<endl;
	else
		cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3552
from collections import deque
ans = []
while True:
    w, h = [int(x) for x in input().split()]
    if w == 0 and h == 0: break
    maze = [[1 for _ in range(2 * w + 1)] for _ in range(2 * h + 1)]
    for y in range(1, 2 * h):
        if y % 2 == 1:
            maze[y][2 : 2 * w : 2] = [int(x) for x in input().split()]
            maze[y][1 : 2 * w : 2] = [0] * w
        else:
            maze[y][1 : 2 * w : 2] = [int(x) for x in input().split()]

    que = deque([(1, 1, 0)])
    while que:
        y, x, d = que.popleft()
        if (y, x) == (2 * h - 1, 2 * w - 1):
            ans.append(d + 1)
            break
        for dy, dx in [(0, 1), (0, -1), (1, 0), (-1, 0)]:
            wy = y + dy
            wx = x + dx
            if maze[wy][wx] == 1: continue # 壁
            ny = y + 2 * dy
            nx = x + 2 * dx
            if maze[ny][nx] == 1: continue # 訪問済み
            maze[ny][nx] = 1 # 訪問済みにする
            que.append((ny, nx, d + 1))
    else:
        ans.append(0)

for i in ans:
    print(i)


Measured memory_bytes: 6064
#include<iostream>


using namespace std;

int main() {


	int retsu[32] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };

	int k;

	cin >> k;

	cout << retsu[k - 1] << endl;

	return 0;

}

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

int main() {
	int N;
	cin >> N;
	vector<int> vecV(N);
	for (int i = 0; i < N; i++) {
		cin >> vecV.at(i);
	}
	vector<int> vecC(N);
	for (int i = 0; i < N; i++) {
		cin >> vecC.at(i);
	}
	int sum = 0;
	for (int i = 0; i < N; i++) {
		if (vecV.at(i) > vecC.at(i)) {
			sum += vecV.at(i) - vecC.at(i);
		}
	}
	cout << sum << endl;
}

Measured memory_bytes: 256
/* {{{ Shinobu kawaii */
/*
  ______   __        _                  __                 
.' ____ \ [  |      (_)                [  |                
| (___ \_| | |--.   __   _ .--.   .--.  | |.--.   __   _   
 _.____`.  | .-. | [  | [ `.-. |/ .'`\ \| '/'`\ \[  | | |  
| \____) | | | | |  | |  | | | || \__. ||  \__/ | | \_/ |, 
 \______.'[___]|__][___][___||__]'.__.'[__;.__.'  '.__.'_/ 

*/
// clang-format off
/* }}} */

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

// #define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* cpp template {{{ */

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << '\n';}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {REP(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}
// clang-format on
/* }}} */

int dp[4010][4010];

signed main() {
  string s, t;
  while (cin >> s >> t) {
    fill(ALL(dp[0]), 0);
    int ans = 0;
    REP(i, s.size()) REP(j, t.size()) {
      if (s[i] == t[j]) {
        dp[i + 1][j + 1] = dp[i][j] + 1;
      } else {
        dp[i + 1][j + 1] = 0;
      }
      chmax(ans, dp[i + 1][j + 1]);
    }
    print(ans);
  }

  return 0;
}

Measured memory_bytes: 65764
n,k=map(int,input().split())
d=list(map(int,input().split()))
possible=set()
for i in range(0,10):
    if i not in d:
        possible.add(str(i))
for i in range(n,100000):
    i=str(i)
    for j in i:
        if j not in possible:
            break
    else:
        print(i)
        exit()


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

int main(){
	char* str1=new char[100];
	char* str2=new char[100];
	memset(str1,'\0',100);
	memset(str2,'\0',100);
	int num1=0;
	int num2=0;
	int score1=0;
	int score2=0;

	scanf("%d",&num1);
	for(int i=0; i<num1; i++){
		scanf("%s",str1);
		scanf("%s",str2);
		if((int)strlen(str1)>=(int)strlen(str2)){
			num2=(int)strlen(str1);
		}else{
			num2=(int)strlen(str2);
		}
		for(int t=0; t<num2; t++){
			if((int)str1[t]>(int)str2[t]){
				score1+=3;
				break;
			}else if((int)str1[t]<(int)str2[t]){
				score2+=3;
				break;
			}
			if((int)strlen(str1)==(int)strlen(str2) && t==num2-1){
				score1++;
				score2++;
				break;
			}
		}
	}
	printf("%d %d\n",score1,score2);
	delete [] str1;
	delete [] str2;

	return 0;
}



Measured memory_bytes: 2732
#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;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1 << 30)
#define LLINF (1LL << 60)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll> a(n + 1), b(n);
    ll ans = 0;
    for (ll i = 0; i < n + 1; i++)
    {
        cin >> a[i];
        ans += a[i];
    }
    for (ll i = 0; i < n; i++)
    {
        cin >> b[i];
    }
    for (ll i = 0; i < n; i++)
    {
        ll tmp = b[i] - a[i];
        if (tmp > 0)
        {
            a[i] = 0;
            a[i + 1] = max(0LL, a[i + 1] - tmp);
        }
        else
        {
            a[i] -= b[i];
        }
    }
    for (auto e : a)
    {
        ans -= e;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
let n, x = Scanf.scanf " %d %d" @@ fun a b -> a, b
let ls = Array.init n @@ fun _ -> Scanf.scanf " %d" @@ (+) 0
let d = ref 0
let ans = ref 1
let _ =
  for i = 0 to n - 1 do
    d := !d + ls.(i);
    if !d <= x then incr ans
  done;
  Printf.printf "%d\n" !ans

Measured memory_bytes: 384
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define mod 1000000007
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a,ll b) {
    if (b==0) return 1;
    ll c = power(a,b>>1);
    c = (c*c)%mod;
    if (b&1) return (c*a)%mod;
    return c;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int N = (int)1e5+5;
const int Q = 301;

void solve() {
	int h,a;
  cin>>h>>a;
  cout<<(h+a-1)/a;
}
int main() {
    //freopen("output.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        cout<<"\n";
    }
}


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

int main() {
  int N, M;
  string s[101], t[101];

  cin >> N;
  for(int i=0; i<N; ++i) cin >> s[i];
  cin >> M;
  for(int i=0; i<M; ++i) cin >> t[i];
  
  int max = 0;
  for(int i=0; i<N; ++i){
    string word = s[i];
    int p = 0;
    for(int j=0; j<N; ++j) if(word == s[j]) p++;
    for(int k=0; k<M; ++k) if(word == t[k]) p--;
    if(p > max) max = p;
  }
  
  cout << max << endl;
}

Measured memory_bytes: 256
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        doit(args, new Scanner(System.in), System.out);
    }

    static void doit(String[] args, Scanner scanner, PrintStream out) {
        int n = scanner.nextInt();
        for (int i = 0; i < n; i++) {
            int[] lengths = { scanner.nextInt(), scanner.nextInt(),
                    scanner.nextInt() };
            Arrays.sort(lengths);
            String result = lengths[0] * lengths[0] + lengths[1] * lengths[1] == lengths[2]
                    * lengths[2] ? "YES" : "NO";
            out.println(result);
        }
    }
}

Measured memory_bytes: 12000
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.function.Consumer;

import static java.util.stream.Collectors.toList;

public class Main {
    private static final Scanner scanner = new Scanner(System.in);
    private static final Consumer<List<String>> consumer = solve();

    public static void main(String[] args) {
        consumer.accept(readInput());
    }

    private static List<String> readInput() {
        final List<String> lineList = new ArrayList<>();
        while (scanner.hasNextLine()) {
            lineList.add(scanner.nextLine());
        }
        return lineList;
    }

    private static Consumer<List<String>> solve() {
        return args -> {
            final char[] numList = args.get(0).toCharArray();

            Integer ans = 0;
            {
                Boolean isOdd0 = numList[0] == '0';
                for (int i = 0; i < numList.length; i++) {
                    if ((i % 2 == 0 && numList[i] == (isOdd0 ? '1' : '0')) || ((i % 2 == 1 && numList[i] == (isOdd0 ? '0' : '1')))) {
                        ans++;
                    }
                }
            }

            Integer recAns = 0;
            {
                Boolean isOdd0 = numList[numList.length - 1] == '0';
                for (int i = 0; i < numList.length; i++) {
                    if ((i % 2 == 0 && numList[numList.length - 1 - i] == (isOdd0 ? '1' : '0')) || ((i % 2 == 1 && numList[numList.length - 1 - i] == (isOdd0 ? '0' : '1')))) {
                        recAns++;
                    }
                }
            }

            System.out.println(Math.min(ans, recAns));
        };
    }

}


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

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

const llong inf = 1100100100100100ll;
const llong mod = 1e9+7;

int main() {
	llong a, b, k;

	cin >> a >> b >> k;

	vector<llong> v;

	for (int i = 100; i >= 1; --i)
		if (a%i == 0 && b%i == 0)
			v.push_back(i);

	cout << v[k-1] << endl;

	return 0;
}

Measured memory_bytes: 256
n = int(input())
list1 = []
for x in range(n):
    list1.append(input())
list1.sort()
cnts = [1]
vals = [list1[0]]
pos = 1
max_cnt = 0
max_val = []
while pos<n:
    if cnts[-1]>max_cnt:
        max_cnt = cnts[-1]
        max_val = [vals[-1]]
    elif cnts[-1]==max_cnt:
        max_val.append(vals[-1])
    if list1[pos]==vals[-1]:
        cnts[-1]+=1
    else:
        cnts.append(1)
        vals.append(list1[pos])
    pos+=1
if cnts[-1]>max_cnt:
        max_cnt = cnts[-1]
        max_val = [vals[-1]]
elif cnts[-1]==max_cnt:
        max_val.append(vals[-1])
max_val.sort()
for item in max_val:
    print(item)

Measured memory_bytes: 24764
N,M = map(int,input().split())
H = [0]
H.extend(list(map(int,input().split())))

R = [[] for _ in range(N+1)]
for i in range(M):
  a,b = map(int,input().split())
  R[a].append(b)
  R[b].append(a)

ans = N

# print(H)
# print(R)

for i in range(1,N+1):
  for j in R[i]:
    if H[i] <= H[j]:
      ans = ans - 1
      break


print(ans)      







Measured memory_bytes: 29336
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

template<typename T>
T gcd(T a, T b) {
	if( a < b ) swap(a, b);
	
	T r;
	while( r = a % b ) {
		a = b;
		b = r;
	}
	
	return b;
}

template<typename T>
T lcm(T a, T b) {
	return (a / gcd(a, b)) * b;
}
int main(void) {
	int n;
	cin >> n;
	
	vector<ll> t(n);
	for(int i = 0; i < n; ++i) {
		cin >> t[i];
	}
	
	ll ans = 1LL;
	for(int i = 0; i < n; ++i) {
		ans = lcm(ans, t[i]);
	}
	
	cout << ans << endl;
	
	return 0;
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define itn long long

typedef long long ll;
typedef pair<ll,ll> p;


int main()
{
  int n;
  cin >> n;
  vector<int> v(n, 0);
  int res = 0;
  for (int i = 0; i < n; i++)
  {
    cin >> v[i];
  }
  int tmp = v[0];
  for (int i = 1; i < n; i++)
  {
    // cout << i << endl;
    if(tmp == v[i]) {
      res++;
      tmp = -1;
      continue;
    }
    tmp = v[i];
  }
  cout << res << endl;

}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    long long int x,y;
    cin >> x >> y;
    if(x % y == 0)
    {
        cout << "-1\n";
    }
    else
    {
        cout << x << "\n";
    }

    return 0;
}

Measured memory_bytes: 256
import fractions
from functools import reduce
n=int(input())
a=list(map(int,input().split()))
p=10**9+7
def lcm_base(x,y):
    return (x*y)//fractions.gcd(x,y)
def lcm(*numbers):
    return reduce(lcm_base,numbers,1)
num=lcm(*a)
l=0
for i in range(n):
  l+=num*pow(a[i],p-2,p)
print(l%p)
  
  
  
  
  
  


Measured memory_bytes: 69592
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
    vector<char*> tmp;
    int ans;
    string s;
    cin >> s;
    int num[4];
    for(int i=0; i<4; i++){
        num[i] = s[i] - '0';
    }

    for(int bit=0; bit < (1<<3); bit++){
        ans = num[0];
        for(int i=0; i<3; i++){
            if(bit & (1<<i)){
                ans += num[i+1];
            }else{
                ans -= num[i+1];
            }
        }

        if(ans == 7){
            cout << num[0];
            for(int i=0; i<3; i++){
                if(bit & (1<<i)){
                    cout << '+' << num[i+1];
                }else{
                    cout << '-' << num[i+1];
                    ans -= num[i+1];
                }
            }
        cout << "=7" << endl;
        return 0;
        }

    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
void ABC50(void);
void ABC51(void);
void ABC52(void);
void ABC53(void);
void ABC54(void);
void ABC55(void);
void ABC56(void);
void ABC57(void);
void ABC58(void);
void ABC59(void);

int main(void){
    ABC54();
}

void ABC54(){
    int n,m,ans=0,i,j,k,l,count=0;
    cin>>n>>m;
    char a[n][n],b[m][m];
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            cin>>a[i][j];
        }
    }
    for(i=0;i<m;i++){
        for(j=0;j<m;j++){
            cin>>b[i][j];
        }
    }
    //Bの左上を指定
    for(i=0;i<=n-m;i++){
        for(j=0;j<=n-m;j++){
            //Bの画像とAの画像を比較
            for(k=0;k<m;k++){
                for(l=0;l<m;l++){
                    if(b[k][l]==a[i+k][j+l])count++;
                }
            }
            if(count==m*m)ans=1;
            count=0;
        }
    }
    if(ans)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
use std::io::stdin;

fn main() {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.clear();
    stdin().read_line(&mut buf).unwrap();
    let mut input: Vec<i32> = buf.trim().split_whitespace().map(|iter| iter.parse::<i32>().unwrap()).collect();
    input.sort();
    input.reverse();
    let mut alice = 0;
    let mut bob = 0;
    for index in 0..input.len(){
        match index {
            even if even % 2 == 0 => alice += input[index],
            even if even % 2 == 1 => bob += input[index],
            _ => panic!(),
        }
    }

    println!("{}", alice - bob);
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
//#include <string>
#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 10000100
//#define NIL -1

bool cmp_f(const pair<LL, LL> &x, const pair<LL, LL> &y)
{
    return x.first < y.first;
}

bool cmp_s(const pair<LL, LL> &x, const pair<LL, LL> &y)
{
    return x.second > y.second;
}

int main() {
    LL n;
    LL a;
    LL b;
    LL c;
    LL d;
    LL ans=0;
    cin >> n;
    vector<pair<LL, LL>> ab(n);
    vector<pair<LL, LL>> cd(n);
    vector<bool> ab_end(n, false);
    for(LL i=0; i<n; i++){
        cin >> a >> b;
        ab[i]=make_pair(a, b);
    }

    sort(ab.begin(), ab.end(), cmp_s);

    for(LL i=0; i<n; i++){
        cin >> c >> d;
        cd[i]=make_pair(c, d);
    }

    sort(cd.begin(), cd.end(), cmp_f);

    for(LL i=0; i<n; i++){
        for(LL j=0; j<n; j++){
            if(ab_end[j]==false){
                if(ab[j].first<cd[i].first && ab[j].second < cd[i].second){
                    ans++;
                    ab_end[j]=true;
                    break;
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3616
import java.util.*;
public class Main {

		static void solve() {
			Scanner sc = new Scanner(System.in);
			int n = sc.nextInt();
			int res = 0;
			int[] array = new int[n];
			for(int i = 0;i<n;i++) {
				array[i] = sc.nextInt();
				res+=array[i];
			}
			int max = array[0];
			for(int num :array) {
				if(max<=num) {
					max = num;
				}
			}
			System.out.println((res-max)+max/2);
			sc.close();
		}
	public static void main(String[] args) {
		solve();

	}

}

Measured memory_bytes: 21588
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
const long long mod = 1e9 + 7;

int main(){
    int n, k, q;
    cin >> n >> k >> q;
    int h[n];
    rep(i,n){
         h[i] = k - q;
    }
    int a;
    rep(i,q){
         cin >> a;
         a--;
         h[a]++;
    }
    rep(i,n){
         if(h[i] > 0) cout << "Yes" << endl;
         else cout << "No" << endl;
    }
}

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

using namespace std;

#define boost ios::sync_with_stdio(0);cin.tie(0);
#define forn(i,n) for ( int i=0 ; i < n ; i++ )
#define all(a) (a).begin(), (a).end()
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define ll long long
#define endl '\n'
#define mod 1000000007

int b[200022];

int main()
{
	// freopen ("f.in","r",stdin);
 	// freopen ("f.out","w",stdout);
	boost
	//code
	int n;
	cin >> n;
	ll ans = 0;
	vector<ll> a(n);
	forn(i,n) cin >> a[i];
	sort(all(a));
	int mid = (n-1)/2;
	int that = 1;
	b[0] = a[mid];
	int i,j;
	i = n-1;j=0;
	while(i>=0&&j<n){
		if(i!=mid) b[that++] = a[i];
		if(j!=mid&&j!=i) b[that++] = a[j];
		i--;j++;
	}
	ll pre = b[0];
	for(int i=1;i<n;i++) {
		ans += abs(pre-b[i]);
		pre = b[i];
	}
	ll other = 0;
	mid = (n-1)/2;
	that = 1;
	b[0] = a[mid];
	i,j;
	i = n-1;j=0;
	while(i>=0&&j<n){
		if(j!=mid&&j!=i) b[that++] = a[j];
		if(i!=mid) b[that++] = a[i];
		i--;j++;
	}
	pre = b[0];
	for(int i=1;i<n;i++) {
		other += abs(pre-b[i]);
		pre = b[i];
	}
	cout << max(ans,other) << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <iostream>
#include <vector>

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

    if (a + b >= c) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }
}


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

int main(){
  int n;
  cin >> n;
  int i,j,k,l;
  string s,o;
  getline(cin,s);
  while(n--){
    getline(cin,s);
    bool f =false;
    
    for(i=1;i<26;i++){
      if(f) break;
      if(i%2==0||i%13==0) continue;
      for(j=0;j<26;j++){
	o=s;
	for(k=0;k<s.size();k++){
	  if(s[k]==' ') continue;
	  o[k]=(((s[k]-'a')*i+j)%26)+'a';
	}
	
	if(o.find("this")!=-1||o.find("that")!=-1)
	  f=true;
	
	if(f){
	  cout << o << endl;
	  break;
	}
      }
    }
  }
  
  return 0;
}

Measured memory_bytes: 1212
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int gcd(int a, int b)
{
  return b ? gcd(b, a%b) : a;
}
int main()
{
  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)
    ans = gcd(ans,A[i]);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
//g++ -std=c++14 test.cpp -o test.out
//問題URL
//https://atcoder.jp/contests/exawizards2019/tasks/exawizards2019_c

//2部探索が使える場合：
//nで成り立つ時、n-1でも成り立つみたいな時

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <map> 
#include <unordered_map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N,Q;
string S;
char T[200000],D[200000];

LL ans = 0;

//左から押し出されるなら-1
//押し出されないなら0
//右から押し出されるなら1を返す
int simulate(int index){
	int p = index;
	for(int i=0;i<Q;i++){
		if(S[p]==T[i]){
			if(D[i]=='L') p--;
			if(D[i]=='R') p++;
			if(p<0) return -1;
			if(p>=N) return 1;
		}
	}
	return 0;
}

void solve(){
	//左から何番目までが左から押し出されるか
	int L;
	{
		int left = 0;
		int right = N;
		while(left+1<right){
			int center = (left+right)/2LL;
			if(simulate(center)==-1) left = center;
			else right = center;
		}
		L = left;
	}

	//右から何番目までが左から押し出されるか
	int R;
	{
		int left = 0;
		int right = N;
		while(left+1<right){
			int center = (left+right)/2LL;
			if(simulate(center)==1) right = center;
			else left = center;
		}
		R = right;
	}

	ans = R - L - 1;
}

int main(){
    cin >> N >> Q;
    cin >> S;
    for(int i=0;i<Q;i++) cin >> T[i] >> D[i];

    solve();

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

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

int n, k, a[102];
bool dp[100002];

int main(){
	cin >> n >> k;
	for (int i=0;i<n;i++) cin >> a[i];
	memset(dp,0,sizeof dp);
	for (int i=0;i<=k;i++){
		for (int j=0;j<n;j++){
			if (i-a[j]<0) continue;
			if (dp[i-a[j]]==0) dp[i]=1;
		}
	}
	cout << (dp[k] ? "First" : "Second") << "\n";
}

Measured memory_bytes: 384
// In the name of god
#include <bits/stdc++.h>
#pragma GCC optimze("02")
#define F first
#define S second
#define pb push_back
using namespace std;
using ll = long long;
const ll maxn=1e5+5,inf=1e18+18;
ll n,m;
int main(){
	ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0);
	cin>>n;
	if(n>1799)cout<<1;
	else if(n>1599)cout<<2;
	else if(n>1399)cout<<3;
	else if(n>1199)cout<<4;
	else if(n>999)cout<<5;
	else if(n>799)cout<<6;
	else if(n>599)cout<<7;
	else cout<<8;
}


Measured memory_bytes: 3664
import java.util.Scanner;

public class Main{
    public static void cut(int[] a, int p, int c){
        int[] temp = new int[c];
        for(int i=0; i<c; i++) temp[i] = a[p+i-1];
        for(int i=p-2; i>=0; i--) a[i+c] = a[i];
        for(int i=0; i<c; i++) a[i] = temp[i];
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(true) {
            int n = sc.nextInt();
            int r = sc.nextInt();
            if(n==0 && r==0) break;
            int[] Num = new int[n];
            for (int i = 1; i <= n; i++) Num[n - i] = i;
            for (int i = 1; i <= r; i++){
                int p = sc.nextInt();
                int c = sc.nextInt();
                cut(Num, p, c);
            }
            System.out.println(Num[0]);
        }
    }
}


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

using namespace std;

void test1(){
    string s;
    getline(cin,s);
    int k=0;
    char r;
    //cout<<s.size()<<endl;
    for(int i=0;i<s.size();i++){
        //cout<<s[i]<<" ";
        if(s[i]==' '){
            if(i+1>=s.size()) r='Z';
            else r=s[i+1];
            break;
        }
    }
    cout<<"A"<<r<<"C"<<endl;
}
int main()
{
    //freopen("data","r",stdin);
    test1();
    return 0;
}


Measured memory_bytes: 384
N, x = map(int, input().split())
a = list(map(int, input().split()))

res = 0
if a[0] > x:
    res += a[0]-x
    a[0] = x
for i in range(1,N):
    if a[i-1]+a[i] > x:
        tmp = a[i]+a[i-1]-x
        a[i] -= tmp
        res += tmp
print(res)

Measured memory_bytes: 14544
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 999999999
#define MINF -999999999

int main() {
	int n, a, mi = INF,now=0;
	cin >> n;
	REP(i, n) {
		now = 0;
		cin >> a;
		while (a % 2 == 0) {
			a = a / 2;
			now++;
		}
		mi = min(now, mi);
	}
	cout << mi<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
using namespace std;
int main() {
	bool flag = false;
	long long int N, M,ans=0,k=0;
	cin >> N >> M;
	vector<long long int>A(N,0);
	vector<pair<long long int, long long int>>p(M);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		ans += A[i];
	}
	sort(A.begin(),A.end());
	for (int i = 0; i < M; i++)cin >> p[i].second >> p[i].first;
	sort(p.begin(), p.end());
	for (int i = M-1; i >= 0; i--)
	{
		for (int j = 0; j < p[i].second; j++)
		{
			if (A[k] < p[i].first&&k!=N) {
				ans += (p[i].first - A[k]);
				k++;
			}
			else flag = true;
			if (flag)break;
		}
		if (flag)break;
	}
	cout << ans;
}


Measured memory_bytes: 2560
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("avx,tune=native")

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pii;

template<typename T>
using pq_gt = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using pq_lt = priority_queue<T, vector<T>, less<T>>;

#define se second
#define fi first
#define pb push_back

ll a[10100];
ll b[10100];
ll totA, totB;
ll cnt = 0;

int main() {
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    for(int i =0; i < n; ++i) {
    	cin>>a[i];
    	totA+=a[i];
    }
    for(int i = 0; i <n; ++i) {
    	cin>>b[i];
    	totB+=b[i];
    	if(a[i]<b[i]) {
    		cnt +=(b[i]-a[i]+1)/2;
    	}
    }
    if(cnt<=(totB-totA)) {
    	cout<<"Yes\n";
    } else cout<<"No\n";
}

Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cctype>
#define ll long long
using namespace std;
ll read()
{
    ll X=0,w=0; char ch=0;
    while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
    while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
    return w?-X:X;
}
char s[150];
int f1;
int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>s;int l=strlen(s);
	for(int i=0;i<l;i++){
		if(s[i]=='C')f1=1;
		if(s[i]=='F'&&f1==1){
			printf("Yes");return 0;
		}
	}
	printf("No");
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#include <iomanip>
using namespace std;
typedef long long ll;

const ll MOD = 1e9+7;

int main()
{
	int n;
	string s;
	ll ans=0;
	cin>>n;
	cin>>s;
	if(n&1)
	{
		cout<<"No"<<endl;
	}else{
		string half;
		for(int i=0;i<n/2;i++)
			half+=s[i];
		if(s==half+half)
			cout<<"Yes"<<endl;
		else
			cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e9+7
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }
  
  ll max(ll a,ll b){
    if(a>b){
      return a;
    }
    else{
      return b;
    }
  }

ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}

 ll gcd(ll m,ll n){
 	if(n==0){
       return m;
     }
   return gcd(n,m%n);
 }
ll lcm(ll a,ll b){
  ll g=gcd(a,b);
  return a/gcd(a,b)*b;
		

}
int main(){
  
  ll N;
  cin>>N;
  
  vector<ll>T(N);
  
  rep(i,N){
    cin>>T[i];
  }
  
 
  sort(all(T));
  
  ll ans=T[0];
 for(ll i=1;i<N;i++){
   
   ans=lcm(ans,T[i]);
   
  
}

  
  cout<<ans<<endl;
}


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

using namespace std;

#define N 600000

int n,m,a[N],cnt;
char s[N];

int main(){
	scanf("%d%d%s",&n,&m,s+1);
	for (int i=1;i<=n;++i) a[i]=s[i]=='A';
	int t=1,w=n;
	while (m--){
		if (a[t]^(cnt&1)){a[t]=cnt&1; continue;}
		++t; ++w; ++cnt;
		a[w]=1^(cnt&1);
		if (cnt==n){
			if (n&1){
				if (m&1){
					putchar('B');
					for (int i=2;i<=n;++i) putchar(i&1?'A':'B');
					puts("");
				}
				else{
					for (int i=1;i<=n;++i) putchar(i&1?'A':'B');
					puts("");
				}
				return 0;
			}
			else{
				for (int i=1;i<=n;++i) putchar(i&1?'B':'A');
				puts("");
				return 0;
			}
		}
	}
	for (int i=t;i<=w;++i)
		putchar(a[i]^(cnt&1)?'A':'B');
	puts("");
		
	return 0;
}
			

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn=1e6+5;
int main() {
    int n,k;cin>>n;
    vector<vector<int>> edge(n+1);
    for(int i=1;i<n;i++) {
    	int u,v;cin>>v>>u;
    	edge[v].push_back(u);
    	edge[u].push_back(v);
    }
   	cin>>k;
   	vector<int> l(n+1),r(n+1),w(n+1),has(n+1);
   	int root; for(int i=1;i<=k;i++) cin>>root>>w[root],has[root]=1;
   	std::function<bool(int,int,int)> dfs=[&](int u,int fa,bool odd) {
   		if(has[u]) {if(w[u]%2!=odd||w[u]<l[fa]-1||w[u]>r[fa]+1) return false;l[u]=r[u]=w[u];}
   		else {l[u]=l[fa]-1;r[u]=r[fa]+1;}
   		for(auto v:edge[u]) {
   			if(v==fa) continue;
   			if(!dfs(v,u,odd^1)) return false;
   			l[u]=max(l[u],l[v]-1);
   			r[u]=min(r[u],r[v]+1);
   		}
   		if(r[u]<l[u]||(r[u]==l[u]&&l[u]%2!=odd)) return false;
   		return true;
   	};
   	std::function<void(int,int,int)> setval=[&](int u,int fa,int val)  {
   		w[u]=val;
   		for(auto v:edge[u]){
   			if(v==fa) continue;
   			if(val-1>=l[v]&&val-1<=r[v]) setval(v,u,val-1);
   			else setval(v,u,val+1);
   		}
   	};
   	l[0]=-1e9;r[0]=1e9;
   	if(!dfs(root,0,w[root]%2)) return cout<<"No\n",0;
    puts("Yes");
    setval(root,0,w[root]);
    for(int i=1;i<=n;i++) cout<<w[i]<<endl;
    return 0;
}

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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    int N;
    cin >> N;
    int on = 0 ;
    REP(i, N)
    {
        ll a;
        cin >> a;
        if (a % 2 == 1)
            on++;
    }
    if (on % 2 == 0)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop

BIG_NUM = 2000000000
HUGE_NUM = 9999999999999999
MOD = 1000000007
EPS = 0.000000001


global nodes

class Node:
    def __init__(self):
        self.left = -1
        self.right = -1
    def set(self,arg_node_left,arg_node_right):
        self.left = arg_node_left
        self.right = arg_node_right


def Preorder(node_id):
    print(" %d"%(node_id),end = "")

    if nodes[node_id].left != -1:
        Preorder(nodes[node_id].left)

    if nodes[node_id].right != -1:
        Preorder(nodes[node_id].right)


def Inorder(node_id):

    if nodes[node_id].left != -1:
        Inorder(nodes[node_id].left)

    print(" %d"%(node_id),end = "")

    if nodes[node_id].right != -1:
        Inorder(nodes[node_id].right)


def Postorder(node_id):

    if nodes[node_id].left != -1:
        Postorder(nodes[node_id].left)

    if nodes[node_id].right != -1:
        Postorder(nodes[node_id].right)

    print(" %d"%(node_id),end = "")




V = int(input())
nodes = [Node() for _ in range(V)]
in_num = [0]*V


for loop in range(V):
    node_id,left,right = map(int,input().split())
    nodes[node_id].set(left,right)
    if left != -1:
        in_num[left] += 1
    if right != -1:
        in_num[right] += 1

root = -1

for i in range(V):
    if in_num[i] == 0:
        root = i
        break

print("Preorder")
Preorder(root)
print()

print("Inorder")
Inorder(root)
print()

print("Postorder")
Postorder(root)
print()





Measured memory_bytes: 6384
#include<bits/stdc++.h>
#define mod 1000000007
#define int long long
using namespace std;
int dp[2010],cnt,n,k,a[2010],ans;
int fastpow(int x,int y)
{
    int sum=1;
    while(y)
    {
        if(y&1)
        {
            sum=(1ll*sum*x)%mod;
        }
        x=(1ll*x*x)%mod;
        y>>=1;
    }
    return sum;
}
signed main()
{
    scanf("%lld%lld",&n,&k);
    for(int i=1;i*i<=n;i++)//枚举因子
    {
        if(n%i==0)
        {
            a[++cnt]=i;
            if(i*i!=n)
            {
                a[++cnt]=n/i;
            }
        }
    }
    sort(a+1,a+cnt+1);
    for(int i=1;i<=cnt;i++)
    {
        dp[i]=fastpow(k,(a[i]+1)/2);//有多少个回文串
        for(int j=1;j<i;j++)
        {
            if(a[i]%a[j]==0)//去重
            {
                dp[i]=(dp[i]-dp[j]+mod)%mod;
            }
        }
        if(a[i]&1)//统计答案
        {
            ans=(ans+dp[i]*a[i])%mod;
        }else{
            ans=(ans+dp[i]*(a[i]/2))%mod;
        }
    }
    printf("%lld\n",ans);
    return 0;
}

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

#define FORE(i, a) for (auto i = a.begin(); i != a.end(); ++i)
#define REPU(i, a, b) for (int i = (a); i < (b); ++i)
#define REPD(i, a, b) for (int i = (a); i > (b); --i)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

vector<string> split(const string &s, char c) {
	vector<string> v; stringstream ss(s); string x;
	while (getline(ss, x, c)) v.push_back(x);
	return v;
}
#define DEBUG(args...) { vector<string> _v = split(#args, ','); err(_v.begin(), args); }
void err(vector<string>::iterator it) {}
template<typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
	cerr << "[DEBUG] " << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << '\n';
	err(++it, args...);
}

typedef long long ll;
const int MOD = 1000000007;

template<class T, class U> inline T tmin(T a, U b) { return (a < b) ? a : b; }
template<class T, class U> inline T tmax(T a, U b) { return (a > b) ? a : b; }
template<class T, class U> inline void amax(T &a, U b) { if (b > a) a = b; }
template<class T, class U> inline void amin(T &a, U b) { if (b < a) a = b; }
template<class T> T gcd(T a, T b) { while (b != 0) { T c = a; a = b; b = c % b; } return a; }

int main(int argc, char *argv[]) {
	ios_base::sync_with_stdio(false);

	int n; cin >> n;
	vector<int> a(n);
	REPU(i, 0, n) cin >> a[i];
	sort(ALL(a));
	int x = a[0], y = a[n - 1];
	REPU(i, 1, n) {
		int nx = a[i];
		if (a[i] + a[i] > y) nx = y - a[i];
		if (nx > x) x = a[i];
	}
	printf("%d %d\n", y, x);

	return 0;
}


Measured memory_bytes: 640
// https://atcoder.jp/contests/abc045/tasks/arc061_b
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll h, w, n;
    cin >> h >> w >> n;
    set<pii> s1, s2;
    REP(i, n) {
        int a, b;
        cin >> a >> b;
        s1.insert({a, b});
        REP(i, 3) REP(j, 3) {
            int x = a - i;
            int y = b - j;
            if (x >= 1 && x + 2 <= h && y >= 1 && y + 2 <= w) {
                s2.insert({a - i, b - j});
            }
        }
    }
    vector<ll> ans(10, 0);
    for (auto &x : s2) {
        int cnt = 0;
        REP(i, 3) REP(j, 3) {
            if (s1.count({x.first + i, x.second + j}) > 0) {
                cnt++;
            }
        }
        ans[cnt]++;
    }
    ans[0] = (h - 2) * (w - 2);
    FOR(i, 1, 10) ans[0] -= ans[i];
    for (auto &x : ans) {
        cout << x << "\n";
    }

    return 0;
}


Measured memory_bytes: 47104
#include <iostream>
#include <cmath>
#include <climits>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <string>
#include <stack>
#include <algorithm>
#include <map>
#include <numeric>
using namespace std;
// scanf
#pragma warning(disable: 4996)
// v:vector  type:型  order:greater or less
#define _sort(v,type,order) do { sort(v.begin(),v.end(),order<type>()); } while(0)
// vector 要素の総和算出
// v:vector  default_value:初期値
#define _sum(v,default_value) accumulate(v.begin(),v.end(),default_value )
// vector 最大値( return ite )
#define _max_element(v) max_element(v.begin(),v.end())
// vector 最大値が格納されている要素値
#define _max_element_number(v) distance(v.begin(),max_element(v.begin(),v.end()))
// 丸め
#define _round(v) round(v)
// 2乗 / 3乗
#define _square(v) pow(v,2)
#define _cube(v)   pow(v,3)
// 大小判定
#define _max(x,y) max(x,y)
#define _min(x,y) min(x,y)
// string ⇒ int
#define _stringtoi(s) stoi(s)
// double 平方根
#define _sqrt(x) sqrt(x)
// double 引数 x 以上で最小の整数値
#define _ceil(x) ceil(x)
// 指定された要素以上の値が現れる最初の位置のイテレータを取得する
#define _lower_bound(v,min) lower_bound(v.begin(), v.end(), min)
// 指定された要素より大きい値が現れる最初の位置のイテレータを取得する
#define _upper_bound(v,min) upper_bound(v.begin(), v.end(), min)

// 順列 n個の数が与えられる
// 0,1,2,...,n-1
// 全ての並べ方を1行ごとに出力する
// ex 0 1 2 / 0 2 1 / 1 0 2 / 1 2 0 / 2 0 1 / 2 1 0
#define _next_permutation(v) do {   \
	for (auto num : v) {            \
		printf("%d ", num);         \
	}                               \
	printf("\n");                   \
} while (next_permutation(v.begin(), v.end()))

// 絶対値
static int32_t _abs(const int32_t x) { return  (x > 0 ? x : -x); }

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

	uint32_t result = 0;
	
	for (uint32_t i = 0; i < s.length(); i++) {

		if (s[i] != 'A') { continue; }

		if ((i + 2) >= s.length()) {
			break;
		}
		if ((s[i + 1] == 'B') && (s[i + 2] == 'C')) {
			result++;
			i += 2;
		}
	}
	
	printf("%d\n", result);

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define maxn 10005
using namespace std;
typedef long long ll;
ll n,m;
int main()
{
	scanf("%lld%lld",&n,&m); if(n>m) swap(n,m);
	if(n==1)
	{
if(m==1)
return printf("1\n",0),0;
		if(m<=2)
			return printf("0\n"),0;
		else
			return printf("%lld\n",m-2),0;
	}
	else
	{
		return printf("%lld\n",(n-2)*(m-2)),0;
	}
}


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

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

    vector<int> v(100010, 0);
    for (int i = 0; i < N; ++i) {
        int a;
        cin >> a;
        v[a]++;
        v[a + 1]++;
        if (a != 0) {
            v[a - 1]++;
        }
    }

    sort(v.begin(), v.end(), greater<int>());
    cout << v[0] << endl;

    return 0;
}


Measured memory_bytes: 640