akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.nio.CharBuffer;
import java.util.NoSuchElementException;

public class Main {

    public static void main(String[] args) {
        SimpleScanner scanner = new SimpleScanner(System.in);
        PrintWriter writer = new PrintWriter(System.out);

        int w = scanner.nextInt();
        int h = scanner.nextInt();
        int x = scanner.nextInt();
        int y = scanner.nextInt();
        writer.print((double) w * h / 2 + " ");
        writer.println(x * 2 == w && y * 2 == h ? 1 : 0);

        writer.close();
    }

    private static class SimpleScanner {

        private static final int BUFFER_SIZE = 10240;

        private Readable in;
        private CharBuffer buffer;
        private boolean eof;

        SimpleScanner(InputStream in) {
            this.in = new BufferedReader(new InputStreamReader(in));
            buffer = CharBuffer.allocate(BUFFER_SIZE);
            buffer.limit(0);
            eof = false;
        }


        private char read() {
            if (!buffer.hasRemaining()) {
                buffer.clear();
                int n;
                try {
                    n = in.read(buffer);
                } catch (IOException e) {
                    n = -1;
                }
                if (n <= 0) {
                    eof = true;
                    return '\0';
                }
                buffer.flip();
            }
            return buffer.get();
        }

        void checkEof() {
            if (eof)
                throw new NoSuchElementException();
        }

        char nextChar() {
            checkEof();
            char b = read();
            checkEof();
            return b;
        }

        String next() {
            char b;
            do {
                b = read();
                checkEof();
            } while (Character.isWhitespace(b));
            StringBuilder sb = new StringBuilder();
            do {
                sb.append(b);
                b = read();
            } while (!eof && !Character.isWhitespace(b));
            return sb.toString();
        }

        int nextInt() {
            return Integer.valueOf(next());
        }

