akhauriyash/Code-Regression huggingface dataset:
<?php

fscanf(STDIN, "%d", $n);
$A = array_map('intval', explode(' ', trim(fgets(STDIN))));
rsort($A);

$pq = new SplPriorityQueue();
$pq->insert(0, 0);

$ans = $A[0];

for ($i = 1; $i < $n; ++$i) {
    // この値だけ心地よさが増える
    $ans += $pq->extract();

    $pq->insert($A[$i], $A[$i]);
    $pq->insert($A[$i], $A[$i]);
}

echo $ans, PHP_EOL;


Measured memory_bytes: 41284
#include<bits/stdc++.h>
using namespace std;
string s,t;
int ans=3000;
int main()
{
	cin>>s>>t;
	for(int i=0;i<=s.size()-t.size();++i)
	{
		int tot=0;
		for(int j=0;j<t.size();++j)
		 if(t[j]!=s[i+j]) ++tot;
		if(tot<ans) ans=tot;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3624
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);
#define FO cout.tie(NULL);
#define FI cin.tie(NULL);
#define IN cin>>
#define OUT cout<<
#define loop(i,a,n) for(long long int i=a; i<n; i++)
#define rloop(i,a,n) for(long long int i=a; i>=n; i--)
#define endl "\n";
#define pb push_back
#define mp make_pair
#define set_bits(a) __builtin_popcount(a)
#define mod 1000000007
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define vll vector<long long int>
#define pll pair<long long int, long long int>
#define stkll stack<ll>
#define qll queue<ll>
#define pqll priority_queue<ll>
#define M 998244353
ll gcd(ll a, ll b)
{
    return (b?gcd(b,a%b):a);
}
ll P(ll B, ll power, ll modulo)
{
    ll ans=1;
    while(power>0)
    {
        if(power%2==1)
        {
            ans=(ans*B)%modulo;
        }
        B=(B*B)%modulo;
        power/=2;
    }
    return ans;
}
bool isPrime(ll n)
{
    if(n<=1)
    {
        return false;
    }
    if(n<=3)
    {
        return true;
    }
    if(n%2==0 || n%3==0)
    {
        return false;
    }
    for(ll i=5; (i*i)<=n; i+=6)
    {
        if(n%i==0 || n%(i+2)==0)
        {
            return false;
        }
    }
    return true;
}
using namespace std;
bool sortbysec(const pair<int,int> &a, const pair<int,int> &b)
{
    return (a.second<b.second);
}
bool sortbysecll(const pll &a, const pll &b)
{
    return (a.second<b.second);
}
ll modinv(ll x, ll y)
{
    return ((x%mod)*(P(y,mod-2,mod)%mod))%mod;
}
int main()
{
    FAST
    FO
    FI
    string s,t;
    IN s>>t;
    string ans= t+s;
    OUT ans<<endl
    return 0;
}


Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<vector>
#include<stack>
#include<string>
#include<algorithm>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<functional>
#include<iostream>
#include<cmath>
#include<cstdlib>
#define NN "\n"
#define mod 1000000007
typedef  long long ll;
typedef long double lb;
using namespace std;

 //vector<ll> v1;
// vector <int> v2;
// vector <int> v3;
//vector <int> v4;

//for (int i=0;i<n;i++){
//
//}

// ll multi(vector<ll> v){
//     ll mul=1;
//     for (int i=0;i<v.size();i++){
//         mul=mul*v[i];
//     }   
//     return mul;
// }
vector<pair<ll, string>> v1;
vector<ll> temp;



// logic(){
//   auto e= find(v1.begin(), v1.end(), )  
// }

string solve(){
    string s,s1,s2,s3;
    cin>>s;
    int n;
    n=s.length()-1;
    s1="s";
    s2="es";
    if(s[n]!='s'){
        s.append(s1);
        return s;
    } 
    if(s[n]=='s'){
        s.append(s2);
        return s;
    }
    
}

int main(){ios_base::sync_with_stdio(false);cin.tie(NULL);
    string s;
    s=solve();
    cout<<s;
    
    return 0;
}

Measured memory_bytes: 3648
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt();
		int x = sc.nextInt(), y = sc.nextInt();
		int min = x*a+y*b;
		min = Math.min(min, 2*y*c+Math.max(0,x-y)*a);
		min = Math.min(min, 2*x*c+Math.max(0,y-x)*b);
		min = Math.min(min, 2*Math.max(x,y)*c);
		System.out.println(min);
		sc.close();
	}
}

Measured memory_bytes: 23764
/* -------------------------------- Template -------------------------------- */

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = std::min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = std::max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

// template<typename T> constexpr T inf;
// template<> constexpr int inf<int> = 1e9;
// template<> constexpr ll inf<ll> = 1e18;
// template<> constexpr ld inf<ld> = 1e30;

