akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
#define N 100000
#define M 100000


struct UnionFind {
  int *data;
  UnionFind(int size) {
      data = new int[size];
      for(int i = 0;i < size;i++)
          data[i] = -1;
  }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

UnionFind uf(N);
pair<int,pair<int,int> > ee[M];
long long rs[N];
int n,m;
vector<pair<int,int> > edge[N];
int ncost[N],ecost[M];
int used[N];
int usede[N];
vector<pair<int,int> > cuse;
int usedp;

void dfs(int p,int c){
    if(used[p]) return;
    used[p] = 1;
    for(int i = 0;i < edge[p].size();i++){
        if(ecost[edge[p][i].first] <= c && usede[edge[p][i].first] == 0){
            //cout << p << ' ' << edge[p][i].second << endl;
            usede[edge[p][i].first] = 1;
            usedp++;
            dfs(edge[p][i].second,c);
        }
    }
}

void solve(){
    int i,j;
    string str;
    cin >> n >> m;
    for(i = 0;i < n;i++){
        cin >> ncost[i];
        rs[i] = ncost[i];
    }
    for(i = 0;i < m;i++){
        int a,b;
        cin >> a >> b >> ee[i].first;
        a--;b--;
        ee[i].second = make_pair(a,b);
        edge[a].push_back(make_pair(i,b));
        edge[b].push_back(make_pair(i,a));
        ecost[i] = ee[i].first;
    }
    sort(ee,ee+m);
    long long ans = 0;
    for(i = 0;i < m;i++){
        int a = ee[i].second.first;
        int b = ee[i].second.second;
        int ra = uf.root(a);
        int rb = uf.root(b);
        long long snc;
        if(uf.findSet(a,b)){
            snc = rs[ra];
        }
        else{
            snc = rs[ra] + rs[rb];
            uf.unionSet(a,b);
            rs[uf.root(a)] = snc;
        }
        int r = uf.root(a);
        if(snc >= ee[i].first){
            cuse.push_back(make_pair(snc,ee[i].second.first));
        }
    }
    sort(cuse.begin(),cuse.end());
    for(i = cuse.size()-1;i >= 0;i--){
        dfs(cuse[i].second,cuse[i].first);
    }
    cout << m-usedp << endl;
}

int main(){
    solve();
}


Measured memory_bytes: 15092
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>
#include <cassert>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = LLONG_MAX;
const ll MOD = 1e9+7;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N,M;cin>>N>>M;
  vll A(N),B(M);
  vector<vector<bool> > used(N,vector<bool>(M,false));
  repeat(i,N){
    cin>>A[i];
  }
  repeat(i,M){
    cin>>B[i];
  }
  sort(A.begin(),A.end(),greater<ll>());
  //debugArray(A,N);
  sort(B.begin(),B.end(),greater<ll>());
  //debugArray(B,M);
  bool isok=true;
  repeat(i,N){
    isok &= A[i]>=(N-i)*M;
    if(i>0){
      isok &= A[i-1]>A[i];
    }
    //debug(isok);
  }
  repeat(j,M){
    isok &= B[j]>=(M-j)*N;
    if(j>0){
      isok &= B[j-1]>B[j];
    }
    //debug(isok);
  }
  if(!isok){
    cout << 0 << endl;
    return 0;
  }
  vll C(N+M);
  repeat(i,N){
    C[i]=A[i];
  }
  repeat(j,M){
    C[j+N]=B[j];
  }
  sort(C.begin(),C.end());
  C.erase(unique(C.begin(),C.end()),C.end());
  //debugArray(C,C.size());
  ll ans = 1;
  int i=0,j=0;
  while(i<N&&j<M){
    if(A[i]==B[j]){
      used[i][j]=true;
      i++;j++;
    }else if(A[i]>B[j]){
      ans = ans*j%MOD;
      used[i][0]=true;
      i++;
    }else{
      ans = ans*i%MOD;
      used[0][j]=true;
      j++;
    }
  }
  if(i<N){
    repeat(c,N-i){
      ans = ans*M%MOD;
      used[i+c][0]=true;
    }
  }
  if(j<M){
    repeat(c,M-j){
      ans = ans*N%MOD;
      used[0][j+c]=true;
    }
  }
  //debug(ans);
  int cnt=0;
  i=N-1;
  j=M-1;
  while(i>=0&&j>=0){
    //cerr<<i<<" "<<j<<endl;
    if(A[i]==B[j]){
      repeat(c,j+i){
        ans = ans*(A[i]-1-cnt)%MOD;
        cnt++;
      }
      i--;j--;
    }else if(A[i]>B[j]){
      repeat(c,i){
        ans = ans*(B[j]-1-cnt)%MOD;
        cnt++;
      }
      j--;
    }else{
      repeat(c,j){
        ans = ans*(A[i]-1-cnt)%MOD;
        cnt++;
      }
      i--;
    }
    cnt++;
    //debug(ans);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define lli long long int  
#define ll  long long 
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(),v.rend() //reverse
#define vl   vector<ll>
#define mii unordered_map<ll,ll>
#define pb push_back
double pi = 2*acos(0.0);
//ll power(ll a,ll b){ ll res=1;while(b){if(b&1)res=res*a;b=b/2; a=(a*a); }return res;}
 
//bool sortinrev(const pair<int,int> &a,   const pair<int,int> &b) {  if(a.first==b.first) return a.second>b.second;  return (a.first < b.first);} 
              
     
 
 int main()
 {
       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
       ll tst;
       tst=1; 
       //cin>>tst;
       while(tst--)
       {
         
          lli n;
          cin>>n;
          if(n>=30)
          	cout<<"Yes"<<endl;
          else
          	cout<<"No"<<endl;

        }  
       
 }

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

int main(){
  int a; cin>>a;
  int b; cin>>b;
  int ans;
  if (a>b) {
    ans=2*a-1;
  }
  else if (a==b) {
    ans=a+b;
  }
  else {
    ans=2*b-1;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

n = int(input())
ba = [list(map(int,input().split()[::-1])) for _ in range(n)]

ba.sort()

time = 0
for tmp in ba:
    b,a = tmp
    time += a
    if(b < time):
        print('No')
        exit()

print('Yes')

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

#define ll long long

template<typename T> void drop(const T &x){cout<<x<<'\n';exit(0);}

void solve() {
  string s, t; cin >> s >> t;

  int ans = 0;
  for(int i=0; i<s.size()-t.size()+1; ++i) {
    int count = 0;
    for(int j=0; j<t.size(); ++j) {
      if(s[i+j] == t[j]) count++;
    }
    ans = max(ans, count);
  }
  cout << t.size()-ans << '\n';
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T=1;
  //cin >> T;
  while(T--) solve();

  return 0;
}


Measured memory_bytes: 3660
H, W = map(int,input().split())
N = int(input())
a = list(map(int,input().split()))

c = []
idx = 0
jdx = 0

for i, cnt in enumerate(a):
    i += 1
    for _ in range(cnt):
        #print(i,cnt,c,idx,jdx)
        if jdx%2 == 0:
            if idx < W:
                c += [i]
                idx += 1
            else:
                print(*c)
                c = [i]
                idx -= 1
                jdx += 1
        else:
            if idx > 0:
                c = [i] + c
                idx -=  1
            else:
                print(*c)
                c = [i]
                idx += 1
                jdx += 1

print(*c)

Measured memory_bytes: 3700
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
using namespace std;
#define rep(i,n) for(int i=1;i<=(int)n;i++)
#define Rep(i,n) for(int i=0;i<=(int)(n-1);i++)
#define REP(i,b,e) for(int i=b;i<(int)e;i++)
typedef long long ll;
typedef map<ll,ll> mll;
typedef vector<ll> vll;
ll INF=1e18;
int inf=1e9+1000;
 
string alpha="abcdefghijklmnopqrstuwvxyz";
 
ll N,M;
ll x[1003],y[1003],z[1003];
ll x0[1003];
ll x1[1003];
ll y0[1003];
ll y1[1003];
ll z0[1003];
ll z1[1003];
ll sum[2][2][2][1003];
ll ss[2][2][2];

ll sw(ll n){
    if(n==0) return 1;
    if(n==1) return -1;
}
 
 
int main(){
    cin>>N>>M;
    Rep(i,N){
        cin>>x[i]>>y[i]>>z[i];
        Rep(p,2){
            Rep(q,2){
                Rep(r,2){
                    sum[p][q][r][i]=sw(p)*x[i]+sw(q)*y[i]+sw(r)*z[i];
                }
            }
        }
    }
    Rep(p,2){
        Rep(q,2){
            Rep(r,2){
                sort(sum[p][q][r],sum[p][q][r]+N);
              reverse(sum[p][q][r],sum[p][q][r]+N);
            }
        }
    }
    Rep(i,M){
        Rep(p,2){
            Rep(q,2){
                Rep(r,2){
                    ss[p][q][r]+=sum[p][q][r][i];
                }
            }
        }
    }
    ll ans=-1;
    Rep(p,2){
        Rep(q,2){
            Rep(r,2){
                ans=max(ans,ss[p][q][r]);
            }
        }
    }
  cout<<ans<<endl;



    return 0;
}

Measured memory_bytes: 384
import queue

def bfs(s1,s2):
    global ans
    queueX = queue.Queue()
    queueY = queue.Queue()
    queueX.put(s1)
    queueY.put(s2)
    s[s1][s2] = 0
    while queueX.empty() == False:
        x = queueX.get()
        y = queueY.get()

        for i in range(4):
            nextX = x + moveR[i]
            nextY = y + moveC[i]
            if 0 <= nextX and nextX < H\
                and 0 <= nextY and nextY < W\
                and s[nextX][nextY] != '#'\
                and s[nextX][nextY] == '.':
                s[nextX][nextY] = s[x][y] + 1
                queueX.put(nextX)
                queueY.put(nextY)

H, W = map(int, input().split())
s = [list(input()) for _ in range(H)]
cnt = 0
for i in range(H):
    for j in range(W):
        if s[i][j] == '#':
            cnt += 1
moveR = [0, 1, -1, 0]
moveC = [1, 0, 0, -1]
bfs(0,0)
if s[H - 1][W - 1] == '.':
    print(-1)
else:
    print(H * W - cnt - s[H - 1][W - 1] - 1)

Measured memory_bytes: 3944
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <sstream>

#define endl "\n"
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define REP(i, n) for(int i = 0; i < n; i++)
using Graph = vector<vector<int>>;

int main(){
    int n;
    cin>>n;
    int a[n];
    int ans = 0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(i%2 == 0 && a[i]%2 == 1) ans++;
    }
    cout<<ans<<endl;
}

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

using ll=long long;
int gcdd(int x, int y, int z){
  if(x<y) swap(x,y);
  if(x<z) swap(x,z);
  if(y<z) swap(y,z);
  if(x%z!=0 && y%z!=0) return(x%z,y%z,z);
  else if(x%z!=0 && y%z==0) return(x%z,y,z);
  else if(x%z==0 && y%z!=0) return(x,y%z,z);
  else  return z;
}
int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  ll ans = 0;
  for(int a=1; a<=n; a++){
    for(int b=1; b<=n; b++){
      for(int c=1; c<=n; c++){
        ans += gcd(gcd(a,b),c);
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3652
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int temp;
		int devideCnt;
		int maxDevideCnt =-1;
		int ans =0;

		for (int i=1; i<=n; i++){
			temp = i;
			devideCnt = 0;
			while (true){
				if (temp % 2 == 0){
					temp = temp / 2;
					devideCnt++;
				} else {
					break;
				}
			}
			if (devideCnt > maxDevideCnt){
				ans = i;
				maxDevideCnt = devideCnt;
			}
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 21844
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>

int main() {
	int a, b, c;
	int count = 0;
	std::cin >> a >> b >> c;
	for (int i = a; i <= b; i++) {
		if (c % i == 0) {
			count++;
		}
	}
	std::cout << count << std::endl;
	return 0;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define INF 1000000007
#define rep(i, N) for(ll i = 0; i < N; i++)
#define rep2(i, j, k) for(ll i = j; i < k; i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define print(x) cout << x << "\n"
#define print2(x, y) cout << x << " " << y << "\n"
#define printv(vec) rep(lp, vec.size()) cout << vec[lp] << " "; print(""); 
#define show(x) cerr << #x << " = " << x << "\n";
#define ALL(v) v.begin(), v.end()
#define SUM(v) accumulate(ALL(v), 0)
#define MAX(v) *max_element(ALL(v))
#define MIN(v) *min_element(ALL(v))
#define SORT(v) sort(ALL(v))
#define REV(v) reverse(ALL(v))
#define pb(x) push_back(x)
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
using namespace std;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vs = vector<string>;

const int mod = INF;
class mint {
public:
	ll x;
	mint(ll x = 0) : x((x % mod + mod) % mod) {}
	mint operator-() const { 
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}
	friend ostream& operator<<(ostream& os, const mint& m){
		os << m.x;
		return os;
	}
};

ll modpow(ll x, ll n, ll p = INF) {
	if (n == 0) return 1 % p;
	if (n % 2 == 0) return modpow(x * x % p, n / 2, p);
	else return x * modpow(x, n - 1, p) % p;
}

void Main(){

	ll N;
	cin >> N;
	map<ll, ll> mp;
	rep(i, N){
		ll in;
		cin >> in;
		mp[in] += 1;
	}
	
	ll ans = 0;
	ll cur = 0;
	ll cnt = 0;
	ll half = N / 2;
	
	for(ll i = 101010; i >= 0; i--){
		cnt += mp[i];
		ans += (cnt == half);
	}
	
	print(ans);
	
}

int main(){
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll t = 1;
	//cin >> t;
	rep(i, t) Main();
	return 0;
	
}





Measured memory_bytes: 9948
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()

using namespace std;

int main(){
  
    int n,m;
    cin >> n >> m;

    vector<int> p;
    p.pback(0);

    rep(i,n){
        int tmp;
        cin >> tmp;
        p.pback(tmp);
    }

    vector<vector<int>> edge;

    rep(i,n + 1){
        vector<int> tmpv;
        edge.pback(tmpv);
    }

    rep(i,m){
        int x, y;
        cin >> x >> y;

        edge[x].pback(y);
        edge[y].pback(x);
    }

    vector<int> traversed(n + 1);

    int ans = 0;

    for(int i = 1; i <= n; i++){
        set<int> tmp_traverse;
        set<int> p_set;

        function<void(int)> bfs = [&](int node) -> void{
            tmp_traverse.insert(node);
            p_set.insert(p[node]);

            traversed[node]++;

            rep(j, edge[node].size()){
                int to = edge[node][j];

                if(traversed[to] == 0){
                    bfs(to);
                }
            }
        };

        if(traversed[i] == 0){
            bfs(i);
        }

        set<int> result;

        set_intersection(tmp_traverse.begin(), tmp_traverse.end(),
                      p_set.begin(), p_set.end(),
                      inserter(result, result.end()));

        ans += result.size();
    }

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


Measured memory_bytes: 23532
table = []
r, c = gets.split.map(&:to_i)
sum_line = Array.new(c) {0}
r.times do
  table << gets.split.map(&:to_i)
end
table.each_with_index do |arr, i|
  puts table[i].join(' ') + ' ' + table[i].inject(:+).to_s
  sum_line.map!.with_index {|num, j| num + table[i][j]}
end
puts sum_line.join(' ') + ' ' + sum_line.inject(:+).to_s

Measured memory_bytes: 6136
#include<stdio.h>
#include<stdlib.h>

int main (void){
  
  int N,Alice=0,Bob=0;
  scanf("%d",&N);
  
  int a[N+1];
  for(int i=1;i<=N;i++){
  scanf("%d",&a[i]);
  }
  
  int tmp;
  for (int i=1; i<=N; i++) {
    for (int j=i+1; j<=N; j++) {
      if (a[i] < a[j]) {
        tmp =  a[j];
        a[j] = a[i];
        a[i] = tmp;
      }
    }
  }

  for (int i=1;i<=N;i=i+2){
    
  	Alice += a[i];
    if(i+1<=N) Bob += a[i+1];
  }
  
  printf("%d",Alice-Bob);
  
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#define BIG 1000000000
#define N 100010
using namespace std;
int n,k,cnta,cntb,Ans,a[N],b[N];

int main() {
	scanf("%d%d",&n,&k);
	for (int i=1; i<=n; i++) a[i]=b[i]=BIG;
	for (int i=1; i<=n; i++) {
		int x; scanf("%d",&x);
		if (x<0) a[++cnta]=-x;
		else b[++cntb]=x;
	}
	for (int i=1; i<=(cnta/2); i++) swap(a[i],a[cnta-i+1]);
	Ans=b[k];
	for (int i=1; i<=min(cnta,k); i++)
		Ans=min(Ans,a[i]+b[k-i]*2);
	Ans=min(Ans,a[k]);
	for (int i=1; i<=min(cntb,k); i++) 
		Ans=min(Ans,b[i]+a[k-i]*2);
	printf("%d",Ans);
}

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


int main(){
    string s;cin >>s;
    stack<char> st;
    st.push(s[0]);
    rep(i,s.size()-1){
        
        char ch = '.';
        if(st.size()){
            ch = st.top();
            //cout << ch << endl;
        }
        if(s[i+1]=='T'&&ch=='S'){
            st.pop();
        }else{
            st.push(s[i+1]);
        }
    }

    cout << st.size() <<endl;
 }

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


int main(){
    int n; cin >> n;
    vector<int> v(n+1);
    rep(i, n) cin >> v[i];
    sort(v.begin(), v.end());
    bool ans = false;
    rep(i, n){
        if(v[i] == v[i+1]){
            ans = true;
            break;
        }
    }
    if(ans) cout << "NO"; else cout << "YES";
}

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

using namespace std;

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

    int a; cin >> a;
    string s; cin >> s;
    if (a >= 3200) {
        cout << s;
    } else {
        cout << "red";
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
constexpr int MAXN = 1e5 + 5;
#define pii pair<int, int>
typedef long long LL;
typedef unsigned long long uLL;
using namespace std;
inline int read(){
    int x = 0, f = 1;
    char ch = getchar();
    while(!isdigit(ch)) f = (ch == '-') ? -1 : 1, ch = getchar();
    while(isdigit(ch)) x = (x << 3) + (x << 1) + ch -48, ch = getchar();
    return x * f;
}
int n, ans = 0x3f3f3f3f;
int x[MAXN];
int main(){
	std::ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> x[i];
	for (int i = 1; i <= 100; i++) {
		int sum = 0;
		for (int j = 1; j <= n; j++) {
			sum += pow(x[j] - i, 2);
		}
		ans = min(ans, sum);
	}
	cout << ans << endl;
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  double x;
  cin >> x;

  int ans = 0;
  if (x == 1) {
    cout << "1" << endl;
    return 0;
  } else {
    for (int i = 2; i <= x; ++i) {
      for (int j = 2; pow(i, j) <= x; ++j) {
        ans = (int)max((double)ans, pow((double)i, (double)j));
      }
    }
    cout << ans << endl;
    return 0;
  }
}


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

typedef long long ll;

using namespace std;

int main()
{
  ll A,B,C;
  cin >> A>>B>>C;
  if (A == 2 || B == 2) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 256
from collections import Counter

N = int(input())
l = list(map(int,input().split()))

if len(set(l)) == 1:
  print(N//2)
else:
  l_odd,l_even = [],[]

  for i in range(N):
    if i%2 == 0:
      l_odd.append(l[i])
    else:
      l_even.append(l[i])

  C_odd = Counter(l_odd).most_common()
  C_even = Counter(l_even).most_common()

  if C_odd[0][0] != C_even[0][0]:
    ans = N - C_odd[0][1] - C_even[0][1]
  else:
    ans = min(N - C_odd[0][1] - C_even[1][1],N - C_odd[1][1] - C_even[0][1])

  print(ans)

Measured memory_bytes: 21084
#include <iostream>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define _CRT_SECURE_NO_WARNINGS
#define REP(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define MP make_pair
#define PB push_back

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;

int main() {
	int n, h, w;
	cin >> n >> h >> w;
	cout << (n - h + 1)*(n - w + 1) << endl;
}

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

int main(){
    long long N, M;
    cin >> N >> M;
    vector<long long> A(N), B(N+1);
    for(int i=0; i<N; i++) cin >> A[i];
    B[0] = 0;
    for(int i=1; i<=N; i++)
        B[i] = (B[i-1] + A[i-1]) % M;

    long long ans = 0;
    map<long long, long long> mp;
    mp[B[N]]++;
    for(int i=N-1; i>=0; i--){
        ans += mp[(M+B[i])%M];
        mp[B[i]]++;
    }

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


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

int main(){
    long long n, m;
    cin >> n >> m;

    if(n == 1 and m == 1){
        printf("1\n");
    }
    else if(n == 1 and m >= 2){
        printf("%lld\n", m-2);
    }
    else if(n >= 2 and m == 1){
        printf("%lld\n", n-2);
    }
    else if(n >= 2 and m >= 2){
        printf("%lld\n", (n-2)*(m-2));
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[]srgs) {
	Scanner scan=new Scanner(System.in);
	String a=scan.next();
	String b=scan.next();
	char c[]=new char[a.length()];
	char d[]=new char[b.length()];
	char e[]=new char[b.length()];
	for(int i=0;i!=a.length();i++) {
		c[i]=a.charAt(i);
	}
	for(int i=0;i!=b.length();i++) {
		d[i]=b.charAt(i);
	}
	Arrays.sort(c);
	Arrays.sort(d);
	for(int i=0;i!=b.length();i++) {
		e[i]=d[b.length()-i-1];
	}
	String A="";
	String B="";
	for(int i=0;i!=a.length();i++) {
		A=A+c[i];
	}
	for(int i=0;i!=b.length();i++) {
		B=B+e[i];
	}
	
	System.out.println(A.compareTo(B)<=-1?"Yes":"No");
}
}

Measured memory_bytes: 23764
def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def main():
    S = input()
    res = 0
    tmp = 0
    for s in S:
        if s in ("A", "T", "C", "G"):
            tmp += 1
        else:
            res = max(res, tmp)
            tmp = 0
    res = max(res, tmp)
    print(res)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
function Main(input) {
  input=input.split("\n");
  if(input[input.length-1]===''){
    input.pop();
  }
  const A=input[0].split(' ')[0]-0;
  const B=input[0].split(' ')[1]-0;
  const C=input[0].split(' ')[2]-0;
  var ans=0;
  ans+=A===B?1:0;
  ans+=B===C?1:0;
  ans+=C===A?1:0;
  console.log(ans===1?'Yes':'No');
}


//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
  



  


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

typedef struct{
  char name[21];
  int w, b, d;
  int p;
}TEAM;
void bsort(TEAM *p, int n){
  int i, j;
  TEAM tmp;
  for(i = 0; i < n - 1; i++)
    for(j = 0; j < n - i - 1; j++)
      if(p[j].p < p[j + 1].p)
	tmp = p[j], p[j] = p[j + 1], p[j + 1] = tmp;
}

int main(){
  int a, b, c, i, j, n, max, f = 1;
  char in[21];
  TEAM tmp, t[11];

  while(scanf("%d", &n) && n){
    for(i = 0; i < n; i++){
      scanf("%s%d%d%d", t[i].name, &t[i].w, &t[i].b, &t[i].d);
      t[i].p = t[i].w * 3 + t[i].d;
    }

    bsort(t, n);
    if(!f) puts("");
    for(i = 0; i < n; ++i) printf("%s,%d\n", t[i].name, t[i].p);
    f = 0;
  }
  return 0;
}

Measured memory_bytes: 612
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int a = int.Parse(str[0]);
            int b = int.Parse(str[1]);

            if (a <= 8 && b <= 8)
            {
                Console.WriteLine("Yay!");
            }
            else
            {
                Console.WriteLine(":(");
            }

        }
    }
}


Measured memory_bytes: 11092
import java.io.*;
import java.util.StringTokenizer;
import java.util.ArrayList;

class Main {
	public static void main(String args[]) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String buf;

		try {
			while (!(buf = br.readLine()).equals("0 0")) {
				StringTokenizer st = new StringTokenizer(buf);
				int n = Integer.parseInt(st.nextToken());
				int m = Integer.parseInt(st.nextToken());
				ArrayList<Integer> a = new ArrayList<Integer>();
				for (int i=1;i<=n;i++) {
					a.add(i);
				}
				int p = (m-1)%n;
				while (a.size()>1) {
					a.remove(p);
					p = (p+m-1)%a.size();
				}
				System.out.println(a.get(0));
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 16960
#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////
ll n;
Vi a;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    cin>>n;
    a.resize(n);
    set<ll> st;
    rep(i,n){
        cin>>a[i];
        st.insert(a[i]);
    }
    YES(st.size()==a.size());
    return 0;
}

Measured memory_bytes: 11264
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define int64 long long
#define uint64 unsigned long long
#define PI 3.1415926535897932384626433832795
using namespace std;

int main()
{
	int64 nn;
	cin >> nn;
	cout << (nn * (nn - 1) / 2) << endl;
	return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define map map <int,int> 
#define hashmap unordered_map <int,int>
#define Set set <int>
#define hashset unordered_set <int> 
#define array vector <int> 
#define Pair pair<int,int>
using namespace std;

// void minput(int mat[][],int n,int m)
// {
//     for(int i=0;i<n;i++)
//     {
//         for(int j=0;j<m;j++)
//         cin>>mat[i][j];
//     }
// }

// void minput(int mat[][],int n,int m)
// {
//     for(int i=0;i<n;i++)
//     {
//         for(int j=0;j<m;j++)
//         cout<<mat[i][j]<<" ";
//         cout<<endl;
//     }
// }

void input(int arr[],int n)
{
    for(int i=0;i<n;i++)
    cin>>arr[i];
}

void output(int arr[],int n)
{
    for(int i=0;i<n;i++)
    cout<<arr[i]<<" ";
    
    cout<<endl;
}


int main() 
{
    long long int num;
    cin>>num;
    long long int sum = num*(num-1);
    sum = sum/2;
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
//  Created by conan1024hao on 2019/11/23.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll>P;
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define PI acos(-1.0)
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll cmp(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    ll n;
    cin>>n;
    vector<ll>a(n);
    for(ll i=0;i<n;i++)
        cin>>a[i];
    ll now=0;
    ll abc;
    ll sum=0;
    ll ac,b;
    ll d,e;
    for(ll i=0;i<n;i++){
        sum+=a[i];
    }
    for(ll i=0;i<n;i++){
        now+=a[i];
        if(now>=(sum/2)){
            ac=now-a[i];
            b=now;
            d=sum-ac;
            e=sum-b;
            break;
        }
    }
    ll ans=min(abs(d-ac),abs(e-b));
    cout<<ans<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------


Measured memory_bytes: 1920
r_A = 0
r_B = 0
r_C = 0
r_D = 0
l_A = 0
l_B = 0
l_C = 0
l_D = 0

while True :
    try :
        l, r = map(float, input().split())
    except EOFError :
        break
    
    if l >= 1.1 :
        l_A += 1
    elif l >= 0.6 :
        l_B += 1
    elif l >= 0.2 :
        l_C += 1
    else :
        l_D += 1
    if r >= 1.1 :
        r_A += 1
    elif r >= 0.6 :
        r_B += 1
    elif r >= 0.2 :
        r_C += 1
    else :
        r_D += 1

print(l_A, r_A)
print(l_B, r_B)
print(l_C, r_C)
print(l_D, r_D)


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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long

const int N = 200009;
int n, d, a;
pair<int, int> m[N];
int rmv[N];

int32_t main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> d >> a;
    for(int i = 0; i < n; ++i) {
        cin >> m[i].first >> m[i].second;
    }

    sort(m, m+n);

    int bombs = 0, ans = 0;
    for(int i = 0; i < n; ++i) {
        pair<int, int> p = m[i];
        bombs -= rmv[i];
        int h = max(0LL, p.second - bombs*a);
        int rem = (h+a-1)/a;

        pair<int, int> srch = {p.first+d+d, 10000000000000};
        auto it = upper_bound(m+i, m+n, srch);
        bombs += rem;
        ans += rem;
        rmv[it-m] += rem;
    }

    cout << ans << '\n';
    
    return 0;
}


Measured memory_bytes: 4992
#include <iostream>

int main() {
  size_t N, H, W;
  std::cin >> N >> H >> W;

  size_t ans = 0;

  for (size_t i=0; i<N; i++) {
    size_t a, b;
    std::cin >> a >> b;

    if (a >= H && b >= W) ans++;
  }

  std::cout << ans << std::endl;

  return 0;
}


Measured memory_bytes: 256
<?php

for ($i = 0; $i < 4; $i++) {
  $inp[] = intval(trim(fgets(STDIN)));
}

if ($inp[0] <= $inp[1]) {
  echo $inp[0] * $inp[2];
  return;
}

$Y = $inp[0] - $inp[1];
$X = $inp[0] - $Y;

echo $Y * $inp[3] + $X * $inp[2];

?>

Measured memory_bytes: 4728
#include<bits/stdc++.h>
using namespace std;
int n,m;
void init(){
    cin>>n>>m;
}
void solve(){
    cout<<((!(n%3)||!(m%3)||!((m+n)%3))?"Possible":"Impossible")<<endl;
}
int main() {
    init();
    solve();
    return 0;
}


Measured memory_bytes: 3580
#include <algorithm>
#include <array>
#include <vector>
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <functional>
#include <queue>

//AtCoderC++.cpp

using namespace std;


int main() {
	int N, M, X;
	cin >> N >> M >> X;
	int Toll;
	int ToLeft = 0, ToRight = 0;
	for (int i = 0; i < M; i++) {
		cin >> Toll;
		(Toll < X) ? ToLeft++ : ToRight++;
	}
	cout << min(ToLeft, ToRight) << endl;
}


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

int main(){
    int n,q,time;cin>>n>>q;
    string name;
    int cnt=0;
    queue<pair<string,int> > que;
    for(int i=0;i<n;i++){
        cin>>name>>time;
        que.push(make_pair(name,time));
    }
    while(!que.empty()){
        pair<string,int> a=que.front();que.pop();
        if(a.second<=q){
            cnt+=a.second;
            cout<<a.first<<' '<<cnt<<endl;
        }
        else{
            cnt+=q;
            que.push(make_pair(a.first,a.second-q));
            
        }
    }
}


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

using namespace std;

#define FOR(i,a,b)  for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n)    FOR(i,0,n)
#define ALL(a)      a.begin(),a.end()
#define vi          vector<int>
#define vvi         vector<vi>
#define P           pair<int,int>
#define vP          vector<P>
#define vvP         vector<vP>

int main(){
    function<int (int,int)> RoundUp=[&](int a,int b){
        return (a+b-1)/b;
    };
    int n;cin>>n;
    vi c(n),s(n),f(n);
    REP(i,n-1){
        cin>>c[i]>>s[i]>>f[i];
    }
    REP(start,n){
        int time=0;
        FOR(i,start,n-1){
            time=(s[i]+max(0,RoundUp(time-s[i],f[i]))*f[i]);
            time+=c[i];
        }
        cout<<time<<"\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <climits>
#include <algorithm>
#include <cstring>

using namespace std;
typedef pair<int, pair<int, int> > edge;

int n, m;
int parent[256];
int rank[256];

void init(int num){	
	for(int i=0; i<num; ++i){
		parent[i] = i;
		rank[i]=0;
	}
}

int find(int x){
	if(parent[x]==x)
		return x;
	else
		return parent[x]=find(parent[x]);
}

void unite(int x, int y){

	x=find(x);
	y=find(y);

	if(x==y)
		return;
	
	if(rank[x]<rank[y]){
		parent[x]=y;
	}
	else{
		parent[y]=x;
		
		if(rank[x]==rank[y])
			rank[x]++;
	}
}

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

int solve(vector<edge> e){

	int res = INT_MAX;
	
	for(int k=0; k<e.size(); ++k){
		
		int lo = e[k].first, hi, cnt=0;
		init(n+1);
		
		for(int p=k; (p<e.size()&&cnt!=n-1); ++p){
			
			if(!same(e[p].second.first, e[p].second.second)){
				hi = e[p].first;
				unite(e[p].second.first, e[p].second.second);
				cnt++;
			}
		}
		
		if(cnt==n-1){
			res = min(res, hi-lo);
		}
	}
	
	return (res!=INT_MAX?res:-1);
}

int main(){

	while(cin>>n>>m, (n||m)){
		
		vector<edge> e;
		int a, b, w;
		
		for(int i=0; i<m; ++i){
			cin>>a>>b>>w;
			e.push_back( make_pair(w, make_pair(a, b)));
		}
		
		sort(e.begin(), e.end());
		cout << solve(e) << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1328
#include <iostream>
#include <vector>
#include <limits>
#include <algorithm>

using namespace std;

int main() {
    ios::sync_with_stdio(false);

    int N; cin >> N;

    vector<int64_t> partial(N);
    for (int i = 0; i < N; ++i) {
        cin >> partial[i];
        if (i > 0)
            partial[i] += partial[i - 1];
    }

    vector< vector<int64_t> > dp(N, vector<int64_t>(N, numeric_limits<int64_t>::max() / 2));
    for (int i = 0; i < N; ++i)
        dp[i][i] = 0;

    for (int L = 1; L < N; ++L)
        for (int i = 0; i + L < N; ++i)
            for (int k = i; k < i + L; ++k)
                dp[i][i + L] = min(dp[i][i + L], dp[i][k] + dp[k + 1][i + L] + partial[i + L] - (i == 0 ? 0 : partial[i - 1]));

    cout << dp[0][N - 1] << "\n";
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
char a[1000001],c[1000001];
int main() {
	int b,sum=0,l=0;
	cin>>a;
	b=strlen(a);
	for(int i=b-1; i>=0; i--) {
		c[sum]=a[i];
		if(c[sum]=='b') c[sum]='d';
		else if(c[sum]=='d') c[sum]='b';
		else if(c[sum]=='p') c[sum]='q';
		else if(c[sum]=='q') c[sum]='p';
		sum++;
	}
	for(int i=0; i<=b-1; i++) {
		if(a[i]!=c[i]) {
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

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

//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("avx,avx2,fma")

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cerr << #a << " = " << a << endl;

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}

template<typename T> void print(const T& a, ostream& out){	
	for(auto i: a) out << i << ' ';
	out << endl;
}

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n; cin >> n;
	dsu d(n);
	int q; cin >> q;
	while(q--){
		int typ, u, v; cin >> typ >> u >> v;
		if (typ == 0) d.merge(u, v);
		else cout << d.same(u, v) << '\n';
	}
	
    cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
    return 0;
}


Measured memory_bytes: 4032
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
 
int main() {
  int n;
  cin >> n;
  vector<int> o(100010), e(100010);
  rep(i,n) {
    int v; cin >> v;
    if (i%2 == 1) o[v]++;
    else e[v]++;
  }
  int i = max_element(e.begin(),e.end()) - e.begin();
  int j = max_element(o.begin(), o.end()) - o.begin();
  if (i != j) {
    cout << n-e[i]-o[j] << endl;
  } else {
    sort(e.rbegin(),e.rend());
    sort(o.rbegin(),o.rend());
    int an = min(n-e[0]-o[1],n-e[1]-o[0]);
    cout << an << endl;
  }
  return 0;
}

Measured memory_bytes: 4032
# -*- coding: utf-8 -*-


# 入力を整数に変換して受け取る
def input_int():
    return int(input())


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return map(int, input().split())


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


def main():
    n, k = input_to_int_map()
    p = input_to_int_tuple()

    p_sorted = sorted(p)

    return sum(p_sorted[:k])

if __name__ == "__main__":
    print(main())


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

int main()
{
  int n;
  std::cin>>n;
  
  int64_t aMax=0;
  std::vector<int64_t> a(n);
  for(int i=0;i!=n;i++)
  {
    std::cin>>a[i];
    if(a[i]>aMax)
      aMax=a[i];
  }
  
  std::sort(a.begin(),a.end());
  
  std::vector<bool> dp(aMax+1,true);
  std::vector<bool> seen(aMax+1,false);
  
  for(int i=0;i!=n;i++)
  {
    int x=a[i];
    
    if(dp[x]==false)
      continue;
    
    if(seen[x])
    {
      dp[x]=false;
      continue;
    }
    
    seen[x]=true;
    
    for(int j=2*x;j<=aMax;j+=x)
      dp[j]=false;
  }
  
  int result=0;
  for(int i=0;i!=n;i++)
    if(dp[a[i]])
      result++;
  
  std::cout<<result<<std::endl;
  
  return 0;
}

Measured memory_bytes: 5032
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<deque>
using namespace std;
typedef long long ll;

int main() {
    string s; cin >> s;
    string ss[7] = {"SUN","MON","TUE","WED","THU","FRI","SAT" };
    int ans;
    for (int i = 0; i < 7; i++)
    {
        if (ss[i] == s) {
            ans = i;
            break;
        }
    }
    
    cout << 7-ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N, M, K = rl()

bool = [False] * (N * M + 1)
for i in range(N+1):
    bool[i*M] = True
    for j in range(1, M+1):
        x = N - (2 * i)
        if 0 <= i*M + x*j <= N * M:
            bool[i*M + x*j] = True

print('Yes' if bool[K] else 'No')
# 47

Measured memory_bytes: 10868
module Main where

import Data.List
import Control.Monad
import Debug.Trace
import qualified Data.ByteString.Char8 as BC
import Data.Maybe (fromJust)


readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b, c)

readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as = let
    (fo, la) = span f as
    las = case la of
        [] -> []
        xs -> split f $ tail xs
    in
        case fo of
            [] -> las
            xs -> xs : las
   
solve :: Int -> Int
solve n = let
    isDivisor a = n `mod` a == 0
    maxDivisor = ceiling $ sqrt $ fromIntegral n
    divisors = filter isDivisor [1..maxDivisor]
    distances = fmap (\a -> a + (n `div` a) - 2) divisors
    in
        minimum distances


main = do
    n <- readInt
    print $ solve n

Measured memory_bytes: 764
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) rep(i, (v).size() - 1) cout << (v)[i] << ' '; cout << (v)[n - 1] << '\n';
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

// End of template.


int main(){
    cout << fixed << setprecision(15);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    int a[100100], b[100100], c[100100];
    scanf("%d", &n);
    rep(i, n) scanf("%d", &a[i]);
    rep(i, n) scanf("%d", &b[i]);
    rep(i, n) scanf("%d", &c[i]);
    sort(begin(a), begin(a) + n);
    sort(begin(b), begin(b) + n);
    sort(begin(c), begin(c) + n);

    int64 bc[100100];
    bc[n] = 0;
    // bc[i]: sum(bk より大きい c の数 for all k >= i)
    for (int i = n - 1; i >= 0; --i) {
        auto it = upper_bound(begin(c), begin(c) + n, b[i]);
        bc[i] = begin(c) + n - it + bc[i + 1];
    }


    int64 ans = 0;
    rep(i, n) {
        auto it = upper_bound(begin(b), begin(b) + n, a[i]);
        ans += bc[it - begin(b)];
    }

    cout << ans << '\n';

    return 0;
}



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

using namespace std;

int main(void)
{

  ios_base::sync_with_stdio(0);

  cin.tie(0);
  cout.tie(0);

  int m1, d1;
  int m2, d2;

  cin >> m1 >> d1;
  cin >> m2 >> d2;

  if( d2 < d1 )
    cout << 1;
  else
    cout << 0;

  return(0);

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll X;
  cin >> X;
  ll ans = 0;
  ans += (X / 500) * 1000;
  X = X % 500;
  ans += (X / 5) * 5;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
MOD=10**9+7
cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end

def puts_yesno(can) puts(can ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
n=gi

if n%2==0
  putsend n/2+-1
else
  putsend n/2
end

Measured memory_bytes: 1788