        long nextLong() {
            return Long.valueOf(next());
        }

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

Measured memory_bytes: 23124
n = input()
l = len(n)
y = 0
if l >= 2:
    for i in range(1, l, 2):
        y += 9 * 10 ** (i-1)
    if l % 2 == 1:
        y += int(n) - int('9'*(l-1))
else: y = int(n)
print(y)

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

const int MN = 1e5+5;
int arr[MN], N, i, x, ans;

int main(){
    for(scanf("%d",&N),i=1;i<=N;i++)
        scanf("%d",&arr[i]);
    for(i=1;i<=N;i++){
        scanf("%d",&x);
        ans += max(0,arr[i]-x);
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef map<char,int> mci;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vii;
typedef vector<char> vc;
typedef vector<vc> vcc;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define F first
#define S second
#define in insert
#define mina(a,b) (a)=min((a),(b));
#define maxa(a,b) (a)=max((a),(b));
const int INF = 1e9 + 7;

void solve(){
    ll n; cin>>n;
    cout<<n*(n-1)/2;

}
int main(){
    int T=1;
    //cin>>T;
    for(int i = 0; i < T; i++) solve(); 
}

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

#define INF INT_MAX/2;
#define MOD 1000000007

using namespace std;

using ll = long long;
using ull = unsigned long long ;

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

   int N;
   cin>>N;
   set<int>d;
   for(int i=0;i<N;i++){
      int a;
      cin>>a;
      d.insert(a);
   }
   cout<<d.size();
   return 0; 
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define INF 1001001001
#define INFll 100100100100100
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

int main(){
  int n;
  cin >> n;
  vector<ull> a(n);
  ull ans=1, MX=1e18;
  rep(i, n){
    cin >> a[i];
    if(a[i]==0){
      cout << "0" << endl;
      return 0;
    }
  }
  rep(i, n){
    if(ans>MX/a[i] || ans*a[i]>MX){
      cout << "-1" << endl;
      return 0;
    } else{
      ans*=a[i];
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3976
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }

int main(void){
    // Your code here!
    int N,T;cin >> N >> T;
    vector<int> t(N);
    rep(i,N)  cin >> t[i];
    ll ans = 0;
    rep(i,N){
        if ( i == N-1) ans+=T;
        else {
        if (t[i+1]-t[i] < T) {
            ans+=(t[i+1]-t[i]);
            }
        else ans+=T;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
fun main(args: Array<String>) {
    val tens = mutableListOf<Int>()
    val noTens = mutableListOf<Int>()
    var answer = 0
    for (i in 1..5) {
        val s = readLine()!!.toInt()
        if (s % 10 == 0) tens.add(s) else noTens.add(s)
    }
    noTens.sortBy { it % 10 }
    for (i in tens.indices) {
        answer += tens[i]
    }
    for (i in noTens.indices) {
        answer += if (i == 0) noTens[i] else round(noTens[i])
    }
    println(answer)
}

fun round(i : Int) = i + 10 - (i % 10)


Measured memory_bytes: 31788
def DP_B() :
    N, K = map(int, input().split())
    h = [int(x) for x in input().split()]
    dp = [10**10]*N

    dp[0] = 0
    for i in range(1,N) :
        for k in range(1,K+1) :
            if i >= k :
                dp[i] = min(dp[i], dp[i-k] + abs(h[i] - h[i-k]))

    return dp[N-1]

print(DP_B())


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

using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int maxn = 110000;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    int x;
    cin >> x;
    int t = (x / 500) * 1000;
    int cur = x % 500;
    int cur1 = cur / 5;
    int ans = t + cur1 * 5;
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
lis = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())

print(lis[k-1])

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

#define repo(i,n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;

int main(){

    ll N,K;
    cin >> N >> K;
    vector<ll> H;
    repo(i,N){
        ll h;
        cin >> h;
        H.push_back(h);
    }

    if(N <= K){
        cout << 0 << endl;
        return 0;
    }
    sort(H.begin(), H.end());
    repo(i,K){
        H.pop_back();
    }
    ll ans = 0;
    repo(i,H.size()){
        ans+=H[i];
    }
//     if(H.size() > 0){
//     cout << accumulate(H.begin(),H.end(),0) << endl;
//     }else{
//         cout << 0 << endl;
//     }
    cout << ans << endl; 


    return 0;
}



Measured memory_bytes: 2420
/*
ID: jerrywcy
TASK: AtCoder ARC 092 Problem C
LINK: https://arc092.contest.atcoder.jp/tasks/arc092_a
LANG: C++
*/
#include <bits/stdc++.h>

using namespace std;

int main(){
  	long long n,ans=0,MAX,cnt;
  	cin >> n;
  	long long a[n],b[n],c[n],d[n];
  	bool f[n];
  	pair<long long,long long> re[n],bl[n];
  	for(int i=0;i<n;i++){
    	cin >> a[i] >> b[i];
    	re[i]=make_pair(a[i],b[i]);
    	f[i]=true;
  	}
  	for(int i=0;i<n;i++){
    	cin >> c[i] >> d[i];
    	bl[i]=make_pair(c[i],d[i]);
  	}
  	sort(re,re+n);
  	sort(bl,bl+n);
  	for(int i=0;i<n;i++){
    	MAX=-1;
    	cnt=0;
    	while(re[cnt].first<bl[i].first){
      		if(re[cnt].first<bl[i].first && re[cnt].second<bl[i].second && f[cnt])
			  	MAX=max(MAX,re[cnt].second);
      		cnt++;
    	}
    	if(MAX!=-1){
      		while(re[cnt].second!=MAX)cnt--;
      		f[cnt]=false;
      		ans++;
    	}
  	}
  	cout << ans << endl;
 	return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "Yes":"No"; }
void uniq(VI& es) { sort(ALL(es)); es.erase(unique(ALL(es)), es.end()); }

#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,M,W,H,K;
	string s;
	while(cin>>N>>K) {
		VI h(N);
		REP(i, N) cin>>h[i];
		sort(ALL(h));
		ll ans=INF;
		REP(i, N-K+1) minUpdate(ans, h[i+K-1]-h[i]);
		cout<<ans<<endl;
	}
	
	return 0;
}


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

const int MAX_N=1e6; // 1e8=x, 1e7=? 1e6=o
int n[MAX_N+1]={};

vector <int> prime;

void eratos_sieve(){
  for(int i=2;i<=MAX_N;i++){
    if(!n[i]){
      prime.push_back(i);
      for(int j=i;j<=MAX_N;j+=i) n[j]=1;
    }
  }
}

int main(){

  eratos_sieve();

  for(;;){
  int n,p;
  cin>>n>>p;
  if(!~n) break;

  vector <int> li,li_sum;
  auto origin=upper_bound(prime.begin(),prime.end(),n);
  int dis=distance(prime.begin(),origin);

  for(int i=dis;i<dis+p+1;i++) li.push_back(prime[i]);

  for(int i=0;i<(int)li.size();i++)
    for(int j=i;j<(int)li.size();j++)
      li_sum.push_back(li[i]+li[j]);

  sort(li_sum.begin(),li_sum.end());

  cout<<li_sum[p-1]<<endl;

  }

  return 0;

}



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

using namespace std;
#define sz(a) (int)a.size()
const int MAXN = 2e5 + 228;
template<typename T1, typename T2>
ostream &operator<<(ostream &out, pair<T1, T2> &p) {
     out << "{" << p.first << ", " << p.second << "} ";//optional
     return out;
}

template<typename T1, typename T2>
istream &operator>>(istream &in, pair<T1, T2> &p) {
     in >> p.first >> p.second;
     return in;
}

template<typename T>
istream &operator>>(istream &in, vector<T> &arr) {
     for (auto &i : arr)
          in >> i;
     return in;
}

template<typename T>
ostream &operator<<(ostream &out, vector<T> &arr) {
     for (int i = 0; i < (int)arr.size(); ++i) {
          if (i != 0) {
               out << ' ';
          }
          out << arr[i];//optional
     }
     out << endl;
     return out;
}

signed main()
{
     int n, p;
     cin >> n >> p;
     vector<int> a(n);
     cin >> a;
     bool flag = true;
     for (auto el : a) {
          if (el & 1) {
               flag = false;
          }
     }
     if (flag && p % 2 == 1) {
          cout << 0;
     } else if (flag) {
          cout << (1ll << n);
     } else {
          cout << (1ll << (n - 1));
     }
     return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m; i >= n; --i)
#define ALL(v) (v).begin(),(v).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
const int nmax=500005;
ll fac[nmax],finv[nmax],inv[nmax];
void COMinit(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for(int i=2;i<nmax;i++){
    fac[i]=fac[i-1]*i%mod;
    inv[i]=mod-inv[mod%i]*(mod/i)%mod;
    finv[i]=finv[i-1]*inv[i]%mod;
  }
}

ll com(int n,int k){
  if(n<k||n<0||k<0){
    return 0;
  }
  return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}

// 繰り返し二乗法 n*nが64bitにおさまる必要
ll pow_mod(ll n,ll k,ll m){
  ll res=1;
  for(;k>0;k>>=1){
    if(k&1){
      res=(res*n)%m;
    }
    n=(n*n)%m;  
  }
  return res;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;cin >> n >> m;
    COMinit();
    ll ans=com(m,n)*fac[n]%mod;
    vector<ll> p(n+1);
    REP(i,n+1){
        p[i]=com(n,i)*com(m-i,n-i)%mod*fac[n-i]%mod;
    }
    ll sum=0;
    REP(i,n+1){
        if(i%2==0){
            sum+=p[i];
            sum%=mod;
        }
        else{
            sum+=mod-p[i];
            sum%=mod;
        }
    }
    cout << ans*sum%mod << endl;
}

Measured memory_bytes: 18668
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    string s; cin>>s;
    int ans=0;
    for(int i=1; i<=s.size();i++){
        if((s.size()-i)%2)continue;
        string key;
        for(int j=0;j<s.size()-i;j++)
            key.push_back(s[j]);
        string a,b;
        for(int k=0; k<key.size();k++){
            if(k<(key.size())/2)a.push_back(key[k]);
            else b.push_back(key[k]);
        }
        if(a==b){cout<<key.size()<<endl; return 0;}
    }
    cout<<0<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
double dis(double xa,double ya,double xb,double yb){
    return sqrt((xa-xb)*(xa-xb)+(ya-yb)*(ya-yb));
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    double x[200001],y[200001],pi=3.14159265358979;
    cin>>n;
    rep(i,n) cin>>x[i]>>y[i];
    vector<pair<double,int>> A;
    rep(i,n){
        double a;
        if(x[i]==0) a=pi/2;
        else a=atan(y[i]/x[i])+(atan(y[i]/x[i])<0)*pi;
        if(y[i]<0) a+=pi;
        if(y[i]==0&&x[i]<0) a+=pi;
        A.push_back(make_pair(a,i));
    }
    sort(all(A));
    double ans=0;
    rep(i,n)for(int j=i;j<n+i;j++){
        double X=0,Y=0;
        for(int k=i;k<=j;k++) X+=x[A[k%n].second],Y+=y[A[k%n].second];
        ans=max(ans,dis(0,0,X,Y));
    }
    cout<<setprecision(11)<<ans<<"\n";
}

Measured memory_bytes: 2304
//bismillahir rahmanir rahim            //Author:Fayed Anik
 
#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;
 
//#define         ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define         ll                          long  long
#define         lf                          double
#define         pb(x)                       push_back(x)
#define         ull                         unsigned long long
#define         sfl(a)                      scanf("%lld",&a)
#define         sf(a)                       scanf("%d",&a)
#define         pf(a)                       printf("%d\n",a)
#define         pfl(a)                      printf("%lld\n",a)
#define         FOR(x,n)                    for(ll x=1;x<=n;++x)
#define         pii                         pair< ll , ll >
#define         mp(a,b)                     make_pair(a,b)
#define         UNIQUE(v)                   v.resize(distance(v.begin(),unique(v.begin(),v.end())))
#define         mod                         1000000007
#define         INF                         2e18
#define         EPS                         1e-15
#define         f1                          first
#define         f2                          second
#define         all(v)                      v.begin(),v.end()
#define         PI                          acos(-1)
#define         printminusone               printf("-1\n")
#define         bug                         printf("bug")
#define         FILEIN                      freopen("in.txt","r",stdin)
#define         FILEOUT                     freopen("out.txt","w",stdout)
 
//ll SET(ll mask,ll pos){ return mask = (mask | (1ll<<pos)); }
//ll RESET(ll mask,ll pos){ return mask = mask & ~(1ll<<pos); }
//bool CHECK(ll mask,ll pos) { return (bool) (mask & (1ll<<pos)); }
//priority_queue <ll, vector<ll>, greater<ll> > pq;
//int dx[]={0,0,1,-1,1,1,-1,-1};
//int dy[]={1,-1,0,0,1,-1,1,-1};

#define lim 200000+5

ll a[lim];
int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);  
    ll n,k,mx=0;
    sfl(n),sfl(k);
    FOR(i,n){
        sfl(a[i]);
        mx = max(mx,a[i]);
    } 
    ll lw=1,hi=1e10,mid,ans=mx,tot=0;
    while(lw<=hi){
        mid=(lw+hi)/2;
        tot=0;
        for(ll i=1;i<=n;i++){
            if(a[i]>mid) tot += a[i]/mid;
        }
        if(tot<=k){
            ans = mid;
            hi = mid-1;
        }
        else{
            lw = mid+1;
        }
    }
    pfl(ans);
    return 0;
}

Measured memory_bytes: 5336
package main

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

func main() {
	var n, z, w int
	fmt.Scan(&n, &z, &w)
	var a = scanInts(n)

	if n > 1 {
		if absInt(a[n-1]-w) < absInt(a[n-1]-a[n-2]) {
			z = a[n-2]
			w = a[n-1]
		} else {
			z = a[n-1]
		}
	} else if n == 1 {
		z = a[0]
	}

	ans := absInt(z - w)
	fmt.Println(ans)
}

func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func scanInts(len int) []int {
	result := make([]int, len)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for i := 0; i < len; i++ {
		if sc.Scan() {
			var err error
			result[i], err = strconv.Atoi(sc.Text())
			if err != nil {
				panic(err)
			}
		}
	}
	return result
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int64_t FastPow(int64_t n, int64_t m){
    if(m==0) return 1;
    if(m==1) return n;

    int64_t v=pow(n,m%2),_v=FastPow(n,m/2);

    v*=_v;
    v%=MOD;

    v*=_v;
    v%=MOD;

    return v;
}

int64_t RevS(int64_t n){
    return FastPow(n,MOD-2);
}

int64_t Factori(int64_t n,int64_t m){
    int64_t v=1;
    _rep(i,n,n-m+1){
        v*=i;
        v%=MOD;
    }
    return v;
}

int64_t Comb(int64_t n,int64_t m){
    int64_t v=Factori(n,m);
    v*=RevS(Factori(m,m));
    v%=MOD;
    return v;
}

int main(){
    int64_t n,a,b; cin>>n>>a>>b;

    int64_t ans=FastPow(2,n);

    ans--;
    ans%=MOD;

    ans-=Comb(n,a);
    if(ans<0) ans+=MOD;

    ans-=Comb(n,b);
    if(ans<0) ans+=MOD;

    cout<<ans<<endl;
}

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

int main(){
    string S, T, U;
    int A, B;
    cin >> S >> T;
    cin >> A >> B;
    cin >> U;

    if (S==U) cout << A-1 << " " << B << endl;
    else cout << A << " " << B-1 << endl;

    return 0;
}

Measured memory_bytes: 256
int main() {
    for (;;) {
        int n, x, i, j, k, ans = 0;
        scanf("%d %d", &n, &x);
        if (n == 0) break;

        for (i = 1; i <= n - 2; i++) {
            for (j = i + 1; j <= n - 1; j++) {
                for (k = j + 1; k <= n; k++) {
                    if (i + j + k == x) ans++;
                }
            }
        }
        printf("%d\n", ans);
    }
}


Measured memory_bytes: 2100
import java.io.InputStream;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

import static java.util.Comparator.*;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        Solver solver = new Solver(System.in, out);
        solver.solve();
        out.close();
    }
}
class Solver {
	Scanner sc;
	PrintWriter out;
    public Solver(InputStream in, PrintWriter out) {
    	sc = new Scanner(in);
    	this.out = out;
    }
    // ==================================================================
    public void solve() {
    	int N = Integer.parseInt(sc.next());
    	int wk;
    	for (int i = 1; i <= N; i++) {
			wk = (int)((double)(i * 1.08));
			if(wk == N) {
				out.println(i);
				return;
			}
		}
    	out.println(":(");
    }
    // ==================================================================
}
class PP{
	public int key, val;
	public PP(int key, int val) {
		this.key = key;
		this.val = val;
	}
	public int getKey() {
		return key;
	}
	public int getVal() {
		return val;
	}
}


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

int main(){
  int ans[8]={1,2,4,8,16,32,64,128};
  int n;
  cin >> n;
  for(int i=0;i<8;i++){
    if(ans[i]>n){
      cout << ans[i-1] << endl;
      break;
    }
  }
}
	


Measured memory_bytes: 256
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
//* vamsicool007    You are never wrong to do the right thing    vamsicool007 *
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
#include<bits/stdc++.h>
using namespace std;
#define flash ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define endl "\n"
#define int long long
typedef long long ll;
typedef long double ld;
const int mod = 1000000007;
const int N=200005;
vector<int>vis(N);
vector<vector<int>>adj(N);
void dfs(int v){vis[v]=1;for(auto i:adj[v]){if(!vis[i]){dfs(i);}}return;}
bool isPrime(ll n){if(n<2)return false;for(ll i=2;i*i<=n;++i){if(n%i==0){return false;}}return true;}
ll factorial(ll n){return (n==1 || n==0) ? 1:n*factorial(n-1);}
ll power(ll x,ll y){ll res=1;x=x;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res%mod;}
ll gcd(ll a,ll b){if (a==0)return b;return gcd(b%a,a);}
ll lcm(ll a,ll b){return (a/gcd(a,b)*b);}
ll max(ll a,ll b){ll ans=a>b?a:b;return ans;}
ll min(ll a,ll b){ll ans=a<b?a:b;return ans;}
int root(int a[],int i){while(a[i]!=i){a[i]=a[a[i]];i=a[i];}return i;}
void unionn(int a[],int i,int j){int root_i=root(a,i);int root_j=root(a,j);a[root_i]=root_j;return;}
// void fun()
// {
//     #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
//     #endif
// }

signed main()
{
    flash;
    //fun();
    int tt=1;
    //cin>>tt;
    while(tt--)
    {
        int n;
        cin>>n;
        map<string,int>m;
        for(int i=0;i<n;i++)
        {
            string s;
            cin>>s;
            m[s]++;
        }
        int c=0;
        for(auto i:m)
        {
            if(i.S>0)
                c++;
        }
        cout<<c<<endl;
    }
    return 0;
}

Measured memory_bytes: 25060
import java.util.*;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.ArrayDeque;
import java.util.Deque;


public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] nm = br.readLine().split(" ");
        int n = Integer.parseInt(nm[0]);
        int m = Integer.parseInt(nm[1]);
        boolean[] covered = new boolean[n+1];
        Interval[] abs = new Interval[m];
        
        for (int i = 0; i < m; i++) {
            String[] s = br.readLine().split(" ");
            int a = Integer.parseInt(s[0]);
            int b = Integer.parseInt(s[1]);
            Interval intr = new Interval(a, b);
            abs[i] = intr;
        }
        
        Arrays.sort(abs, new IntervalComparator());
        
        int count = 0;
        for (Interval ab : abs) {
            if (!covered[ab.b] && !covered[ab.a]) {
                count++;
                for (int i = 0; i < ab.b; i++) {
                    covered[i] = true;
                }
            }
        }
        
        System.out.println(count);
    }
}

class Interval {
    int a;
    int b;
    public Interval(int a, int b) {
        this.a = a;
        this.b = b;
    }
}

class IntervalComparator implements Comparator<Interval>{
	public int compare(Interval intr1, Interval intr2) {
		return intr1.b - intr2.b;
	}
}

Measured memory_bytes: 49352
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_s(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;

int main() {
  int h, w;
  cin >> h >> w;

  vector<char> a(h * w);
  vector<bool> enable(h * w);

  rep(i, h * w) {
    cin >> a[i];
    enable[i] = true;
  }

  // 横検索
  rep(_h, h) {
    bool is_white = true;
    rep(_w, w) {
      if (a[w * _h + _w] == '#') {
        is_white = false;
        break;
      }
    }
    if (is_white) {
      // 無効化しておく
      rep(_w, w) {
        enable[w * _h + _w] = false;
      }
    }
  }

  // 縦検索
  rep(_w, w) {
    bool is_white = true;
    rep(_h, h) {
      if (a[w * _h + _w] == '#') {
        is_white = false;
        break;
      }
    }
    if (is_white) {
      // 無効化しておく
      rep(_h, h) {
        enable[w * _h + _w] = false;
      }
    }
  }

  rep(_h, h) {
    bool is_out = false;
    rep(_w, w) {
      if (enable[w * _h + _w]) {
        is_out = true;
        cout << a[w * _h + _w];
      }
    }
    if (is_out) {
      cout << endl;
    }
  }

}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<set>
using namespace std;
#define int long long
const int N=200005;
struct D{int o,w,x;}d[N];
int n,va[2][N],b[2],a,r=1e18;bool v[2][N];
set<pair<int,int> >s;
bool cmp(D x,D y){return x.x<y.x;}
inline int mn(int x,int y){return x<y?x:y;}
signed main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;++i)
		scanf("%lld%lld",&d[i*2-1].x,&d[i*2].x),
		va[0][i]=d[i*2-1].x,va[1][i]=d[i*2].x,
		d[i*2-1].w=d[i*2].w=i,d[i*2-1].o=0,d[i*2].o=1;
	sort(d+1,d+n*2+1,cmp);
	for(int i=1;i<=n;++i)
		a+=d[i].x,++b[d[i].o],v[d[i].o][d[i].w]=1;
	if(b[0]==n||b[1]==n)return printf("%lld",a),0;
	for(int i=1;i<=n;++i)if(!v[0][i]&&!v[1][i])return printf("%lld",a),0;
	for(int i=n+1;i<=n*2;++i)s.insert(make_pair(d[i].x,d[i].w));
	for(int i=1;i<=n;++i)
		for(auto j=s.begin();j!=s.end();++j)
			if((*j).second!=i){r=mn(r,a+(*j).first-(v[0][i]?va[0][i]:va[1][i]));break;}
	return printf("%lld",r),0;
}

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

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

    map<char, int> alla {
        { '1', 2 }, { '2', 5 }, { '3', 5 },
        { '4', 4 }, { '5', 5 }, { '6', 6 },
        { '7', 3 }, { '8', 7 }, { '9', 6 },
    };

    map<char, int> a;
    for (int i=0; i<m; i++) {
        char c;
        cin >> c;
        a[c] = alla[c];
    }

    auto compare = [&](string a, string b) -> int {
        if (a.size() > b.size()) return 1;
        if (a.size() < b.size()) return -1;

        for (int i = 0, e = a.size(); i < e; i++) {
            if (a[i] == b[i]) continue;
            if (a[i] > b[i]) return 1;
            if (a[i] < b[i]) return -1;
        }

        return 0;
    };

    vector<string> dp(n + 1);
    
    for (int i = 0; i < n; i++) {
        for (auto& e : a) {
            if (i + e.second > n || (dp[i].empty() && i != 0)) continue;
        
            if (compare(e.first + dp[i], dp[i + e.second]) == 1) {
                dp[i + e.second] = e.first + dp[i];
            }
        }
    }

    cout << dp[n] << endl;
}


