akhauriyash/Code-Regression huggingface dataset:
<?php
list($n, $m, $x) = explode(" ", trim(fgets(STDIN)));

$hon = [];
$money = [];
$ps = f($n, "");

for ($i=0; $i<$n; $i++) {
  $hon[$i] = explode(" ", trim(fgets(STDIN)));
  $money[$i] = $hon[$i][0];
}

$min_sum = PHP_INT_MAX;
foreach($ps as $p){
  $sum = 0;
  $check = array_fill(0, $m, 0);
  for ($i=0; $i<$n; $i++){
    if($p[$i] == "1"){
      $sum += $money[$i];
      for ($j=0; $j<$m; $j++){
        $check[$j] += $hon[$i][$j+1];
      }
    }
  }
  // 全部10以上か？
  $bTen = true;
  for ($i=0; $i<$m; $i++){
    if($check[$i] < $x){
      $bTen = false;
      break;
    }
  }
  if($bTen){
//    echo $p." ". $sum.PHP_EOL;
    $min_sum = min($min_sum, $sum);
  }
}

if($min_sum == PHP_INT_MAX){
  echo "-1";
  exit;
}

echo $min_sum;

function f($n, $str){
  if($n == strlen($str)){
    return [$str];
  }
  $ret = [];
  $ret = array_merge($ret, f($n, $str."0"));
  $ret = array_merge($ret, f($n, $str."1"));
  return $ret;
}

Measured memory_bytes: 16704
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>

using namespace std;

