akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF = 1e9;
const int MOD = 1000000007;


int main() {
    int k,n;
    cin >> k >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int p = 0;
    rep(i,n-1) p = max(p,a[i+1]-a[i]);
    p = max(p,a[0]+k-a[n-1]);
    cout << k - p << endl;
    return 0;  
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define loop(i,x,z) for (int i=x;i<z;i++)
using ll = long long;
int n, A[200002], k = 0;
int main()
{
	cin >> n;
	loop(i, 0, n)cin >> A[i];
	ll ans = 0;
	loop(i, 0, n)
	{
		if (A[i] >= k)k = A[i];
		else
		{
			ans += k - A[i];
		}
	}
	cout << ans;
}

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

int main() {
	int a , b , c , d;
        cin >> a >> b >> c ;
       if (a > b) {
d = b;
b = a;
a = d;
};
       if (b > c){
d = c;
c = b;
b = d;
};
if (a > b) {
d = b;
b = a;
a = d;
};
cout << a << " " << b << " " << c << endl;
 	return 0;
}

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

int main(){

  int n;
  int k;
  int p=0;
  int ans=0;
  int an=0;
  int l=1;

  vector <int> a;
  cin >>n>>k;
  for(int i=1;i <=k;i++){
    int mi;
    cin >>mi;
    for(l=1;l<=mi;l++){
      int nl;
      cin >>nl;
      p +=1;
      a.push_back(nl);
    }
    l=1;
  }

for(int r=1;r<=n;r++){
  for(int q=0;q<p;q++){
   if(a[q]==r){
     an +=1;
   }
  }
  if(an ==0){
    ans+=1;
  }
  an =0;
}

 cout << ans <<endl;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define repr(i,n) for(int i=(n-1);i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
//二次元配列
//vector<vector<int>> vec(h, vector<int>(w));

int main() {

    string s;

    cin >> s;

    vector<ll> vec_num;
    vector<string> vec_str;

    int first_dainari = -1;

    int dainari_count = 0;
    int shonari_count = 0;

    for(int i = 0; i < s.size(); i++){
        if(s.at(i) == '<'){
            shonari_count++;
            if(dainari_count != 0){
                vec_num.pb(dainari_count);
                vec_str.pb(">");
                dainari_count = 0;
            }
        }
        if(s.at(i) == '>'){
            dainari_count++;
            if(shonari_count != 0){
                vec_num.pb(shonari_count);
                vec_str.pb("<");
                shonari_count = 0;
            }
        }
    }
    if(shonari_count != 0){
        vec_num.pb(shonari_count);
        vec_str.pb("<");
    }else{
        vec_num.pb(dainari_count);
        vec_str.pb(">");
    }


    /*
    for(int i = 0; i < vec_num.size(); i++){
        cout << vec_num.at(i);
    }
    cout << "" << endl;
    for(int i = 0; i < vec_str.size(); i++){
        cout << vec_str.at(i);
    }
    cout << "" << endl;
    */
    

    
    ll ans = 0;
    ll tmp = 0;

    if(vec_num.size() == 1){
        ans = (0 + vec_num.at(0)) * (vec_num.at(0)+1) / 2;
        cout << ans << endl;
        return 0;
    }

    
    for(int i = 0; i < vec_num.size(); i++){
        tmp = (0 + vec_num.at(i)) * (vec_num.at(i)+1) / 2;

        if(i == 0){
            if(vec_str.at(i) == "<"){
                if(vec_num.at(i) <= vec_num.at(i+1)){
                    ans += (tmp - vec_num.at(i));
                }else{
                    ans += tmp;
                }
            }else{
                ans += tmp;
            }
        }

        if(i == vec_num.size()-1){
            if(vec_str.at(i) == ">"){
                if(vec_num.at(i) < vec_num.at(i-1)){
                    ans += (tmp - vec_num.at(i));
                }else{
                    ans += tmp;
                }
            }else{
                ans += tmp;
            }
        }

        if(i != 0 && i != vec_num.size()-1){
            if(vec_str.at(i) == ">"){
                if(vec_num.at(i) < vec_num.at(i-1)){
                    ans += (tmp - vec_num.at(i));
                }else{
                    ans += tmp;
                }
            }
            if(vec_str.at(i) == "<"){
                if(vec_num.at(i) <= vec_num.at(i+1)){
                    ans += (tmp - vec_num.at(i));
                }else{
                    ans += tmp;
                }
            }
        }

    }
    

    cout << ans << endl;
    return 0;


}



Measured memory_bytes: 16364
#include <iostream>
using namespace std;
int main(void){

  int a, b, c;

  cin >> a >> b;  

  if (a < b){
    cout << "a < b" << "\n";
  } else if(a > b){
    cout << "a > b" << "\n";
  } else if(a == b){
    cout << "a == b" << "\n";
  }

  return 0;
 }

Measured memory_bytes: 1124
#include<string.h>
char a[11], b[11];
main() {
    scanf("%s%s", a, b);
    if(strlen(a) != strlen(b) - 1) printf("No\n");
    else {
        b[strlen(b) - 1] = '\0';
        if(strcmp(a, b)) printf("No\n");
        else printf("Yes\n");
    }
}

Measured memory_bytes: 1616
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main(void){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ans = max({a * c, b * d, b * c, a * d});
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3636
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n,m,c;
    cin>>n>>m>>c;
    vi b(m);
    rep(i,m)cin>>b[i];
    vvi a(n,vi(m));
    rep(i,n){
        rep(j,m){
            cin>>a[i][j];
        }
    }
    int ans=0;
    rep(i,n){
        int s=0;
        rep(j,m)s+=a[i][j]*b[j];
        ans+=s>-c;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using namespace std;

struct BoolName : numpunct<char> {
  string t, f;
  BoolName (string t = "Yes", string f = "No") : t(t), f(f) {}
  string do_truename() const {return t;}
  string do_falsename() const {return f;}
};

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15) << boolalpha;
    cout.imbue(locale(cout.getloc(), new BoolName));
  }
} initializer;

template<typename T> istream& operator>>(istream &s, vector<T> &v) {
  for (T &t : v) s >> t;
  return s;
}

template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
  for (const T &t : v) s << t << endl;
  return s;
}

template<typename T> map<typename T::value_type, int> count(const T& t) {
  map<typename T::value_type, int> res;
  for (const auto& i : t) ++res[i];
  return res;
}

template<typename T> bool chmin(T& a, T b) {return a > b ? a = b, true : false;}

template<typename T> bool chmax(T& a, T b) {return a < b ? a = b, true : false;}

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  cin >> s;
  vector<int> cnt(26, numeric_limits<int>::max());
  for (auto& i : s) {
    auto c = count(i);
    for (int i = 0; i < 26; ++i) chmin(cnt[i], c[i + 'a']);
  }
  for (int i = 0; i < 26; ++i) cout << string(cnt[i], i + 'a');
  cout << endl;
}



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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    int freq[n+1];
    for (int i=0;i<=n;i++) freq[i]=0;
    for (int x=1;x<=105;x++)
        for (int y=1;y<=105;y++)
            for (int z=1;z<=105;z++){
                int temp=(pow(x+y,2)+pow(y+z,2)+pow(z+x,2))/2;
                if(temp<=n) freq[temp]++;
            }
    for (int i=1;i<=n;i++) cout<<freq[i]<<"\n";
	return 0;
}

