akhauriyash/Code-Regression huggingface dataset:
n, m = map(int, input().split())
edges = [list(map(lambda x: int(x) - 1, input().split())) for _ in range(m)]

q = int(input())
vv = [None] * q
dd = [None] * q
cc = [None] * q
dp = [[-1 for j in range(11)] for i in range(n)]
for i in range(q):
    vv[i], dd[i], cc[i] = map(int, input().split())
    dp[vv[i] - 1][dd[i]] = i

for i in reversed(range(1, 11)):
    for j in range(n):
        dp[j][i - 1] = max(dp[j][i - 1], dp[j][i])
    for u, v in edges:
        dp[u][i - 1] = max(dp[u][i - 1], dp[v][i])
        dp[v][i - 1] = max(dp[v][i - 1], dp[u][i])

for i in range(n):
    if dp[i][0] == -1:
        print('0')
    else:
        print(cc[dp[i][0]])



Measured memory_bytes: 107480
#include <stdio.h>
int main(){
	int a,b,c;
	scanf("%d %d",&a,&b);
	c = a+b;
	if (c>16){
		printf(":(");
	}else if (a>8){
		printf(":(");
	}else if (b>8){
		printf(":(");
	}else{
		printf("Yay!");
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <iterator>

using namespace std;

int main() {
	set<int> A, B;
	set<int> V;
	int n, m;
	int x;

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x;
		A.insert(x);
	}

	cin >> m;
	for (int i = 0; i < m; i++) {
		cin >> x;
		B.insert(x);
	}
	
	set_intersection(A.begin(), A.end(), B.begin(), B.end(), inserter(V, V.end()));
	   
	for (auto it = V.begin(); it != V.end(); it++) 
		cout << *it << endl;
}


Measured memory_bytes: 23688
jin,ter,q=map(int,input().split())
INF=10**19
jil,tel=[-INF]+[int(input()) for i in range(jin)]+[INF],[-INF]+[int(input()) for i in range(ter)]+[INF]
from bisect import bisect_right as bl
for _ in range(q):
    x=int(input())
    ans=INF
    b,d=bl(jil,x),bl(tel,x)
    for s in jil[b-1:b+1]:
        for t in tel[d-1:d+1]:
            ans=min(min(abs(x-s),abs(t-x))+abs(t-s),ans)
    print(ans)

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

using namespace std;
using ll = long long;


int main()
{
    int n;
    string s;
    cin>>n>>s;
    int k = s.length();
    vector<char> v;
    for(char a='A';a<='Z';a++){
        v.push_back(a);
    }
     for(char a='A';a<='Z';a++){
        v.push_back(a);
    }
   // for(auto c:v)cout<<c<<endl;

    for(int i=0;i<k;i++){
            int p;
        for(int j=0;j<26;j++){
            if(v[j]==s[i]){
                p=j;
                //cout<<p<<endl;
                break;
            }

        }
 cout<<v[p+n];
    }

    return 0;
}


Measured memory_bytes: 256
//{Headers
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<algorithm>
#include<list>
#include<queue>
#include<deque>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<bitset>

using namespace std;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > pii;
#define mp(x,y) make_pair(x,y)
typedef long long ll;
//}

const int MAXN=1e4,MAXM=1e8;
int N,M,par[MAXN+1];
pair<int,int> pt[MAXN+1];
struct Edge{int from,to;double cost;} edge[MAXM];

bool cmp(const Edge& a,const Edge& b){return a.cost>b.cost;}

double dist(int from,int to){
    return sqrt(pow(pt[from].first-pt[to].first,2)
                +pow(pt[from].second-pt[to].second,2));
}

int root(int x){return x==par[x]?x:par[x]=root(par[x]);}

bool unite(int x,int y){
    int rx=root(x),ry=root(y);
    if(rx>ry) par[rx]=ry;
    else if(rx<ry) par[ry]=rx;
    else return false;
    return true;
}

void solve(){
    double ans=0;
    for(int i=0;i<M;i++) ans+=edge[i].cost;
    sort(edge,edge+M,cmp);
    for(int i=1;i<=N;i++) par[i]=i;
    for(int i=0;i<M;i++) if(unite(edge[i].from,edge[i].to))
        ans-=edge[i].cost;
    printf("%.8f\n",ans);
}

int main(void){
//    freopen("in.txt","r",stdin);
    while(~scanf("%d%d",&N,&M)){
        for(int i=1;i<=N;i++) scanf("%d%d",&pt[i].first,&pt[i].second);
        for(int i=0;i<M;i++){
            scanf("%d%d",&edge[i].from,&edge[i].to);
            edge[i].cost=dist(edge[i].from,edge[i].to);
        }
        solve();
    }
    return 0;
}

/*
Sample Input 1
3 3
0 0
3 0
0 4
1 2
2 3
3 1
Output for the Sample Input 1
3.000
Sample Input 2
4 3
0 0
-100 0
100 0
0 100
1 2
1 3
1 4
Output for the Sample Input 2
0.000
Sample Input 3
6 7
2 0
6 0
8 2
6 3
0 5
1 7
1 2
2 3
3 4
4 1
5 1
5 4
5 6
Output for the Sample Input 3
7.236
Sample Input 4
6 6
0 0
0 1
1 0
30 0
0 40
30 40
1 2
2 3
3 1
4 5
5 6
6 4
Output for the Sample Input 4
31.000
*/



Measured memory_bytes: 3852
#include <iostream>
#include <vector>
#include <set>
 #include <iomanip>
using namespace std;

double r2(double n){
	double i=0;
	double ans = 1;
	while(i<n){
		ans = ans/2;
		i++;
	}
	return ans;
}

double r1(double a,double b){
	double n=0;
	double c=a;
	while(a<b){
		a = a*2;
		n++;
	}
	return n;
}
int main(){
	double N,K;
	cin >> N >>K;
	double ans=0;
	for(double i=1;i<=N;i++){
		//i+1
		//cout << ans << endl;
		ans += r2(r1(i,K));
	}
	
	cout <<setprecision(20)<< ans/N << endl;
}


Measured memory_bytes: 256
primes = []
for i in range(2, 10 ** 4):
    for j in primes:
        if i % j == 0:
            break
    else:
        primes.append(i)

n = int(input())
cnt = 0
for i in range(n):
    p = int(input())
    if p in primes:
        cnt += 1
    elif p > 10 ** 4:
        for j in primes:
            if p % j == 0:
                break
        else:
            cnt += 1
    else:
        pass
print(cnt)



Measured memory_bytes: 5620
#include <bits/stdc++.h>
using namespace std;
// define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (((a)%mod) * ((b)%mod)) % mod
#define rollcall cout << "I'm Sucu." << endl;
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// debug
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
  }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void PRINTF(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void PRINTF(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
string substr(const string &str, int S1, int S2 = -1){
  if(S2 == -1)return str.substr(S1);
  return str.substr(S1, S2-S1);
}
// typedef
typedef complex<double> Point;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;
// int sum = accumulate(a, a+n, 0LL);
// int mx = max_element(a, a+n);
// int mn = min_element(a, a+n);
// int cnt = count(a, a+n, k);

int n, a[200000];
int gcd(int a, int b){
  if(a == 0 || b == 0)return max(a, b);
  if(a == b)return a;
  if(a > b)a = a%b;
	else b = b%a;
  return gcd(a, b);
}

bool solve(){
  int sum = -n, cnt = 0, ng = 0;
  rep(i,n)sum += a[i];
  rep(i,n)if(a[i]%2 == 1)cnt++;
  rep(i,n)if(a[i] == 1)ng = 1;
  if(ng)return sum%2;
  if(sum%2 == 1 and cnt > 1)return true;
  if(sum%2 == 0 and cnt > 1)return false;
  if(sum%2 == 1 and cnt == 1)return true;
  if(sum%2 == 0 and cnt == 1){
    rep(i,n)if(a[i]%2 == 1)a[i]--;
    int g = a[0];
    rep(i,n-1)g = gcd(g, a[i+1]);
    rep(i,n)a[i] /= g;
    return !solve();
  }
  return false;
}

signed main(){
  cin >> n;
  rep(i,n)cin >> a[i];
  cout << (solve() ? "First" : "Second") << endl;
  return 0;
}





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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;
// const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

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

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

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

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

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}


int main() {
  int N;
  cin >> N;
  vector< int > A(N);
  cin >> A;
  int now = 1;
  for(int i = 0; i < N; i++) {
    if(A[i] == now) ++now;
  }
  if(now == 1) cout << -1 << endl;
  else cout << N - now + 1 << endl;
}

Measured memory_bytes: 1024
/* * * * * * * * * * * **
*                      *
*	   saurabh8522	   *
*	  I will handle	   *
*		   IT.		   *
*                      *
* * * * * * * * * * * **/
#include<bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define ld long double
#define zero(a) memset((a),0,sizeof((a)))
#define one(a) memset((a),1,sizeof((a)))
#define minus(a) memset((a),-1,sizeof((a)))
#define all(g) g.begin(),g.end()
#define ppb pop_back
using namespace std;
typedef long long int ll;
#define MOD 1000000007
ll extgcd(ll a,ll b,ll& x,ll& y){if(b==0){x=1;y=0;return a;}else{int g=extgcd(b,a%b,y,x);y-=a/b*x;return g;}}
ll modpow(ll a,ll b) {ll res=1;a%=MOD;for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
ll numdigit(ll n){return floor(log10(n)) + 1;}
bool isPowerTwo (ll x) { return x && (!(x&(x-1))); }
ll dp[10005][2][105]; 
ll d;
string k;
ll builddp(ll pos,int flag,int rem){
	// cout<<pos<<" "<<flag<<" "<<rem<<" "<<res<<endl;
	if(pos==k.size()){
		return (rem==0);
	}
	ll &ans=dp[pos][flag][rem];
	if(ans!=-1) return ans;
	ans=0;
	int num=k[pos]-'0';
	if(flag==0){
		for(int i=0;i<=num;i++){
			// string res1=res;
			// res1+=(i+'0');
			ans=(ans+builddp(pos+1,(i<num),(rem+i)%d))%MOD;
			ans%=MOD;
		}
	}
	else{
		for(int i=0;i<=9;i++){
			// string res1=res;
			// res1+=(i+'0');
			ans=(ans+builddp(pos+1,1,(rem+i)%d))%MOD;
			ans%=MOD;
		}
	}
	// cout<<"After DP-====>>"<<pos<<" "<<flag<<" "<<rem<<" "<<ans<<endl;
	return ans;
}
int  main(){
	FastRead;
	ll t=1;
	// cin>>t;
	while(t--){
		// string k;
		// ll d;
		cin>>k>>d;
		// string res="/";
		minus(dp);
		builddp(0,0,0);
		// builddp(0,k,1,0,0,d,res);
		// cout<<"ans="<<dp[0][0][0]<<endl;
		ll ans=(dp[0][0][0]-1+MOD)%MOD;
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 17408
H, W = map(int, input().split())
if (H%3) * (W%3) == 0:
  print(0)
  quit()

ans = min(H, W)
w1 = W // 2
w2 = W - w1
S1 = (H - 1) * w1
S2 = (H - 1) * w2
S3 = W
for i in range(H-1):
  diff = max(S1, S2, S3) - min(S1, S2, S3)
  ans = min(ans, diff)
  S1 -= w1; S2 -= w2; S3 += W

h1 = H // 2
h2 = H - h1
S1 = (W - 1) * h1
S2 = (W - 1) * h2
S3 = H
for i in range(W-1):
  diff = max(S1, S2, S3) - min(S1, S2, S3)
  ans = min(ans, diff)
  S1 -= h1; S2 -= h2; S3 += H

print(ans)

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

using namespace std;

long long int n;
long long int ans;

void dfs(string s) {
    if (stol(s) > n) {
        return;
    }

    if ((int)s.find("3") != -1 && (int)s.find("5") != -1 && (int)s.find("7") != -1) {
        ans++;
    }

    dfs(s+'3');
    dfs(s+'5');
    dfs(s+'7');
}

int main()
{
    cin >> n;

    dfs("3");
    dfs("5");
    dfs("7");

    cout << ans << endl;
}




Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int W, H, x, y, r;

		Scanner scan = new Scanner(System.in);

		W = scan.nextInt();
		H = scan.nextInt();
		x = scan.nextInt();
		y = scan.nextInt();
		r = scan.nextInt();

		if (0 <= x-r && x+r <= W) {
			if(0 <= y-r && y+r <= H){
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 26248
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define abdelrahman001 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
using namespace std;
ll n,t;
pair<ll,ll>arr[200005];
int main()
{
    abdelrahman001
    cin >> n;
    for(int i = 0;i<n;i++)
        cin >> arr[i].second >> arr[i].first;
    sort(arr,arr+n);
    for(int i = 0;i<n;i++)
    {
        t+=arr[i].second;
        if(t > arr[i].first)
            return cout << "No",0;
    }
    cout << "Yes";
    return 0;
}


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

struct LazySegmentTree{
private:
    int siz;
    vector<ll> node,lazy;
public:
    LazySegmentTree(int n){
        siz=1;
        while(siz<n)siz*=2;
        node.resize(2*siz-1);
        lazy.resize(2*siz-1);
    }
    void eval(int k){
        node[k]+=lazy[k];
        if(k<siz-1){
            lazy[2*k+1]+=lazy[k];
            lazy[2*k+2]+=lazy[k];
        }
        lazy[k]=0;
    }
    void update(int a,int b,ll x,int k,int l,int r){
        eval(k);
        if(b<=l||r<=a)return;
        if(a<=l&&r<=b){
            lazy[k]+=x;
            eval(k);
        }else{
            update(a,b,x,2*k+1,l,(l+r)/2);
            update(a,b,x,2*k+2,(l+r)/2,r);
            node[k]=min(node[2*k+1],node[2*k+2]);
        }
    }
    ll query(int a,int b,int k,int l,int r){
        eval(k);
        if(b<=l||r<=a)return 1e9+10;
        if(a<=l&&r<=b)return node[k];
        ll vl=query(a,b,2*k+1,l,(l+r)/2);
        ll vr=query(a,b,2*k+2,(l+r)/2,r);
        return min(vl,vr);
    }
    void add(int a,int b,ll x){
        update(a,b,x,0,0,siz);
    }
    ll getmin(int a,int b){
        return query(a,b,0,0,siz);
    }
};

void solve(long long N, long long D, long long A, std::vector<long long> X, std::vector<long long> H){
    LazySegmentTree tree(N);
    set<pair<ll, int>> se;
    vector<pair<ll, ll>> uku;
    vector<ll> d;
    for(int i = 0;i < N;i++)uku.push_back(make_pair(X[i], H[i]));
    sort(uku.begin(), uku.end());
    for(int i = 0;i < N;i++){
        tree.add(i, i+1, uku[i].second);
        d.push_back(uku[i].first);
    }
    ll ans = 0;
    for(int i = 0;i < N;i++){
        int itr = upper_bound(d.begin(), d.end(), d[i] + 2*D) - d.begin();
        ans += ceil(1.0 * max(tree.getmin(i, i+1), 0LL) / A);
        tree.add(i, itr, -  A*ceil(1.0*max(tree.getmin(i, i+1), 0LL) / A));
    }
    cout<<ans<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long D;
    scanf("%lld",&D);
    long long A;
    scanf("%lld",&A);
    std::vector<long long> X(N);
    std::vector<long long> H(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&X[i]);
        scanf("%lld",&H[i]);
    }
    solve(N, D, A, std::move(X), std::move(H));
    return 0;
}


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

/*
縦にnマス、横にmマス
ややこしいが、縦方向をxとする。

2つのペアを考える。
x座標の差の絶対値がdになる時、ペアの個数は(n-d)*m*m d=1~n-1
さらに、残りk-2個の組み合わせを考えるとnm-2Ck-2
これらについて、dの総和をとる。
yについても同じことをやれば計算できる。
*/

const int MAX = 510000;
ll 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;
    }
}

// 二項係数計算
ll 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;
}

void solve(){
    ll n,m,k;
    cin >> n >> m >> k;
    ll ans = 0;

    COMinit();

    ll sum1 = 0;
    rep(d,n){
        sum1 += d*(n-d)*m*m;
        sum1 = sum1 % MOD;
    }
    ll tmp1 = 0;
    tmp1 = COM(n*m-2, k-2);

    //cout << "sum1:" << sum1 << " tmp1:" << tmp1 << endl;
    ans = (sum1*tmp1) % MOD;

    ll sum2 = 0;
    rep(d,m){
        sum2 += d*(m-d)*n*n;
        sum2 = sum2 % MOD;
    }
    ll tmp2 = 0;
    tmp2 = COM(n*m-2, k-2);
    //cout << "sum2:" << sum2 << " tmp2:" << tmp2 << endl;

    ans = (((sum2*tmp2) % MOD) + ans) % MOD;

    cout << ans << endl;  
}

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


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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)):((m)-(n))),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)
#define loop for(;;)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

