akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int N, Q;
	cin >> N >> Q;
	vector<int> A(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
	sort(A.begin(), A.end());
	for (int i = 0; i < Q; ++i) {
		int L, R;
		cin >> L >> R;
		cout << lower_bound(A.begin(), A.end(), R + 1) - lower_bound(A.begin(), A.end(), L) << '\n';
	}
	return 0;
}


Measured memory_bytes: 3352
# encoding:utf-8

import numpy as np
import random

n = int(input())
x = []
t = []
y = []
for i in range(n):
    t_tem,x_tem,y_tem = map(int,input().split())
    t.append(t_tem)
    x.append(x_tem)
    y.append(y_tem)

def check_move(t,x,y):
    check = True
    #距離が長いとダメ
    if x+y > t:
        check = False
    #偶奇の組み合わせだとダメ
    elif x+y+t%2 == 1:
        check = False

    return check

answer = True
x_now = 0
y_now = 0
t_now = 0
for i in range(n):
    answer *= check_move(t[i]-t_now,x[i]-x_now,y[i]-y_now)
    t_now = t[i]
    x_now = x[i]
    y_now = y[i]

if answer:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 22600
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int MX=60;
const ll mod=1000000007;
int n,m,k;
int main(){
    cin>>n>>m>>k;
    for(int i=0;i<=n;i++){
        for(int j=0;j<=m;j++){
            if(i*(m-j)+j*(n-i)==k){
                puts("Yes");
                return 0;
            }
        }
    }
    puts("No");
}


Measured memory_bytes: 256
//逆ポーランド記法
#include<stdio.h>
#include<string.h>

#define STACK_SIZE 100
#define TRUE 1
#define FALSE 0

int stack[STACK_SIZE];
int top=0;

int isEmpty(){
  if(top==0){
    return TRUE;
      }else{
    return FALSE;
      }
}

void push(int a){
  top++;
  stack[top]=a;
}

int pop(){
  if(isEmpty()==TRUE){
    printf("error underflow\n");
  }else{
    return stack[top--];
  }
}

int main(){
  int a=0;
  char str[10];
  char input;
  int num;
  int pop1,pop2;

  while(scanf("%c",&input)!=EOF){
    if('0'<=input && input<='9'){
      str[a]=input;
      a++;
    }else if(input==' '){
      str[a]='\0';
      num=atoi(str);
      if(str[0]!='\0')push(num);
      a=0;
    }else if(input=='+'){
      pop2=pop();
      pop1=pop();
      push(pop1+pop2);
    }else if(input=='-'){
      pop2=pop();
      pop1=pop();
      push(pop1-pop2);
    }else if(input=='*'){
      pop2=pop();
      pop1=pop();
      push(pop1*pop2);
    }else{
      continue;
    }
  }

  printf("%d\n",pop());
  return 0;
}

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

using namespace std;

int main()
{
    int n,k;
    cin>>n>>k;
    set<int>s;
    vector<int>v(n);
    for(int i=0;i<n;i++)
        cin>>v[i];
    int cnt=1;
    for(int i=0;i<k;i++){
            s.insert(v[i]);
    }
    int l=0;
    for(int i=k;i<n;i++){
        s.erase(v[l]);
        l++;
        if(v[i]<*(s.rbegin())||v[l-1]>*(s.begin())){
            cnt++;
        }
        s.insert(v[i]);
    }
    int cntrp=0;
    int b=0,e=0;
    int f=0;
    for(int i=0;i<n;i++){
        while(v[b]>v[e]||e-b+1>k||(e-b+1>1&&v[e]<v[e-1])){
            b++;
        }
        if(e-b+1==k&&!f){
            cntrp++;
            f=1;
        }
        else if(e-b+1!=k){
            f=0;
        }
        e++;
    }
    if(cntrp)
        cnt-=(cntrp-1);
    cout << cnt << endl;
    return 0;
}
/**
5 3
0 2 1 4 3
4 4
0 1 2 3

10 4
2 0 1 3 7 5 4 6 8 9
*/


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


int main(){
	int n,W;
	cin>>n>>W;
	vector<vector<long long int> > dp(n+1,vector<long long int>(W+1,0));
	vector<int> w(n),v(n);
	for(int i=0;i<n;i++){
		cin>>w[i]>>v[i];
	}
	for(int i=1;i<=n;i++){
		for(int j=0;j<(W+1);j++){
			if(w[i-1]>j){
				dp[i][j]=dp[i-1][j];
			}
			else{
				dp[i][j]=max(v[i-1]+dp[i-1][j-w[i-1]],dp[i-1][j]);
			}
		}
	}
	cout<<dp[n][W]<<endl;
	return 0;
}

Measured memory_bytes: 80256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cstdint>
using namespace std;

int main(){
  int64_t N ; cin >> N;
  
  int64_t a = 2;
  int64_t b = 1;
  int64_t c;
  bool flag = true;
  if(N == 1){
    flag = false;
    c = 1;
  }
  if(flag){
  for(int i = 0; i < N -1 ; i++){
    c = b + a;
    a = b;
    b = c;
  }
}
  cout << c << endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int M = sc.nextInt();
		int K = sc.nextInt();
		int n = (int)Math.pow(2,M);
		
		if(K >= n){
			System.out.print(-1);
			return;
		}else if(M == 0){
			if(K == 0){
				System.out.print("0 0");
			}else{
				System.out.print(-1);
			}
			return;
		}else if(M == 1){
			if(K == 0){
				System.out.print("0 0 1 1");
			}else{
				System.out.print(-1);
			}
			return;
		}
		
		for(int i = 0; i < n; i++){
			if(K != i){
				System.out.print(i + " ");
			}
		}
		System.out.print(K + " ");
		
		for(int i = n-1; i > -1; i--){
			if(K != i){
				System.out.print(i + " ");
			}
		}
		System.out.print(K);
	}
}

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


