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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

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

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int d;
    cin >> d;
    vi c(26);
    rep(i, 26) cin >> c[i];
    vector<vi> s(d, vi(26));
    rep(i, d) rep(j, 26) cin >> s[i][j];
    vi t(d);
    rep(i, d) {
        cin >> t[i];
        t[i]--;
    }
    vi last(26);
    ll sum = 0;
    rep1(i, d) {
        sum += s[i-1][t[i-1]];
        last[t[i-1]] = i;
        rep(j, 26) sum -= c[j] * (i - last[j]);
        cout << sum << endl;
    }
    return 0;
}


Measured memory_bytes: 3596
#include <cstdio>
#include <utility>
#include <cctype>
#include <vector>
#include <algorithm>
#include <climits>
using namespace std;

#ifdef __linux
#define _U(s) s##_unlocked
#else
#define _U(s) _##s##_nolock
#define _CRT_DISABLE_PERFCRIT_LOCKS
#endif
#define gcu _U(getchar)
#define pcu _U(putchar)
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template <typename T>
#define _HT template <typename H,typename... T>
#define _OP(t) inline operator t()
struct _in {
#ifdef _GLIBCXX_STRING
	_OP(string){string s;char c;while(isspace(c = gcu()));do{s+=c;}while(c=gcu(),c!=' '&&c!='\n'&&c!=EOF);return s;}
#define _S
#endif
	_OP(char){char c=gcu();gcu();return c;}
	_OP(double){double d; scanf("%lf",&d); gcu();return d;}
	_T _OP(T){T n{},m{1},c;while(isspace(c = gcu()));if(c=='-')m=-1,c=gcu();do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
} in;
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
#ifdef _S
_SCAN(string &o) {int c{gcu()};if(c==EOF)return false;else{ungetc(c,stdin);string t=move(in);o=t;return true;}}
#endif
_T _SCAN(T &o) {int c{gcu()};return c==EOF?false:(ungetc(c,stdin),o=in,true);}
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);}
_OUT(const char *s){while(*s)pcu(*s++);}
_OUT(char c){pcu(c);}
#ifdef _S
_OUT(string &s){for(char c:s)pcu(c);}
#endif
_T _OUT(T n){static char b[20];char *p=b;T m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=(char)(n%10*m+'0'),n/=10;while(p!=b)pcu(*--p);}
_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
	_T _OUT(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);}
#endif
_HT _OUT(H &&h, T... t){out(h);out(t...);}
template <typename... T> _OUTL(T... t){out(t...);outl();}
struct range{
	int e,b=0,s=1;range(int _b,int _e,int _s):e(_e),b(_b),s(_s){} range(int _b,int _e): e(_e), b(_b){} range(int _e):e(_e){}
	struct it{int v,s; it(int _v,int _s):v(_v),s(_s){} operator int()const{return v;} operator int&(){return v;}int operator*()const{return v;}
		it& operator++(){v+=s;return *this;} }; it begin(){return {b,s};} it end(){return {e,s};}};
#define times(i,n) for(int i=n;i;i--)

struct P {
	int i, c;
	P () : i {-1}, c {} {}
	bool operator == (P a) const {
		return c == a.c && i == a.i;
	}
	bool operator < (P a) const {
		return c == a.c ? i < a.i : c > a.c;
	}
};

template <typename T>
struct RMQ {
	int n;
	vector<T> t;
	RMQ (int l) :
		n(1 << (32 - __builtin_clz(l - 1))),
		t(n * 2) {}
	void update(int i, int v) {
		t[i + n].i = i;
		i += n;
		t[i].c += v;
		while (i > 1) {
			i >>= 1;
			T n = min(t[i << 1], t[i << 1 | 1]);
			if (t[i] == n)
				break;
			else
				t[i] = n;
		}
	}
};


int main() {
	int n {in}, m {in};
	RMQ<P> r(n);
	times (i, m) {
		int a {(int) in - 1}, v {in};
		r.update(a, v);
		P t = r.t[1];
		outl(t.i + 1, ' ', t.c);
	}
}


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

using namespace std;

const auto inf = LLONG_MAX - 10;

long long mul(long long a, long long b) {
  if (inf / a < b) {
    return inf;
  } else {
    return a * b;
  }
}

long long add(long long a, long long b) {
  if (inf - a < b) {
    return inf;
  } else {
    return a + b;
  }
}

void solve() {
  long long n;
  long long a[3], d;
  int v[] = {2, 3, 5};
  cin >> n >> a[0] >> a[1] >> a[2] >> d;
  set<long long> used;
  priority_queue<pair<long long, long long>> q;
  q.emplace(0, n);
  while (true) {
    long long x, y;
    tie(x, y) = q.top();
    q.pop();
    if (used.count(y)) {
      continue;
    }
    used.insert(y);
    x = -x;
    if (y == 0) {
      cout << x;
      return;
    }
    for (int i = 0; i < 3; ++i) {
      int k = y % v[i], l = v[i] - k;
      if (k) {
        q.emplace(-(x + k * d), y - k);
        q.emplace(-(x + l * d), y + l);
      } else {
        q.emplace(-(x + a[i]), y / v[i]);
        q.emplace(-add(x, mul(y - y / v[i], d)), y / v[i]);
      }
    }
  }
}

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

  int t;
  cin >> t;
  while (t--) {
    solve();
    cout << '\n';
  }

  return 0;
}


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

int main(){
    int A,B,C,W ;
    scanf("%d",&A) ;
    scanf("%d",&B) ;
    scanf("%d",&C) ;

    if(A<B){
      printf("A<B") ;
      exit(0) ;
    }

    W=C-(A-B) ;
    if (W <= 0){
      printf("%d",0) ;
    }else{
      printf("%d",W);
    }
  }