int main()
{
    int H, W, h, w;
    cin >> H >> W >> h >> w;
    cout << (H * W - h * W - w * H + h * w) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int ans =0;
  for(int i =0; i<s.size(); i++){
    ans = ans + int(s.at(i))-48;
  }
  if(ans%9==0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3748
import itertools
n=int(input())
D={'M':0,'A':0,'R':0,'C':0,'H':0}
for i in range(n):
    x=input()
    if x[0]=='M':
        D['M']+=1
    elif x[0]=='A':
        D['A']+=1
    elif x[0]=='R':
        D['R']+=1
    elif x[0]=='C':
        D['C']+=1
    elif x[0]=='H':
        D['H']+=1

X=D.values()
Y=list(itertools.combinations(X,3))
cnt=0
for i in range(10):
    cnt+=Y[i][0]*Y[i][1]*Y[i][2]

print(cnt)


Measured memory_bytes: 3064
c = []
tmp = []
for i in range(3):
    tmp = list(map(int,input().split()))
    c.append(tmp)

for a1 in range(100+1):
    for b1 in range(100+1):
        if not a1 + b1 == c[0][0]:
            continue
        a2 = c[1][0] - b1
        b2 = c[0][1] - a1
        a3 = c[2][0] - b1
        b3 = c[0][2] - a1
        if a2 + b2 == c[1][1] and a2 + b3 == c[1][2] and a3 + b2 == c[2][1] and a3 + b3 == c[2][2]:
            print('Yes')
            exit()

print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, k; cin >> n >> k;
  int ans = 0;
  for(int i = 0; i < n; i++){
    int x; cin >> x;
    ans += 2 * min(x, k - x);
  }
  cout << ans << endl;
  return 0;
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

const int mod = 1000000007;

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

    int ans = T.size();
    for (int i = 0; i < S.size(); i++) {
        int cnt = 0;
        int ok = true;
        for (int j = 0; j < T.size(); j++) {
            if (S.size() <= i + j) {
                ok = false;
                break;
            }
            if (S[i + j] != T[j]) cnt++;
        }
        if (ok) chmin(ans, cnt);
    }
    cout << ans << endl;
}


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

int main() {
	int R,G,B,N;
	cin>>R>>G>>B>>N;
	int cont =0;
	for(int i=0;i<=N/R;i++){
		for(int j=0;j<=N/G;j++){
		int aux = N- i*R -j*G;
		if(aux%B ==0){
			aux/=B;
			if(0 <=aux && aux<=N/B)cont++;
		}
		}
	}
	cout<<cont<<endl;
	
	return 0;
}

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

using namespace std;
using ll = long long;

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

int main(){
    int n;
    cin >> n;
    int ans = 0;

    vector<int> vc(n),vs(n),vf(n);
    rep(i,n){
        cin >> vc[i] >> vs[i] >> vf[i];
    }

    rep(j,n-1){
        ans = 0;
        reps(i,j,n-1){
            int c,s,f;
            c = vc[i], s = vs[i],f =vf[i]; 
            int tmp = ((ans+f-1) / f) * f;

            if(s >= tmp) ans = s;
            else ans = tmp;
            ans += c;
        }
        cout << ans << endl;
    }
    cout << 0 << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
const long long mod = 1e9+7;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
const int ddx[4] = {1,1,-1, -1};
const int ddy[4] = {1,-1,-1,1};
//////////////////////////////////

int main(){
  int k; cin >> k;
  queue<long long> q;
  for(int i=1; i<=9; i++) q.push(i);
  long long p;
  while(k--) {
    p = q.front();
    q.pop();
    long long nx = 10 * p + p%10;
    if(p%10 != 0) q.push(nx - 1);
    q.push(nx);
    if(p%10 != 9) q.push(nx + 1);
  }
  cout << p << endl;
}

// EOF


Measured memory_bytes: 1792
#include<iostream>
#include<cmath>
#include<algorithm>
#include <cassert>
#include<string>
using namespace std;
int main(){
	int a = 0, b = 0, c[100000], d[100000], e[100000], count = 0;
	char uc[100000];
	for (int i = 0; i < 9; i++) {
		cin >> uc[i];
	}
	cout << uc[0] << uc[4] << uc[8] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#define Max 100000

using namespace std;

int n,k;
long long a[Max];

int check(long long p)
{
    int i=0;
    for(int j=0;j<k;j++)
    {
        long long s = 0;
        while(s+a[i] <= p)
        {
            s = s+a[i++];
            if(i == n)
                return n;
        }
    }
    return i;
}

int solve()
{
    long long left = 0;
    long long right = 100000*10000;
    long long mid;
    while(left+1 < right)
    {
        mid = (left + right)/2;
        int v = check(mid);
        if(v>=n)
            right = mid;
        else
            left = mid;
    }
    return right;
}

int main()
{
    int i;
    scanf("%d%d",&n,&k);
    for(i=0;i<n;i++)
        scanf("%d",&a[i]);
    int res = solve();
    printf("%d\n",res);
    return 0;
}

Measured memory_bytes: 3980
#include<iostream>
#include<algorithm>

using namespace std;

int N, T;
int in[100001];

int main() {

	cin >> N >> T;
	for (int i = 0; i < N; i++)cin >> in[i];
	int ct = 1, biggest = -1, small = in[0];
	int ans = 0;
	int beforesmall = 0;
	for (int i = 1; i <= N; i++) {
		beforesmall = small;
		small = min(small, in[i]);
		if (i != N && in[i] > in[i - 1])ct++;
		else {
			if (ct != 0) {
				if (biggest == in[i - 1] - beforesmall) {
					ans++;
				}
				else if (biggest < in[i - 1] - beforesmall) {
					biggest = in[i - 1] - beforesmall;
					ans = 1;
				}
				ct = 0;
			}
		}
		//cout << i << " " << biggest << " " << small << endl;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
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; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N,M,V,P;
    cin >> N >> M >> V >> P;
    vector<ll> A(N),S(N+1);
    rep(i,N){
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    rep(i,N){
        S[i+1] = A[i] + S[i];
    }
    ll sc = M*V;
    ll cnt = 0;
    rep(i,N){
        sc = M*V;
        sc -= M*(i+1);
        sc -= M*(P-1);
        if(sc <= 0){
            if(A[i] + M >= A[N-P]){
                //cout << "b " << A[i] <<endl;
                cnt++;
            }
        }else{
            /*
            ll sum = S[N-P+1] - S[i+1];
            sum += sc;
            ll n = N-P - i;
            ll t = sum / n;
            */
            ll t = 0;
            //bool flag = false;
            ll p = A[i] + M;
            if(p - A[N-(P-1)-1] < 0) continue;
            /*for(ll j=i+1; j<N-(P-1); j++){
                t = p - A[j];
                sc -= t;
            }*/
            sc -= p*(N-(P-1)-(i+1)) -  (S[N-P+1] - S[i+1]);
            //if(flag) continue;
            //cout << "c " << A[i] << endl;
            if(sc > 0){
                continue;
            }
            //cout << "a " << A[i] << endl;
            cnt++;
        }
        sc = M*V;
    }
    cout << cnt << endl;
}   

Measured memory_bytes: 4820
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
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; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

int main(){
  ll N,M,Q,L,R;
  vector<vector<ll>> V(507);
  cin >> N >> M >> Q;
  rep(i,M){
    cin >> L >> R;
    V[L].pb(R);
  }
  Rep(i,1,N+1){
    if(V[i].size()>0){
      sort(ALL(V[i]));
    }
  }
  rep(i,Q){
    ll C=0;
    cin >> L >> R;
    Rep(i,L,R+1){
      C+=(upper_bound(V[i].begin(),V[i].end(),R))-V[i].begin();
    }
    cout << C << endl;
  }
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  ll c = a+b;
  ll ans = a * (n/c);
  ans += min(n%c, a);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
fn main() {
    let mut buf = String::new();
    let handle = std::io::stdin();

    let mut ns: Vec<usize> = {
        handle.read_line(&mut buf).unwrap();
        let tmp = buf.trim().split_whitespace().map(|a| a.parse().unwrap()).collect();
        buf.clear();
        tmp
    };
    ns.sort();
    if ns.binary_search(&1).is_ok() && ns.binary_search(&9).is_ok() && ns.binary_search(&7).is_ok() && ns.binary_search(&4).is_ok() {
        println!("{}", "YES");
    } else {
        println!("{}", "NO");
    }
}


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

int main(){
    int n, m;
    bool judge = true;
    cin >> n;
    cin >> m;
    int ans[n];
    memset(ans, -1, sizeof(ans));
    int s[m], c[m];
    REP(i,m){
        cin >> s[i] >> c[i];
        if(ans[s[i]-1]!=-1 && ans[s[i]-1] != c[i]){
            judge = false;
        }
        ans[s[i]-1] = c[i];
    }
    REP(i,n){
        if(ans[i] == -1 && (n == 1 || i != 0))
            ans[i] = 0;
        if(ans[i] == -1 && n != 1 && i == 0)
            ans[i] = 1;
    }
    if(n != 1 && ans[0] == 0)
        judge = false;
    if(judge){
        REP(i,n){
            cout << ans[i];
        }
        cout << endl;
    }
    else{
        cout << -1 << endl;
    }
    return 0;
}

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

#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)

int main(){
  int a,b;
  char op[1];
  cin>>a>>op[0]>>b;
  if(op[0]=='+'){
    cout<<a+b<<endl;
  }
  else{
    cout<<a-b<<endl;
  }
}


Measured memory_bytes: 256
n,k=map(int,input().split())
s=input()
d=s+s[::-1]
d=d[::-1]
r=d[:n]
e=d[:n]
for i in range(n):
    e=e[1:]+d[n+i]
    r=min(r,e)
t=1
qo=r[0]
for i in range(1,n):
    if qo==r[i]:
        t+=1
    else:
        break
r=r[::-1]
for i in range(k-1):
    p=r+r[n-t:]
    p=p[::-1]
    p=p[:n]
    if r==p:
        break
    else:
        r=p[::-1]
        t+=t
print(r[::-1])

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;

#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,s,n)	for(int i=s;i<n;++i)
#define FORR(i,s,n)	for(int i=n-1;i>=s;--i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define F			first
#define S			second

int main(int argc, char **argv) {
	ll n, w, a, b;
	cin >> n >> w >> w;
	REP(i, n-1) cin >> a;
	cin >> b;
	cout << (n == 1 ? abs(w-b) : max(abs(w-b), abs(a-b))) << endl;
	return 0;
}


Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.complex;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

const real eps = 1e-10;

void main(){
    auto n = readInt();
    auto s = readln().chomp();
    auto t = readln().chomp();
    foreach(uint i; iota(n)) {
        if(s[i..$] == t[0..n-i]) {
            writeln(n+i);
            return;
        }
    }
    writeln(n*2);
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(auto i=0;i<n;++i)
#define REPR(i,n) for(auto i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(auto i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d",&tmp);v.push_back(tmp);}}

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  llong sum = 0;
  REP(i,n){
    cin >> a[i];
    sum += a[i];
  }
  llong cnt = 0;
  REP(i,n){
    if(a[i] * 4 * m >= sum) cnt++;
  }
  if(cnt >= m){
    cout << "Yes\n";
  }else{
    cout << "No\n";
  }

  return 0;
}



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

int main()
{
  long long int k,a,b,c,s1,s2;
    cin>>a>>b>>c>>k;
    s1=a+b;
    s2=a+b+c;
    if(k<=a){
        cout<<k;
    }
    else if(k>a&&k<=s1){
        cout<<a;
    }

    else if(k>s1&&k<=s2){
        cout<<a-(k-s1);
    }

}


Measured memory_bytes: 3636
def ints():
  return [int(x) for x in input().split()]
def ii():
  return int(input())

N, M = ints()
A = ints()
A.sort()

def combinations(x):
  s = 0
  i = 0
  j = N-1
  while j>=0:
    while i<N and A[i]+A[j]<x:
      i += 1
    s += N-i

    j -= 1
    
  return s

def koufukudo(x):
  s = 0
  si = 0
  j = 0
  i = N-1
  while j<N:
    while i>=0 and A[i]+A[j]>=x:
      si += A[i]
      i -= 1
    s += si + A[j]*(N-1-i)

    j += 1
    
  return s


def bsearch(lower, upper):
  l = lower
  u = upper
  m = (l+u)//2
  c = combinations(m)
  if c<M:
    return bsearch(l, m)
  else:
    if l==m:
      return (l, c-M)
    return bsearch(m, u)

x, dm = bsearch(0, A[-1]*2+1)
print(koufukudo(x)-dm*x)


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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int a, b; std::cin >> a >> b;
  int ans;
  if (a != 1 && b != 1) ans = 1;
  else if (a != 2 && b != 2) ans = 2;
  else ans = 3;
  std::cout << ans << "\n";
}


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

int main(){
    string s, t, u;
    int a, b;
    cin >> s >> t;
    cin >> a >> b;
    cin >> u;
    if(s == u) cout << a-1;
    else cout << a;
    cout << ' ';
    if(t == u) cout << b-1;
    else cout << b;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll; 
typedef long double ld;
typedef pair<ll, ll> pll;

const ll N = 2e5 + 30, Mod = 1e9 + 7;
const ll SQ = 330;

int main () {
    ios::sync_with_stdio(0), cin.tie(0);
	ll n, k;
	cin >> n >> k;
	ll ans = 0;
	for (ll i = k; i <= n + 1; i ++) {
		ll mn = (i) * (i - 1);
		mn /= 2ll;
		ll mx = n * (n + 1) - (max(0ll, (n - i)) * max(0ll, (n - i + 1)));
		mx /= 2ll;
		if (mn <= mx) ans += mx - mn + 1;
		//cout << mn << ' ' << mx << endl;
 		ans %= Mod;
	}
	cout << ans;
    return (0);
}

Measured memory_bytes: 3656
def slove():
    import sys
    import bisect
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    l = list(map(int, input().rstrip('\n').split()))
    l.sort()
    cnt = 0
    for i in range(n-2):
        for j in range(i+1, n-1):
            t = l[i] + l[j]
            p = bisect.bisect_left(l, t)
            cnt += (p - j - 1)
    print(cnt)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 42204
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import kotlin.math.min

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val s = br.readLine()!!
    if (s == "zyxwvutsrqponmlkjihgfedcba") {
        out.println(-1)
        return
    }

    val isUsed = BooleanArray(26)
    for (c in s) {
        isUsed[c - 'a'] = true
    }

    val ans = if (s.length < 26) {
        s + ('a' + isUsed.indexOf(false))
    } else {
        val tmp = s.toCharArray().toTypedArray()
        nextPermutation(tmp)
        tmp.joinToString("")

        var count = 0
        for ((i, c) in s.withIndex()) {
            count++
            if (c != tmp[i]) {
                break
            }
        }

        tmp.take(count).joinToString("")
    }
    out.println(ans)
}

/** O(n): n = currentPermutation.size */
fun <T : Comparable<T>> nextPermutation(currentPermutation: Array<T>): Boolean {
    fun <T> Array<T>.reverse(start: Int, end: Int) {
        val midPoint = ((start + end) / 2) - 1
        if (midPoint < 0) return
        var reverseIndex = end - 1
        for (index in start..midPoint) {
            val tmp = this[index]
            this[index] = this[reverseIndex]
            this[reverseIndex] = tmp
            reverseIndex--
        }
    }

    val n = currentPermutation.size
    var i = n - 2
    while (i >= 0) {
        if (currentPermutation[i] < currentPermutation[i + 1]) break
        i--
    }
    if (i < 0) return false
    var j = n
    do { j-- } while (currentPermutation[i] > currentPermutation[j])
    if (currentPermutation[i] < currentPermutation[j]) {
        val tmp = currentPermutation[i]
        currentPermutation[i] = currentPermutation[j]
        currentPermutation[j] = tmp
        currentPermutation.reverse(i + 1, n)
        return true
    }
    return false
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 40188
S = input()
T = input()
len_T = len(T)

lst = []
for x in range(len(S) - len_T + 1):
    flg = True
    s = S[x:len_T+x]    
    for idx in range(len_T):
        if s[idx] != '?' and s[idx] != T[idx]:
            flg = False
            break
    if flg:
        tmp = S[:x] + T + S[x + len_T:]
        tmp = tmp.replace('?', 'a')
        lst.append(tmp)


if len(lst) == 0:
    print('UNRESTORABLE')
else:
    print(min(lst))

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <functional>
#include <sstream>
#include <bitset>
#include <map>

using namespace std;

typedef long long ll;
const ll MOD = 1000000007;
ll dp[101][9];

int main() {
  int H,W,K;
  cin>>H>>W>>K;
  dp[0][0] = 1;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      for (int k = 0; k < 1 << (W - 1); k++) {
        bool ok = true;
        for (int l = 0; l < W - 2; l++) {
          if (((k >> l) & 1) && ((k >> (l + 1)) & 1)) ok = false;
        }
        if (ok) {
          if (j >= 1 && ((k >> (j - 1)) & 1)) {
            dp[i + 1][j - 1] += dp[i][j];
            dp[i + 1][j - 1] %= MOD;
          } else if (j <= W - 2 && ((k >> j) & 1)) {
            dp[i + 1][j + 1] += dp[i][j];
            dp[i + 1][j + 1] %= MOD;
          } else {
            dp[i + 1][j] += dp[i][j];
            dp[i + 1][j] %= MOD;
          }
        }
      }
    }
  }
  cout<<dp[H][K - 1]<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
 	int a[4];
 	
 	scanf( "%d %d %d", &a[0], &a[1], &a[2]);
 	
 	int i,j;
 	for( i=0; i<3; i++) {
 		for( j=i+1; j<3; j++) {
 			if( a[j] < a[i] ) {
 				a[3]=a[j];
 				a[j]=a[i];
 				a[i]=a[3];
 			}
 		}
 	}
 	printf( "%d %d %d\n", a[0], a[1], a[2]);


	return 0;
}

Measured memory_bytes: 596
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<int, P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (int i = 0; i < x; i++)
#define rep1(i, x) for (int i = 1; i <= x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (int i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))

const int INF = 1000000000;
const ll M = 1000000000;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0},  {1, 1},   {0, 1},  {-1, 1},
                         {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

/*----------------------------------------------/
/- char         : %c  | char *       : %s  | short        : %hd
/- int          : %d  | long         : %ld | long long    : %lld
/- unsigned short:%hu | unsigned int : %u  | unsigned long: %lu
/- u_long long  : %llu| (octal)      : %o  | (hexadecimal): %x
/- float        : %f  | double       : %lf |
/----------------------------------------------*/

/*----------------------------------------------/
/- INT_MAX, LONG_MAX   : 1<<15 = 2.1*pow(10, 9)       (= 2147483647)
/- UINT_MAX, ULONG_MAX : 1<<16 = 4.2*pow(10, 9)       (= 4294967295)
/- LLONG_MAX           : 1<<63 = 9.2*pow(10, 18)      (= 9223372036854775807)
/- ULLONG_MAX          : 1<<64 = 1.8*pow(10, 19)      (= 18446744073709551615)
/----------------------------------------------*/

// i番目にたどり着くための最小コスト
int dp[100010];

int main() {
    int n, h[100010];
    cin >> n;
    int h_;
    rep(i, n) {
        scanf("%d", &h_);
        h[i] = h_;
    }
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    for (int i = 2; i < n; i++) {
        dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]),
                    dp[i - 2] + abs(h[i] - h[i - 2]));
    }

    cout << dp[n - 1];

    /* ====================================== */
    cout << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long int N,X=0;string S,T="MARCH";
  cin>>N;vector<long long int>A(5,0);
  for(int i=0;i<N;i++){
    cin>>S;
    for(int j=0;j<5;j++)if(S[0]==T[j])A.at(j)++;
  }
  for(int i=2;i<5;i++)for(int j=1;j<i;j++)for(int k=0;k<j;k++)X+=A.at(i)*A.at(j)*A.at(k);
  cout<<X<<endl;
}

Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

//const long long int MOD = 1000000007;
const int MOD = 1000000007;
//const int MOD = 998244353;
//const long long int MOD = 998244353;
const double EPS = 1e-8;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


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

	cin >> N;
	vector<long long int>v(N);
	for (auto&i : v)cin >> i;
	vector<long long int>w(N);
	for (int i = 0; i < N * 2 - 2; i += 2) {
		w[(i + 2) % N] = w[i%N] + (v[(i + 1) % N] - v[(i%N)]) * 2;
	}
//	cout << w[0] << " " << w[1] << " " << w[2] << endl;
	long long int add = -(w[0] + w[1] - v[0]*2) / 2;
	for (auto i : w)cout << i + add << " ";
	cout << endl;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; i++)
