akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>

using namespace std;

typedef long long ll;

int main(){
 int N; cin >> N;
  vector<tuple<string,int,int>> A;
    A.clear();
  for(int i = 0; i < N; i++){
    string s; int p; cin >> s >> p;  p = -p;
    A.emplace_back(s,p,i+1);}
  
  sort(A.begin(),A.end());
  
  for(int i = 0; i < N; i++){
    cout << get<2>(A[i]) << endl; }
return 0;}
  
  

Measured memory_bytes: 256
n, m = [int(i) for i in input().split()]
td = [[int(i) for i in input().split()] for n in range(n)]
td.sort(key=lambda x:-x[1])
memo = set()
a = []
for t, d in td:
  if t in memo:
    a.append((d, 0))
  else:
    a.append((d, 1))
  memo.add(t)
a = [(-x, x, d) for x, d in a]
import heapq
heapq.heapify(a)
val = 0
kind = 0
b = []
for _ in range(m):
  ele = heapq.heappop(a)
  val += ele[1]
  kind += ele[2]
  if ele[2] == 0:
    b.append(ele[1])
ans = val + kind ** 2
while (len(a) > 0 and len(b)>0):
  val -= b.pop()
  flag = False
  while(len(a) > 0):
    elem = heapq.heappop(a)
    if elem[2] == 1:
      flag = True
      break
  if not flag:
    break
  val += elem[1]
  kind += 1
  tmpans = val + kind ** 2
  if tmpans > ans:
    ans = tmpans
print(ans)

Measured memory_bytes: 43468
use std::io::{stdin, BufReader, BufRead};

fn main() {
    let input = BufReader::new(stdin());
    let mut heights: Vec<u32> = Vec::new();

    for line in input.lines() {
        match line.unwrap().trim().parse() {
            Ok(v) => heights.push(v),
            Err(_) => break,
        }
    }
    let heights = heights.as_mut_slice();
    heights.sort();
    heights.reverse();
    for h in heights[0..3].iter() {
        println!("{}", h);
    }
}



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

int sgn(int n) {
    if (n>0) return 1;
    else if (n<0) return -1;
    else return 0;
}

int main() {
    int l; cin >> l;
    stack<int> s;
    set<int> li;
    int out = -1;
    rep(i,l) {
        int t; cin >> t;
        if (sgn(t) == 1) {
            if (li.find(t) != li.end()) {
                out = i;
                break;
            }
            else s.push(t);
            li.insert(t);
        }
        else {
            t = -t;
            if (li.find(t) == li.end() or s.top() != t) {
                out = i;
                break;
            }
            else s.pop();
            li.erase(t);
        }
    }
    if (out == -1) cout << "OK" << endl;
    else cout << out+1 << endl;
}


Measured memory_bytes: 3116
def main():
    X=input()
    Y=input()
    dp=[]
    for y in range(len(Y)):
        now=0
        for i  in range(len(dp)):
            d=dp[i]
            if Y[y] in X[now:d]:
                dp[i]=now+X[now:d].index(Y[y])
            now=d+1
        if Y[y] in X[now:]:
            dp.append(now+X[now:].index(Y[y]))
    return len(dp)
for i in range(int(input())):
    print(main())
                 


Measured memory_bytes: 5624
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  if(a+b >= a-b && a+b >= a*b)
    cout << a+b << endl;
  else if(a*b >= a-b && a*b >= a+b)
    cout << a*b << endl;
  else if(a-b >= a+b && a-b >= a*b)
    cout << a-b << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mp make_pair
#define fst first
#define snd second

bool c[64][16];
int w[64][16], num[64], pen[64];

int main() {
    for (;;) {
        int T, P, R;
        scanf("%d%d%d", &T, &P, &R);
        if (T == 0) return 0;
        memset(c, 0, sizeof(c));
        memset(w, 0, sizeof(w));
        memset(num, 0, sizeof(num));
        memset(pen, 0, sizeof(pen));
        rep (_, R) {
            int t, p, ti;
            char msg[16];
            scanf("%d%d%d%s", &t, &p, &ti, msg);
            t--, p--;
            if (msg[0] == 'C') c[t][p] = true, pen[t] += ti;
            else w[t][p]++;
        }
        rep (i, T) rep (j, P) if (c[i][j]) {
            num[i] += 1;
            pen[i] += 1200*w[i][j];
        }
        vector<pair<pair<int, int>, int> > vs;
        rep (i, T) vs.push_back(mp(mp(-num[i], pen[i]), i));
        sort(vs.begin(), vs.end());
        rep (i, T) {
            printf("%d %d %d\n", vs[i].snd+1, -vs[i].fst.fst, vs[i].fst.snd);
        }
    }
}

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

int main(){
    string A="keyence";
    string S;cin>>S;
    int a=S.size()-7;
    bool ans=0;
    for(int i=0;i<7;i++){
        string SS = S;
        SS.erase(i,a);
        if(A==SS){
            ans=1;
            break;
        }
    }
    if(ans)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#pragma gcc optimize("Ofast")

#include "bits/stdc++.h"
using namespace std;
typedef int64_t lld;
typedef pair<int,int> pii;
typedef pair<lld,lld> pll;
typedef pair<int,pll> pip;
typedef pair<pll,int> ppi;
typedef pair<lld,pll> plp;
typedef pair<pll,lld> ppl;
typedef pair<pll,pll> ppp;
template<typename T>
using maxHeap = priority_queue<T,vector<T>,less<T>>;
template<typename T>
using minHeap = priority_queue<T,vector<T>,greater<T>>;
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define endl '\n'
#define jizz cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
inline void input(int &_x) {
    _x = 0;
    int _tmp = 1; char _tc = getchar();
    while((_tc < '0' || _tc > '9') && _tc != '-') _tc = getchar();
    if(_tc == '-') _tc = getchar(), _tmp = -1;
    while(_tc >= '0' && _tc <= '9') _x = _x*10+(_tc-48), _tc = getchar();
    _x *= _tmp;
}
inline void output(int _x) {
    char _buff[20]; int _f = 0;
    if(_x == 0)putchar('0');
    while(_x > 0)
    {
        _buff[_f++] = _x%10+'0';
        _x /= 10;
    }
    for(_f-=1; _f >= 0; _f--)
        putchar(_buff[_f]);
    putchar('\n');
}
template<typename Iter>
ostream& _out(ostream &s, Iter b, Iter e) {
    s<<"[";
    for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
    s<<"]";
    return s;
}
template<class T1,class T2>
ostream& operator<<(ostream& out, pair<T1,T2> p) {
    return out << '(' << p.first << ", " << p.second << ')';
}
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) {
     return _out(s,c.begin(),c.end());
 }
