akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

#define MOD 1000000007
#define ll long long
#define pb push_back
#define st first
#define N 200005
#define nd second
#define ii pair<int,int>
#define fr freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

ll pw(ll b,ll e){
	if(!e) return 1;
	ll t=pw(b,e/2);
	t=t*t%MOD;
	if(e&1)
		return t*b%MOD;
	else return t;
}

ll fac[2000000];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	//fr
	int x,y;
	cin>>x>>y;
	int n=(2*x-y)/3;
	int m=(2*y-x)/3;
	if(2*x<y || 2*y<x || (x+y)%3)return cout<<0,0;

	fac[0]=1;
	for(int i=1;i<=n+m;i++)
		fac[i]=(i*fac[i-1])%MOD;
	cout<<(fac[n+m]*pw(fac[n],MOD-2)%MOD)*pw(fac[m],MOD-2)%MOD;
}


Measured memory_bytes: 6400
#include <iostream>
#include <cstdio>
#include <stack>
#include <queue>

#define N 128

int main(void) {
	while(1) {
		int n;
		int s[N];
		int sum = 0, max, min, point;
		scanf("%d", &n);
		if(n == 0) break;
		for(int i = 0; i < n; i++) {
			scanf("%d", &s[i]);
		}
		max = min = s[0];
		for(int i = 0; i < n; i++) {
			sum += s[i];
			if(s[i] > max) max = s[i];
			if(s[i] < min) min = s[i];
		}
		point = (sum - max - min) / (n - 2);
		printf("%d\n", point);
	}
	return 0;
}

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


int main()
{
	string a;
	cin >> a;
	int b = 0;
	for (int i = 0; i < a.size(); i++) {

		if (a[i] == 'o') {
			b++;
		}
	}
	cout << 700 + (b * 100) << endl;
}



Measured memory_bytes: 3588
fun main(args: Array<String>?): Unit {
    while(true){
        val (math, greedy, geometry, dp, graph, other) = readLine()!!.trim().split(' ').map(String::toInt).let{ if (it.all { it == 0 }) return else it}
        val mathGame = math + dp
        val algo = greedy + graph
        val write = geometry + other
        println((0 .. listOf(2, mathGame, algo, write).min()!!).map{i ->
            i + (mathGame - i) / 3 + (algo - i) / 3 + (write - i) / 3
        }.max()!!)
    }
}
operator fun <T> List<T>.component6(): T {return this[5]}


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

#define ll long long
#define MAXV 10000000007
using namespace std;

int main(){

    int n; cin >> n;
    vector<ll> L(n);
    ll sum = 0;
    ll x = 0;
    for(int i=0; i<n; i++){
        cin >> L[i];
        sum += L[i];
    }

    ll result = MAXV;
    for(int i=0; i<n; i++){
        x += L[i];
        if(i+1 < n) result = min(result, abs(sum - 2*x));
    }

    cout << result << endl;

    return 0;
}


Measured memory_bytes: 1792
class RollingHash:
    def __init__(self, s: list, base: int = 1007, mod: int = 10**9 + 7):
        self.s = s
        self.n = len(s)
        self.base = base
        self.mod = mod

        # preprocess
        self.h_cum = [0] * (self.n + 1)  # h_cum[i] = (hash of s[:i])
        self.b_pow = [1] * (self.n + 1)  # b_pow[i] = base ** i
        for i in range(self.n):
            self.h_cum[i + 1] = (self.h_cum[i] * base + s[i]) % mod
            self.b_pow[i + 1] = (self.b_pow[i] * base) % mod

    def get_hash(self, l: int, r: int) -> int:
        # get hash value of the substring s[l:r]
        hash_val = self.h_cum[r] - self.h_cum[l] * self.b_pow[r - l] % self.mod
        if hash_val < 0:
            hash_val += self.mod
        return hash_val


n = int(input())
a = tuple(map(int, input().split()))
b = tuple(map(int, input().split()))

a_xor = [a[i % n] ^ a[(i + 1) % n] for i in range(n * 2)]
b_xor = [b[i % n] ^ b[(i + 1) % n] for i in range(n * 2)]

a_xor_rh = RollingHash(a_xor)
b_xor_rh = RollingHash(b_xor)

b_hash = b_xor_rh.get_hash(0, n)
for k in range(n):
    if a_xor_rh.get_hash(k, k + n) == b_hash:
        x = a[k] ^ b[0]
        print(k, x)


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

int main(){
  string S;
  cin >> S;
  
  int N = S.size();
  int res = 0;
  for (int i = 0; i < N; i++){
    if (i % 2 == S[i] - '0'){
      res++;
    }
  }
  
  cout << min(res, N - res)<<endl;
  
  return 0;
}

Measured memory_bytes: 768
#include<stdio.h>
#include<stdlib.h>
#define N 2000

int n,A[N];

int solve(int,int);


int main(){
  int m,q,i;

  while(1){
    scanf("%d",&n);
    if(n<=20) break;
  }
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
      }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&m);
    if(m<1||m>2000) exit(2);
    if(solve(0,m)==1) printf("yes\n");
    else printf("no\n");
  }
  return 0;
}


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

  return res;
 
}



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

