akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<vector>
#define R register
#define next kkksc03
#define maxn 1000000
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
inline ll read();
inline void write(ll x);
inline void writesp(ll x);
inline void writeln(ll x);
ll n,h[165],son[165][165],say[165][165];
bool check(ll k){
	bool flag=false;
	for(R ll i=1;i<=n;i++){
		flag=false;
			for(R ll j=1;j<=h[i];j++){
				if((say[i][son[i][j]])^((k&(1<<(son[i][j]-1)))>>(son[i][j]-1))) flag=true;
			}
		if(!(k&(1<<(i-1)))){
			if(!flag) return false;
		}
		else if(flag) {
		return false;
		}
	}
	return true;
}
ll lowbit(ll x){
	return x&-x;
}
inline ll query(ll x){
	ll ans=0;
	for(;x;x-=lowbit(x)) ans++;
	return ans;
}
ll maxx;
int main(){
	n=read();
	for(R ll i=1;i<=n;i++){
		h[i]=read();
		for(R ll j=1;j<=h[i];j++){
			son[i][j]=read();
			say[i][son[i][j]]=read();	
		}
	}
	for(R ll state=0;state<(1<<n);state++){
		if(check(state)) maxx=max(maxx,query(state));
	}
	writeln(maxx);
}
inline ll read(){
	ll x=0,t=1;char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-') t=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return x*t;
}
inline void write(ll x){
	if(x<0){putchar('-');x=-x;}
	if(x<=9){putchar(x+'0');return;}
	write(x/10);putchar(x%10+'0');
}
inline void writesp(ll x){
	write(x);putchar(' ');
}
inline void writeln(ll x){
	write(x);putchar('\n');
}

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

using namespace std;

static const int INF = 1e9 + 7;

void hawawa()
{
  int n;
  cin >> n;
  vector<pair<long long, long long> > v(n);
  long long ans = 0;
  for (auto&& i : v) { 
    cin >> i.first >> i.second; 
  }
  reverse(v.begin(), v.end());
  for (auto&& i : v) {
    ans += (i.second - ((i.first + ans) % i.second)) % i.second;
  }
  cout << ans << "\n";
}

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

Measured memory_bytes: 1792
#!/usr/bin/env python
# -*- coding: utf-8 -*-

def main():
    N, K = map(int, input().split())
    p = [((int(i)+1) * int(i) / 2)/int(i) for i in input().split()]
    result = sum(p[:K])
    prev = result
    for i in range(0, N-K):
        prev = prev - p[i] + p[i+K]
        result = max(result, prev)
    print(result)

if __name__ == "__main__":
    main()

Measured memory_bytes: 23524
#!/usr/bin/env python3

from fractions import gcd

a, b, c, d = list(map(int, input().split()))


def calc(min_, max_, div_num):
    if (min_ % div_num) != 0:
        min_ = min_ - (min_ % div_num)+div_num

    if min_ > max_:
        return 0
    return (max_-min_)//div_num+1