Measured memory_bytes: 32384
L, R = map(int, input().split())

def mod(num):
    return num % 2019


#  (2019a + x)(2019b + y) = 2019(n) + xy

ans = 10 ** 9

lr = min(R, L + 2019) + 1

for i in range(L, lr):
    for j in range(i + 1, lr):
        ans = min(ans, mod(i * j))
        
print(ans)

Measured memory_bytes: 9060
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <map>
#include <vector>
#include <stack>
#include <queue>

using namespace std;

#define inf                  1e9   // this is double value
#define ms(a,b)              memset(a,b,sizeof a)
#define CLR(a)               memset(a,0,sizeof a)
#define input_file           freopen("in.txt","r",stdin)
#define output_file          freopen("out.txt","w",stdout)
#define N                    100000008
#define LL                   long long
#define nl                   printf("\n")
#define spc                  printf(" ")
#define isValid(x,y,dx,dy)   ((0<=dx&&dx<x) && (0<=dy&&dy<y)) 
#define Abs(a,b)             a>b ? a-b : b-a

int main()
{
	LL n,sum,temp,min,diff,i,arr[200005],x;
	while(cin>>n)
	{
		sum=0;
		for(i=0; i<n; i++)
		{
			cin>>arr[i];
			sum+=arr[i];
		}
		//sort(arr,arr+n);
		temp=0;
		min=10000000000;
		for(i=0; i<n-1; i++)
		{
			temp+=arr[i];
			x=sum-temp;
			diff=Abs(x,temp);
			if(diff<min)
			{
				min=diff;
			}
		}
		cout<<min<<endl;
	}
	return 0;
}



Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
#include<stack>
#include<map>
#include<math.h>
#include<string>
#include <cctype>
#include <cstdlib>
#include<bitset>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl;
#define INF 1ll<<60;
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; }