#define all(a) (a).begin(), (a).end()

int main () {
  int N, X;
  cin >> N >> X;
  vector<int> m(N);
  rep(i,N) {
    cin >> m[i];
    X -= m[i];
  }
  sort(m.begin(), m.end());
  cout << N + (X/m[0]) << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;

public class Main {

	int INF = 1 << 28;
	//long INF = 1L << 62;
	double EPS = 1e-10;
	int n;
	String[] words;
	
	void run() {
		Scanner sc = new Scanner(System.in);
		for(;;) {
			n = sc.nextInt();
			if(n == 0) break;
			
			words = new String[n];
			for(int i=0;i<n;i++) words[i] = sc.next();
			sort(words, new Comp());
			ArrayList<String> list = new ArrayList<String>();
			for(int i=0;i<n;i++) {
				boolean f = true;
				for(int j=i+1;j<n;j++){
					if(words[j].indexOf(words[i]) >= 0 ) {
						f = false;
						break;
					}
				}
				if(f) list.add(words[i]);
			}
			list.add("");
			words = list.toArray(new String[]{});
			sort(words);
			n = words.length;
			int[][] es = new int[n][n];
			for(int i=0;i<n;i++) for(int j=0;j<n;j++) {
				es[i][j] = words[i].length() - wordsRap(words[i], words[j]);
			}
//			debug(words);
//			debug(es);
			String[][] dp = new String[1<<n][n]; 
			for(String[] a: dp)fill(a, "."); dp[1][0] = "";
			for(int i=1;i<1<<n;i++) for(int j=0;j<n;j++){
				if(dp[i][j].equals(".")) continue;
				for(int k=0;k<n;k++) if( ((i>>k)&1) == 0 ) {
//					debug(i, j, k, dp[i][j]);
					if(dp[i|(1<<k)][k].equals(".") || dp[i|(1<<k)][k].length() > dp[i][j].length() + words[k].length() - es[j][k]) {
						dp[i|(1<<k)][k] = dp[i][j].substring(0, dp[i][j].length()-es[j][k]) + words[k];
					}
					else if(dp[i|(1<<k)][k].length() == dp[i][j].length() + words[k].length() - es[j][k]) {
						String tmp = dp[i][j].substring(0, dp[i][j].length()-es[j][k]) + words[k];
						if(tmp.compareTo(dp[i|(1<<k)][k]) < 0) dp[i|(1<<k)][k] = tmp;
					}
				}
			}
			String ans = ".";
//			debug(dp[(1<<n)-1]);
			for(int i=0;i<n;i++) {
				if(ans.equals(".") || ans.length() > dp[(1<<n)-1][i].length()) ans = dp[(1<<n)-1][i];
				else if(ans.length() == dp[(1<<n)-1][i].length()) {
					if(ans.compareTo(dp[(1<<n)-1][i]) > 0) ans = dp[(1<<n)-1][i];
				}
			}
			
			System.out.println(ans);
		}
	}
	
	class Comp implements Comparator<String> {

		public int compare(String o1, String o2) {
			// TODO 自動生成されたメソッド・スタブ
			return o1.length() - o2.length();
		}
		
	}
	
	int wordsRap(String a, String b) {
//		debug(a.length());
		for(int i=0;i<a.length();i++) if(b.length() != 0 && a.charAt(i) == b.charAt(0)) {
			boolean f = true;
			for(int j=0;j<b.length();j++) {
				if(i+j>=a.length()) break;
				if(a.charAt(i+j) != b.charAt(j)) {
					f = false; break;
				}
			}
			if(!f) continue;
			return i;
		}
		return a.length();
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}

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

Measured memory_bytes: 71276
#include<algorithm>
#include<stdio.h>
#include<string>
#include<string.h>
#include<stdlib.h>
#include<iostream>
#include<vector>
#include<map>
#include<math.h>
#define ll long long
using namespace std;
double p = 3.1415926535897932384626433832795028841971693993751058209749445923078164;
/**/
int main()
{
	int n;
	cin>>n;
	ll num[200005];
	for(int i=0;i<n;i++)
		cin>>num[i];
	ll sum1=0,sum2=0,ans=0;
	int r=0;
	for(int l=0;l<n;l++)
	{
		while((sum1^num[r])==(sum2+num[r])&&r<n)
		{
			sum1 ^= num[r];
			sum2 += num[r];
			r++;
		}
		ans += (r-l);
		//printf("%lld %lld\n",sum1,sum2);
		sum1 ^= num[l];
		sum2 -= num[l];
		//printf("%lld %lld\n",sum1,sum2);
	}
	cout<<ans<<endl;
	return 0;
}


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

#define F first
#define S second
#define pii pair<int, int>
#define pb push_back

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 2e5 + 10;

int a[N], f[N], g[N];
ll ps[N];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin >> n;
	for (int i=0; i<n; i++) 
	{
		cin >> a[i];
		ps[i + 1] = ps[i] + a[i];
	}

	f[1] = 0;
	for (int i=2; i<=n; i++)
	{
		f[i] = f[i - 1];
		while(ps[f[i]] <= ps[i] - ps[f[i]]) f[i] ++;
		f[i] --;
	}

	g[n - 1] = n;
	for (int i=n-2; i>=0; i--)
	{
		g[i] = g[i + 1];
		while(ps[n] - ps[g[i]] <= ps[g[i]] - ps[i]) g[i] --;
		g[i] ++;
	}

	ll ans = 1e18;

	for (int i=2; i<=n-2; i++)
	{
		pair<ll, ll> s1, s2;
		pair<ll, ll> f1, f2;
		s1 = {ps[f[i]], ps[i] - ps[f[i]]};
		s2 = {ps[f[i] + 1], ps[i] - ps[f[i] + 1]};
		f1 = {ps[n] - ps[g[i]], ps[g[i]] - ps[i]};
		f2 = {ps[n] - ps[g[i] - 1], ps[g[i] - 1] - ps[i]};
	
	
		ans = min(ans, max(max(s1.F, s1.S), max(f1.F, f1.S)) - min(min(s1.F, s1.S), min(f1.F, f1.S)));
		ans = min(ans, max(max(s2.F, s2.S), max(f1.F, f1.S)) - min(min(s2.F, s2.S), min(f1.F, f1.S)));
		ans = min(ans, max(max(s1.F, s1.S), max(f2.F, f2.S)) - min(min(s1.F, s1.S), min(f2.F, f2.S)));
		ans = min(ans, max(max(s2.F, s2.S), max(f2.F, f2.S)) - min(min(s2.F, s2.S), min(f2.F, f2.S)));
	}
	cout << ans << endl;
}


Measured memory_bytes: 4224
function parseInt(x) parse(Int, x) end

function main()
	n = parseInt(readline())
	s = Dict()
	for i in 1:n
		x = readline()
		if haskey(s, x)
			s[x] += 1
		else
			s[x] = 1
		end
	end
	m = parseInt(readline())
	for i in 1:m
		x = readline()
		if haskey(s,x)
			s[x] -= 1
		else
			s[x] = -1
		end
	end
	print(max(maximum(values(s)), 0))
end
main()

Measured memory_bytes: 110812
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pll = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(i) begin(i), end(i)

const int INF = 0x3fffffff;
const ll MINF = 0x7fffffffffff;
const ld DINF = numeric_limits<ld>::infinity();
const int MOD = 1000000007;
const int MODD = 998244353;
const ld EPS = 1e-9;
const ld PI = 3.1415926535897932;

template<class T> bool chmin(T &a, const T &b){ if(a > b){ a = b; return 1; } else return 0; }
template<class T> bool chmax(T &a, const T &b){ if(a < b){ a = b; return 1; } else return 0; }
template<class T> auto min(const T& a){ return *min_element(all(a)); }
template<class T> auto max(const T& a){ return *max_element(all(a)); }

ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }
ll pow_mod(ll n,ll k,ll m){ll r = 1;for(; k > 0;k >>= 1) {if (k & 1) r = (r * n) % m; n = (n * n) % m;}return r;}

