akhauriyash/Code-Regression huggingface dataset:
/*
The Lord your God is with you,
the Mighty Warrior who saves.
He will take great delight in you;
in his love he will no longer rebuke you,
but will rejoice over you with singing.
*/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;

const int N = 105;
const int M = 305;
int n, v[N], dp[N][N][M];
ll total, w[N];

void update(int &x, int y) { if (x == -1 || x < y) x = y; }

int main() {
	scanf("%d%lld", &n, &total);
	for (int i = 1; i <= n; ++i) scanf("%lld%d", &w[i], &v[i]);
	memset(dp, -1, sizeof(dp));
	dp[0][0][0] = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			for (int k = 0; k < M-5; ++k) {
				if (dp[i][j][k] == -1) continue;
				update(dp[i + 1][j][k], dp[i][j][k]);
				if (k + w[i + 1] - w[1] < M-5)
					update(dp[i + 1][j + 1][k + w[i + 1] - w[1]], dp[i][j][k] + v[i + 1]);
			}
		}
	}
	int res = -1;
	for (int j = 0; j <= n; ++j) for (int k = 0; k <= M-5; ++k)
		if (w[1] * (ll)j + (ll)k <= total)
			update(res, dp[n][j][k]);
	printf("%d", res);
	return 0;
}


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

const int N = 110;

int h, w, n;
int b[N][N], a[N * N];

int main() {
	scanf("%d%d", &h, &w);
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	int i = 0, j = 1, d = 1;
	for(int cur = 1; cur <= n; ++cur) {
		while(a[cur]) {
			i += d;
			if(i == h + 1) i = h, ++j, d *= -1;
			else if(!i) i = 1, ++j, d *= -1; 
			b[i][j] = cur;
			--a[cur];
		}
	}
	for(int i = 1; i <= h; ++i) {
		for(int j = 1; j <= w; ++j) printf("%d ", b[i][j]);
		puts("");
	}
	return 0;
}

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

int main() {
	long long n;
	cin >> n;
	int a=n/1000;
	int b=(n/100)%10;
	int c=(n/10)%10;
	int d=n%10;
	if(a+b+c+d==7){
		cout<<a<<'+'<<b<<'+'<<c<<'+'<<d<<"=7";
	}else if(a+b+c-d==7){
		cout<<a<<'+'<<b<<'+'<<c<<'-'<<d<<"=7";
	}else if(a+b-c+d==7){
		cout<<a<<'+'<<b<<'-'<<c<<'+'<<d<<"=7";
	}else if(a-b+d+c==7){
		cout<<a<<'-'<<b<<'+'<<c<<'+'<<d<<"=7";
	}else if(a+b-d-c==7){
		cout<<a<<'+'<<b<<'-'<<c<<'-'<<d<<"=7";
	}else if(a-b-d+c==7){
		cout<<a<<'-'<<b<<'+'<<c<<'-'<<d<<"=7";
	}else if(a-b+d-c==7){
		cout<<a<<'-'<<b<<'-'<<c<<'+'<<d<<"=7";
	}else if(a-b-d-c==7){
		cout<<a<<'-'<<b<<'-'<<c<<'-'<<d<<"=7";
	}return 0;
}

Measured memory_bytes: 3660
n,C = map(int,input().split())
imos = [0]*(10**5+2)
ch = [set() for _ in range(C)]
for i in range(n):
    s,t,c = map(int,input().split())
    c -= 1
    if s in ch[c]:
        ch[c].remove(s)
        imos[s+1] +=1
    else:
        ch[c].add(s)
        imos[s] += 1
    if t in ch[c]:
        ch[c].remove(t)
        imos[t] -= 1
    else:
        ch[c].add(t)
        imos[t+1] -= 1
ans = 0
cnt = 0
for i in imos:
    cnt += i
    ans = max(ans,cnt)
print(ans)

Measured memory_bytes: 66776
#include <stdio.h>
#include <iostream>
#include <bits/stdc++.h>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i = 0; i < v.size(); ++i) cin >> v[i];
    
    int diff = 0;
    int min = v[0];
    int maxv = v[1] - v[0];
    if(n > 2){
        for(int i = 2; i < v.size(); ++i){
            if(min > v[i-1]){
                min = v[i-1];
            }
            diff = v[i] - min;
            if(diff > maxv){
                maxv = diff;
            }
        }
    }
    
    cout << maxv << endl;
}


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

int main() {
    int n;
    string s;
    cin >> n >> s;
    stack<char> st1, st2;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '(') {
            st1.push(s[i]);
        } else if (st1.empty() && s[i] == ')') {
            st2.push(s[i]);
        } else if (!st1.empty() && s[i] == ')') {
            st1.pop();
        }
    }
    string ans = "";
    for (int i = 0; i < st2.size(); i++) ans += '(';
    ans += s;
    for (int i = 0; i < st1.size(); i++) ans += ')';
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
from math import factorial
N, M = map(int, input().split())
if N >= 2:
    a = factorial(N) / factorial(2) / factorial(N - 2)
else:
    a = 0
if M >= 2:
    b = factorial(M) / factorial(2) / factorial(M - 2)
else:
    b = 0
print(int(a + b))

Measured memory_bytes: 3064
#import re
import sys
input = sys.stdin.readline
#import heapq
#import bisect
#from collections import deque
#import math

def main():
    n = int(input())
    rgb = input()
    ans = 0
    for moji in ["RGB", "RBG", "BGR", "BRG", "GBR", "GRB"]:
        ans += search(moji, rgb)
    print(ans)