int dx[] = { -1, 0, 1, 0 };
int dy[] = {  0, -1, 0, 1 };

int main() {

  string s;
  char cur = 'A';
  loop {
    cin >> s;
    if (!cin) break;
    if (s[0] == cur) cur = s[2];
    else if (s[2] == cur) cur = s[0];
  }
  cout << cur << endl;

  return 0;
}

Measured memory_bytes: 1176
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
int main() {
  int N;
  cin >> N;
  vector<vector<int>> count(9, vector<int>(9,0));
  rep(i, N){
    int num = i + 1;
    int a = num % 10;
    int b = num;
    while(!(b/10==0)) {
      b /= 10;
    }
    if(!(a==0 || b==0)){
      count.at(a-1).at(b-1)++;
    }
  }
  int ans = 0;
  rep(i, 9){
    rep(j, 9) {
      ans += count.at(i).at(j) * count.at(j).at(i);
    }
  }
  cout << ans << endl;
  return 0;
}


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

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

int main() {

    ll n, k;
    cin >> n >> k;
    string s;
    cin >> s;

    ll ans = 0;
    rep(i, n - 1) {
        if (s[i] == s[i + 1]) ans++;
    }
    ans += 2 * k;
    cout << min(n - 1, ans) << '\n';
    return 0;
}

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