int main(){
    ll n,k;cin>>n>>k;
    string s;cin>>s;
    ll one=1,cn=0;
    vector<ll> a;
    a.push_back(0);
    rep(i,0,s.size()){
        if(one==0&&s.at(i)=='1'){
            a.push_back(cn);
            cn=0;
            one=1;
        }
        else if(one==1&&s.at(i)=='0'){
            a.push_back(cn);
            cn=0;
            one=0;
        }
        cn++;
    }
    a.push_back(cn);
    if(one==0)a.push_back(0);
    rep(i,1,a.size()){
        a.at(i)+=a.at(i-1);
    }
    ll kk=min((ll)a.size()/2-1,k),MAX=-1;
    rep(i,0,a.size()/2-kk){
        MAX=max(MAX,a.at(2*kk+1+2*i)-a.at(2*i));
    }
    cout<<MAX<<endl;
}







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

#define vi vector<int>
#define vii vector<int, int>
#define ll long long
#define pb push_back
#define mp make_pair
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
#else
#define trace(...) 42
#endif

const int MOD = 1000000007;

double distance(vector<int> a, vector<int> b){
    int sum = 0;

    for (int i = 0; i < (int)a.size(); i++){
        sum += pow(a[i] - b[i], 2);
    }

    return sqrt(sum);
}

int main(){
    IOS;
    int n, d;
    cin >> n >> d;
    vector<int> a[n];

    for (int i = 0; i < n; i++){
        for (int j = 0; j < d; j++){
            int x;
            cin >> x;
            a[i].pb(x);
        }
    }

    int count = 0;
    for (int i = 0; i < n; i++){
        for (int j = i+1; j < n; j++){
            double dist = distance(a[i], a[j]);
            if (floor(dist) == dist) count++;
        }
    }

    cout << count << endl;

    #ifdef LOCAL
        cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif

    return 0;
}



Measured memory_bytes: 256
import collections

n = int(input())
aol = [input() for i in range(n)]
m = int(input())
akal = [input() for j in range(m)]

aod = collections.Counter(aol)
akad = collections.Counter(akal)

l = [0]
for key in aod:
    if (key in akad) == True:
        sa = aod[key] - akad[key]
        l.append(sa)
    else:
        l.append(aod[key])

print(max(l))

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

int n, q, m;
int a[20];

int solve(int i, int m) {
  if (m == 0) return 1;
  if (i >= n) return 0;
  int res = solve(i+1, m) || solve(i+1, m - a[i]);
  return res;
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i ++) cin >> a[i];
  cin >> q;
  for (int i = 0; i < q; i ++) {
    cin >> m;
    if (solve(0, m)) cout << "yes" << endl;
    else cout << "no" << endl;
  }
}



Measured memory_bytes: 3100
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int n;
    string s;
    cin >> n >> s;
    VI sw(n);
    sw[0] = s[0] == '.';
    REP(i,1,n) sw[i] = sw[i-1] + (s[i] == '.');
    //dump(sw[n-1]);
    int ans = min(sw[n-1], n - sw[n-1]);
    REP(i,0,n) {
        int lb = i + 1 - sw[i];
        int rw = (sw[n-1] - sw[i]);
        //dump(i);
        //dump(lb);
        //dump(rw);
        ans = min(ans, lb + rw);
    }
    cout << ans << endl;
}

int main() {
    solve();
    
    return 0;
}

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


void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
}

#define ll long long
#define ld long double
#define ull unsigned long long
#define ull unsigned long long
#define mod 1000000007
#define pi (3.1415926)

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))

#define scd(a)  scanf("%lld",&a)
#define scdd(a,b)	scanf("%lld%lld",&a,&b)
#define scddd(a,b,c)	scanf("%lld%lld%lld",&a,&b,&c)
#define ptab(a)	printf("%lld ",a)
#define pdn(a)	printf("%lld\n",a)
#define pddn(a,b)	printf("%lld %lld\n",a,b)
#define pdddn(a,b,c)	printf("%lld %lld %lld\n",a,b,c)

#define Filein(N) freopen("N", "r", stdin);
#define Fileout(N) freopen("N", "w", stdout);

#define forr(n) for(ll i=0;i<n;i++)
#define rev(n) for(ll i=n-1;i>=0;i--)
#define forp(x, y) for(ll i=x;i<y;i++)
#define loop( j, k, in) for (ll i=j ; i<k ; i+=in)

#define en "\n"
#define sp " "
#define eps 1.0E-14
#define l length()
#define preci(x) cout << fixed<<setprecision(x)
#define inf LONG_LONG_MAX
#define ninf LONG_LONG_MIN

ull fastpow(ull a,ull b)
{
  ull wynik=1;
  while (b)
  {
    if (b&1)wynik=(wynik*a)%mod;
    a=(a*a)%mod;
    b>>=1;
  }
  return wynik;
}

bool odd(int n)
    {
        int x = sqrt(n);
    for (int i=2 ; i<=x ; ++i)

    {
        if(n%i == 0)return false;
    }

    return true;
    }
ll fact(int n ){

long long fact =1;

for (int i =2 ;i<=n;++i)

{
    fact*=i;
}
return fact;
}

bool prim(long long a){

long long s = sqrt(a);

for (int i=2 ; i<= s ;++i){

    if (a % i == 0)return false;
}
return true;
}

