akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(10000)
def f(x,y):
    a[y][x]='0'
    for dx,dy in[[-1,0],[1,0],[0,-1],[0,1],[-1,-1],[1,-1],[-1,1],[1,1]]:
        dx+=x;dy+=y
        if 0<=dx<w and 0<=dy<h and a[dy][dx]=='1':f(dx,dy)
while 1:
    w,h=map(int,input().split())
    if w==0:break
    a=[list(input().split()) for _ in[0]*h];b=0
    for i in range(w):
        for j in range(h):
            if a[j][i]=='1':
                b+=1;f(i,j)
    print(b)

Measured memory_bytes: 11824
// ※※※ 解答不能 ※※※
// Kmcode氏.
// https://atcoder.jp/contests/abc164/submissions/12391952
#include <bits/stdc++.h>
using namespace std;
using ULL = unsigned long long int;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define MAX 505
int n, ty_r[MAX], ty_c[MAX], emp[MAX];
ULL val_r[MAX], val_c[MAX], ans[MAX][MAX];
bool tmp[MAX][MAX];

void transpose(){
    rep(i, n){
        rep(j, i) swap(tmp[i][j], tmp[j][i]);
        swap(val_r[i], val_c[i]);
        swap(ty_r[i], ty_c[i]);
   }
}

void fi(ULL pos){
    memset(emp, 0, sizeof(emp));
    rep(j, n){
        if(!ty_c[j]){
            emp[j] = n - 1;
            rep(k, n) emp[j] -= tmp[k][j];
        }
    }
    rep(i, n){
        if(ty_r[i]){
            if(((val_r[i]) >> pos) & 1ULL){
                bool valid = false;
                rep(j, n) valid |= tmp[i][j];
                if(!valid){
                    rep(j, n){
                        if(emp[j] > 0){ 
                            emp[j]--;
                            tmp[i][j] = true;
                            break;
                        }
                    }
                }
            }
       }
    }
}

void solve(ULL pos){
    memset(tmp, false, sizeof(tmp));
    rep(i, n){
        if(!ty_r[i] && ((val_r[i]) >> pos) & 1ULL) rep(j, n) tmp[i][j] = 1;
        if(!ty_c[i] && ((val_c[i]) >> pos) & 1ULL) rep(j, n) tmp[j][i] = 1;
    }
    rep(i, n){
        rep(j, n){
            if(ty_r[i] == ty_c[j]){
                if(!ty_r[i]) tmp[i][j] = ((val_r[i] >> pos) & 1ULL) | ((val_c[j] >> pos) & 1ULL);
                else         tmp[i][j] = ((val_r[i] >> pos) & 1ULL) & ((val_c[j] >> pos) & 1ULL);
            }
        }
    }
    fi(pos);
    transpose();
    fi(pos);
    transpose();
    rep(i, n) rep(j, n) ans[i][j] += ((ULL)(tmp[i][j]) << pos);
}

void fo(){
   puts("-1");
   exit(0);
}

void check(){
    rep(i, n){
        ULL AN1 = -1, AN2 = -1;
        ULL O1 = 0, O2 = 0;
        rep(j, n){
            AN1 &= ans[i][j];
             O1 |= ans[i][j];
            AN2 &= ans[j][i];
             O2 |= ans[j][i];
        }
        if(!ty_r[i] && AN1 != val_r[i])    fo();
        else if(ty_r[i] && O1 != val_r[i]) fo();
        if(!ty_c[i] && AN2 != val_c[i])    fo();
        else if(ty_c[i] && O2 != val_c[i]) fo();
    }
}

int main(){
    scanf("%d", &n);
    rep(i, n) scanf("%d", &ty_r[i]);
    rep(i, n) scanf("%d", &ty_c[i]);
    rep(i, n) scanf("%llu", &val_r[i]);
    rep(i, n) scanf("%llu", &val_c[i]);
    rep(i, 64) solve(i);
    check();
    rep(i, n){
       rep(j, n){
          if(j) printf(" ");
          printf("%llu", ans[i][j]);
       }
       puts("");
    }
    return 0;
}

Measured memory_bytes: 7752
#include <bits/stdc++.h>
#define int long long
#define f first
#define s second
using namespace std;
int32_t main(){
    ios::sync_with_stdio(0),cin.tie(0);
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int x=ceil((double)c/b);
    int y=ceil((double)a/d);
    if(x<=y)cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 3760
#include<stdio.h>

struct DICE {
		int data;
		struct DICE *N;
		struct DICE *E;
		struct DICE *S;
		struct DICE *W;
		struct DICE *B;
		};

struct DICE *turn(struct DICE *NOW,char com);


int main(void){
struct DICE A[6],*NOW;
int j,i,c,up,front;

for(i=0;i<6;i++){
	scanf("%d",&A[i].data);
}
A[0].N=&A[4];
A[0].E=&A[2];
A[0].S=&A[1];
A[0].W=&A[3];
A[0].B=&A[5];
NOW=&A[0];

scanf("%d",&c);
for(j=0;j<c;j++){
scanf("%d %d",&up,&front);
while(1){
for(i=0;i<4;i++){
if(NOW->S->data==front){break;}
    NOW=turn(NOW,'S');
}
if(i==4){NOW=turn(NOW,'E');}else{break;}
}
for(i=0;i<4;i++){
if(NOW->data==up){break;}
    NOW=turn(NOW,'E');
}
printf("%d\n",NOW->E->data);
}

return 0;
}

struct DICE *turn(struct DICE *NOW,char com){
	struct DICE *TEMP;
	TEMP=NOW;
	switch(com){
	case 'N':
		NOW=NOW->S;
		NOW->N=TEMP;
		NOW->S=TEMP->B;
		NOW->E=TEMP->E;
		NOW->W=TEMP->W;
		NOW->B=TEMP->N;
		break;
	case 'S':
		NOW=NOW->N;
		NOW->N=TEMP->B;
		NOW->S=TEMP;
		NOW->E=TEMP->E;
		NOW->W=TEMP->W;
		NOW->B=TEMP->S;
		break;
	case 'E':
		NOW=NOW->W;
		NOW->N=TEMP->N;
		NOW->S=TEMP->S;
		NOW->E=TEMP;
		NOW->W=TEMP->B;
		NOW->B=TEMP->E;
		break;
	case 'W':
		NOW=NOW->E;
		NOW->N=TEMP->N;
		NOW->S=TEMP->S;
		NOW->E=TEMP->B;
		NOW->W=TEMP;
		NOW->B=TEMP->W;
		break;
	}
	return(NOW);
}

Measured memory_bytes: 596
a, b, m = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
X = []
Y = []
C = []
for i in range(m):
    x, y, c = [int(j) for j in input().split()]
    X.append(x)
    Y.append(y)
    C.append(c)
# print(X, Y, C)

pricelist = [min(A) + min(B)]
for i in range(m):
    pricelist.append(A[X[i]-1] + B[Y[i]-1] - C[i])
print(min(pricelist))


Measured memory_bytes: 27764
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
//const int MAX=;

int main(){
	int X;
	cin>>X;
	int ans=1;
	for(int i=2;i<=31;i++){
		int k=i*i;
		while (k<=X){
			ans=max(k,ans);
			k=k*i;
		}
	}
	cout<<ans;
}


Measured memory_bytes: 256
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string a = Console.ReadLine();
                if (a == null)
                {
                    break;
                }
                else
                {
                    if (a.Length == 0)
                        continue;
                    string[] str = a.Split(' ');
                    

                    int n = Convert.ToInt32(str[0]);
                    int m = Convert.ToInt32(str[1]);
                    int p = n + m;
                    string wr = Convert.ToString(p);
                    int w = wr.Length;
                    Console.WriteLine(w);
                }
            }
        }
    }
}

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