#define REP(i, start, count) for(int i=(start); i<(int)(count); ++i)
#define rep(i, count) REP(i, 0, count)
#define ALLOF(c) (c).begin(), (c).end()

typedef long long ll;
typedef unsigned long long ull;

string S;

int main(void) {

    cin >> S;

    string ans = "";
    for(char c : S) {
        switch(c) {
            case '0':
                ans += '0';
            break;
            case '1':
                ans += '1';
            break;
            case 'B':
                if (ans.size() > 0) {
                    ans.pop_back();
                }
            break;
        }
    }

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

Measured memory_bytes: 256
#include <cstdio>

inline int read()
{
	int data = 0, w = 1; char ch = getchar();
	while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
	if (ch == '-') w = -1, ch = getchar();
	while (ch >= '0' && ch <= '9') data = data * 10 + (ch ^ 48), ch = getchar();
	return data * w;
}

const int N(2e5 + 10), M(5000), L(2000), Mod(1e9 + 7);
int n, ans, a[N], b[N], g[M][M], C[8010][4010];
#define f(x, y) g[(x) + L + 10][(y) + L + 10]

int main()
{
	n = read();
	for (int i = 0; i <= 8000; i++) C[i][0] = 1;
	for (int i = 1; i <= 8000; i++) for (int j = 1; j <= i && j <= 4000; j++)
		C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % Mod;
	for (int i = 1; i <= n; i++)
		a[i] = read(), b[i] = read(), ++f(-a[i], -b[i]);
	for (int i = -L; i <= L; i++)
		for (int j = -L; j <= L; j++)
			f(i, j) = (f(i, j) + (f(i - 1, j) + f(i, j - 1)) % Mod) % Mod;
	for (int i = 1; i <= n; i++)
		ans = (ans + f(a[i], b[i])) % Mod,
		ans = (ans - C[2 * (a[i] + b[i])][a[i] * 2] + Mod) % Mod;
	printf("%lld\n", ans * 500000004ll % Mod);
	return 0;
}

Measured memory_bytes: 206976
#include<iostream>
#include<string>

using namespace std;

int main(){
	string S;
	cin>>S;
	
	bool sta=true;
	for(int i=0 ; i<S.size() ; i++){
		for(int j=i+1 ; j<S.size() ; j++){
			if(S.substr(i,1)==S.substr(j,1)){
				sta=false;
				break;
			}
		}
		if(!sta)break;
	}
	if(sta)cout<<"yes\n";
	else cout<<"no\n";
	
	return 0;
}


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

using namespace std;

inline void _read(int &x)
{
    x = 0;
    char t = getchar();
    while (!isdigit(t)) t = getchar();
    while (isdigit(t))
    {
        x = x * 10 + t - '0';
        t = getchar();
    }
}


typedef long long ll;
typedef vector< pair<ll, ll> > vec;
const int MAXN = 2e5 + 10;

int n, fa[MAXN];
vec g[MAXN], f[MAXN];
ll mid, mv[MAXN];

inline bool cmpx(pair<ll, ll> a, pair<ll, ll> b)
{
	return a.first < b.first;
}
inline bool cmpy(pair<ll, ll> a, pair<ll, ll> b)
{
	return a.second < b.second;
}

inline void work(vec &ls, vec &rs, vec &f)
{
	if(ls.size() > rs.size())swap(ls, rs);
	int el = ls.size(), er = rs.size();

	sort(ls.begin(), ls.end(), cmpy);
	sort(rs.begin(), rs.end(), cmpx);

	mv[0] = rs[0].second;
	for(int i = 1; i < er; i++)
		mv[i] = min(mv[i - 1], rs[i].second);

	for(int i = 0, j = er - 1; i < el; i++)
	{
		while(j >= 0 && ls[i].second + rs[j].first > mid)j--;
		if(j >= 0)f.push_back(pair<ll, ll>(ls[i].first, mv[j]));
	}

	sort(ls.begin(), ls.end(), cmpx);
	sort(rs.begin(), rs.end(), cmpy);
	mv[0] = rs[0].first;
	for(int i = 1; i < er; i++)
		mv[i] = min(mv[i - 1], rs[i].first);

	for(int i = 0, j = er - 1; i < el; i++)
	{
		while(j >= 0 && ls[i].first + rs[j].second > mid)j--;
		if(j >= 0)f.push_back(pair<ll, ll>(mv[j], ls[i].second));
	}
}

inline void dfs(int u)
{
	if(!f[u].empty())f[u].clear();
	if(g[u].empty())
	{
		f[u].push_back(pair<ll, ll>(0, 0));
		return;
	}

	for(int i = 0, e = g[u].size(); i < e; i++)
		dfs(g[u][i].first);

	vec &ls = f[g[u][0].first];
	for(int i = 0, e = ls.size(), c = g[u][0].second; i < e; i++)
		ls[i].first += c, ls[i].second += c;
	vec &rs = f[g[u][1].first];
	for(int i = 0, e = rs.size(), c = g[u][1].second; i < e; i++)
		rs[i].first += c, rs[i].second += c;

	work(ls, rs, f[u]);
	ls.clear();
	rs.clear();
}

int main()
{
    _read(n);
	for(int i = 2, a; i <= n; i++)
	{
        _read(fa[i]);
        int x;
        _read(x);
		g[fa[i]].push_back(pair<ll, ll>(i, x));
	}

	ll l = 0, r = 1e10, ans = 1e10;
	while(l <= r)
	{
		mid = l + r >> 1;
		dfs(1);
		if(f[1].empty())
			l = mid + 1;
		else
			r = mid - 1, ans = mid;
	}

	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 33528
#include <bits/stdc++.h>
using namespace std;
#define int        long long 
#define test       int t;cin>>t;while(t--)
#define tezi       ios_base::sync_with_stdio(false);cin.tie(NULL);
#define F(i,a,b)   for(int i=a;i<b;i++)
#define pb         push_back
#define mp         make_pair
#define pii        pair<int,int>
#define vi         vector<int>
#define umap       unordered_map<int,int>
#define MAXN 200005
#define endl "\n"
#define YES cout<<"YES\n";
#define NO  cout<<"NO\n";
#define ll long long


signed main(){
    tezi
    {
        string n;
        cin>>n;
        int sum = 0;
        for(int i=0;i<n.size();i++){
            int a = n[i] - '0';
            sum +=a;
        }
        if(sum%9 == 0)cout<<"Yes\n";
        else cout<<"No\n";
    }
}

Measured memory_bytes: 3740
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
char st[5],st2[5];
int main()
{
 
   scanf("%s%s",st,st2);
    //puts(st);
    int flag=1;
    int len2=strlen(st2);
    for(int i=0; i<strlen(st); i++)
        if(st[i]!=st2[len2-i-1])
        {
            flag=0;
            break;
        }
    if(flag==0)
        cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
 
    return 0;
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

int G[10][10];

int main() {
    int H, W;
    cin >> H >> W;
    rep(i, 10) rep(j, 10) cin >> G[i][j];

    rep(k, 10) rep(i, 10) rep(j, 10) chmin(G[i][j], G[i][k] + G[k][j]);

    int ans = 0;
    rep(i, H) {
        rep(j, W) {
            int a;
            cin >> a;
            if (a == 1 || a == -1) continue;
            ans += G[a][1];
        }
    }

    cout << ans << endl;
}

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

int main()
{
	ios::sync_with_stdio(false); 
	cin.tie(0); 
	cout.tie(0);
	int n;
	cin>>n;
	int ans[n+1]={0};
	for(int i=1;i<100;i++)
	{
		for(int j=1;j<=100;j++)
		{
			for(int k=1;k<=100;k++)
			{
				int x=i*i+j*j+k*k+i*j+j*k+i*k;
				if(x<=n)ans[x]++;
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		cout<<ans[i]<<"\n";
	}
	return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
const ll MOD = 1e9+7;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
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; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
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(); cout << ans << endl; }
#define fs first
#define sc second


const int INF = 1e9;
const ll LLINF = 1e16;

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}
 
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}
 
template<typename T>
T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T>
T ngcd(vector<T> a){
    T res;
    res = a[0];
    for(int i = 1; i < a.size() && res != 1; i++) {
        res = gcd(a[i], res);
    }
    return res;
}
 
template<typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

template<typename T>
T nlcm(vector<T> numbers) {
    T res;
    res = numbers[0];
    for (int i = 1; i < numbers.size(); i++) {
        res = lcm(res, numbers[i]);
    }
    return res;
}


// 素数判定
template<typename T>
bool isPrime(T x){
    T i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 回文判定
bool kai (string s) {
    string t{s};
    reverse(begin(t), end(t));
    return s == t;
};

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}



// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
  return (a + b - 1) / b;
}


using pint = pair<int, int>;
using pll = pair<ll, ll>;

int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    double r;
    cin >> r;
    print(2.0 * r * 3.14);

}



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

#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define irrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define irrep2(i,n,a) for(int i = (int)(n); i >= (int)(a); i--)

#define fi first
#define se second

using namespace std;

using ll = long long;
using v_int = vector<int>;
using v2_int = vector<v_int>;
using v_ll = vector<ll>;
using v2_ll = vector<v_ll>;
using v_string = vector<string>;
using v_bool = vector<bool>;
using v2_bool = vector<v_bool>;
using pii = pair<int, int>;
using mii = map<int, int>;

const double PI = 3.1415926535897932;
const int INF = (int)2e9;
const ll LINF = (ll)2e18;
const ll MOD = 1000000007;
const int dc[8] = {1, -1, 0,  0, 1, -1,  1, -1};
const int dr[8] = {0,  0, 1, -1, 1,  1, -1, -1};

template<typename T, typename U> inline
ostream& operator<<(ostream &o, pair<T,U> &p) {
    return o << "{" << p.first << "," << p.second << "}";
}
template<typename T> inline
istream& operator>>(istream &is, vector<T> &vec) {
    for(auto &v : vec) { is >> v; }
    return is;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<T> &vec) {
    for(auto &v : vec) { os << v << ",";}
    return os;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<vector<T> > &mat) {
    for(auto &row : mat) { os << row << endl; }
    return os;
}
template<typename T> inline
void chmin(T &a, T b) { a = min(a, b); }
template<typename T> inline
void chmax(T &a, T b) { a = max(a, b); }

struct Edge {
    int cost, to;
    Edge(int to_, int cost_) : 
        to(to_), cost(cost_) { } 
};

using Graph = vector<vector<Edge> >;

Graph graph;
v_int ans;

void solve(int from, ll d)
{
    for(auto node : graph[from]) {
        if(ans[node.to] != INF) { continue; }    
        if((d + node.cost)%2 == 0) {
            ans[node.to] = 1;    
        } else {
            ans[node.to] = 0;
        }
        solve(node.to, d+node.cost);
    }
}

int main(void)
{
    int n;
    cin >> n;
    
    graph.resize(n);
    ans.assign(n, INF);

    irep(i, n-1) {
        int u, v, w;
        cin >> u >> v >> w;
        graph[u-1].push_back(Edge(v-1, w));
        graph[v-1].push_back(Edge(u-1, w));
    }

    ll d = 0;
    ans[0] = 1;

    solve(0, d);

    irep(i, n) {
        cout << ans[i] << endl;
    }
    
    return 0;
} /*atcoder*/


Measured memory_bytes: 10704
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

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

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

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

  vector<ll> P(5);
  rep(i, 5) cin >> P[i];

  sort(all(P));
  ll ans = 4 + (N + P[0] - 1) / P[0];

  cout << ans << endl;
}