ll sum (int n ){return ((n*(n+1)) / 2) ;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

bool myfunction (string i,string j) /* this function to check who is grater in
sorting strings as numbers ////////
int n;
    cin>>n;
    vector <string> arr(n);
    for(int i=0;i<n;i++)
        cin>>arr[i];


    sort(arr.begin(),arr.end(),myfunction);

    for(int i=0;i<n;i++)
        cout<<arr[i]<<endl;
*/
{
    int n=i.length();
    int m=j.length();
    if(n==m)
        return (i<j);

    return n<m;
}
long long solve (int a, int b)
{
    return min(a,min(b , (a+b) / 3));
}

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

    string s; cin>>s;

    cout << s[0] << s[1] << s[2];
}



Measured memory_bytes: 3616
if __name__ == "__main__":
    from itertools import permutations
    N, M, R = map(int, input().split())
    rs = map(lambda x: int(x) - 1, input().split())
    dist = [[10**9 for _ in range(N)] for _ in range(N)]
    for _ in range(M):
        v1, v2, d = map(int, input().split())
        dist[v1-1][v2-1] = dist[v2-1][v1-1] = d
    for i in range(N):
        dist[i][i] = 0
    for k in range(N):
        for i in range(N):
            for j in range(N):
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
    ans = 10**9
    for r in permutations(rs):
        t = 0
        for i in range(R-1):
            t += dist[r[i]][r[i+1]]
            if t > 10**9:
                break
        ans = min(t, ans)
    print(ans)

Measured memory_bytes: 47064
N=int(input())
p=list(map(int, input().split()))

S=[]
for i in range(1,N+1):
  S.append(i)

count=0
for i in range(0,N):
  diff=S[i]-p[i]
  #print(diff)
  if diff!=0:
    count=count+1

if count<=2:
  print("YES")
else:
  print("NO")

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
using namespace std;
int main() {
  char b;
  int a, c;
  cin >> a >> b >> c;
  if(b == '+') cout << a + c << endl;
  else cout << a - c << endl;
  
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
#define ll long long 
#define il inline
const int maxn=110;
ll a[maxn]; int n,ans; 
bool check(ll x,ll y,ll z){
    if (x==y||y==z||x==z) return false;
    if (x+y>z&&x+z>y&&y+z>x) return true;
    else return false;
}
int main(){
    scanf("%d",&n);
    for (int i=1;i<=n;++i){
        scanf("%lld",&a[i]);
    }
    for (int i=1;i<=n-2;++i){
        for (int j=i+1;j<=n-1;++j){
            for (int k=j+1;k<=n;++k){
                if (check(a[i],a[j],a[k])){
                    ++ans;
                    //cout<<i<<j<<k;
                }
            }
        }
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 3828
def is_palindromic(num):
    tmp = list(str(num))
    while len(tmp) != 1:
        if tmp[0] == tmp[-1]:
            tmp.pop(0)
            tmp.pop(-1)
        else:
            return False
    return True


A, B = map(int, input().split())
ans = 0
for i in range(A, B+1):
    if is_palindromic(i):
        ans += 1

print(ans)


Measured memory_bytes: 3060
import java.util.Scanner;

   class Main {
    public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
    	String a=sc.next();
    	String b=sc.next();
    	if((a.equals("H") && b.equals("H")) || (a.equals("D") && b.equals("D"))) {
    		System.out.println("H");
    		System.exit(0);
    	}
    	else{
    		System.out.println("D");
    		System.exit(0);
    	}
    }
}

Measured memory_bytes: 21716
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new java.util.Scanner(System.in);
		int[] array = new int[5];

		for(int i = 0; i < 5; i++){
			array[i] = scanner.nextInt();
		}

		Arrays.sort(array);

		System.out.println(array[4]+" "+array[3]+" "+array[2]+" "+array[1]+" "+array[0]);

	}
}

Measured memory_bytes: 26176
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)



typedef long long ll;
int N;
int A[101010];
vector<int> E[101010];
//-----------------------------------------------------------------
ll dfs(int cur, int par) {
	if (E[cur].size() == 1) return A[cur];

	ll sm = 0;
	ll ma = 0;
	for (int i : E[cur]) if (i != par) {
		ll r = dfs(i, cur);
		if (r < 0) return -1;
		sm += r;
		ma = max(ma, r);
	}

	ll nxt = 2LL * A[cur] - sm;

	if (sm < A[cur]) return -1;
	if (nxt < 0) return -1;
	if (ma > A[cur] && ma * 2 > sm) return -1;

	return nxt;
}
//-----------------------------------------------------------------
bool sol() {
	if (N == 2) {
		if (A[0] == A[1]) return true;
		return false;
	}

	int ma = 0;
	rep(i, 0, N) if (E[ma].size() < E[i].size()) ma = i;

	ll ret = dfs(ma, -1);

	return ret == 0;
}
//-----------------------------------------------------------------
int main() {
	cin >> N;
	rep(i, 0, N) scanf("%d", &A[i]);
	rep(i, 0, N - 1) {
		int a, b;
		scanf("%d %d", &a, &b);
		a--; b--;
		E[a].push_back(b);
		E[b].push_back(a);
	}

	if (sol())
		printf("YES\n");
	else
		printf("NO\n");
}

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

int main() {
	int X, Y, Z;
	cin >> X >> Y >> Z;
	
	X = X - Z*2;
	int cnt;
	while(true){
		if(X>=Y+Z){
			X -=Y;
			cnt++;
			X -= Z;
		}
		else if(X==Y){
			cnt++;
			X-=Y;
		}
		else break;
	}
	
	cout << cnt;
	cout << endl;
	
	
	return 0;
}

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