def search(moji, kensaku):
    n = len(kensaku)
    memo1 = []
    r = 0
    g = 0
    b = 0
    red = 0
    for i in range(n):
        if kensaku[i] == moji[0]:
            memo1.append(i)
        elif kensaku[i] == moji[1]:
            for num in memo1:
                check = num + 2 * (i - num)
                if check >= n:
                    continue
                else:
                    if kensaku[check] == moji[2]:
                        red += 1
    for i in range(n):
        if kensaku[i] == moji[0]:
            r += 1
        elif kensaku[i] == moji[1]:
            g += r
        elif kensaku[i] == moji[2]:
            b += g
    ans = b - red
    return ans
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 68316
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <iomanip>
#include <cmath>
using namespace std;

const double Pi = acos(-1);

int main() {
    double d;
    cin >> d;
    cout << d * d << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include<queue>

using namespace std;

int main(void) {
	int n;
	cin >> n;
	long long int ans = 0/*, min = 10e10*/;
	priority_queue<long long int> que;
	for (int i = 0; i < n; i++) {
		long long int temp;
		cin >> temp;
	/*	if (min > temp) {
			min = temp;
		}*/
		que.push(temp);
	}

	long long int max1 = que.top();
	que.pop();

	ans = max1;
	long long int now = n-2;
	while (now != 0) {
		if (now == 1) {
			now--;
			ans += que.top();
			que.pop();
		}
		else {
			now -= 2;
			ans += (que.top() * 2);
			que.pop();
		}
	}


	cout << ans;


	return 0;
}

Measured memory_bytes: 5344
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<numeric>
#include<iomanip>
#include<utility>
#include<cstdlib>
#include<typeinfo>

using namespace std;
typedef long long int lint;
#define INF 1000000005
int main()
{

int n;
std::vector<pair<int,int>> a;
std::cin >> n;
for(int i = 0; i < n; i++){
    int temp;
    std::cin >> temp;
    pair<int,int> aa = make_pair(temp,i);
    a.push_back(aa);
}

std::sort(a.begin(),a.end());
int sume = 0;
int sumo = 0;
for(int i = 0; i < n; i++){
    int bin = i % 2;
    if(a[i].second % 2 != bin){
        if(bin == 0){
            sume++;
        } else {
            sumo++;
        }
    }
}
int sum = 0;
while(sume > 0 && sumo > 0){
    sume--;
    sumo--;
    sum++;
}

std::cout << sume + sumo + sum << std::endl;


return 0;
}

Measured memory_bytes: 1400
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring>
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
//vector<vector<ll>> dp(n,vector<ll>(n))
//2-dim:vector<vector<Type>> vv(n, vector<Type>(m, d));
//3-dim:vector<vector<vector<Type>>> vvv(n, vector<vector<Type>>(m, vector<Type>(l, d)));
const ll MOD = 1e9+7;
const int MAX = 1001001;
long long fac[MAX],finv[MAX],inv[MAX];
void COMinit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i % MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i) % MOD;
        finv[i]=finv[i-1]*inv[i] % MOD;
    }
}
long long COM(int n,int k){
    if(n<k) return 0;
    if(n<0 || k<0) return 0;
    return fac[n]*(finv[k]*finv[n-k] % MOD) % MOD;
}
signed main(){
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    COMinit();
    int s; cin >> s;
    int x=s/3;
    ll ans=0;
    for(int i=1;i<=x;i++){
        int res=s-i*3;
        ans+=COM(res+i-1,i-1);
        ans%=MOD;
    }
    cout << ans << endl;
}




Measured memory_bytes: 27076
#include <bits/stdc++.h>
#define rep(i,n) for ((i)=1;(i)<=(n);(i)++)
#define per(i,n) for ((i)=n;(i)>=(1);(i)--)
using namespace std;
string s1,s2;
int a[100005],b[100005],n,m,q,i,j;
int main()
{
	cin>>s1>>s2>>q;n=s1.size();m=s2.size();
	rep(i,n) a[i]=a[i-1]+(s1[i-1]=='A'?1:2);
	rep(i,m) b[i]=b[i-1]+(s2[i-1]=='A'?1:2);
	while(q--)
	{
		int l1,r1,l2,r2;
		cin>>l1>>r1>>l2>>r2;
		cout<<((a[r1]-a[l1-1])%3==(b[r2]-b[l2-1])%3?"YES\n":"NO\n");
	}
	return 0;
}

Measured memory_bytes: 1664
#include<stdio.h>
int main(void){
    int a,b,c,k;
    scanf("%d %d %d %d",&a,&b,&c,&k);
    if(k<=a){
        printf("%d\n",k);
    }else{
        if(k<=a+b){
            printf("%d\n",a);
        }else{
            printf("%d\n",a-(k-(a+b)));
        }
    }
    return 0;
}

Measured memory_bytes: 1732
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
typedef long double ld;
#define pb push_back
#define fi first
#define se second
const ll mod = 1e9+7;
const int N = 2e5+5;
void solve(){
	int n,a,b; 
	cin>>n>>a>>b; 
	cout<<min(a,b)<<" "<<max(0,a+b-n)<<endl;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1; 
//	cin>>t; 
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
int n,f=1,sum,a[200001];
int main() 
{
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=n;i++)
        if (a[i]==f)
            f++;
		else
            sum++;
    if(f==1)
        cout<<-1;
    else
        cout<<sum;
}

Measured memory_bytes: 4320
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

const ll MOD = 1e9 + 7;

/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/
const int N = 2e5 + 100;

int n, m;
string s;

int gn(int x) {
	return x + 1 - (x % 2);
}

ll dp[N];
ll dp2[N];