Measured memory_bytes: 128
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int mod = 1e9 + 7;
const int IMAX = 200010;
constexpr ll modpow(ll A, ll B) {
	ll kotae = 1;
	while (B > 0) {
		if (B & 1) kotae = kotae * A % mod;
		A = A * A % mod;
		B >>= 1;
	}
	return kotae;
}
class unko {
public:
	int fac[IMAX + 1], ifac[IMAX + 1], inv[IMAX + 1], tokusei[IMAX + 1];
	constexpr unko() : fac(), ifac(), inv(), tokusei() {
		fac[0] = 1;
		rep1(i, IMAX) fac[i] = ll(fac[i - 1]) * i % mod;
		ifac[IMAX] = modpow(fac[IMAX], mod - 2);
		for (int i = IMAX; i > 0; i--) ifac[i - 1] = ll(ifac[i]) * i % mod;
		inv[0] = 1;
		rep1(i, IMAX) inv[i] = ll(ifac[i]) * fac[i - 1] % mod;
		rep1(i, 199999) tokusei[i] = ll(i) * inv[200000 - i] % mod;
	}
} f;

int N;
const int VN = 200000;
int to[VN * 2 + 2], ne[VN * 2 + 2], he[VN + 1];
int *kari;
int n[VN + 1];
void dfs(int v) {
	n[v]++;
	int mae = 0;
	for (int i = he[v]; i; i = ne[i]) {
		int t = to[i];
		if (n[t]) {
			if (mae) ne[mae] = ne[i];
			else he[v] = ne[i];
		}
		else {
			dfs(t);
			n[v] += n[t];
			mae = i;
		}
	}
}
void dfs2(int v) {
	for (int i = he[v]; i; i = ne[i]) {
		int t = to[i];
		n[t] = ll(n[v]) * kari[n[t]] % mod;
		dfs2(t);
	}
}

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

	
	cin >> N;
	int k = 2;
	rep1(i, N - 1) {
		int a, b;
		cin >> a >> b;

		to[k] = b;
		ne[k] = he[a];
		he[a] = k++;
		to[k] = a;
		ne[k] = he[b];
		he[b] = k++;
	}
	dfs(1);
	ll tmp = 1;
	rep1(i, N) tmp = (tmp * n[i]) % mod;
	n[1] = modpow(tmp, mod - 2) * f.fac[N] % mod;

	int ka[VN + 1];
	if (N == 200000) kari = f.tokusei;
	else {
		kari = ka;
		rep1(i, N - 1) kari[i] = ll(i) * f.inv[N - i] % mod;
	}

	for (int i = he[1]; i; i = ne[i]) {
		int t = to[i];
		n[t] = ll(n[1]) * kari[n[t]] % mod;
		dfs2(t);
	}
	rep1(i, N) co(n[i]);

	Would you please return 0;
}

Measured memory_bytes: 7680
#include <bits/stdc++.h>
#define INF 1000000007
#define rep(i, N) for(ll i = 0; i < N; i++)
#define rep2(i, j, k) for(ll i = j; i < k; i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define print(x) cout << x << "\n"
#define print2(x, y) cout << x << " " << y << "\n"
#define printv(vec) rep(i, vec.size()) cout << vec[i] << " "; print("");
#define ALL(v) v.begin(), v.end()
#define SUM(v) accumulate(ALL(v), 0)
#define MAX(v) *max_element(ALL(v))
#define MIN(v) *min_element(ALL(v))
#define SORT(v) sort(ALL(v))
#define REV(v) reverse(ALL(v))
typedef long long ll;
using namespace std;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vs = vector<string>;

void Main(){

	ll N, M;
	cin >> N >> M;
	vl v(N, -1);
	rep(i, M){
		ll in1, in2;
		cin >> in1 >> in2;
		if(v[in1 - 1] != -1 && v[in1 - 1] != in2){
			print(-1);
			return;
		}
		v[in1 - 1] = in2;
	}
	
	string ans = "";
	
	if(N == 1 && M == 1 && v[0] == 0){
		print(0);
		return;
	}	
	
	if(v[0] == 0){
		print(-1);
		return;
	}
	
	if(N == 1 && M == 0){
		print(0);
		return;
	}
	
	rep(i, N){
		if(v[i] != -1) ans += to_string(v[i]);
		else{
			if(i == 0) ans += '1';
			else ans += '0';
		}
	}
	
	print(ans);
	
	
}

int main(){
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	Main();
    
	return 0;
	
}