int main(){

  int n,m;
  int a,b;
  int ans,k;

  cin >> n >> m;

  ans = k = m;

  for(int i=0;i<n;i++){
    cin >> a >> b;

    if(a+k < b){
      ans = 0;
      k = -10000000;
    }

    k = k + a - b;

    ans = max(ans,k);
  }

  cout << ans << endl;

}

Measured memory_bytes: 1160
# coding:utf-8
def main():
    n,a,b = map(int, input().split())
    #総和
    count = 0

    for number in range(1,n+1):
        #各桁の合計値
        score = 0
        for loop in str(number):
            loop = int(loop)
            score = score + loop
        if score >= a and score <= b:
            count += int(number)
    print(count)


if __name__ == '__main__' :
    main()

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

const int maxn=3005;
const int mid=3000;
long double dp[maxn][maxn*2];
long double t[maxn];

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%Lf",&t[i]);
	dp[1][mid+1]=t[1];
	dp[1][mid-1]=(1-t[1]);
	for(int i=2;i<=n;i++)
		for(int j=-mid;j<=mid;j++)
			dp[i][j+mid]=dp[i-1][mid+j-1]*t[i]+dp[i-1][mid+j+1]*(1-t[i]);
	long double sum=0;
	for(int i=1;i<=mid;i++)
		sum+=dp[n][mid+i];
	printf("%.10Lf",sum);
}

Measured memory_bytes: 281856
#include<bits/stdc++.h>
using namespace std ;
typedef  long long int ll ;
#define inf ll(1e18)
#define mod 1000000007
#define mod1 998244353
#define mod2 999983
ll power(ll a,ll n,ll m) ;
ll power(ll a,ll n,ll m)
{  if(n==0)
   return 1 ;
   ll x=power(a,n/2,m) ;
   if(n%2!=0)
    return (((a*x)%m)*(x)%m)%m ;
    else return (x*x)%m ;
}
double PI=3.14159265357 ;
int32_t main()
{ ll n,i,j,x,y,m,k,t,sum,count,cnt,b,c,d,j1,z,a,temp;
  ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
   cin>>x>>y ;
   for(i=0;i<=x;i++)
   {

       z=i*2+(4)*(x-i) ;
       if(z==y)
        break ;
   }
   if(i<=x)
    cout<<"Yes" ;
   else cout<<"No" ;
   return 0; }


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a,b;cin>>a>>b;
    cout<<a/__gcd(a,b)*b;
    return 0;
}

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

int main () {
  string s;
  cin >> s;
  string num = to_string(s.size() - 2);
  string prefix = ""s + s[0];
  string suffix = ""s + s[s.size() - 1];
  string ans = prefix + num + suffix;
  cout << ans << endl;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
from operator import itemgetter
bridges = []
for i in range(M):
    bridges.append(list(map(int, input().split())))
bridges.sort(key=itemgetter(1))
b_right = 0
cnt = 0
for a,b in bridges:
    if a > b_right:
        b_right = b - 1
        cnt += 1
print(cnt) 


Measured memory_bytes: 29148
#include <stdio.h>

const int N = 105;
int main(void)
{
	int n, a[N] = {0};
	
	scanf("%d", &n);
	
	for(int i = 0; i < n;i++)
	{
		scanf("%d", &a[i]);
	}
	for(int i = n - 1;i >= 0;i--)
	{
		if(i)
		{
	    	printf("%d ", a[i]);	
		}
		else
		{
	    	printf("%d\n", a[i]);	
		}
    }
 } 



Measured memory_bytes: 2704
import heapq

X, Y, Z, K = map(int, input().split())
A = sorted(list(map(int, input().split())),reverse=True)
B = sorted(list(map(int, input().split())),reverse=True)
C = sorted(list(map(int, input().split())),reverse=True)

used = set()
candidate = []
heapq.heappush(candidate, (-A[0]-B[0]-C[0], 0, 0, 0))

for _ in range(K):
    value, x, y, z = heapq.heappop(candidate)
    print(-value)

    if x+1 < X and (x+1, y, z) not in used:
        heapq.heappush(candidate, (-A[x+1]-B[y]-C[z], x+1, y, z))
        used.add((x+1, y, z))

    if y+1 < Y and (x, y+1, z) not in used:
        heapq.heappush(candidate, (-A[x]-B[y+1]-C[z], x, y+1, z))
        used.add((x, y+1, z))

    if z+1 < Z and (x, y, z+1) not in used:
        heapq.heappush(candidate, (-A[x]-B[y]-C[z+1], x , y, z+1))
        used.add((x, y, z+1))

Measured memory_bytes: 4976
N = int(input())

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

lis = []


mi = float("inf")
ma = float("-inf")
mi_ind = 0
ma_ind = 0

for i in range(N):

    if mi > a[i]:
        mi = a[i]
        mi_ind = i
    if ma < a[i]:
        ma = a[i]
        ma_ind = i
        
flag = None
if mi < 0 and 0 < ma:

    if abs(mi) <= abs(ma):

        flag = 0

        for i in range(N):

            if a[i] < 0:
                lis.append([ma_ind + 1,i+1])

    else:

        flag = 1

        for i in range(N):

            if a[i] > 0:
                lis.append([mi_ind + 1,i+1])

if mi >= 0 or flag == 0:

    for i in range(N-1):

        lis.append([i+1,i+2])

else:

    for i in range(N-1):

        lis.append([N-i,N-1-i])


print (len(lis))

for i in lis:

    print (i[0],i[1])
    


Measured memory_bytes: 38384
while True:
    h,w = map(int,input().split())
    
    if h==0 and w==0:
        break
    
    for y in range(h):
        for x in range(w):
            if (x + y) % 2 == 0:
                print('#',end='')
            else:
                print('.',end='')
        print('')
    print('')
    


Measured memory_bytes: 7012
import java.io.*;
import java.util.*;

/**
 * Created by Ayushi on 19 Jan 2020.
 * Problem:
 * Round:
 */

public class Main {
    public static void main(String[] args) throws IOException {
        StringTokenizer st;
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String temp = br.readLine();
        st = new StringTokenizer(temp, " ");
        int a = Integer.parseInt(st.nextToken());
        int b = Integer.parseInt(st.nextToken());
        br.close();

        System.out.println(a == b ? "Yes":"No");
    }
}


Measured memory_bytes: 21076
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <bitset>

using namespace std;

int N, K;
string S;
vector<pair<int, int> > pVector; // 直立範囲の集合

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

    int temp = -1;
    for (int i = 0; i < N; i++) {
        if (S[i] == '0') {
            if (temp == -1) {
                temp = i;
                if (i+1 < N) {
                    if (S[i+1] == '1') {
                        pVector.push_back(make_pair(i, i));
                        temp = -1;
                    }
                }
            } else if (i == N-1) {
                pVector.push_back(make_pair(temp, i));
                temp = -1;
            } else {
                if (S[i+1] == '1') {
                    pVector.push_back(make_pair(temp, i));
                    temp = -1;
                }
            }
        }
    }
    if (temp != -1) {
        pVector.push_back(make_pair(temp, temp));
    }

    if (pVector.size() <= K) {
        cout << N << endl;
        return 0;
    }

    int ans = 0;
    for (int i = 0; i <= pVector.size() - K; i++) {
        int start;
        if (i == 0) {
            start = 0;
        } else {
            pair<int, int> temp = pVector[i-1];
            start = temp.second + 1;
        }
        
        int end;
        if (i == pVector.size() - K) {
            end = N - 1;
        } else {
            pair<int, int> temp = pVector[i+K];
            end = temp.first - 1;
        }

        int num = end - start + 1;
        if (ans < num) {
            ans = num;
        }
    }

    cout << ans << endl;

    return 0;
}


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