# print(calc(a, b, c))
# print(calc(a, b, d))
# print(calc(a, b, c*d//gcd(c, d)))
print((b-a+1)-(calc(a, b, c)+calc(a, b, d)-calc(a, b, c*d//gcd(c, d))))


Measured memory_bytes: 5048
using System;

namespace ConsoleApp2
{
	class Program
	{
		static void Main(string[] args)
		{
			var nk = Console.ReadLine().Split();
			var n = int.Parse(nk[0]);
			var k = int.Parse(nk[1]);

			var p = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
			Array.Sort(p);

			var ans = 0;
			for (int i = 0; i < k; i++)
			{
				ans += p[i];
			}

			Console.WriteLine(ans);
		}
	}
}


Measured memory_bytes: 27924
#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
const int N = (int)(1e6) + 5;
const int oo = 1e8;
int t[N];
int s[N];
int g(int l,int r)
{
    return s[r] - s[l - 1];
}
void update(int l,int r,int pos,int v,int node)
{
    if (l == r)
        t[node] = v;
    else
    {
        int m = (l + r) / 2;
        if (pos <= m)
            update(l,m,pos,v,node * 2);
        else
            update(m+1,r,pos,v,node * 2 + 1);
        t[node] = min(t[node * 2],t[node * 2 + 1]);
    }
}
int query(int l,int r,int l1,int r1,int node)
{
    if (l1 <= l && r <= r1)
        return t[node];
    else
    {
        int m = (l + r) / 2;
        int ans = oo;
        if (l1 <= m)
            smin(ans,query(l,m,l1,r1,node * 2));
        if (m+1<=r1)
            smin(ans,query(m+1,r,l1,r1,node * 2 + 1));
        return ans;
    }
}
void build(int l,int r,int node)
{
    t[node] = oo;
    if (l == r) return;
    int m = (l + r) / 2;
    build(l,m,node * 2);
    build(m+1,r,node * 2 + 1);
}
vi w[N];
int dp[N];
int main(void)
{
    int n;
    ios_base :: sync_with_stdio(0);
    cin>>n;
    for (int i = 1;i <= n;++i)
        cin>>s[i],s[i] += s[i - 1];
    int m;
    cin>>m;
    while (m --)
    {
        int l,r;
        cin>>l>>r;
        w[l].pb(r);
    }
    build(1,n,1);
    for (int i = 1;i <= n;++i)
        dp[i] = oo;
    for (int i = 1;i <= n;++i)
    {
        smin(dp[i],dp[i - 1] + g(i,i));
        for (auto it : w[i])
        {
            int omg = min(query(1,n,i,it,1),dp[i - 1] + s[i - 1] - (i - 1));
            update(1,n,it,omg,1);
            smin(dp[it],omg + it - s[it]);
        }
    }
    cout << dp[n] << '\n';
    return 0;
}


Measured memory_bytes: 35712
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll a;
  cin >> a;
  cout << a + a*a + a*a*a << endl;
}

Measured memory_bytes: 3632
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    S = list(input())
    T = list(input())
    
    ind = []
    isOk = False
    
    for i, val in enumerate(S):
        if val == "?" or val == T[0]:
            flg = True
            if len(S)-i < len(T):
                #print(val)
                #print("{} {}".format(len(S)-i, len(T)))
                break
            for j, vol in enumerate(T):
                if S[i+j] != T[j] and S[i+j] != "?":
                    flg = False
                    break
            if flg == True:
                ind.append(i)
                isOk = True
                
    if isOk == False:
        print("UNRESTORABLE")
    else:
        ind.sort()
        tmp = ind[-1]
        for i, val in enumerate(S):
            if i == tmp:
                for j, vol in enumerate(T):
                    S[i+j] = T[j]
            else:
                if val == "?":
                    S[i] = "a"
        print("".join(S))
    
            	
if __name__ == "__main__":
	main()


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

using namespace std;

using ll = long long;

int main()
{
    ll A, B; cin >> A >> B;

    ll ans = 0;
    ll num = B - A + 1;
    if (num % 2 == 0) {
        if (A % 2 == 0) {
            if (num % 4 == 0) ans = 0;
            else ans = 1;
        } else {
            if ((num - 2) % 4 == 0) ans = A ^ B;
            else ans = A ^ B ^ 1;
        }
    } else {
        if (A % 2 == 0) {
            if ((num - 1) % 4 == 0) ans = B;
            else ans = B ^ 1;
        } else {
            if ((num - 1) % 4 == 0) ans = A;
            else ans = A ^ 1;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string { sc.Scan(); return sc.Text() }
func scanInt() int { a,_ := strconv.Atoi(scanString()); return a }
func scanInt64() int64 { a,_ := strconv.ParseInt(scanString(),10,64); return a }
func scanFloat64() float64 { a,_ := strconv.ParseFloat(scanString(),64); return a }

func scanInts(n int) []int {
	res := make([]int, n); for i := 0; i < n; i++ { res[i] = scanInt() }; return res
}

func abs(a int) int { if a<0 { return -a }; return a }
func min(a,b int) int { if a<b { return a }; return b }
func max(a,b int) int { if a>b { return a }; return b }

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	p := scanInts(n)

	cnt := make([]int, n+1)

	for i := 0; i < n; i++ {
		cnt[p[i]] = cnt[p[i]-1] + 1
	}

	ma := 0 
	for i := 0; i < n; i++ {
		ma = max(ma, cnt[i+1])
	}

	fmt.Fprintln(wr, n-ma)
}


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

using namespace std;
typedef long long ll;
const ll mx = 10000007;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
#define    ss   second
#define    ff   first
#define    pb   push_back
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
#define FIO ios_base::sync_with_stdio(false);  cin.tie(NULL);


int main() {
    FIO;
    ll n, m;
    cin >> n >> m;
    cout << (1800*m + (100 * n)) * (ll)pow(2, m) << endl;
    return 0;
}


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


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    
    int n,ans=0;
    cin>>n;
    vector<ll>a(n),b(n);
    
    rep(i,n) cin>>a[i];
    sort(begin(a),end(a));
    b[0]=a[0];
    forx(i,1,n)b[i]=a[i]+b[i-1];
    
    rep(i,n-1){
        if(a[i+1]<=2*b[i])ans++;
        else ans=0;
    }
    ans++;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
    int n;
    long a[300000],ans=0;
    scanf("%d",&n);
    for(int i=0;i<3*n;i++){
        scanf("%ld",&a[i]);
    }
    sort(a,a+3*n);
    for(int i=0;i<n;i++){
        ans+=a[3*n-2-2*i];
    }
    printf("%ld\n",ans);
}

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

typedef long long ll;

ll p[50],a[50];

ll func(int N,ll X) {
  if ( N == 0 && X <= 0 ) return 0;
  else if ( N == 0 && X > 0 ) return 1;
  else if ( X <= 1 + a[N-1] ) return func(N-1,X-1);
  else if ( X == 2+a[N-1] ) return p[N-1]+1;
  else if ( X <= 2+2*a[N-1] ) return p[N-1]+1+func(N-1,X-2-a[N-1]);
  else return 2*p[N-1]+1;
}

int main() {
  int N; ll X; cin >> N >> X;
  p[0] = a[0] = 1;
  for ( int i = 1; i <= N; i++ ) {
    p[i] = 2*p[i-1]+1;
  }
  for ( int i = 1; i <= N; i++ ) {
    a[i] = 2*a[i-1]+3;
  }

  cout << func(N,X) << endl;
  return 0;
}


Measured memory_bytes: 256
N,P = map(int,input().split())
A = list(map(int,input().split()))
ce = 0
co = 0
for i in range(N):
    if A[i]%2==0:
        ce += 1
    else:
        co += 1
if co>0:
    n = (2**ce)*(2**(co-1))
else:
    n = 2**ce
if P==0:
    print(n)
else:
    print(2**N-n)

Measured memory_bytes: 38384
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <string.h>
using namespace std;
const int maxN=200005;
char s[maxN];
int main(int argc, const char * argv[]) {
    while(scanf("%s",s)!=EOF){
        int k=0;
        for(int i=0;i<strlen(s);i++){
            if(s[i]=='T'&&k>0)k--;
            else if(s[i]=='S')k++;
            
        }
        printf("%d\n",2*k);
    }
    return 0;
}

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

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

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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sax(x) cout << "!!!!!!!!!!! " << #x << " = " << x << '\n'
#define inf (sizeof(int) == 4 ? (int)1E9 : (int)1E18)
#define one(x) x.insert(x.begin(), 0);
#define TCT template <class T>
#define TCT12 template <class T1, class T2>
#define IS istream
#define OS ostream
#define OP operator

//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less_equal<int>,rb_tree_tag,
//tree_order_statistics_node_update> imsi;

TCT IS& OP>>(IS &I, vector<T>& v) {for (T &e: v) I >> e; return I;}
TCT OS& OP<<(OS &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; O << '\n'; return O;}
TCT OS& OP<<(OS &O, const unordered_set<T>& v) {for (const T &e: v) O << e << ' '; return O;}
TCT OS& OP<<(OS &O, const set<T>& v) {for (const T &e: v) O << e << ' '; return O;}
TCT OS& OP<<(OS &O, const unordered_multiset<T>& v) {for (const T &e: v) O << e << ' '; return O;}
TCT OS& OP<<(OS &O, const multiset<T>& v) {for (const T &e: v) O << e << ' '; return O;}
TCT IS& OP>>(IS &I, deque<T>& v) {for (T &e: v) I >> e; return I;}
TCT OS& OP<<(OS &O, const deque<T>& v) {for (const T &e: v) O << e << ' '; return O;}
TCT OS& OP<<(OS &O, priority_queue<T> v) {while (!v.empty()) {O << v.top() << ' '; v.pop();} return O;}
TCT OS& OP<<(OS &O, stack<T> v) {while (!v.empty()) {O << v.top() << '\n'; v.pop();} return O;}
TCT OS& OP<<(OS &O, queue<T> v) {while (!v.empty()) {O << v.front() << ' '; v.pop();} return O;}
TCT12 IS& OP>>(IS &I, pair<T1,T2>& p) {return I >> p.first >> p.second;}
TCT12 OS& OP<<(OS &O, const pair<T1,T2>& p) {return O << '(' << p.first << ' ' << p.second << ')';}
TCT12 OS& OP<<(OS &O, const unordered_map<T1,T2>& v) {for (const auto &e: v) O << e << ' '; return O;}
TCT12 OS& OP<<(OS &O, const map<T1,T2>& v) {for (const auto &e: v) O << e << ' '; return O;}
typedef pair<int,int> pii;
typedef vector<int> vi;




void _main() {
        int a, b; cin >> a >> b;
        cout << (a * 500 >=b ? "Yes" : "No");
}



signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void) {

	int a, b,ans;
	char op;

	while (1) {

		scanf("%d %c %d", &a, &op, &b);

		if (op == '?')
			break;

		switch (op) {

		case '+':
			ans = a + b;
			printf("%d\n", ans);
			break;
		case '-':
			ans = a - b;
			printf("%d\n", ans);
			break;
		case '*':
			ans = a * b;
			printf("%d\n", ans);
			break;
		case '/':
			ans = a / b;
			printf("%d\n", ans);
			break;
		}

	}



	return(0);

}


Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int, int> pi;

const int MAXN = 20005;
struct maxflow{
	struct edg{int pos, cap, rev;};
	vector<edg> gph[MAXN];

	void clear(){
		for(int i=0; i<MAXN; i++){
			gph[i].clear();
		}
	}

	void add_edge(int s, int e, int x){
		gph[s].push_back({e, x, (int)gph[e].size()});
		gph[e].push_back({s, 0, (int)gph[s].size()-1});
	}

	int dis[MAXN], pnt[MAXN];

	bool bfs(int src, int sink){
		memset(dis, 0, sizeof(dis));
		memset(pnt, 0, sizeof(pnt));
		queue<int> que;
		que.push(src);
		dis[src] = 1;
		while(!que.empty()){
			int x = que.front();
			que.pop();
			for(int i=0; i<gph[x].size(); i++){
				edg e = gph[x][i];
				if(e.cap > 0 && !dis[e.pos]){
					dis[e.pos] = dis[x] + 1;
					que.push(e.pos);
				}
			}
		}
		return dis[sink] > 0;
	}

	int dfs(int x, int sink, int f){
		if(x == sink) return f;
		for(; pnt[x] < gph[x].size(); pnt[x]++){
			edg e = gph[x][pnt[x]];
			if(e.cap > 0 && dis[e.pos] == dis[x] + 1){
				int w = dfs(e.pos, sink, min(f, e.cap));
				if(w){
					gph[x][pnt[x]].cap -= w;
					gph[e.pos][e.rev].cap += w;
					return w;
				}
			}
		}
		return 0;
	}

	lint match(int src, int sink){
		lint ret = 0;
		while(bfs(src, sink)){
			int r;
			while((r = dfs(src, sink, 2e9))) ret += r;
		}
		return ret;
	}
}mf;

int n, m;
char str[105][105];

int main(){
	cin >> n >> m;
	for(int i=0; i<n; i++) cin >> str[i];
	vector<pi> v;
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			if(str[i][j] == '.') continue;
			v.push_back(pi(i, j));
		}
	}
	int st = -1, ed = -1;
	for(int i=0; i<v.size(); i++){
		mf.add_edge(2*i, 2*i+1, 1);
		if(str[v[i].first][v[i].second] == 'S'){
			st = 2 * i + 1;
		}
		if(str[v[i].first][v[i].second] == 'T'){
			ed = 2 * i;
		}
		for(int j=0; j<v.size(); j++){
			if(i == j) continue;
			if(v[i].first == v[j].first || v[i].second == v[j].second){
				mf.add_edge(2*i+1, 2*j, 1e9);
			}
		}
	}
	int ans = mf.match(st, ed);
	if(ans > 1e8) ans = -1;
	cout << ans << endl;
}