Measured memory_bytes: 3716
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
//CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
//-----------------------------------------
#define dcml(n) fixed<<setprecision(n)
using namespace std;
int main(void){
    ll N;cin>>N;
    ll ans=0;ll idx=1;
    REPS(i,N){
        ll k=i;ll cnt=0;
        while(k>0&&k%2==0)k/=2,cnt++;
        if(cnt>ans)ans=cnt,idx=i;
    }
    cout<<idx<<"\n";
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;

#define reep(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reep(i,0,n)

typedef vector<int> vi;
typedef vector<vi> vvi;

struct Data
{
	int y, x, d, cost;
	Data(int y, int x, int d, int cost) : y(y), x(x), d(d), cost(cost) {}

	bool operator< (const Data& d)const
	{
		return cost > d.cost;
	}
};

int main()
{
	int w, h;
	while(scanf("%d%d", &w, &h), w){
		vvi field(h, vi(w));
		rep(i, h) rep(j, w)
			scanf("%d", &field[i][j]);

		int c[4];
		rep(i, 4) scanf("%d", &c[i]);

		vector<vvi> done(h, vvi(w, vi(4, 0)));

		int ans;
		priority_queue<Data> Q;
		Data start(0, 0, 0, 0);
		Q.push(start);
		while(!Q.empty()){
			Data d = Q.top();
			Q.pop();
			if(done[d.y][d.x][d.d])
				continue;

			done[d.y][d.x][d.d] = 1;
			if(d.y == h-1 && d.x == w-1){
				ans = d.cost;
				break;
			}

			const int dx[] = {1, 0, -1, 0};
			const int dy[] = {0, 1, 0, -1};
			rep(i, 4){
				int pd = (i + d.d) % 4;
				int py = d.y + dy[pd];
				int px = d.x + dx[pd];
				if(py<0 || h<=py || px<0 || w<=px)
					continue;

				if(done[py][px][pd])
					continue;
				
				int pc = d.cost + (i==field[d.y][d.x] ? 0 : c[i]);
				Q.push(Data(py, px, pd, pc));
			}
		}

		printf("%d\n", ans);
	}

	return 0;
}

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

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

num = input()
nums = [int(num[0]), int(num[1]), int(num[2]), int(num[3])]

sum_ = sum(nums)

for bit in range(1 << 3):
    tmp = sum_
    ops = ['+', '+', '+']
    for j in range(3):
        if bit & (1 << j):
            tmp -= 2 * nums[j+1]
            ops[j] = '-'
    if tmp == 7:
        res = str(nums[0]) + ops[0] + str(nums[1]) + ops[1] + str(nums[2]) + ops[2] + str(nums[3]) + '=7'
        print(res)
        break


Measured memory_bytes: 9172
//#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<utility>
#include<algorithm>
#include<cstring>
#include<sstream>
#include <iomanip>

using namespace std;

typedef long long ll ;
typedef double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector< pair<int,int> > vii;
const double pi = 2*acos(0) ;

#define pf		  	printf
#define sf			  scanf
#define pb(a)         push_back(a)
#define mp			make_pair
#define fi			 first
#define se			 second
#define for0(i,n)        for(int i=0;i<n;i++)
#define for1(i,n)        for(int i=1;i<=n;i++)
#define forab(i,a,b)       for(int i=a;i<=b;i++)
#define lcm(a, b)     ((a)*((b)/gcd(a,b)))
#define sq(a)		   (a)*(a)
#define nw				"\n"
#define abs(x)		fabs(x)
#define pcase(z,x)    cout<<"Case "<<z<<": "<<x<<"\n"
int main()
{
	int n,k,p;
	cin>>n>>k;
	vi a(n+2,0),x;
	for0(i,n){
		cin>>p;
		a[p]++;
		}
	for0(i,n+1){
		if(a[i]>0) x.pb(a[i]);
		}
	sort(x.begin(),x.end());
	if(x.size()<=k) pf("0");
	else{
		int t,s=0;
		t = x.size() - k;
		for0(i,t){
			s += x[i];
			}
		cout<<s<<nw;
		}
	return 0;
}

Measured memory_bytes: 2168
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int n;
    scanf("%d",&n);
    int x=1;
    int r[n+1];
    r[0]=1;
    for(int i=1;i<n+1;i++){
        r[i]=2*r[i-1];
    }
    x=r[n];
    long long a[x];
    for(int i=0;i<x;i++){
        scanf("%lld",&a[i]);
    }
    long long b1[x];
    long long b2[x];
    int b3[x];
    for(int i=0;i<x;i++){
        b1[i]=a[i];
        b2[i]=-1;
        b3[i]=-1;
    }
    b1[0]=a[0];
    b2[0]=0;
    b3[0]=0;
    long long bss1[x],bss2[x];
    bss1[0]=0;
    for(int i=0;i<x;i++){
        bss1[i]=i;
        bss2[i]=-1;
    }
    long long h;
    for(int i=0;i<n;i++){
        for(int j=0;j<x;j++){
            if(b3[j]==i){
                for(int k=0;k<n;k++){
                    if((j&r[k])==0){
                        if(b1[j]>b2[j|r[k]]&&bss2[j|r[k]]!=bss1[j]&&bss1[j|r[k]]!=bss1[j]){
                            b2[j|r[k]]=b1[j];
                            bss2[j|r[k]]=bss1[j];
                            if(b2[j|r[k]]>b1[j|r[k]]){
                                h=b2[j|r[k]];
                                b2[j|r[k]]=b1[j|r[k]];
                                b1[j|r[k]]=h;
                                h=bss2[j|r[k]];
                                bss2[j|r[k]]=bss1[j|r[k]];
                                bss1[j|r[k]]=h;
                            }
                        }
                        b3[j|r[k]]=i+1;
                    }
                }
            }
        }
    }
    long long d[x];d[0]=0;
    for(int i=1;i<x;i++){
        d[i]=b1[i]+b2[i];
        if(d[i-1]>d[i])d[i]=d[i-1];
        printf("%lld\n",d[i]);
    }
}

Measured memory_bytes: 16256
import java.util.Scanner;