int main()
{
  int i,a,b,c;
  while(1){
    cin >> a >> b >> c;
    if(a==-1 && b==-1 && c==-1) break;
    if(a==-1 || b==-1) cout << "F\n";
    else if(a+b>=80) cout << "A\n";
    else if(a+b>=65) cout << "B\n";
    else if(a+b>=50) cout << "C\n";
    else if(a+b>=30){
      if(c>=50) cout << "C\n";
      else cout << "D\n";
    }else cout << "F\n";
  }
  return 0;
}

Measured memory_bytes: 3052
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++) //for文マクロ
using namespace std;

typedef unsigned long ul;
typedef long long ll;
typedef pair<ul, ul> P; //ペア　タイプでふ

int main()
{
    int n, a, b;
    cin >> n >> a >> b;
    if (n * a > b)
    {
        cout << b;
    }
    else
    {
        cout << a * n;
    }
}

Measured memory_bytes: 256
n, m = map(int, input().split())
dic = {}

for i in range(m,1):
    dic[i] = 0


for _ in range(n):
    arr = list(map(int, input().split()))

    for item in arr[1:]:

        if item in dic:
            dic[item] += 1
        else:
            dic[item] = 1

ans = 0
for count in dic.values():
    if count == n:
        ans += 1

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
static const double pi = 3.141592653589793;

double search(double t){
	double ok = 0, ng = 90;
	for(int i=0; i<1000; i++){
		double mid = (ok + ng)/2;
		if(tan(pi*(2*mid/360)) >= t){
			ng = mid;
		}else{
			ok = mid;
		}
	}
	return ok;
}

int main(){
	double a, b, x; cin >> a >> b >> x;
	if(x <= a*a*b/2){
		double ans = (x*2)/(a*b);
		cout << setprecision(12) << search(b/ans) << endl;
	}else{
		x = a*a*b - x;
		double ans = (x*2)/(a*a);
		cout << setprecision(12) << 90 - search(a/ans) << endl;;
	}
	return 0;
}


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

int a, b, c, x;