Measured memory_bytes: 62720
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String s[] = new String[n];
    String answer = "Yes";
    for(int i=0;i<n;i++){
      s[i]=sc.next();
    }
    for(int i=0;i<n-1;i++){
      if(!s[i].substring(s[i].length()-1,s[i].length())
         .equals(s[i+1].substring(0,1))){
        answer="No";
        break;
      }
    }
    for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
        if(s[i].equals(s[j])){
          answer = "No";
        }
      }
    }
    System.out.println(answer);
           
          
      
    
  }
  

  
}

Measured memory_bytes: 21844
//#pragma GCC optimize(2)
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<cassert>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<bitset>
#define heap priority_queue<int,vector<int>,greater<int> >
#define _heap priority_queue<int,vector<int>,less<int> >
#define _for(a,b,c) for((a)=(b);(a)<=(c);++(a))
#define __for(a,b,c) for((a)=b;(a)>=(c);--(a))
#define _init(a,b) memset((a),(b),sizeof (a))
#define LL long long
#define mod 1e9+7
#define INF 0x3f3f3f3f
using namespace std;

namespace FastIO {
	template<typename tp> inline void read(tp &x) {
		x=0; register char c=getchar(); register bool f=0;
		for(;c<'0'||c>'9';f|=(c=='-'),c = getchar());
		for(;c>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0',c = getchar());
		if(f) x=-x;
	}
	template<typename tp> inline void write(tp x) {
		if (x==0) return (void) (putchar('0'));
		if (x<0) putchar('-'),x=-x;
		int pr[20]; register int cnt=0;
		for (;x;x/=10) pr[++cnt]=x%10;
		while (cnt) putchar(pr[cnt--]+'0');
	}
	template<typename tp> inline void writeln(tp x) {
		write(x);
		putchar('\n');
	}
}
using namespace FastIO;

//------------Coding Area------------
int d[3];
int main(){
	read(d[0]),read(d[1]),read(d[2]);
	sort(d,d+3);
	int jis=0;
	while(!(d[1]==d[2]&&d[2]==d[0])){
		if(d[0]==d[1]) {
			jis+=d[2]-d[0];
			break;
		}
		if(d[1]!=d[2]){
			jis+=d[2]-d[1];
			d[0]+=d[2]-d[1];
			d[1]=d[2];
		}else while(d[0]<d[2]) d[0]+=2,++jis;
		sort(d,d+3);
	}
	return writeln(jis),0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include <list>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    int n;
    cin >> n;
    vector<ll>a(n);
    rep(i,n)cin >> a[i];
    sort(a.rbegin(), a.rend());
    ll ans = 0;
    for(int i = 1; i < n; i++){
        ans += a[i/2];
    }
    cout << ans << endl;
}


Measured memory_bytes: 4828
while 1:
    try:
        x,y=[int(i) for i in input().split()]
        a=x
        b=y