struct yes_no : std::numpunct<char> {
  string_type do_truename()  const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

void solve();

int main() {
  std::locale loc(std::locale(), new yes_no);
  std::cout << std::boolalpha << std::setprecision(12) << std::fixed;
  std::cout.imbue(loc);
  solve();
  return 0;
}

using namespace std;

/* -------------------------------- Library -------------------------------- */

/* ---------------------------------- Main ---------------------------------- */

void solve() {
  int N, M;
  cin >> N;
  vector<int> T(N);
  for (int &i: T) cin >> i;
  int sum = accumulate(ALL(T), 0);
  cin >> M;
  REP(i,M) {
    int P, X;
    cin >> P >> X;
    cout << sum + X - T[P-1] << endl;
  }
  return;
}


Measured memory_bytes: 256
n = int(input())
points = [0] + list(map(int,input().split())) + [0]
time = [0]
for a, b in zip(points, points[1:]):
    time.append(time[-1] + abs(a - b))
for i in range(n):
    ans = time[i] + abs(points[i] - points[i+2]) - time[i+2] + time[-1]
    print(ans)


Measured memory_bytes: 14908
#include<iostream>
using namespace std;
int main(){
  while(1){
    int x,y,s,ans=0,a,b,m;
    cin>>x>>y>>s;
    if(x==0)break;
    for(a=1;a<s;a++)
      for(b=a;b+a<=s;b++){
	m=a*(100+y)/100+b*(100+y)/100;
	if(a*(100+x)/100+b*(100+x)/100==s&&ans<m)ans=m;
      }
    cout<<ans<<endl;
  }
  return 0;
}

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

map<int, int> m;

int cal(int h) {
  if (m[h]) return m[h];
  return m[h] = 1 + cal(h / 2) * 2;
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int h;
  cin >> h;
  m[1] = 1;
  cout << cal(h) << '\n';
}


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

import sys
import math


debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        for line in sys.stdin:
            lines.append(line.strip())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    (n, x, t) = [int(e) for e in lines[0].split(" ")]
    

    return (n, x, t)


def solve(n, x, t):

    tmp = n // x 
    if n % x == 0:
        result = tmp * t
    else:
        result = (tmp + 1 ) * t


    return result
    


def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':

    main()
	

Measured memory_bytes: 61964
#include<bits/stdc++.h>
using namespace std;
int n,k,ans;
int a[100000];
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	sort(a+1,a+1+n);
	for(int i=n;i>=n-k+1;i--)
		ans+=a[i];
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define db double
#define iosks std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
const int N=5e5+10,M=3e4+10;
const ll inf=INT_MAX,mod=1e9+7;
const db pi=atan(1)*4;
ll pow2(ll a,ll b) {ll s=1; while(b) {if(b&1) s=(s*a)%mod; a=(a*a)%mod; b/=2; } return s;}
ll lcm(ll a,ll b) {return a/__gcd(a,b)*b; }
int read()
{
    int s=0,f=1; char ch=getchar();
    while(ch<'0'&&ch>'9') {if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9') {s=s*10+ch-'0'; ch=getchar();} return s*f;
}

int n,k;
int a[N];

int main()
{
    iosks;
    cin>>n>>k;
    for(int i=0;i<n;i++) cin>>a[i];
    ll l=0,r=1e9+10,mid;
    while(r-l>1){
        mid=(l+r)/2;
        int c=0;
        for(int i=0;i<n;i++) if(a[i]>mid) c+=(a[i]-1)/mid;
        if(c>k) l=mid;
        else r=mid;
    }
    cout<<r<<endl;
    return 0;
}


Measured memory_bytes: 4388
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

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;
}

const ll MOD = 1e9 + 7;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }

int main() {
   char b;
   cin >> b;
   if (b == 'A') cout << 'T' << endl;
   if (b == 'T') cout << 'A' << endl;
   if (b == 'C') cout << 'G' << endl;
   if (b == 'G') cout << 'C' << endl;
   return 0;
}


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

bool wf[200][200];

int main(){
	int N;
	cin >> N;
	for(int i = 0 ; i < N ; i++){
		int a,b;
		string c;
		cin >> a >> c >> b;
		--a,--b;
		if( c == "wait" ){
			wf[a][100+b] = true;
		}else{
			wf[b+100][a] = true;
		}
	}
	bool found = false;
	for(int i = 0 ; i < 200 ; i++){
		for(int j = 0 ; j < 200 ; j++){
			for(int k = 0 ; k < 200 ; k++){
				wf[j][k] |= wf[j][i] & wf[i][k];
			}
		}
	}
	for(int i = 0 ; i < 200 ; i++)
		found |= wf[i][i];
	cout << found << endl;
	
	
	

}

Measured memory_bytes: 3204
#include <iostream>
//#include <iomanip>
//#include <string>
//#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	ll a,b,c,x,y ;
	cin >> a >> b >> c >> x >> y ;
	cout << min(min(max(x,y)*2*c,min(x,y)*2*c+(x>y?(x-y)*a:(y-x)*b)),x*a+y*b) << endl ;
}



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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;
}
int64_t abs(int64_t n) {
  if (n < 0) {
    n = -n;
  }
  return n;
}

int main() {
  int n, w;
  cin >> n >> w;
  vector <int64_t> weight(n);
  vector <int64_t> value(n);
  rep(i, n) {cin >> weight.at(i) >> value.at(i);}
  vector <vector <int64_t>> dp(n+10, vector <int64_t>((int)pow(10, 5)+10, 0));
  rep(i, n) {
    for (int sum_w = 0; sum_w <= w; sum_w++) {
      if (sum_w-weight.at(i) >= 0) {
        chmax(dp.at(i+1).at(sum_w), dp.at(i).at(sum_w-weight.at(i))+value.at(i));
      }
      chmax(dp.at(i+1).at(sum_w), dp.at(i).at(sum_w));
    }
  }
  cout << dp.at(n).at(w) << endl;
}

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

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

  int cnt[26] = {0};
  for (int i = 0; i < h * w; ++i) {
    char c;
    cin >> c;
    cnt[c % 26]++;
  }

  int a = 0, b = 0;
  for (int i = 0; i < 26; ++i) {
    if (cnt[i] & 1) {
      a++;
      cnt[i]--;
    }
    if (cnt[i] % 4) {
      b++;
    }
  }

  int c = (h & 1) && (w & 1);
  int d = (w & 1) * (h / 2) + (h & 1) * (w / 2);

  cout << (a == c && b <= d ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)

using namespace std;

int main() {
  char C;
  cin>>C;
  C++;
  cout<<C<<endl;
}