using namespace std;
using ll = long long;
typedef pair<int, int> P;

int main(){
    string s; cin >> s;
    string str="";
    rep(i, s.size()){
        if(s[i]=='0'){
            str+='0';
        }
        else if(s[i]=='1'){
            str+='1';
        }
        else{
            if(str=="")continue;
            else str.erase(str.end()-1);
        }
    }
    out(str);
}

Measured memory_bytes: 3604
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
  long long a,b,c;
  cin >> a >> b >> c;
  
  if((a * b * c) % 2 == 0)
    cout << 0 << endl;
  else
    cout << min({a * b,b * c,c * a}) << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, a, b, c, d;

bool possA[N], possB[N];
string s;

void yes(){
   cout<<"Yes"<<endl;
   exit (0);
}
void no(){
   cout<<"No"<<endl;
   exit (0);   
}

int32_t main(){_

   cin>>n>>a>>b>>c>>d;
   cin>>s;   
   s = '#' + s;

   int cnt = 0;

   memset(possA, 0, sizeof possA);
   memset(possB, 0, sizeof possB);
   

   for (int i = a; i <= c; ++i)
   {
      if(s[i] == '#'){
         cnt++;
         if(cnt == 2){
            no();
         }
         continue;
      }
      cnt = 0;
      possA[i] = 1;
   }
   
   cnt = 0;
   for (int i = b; i <= d; ++i)
   {
      if(s[i] == '#'){
         cnt++;
         if(cnt == 2){
            no();
         }
         continue;
      }
      cnt = 0;
      possB[i] = 1;
   }

   if(!possA[c] or !possB[d]){
      no();
   }

   if (c < d){
      yes();
   }

   for (int i = 1; i+2 <= n; ++i)
   {
      if(possA[i] and possB[i+1] and possA[i+2]){
         tr(i, i+1, i+2);
         yes();
      }
   }

   no();

   return 0;
}

