akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;;
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin >>n;
  string s;cin >> s;
  ll q;cin >> q;
  vector<set<ll>> v(26);
  rep(i,s.size()){
    ll num = s[i]-'a';
    v[num].insert(i);
  }
  rep(j,q){
    ll op;cin >> op;
    if(op==1){
      ll i;cin >> i;i--;
      char c;cin >> c;
      ll num = s[i]-'a';
      v[num].erase(i);
      num = c - 'a';
      v[num].insert(i);
      s[i] = c;
    }else{
      ll l,r;cin >> l >> r;l--;r--;
      ll ans = 0;
      rep(i,26){
        auto it = v[i].lower_bound(l);
        if(it!=v[i].end() && *it <= r)ans++;
      }
      cout << ans << endl;
    }
  }
}

Measured memory_bytes: 24220
#include <algorithm>
#include <iostream>

using namespace std;

int main()
{
	int A[3];
	cin >> A[0] >> A[1] >> A[2];
	sort(A, A + 3);
	cout << A[0] << " " << A[1] << " " << A[2] << endl;
	return 0;
}



Measured memory_bytes: 3112
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
P = np.array(lr())
Q = P.copy()
Q.sort()
result = P == Q
if N - result.sum() <= 2:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 12500
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, l; cin >> n >> l;
    vector<string> v;
    string s;
    for (int i = 0; i < n; i++)
    {
        cin >> s;
        v.push_back(s);
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < n; i++)
    {
        cout << v[i];
    }
    cout << endl;
    
}

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

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

    if(num % 2 == 0){
        cout << num << endl;
    }

    else{
        for(int i = 1; ; i++){
            if((num * i) % 2 == 0) {
                cout << num * i << endl;
                break;
            }
        }
    }
}

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

bool IsPrime(int n)
{
    /* n = 2 の場合 */
    if (n == 2) return true;

    /* n > 2 の偶数の場合 */
    if (n % 2 == 0) return false;

    /* n > 2 の奇数の場合 */
    int i = 3;
    while (i <= sqrt(n)){
        if (n % i == 0) return false;
        i += 2;
    }
    return true;
}