        while 1:
            c=x%y
            if x%y==0:
                print(y,a*b//y)
                break
            else:
                x=y
                y=c
    except EOFError:
        break

Measured memory_bytes: 7588
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		new Main().start();
	}
	void start(){
		Scanner in = new Scanner(System.in);
		String s = in.next();
		int n = s.length()/2-1;
		for(int i = n; i > 0; i-=1){
			if(isDouble(s,i)){
				System.out.println(i*2);
				break;
			}
		}
		in.close();
	}
	boolean isDouble(String s, int n){
		for(int i = 0; i < n; i++){
			if(s.charAt(i) != s.charAt(n+i)) return false;
		}
		return true;
	}

}


Measured memory_bytes: 21844
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto abc = RDR.ARR;
	abc.sort();

	writeln(abc[0] + abc[1]);
	stdout.flush();
	debug readln();
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define pie 3.141592653589793238462643383279
#define mod 998244353
#define inf 10000000000000007
#define all(vec) vec.begin(),vec.end()
#define ggr getchar(); getchar();return 0;
#define ll long long
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int kai(int x) {
	if (x == 1)return 1;
	return kai(x - 1)*x;
}

int mod_pow(int x, int y, int moder) {
	int res = 1;
	while (y > 0) {
		if (y & 1)res = res * x%moder;
		x = x * x%moder;
		y >>= 1;
	}
	return res;
}

int n;
string s;
char ta[4][100010];

signed main() {
	cin >> n >> s;
	ta[0][0] = 'S';
	ta[0][1] = 'S';
	ta[1][0] = 'S';
	ta[1][1] = 'W';
	ta[2][0] = 'W';
	ta[2][1] = 'S';
	ta[3][0] = 'W';
	ta[3][1] = 'W';
	for (int i = 2; i < n; i++) {
		rep(j, 4) {
			if (s[i - 1] == 'o') {
				if (ta[j][i - 1] == 'S')ta[j][i] = ta[j][i - 2];
				else if (ta[j][i - 2] == 'S')ta[j][i] = 'W';
				else ta[j][i] = 'S';
			}
			else {
				if (ta[j][i - 1] == 'W')ta[j][i] = ta[j][i - 2];
				else if (ta[j][i - 2] == 'S')ta[j][i] = 'W';
				else ta[j][i] = 'S';
			}
		}
	}
	bool mu = true;
	rep(i, 4) {
		if (ta[i][n - 1] == 'S') {
			if (s[n - 1] == 'o'&&ta[i][n - 2] != ta[i][0])mu = false;
			else if (s[n - 1] == 'x'&&ta[i][n - 2] == ta[i][0])mu = false;
		}
		else {
			if (s[n - 1] == 'o'&&ta[i][n - 2] == ta[i][0])mu = false;
			else if (s[n - 1] == 'x'&&ta[i][n - 2] != ta[i][0])mu = false;
		}
		if (ta[i][0] == 'S') {
			if (s[0] == 'o'&&ta[i][n - 1] != ta[i][1])mu = false;
			else if (s[0] == 'x'&&ta[i][n - 1] == ta[i][1])mu = false;
		}
		else {
			if (s[0] == 'o'&&ta[i][n - 1] == ta[i][1])mu = false;
			else if (s[0] == 'x'&&ta[i][n - 1] != ta[i][1])mu = false;
		}
		if (mu) {
			rep(j, n) {
				cout << ta[i][j];
			}
			cout << endl;
			return 0;
		}
		mu = true;
	}
	cout << -1 << endl;
	return 0;
}

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