int main() {
	int N;
	cin >> N;
	vector<int> a(N);
	for (int i = 0; i < N; i++) {
		cin >> a.at(i);
	}
	sort(a.begin(), a.end(), greater<int>());

	int A_score = 0, B_score = 0;
	for (int i = 0; i < N; i++) {
		if (i % 2 == 0) {
			A_score += a.at(i);
		} else {
			B_score += a.at(i);
		}
	}
	cout << A_score - B_score << endl;
}

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

#define LINE_BUF_SIZE 16
//#define N 100

int main(){

    int i,j,k;
    int max = 0;
    int count = 0;
    int A,B,N = 100;
    char line[LINE_BUF_SIZE];

    fgets(line,sizeof(line),stdin);
    sscanf(line,"%d %d", &A,&B);

    char **C = (char **)malloc( sizeof(char *) * N );   /*行数分{(char *)*N byte}だけのメモリを動的確保した、それへのポインタ*/

    /*ちょうど半分で色分け*/

    for(i=0;i<N;i++){
        C[i] = (char *)malloc( sizeof(char) * ( N + 1 ));   /*一行の文字列を格納するために動的確保したメモリへのポインタ*/
        for(j=0;j<N;j++){
            if(i < N / 2){
                C[i][j] = '.';
            }
            else{
                C[i][j] = '#';
            }
        }
        C[i][N] = '\0';
    }

    //printf("色分け完了\n");

    /*必要数だけブロックを配置*/

    int Line = 0,Colum = 0;

    for(i=1;i<A;i++){
        if(N-(2*Colum-1) > 1){
            C[N-2*Line-1][N-(2*Colum+1)] = '.';
            Colum += 1;
        }
        else{           /*一列が全て白黒のブロックで埋まった場合*/
            Colum = 0;
            Line += 1;
            C[N-2*Line-1][N-(2*Colum+1)] = '.';
            Colum += 1;
        }
    }

    Line = 0;
    Colum = 0;

    for(i=1;i<B;i++){
        if((2*Colum-1) < N-1){
            C[2*Line][2*Colum] = '#';
            Colum += 1;
        }
        else{           /*一列が全て白黒のブロックで埋まった場合*/
            Colum = 0;
            Line += 1;
            C[2*Line][2*Colum] = '#';
            Colum += 1;
        }
    }

    printf("%d %d", N,N);
    printf("\n");

    for(i=0;i<N;i++){
        printf("%s\n",C[i]);
    }

    return 0;

}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		long possession = 1000;
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] stock = new long[n];
		for (int i = 0; i < n; i++) {
			stock[i] = sc.nextLong();
		}
		for (int i = 0; i < stock.length - 1; i++) {
			long stocks = 0;
			//翌日が今よりも高かったら即購入
			//
			if(stock[i] < stock[i + 1]) {
				stocks = possession / stock[i];
				possession += (stock[i + 1] - stock[i])  * stocks;
			}
		}
		
		System.out.println(possession);
	}

}


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

const ll INF = 1LL << 60;

ll N, M;
vector<ll> a;

// 2で何回割り切れるか
ll f(ll x) {
    ll cnt = 0;
    while (x % 2 == 0) {
        x /= 2;
        cnt++;
    }
    
    return cnt;
}

// 最大公約数
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

// 最小公倍数
ll lcm(ll a, ll b) { return a / gcd(a,b) * b; }

int main() {
    cin >> N >> M;
    a.resize(N);
    rep(i, N) cin >> a[i];

    rep(i, N) a[i] /= 2;

    ll t = f(a[0]);

    for (int i = 0; i < N; i++) {
        ll b = f(a[i]);

        // 2の素因数の数が違う場合、ありえない
        if (t != b) {
            cout << 0 << endl;
            return 0;
        }

        a[i] <<= t;
    }
    M <<= t;

    // lcm を求める
    ll val = 1;
    for (int i = 0; i < N; i++) {
        val = lcm(val, a[i]);
    }

    // 計算 偶数は省く
    ll ans = ((M / val) + 1) / 2;
    cout << ans << endl;
}