Measured memory_bytes: 256
A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
f = [[0] * 3 for _ in range(3)]
for _ in range(N):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if A[i][j] == b:
                f[i][j] = 1
res = "No"
if f[0][0] == 1 and f[0][1] == 1 and f[0][2] == 1:
    res = "Yes"
if f[1][0] == 1 and f[1][1] == 1 and f[1][2] == 1:
    res = "Yes"
if f[2][0] == 1 and f[2][1] == 1 and f[2][2] == 1:
    res = "Yes"
if f[0][0] == 1 and f[1][0] == 1 and f[2][0] == 1:
    res = "Yes"
if f[0][1] == 1 and f[1][1] == 1 and f[2][1] == 1:
    res = "Yes"
if f[0][2] == 1 and f[1][2] == 1 and f[2][2] == 1:
    res = "Yes"
if f[0][0] == 1 and f[1][1] == 1 and f[2][2] == 1:
    res = "Yes"
if f[2][0] == 1 and f[1][1] == 1 and f[0][2] == 1:
    res = "Yes"

print(res)


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


#define deb(x,y) cout << ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>   " << #x << ':' << x <<" ###### "<< y <<"\n";
#define ll long long  


using namespace std;

int main(){

	//freopen("input.txt","r",stdin);

	int a,b,c,i,sum=0;

	cin>>a;

	for(i=0 ; i<a ;i++){
		cin>>b;
		cin>>c;
		sum=sum+(abs(c-b)+1);
	}
	cout<<sum;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //  repマクロ
#define leng(n) (int)(log10(n)+1)  //  桁数
using namespace std;

signed main() {
  int H, W, h, w;
  cin >> H >> W >> h >> w;
  cout << H * W - H * w - h * W + h * w << endl;
}

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

#define fs first
#define sc second
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

const int32_t inf = 1001001001;
const int64_t infll = 1001001001001001001ll;
const int dx[] = {0, -1, 1, 0, -1, 1, -1, 1}, dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};