int main() {
  int a, b, c, d; //入力する数値の初期化
  
  cin >> a >> b >> c >> d;
  
  if (a + b > c + d){
  	cout << "Left" << endl;
  }else if ( a + b < c + d) {
  	cout << "Right" << endl;
  }else{
  	cout << "Balanced" << endl;
  }
}


Measured memory_bytes: 3592
#include <stdio.h>

int main(void)
{
    int N;
    int P[200000];
    int i, counter = 0, cmp_num = 0;

    scanf("%d", &N);
    for (i = 1; i <= N; i++)
    {
        scanf("%d", &P[i]);
    }
    for (i = 1; i <= N; i++)
    {
        if (i == 1)
        {
            cmp_num = P[i];
            counter++;
        }
        while (i != 1 && cmp_num > P[i])
        {
            cmp_num = P[i];
            counter++;
        }
    }
    printf("%d", counter);

    return (0);
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
#define mp make_pair
using namespace std;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;//cnt, coodinate
string grid[1001];
int neiber[1001][1001],
  dx[] = {0, 1, 1,  1,  0, -1, -1, -1},
  dy[] = {1, 1, 0, -1, -1, -1,  0,  1};
int w, h;
inline bool renge(int x, int y){
  return (0 <= x && x < w &&
          0 <= y && y < h);
}
bool del(int x, int y){
  int cnt = 0;
  for (int i = 0; i < 8; i++) {
    int nx = x + dx[i], ny = y + dy[i];
    if(!renge(nx, ny))continue;
    if(grid[ny][nx] == '.')cnt++;
  }
  char tmp = grid[y][x];
  neiber[y][x] = cnt;
  return cnt >= atoi(&tmp);
}
 
int main(int argc, char *argv[]){
  queue<piii> que;
  cin >> h >> w;
  for (int i = 0; i < h; i++)
    cin >> grid[i];

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if(grid[i][j] != '.' && del(j, i))
        que.push(mp(1, mp(j, i)));
    }
  }
  
  int ans = 0;
  while(!que.empty()){
    int cnt = que.front().first;
    int x = que.front().second.first;
    int y = que.front().second.second;
    que.pop();
    if(grid[y][x] == '.')continue;
    grid[y][x] = '.';
    ans = cnt;
    for (int i = 0; i < 8; i++) {
      int nx = x + dx[i], ny = y + dy[i];
      if(!renge(nx, ny))continue;
      char tmp = grid[ny][nx];
      neiber[ny][nx]++;
      if(neiber[ny][nx] >= atoi(&tmp))
        que.push(mp(cnt + 1, mp(nx, ny)));
    }
  }
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 6252
#include<bits/stdc++.h>
using namespace std;
     
#define ll long long
#define loop(i,a,n) for(ll i=a;i<n;++i)
#define revloop(i,a,b) for(ll i=a;i>=b;--i)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define INF 999999999999999
#define MOD 1000000007

void func()
{
    ll n,k;
    cin>>n>>k;
    ll a[n+1],b[n+1]={0};
    loop(i,1,n+1){
        cin>>a[i];
    }
    vector<ll> v;
    v.pb(1);
    ll cur=a[1];
    b[1]++;
    while(b[cur]!=2){
        v.pb(cur);
        cur=a[cur];
        b[cur]++;
    }
    vector<ll> nc;
    vector<ll> c;
    ll i=0;
    while(b[v[i]]!=2){
        nc.pb(v[i]);
        ++i;
    }
    loop(j,i,v.size()){
        c.pb(v[j]);
    }
    cout<<"\n";
    if(k<nc.size())
    {
        cout<<nc[k]<<"\n";
        return;
    }
    else{
        k=k-nc.size();
        ll s=c.size();
        cout<<c[k%s]<<"\n";
    }
}

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

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

    ll t=1;
    //cin>>t;
    while(t--)
    {
        func();
    }
}

Measured memory_bytes: 10880
from math import sqrt
from collections import defaultdict 

# 半開区間[lower, upper)の素数のリストを作成する
def make_prime_list(lower:int, upper:int) -> list:
    
    # 変数のバリデーション
    if lower < 0:
        raise ValueError("lowerは0以上でなければいけません。(lower:{})".format(lower))

    elif upper <= lower:
        raise ValueError("upperはlowerより大きい数でなければいけません。\
                         (lower:{}, upper:{})".format(lower,upper))
    
    # 素数リストの初期化    
    isPrime = [True]*upper
    primeList = []
    
    # 区間内の数字が0,1のみならここで終了
    if upper <= 2:
        return primeList
    
    # 区間内の数字に2以上のものがあるとき
    isPrime[0] = False
    isPrime[1] = False
    
    # エラトステネスの篩の処理
    for n in range(2,int(sqrt(upper))+2):
        if isPrime[n]:
            res=2*n
            while res<upper:
                isPrime[res] = False
                res += n
    
    # 区間内の素数を抽出
    for n in range(lower,upper):
        if isPrime[n]:
            primeList.append(n)
        
    return primeList