//ここから。
int main(){
    string S,T;
    cin >> S >> T;
    int ans = 0;
    if(S[0] == T[0]) ans++;
    if(S[1] == T[1]) ans++;
    if(S[2] == T[2]) ans++;

    cout << ans << endl;
}

Measured memory_bytes: 256
function main(input) {
  const args = input.split(' ').map(n => parseInt(n, 10));
  args.sort((a, b) => {
    return b - a;
  });
  
  console.log(args[0] * 10 + args[1] + args[2]);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 29660
#include <stdio.h>
int main(void){
  int n,t[100],m,p,x,s=0,i,ans;
  scanf("%d",&n);
  for (i=0;i<n;i++){
    scanf("%d",&t[i]);
    s+=t[i];
  }
  scanf("%d",&m);
  for (i=0;i<m;i++){
    scanf("%d%d",&p,&x);
    printf("%d\n",s-t[p-1]+x);
  }
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;

int fact(int n) {
    if (n == 1) {
        return 1;
    } else {
        return n * fact(n - 1);
    }
}

int main() {
    int n;
    cin >> n;
    vector<pair<int, int>> r(n);
    for (int i = 0; i < n; i++) {
        cin >> r.at(i).first >> r.at(i).second;
    }
    vector<vector<double>> d(n, vector<double>(n));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            int dx = r.at(i).first - r.at(j).first;
            int dy = r.at(i).second - r.at(j).second;
            d.at(i).at(j) = sqrt(dx * dx + dy * dy);
        }
    }
    vector<int> p(n);
    for (int i = 0; i < n; i++) {
        p.at(i) = i + 1;
    }
    double ave = 0;
    do {
        for (int i = 0; i < n - 1; i++) {
            ave += d.at(p.at(i) - 1).at(p.at(i + 1) - 1);
        }
    } while (next_permutation(p.begin(), p.end()));
    cout << setprecision(20) << ave / fact(n) << endl;
    return 0;
}