#ifdef erd1
    #define pprint(x) cerr<<__PRETTY_FUNCTION__<<":"<<__LINE__<<" - "<<(#x)<<"="<<(x)<<endl
#else
    #define pprint(x)
#endif

// code starts here
vector<vector<int>> G;
vector<bool> gone;
vector<int> E;
int S, T, N;
bool empty(int i, bool from){
    if(i == -1)return true;
    if(i == 0)return false;
    if(E[i] == 0)return true;
    return E[i] == (from?-1:1);
}
void use(int i, bool from){
    if(i == -1)return;
    E[i] += from?1:-1;
}
bool dfs(int i){
    if(i == T)return true;
    gone[i] = true;
    for(int x = 0; x < N; x++)
        if(!gone[x] && empty(G[i][x], i>x) && dfs(x))return use(G[i][x], i>x), true;
    return false;
}
signed main(){
    int n, m, es = 1;
    cin >> n >> m;
    S = n+m, T = n+m+1, N = n+m+2;
    G.resize(N);
    for(auto& i: G)i.resize(n+m+2);
    pii s, t;
    for(int i = 0; i < n; i++){
        string str;
        cin >> str;
        for(int j = 0; j < m; j++){
            if(str[j] == 'o'){
                G[i][n+j] = G[n+j][i] = es++;
            }
            if(str[j] == 'S')s = {i, n+j};
            if(str[j] == 'T')t = {i, n+j};
        }
    }
    E.resize(es);
    if(s.ff == t.ff || s.ss == t.ss)return cout << -1 << endl, 0;
    G[S][s.ff] = G[S][s.ss] = G[t.ff][T] = G[t.ss][T] = -1;
    int ans = 0;
    gone.resize(N);
    while(true){
        fill(all(gone), false);
        if(dfs(S))ans++;
        else break;
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
#include<iostream>

using namespace std;

int main(){
    long long int N,M;
    cin >> N >> M;
    if(N==1&&M==1) cout << 1 << endl;
    else if(N==2||M==2) cout << 0 << endl;
    else if(N==1) cout << M - 2;
    else if(M==1) cout << N - 2;
    else cout << (M-2)*(N-2);
}

Measured memory_bytes: 256
x, y = map(int, input().split())
ans = abs(abs(x)-abs(y))

if abs(y) > abs(x):
    if x < 0:
        ans += 1
    if y < 0:
        ans += 1

else:
    if x > 0:
        ans += 1
    if y > 0:
        ans += 1
print(ans)




Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(long long i = 0; i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    string s,a="CODEFESTIVAL2016";
    cin>>s;
    ll ans=0;
    rep(i,16) if(s[i]!=a[i]) ans++;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
#define INF 1e10
#define MOD 1e9+7
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;
signed main(){
  int a;
  cin>>a;
  vector<int> b(a);
  rep(i,a-1)
    cin>>b[i];
  int c=b[0]+b[a-2];
  rep(i,a-2)
    c+=min(b[i],b[i+1]);
  cout<<c<<endl;
}

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

int main() {
	int n;
	long long l[100];
	cin >> n;
	l[0] = 2, l[1] = 1;
	for (int i = 2; i <= n; i++) {
	    l[i] = l[i - 1] + l[i - 2];
	}
	cout << l[n];
}


Measured memory_bytes: 256
def resolve():
    N, K = map(int, input().split())
    H = list(map(int, input().split()))

    dp = [0] * N

    for i in range(1, N):
        s = max(0, i-K)
        dp[i] = min([c + abs(h - H[i]) for c, h in zip(dp[s:i], H[s:i])] )

    print(dp[N-1])

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 13928
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,unroll-all-loops")
// #pragma GCC option("arch=native","tune=native")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx")

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

#define f(_i, _n) for (auto _i = 0; _i < _n; _i++)
#define F(_i, _k, _n) for (auto _i = _k; _i < _n; _i++)
#define re return
#define pb push_back
#define all(_v) _v.begin(), _v.end()
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; }
#define fi first
#define se second

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

vector<int> gr[100500];

set<pii> can;
set<pii> unreached;

int was[100500];
int a[100500];

int mnv;

int dfs(int v) {
  if (was[v]) {
    return 0;
  }
  if (mnv == -1 || a[mnv] > a[v]) {
    mnv = v;
  }
  was[v] = 1;
  for (auto to : gr[v]) {
    dfs(to);
  }
  re 0;
}

int main() {
  ll ans = 0;
  int n, k;
  cin >> n >> k;
  f(i, n) {
    cin >> a[i];
    unreached.insert({a[i], i});
  }
  f(i, k) {
    int x, y;
    cin >> x >> y;
    gr[x].pb(y);
    gr[y].pb(x);
  }
  int cnt = 0;
  f(i, n) {
    if (!was[i]) {
      mnv = -1;
      dfs(i);
      cnt++;
      ans += a[mnv];
      // cerr << ' ' << mnv << ' ' << a[mnv] << endl;
      unreached.erase({a[mnv], mnv});
    }
  }
  if (cnt == 1) {
    cout << 0;
    re 0;
  }
  if (cnt - 2 > (int)unreached.size()) {
    cout << "Impossible";
    re 0;
  }
  f(i, cnt - 2) {
    ans += unreached.begin()->fi;
    unreached.erase(unreached.begin());
  }
  cout << ans;
}


Measured memory_bytes: 11264
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let s = buf.split_whitespace().next().unwrap();
    let cycle = ["Sunny", "Cloudy", "Rainy"];
    let index = cycle.iter().position(|&x| x == s).unwrap();
    println!("{}", cycle[(index + 1) % 3]);
}


Measured memory_bytes: 4352
x, y = map(int, input().split())
d = {
    4: 0,
    3: 100000,
    2: 200000,
    1: 300000
}
ans = d[min(x, 4)] + d[min(y, 4)]
if x * y == 1:
    ans += 400000
print(ans)


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

int main()
{
    int N, K;
    ll L;
    cin >> N >> K >> L;
    vector<int> a(N);
    for(int i = 0;i < N;i++){
        cin >> a[i];
    }
    int lb = 0, ub = N;
    while(ub - lb > 1){
        int x = (lb + ub) / 2;
        ll cnt = 0;
        queue<int> ids;
        for(int i = 0;i < N;i++){
            if (a[i] <= x) {
                ids.push(i);
            }
            while((int)ids.size() > K) ids.pop();
            if ((int)ids.size() == K) cnt += ids.front() + 1;
        }
        (cnt < L ? lb : ub) = x;
    }
    cout << ub << endl;
    return 0;
}



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

const int maxn = 1e5;

int n, k;
int v[maxn+2], dp[maxn+2];

int main()
{
    cin>>n>>k;
    for(int i=1; i<=n; i++)
    {
        cin>>v[i];
    }
    for(int i=2; i<=k+1; i++)
    {
        dp[i]=abs(v[1]-v[i]);
    }
    for(int i=k+2; i<=n; i++)
    {
        dp[i]=dp[i-1]+abs(v[i-1]-v[i]);
        for(int j=2; j<=k; j++)
        {
            dp[i]=min(dp[i],dp[i-j]+abs(v[i-j]-v[i]));
        }
    }
    cout<<dp[n];
    return 0;
}


Measured memory_bytes: 1024
import collections

count = collections.Counter
mod = 1000000007

def main():
    N = int(input())
    S = input()

    valuelist = list(count(S).values())
    ans = 1
    for v in valuelist:
        ans = (ans * (v + 1))%mod

    ans -= 1

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3444
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<cctype>
#define int long long
#define rg register
using namespace std;
namespace Prev1ous{
	inline int read(){
		rg int s=0,f=0;
		rg char ch=getchar();
		while(!isdigit(ch)) f|=(ch=='-'),ch=getchar();
		while(isdigit(ch)) s=(s<<1)+(s<<3)+(ch^48),ch=getchar();
		return f?-s:s;
	}
	int n,ans;
	const int MAX=45;
	char mp[MAX][MAX];
	int f[MAX][MAX][MAX];
	int dp(int l,int r,int k){
		int &res=f[l][r][k];
		if(~res) return res;
		if(l==r) return res=1;
		if(l==k or r==k) return res=0;
		res=0;
		for(rg int i=l;i<k;i=-~i){
			for(rg int j=k+1;j<=r;j=-~j){
				if(mp[i][j]=='0') continue;
				for(rg int p=i;p<k;p=-~p){
					for(rg int o=k+1;o<=j;o=-~o){
						res+=dp(l,p,i)*dp(p+1,o-1,k)*dp(o,r,j);
					}
				}
			}
		}
		return res;
	}
	inline void main(){
		n=read();
		for(rg int i=1;i<=2*n;i=-~i) scanf("%s",mp[i]+1);
		memset(f,-1,sizeof(f));
		for(rg int i=2;i<=n*2;i=-~i){
			if(mp[1][i]=='1') ans+=dp(2,n*2,i);
		}
		printf("%lld",ans);
	}
}
signed main(){
	Prev1ous::main();
	return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>

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

int A[2000];
bool ans[200];

bool canAmake(int num, int current)
{
	bool ret = false;

	if (num == 0) return true;
	else if (current < 0) return false;

	ret = canAmake(num, current - 1) || canAmake(num - A[current], current - 1);

	return ret;
}

int main()
{
	int n, q, m;
	cin >> n;
	rep(i, n) cin >> A[i];
	cin >> q;
	rep(i, q) {
		cin >> m;
		ans[i] = canAmake(m, n - 1);
	}
	rep(i, q) {
		if (ans[i]) cout << "yes" << endl;
		else cout << "no" << endl;
	}

	return 0;
}



Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
constexpr int maxn = 1000000;
int kid[maxn + 1][26], tot = 1;
int app[maxn][26];
vector<int> v[maxn + 1];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int N;
    cin >> N;
    vector<string> S(N);
    for(auto& s : S){
        cin >> s;
        int p = 0;
        for(int i = s.size() - 1; i; i -= 1){
            if(not kid[p][s[i] - 'a']) kid[p][s[i] - 'a'] = tot ++;
            p = kid[p][s[i] - 'a'];
        }
        v[p].push_back(s[0] - 'a');
    }
    int ans = 0;
    for(auto&& s : S){
        for(int i = 0; i < s.size(); i += 1){
            for(int j = 0; j < 26; j += 1) app[i][j] = i ? app[i - 1][j] : 0;
            app[i][s[i] - 'a'] = 1;
        }
        for(int j : v[0]) ans += app[s.size() - 1][j];
        for(int i = s.size() - 1, p = 0; i; i -= 1){
            p = kid[p][s[i] - 'a'];
            for(int j : v[p]) ans += app[i - 1][j];
        }
    }
    cout << ans - N;
    return 0;
}

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    int n; cin >> n;

    vector<int> p(n), q(n);
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
    }

    for (int i = 0; i < n; ++i) {
        cin >> q[i];
    }

    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        a[i] = i + 1;
    }

    map<vector<int>, int> mp;
    do {
        mp[a] = mp.size();
    } while (next_permutation(a.begin(), a.end()));

    cout << abs(mp[p] - mp[q]) << endl;
}

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