Measured memory_bytes: 3576
import java.util.*;
public class Main{   
    public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      long[] t = new long[n];
      long[] a = new long[n];
      for(int i = 0;i < n;i++){
      	t[i] = sc.nextLong();
        a[i] = sc.nextLong();
      }
      for(int i = 0;i < n-1;i++){
          long ft = t[i]/t[i+1]+(t[i]%t[i+1]==0?0:1);
          long fa = a[i]/a[i+1]+(a[i]%a[i+1]==0?0:1);
          long f = Math.max(fa,ft);
          t[i+1] *= f;
          a[i+1] *= f;
      }
      System.out.println(t[n-1]+a[n-1]);
    }
    public static int lcm(int x, int y){
      return x*y/gcd(x,y);
    }
    public static int gcd(int x, int y){
      if(x < y)return gcd(y,x);
      if(y==0)return x;
      return gcd(y,x%y);
    }
}

Measured memory_bytes: 25476
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef gp_hash_table<int, null_type,hash<int>, equal_to<int>, direct_mask_range_hashing<int>, linear_probe_fn<>,
    hash_standard_resize_policy<hash_exponential_size_policy<>, hash_load_check_resize_trigger<true>,true>> hash_set;
typedef gp_hash_table<int,null_type> hash_map;

#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define all(a) a.begin(),a.end()
#define println printf("\n");
#define readln(x) getline(cin,x);
#define pb push_back
#define endl "\n"
#define INT_INF 0x3f3f3f3f
#define LL_INF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-9
#define MOD 1000000007
#define MOD2 1494318097
#define SEED 131
#define mp make_pair
#define fastio cin.tie(0); cin.sync_with_stdio(0);

#define MAXN 200005

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef pair<int,pii> triple;
typedef int8_t byte;

const ld PI = (ld)4*atanl(1);

mt19937 g1(chrono::steady_clock::now().time_since_epoch().count());

int randint(int a, int b){return uniform_int_distribution<int>(a, b)(g1);}
ll randlong(ll a,ll b){return uniform_int_distribution<long long>(a, b)(g1);}

ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}

int len,par[MAXN];
ll D,arr[MAXN],res;
vector<pair<ll,pii>> edges;

inline ll get(int a, int b){
    return D*abs(a-b)+arr[a]+arr[b];
}

void solve(int l, int r){
    if(l >= r) return;
    int mid = (l+r)/2, f = l, s = mid+1;
    for(int i=l; i<=mid; i++)
        if(arr[i]-D*i < arr[f]-D*f)
            f = i;
    for(int i=mid+1; i<=r; i++)
        if(arr[i]+D*i < arr[s]+D*s)
            s = i;
    for(int i=l; i<=r; i++){
        if(i <= mid) edges.pb(mp(get(i,s),mp(i,s)));
        else edges.pb(mp(get(f,i),mp(f,i)));
    }
    solve(l,mid);
    solve(mid+1,r);
}