Measured memory_bytes: 3864
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

int main(){
    ll q,h,s,d,n;
    cin>>q>>h>>s>>d>>n;
    q*=4,h*=2;
    ll li=min(q,min(h,s));
    ll ans;
    if(n%2==0) ans=min(li*n,d*n/2);
    else ans=min(li*n,d*(n/2)+li);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<double, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;
	//作るときはParentの値を全て-1にする
	//こうするとすべてバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}
	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}
	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}
	//AとBをくっつける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついているからくっつけない
			return false;
		}
		//大きい方(A)に小さいほう(B)をくっつけたい
		//大小が逆だったらひっくり返しちゃう
		if (size(A) < size(B)) swap(A, B);
		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
	//AとBが同じグループにいるか
	bool same(int A, int B) { return root(A) == root(B); }
};

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	vector<ll> ans;
	UnionFind Uni(n);
	vector<int> a(m), b(m);
	rep(i, m) cin >> a[i] >> b[i], a[i]--, b[i]--;
	reverse(all(a));
	reverse(all(b));
	ll sum = 0;
	rep(i, m) {
		ans.push_back(sum);
		if (!Uni.same(a[i], b[i])) {
			ll res = Uni.size(a[i]);
			res *= Uni.size(b[i]);
			sum += res;
			Uni.connect(a[i], b[i]);
		}
	}
	reverse(all(ans));
	for (ll c : ans) cout << sum - c << endl;
 	return 0;
}