struct Segt {
  int c;
  Segt *lc, *rc;
  Segt(int _c = 0) : c(_c), lc(0), rc(0) {}
  Segt *add(int k, int lb, int rb, int t = 1) {
    Segt *q = new Segt();
    q->c = c;
    if (rb - lb == 1) return ++q->c, q;
    int mb = lb + rb >> 1;
    if (k < mb) {
      q->lc = lc->add(k, lb, mb, t << 1);
      q->rc = rc;
      q->c = q->lc->c + (rc ? rc->c : 0);
    } else {
      q->rc = rc->add(k, mb, rb, t << 1 | 1);
      q->lc = lc;
      q->c = q->rc->c + (lc ? lc->c : 0);
    }
    return q;
  }
  int sum(int ql, int lb, int rb, int t = 1) {
    if (ql <= lb) return c;
    if (rb <= ql) return 0;
    int mb = lb + rb >> 1;
    return (lc ? lc->sum(ql, lb, mb, t << 1) : 0) + (rc ? rc->sum(ql, mb, rb, t << 1 | 1) : 0);
  }
};

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

  vector<int> C(N);
  for (int i = 0; i < N; ++i) scanf("%d", &C[i]);

  vector<int> nxt(N);
  vector<int> lst(N + 1, N);
  for (int i = N - 1; ~i; --i) {
    nxt[i] = lst[C[i]];
    lst[C[i]] = i;
  }

  vector<Segt *> trees(N + 1); {
    function<Segt *(int, int)> build = [&](int l, int r) {
      Segt *t = new Segt();
      int m = l + r >> 1;
      if (r - l == 1) return t;
      t->lc = build(l, m);
      t->rc = build(m, r);
      return t;
    };
    trees[0] = build(0, N + 1);
  }
  for (int i = 0; i < N; ++i) {
    trees[i + 1] = trees[i]->add(nxt[i], 0, N + 1);
  }

  while (Q--) {
    int L, R;
    scanf("%d%d", &L, &R);
    --L;
    int res = trees[R]->sum(R, 0, N + 1) - trees[L]->sum(R, 0, N + 1);
    printf("%d\n", res);
  }

  return 0;
}