int main()
{
    int n;
    cin >> n;
    int ans = 0;
    rep(i,n){
        int num; cin >> num;
        if (IsPrime(num) == true) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3104
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define sz(a) int(a.size())
#define clr(a) memset(a,0,sizeof(a))
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
const int inf=1e9;
const ll Inf=1e18;
const int mod=0;
int gi() {
    int x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
template<typename T> bool chkmax(T &a,T b) { return a<b?a=b,1:0; };
template<typename T> bool chkmin(T &a,T b) { return a>b?a=b,1:0; };
int add(int a,int b) { return a+b>=mod?a+b-mod:a+b; }
int sub(int a,int b) { return a-b<0?a-b+mod:a-b; }
void inc(int &a,int b) { a=(a+b>=mod?a+b-mod:a+b); }
void dec(int &a,int b) { a=(a-b<0?a-b+mod:a-b); }
int a,b,c;
int main() {
    cin>>a>>b>>c;
    cout<<b+min(a+b+1,c);
    return 0;
}


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

using namespace std;

const long long INF=1e18l+2;
const int MOD = 1e9+7;

ifstream f("1.in");

int n;
int dp[Nmax][3]; // dp[i][j]= numarul de mod de colorare cu ultimul nod de culoarea i
vector <int> v[Nmax];

void dfs(int x, int tt)
{
    dp[x][1]=dp[x][0]=1;
    for (int i = 0, l=v[x].size(); i < l; i++)
    {
        int y=v[x][i];
        if(y == tt) continue;
        dfs(y, x);
        dp[x][1]=(1ll*dp[x][1]*dp[y][0])%MOD;
        dp[x][0]=(1ll*dp[x][0]*(dp[y][1]+dp[y][0]))%MOD;
    }
}


int main()
{
    cin >> n;
    for (int i = 2, x, y; i <= n; i++)
    {
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    dfs(1, 0);
    cout << (dp[1][0]+dp[1][1])%MOD;
    return 0;
}


Measured memory_bytes: 13824
N=int(input())
A=list(map(int,input().split()))
B=[]
C=[]
for i in range(N):
    if A[i]<=0:
        B.append(-A[i])
    else:
        C.append(A[i])
if len(B)%2==0:
       print(sum(B)+sum(C))
else:
        if C==[]:
            print(sum(B)+sum(C)-2*min(B))
        else:
            print(sum(B)+sum(C)-2*min(min(B),min(C)))

Measured memory_bytes: 64752
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
const LL MOD = 1000000007LL;
bool dp[5001][5001];
int A[5000];
int N, K;
bool check(int x) {
	memset(dp, 0, sizeof(dp));
	dp[0][0] = 1;
	int idx = 0;
	for (int i = 0; i < N - 1; i++) {
		if (idx == x) idx++;
		for (int j = 0; j <= K; j++) {
			dp[i + 1][j] |= dp[i][j];
			if (j + A[idx] <= K) dp[i + 1][j + A[idx]] |= dp[i][j];
		}
		idx++;
	}
	for (int i = max(K - A[x], 0); i < K; i++) {
		if (dp[N - 1][i]) return 1;
	}
	return 0;
}
int main() {
	cin >> N >> K;
	for (int i = 0; i < N; i++) cin >> A[i];
	sort(A, A + N);
	int l = -1, r = N - 1;
	while (r - l > 1) {
		int m = (l + r) / 2;
		if (check(m)) r = m;
		else l = m;
	}
	if (check(r)) cout << r << endl;
	else cout << N << endl;
}

Measured memory_bytes: 24704
import java.math.BigInteger;
import java.util.stream.IntStream;

public class Main {
    private static java.util.Scanner scanner = new java.util.Scanner(System.in);

    public static void main(String[] args) {
        System.out.println(lcm(IntStream.range(0, scanner.nextInt()).mapToLong(i -> scanner.nextLong()).toArray()));
    }

    public static long lcm(long... array) {
        BigInteger j = BigInteger.valueOf(array[0]), temp;
        for (int i = 1; i < array.length; i++)
            j = j.multiply(temp = BigInteger.valueOf(array[i])).divide(j.gcd(temp));
        return j.longValue();
    }
}

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

int main(void){
	char s[10],sign[9];
	int a[10],l,i,j;
	scanf("%s",s);
	l = strlen(s);
	long box = 0;
	long res = 0;
	for(i=0;i<l;i++){
		a[i] = s[i] - '0';
	}
	for(i=0;i < (1<<(l-1));i++){
		for(j=0;j<l-1;j++){
			if((i>>j)&1){
				sign[j] = '+';
			}else{
				sign[j] = ' ';
			}
		}
		for(j=0;j<l;j++){
			box += a[j];
			if(j < l-1){
				if(sign[j] == ' '){
					box *= 10;
				}else{
					res += box;
					box = 0;
				}
			}else{
				res += box;
				box = 0;
			}
		}
	}
	printf("%ld\n",res);
	return 0;
}

Measured memory_bytes: 128
def solve(N, M, PYs):
    Ys = {i + 1: 1 for i in range(N)}
    ret = {}
    for p, y in sorted(PYs, key=lambda x: x[1]):
        ret[(p, y)] = "{:06d}{:06d}".format(p, Ys[p])
        Ys[p] += 1
    return [ret[(p, y)] for (p, y) in PYs]

if __name__ == "__main__":
    N, M = tuple(map(int, input().split(" ")))
    PYs = [tuple(map(int, input().split(" "))) for _ in range(M)]
    print("\n".join(solve(N, M, PYs)))


Measured memory_bytes: 49936
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 998244353;
const int inf = (1 << 30) - 1;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;
ll A[MAX_N], B[MAX_N];

void solve() {
	cin >> N;
	rep(i, 0, N) cin >> A[i] >> B[i];
	ll ans = 1;
	rep(i, 0, N) MUL(ans, 2);
	ADD(ans, mod - N);
	ADD(ans, mod - 1);

	rep(i, 0, N) {
		rep(j, i + 1, N) {
			ll tmp = 1;
			rep(k, j + 1, N) {
				// B[k] = (B[j] - B[i]) / (A[j] - A[i]) (A[k] - A[i]) + B[i];
				if((B[k] - B[i]) * (A[j] - A[i]) == (B[j] - B[i]) * (A[k] - A[i])) {
					MUL(tmp, 2);
				}
			}
			ADD(ans, mod - tmp);
		}
	}
	cout << ans << "\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K;
  cin >> N >> K;
 
  int count;
  if ((N-1) % (K-1) == 0){
    count = (N-1) / (K-1);
  }
  else {
    count = (N-1) / (K-1) + 1;
  }
  cout << count << endl;
}
  
  

Measured memory_bytes: 3612
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
typedef long long ll;
using vi=vector<ll>;
template<class T> bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}

const int INF=1001001001;

ll num(ll x,ll y){
  return max(x,y)-min(x,y); // 絶対値
}
void solve() {
  ll n,k; cin>>n>>k;
  vi h(n),dp(n);
  rep(i,n) cin>>h[i];
  dp[0]=0;
  REP(i,1,k) dp[i]=num(h[0],h[i]);
  if(n>k){
    REP(i,k,n){
      dp[i]=INF;
      REP(j,1,k+1){
        chmin(dp[i],dp[i-j]+num(h[i-j],h[i]));
      }
      // dp[i]=min(dp[i-2]+num(h[i-2],h[i]),dp[i-1]+num(h[i-1],h[i]));
    }
  }
  cout<<dp[n-1]<<endl;
}

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


Measured memory_bytes: 1792
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define INF 1LL << 62
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i, m) for (int i = 0; i < m; i++)
#define FOR(i, n, m) for (int i = n; i < m; i++)
#define ALL(v) v.begin(),v.end() 
#define pb push_back
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main(){
  REP(i, 3){
    string s;
    cin >> s;
    cout << s[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
#include <math.h>
#include <cassert>
#include <unordered_map>
#include <chrono>
#include <random>
#include <ctime>
#include <complex>
using namespace std;
#pragma warning(disable : 4996)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const ld PI = acosl(-1.0);
const ll MOD = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
#ifdef _DEBUG
	freopen("input1.txt", "r", stdin);
	freopen("output2.txt", "w", stdout);
#endif
	srand(time(0));
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++)cin >> a[i];
	int ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < i; j++) {
			for (int k = 0; k < j; k++) {
				if (a[i] + a[j] > a[k] && a[i] + a[k] > a[j] && a[j] + a[k] > a[i] && a[i] != a[j] && a[j] != a[k] && a[k] != a[i]) {
					ans++;
				}
			}
		}
	}
	cout << ans;
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

#define SUM(vec) accumulate(all(vec),0LL) // 配列の中身を全部足す
template<typename T>void print(T&& x){cout<<x<<endl;}// 改行付き出力
ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
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){return c - '0';}

// TODO: write
int main() { 
  int n;cin>>n;
  string s,t;cin>>s>>t;
  string a = s+t;
  int tmp = 0;
  
  rep(i,n+1){
    if(s.substr(n-i,i) == t.substr(0,i))tmp = i;
  }
  print(n*2-tmp);
  return 0;
}

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

int main()
{
    ll n,m,t,sum=0;
    cin>>n>>m;
    ll arr[m]; 
    for(ll i=0;i<m;i++)
        cin>>arr[i];
    for(ll i=0;i<m;i++)
        sum+=arr[i];
    t= n-sum;
    if(t<0)
        cout<<"-1";
    else
        cout<<t;
   return 0; 
}

Measured memory_bytes: 3704
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main(int argc,char *argv[]){
  int h;
  int w;
  char mokuhyou[1000001];
  int tate=0;
  int sharp=0;
  char isrd = 0;
  long ans[100000];
  int i = 0,j=0;
  int goukei=0;
  short int n;
  long long a,b;
  long long kotae=0;
  long long loopc=0;
  char op = 0;
  fgets(mokuhyou,100000,stdin);
  sscanf(mokuhyou,"%lld %c %lld",&a,&n,&b);
  if(n == '+'){
    kotae = a + b;
  }
  if(n == '-'){
    kotae = a - b;
  }
  printf("%lld",kotae);
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int a,b;
    cin>>a>>b;
    a-=b;
    cout<<max(a,0)<<endl;

    return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

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

int main() {
	int w, h, n; scanf("%d%d%d", &w, &h, &n);
	std::vector<std::vector<int>> vec(h);
	for(int i = 0; i < n; i++) {
		int x, y; scanf("%d%d", &x, &y);

		vec[y].push_back(x);
	}

	int ans = 1 << 30, tmp = 0;
	for(int i = h - 1; i >= 0; i--) {
		ans = std::min(ans, i + tmp);
		sort(begin(vec[i]), end(vec[i]));
		if(!vec[i].empty()) tmp = std::max(tmp, vec[i].back());
	}
	printf("%d\n", ans);
	return 0;
}



Measured memory_bytes: 8340
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
int n,k;
cin >> n >> k;
int ans = (n-1)*(k-1);
cout << ans << endl;
return 0;
}


Measured memory_bytes: 384
a =[11,31,41,61,71,101,131,151,181,191,211,241,251,271,311,401,431,461,911,941,1021,1031,1051,1061,1091,1151,1171,1181,1201,1231,1291,1741,1801,1811,1831,1861,1901,1931,1951,2011,2111,2141,2221,2311,2351,2411,2441,2731,2791,2801,2851,2861,2971,3001,3011,3041,3061,3121,3181,3191]
n = int(input())
for i in range(n):
	print(a[i],end = " ")

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

char X[1002] , Y[1002];
int C[1001][1001], cnt;

int LCSLength() {
    int m = strlen(X), n = strlen(Y), i, j;
    cnt = 0;
    
    for (i = 0; i <= m; i++) {
        C[i][0] = 0;
    }
    
    for (i = 0; i <= n; i++) {
        C[0][i] = 0;
    }
    
    for (i = 1; i <= m; i++) {
        for (j = 1; j <= n; j++) {
            if (X[i-1] == Y[j-1]) C[i][j] = C[i-1][j-1] + 1;
            else if (C[i-1][j] >= C[i][j-1]) C[i][j] = C[i-1][j];
            else C[i][j] = C[i][j-1];
        }
    }
    return C[m][n];
}

int main() {
    int n, i;
    
    scanf("%d", &n);
    
    for(i = 0; i < n; i++) {
        scanf("%s", X);
        scanf("%s", Y);
        printf("%d\n", LCSLength());
    }
    
    return 0;
}


Measured memory_bytes: 5720
#include <iostream>
#include <stdio.h>
#include <cmath>

using namespace std;

int main(){
    int a, b, h, m;
    double dist, h_deg, m_deg, deg;

    cin >> a >> b >> h >> m;

    h_deg = h * 30.0 + m * 0.5;
    m_deg = m * 6.0;
    dist = sqrt((double)(a*a + b*b) - (double)(2*a*b*cos(abs(h_deg - m_deg) * M_PI / 180)));

    printf("%.10f\n", dist);

    return 0;
}

Measured memory_bytes: 4092
#include<bits/stdc++.h>
using namespace std;
int n,k,a[10005],b[10005];
int main(){
	scanf("%d %d",&n,&k);
	if(k>(n-1)*(n-2)/2){puts("-1");return 0;}
	if(n==2){
		if(k==0){printf("1\n1 2\n");return 0;}
		else {puts("-1");return 0;}
	}
	if(n==3){
		if(k==1){printf("2\n1 2\n1 3\n");return 0;}
		else {printf("3\n1 2\n1 3\n2 3\n");return 0;}
	}
	int m=n-1;k=(n-1)*(n-2)/2-k;
	for(int i=1;i<n;++i){
		a[i]=1;b[i]=i+1;
	}
	int l=2,r=3;
	for(int i=1;i<=k;++i){
		++m;a[m]=l;b[m]=r;
		r++;
		if(r>n){
			l++;r=l+1;
		}
	}
	printf("%d\n",m);
	for(int i=1;i<=m;++i){
		printf("%d %d\n",a[i],b[i]);
	}
}

Measured memory_bytes: 256
n = int(input())
d = {}
astr = list(map(int, input().split()))
for i in astr:
    d[i] = d.get(i, 0) + 1

def f(n):
    return n * (n - 1) // 2

s = sum(f(i)  for i in d.values())


for i in astr:
    t = d[i]
    print(s - f(t) + f(t-1))





Measured memory_bytes: 26140
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

bool isPal(string s) { 
	int n=s.size();
	for (int i=0; i<n/2; i++)
		if (s[i]!=s[n-1-i])
			return false;
	return true;
}

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string s; cin>>s;
	int n=s.size(), x=(n-1)/2;
	cout<< (isPal(s.substr(0,x))&&isPal(s)&&isPal(s.substr(x+1))?"Yes":"No")<<endl;
	return 0;
}


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