Measured memory_bytes: 256
main(m,f,r){for(;scanf("%d%d%d",&m,&f,&r),~m||~f||~r;puts(m==-1||f==-1?"F":m+f>=80?"A":m+f>=65?"B":m+f>=50?"C":m+f<30?"F":r<50?"D":"C"));exit(0);}

Measured memory_bytes: 584
//BELIEVE IN YOURSELF
//next_permutation

#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define pob pop_back
#define vi vector<ll>
#define mp make_pair
#define sz size()
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define rep(i,n) for(ll i=0;i<n;i++)
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define maxx 205
#define se second
#define fi first
#define be begin()
#define en end()
#define sortv(v) sort(v.begin(),v.end());
#define sortr(v) sort(v.rbegin(),v.rend());
#define w() ll _;cin>>_;while(_--)
#define edge pair<ll,ll>
#define pq priority_queue<ll>
#define mod 1000000007
#define Endl "\n"
#define cy cout<<"YES"<<endl;
#define cn cout<<"NO"<<endl;
#define lb(v,x) std::lower_bound(v.begin(),v.end(),x)
#define ub(v,x) std::upper_bound(v.begin(),v.end(),x)

using namespace std;

//------BEAST MODE ON------------
//-----fuck rating

int main()
{
	fast;
	
	ll n,x,t;
	cin>>n>>x>>t;
	
	ll ans=(n/x+(n%x!=0))*t;
	
	cout<<ans<<endl;
	
	
	return 0;	
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define degreeToRadian(deg) (((deg)/360)*2*M_PI)
#define radianTodegree(rad) (((rad)/2/M_PI)*360)
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; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const int MOD = 1e9 + 7;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//cin.tie(0);ios::sync_with_stdio(false);
//cout << fixed << setprecision(15) << y << endl;
int main() {
  string s; cin >> s;
  string t = "";
  string tt = "";
  rep (i, s.size()) {
    if (i % 2 == 0) t += '0';
    else t += '1';
  }

  rep (i, s.size()) {
    if (i % 2 == 0) tt += '1';
    else tt += '0';
  }

  int c, cc;
  c = cc = 0;

  rep (i, s.size()) {
    if (s[i] != t[i]) c++;
    if (s[i] != tt[i]) cc++;
  }

  cout << min(c, cc) << endl;
  return 0;
}


Measured memory_bytes: 3812
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <string>
#include <numeric>
#include <algorithm>
#include <functional>
#include <iterator>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <complex>
#include <ctime>
#define ll long long
#define inf 0x3f3f3f3f
#define N 200010
//ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
int father[N],num[N];
void init()
{
    for(int i=1;i<N;i++)
        father[i]=i;
}

int Find(int x)
{
    if(father[x]==x)
        return x;
    else
        return father[x]=Find(father[x]);
}

int main(){
    init();
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        a=Find(a);
        b=Find(b);
        if(a!=b)
            father[a]=b;
    }
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        num[Find(i)]++;
        ans=max(ans,num[Find(i)]);
    }
    printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 10612
use std::io;
use std::str::FromStr;

fn input_tuple() -> (i64, i64) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<i64> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1])
}

fn input<T:FromStr>() -> T {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().parse().ok().unwrap()
}

fn main() {
    let (a, v) = input_tuple();
    let (b, w) = input_tuple();
    let t: i64 = input();
    if v <= w {
        println!("NO");
    } else {
       if (a-b).abs() <= t * (v - w) {
           println!("YES");
       } else {
           println!("NO");
       }
    }
}


Measured memory_bytes: 2148
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;


int main() {
  int K;
  std::cin >> K;
  std::vector<int> A(K);
  for(int i=0;i<K;i++) std::cin >> A[i];

  long long l = 0, r = 1LL<<60, mid, ansmin, ansmax;
  while(r-l>1){
    mid = (l+r)/2;
    long long a = mid;
    for(int i=0;i<K;i++){
      a = (a/A[i]) * A[i];
    }
    if(a > 2) r = mid;
    else l = mid;
  }
  ansmax = l;
  l = 0, r = 1LL<<60;
  while(r-l>1){
    mid = (l+r)/2;
    long long a = mid;
    for(int i=0;i<K;i++){
      a = (a/A[i]) * A[i];
    }
    if(a>=2) r = mid;
    else l = mid;
  }
  ansmin = r;
  if(ansmax - ansmin <= 0){
    std::cout << -1 << '\n';
    return 0;
  }
  std::cout << ansmin << " " << ansmax << '\n';
  return 0;
}


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

int main() {
  int H,W,i;
  int f=0,t=0;
  int o;
  string str="No";
  cin >> H >> W;
  int a[26];
  for(i=0;i<26;i++) a[i]=0;

  for(i=0;i<H*W;i++) {
    char x;
    cin >> x;
    a[x-'a'] += 1;
  }

  for(i=0;i<26;i++) {
    f += a[i]/4;
    t += (a[i]%4)/2;
    o += a[i]%2;
  }
  if(H%2==0&&W%2==0) {
    if(f == (H*W)/4) str = "Yes";
  }
  else if(H%2!=0 && W%2!= 0) {
    if(f>=(H/2)*(W/2) && (f-(H/2)*(W/2))*2+t >= H/2+W/2) {
    str = "Yes";
    }
  }
  else if(H%2==0) {
    if(f>=(H/2)*(W/2) && (f-(H/2)*(W/2))*2+t >= H/2) str = "Yes";
  }
  else {
    if(f>=(H/2)*(W/2) && (f-(H/2)*(W/2))*2+t >= W/2) str = "Yes";
  }
  cout << str << endl;
  return 0;
}   

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <limits>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <array>
#include <tuple>
#include <utility>
#include <cctype>
#include <typeinfo>
using namespace std;

