akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main{
 public static void main(String args[]){
   Scanner sc = new Scanner(System.in);
   int n = sc.nextInt();
   int[] pos = new int[n];
   for(int i=0;i<n;i++){
     pos[i]=sc.nextInt();
   }
   int min = Integer.MAX_VALUE;
   for(int i=0;i<=100;i++){
     int total=0;
     for(int j=0;j<n;j++){
       total+=(pos[j]-i)*(pos[j]-i);
     }
     if(total<min)min=total;
   }
   System.out.println(""+min);
 }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int N,K;
  cin>>N>>K;
  map<int,int> A;
  for(int i=0;i<N;i++){
    int a;
    cin>>a;
    A[i]=a-1;
  }
  map<int,int> B;
  int j=0,k=0;
  bool bo=true;
  for(int i=0;i<min(N,K);i++){
    if(B.count(j)){
      k=B[j]-i;
      bo=false;
      break;
    }
    B[j]=i;
    j=A[j];
  }
  if(bo){
    cout<<j+1<<endl;
    return 0;
  }
  K=(K-B[j])%k;
  for(int i=0;i<K;i++)
    j=A[j];
  cout<<j+1<<endl;
}

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

int main(void){
  int N,X,i,l[105],count,dis,k;
  char str[1000],*p;
  
  fgets(str,sizeof(str),stdin);
  p=strtok(str," \n");
  N=atoi(p);
  p=strtok(NULL," \n");
  X=atoi(p);
  
  l[0]=0;
  fgets(str,sizeof(str),stdin);
  p=strtok(str," \n");
  l[1]=atoi(p);
  
  for(i=2;i<N+1;i++){
    p=strtok(NULL," \n");
  	l[i]=atoi(p);
  }
  dis=l[0],count=0,k=0;
  
  while(dis<=X && k<N){
    count++,k++;
    dis+=l[k];
    if(k==N && dis<=X){
      count++;
    }
  }
  
  printf("%d\n",count);
  
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <deque>

using namespace std;
using ll = long long;

inline int calc(const int a, const int b)
{
    return min(4, (int)pow(a, b));
}

int main()
{
    int N;
    cin >> N;
    deque<ll> A;
    deque<ll> B;
    deque<ll> C;  //ABC
    int zero = 0;
    int one = 0;
    int two = 0;
    int three = 0;
    for (int i = 0; i < N; i++) {
        ll x;
        cin >> x;
        if (x <= 3) {
            if (x <= 1) {
                C.push_back(x);
            } else {
                A.push_back(x);
            }
        } else {
            B.push_back(x);
        }
        if (x == 0) {
            zero++;
        } else if (x == 1) {
            one++;
        } else if (x == 2) {
            two++;
        } else if (x == 3) {
            three++;
        }
    }
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());
    if (one > 0 and zero % 2 == 1) {
        for (int i = 0; i < C.size() - 1; i++) {
            if (C[i] == 0 and C[i + 1] == 1) {
                C[i] = 1;
                C[i + 1] = 0;
                break;
            }
        }
    }
    if (one > 0 or zero % 2 == 0) {
    } else {
        if (A.empty()) {
            if (not B.empty()) {
                const ll f = B.front();
                B.pop_front();
                C.push_back(f);
                swap(C[C.size() - 1], C[C.size() - 2]);
            }
        } else {
            const ll f = A.front();
            if (f == 2) {
                two--;
            } else if (f == 3) {
                three--;
            }
            A.pop_front();
            C.push_back(f);
            swap(C[C.size() - 1], C[C.size() - 2]);
        }
    }
    if (B.empty() and A.size() >= 2) {
        if (A[A.size() - 2] == 2 and A[A.size() - 1] == 3) {
            A[A.size() - 2] = 3;
            A[A.size() - 1] = 2;
        }
    }
    for (const ll x : A) {
        cout << x << endl;
    }
    for (const ll x : B) {
        cout << x << endl;
    }
    for (const ll x : C) {
        cout << x << endl;
    }
    return 0;
}



Measured memory_bytes: 3140
from heapq import heappush, heappop
N,M = map(int, input().split())
a = [[int(i) for i in input().split()] for i in range(N)]

a = sorted(a, key=lambda x:(x[0]))

hq = []
ans = 0
j = 0
for i in range(1,M+1):
	if j < N:
		while a[j][0] == i:
			heappush(hq, -a[j][1])
			j += 1
			if j == N:
				break
	if hq:
	 	ans -= heappop(hq)
    
print(ans)


Measured memory_bytes: 25720
class common_function():
    """
        1. よく使いそうで予め用意しておいた変数をまとめた
        2. よく使いそうな関数群をまとめた
    """
    def __init__(self):
        """
            1. 英字の一覧をリストに格納しておいた変数
        """
        self.sletter = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
        self.bletter = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']


def main():
    common = common_function()
    s = list(input())
    K = int(input())
    t = [0]
    for i in range(len(common.sletter)-1, 0, -1):
        t.append(i)

    u = []
    for i in range(len(s)):
        u.append(t[common.sletter.index(s[i])])
    
    ans = ''
    for i in range(len(s)-1):
        if u[i] <= K:
            ans += 'a'
            K -= u[i]
        else:
            ans += s[i]
    K = K%26
    if u[len(s)-1] <= K:
        K -= u[len(s)-1]
        ans += common.sletter[K]
    else:
        ans += common.sletter[common.sletter.index(s[len(s)-1])+K]
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 10908
a = gets.to_i

b = gets.chomp.split.map(&:to_i)

c = gets.chomp.split.map(&:to_i)

d = gets.chomp.split.map(&:to_i)

reselt = 0

c.each do |c|
	reselt += c
end

i = 0

while i < a
	if b[i+1] == (b[i]+1) && i < a-1
		reselt += d[b[i]-1]
	end
	i += 1
end

puts reselt

Measured memory_bytes: 1788
#include<iostream>

using namespace std;