int main(void){
	cin >> a >> b >> c >> x;
	int ans = 0;
	rep(i, a+1){
		rep(j, b+1){
			rep(k, c+1){
				if(500*i+100*j+50*k == x) ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


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

bool has_smaller_second(const pair<int, int>& a, const pair<int, int>& b)
{
  return a.second < b.second;
}

int main()
{
  int n;
  cin >> n;
  vector<pair<int, int>> v(n);
  for (int i = 0; i < n; i++) {
    v.at(i).first = i;
    cin >> v.at(i).second;
  }
  sort(v.begin(), v.end(), has_smaller_second);
  cout << v.at(0).first + 1;
  for (int i = 1; i < n; i++) {
    cout << ' ' << v.at(i).first + 1;
  }
  cout << '\n';
  return 0;
}


Measured memory_bytes: 1536
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <queue>

using namespace std;


int main(){

	int table[6] = {0,0,0,0,0,0},sum;

	for(int i = 0; i < 6; i++){
		scanf("%d",&table[i]);
	}

	sum = 1*table[0]+5*table[1]+10*table[2]+50*table[3]+100*table[4]+500*table[5];
	if(sum >= 1000)printf("1\n");
	else{
		printf("0\n");
	}

	return 0;
}

Measured memory_bytes: 2572
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int[] A = {sc.nextInt(), sc.nextInt(), sc.nextInt()};
        int min = Integer.MAX_VALUE;
        
        // 総当たりする方法
        for(int i = 0; i < 3; i++){
            for(int j = 0; j < 3; j++){
                if(j == i) continue;
                
                for(int k = 0; k < 3; k++){
                    if(k == i || k == j) continue;

                    int cost = Math.abs(A[i] -A[j]) + Math.abs(A[j] - A[k]);
                    if(min > cost) min = cost;
                }
            }
        }
        System.out.println(min);
    }
}


Measured memory_bytes: 21972
#include <iostream>
#include <vector>
#include <map>
#include <iterator>
#include <algorithm>
using namespace std;

int N, K;
vector<int> C;
map<int, int> M;

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

	cin >> N >> K;
	for (int i = 0; i < N; ++i) {
		int a;
		cin >> a;
		++M[a];
	}

	int sz = M.size();
	C.resize(sz);
	int p = 0;
	map<int, int>::iterator itr;
	for (itr = M.begin(); itr != M.end(); ++itr)
		C[p++] = itr -> second;

	int ans = 0;
	sz = C.size();
	if (sz > K) {
		sort(C.begin(), C.end());
		for (int i = 0; i < sz - K; ++i)
			ans += C[i];
	}

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


Measured memory_bytes: 10368
#include<stdio.h>
static inline int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
int main()
{
  int c[26],D=IN(),i=0,j=0,M=0,s[365][26]={{0}},t[365],sum=0,temp=0,update[26]={0};
  while(i<26){c[i++]=IN();}i=0;
  while(i<D){while(j<26){s[i][j++]=IN();}i++,j=0;}i=0;
  while(i<D)
  {
    j=0;temp=IN()-1;t[i]=temp;sum+=s[i][temp];update[temp]=++i;
    while(j<26){sum-=c[j]*(i-update[j]);j++;}
  }M=IN();
  while(M--)
  {
    int d=IN()-1,q=IN()-1,l0=-1,l1=-1,r0=D,r1=D,esc0=0,esc1=0;
    sum+=s[d][q]-s[d][t[d]];i=d-1;
    while(i>=0)
    {
      if(t[i]==t[d]&&!esc0){l0=i;esc0=1;}
      if(t[i]==q&&!esc1){l1=i;esc1=1;}
      if(esc0&esc1){break;}i--;
    }
    esc0=esc1=0;i=d+1;
    while(i<D)
    {
      if(t[i]==t[d]&&!esc0){r0=i;esc0=1;}
      if(t[i]==q&&!esc1){r1=i;esc1=1;}
      if(esc0&esc1){break;}i++;
    }
    sum-=c[t[d]]*(d-l0)*(r0-d);sum+=c[q]*(d-l1)*(r1-d);t[d]=q;
    printf("%d\n",sum);
  }
}

Measured memory_bytes: 1596
N = int(input())
count = 0
flag = False
for _ in range(N):
    D1, D2 = map(int, input().split())
    if D1 == D2:
        count += 1
        if count == 3:
            flag = True
            break
    else:
        count = 0

if flag == True:
    print('Yes')
else:
    print("No")


Measured memory_bytes: 62428
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N = n()

def ok(S):
    for ng in ['AGC', 'GAC', 'ACG']:
        if S[1:] == ng or S[:3] == ng:
            return False
    if S[0] == 'A' and S[2:] == 'GC':
        return False
    if S[:2] == 'AG' and S[3] == 'C':
        return False
    return True


memo = {}
def find(i, prev):
    if (i, prev) in memo:
        return memo[(i, prev)]

    if i == N:
        return 1

    res = 0
    for c in 'ACGT':
        if ok(prev + c):
           res += find(i+1, prev[1:] + c)

    res %= 1000000007
    memo[(i, prev)] = res
    return res

print(find(0, 'TTT'))





Measured memory_bytes: 4556
from bisect import bisect_left

N = int(input())
X = list(map(int, input().split()))
S = sorted(X)
m1 = S[int(N/2 - 1)]
m2 = S[int(N/2)]
for x in X:
    if bisect_left(S, x) <= N/2 - 1:
        print(m2)
    else:
        print(m1)


Measured memory_bytes: 25228
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7


def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限。素数しか使用不可。
N = 2*10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

# need to calculate factorials to n+k-1
def combinations_with_repetition(n, k):
    return cmb(n+k-1, k, mod)

def num_of_pattern(n):
    sum_of_pattern = 0
    if n%2 == 1:
        for k in range(0,n,2):
            sum_of_pattern += combinations_with_repetition(((n-k)//2)+1, k)
        return sum_of_pattern % mod
    else:
        for k in range(1,n,2):
            sum_of_pattern += combinations_with_repetition(((n-k)//2)+1, k)
        return sum_of_pattern % mod

def main(): 
    N, M = LI()
    a_li = [-1]
    prev = INF
    for _ in range(M):
        now = II()
        if prev+1 == now:
            print(0)
            return
        elif prev == now:
            continue
        prev = now
        a_li.append(now)
    a_li.append(N+1)

    ans = 1
    for i in range(len(a_li)-1):
        ans *= num_of_pattern(a_li[i+1] - a_li[i] - 1)
        ans %= mod

    print(ans)

main()

Measured memory_bytes: 28852
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */

public class Main {
    public static void main(String[] args) {
        InputStream    inputStream    = System.in;
        OutputStream outputStream = System.out;
        InputReader    in                      = new InputReader(inputStream);
        PrintWriter      out                    = new PrintWriter(outputStream);
        Task                 solver               = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
    	public void solve(int testNumber, InputReader in, PrintWriter out) {
    		int A = in.nextInt();
    		int B = in.nextInt();
    		out.println(A * B - (A +B - 1));
    	}
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

const int N = 200010;
const int moder = (int) 1e9 + 7;

char s[N];
int a[N], diff[N];

int main() {
    int n;
    scanf("%d%s", &n, s);
    for (int i = 0; i < 2 * n; ++i) {
        a[i] = s[i] == 'W' ? 0 : 1;
    }
    int now = 0, ans = 1;
    for (int i = 0; i < 2 * n; ++ i){
        if ((now & 1) == a[i]){
            ans = 1ll * ans * now % moder;
            -- now;
        }
        else{
            ++ now;
        }
    }
    if (now != 0){
        puts("0");
        return 0;
    }
    for (int i = 1; i <= n; ++ i){
        ans = 1ll * ans * i % moder;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

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

	for (auto i = 0; i < s.length(); ++i)
	{
		if (s[i] == 'a')
		{
			continue;
		}

		auto diff = (ll)('z' - s[i]) + 1;
		if (diff > K)
		{
			continue;
		}

		K -= diff;
		s[i] = 'a';
	}

	if (K > 0)
	{
		auto last = s.length() - 1;
		auto mod = (ll)('z' - 'a') + 1;
		K %= mod;
		auto diff = (ll)('z' - s[last]) + 1;
		if (K >= diff)
		{
			s[last] = 'a' + (K - diff);
		}
		else
		{
			s[last] = s[last] + K;
		}
	}

	cout << s << endl;

	return 0;
}

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

typedef long long ll;

int main(){
  ll H, W, K;
  std::cin >> H >> W >> K;
  std::vector<std::string> c(6);
  for(int i = 0 ; i < H ; i++){
    std::cin >> c[i];
  }
  ll resa = 0;
  for(int i = 0 ; i < (1 << H); i++){
    for(int j = 0 ; j < (1 << W) ; j++){
      int num = 0;
      for(int k = 0 ; k < H ; k++){
	for(int l = 0 ; l < W ; l++){
	  int check_i = (i >> k) & 1;
	  int check_j = (j >> l) & 1;
	  if(check_i == 0 && check_j == 0){
	    if(c[k][l] == '#') num++;
	  }
	}
      }
      if(num == K) resa++;
    }
  }
  std::cout << resa << std::endl;
  return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int N;
    cin>>N;
    int a[N];
    int sum=0;
    rep(i,N){
        cin>>a[i];
        sum+=a[i];
    }
    int b=0,c=INF;
    rep(i,N){
        if(abs(a[i]*N-sum)<c){
            c=abs(a[i]*N-sum);
            b=i;
        }
    }
    cout << b << endl;








}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
#define faf ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define ll long long
#define pb push_back
#define mp make_pair
#define nt _int128
 
long double PI =3.14159265358979323846;
 
 
ll modo=1e9+7;
const ll inf=1e13;
const ll ms=1e5 +5;

int dp[3001][3001]={0};

int main()
{
    faf;
    
    
    string s;
    string t;
    cin>>s;
    cin>>t;
    int n=s.length();
    int k=t.length();
    int i;
    int j;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=k;j++)
        {
            if(s[i-1]==t[j-1])dp[i][j]=1+dp[i-1][j-1];
            else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
    i=n;
    j=k;
    stack<char> st;
    while(i>0&&j>0)
    {
        if(s[i-1]==t[j-1])
        {
            st.push(s[i-1]);
            i--;j--;
        }
        else if(dp[i-1][j]>=dp[i][j-1])i--;
        else j--;
    }
    while(!st.empty())
    {
        cout<<st.top();
        st.pop();
    }
    return 0;
}

Measured memory_bytes: 35456
#include <stdio.h>

int main(int argc, const char * argv[]) {
    // insert code here...
    int N;
    scanf("%d", &N);
    int state = 0;
    int arrCount = 1;
    int lastNum;
    scanf("%d", &lastNum);
    int newNum;
    for(int i = 1; i < N; i++) {
        scanf("%d", &newNum);
//        if (newNum == lastNum) continue;
        if (newNum > lastNum) {
            if (state >= 0) {
                state = 1;
            }
            else {
                state = 0;
                arrCount++;
            }
        }
        
        else if (newNum < lastNum) {
            if (state <= 0) {
                state = -1;
            }
            else {
                state = 0;
                arrCount++;
            }
        }
        
        lastNum = newNum;
    }
    
    
    printf("%d\n", arrCount);
    return 0;
}

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

fn main() {
    let i = stdin();
    run(&mut i.lock(), &mut stdout());
}

fn run(i: &mut BufRead, o: &mut Write) {
    let _: usize = read(i);
    let s = read_vec::<String>(i);

    let r = if s.contains(&String::from("Y")) {
        "Four"
    } else {
        "Three"
    };
    writeln!(o, "{}", r).unwrap();
}

fn read_line(i: &mut BufRead) -> String {
    let mut line = String::new();
    i.read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn read<T: FromStr>(i: &mut BufRead) -> T {
    read_line(i).parse().ok().unwrap()
}
fn read_vec<T: FromStr>(i: &mut BufRead) -> Vec<T> {
    read_line(i)
        .split(' ')
        .map(|x| x.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main(){
    int n;
    cin >> n;
    int len = to_string(n).length(), sum = 0;
    int pw_init = 1;
    for(int i = 0; i < len-1; i++) pw_init *= 10;
    for(int i = n; i > 0; i--){
        if(i % 10 == 0) continue;
        int pw = pw_init;
        // ex) 2011 -> 1xx2
        string s = to_string(i);
        for(int j = len; j > 1; j--){
            // ex) 1002
            int th = (s[s.length()-1] - '0') * pw + (s[0] - '0');
            // cout << "th: " << th << endl;
            sum += max(0, min((n-th+10)/10, pw/10));
            // cout << "sum: " << sum << endl;
            pw /= 10;
        }
        if(s[s.length()-1] == s[0]) sum += 1;
    }
    cout << sum;
    return 0;
}

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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const ll MOD=1e9+7;


int main(){
    int n; cin >> n;
    const int N=100000+5;
    vi v(n);
    vi cnt0(N, 0), cnt1(N, 0);
    for(int i=0; i<n; i++){
        cin >> v[i];
        if(i%2 == 0) cnt0[v[i]]++;
        else cnt1[v[i]]++;
    }
    vi ids0(N), ids1(N);
    for(int i=0; i<N; i++){
        ids0[i]=ids1[i]=i;
    }
    sort(all(ids0), [&](int i, int j){return cnt0[i] > cnt0[j];});
    sort(all(ids1), [&](int i, int j){return cnt1[i] > cnt1[j];});
    int res;
    if(ids0[0] != ids1[0]){
        res=n-cnt0[ids0[0]]-cnt1[ids1[0]];
    }
    else{
        res=n-max(cnt0[ids0[0]]+cnt1[ids1[1]], cnt0[ids0[1]]+cnt1[ids1[0]]);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 5372
use whiteread::parse_line;

fn main() {
    let (n, k): (usize, usize) = parse_line().unwrap();
    let mut ans: f64 = 0.0;
    let prob = 1.0 / n as f64;

    for mut i in 1..=n {
        let mut cnt = 0;
        while i < k {
            i *= 2;
            cnt += 1;
        }
        ans += prob / 2_u32.pow(cnt) as f64;
    }
    println!("{}", ans);
}


Measured memory_bytes: 2156
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define ll  long long 
#define rep(i, n)        for(ll i=0; i<(ll)(n); ++i)
#define mod 1000000007
  vector<ll>to[1000005];
int main(){
  ll a,b;cin>>a;
  for(ll i=1;i<=a;i*=2){
     b=i;
  }
  cout<<b;
  }


Measured memory_bytes: 23680
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define INF 1000000000
int main(){
cin.tie(0);
ios::sync_with_stdio(false);

	string s;
	int co=0;
	cin>>s;
	REP(i,4)
		if(s[i]=='2')co++;
	
	cout<<co<<endl;

	return 0;
}
		

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;
#define n_max 10000
#define INF 10001000

#define rep(i, a, n) for(int i = a; i < n; i++)
#define rep2(i, a, n) for(int i = a; i <= n; i++)
#define rrep(i, a, n) for(int i = a; i > n; i--)
#define rrep2(i, a, n) for(int i = a; i >= n; i--)
#define lrep(i, a, n) for(long int i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl
typedef long long ll;

ll func(ll i, ll j) {
    if(i<j) { return 0; }
    else    { return i/j;   }
}
 
ll gcd(ll i, ll j) {

    ll tmp;
    while(i%j!=0) {
        tmp = j;
        j = i%j;
        i = tmp;
    }
    return j;
}

ll lcm(ll i, ll j) {
    return i * j / gcd(i,j);
}

int main()
{
    ll A, B, C, D;

    cin >> A >> B >> C >> D;
    
    ll n = B-A+1;

    //ll c_cnt = B/C, d_cnt = B/D, cd_cnt = B/(C*D);
    ll c_cnt = func(B,C) - func(A-1,C);
    ll d_cnt = func(B,D) - func(A-1,D);
    ll cd_cnt = func(B,lcm(C,D)) - func(A-1,lcm(C,D));
    
    cout << n-(c_cnt+d_cnt-cd_cnt) << endl;

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]C - Shopping Street
            int N = int.Parse(Console.ReadLine());

            var F = GetShopData(N); //営業時間
            var P = GetShopData(N); //利益

            int max = 0 - int.MaxValue;

            //10個の時間帯それぞれについて、営業するかどうかを総当たりで試す
            for(int i = 1; i < Math.Pow(2, 10); i++)
            {
                string s = Convert.ToString(i, 2).PadLeft(10, '0');
                int profit = 0;

                for(int j = 0; j < N; j++)
                {
                    int p = GetProfit(F[j], P[j], s);
                    profit += p;
                }

                max = Math.Max(max, profit);
            }

            Console.WriteLine(max);
        }

        static int GetProfit(int[] F, int[] P, string s)
        {
            int opened = 0;

            for(int i = 0; i < 10; i++)
            {
                if (s[i] == '1' && F[i] == 1)
                {
                    opened++;
                }
            }

            return P[opened];
        }

        static int[][] GetShopData(int N)
        {
            var shop = new int[N][];

            for(int i = 0; i < N; i++)
            {
                var data = ReadLine();
                shop[i] = data;
            }

            return shop;
        }

        static int[] ReadLine()
        {
            var line = Console.ReadLine();
            var arr = line.Split(' ');

            return arr.Select(x => int.Parse(x)).ToArray();
        }
    }
}

Measured memory_bytes: 13396
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        char[] s = new char[4];
        String str = in.next();
        for(int i=0; i<4; i++) {
            s[i] = str.charAt(i);
        }
        Arrays.sort(s);
        System.out.println(s[0]==s[1] && s[2]==s[3] && s[1]!=s[2] ? "Yes" : "No");
    }
}


Measured memory_bytes: 21716