void solve(int n) {
	dp[0] = 1;
	dp[1] = 2;
	for (int i = 2; i <= n; ++i) {
		dp[i] = (dp[i - 1] + dp[i - 2]) % MOD;
	}
	ll ans = dp[n];
	if (n >= 4)
		ans = (ans - dp[n - 4] + MOD) % MOD;
	if (n == 2)
		ans = 3;
	if (n == 3)
		ans = 4;
	cout << ans << "\n";
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> m;
	cin >> s;
	if (s[0] != 'R') {
		for (int i = 0; i < m; ++i)
			if (s[i] == 'R')
				s[i] = 'B';
			else
				s[i] = 'R';
	}
	while (!s.empty() && s.back() == 'R')
		s.pop_back();
	if (s.empty()) {
		solve(n);
		return 0;
	}
	int cur = 0;
	while (s[cur] != 'B')
		++cur;
	int l = gn(cur);
	++cur;
	while (cur < s.size()) {
		if (s[cur] == 'B')
			++cur;
		else {
			int c = 0;
			while (s[cur] == 'R')
				++cur, ++c;
			if (c % 2 == 1)
				l = min(l, c);
		}
	}
	if (n % 2 == 1) {
		cout << 0 << "\n";
		return 0;
	}
	++l;
	n /= 2;
	l /= 2;
	dp[0] = 1;
	ll sum = dp[0];
	ll sum2 = 0;
	for (int i = 1; i <= n; ++i) {
		sum2 = (sum2 + sum) % MOD;
		if (i > l) {
			sum = (sum - dp[i - l - 1] + MOD) % MOD;
			sum2 = (sum2 - dp[i - l - 1] * (l + 1) % MOD + MOD) % MOD;
		}
		dp[i] = sum;
		dp2[i] = sum2;
		sum = (sum + dp[i]) % MOD;
	}
	cout << (2 * dp2[n]) % MOD;
	return 0;
}




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

int main(){
    int i,j,k;
    int n,m;
    int a[100],b[100];
    int sum[2]={0};
    int tmp1=101,tmp2=101;
    
    while(1){
        scanf("%d %d",&n,&m);

        if(n==0 && m==0){
            break;
        }

        tmp1=101;
        tmp2=101;

        for(i=0;i<n;i++){
            scanf("%d",&a[i]);
        }
        for(i=0;i<m;i++){
            scanf("%d",&b[i]);
        }

        for(i=0;i<n;i++){
            for(j=0;j<m;j++){
                for(k=0;k<n;k++){
                    if(k==i){
                        sum[0] += b[j];
                    }else{
                        sum[0] += a[k];
                    }
                }
                for(k=0;k<m;k++){
                    if(k==j){
                        sum[1] += a[i];
                    }else{
                        sum[1] += b[k];
                    }
                }

                if(sum[0] == sum[1]){
                    if((tmp1+tmp2) > (a[i]+b[j])){
                        tmp1 = a[i];
                        tmp2 = b[j];
                    }
                }

                sum[0]=0;
                sum[1]=0;

            }

        }
        if(tmp1 == 101){
            printf("-1\n");
        }else{
            printf("%d %d\n",tmp1,tmp2);
        }
    }
    return 0;
                                                                                                                                                                                                                                                                                                               
}


Measured memory_bytes: 1928
formula = list(input().split())
stack = []

for item in formula:
    if item == '+' or item == '-' or item == '*':
        a = stack.pop()
        b = stack.pop()
        if item == '+':
            c = a + b
        elif item == '-':
            c = b - a
        else:
            c = a * b
        stack.append(c)
    else:
        stack.append(int(item))
print(stack.pop())



Measured memory_bytes: 5596
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();

    if (a + b == c || b + c == a || c + a == b) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
    
  }
}

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

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  int i;
  for (i = 0; i < n; i++) {
    cin >> d[i];
  }
  sort(d.begin(), d.end(), greater<int>());
  int result = 1;
  for (i = 1; i < n; i++) {
    if (d[i - 1] > d[i]) {
      result++;
    }
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
	Scanner sc = new Scanner(System.in);
	
	
	
	void run(){
		while(sc.hasNext()){
			int d = sc.nextInt();
			long ans = 0;
			
			for(int x = d; x < 600; x+=d){
				ans += x*x*d;
			}
			
			System.out.println(ans);;
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 17344
import std.conv, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex, std.typecons;
import core.bitop, core.thread;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) throw new EOFException; tokens = readln.split; } auto token = tokens[0]; tokens.popFront; return token; }
int readInt() { return readToken().to!int; }
long readLong() { return readToken().to!long; }
real readReal() { return readToken().to!real; }

void chmin(T)(ref T t, in T f) { if (t > f) t = f; }
void chmax(T)(ref T t, in T f) { if (t < f) t = f; }

int binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = cast(int)(as.length); for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }
int lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a < val)); }
int upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a <= val)); }


immutable INF = 10L^^18;

int N;
long[] A;

void main() {
  try {
    for (; ; ) {
      N = readInt;
      A = new long[N];
      foreach (i; 0 .. N) {
        A[i] = readLong();
      }
      auto ASum = new long[N + 1];
      foreach (i; 0 .. N) {
        ASum[i + 1] = ASum[i] + A[i];
      }
      auto dp = new long[][](N + 1, N + 1);
      foreach (i; 0 .. N + 1) foreach (j; 0 .. N + 1) {
        dp[i][j] = INF;
      }
      foreach (i; 0 .. N) {
        dp[i][i + 1] = 0;
      }
      foreach (w; 2 .. N + 1) {
        for (int i = 0, j = w; j <= N; ++i, ++j) {
          foreach (k; i + 1 .. j) {
            chmin(dp[i][j], dp[i][k] + dp[k][j]);
          }
          dp[i][j] += (ASum[j] - ASum[i]);
        }
      }
      writeln(dp[0][N]);
    }
  } catch (EOFException e) {
  }
}


Measured memory_bytes: 3708
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
 