public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int D = sc.nextInt();
        int cov = D+D+1;
        int ans = N/cov + Math.min(1, N%cov);
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define int long long
using namespace std;main(){int a,b,c,d;cin>>a>>b>>c>>d;a--;cout<<b-a+a/c-b/c+a/d-b/d+b/c*__gcd(c,d)/d-a/c*__gcd(c,d)/d;}


Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 2019/3/23
Solved on 2019/3/23
@author: shinjisu
"""


# ABC 071 C Make Rectangle
from collections import Counter

def getInt(): return int(input())

def getIntList(): return [int(x) for x in input().split()]
# def getIntList(): return np.array(input().split(), dtype=np.longlong)

def zeros(n): return [0]*n
# def zeros(n): return np.zeros(n, dtype=np.longlong)

def getIntLines(n): return [int(input()) for i in range(n)]


def zeros2(n, m): return [zeros(m) for i in range(n)] # obsoleted zeros((n, m))で代替


class Debug():
    def __init__(self):
        self.debug = True
 
    def off(self):
        self.debug = False
 
    def dmp(self, x, cmt=''):
        if self.debug:
            if cmt != '':
                print(cmt, ':  ', end='')
            print(x)
        return x


def prob():
    d = Debug()
    d.off()
    N = getInt()
    d.dmp((N), 'N')
    A = getIntList()
    d.dmp((A), 'A')
    dic = Counter(A)
    d.dmp((dic), 'dic')
    side = []
    for k in dic.keys():
        if dic[k] >= 4:
            side.append(k)
            side.append(k)
        elif dic[k] >= 2:
            side.append(k)
    side.sort()
    d.dmp((side), 'side')
    if len(side) >= 2:
        return side[-1]*side[-2]
    else:
        return 0


ans = prob()
print(ans)


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

using namespace std;
using ll = long long;
using P = pair<int, uint>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

const int CASES = 3;

void solve(){

    string s; cin >> s;
    ll n = s.length();

    vector<ll> a(26);
    for (char c : s) ++a[c - 'a'];

    ll ans = n * (n-1) / 2;

    for (ll l : a) {
        ans -= l * (l-1) / 2;
    }
    cout << ans + 1 << '\n';
    
    /*
    ll ans_ = 1;
    vector<ll> cnt(26);
    for(int i = n - 1; i >= 0; --i) {
        int si = s[i] - 'a';
        for(int j = 0; j < 26; ++j){
            if (j != si) ans_ += cnt[j];
        }
        ++cnt[si];
    }
    cout << ans_ << '\n';
     */
    return;
}

int main() {
    #ifdef MYLOCAL
    vector<string> filenames {"input1.txt", "input2.txt", "input3.txt", "input4.txt"};
    cout << "------------\n";
    for(int i = 0; i < CASES; ++i){
        ifstream in(filenames[i]);
        cin.rdbuf(in.rdbuf());
        solve();
        cout << "------------\n";
    }
    #else

    solve();

    #endif
    return 0;
}



Measured memory_bytes: 640
package main

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

func main() {
	var n, m int
	nextInts(&n, &m)

	hs := make([]int, n)
	for i := range hs {
		nextInts(&hs[i])
	}

	to := make([][]int, n)
	for i := 0; i < m; i++ {
		var a, b int
		nextInts(&a, &b)
		a--
		b--
		to[a] = append(to[a], b)
		to[b] = append(to[b], a)
	}

	var ans int
	for i := 0; i < n; i++ {
		ok := true
		for _, j := range to[i] {
			if hs[i] <= hs[j] {
				ok = false
			}
		}
		if ok {
			ans++
		}
	}
	fmt.Println(ans)
}

var sc *bufio.Scanner

func init() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
}

func nextInts(ints ...*int) {
	for i := range ints {
		sc.Scan()
		*ints[i], _ = strconv.Atoi(sc.Text())
	}
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}


Measured memory_bytes: 11932
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()

total = 0

for i in range(N):
    low = 0
    high = N 
    while low < high:
        mid1 = (low + high) // 2
        if A[mid1] < B[i]:
            low = mid1 + 1
        else:
            high = mid1
    mid1 = low
    low = 0
    high = N
    while low < high:
        mid2 = (low + high) // 2
        if C[mid2] > B[i]:
            high = mid2
        else:
            low = mid2 + 1
    mid2 = low
    total = total + mid1 * (N - mid2)

print(total)

Measured memory_bytes: 24052
#include <bits/stdc++.h>
using namespace std;
using P = pair<int,int>;

int main(){
  int d;
  cin >> d;
  vector<int> c26(26);
  vector<vector<int>> si(d, vector<int>(26));
  for(int i=0; i<26; ++i) cin >> c26[i];
  for(int i=0; i<d; ++i) for(int j=0; j<26; ++j) cin >> si[i][j];
  
  vector<vector<int>> koho(d);
  for(int i=0; i<26; ++i){
    int hindo;
    if(c26[i] <=10) hindo = 100;
    else if(c26[i] <=30) hindo = 50;
    else if(c26[i] <=60) hindo = 20;
    else hindo = 10;
    
    int j = 0;
    while(j<d-1){
      int cnt = 0;
      int mxday = min(j+hindo, d-1);
      for(int k=mxday; k>j; --k){
        if(si[k][i] >= 13333){
          koho[k].push_back(i);
          ++cnt;
          for(int l=j+1; l<=k; ++l){
            si[l][i] += (l-j) *(l-j) *c26[i];
          }
          j = k;
          break;
        }
      }
      if(cnt == 0){
        for(int l=j+1; l<=mxday; ++l){
          si[l][i] += (l-j) *(l-j) *c26[i];
        }
        j = mxday;
      }
    }
  }
  
  vector<int> ans(d);
  for(int i=0; i<d; ++i){
    vector<P> koho2(0);
    if(koho[i].size() == 0){
      for(int j=0; j<26; ++j){
        koho2.push_back(make_pair(si[i][j], j));
      }
    }else{
      for(int n: koho[i]){
        koho2.push_back(make_pair(si[i][n], n));
      }
    }
    sort(koho2.begin(),koho2.end());
    reverse(koho2.begin(),koho2.end());
    ans[i] = koho2[0].second;
  }
  for(int i=0; i<d; ++i){
    cout << ans[i]+1 << endl;
  }
}

Measured memory_bytes: 3708
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
long long cost[101],cap[101],n;
long long dp[2][100005];
 
long long knap(int n,int c){
    
    for(int i=0;i<=n;i++){
        for(int j=0;j<=c;j++){
          
          if(i%2==0){
              if(i==0 || j==0) dp[0][j]=0;
            else if(cap[i-1]>j) dp[0][j]=dp[1][j];
            else{
                long long t1,t2;
                t1=dp[1][j];
                t2=dp[1][j-cap[i-1]]+cost[i-1];
                dp[0][j]=max(t1,t2);
            }
          } 
          
          else{
               if(i==0 || j==0) dp[1][j]=0;
            else if(cap[i-1]>j) dp[1][j]=dp[0][j];
            else{
                long long t1,t2;
                t1=dp[0][j];
                t2=dp[0][j-cap[i-1]]+cost[i-1];
                dp[1][j]=max(t1,t2);
            }
          }
        }
    }
    return (n%2 != 0)? dp[1][c] : dp[0][c]; 
}
int main(){
    
        memset(dp,-1,sizeof(dp));
      
        long long c;
        cin >> n >> c;
       
        for(int i=0;i<n;i++){
            cin >> cap[i] >> cost[i] ;
           
        }
        
        cout << knap(n,c) << endl;
    
}

Measured memory_bytes: 5208
from collections import deque, defaultdict

N = int(input())
ab = []
for i in range(N - 1):
    ab.append(tuple(map(int, input().split())))

c_list = list(map(int, input().split()))
c_list.sort()
c_que = deque(c_list)

cnt = defaultdict(int)
outs = defaultdict(list)
for a, b in ab:
    cnt[a - 1] += 1
    cnt[b - 1] += 1
    outs[a - 1].append(b - 1)
    outs[b - 1].append(a - 1)

top = 0
tar = defaultdict(lambda: 0)

import sys

sys.setrecursionlimit(10 ** 9)
visit = [False] * N


def dfs(start):
    tmp = []
    visit[start] = True
    for v2 in outs[start]:
        if visit[v2]:
            continue
        q = c_que.pop()
        tar[v2] = q
        tmp.append(v2)
    for v2 in tmp:
        if visit[v2]:
            continue
        dfs(v2)


tar[top] = c_que.pop()
dfs(top)
ans = 0
for a, b in ab:
    a -= 1
    b -= 1
    ans += min(tar[a], tar[b])
print(ans)
for i in range(N):
    print(tar[i], end=" ")


Measured memory_bytes: 18496
n, y = list(map(int, input().split()))
for i in range(n+1):
    for j in range(n-i+1):
        k = n-i-j
        if k < 0:
            continue
        if 10000*i+j*5000+k*1000 == y:
            print("{} {} {}".format(i, j, k))
            break
    else:
        continue
    break
else:
    print("-1 -1 -1")

Measured memory_bytes: 3060
// problem: "https://atcoder.jp/contests/abc155/tasks/abc155_b"

#include<bits/stdc++.h>

using namespace std;

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

    vector<int>V(n);
    int i;
    for(i=0;i!=n;i++)
        cin>>V[i];

    for(i=0;i!=n;i++)
    {
        if(V[i]%2 == 0)
        {
            if(!(V[i]%3 == 0 || V[i]%5 == 0))
            {
                cout<<"DENIED";
                exit(0);
            }
        }
    }

    cout<<"APPROVED";

    return 0;
}


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


int main() {
    int N;
    cin >> N;
    vector<ll> a(N);
    rep(i, N) cin >> a[i];
    rep(i, N - 1) a[i + 1] += a[i];

    ll ans = 1e+12;
    ll x, y;
    rep(i, N - 1) {
        x = a[i];
        y = a[N - 1] - x;
        ans = min(ans, abs(x - y));
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4700
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  string ans;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'B') {
      if (ans.empty() != true) {
        ans.erase(ans.size() - 1);
      }
    }
    else {
      ans += s[i];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
def create_array(n,ary)
  return ary[n] = 1 if n == 0
  ary[n] = create_array(n-1,ary)*2
end
ary = []
create_array(7,ary)
n = gets.to_i
ary.each_cons(2) {|a,b| puts a if (a...b).include?(n)}

Measured memory_bytes: 14316
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int H = in.nextInt();
        int W = in.nextInt();
        char[][] board = new char[H][W];
        int blackNum = 0;

        for(int i = 0; i < H; i++){
            String row = in.next();
            for(int j = 0; j < W; j++){
                board[i][j] = row.charAt(j);
                if (board[i][j] == '#'){
                    blackNum++;
                }
            }
        }        
        int length = getShortestPathLength(board, H,W);
        int result = -1;
        if(length != -1){
            result = W*H - blackNum - length - 1;
        }        
        System.out.println(result);

        in.close();
    }

    static char wall = '#';
    static int[][] dist;
	
	public static int getShortestPathLength(char[][] board, int MaxMapHeight, int MaxMapWidth) {

		dist = new int[MaxMapHeight][MaxMapWidth];
        int[] dx = {1,0,-1,0}, dy = {0,1,0,-1};	
		for (int i = 0; i < MaxMapHeight; i++) {
			for (int j = 0; j < MaxMapWidth; j++) {
				dist[i][j] = -1;
			}
		}
		
		Queue<Point> que = new LinkedList<Point>();
		
		Point Start = new Point(0,0);
		Point Goal = new Point(MaxMapHeight-1,MaxMapWidth-1);	
		int tempX, tempY;
		
		que.offer(new Point(0,0));
		dist[Start.Y][Start.X] = 0;
		
		while(que.size() > 0) {
            Point point = que.poll();
			if(point.Y == MaxMapHeight-1 && point.X == MaxMapWidth-1) break; 
			for(int i = 0; i < 4; i++) {
				tempY = point.Y + dy[i];
				tempX = point.X + dx[i];
				if((0 <= tempY && tempY < MaxMapHeight) && (0 <= tempX && tempX < MaxMapWidth) 
						&& (board[tempY][tempX] != wall) && dist[tempY][tempX] == -1) {
					que.offer(new Point(tempY, tempX));
                    dist[tempY][tempX] = dist[point.Y][point.X] + 1; 
                }
			}
		}
        
        return dist[Goal.Y][Goal.X];        
		
	}    
	static class Point {
		public int Y, X;
		
		public Point(int Y, int X) {
			this.Y = Y;
			this.X = X;
		} 
	} 
}


Measured memory_bytes: 21844
from collections import deque
H,W,K=map(int,input().split())
A=[list(input())for _ in range(H)]
for i,a in enumerate(A):
	if"S"in a:y,x=(i,a.index("S"))
d=1e9
Q=deque([(1,y,x)])
while Q:
	c,i,j=Q.popleft()
	d=min(d,i,j,H-i-1,W-j-1)
	if c>K:continue
	for h,w in((i+1,j),(i,j+1),(i-1,j),(i,j-1)):
		if 0<=h<H and 0<=w<W and A[h][w]==".":
			A[h][w]=""
			Q+=[(c+1,h,w)]
print(1-(-d//K))

Measured memory_bytes: 75356
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include <cassert>
    #include <cmath>

    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))

    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;


    vector<bool> seen;
    void dfs(const Graph &G,int v){
        int cnt = 0;
        seen[v] = true;
        for(auto nv:G[v]){
            if(seen[nv])continue;
            cnt++;
            dfs(G,nv);
        }
    }
    int main(){
      ll n,W;cin>>n>>W;
      auto w = vec(ll,n+20);
      auto v = vec(ll,n+20);
      rep(i,n)cin>>w[i]>>v[i];
      ll dp[n+20][W+20];
      rep(i,n)rep(j,W+20)dp[i][j] = 0;
      rep(i,n)rep(j,W+20){
          if(j>=w[i])dp[i+1][j] = max(dp[i+1][j],dp[i][j-w[i]]+v[i]);
          dp[i+1][j] = max(dp[i+1][j],dp[i][j]);
      }
      cout<<dp[n][W]<<endl;
    }


Measured memory_bytes: 81152
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;

signed main(){
    cin.tie(0); 
    ios::sync_with_stdio(false);
    int n,k;
    int h[100010];
    int dp[100010];
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    dp[0]=0;
    for(int i=1;i<n;i++){
        dp[i]=dp[i-1]+abs(h[i]-h[i-1]);
        for(int j=2;j<=k;j++){
            if(i>=j){
                dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
            }
        }
    }
    cout<<dp[n-1]<<"\n";
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define all(x) (x).begin(), (x).end()
#define MOD 1000000007

int main() {
    ll q, h, s, d, n;
    cin >> q >> h >> s >> d >> n;
    ll one = min({4 * q, 2 * h, s});
    if(one * 2 <= d) {
        cout << n * one << endl;
    } else {
        cout << n / 2 * d + (n % 2) * one << endl;
    }
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#define rep(i,n) for (int i=0; i<n;++i)
using namespace std;
int N, M; 
int DP[100003];
vector<int> Graph[100003];

int dfs(int idx) {
  if (DP[idx] > 0) return DP[idx];
  vector<int> a = Graph[idx];
  int ret = 0;
  rep(i, a.size()) {
    ret = max(dfs(a[i])+1, ret);
  }
  DP[idx] = ret;
  return ret;
}

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

  cin >> N >> M;
  rep(i, N) DP[i] = -1;
  int x,y;
  rep(i, M) {
    cin >> x >> y;
    x--;y--;
    Graph[x].push_back(y); 
  }
  int idx = 0;
  int ans = 0; 
  while(idx<N) {
    if (DP[idx] > 0) {
      idx++;
      continue;
    }
    ans = max(ans, dfs(idx));
    idx++;
  }

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

Measured memory_bytes: 9600
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
char a[102],b[102],c[102];
int la,lb,lc;
void card(int x,int y,int z,int m)
{
	if(m==1)
	{
		if(la==x)
		{printf("A");return ;}
		card(x+1,y,z,a[x]-'a'+1);
	}
	else	if(m==2)
	{
		if(lb==y)
		{printf("B");return ;}
		card(x,y+1,z,b[y]-'a'+1);
	}
	else	if(m==3)
	{
		if(lc==z)
		{printf("C");return ;}
		card(x,y,z+1,c[z]-'a'+1);
	}
}
int main()
{
	scanf("%s%s%s",a,b,c);
	la=strlen(a);lb=strlen(b);lc=strlen(c);
	card(0,0,0,1);
	//return 0;
}

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

void solve()
{
	int n, k;
	cin >> n >> k;
	vector<pair<int, int>> arr(k);
	for (int c = 0; c < k; c++)
		cin >> arr[c].first >> arr[c].second;
	vector<ll int> dp(n + 1);
	vector<ll int> suffx(n + 2);
	dp[n] = 1;
	suffx[n + 1] = 0;
	suffx[n] = 1;
	for (int c = n - 1; c >= 0; c--)
	{
		for (int c1 = 0; c1 < arr.size(); c1++)
		{
			if (c + arr[c1].first > n)
				continue;
			(dp[c] += mod + suffx[c + arr[c1].first] - suffx[min(n + 1, 1 + c + arr[c1].second)]) %= mod;
		}
		(suffx[c] = suffx[c + 1] + dp[c]) %= mod;
	}

	cout << dp[1] << endl;
}
int main()
{

	int t;
	t = 1;
	for (int c = 0; c < t; c++)
		solve();
}

Measured memory_bytes: 6408
///AJoy Sarker ,CSE JAHANGIRNAGAR UNIVERSITY 48 Batch

#include<bits/stdc++.h>

using namespace std;
#define SORT(c) sort((c).begin(),(c).end());
#define inf INT_MAX/3
#define pb push_back
#define MP make_pair
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define pi 3.141592653589793
#define in scanf
#define out printf
#define ll long long
#define ull unsigned long long
typedef unsigned long long UL;
template<typename T>inline T  S(T a)
{
    return a*a;
}
template<class T>inline string tostring(T a)
{
    ostringstream os("");
    os << a;
    return os.str();
}
template<typename T>inline ll tolong(T a)
{
    ll res;
    istringstream os(a);
    os>>res;
    return res;
}
template<typename T>inline T gcd(T a, T b)
{
    if (b == 0)return a;
    else return gcd(b, a % b);
}
template<typename T>inline T bigmod(T a, T b, T m)
{
    if (b == 0)return 1;
    else if (b % 2 == 0)return S(bigmod(a, b / 2, m)) % m;
    else return (a % m*bigmod(a, b - 1, m)) % m;
}

int main()
{
    ios_base::sync_with_stdio(0);
    //ll n,c,cnt=0,prev;
    string s,s1;
    cin>>s>>s1;
    int len1=s.length();
    int len2=s1.length();

    if(len1==len2)
    {
        if(s==s1)cout<<"EQUAL"<<endl;
        else if(s[0]>s1[0])cout<<"GREATER"<<endl;
        else cout<<"LESS"<<endl;
    }
    else if(len1>len2)cout<<"GREATER"<<endl;
    else cout<<"LESS"<<endl;
}




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

const int maxn = 1e5 + 10;
const int INF = 0x7fffffff;
int n, l, r, q[maxn], dis[2][maxn];

vector <int> e[maxn];

int main() {
	scanf("%d", &n);
	for (int i = 1, u, v; i < n; i++) {
		scanf("%d %d", &u, &v);
		e[u].push_back(v), e[v].push_back(u);
	}
	for (int i = 1; i <= n; i++) {
		dis[0][i] = dis[1][i] = INF;
	}
	dis[0][1] = 0;
	l = 1, r = 0;
	q[++r] = 1;
	for (; l <= r; ) {
		int u = q[l++];
		for (int v : e[u]) {
			if (dis[0][v] > dis[0][u] + 1) {
				dis[0][v] = dis[0][u] + 1;
				q[++r] = v;
			}
		}
	}
	dis[1][n] = 0;
	l = 1, r = 0;
	q[++r] = n;
	for (; l <= r; ) {
		int u = q[l++];
		for (int v : e[u]) {
			if (dis[1][v] > dis[1][u] + 1) {
				dis[1][v] = dis[1][u] + 1;
				q[++r] = v;
			}
		}
	}
	int sum1 = 0, sum2 = 0;
	for (int i = 1; i <= n; i++) {
		if (dis[0][i] > dis[1][i]) {
			sum2++;
		} else {
			sum1++;
		}
	}
	puts(sum1 > sum2 ? "Fennec" : "Snuke");
	return 0;
}

Measured memory_bytes: 6912
#include <bits/stdc++.h>
using namespace std;
long long a,m;
int main()
{
    cin>>a>>m;
    for(int i=1;i<=m;++i)
    {
        long long x;cin>>x;
        a=a-x;
    }
    if(a>=0) cout<<a;else cout<<-1;
}


Measured memory_bytes: 3624
while True:
    m,f,r = map(int,input().split())
    if m == f == r == -1:
        break

    if m == -1 or f == -1:
        print("F")
    elif m + f >= 80:
        print("A")
    elif m + f >= 65:
        print("B")
    elif m + f >= 50:
        print("C")
    elif m + f >= 30:
        if r >= 50:
            print("C")
        else:
            print("D")
    elif m + f >= 0:
        print("F")


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

int gcd(int n,int m){
  if(n<m){
    swap(n,m);
  }
  if(n%m==0){
    return m;
  }
  else {
    gcd(n%m,m);
  }
}

int main(){
  int n,x;
  cin >> n >> x;
  int a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  for(int i=0;i<n;i++){
    a[i]=abs(a[i]-x);
  }
  int ans=a[0];
  for(int i=0;i<n;i++){
    ans=gcd(ans,a[i]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <map>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline bool Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+" ";
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
constexpr const ll INF = 1e15;
constexpr const ll MOD = 1000000007;
constexpr int nx[4] = {1,0,-1,0};
constexpr int ny[4] = {0,1,0,-1};
typedef pair<ll,ll> P;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll k,n;
    cin >> k >> n;
    vector<ll> a(n);
    cins(all(a));
    ll max = 0;
    rep(i,n-1) chmax(max,a[i+1]-a[i]);
    chmax(max,a[0]+(k-a[n-1]));
    PRINT(k-max);
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int H,W,four=0,two=0,one=0;
    cin>>H>>W;
    
    if(H%2&&W%2){
        two+=W+H-2;
        one+=1;
    }else if(H%2) two+=W;
    else if(W%2) two+=H;
    four=H*W-two-one;
    
    map<char,int> dic;
    rep(i,H)rep(j,W){
        char c; cin>>c;
        dic[c]++;
    }
    
    for(auto p:dic){
        int n=p.second;
        if(four){
            int f=min(n,four)/4;
            four-=f*4;
            n-=f*4;
        }
        if(two){
            int t=min(n,two)/2;
            two-=t*2;
            n-=t*2;
        }
        if(one){
            int o=min(n,one);
            one-=o;
            n-=o;
        }
        if(n){
            cout1("No");
            return 0;
        }
    }
    cout1("Yes");
}

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

#define all(x) (x).begin(), (x).end()
#define pb push_back

typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;

int main(){
	string s,t;
	cin>>s>>t;
	vi st(26,-1);
	vi gl(26,-1);

	for (int i = 0; i < s.size(); ++i){
		int a=s[i]-'a';
		int b=t[i]-'a';

		if(st[a]!=-1||gl[b]!=-1){
			if(st[a]!=b||gl[b]!=a){
				cout<<"No"<<endl;
				return 0;
			}
		}else{
			st[a]=b;
			gl[b]=a;
		}
	}

	cout<<"Yes"<<endl;

}


Measured memory_bytes: 776
#include <stdio.h>
#include <math.h>
#include <stdbool.h>

int main(void) {
	int n = 0;
	int num[2001] = {};		//???????????????????????°???????????°1.
	int a = 0;					//????????\?????????????´?.
	int q = 0;

	int i = 0;
	int j = 0;

	scanf("%d", &n);

	//?????§???????????°???????´?.
	for (i = 0; i < n; i++) {
		scanf("%d", &a);

		num[0] = 1;

		for (j = 2000; j >= 0; j--) {
			if (num[j] && j + a < 2001)
				num[j + a] = 1;
		}
	}

	//??????.
	scanf("%d", &q);

	for (i = 0; i < q; i++) {
		scanf("%d", &a);

		if (num[a])
			printf("yes\n");
		else
			printf("no\n");
	}

	return 0;
}

Measured memory_bytes: 588
class Main{
    public static void main(String[] a){
		for(int i = 1; i<10; i++ ){
			for(int j=1; j<10; j++){
				System.out.println(i+"x"+j+"="+kuku(i,j));
			}
    }
}
	public static int kuku(int a,int b){
		return a*b;
	}
}

Measured memory_bytes: 16844
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <deque>

int main(){
  int N;
  scanf("%d", &N);
  std::string S;
  std::cin >> S;
  std::vector<int > left(N), right(N);
  left[0]=0;
  right[0] = 0;
  for (int i=1; i<N; i++){
    left[i] = left[i-1];
    right[i] = right[i-1];
    if (S[i-1]=='W'){
      left[i]++;
    }
    if (S[N-i]=='E'){
      right[i]++;
    }
  }
  int ans = 1e9;
  for (int i=0; i<N; i++){
    ans = std::min(ans, left[i]+right[N-i-1]);
  }
  printf("%d\n", ans);
  return 0;
}


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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

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

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n;
    cin >> n;
    string c;
    cin >> c;
    int l = 0, r = n-1;
    int cnt = 0;
    while (l<r) {
        if (c[l]!='W' || c[r]!='R') {
            if (c[l]!='W') ++l;
            if (c[r]!='R') --r;
        }
        else {
            ++cnt;
            ++l; --r;
        }
    }
    cout << cnt << endl;
    return 0;
}


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

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

	if (s[2] == s[3] && s[4] == s[5])
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
import Data.IORef
import Control.Monad
import qualified Data.ByteString.Char8 as BC
import Data.Maybe
  
main :: IO()
main = BC.getLine >> BC.getContents >>= solve.map (fst.fromJust.BC.readInt).BC.lines >>= print
  
solve :: [Int] -> IO Int
solve (x : y : xs) = do
                a <- newIORef (y - x)
                b <- newIORef (if x < y then x else y)
                forM_ xs $ \z -> do
                    a' <- readIORef a
                    b' <- readIORef b
                    when (z - b' > a') $ writeIORef a (z - b')
                    when (z < b')      $ writeIORef b z
                readIORef a

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

int main() {
  while(true) {
    int e; cin >> e;
    if(e == 0) break;
    int res = (int)1e9;
    for(int z = 0; z*z*z <= e; z++) {
      for(int y = 0; y*y + z*z*z <= e; y++) {
        int x = e - z*z*z - y*y;
        res = min(res, x+y+z);
      }
    }
    cout << res << endl;
  }
}

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

typedef long long ll;
typedef pair<string, int> ii;
typedef pair<int, ii> iii;

int main()
{
    int n;
    scanf("%d", &n);

    iii inp[n];
    for (int i = 0; i < n; i++) {
        char s[111];
        scanf("%s %d", s, &inp[i].second.second);
        inp[i].first = i + 1;
        inp[i].second.first = s;
    }

    sort(inp, inp + n, [](const iii a, const iii b) -> bool {
        if (a.second.first == b.second.first)
            return a.second.second > b.second.second;
        return a.second.first < b.second.first;
    });

    for (int i = 0; i < n; i++)
        printf("%d\n", inp[i].first);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define f first
#define s second
#define int long long int

main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	map<string, int>m;
	cin>>n;
	while(n--){
		string s;
		cin>>s;
		m[s]++;
		
	}
	cout<<"AC"<<" x "<<m["AC"]<<endl;
	cout<<"WA"<<" x "<<m["WA"]<<endl;
	cout<<"TLE"<<" x "<<m["TLE"]<<endl;
	cout<<"RE"<<" x "<<m["RE"]<<endl;
	return 0;
}

Measured memory_bytes: 3664
#include<stdio.h>
int MAX = 2000000;
int main(){
  int i,R[MAX],n;

  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&R[i]);

  int maxv = -2000000000;
  int minv = R[0];

  for(i = 1; i < n; i++){
    if(maxv<R[i]-minv) maxv = R[i]-minv;
    if(minv>R[i]) minv = R[i];
  }
  printf("%d\n",maxv);
  return 0;
}



Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int n,m;
int t[6]={1,2,4,8,16,32};
long long a,res=0;
int main(){
 cin>>n>>m;
long long x=t[m];
a=(n-m)*100ll+1900ll*m;
res=a*x;
cout<<res;
}

Measured memory_bytes: 256
import math

N, D = map(int, input().split())
x=[['' for i in range(D)] for j in range(N)]
for i in range(N):
  x[i]=list(map(int,input().split()))
count=0
for i in range(N):
  for j in range(0,i):
    sum=0
    for k in range(D):
      sum+=pow(x[i][k]-x[j][k],2)
    #print(math.sqrt(sum).is_integer(),str(math.sqrt(sum)))
    if math.sqrt(sum).is_integer():
      count+=1
print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100000;

int main() {
	ll n,k;cin>>n>>k;
	ll t[N],d[N];
	rep(i,n) cin>>t[i]>>d[i];

	ll maxd[N+1];
	rep(i,n+1) maxd[i]=0;
	rep(i,n) maxd[t[i]]=max(d[i],maxd[t[i]]);

	pll p[N];
	rep(i,n) p[i]=pll(d[i],t[i]);

	vector<pll> vpll;
	rep(i,n+1) if(maxd[i]!=0) vpll.push_back(pll(maxd[i],i));

	sort(p,p+n,greater<pll>());
	sort(vpll.begin(),vpll.end(),greater<pll>());

	ll ans=0,ct=0;
	ll cnt[N+1];
	rep(i,n+1) cnt[i]=0;
	rep(i,k){
		ans+=p[i].first;
		cnt[p[i].second]++;
	}

	rep(i,n+1) if(cnt[i]>0) ct++;
	ans+=ct*ct;
	ll anst=ans;

	for(int i=k-1;i>=0;i--){
		if(cnt[p[i].second]<2) continue;
		if(ct>=vpll.size()) break;
		cnt[p[i].second]--;
		anst-=p[i].first;
		anst+=vpll[ct].first;
		anst+=2*ct+1;
		ct++;
		ans=max(anst,ans);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 7156