// Common sense: do smth instead of nothing
// Even a single second counts...
// If other's can do it, even I can do it. It wouldn't be that tough. Let me give it a try.
// Mistakes made in past
// -Ques. ask for max-min => think binary_search, DP, greedy
// -not reading question properly / skipping to read & understand all samples properly & wasting time in wrong direction.
// -Using wrong indexing in nested loops something like a[i], when it is supposed to be a[j](WA)
// -value of const int N is not correct (WA/RTE).
// -Did you memset dp to -1 ?
// -check for small edges cases and work on small test cases manually if WA
// -not deallocating memory to pointers can lead to MLE. Use delete :))
// -not reading problem statements of harder problems E,..., thinking it couldn't be solved, but it isn't the case.
// -Avoid using #define int long long as much as possible when it's dp problem and requires high memory say, O(N^2, N=5000) (MLE)
// -Check Bitwise Operator Precedence 
// -Use pragmas to optimize (by constant factor) when necessary..
// -Think before coding & starting to debug. Have patience to look inside code and actually see how it works

Measured memory_bytes: 1560
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <tuple>
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Range(container) container.begin(), container.end()
#define Cin(T, x) T x; cin >> x;
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i];
#define Cout(val) cout << (val) << "\n";
using namespace std;
using ll = long long;