#define len(x)  (int((x).size()))
#define append push_back
#define pp make_pair
#define ff(a, b)    for (int a = 0; a < int(b); ++a)
#define ii(n)    ff(i, n)
#define kk(n)    ff(k, n)
#define mm(n)    ff(m, n)
#define fff(a, b, c) for (int a = int(b); a < int(c); ++a)
#define iii(a, b) fff(i, a, b)
#define kkk(a, b) fff(k, a, b)
#define mmm(a, b) fff(m, a, b)
#define xx first
#define yy second
#define bb begin()
#define ee end()
#define all(x)  (x).bb, (x).ee
#define ite(v)   decltype((v).bb)
#define fe(i, v) for(ite(v) i = (v).bb; i != (v).ee; ++i)
#define err(...)    { fprintf(stderr, __VA_ARGS__); fflush(stderr); }

using LL = long long;
using pii = pair<int, int>;


const LL INF = 9223372036854775807LL;
//const int INF = 2147483647;
   




int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //cout << '\n';
    


    int N;
    cin >> N;
    map<int, int> counts;
    ii (N) {
        int a;
        cin >> a;
        ++counts[a];
    }

    int npairs = 0;
    int nsingle = 0;
    fe (it, counts) {
        int c = it->yy;

        if (1 == c) {
            ++nsingle;
            continue;
        } else if (2 == c) {
            ++npairs;
            continue;
        }
        if (c % 2 == 1) {
            ++nsingle;
        } else {
            ++npairs;
        }

    }

    nsingle += 2 * (npairs / 2);


    cout << nsingle << '\n';



    return 0;
}



Measured memory_bytes: 4992
import java.util.*;

public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int count = sc.nextInt(); // 材料の種類数
        int gram = sc.nextInt(); // 材料の総量
        int sum = 0; // 全ドーナツを1つずつ作る場合の必要材料
        int primal = 0; // ループ中で注目しているドーナツの必要材料
        int min = 1000; // ドーナツ一つを作る際の最少材料量

        for (int i=0; i < count; i++) {
        	primal = sc.nextInt();
        	sum = sum + primal;
        	if (min > primal) {
        		min = primal;
			}
        }
        System.out.println(calcMax(count, gram, min, sum));
    }

    public static int calcMax(int count, int gram, int min, int sum) {
		// まず１つずつドーナツを作る
		int total = count; // 作ることのできるドーナツの量
		gram = gram - sum;

		// 残った材料で、最も少ない材料で作ることができるドーナツ、を作れるだけ作る
		while(gram >= min) {
			gram = gram - min;
			total = total + 1;
		}
		return total;
	}

}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,nn) for(int i=0;i<nn;i++)
#define MOD 1000000007
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}


int main(){
  string s,ans="";
  cin >> s;
  int num,n;
  FOR(i,8){
    num=s[0]-'0';
    n=0;
    FOR(j,3){
      if(i & (1<<j)){
        num-=s[j+1]-'0';
      }else{
        num+=s[j+1]-'0';
      }
    }
    if(num==7){
      ans+=s[0];
      FOR(j,3){
        if(i & (1<<j)){
          ans+='-';
        }else{
          ans+='+';
        }
        ans+=s[j+1];
      }
      ans+="=7";
      cout << ans << endl;
      return 0;
    }
  }
  
}

Measured memory_bytes: 256
#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 ll long long
#define ld long double
#define pb push_back
#define all(x) (x).begin(), (x).end()
template <typename T> using ord_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 2003, inf = 1e9;
int n, dp[2][N], A, B, a[N];

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	
	cin >> n >> A >> B;
	for (int i = 1; i <= n; i++) cin >> a[i];
	a[0] = B;
	for (int i = n; i >= 1; i--) {
		dp[0][i] = dp[1][i] = abs(a[i - 1] - a[n]);
		for (int j = i + 1; j <= n; j++) {
			dp[0][i] = max(dp[0][i], dp[1][j]);
			dp[1][i] = min(dp[1][i], dp[0][j]);
		}
	}
	cout << dp[0][1];
}


Measured memory_bytes: 3652
#include <stdio.h>

int main(void){
        long n, k, x=1,i, a=1,b=1;
        scanf("%ld %ld",&n, &k);
        for(i=0;i<n;i++){
                a *= 2;
                b += k;
                if(a > b){
                        x = b;
                        a = x;
                        b = x;
                }else{
                        x = a;
                        a = x;
                        b = x;
                }
        }

        printf("%ld", x);
        return 0;
}

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

int main() {
	int k;
	int a,b;
	cin >>k>>a>>b;
	int c=0;
	for(int i=a;i<=b;i++){
		if(i%k==0){
			c=1;
		}
	}
	if(c==1){
		cout <<"OK";
	}
	else{
		cout <<"NG";
	}
}

Measured memory_bytes: 3632
n = int(input())
MOD = 10**9 + 7

dp = [[[[0] * 4 for _ in range(4)] for _ in range(4)] for _ in range(n - 2)]
for i in range(4):
    for j in range(4):
        for k in range(4):
            dp[0][i][j][k] = 1
dp[0][0][2][1] = 0
dp[0][0][1][2] = 0
dp[0][2][0][1] = 0

for i in range(n - 3):
    for j in range(4):
        for k in range(4):
            for l in range(4):
                for m in range(4):
                    dp[i + 1][k][l][m] += dp[i][j][k][l]
                    dp[i + 1][k][l][m] %= MOD
                    if j == 0 and k == 2 and m == 1:
                        dp[i + 1][k][l][m] = 0
                    elif j == 0 and l == 2 and m == 1:
                        dp[i + 1][k][l][m] = 0
                dp[i + 1][0][2][1] = 0
                dp[i + 1][0][1][2] = 0
                dp[i + 1][2][0][1] = 0