typedef long long ll;
typedef vector<int> vi;
typedef unsigned long ul;
typedef vector<ll> vl;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef set<int> si;
typedef multiset<int> mi;
 
const ll INF = 1e18;
const int MOD = 1e9+7;
 
int main() {
	
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);

	//ofstream cout ("name.out");
	//ifstream cin ("name.in");

	int n, ans=0;
	string s;
	cin>>n>>s;

	int lhs=0, rhs=n-1;
	while(lhs<rhs) {
		if(s[lhs]=='R') ++lhs;
		else if(s[rhs]=='W') --rhs;
		else ++ans,++lhs,--rhs;
	}

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



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

using namespace std;
using ll = long long;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, x;
  cin >> n >> x;
  cout << (n + 2 * x) / (2 * x + 1) << '\n';
  return 0;
}


Measured memory_bytes: 256
try:
    while True:
        n = int(input())
        if n == 0:
            break
        c = 0
        d = 0
        for i in range(n):
            a, b = map(int, raw_input().split())
            if a > b:
                c += a + b
            elif a == b:
                c += a
                d += b
            else:
                d += a + b

        print str(c) + " " + str(d)

except:
    None

Measured memory_bytes: 4812
H, W = map(int,input().split())
A = []
for _ in range(H):
    A.append(list(input()))
col = []
row = []
for i in range(H):
    if not '#' in A[i]:
        row.append(i)
for i in range(W):
    flag = 1
    for j in range(H):
        if '#' == A[j][i]:
            flag = 0
    if flag:
        col.append(i)
for i in range(H):
    if i in row:
        continue
    for j in range(W):
        if j in col:
            continue
        print(A[i][j], end='')
    print()

Measured memory_bytes: 4596
def main():
    n = int(input())
    *a, = map(int, input().split())

    bool_ = any(x for x in a if (x % 2 == 0) and not (x % 3 == 0 or x % 5 == 0))

    print('DENIED' if bool_ else 'APPROVED')


if __name__ == '__main__':
    main()
    

Measured memory_bytes: 2940
{-# LANGUAGE ScopedTypeVariables #-}

import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Control.Monad

-- Union-Find
type Parent = VUM.IOVector Int
type Size = VUM.IOVector Int

makeUF :: Int -> IO (Parent, Size)
makeUF n = do
    par <- VU.unsafeThaw $ VU.generate n id
    siz <- VUM.replicate n 1
    return (par, siz)

root :: Int -> Parent -> IO Int
root x par = do
    r <- VUM.read par x
    if x == r
        then return x
        else do
            newr <- root r par
            VUM.write par x newr
            return newr

same :: Int -> Int -> Parent -> IO Bool
same x y par = do
    rx <- root x par
    ry <- root y par
    return $ rx == ry

unite :: Int -> Int -> Parent -> Size -> IO ()
unite x y par siz = do
    x' <- root x par
    y' <- root y par
    sx <- VUM.read siz x'
    sy <- VUM.read siz y'
    unless (x' == y') $ 
        if sx < sy
            then do
                VUM.modify siz (+sx) y'
                VUM.write par x' y'
            else do
                VUM.modify siz (+sy) x'
                VUM.write par y' x'

size :: Int -> Parent -> Size -> IO Int
size x par siz = root x par >>= VUM.read siz
    
main = do
    [n,m,k] <- map read . words <$> getLine :: IO [Int]
    (par, siz) <- makeUF (n+1)
    (fre :: VUM.IOVector Int) <- VUM.replicate (n+1) 0
    (blo :: VUM.IOVector Int) <- VUM.replicate (n+1) 0
    forM_ [1..m] $ \_ -> do
        [a,b] <- map read . words <$> getLine :: IO [Int]
        unite a b par siz
        VUM.modify fre (+1) a
        VUM.modify fre (+1) b

    forM_ [1..k] $ \_ -> do
        [c,d] <- map read . words <$> getLine :: IO [Int]
        branch <- same c d par
        when branch $ do
            VUM.modify blo (+1) c
            VUM.modify blo (+1) d
        
    forM_ [1..n] $ \i -> do
        s <- size i par siz
        f <- VUM.read fre i
        b <- VUM.read blo i
        putStr $ show (s - f - b - 1)
        putStr " "
    putStrLn ""

Measured memory_bytes: 6396
#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>
#include <numeric>
#include <bitset>
#include <cassert>
#include <functional>

using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)

int main() {
	ll L, R;
	cin >> L >> R;
	ll mn = 2020;
	if (R / 2019 * 2019 >= L) {
		cout << 0 << endl;
	}
	else {
		for (int i = L; i < R; i++) {
			for (int j = i + 1; j <= R; j++) {
				chmin(mn, ll((i % 2019) * (j % 2019) % 2019));
			}
		}
		cout << mn << endl;
	}
	return 0;
}

Measured memory_bytes: 256
//
// Created on 2020/07/25.
//


#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;


int main() {
    int n;
    cin>>n;
    vector<ll>g(n+1,0);
    g[0] = 1000;
    vector<ll>p(n+1);
    for (int j = 1; j <= n; ++j) {
        cin>>p[j];
    }
    for (int i = 1; i <= n; ++i) {
        ll kabu_num = g[i-1]/p[i];
        ll cash = g[i-1]%p[i];
        
        for (int j = i; j <= n; ++j) {
            if(g[j] < (kabu_num * p[j])+cash) g[j] = kabu_num * p[j]+cash;
        }
    }

    cout<<g[n]<<endl;
    return 0;
}