inline int root(int node){
    while(node != par[node]){
        par[node] = par[par[node]];
        node = par[node];
    }
    return node;
}

int main(){
    scanf("%d %lld",&len,&D);
    for(int i=1; i<=len; i++){
        scanf(" %lld",&arr[i]);
        par[i] = i;
    }
    solve(1,len);
    sort(all(edges));
    for(pair<ll,pii> check:edges){
        int f = check.second.first, s = check.second.second;
        int fp = root(f), sp = root(s);
        if(fp == sp) continue;
        par[fp] = sp;
        res+=check.first;
    }
    printf("%lld\n",res);
}

Measured memory_bytes: 70240
io = STDIN
n=io.gets.to_i
s = []
n.times do
  s<<io.gets.chomp
end
def check(s)
  dup=[]
  s.each_cons(2) do |x,y|
    dup << x
    return "No" if x[-1]!=y[0]
    return "No" if dup.include?(y)

  end
  'Yes'
end
puts check(s)


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

int kai(string S,int64_t s,int64_t e){
	int64_t i = s-1;
	int64_t j = e-1;

	while(i<j){
		if(S.at(i) != S.at(j)) return 0;
		i++;
		j--;
	}
	return 1;
}

int main() {
	string S;
	 cin >> S;
	 int64_t n = S.size();

	 if(kai(S,1,n) && kai(S,1,(n-1)/2) && kai(S,(n+3)/2,n)){
		 cout << "Yes" << endl;
	 }
	 else{
		 cout << "No" << endl;
	 }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <complex>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>
#include <iterator>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;

int main() {
    long double a, b, c;
    cin >> a >> b >> c;
    long double d = 2.0 * sqrt(a) * sqrt(b);
    bool f = a + b + d < c;
    cerr << a + b + d << endl;
    cout << (f ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in); 
		int x;
		
		for(int i = 1; i <= 10000; i++){
			x = scan.nextInt();
			if(x == 0){
				break;
			}
			
			System.out.println("Case " + i + ": " + x);
		}
	
	}

}

Measured memory_bytes: 42856
#include <bits/stdc++.h>
#define FIN         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ii          pair<int,int>
#define F           first
#define S           second
#define pb          push_back
#define all(x)      (x).begin(),(x).end()
#define rall(x)     (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a)   for(int i = a; i >= 0; i--)
#define fori(i,m)   for(auto i = m.begin(); i != m.end(); i++) 
#define w(t)        while(t--)
#define sz(s)       int(s.size())
#define cls(a,car)  memset(a,car,sizeof (a))
#define db(x)       cerr << #x << " is " << x << '\n'
#define FL          freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout);
#define EjecuteTime cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
#define angle(x)    double(x * acos(-1) / 180.0)
using namespace std;
typedef long long   ll;
typedef vector<int> vi;
typedef vector<ii>  vii;
const int N = 1 * 1e5 + 5;
const ll mod = 1e9 + 7;
const double E = 1e-9;
//int dx[] = {1, 0}, dy[] = {0, 1};
//int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//int dx[] = {2, 1, -1, -2, -2, -1, 1, 2}, dy[] = {1, 2, 2, 1, -1, -2, -2, -1};
//int dx[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy[] = {0 ,1, 1, 1, 0, -1, -1, -1};
// fflush(stdout)
// cout << flush
// a + b = a ^ b + 2 * (a & b)
int v[N];
int dp[N];
int n, k;
int f(int i){
    if(i == n - 1)return 0;
    int &ans = dp[i];
    if(ans == -1){
        ans = 1e9;
        for(int j = 1; j <= k; j++)
            if(i + j < n)
                ans = min(ans, f(i + j) + abs(v[i] - v[i + j]));
            else
                break;
    }
    return ans;
}
int main(){
    //FL;
    FIN;
    cin >> n >> k;
    fore(i, 0, n)cin >> v[i];
    for(int i = 0; i < n; i++)
        dp[i] = 1e9;
    for(int i = n - 1; i >= 0; i--){
        int &ans = dp[i];
        if(i == n - 1){
            ans = 0;
            continue;
        }
        ans = 1e9;
        for(int j = 1; j <= k; j++){
            if(i + j < n)
                ans = min(ans, dp[i + j] + abs(v[i] - v[i + j]));
            else
                break;
        }
    }
    
    cout << dp[0] << '\n';
    EjecuteTime;
    return 0;
}       

Measured memory_bytes: 4492
N, M = [int(s) for s in input().split()]
H = [int(s) for s in input().split()]
good = [True] * N

for _ in range(M):
    a, b = [int(s) - 1 for s in input().split()]
    if H[a] == H[b]:
        good[a] = False
        good[b] = False
    elif H[a] < H[b]:
        good[a] = False
    else:
        good[b] = False
    