int main(void){
    Cin(int, n);
    Cin(int, m);
    vector<tuple<int,int,int>> cities(m);
    For(i, m){
        cin >> get<1>(cities[i]) >> get<0>(cities[i]);
        get<2>(cities[i]) = i;
    }
    sort(Range(cities));
    vector<int> nums1(m), nums2(m), ords(n);
    for(const auto &city : cities) nums1[get<2>(city)] = get<1>(city), nums2[get<2>(city)] = ++ords[get<1>(city)];
    
    For(i, m) printf("%06d%06d\n", nums1[i], nums2[i]);
}

Measured memory_bytes: 3840
// //bitset操作
// #include <iostream>
// #include <bitset>
// #include <algorithm>
 
// using namespace std;
 
// bitset<5> cookie[10]; 

// int main()
// {
 
//     int R, C;bool upwards;
// 	while(cin >> R >> C && R > 0)
// 	{
// 		int i, j;
// 		for (i = 0; i < R; ++i)
// 		{
// 			for (j = 0; j < C; ++j)
// 			{			
// 				cin >> upwards;
// 				cookie[i][j] = upwards;
// 			}
// 		}
// 		// 在横向一共有2^R种变换
// 		int permute_r = 1 << R;
// 		int result = 0;
// 		for (i = 0; i < permute_r ; ++i)
// 		{	
// 			// 完成当前的变换
// 			for (j = 0; j < R; ++j)
// 			{
// 				//cout<<cookie[j]<<endl;
// 				int temp=1<<j;
// 				cout<<endl;
// 				cout<<i<<" "<<temp<<endl;
// 				int res=i&(1<<j);
// 				cout<<res<<endl;
// 				cout<<endl;
// 				// 这一行是否应当翻个面
// 				if (i & (1 << j))
// 				{
// 					cookie[j].flip();
// 				//	cout<<cookie[j]<<endl;
// 				}
// 			}
// 			// 对每一列分别算出朝上和朝下的煎饼个数，取其最大值
// 			int possible_answer = 0;
// 			for (j = 0; j < C; ++j)
// 			{
// 				int up_cookie_count = 0;
// 				for (int k = 0; k < R; ++k)
// 				{
// 					if (cookie[k][j])
// 					{
// 						++up_cookie_count;
// 					}
// 				}
// 				possible_answer += max(up_cookie_count, R - up_cookie_count);
// 			}
// 			// 结果取最大值
// 			result = max(result, possible_answer);			
// 			for (j = 0; j < R; ++j)
// 			{
// 				if (i & (1 << j))
// 				{
// 					cookie[j].flip();
// 				}
// 			}
// 		}
// 		cout << result << endl;
// 	}
 