int main(){
    int A,B,C,X;
    int ans = 0;
    cin >> A >> B >> C >> X;
    for(int a = 0;a <= A;a++){
        for(int b = 0; b <= B;b++){
            for(int c = 0;c <= C;c++){
                int sum = a * 500 + b * 100 + c * 50;
                if((sum) == X){
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;
}

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


int main() {
  int A, B;
  cin >> A >> B;
  int result = 0;
  for (int i = A; i <= B; ++i) {
    int num = i;
    vector<vector<int>> cnt(2, vector<int>(10, 0));
    for (int j = 4; 0 <= j; --j) {
      int ans = num / pow(10, j);
      if (j == 0 || j == 4) {
        ++cnt[0][ans];
      } else if (j == 1 || j == 3) {
        ++cnt[1][ans];
      }
      num -= ans * pow(10, j);
    }
    int c = 0;
    for (int j = 0; j < 2; ++j) {
      for (int k = 0; k < 10; ++k) {
        if (cnt[j][k] == 2) {
          ++c;
          break;
        }
      }
    }
    if (c == 2) {
      ++result;
    }
  }
  cout << result << endl;
}

Measured memory_bytes: 256
n,K=map(int,input().split())
d_=[]
a=[int(i) for i in input().split()]
S=sum(a)

i=1
while i*i<=S:
  if S%i==0:
    d_.append(i)
    d_.append(S//i)
  i+=1

d_.sort()
for d in d_[::-1]:
  b=[]
  B=0
  for i in range(n):
    b.append(a[i]-d*(a[i]//d))
    B+=b[-1]
  b.sort()
  
  flag=False
  for k in range(n+1):
    if sum(b[0:k])<=min(K,K+B-d*(n-k)):
      flag=True
      break
  if flag:
    break
print(d)
      
    
    
  
  

Measured memory_bytes: 44380
s = input()
n = len(s)
a1 = [0] * (n+1) # 左側に連続する<の個数
a2 = [0] * (n+1) # 右側に連続する>の個数
tmp1 = 0
tmp2 = 0
for i in range(n):
    if s[i] == "<": tmp1 += 1
    else: tmp1 = 0
    if s[n-i-1] == ">": tmp2 += 1
    else: tmp2 = 0
    a1[i+1] = tmp1
    a2[n-i-1] = tmp2
ans = 0
for i in range(n+1):
    ans += max(a1[i], a2[i])
print(ans)

Measured memory_bytes: 27324
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    B = list(map(int, input().split()))

    res = []
    for i in range(n):
        L = len(B)
        for j in reversed(range(L)):
            if j + 1 == B[j]:
                b = B.pop(j)
                res.append(b)
                break
        else:
            print(-1)
            break
    else:
        print(*res[::-1], sep="\n")


if __name__ == '__main__':
    resolve()


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

int main() {
    for (;;) {
        int H, W;
        cin >> H >> W;

        if (H == 0 && W == 0) {
            break;
        } else {
            for (int i = 0; i < H; ++i) {
                for (int j = 0; j < W; ++j) {
                    cout << "#";
                }
                cout << endl;
            }
            cout << endl;
        }
    }
}

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

int getResult(int N, int H, int W){
  int hPattern = N - H + 1;
  int wPattern = N - W + 1;
  if(hPattern <= 0 || wPattern <= 0) return 0;
  return hPattern * wPattern;
}

int main(){
  int N, H, W;
  cin >> N >> H >> W;
  
  int result = getResult(N, H, W);
  cout << result;
  return 0;
}

Measured memory_bytes: 3604
#!/usr/bin/env python
n = int(input())
va = list(map(int, input().split()))

res = set()
cnt = 0
for a in va:
    if a // 400 < 8:
        res.add(a // 400)
    else:
        cnt += 1

if len(res) == 0:
    print(1, cnt)
else:
    print(len(res), len(res) + cnt)


Measured memory_bytes: 3060
#include<stdio.h>
int main(void)
{
	int a,b;
	int c[28];
	for(a=0;a<28;a++){
		scanf("%d",&c[a]);
	}
	for(a=1;a<31;a++){
		for(b=0;b<28;b++){
			if(a!=c[b]&&b==27){
				printf("%d\n",a);
			}
			else if(a==c[b]){
				break;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
typedef long long int lint;
using namespace std;

//セグメント木
// ref:https://ei1333.github.io/luzhiled/snippets/structure/segment-tree.html
template <typename Mnd>
struct segment_tree {
    int n;
    vector<Mnd> data;
    function<Mnd(Mnd, Mnd)> op;
    Mnd e;
    //サイズだけ指定して初期化
    segment_tree(int sz, function<Mnd(Mnd, Mnd)> f, Mnd a) : op(f), e(a) {
        n = 1;
        while (n < sz) n *= 2;
        data.assign(n * 2, e);
    }
    // vectorで要素を指定して初期化
    segment_tree(vector<Mnd> v, function<Mnd(Mnd, Mnd)> f, Mnd a)
        : op(f), e(a) {
        n = 1;
        while (n < (int)v.size()) n *= 2;
        data.assign(n * 2, e);
        for (int i = 0; i < (int)v.size(); i++) {
            *this[i] = v[i];
        }
    }
    //参照渡しなので代入とかもできる
    Mnd& operator[](const int& k) {
        return data[k + n];
    }
    //木を構築 O(n)
    void build() {
        for (int i = n - 1; i > 0; i--) {
            data[i] = op(data[2 * i], data[2 * i + 1]);
        }
    }
    //更新しつつ木を再構築 O(log n)
    void update(int k, Mnd x) {
        (*this)[k] = x;
        k += n;
        while (k >>= 1) {
            data[k] = op(data[2 * k], data[2 * k + 1]);
        }
    }
    //[a,b)でのクエリに答える　O(log n)
    Mnd query(int a, int b) const {
        Mnd l = e, r = e;
        for (a += n, b += n; a < b; a /= 2, b /= 2) {
            if (a % 2 == 1) l = op(l, data[a++]);
            if (b % 2 == 1) r = op(r, data[--b]);
        }
        return op(l, r);
    }
};

int main() {
    int n, q;
    cin >> n >> q;
    segment_tree<int> seg(
        n, [](int a, int b) { return min(a, b); }, INT_MAX);
    for (int i = 0; i < q; i++) {
        int com, x, y;
        cin >> com >> x >> y;
        if (com) {
            cout << seg.query(x, y + 1) << endl;
        } else {
            seg.update(x, y);
        }
    }
}


Measured memory_bytes: 3884
from collections import Counter

N = int(input())
d = list(map(int, input().split()))
max_d = max(d)
c = Counter(d)
mod = 998244353

if d[0] != 0:
    print(0)
    exit()

if N == 1:
    if d[0] == 0:
        print(1)
    else:
        print(0)
    exit()

if c[0] != 1:
    print(0)
    exit()

ans = 1
prev = 1
for i in range(1, max_d + 1):
    if c[i] == 0:
        ans = 0
    ans = (ans * pow(prev, c[i], mod)) % mod
    prev = c[i]

print(ans)


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

#define pb push_back

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const ll MOD = 1e9+7;
const ll INF = (ll)1<<62;
const double PI = 3.14159265359;

const int maxn = 3005; 
ll dp[maxn][maxn];

int main(){
	int n;
	ll pre[maxn];
	string s;
	cin>>n>>s;

	dp[1][1] = 1;
	pre[0] = 0;
	pre[1] = 1;

	for(int len=2;len<=n;len++){
		for(int curr=1;curr<=len;curr++){
			dp[len][curr] = 0;
			/*for(int last=1;last<len;last++){
				if(s[len-2] == '<' && curr>last)
					dp[len][curr] = (dp[len][curr]+dp[len-1][last])%MOD;
				if(s[len-2] == '>' && curr<=last)
					dp[len][curr] = (dp[len][curr]+dp[len-1][last])%MOD;

				if(dp[len][curr] < 0)
					dp[len][curr] += MOD;
			}*/

			if(s[len-2] == '<')
				dp[len][curr] = pre[curr-1];
			else
				dp[len][curr] = pre[len-1]-pre[curr-1];
		}
		pre[0] = 0;
		for(int i=1;i<=len;i++){
			pre[i] = (pre[i-1]+dp[len][i])%MOD;
			if(pre[i] < 0)
				pre[i] += MOD;
		}
	}

	ll ans = 0;
	for(int i=1;i<=n;i++){
		ans = (ans+dp[n][i])%MOD;
		if(ans < 0)
			ans += MOD;
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 69120
#include <vector>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)
#define SORT(c) sort((c).begin(),(c).end())

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

  int n;
  cin >> n;
  vector< pair<int, int> > red(n), blue(n);
  vector<bool> matchedR(n);

  REP(i, n) {
    int x, y;
    cin >> x >> y;
    red[i] = make_pair(x, y);
    matchedR[i] = false;
  }

  REP(i, n) {
    int x, y;
    cin >> x >> y;
    blue[i] = make_pair(x, y);
  }

	SORT(blue);

	int ans = 0;

	REP(i, n) {
		int a=-1,b=-1;

		REP(j, n) {
			if (blue[i].first > red[j].first && blue[i].second > red[j].second) {
        if (red[j].second > b && !matchedR[j]) {
          a = j;
          b = red[j].second;
        }
			}
		}

		if (a != -1) {
			matchedR[a] = true;
			ans++;
		}
	}

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}
const int MOD=1000000007;

int main() {
  int64_t S;
  cin>>S;
  int64_t v=1000000000;
  int64_t x1=(S+v-1)/v;
  int64_t y1=v*x1-S;
  cout<<0<<" "<<0<<" "<<x1<<" "<<y1<<" "<<1<<" "<<v<<endl;
  return 0;
}

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

int main(){
  int N;
  int X;
  cin >> N >> X;
  vector<int> m(N);
  
  int i;
  for(i = 0;i < N;i++){
    cin >> m.at(i);
  }
  
  int sum = 0;
  for(int j = 0;j < N;j++){
    sum += m.at(j);
  }
  
  sort(m.begin(),m.end());
  int nokori = (X - sum)/m.at(0);
  
  int kekka = N + nokori;
  
  cout << kekka << endl;
}

Measured memory_bytes: 256
def main():
    import heapq
    x,y,a,b,c = map(int,input().split())
    p = sorted(list(map(int,input().split())),reverse=True)[0:x]
    q = sorted(list(map(int,input().split())),reverse=True)[0:y]
    r = sorted(list(map(int,input().split())),reverse=True)
    P,Q = [],[]
    for i in range(x):
        heapq.heappush(P,p[i])
    for i in range(y):
        heapq.heappush(Q,q[i])
    for i in range(c):
        p,q = heapq.heappop(P), heapq.heappop(Q)
        if p>q:
            heapq.heappush(P,p)
            if r[i]>q:
                heapq.heappush(Q,r[i])
            else:
                heapq.heappush(Q,q)
        else:
            heapq.heappush(Q,q)
            if r[i]>p:
                heapq.heappush(P,r[i])
            else:
                heapq.heappush(P,p)
    print(sum(P)+sum(Q))

if __name__ == "__main__":
    main()


Measured memory_bytes: 28468
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<string>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
vector<int> input(int n) {
    vector<int> vec(n);
    for (int i = 0; i < n; i++) {
        cin >> vec.at(i);
    }
    return vec;
}
void output(vector<int> vec) {
    for (int i = 0; i < vec.size(); i++) {
        cout << vec[i] << " ";
    }
    return;
}
vector<int> sort(vector<int> vec) {
    vector<int> sorted(vec.size(),0);
    sort(vec.begin(), vec.end());
    rep(i, vec.size()) {
        sorted[i] = vec[i];
    }
    return sorted;
}
vector<int> resort(vector<int> vec) {
    sort(vec);
    reverse(vec.begin(), vec.end());
    return vec;
}
vector<vector<int>> input(int n, int m) {
    vector<vector<int>> table(n, vector<int>(m));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> table. at(i).at(j);
        }
    }
    return table;
}
void output(vector<vector<int>> table) {
    for (int i = 0; i < table.size(); i++) {
        for (int j = 0; j < table.at(0).size(); j++) {
            cout << table.at(i).at(j) << " ";
        }
        cout << endl;
    }
}
long long perm(int n, int r) {
    if (n < r) {
        cout << "error" << endl;
        return 0;
    }
    long long perm = 1;
    for (int i = n; i > n - r; i--) {
        perm *= i;
    }
    return perm;
}
long long comb(int n, int r) {
    if (n < r) {
        cout << "error" << endl;
        return 0;
    }
    long long comb = perm(n,r);
    for (int i = r; i > 0; i--) {
        comb /= i;
    }
    return comb;
}
long long homo(int n, int r) {
    return comb(n + r - 1, n - 1);
}
long long fact(int n) {
    long long fact = 1;
    for (int i = n; i > 0; i--) {
        fact *= i;
    }
    return fact;
}
int gcd(int a, int b)
{
    if (a % b == 0)
    {
        return(b);
    }
    else
    {
        return(gcd(b, a % b));
    }
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int main() {
  string s;
  cin >> s;
  vector<char> c(s.size());
  rep(i,s.size()){
    c[i]=s[i];
  }
  vector<int> x(s.size());
  int sum=0;
  rep(i,s.size()){
    x[i]=ctoi(c[i]);
    sum += x[i];
  }
  if(stoi(s)%sum==0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
import sys
from itertools import product
#from collections import defaultdict
input = sys.stdin.readline
def main():
    N = int( input())
    A = [[0]*N for _ in range(N)]
    C = [0]*N
    for i in range(N):
        C[i] = int( input())
        for _ in range(C[i]):
            x, y = map( int, input().split())
            A[i][x-1] = -1+y*2
    ans = 0
    T = [-1, 1]
    for P in product( range(-1, 2, 2), repeat = N):
        check = True
        for i in range(N):
            if P[i] == -1:
                continue
            for j in range(N):
                if A[i][j] == 0:
                    continue
                if A[i][j]*P[i] != P[j]:
                    check = False
                    break
        if check:
            if ans < (sum(P) + N)//2:
                ans = (sum(P) + N)//2
    print(ans)
if __name__ == '__main__':
    main()


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

void solve() 
{
    int x,a;cin>>x>>a;
    cout<<(x<a?0:10)<<endl;
}

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

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX 1000

void initialize();
void push(int);
int pop();
int isEmpty();
int isFull();

int top, S[MAX];

void initialize(){
  top = 0;
}

void push(x){

  if(isFull() == 1 ){
    fprintf(stderr,"エラー（オーバーフロー）\n");
    exit(8);
  }

  else {

    S[++top] = x;
  }
}

int pop(){
  if(isEmpty() == 0 ){
    fprintf(stderr,"エラー（アンダーフロー）\n");
    exit(8);
  }
  top--;
  return S[top+1];
}

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

int isFull(){
  if( top >= MAX-1 ) return 1;
  else return 0;
}
int main(){
  int x,y;
  top = 0;
  char s[100];

  while( scanf("%s",s) != EOF ){
    if(s[0] == '+'){
      x = pop();
      y = pop();
      push( x+y );
    }
    else if(s[0] == '-'){
      y = pop();
      x = pop();
      push( x-y );
    }
    else if(s[0] == '*'){
      x = pop();
      y = pop();
      push(x*y);
    }
    else push(atoi(s));
  }
  printf("%d\n",pop());

  return 0;
}



Measured memory_bytes: 2144
#include<stdio.h>
long long int dp[101][4][4];
int main(void)
{
	int n,k,a,b[101];
	int i,j,t,x,z=0;
	scanf("%d%d",&n,&k);
	for(i=1;i<=n;i++) b[i]=0;
	for(i=1;i<=k;i++){
		scanf("%d",&a);
		scanf("%d",&b[a]);
	}	
	for(i=1;i<=n;i++){
		for(j=1;j<=3;j++){
			for(t=0;t<=3;t++) dp[i][j][t]=0;
		}
	}
	if(b[1]!=0)	dp[1][b[1]][0]=1;
	else{
		for(i=1;i<=3;i++) dp[1][i][0]=1;
	}	
	for(i=1;i<n;i++){
		for(j=1;j<=3;j++){
			for(t=0;t<=3;t++){
				if(dp[i][j][t]!=0){
					if(b[i+1]!=0){
						if(j!=b[i+1]||t!=b[i+1]){
							dp[i+1][b[i+1]][j]+=dp[i][j][t];
							dp[i+1][b[i+1]][j]%=10000;
						}
					}
					else{
						for(x=1;x<=3;x++){
							if(j!=x||t!=x){
								dp[i+1][x][j]+=dp[i][j][t];
								dp[i+1][x][j]%=10000;
							}
						}
					}
				}
			}
		}
	}
	for(i=1;i<=3;i++){
		for(j=1;j<=3;j++) z+=dp[n][i][j];
	}
	z%=10000;
	printf("%d\n",z);
	return 0;
}

Measured memory_bytes: 2660
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <algorithm>

using namespace std;

int distsq(int x1, int y1, int x2, int y2){
	return (x2-x1)*(x2-x1)+(y2-y1)*(y2-y1);
}

// 線分と円の外周との当たり判定
bool checkLineCircle(int tx, int ty, int sx, int sy, int wx, int wy, int wr){
	bool t_in = (distsq(tx, ty, wx, wy) < wr*wr);
	bool s_in = (distsq(sx, sy, wx, wy) < wr*wr);
	if(t_in && s_in) return false; // お互いが中なら接触していない
	if(t_in != s_in) return true; // お互いの中/外が異なれば接触している

	// 線分の始点/終点が円の外部
	int vx = sx - tx; // 始点→終点 へのベクトル
	int vy = sy - ty;
	int cx = wx - tx; // 始点→円の中心 へのベクトル 
	int cy = wy - ty;
	int cv = vx*cx + vy*cy; // cvの内積
	int vv = vx*vx + vy*vy;
	int cc = cx*cx + cy*cy;
	if(cv < 0) return false; // 内積<0 -> 円の中心は線分の始点方向の外
	if(cv > vx*vx+vy*vy) return false; // |c・v|>|v・v| なら 円の中心は終点方向の外
	if( cc-cv*cv/vv <= wr*wr) return true; // c^2 - (c*cosθ)^2 < wr^2 なら接触
	return false;
}

int main(){
	int n, m;
	while(cin >> n, n){
		vector<int> wx(n), wy(n), wr(n);
		for(int i = 0; i < n; i++){
			cin >> wx[i] >> wy[i] >> wr[i];
		}
		cin >> m;

		int tx, ty, sx, sy;
		for(int i = 0; i < m; i++){
			cin >> tx >> ty >> sx >> sy;
			bool safe = false;
			for(int j = 0; j < n; j++){
				if(checkLineCircle(tx, ty, sx, sy, wx[j], wy[j], wr[j])){
					safe = true;
					break;
				}
			}
			if(safe) cout << "Safe" << endl;
			else cout << "Danger" << endl;
		}

	}

	return 0;
}

Measured memory_bytes: 1192
#include<stdio.h>

int main(void)
{
        int n,i,j,a,b,c;

        scanf("%d",&n);

        c=0;
        for(i=1;i<=n;i+=2){
                b = 0;
                for(j=1;j<=i;j++){
                        a = i % j;
                        if(a==0)
                                b++;
                }
                if(b==8)
                c++;
        }

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


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
#define TO(x,t,f) ((x)?(t):(f))
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define FILV(x,a) fill(x.begin(),x.end(),a)
#define FILA(ar,N,a) fill(ar,ar+N,a)
#define NEXTP(x) next_permutation(x.begin(),x.end())
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define pb push_back
#define pri(aa) cout<<(aa)<<endl

const ll INF=1e9+7;
const ll N = 100002;
ll n,a,a4=0,a2=0;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	FOR(i,0,n){
		cin>>a;
		if(a%4==0){
			a4++;
		}else if(a%2==0){
			a2++;
		}
	}
	bool ans=false;
	if(a2>0){
		if(a4>=(n-a4-a2))ans=true;
	}else{
		if((a4+1)>=n-a4)ans=true;
	}
	if(ans)pri("Yes");
	else pri("No");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    while (true) {
        int N, D;
        cin >> N >> D;
        if (N == 0 and D == 0) { break; }
        vector<vector<int>> c(N);
        vector<int> ind(N, 0);
        int sum = 0;
        for (int i = 0; i < N; i++) {
            int M;
            cin >> M;
            sum += M, c[i].resize(M + 1);
            for (int j = 1; j <= M; j++) { cin >> c[i][j]; }
            for (int j = 1; j <= M; j++) { c[i][j] += c[i][j - 1]; }
            reverse(c[i].begin(), c[i].end()), ind[i] = c[i].size() - 1;
        }
        bool ok = true;
        for (int i = 0; ok and i < sum; i++) {
            using P = pair<int, int>;
            multiset<P> m;
            vector<P> v;
            for (int j = 0; j < N; j++) { m.insert({c[j][ind[j]], j}), v.push_back({c[j][ind[j]], j}); }
            ok = false;
            for (auto& p : v) {
                const int i = p.second;
                if (ind[i] == 0) { continue; }
                m.erase(m.find(p)), m.insert({c[i][ind[i] - 1], i - 1});
                if (m.rbegin()->first - m.begin()->first <= D) {
                    ind[i]--, ok = true;
                    break;
                } else {
                    m.insert(p), m.erase(m.find({c[i][ind[i] - 1], i - 1}));
                }
            }
        }
        cout << (ok ? "Yes" : "No") << endl;
    }
    return 0;
}



Measured memory_bytes: 3112
/**
 *    Coded by : lucky_21
 *               --------Lokesh Singh
**/

#include<bits/stdc++.h>
using namespace std;

#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define     F           first
#define     S           second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<int,int>
#define     all(x)      x.begin(),x.end()
#define     fix         fixed<<setprecision(10)
#define     rep(i,a,b)  for(int i=int(a);i<=int(b);i++)
#define     repb(i,b,a) for(int i=int(b);i>=int(a);i--)
#define     FastIO      ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)

typedef double db;
typedef long long ll;

const int N=2e5+5;
const int mod=1e9+7;

ll n,k,a[N];
bool ok[N];
signed main(){
    FastIO;
    cin>>n>>k;
    rep(i,1,n) cin>>a[i];
    deque<int>path;
    path.pb(1);
    int nxt=a[1];
    ok[1]=1;
    while(!ok[nxt]){
        path.pb(nxt);
        ok[nxt]=1;
        nxt=a[nxt];
    }
    int i=0;
    while(path[i]!=nxt) i++;
    if(k<=i) return cout<<path[k],0;
    rep(j,1,i) path.pop_front();
//    cout<<i<<"::"<<path.size()<<endl;
    k-=i;
    int sz=path.size();
    cout<<path[k%sz];
    return 0;
}


Measured memory_bytes: 5888
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

class UnionFind {
public:
    vl parent;  // 親ノード
    vl Siz;  // 集合の大きさ
    
    // コンストラクタ
    UnionFind(ll n): parent(n), Siz(n, 1) {
        rep(i, n) {
            parent[i] = i;
        }
    }

    // n要素で初期化
    void init(ll n) {
        parent.resize(n);
        Siz.assign(n, 1);
        rep(i, n) {
            parent[i] = i;
        }
    }

    // xの属する集合の根を求める
    ll root(ll x) {
        if(parent[x] == x) {
            return x;
        }
        else {
            return parent[x] = root(parent[x]);
        }
    }

    // xとyの属する集合を併合
    void unite(ll x, ll y) {
        x = root(x);
        y = root(y);
        if(x == y) {
            return;
        }
        if(Siz[x] < Siz[y]) {
            swap(x, y);
        }
        Siz[x] += Siz[y];
        parent[y] = x;
    }
    
    // xとyが同じ集合に属するかどうか
    bool same(ll x, ll y) {
        return root(x) == root(y);
    }

    // xの属する集合の要素数を求める
    ll size(ll x) {
        return Siz[root(x)];
    }
};
 
int main() {
    ll n, m;
    cin >> n >> m;

    UnionFind Uni(n+m);
    Uni.init(n+m);
    rep(v, n) {
        ll k;
        cin >> k;
        rep(i, k) {
            ll L;
            cin >> L;
            L--;
            Uni.unite(v, n+L);
        }
    }

    set<ll> st;
    rep(v, n) {
        st.insert(Uni.root(v));
    }
    
    if(st.size() == 1) {
        out("YES");
    }
    else {
        out("NO");
    }
    
    re0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <cmath>
#include <cstdio>
#include <vector>
#include <algorithm>
 
using namespace std;
 
#define EPS 1e-10
#define equal(a,b) (fabs(a-b) < EPS)
#define not_equal(a,b) (!equal(a,b))
#define lt(a,b) (a-b < -EPS)
#define PI acos(-1)
 
struct Point{
  double x,y;
 
  Point(){}
  Point(double x,double y) : x(x),y(y) {}
 
  Point operator + (const Point &p)const{ return Point(x+p.x,y+p.y); }
  Point operator - (const Point &p)const{ return Point(x-p.x,y-p.y); }
  Point operator * (const double &k)const{ return Point(x*k,y*k); }
  Point operator / (const double &k)const{ return Point(x/k,y/k); }
  bool operator < (const Point &p)const{ return x != p.x ? x < p.x : y < p.y; }
};
 
double dot(const Point &a,const Point &b){ return a.x*b.x+a.y*b.y; }
double cross(const Point &a,const Point &b){ return a.x*b.y - b.x*a.y; }
double norm(const Point &p){ return dot(p,p); }
double abs(const Point &p){ return sqrt(norm(p)); }
double dist(const Point &a,const Point &b){
  return sqrt(pow(a.x-b.x,2) + pow(a.y-b.y,2));
}
Point rotate(const Point &p,double th){
  return Point(cos(th)*p.x-sin(th)*p.y,sin(th)*p.x+cos(th)*p.y);
}
Point rotate90(const Point &p){ return Point(-p.y,p.x); }
 
istream &operator >> (istream &is,Point &p){ 
  return is >> p.x >> p.y;
}
 
ostream &operator << (ostream &os,Point &p){ 
  return os << "(" << p.x << "," << p.y << ")";
}
 
#define curr(G,i) (G[i%G.size()])
#define next(G,i) (G[(i+1)%G.size()])
typedef vector<Point> Polygon;
 
int containmentPoP(const Polygon &pg,const Point &p){
  int N = pg.size();
  bool in = false;
  for(int i = 0 ; i < N ; i++){
    Point a = curr(pg,i)-p, b = next(pg,i)-p;
    if(a.y > b.y){ swap(a,b); }
    if(a.y <= 0 && 0 < b.y && cross(a,b) < 0){ in = !in; }
    if(cross(a,b) == 0 && dot(a,b) <= 0){ return 1; }
  }
  return (in ? 2 : 0); 
}
 
int main(){
  int N,Q;
  cin >> N;
  Polygon pg(N);
  for(int i = 0 ; i < N ; i++){
    cin >> pg[i];
  }
  cin >> Q;
  while(Q--){
    Point p;
    cin >> p;
    cout << containmentPoP(pg,p) << endl;
  }
  return 0;
}

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

int main(){
    
  int i,n,q,a,sum=0,c=0;
  cin >> n >> q;
  queue<string> qu1;
  queue<int> qu2;

  for(i=0;i<n;i++){
    string s;
    cin >> s >> a;
    qu1.push(s);
    qu2.push(a);
  }

  while(c!=n){
    a=qu2.front();
    a=a-q;
    sum+=q;
    qu2.pop();
    if(a>0){
      qu2.push(a);
      qu1.push(qu1.front());
      qu1.pop();
    }
    else{
      sum+=a;
      cout << qu1.front() << " " << sum << endl;
      c++;
      qu1.pop();
    }
  }
  return 0;
}

Measured memory_bytes: 4172
def resolve():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    for _ in range(min(k,100)):
        dp = [0] * (n + 1)
        for index, i in enumerate(a):
            dp[max(0, index - i)] += 1
            dp[min(n, index + i + 1)] -= 1
        a[0] = dp[0]
        for i in range(1, n):
            a[i] = a[i - 1] + dp[i]
    print(*a)


if __name__ == '__main__':
    resolve()


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

int main() {
  string S;
  cin>>S;
  int ans = 0;
  rep(i, S.size()){
    int lg = 0;
    
    for(int x=i;x<S.size();x++){
      if(S[x]=='A'||S[x]=='C'||S[x]=='G'||S[x]=='T') lg++;
      else break;
    }
    
    ans=max(ans, lg);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <string>
using namespace std;
int main(void){
    int N, sum = 0;
    int *a;
    cin >> N;
    a = new int[N];
    for(int i = 0; i < N; i++){
        cin >> a[i];
        sum += a[i] - 1;
    }
    cout << sum << endl;
}

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

/*
 b
lurd
 f
*/
struct Dice {
  long long l, r, f, b, d, u, x, y;
  Dice(long long _l = 4, long long _r = 3, long long _f = 2, long long _b = 5,
       long long _d = 6, long long _u = 1, long long _x = 0, long long _y = 0)
      : l(_l), r(_r), f(_f), b(_b), d(_d), u(_u), x(_x), y(_y) {}

  void RollN() {
    long long buff = d;
    d = b;
    b = u;
    u = f;
    f = buff;
    ++y;
  }

  void RollS() {
    long long buff = d;
    d = f;
    f = u;
    u = b;
    b = buff;
    --y;
  }

  void RollE() {
    long long buff = d;
    d = r;
    r = u;
    u = l;
    l = buff;
    ++x;
  }

  void RollW() {
    long long buff = d;
    d = l;
    l = u;
    u = r;
    r = buff;
    --x;
  }

  void RollL() {
    long long buff = f;
    f = l;
    l = b;
    b = r;
    r = buff;
  }

  void RollR() {
    long long buff = f;
    f = r;
    r = b;
    b = l;
    l = buff;
  }

  vector<Dice> makeDice() {
    vector<Dice> ret;
    for (int i = 0; i < 6; i++) {
      Dice d(*this);
      if (i == 1) d.RollN();
      if (i == 2) d.RollS();
      if (i == 3) d.RollS(), d.RollS();
      if (i == 4) d.RollE();
      if (i == 5) d.RollW();
      for (int j = 0; j < 4; j++) {
        ret.emplace_back(d);
        d.RollL();
      }
    }
    return (ret);
  }

  bool operator==(const Dice &di) const {
    return l == di.l && r == di.r && f == di.f && b == di.b && d == di.d &&
           u == di.u;
  }
};

const int ofst = 1200;
long long n;
vector<long long> dp;
vector<vector<long long>> memo;
vector<map<pair<int, int>, int>> v;
long long solve();

int main() {
  while (1) {
    cin >> n;
    if (n == 0) break;
    dp.assign(1LL << n, 0);
    memo.assign(3000, vector<long long>(3000, 0));
    v.clear();
    v.resize(n);
    for (int i = 0; i < n; ++i) {
      int x, y, l, r, f, b, d, u;
      string rot;
      cin >> x >> y >> l >> r >> f >> b >> d >> u >> rot;
      Dice di(l, r, f, b, d, u, x, y);
      int len = rot.size();
      for (int j = 0; j <= len; ++j) {
        memo[di.x + ofst][di.y + ofst] |= 1 << i;
        v[i][make_pair(di.x + ofst, di.y + ofst)] = di.d;
        if (j == len) break;
        if (rot[j] == 'R')
          di.RollE();
        else if (rot[j] == 'L')
          di.RollW();
        else if (rot[j] == 'F')
          di.RollS();
        else
          di.RollN();
      }
    }
    cout << solve() << endl;
  }
  return 0;
}

long long solve() {
  long long res = 0;
  for (int i = 1; i < (1 << n); ++i)
    for (int j = 0; j < n; ++j)
      if (i >> j & 1) {
        long long sum = dp[i - (1 << j)];
        for (auto p : v[j]) {
          int x = p.first.first, y = p.first.second;
          if ((memo[x][y] & i) == (1 << j)) sum += p.second;
        }
        dp[i] = max(dp[i], sum);
        res = max(res, dp[i]);
      }
  return res;
}



Measured memory_bytes: 73848
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;

int main(){
    long long n,t=0;
    cin>>n;
    t+=(n/500)*1000;
    n-=(n/500)*500;
    t+=(n/5)*5;
    cout<<t;
    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
 
using tpl = tuple<int, int, int>;
typedef pair<int,int> pii;

void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}

ll N;
ll A1[200010];
ll A2[200010];

ll dp_pos[200010][16];
ll dp_neg[200010][16];

void solve(ll A[200010], ll dp_pos[200010][16]){
    for(ll pos = N - 1; pos >= 0; pos--){
        for(ll ope_cnt = 0; ope_cnt <= 15; ope_cnt++){ 
            ll res = 1LL << 62;
            if(pos == N - 1) {
                res = 0;
            }
            else{
                // 現在のところの値に対して 4 ^ ope_cnt したものと、次の要素の値を比較し、次の値が何回計算する必要があるか調べる
                ll c_val = A[pos] * (1LL << (ope_cnt * 2));
                if(c_val <= A[pos + 1]){
                    // 操作の必要なし
                    res = dp_pos[pos + 1][0];
                }
                else{
                    // 何回操作したら超えるか調べる
                    // 15を超えた分は、残りの数字をすべて4でかける操作で代用できるので、その分を加算しておくことで代用する
                    // c_val <= A[pos + 1] * (4 ^ n_cnt)となる最小のn_cntを計算する
                    ll n_cnt = 0;
                    ll cmp = (A[pos + 1] + c_val - 1) / A[pos + 1];
                    for(; ; n_cnt++){
                        if(cmp <= 1LL << (n_cnt * 2)){
                            break;
                        }
                    }
                    if(n_cnt > 15){
                        ll diff = n_cnt - 15;
                        res = (N - 1 - pos) * 2 * diff + 15 * 2 + dp_pos[pos + 1][15];
                    }
                    else{
                        res = n_cnt * 2 + dp_pos[pos + 1][n_cnt];
                    }
                }

            }
            dp_pos[pos][ope_cnt] = res;
        }
    }
}

int main(){
    cin >> N;
    for(ll i = 0; i < N; i++){
        cin >> A1[i];
        A2[N - 1 - i] = A1[i];
    }
    
    solve(A1, dp_pos);
    solve(A2, dp_neg);
    
    ll ans = min(dp_pos[0][0], dp_neg[0][0] + N);
    for(ll i = 1; i < N; i++){
        // iから正になる場合
        ans = min(ans, dp_neg[N-i-1][0] + dp_pos[i][0] + i);
    }
    cout<< ans << endl;

    return 0;
}


Measured memory_bytes: 53376
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;

//#define int long long
//using ll = boost::multiprecision::cpp_int;
using ll = long long;
//constexpr int INF = 1e9;//INT_MAX=(1<<31)-1=2147483647
constexpr ll INF = (ll)1e18;//(1LL<<63)-1=9223372036854775807
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-9;
constexpr int dx[4]={1,0,-1,0};
constexpr int dy[4]={0,1,0,-1};
#ifdef LOCAL_ENV
	#define debug(var) std::cout<<#var" = "<<var<<std::endl
#else
	#define debug(var)
#endif
#define p(var) std::cout<<var<<std::endl
#define rep(i, n)   for(ll i=0, i##_length=(n); i< i##_length; ++i)
#define repeq(i, n) for(ll i=1, i##_length=(n); i<=i##_length; ++i)
#define all(a) (a).begin(), (a).end()
#define PI (acos(-1))
template<typename T> inline T power(T x, T n){ return n ? power(x*x%MOD,n/2)*(n%2?x:1)%MOD : 1; }
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a; }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b; }
template<typename T1, typename T2>inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2>inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	for (int i = 0, len = v.size(); i < len; ++i){
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
	for (int i = 0, len = vv.size(); i < len; ++i){
		s << vv[i] << endl;
	}
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const map<T1, T2>& m) {
	s << "{" << endl;
	for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr){
		s << "\t" << (*itr).first << " : " << (*itr).second << endl;
	}
	s << "}" << endl;
	return s;
}

/*-----8<-----8<-----*/

constexpr ll N_MAX = 100000;
constexpr ll V_I_MAX = 100000;

ll N;
ll v[N_MAX];

void input() {
	scanf("%lld", &N);
	rep(i, N) scanf("%lld", v + i);
}

void solve() {
	ll ans = 0;

	map<ll,ll> m0,m1;
	rep(i,N){
		if(i%2){
			m0[v[i]]++;
		}else{
			m1[v[i]]++;
		}
	}

	vector<pair<ll,ll>> v0,v1;
	for(auto m:m0){
		v0.push_back(make_pair(m.second,m.first));
	}
	for(auto m:m1){
		v1.push_back(make_pair(m.second,m.first));
	}
	sort(all(v0));
	sort(all(v1));

	if(v0[v0.size()-1].second==v1[v1.size()-1].second){
		if(v0.size()==1 && v1.size()==1){
			ans+=(N/2);
		}else if(v0.size()==1){
			ans=(N/2-v0[v0.size()-1].first) + (N/2-v1[v1.size()-2].first);
		}else if(v1.size()==1){
			ans=(N/2-v1[v1.size()-1].first) + (N/2-v0[v0.size()-2].first);
		}else if(v0[v0.size()-2].first>v1[v1.size()-2].first){
			ans=(N/2-v1[v1.size()-1].first) + (N/2-v0[v0.size()-2].first);
		}else{
			ans=(N/2-v0[v0.size()-1].first) + (N/2-v1[v1.size()-2].first);
		}
	}else{
		ans=ans=(N/2-v0[v0.size()-1].first) + (N/2-v1[v1.size()-1].first);
	}


	printf("%lld\n", ans);
}

signed main() {
	input();
	solve();
	return 0;
}


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

// APG4b-G
int main() {
  int a,b;
  cin >> a >> b;
  
  string answer = "Odd";
  if (!(a & 0x1) || !(b & 0x1)) answer = "Even";
  cout << answer << endl;
  
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)

typedef struct edge{ll s,g;}E;
E e[200010];
int vnow[100010];
int epre[200010];

int check[100010];
int path1[100010],path2[100010];

int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	rep(i,0,n)vnow[i]=-1;
	
	rep(i,0,m){
		int a,b;
		scanf("%d%d",&a,&b);
		a--;b--;
		e[2*i].s=a;
		e[2*i].g=b;
		epre[2*i]=vnow[a];
		vnow[a]=2*i;
		
		e[2*i+1].s=b;
		e[2*i+1].g=a;
		epre[2*i+1]=vnow[b];
		vnow[b]=2*i+1;
	}
	
	int p1cnt=1;
	path1[0]=0;
	check[0]=1;
	int flag=1;
	while(flag){
		flag=0;
		for(int t=vnow[path1[p1cnt-1]];t!=-1;t=epre[t])if(!check[e[t].g]){
			flag=1;
			path1[p1cnt++]=e[t].g;
			check[e[t].g]=1;
			break;
		}
	}

	int p2cnt=1;
	path2[0]=0;
	flag=1;
	while(flag){
		flag=0;
		for(int t=vnow[path2[p2cnt-1]];t!=-1;t=epre[t])if(!check[e[t].g]){
			flag=1;
			path2[p2cnt++]=e[t].g;
			check[e[t].g]=1;
			break;
		}
	}
	
	printf("%d\n",p1cnt+p2cnt-1);
	for(int i=p2cnt-1;i>=0;i--)printf("%d ",path2[i]+1);
	rep(i,1,p1cnt)printf("%d ",path1[i]+1);
	return 0;
}

Measured memory_bytes: 5760
def resolve():
    import numpy as np
    from decimal import Decimal

    n = int(input())
    A = np.array(list(map(Decimal, input().split())))
    if 0 in A:
        print(0)
        return

    a = Decimal(1)
    for b in A:
        a *= b
        if a > 10**18:
            print(-1)
            return
    print(a)

resolve()

Measured memory_bytes: 48160
#include <stdio.h>

int main(void) {

  int h,w,a,b;
	scanf("%d %d %d %d", &h, &w, &a, &b);
  for (int i = 0; i < b; i++) {
    for (int j = 0; j < a; j++) {
      printf("0");
    }
    for (int j = a; j < w; j++) {
      printf("1");
    }
    printf("\n");
  }
  for (int i = b; i < h; i++) {
    for (int j = 0; j < a; j++) {
      printf("1");
    }
    for (int j = a; j < w; j++) {
      printf("0");
    }
    printf("\n");
  }

  return 0;
}

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

int main(int argc, const char * argv[]) {
    //read
    int n;
    cin>>n;
    int a[n];
    int count = 0;
    
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    
    //solve
    for(int i=0;i<n;i++){
        int minj = i;
        for(int j=i;j<n;j++){
            if(a[j]<a[minj]){
                minj = j;
            }
        }
        if(a[i]!=a[minj]){
            int tmp = a[i];
            a[i]=a[minj];
            a[minj]=tmp;
            count++;
        }
    }
    //output
    cout<<a[0];
    for(int i = 1;i<n;i++){
        cout<<' '<<a[i];
    }
    cout<<endl;
    cout<<count<<endl;
}

Measured memory_bytes: 1164
#include <stdio.h>
int main()
{
    int a,b;
    scanf(" %d%d",&a,&b);
    if((1<=a&&a<=100)&&(1<=b&&b<=100))
        {
        if((a+b)%3==0||a%3==0||b%3==0){printf("Possible");}
        else {printf("Impossible");}
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = n;i >= m;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define ALL(n) n.begin(),n.end()
#define MP make_pair
ll dp[114514][3],in[114514][3];

int main() {
	int n;
	cin >> n;
	REP(i, n) REP(j, 3) cin >> in[i][j];
	REP(i, n) {
		dp[i + 1][0] = max(dp[i][1], dp[i][2]) + in[i][0];
		dp[i + 1][1] = max(dp[i][0], dp[i][2]) + in[i][1];
		dp[i + 1][2] = max(dp[i][1], dp[i][0]) + in[i][2];
	}
	cout << max(dp[n][0], max(dp[n][1], dp[n][2])) << endl;
}

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

#define     F       first
#define     S       second
typedef pair<int, int>  pi;
typedef long long       ll;

int n, k;
bool freq[109];

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

    cin >> n >> k;
    for (int i=1; i<=k; ++i) {
        int c;
        cin >> c;
        while (c--) {
            int s;
            cin >> s;
            freq[s]=1;
        }
    }

    int cnt=0;
    for (int i=1; i<=n; ++i) {
        cnt+=(freq[i]==0);
    }

    cout << cnt;

    return 0;
}


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

using namespace std;
int a[200010]={0};
int n;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)	cin>>a[i];
	sort(a+1,a+n+1);
	for(int i=2;i<=n;i++)
	{
		if(a[i]==a[i-1]){
			cout<<"NO"<<endl;
			return 0;
		}
	}
	cout<<"YES";
	
	return 0;
 } 

Measured memory_bytes: 1024
l = list()
for i in range(3):
    a1, a2, a3 = map(int, input().split())
    l.append(a1)
    l.append(a2)
    l.append(a3)
n = int(input())
for i in range(n):
    b = int(input())
    if b in l:
        l[l.index(b)] = 0
for i in range(3):
    if l[3 * i] == 0 and l[3 * i + 1] == 0 and l[3 * i + 2] == 0:
        print("Yes")
        exit()
    if l[i] == 0 and l[i + 3] == 0 and l[i + 6] == 0:
        print("Yes")
        exit()
if l[0] == 0 and l[4] == 0 and l[8] == 0:
    print("Yes")
    exit()
if l[2] == 0 and l[4] == 0 and l[6] == 0:
    print("Yes")
    exit()
print("No")


Measured memory_bytes: 3064