print(sum(sum(sum(dp[n - 3], []), [])) % MOD)

Measured memory_bytes: 3316
#include<stdio.h>
int main(){

  int a,b;
  int x,y,z;
  scanf("%d %d",&a,&b);

  while(1){
    b=b-a;

    z=b/1000;
    b=b%1000;

    y=b/500;
    b=b%500;

    x=b/100;

    printf("%d %d %d\n",x,y,z);
    scanf("%d %d",&a,&b);

    if(a==0 && b==0) break;
  }

  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;
 
 
int main() {
    int h, w, x, y;
    cin >> w >> h >> x >> y;
    cout << ((w + 0.0000) * h) / 2 << " ";
    if ((w + 0.0000) / 2 == x && (h + 0.0000) / 2 == y){
        cout << 1 << endl;
    }else{
        cout << 0 << endl;
    }
}

Measured memory_bytes: 256
S = input()
ls1 = []
ls2 = []
ans = 0
if len(S)%2 == 1:
    for i in range(0,(len(S))//2+1):
        ls1.append(S[i])
    for j in range(len(S)//2+1,len(S)):
        ls2.append(S[j])
    ls2.reverse()
    for i in range(len(ls2)):
        if ls1[i] != ls2[i]:
            ans += 1
else:
    for i in range(0,(len(S)//2)):
        ls1.append(S[i])
    for j in range((len(S)//2),len(S)):
        ls2.append(S[j])
    ls2.reverse()
    for i in range(len(ls1)):
        if ls1[i] != ls2[i]:
            ans += 1
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#include <deque>
#include <map>
#include <string>
using namespace std;



int main()
{
	string s, t;
	cin >> s >> t;
	int table[26][26];
	for (int i = 0; i < 26; i++) {
		for (int j = 0; j < 26; j++) {
			table[i][j] = 0;
		}
	}

	for (int i = 0; i < s.size(); i++) {
		table[s[i] - 'a'][t[i] - 'a']++;
	}

	for (int i = 0; i < 26; i++) {
		int a = 0;
		for (int j = 0; j < 26; j++) {
			a += table[i][j];
		}

		for (int j = 0; j < 26; j++) {
			if (table[i][j] > 0 && table[i][j] != a) {
				cout << "No" << endl;
				return 0;
			}
		}

		a = 0;
		for (int j = 0; j < 26; j++) {
			a += table[j][i];
		}

		for (int j = 0; j < 26; j++) {
			if (table[j][i] > 0 && table[j][i] != a) {
				cout << "No" << endl;
				return 0;
			}
		}

	}

	cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 776
/*
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_A&lang=ja 
ALDS1_3_A:逆ポーランド記法
*/

#include <bits/stdc++.h>
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;

using namespace std;

void disp(unsigned short int *n, unsigned short int N);
int calc(int a, int b, string ope);

inline void DeleteSpace(string &buf);

#define MAX 100

int main(void){

    string in_str;
    getline(cin, in_str);
    //cout << in_str << endl;

    stringstream ss(in_str);

    char delim = ' ';
    string ope;//各
    stack<int> operands;

    while(getline(ss, ope, delim)){
        if(ope == "+" || ope == "-" || ope == "*" || ope == "/"){
            int b = operands.top();
            operands.pop();
            int a = operands.top();
            int result_tmp = calc(a,b,ope);
            operands.pop();
            operands.push(result_tmp);
        }else{
            operands.push(stoi(ope));
        }
    }

    printf("%d\n", operands.top());

	return 0;
  
}

void disp(unsigned short int *n, unsigned short int N){
	//printf("disp: ");
	for(int i=0; i<N; i++) {
		printf("%d", n[i]);
		if( i != N-1) printf(" ");
	}
	printf("\n");
}


int calc(int a, int b, string ope){
    int result;

    if(ope == "+") return a + b;
    else if(ope == "-") return a - b;
    else if(ope == "*") return a * b;
    else if(ope == "/") return a / b;
    else {
        printf("error: in calc");
        return -99999;
    }
}


Measured memory_bytes: 3276
fun main(args: Array<String>) {
    val (n,x) = readLine()!!.split(" ").map { it.toInt() }

    val l = readLine()!!.split(" ").map { it.toInt() }
    val s = l.summed()
    println(s.count{ it<=x }+1)
}

inline fun List<Int>.summed(): List<Int> {
    var sum = 0
    return this.map { sum += it; sum }
}

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; const int inf = 0x3fffffff; const ll INF = 0x3fffffffffffffff;
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 end



int main(){
    int n; scanf("%d",&n);
    int g=0;
    rep(rot,0,n){
        int a,k; scanf("%d%d",&a,&k);
        int c=0; bool f=1;
        while(f){
            if(a<k)f=0;
            if(a%k==0){c=a/k; f=0;}
            a-=a/k+1;
        } g^=c;
    }
    printf(g?"Takahashi\n":"Aoki\n");
    return 0;
}


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

int main() {
  int a;cin >> a;
  if(a<1200){
    cout << "ABC" << endl;
  }else if(a<2800){
    cout << "ARC" << endl;
  }else{
    cout << "AGC" << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
	    Scanner s = new Scanner(System.in);
	    int[] p = new int[50050];
	    p[0] = 2;
	    int num = 1;
	    for(int i=3 ; i<50050 ; i+=2){
		boolean flag = true;
		for(int j=0 ; p[j]*p[j]<=i ; j++){
		    if(i%p[j]==0){
			flag = false;
			break;
		    }
		}
		if(flag){
		    p[num] = i;
		    num++;
		}
	    }
	    while(s.hasNext()){
		int a=0;
		int c = s.nextInt();
		for(int i=0 ; p[i]<c ; i++)
		    a++;
		if(p[a]==c)
		    System.out.println(p[a-1] + " " + p[a+1]);
		else
		    System.out.println(p[a-1] + " " + p[a]);
	    }
      	}
}

Measured memory_bytes: 11000
from collections import defaultdict
def resolve():
    N = int(input())
    S = [input() for _ in range(N)]
    
    res = defaultdict(int)

    for s in S:
        res[s] += 1

    max_v = max(res.values())
    max_k_list = [kv[0] for kv in res.items() if kv[1] == max_v]

    max_k_list.sort()
    for k in max_k_list:
        print(k)


if __name__ == "__main__":
    resolve()

Measured memory_bytes: 35568
#include<bits/stdc++.h>
using namespace std;
#define int long long
int mod;
int po(int a,int b){
    int res=1;
    while(b!=0){
        if(b&1){
            res*=a;
            res%=mod;
        }
        a*=a;
        a%=mod;
        b/=2;
    }
    return res;
}
int inv(int a){
    return po(a,mod-2);
}
int32_t main(){
  string s,t;
  cin>>s>>t;
  cout<<t<<s;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
#define rep(i,n) for(int i = 0;i <n;i++)
class Monoid {
public:
	int unit;
	Monoid(){
		unit = 2147483647;
	}int calc(int a, int b) {
		return min(a, b);
	}
};
struct RUP {
	int n;
	Monoid mono;
	vector<int> dat, laz;
	RUP() {}
	RUP(int n_) { init(n_); }
	void init(int n_) {
		n = 1;
		while (n < n_) n *= 2;
		dat.clear();
		dat.resize(2 * n - 1, mono.unit);
		laz.clear();
		laz.resize(2 * n - 1, -1);
	}
	inline void eval(int len, int k) {
		if (laz[k] < 0) return;
		if (k * 2 + 1 < n * 2 - 1) {
			laz[k * 2 + 1] = laz[k];
			laz[k * 2 + 2] = laz[k];
		}
		dat[k] = laz[k];
		laz[k] = -1;
	}
	int update(int a, int b, int x, int k, int l, int r) {
		eval(r - l, k);
		if (r <= a || b <= l) return dat[k];
		if (a <= l && r <= b) return laz[k] = x;
		eval(r - l, k);
		dat[k] = mono.calc(update(a, b, x, k * 2 + 1, l, (l + r) / 2),
			update(a, b, x, k * 2 + 2, (l + r) / 2, r));
		return dat[k];
	}
	int query(int a, int b, int k, int l, int r) {
		eval(r - l, k);
		if (r <= a || b <= l) return mono.unit;
		if (a <= l && r <= b) return dat[k];
		int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
		int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
		return mono.calc(vl, vr);
	}
	void update(int a, int b, int x) {
		update(a, b, x, 0, 0, n);
	}
	int query(int a, int b) {
		return query(a, b, 0, 0, n);
	}
};
int main(){
	int n, q; cin >> n >> q;
	RUP rup(n);
	rep(i, q) {
		int a; cin >> a;
		if (a == 0) {
			int s, t, x; cin >> s >> t >> x;
			rup.update(s, t + 1, x);
		}
		else {
			int s, t; cin >> s >> t;
			cout << rup.query(s, t + 1) << endl;
		}
	}
}


Measured memory_bytes: 4868
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;

int main()
{
	//ifstream cin("input.txt");

	int K, T;
	int a[10000];

	cin >> K >> T;
	for (int i = 0; i < T; ++i)
	{
		cin >> a[i];
	}

	sort(a, a + T);

	int sum = 0;
	for (int i = 0; i < T - 1; ++i)
	{
		sum += a[i];
	}

	cout << max(a[T - 1] - sum - 1, 0) << endl;
	
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-8;

ld p[2002][2002];
ld rp[2002][2003];
void init() {
	p[0][0] = 1;
	rep(i, 2001) {
		rep(j, i + 1) {
			p[i + 1][j] += p[i][j] * (2 / 3.0);
			p[i + 1][j + 1] += p[i][j] * (1 / 3.0);
		}
	}
	rep(i, 2001) {
		rep(j, 2001) {
			rp[i][j + 1] = rp[i][j] + p[i][j];
		}
	}
}
vector<int> coef = { 5,3,2 };

int val[2000][3];
ld e[3][2001];

void solve() {
	int n, m; cin >> n >> m;
	rep(i, n) {
		rep(j, 3) {
			cin >> val[i][j];
		}
	}
	rep(id, 3) {
		rep(i,m+1 ) {
			int s = val[0][id] * i;
			//全部最下位
			ld pro = 1;
			rep1(j, n - 1) {
				int d = (s + val[j][id] - 1) / val[j][id];
				if (d > m)d = m+1;
				pro = pro * (1-rp[m][d]);
			}
			//1位,2位,3位
			vector<ld> dp(3, 0); dp[0] = 1;
			rep1(j, n - 1) {
				int d = (s + val[j][id] - 1) / val[j][id];
				if (d > m)d = m + 1;
				ld pp = rp[m][d];
				dp[2] = dp[2] * pp + dp[1] * (1 - pp);
				dp[1] = dp[1] * pp + dp[0] * (1 - pp);
				dp[0] = dp[0] * pp;
			}
			ld sum = 0;
			rep(j, 3)sum += dp[j];
			e[id][i] = pro * -1 + sum * coef[id];
		}
	}
	vector<ld> mdp(m + 1, -mod);
	rep(i, m + 1) {
		rep(j, m + 1) {
			if (i + j > m)continue;
			mdp[i + j] = max(mdp[i + j], e[0][i] + e[1][j]);
		}
	}
	ld ans = -mod;
	rep(i, m + 1) {
		ans = max(ans, mdp[i] + e[2][m - i]);
	}
	cout << ans << endl;
}

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

	cout << fixed << setprecision(10);
	init();
	solve();
	//stop
		return 0;
}


Measured memory_bytes: 104856
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,sum=1,M=0;
	cin>>n;
	for(int i=0;i<=n;i++){
		for(int j=1;j<=i;j++){
			sum=sum*2;
		}
		if(sum<=n){
			M=max(sum,M);
		}
		sum=1;
	}
	cout<<M<<endl;
	return 0;
}

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

int main()
{

	int H, W, N;

	cin >> H >> W >> N;

	int maxHW = H;

	if(H < W){
		maxHW = W;
	}

	if(N % maxHW == 0){
		cout << (N/ maxHW) << endl;
	}else{
		cout << (N / maxHW)+1 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
N = int(input())
import itertools
import math
town = []
gokei = 0
for _ in range(N):
    town.append(list(map(int, input().split())))
for i in itertools.permutations(town):
    for k in range(N-1):
        gokei += math.sqrt((i[k][0]-i[k+1][0])**2+(i[k][1]-i[k+1][1])**2)
print(gokei/math.factorial(N))

Measured memory_bytes: 3064
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] s = new long[n+1];
        for(int i=1;i<n+1;i++){
            s[i] = s[i-1] + sc.nextInt();
        }
        long answer = 100000000;
        answer *= answer;
        for(int m=2;m<n-1;m++){
            long[] x = binarySearch(1, m, s);
            long[] y = binarySearch(m+1, n, s);
            long a = x[0];
            long b = x[1];
            long c = y[0];
            long d = y[1];
            long candidate = Math.max(b,d)-Math.min(a,c);
            answer = Math.min(candidate,answer);
        }
        System.out.println(answer);
    }
    public static long[] binarySearch(int left, int right, long[] array){
        double s = (double) (array[right]-array[left-1]);
        double half = s/2;
        int ok = right;
        int ng = left - 1 ;
        while(ok>ng+1){
            int mid = (ok+ng)/2;
            if (array[mid]-array[left-1] >= half) {
                ok = mid;
            } else {
                ng = mid;
            }
        }
        double dOk = Math.abs((double) (array[ok]-array[left-1]) -half);
        double dNg = Math.abs((double) (array[ng]-array[left-1]) -half);
        long x;
        long y;
        if (dOk < dNg) {
            x = array[ok]-array[left-1];
            y = array[right]-array[ok];
        } else {
            x = array[ng]-array[left-1];
            y = array[right]-array[ng];
        }
        long [] answer = new long[2];
        answer[0] = Math.min(x,y);
        answer[1] = Math.max(x,y);
        return(answer);
    }
}

Measured memory_bytes: 93784
#!python3



def main():
    # input
    N, M = list(map(int, input().split()))
    A = list(map(int, input().split()))
    s = sum(A)
    t = s / (4 * M)
    A.sort()
    A = A[::-1]
    ans = 'Yes'
    for i in range(M):
        if A[i] < t:
            ans = 'No'
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>
int main(void){
	char s[1000],t[1000];
	scanf("%s%s",s,t);
	int len=strlen(t),i,j,cnt,min=len;
	for(i=0;s[i+len-1]!='\0';i++){
		cnt=0;
		for(j=0;t[j]!='\0';j++){
			if(s[i+j]!=t[j]){
				cnt++;
			}
		}
		min=cnt<min?cnt:min;
	}
	printf("%d",min);
	return 0;
}


Measured memory_bytes: 1728
import math

n = int(input())
A = list(map(int, input().split()))
cnt = 0
inf = 10**9



def merge(A,left,mid,right):
	global cnt
	L = A[left:mid] + [inf]
	R = A[mid:right] + [inf]
	i = 0
	j = 0

	for k in range(left,right):
		cnt += 1
		if L[i] <= R[j]:
			A[k] = L[i]
			i += 1
		else:
			A[k] = R[j]
			j += 1


def mergeSort(A,left,right):
	if left + 1 < right:
		mid = (left + right) // 2
		mergeSort(A,left,mid)
		mergeSort(A,mid,right)
		merge(A,left,mid,right)

mergeSort(A,0,n)
print(*A)
print(cnt)


Measured memory_bytes: 65820
n = gets.to_i
a = gets.split.map(&:to_i)
min = a.min
max = a.max
sum = 100000000 

(min..max).each do |i|
    tmp = 0
    a.each do |j| 
        tmp += (j-i)**2
    end
    
    if sum > tmp
        sum = tmp
    end
end

p sum

Measured memory_bytes: 1788
#include <iostream>
#include <cstring>
using namespace std;
long long a[200005], sum[200005];
long long dp[200005];
int main() {
    int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i], sum[i] = a[i] + (i > 1? sum[i - 2]: 0);
	for (int i = 1; i < n; i++) {
		if (i % 2 == 0)
			dp[i] = max(a[i] + dp[i - 2], dp[i - 1]);
		else
			dp[i] = max(a[i] + dp[i - 2], sum[i - 1]);
	}
    cout << dp[n - 1] << endl;
	return 0;
}

Measured memory_bytes: 8280
#include<bits/stdc++.h>
#define ll long long
#define N 100009
using namespace std;

bitset<4000009> a;
int n;
int main(){
	scanf("%d",&n);
	int i,x,sum=0;
	a[0]=1;
	for (i=1; i<=n; i++){
		scanf("%d",&x); sum+=x;
		a|=a<<x;
	}
	for (i=sum+1>>1; i<=sum; i++) if (a[i]) break;
	printf("%d\n",i);
	return 0;
}


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


int main(){
    int N;
    int result =0;
    cin >> N;
    vector<int> tak;
    for(int i=0;i<N;i++){
        int tmp;
        cin >> tmp;
        tak.push_back(tmp);
        
    }
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            result +=(tak[i]*tak[j]);
            
        }
        
    }
    
    cout << result << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
        new Main().solve();
    }

    private void solve() throws IOException {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);

        StringTokenizer tokenizer = new StringTokenizer(f.readLine());
        long x = Long.parseLong(tokenizer.nextToken());
        if (x < 0) x *= -1;
        long k = Long.parseLong(tokenizer.nextToken());
        long orgK = k;
        long d = Long.parseLong(tokenizer.nextToken());
        long ten = 0;
        long fact = 10;
        while (d / fact > 0) {
            ten++;
            fact *= 10;
        }
        long potentialK = 1;
        for (int i = 0; i < (18 - ten); i++) {
            potentialK *= 10;
        }
        k = Math.min(k, potentialK);
        long a = 0;
        long b = k;
        long res = -1;
        while (a <= b) {
            long mid = (a + b) / 2;
            if (x - mid * d < 0) {
                res = mid;
                b = mid - 1;
            } else {
                a = mid + 1;
            }
        }

        if (res == -1) {
            out.println(x - k * d);
            out.close();
            return;
        }

        long value1 = x - res * d;
        long value2 = x - res * d + d;
        orgK -= res;
        if (orgK % 2 == 0) {
            out.println(Math.abs(value1));
        } else {
            out.println(Math.abs(value2));
        }

        out.close();
    }
}

Measured memory_bytes: 32748
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int mod = 1e9+7;

int main()
{
    int n;
    cin >> n;
    map<int,int> mp;
    for(int i = 0; i < n; i++){
        int a; cin >> a;
        mp[a]++;
    }

    int ans = 0;
    for(auto x: mp) if(x.second%2) ans++;
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4992
n = int(input())
a = [int(input()) for _ in range(n)]
b = 10001
dp = [0 for i in range(n+1)]
for i in range(n+1):
    dp[i] =[0 for _ in range(b)]
dp[0][0] = 1

for i in range(n):
    for j in range(b):
        if dp[i][j]:
            dp[i+1][j] = 1
            dp[i+1][j+a[i]] = 1
for i in range(b-1,-1,-1):
    if dp[n][i]:
        if i % 10 or i == 0:
            print(i)
            break

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

using namespace std;

#define rep(i, n) for(int i=0; i<(int)(n); i++)

int main() {
    int N;
    cin >> N;
    long long int limit = pow(10.0, 18.0);
    
    vector<long long int> inputs(N);
    rep(i, N){
        cin >> inputs.at(i);
        if(inputs.at(i) == 0){
            cout << 0 << endl;
            return 0;
        }
    }
    long long int prod = 1;
    rep(i, N){
        if(inputs.at(i) <= limit / prod){
            prod *= inputs.at(i);
        } else {
            cout << "-1" << endl;
            return 0;
        }
    }
    cout << prod << endl;
}

Measured memory_bytes: 4060
#include<iostream>
#include<vector>
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	string stra,strb;
	for( int i=0; i<b; i++ )
	{
		stra += '0'+a;
	}
	for( int i=0; i<a; i++ )
	{
		strb += '0'+b;
	}
	
	if( stra < strb )
		cout << stra << endl;
	else
		cout << strb << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
K = int(input())

def pow(a,n):
    ans = 1
    while n > 1:
        if bin(a&1)==bin(1):
            ans = ans*a
        a = a*a
        n = n>>1
    return ans

def com(N,k):
    if k<0 or k>N: return 0
    if k==1:return N
    elif k==2: return N*(N-1)//2
    else: return N*(N-1)*(N-2)//6

S = len(str(N))
N = str(N)
def helper(i,k,smaller):
    if i==S:
        if k==0: return 1
        else: return 0
    if k ==0: return 1
    if smaller: return com(S-i,k)*(9**k)
    else:
        if N[i]=='0': return helper(i+1,k,False)
        else:
            zero = helper(i+1,k,True)
            a = helper(i+1,k-1,True)*(int(N[i])-1)
            b = helper(i+1,k-1,False)
            return zero + a + b
print(helper(0,K,False))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define re return
typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> pii; 
ll dp[5001*5001];
ll n;
ll a[10][10];
ll ans;
int main() { 
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>n;
	for(int i=0;i<2;i++){
		for(int j=0;j<3;j++){
			cin>>a[i][j];
		}
	}
	for(int i=1;i<=n;i++){
		dp[i]=dp[i-1];
		if(i-a[0][0]>=0){
			dp[i]=max(dp[i],dp[i-a[0][0]]+a[1][0]-a[0][0]);
		}
		if(i-a[0][1]>=0){
			dp[i]=max(dp[i],dp[i-a[0][1]]+a[1][1]-a[0][1]);
		}
		if(i-a[0][2]>=0){
			dp[i]=max(dp[i],dp[i-a[0][2]]+a[1][2]-a[0][2]);
		}
	}
	ans=n+dp[n];
	n=n+dp[n];
	memset(dp,0,sizeof(dp));
	for(int i=1;i<=n;i++){
		dp[i]=dp[i-1];
		if(i-a[1][0]>=0){
			dp[i]=max(dp[i],dp[i-a[1][0]]+a[0][0]-a[1][0]);
		}
		if(i-a[1][1]>=0){
			dp[i]=max(dp[i],dp[i-a[1][1]]+a[0][1]-a[1][1]);
		}
		if(i-a[1][2]>=0){
			dp[i]=max(dp[i],dp[i-a[1][2]]+a[0][2]-a[1][2]);
		}
	}
	ans+=dp[n];
	cout<<ans<<endl;
    return 0; 
}

Measured memory_bytes: 195584