print(sum(good))



Measured memory_bytes: 19972
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) *b;
}

struct edge {
	ll ind;
	ll to;
	ll d;
};


///////////////////////////

int main() {

	string s;
	cin >> s;

	cout << s[0] << s.size() - 2 << s[s.size() - 1];
	
	system("PAUSE");
}


Measured memory_bytes: 504
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repq(i,a,n) for(int i=a; i<=n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

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

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int pow(int i) {
    int ret = 1;
    rep(k,0,i) ret *= 10;
    return ret;
}

signed main() {
    string s; cin >> s;
    reverse(s.begin(), s.end());
    int ans = 0;
    rep(i,0,1 << (s.length() - 1)) {
        int prev = 0;
        rep(j,0,s.length()) {
            int temp = 0;
            if(i >> j & 1) {
                repq(k,prev,j) {
                    temp += (s[k] - '0') * pow(k - prev);
                }
                prev = j+1;
            }
            // debug
            // cout << temp << endl;
            ans += temp;
        }
        rep(k,prev,s.length()) {
            ans += (s[k] - '0') * pow(k - prev);
        }
        // printf("prev = %lld\n", prev);
        // printf("ans: %lld\n", ans);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;


long long int dp[105][4][4][4];

int N;

long long int MOD = 1000000007;

int main(void) {

	cin >> N;

	for (int p = 0; p < 4; p++) {
		for (int q = 0; q < 4; q++) {
			for (int r = 0; r < 4; r++) {
				if (p == 0 && q == 2 && r == 1) { continue; }
				if (q == 0 && p == 2 && r == 1) { continue; }
				if (p == 0 && r == 2 && q == 1) { continue; }
				dp[3][p][q][r] = 1;
			}
		}
	}

	for (int i = 3; i <= N - 1; i++) {
		for (int p = 0; p < 4; p++) {
			for (int q = 0; q < 4; q++) {
				for (int r = 0; r < 4; r++) {
					for (int s = 0; s < 4; s++) {
						if ((q == 0) && (r == 2) && (s == 1)) { continue; }
						if ((p == 0) && (r == 2) && (s == 1)) { continue; }
						if ((r == 0) && (q == 2) && (s == 1)) { continue; }
						if ((q == 0) && (s == 2) && (r == 1)) { continue; }
						if ((p == 0) && (q == 2) && (s == 1)) { continue; }
						dp[i + 1][q][r][s] += dp[i][p][q][r];
						dp[i + 1][q][r][s] %= MOD;
					}
				}
			}
		}
	}


	long long int ans = 0;

	for (int p = 0; p < 4; p++) {
		for (int q = 0; q < 4; q++) {
			for (int r = 0; r < 4; r++) {
				ans += dp[N][p][q][r];
				ans %= MOD;
			}
		}
	}

	cout << ans << endl;

	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

const string YES = "YES";
const string NO = "NO";

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<int> haiku;
    REP(i, 3) {
        int tmp;
        cin >> tmp;
        haiku.push_back(tmp);
    }
    sort(haiku.begin(), haiku.end());
    if (haiku[0] == 5 && haiku[1] == 5 && haiku[2] == 7)
        cout << YES << '\n';
    else cout << NO << '\n';
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  unsigned long a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  unsigned long count=0;
  unsigned long best = 0;
  for(int i=n-1;i>0;i--){
    if(a[i-1]>=a[i]){
      count++;
      best = max(best,count);
    }
    else{
      count=0;
    }
  }
  cout << best;
}


Measured memory_bytes: 1024
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=1,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN(n);
  while(true){
    if(m*2 <= n) m*=2;
    else break;
  }
  OUT(m);
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <stack>
#include <set>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef long long LL;
#define ALL(a) (a).begin(),(a).end()
#define PB push_back
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define OUT(v) cout<<v<<endl


int main() {
  LL L, R;
  cin >> L >> R;

  LL min_val = 2019*2019;
  FOR(i, L, R) {
    if (i == L + 2019)
      break;
    FOR(j, i + 1, R + 1) {
      if (j == i + 2020)
        break;
      min_val = min(min_val, i * j % 2019);
    }
  }
  OUT(min_val);

  return 0;
}


Measured memory_bytes: 256
import sys

h,w = [int(i) for i in input().split()]

sys.setrecursionlimit(100000)

s = [['#']*(w+2)] + [['#']+list(input())+['#'] for _ in range(h)] + [['#']*(w+2)]
#print(s)

cost = [[-1 if s[y][x] == '#' else float('inf') for x in range(w+2)] for y in range(h+2)]
cost[1][1] = 0
#print(cost)

def list_flatten(nested_list):
  flat_list = []
  fringe = [nested_list]
  
  while len(fringe) > 0:
    node = fringe.pop(0)
    if isinstance(node, list):
      fringe = node + fringe
    else:
      flat_list.append(node)

  return(flat_list)
      
def move(y,x):
  if cost[y+1][x] != -1:
    if cost[y+1][x] > cost[y][x]+1:
      cost[y+1][x] = cost[y][x]+1
      move(y+1,x)
      
  if cost[y-1][x] != -1:
    if cost[y-1][x] > cost[y][x]+1:
      cost[y-1][x] = cost[y][x]+1
      move(y-1,x)
  
  if cost[y][x+1] != -1:
    if cost[y][x+1] > cost[y][x]+1:
      cost[y][x+1] = cost[y][x]+1
      move(y,x+1)
  
  if cost[y][x-1] != -1:
    if cost[y][x-1] > cost[y][x]+1:
      cost[y][x-1] = cost[y][x]+1
      move(y,x-1)
  

move(1,1)

#print(cost)

if cost[h][w] == float('inf'):
  print(-1)
else:
  while_num = list_flatten(s).count('.')
  print(while_num - (cost[h][w]+1))


Measured memory_bytes: 5104
#include <iostream>
#include <unordered_set>

using namespace std;

int main() {
    int x, n;
    cin >> x >> n;
    unordered_set<int> us;
    for (int i = 0; i < n; ++i) {
        int p;
        cin >> p;
        us.insert(p);
    }
    for (int i = 0; i < 100; ++i) {
        if (us.find(x - i) == us.end()) {
            cout << x - i << endl;
            return 0;
        }
        if (us.find(x + i) == us.end()) {
            cout << x + i << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A.at(i);
  }
  vector<int> B(N);
  for (int i = 0; i < N; i++){
    B.at(0) += A.at(i) * pow(-1, i);
  }
  for (int i = 1; i < N; i++){
    B.at(i) = 2*A.at(i-1) - B.at(i-1);
  }
  for (int i = 0; i < N-1; i++){
    cout << B.at(i) << " ";
  }
  cout << B.at(N-1);
  return 0;
}

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

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int eval(priority_queue<ii> &odd, priority_queue<ii> &even) {
	vector<int> a,b;
	while(!odd.empty()) {
		ii cur=odd.top(); odd.pop();
		a.push_back(-cur.first);
		b.push_back(-cur.second);
		swap(odd,even);
	}
	int N=a.size();
	for (int i=0; i<N-1; i++)
		if(a[i]>a[i+1])
			return -1;
	int ret=0;
	for (int i=0; i<N; i++) {
		int idx=-1;
		for (int j=i; j<N; j++)
			if(b[j]==i) {
				idx=j; break;
			}
		for (int t=idx; t>=i+1; t--)
			swap(b[t],b[t-1]), ret++;
	}
	return ret;
}

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int N; cin>>N;
	vector<ii> V(N);
	for (int i=0; i<N; i++)
		cin>>V[i].first;
	for (int i=0; i<N; i++)
		cin>>V[i].second;
	int O=(N+1)/2;
	int ret=-1;
	for (int i=0; i<(1<<N); i++) {
		if(__builtin_popcount(i)!=O)
			continue;
		priority_queue<ii> odd, even;
		for (int j=0; j<N; j++) {
			ii top={-V[j].first,-j};
			ii bot={-V[j].second,-j};
			if(i&(1<<j)) {
				j%2 ? odd.push(bot) : odd.push(top);
			}
			else {
				j%2 ? even.push(top) : even.push(bot);
			}
		}
		int cur=eval(odd,even);
		if(cur==-1)
			continue;
		if(ret==-1) ret=cur;
		else ret=min(ret,cur);
	}
	cout<<ret<<endl;
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000;

int main(){
	int a,b;
	cin>>a>>b;
	cout<<(a-1)*(b-1)<<endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
tempArr = input().split(" ")
arr = [0]*N
for i in range(N) :
    arr[i] = int(tempArr[i])

leftSum = 0
rightSum = 0

minmum = 10000

for i in range(N) :
    for k in range(N) :
        if k <= i :
            leftSum += arr[k]
        else :
            rightSum += arr[k]

    if minmum > abs(leftSum - rightSum) :
        minmum = abs(leftSum - rightSum)

    leftSum = 0
    rightSum = 0

print(minmum)


Measured memory_bytes: 3188
#include <stdio.h>
int table[601][601];
double E[601];

int main() {
    int N, M;
    double ans = 1000;
    scanf(" %d %d", &N, &M);
    for (int i = 0; i < M; ++i) {
        int s, t;
        scanf(" %d %d", &s, &t);
        table[s][t] = 1;
        // table[t][s] = 1;
    }
    for (int i = 0; i < N; ++i) {
        E[N] = 0;
        for (int u = N - 1; u > 0; --u) {
            double e = 0;
            int len = 0;
            double max = -1;
            int maxv = 0;
            for (int v = u + 1; v <= N; ++v) {
                if (table[u][v]) {
                    e += E[v];
                    if (max < E[v]) {
                        max = E[v];
                        maxv = v;
                    }
                    len++;
                }
            }
            if (i == u && len > 1) {
                e -= E[maxv];
                len--;
            }
            E[u] = e / len + 1;
        }
        ans = ans > E[1] ? E[1] : ans;
    }
    printf("%f\n", ans);
    return 0;
}

Measured memory_bytes: 1536
#include<stdio.h>
#define N 100000
  int getDep(int);
struct Node{
  int p;
  int left;
  int right;
  int s;
  int h;
    }Node;
  
struct Node T[N];
  
int getDep(int u){
  int d=0;  
  for(;T[u].p != -1; d++) u=T[u].p; 
  return d;
}
void setHei(int n){
  int d,i,j;
  for(i = 0;i < n;i++){
     
    if(T[i].right == -1 && T[i].left == -1){
      T[i].h == 0;
      for(j = i,d = 1;j != -1; d++){
	j = T[j].p;
	if(T[j].h < d) T[j].h = d;    
      }
    }
  }
}
  
int main(){
  int i;
  int j;
  int n = 0;
  int v  =0;
  int d = 0;
  int c = 0;
  int l = 0;
  scanf("%d",&n);
   
 for(i = 0;i < n;i++) {
     
    T[i].p = -1;
    T[i].left = -1;
    T[i].right = -1;
    T[i].s = -1;
  }
    
 for(i = 0;i < n;i++){
   scanf("%d %d %d",&v,&d,&c);
   if( d!= -1 && c == -1){
     T[v].left = d;
     T[d].p = v;
   }
   if(c != -1 && d == -1){
    T[v].right = c;
    T[c].p = v;
   }
   if(d != -1 && c != -1){
     T[v].left = d;
     T[d].p = v;
     T[v].right = c;
     T[c].p = v;
     T[d].s = c;
     T[c].s = d;
   }
 }  
     
 for(i = 0;i < n;i++){
    
   printf("node %d: parent = %d, sibling = %d, ",i,T[i].p,T[i].s);
   if(T[i].right == -1 && T[i].left == -1) printf("degree = 0, ");
     
else if(T[i].right == -1 || T[i].left == -1) printf("degree = 1, ");
    
   else printf("degree = 2, ");
   setHei(n);
   printf("depth = %d, height = %d,",getDep(i),T[i].h);
  
   if(T[i].p == -1) printf(" root\n");
  
   else if(T[i].left == -1 && T[i].right == -1) printf(" leaf\n");
  
   else printf(" internal node\n");
 }
 return 0;
}

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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

const int MC = 1e5 + 3;
const LL mod = 998244353;
map<pair<int,int>,int> S;
int p1[MC],p2[MC],p0[MC];

int main(){
	LL N,M; cin >> N >> M;
	fill(p0,p0+MC,-1);
	fill(p1,p1+MC,-1);
	fill(p2,p2+MC,-1);
	LL z = N*(N+1)/2;
	repp(i,0,M){
		LL a,b,c; cin >> a >> b >> c;
		if(a == b) p0[a] = c;
		if(a > b) swap(a,b);
		auto it = S.find(MP(a,b));
		if(it != S.end()){
			if(b-a >= 3){
				if((*it).second != c) return cout << 0 << endl, 0;
			} else if(b-a == 2){
				p2[a] = ((*it).second != c);
			} else if(b-a == 1){
				p1[a] = ((*it).second != c);
			}
		} else {
			S[MP(a,b)] = c;
			--z;
		}
	}
	repp(i,1,N+1){
		if(p2[i] == 0){
			if(p0[i+1] == 1) return cout << 0 << endl, 0;
			if(p0[i+1] == -1) --z;
			p0[i+1] = 0;
		} else if(p2[i] == 1){
			if(p0[i+1] == 0) return cout << 0 << endl, 0;
			if(p0[i+1] == -1) --z;
			p0[i+1] = 1;
		}
		if(p1[i] == 0){
			if(p0[i] != -1 && p0[i+1] != -1 && p0[i] != p0[i+1]) return cout << 0 << endl, 0;
			if(p0[i] == -1 || p0[i+1] == -1) --z;
			if(p0[i] != -1) p0[i+1] = p0[i];
			else p0[i] = p0[i+1];
		} else if(p1[i] == 1){
			if(p0[i] != -1 && p0[i+1] != -1 && p0[i] == p0[i+1]) return cout << 0 << endl, 0;
			if(p0[i] == -1 || p0[i+1] == -1) --z;
			if(p0[i] != -1) p0[i+1] = 1-p0[i];
			else if(p0[i+1] != -1) p0[i] = 1-p0[i+1];
		}
	}
	LL ans = 1;
	for(LL k = 2 ; z > 0 ; k = k*k%mod){
		if(z&1) (ans *= k) %= mod;
		z /= 2;
	}
	cout << ans << endl;
	return 0;
}


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

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

  int N;
  std::cin >> N;

  int ac = 0;
  int wa = 0;
  int tle = 0;
  int re = 0;
  string r;

  for (int n = 0; n < N; n++)
  {
    std::cin >> r;
    if (r == "AC") ac++;
    else if (r == "WA") wa++;
    else if (r == "TLE") tle++;
    else if (r == "RE") re++;
  }
  std::cout << "AC x " << ac << "\nWA x " << wa 
      << "\nTLE x " << tle << "\nRE x " << re << "\n";
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
//#define DEBUG
#define REP(i, nn ) for(int i = 0 ; i < (int) nn; i++)
#define deb(x) std::cout << #x << " " << x << endl;

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;

template<typename... T>
void read(T& ... a){
    ((cin >> a),...);
}
template<typename... T>
void write(T... a){
    ((cout << a << "\n"),...);
}

void solve(){
    ll n;
    read(n);
    vl a(n);
    REP(i,n) cin >> a[i];
    int count = 0;
    REP(i,n){
        ll num = a[i];
        while( num % 2 == 0){
            num /= 2;
            count++;
        }
    }
    cout << count << "\n";
} 

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/

    #ifdef DEBUG
    int TEST_CASES = 2;
    while(TEST_CASES--){
    #endif // DEBBUG

    solve();

    #ifdef DEBUG
    }
    #endif // DEBUG
    
    return 0;
}

//Thanks to CSES problemset
// I am trained with this kind of problem

Measured memory_bytes: 3692
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::iter::*;
#[allow(unused_imports)]
use std::*;

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
#[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

fn main() {
    println!("{}", solve(&stdin!()));
}

fn div_game(mut n: usize) -> usize {
    let mut v = 2;
    let mut r = 0;

    let mut mark_map = HashSet::new();
    while n >= v * v {
        if n % v == 0 {
            if !mark_map.contains(&v) {
                let mut div_c = 1;
                let mut d = v;
                while n % d == 0 {
                    n /= d;
                    mark_map.insert(d);
                    div_c += 1;
                    d = v.pow(div_c);
                }
                r += div_c as usize - 1;
            } else {
                n /= v;
            }
        } else {
            v += 1;
        }
    }
    if n > 1 && !mark_map.contains(&n) {
        r += 1;
    }

    r
}
fn solve(src: &str) -> String {
    input! {
        source = src,
        n:usize,
    }
    div_game(n).to_string()
}
test! {

    "24" => "3",
    "1"=> "0",
    "64"=> "3",
    "1000000007"=>"1",
    "997764507000"=> "7",
    "4"=>"1",
    "32"=>"2",
    "16384" => "4",
    "32768" => "5",


}


Measured memory_bytes: 2160
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
    char tmp;
    std::vector<char> S;
    std::vector<char> T;
    int ctrl=0;
    int counter=0;

    while(cin >> tmp){
        if(ctrl<3){
            S.push_back(tmp);


        }else{

            T.push_back(tmp);
        }
        ctrl++;
    }

    for(int i=0;i<3;i++){
        if(S[i]==T[i]){
            counter++;
        }
    }

    cout << counter <<endl;

    return 0;

}

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

int main(){
    int n;
    cin >> n;
    vector<int> A(n);
    copy_n(istream_iterator<int>(cin), n, A.begin());
    vector<map<int, int>> C(2);
    for (int j = 0; j < 2; j++){
        for (int i = j; i < n; i += 2)
            C[j][A[i]]++;
    }
    vector<vector<pair<int, int>>> ma(2, vector<pair<int, int>>(2));
    for (int i = 0; i < 2; i++){
        for (const auto &c: C[i]){
            if (ma[i][0].second <= c.second){
                ma[i][1] = ma[i][0];
                ma[i][0] = c;
            } else if (ma[i][1].second <= c.second){
                ma[i][1] = c;
            }
        }
    }

    if (ma[0][0].first != ma[1][0].first){    
        cout << n - ma[0][0].second - ma[1][0].second << endl;
        return 0;
    }
        
    cout << n - max(ma[0][0].second + ma[1][1].second, ma[0][1].second + ma[1][0].second) << endl;
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;  
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define Rep(i, a, b) for(ll i = a; i <= b; i++)
#define repr(i, a, b) for(ll i = b-1; i >= a; i--)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
// const ll INF = 1LL << 60;
const ll INF = 100000000000;
#define pp pair<ll, pair<ll, ll>> 
#define fi first
#define se second
 
// rep(i, 0, sz(v)) cout << v[i] << " \n"[i==sz(v)-1];
 
////////////////////////////////////////////////////////

map<ll, ll> PrimeFactorization(ll n){
    map<ll, ll> ma;
    Rep(i, 2, sqrt(n)){
        while(n%i == 0){
            ma[i]++;
            n /= i;
        }
        if(n == 1) break;
    }
    if(n != 1) ma[n]++;
    return ma;
}

ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main() {
    ll n; cin >> n;
    Vl a(n);
    rep(i, 0, n) cin >> a[i];
    vector<map<ll, ll>> vm(n);
    rep(i, 0, n) vm[i] = PrimeFactorization(a[i]);
    map<ll, ll> Lcm;
    rep(i, 0, n){
        for(auto it : vm[i]) chmax(Lcm[it.first], it.second);
    }
    ll L = 1;
    for(auto it : Lcm) L = (L*modpow(it.first, it.second, MOD))%MOD;
    ll fa = 0;
    rep(i, 0, n){
        fa = (fa + L * modinv(a[i], MOD) % MOD) %MOD;
    }
    co(fa);
    
    return 0;
}

Measured memory_bytes: 6908
N,W = map(int,input().split())
VW = [list(map(int,input().split())) for _ in range(N)]
Val = [VW[i][0] for i in range(N)]
Wei = [VW[i][1] for i in range(N)]

dp = [[0 for _ in range(W+1)] for _ in range(N+1)]
#dp[i][j]:=i番目までの品物で重さjまででの価値の合計の最大値

for n in range(1,N+1):
    for w in range(W+1):
        if w - Wei[n-1] >= 0:
            dp[n][w] = max(dp[n-1][w],dp[n-1][w-Wei[n-1]]+Val[n-1])
        else:
            dp[n][w] = dp[n-1][w]
print(dp[n][w])



Measured memory_bytes: 25952
import string

S = str(input())
ans = []

for a in string.ascii_lowercase:
    isExist = False
    for i in range(len(S)):
        if S[i] == a:
            isExist = True
    if isExist == False:
        ans.append(a)

ans.sort()
if len(ans) == 0:
    print("None")
else:
    print(ans[0])


Measured memory_bytes: 3960
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define INF 1LL<<60
#define pi 3.14159265358979323846
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;} return false;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;} return false;}

int main(){
    ll n,a,b,ans=0;cin>>n>>a>>b;

    if((b-a)%2==0){ans=(b-a)/2;}
    else{
        if(n-b<a-1){
            ans+=(n-b);
            a+=(n-b);
            ans++;
            a++;
            ans+=(n-a)/2;
        }else{
            ans+=(a-1);
            b-=(a-1);
            ans++;
            b--;
            ans+=(b-1)/2;
        }
    }

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

Measured memory_bytes: 256
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>

#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>

using namespace std;

int main()
{
    std::string S;
    std::cin >> S;

    while (!S.empty()) {
        if (boost::algorithm::ends_with(S, "dreamer")) {
            S.resize(S.size() - 7);
        }
        else if (boost::algorithm::ends_with(S, "eraser")) {
            S.resize(S.size() - 6);
        }
        else if (boost::algorithm::ends_with(S, "erase")) {
            S.resize(S.size() - 5);
        }
        else if (boost::algorithm::ends_with(S, "dream")) {
            S.resize(S.size() - 5);
        }
        else {
            std::cout << "NO" << std::endl;
            return 0;
        }
    }

    std::cout << "YES" << std::endl;

    return 0;
}


Measured memory_bytes: 512
class Dice:
    def __init__(self,t,f,r,l,ba,bo):
        self.t = t
        self.f = f
        self.r = r
        self.l = l
        self.ba = ba
        self.bo = bo

s = input().split(" ")
dice = Dice(s[0],s[1],s[2],s[3],s[4],s[5])
n = int(input())
for i in range(n):
    t = input().split(" ")
    if t[0] == dice.t:
        if t[1] == dice.f:
            print(dice.r)
        elif t[1] == dice.r:
            print(dice.ba)
        elif t[1] == dice.ba:
            print(dice.l)
        else:
            print(dice.f)
    elif t[0] == dice.f:
        if t[1] == dice.bo:
            print(dice.r)
        elif t[1] == dice.r:
            print(dice.t)
        elif t[1] == dice.t:
            print(dice.l)
        else:
            print(dice.bo)
    elif t[0] == dice.r:
        if t[1] == dice.bo:
            print(dice.ba)
        elif t[1] == dice.t:
            print(dice.f)
        elif t[1] == dice.f:
            print(dice.bo)
        else:
            print(dice.t)
    elif t[0] == dice.l:
        if t[1] == dice.bo:
            print(dice.f)
        elif t[1] == dice.t:
            print(dice.ba)
        elif t[1] == dice.f:
            print(dice.t)
        else:
            print(dice.bo)
    elif t[0] == dice.ba:
        if t[1] == dice.bo:
            print(dice.l)
        elif t[1] == dice.t:
            print(dice.r)
        elif t[1] == dice.r:
            print(dice.bo)
        else:
            print(dice.t)
    elif t[0] == dice.bo:
        if t[1] == dice.f:
            print(dice.l)
        elif t[1] == dice.l:
            print(dice.ba)
        elif t[1] == dice.r:
            print(dice.f)
        else:
            print(dice.r)

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

using namespace std;

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

	vector<long long> L(N);
	int count = 0;

	for(int i = 0; i < N; i++) {
		cin >> L[i];
	}

	for(int i = 0; i < N-2; i++) {
		for(int j = i+1; j < N-1; j++) {
			for(int k = j+1; k < N; k++) {
				if(L[i] != L[j] && L[j] != L[k] && L[k] != L[i]) {
					if(L[i] + L[j] > L[k] && L[j] + L[k] > L[i] && L[k] + L[i] > L[j]) {
						count++;
					}
				}
			}
		}
	}
	
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 3612