//     return 0;
// }
//dfs
#include<iostream>
#include<cstdio>
#include<bitset>

using namespace std;

#define rep(i,a,b) for(int i=a;i<b;i++)
int readint(){int n;scanf("%d",&n);return n;}

bitset<10000>bookie[10];
int r,c,res;

void dfs(int row)
{
	if(row==r){
		int temp=0,temp1;
		rep(i,0,c){
			temp1=0;
			rep(j,0,r){
				if(bookie[j][i]==0){
					temp1++;
				}
			}
			temp+=max(temp1,r-temp1);
		}
		if(res<temp){
			res=temp;                 
		}
		return ;
	}
	rep(i,0,2){
		if(i==0){
			dfs(row+1);
		}
		if(i==1){
			bookie[row].flip();
			dfs(row+1);
			bookie[row].flip();
		}
	}
}

int main()
{
	while(cin>>r>>c){
		if(r==0&&c==0){
			break;
		}else{
			rep(i,0,r){
				rep(j,0,c){
					bookie[i][j]=readint();
				}
			}
			res=0;
			dfs(0);
			cout<<res<<endl;
		}
	}
	return 0;
}




Measured memory_bytes: 3140
#include <bits/stdc++.h>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;

int main(){
	int n,k; cin>>n>>k;
	string s; cin>>s;
	s[k-1]+=0x20;
    cout << s << endl;
}


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

int main() {
	int n;
	cin >> n;
	vector<double> p(n);
	for(int i=0; i<n; i++) {
		cin >> p[i];
	}
	vector< vector<double> > dp(n+1, vector<double>(n+1, 0));
	dp[0][0]=1;
	for (int i=1; i<=n; i++) {
		dp[i][0] = dp[i-1][0]*(1-p[i-1]);
		dp[i][i] = dp[i-1][i-1]*p[i-1];
	}
	for (int i=2; i<=n; i++) {
		for (int j=1; j<i; j++) {
			dp[i][j] = dp[i-1][j-1]*p[i-1] + dp[i-1][j]*(1-p[i-1]);
		}
	}
	double ans=0;
	for (int i=(n+1)/2; i<=n; i++)
		ans+=dp[n][i];
	cout << setprecision(15)<< ans << endl;
}

Measured memory_bytes: 70784
#include <iostream>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
//#include <math.h>
#include <vector>
//#include <string>
//typedef long long LL;
using namespace std;

#define MATRIX 100010