Measured memory_bytes: 3592
fun main(args: Array<String>) {
    val (H, W) = readInputLine().split(" ").map{it.toInt()}
    val (h, w) = readInputLine().split(" ").map{it.toInt()}
    
    println(H * W - h * W - w * H + h * w)
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 36008
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
using namespace std;

string s;
deque< char > dq;
ll ans;

int main()
{

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

    cin >> s;
    for( auto ch:s ) dq.pb( ch );

    while( !dq.empty() ){
        if( dq.front()!=dq.back() ) ans++;
        dq.pop_back();
        if( !dq.empty() ) dq.pop_front();
    }

    cout << ans;

    return 0;
}


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

using ll = long long;
const ll MAX = 1e18;
int main()
{
    int n;
    cin >> n;
    ll a[n];
    ll val = 1;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        if(a[i] == 0) {
            cout << "0";
            return 0;
        }
    }
    for(int i = 0; i < n; i++) {
        ll x = a[i];
        //if((MAX/val < x) || ((MAX/val == x) && (MAX%val != 0))) {
        if(x > MAX/val) {
            cout << "-1" << endl;
            return 0;
        }
        val *= x;
    }
    cout << val;
}


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


def solve(S: str):
    res = 0
    n = len(S)
    for i in range(n // 2):
        if S[i] == S[-1-i]:
            continue
        res += 1
    print(res)
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int n, l, q;
    std::cin >> n;
    std::vector<int> x(n);
    for (auto &e : x) std::cin >> e;
    std::cin >> l >> q;

    constexpr int m = 16;
    std::vector<std::vector<int>> bin(n, std::vector<int>(m + 1, -1));
    for (int i = 0; i < n; i++) {
        bin[i][0] = std::upper_bound(x.begin(), x.end(), x[i] + l) - x.begin();
        bin[i][0]--;
        if (bin[i][0] == i) bin[i][0] = -1;
    }
    for (int i = 0; i < m; i++) for (int j = 0; j < n; j++) {
        if (bin[j][i] < 0) continue;
        bin[j][i + 1] = bin[bin[j][i]][i];
    }

    while (q--) {
        int a, b;
        std::cin >> a >> b;
        --a; --b;
        if (a > b) std::swap(a, b);
        int ret = 0;
        for (int i = m; i >= 0; i--) {
            if (bin[a][i] >= 0 && bin[a][i] <= b) {
                ret += 1 << i;
                a = bin[a][i];
            }
        }
        std::cout << (a != b ? 1 : 0) + ret << std::endl;
    }

    return 0;
}


Measured memory_bytes: 11392
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

int main(){
    int n;
    cin >> n;
    if(n <= 999){
        cout << "ABC" << endl;
    }else{
        cout << "ABD" << endl;
    }
}

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

const int mod=1e9+7;