Measured memory_bytes: 3972
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int s = scanner.nextInt();
		
		int m = s / 60;
		
		s = s % 60 ;
		
		int h = m / 60;
		
		m = m % 60 ;
		
		
		
		
		System.out.println(h + ":" + m + ":" + s);
	}
}


Measured memory_bytes: 26224
#include <stdio.h>

int n, s, count = 0,cur;
int digits[10] ;
int dataSet[50] ;

void dfs(int cur){
	if(cur == n){
		int sum = 0;
		for(int i = 0; i < n; i++) {sum += digits[i];}
		if(sum == s) {count++;}
		return;
	}
	for (int i = cur; i < 10; i++) {
		if (cur == 0) {
			digits[cur] = i;
	                dfs(cur+1);
	}
         else if(digits[cur-1] < i){
		digits[cur] = i;
                dfs(cur+1);
         }
	}
}

int main(void){
	int num = 0;
	while(scanf("%d %d",&n,&s)!= EOF){
		if(n == 0 && s == 0){
			break;
		}
		count = 0;
		dfs(0);
		dataSet[num] = count;
		num++;
              
	}
         for (int i = 0; i < num; i++) {printf("%d\n", dataSet[i]);}
	return 0;
}



Measured memory_bytes: 1920
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <iomanip>
#include <stdio.h>
#include <queue>
#include <string.h>
#include <algorithm>
#define endl '\n'
#define pb push_back
#define mp make_pair
#define LL long long
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define F first
#define S second
using namespace std;
typedef pair<int,int>pii;
int main(){
	string s;
	cin>>s;
	for(int i=1;i<=s.size();i++)cout<<'x';
	puts("");
	return 0;
}


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

int main(){
  string S;
  long long K;
  cin >> S >> K;
  for(int i = 0; i < min(K,(long long)S.length()); ++i){
    if(S[i] != '1'){
      cout << S[i] << endl;
      return 0;
    }
  }
  cout << 1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;
const ll mod = 1000000007;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}