Measured memory_bytes: 357908
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_poizcy.hpp>
typedef long long  ll;
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define mem(a,h)          memset(a, (h), sizeof(a))
#define se second
#define fi first
#define por(a,b) (((a%MOD) * (b%MOD))%MOD)
#define forg(i, b, e, c)    for (ll i = (ll)b; i < (ll)e; i+=c)
#define forr(i, b, e)    for (ll i = b; i < e; i++)
 
 
using namespace std;
//using namespace __gnu_pbds;
typedef double lldb;
typedef pair<ll, ll>  ii;
typedef pair<ll, ii>  iii;
typedef pair<double, double>  iidb;
//typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const ll INF = 1e9+7;
const double PI = acos(-1);
#define initseg ll new_nodo=(pnodo*2),mid=(iz+der)/2;
 
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define offset 3000
#define ptr nodo*
const ll MOD=998288383;
#define tam 234
using namespace std;
int v[tam];
vector<ii> ans;
void change(int i,int j)
{
	ans.pb({i+1,j+1});
	//cout<<i+1<<" "<<j+1<<endl;
	v[j]+=v[i];

}
int main()
{	
	ios::sync_with_stdio(false);cin.tie(0);
	int n;
	cin>>n;
	ii minn,maxx;minn.fi=1e9,maxx.fi=-1e9;
	forr(i,0,n)
	{
		cin>>v[i];
		
		minn=min(minn,ii(v[i],i));
		maxx=max(maxx,{v[i],i});

	}
	if (abs(minn.fi)>abs(maxx.fi) && minn.fi<0)
	{
		forr(i,0,n)
		{
			if (v[i]>0)
				change(minn.se,i);
		}
		for(int i=n-1;i>=1;i--)
		{
			change(i,i-1);
		}
	}
	else
	{
		forr(i,0,n)
		{
			if (v[i]<0)
				change(maxx.se,i);
		}
		forr(i,0,n-1)
			change(i,i+1);
	}
	cout<<ans.size()<<endl;
	for(auto par:ans)
		cout<<par.fi<<" "<<par.se<<endl;
}

Measured memory_bytes: 3628
Module Program
  Sub Main
    Dim s=Gets()
    Dim a=s(0)
    Dim ans=If(a(0)=a(2),"Yes","No")
    Console.WriteLine(ans)
  End Sub
  
  '/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
  Function Gets() As String()
    Gets = Console.ReadLine().Split(" "c)
  End Function
  Function GetInts() As Integer()
    Dim s = Gets(), r(UBound(s)) As Integer
    For i As Integer=0 To UBound(s): r(i)=s(i): Next i
    GetInts = r
  End Function
End Module

Measured memory_bytes: 22608
#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする
 
vector<int> G[100005];
std::vector<P> tree[100010];
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
 
#define p(x) cout<<x<<endl;
#define e cout<<endl;
#define pe(x) cout<<x<<" ";
#define re(i,a,b) for(i=a;i<=b;i++)
 