ll quick_pow(ll a,ll b){
	ll ans=1;
	while(b){
		if(b&1) ans=ans*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ans;
}

const int maxn=2e6+7;
ll fac[maxn],inv[maxn],f[maxn];

ll C(ll n,ll m){
	if(n<m)  return 0;
	if(m==0) return 1;
	return fac[n]*inv[m]%mod*inv[n-m]%mod;
}

int main (){
	int n;cin>>n;
	fac[0]=1;fac[1]=1;
	for(int i=2;i<=maxn;i++) fac[i]=fac[i-1]*i%mod;
	inv[maxn]=quick_pow(fac[maxn],mod-2);
	for(int i=maxn-1;i>=0;i--) inv[i]=inv[i+1]*(i+1)%mod;
	ll ans=fac[n];
	for(int k=1;k<n;k++){
		ans-=C(k-1,n-k-1)*fac[k]%mod*fac[n-k-1]%mod;
		if(ans<0) ans+=mod;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 32768
#import pprint
n, d = map(int, input().split())
#x = list[int(input().split()) for i range(1, n+1)]
x = [list(map(int, input().split())) for _ in range(n)]
#pprint.pprint(x)

cnt = 0
a = 0
for i in range(n-1):
    for j in range(i+1, n):
        for k in range(d):
            a += (x[i][k]-x[j][k])**2
        if (a**0.5)%1 == 0:
            cnt += 1
            a = 0
        else:
            a = 0
print(cnt)

Measured memory_bytes: 3064
use std::io;
use std::str::FromStr;

fn main(){
    let stdin = io::stdin();
    let mut buf = String::new();

    let _ = stdin.read_line(&mut buf);
    let vec : Vec<i64> = buf.split_whitespace().map(|x| i64::from_str(x).unwrap()).collect();
    let (n, m) = (vec[0] as usize, vec[1] as usize);

    let mut a : Vec<Vec<i64>> = Vec::new();
    for _ in 0..n {
        buf.clear();
        let _ = stdin.read_line(&mut buf);
        a.push(buf.split_whitespace().map(|x| i64::from_str(x).unwrap()).collect());
    }

    let mut b : Vec<i64> = Vec::new();
    for _ in 0..m {
        buf.clear();
        let _ = stdin.read_line(&mut buf);
        b.push(i64::from_str(buf.trim()).unwrap());
    }

    for i in 0..n {
        println!("{}", (0..m).fold(0, |sum, j| sum + a[i][j] * b[j]));
    }
}



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



int main(void)
{
    int N,Y;
    cin >> N >> Y;

    for(int i = 0; i <= N; i++)
    {
        for(int j = 0; j + i <= N; j++)
        {
            if(10000 * i + 5000 * j + 1000 * (N - i - j) == Y)
            {   printf("%d %d %d\n", i, j, N - i - j);
                return 0;
            }
        }
    }

    printf("-1 -1 -1\n");
    
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int k = sc.nextInt();
      String[] d = new String[k];
      for(int i = 0;i < k;i++){
        d[i]=String.valueOf(sc.nextInt());
      }
      int cnt = 0;
      for(int i = n;i < 1000000000;i++){
        String s = String.valueOf(i);
        for(int j = 0;j < s.length();j++){
        	if(Arrays.asList(d).contains(s.substring(j,j+1)))cnt++;
        }
        if(cnt==0){
        	System.out.println(i);
          return;
        }
        cnt = 0;
      }
    }
}

Measured memory_bytes: 38556
#include <stdio.h>
int main()
{
    long int n,d,ct=0;
    scanf("%ld%ld",&n,&d);
    d*=d;
    long int i,x,y;
    for(i=0;i<n;i++)
    {
        scanf("%ld%ld",&x,&y);
        x*=x;
        y*=y;
        if(x+y<=d) ct++;
    }
    printf("%ld",ct);
    return 0;
}


Measured memory_bytes: 1732
// abc061-A.cpp : アプリケーションのエントリ ポイントを定義します。
//

#include <iostream>
using namespace std;

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



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

int main() {
	long long n;
	int cnt = 0;
	cin >> n;

	if (n < 10) {
		cout << n << endl;
		return 0;
	}

	while (n >= 10) {
		if (n % 10 == 9) {
			n /= 10;
		}
		else {
			n /= 10;
			n--;
		}
		cnt += 9;
	}

	cnt += n;

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
k=50
a,b=map(int,input().split())
a-=1;b-=1
ans=[["#"for _ in range(2*k)]for _ in range(2*k)]
for i in range(k):
	for j in range(2*k):
		ans[i][j]="."
for i in range(k-1):
	if b>0:
		for j in range(i%2*2,2*k,4):
			if b>0:
				ans[i][j]="#"
				b-=1
			else:
				break
for i in range(k+1,2*k):
	if a>0:
		for j in range(i%2*2,2*k,4):
			if a>0:
				ans[i][j]="."
				a-=1
			else:
				break
print(2*k,2*k)
for i in range(2*k):
	print("".join(ans[i]))

Measured memory_bytes: 9204
#include<stdio.h>
int main(){
  int n,k,num=1,i;
  scanf("%d%d",&n,&k);
  for(i=0;i<n;i++){
    if(num<k)
      num*=2;
    else
      num+=k;
  }
  printf("%d\n",num);
  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>

int main(void)
{
	int a, b, c,d;
	scanf("%d %d %d", &a, &b, &c);

	if (b >= a * c)
	{
		printf("%d", c);
	}

	else
	{
		d = b / a;
		printf("%d", d);
	}
	return 0;
}

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

int main() {
    int n;
    cin>>n;
    int ans=0;
    for (int i=0;i<n;i++) {
        int a;cin>>a;
        while (a%2==0) {
            a/=2;
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

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; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const double PI = acos(-1.0);
const double EPS = 1e-10;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin>>N;
    vector<ll> X(N+1),A(N+1);
    ll sum = 0;
    REP(i,N){
        cin>>A[i+1];
        sum += A[i+1];
    }
    X[1] = sum;
    for(int i=2;i<N;i+=2){
        X[1] -= 2*A[i];
    }
    for(int i=2;i<=N;i++){
        X[i] = 2*A[i-1] - X[i-1];
    }
    REP(i,N) cout<<X[i+1]<<" ";
    cout<<endl;
}


Measured memory_bytes: 2944
def main():
    N = int(input())
    posi = [0, 0]
    time = 0
    txy = [[int(i) for i in input().split()] for _ in range(N)]
    for t, x, y in txy:
        move = abs(posi[0] - x) + abs(posi[1] - y)
        if (t - time) < move or (t - time) % 2 != move % 2:
            return print("No")
        time = t
        posi = [x, y]
    print("Yes")


if __name__ == '__main__':
    main()


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

void solve(int test_case) {
	int n;
	cin>>n;
	string s;
	cin>>s;
	int cnt=0;
	stack<int> st;
	for(char c:s) {
		if(c=='(') {if(cnt<0)st.push(cnt),cnt=0;cnt++;}
		else
			--cnt;
	}
	if(cnt!=0)st.push(cnt);
	while(!st.empty()) {
		int val = st.top();
		st.pop();
		if(val>0) {
			while(val--)s+=")";
		} else {
			while(val++)s="("+s;
		}
	}
	cout<<s;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("in", "r", stdin);
	//freopen("out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
}	


Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vi  = vector<int>;
#define _GLIBCXX_DEBUG
#define IO_STREAM cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define rep(i,sta,end) for(int i=sta;i<end;++i)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
const ll INF = 1000000000000000;
const ll MOD = 1000000007;
const double PI = acos(-1);
//||
#define DBG(a,b,c,d) //cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl
//DBG("","","","");

signed main(){
	IO_STREAM;
	int N;
	cin>>N;
	map<ll,ll>mp;
	ll sum=0;
	rep(i,0,N){
		int A;
		cin>>A;
		sum+=A;
		mp[A]++;
	}
	int Q;
	cin>>Q;
	vi B(Q),C(Q);
	rep(i,0,Q){
		cin>>B[i]>>C[i];
	}
	rep(i,0,Q){
		sum-=B[i]*mp[B[i]];
		sum+=C[i]*mp[B[i]];
		mp[C[i]]+=mp[B[i]];
		mp[B[i]]=0;
		cout<<sum<<endl;
	}
	return 0;
}


Measured memory_bytes: 10052
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    int N;
    cin >> N;
    bool ans = true;
    for(int i=0; i<N; i++){
        int a;
        cin >> a;
        if(a%2 == 0){
            if(a%3 == 0 || a % 5 == 0) ;
            else ans = false;
        }
    }
    if(ans) cout << "APPROVED" << endl;
    else cout << "DENIED" << endl;
    return 0;
}

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

int main() {
    int N; cin >> N;
    string S; cin >> S;
    string S1 = S.substr(0, N / 2);
    string S2 = S.substr(N / 2);
    if (S1 == S2) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e4+5;
int n;
int main()
{
    scanf("%d",&n);
    int ans=0,l=0,r=0,flag=false;
    for(int i=1;i<=n;i++)
    {
        char s[15];
        scanf("%s",s+1);
        int m=strlen(s+1);
        if(s[1]=='B') l++;
        if(s[m]=='A') r++;
        if(!(s[1]=='B'&&s[m]=='A')&&(s[1]=='B'||s[m]=='A')) flag=true;
        for(int i=1;i<m;i++)
            if(s[i]=='A'&&s[i+1]=='B') ans++;
    }
    ans+=min(l,r);
    if(!flag&&min(l,r)>0) ans--;
    printf("%d\n",ans);
}


Measured memory_bytes: 256
#include<stdio.h>

void quick(int *,int,int);

int main(){
  int N,sum=0,min_odd=100;
  scanf("%d",&N);
  int s[N];
  for (int i = 0; i < N; i++)
  {
    scanf("%d",&s[i]);
    sum += s[i];
    if (s[i]%2!=0&&min_odd>s[i]){
      min_odd=s[i];
    }
    
  }
  
  quick(s,0,N-1);

  int ans_a;
  if (min_odd<100){
    ans_a=sum-min_odd;
  }

  int j=0,ans_b=sum;
  while (sum%10==0&&j<=N-1)
  {
    ans_b -= s[j++];
  }

  ans_a > ans_b ? printf("%d",ans_a):printf("%d",ans_b);

  return 0;
}

void quick(int a[],int left,int right)
{
    int s,t,i,j;

    if (left<right){
        s=a[left];            
        i=left; j=right+1;      
        while (1){              
            while (a[++i]<s);
            while (a[--j]>s);
            if (i>=j) break;
            t=a[i]; a[i]=a[j]; a[j]=t;
        }
        a[left]=a[j]; a[j]=s;

        quick(a,left,j-1);
        quick(a,j+1,right);
    }
}

Measured memory_bytes: 1724
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n)cin >> a[i];

    if(k == 0){
        int ans = 0;
        rep(i, n)ans = max(ans, a[i]);
        cout << ans << endl;
        return 0;
    }

    int l = 0;
    int r = 1001001001;
    while(l + 1 < r){
        int x = (l + r) / 2;
        ll cnt = 0;
        rep(i, n){
            if(a[i] % x == 0)cnt += a[i] / x - 1;
            else cnt += a[i] / x;
        }
        if(cnt <= k)r = x;
        else l = x;
    }

    cout << r << endl;
}

Measured memory_bytes: 3992
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
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;}

int main(){
  int N, M; cin >> N >> M;
  vector<int> H(N); rep(i,N) cin >> H[i];

  vector<bool> good(N, true);
  rep(i,M){
    int a, b;
    cin >> a >> b;
    a--; b--;
    if(H[a]>=H[b]) good[b] = false;
    if(H[b]>=H[a]) good[a] = false;
  }
  int ans = 0;
  rep(i,N) if(good[i]) ans++;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3796
package main

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

func main() {
	N := nextInt()
	K := nextInt()
	D := make([]int, N)

	for i := 0; i < N; i++ {
		D[i] = nextInt()
	}

	score := math.MinInt32

	// 操作回数
	for k := 0; k <= K; k++ {
		// 前からいくつ取り出すか？
		for k1 := 0; k1 <= k; k1++ {
			// 後ろからいくつ取り出すか？
			for k2 := 0; k2 <= k-k1; k2++ {
				// いくつ捨てるか
				k3 := k - k1 - k2
				l := make(t, k)
				j := 0
				s := 0

				// 処理
				for i := 0; i < k1; i++ {
					if j == N {
						break
					}
					l[j] = D[i]
					j++
				}
				for i := 0; i < k2; i++ {
					if j == N {
						break
					}
					l[j] = D[N-1-i]
					j++
				}
				sort.Sort(l)
				for i := 0; i < k; i++ {
					if i >= k3 {
						s += l[i]
					}
				}
				// fmt.Println(k1, k2, k3, l, s)
				if s > score {
					score = s
				}
			}
		}
	}

	fmt.Println(score)
}

type t []int

func (a t) Len() int           { return len(a) }
func (a t) Less(i, j int) bool { return a[i] < a[j] }
func (a t) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024 // 1 MB
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextBytes() []byte {
	stdin.Scan()
	return stdin.Bytes()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextString())
	return i
}

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)

	return i
}


Measured memory_bytes: 5632
//SPFA-标程
#include <bits/stdc++.h>
#define LL long long
#define INF 1e18
#define MAXN 100005
 
LL min(LL x, LL y) {if(x<y) return x; return y;}
 
int n, m, s, t, u, v;
LL a, b, f=1e15, ans[MAXN];
 
struct Graph
{
	int cnt, head[MAXN], vis[MAXN];
	LL dis[MAXN];
	
	struct Edge {int next, to; LL dis;} edge[MAXN*2];
	
	std::queue<int> q;
	
	void addedge(int from, int to, LL dis)
	{
		edge[++cnt].next=head[from];
		edge[cnt].to=to;
		edge[cnt].dis=dis;
		head[from]=cnt;
	}
	
	void spfa(int s)
	{
		for(int i=1; i<=n; i++) dis[i]=INF;
		memset(vis, 0, sizeof(vis));
		q.push(s); vis[s]=1; dis[s]=0;
		while(!q.empty())
		{
			int x=q.front(); q.pop();
			vis[x]=0;
			for(int i=head[x]; i; i=edge[i].next)
			{
				int to=edge[i].to;
				if(dis[to]>dis[x]+edge[i].dis)
				{
					dis[to]=dis[x]+edge[i].dis;
					if(!vis[to]) q.push(to), vis[to]=1;
				}
			}
		}
	}
} g1, g2;
 
int main()
{
	
	scanf("%d%d%d%d", &n, &m, &s, &t);
	for(int i=1; i<=m; i++)
	{
		scanf("%d%d%lld%lld", &u, &v, &a, &b);
		g1.addedge(u, v, a); g1.addedge(v, u, a);
		g2.addedge(v, u, b); g2.addedge(u, v, b);
	}
	g1.spfa(s);  g2.spfa(t);
	ans[n+1]=INF;
	for(int i=n; i>=1; i--) ans[i]=min(ans[i+1], g1.dis[i]+g2.dis[i]);
	for(int i=1; i<=n; i++) printf("%lld\n", f-ans[i]);
}

Measured memory_bytes: 12032
#include <iostream>

using namespace std;

int main()
{
	int a,b,n;
	while( cin>>a >>b >>n){
		int sum=0;
		for(int i=0;i<n;i++){
			a = ( a % b ) *10;
			sum += a/b;
		}
		
		cout<<sum<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
tp = 0
hp = 0
list = []
n = int(input())
for i in range(n):
    list = input().split()
    if list[0] == list[1]:
        tp += 1
        hp += 1
    elif list[0] > list[1]:
        tp += 3
    else:
        hp += 3
    list = []

print(tp,hp)




Measured memory_bytes: 5604
/*
与位运算的题目如果不是规律的话，那么就从每一个二进制位置上考虑如何操作。
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1e5 + 10;
LL arr[maxn],K,N;
int main(){
	scanf("%d%lld",&N,&K);
	for(int i = 0 ; i < N ; ++i){
		scanf("%lld",arr+i);
	}
	LL ans = 0ll;
	for(LL i = 40 ; i >= 0 ; --i){
		int cnt = 0;
		for(int j = 0 ; j < N ; ++j){
			if((arr[j]>>i)&1ll){
				++cnt;
			}else --cnt;
		}
		LL k = 0;
		if(cnt<0){
			k = 1ll<<i;
		}
		if((ans+k) <= K){
			ans += k;
		}
	}
	// cout<<"ans = "<<ans<<endl;
	LL sum = 0ll;
	for(int i = 0 ; i < N ; ++i){
		sum += ans ^ arr[i];
	}
	printf("%lld\n",sum);
	return 0;
}

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

long long mod = 1E9 +7;

long long add(long long a, long long b){
  return ((a%mod)+(b%mod))%mod;
}

int main(){
  int h, w;
  cin>>h>>w;
  char grid[h][w];
  for(int i=0; i<h; i++)
  for(int j=0; j<w; j++)
  cin>>grid[i][j];
  long long path[h][w];
  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      if(grid[i][j] == '#') path[i][j] = 0;
      else if(i == 0 || j == 0){
            if(i == 0 && j == 0) path[i][j] = 1;
            else if(i == 0){
                  path[i][j] = path[i][j-1];
            }
            else if(j == 0){
                  path[i][j] = path[i-1][j];
            }
      }
      else{
        path[i][j] = add(path[i-1][j], path[i][j-1]);
      }
      // cout<<path[i][j]<<" ";
    }
    // cout<<endl;
  }
  cout<<path[h-1][w-1];
  return 0;
}


Measured memory_bytes: 9088
import bisect

n = int(input())
a = list(map(int, input().split()))

def partition(A, p, r):
    x = A[r]
    i = p-1
    for j in range(p,r):
        if A[j] <= x:
            i = i+1
            A[i], A[j] = A[j], A[i]
    A[i+1], A[r] = A[r], A[i+1]
    
    return i+1

p_ind = partition(a, 0, n-1)

print(*a[:p_ind], '['+str(a[p_ind])+']', *a[p_ind+1:])


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

int main()
{
    int x, ans;
    for (int i = 1; i <= 5; i++)
    {
        cin >> x;
        if (x == 0)
        {
            ans = i;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3568
n = int(input())
d = list(map(int, input().split()))

d.sort()
count = 0

if n % 2 == 1:
    print("0")
    exit(0)
else:
    if d[int(n/2)-1] == d[int(n/2)]:
        print("0")
        exit(0)
    else:
        k = d[int(n/2)-1]
        while(1):
            if k != d[int(n/2)]:
                count += 1
                k = k + 1
            else:
                break

print(count)

Measured memory_bytes: 14396
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define x first
#define y second
using namespace std;
using ll  = long long;
#define int ll

signed main() {
#ifdef LC
    assert(freopen("input.txt", "r", stdin));
#endif
    ios::sync_with_stdio(0), cin.tie(0);

	string s;
	cin >> s;
	for (char c : s) {
		if (c == '?') {
			cout << 'D';
		} else {
			cout << c;
		}
	}
	cout << endl;

    return 0;
}


Measured memory_bytes: 3744
# https://atcoder.jp/contests/abc149/tasks/abc149_c
import math


def is_prime(x):
    for i in range(2, x):
        if x % i == 0:
            return False
    return True


def main():
    n = int(input())
    for i in range(n, 100004):
        if is_prime(i):
            print(i)
            break


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
use std::io::*;
use std::str::FromStr;

//https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn gcd(x:i64, y:i64) -> i64 {
    if x == 0 {
        return y;
    }
    return gcd(y%x,x);
}

fn main() {
    let n:usize = read();
    let x:i64 = read();
    let a:Vec<i64> = (0..n).map(|_| read()).collect();
    let mut d: Vec<i64> = Vec::new();

    for i in a.iter() {
        d.push((x-*i).abs());
    }

    let mut g: i64 = d[0];

    for i in 1..d.len() {
        g = gcd(g,d[i]);
    }

    //println!("{:?}",d);
    println!("{}", g);
}

Measured memory_bytes: 6396