int main(){
  int N;
  cin >> N;
  vector<string> S(N);
  for(int i=0; i<N; i++) cin >> S.at(i);
  map<string, int> M;
  for(int i=0; i<N; i++){
    if(M.count(S.at(i))) M.at(S.at(i))++;
    else M[S.at(i)] = 1;
  }
  int max = 0;
  for(pair<string, int> p : M){
    if(p.second > max) max = p.second;
  }
  vector<string> dic;
  for(pair<string, int> p : M){
    if(p.second == max) dic.push_back(p.first);
  }
  sort(dic.begin(), dic.end());
  for(string v : dic){
    cout << v << endl;
  }
}

Measured memory_bytes: 28788
#pragma GCC optimize("Ofast")
#include <cstring>
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
typedef long long ll;

int main() {
    string S, s;

    cin >> S;

    s = S.substr(1, 1);

    if(s=="B") {
        cout << "ARC";
    } else if(s=="R") {
        cout << "ABC";
    }
}

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

int main(void)
{
	int max = 0;
	int N, K; cin >> N >> K;
	vector<long long int> h(N);
	for (int i = 0; i < N; i++)cin >> h[i];
	sort(h.begin(), h.end());
	long long int ans = h[N - 1] - h[0];
	for (int i = 0; i <= N - K; i++) {
		long long int diff = h[i + K - 1] - h[i];
		if (ans > diff)ans = diff;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <math.h>
#include <string>
#include <algorithm>
#include <ctype.h>
#include <vector>
#include <numeric>
#include <map>
#include <queue>
#include <deque>
#include <bitset>
using namespace std;

#define ll long long int
#define rep(i, a, n) for (int i = a; i < n; i++)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vii vector<vector<int>>
#define vll vector<ll>
#define vllll vector<vector<ll>>
#define ALL(a) (a).begin(), (a).end()
#define sort_v(a) sort(a.begin(), a.end())
#define fi first
#define se second

void print(bool c)
{
    if (c)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

void Print(bool c)
{
    if (c)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}

ll gcdll(ll a, ll b)
{
    while (1)
    {
        if (a < b)
            swap(a, b);
        if (b == 0)
            break;
        a %= b;
    }
    return a;
}

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

bool cmp(const pii &a, const pii &b)
{
    if (a.second != b.second)
        return a.second < b.second;
    return a.first < b.first;
}

ll calc(ll n, ll a, ll b)
{
    string tmp = to_string(n);
    return a * n + b * tmp.size();
}

int main()
{
    string s, t;
    cin >> s;
    ll cnt = 0, ans = 0;
    rep(i, 0, s.size())
    {
        if (i != s.size() - 1 && s[i] == 'B' && s[i + 1] == 'C')
        {
            t += 'D';
            i++;
        }
        else
            t += s[i];
    }
    rep(i, 0, t.size())
    {
        if (t[i] == 'A')
            cnt++;
        else if (t[i] == 'D')
            ans += cnt;
        else
            cnt = 0;
    }
    cout << ans << endl;
}


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

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

use std::collections::BinaryHeap;

fn main() {
    let n: usize = read();
    let mut bh: BinaryHeap<i64> = BinaryHeap::new();

    for _ in 0..n {
        let a: i64 = read();
        bh.push(a);
    }

    let mut maxv = bh.pop().unwrap();
    let mut ans = maxv;

    let m = n - 2;
    if m % 2 == 0 {
        for _ in 0..m / 2 {
            ans += bh.pop().unwrap() * 2;
        }
    } else {
        for _ in 0..(m - 1) / 2 {
            ans += bh.pop().unwrap() * 2;
        }
        ans += bh.pop().unwrap()
    }
    println!("{}", ans);
}


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

int main() {
  string S;
  cin >> S;
  int N = S.size(), cnt = 0;
  for (int i = 0; i < N; i++) if (S.at(i) == '0' + i % 2) cnt++;
  cout << min(cnt, N - cnt) << "\n";
}

Measured memory_bytes: 512
//#include<bits/stdc++.h>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0)
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
const double pi = acos(-1);
typedef long long ll;
ll arr[1000000];
int main()
{
	fast;
	ll n,s=0,i,m,ans=0;
	m=1000000007;
	cin>>n;
	
	for(i=0;i<n;i++)
	{
		cin>>arr[i];
		s+=arr[i];
		s%=m;
	}
	for(i=0;i<n;i++)
	{
		s-=arr[i];
		if(s<0)s+=m;
		ans+=(arr[i]*s);
		ans%=m;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 5212
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int N;
int a[105000];

int main() {
    //cout.precision(10);
    cin >> N;
    for(int i = 1; i <= N; i++) {
        cin >> a[i];
    }
    if(N % 3 != 0) {
        for(int i = 1; i <= N; i++) {
            if(a[i] != 0) {
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
        return 0;
    }
    set<int> st;
    map<int, int> mp;
    for(int i = 1; i <= N; i++) {
        st.insert(a[i]);
        mp[a[i]]++;
    }
    if(st.size() > 3) {
        cout << "No" << endl;
        return 0;
    }
    vector<int> v;
    for(auto itr = st.begin(); itr != st.end(); itr++) {
        while(mp[*itr] > 0) {
            if(mp[*itr] % (N / 3) != 0) {
                cout << "No" << endl;
                return 0;
            }
            mp[*itr] -= N / 3;
            v.push_back(*itr);
        }
    }
    cerr << v[0] << " " << v[1] << " " << v[2] << endl;
    if((v[0] ^ v[1]) == v[2]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 7808
def main():
  n,k=map(int,input().split())
  x=list(map(int,input().split()))
  ans=pow(10,10)
  for i in range(0,n-k+1):
    if x[i]*x[i+k-1]>=0:
      ans=min(ans,max(abs(x[i+k-1]),abs(x[i])))
    else:
      ans=min(ans,min(abs(x[i])+abs(x[i]-x[i+k-1]),abs(x[i+k-1])+abs(x[i]-x[i+k-1])))
  print(ans)
if __name__=='__main__':
  main()

Measured memory_bytes: 14664
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
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 INF=1e10;
int MOD=1e9+7;
signed main(){
  int a,b,c;
  cin>>a>>b>>c;
  bool e=0;
  for(int i=b;i<=c;i++){
    if(i%a==0)
      e=1;
      }
  if(e)
    cout<<"OK";
  else
    cout<<"NG";
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
    
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
    
#define int long long
#define double long double
    
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
    
#define ff first
#define ss second
#define mp make_pair
         
#define pb push_back
#define endl "\n" 
         
#define f(i,l,r) for(int i=l;i<=r;i++)
#define rf(i,r,l) for(int i=r;i>=l;i--)    

#define bp __builtin_popcountll
#define inf 1e15
    
const int N=1e5+5;
const int M=1e9+7;
void solve()
{
	int n;
	cin>>n;
	string s;
	cin>>s;
	vector<int> v[10];
	for(int i=0;i<n;i++)
	{
		v[s[i]-'0'].pb(i);
	}
	int ans=0;
	for(int i=0;i<=999;i++)
	{
		string pp=to_string(i);
		while(pp.size()<3)
		{
			pp='0'+pp;
		}
		int curr=-1;
		for(int j=0;j<3;j++)
		{
			int f=pp[j]-'0';
			curr++;
			curr=lower_bound(all(v[f]),curr)-v[f].begin();
			if(curr==v[f].size())
			{
				curr=n;
				break;
			}
			curr=v[f][curr];
		}
		if(curr<n){
			ans++;
		} 
	}
	cout<<ans;
}
signed main()  
{
	FAST
    int t=1;
    // cin>>t;
    for(int tc=1;tc<=t;tc++)
    {
    	// cout<<"Case #"<<tc<<": ";
    	solve();
    }
}


Measured memory_bytes: 768
package main

import (
        "errors"
        "fmt"
        "strconv"
)

func main() {
        var s string
        fmt.Scan(&s)
        nums := make([]int, 4)
        for i := 0; i < 4; i++ {
                nums[i], _ = strconv.Atoi(s[i : i+1])
        }
        exp, _ := dfs(nums[0], nums[1:len(nums)])
        fmt.Printf("%d%s\n", nums[0], exp)
}
func dfs(sum int, rests []int) (exp string, err error) {
        if len(rests) == 0 {
                if sum != 7 {
                        return "", errors.New("invalid")
                }
                return "=7", nil
        }
        exp, err = dfs(sum+rests[0], rests[1:len(rests)])
        if err == nil {
                return fmt.Sprintf("+%d%s", rests[0], exp), nil
        }
        exp, err = dfs(sum-rests[0], rests[1:len(rests)])
        if err == nil {
                return fmt.Sprintf("-%d%s", rests[0], exp), nil
        }
        return "", err
}

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

using namespace std;

#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define ALL(x) x.begin(),x.end()
#define pb push_back
#define mk make_pair

typedef long long LL;
typedef pair<int,int> Interval;

template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {
    _for(i,0,v.size()) os << v[i] << " ";
    return os;
}

template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){
    for(typename set<T>::iterator it = v.begin();it != v.end();it++)
    os << *it <<" ";
    return os;
}

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

const int maxn =1e5+5;
const int mod = 1e9+7;
int f[maxn];
int finv[maxn];

int mult(LL a, LL b){return (int)((a*b)%mod);}
int add( LL a, LL b){return (int)((a + b + mod)%mod);}


int fpow(int a,int p){
    if(p == 0) return 1;
    LL ret = fpow(a,p/2);
    ret = mult(ret,ret);
    if(p&1) ret = mult(ret,a);
    return (int)ret;
}

void init(){
    f[0] = 1;
    _for(i,1,maxn){
        f[i] = mult(i,f[i-1]);
        //cout << f[i] << endl;
    }

    finv[maxn-1] = fpow(f[maxn-1],mod-2);
    for(int i = maxn-2;i >= 0;i--){
        finv[i] = mult(i+1,finv[i+1]);
    }
}

int C(int a,int b){
    if(a < b) return 0;
    return mult(mult(f[a],finv[b]),finv[a-b]);
}

int l,r;
map<int,int> si;

int N;

int ans[maxn];
int cl[maxn];
int cr[maxn];

int main()
{
    cin >> N;
    init();
    _for(i,0,N+1){
        int a; cin >> a;
        if(si.count(a)){
            l = si[a];
            r = i;
        }
        si[a] = i;
    }

    _rep(i,1,N+1){
        ans[i] = C(N+1,i);
    }

    r = N-r;

    //cout << l <<" "<<r<<endl;

    _rep(i,0,l+r){
        ans[i+1] = add(ans[i+1],-C(l+r,i));
    }

    /*
    _rep(i,0,l){
        _rep(j,0,r){
            int sub = mult(C(l,i),C(r,j));
            ans[i+j+1] = add(ans[i+j+1],-sub);
        }
    }
    */
    _rep(i,1,N+1){
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 7040
#include <vector>
#include <iostream>
#include <cstring>
#include <climits>

using namespace std;

const int N = 100005;

vector<int> adj[N];
vector<int> r_adj[N];
int parents[N];
vector<int> order;
bool visited[N];
int number;
int po_numbers[N];

void dfs(int i) {
    visited[i] = true;
    for (int v : adj[i]) {
        if (!visited[v])
            dfs(v);
    }
    po_numbers[i] = number++;
}

int main() {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n - 1 + m; i++) {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        r_adj[v].push_back(u);
    }
    memset(visited, false, (n + 1) * sizeof(bool));
    number = 0;
    for (int i = 1; i <= n; i++) {
        if (!visited[i]) dfs(i);
    }

    for (int i = 1; i <= n; i++) {
        int min_po = INT_MAX;
        int parent = 0;
        for (int p : r_adj[i]) {
            if (po_numbers[p] < min_po) {
                min_po = po_numbers[p];
                parent = p;
            }
        }
        parents[i] = parent;
    }

    for (int i = 1; i <= n; i++) cout << parents[i] << endl;
}

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

typedef long long ll;
using namespace std;


const int di[4] = {1, 0, -1, 0};
const int dj[4] = {0, 1, 0, -1};

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 dist_max = 0;

    for (int si = 0; si < h; ++si) {
        for (int sj = 0; sj < w; ++sj) {
            if (S[si][sj] == '#') continue;
            
            // si, sjから各マスへの最短距離を記録する
            queue<pair<int, int>> Q;
            vector<vector<int>> dist(h, vector<int>(w, -1));
            dist[si][sj] = 0;
            Q.push(make_pair(si, sj));
            while (!Q.empty()) {
                int current_i = Q.front().first;
                int current_j = Q.front().second;
                Q.pop();

                for (int i = 0; i < 4; ++i) {
                    int next_i = current_i + di[i];
                    int next_j = current_j + dj[i];

                    if (next_i < 0 || h <= next_i || next_j < 0 || w <= next_j) continue;
                    if (S[next_i][next_j] == '#') continue;

                    if (dist[next_i][next_j] == -1) {
                        Q.push(make_pair(next_i, next_j));
                        dist[next_i][next_j] = dist[current_i][current_j] + 1;
                    }
                }
            }

            for (int ei = 0; ei < h; ++ei) {
                for (int ej = 0; ej < w; ++ej) {
                    dist_max = max(dist[ei][ej], dist_max);
                }
            }
        }
    }

    cout << dist_max;

    return 0;
}


Measured memory_bytes: 256
n = int(input())
v = list(map(int, input().split()))
c = list(map(int, input().split()))

z = []
for i in range(n):
  z.append(v[i]-c[i])
#print(z)
ans = 0
for i in z:
  if i >= 0:
    ans += i

print(ans)

Measured memory_bytes: 9116
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        boolean[] mod = new boolean[b];
        int now = a%b;
        mod[now] = true;
        while(true){
            now += a%b;
            now %= b;
            if(now == c){
                System.out.println("YES");
                return;
            }else if(mod[now]){
                System.out.println("NO");
                return;
            }
            mod[now] = true;
        }
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }
    
    public void close() throws Exception{
        this.reader.close();
        return;
    }

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

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

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

    public double nextDouble() {
         return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}

Measured memory_bytes: 25392
using System;

class Program{
    static bool[,] nodes;
    static int[] d, f;
    static int time;

    static void traverse(int id){
        if (d[id]==0) {
            time++;
            d[id]=time;
            for (var i=0; i<nodes.GetLength(0); i++) {
                if (nodes[id, i]) {
                    traverse(i);
                }
            }
            time++;
            f[id]=time;
        }
    }

    public static void Main(){
        var n=int.Parse(Console.ReadLine());
        nodes=new bool[n, n];
        d=new int[n];
        f=new int[n];
        for (var i=0; i<n; i++) {
            var s=Console.ReadLine().Split(' ');
            var id=int.Parse(s[0]);
            var k=int.Parse(s[1]);
            for (var j=0; j<k; j++) {
                nodes[id-1, int.Parse(s[j+2])-1]=true;
            }
        }

        for (var i=0; i<n; i++) {
            traverse(i);
        }

        for (var i=0; i<n; i++) {
            Console.WriteLine((i+1)+" "+d[i]+" "+f[i]);
        }
    }
}

Measured memory_bytes: 9216
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <utility>
#include <string>
#include <math.h>
#include <algorithm>
#include <cstring>
#include <cctype>

typedef long long int lli;

using namespace std;

int main() {

   int A,B,H,M;
   cin >> A >> B>> H >> M;
   double r;

   r=fabs(2.0*M_PI/720.0*(60*(double)H+(double)M)-2.0*M_PI/60.0*(double)M);
   if(r<=M_PI){
      cout << fixed << setprecision(15) << pow(A*A+B*B-2*A*B*cos(r),0.5) << endl;
   }else{
      r=2.0*M_PI-r;
      cout << fixed << setprecision(15) << pow(A*A+B*B-2*A*B*cos(r),0.5) << endl;
   }

}

Measured memory_bytes: 4352
N=int(input())
S=input()
i_lis=[]
key=0
for i in range(N-2):
  if S[i] in i_lis:continue
  else:i_lis.append(S[i])
  j_lis=[]
  for j in range(i+1,N-1):
    if S[j] in j_lis:continue
    else:j_lis.append(S[j])
    k_lis=[]
    for k in range(j+1,N):
      if S[k] in k_lis:continue
      else:k_lis.append(S[k]);key+=1
print(key)       
           

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

int n;
string *S;

int dp[51][51];
string dp2[51][51];

string func(string x, string y)
{
	for (int i = 0; i < 51; ++i) {
		for (int j = 0; j < 51; ++j) {
			dp[i][j] = 0;
			dp2[i][j] = "";
		}
	}

	for (unsigned int i = 0; i < x.length(); i++) {
		for (unsigned int j = 0; j < y.length(); j++) {
			if (x[i] == y[j]) {
				dp[i + 1][j + 1] = dp[i][j] + 1;
				dp2[i + 1][j + 1] = dp2[i][j] + x[i];
			} else {
				dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
				if (dp[i][j + 1] > dp[i + 1][j]) {
					dp2[i + 1][j + 1] = dp2[i][j + 1];
				} else {
					dp2[i + 1][j + 1] = dp2[i + 1][j];
				}
			}
		}
	}
	return dp2[x.length()][y.length()];
}

int main(void)
{

	cin >> n;
	S = new string[n];
	for (int i = 0; i < n; ++i) {
		cin >> S[i];
		sort(S[i].begin(), S[i].end());
	}
	
	for (int j = 0; j < n - 1; ++j) {
		for (int i = 1; i < n; ++i) {
			S[i] = func(S[j], S[i]);
		}
	}

	cout << S[n-1] << endl;

	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long A,B,N;
    cin >> A >> B >> N;
    if(B != 1){
        long long x;
        if(B > N) x = N;
        else x = B - 1;
        cout << A*x/B << endl;
    }
    else cout << 0 << endl;
}
    


Measured memory_bytes: 3596
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <cmath>
#include <map>
#include <fstream>
#include <iterator>

#define rep(i,a,n) for(int i=a;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

// Debug Vector
template <typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v){
    if(!v.empty()) {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}

template <typename T1, typename T2>
std::ostream &operator<<(std::ostream &out, const std::pair<T1, T2> &p) {
    out << "[" << p.first << ", " << p.second << "]";
    return out;
}
//---------


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
//    CLion Standard Input for DEBUG
//    --------------------------------------------------------------------------
//    ifstream in("/Users/ryo/Dropbox/competition/CompetitivePrograming/in.txt");
//    cin.rdbuf(in.rdbuf());
//    ------------------------------------------------------------------------

    int r, g, b;
    cin >> r >> g >> b;
    int sum = r * 100 + g * 10 + b;
    if (sum % 4 == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


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

int main() {

  int N,A,sum = 0 ;
  cin >> N ;

  int n = N ;
  for(int i = 0;i<8;i++){
    A=n%10;
    n/=10;
    sum+=A;
  }
  
  if(N % sum == 0){
    cout << "Yes" << endl;
  }
    
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
 
int main()
{
  int i,n;
  double x1,x2,x3,y1,y2,y3,xp,yp,r;
  scanf("%d",&n);
  for (i=0;i<n;i++){
    scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3);
 
    xp=((y1-y3)*(y1*y1 - y2*y2 + x1*x1 - x2*x2)
          - (y1-y2)*(y1*y1-y3*y3+x1*x1-x3*x3))
      /(2*(y1-y3)*(x1-x2)-2*(y1-y2)*(x1-x3));
    yp=((x1-x3)*(x1*x1 - x2*x2 + y1*y1 - y2*y2)
          - (x1-x2)*(x1*x1-x3*x3+y1*y1-y3*y3))
      /(2*(x1-x3)*(y1-y2)-2*(x1-x2)*(y1-y3));
    r = sqrt((xp-x1)*(xp-x1)+(yp-y1)*(yp-y1));
 
    printf("%.3f %.3f %.3f\n",xp,yp,r);
  }
  return 0;
}

Measured memory_bytes: 660
#include<iostream>
#include<cstdio>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
	int a,b,asum=0,bsum=0;
	for(int i=0;i<4;i++)
	{
		cin>>a;
		asum+=a;
	}
	for(int i=0;i<4;i++)
	{
		cin>>b;
		bsum+=b;
	}
	if(asum>=bsum)
		cout<<asum<<endl;
	else
		cout<<bsum<<endl;
	return 0;
}


Measured memory_bytes: 3080
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL


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

    string s;
    cin >> s;

    char a = s[0];
    bool ans = false;
    rep(i, s.size())
    {
        if (s[i] != a) ans = true;
    }

    cout << (ans ? "Yes\n" : "No\n");
    return 0;
}



Measured memory_bytes: 256
N = int(input()) # 奇数
inputs = [int(i) for i in input().split()]

double_inputs = list(map(lambda x: x * 2, inputs))
ans = [0 for _ in range(N)]
for i in range(N):
    if i == 0:
        ans[i] = sum(inputs) - sum(double_inputs[1::2])
    elif i == N - 1:
        ans[i] = double_inputs[-1] - ans[0]
    else:
        ans[i] = double_inputs[i-1] - ans[i-1]

print(' ' .join(map(str, ans)))


Measured memory_bytes: 23732
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define debug(x) cout << #x << " =" << (x) << endl;
#define MOD 1000000007
#define EPS (1 >> 30)
#define INF (1 << 30)
//#define INFll (1LL << 60)

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    //---------------------------------------------
    
    int k,x;
    cin>>k>>x;
    k--;
    for(int i=x-k;i<=x+k;i++){
        cout<<i<<" ";
    }
    cout<<endl;
}

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

int main() {
    int n, k;
    scanf("%d %d", &n, &k);
    int res = 0;
    for (int i = 0; i < n; ++ i) {
        int a;
        scanf("%d", &a);
        res += std::min(k - a, a);
    }
    printf("%d", 2 * res);
    return 0;
}


Measured memory_bytes: 128
li = list(map(int, input().split()))
even_count = sum([l % 2 for l in li])
ans = 1
if even_count == 1:
    li = [l + 1 if l % 2 == 0 else l for l in li]
elif even_count == 2:
    li = [l + 1 if l % 2 == 1 else l for l in li]
else:
    ans = 0
ans += sum([(max(li) - l) // 2 for l in li])
print(ans)

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

using namespace std;

typedef long long ll;

#define MOD 998244353
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>b;--i)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);

ll newmod(ll a,ll b)
 {
  return ((a%b)+b)%b;
}




ll powM(ll a,ll b,ll m )
{ 
  a%=m;
  ll ans=1;
  while(b>0)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }

return ans;
}

ll pow(ll a,ll b)
{ 
  
  ll ans=1;
  while(b)
  {
    if(b&1)ans=ans*a;
    a=a*a;
    b>>=1;
  }

return ans;
}


/*const int N=200000;

ll fac[N+1];
ll inv[N+1];
ll p=998244353;

ll c(ll a, ll b,ll m)
{
  if(a<b)return 0;
  return (fac[a]*inv[b]%m)*(inv[a-b])%m;
}

void fill()
{
inv[0]=1;
fac[0]=1;

for(int i=1;i<=N;i++)
{
  fac[i]=fac[i-1]*i%p;
  inv[i]=powM(fac[i],p-2,p);
}

}
*/
//ld dp[2001][2001];

ll dp[3001][3001];  // dp[i][j] ways to make sum i using j numbers.


int main()
{  fast

ll n,s;
cin>>n>>s;



vl a(n+1);



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

//sort(all(a));

dp[0][0]=powM(2,n,MOD);

for(int i=1;i<=n;i++)
{
  for(int j=0;j<=s;j++)
  {
     dp[i][j]+=dp[i-1][j];
    if(j>=a[i]) dp[i][j]+=dp[i-1][j-a[i]]*powM(2,MOD-2,MOD)%(MOD);
    dp[i][j]=newmod(dp[i][j],MOD);
  }
}


cout<<dp[n][s]<<"\n";

 return 0;

}


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

// ?????¬???????????¬??????
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// ???
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long double> vld;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T> int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F> int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T> void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C> void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U> void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U> void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C> void reverse(C& c) { reverse(ALL(c)); }
template<typename C> void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred> void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// ?????°
#pragma region CONST_VAL
constexpr int PI = (2*acos(0.0));
constexpr int EPS = (1e-9);
constexpr int MOD = (int)(1e9+7);
constexpr int INF = 100000000;
#pragma endregion

#define int long long

signed main()
{
    int n;
    int M = 300005;
    while(cin>>n, n!=1) {
        cout << n << ":";
        bool is_primes[M];
        fill(is_primes, is_primes+M, true);
        for(int i=2; i<=n; ++i) {
            if(i%7!=1&&i%7!=6) continue;
            if(is_primes[i]) {
                if(n%i==0) cout << " " << i;
                for(int j=i*2; j<=n; j+=i) is_primes[j] = false;
            }
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3364
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <functional>
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
using namespace std;
typedef long long ll;
const ll INF = 9223372036854775807-1;
const int inf = 2147483647-1;
ll minl(ll a[],int n){
    ll rtn = a[0];
    REP(i,n){
        if(rtn>a[i])rtn=a[i];
    }
    return rtn;
}
ll maxl(ll a[],int n){
    ll rtn = a[0];
    REP(i,n){
        if(rtn<a[i])rtn=a[i];
    }
    return rtn;
}

int main() {
    ll n,k;
    cin >> n >> k;
    if(n+k==15){
        put("+");
    }else if(n*k==15){
        put("*");
    }else{
        put("x");
    }
    //put(res);
    return 0;
}


Measured memory_bytes: 764
N = int(input())
h = list(map(int,input().split()))+[float("inf")]
dp = [0]+[float("inf")]*N
for i in range(0,N-1):
    dp[i+1] = min(dp[i+1],dp[i]+abs(h[i+1]-h[i]))
    dp[i+2] = min(dp[i+2],dp[i]+abs(h[i+2]-h[i]))
print(dp[N-1])


Measured memory_bytes: 13928
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
ll d[1010];
int main()
{
	int num, t;
	scanf("%d%d", &num, &t);
	for (int i = 0; i < num; i++)scanf("%lld", &d[i]);
	sort(d, d + num);
	ll s = 0;
	int r = 0;
	for (int i = 0; i < num; i++)
	{
		s += d[i];
		if (s <= t)r = i + 1;
	}
	if (r == num&&s != t)r--;
	printf("%d\n", r);
}

Measured memory_bytes: 128
(n, m), mod = map(int, raw_input().split()), 10 ** 9 + 7
if abs(n - m) > 1:
    print '0'
    exit()
def p(n, m):
    ans = 1
    for i in xrange(1, n + 1):
        ans = ((ans % m) * (i % m) % m)
    return ans
print (p(n, mod) * p(m, mod) % mod) if (n + m) % 2 else (p(n, mod) * p(m, mod) * 2) % mod


Measured memory_bytes: 2692
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Math;
using static System.Console;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        solve();
    }
    static Scanner cin;
    static int N;
    static int[] A;

    static void input()
    {
        cin = new Scanner();
        N = cin.nextInt();
        A = cin.ArrayInt(N);
    }
    static void solve()
    {
        input();
        int[] Count = new int[9];
        for(int i = 0; i < N; i++)
            Count[Min(A[i] / 400, 8)]++;

        int max = 0;
        int min = 0;
        for(int i = 0; i < 8; i++)
        {
            if(Count[i] > 0)
            {
                max++;
                min++;
            }
        }

        if(Count[8] > 0)
        {
            if(min == 0)
            {
                min = 1;
            }
            max += Count[8];
        }
        WriteLine(min + " " + max);
    }
    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }
        
        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }

        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for(int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for(int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }

        public double[] ArrayDounble(int N, int add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define F first
#define int long long
#define S second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<class T1, class T2>
istream &operator>>(istream &in, pair<T1, T2> &P){
	in >> P.first >> P.second;
	return in;
}
template<class T1, class T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &P){
	out << "(" << P.first << ", " << P.second << ")";
	return out;
}
template<class T>
istream &operator>>(istream &in, vector<T> &arr){
	for(auto &x: arr) in >> x;
	return in;
}
template<class T>
ostream &operator<<(ostream &out, const vector<T> &arr){
	for(auto &x: arr) out << x << ' '; cout << "\n";
	return out;
}
template<class T>
istream &operator>>(istream &in, deque<T> &arr){
	for(auto &x: arr) in >> x;
	return in;
}
template<class T>
ostream &operator<<(ostream &out, const deque<T> &arr){
	for(auto &x: arr) out << x << ' '; cout << "\n";
	return out;
}
int n , k;
int v[200005];

int32_t main(){
	scanf("%lld%lld" , &n , &k);
	rep(i,1,n+1) scanf("%lld" , &v[i]) , v[i] += v[i-1] , v[i] %= k;
	int ans = 0;
	map<int,int> cnt;
	cnt[0] ++ ;
	rep(i,1,n+1){
		if((i-k) >= 0){
			cnt[((((v[i-k] - (i-k))%k + k + k)%k)%k + k)%k]--;
		}
		ans += cnt[(((v[i] - i + k + k)%k) + k)%k];
		cnt[((((v[i] - i +k)%k + k)%k) + k)%k] ++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 16384
#include<stdio.h>
int main(){
    int i,j,k,n,v;
    int A[10000];

    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&A[i]);
        if(i>0)printf(" ");
        printf("%d",A[i]);
    }
    printf("\n");
   
    for(i=1;i<=n-1;i++){
        v = A[i];
        j=i-1;
        while(j>=0 && A[j]>v){
            A[j+1] = A[j];
            j--;
        }
            A[j+1] = v;

            for(k=0;k<n;k++){
            if(k>0)printf(" ");
            printf("%d", A[k]);
            }
            printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2084
n = int(input())
V = list(map(int, input().split()))

Dic = [[i,0] for i in range(1,(10**5)+1)]
Dic2 = [[i,0] for i in range(1,(10**5)+1)]
for i in range(n):
    if i%2 == 0:
        Dic[V[i]-1][1] += 1
    else:
        Dic2[V[i]-1][1] += 1
Dic.sort(key = lambda x:x[1],reverse = True)
Dic2.sort(key = lambda x:x[1], reverse = True)
#print(Dic,Dic2)
cn = 0
if Dic[0][0] != Dic2[0][0]:
    cn += n - Dic[0][1] - Dic2[0][1]
else:
    cn += n - max((Dic[0][1]+Dic2[1][1]), (Dic[1][1]+Dic2[0][1]))
print(cn)

Measured memory_bytes: 35068
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int,int> Pi;
typedef long long int ll;
const int INF=(ll)(1LL<<31)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
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 dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int n;
ll a[100100];

int main(){
	cin>>n;
	REP(i,n)
		cin>>a[i];
	sort(a,a+n);
	ll sum=0;
	
	if(n%2==0){
		for(int i=0;i<n/2-1;i++){
			sum+=(-2)*a[i];
		}
		sum-=a[n/2-1];
		sum+=a[n/2];
		for(int i=n/2+1;i<n;i++){
			sum+=2*a[i];
		}
	}
	ll suma=0;
	ll sumb=0;
	if(n==3){
		cout<<max(a[2]+a[1]-a[0]*2,2*a[2]-a[1]-a[0])<<endl;
		return 0;
	}
	if(n%2==1){
		vector<int> v;
        REP(i,n)v.push_back(abs(a[i]-a[n/2]));
        sort(v.begin(),v.end());
        for(auto x:v)sum+=2*x;
        sum-=min(a[n/2]-a[n/2-1],a[n/2+1]-a[n/2]);
		
	}
	cout<<sum<<endl;
	return 0;
}
		

Measured memory_bytes: 1660
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <ostream>
#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 INF 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
    int N;
    int t;
    cin >> N;
    int cnt = 0;
    vector<int> p;
    vector<int> q;
    vector<int> nums(N);
    int ans[2] = {0, 0};
    iota(nums.begin(), nums.end(), 1);
    for (int i = 0; i < N; i++)
    {
        cin >> t;
        p.push_back(t);
    }
    for (int i = 0; i < N; i++)
    {
        cin >> t;
        q.push_back(t);
    }
    do
    {
        cnt++;
        if (nums == p)
        {
            ans[0] = cnt;
        }
        if (nums == q)
        {
            ans[1] = cnt;
        }
    } while (next_permutation(nums.begin(), nums.end()));

    cout << abs(ans[0] - ans[1]) << endl;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#include<vector>
#include<set>
#define ll long long int

using namespace std;
#define mod 1000000007





ll power(ll x, ll n){
	ll res = 1;
	while(n){
		if(n%2) res = ((res%mod)*(x%mod))%mod;
		x = ((x%mod)*(x%mod))%mod;
		n /= 2;
	}
	return res;
}

int main(){
	ll n;
	cin >> n;
	ll res = (power(10, n)-2*power(9, n)+power(8,n)+2*mod)%mod;
	printf("%lld\n", res);
}

Measured memory_bytes: 3728
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
int main(){
  cout << fixed << setprecision(10);
int N;
cin >> N;
vector<vector<int>> p(N,vector<int>(2));
for(int i = 0; i < N; i++){
  for(int j = 0; j< 2; j++){
    cin >> p.at(i).at(j);
  }
}
double sum = 0LL;
for(int i = 0; i < N-1; i++){
  for(int j = i+1; j < N; j++){
    double nijou_x = (p.at(i).at(0)-p.at(j).at(0))*(p.at(i).at(0)-p.at(j).at(0));
    double nijou_y = (p.at(i).at(1)-p.at(j).at(1))*(p.at(i).at(1)-p.at(j).at(1));
    double distance = sqrt(nijou_x + nijou_y) ;
    for(int k = 1; k < N ; k++){
      distance*= k;
    }
    sum += distance*2LL;
  }
}
for(int i = 2; i <= N ; i ++){
  sum/= i;

}
cout << sum << endl;
}



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


int main(){
    string s;cin>>s;
    vector<ll> mod(2019,0);
    mod[0]++;
    ll now=0,tenex=1,n=s.size();
    rep(i,0,n){
        now=(now+(s[n-i-1]-'0')*tenex%2019)%2019;
        tenex=tenex*10%2019;
        mod[now]++;
    }
    ll an=0;
    rep(i,0,2019){
        an+=mod[i]*(mod[i]-1)/2;
    }
    cout<<an<<endl;

}
    









Measured memory_bytes: 3720
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int m=INT_MAX;
	string s,t;
	cin>>s>>t;
	//for(int j=0;j<s.size();j++)
	//{
	long long int p=t.size();
	long long int q=s.size();
	long long int r=q-p+1;
	//while(r>0)
	//{
int c=0;
	for(int j=0;j<r;j++)
	{
		c=0;
	for(int i=0;i<p;i++)
	{
		//j=i;
			if(s[i+j]!=t[i])
			c++;
		//	cout<<j<<endl;
		//	j=i+1;
	}
	m=min(c,m);
		}
		//c=0;
		
		//m=min(m,c);
		//j=0;
		//cout<<j<<endl;
	//	r--;
			
		//p++;
	//}//
	cout<<m<<endl;
	return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define mp make_pair
#define X first
#define Y second
#define pii pair<ll,ll>
#define x1 dlfjl
#define x2 dkfj
#define x3 dflgkg
#define y1 dskgj
#define y2 dskfj
#define y3 dfhgdh
#define SQ 320
#define PI 3.14159265359
#define MOD 998244353
typedef long long ll;
using namespace std;
ll n,i,j,k,x,y,z,m,q,h,r,timer,mx,l, cnt,s,col;
ll a[300500], fac[300500];
ll binpow(ll x, ll y) {
    if (y == 0)
        return 1;
    ll tmp = binpow(x, y/2);
    tmp = (tmp*tmp)%MOD;
    if (y%2) {
        return x*tmp%MOD;
    }
    return tmp;
}
ll C(ll n, ll k) {
    return fac[n]*a[k]%MOD*a[n-k]%MOD;
}
int main() {
    //freopen("input.txt","r",stdin);
    fac[0] = 1;
    a[0] = 1;
    for (int i = 1; i <= 300000; i++) {
        fac[i] = fac[i-1]*i%MOD;
        a[i] = binpow(fac[i], MOD-2);
    }
    cin >> n >> x >> y >> k;
    ll ans = 0;
    for (int i = 0; i <= n; i++) {
        if (x*i <= k && (k-x*i)%y == 0 && (k-x*i)/y <= n) {
            ll j = (k-x*i)/y;
            ans += C(n,i)*C(n,j)%MOD;
            ans %= MOD;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4992