# numを素因数分解する
def factoring(num: int, prime_list:list) -> dict:
    
    # バリデーション
    if num < 2:
        raise ValueError("numは2以上でなければいけません。(num:{})".format(num))
    
    
    # numまでの素数リストを作る
    prime_set = set(prime_list)
    
    # {素数: 含まれる数}の辞書を作る
    dic = defaultdict(int)
    res = num
    i = 0
    
    # resが素数になるまでdicに素因数を詰め続ける
    while not res in prime_set:
        if res % prime_list[i] == 0:
            dic[prime_list[i]] += 1
            res //= prime_list[i]
        
        else:
            i += 1
            if i >= len(prime_list):
                break
            
    dic[res] += 1
    
    return dic

# 入力
import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())


MOD = 10**9 + 7
n = ni()

# nまでの素数リストを作る
prime_list = make_prime_list(0,n+1)

# 素因数の辞書
dic = defaultdict(int)
for num in range(2,n+1):
    fac = factoring(num, prime_list)
    for k,v in fac.items():
        dic[k] += v

# 約数は各素因数の数を+1して掛け算したもの
ans = 1
for v in dic.values():
    ans = ans*(v+1) % MOD
    
print(ans)

Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef string str;
static const long long INF = 1LL<<59;
static const long long MOD = (ll)1e9+7;

#define endl "\n"
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define REP(i, n) for(ll i=0;i<n;i++)
#define SZ(v) (ll)((v).size())
#define WHOLE(v) (v).begin(), (v).end()
#define ASC(v) sort((v).begin(), (v).end())
#define DESC(v) sort((v).rbegin(), (v).rend())
#define INV(v) reverse((v).begin(), (v).end())
#define FOLDL(src, dst, lambda) partial_sum((src).begin(), (src).end(), (dst).begin(), lambda)
#define FOLDR(src, dst, lambda) INV(src);partial_sum((src).begin(), (src).end(), (dst).begin(), lambda);INV(dst)
#define CUMSUML(src, dst) FOLDL(src, dst, [](auto a, auto b) {return a+b;})
#define CUMSUMR(src, dst) FOLDR(src, dst, [](auto a, auto b) {return a+b;})
#define ACCUM(v, d0, lambda) accumulate((v).begin(), (v).end(), d0, lambda)
#define SUM(v, d0) ACCUM(v, d0, [](auto a, auto b) {return a+b;})
#define ERASE(v, i) v.erase(v.begin() + i)
#define UNIQ(v) ASC(v);v.erase(unique(v.begin(), v.end()), v.end())

template <typename T>void debug(T t) {cerr << t << endl;}
template <typename T, typename ...Args>void debug(T t, Args ...args) {cerr << t << " ";debug(args...);}
template <typename T>void out(T t) {cout << t << endl;}
template <typename T, typename ...Args>void out(T t, Args ...args) {cout << t << " ";out(args...);}

void solve() {
    ll N, M;
    cin >> N >> M;
    vll s(N+1), t(N+1);
    REP(i, M) {
        ll l, r;
        cin >> l >> r;
        s[l]++;
        s[r+1]--;
    }
    CUMSUML(s, t);
    ll ans = 0;
    REP(i, N+1) {
        if(t[i]==M) ans++;
    }
    out(ans);
}

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

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