int main() {
  ll n, m;
  cin >> n >> m;
  vector <vector <char>> v(n+2, vector <char> (m+2, '.'));
  rep(i, n) {
    rep(j, m) cin >> v.at(i+1).at(j+1);
  }
  string ans = "Yes";
  rep(i, n) {
    rep(j, m) {
      if (v.at(i+1).at(j+1) == '#') {
        if (v.at(i).at(j+1)=='.' && v.at(i+2).at(j+1)=='.' && v.at(i+1).at(j)=='.' && v.at(i+1).at(j+2)=='.') {
          ans = "No";
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define showall(obj) for(auto x:obj)cout<<x<<endl;
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
typedef vector<int> vint;
typedef vector<ll> vll;
const int inf = 100100100;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int n; cin>>n;
	ll bf;
	cin>>bf; 
	int max_cnt = 0, cur_cnt = 0;
	for(int i = 1; i<n; ++i){
		ll t; cin>>t;
		if(t<=bf)cur_cnt++;
		else cur_cnt = 0;
		max_cnt = max(max_cnt, cur_cnt);
		bf = t;
	}
	cout<<max_cnt<<endl; return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const ll LINF = LLONG_MAX;
const int INF = INT_MAX;
const double PI=acos(-1);
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; }

int main(){
    int x,y; cin>>x>>y;
    bool ok=false;
    rep(a,0,100){
        rep(b,0,100){
            if(a+b==x and 2*a+4*b==y){
                ok=true;
            }
        }
    }
    if(ok) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 3624
#include<iostream>
#include<vector>
#include<map>
#include<utility>
#include<set>
#include<functional>
#include<cmath>
#include<algorithm>
using namespace std;
using ll = long long;
using p = pair<ll,ll>;
const ll INF = (ll)1e9;
void a(){
    int h;
    int w;
    int n;
    cin >> h >> w >> n;
    int max = std::max(h,w);
    int min = std::min(h,w);

    for(int i=1;i<=min;i++){
        if(max*i>=n){
            cout << i;
            return;
        }
    }
    cout << 0;
}

void b(){
    int n;
    cin >> n;
    auto st=vector<p>(n,p(0,0));
    for(int i=0;i<n;i++){
        int x,l;
        cin >> x >> l;
        st[i] = make_pair(x+l,x-l);
    }
    sort(st.begin(),st.end());
    int ans=0,t=-INF;
    for(int i=0;i<n;i++){
        if(t<=st[i].second){
            ans++;
            t = st[i].first;   
        }
    }
    cout << ans;
}

void c(){
    ll n,k,s;
    cin >> n >> k >> s;
    for(int i=1;i<=k;i++){
        cout << s <<" ";
    }

    for(int i=k+1;i<=n;i++){
        cout << (s!=INF?INF:1) << " ";
    }
}
int main(){
    c();
    return 0;
}

Measured memory_bytes: 1280
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

class Main {
	public static void main(String[] args) throws Exception {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		String S=sc.next();
		String T=sc.next();
		int A=sc.nextInt();
		int B=sc.nextInt();
		String U=sc.next();
		if(S.equals(U))--A;
		else --B;
		System.out.println(A+" "+B);
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}


Measured memory_bytes: 23764
#include "bits/stdc++.h"

typedef long long ll;
using namespace std;


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

int maxDistance(int h, int w, vector<vector<char>> &S, int si, int sj) {
    // スタートが壁の場合
    if (S[si][sj] == '#') return 0;

    vector<vector<int> > dist(h, vector<int>(w, -1));
    dist[si][sj] = 0;
    queue<pair<int, int> > que;
    que.push(make_pair(si, sj));

    while (!que.empty()) {
        pair<int, int> current_pos = que.front(); que.pop();
        int i = current_pos.first;
        int j = current_pos.second;

        for (int direction = 0; direction < 4; ++direction) {
            int next_i = i + dx[direction];
            int next_j = j + dy[direction];
            // 迷路外
            if (next_i < 0 || next_i >= h || next_j < 0 || next_j >= w) continue;
            // 壁
            if (S[next_i][next_j] == '#') continue;

            // 未訪問
            if (dist[next_i][next_j] == -1) {
                que.push(make_pair(next_i, next_j));
                dist[next_i][next_j] = dist[i][j] + 1;
            }
        }
    }

    int maxDist = 0;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            maxDist = max(maxDist, dist[i][j]);
        }
    }
    return maxDist;
}

int main() {
    int h, w;
    cin >> h >> w;
    vector<vector<char>> S(h);
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            char s;
            cin >> s;
            S[i].push_back(s);
        }
    }

    int maxDist = 0;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            maxDist = max(maxDist, maxDistance(h, w, S, i, j));
        }
    }

    cout << maxDist;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int i, count, N, A[200];
	scanf("%d", &N);
	for (i = 0; i < N; i++) scanf("%d", &(A[i]));
	for (count = 0; ; count++) {
		for (i = 0; i < N; i++) {
			if (A[i] % 2 == 1) break;
		}
		if (i < N) break;
		else {
			for (i = 0; i < N; i++) A[i] /= 2;
		}
	}
	printf("%d\n", count);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 128
import math
n, m = map(int, input().split())
ans = 0

ans += min(n, m // 2)
m -= 2 * min(n, m // 2)
#
# if m >= 2*n:
#     ans += n
#     m -= 2*n
#
# else:
#     ans += m//2
#     m -= 2*m//2

ans += math.floor(m / 4)



print(ans)


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

int main(){
  int N;
  string S;
  cin >> N >> S;
  int ans =1;
  for(int i=0;i<N-1;i++){
    if(S.at(i)!=S.at(i+1)){
      ans++;
    }
  }
  cout << ans << endl;
  
  
}
      
    
      


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdio>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;

double R(double x,double y,double z,double w){
  return sqrt((x-z)*(x-z)+(y-w)*(y-w));
}

int main()
{
  int n;
  cin >> n;
  vector<double> x(n),y(n);
  rep(i,n){
    cin >> x[i] >> y[i];
  }

  double res = 100000.;
  rep(i,n){
    rep(j,n){
      if(i==j) continue;
      double p = (x[i]+x[j])/2;
      double q = (y[i]+y[j])/2;
      double r = R(x[i],y[i],x[j],y[j])/2;
      bool f = true;
      rep(k,n){
	if(R(p,q,x[k],y[k])>r){
	  f = false;
	  break;
	}
      }
      if(f){
	res = min(res,r);
      }
    }
  }

  rep(i,n){
    rep(j,n){
      if(i==j) continue;
      rep(k,n){
	if(i==k||j==k) continue;
	double p = ((y[k]-y[i])*(x[j]*x[j]+y[j]*y[j]-x[i]*x[i]-y[i]*y[i])-(y[j]-y[i])*(x[k]*x[k]+y[k]*y[k]-x[i]*x[i]-y[i]*y[i]))/(2*((y[k]-y[i])*(x[j]-x[i])-(y[j]-y[i])*(x[k]-x[i])));
	double q = ((x[k]-x[i])*(x[j]*x[j]+y[j]*y[j]-x[i]*x[i]-y[i]*y[i])-(x[j]-x[i])*(x[k]*x[k]+y[k]*y[k]-x[i]*x[i]-y[i]*y[i]))/(2*((x[k]-x[i])*(y[j]-y[i])-(x[j]-x[i])*(y[k]-y[i])));
	double r = sqrt((x[i]-p)*(x[i]-p)+(y[i]-q)*(y[i]-q));
	bool f = true;
	rep(k,n){
	  if(R(p,q,x[k],y[k])>r){
	    f = false;
	    break;
	  }
	}
	if(f){
	  res = min(res,r);
	}
      }
    }
  }

  printf("%.7f\n",res);
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <bitset>
#include <list>
#include <cstdio>
#include <stdio.h>
#include <string.h>
#include <cmath>

typedef long long ll;

using namespace std;

ll gcd(ll a, ll b)
{
    if((a%b) == 0) return b;
    else return gcd(b, a%b);
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    double h, a;
    cin >> h >> a;
    cout << ceil(h/a);
}


Measured memory_bytes: 256
/*input
2 2 4
0 0 2 2
2 0 0 1
0 2 1 2
1 1 2 1
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=805;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}

int h,w,q;
int pt=0;

vector<pii> v;

int get(int x,int y){
	if(y==0) return x;
	else if(x==h) return h+y;
	else if(y==w) return h+w+(h-x);
	else if(x==0) return h+w+h+(w-y);
	else return -1;
}
vector<int> st;
int main()
{
	IOS;
	cin>>h>>w>>q;
	while(q--){
		int a,b,c,d;
		cin>>a>>b>>c>>d;
		int L=get(a,b),R=get(c,d);

		if(L==-1||R==-1) continue;
		v.pb(MP(L,pt));
		v.pb(MP(R,pt));
		pt++;
	}
	sort(ALL(v));
	for(pii i:v){
		int cur=i.S;

		if(SZ(st)&&cur==st.back()) st.pop_back();
		else st.pb(cur);
	}
	if(SZ(st)) cout<<"NO\n";
	else cout<<"YES\n";
	return 0;
}


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

using namespace std;

int main(){
    int N, K;
    cin >> N >> K;
    double p = 0;
    for(int i=1; i<=N; ++i){
        int count = 0;
        int current = i;
        while(current<K){
            current *= 2;
            ++count;
        }
        p += pow(0.5, count) / N;
    }
    cout << setprecision(12) << p << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>

using namespace std;

const int MAX_N = 10005;

int prime[MAX_N];
bool is_prime[MAX_N];

int sieve(int n)
{
	int p = 0;
	for(int i=0;i<=n;i++){
		is_prime[i] = true;
	}
	is_prime[0] = is_prime[1] = false;
	for(int i=2;i<=n;i++){
		if(is_prime[i]){
			prime[p++] = i;
			for(int j=2*i;j<=n;j+=i){
				is_prime[j] = false;
			}
		}
	}
	return p;
}

int main()
{
	int n,p;
	p = sieve(10000);
	while(scanf("%d",&n) > 0){
		int cnt=0;
		for(int i=1;i<=n;i++){
			if(is_prime[i] == true){
				if(is_prime[n+1-i] == true){
					cnt++;
				}
			}
		}
		cout << cnt << "\n";
	}
}

Measured memory_bytes: 3136
import scala.io.StdIn
import scala.annotation.tailrec
import scala.collection.mutable.ListBuffer

object Main{
  def main(args: Array[String]){
    StdIn.readLine()
    val line = StdIn.readLine().split(" ").toList.map(_.toInt)

    println(line.sorted.mkString(" "))
    println(sSort(List(), line, 0))
  }

  @tailrec
  def sSort(sorted: List[Int], unsorted: List[Int], n: Int): Int={
    if(unsorted.length == 0) n
    else if(unsorted.sorted == unsorted) n
    else {
      val pos = unsorted.indexWhere(_ == unsorted.min)
      // unsorted????????????????°????????????¨0??????????????????0?????????sorted????????????unsorted??????0???????????????
      val swapped = unsorted.updated(0, unsorted(pos)).updated(pos, unsorted(0))

      if(pos == 0) sSort(sorted :+ unsorted.min, deleteOne(swapped, 0), n)
      else sSort(sorted :+ unsorted.min, deleteOne(swapped, 0), n+1)
    }
  }

  def deleteOne(list: List[Int], index: Int): List[Int] = {
    val buf = ListBuffer(list: _*)
    buf.remove(index)
    buf.toList
  }
}

Measured memory_bytes: 45348
#include "bits/stdc++.h"
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e18;

lint N, K, arr[100000];
lint sums[100001];
lint plsums[100001];
int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	cin >> N >> K;
	REP(i, N) {
		cin >> arr[i];
	}
	sums[0] = 0;
	plsums[0] = 0;
	REP(i, N) {
		sums[i + 1] = sums[i] + arr[i];
		if (arr[i] > 0) plsums[i + 1] = plsums[i] + arr[i];
		else plsums[i + 1] = plsums[i];
	}
	lint maxv = 0;
	REP(i, N - K + 1) {
		chmax(maxv, plsums[i] + plsums[N] - plsums[i + K]);
		chmax(maxv, plsums[i] + (sums[i + K] - sums[i]) + plsums[N] - plsums[i + K]);
	}
	cout << maxv << endl;
}


Measured memory_bytes: 5964
import sys
import math
input = sys.stdin.readline

s = int(input())
if s == 10**18:
    print(0, 0, 0, 10**9, 10**9, 0)
    sys.exit()
t = math.floor(math.sqrt(s))
if t*(t+1) < s:
    x1 = t+1
    y2 = t+1
else:
    x1 = t
    y2 = t+1
x2 = 1
y1 = x1*y2 - s

print(0, 0, x1, y1, x2, y2)

Measured memory_bytes: 3064
def vals(arr):
    even = True
    res = [[], []]
    tmp = []
    for e in arr:
        if e == "\"":
            even = not even
            res[even].append(tmp)
            tmp = []
            continue
        tmp.append(e)
    even = not even
    res[even].append(tmp)
    return res


while True:
    str1 = input()
    if str1 == ".":
        break
    a = vals(str1)
    b = vals(input())
    res = 0
    if len(a[0]) != len(b[0]) or len(a[1]) != len(b[1]) :
        res = 2
    else:
        for (x, y) in zip(a[0], b[0]):
            if x != y:
                res = 2
                break
    if res == 0:
        for (a, b) in zip(a[1], b[1]):
            if a != b:
                res += 1
                if res == 2:
                    break
    if res == 0:
        print("IDENTICAL")
    elif res == 1:
        print("CLOSE")
    else:
        print("DIFFERENT")



Measured memory_bytes: 5588
/******************** Beginning of Template **************************/
/************ ALL HEADER FILE ***********/
//#include<bits/stdc++.h>
#include <iostream>
using namespace std;

/************************************ ALL DEFINE ****************************************************/
#define FORS(i, j, k, step) for (int i=j; i<k; i+=step)
#define FOR(i, j, k) for (int i=j; i<k; i++)
#define RFORS(i, j, k, step) for (int i=j; i>=k; i-=step)
#define RFOR(i, j, k, step) for(int i=j; i>=k; i--)
#define REP(i, k) for(int i = (0); i < (k); i++ )
#define RREP(i, k) for(int i = j; i >= (k); i-- )

#define ALL(cont) cont.begin(), cont.end()
#define RALL(cont) cont.begin(), cont.end()
#define FOREACH(it, l) for(auto it=l.begin(); it != l.end(); it++)
#define mp make_pair
#define pb push_back
#define RESET(a, b) memset(a, b, sizeof(a))
#define INF (int)MAX_INT
#define EPS (int)1e-9
#define PI acos(-1)
#define MOD 1000000007
#define fango using
#define ganteng namespace
#define sekali std

/*********************************Debug DEFINE  ********************************/
#define TESTING
//#define FILE_INPUT
//#define FILE_OUTPUT
/*********************************END of Debug DEFINE  ********************************/

#ifdef TESTING
#define VALUE(x) cout << ">>>> The value of " << #x << " is " << x << "<<<<" << endl
#define NEWLINE cout << "---------------------------------------------" << endl
#define DUMP_STR cout << ">>>>FANGO IS THE MOST HANDSOME MANKIND IN THE ENTIRE WORLD<<<<" << endl;
#define DUMP_CHAR cout << " YO ";
#endif //TESTING_ON_CONSOLE



/************************************ END OF DEFINE ****************************************************/

/************************************ ALL TYPEDEF ****************************************************/
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<piii> viii;
typedef long long int32;
typedef unsigned long long uint32;
typedef long long int int64;
typedef unsigned long long int uint64;



/************************************ ALL DEFINE ****************************************************/

/************************************ END OF PREHEADER ***********************************************/



void solve() {

	string s;
	cin >> s;
	int f = 0;
	if (s[0] == s[1] && s[2] == s[3] && s[0] != s[2]) {
		f = 1;
	}
	else if (s[0] == s[2] && s[1] == s[3] && s[0] != s[1]) {
		f = 1;
	}
	else if (s[1] == s[2] && s[0] == s[3] && s[1] != s[3]) {
		f = 1;
	}
	else {
		f = 0;
	}
	if (f == 1) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
}

int main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

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

	int TC = 1;
	//cin >> TC;

	while (TC--) {

		solve();
	}
}

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

#define PI acos(-1)
#define int long long int
#define pb push_back
#define mp make_pair
#define pi pair<string, int>
#define pii pair<int, pi>
#define fir first
#define sec second
#define MAXN 100001
#define MAXL 20
#define mod 998244353

signed main()
{
  vector<int> v(5);
  for (int i = 0; i < 5; i++)
  {
    cin >> v[i];
    if (v[i] == 0)
      cout << i + 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 3592
def main():
    MOD = 10 ** 9 + 7

    s = input()
    n = len(s)

    acc_a = [0] * (n + 1)
    acc_c = [0] * (n + 1)
    acc_q = [0] * (n + 1)

    a = 0
    c = 0
    q = 0
    for i, char in enumerate(s, 1):
        if char == 'A':
            a += 1
        elif char == 'C':
            c += 1
        elif char == '?':
            q += 1
        acc_a[i] = a
        acc_c[i] = c
        acc_q[i] = q

    sq = [1]
    for _ in range(acc_q[n]):
        sq.append(sq[-1] * 3 % MOD)

    ans = 0
    qn = acc_q[n]
    for i, char in enumerate(s, 1):
        if char == 'B' or char == '?':
            is_q = int(char == '?')
            rq = acc_q[n] - acc_q[i]
            rc = acc_c[n] - acc_c[i]
            t = 0
            if qn - is_q >= 0:
                t += acc_a[i - 1] * rc * sq[acc_q[n] - is_q]
            if qn - 1 - is_q >= 0:
                t += acc_a[i - 1] * rq * sq[acc_q[n] - 1 - is_q]
                t += acc_q[i - 1] * rc * sq[acc_q[n] - 1 - is_q]
            if qn - 2 - is_q >= 0:
                t += acc_q[i - 1] * rq * sq[acc_q[n] - 2 - is_q]
            t %= MOD
            ans = (ans + t) % MOD
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 12660
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, int>;
using vpii = vector<pair<int, int>>;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define rep1(i, n) for (int i = 1; i < (int)n; i++)
const ll mod = 1e9 + 7;
const ll inf = 1e12;
const double pi = 3.141592;
const int di[4] = {1, -1, 0, 0};
const int dj[4] = {0, 0, 1, -1};

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> dp(n + 1);
    dp[1] = 1;
    int sixpow = 6, ninepow = 9;
    while(sixpow <= n){
        dp[sixpow] = 1;
        sixpow *= 6;
    }
    while (ninepow <= n)
    {
        dp[ninepow] = 1;
        ninepow *= 9;
    }
    auto f = [](int n, int r) {
        int m = 1;
        while (m <= n)
        {
            m *= r;
        }
        return m / r;
    };
    rep(i, n)
    {
        dp[i + 1] = min({dp[i], dp[i + 1 - f(i + 1, 6)], dp[i + 1 - f(i + 1, 9)]}) + 1;
    }
    cout << dp[n] << "\n";
    return 0;
}

Measured memory_bytes: 640
//
//  main.cpp
//  3
//
//  Created by RISHAV SINGH MEHTA on 01/12/19.
//  Copyright © 2019 RISHAV SINGH MEHTA. All rights reserved.
//

#include <iostream>
using namespace std;

int main(int argc, const char * argv[]) {
    // insert code here...
    int i,j,k,l,n;
    cin>>n;
    
    k=n/100;
    l=k*5;
    i=n%100;
    if ( i <= l ) {
        cout<<1<<endl;
    }else{
        cout<<0<<endl;
    }
    
    
    return 0;
}


Measured memory_bytes: 256
import math

s = input().split()

a = int(s[0])
b = int(s[1])
h = int(s[2])
m = int(s[3])

h = (h + float(m / 60)) * 30

m = m * 6

kaku = max(h,m) - min(h,m)

result = math.sqrt(a**2 + b**2 - 2 * a * b * math.cos(math.radians(kaku)))

print(result)

Measured memory_bytes: 9516
#include <stdio.h>
#define N 10001
#define MAX(a,b) ((a>b)?(a):(b))

int main(void){
	int a[N];
	int i,j,n,k,sum;
	int max=-1;
	for(i=0;i<N;i++) a[i]=0;

	scanf("%d",&n);
	while(n--){
		scanf("%d",&k);
		max=MAX(max,k);
		a[k]++;
	}

	for(i=0;i<=max;i++){
		if(max!=i){
			for(j=0;j<a[i];j++){
				printf("%d ",i);
			}
		}
		else{
			for(j=0;j<a[i];j++){
				if(j!=a[i]-1) printf("%d ",i);
				else printf("%d",i);
			}
		}
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 644
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
using Pair = System.Tuple<int, int>;
using Edge = System.Tuple<int, int, long>;
//using Debug;
//using static System.Globalization.CultureInfo;

class Program
{
    static void Main(string[] args)
    {
        var str = ReadLine().ToCharArray();
        var dp = new long[str.Length + 1, 4];
        var abc = "ABC";
        dp[0, 0] = 1;
        for (var i = 1; i <= str.Length; i++)
            for (var j = 0; j < 4; j++)
            {
                if (j == 3)
                {
                    dp[i, j] = (dp[i, j] + (str[i - 1] == '?' ? 3 : 1) * dp[i - 1, j]) % Input.MOD;
                    continue;
                }
                if (abc[j] == str[i - 1] || str[i - 1] == '?')
                    dp[i, j + 1] = (dp[i, j + 1] + dp[i - 1, j]) % Input.MOD;
                if (str[i - 1] == '?') dp[i, j] = (dp[i, j] + 3 * dp[i - 1, j]) % Input.MOD;
                else dp[i, j] = (dp[i, j] + dp[i - 1, j]) % Input.MOD;
            }
        WriteLine(dp[str.Length, 3]);
    }
}

public class Input
{
    public static string read => ReadLine();
    public  static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse);
    public  static int num => ToInt32(read);
    public static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse);
    public  static long numL => ToInt64(read);
    public static char[][] gred(int h) 
        => Enumerable.Repeat(0, h).Select(v => read.ToCharArray()).ToArray();
    public static int[][] twodim(int num)
        => Enumerable.Repeat(0, num).Select(v => ar).ToArray();
    public static long[][] twodimL(int num)
        => Enumerable.Repeat(0, num).Select(v => arL).ToArray();
    public const long Inf = (long)1e18/2;
    public const double eps = 1e-6;
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}


Measured memory_bytes: 14560
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
#define MAX 1000000
typedef long long ll;


int main(){
  int countA=0,countC=0,hantei=1;
  string s;
  cin>>s;
  if(s[0]!='A') hantei=0;
  for(int i=1;i<s.size();i++){
    if(s[i]=='C'){
      if(i==1 || i==s.size()-1){
        hantei=0;
        break;
      }
      countC++;
      continue;
    }
    int temp=s[i]-'a';
    if(temp<0 || temp>25) hantei=0;
  }
  if(countC!=1) hantei=0;
  if(hantei) cout<<"AC"<<endl;
  else cout<<"WA"<<endl;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<string.h> 
int main()
{
	char s[10005],a;
	int n,l;
	scanf("%d",&n);
	getchar();
	scanf("%s",s);
	l=strlen(s);
	for(int i=0;i<l;i++)
	{
		a=s[i]+n;
		if(a>'Z')a=a-'Z'+'A'-1;
		printf("%c",a);
	}
	printf("\n");
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>

using namespace std;

typedef struct {
	int x, y;
} Point;

vector<Point> mon[5];
int dp[5][1024];

int dist(Point i, Point j)
{
	return (abs(i.x - j.x) + abs(i.y - j.y));
}

int main()
{
	static char str[1024][1024];
	int W, H;
	Point S, G;
	
	while (1){
		scanf("%d %d", &W, &H);
		
		if (W + H == 0){
			break;
		}
		
		for (int i = 0; i < H; i++){
			scanf("%s", str[i]);
		}
		
		for (int i = 0; i < 5; i++){
			mon[i].clear();
		}
		
		for (int i = 0; i < H; i++){
			for (int j = 0; j < W; j++){
				if (str[i][j] == 'S'){
					S.x = j;
					S.y = i;
				}
				if (str[i][j] == 'G'){
					G.x = j;
					G.y = i;
				}
				if (1 <= str[i][j] - '0' && str[i][j] - '0' <= 5){
					Point t;
					t.x = j;
					t.y = i;
					mon[str[i][j] - '0' - 1].push_back(t);
				}
			}
		}
		
		int acre = 1 << 30, adist = 1 << 30;
		for (int i = 0; i < 5; i++){
			for (int j = 0; j < mon[(i + 1) % 5].size(); j++){
				dp[(i + 1) % 5][j] = dist(S, mon[(i + 1) % 5][j]);
			}
			for (int j = i + 2; j < i + 5; j++){
				int t = j % 5;
				int s = (t + 4) % 5;
				for (int k = 0; k < mon[t].size(); k++){
					dp[t][k] = 1 << 30;
				}
				for (int k = 0; k < mon[t].size(); k++){
					for (int l = 0; l < mon[s].size(); l++){
						dp[t][k] = min(dp[t][k], dp[s][l] + dist(mon[s][l], mon[t][k]));
					}
				}
			}
			int a = 1 << 30;
			for (int j = 0; j < mon[(i + 4) % 5].size(); j++){
				a = min(a, dp[(i + 4) % 5][j] + dist(mon[(i + 4) % 5][j], G));
			}
			if (a < adist){
				adist = a;
				acre = i + 1;
			}
		}
		if (acre != 1 << 30){
			printf("%d %d\n", acre, adist);
		}
		else {
			printf("NA\n");
		}
	}
	
	return (0);
}

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

const int N_MAX=100000;
const int V_MAX=100000;
typedef pair<int, int> P;

int main() {
  int N;
  int a[N_MAX];
  int c1[V_MAX + 1] = {0};
  int c2[V_MAX + 1] = {0};
  P b1[N_MAX];
  P b2[N_MAX];

  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> a[i];
  }
  
  int m = N / 2;
  for (int i = 0; i < m; ++i) {
    ++c1[a[i * 2]];
    ++c2[a[i * 2 + 1]];
  }

  int j1 = 0;
  for (int i = 1; i <= V_MAX; ++i) {
    if (c1[i] > 0) {
      b1[j1++] = P(c1[i], i);
    }
  }
  sort(b1, b1 + j1, greater<P>());
  int j2 = 0;
  for (int i = 1; i <= V_MAX; ++i) {
    if (c2[i] > 0) {
      b2[j2++] = P(c2[i], i);
    }
  }
  sort(b2, b2 + j2, greater<P>());

  if (b1[0].second != b2[0].second) {
    cout << N - b1[0].first - b2[0].first << endl;
    return 0;
  }

  if (j1 == 1 && j2 == 1) {
    cout << m << endl;
    return 0;
  }

  if (j1 == 1) {
    cout << m - b2[1].first << endl;
    return 0;
  }

  if (j2 == 1) {
    cout << m - b1[1].first << endl;
    return 0;
  }

  int k1 = b1[0].first + b2[1].first;
  int k2 = b2[0].first + b1[1].first;
  cout << N - max(k1, k2) << endl;

  return 0;
}


Measured memory_bytes: 2944
function Main(input) {
    input = input.trim().split(" ");
    var A = parseInt(input[0],10);
    var B = parseInt(input[1],10);
    var output;

    if(A <= 5){
        output = 0;
    }
    else if(A <= 12){
        output = B/2;
    }
    else{
        output = B;
    }
    console.log(output);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

Measured memory_bytes: 256
# coding: utf-8
n, q = map(int, input().split())
s = input()
lr = [list(map(int, input().split())) for _ in range(q)]
T = [0]
cnt = 0
for i in range(n-1):
    if s[i] == "A" and s[i+1] == "C":
        cnt += 1
    T.append(cnt)
for l, r in lr:
    print(T[r-1] - T[l-1])

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

int main()
{
    int i,ch[27]={0},flag=0;
    char s[27];
    gets(s);
    for(i=0;i<strlen(s);i++)
    {
        if(ch[s[i]-'a']==0) ch[s[i]-'a']=1;
        else
        {
            flag=1;
            break;
        }
    }
    if(flag==1) printf("no");
    else printf("yes");
    return 0;
}


Measured memory_bytes: 128
import math

a,b,h,m = map(int, input().split())

theta_h = (60 * h + m)/2
theta_m = 6 * m
the = abs(theta_h -theta_m)
the = min(the, 360 - the)

r = (a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(the))) ** (1/2)
print(r)

Measured memory_bytes: 9504
import java.util.Scanner;
public class Main{
  public static void main(String [] args){
    Scanner sc=new Scanner(System.in);
    int count2=1;
    for(int count=1; count==count2; count++){
      int x=sc.nextInt(), y=sc.nextInt();
      int max=x, min=x;
      if((x==0)&&(y==0)){
        break;
      }
      else{
        if(y<min){
          min=y;
        }
        else{
          max=y;
        }
      }
      System.out.println(min+" "+max);
      count2++;
    }
  }
}


Measured memory_bytes: 35668
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  ll x[N], y[N], h[N];
  FOR(i,0,N) {
    cin >> x[i] >> y[i] >> h[i];
  }
  FOR(X,0,101) {
    FOR(Y,0,101) {
      set<ll> H;
      FOR(i,0,N) {
        if(h[i] == 0) continue;
        H.insert(h[i] + abs(x[i] - X) + abs(y[i] - Y));
      }
      if(H.size() == 1) {
        for(ll ans : H) {
          bool ok = true;
          FOR(j,0,N) {
            if(h[j] != max(0LL, ans - abs(x[j] - X) - abs(y[j] - Y))) ok = false;
          }
          if(ok) {
            cout << X << " " << Y << " " << ans << endl;
            return 0;
          }
        }
      }
    }
  }
}

Measured memory_bytes: 256
void main() {
	auto ip = readAs!(int[]), H = ip[0], W = ip[1];
	
	auto a = readMatrix!char(H, W);

	string[] tmp;
	foreach(i; a) {
		if(i != '.'.repeat(W).array) {
			tmp ~= i.to!string;
		}
	}
	string[] res;
	foreach(i; 0..W) {
		bool flag = true;
		foreach(j; 0..tmp.length) {
			if(tmp[j][i] == '.') continue;
			flag = false;
		}
		if(!flag) {
			string tmp2;
			foreach(k; 0..tmp.length) {
				tmp2 ~= tmp[k][i];
			}
			res ~= tmp2;
		}
	}
	foreach(i; 0..res[0].length) {
		foreach(j; 0..res.length) {
			write(res[j][i]);
		}
		writeln;
	}
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 380
n,m = map(int, input().split())
sc = [list(map(int,input().split())) for _ in range(m)]

ans = [-1] * n
for s,c in sc:
    if(ans[s-1] != -1):
        if(ans[s-1] != c):
            print(-1)
            exit()

    if(n>1)&(s==1)&(c==0):
        print(-1)
        exit()
    ans[s-1] = c

ans_num = 0
for i,num in enumerate(ans[::-1]):
    if(num == -1):
        if(i==n-1)&(n!=1):
            ans_num += 1*10**(i)
        continue

    ans_num += num * 10**(i)

print(ans_num)

Measured memory_bytes: 38500
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define repd(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>; // グラフ型
using pint = pair<int, int>;

int main()
{
    int N;
    cin >> N;
    rep2(i, 1, 10)
    {

        rep2(j, 1, 10)
        {
            if (i * j == N)
            {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using std::ifstream;
#define fri(i,n) 			for(int i = 0 ; i < n;++i) 
#define jri(j,k,n) 		for(int j = k ; j >= n;j--) 
#define swapnumsxor 	a ^= b; b ^= a; a ^= b
#define inp(i) 				cin >> i 
#define inp2(i,j) 		cin >> i >> j  
#define inp3(i,j,k) 	cin >> i >> j >> k
#define oup(i) 				cout << i << "\n"
#define oup2(i,j) 		cout << i << " "<<j<< "\n"
#define oup3(i,j,k) 	cout << i << " "<< j << " "<<k<< "\n"
#define MOD 1000000007
#define rmdup 				std::sort(str.begin(), str.end());str.erase(std::unique(str.begin(), str.end()), str.end());
typedef long long int lli;
typedef unsigned long long int ulli;
#define oo(x) cout << #x <<  " = " << x << "\n";
#define pb 		emplace_back
#define mp 		make_pair 
#define MAXN 	1000000
const int INF = 0x3f3f3f3f;
using std::cin;
using std::cout;
using std::vector;
using std::string;
using std::map;
using std::min;
using std::abs;
using std::sort;
using std::__gcd;
using std::ios_base;
unsigned lcm(int a, int b) { return (a / __gcd(a, b) * b); }

int main()
{ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
		// ifstream in("input.txt");
		int p,q,r , sum ;
    inp3(p,q,r);
    sum = p+q+r;
    cout << min( {abs(sum-p) , abs(sum-q),abs(sum-r) }); 
    return 0;
}


Measured memory_bytes: 256