Measured memory_bytes: 3444
#include <stdio.h>

int main(){

  int i,minj,j,count=0,N,A[100],tmp;

  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }

  for(i=0;i<N-1;i++){
    minj=i;
    for(j=i;j<=N-1;j++){
      if(A[j] < A[minj]) minj=j;
			   
    }
    if(minj!=i){
      tmp=A[i];
      A[i]=A[minj];
      A[minj]=tmp;
      count++;
    }
  }
  for(j=0;j<N;j++){
    if(j>0) printf(" ");
    printf("%d",A[j]);
  }
  printf("\n");
  printf("%d\n",count);

  
}



Measured memory_bytes: 2128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define INF pow(10,10)

int main(void){
    ll n,max_w; cin >> n >> max_w;
    vector<ll>w(n+1),v(n+1);
    for(int i=1;i<=n;i++) cin >> w[i] >> v[i];
    vector<vector<ll>>weight(n+1,vector<ll>(100005,0));
    for(int i=1;i<=n;i++){
        for(int j=0;j<weight[0].size();j++){
            ll a=INF,b=INF;
            if(weight[i-1][j]!=0) a = weight[i-1][j];
            if(j-v[i]==0||(0<=j-v[i] && weight[i-1][j-v[i]]!=0)) b = weight[i-1][j-v[i]] + w[i];
            if(a != INF || b != INF) weight[i][j] = min(a,b);
        }
    }
    // cout << min_element(weight[n].begin(),weight[n].end()) - weight[n].begin() << endl;
    // for(int i=1;i<=n;i++){
    //     for(int j=0;j<100;j++){
    //         cout << weight[i][j] << ' ';
    //     }cout << endl;
    // }
    ll ans;
    for(int i=0;i<weight[n].size();i++){
        if(weight[n][i] != 0 && weight[n][i]<=max_w) ans = i;
    }
    cout <<ans << endl;
    return 0;
}