ll i,j,k,l,ii,jj;
ll n,m;
ll x,y;
ll a[100005];
ll ans=0;
ll sum=0;
 
int main(){
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	for(i=0;i<n-1;i++){
		x=a[i];
		y=a[i+1];
		if(x>y){
			if((x+y)%2==0 || y==0){
				ans+=y;
				x-=y;
				y=0;
				ans+=x/2;
				x=0;
			}else{
				ans+=(y-1);
				x-=(y-1);
				y=1;
				ans+=x/2;
				x=x%2;
			}
		}else{
			ans+=x;
			y-=x;
			x=0;
		}
		a[i]=x;
		a[i+1]=y;
	}
	ans+=a[n-1]/2;
 
	p(ans);
	return 0;
}

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

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
constexpr int mod = 1e9 + 7;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint &operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint &operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }
  mint inv() const { return pow(mod - 2); }
  mint &operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
  friend ostream &operator<<(ostream &os, const mint &a) { return (os << a.x); }
};
struct combination {
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

int main() {
  string s;
  cin >> s;
  if (s[2] == s[3] && s[4] == s[5])
    cout << "Yes";
  else
    cout << "No";
  cout << endl;
}


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

int main(void){
    char s[101];
    int i,len,ans=0;
    scanf("%s",s);
    len = strlen(s);
    for(i=0;i<len/2;i++){
        if(s[i]!=s[len-1-i]){
            ans++;
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;



public class Main {
    
    
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String[] lineString = br.readLine().split(" ");
        int N = Integer.valueOf(lineString[0]);
        int K = Integer.valueOf(lineString[1]);
        
        String[] lazhu = br.readLine().split(" ");
        int[] l = new int[N];

        for (int i = 0; i < N; i++) {
            l[i] = Integer.parseInt(lazhu[i]);
        }
        
        int sum = 0;
        int temp = 0;
        int pos = 0;
        for (int i = 0; i < N ; i++) {
            pos = i + K - 1;
            if (pos >= N) {
                continue;
            }
            if (l[i] >= 0) {
                sum = l[pos];
            } else if (l[pos] <= 0) {
                sum = Math.abs(l[i]);
            } else {
                if (Math.abs(l[i]) < l[pos]) {
                    sum = Math.abs(l[i]) * 2 + l[pos];
                } else {
                    sum = Math.abs(l[i]) + 2 * l[pos];
                }
            }
            if (temp > sum || temp == 0) {
                temp = sum;
            }
            
        }
        System.out.println(temp);
    }
}



Measured memory_bytes: 38548
n, k = gets.split(" ").map(&:to_i)
ary = gets.split(" ").map(&:to_i)
ary_rate = []

ary.each do |x|
  ary_rate << (x + 1) / 2.0
end

sum = ary_rate[0..(k-1)].inject(:+)
max = sum

(n - k).times do |i|
  sum = sum - ary_rate[i] + ary_rate[i+k]
  if sum > max
    max = sum
  end
end

puts max

Measured memory_bytes: 19076
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ProconTemplate
{
    class Doing
    {
        public static void Main(string[] args)
        {
            var inputInt = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var useCt = inputInt[0] / 2;
            if(inputInt[0] % 2 == 1) { useCt++; }
            if(useCt >= inputInt[1])
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }
        }
    }
}


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

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define SX(x) (x).begin(), (x).end()
typedef pair<int, int> P;
using ll = long long;

int DIGITS(ll n){
  int sum=0;
  while(n>0) {
    n /= 10;
    sum++;
  }
  return sum;
}

int main()
{
  ll n; cin >> n;
  
  ll ans=1000000000;
 
  for (ll A=1; A*A<=n; A++)
  {
    if (n%A != 0)	continue;
     ll B = n/A;
    //cout << "A : " << A << endl;
    //cout << "B : " << B << endl;
    
    ll res = max(DIGITS(A), DIGITS(B));
    ans = min(ans,res);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
n, q = map(int, input().split())
s = input()
list = [list(map(int, input().split())) for _ in range(q)]
ans_list = [0 for _ in range(n)]

for i in range(1, n):
    if s[i] == 'C' and s[i-1] == 'A':
        ans_list[i] = ans_list[i-1] + 1
    else:
        ans_list[i] = ans_list[i-1]
#print(ans_list)
for j in range(q):
    l, r = list[j]
    print(ans_list[r-1]-ans_list[l-1])


Measured memory_bytes: 69336
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <map>
#include <stack>
#include <map>
#include <unordered_map>
#define REP(i,n) for(long (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(long (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 1e9 + 7;
using namespace std;
using P = pair<long, long>;
using VI = vector<long>;

unordered_map<string, int> mp;

int main() {
    int n, m;
    cin >> n;
    REP(i,n) {
        string s;
        cin >> s;
        mp[s]++;
    }
    cin >> m;
    REP(i,m) {
        string s;
        cin >> s;
        mp[s]--;
    }
    
    int ans = -1e9;
    for (auto i = mp.begin(); i != mp.end(); i++) {
        ans = max(ans, i->second);
    }
    cout << max(0,ans) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
const int maxn = 2e5 + 10;
const int mod = 998244353;
ll f[maxn];

ll ksm(ll a, int n){
    ll ans = 1;
    while(n){
        if(n & 1)ans = (ans * a) % mod;
        a = (a * a) % mod;
        n >>= 1;
    }
    return ans;
}
void solve(){
    ll n, m, k; cin >> n >> m >> k;
    ll ans = 0;
    f[0] = 1;
    ll base = 1, cnt = 1;
    for (int i = 1; i < n; i++){
        base = (base * (n - i)) % mod;
        cnt = (cnt * i) % mod;
        f[i] = base * ksm(cnt, mod - 2) % mod;
    }

    for (int i = 0; i <= k; i++){
        ans += (m % mod * ksm(m - 1, n - i - 1)) % mod * f[i];
        ans %= mod;
    }
    cout << ans << endl;
}
int main(){
    IOS; int t = 1;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 5172
import numpy as np 

N,K,Q = map(int,input().split())

member = np.array([K-Q]*N)

for _ in range(Q):
    x = int(input())
    member[x-1] += 1

for i in range(N):
    if member[i] > 0:
        print("Yes")
    else:
        print("No")

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

using namespace std;

int main()
{
    //system("chcp 65001");

    char S[4];
    int i,ans = 0;
    for(i = 0;i <= 3;i++)
    {
        cin >> S[i];
        if(S[i] == '+')
        {
            ans += 1;
        }
        else
        {
            ans -= 1;
        }
        
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 256
import sys

fin = sys.stdin.readline
num = str(fin()).split()[0]

sum = 0
for i in range(len(num) // 2):
    sum += 9 * (10 ** (i*2))

if len(num) % 2 == 0:
    # 桁数が偶数の場合
    print(sum)
else:
    print(sum + int(num) - 10 ** (len(num) - 1) + 1)


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

using namespace std;

const int mod = 1e9 + 7;
int N;
string S[50];
int dp[50][51][25][128];

int rec(int top, int bottom, int left, int x) {
  if(top >= bottom || x > 'z') return 0;
  if(left == 20) return top + 1 == bottom;
  if(~dp[top][bottom][left][x]) return dp[top][bottom][left][x];
  int &ret = dp[top][bottom][left][x];
  ret = rec(top, bottom, left, x + 1);
  for(int i = top; i < bottom; i++) {
    if((x < 'a' || S[i][left] != '?') && S[i][left] != x) return ret;
    ret += 1LL * rec(top, i + 1, left + 1, 'a' - 2) * rec(i + 1, bottom, left, x + 1) % mod;
    ret %= mod;
  }
  ret += rec(top, bottom, left + 1, 'a' - 2);
  ret %= mod;
  return ret;
}

int main() {
  cin >> N;
  for(int i = 0; i < N; i++) {
    cin >> S[i];
    S[i] += (char) ('a' - 2);
    while(S[i].size() < 21) S[i] += (char) ('a' - 1);
  }
  memset(dp, -1, sizeof(dp));
  cout << rec(0, N, 0, 'a') << endl;
}




Measured memory_bytes: 35100
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
typedef long long LL;
const LL INF = 0x3f3f3f3f3f3f3f3f;

LL ec = 0,hed[200005] = {0},to[400005],w[400005],nxt[400005];
void add_edge(LL f,LL t,LL cst){
	++ ec; to[ec] = t; nxt[ec] = hed[f]; w[ec] = cst; hed[f] = ec;
}

LL siz[200005],mx[200005];
LL ans = 0,n;

void dfs(LL u,LL f){
	siz[u] = 1;
	for(LL i = hed[u];i;i = nxt[i]){
		LL v = to[i];
		if(v == f) continue;
		dfs(v,u);
		siz[u] += siz[v]; mx[u] = max(mx[u],siz[v]);
		ans += 2 * min(siz[v],n - siz[v]) * w[i];
	}
	mx[u] = max(mx[u],n - siz[u]);
}

int main(){
	ios::sync_with_stdio(false);
	LL u,v,ww,g = INF,sub = INF,p1 = 0,p2 = 0;
	cin >> n;
	for(LL i = 1;i < n;i ++){
		cin >> u >>	v >> ww;
		add_edge(u,v,ww);
		add_edge(v,u,ww);
	}
	dfs(1,0);
	for(LL i = 1;i <= n;i ++) g = min(g,mx[i]);
	for(LL i = 1;i <= n;i ++){
		if(mx[i] != g) continue;
		if(!p1) p1 = i;
		else p2 = i;
	}
//	cout << p1 << ' ' << p2 << endl;
	for(LL i = hed[p1];i;i = nxt[i]){
		LL v = to[i];
		if(p2 && v != p2) continue;
		sub = min(sub,w[i]);
	}
	cout << ans - sub << endl;
	return 0;
}

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

int main(){
	long long int n,ans=100000000000000;
	cin>>n;
	for(long long int i=1;i*i<=n;i++){
		if(n%i==0){
			if(ans>(n/i)+i){
				ans=(n/i)+i;
			}
		}
	}
	cout<<ans-2<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <algorithm>
using namespace std;

#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define forab(i, a, b) for(int i=(a);i<(b);++i)
#define foreach(i, n) for (__typeof(n.begin()) i = n.begin(); i != n.end(); ++i)
#define sqr(x) ((x)*(x))
#define clr(a, b) memset(a, b, sizeof(a))
#define MP make_pair
#define PB push_back
#define SZ(a) ((int)a.size())
#define all(a) (a).begin(),(a).end()
#define inf 0x3f3f3f3f
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
const double eps = 1e-8;
int dcmp(double x) { if (x < -eps) return -1; else return x > eps;}
#define se(x) cout<<#x<<" = "<<x<<endl

#ifdef CHEN_PC
	#define debug(...) printf(__VA_ARGS__)
#else 
	#define debug(...)
#endif

const int N = 200010;
const int mod = 1000000007; // 10^9+7
int n;
int a[N];

int solve() {
	map<int, int> dic1;
	map<int, int> dic2;
	int ret = 0;
	for (int i = 0; i < n; i += 2) {
		dic1[a[i]]++;
	}
	for (int i = 1; i < n; i += 2) {
		dic2[a[i]]++;
	}
	vector<pii> v1;
	vector<pii> v2;
	foreach (it, dic1) {
		v1.push_back(MP(it->second, it->first));
	}
	foreach (it, dic2) {
		v2.push_back(MP(it->second, it->first));
	}
	sort(all(v1)); reverse(all(v1));
	sort(all(v2)); reverse(all(v2));

	debug("%d %d\n", v1[0].second, v2[0].second);
	if (v1[0].second != v2[0].second) {
		ret = n - v1[0].first - v2[0].first;
	}
	else if (SZ(v1) == 1 && SZ(v2) == 1) {
		ret = n / 2;
	}
	else if (SZ(v1) == 1) {
		ret = n / 2 - v2[1].first;
	}
	else if (SZ(v2) == 1) {
		ret = n / 2 - v1[1].first;
	} else {
		ret = min(
			n - v1[0].first - v2[1].first,
			n - v1[1].first - v2[0].first
		);
	}

	return ret;
}

int main(int argc, char *argv[]) {
#ifdef CHEN_PC
	freopen("C.in", "r", stdin);
#endif

	while (scanf("%d", &n) != EOF) {
		forn (i, n)	scanf("%d", a + i);
		int ret = solve();
		printf("%d\n", ret);
	}
	return 0;
}



Measured memory_bytes: 6520
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>
#include<bitset>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

string s;
bool flag1 = false, flag2 = false;

int main() {
	cin >> s;
	rep(i, sz(s)) {
		if (s[i] == 'A')flag1 = true;
		if (s[i] == 'B')flag2 = true;
	}
	if (flag1 && flag2) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int n;
  cin >> n;
  for (int x = 1; x <= n; ++x) {
    int res = x * 1.08;
    if (res == n) {
      cout << x << endl;
      return 0;
    }
  }
  cout << ":(" << endl;
  return 0;
}

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

using namespace std;
typedef long long ll;

#define MAX 802

char A[MAX][MAX];
int dp[MAX][MAX];
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

int main(void) {
    int i, j, H, W, K, sx, sy;
    scanf("%d%d%d", &H, &W, &K);
    for(i=0; i<H; i++) scanf("%s", &A[i]);
    for(i=0; i<H; i++) for(j=0; j<W; j++) {
        if(A[i][j] == 'S') {
            sy = i; sx = j;
        }
    }
    for(i=0; i<H; i++) for(j=0; j<W; j++) dp[i][j] = -1;
    dp[sy][sx] = 0;
    queue<pair<int, int> > P;
    P.push(make_pair(sy, sx));
    while(!P.empty()) {
        int y = P.front().first;
        int x = P.front().second;
        P.pop();
        for(i=0; i<4; i++) {
            int ny = y + dy[i];
            int nx = x + dx[i];
            if(ny < 0 || ny >= H || nx < 0 || nx >= W) {
                if(dp[y][x] <= K) return !printf("1\n");
                continue;
            }
            if(~dp[ny][nx] || A[ny][nx] == '#') continue;
            dp[ny][nx] = dp[y][x] + 1;
            P.push(make_pair(ny, nx));
        }
    }

    int ret = 1e9;
    for(i=0; i<H; i++) for(j=0; j<W; j++) {
        if(~dp[i][j] && dp[i][j] <= K) {
            int d = min(min(i, j), min(H-i-1, W-j-1));
            ret = min(ret, (d+K-1) / K);
        }
    }

    return !printf("%d\n", ret+1);
}

Measured memory_bytes: 3328
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e+9+7;

int main(){
    ll N; cin>>N;
    vector<ll>a(N-1);
    vector<ll>ans(N,0);
    rep(i,N-1){
        cin>>a[i];
        ans[a[i]-1]++;
    }
    rep(i,N)cout<<ans[i]<<endl;
}




Measured memory_bytes: 6432
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m;
	scanf("%d",&n);
	if(n>=1&&n<=999)
	{
		printf("ABC");
	}
	else if(n>=1000&&n<=1998)
	{
		printf("ABD");
	}
	return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque
sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

X, Y, A, B, C = map(int, input().split())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))

P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)

P = P[:X]
Q = Q[:Y]

ALL = P + Q + R
ALL.sort(reverse=True)

ans = sum(ALL[: X + Y])
print(ans)


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

int main(){
    int N, ans;
    cin >> N;
    vector<int> a(N/2), b(N/2);
    map<int, int> mp, mp2;
    pair<int, int> aAns[2], bAns[2];
    
    for(int i=0; i<N/2; i++){
	cin >> a[i] >>b[i];	
    }

    for(int i=0; i<N/2; i++){
	mp[a[i]]++;
	mp2[b[i]]++;
    }
    aAns[0].second = 0;
    aAns[1].second = 0;
    bAns[0].second = 0;
    bAns[1].second = 0;
    for(auto itr=mp.begin(); itr!=mp.end(); itr++) {
	if(aAns[0].second < itr->second){
	    aAns[1] = aAns[0];
	    aAns[0].first = itr->first;
	    aAns[0].second = itr->second;
	}
	if(aAns[1].second <= itr->second && aAns[0].first != itr->first){
	    aAns[1].first = itr->first;
	    aAns[1].second = itr->second;
	}
    }
    for(auto itr=mp2.begin(); itr!=mp2.end(); itr++) {
	if(bAns[0].second < itr->second){
	    bAns[1] = bAns[0];
	    bAns[0].first = itr->first;
	    bAns[0].second = itr->second;
	}
	if(bAns[1].second <= itr->second && bAns[0].first != itr->first){
	    bAns[1].first = itr->first;
	    bAns[1].second = itr->second;
	}

    }

    if(aAns[0].first != bAns[0].first)
	ans = N - aAns[0].second - bAns[0].second;
    else
	ans = min(N - aAns[1].second - bAns[0].second, N - aAns[0].second - bAns[1].second);
    cout << ans << endl;
}




Measured memory_bytes: 5376
#include<iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=9;i++){
        if(n%i)continue;
        else if(n/i>=10)continue;
        else{
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int rating;
    cin >> rating;
    string out = rating < 1200 ? "ABC" : "ARC";
    cout << out << endl;
    return 0;
};


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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long



int32_t main() {

    int a, b, c; cin >> a >> b >> c;
    int ans = min(b/a, c);
    cout << ans << endl;
        
    return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N, K; string S;
    cin >> N >> S >> K;
    char c = S[K - 1];
    rep(i, N){if (S[i] != c){S[i] = '*';}}
    cout << S << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


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

using ll = long long;
#define REP(i,n) for(int i = 0;i < n;i++)

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

  int ans = 0;

  int n;cin >> n;
  ll d;cin >> d;
  REP(i,n){
  	ll x,y;cin >> x >> y;
  	if(x*x+y*y <= d*d)ans++;
  }

  cout << ans << '\n';
}


Measured memory_bytes: 3648
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

ll n,m;
int main(){
	scanf("%lld %lld",&n,&m);
	printf("%lld",n-m+1);
}


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

int main() {
  int a,b,k;
  cin>>a>>b>>k;
  if(a<=b){
    int tmp=a;
    a=b;
    b=tmp;
  }
  //a>=bにする

  int ans=a;
  int count=0;
  while(true){
    if(a%ans==0&&b%ans==0){
      count++;
      if(count==k)break;
    }
    ans--;
  }
  cout<<ans<<endl;
  return 0;
}
  

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

lli max(lli a,lli b)
{
   if(a>b)
   {
       return a;
   }
   return b;
}

lli power(lli x,lli n,lli mod)
{
    lli res=1;
    while(n>0)
    {
        if(n%2==1)
        {
            res=(res*x)%mod;
        }
        x=(x*x)%mod;
        n=n/2;
    }

    return  res%mod;

}




int main()
{
    lli n;
    cin>>n;
    map<string,lli> m;
    for(int i=0;i<n;i++)
    {
        string str;
        cin>>str;
        m[str]++;
    }
    cout<<m.size()<<"\n";

    return 0;
}


Measured memory_bytes: 19224
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>

using namespace std;

const int nmax = 1e9 + 7;
const long long INF = 1e18;
const double PI = 2 * asin(1);
typedef long long ll;

int main(){

  int N; cin >> N;

  vector <double> T(N + 2), V(N + 2);
  int sum = 0;
  for (int i = 1; i < N + 1; i++){
    double t; cin >> t; sum += t;
    T[i] = T[i - 1] + t;
  }
  T[N + 1] = T[N];
  
  for (int i = 1; i < N + 1; i++){
    cin >> V[i];
  }

  vector <double> ans(sum * 2 + 1);
  for (int i = 0; i < sum * 2 + 1; i++){
    ans[i] = min(0.5 * i, sum - 0.5 * i);
  }

  for (int i = 0; i < sum * 2 + 1; i++){
    double now = 0.5 * i;
    for (int j = 1; j < N + 2; j++){
      if (T[j] < now){
        ans[i] = min(ans[i], V[j] + abs(now - T[j]));
      }else if (T[j - 1] <= now && now <= T[j]){
        ans[i] = min(ans[i], V[j]);
      }else{
        ans[i] = min(ans[i], V[j] + abs(now - T[j]));
      }
    }
  }


  for (int i = sum * 2 - 1; i >= 0; i--){
    if (abs(ans[i] - ans[i + 1]) > 0.5){
      if (ans[i] > ans[i + 1]) ans[i] = ans[i + 1] + 0.5;
      else ans[i] = ans[i + 1] - 0.5;
    }
  }

  double A = 0;

  for (int i = 0; i < sum * 2; i++){
    A += 0.25 * (ans[i] + ans[i + 1]);
  }
  
  cout <<setprecision(32) <<  A << endl;
  


  return 0;
}

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

#define REP(i,n) for(int i=0;i<n;i++)

using namespace std;


int main()
{
	int N,T;
	cin>>N>>T;
	
	int t[N+10];
	for(int i=1;i<N+1;++i){
		cin>>t[i];
	}
	
	int x;
	x=0;
	
	for(int i=1;i<N;++i){
		if(t[i+1]-t[i]>=T){
			x=x+T;
		}
		else{
			x=x+t[i+1]-t[i];
		}
	
	}
	cout<<x+T<<endl;
	
	
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <ctype.h>
#include <math.h>

int main(int argc, void **argv)
{
	long long n, m;
	long long k[10], s[10][10], p[10];
	char x[10];
	long long count = 0;
	long long max;

	scanf("%lld %lld", &n, &m);
	for (int i = 0; i < m; i++)
	{
		scanf("%lld", &k[i]);
		for (int j = 0; j < k[i]; j++)
		{
			scanf("%lld", &s[i][j]);
		}
	}
	for (int i = 0; i < m; i++)
	{
		scanf("%lld", &p[i]);
	}

	//============================
	max = 1 << n;
	for (int i = 0; i < max; i++)
	{
		int t = i;
		int c;
		int ans[10];

		for (int j = 0; j < 10; j++)
		{
			x[j] = t % 2;
			t /= 2;
		}

		for (int a = 0; a < m; a++)
		{
			int status = 0;
			for (int b = 0; b < k[a]; b++)
			{
				status += x[s[a][b] - 1];
			}
			if( status % 2 == p[a] )
			{
				ans[a] = 1;
			}
			else
			{
				ans[a] = 0;
			}
		}

		for (c = 0; c < m; c++)
		{
			if( ans[c] == 0 ) break;
		}
		if( c == m )
			count++;
	}

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

	return 0;
}


Measured memory_bytes: 128