using namespace std;
int N,SUM=0;
vector<int>vec;
int main(){
  cin>>N;
  int arr[N];
  for(int i=0;i<N;i++){
    cin>>arr[i];
    SUM=SUM+arr[i];
    if(arr[i]%10!=0){
      vec.push_back(arr[i]);
    }
  }
  sort(vec.begin(),vec.end());
  if (SUM%10!=0){
    cout<<SUM;
  }
  else if(SUM%10==0&&vec.size()!=0){
    SUM=SUM-vec[0];
    cout<<SUM;
  }
  else{
    SUM=0;
    cout<<SUM;
  }
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <cstring>
#include <ctime>
using namespace std;
typedef long long ll;
const int maxn = 100005;

int a[7];
//0,1,3,4
int main() {
  // freopen("in.cpp","r",stdin);
    for(int i=0; i<7; i++)cin>>a[i];
    ll ret = 0;
    int tt = min(min(a[0],a[3]),a[4]);
    for(int i=0; i<=tt&&i<=10; i++) {
        ll tmp = (tt - i) * 3LL;
        tmp+= (a[0] - (tt - i))/2*2;
        tmp+= (a[3] - (tt - i))/2*2;
        tmp+= (a[4] - (tt - i))/2*2;
        ret=max(ret,tmp);
    }
    cout<<ret+a[1]<<endl;
    return 0;
}


Measured memory_bytes: 384
/*
ID: zhaowei10
TASK:
LANG: C++
*/
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define mp make_pair
#define eb emplace_back
#define pb push_back
#define MOD 1000000007
#define NDIG(x) floor(log10(x)) + 1
#define FOR(i, j, k, l) for (s32 i = j; i < k; i += l)
#define RFOR(i, j, k, l) for (s32 i = j; i >= k; i -= l)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define ALL(x) x.begin(), x.end()
#define MEAN(a, b) min(a, b) + (abs(b - a) >> 1)
#define FASTIO()    \
  cin.tie(nullptr); \
  ios::sync_with_stdio(false);

typedef long long ll;
typedef int64_t s64;
typedef uint64_t u64;
typedef int32_t s32;
typedef uint32_t u32;
typedef float f32;
typedef double f64;
typedef long double f80;
typedef pair<s32, s32> II;
typedef pair<s64, s64> LL;
typedef vector<s32> VI;
typedef vector<II> VII;
typedef vector<char> VC;
typedef vector<VII> VVII;
typedef priority_queue<s32> PQI;
typedef priority_queue<s32, VI, greater<s32>> PQIA;
typedef priority_queue<s64> PQL;
typedef priority_queue<II> PQII;
typedef priority_queue<II, VII, greater<II>> PQIIA;
typedef priority_queue<LL> PQLL;
typedef unordered_set<s32> USI;
typedef unordered_set<s64> USL;
typedef set<II> SII;
typedef multiset<s32> MSI;

int main() {
  FASTIO();

  int h, a;
  cin >> h >> a;
  cout << ceil((f64)h / a);
}

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

#define REP(i,s,n) for(int i=s; i<n; ++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

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

int main(){

	int a, b;
	cin >> a >> b;
	if((a+b)%2 == 0) cout << (a+b)/2 << endl;
	else cout << (int)((a+b)/2) + 1 << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<limits.h>
#include<utility>
#include<bits/stdc++.h>
#include<vector>
#include<tuple>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(A) A.begin(),A.end()


int main() {
	int n, w;
	cin >> n >> w;
	vector<P> a(n);
	rep(i, n) {
		cin >> a[i].first >> a[i].second;
	}
	vector<int> p(w + 1,0);
	for (int i = 1; i < w + 1;i++) {
		//cout << i << " ";
		p[i] = p[i - 1];

		for (int j = 0; j < n;j++) {
			if (i >= a[j].second) {
				//cout << p[i]<<"→";
				p[i] = max(p[i - a[j].second] + a[j].first, p[i]);
				//cout << p[i] << " ";
			}
		}
		//cout << p[i] << endl;
	}
	cout << p[w] << endl;
}




Measured memory_bytes: 3144
#include<iostream>
#include<vector>

using namespace std;

class IData{
public:
    int n;
    int x;
    IData(int nn, int xx) : n(nn), x(xx) {}
};

int main(){
    int n,x;
    int counter = 0;
    vector<IData> data;
    while(1){
        cin >> n >> x;
        if(n == 0 && x == 0) break;
        data.push_back(IData(n, x));
    }

    // return 0;
    
    for(vector<IData>::size_type m = 0; m < data.size(); m++){
        counter = 0;
        for(int i = 1; i < data[m].n - 1; i++){
            for (int j = i + 1; j < data[m].n; j++){
                for(int k = j + 1; k < data[m].n + 1; k++){
                    if(i + j + k == data[m].x) counter++;
                    // cout << "test" << endl;
                }
            }
        }
        cout << counter << endl;
    }
    
    
    return 0;
}


Measured memory_bytes: 3096
defmodule Main do

  def main do
    k = IO.gets("") |> String.trim() |> String.to_integer()
    case {rem(k, 2), rem(k, 5)} do
      {0, _} -> IO.puts(-1)
      {_, 0} -> IO.puts(-1)
      _ -> search(7, 1, k) |> IO.puts()
    end
  end

  defguard ok?(n, k) when rem(n, k) == 0

  def search(n, i, k) when ok?(n, k), do: i
  def search(n, i, k) do
    n*10+7 |> rem(k) |> search(i+1, k)
  end

end


Measured memory_bytes: 30756
import sys
from collections import defaultdict, deque, Counter
import math

# import copy
from bisect import bisect_left, bisect_right
# import heapq

# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)


def nck(n, k, kaijyo):
    return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD


def npk(n, k, kaijyo):
    if k == 0 or k == n:
        return n % MOD
    return (kaijyo[n] * divide(kaijyo[n-k])) % MOD


def kaijyo(n):
    ret = [1]
    for i in range(1, n + 1):
        ret.append((ret[-1] * i)% MOD)
    return ret


def solve():
    n = getN()
    s = getS()
    c = Counter(s)
    ans = 1
    for v in c.values():
        # print(v)
        ans *= v + 1
        ans %= MOD

    print(ans-1)


def main():
    n = getN()
    for _ in range(n):
        solve()


if __name__ == "__main__":
    # main()
    solve()

Measured memory_bytes: 73704
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>

using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const int MINF = -1e9;


int cnt[2][101010];

int main() {
	
	int n;
	cin >> n;
	vector<int> v(n);

	set<int> st;

	rep(i, n) {
		int x;
		cin >> x;
		v[i] = x;
	}
	map<int, int> cnt[2];
	rep(i,n) {
		cnt[i % 2][v[i]]++;
	}

	vector<pair<int, int>> pairs[2];
	for (int k = 0; k < 2; k++) {
		cnt[k][0] = 0;
		for (auto&& p : cnt[k]) pairs[k].push_back({ p.second, p.first });
		sort(pairs[k].rbegin(), pairs[k].rend());
	}

	int ans;
	if (pairs[0][0].second != pairs[1][0].second) {
		ans = n - pairs[0][0].first - pairs[1][0].first;
	}
	else {
		ans = n - max(pairs[0][1].first + pairs[1][0].first, pairs[0][0].first + pairs[1][1].first);
	}

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


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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")

int K[210000];
int main()
{
	int N;
	cin >> N;

	vec(P);

	fx(N) {
		vecp(P);
		K[P[x]] = x;
	}

	int sum = 0;
	int l = 1, r = 1;
	while (l<=N) {
		while (K[r]<K[r+1]) {
			r++;
		}
		sum = max(sum, r - l + 1);
		l = ++r;
	}
	

	ce(N-sum)
    return 0;
}



Measured memory_bytes: 2168
#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Bytes, Chars, Isize1, Usize1},
};

#[allow(unused_macros)]
macro_rules! echo {
    ($($e:expr),+) => ( { $(println!("{}", $e))+ } );
}

fn calc(i: usize, day: usize, s: &Vec<Vec<isize>>, c: &Vec<isize>, last: &mut Vec<usize>) -> isize {
    last[i] = day;
    let up = s[day - 1][i];
    let mut down = 0;

    for j in 0..26 {
        down += (day - last[j]) as isize * c[j];
    }

    up - down
}

fn main() {
    input! {
        d: usize,
        c: [isize; 26],
        s: [[isize; 26]; d],
    }

    let mut score = 0;
    let mut last = vec![0; 26];

    let mut tmp_dec_max = (0, 0);
    for e in c.iter().enumerate() {
        if tmp_dec_max.1 < *e.1 {
            tmp_dec_max = (e.0, *e.1);
        }
    }

    for day in 1..=d {
        let mut tmp_inc_max = (0, 0);
        for i in 0..26 {
            if tmp_inc_max.1 < s[day - 1][i] {
                tmp_inc_max = (i, s[day - 1][i]);
            }
        }

        let target: usize;

        if tmp_inc_max.0 == tmp_dec_max.0 {
            target = tmp_inc_max.0;
        } else if tmp_inc_max.1 > tmp_dec_max.1 {
            target = tmp_inc_max.0;
        } else {
            target = tmp_dec_max.0;
        };
        echo!(target + 1);
        // score += calc(tmp_inc_max.0, day, &s, &c, &mut last);
    }

    // score += 10_isize.pow(6);
    // score = std::cmp::max(0, score);

    // dbg!(score);
}


Measured memory_bytes: 2328
/**
 * C - Train Ticket
 */

#include <iostream>

using namespace std;

string N;

bool rec(int, int, string);

int main() {
    cin >> N;
    if (rec(1, N[0] - '0', N.substr(0, 1))) return 0;
}

bool rec(int p, int s, string e) {

    if (p == 4) {
        if (s == 7) {
            cout << e + "=7" << endl;
            return true;
        } else {
            return false;
        }
    }

    return rec(p + 1, s + (N[p] - '0'), e + "+" + N[p])
           || rec(p + 1, s - (N[p] - '0'), e + "-" + N[p]);
}

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

int main()
{
  ll n, p;
  string s;
  cin >> n >> p >> s;

  if ( 10 % p  == 0 ) { // 2 or 5                                               
    ll ans = 0;
    rep(r, n) {
      if ( ( s[r] - '0' ) % p == 0 ){
        ans += r + 1;
      }
    }
    cout << ans << endl;
    return 0;
  }

  vector<ll> d(n+1);
  ll ten = 1;
  vector<ll> cnt(p);
  cnt[0] += 1;
  for (int i = n-1 ; i >= 0; --i) {
    ll a = (s[i] - '0') * ten % p;
    d[i] = (d[i+1]+a) % p;
    ten *= 10; ten %= p;
    cnt[d[i]]++;
  }
  ll ans = 0;                                                                         
  rep(i,p) ans += cnt[i] * (cnt[i]-1) / 2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2180
function main(input){
  const lines = input.split('\n');

  const HW = lines.shift().split(' ').map(x => parseInt(x));
  const H = HW[0];
  const W = HW[1];
  const C = [];
  for(var i=0;i<10;i++){
    C.push( lines.shift().split(' ').map(x => parseInt(x)) );
  }
  const A = [];
  for(var i=0;i<H;i++){
    A.push( lines.shift().split(' ').map(x => parseInt(x)) );
  }

//console.log(H);
//console.log(W);
//console.log(C);
//console.log(A);

  for(var k=0;k<10;k++){
    for(var i=0;i<10;i++){
      for(var j=0;j<10;j++){
        C[i][j] = Math.min(C[i][j], C[i][k] + C[k][j]);
      }
    }
  }

//console.log(C);

  var result = 0;
  for(var i=0;i<H;i++){
    for(var j=0;j<W;j++){
      var current_from = A[i][j];
      if(current_from >= 0){
        //console.log([current_from,C[current_from][1],i]);
        result += C[current_from][1];
      }
    }
  }

  console.log(result);  


}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


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

int main()
{
    int n;
    cin >> n;
    int c = 0;
    for(int i = 1; i <= n; i++){
        ostringstream str1;
        str1 << i;
        string s = str1.str();
        if(s.size() % 2 != 0){
            c++;
        }
    }
    cout << c << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long int knapSack(int W, int wt[], int val[], int n) 
{ 
   int i, w; 
   long long int K[n+1][W+1]; 
  
   // Build table K[][] in bottom up manner 
   for (i = 0; i <= n; i++) 
   { 
       for (w = 0; w <= W; w++) 
       { 
           if (i==0 || w==0) 
               K[i][w] = 0; 
           else if (wt[i-1] <= w) 
                 K[i][w] = std::max(val[i-1] + K[i-1][w-wt[i-1]],  K[i-1][w]); 
           else
                 K[i][w] = K[i-1][w]; 
       } 
   } 
  
   return K[n][W]; 
} 


int main() {
	int n,w;
	cin>>n>>w;
	int weight[n],value[n];
	for(int i=0;i<n;i++)
	{
		cin>>weight[i]>>value[i];
	}
	cout<<knapSack(w,weight,value,n)<<"\n";
	
	return 0;
}

Measured memory_bytes: 79104
#include <iostream>
#include <string>

using namespace std;
int main() {
  int i = 0;
  cin >> i;
  switch (i % 10) {
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
        cout << "hon" << endl;
        break;
    case 0:
    case 1:
    case 6:
    case 8:
        cout << "pon" << endl;
        break;
    case 3:
        cout << "bon" << endl;
        break;
  }
}


Measured memory_bytes: 3640
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
A,B,C,D = map(int,input().split())
T = 0
while A>0 and C>0:
    if T%2 == 0:
        C = C-B
        T += 1
    else:
        A = A-D
        T += 1

if A>C:
    print("Yes")
else:
    print("No")
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


Measured memory_bytes: 9152