Measured memory_bytes: 80256
#include <bits/stdc++.h>
#define rep(i,n)  for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define deb(x) cerr << #x <<": " << x << '\n';
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
typedef long double ld;
typedef long long ll;

int main(){
    ios;
    vector<int> V(3);
    rep(i,3){
        cin >> V[i];
    }
    sort(V.begin(),V.end());
    cout << V[0] + V[1];
    return 0;
    
}



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

typedef long long ll;
const int maxn = 100010;
int n;
ll a[maxn];

int main() {
    scanf("%d", &n);
    long long sum = 0;
    for (int i = 1; i <= n; i++) {
        scanf("%lld", &a[i]), sum += a[i];
    }
    if (sum % (1LL * n * (n + 1) / 2)) {
        printf("NO\n"), exit(0);
    }
    sum /= (1LL * n * (n + 1) / 2);
    long long all = 0;
    for (int i = 1; i <= n; i++) {
        int j = i == 1 ? n : i - 1;
        all += (a[j] + sum - a[i]) / n;
        if (a[j] + sum - a[i] < 0) printf("NO\n"), exit(0);
    }
    printf("%s\n", sum == all ? "YES" : "NO");
    return 0;
}

Measured memory_bytes: 1024
import numpy as np
from scipy.spatial import ConvexHull
from scipy.spatial.qhull import QhullError
from scipy.spatial.distance import cosine

def main(points):
    ans = [0.0] * N

    try:
        hull = ConvexHull(np.asarray(points))
    except QhullError:
        ans[points.index(min(points))] = ans[points.index(max(points))] = 0.5
        return ans

    L = hull.vertices.shape[0]

    for i, v in enumerate(hull.vertices):
        prv, nxt = hull.vertices[[(i+L-1) % L, (i+1) % L]]
        deg = np.arccos(1-cosine(hull.points[prv]-hull.points[v],
                                 hull.points[nxt]-hull.points[v]))
        ans[v] = (np.pi-deg)/(2*np.pi)
    return ans


if __name__ == '__main__':
    N = int(input())
    points = []
    for _ in range(N):
        x, y = map(int, input().split())
        points.append([x, y])
    print(*main(points), sep='\n')


Measured memory_bytes: 20136
#include<bits/stdc++.h>
#include<vector>
#include<cstring>
#include<iostream>
#include<cstdio>
#define ull unsigned long long
#define ll long long
const int mod=1e9+7;
using namespace std;
//priority_queue
inline int in()
{
    int res=0;
    char c=getchar();
    while(c<'0'||c>'9') c=getchar();
    while(c>='0'&&c<='9') res=res*10+c-48,c=getchar();
    return res;
}

 int gcd(int a,int b)
 {
     return b==0?a:gcd(b,a%b);
 }
int main()
{  ios::sync_with_stdio(false);
  ll a;
  cin>>a;
  cout<<(a-2)*180;
}


Measured memory_bytes: 256
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