using namespace std;

using ll = long long;
constexpr ll MAX = 1e6;

class UnionFind {
    int v[MAX];
    int deep[MAX];

  public:
    UnionFind() {
        for(int i = 0; i < MAX; i++) {
            v[i] = i;
            deep[i] = 0;
        }
    }

    int root(int x) {
        if(v[x] == x)
            return x;
        else
            return v[x] = root(v[x]);
    }

    bool same(int x, int y) {
        return (root(x) == root(y));
    }

    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if(deep[x] > deep[y]) {
            v[y] = x;
        } else {
            if(deep[x] == deep[y]) deep[y]++;
            v[x] = y;
        }
        return;
    }
};

int main() {
    ll n,i;
    cin >> n;
    vector<pair<pair<ll, ll>,ll>> v(n);
    priority_queue<pair<ll, pair<ll, ll>>,vector<pair<ll,pair<ll,ll>>>,greater<>> pq;

    for(i = 0; i < n;i++){
        cin >> v[i].first.first >> v[i].first.second;
        v[i].second = i;
    }
    sort(v.begin(), v.end());
    for(i = 1; i < n;i++){
        pq.push({v[i].first.first - v[i - 1].first.first, {v[i].second, v[i-1].second}});
    }
    sort(v.begin(), v.end(), [](const auto &a, const auto &b) {
        return a.first.second < b.first.second;
    });
    for(i = 1; i < n; i++) {
        pq.push({v[i].first.second - v[i - 1].first.second, {v[i].second, v[i-1].second}});
    }

    UnionFind uf;
    ll ret = 0;
    while(!pq.empty()) {
        auto x = pq.top();
        pq.pop();
        if(!uf.same(x.second.first,x.second.second)){
            uf.unite(x.second.first, x.second.second);
            ret += x.first;
        }
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 16492
#pragma region header
#include <bits/stdc++.h>
using namespace std;

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;
#pragma endregion

#pragma region const
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#pragma endregion

#pragma region util
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}
#pragma endregion

#pragma region init
struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

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

	int ans = 0;
	FOR(i, 1, N + 1)
	{
		if (i % 2 == 0)
			continue;

		int count = 0;
		FOR(j, 1, i+1)
		{
			if (i%j == 0)
				count++;
		}

		if (count == 8)
			ans++;
	}

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


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
print(" ".join(map(str,A)))
for i in range(1,N):
    tmp = A[i]
    j = i-1
    while j >= 0 and A[j] > tmp:
        A[j+1] = A[j]
        j += -1
    A[j+1] = tmp
    print(" ".join(map(str,A)))


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

int main() {
  int N,M,K,i,j;
  string str = "No";
  
  cin >> N >> M >> K;
  for(i=0;i<=N;i++) {
    for(j=0;j<=M;j++) {
      int ans;
      ans = i*M+j*N-2*i*j;
      if(ans==K) {
        str = "Yes";
        break;
      }
    }
  }
  cout << str << endl;
  return 0;
}     

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	long long N, A, B, C, D, E;
	cin >> N >> A >> B >> C >> D >> E;
	cout << max({ (N - 1) / A, (N - 1) / B, (N - 1) / C, (N - 1) / D, (N - 1) / E }) + 5 << endl;
	return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include<bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll h,w,d[1000][1000],x[]={1,-1,0,0},y[]={0,0,1,-1},ans;
string s[1000];
queue<P>que;
int main(void){
    cin>>h>>w;
    for(int i=0;i<h;i++){
        cin>>s[i];
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(s[i][j]=='#'){
                que.push({i,j});
                d[i][j]=1;
            }
        }
    }
    while(!que.empty()){
        P q=que.front();
        que.pop();
        for(int i=0;i<4;i++){
            ll X=q.F+x[i],Y=q.S+y[i];
            if(0<=X&&X<h&&0<=Y&&Y<w){
                if(d[X][Y]!=0)continue;
                d[X][Y]=d[q.F][q.S]+1;
                que.push({X,Y});
            }
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            ans=max(ans,d[i][j]-1);
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 25524
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> T gcd(T a, T b){return !b?a:gcd(b,a%b);}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
mt19937 R(chrono::system_clock().now().time_since_epoch().count());
const int N = 1<<10|3;
int a[N][N],n,m,f[N];
void solve(int n){
	rep(i,0,(1<<n)-1)rep(j,0,(1<<n)-1)a[i][j]=f[i&j];
}
int main() {
	read(n);read(m);
	rep(i,1,N-1)f[i]=f[i>>1]^(i&1);
	solve(max(n,m));
	rep(i,1,(1<<n)-1)rep(j,1,(1<<m)-1){
		int res=a[i][j];
		if(i-1>=0)res^=a[i-1][j];
		if(j-1>=0)res^=a[i][j-1];
		if(i-1>=0&&j-1>=0)res^=a[i-1][j-1];
		printf("%d",res);
		if(j==(1<<m)-1)puts("");
	}
//	cerr<<c[0]<<' '<<c[1]<<endl;
	return 0;
}


Measured memory_bytes: 5376
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int x = sc.nextInt();
        int left = 0;
        int right = 0;
        for(int i = 0; i < m; i++){
            int tmp = sc.nextInt();
            if(tmp < x){
                left++;
            }else{
                right++;
            }
        }
        System.out.println(Math.min(left,right));
    }
}


Measured memory_bytes: 21076
def gcd(p, q):
    if p % q == 0:
        return q
    else:
        return gcd(q, p % q)


def lcm(p, q):
    return p * q // gcd(p, q)


a, b, c, d = list(map(int, input().split()))
a_ = a - 1
bn = b - (b // c + b // d - b // lcm(c, d))
an = a_ - (a_ // c + a_ // d - a_ // lcm(c, d))
n = bn - an
print(n)

Measured memory_bytes: 38488
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define ll long long
using namespace std;
signed main() {
	int x[8] = { 1,3,5,7,8,10,12 }, y[5] = { 4,6,9,11 };
	int a, b;
	cin >> a >> b;
	if (a == 2 || b == 2)puts("No");
	else {
		for(int i = 0; i < 8; i++) { if (x[i] == a)a = -1; if (x[i] == b)b = -1; }
		for (int i = 0; i < 5; i++) { if (y[i] == a)a = -2; if (y[i] == b)b = -2; }
		if (a == b)puts("Yes");
		else puts("No");
	}
	getchar(); getchar(); return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define IOS cin.tie(0); ios::sync_with_stdio(false)
const int INF = 1e9;
using namespace std;
int gcd(int a,int b){return b ? gcd(b,a%b) : a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}

main() {
    int N,M; cin >> N >> M;
    string S,T; cin >> S >> T;
    int a=gcd(N,M);
    bool can = true;
    rep(i,a){
        if(S[i*(N/a)]!=T[i*(M/a)]){
            can = false; break;
        } 
    }
    if(can) cout << lcm(N,M) << endl;
    else cout << -1 << endl;
}

Measured memory_bytes: 512
/// kAAzuki Hoshino
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define inf 1000000000
#define mod 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple

signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int a,b,c;
cin >> a >> b >> c;
cout << min(b/a, c) << endl;

return 0;}
///....


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mx 10000007
#define mod 1000000007
#define forn for(int i=0;i<n;i++)
#define vecti vector<int>
#define pb push_back
#define sti stack<int>
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll int n;
    cin>>n;
    cout<<n*n*n<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstring>
#define FIN freopen("inputs.txt", "r", stdin)
using namespace std;
typedef pair<int, int> P;
int n = 0;
int d[10][10];
int loOrder(int n){
    return n % 10;
}
int hiOrder(int n){
    int res;
    while(n!=0){
        res = n %10;
        n /= 10;
    }
    return res;
}
int getLen(int n){
    return (to_string(n).size());
}
int exp(int p){
    int res = 1;
    for (int i = 0; i < p; i++)
        res *= 10;
    return res;
}
int main(){
//FIN;
    int ans = 0;
    cin>>n;
    memset(d, 0, sizeof(d));
    for (int i = 1; i <= n; i++)
    {
        d[hiOrder(i)][loOrder(i)]++;
    }
    for (int i = 0; i < 10; i++)
    {
        for (int j = 0; j < 10; j++)
        {
            ans += d[i][j]*d[j][i];
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

static const double eps = 10e-6;

char stage[100][100];
int costTable[100][100];

void bfs(int w,int h){
	const int t[][2] = {{1,0},{0,1},{-1,0},{0,-1}};
	int sx,sy;
	for(int y=0;y<h;y++){
		for(int x=0;x<w;x++){
			if(stage[y][x] == '&'){
				sx = x;
				sy = y;
				goto found;
			}
		}
	}
found:;

	memset(costTable,0x3,sizeof(costTable));
	queue<P> que;
	que.push(P(sx,sy));

	costTable[sy][sx] = 0;

	while(!que.empty()){
		int x = que.front().first;
		int y = que.front().second;
		que.pop();	

		for(int i=0;i<4;i++){
			int dx = x + t[i][0];
			int dy = y + t[i][1];
			if(dx < 0 || dx >= w || dy < 0 || dy >= h) continue;

			int cost = costTable[y][x] + ((stage[dy][dx] == '#' && stage[y][x] != '#') ? 1 : 0);
			if(costTable[dy][dx] <= cost) continue;

			if(cost == 2){
				int a = 3;
			}
			costTable[dy][dx] = cost;
			que.push(P(dx,dy));
		}
	}
}

int seekExtWall(int w,int h){
	int res = 0x3333;

	for(int x=0;x<w;x++){
		res = min(res,costTable[0][x]);
	}

	for(int x=0;x<w;x++){
		res = min(res,costTable[h-1][x]);
	}

	for(int y=0;y<h;y++){
		res = min(res,costTable[y][0]);
	}

	for(int y=0;y<h;y++){
		res = min(res,costTable[y][w-1]);
	}

	return res;
}

void printCostTable(int w,int h){
	for(int y=0;y<h;y++){
		for(int x=0;x<w;x++){
			cout << costTable[y][x];
		}
		cout << endl;
	}
}

int main(){
	int w,h;
	while(~scanf("%d %d",&w,&h)){
		if(w==0 && h==0) break;
		for(int y=0;y<h;y++){
			char buf[128];
			scanf("%s",buf);
			for(int x=0;x<w;x++){
				stage[y][x] = buf[x];
			}
		}

		bfs(w,h);
		cout << seekExtWall(w,h) << endl;
		//printCostTable(w,h);
	}
}

Measured memory_bytes: 0
using System;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();
            string[] str =new string[N];
            for(int i = 0; i <N; i++)
            {
                str[i] = s.Substring(i, 1);
            }
            int rnum = 0;
            int bnum = 0;
            foreach (var item in str)
            {
                if(item == "R")
                {
                    rnum++;
                }
                else
                {
                    bnum++;
                }
            }
            if(rnum > bnum)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 11092
n, m = map(int, input().split())
h = list(map(int, input().split()))
ls = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    ls[a].append(b)
    ls[b].append(a)

ans = 0
for i, l in enumerate(ls):
    if len(l) == 0:
        ans += 1
    else:
        ok = True
        for j in l:
            if h[i] <= h[j]:
                ok = False
                break
        if ok:
            ans += 1
print(ans)


Measured memory_bytes: 94612
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(){
        string s;
        cin>>s;
        ll flag=0;
        ll l=s.size();

        for(ll i=0;i<l;++i){
            if(s[i]=='A'){
                flag++;
                break;
            }
        }
        for(ll i=0;i<l;++i){
            if(s[i]=='B'){
                flag++;
                break;
            }
        }
        if(flag==2){
            cout<<"Yes"<<endl;
        }else{
            cout<<"No"<<endl;
        }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,a,n) for(ll i=(a); i<(ll)(n); i++)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(v) (v).begin(), (v).end()

int main(void) {
    int N,K;
    cin >> N >> K;
    vector<ll> x(N), y(N);
    vector<ll> xary, yary;
    for (int i=0; i<N; i++) {
        cin >> x[i] >> y[i];
        xary.push_back(x[i]);
        yary.push_back(y[i]);
    }

    sort(ALLOF(xary));
    sort(ALLOF(yary));

    ll ans = 1LL * (xary[N-1] - xary[0]) * (yary[N-1] - yary[0]);

    for (int xi=0; xi<N; xi++)
        for (int xj=xi+1; xj<N; xj++)
            for (int yi=0; yi<N; yi++)
                for (int yj=yi+1; yj<N; yj++) {
                    int num = 0;
                    ll ux = xary[xi], dx = xary[xj];
                    ll uy = yary[yi], dy = yary[yj];
                    for (int i=0; i<N; i++)
                        if (ux <= x[i] and x[i] <= dx and uy <= y[i] and y[i] <= dy) num++;
                    if (num >= K) ans = min(ans, 1LL * (dx - ux) * (dy - uy));
                }

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


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

void Main()
{
  ll n,k; cin >> n >> k;
  vector<ll> p(n);
  rep(i,n) cin >> p[i];
  ll sum = 0, maxsum = 0;
  rep(i,k) {
    sum += p[i];
    maxsum += p[i];
  }
  ll maxind = k-1;
  for (int i = k; i < n; i++) {
    sum -= p[i-k];
    sum += p[i];
    if (sum > maxsum) {
      maxsum = sum;
      maxind = i;
    }
  }
  double ans = 0;
  for (int i = maxind-k+1; i <= maxind; i++) {
    ans += (double)(p[i] + (ll)1) / (ll)2;
  }
  cout << ans << endl;
}

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

Measured memory_bytes: 4708
s = [1,2,3,4,5,6,7,8,9,10,11,12,13]
h = [1,2,3,4,5,6,7,8,9,10,11,12,13]
c = [1,2,3,4,5,6,7,8,9,10,11,12,13]
d = [1,2,3,4,5,6,7,8,9,10,11,12,13]

n = gets.to_i

for i in 1..n
  mark, num = gets.split
  mark = mark.to_s
  num = num.to_i
    if mark == "S"
      s.delete(num)
    elsif mark == "H"
      h.delete(num)
    elsif mark == "C"
      c.delete(num)
    elsif mark == "D"
      d.delete(num)
    end
end

s.each { |x|
    puts "S #{x}"
}
h.each { |x|
    puts "H #{x}"
}
c.each { |x|
    puts "C #{x}"
}
d.each { |x|
    puts "D #{x}"
}

Measured memory_bytes: 8608
N = int(input())
H = list(map(int,input().split()))
if N == 1:
    print('Yes')
    exit()
if N == 2:
    if H[0] - H[1] > 1:
        print('No')
        exit()
    else:
        print('Yes')
        exit()
for i in range(N-1,0,-1):
    if H[i] < H[i-1]:
        H[i-1] -= 1
    if H[i] < H[i-1]:
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 14396
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}

int main(){
  long n;
  cin >> n;
  int a[n];
  for(int i = 0; i < n; i++) cin >> a[i];

  vector<int> odd(1010000,0);
  vector<int> even(1010000,0);
  vector<pair<int,int> > pairEven;
  vector<pair<int,int> > pairOdd;


  // count even odd
  for(int i = 0; i < n; i++){
    if(i % 2)   odd[a[i]] ++;
    else        even[a[i]] ++;
  }
  //cout << even[1] << ' ' << odd[1] << ' '<<even[2] << ' '<<odd[2];
  //int -> pair
  for(int i = 0; i < odd.size() ; i++) {
    if(odd[i] != 0){
      pair<int,int> x;
      x.first = odd[i];
      x.second = i;
      pairOdd.push_back(x);
    }
  }

  for(int i = 0; i < even.size(); i++) {
    if(even[i] != 0){
      pair<int,int> x;
      x.first = even[i];
      x.second = i;
      pairEven.push_back(x);
    }
  }
  pair<int,int> x;
  x.first = 0;
  x.second = 0;
  pairOdd.push_back(x);
  pairEven.push_back(x);
  // out even max odd
  sort(pairEven.begin(),pairEven.end(),greater<pair<int,int>>());
  sort(pairOdd.begin(),pairOdd.end(),greater<pair<int,int>>());

  // == 多く登場するものを出力
  int ans ;
  if(pairEven[0].second == pairOdd[0].second){
    ans = min(n - pairEven[0].first - pairOdd[1].first, n - pairEven[1].first - pairOdd[0].first);
  }else ans = n - pairEven[0].first - pairOdd[0].first;

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


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

using namespace std;

#define lli long long int

lli a[100005],dp[100005];

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


Measured memory_bytes: 1792
#include<stdio.h>
int main(void) 
{
  int a,b;
  scanf("%d %d",&a,&b);
  if(a>b){
    printf("a > b\n");
  }else if(a<b){
    printf("a < b\n");
  }else{
    printf("a == b\n");
  }
  return 0;
}

Measured memory_bytes: 580
N, X = map(int, raw_input().split())
a,p=[1],[1] 
for i in range(N):
	a.append(a[i] * 2 + 3)
	p.append(p[i] * 2 + 1)
def f(N,X):
	if N == 0:
		return 0 if X <= 0 else 1
	elif X <= 1 + a[N-1]:
		return f(N-1, X-1)
	else:
		return p[N-1] + 1 + f(N-1, X-2-a[N-1])
print(f(N, X))

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

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

using namespace std;

int main(){
	string s; cin>>s;
	int ans=0;
	for(char c:s) ans=(ans+c-'0')%9;
	cout<<(ans==0?"Yes":"No")<<'\n';
	return 0;
}


Measured memory_bytes: 3716
#pragma target("avx")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define rep(i,b,e) for(ll i=b; i<e; i++)
#define be(vec) vec.begin(),vec.end()
#define print(vec) for(auto &i:vec)fprintf(stderr,"%ld ",i);puts("");
#define scan(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
	ll a, b;
	scanf("%ld %ld", &a, &b);
	ll ans = 0, l = b-a+1;
	if(a%2) ans ^= a, l--;
	if(b%2==0) ans ^= b, l--;
	ans ^= l/2%2;
	printf("%ld\n", ans);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define PI 3.14159265358979
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
// using Graph = vector<vector<Edge>>;
using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

const int MAX = 410;
ll numb = 0, numw = 0;
bool seen[MAX][MAX];

void dfs(int y, int x, int &H, int &W, vector<string> &S)
{
  seen[y][x] = true;
  if (S[y][x] == '#')
    numb++;
  else
    numw++;

  for (int i = 0; i < 4; i++)
  {
    int ny = y + dy[i];
    int nx = x + dx[i];
    if (ny < 0 || ny >= H || nx < 0 || nx >= W)
      continue;
    if (S[y][x] == S[ny][nx])
      continue; // 隣接しているマスが同じ色だったら分断されている．
    if (seen[ny][nx])
      continue;
    dfs(ny, nx, H, W, S);
  }
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  for (auto &it : S)
    cin >> it;
  ll ans = 0;
  for (int i = 0; i < H; i++)
  {
    for (int j = 0; j < W; j++)
    {
      if (S[i][j] == '.')
        continue;
      if (seen[i][j])
        continue;
      numb = numw = 0; // 0で初期化
      dfs(i, j, H, W, S);
      ans += numb * numw;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 20608
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }

//答え決め打ってニブタンでO(N^2logN)を狙う
//答えとなりうるのは0~n/2のいずれかニブタンかけるのは0~nでいい
ll ans,n;string s;
void solve(ll a,ll b){
    if(a>b) return;
    //mは部分文字列の長さ以下O(N^2)でチェック
    ll m=(a+b)/2;
    bool f=false;
    map<string ,int> mp;
    for(int i=0;i+m<=n;i++){
        string tmp=s.substr(i,m);
        if(mp.count(tmp)){
            if(mp[tmp]+m<=i) f=true;
        }
        else mp[tmp]=i;
    }
    if(f){
        ans=max(ans,m);
        solve(m+1,b);
    }
    else{
        solve(a,m-1);
    }
}
int main(){
    cin>>n;
    cin>>s;
    rep(i,n) s+="-";
    solve(0,n/2+1);
    cout<<ans<<endl;
    return 0;
}

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

int main(){
 int n,k,v,u;
  cin>>n;

  int V[100][100]; //隣接リスト
  int cnt[100]; //各点においてどこまでみたかの把握
  int d[100];
  int f[100];
  int time=1;
  int l=0;
  int come[100]; //その点はどこからきたかの把握

  //初期化
  for(int i=0;i<100;i++){
    for(int j=0;j<100;j++){
      V[i][j]=0;
      cnt[j]=0;
      d[j]=0;
      f[j]=0;
      come[j]=0;
    }
  }
  //グラフ情報の読み込み
 int  m=0;
  for(int i=0;i<n;i++){
    cin>>u;
    cin>>k;
    for(int j=0;j<k;j++){
      cin>>v;
      V[u-1][m]=v;
if(u==v) V[u-1][m]=0;  //自己ループを除く
      m++;
    }
    m=0;
  }


  //スタートは0
 d[0]=1;
 time++;
int start=0;
come[0]=-1;
  while(1){

    if(time==2*n+1) break;
    //先がありかつそこは探索終了していない

if(d[V[l][cnt[l]]-1]!=0 &&   f[   V [ V[l][cnt[l]] -1]  [ cnt[V[l][cnt[l]]-1]-1 ] -1  ]==0 ){

if(V[l][cnt[l]+1]==0){
      if(d[l]==0) d[l]=time;
       f[l]=time;
      l=come[l];
      time++;
}else{
cnt[l]++;
}

    }else if(V[l][cnt[l]]!=0 && f[V[l][cnt[l]]-1]==0 ){ 
     
      if(d[V[l][cnt[l]]-1]==0) d[V[l][cnt[l]]-1]=time;

   come[V[l][cnt[l]]-1]=l;
      cnt[l]++;
      l=V[l][cnt[l]-1]-1; 

      time++;
//if(V[l][cnt[l]]==l) time--;

      //先がないまたはさきが探索終了している
    }else{

if(V[l][cnt[l]+1]==0){
      if(d[l]==0) d[l]=time;
       f[l]=time;
      l=come[l];
      time++;
}else{
cnt[l]++;
}

    }

if(l==-1){
time--;
 f[start]=time;
  time++;
for(int i=0;i<n;i++){
if(d[i]==0){
 l=i;
come[i]=-1;
start=i;
d[i]=time;
time++;
break;
}
}
}


  }
  /*
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
    cout<<V[i][j]<<" ";
    if(j==n-1) cout<<endl;
  }
  }
  */
  //出力
  for(int i=0;i<n;i++){

    cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
    }


  return 0;
}


Measured memory_bytes: 3140
n = int(input())
a = list(map(int, input().split()))

def two(n):
	count = 0
	while n%2 == 0:
		n = n/2
		count += 1
	return count
	
l = []
for i in range(n):
	l.append(two(a[i]))
	
print(sum(l))

Measured memory_bytes: 4148
#include <iostream>
#include <cmath>

int N, total, avg, arr[100];

void solve() {
    std::cin >> N;
    avg = 0;
    total = 0;
    for (int i=0; i<N; ++i) 
        std::cin >> arr[i];
    for (int i=0; i<N; ++i) 
        avg += arr[i];
    avg = round((double)avg/(double)N);
    for (int i=0; i<N; ++i) {
        total += pow((arr[i]-avg), 2);
    }
    
    std::cout << total << std::endl;
}

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


Measured memory_bytes: 256