template <typename T> using vector2d = vector<vector<T>>;

// clang-format off
template <typename T> void sort(vector<T> &v) { sort(all(v)); }
ostream &operator<<(ostream &os, __int128_t value) { if (ostream::sentry(os)) { __uint128_t tmp = value < 0 ? -value : value; char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[tmp % 10]; tmp /= 10; } while (tmp != 0); if (value < 0) { --d; *d = '-'; } int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); }} return os; }
istream &operator>>(istream &is, __int128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } if (in[0] == '-') value *= -1; return is; }
ostream &operator<<(ostream &os, __uint128_t value) { if (ostream::sentry(os)) { char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[value % 10]; value /= 10; } while (value != 0); int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); }} return os; }
istream &operator>>(istream &is, __uint128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } return is; }
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { os << v[0]; for (int i = 1; i < v.size(); ++i) os << " " << v[i]; return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << p.fs << " " << p.sc; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.fs >> p.sc; return is; }

struct IoSetup { IoSetup(){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup;

inline int64_t in() { int64_t x = 0; cin >> x; return x; }
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on

signed main(int argc, char *argv[]) {
  int m = 24 - in() + 24;
  cout << m << endl;
}


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

using namespace std;

int main()
{
  int a[100001]={};
  int n,ans=0;
  cin>>n;
  for(int i=0;i<n;++i){
    int c;
    cin>>c;
    if(c>100000)++ans;
    else a[c]++;
  }
  for(int i=1;i<=100000;++i){
    if(a[i]>i)ans+=a[i]-i;
    if(a[i]<i)ans+=a[i];
  }
  cout<<ans<<endl;
}


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

using ll = long long;

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