def judge(n, a, f, x, k):
    req = 0
    for i in range(n):
        if a[i]*f[i] > x:
            req += -(-(a[i]*f[i] - x) // f[i])
    return True if req <= k else False

def binsearch(n, a, f, k):
    low = 0
    high = max(a) * max(f)
    while high - low > 1:
        mid = (low + high) // 2
        if judge(n, a, f, mid, k):
            high = mid
        else:
            low = mid

    return high

n, k = li()
a = list(li())
f = list(li())

a.sort()
f.sort(reverse=True)

if k >= sum(a):
    print(0)
else:
    print(binsearch(n, a, f, k))

Measured memory_bytes: 107340
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
using namespace std;
const int inf = 1e9;

int main(){
	while(1){
		int n;
		cin >> n;
		if(n==0) break;
		
		vector<vector<int> > cost(n,vector<int>(n+1));
		for(int i=0; i<n; i++){
			for(int j=0; j<n+1; j++){
				cin >> cost[i][j];
			}
		}
		
		//make adjlist 
		vector<vector<pair<int,int> > > adj(1<<n);
		for(int i=0; i<(1<<n); i++){
			for(int b=0; b<n; b++){
				if((i&(1<<b)) == 0){
					int c=cost[b][0];
					for(int j=0; j<n; j++){
						if((i&(1<<j)) != 0){
							c = min(c, cost[b][j+1]);
						}
					}
					adj[i].push_back(make_pair(i|(1<<b), c));
				}
			}
		}
		
		//dijkstra
		priority_queue<pair<int,int> > pq;
		pq.push(make_pair(0,0));
		vector<int> mc(1<<n, inf);
		mc[0]=0;
		while(!pq.empty()){
			int cpos = pq.top().second;
			int ccost = -pq.top().first;
			pq.pop();
			if(cpos == (1<<n)-1) break;
			if(ccost > mc[cpos]) continue;
			
			for(int i=0; i<(int)adj[cpos].size(); i++){
				int dest = adj[cpos][i].first;
				int cost = adj[cpos][i].second;
				if(ccost +cost < mc[dest]){
					mc[dest] = ccost+cost;
					pq.push(make_pair(-mc[dest], dest));
				}
			}
		}
		cout << mc[(1<<n)-1] << endl;
	}
	return 0;
}

Measured memory_bytes: 12032
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<cstdio>
using namespace std;
#define P pair<int, double>

class C{
    public:
        //0 : 普通のマス, 1 : L, 2 : B
        int type;
        double ans;
        C(int t, double a);
};

C::C(int t, double a){
    type = t;
    ans = a;
}

int main(){
    int n, t, l, b;
    while(cin >>n >>t >>l >>b){
        if(n == 0 && t == 0 && l == 0 && b == 0) break;
        vector<C> vec, vec2;
        for(int i = 0; i <= n; i++){
            C cls(0, 0.0);
            vec.push_back(cls);
        }
        for(int i = 0; i < l + b; i++){
            int tmp;
            cin >>tmp;
            vec[tmp].type = ((i < l)? 1 : 2);
        }
        vec[0].ans = 1.0;
        vec2 = vec;
        for(int i = 0; i < t; i++){
            queue<P> qu;
            for(int j = 0; j < n; j++){
                for(int k = 1; k <= 6; k++){
                    int next = j + k;
                    if(next > n) next = n - (next - n);
                    if(vec[next].type == 1){
                        qu.push( P(next, (vec[j].ans * ((double)(1.0 / 6.0)))) );
                        continue;
                    }
                    if(vec[next].type == 2) next = 0;
                    vec2[next].ans += (vec[j].ans * ((double)(1.0 / 6.0)));
                }
            }
            if(i == 0) vec2[0].ans -= 1.0;
            vec2[n].ans += vec[n].ans;
            vec = vec2;
            for(int m = 0; m < vec2.size(); m++) vec2[m].ans = 0.0;
            while(!qu.empty()){
                vec2[qu.front().first].ans += qu.front().second;
                qu.pop();
            }
        }
        printf("%.06lf\n", vec[n].ans);
    }
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, n) for (int i = 1; i <= (int)(n); i++)
using ll = long long;

/*
 string -> int : stoi(S);
 int -> string : to_string(N);
 Sのn文字以降をm文字取り出す : S.substr(n,m)
cout << fixed << setprecision(2) << 3.14 << endl; //3.1

 int: -2,147,483,648 ～ 2,147,483,647 (2×10^9)
 ll: -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 (9×10^18)

*/

int main() {

  int n,m, count=0, ans=0;
  string s;
 
  cin >> n >> m;
  vector<int> a(m);
  rep(i,m) {
    cin >> a[i];
    count+=a[i];
  }
  ans = n-count;
  ans =max(-1,ans);
  cout << ans << endl;
  
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define endl enjoy_codeforces
using lint=long long;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::string s,t;std::cin>>s>>t;
    lint l=s.length();
    s+=s;
    std::vector<std::vector<lint>>a(2*l,std::vector<lint>(26));
    for(lint i=0;i<26;i++)a.at(2*l-1).at(i)=2*l;
    for(lint i=2*l-2;i>=0;i--){
        for(lint j=0;j<26;j++){
            a.at(i).at(j)=s.at(i+1)=='a'+j?i+1:a.at(i+1).at(j);
        }
    }
    lint ans=-1;
    for(char c:t){
        int i=(ans+l)%l;
        if(a.at(i).at(c-'a')==2*l){
            std::cout<<-1<<'\n';
            return 0;
        }
        ans+=a.at(i).at(c-'a')-i;
    }
    std::cout<<ans+1<<'\n';
}


Measured memory_bytes: 49004