int main(){
    int n;
    int ans;
    int tmp_a;
    int tmp_b;
    int a1=0;
    int b1=0;
    int a2=0;
    int b2=0;
    cin >> n;
    vector<int> a(MATRIX, 0);
    vector<int> b(MATRIX, 0);
    for(int i=0; i<n; i+=2){
        cin >> tmp_a;
        cin >> tmp_b;
        a[tmp_a]++;
        b[tmp_b]++;
    }
    for(int i=1; i<MATRIX; i++){
        if(a[a1]<a[i]){
            a2=a1;
            a1=i;
        }else if(a[a2]<a[i]){
            a2=i;      
        }
        if(b[b1]<b[i]){
            b2=b1;
            b1=i;
        }else if(b[b2]<b[i]){
            b2=i;      
        }
    }
    if(a1!=b1){
        ans = n-(a[a1]+b[b1]);
    }else if((a[a1]+b[b2])>(a[a2]+b[b1])){
        ans = n-(a[a1]+b[b2]);
    }else{
        ans = n-(a[a2]+b[b1]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cmath>
#define PLEN 1000010
using namespace std;

int gcm ( int a, int b ) {
	int temp;

	while ( a != 0 ) {
		
		temp = a-b;
		a = b;
		b = temp;
	}
	return b;
}
		

int dish[30];
bool oprime[PLEN];
bool data[PLEN];

int main () {

	for ( int i=0; i<PLEN; i++ ) {
		oprime[i++] = false;
		oprime[i] = true;
	}

	oprime[2] = true;

	int limit;
	limit = (int)(sqrt((double)PLEN));

	for ( int i=3; i<limit; i+=2 ) {
		for ( int j=1; j<PLEN; j+=2 ) {
				if ( j != i ) {
				if ( (j % i) == 0 ) {
						oprime[j] = false;
				}
			}
		}
	}

	oprime[1] = false;

	//cout << "Start" << endl;
	
	while(true) {
		int dishNum;
		cin >> dishNum;

		int budget;
		cin >> budget;

		if ( dishNum == 0 )
			break;


		for ( int i=0; i<=budget; i++ ) {
			data[i] = false;
		}


		for ( int i=0; i<dishNum; i++ ) {
			cin >> dish[i];
			data[dish[i]] = true;
		}

		int count = 1;

		while ( true ) {
			bool done = false;

			for ( int i=0; i<=budget; i++ ) {
				if ( data[i] ) {
					for ( int j=0; j<dishNum; j++ ) {
						if ( i + dish[j] <= budget ) {
							if ( !data[i+dish[j]] ) {
								data[i+dish[j]] = true;
								done = true;
							}
						}
					}
				}
			}

			//cout << "Pass" << count++ << endl;

			if ( !done )
				break;
		}
		/*
		for ( int i=0;i<=budget; i++ ) {
			if ( data[i] )
				{
					if ( i%10 )
						//cout << i << endl;
				}
		}
		*/
		int answer = 0;

		for ( int i=0; i<=budget; i++ ) {
			if ( data[i] ) {
				if ( oprime[i] ) {
					//cout << "S" << i << endl;
					if ( answer < i )
						answer = i;
				}
			}
		}
		
		if ( answer != 0 )
			cout << answer << endl;
		else
			cout << "NA" << endl;
	}
}

Measured memory_bytes: 2816
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include<set>
#include<map>
using namespace std;
#define rep(i,n) for(int i=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int i=(m);(i)<(n);(i)++)
typedef long long ll;
const int dx[8] = {0,1,1,1,0,-1,-1,-1};
const int dy[8] = {1,1,0,-1,-1,-1,0,1};
int w,h,res;

void dfs(int x,int y,int f,vector<vector<int> >& mp){
    if(mp[y][x]==1){
        if(f==0){
            f=1;
            res++;
        }
        mp[y][x]=0;
        rep(i,8){
            int nx=x+dx[i],ny=y+dy[i];
            if(nx>=0&&nx<w&&ny>=0&&ny<h){
                dfs(nx,ny,f,mp);
            }
        }
    }

}

int main(){
    while(cin >> w >> h,w|h){
        vector<vector<int> > c(h,vector<int>(w));
        
        rep(i,h)rep(j,w)cin >> c[i][j];
        res=0;
        rep(i,h)rep(j,w)dfs(j,i,0,c);
        cout << res << endl;
    }   
    return 0;
}


Measured memory_bytes: 3232
from collections import defaultdict
from bisect import bisect_left
def bubble_sort(A):
    cnt = 0
    for i in range(len(A)):
        for j in range(len(A)-1, i, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                cnt += 1
    return cnt

def main():
    N,K = map(int,input().split())
    A = [int(x) for x in input().split()]
    mod = 10**9 + 7
    
    falls = bubble_sort(A)
    rank = 0
    for i in A:
        rank += bisect_left(A,i)
        
    falls_all = (falls*K)%mod
    rank_all  = ((K*(K-1))//2)%mod
    rank_all  = (rank_all*rank)%mod

    print((falls_all+rank_all)%mod) 
    




if __name__ == "__main__":
    main()

Measured memory_bytes: 42092
#include "bits/stdc++.h"
using namespace std;
/*ABC075-B "Minesweeper"*/
int h, w;
vector<vector<char> > maps(50, vector<char> (50));
vector<vector<int> > nmap(50, vector<int> (50));
vector<vector<char> > ansmap(50, vector<char> (50));
void find_bomb(int h, int w, int i, int j){
    if(0 < i){ //一番上の行でない時
        if(0 < j){ //一番左の列でない時
        if(maps.at(i - 1).at(j - 1) == '#'){
        nmap.at(i).at(j)++;
        }
        }
        if(maps.at(i - 1).at(j) == '#'){
        nmap.at(i).at(j)++;
        }
        if(j < w - 1){//一番右の列でない時
        if(maps.at(i - 1).at(j + 1) == '#'){
        nmap.at(i).at(j)++;            
        }
        }
    }
    if(0 < j){//一番左の列でない時
        if(maps.at(i).at(j - 1) == '#'){
        nmap.at(i).at(j)++;
        }
     }   
    if(j < w - 1){//一番右の列でない時
        if(maps.at(i).at(j + 1) == '#'){
        nmap.at(i).at(j)++;
        }
    }
    if(i < h - 1){
        if(0 < j){//一番左の列でない時
        if(maps.at(i + 1).at(j - 1) == '#'){
        nmap.at(i).at(j)++;
        }
        }
        if(maps.at(i + 1).at(j) == '#'){
        nmap.at(i).at(j)++;
        }
        if(j < w - 1){//一番右の列でない時
        if(maps.at(i + 1).at(j + 1) == '#'){
        nmap.at(i).at(j)++;        
        }
        }
    }
}
void solve(){
    cin >> h >> w;
    string s;
    for(int i = 0; i < h; i++){
        cin >> s;
        for(int j = 0; j < w; j++){
            maps.at(i).at(j) = s.at(j);
        }
    }
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            find_bomb(h, w, i, j);
        }
    }
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(maps.at(i).at(j) == '#'){
                cout << '#';
                if(j == w - 1)
                cout << endl;
            }
            else if(j == w - 1){
                cout << nmap.at(i).at(j) << endl;
            }
            else 
            cout << nmap.at(i).at(j);
        }
    }
}
int main(){
    solve();
    return 0;
}


Measured memory_bytes: 256