    int N;
    cin >> N;
    const int MAX_NUM = (int) 1e9 + 1;
    int min_num = MAX_NUM;
    ll sum = 0;
    int continuous_minus = 0;
    int minus_groups = 0;
    while (N--) {
        int a;
        cin >> a;
        min_num = min(min_num, abs(a));
        sum += abs(a);
        if (a < 0) {
            continuous_minus++;
        } else {
            minus_groups += continuous_minus % 2 == 1;
            continuous_minus = 0;
        }
    }
    minus_groups += continuous_minus % 2 == 1;

    if (minus_groups % 2 == 1) {
        cout << sum - min_num * 2 << '\n';
    } else {
        cout << sum << '\n';
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
#define pb push_back
using namespace std;

int main() {
	int n, x, ans = 1e9;
	set<pair<int,int> > st, st2;
	map<int,int> mep, mep2;
	cin>>n;
	for(int i = 0; i < n; i++) {
		cin>>x;
		if(i % 2 == 0) mep[x]++;
		else mep2[x]++;
	}
	if(mep.size() == 1 && mep2.size() == 1 && *(mep.begin()) == *(mep2.begin())) {
		cout<<n/2<<endl;
		return 0;
	}
	for(auto it : mep) {
		st.insert({n/2-it.second, it.first});
	}
	for(auto it : mep2) {
		st2.insert({n/2-it.second, it.first});
	}
	// for(auto it : st) cout<<(it.first)<<" "<<(it.second)<<endl;
	// for(auto it : st2) cout<<(it.first)<<" "<<(it.second)<<endl;
	auto it = st.begin();
	auto it2 = st2.begin();
	if(it->second != it2->second) {
		ans = it->first + it2->first;
	}
	else {
		auto it3 = it;
		it3++;
		if(it3 != st.end()) {
			int temp = it3->first + it2->first;
			ans = min(ans, temp);
		}
		it3 = it2;
		it3++;
		if(it3 != st2.end()) {
			int temp = it3->first + it->first;
			ans = min(ans, temp);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll n, m;
    cin >> n >> m;
    ll ans = 0;
    if (n == 1 && m == 1) ans = 1;
    else if (n >= 2 && m >= 2) ans = (n-2) * (m-2);
    else ans = max(max(n-2, m-2), 0LL);
    cout << ans << endl;
}

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

// int/long:		-2,147,483,648 - 2,147,483,648 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<29)
//536,870,912

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

#define	MOD 1000000007

int	main() {
	int N=0;
	string S;
	cin >>S;
	for (int i=0; i<4; i++)
		if ('+'==S.at(i))
			N++;
		else 
			N--;
	cout << N <<endl;
	return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();

        boolean aliceTurn = true;
        if(Math.abs(a - b) == 1) {
            System.out.println("Borys");
            return;
        }

        while (Math.abs(a - b) != 1) {
            if(aliceTurn) {
                if(a == n && b != n - 1) {
                    a--;
                }
                else {
                    a++;
                }
                aliceTurn = false;
            }
            else {
                if(b == n && a != n - 1) {
                    b--;
                }
                else {
                    b++;
                }
                aliceTurn = true;
            }
        }
        // TODO: this doesnt take into account that they can move left ?

        if(aliceTurn) {
            System.out.println("Borys");
        }
        else {
            System.out.println("Alice");
        }
    }

}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
typedef unsigned u32;
typedef unsigned long long u64;
const u32 P=1e9+7;
const int N=1e7+5;
u32 fac[N], ifac[N], inv[N];
u64 power(u64 a, int b) {
	u64 ans=1;
	for(; b; a=a*a%P, b/=2) {
		if(b&1) ans=ans*a%P;
	}
	return ans;
}
int main() {
	int n, a;
	u32 ans=0;
	scanf("%d%d", &n, &a);
	fac[0]=1;
	for(int i=1; i<=n; ++i) fac[i]=1llu*fac[i-1]*i%P;
	ifac[n]=power(fac[n], P-2);
	for(int i=n; i--; ) ifac[i]=(i+1llu)*ifac[i+1]%P;
	for(int i=1; i<=n; ++i) inv[i]=1llu*ifac[i]*fac[i-1]%P;
	for(int i=1; i<=a; ++i) {
		for(int k=0; k<i-1; ++k) {
			u32 cur=1llu*fac[i-1]*ifac[k]%P*fac[n-k-1]%P*ifac[i-k-2]%P*inv[i-k+n-a-1]%P;
			if(k&1)
				ans=(ans+P-cur)%P;
			else
				ans=(ans+cur)%P;
		}
	}
	for(int k=0; k<=a; ++k) {
		u32 cur=1llu*fac[a]*ifac[k]%P*fac[n-k-1]%P*ifac[a-k-1]%P;
		if(k&1)
			ans=(ans+P-cur)%P;
		else
			ans=(ans+cur)%P;
	}
	printf("%u\n", ans);
	return 0;
}


Measured memory_bytes: 120972
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<string>
#include<set>

const long long int MOD=1e9+7;

using namespace std;

int main(){
    long long int n;
    cin >> n;
    cout << ((n-1)*n)/2 << endl;
}



Measured memory_bytes: 256
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set; 

int main(){
    fastio
    ll a , b ; 
    cin >> a >> b ; 
    // check if there is a multiple of 2019 in range a b
    int c = b / 2019 - ( a - 1 )/2019;
    if ( c > 0 ) {
    	cout << 0 << endl;
    	return 0 ; 
    }
    a = a % 2019 ; 
    b = b % 2019 ; 
    ll ans = a * b % 2019 ; 
    for(ll i=a;i<b;i++){
    	for(ll j=i+1;j<=b;j++){
    		ans = min(ans,i*j%2019) ; 
    	}
    }
    cout << ans << endl;
    return 0 ;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define BE(x) (x).begin(), (x).end()

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

    if (a+2 >= b || k < a+1) cout << 1 + k << endl;
    else {
        long long x = k-a+1;
        long long y = x/2;
        cout << y*b - (y-1)*a + x%2 << endl;
    }
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

int n, m, r;
int d[210][210];

void init(int n){
   rep(i, 0, n){
       rep(j, 0, n){
           d[i][j] = INF;
           if(i == j) d[i][j] = 0;
       }
   }
}

void warshall_floyd(){
   rep(k, 0, n){
       rep(i, 0, n){
           rep(j, 0, n){
               d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
           }
       }
   }
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m >> r;
    init(n);
    vector<int> a(r);
    rep(i, 0, r){
        cin >> a[i];
        a[i]--;
    }
    rep(i, 0, m){
        int s, t, c;
        cin >> s >> t >> c;
        s--; t--;
        d[s][t] = c;
        d[t][s] = c;
    }   
    warshall_floyd();
    sort(all(a));
    int MIN = 1e18;
    do{
        // for(int ii = 0; ii < r.size(); ii++){
        //     if(ii) cout << ' ';
        //     cout << r[ii];
        // }
        // cout << endl;
        int now = 0;
        rep(i, 0, r - 1){
            now += d[a[i]][a[i + 1]];
        }
        chmin(MIN, now);
    }while(next_permutation(all(a)));
    cout << MIN << endl;
}

Measured memory_bytes: 640
N=int(input())
A=[int(i) for i in input().split()]
M=max(A)
m=min(A)
if M-m>=2:
    print("No")
elif M-m==1:
    x=0
    y=0
    for i in range(N):
        if A[i]==m:
            x+=1
        else:
            y+=1
    if x<M and 2*(M-x)<=y:
        print("Yes")
    else:
        print("No")
else:
    if 2*M<=N or M==N-1:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 13964
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
using namespace std;
typedef long long LL;
#define maxn 101000
 
int n,m;
LL tot,ans;
struct node
{
	LL d,x;
	friend bool operator < (node x,node y)
	{
		if (x.d!=y.d) return x.d<y.d;
		return x.x<y.x;
	}
}a[maxn];
priority_queue<LL,vector<LL>,greater<LL> > q;

inline int read(){
	int X=0,w=0;
	char ch=0;
	while (ch<'0' || ch>'9')
	  w|=ch=='-',ch=getchar();
	while (ch>='0' && ch<='9')
	  X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
	return w ? -X : X;
}

int main()
{
	n=read();m=read()+1;
	for (int i=1;i<=n;i++){
		int A=read(),B=read();
		a[i].x=B;
		a[i].d=m-A;
	}
	sort(a+1,a+1+n);
	for (int i=1;i<=n;i++)
	{
		ans+=a[i].x;tot++;q.push(a[i].x);
		if (tot>a[i].d) {ans-=q.top();q.pop();tot--;}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 2936