akhauriyash/Code-Regression huggingface dataset:
#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()
{
	ios::sync_with_stdio(false);
	cin.tie(0);

	ll			n;
	ll			k;
	ll			minv;

	cin >> n >> k;
	minv = n;
	if (n > k)
		n %= k;
	minv = min(n, minv);
	rep(i, 3)
	{
		n = abs(k - n);
		minv = min(n, minv);
	}
	cout << minv << "\n";

}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Iterator;
import java.util.Collections;
import java.util.Comparator;
import java.util.Random;
import java.util.Map;
import java.util.HashMap;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int H = sc.nextInt();
		int a;
		int aMax = 0;
		int[] b = new int[N];
		for(int i=0; i<N; i++){
			a = sc.nextInt();
			b[i] = sc.nextInt();
			aMax = Math.max(aMax,a);
		}

		Arrays.sort(b);
		int bNum=0;
		int bSum=0;
		for(int i=N-1; i>=0; i--){
			if(aMax<b[i]){
				bSum += b[i];
				bNum++;
			}else if(aMax>=b[i]){
				break;
			}
			if(i == 0){
				bNum = N;
			}
		}

		int count = 0;

		if(bSum>=H){
			for(int i=N-1; H>0; i--){
				H -= b[i];
				count ++;
			}
		}else{
			if((H-bSum) % aMax == 0){
				count = bNum + (H-bSum)/aMax;
			}else{
				count = bNum + (H-bSum)/aMax +1;
			}  
		}

		System.out.println(count);
	}	
}


Measured memory_bytes: 64500
#include<stdio.h>

#define INFTY 1000000001 

void merge(int *,int,int,int);
void mergeSort(int *,int,int);

int count=0,n;


int main(){

  int i;

  int S[500000];

  // printf("%d\n",INFTY);
  
  scanf("%d",&n);

  //printf("wa-i2\n");
  
  for(i=0;i<n;i++){

    scanf("%d",&S[i]);

    // printf("%d ",S[i]);
    
  }

  // printf("\n");
  
  //printf("wa-i\n");
  
  mergeSort(S,0,n);

  //printf("wa-i1\n");

  for(i=0;i<n;i++){
    
    if(i==n-1)printf("%d\n",S[i]);
    else printf("%d ",S[i]);

  }

  printf("%d\n",count);

  return 0;
  
}

void merge(int *A,int left,int mid,int right){

  int n1,n2,i,j,L[500000],R[500000],k;

  
  n1= mid-left;
  n2= right-mid;


  for(i=0;i<n1;i++){

    L[i]=A[left+i];

  }

  for(i=0;i<n2;i++){

    R[i]=A[mid+i];

  }

  L[n1]=INFTY;
  R[n2]=INFTY;
  i=0;
  j=0;

  for(k=left;k<right;k++){

    count++;

    if(L[i]<=R[j]){

      A[k]=L[i];
      i=i+1;
    }

    else{
      A[k]=R[j];
      j=j+1;
    }

  }
  
}

void mergeSort(int *A,int left,int right){

  int mid;

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

    printf("%d ",A[i]);

  }

  printf("\n");
  printf("left: %d,right: %d\n",left,right);
  */
 
  if(left+1<right){

    mid=(left+right)/2;

    //printf("mid: %d\n",mid);
    
    mergeSort(A,left,mid);
    mergeSort(A,mid,right);
    merge(A,left,mid,right);

  }

}
    

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

using namespace std;
typedef long long ll;

#define INF (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

ll f(ll a, ll b)
{
    return max(to_string(a).size(), to_string(b).size());
}

int main(void)
{
    ll n;
    cin >> n;
    ll mi = INF * 100;
    for(ll i = 1; i*i <= n; i++) {
        if(n % i == 0) {
            mi = min(mi, f(i, n / i));
        }
    }
    cout << mi << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <set>

using namespace std;

typedef long long ll;
ll MOD = 1000000007LL;
ll INF = 1LL << 60;
typedef pair<ll,ll> P;

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

ll D[200005];

int main() {
  ios::sync_with_stdio(false);
  int N;
  ll A, B;
  cin >> N;
  ll nZZ = 0;
  ll nZero = 0;
  ll nInf = 0;
  map<P, ll> m[2];
  set<P> st;
  for (int i=0; i<N; i++) {
    cin >> A >> B;
    if (A == 0 && B == 0) {
      nZZ++; continue;
    }
    if (A == 0) {
      nZero++; continue;
    }
    if (B == 0) {
      nInf++; continue;
    }
    int s = 0;
    if (A < 0 && B < 0) {
      A = -A; B = -B;
    } else if (A < 0 || B < 0) {
      s = 1;
      A = (A < 0) ? -A : A;
      B = (B < 0) ? -B : B;
      swap(A, B);
    }
    ll g = gcd(A, B);
    A /= g;
    B /= g;
    P p = make_pair(A, B);
    m[s][p]++;
    st.insert(p);
  }
  D[0] = 1;
  for (int i=1; i<=200005; i++) {
    D[i] = (D[i-1] * 2LL) % MOD;
  }
  ll ret = 1;
  ret *= D[nZero + nInf];
  ret %= MOD;
  ret -= (D[nZero] - 1) * (D[nInf] - 1) % MOD;
  ret = (ret % MOD + MOD) % MOD;
  //cout << ret << endl;
  for (set<P>::iterator it = st.begin(); it != st.end(); ++it) {
    ll a = m[0][*it];
    ll b = m[1][*it];
    ll c = D[a + b];
    c -= (D[a] - 1) * (D[b] - 1) % MOD;
    c = (c % MOD + MOD) % MOD;
    ret = (ret * c) % MOD;
    //cout << it->first << "/" << it->second << " " << a << b << c << ret << endl;
  }
  cout << (ret - 1 + MOD + nZZ) % MOD << endl;
}

Measured memory_bytes: 42612
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <climits>
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mpair make_pair
#define pm(first, second) pb(mpair(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()
#define reall(X) (X).rbegin(), (X).rend()
#define divcel(a, b) (((a) + ((b) - 1)) / (b))

int main(){

    ll N, M;
    cin >> N >> M;
    vector<pair<ll, ll>> V(N + M);
    ll in1, in2;
    for(ll i = 0; i < N; i++){
        cin >> in1;
        V[i] = mpair(in1, 1);
    }
    for(ll i = 0; i < M; i++){
        cin >> in1 >> in2;
        V[N + i] = mpair(in2, in1);
    }
    sort(all(V));
    ll ans = 0, cnt = N, index = N + M - 1;
    while(cnt > 0 && index >= 0){
        if(V[index].second < cnt){
            ans += V[index].first * V[index].second;
            cnt -= V[index].second;
            index--;
        }
        else{
            ans += V[index].first * cnt;
            cnt = 0;
            index--;
        }
    }
    cout << ans << endl;

    return 0;
}

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

int main(){
  int N, K;
  string S;
  cin >> N >> S >> K;
  char c = S.at(K-1);
  for(int i = 0; i < N; i++){
    if (S.at(i) != c) {
      S.at(i) = '*';
    }
  }
  cout << S;
}

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

int main(){
    int n, m; cin >> n >> m;
    priority_queue<int> pq;
    for (int i = 0; i < n; ++i) {
        int a; cin >> a;
        pq.push(a);
    }
    for (int i = 0; i < m; ++i) {
        int num = pq.top();
        pq.pop();
        pq.push(num / 2);
    }
    long long ans = 0;
    while (!pq.empty()) {
        ans += pq.top();
        pq.pop();
    }
    cout << ans << endl;
}

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

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

typedef pair<int, int> pii;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

signed main() {
    int N, W, D;
    while(cin >> N >> W >> D, N || W || D) {
        vector<int> p(N), s(N);
        rep(i,0,N) cin >> p[i] >> s[i];

        vector<pii> cakes;
        cakes.push_back(pii(W, D));

        rep(i,0,N) {
            int num = p[i] - 1;
            pii cur = cakes[num];
            int a = cur.first, b = cur.second;
            cakes.erase(cakes.begin() + num);

            int T = a + b;
            s[i] %= T;
            if(s[i] < cur.first) {
                // ???????????? (?¨?????????????)
                int nw = a - s[i];
                pii x = pii(nw, b);
                pii y = pii(a - nw, b);

                if(nw*b > (a-nw)*b) swap(x, y);
                cakes.push_back(x);
                cakes.push_back(y);
            }
            else {
                s[i] -= cur.first;
                // ?¨?????????? (???????????????)
                int nd = b - s[i];
                pii x = pii(a, nd);
                pii y = pii(a, b - nd);

                if(a*nd > a*(b-nd)) swap(x, y);
                cakes.push_back(x);
                cakes.push_back(y);
            }
        }

        vector<int> ans;
        for(auto x : cakes) ans.push_back(x.first * x.second);
        sort(ans.begin(), ans.end());

        rep(i,0,ans.size()) {
            if(i != 0) cout << " ";
            cout << ans[i];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3024
#include <iostream>

using namespace std;

int main() {
    int a, b, c, x, y;
    int i, j, k;
    int ans[3];
    cin  >> a >> b >> c >> x >> y;
    int price = INT_MAX;

    if (x > y) {
        for (i = 0; i <= x; i++) {
            j = max(y-x+i, 0);
            k = 2*(x - i);
            int tmp = a*i + b*j + c*k;
            if (tmp < price) {
                price = tmp;
                ans[0] = i;
                ans[1] = j; 
                ans[2] = k;
            }
        }
    }
    else {
        for (j = 0; j <= y; j++) {
            k = 2*(y - j);
            i = max(x-y+j, 0);
            int tmp = a*i + b*j + c*k;
            if (tmp < price) {
                price = tmp;
                ans[0] = i;
                ans[1] = j; 
                ans[2] = k;
            }
        }
    }
    cout << a*ans[0] + b*ans[1] + c*ans[2] << endl;
    return 0;
}

Measured memory_bytes: 256
import collections
N = int(input().strip())
A = list(map(int, input().strip().split(' ')))
C = [0 for j in range(N)]
C[0] = A[0]
for i in range(1,N):
        C[i] = C[i-1] + A[i]
C.sort()

CC = collections.Counter(C)

result = CC[0]
for k in CC.values():
    if k > 1:
        result = result + k*(k-1)/2

print(int(result))

Measured memory_bytes: 41696
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
#include <set>
using namespace std;
typedef long long ll;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n ,  a;
    cin >> n >> a;
    cout << n * n - a;
}

Measured memory_bytes: 3624
A, B, C, D = map(int, input().split())
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a*b//gcd(a,b)

def calc(n):
    return n-n//C-n//D+n//(lcm(C,D))
 
print(calc(B)-calc(A-1))

Measured memory_bytes: 3060
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<double> a(n);
	for (double& i : a) cin >> i;
	sort(a.begin(), a.end());
	sort(a.begin(), a.end() - 1, [&a](double& b, double& c) { return fabs(a.back() / 2.0 - b) < fabs(a.back() / 2.0 - c); });
	printf("%.f %.f", a.back(), a.front());
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <unordered_map>
using namespace std;
using u64 = uint64_t;
/*
NをAで割る→Aを何倍していいか分かる。
10/3 = 3, つまり A=3のときB=1,2,3
ただしC=0はダメなので、N-1を上限とすればよい。
*/

int main()
{
    u64 N = 0;
    cin >> N;
    int A = 1;
    u64 result = 0;
    while((N-1) / A != 0) {
        // A is 
        result += ((N-1) / A);
        A++;
    }
    cout << result << endl;
}

Measured memory_bytes: 3220
/* include c++ libraries */
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <map>
#include <queue>
#include <set>

/* include c-lang libraries */
#include <climits>
#include <cmath>

/* include my libraries */
//#include <show_vec.hh>

using namespace std;

#define LINE DEBUG{ printf("LINE : %d\n", __LINE__); }
#define DEBUG if(false)

using ll = long long;
template<class T> using vec = vector<T>;

const int MOD = 1000000007;

int main(){
  string S, T;
  cin >> S >> T;
  int diff = 0;
  for(int i = 0; i < S.length(); i++){
    if(S[i] != T[i]) diff++;
  }
  cout << diff << endl;

  return 0;
}


Measured memory_bytes: 3920
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる


int len(int x, vector<vector<int>> &p, vector<int> &memo){
  if(memo[x]!=-1) return memo[x];
  if(p[x].empty()) return 0;
  int rtn=0;
  for(auto z : p[x]){
    chmax(rtn,len(z,p,memo)+1);
  }
  memo[x]=rtn;
  return rtn;
}



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

  vector<vector<int>> p(n);
  rep(i,m){
    int x,y;
    cin>>x>>y;
    x--;y--;
    p[x].pb(y);
  }

  vector<int> memo(n,-1);

  int ans=0;
  rep(i,n){
    chmax(ans,len(i,p,memo));
  }

  cout << ans << endl;
}


Measured memory_bytes: 8832
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <climits>
#include <iomanip>
#define endl "\n"
#define debug(x) cout << #x << " : " << x << endl;
#define debug2(x, y) cout << #x << " : " << x  << ", " << #y << " : " << y << endl;
#define FASTIO ios_base::sync_with_stdio(false),cin.tie(0);
typedef long long ll;
using namespace std;

const int maxn = 1e6 + 5;
int spf[maxn];
int gcd(int a, int b)
{
	if(b == 0)
		return a;
	return gcd(b, a % b);
}

void sieve()
{
	for(int i = 1; i <= 1e6; i ++)
	{
		if(i % 2 == 0)
			spf[i] = 2;
		else
			spf[i] = i;
	}

	for(int i = 3; i * i <= 1e6; i ++)
	{
		if(spf[i] == i)
		{
			for(int j = i; i * j <= 1e6; j ++)
			{
				if(spf[i * j] == i * j)
					spf[i * j] = i;
			}
		}
	}
}

int main()
{
	FASTIO

	sieve();
	int n;
	cin >> n;

	vector <int> v(n);
	for(int i = 0; i < n; i ++)
	{
		cin >> v[i];
	}	

	int gcdVal = 0;
	int flag = 0; // Array is pairwise coprime
	for(int i = 0; i < n; i ++)
	{
		gcdVal = gcd(gcdVal, v[i]);
	}

	map <int, bool> mp;
	set <int> primes;
	for(int i = 0; i < n; i ++)
	{
		int val = v[i];
		primes.clear();
		while(val != 1)
		{
			primes.insert(spf[val]);
			val = val / spf[val];
		}

		for(auto it = primes.begin(); it != primes.end(); it ++)
		{
			if(mp.find(*it) != mp.end())
			{
				flag = 1;
				break;
			}
			mp[*it] = true;
		}

		if(flag == 1)
			break;
	}

	if(flag == 0)
	{
		cout << "pairwise coprime" << endl;
	}
	else if(gcdVal == 1)
		cout << "setwise coprime" << endl;
	else 
		cout << "not coprime" << endl;


}	

Measured memory_bytes: 11200
n, k = map(int, input().split())
a = [int(i) for i in input().split()]
MOD = 10 ** 9 + 7
s, t = [], []  # 正、負の配列
for i in a:
  if i < 0:
    t.append(i)
  else:
    s.append(i)
S, T = len(s), len(t)
is_positive = False  # 積が正である
if S > 0:
  # 正の数が0より大きい
  if n == k:
    # nとkが同じ
    is_positive = (T % 2 == 0) # 負の数が偶数個のとき、積は正
  else:
    is_positive = True
else:
  is_positive = (k % 2 == 0)

ans = 1
if not is_positive:
  a.sort(key=abs)
  for i in range(k):
    ans = ans * a[i] % MOD
else:
  s.sort()
  t.sort(reverse=True)
  if k % 2 == 1:
    ans = ans * s.pop(-1) % MOD
  p = []
  while(len(s) >= 2):
    x = s.pop(-1)
    x *= s.pop(-1)
    p.append(x)
  while(len(t) >= 2):
    x = t.pop(-1)
    x *= t.pop(-1)
    p.append(x)
  p.sort(reverse=True)
  for i in range(k // 2):
    ans = ans * p[i] % MOD
print(ans)

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

int main(){
 vector<int>v(3);
  for(int i=0;i<3;i++){
   cin>>v.at(i); 
  }
  
  int cnt5,cnt7;
  cnt5=count(v.begin(),v.end(),5);
  cnt7=count(v.begin(),v.end(),7);
  
  if(cnt5==2&&cnt7==1){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
  return 0;
}

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a, b) accumulate(all(a), b)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
typedef unsigned long long ull;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
ll const INF = 1e18;

template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    int n;
    cin >> n;
    vector<pair<ll,ll>> v(n);
    for(auto& i : v) cin >> i.first >> i.second;

    sort(all(v));

    map<pair<ll,ll>, int> mp;

    REP(i, n){
        FOR(j, i+1, n){
            mp[make_pair(v[i].first - v[j].first, v[i].second - v[j].second)]++;
        }
    }

    int ans = 0;

    for(auto i : mp){
        chmax(ans, i.second);
    }

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


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
static   Scanner scan = new Scanner(System.in);
 
    public static void main(String[] args) {
        int x,b;
        while(true){
            x=scan.nextInt(); b=scan.nextInt();
            if (x == 0 && b == 0){
                break;
            }
            if(x>b){
                System.out.printf("%d %d\n",b,x);
            }else{
                  System.out.printf("%d %d\n",x,b);
            }
        }
        
    }
}


Measured memory_bytes: 42208
import java.util.*;
class Main
{
  public static void main(String []args)
  {
    Scanner sc=new Scanner(System.in);
    int a=sc.nextInt();
    int z=0;
    double d=0.0;
    for(int i=0;i<a;i++)
    {
      z=sc.nextInt();
      d=d+1.0/z;
    }
    d=1/d;
    System.out.println(d);
    }
}

Measured memory_bytes: 21844
def p(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
def P(L):
  P = 1
  for c in range(len(L)):
    P = P*L[c]
  return P  
N = int(input())
A = p(N)
F = []
for i in range(2**(len(A))):
  B = []
  C = []
  for j in range(len(A)):
    if(i>>j&1):
      B.append(A[j])
    else:
      C.append(A[j])
  F.append(max(len(str(P(B))),len(str(P(C)))))
  
print(min(F))

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

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define chmax(a,b) (a<(b)?(a=b,1):0)
#define chmin(a,b) (a>(b)?(a=b,1):0)
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
const int INF = 1<<29;
const double EPS = 1e-8;
const double PI = acos(-1);
typedef pair<int,int> pii;
typedef long long ll;

typedef int weight;
typedef vector<weight> Array;
typedef vector<Array> matrix;

weight hungarian(const matrix &a) {
  int n = a.size(), p, q;
  Array fx(n, INF), fy(n, 0);
  vector<int> x(n, -1), y(n, -1);
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j)
      fx[i] = max(fx[i], a[i][j]);
  for (int i = 0; i < n; ) {
    vector<int> t(n, -1), s(n+1, i);
    for (p = q = 0; p <= q && x[i] < 0; ++p)
      for (int k = s[p], j = 0; j < n && x[i] < 0; ++j)
        if (fx[k] + fy[j] == a[k][j] && t[j] < 0) {
          s[++q] = y[j], t[j] = k;
          if (s[q] < 0)
            for (p = j; p >= 0; j = p)
              y[j] = k = t[j], p = x[k], x[k] = j;
        }
    if (x[i] < 0) {
      weight d = INF;
      for (int k = 0; k <= q; ++k)
        for (int j = 0; j < n; ++j)
          if (t[j] < 0) d = min(d, fx[s[k]] + fy[j] - a[s[k]][j]);
      for (int j = 0; j < n; ++j) fy[j] += (t[j] < 0 ? 0 : d);
      for (int k = 0; k <= q; ++k) fx[s[k]] -= d;
    } else ++i;
  }
  weight ret = 0;
  for (int i = 0; i < n; ++i) ret += a[i][x[i]];
  return ret;
}

int main() {
  int n;
  while(cin >> n) {
    int p[n];
    REP(i,n) {
      cin >> p[i];
    }
    matrix a(n,Array(n));
    REP(i,n) {
      REP(j,n) {
        if (p[i]-1==j) a[i][j] = -INF;
        else {
          a[i][j] = -p[i]*abs(j-i);
        }
      }
    }
    cout << -hungarian(a) << endl;
  }
}

Measured memory_bytes: 1260
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl 	"\n"
 
typedef vector< ll > 	vi;
typedef vector< vi > 	vvi;
typedef pair< ll,ll > 	ii;
#define pb 		push_back
#define all(c) 		(c).begin(),(c).end()
#define tr(c,i) 	for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) 	((c).find(x) != (c).end())
 
#define MOD 	1000000007
#define INF 	(int)1e9
#define MEM(a, b) memset(a, (b), sizeof(a))
 
int main()
{	 ios_base::sync_with_stdio(false);
	 cin.tie(NULL);
	
 
	ll a[3]={0};
	for(ll i=0; i<3; i++){
		cin>>a[i];
	}
	sort(a,a+3);
	if( (a[0]!=a[1] && a[1]==a[2]) || (a[0]==a[1] && a[1]!=a[2]) )
		cout<<"Yes";
	else cout<<"No";
	
	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10000)
num = int(input())
cnt = 0
def merge(A, left, mid, right):
    global cnt
    n1 = mid - left
    n2 = right - mid
    L = A[left:mid]  + [ 1e10 ]
    R = A[mid:right] + [ 1e10 ]
    i = 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)

L = [int(x) for x in input().split()]
c = mergeSort(L, 0, len(L))
print(" ".join(map(str,L)))
print(cnt)



Measured memory_bytes: 66604
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)

using namespace std;

const int N=20010,inf=1e9;
int n,a[N],b[N],p[N];

int main(){
	scanf("%d",&n);
	rep (i,1,n) scanf("%d",&p[i]);
	int v=(inf-1)/n;
	a[1]=1,b[n]=1;
	rep (i,1,n-1) a[i+1]=a[i]+v,b[n-i]=b[n-i+1]+v;
	rep (i,1,n){
		if (a[p[i]]-(n-i)>0&&(p[i]==1||a[p[i]]-(n-i)>a[p[i]-1])) a[p[i]]-=n-i;
		else b[p[i]]-=(n-i);
	}
	rep (i,1,n) printf("%d ",a[i]); puts("");
	rep (i,1,n) printf("%d ",b[i]); puts("");
	return 0;
}

Measured memory_bytes: 896
#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() {
  int n, k, r, s, p;
  cin >> n >> k >> r >> s >> p;
  char t[n];
  rep(i,n) cin >> t[i];
  for(int i=0; t[i+k]!='\0'; i++) {
    if(t[i]==t[i+k]) t[i+k]='x';
  }
  int ans=0;
  for(int i=0; t[i]!='\0'; i++) {
    if(t[i]=='r') ans+=p;
    else if(t[i]=='s') ans+=r;
    else if(t[i]=='p') ans+=s;
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 384
#include<stdio.h>
int main(void)
{
	int A,op,B,t;
	scanf("%d %c %d",&A,&op,&B);
	if(op=='+'){
	        t=A+B;
				printf("%d\n",t);
	}
	else{
			t=A-B;
				printf("%d\n",t);
	}
	return 0;
}


Measured memory_bytes: 128
data=[]
for num in input().split():
    a=0
    b=0
    if num is "+":
        a=data.pop()
        b=data.pop()
        data.append(b+a)
    elif num is "-":
        a=data.pop()
        b=data.pop()
        data.append(b-a)
    elif num is "*":
        a=data.pop()
        b=data.pop()
        data.append(b*a)
    else:
        data.append(int(num))
print(data.pop())



Measured memory_bytes: 5592
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;


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

    int res_0 = 0;
    for (int i = 0; i < S.size(); i++) {
        if (i % 2 == 0 && S[i] == '1') res_0++;
        if (i % 2 == 1 && S[i] == '0') res_0++;
    }

    int res_1 = 0;
    for (int i = 0; i < S.size(); i++) {
        if (i % 2 == 0 && S[i] == '0') res_1++;
        if (i % 2 == 1 && S[i] == '1') res_1++;
    }

    cout << min(res_0, res_1) << endl;


    return 0;
}


Measured memory_bytes: 512
def findSumOfDigits(n):
    sum = 0
    while n > 0:
        sum += n % 10
        n //= 10
    return sum

n = int(input())
minTotal = float('inf')
for i in range(1,n+1):
    if 0 < n - i < n:
        a = findSumOfDigits(i)
        b = findSumOfDigits(n-i)
        if a + b < minTotal:
            minTotal = a + b
print(minTotal)

Measured memory_bytes: 9164
#include <iostream>
#include <assert.h>
#include <vector>
#include <algorithm>

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

    int32_t N, M;
    std::cin >> N >> M;

    if(N >= M){
        std::cout << 0;
        return 0;
    }
    
    std::vector<int32_t> X(M);
    for(auto& i : X){
        std::cin >> i;
    }
    std::sort(X.begin(), X.end());
    std::vector<int32_t> diffs(M-1);
    for(int32_t i = 0; i < M - 1; i++){
        diffs[i] = X[i+1] - X[i];
    }
    std::sort(diffs.begin(), diffs.end());
    int64_t res = 0;
    for(int32_t i = 0; i < M - N; i++){
        res += diffs[i];
    }
    std::cout << res;
    return 0;

}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main()
{
    int arr[33] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;cin >> k;
    cout << arr[k - 1];
    return 0;
}


Measured memory_bytes: 3608
n,m = map(int, input().split())
xl = list(map(int, input().split()))
xl.sort()
selected = m-n
if selected <= 0:
    print(0)
    exit()

diffs = []
for x1,x2 in zip(xl[:-1],xl[1:]):
    diff = x2-x1
    diffs.append(diff)

diffs.sort()
ans = sum(diffs[:selected])
print(ans)

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

const long long INF = 1e18L + 10;

int main()
{
  int n, W;
  scanf("%d%d", &n, &W);
  vector<long long> dp(100010, INF);
  dp[0] = 0;
  int total_value = 0;
  for(int i = 0; i < n; i++)
  {
    int w, v;
    scanf("%d%d", &w, &v);
    for(int value = 100000; value >= v; value--)
    {
      dp[value] = min(dp[value], dp[value - v] + w);
    }
    total_value += v;
  }
  long long sol = 0;
  for(int i = 0; i <= total_value; i++)
  {
    if(dp[i] != INF and dp[i] <= W)
    sol = i;
  }
  cout << sol;
  
  return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> cost(N);
  vector<int> sum(N);
  for(x:cost){
    cin >> x;
  }
  sum.at(0)=0;
  sum.at(1)=abs(cost.at(1)-cost.at(0));
  for(int i=2;i<N;i++){
    sum.at(i)= min((sum.at(i-1)+abs(cost.at(i)-cost.at(i-1))),
                    (sum.at(i-2)+abs(cost.at(i)-cost.at(i-2))));
  }
  cout << sum.at(N-1)<<endl;
}


Measured memory_bytes: 1024
(n,d),*xx = [list(map(int, s.split())) for s in open(0)]

from itertools import combinations

ans = 0
for i, j in combinations(range(n),2):
    s = sum((a-b)**2 for a,b in zip(xx[i],xx[j]))
    if s == round(s**0.5)**2:
        ans += 1

print(ans)

Measured memory_bytes: 62696
fun main(args:Array<String>) {
    val hotelCount = readLine()!!.toInt()
    val hotelList = readLine()!!.split(" ").map { it.toInt() }
    var max = 0
    var ans = 0
    for(i in hotelList) {
        if(i >= max) {
            ans++
            max = i
        }
    }
    println(ans)
}



Measured memory_bytes: 38036
#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;
    ll a; cin >> a;
    cout << a + a*a + a*a*a;
    return 0;
}


Measured memory_bytes: 3648
#include<stdio.h>
#include<string.h>
#include<math.h>

 
int main(){
   int a,b,c;
   scanf("%d %d %d", &a,&b,&c);
   if(a+b+c>=22) 
     printf("bust");
   else
     printf("win");
	return 0;
 
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
static const int MAX_N = 100000;
struct edge{int from, to; ll cost;};

int N;
int x[MAX_N], y[MAX_N];

P s1[MAX_N], s2[MAX_N];
vector<edge> es;

int par[MAX_N];
int rank_[MAX_N];
void init_union_find(int n){
	for(int i = 0; i < n; i++){
		par[i] = i;
		rank_[i] = 0;
	}
}
int find(int x){
	if(par[x] == x){
		return x;
	}else{
		return par[x] = find(par[x]);
	}
}
void unite(int x, int y){
	x = find(x);
	y = find(y);
	if(x == y) return;
	if(rank_[x] < rank_[y]){
		par[x] = y;
	}else{
		par[y] = x;
		if(rank_[x] == rank_[y]) rank_[x]++;
	}
}
bool same(int x, int y){
	return find(x) == find(y);
}
bool comp(const edge& e1, const edge& e2){
	return e1.cost < e2.cost;
}

ll kruskal(){
	sort(es.begin(), es.end(), comp);
	init_union_find(N);
	ll res = 0;
	for(int i = 0; i < es.size(); i++){
		edge e = es[i];
		if(!same(e.from, e.to)){
			unite(e.from, e.to);
			res += e.cost;
		}
	}
	return res;
}

int main(){
	cin >> N;
	for(int i = 0; i < N; i++){
		cin >> x[i] >> y[i];
	}
	for(int i = 0; i < N; i++){
		s1[i].first = x[i]; s1[i].second = i;
		s2[i].first = y[i]; s2[i].second = i;
	}
	sort(s1, s1 + N);
	sort(s2, s2 + N);
	for(int i = 0; i < N - 1; i++){
		es.push_back((edge){s1[i].second, s1[i + 1].second, abs(s1[i].first - s1[i + 1].first)});
		es.push_back((edge){s1[i + 1].second, s1[i].second, abs(s1[i].first - s1[i + 1].first)});
		es.push_back((edge){s2[i].second, s2[i + 1].second, abs(s2[i].first - s2[i + 1].first)});
		es.push_back((edge){s2[i + 1].second, s2[i].second, abs(s2[i].first - s2[i + 1].first)});
	}
	cout << kruskal() << endl;
	return 0;
}


Measured memory_bytes: 12908
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1.0);

void precalc() {
}

long long x;

int read() {
  if (scanf("%lld", &x) < 1) {
    return 0;
  }
  return 1;
}

const int len = 8;
const char str[] = "FESTIVAL";

const int k = 180;

void solve() {
  string ans = str;
  --x;
  for (int iter = 0; x && iter < len; ++iter) {
    int rem = x % k;
    x /= k;
    ans += string(rem, str[len - 1]);
    if (iter < len - 1) {
      for (int i = len - 2; i >= iter; --i) {
        if (i - 1 >= iter) {
          ans += string(k - 2, str[i - 1]);
          ans += str[i];
          ans += str[i - 1];
          --i;
        } else {
          ans += string(k - 1, str[i]);
        }
      }
    }
  }
  assert(!x);
  printf("%s\n", ans.c_str());
}

int main() {
  precalc();
#ifdef LOCAL
  freopen(TASK ".out", "w", stdout);
  assert(freopen(TASK ".in", "r", stdin));
#endif

  while (1) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


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

#define ll long long

int main() {
  int h, w;

  while (true) {
    cin >> h >> w;
    if (h == 0 && w == 0) break;
    for (int i = 0; i < h; i ++) {
      for (int j = 0; j < w; j++) {
        if ((i + j) % 2 == 0) cout << "#";
        else cout << ".";
      }
      cout << "\n";
    }
    cout << "\n";
  }
  cout << flush;
    
  return 0;
}
  

Measured memory_bytes: 1112
N = int(input())
S = input()

ans = 0

for i in range(N-1):
    l1 = [0]*26
    l2 = [0]*26
    for j in S[:i+1]:
        if l1[(ord(j)-ord("a"))]==0:
            l1[(ord(j)-ord("a"))]=1
    for k in S[i+1:]:
        if l2[(ord(k)-ord("a"))]==0:
            l2[(ord(k)-ord("a"))]=1
    cnt = 0
    for i in range(26):
        if l1[i]*l2[i] == 1:
            cnt += 1
    ans = max(ans, cnt)

print(ans)

Measured memory_bytes: 9168
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
using namespace std;

// typedef
typedef long long ll;
typedef unsigned long ul;
// #define int long long

// macro
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (int i=0; i < (int)(n); i++)  // 0 ~ n-1
#define REPN(i, n) for (int i=1; i <= (int)(n); i++)  // 1 ~ n
#define DESCEND greater<int>()  // sort 降順 大きい順
#define UNIQUE(vec) (vec).erase(unique(ALL((vec))), (vec).end());  // 必ずsortを行なってから
#define MIN(vec) min_element(ALL((vec)))  // 値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(ALL((vec)), 0)  // 0 は初期値
#define COPY(vec1, vec2) copy(ALL(vec1), back_inserter(vec2))  // vec1をvec2にコピーする vec2は空にしておく必要あり
#define zero_pad(num) setfill('0') << std::right << setw(num)  // 直後の要素をパディング
#define space_pad(num) setfill(' ') << std::right << setw(num)  // 直後の要素をパディング

// func declaration
template <class T> void print2DVec(vector< vector<T> >&);
template <class T> void calcVec(vector<T>&, int, char);
int char_to_int(const char);

// const
const int INF = 10000000;

/*MEMO
・辞書順
abc < abcd, atcoder < atlas
・イテレータ
std::vector<int>::iterator とタイプするのは面倒なので、
 通常は型推論の auto を使用する。
 auto iter = max_element(ALL(vec));
・2次元配列
vector<vector<int>> vec = {{1, 2, 3}, {4, 5, 6}}
・20×10の配列
vector<vector<int>> vec(20, vector<int>(10, 0));
・(n, m)の多次元配列
vector< vector<int> > vec(n, vector<int>(m, 0))  // 0で初期化
*/

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

    // input
    string str;
    cin >> str;
    
    // calculation
    str[3] = '8';
    cout << str << "\n";
    
    return 0;
}


// function
template <class T> void print2DVec(vector< vector<T> >& vec) {
    REP(i, vec.size()) {
        REP(j, vec.front().size()) {
            cout << vec.at(i).at(j);
        }
        cout << endl;
    }
}

template <class T> void calcVec(vector<T> &vec, int num, char ch) {
    // vec全体への演算
    switch (ch) {
        case '+':
            REP(i, vec.size()) vec.at(i) += num; break;
        case '-':
            REP(i, vec.size()) vec.at(i) -= num; break;
        case '*':
            REP(i, vec.size()) vec.at(i) *= num; break;
        case '/':
            REP(i, vec.size()) vec.at(i) /= num; break;
        case '%':
            REP(i, vec.size()) vec.at(i) %= num; break;
        default:
            cout << "Incorrect Operator" << endl;
    }
}

int char_to_int(const char c) {
    if('0' <= c && c <= '9') return (c - '0');
    return -1;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int a;
    cin >> a;
    int i = 0, p = 0;
    while (p < a){
        i++;
        p += i;
    }
    string ans;
    REP(j,i) ans = ans + ')';
    REP(j,i) ans = ans + '(';
    int j = i - (p - a);
    swap(ans[i], ans[j]);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3400
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <unordered_set>
#include <set>

using namespace std;

typedef long long ll;
typedef long double ld;
const ll SIZE = 1e5 + 10;

vector<vector<ll>> vec;

#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

int main() {
    fastInp;

    string s;
    cin >> s;
    ll cnt[4];
    for (int i = 0; i < 4; i++) cnt[i] = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'E') cnt[0]++;
        if (s[i] == 'W') cnt[1]++;
        if (s[i] == 'S') cnt[2]++;
        if (s[i] == 'N') cnt[3]++;
    }

    if (((cnt[0] != 0) ^ (0 != cnt[1])) || (((cnt[2] != 0) ^ ( 0 != cnt[3])) > 0)) {
        cout << "No";
    }
    else {
        cout << "Yes";
    }
    return 0;
}

Measured memory_bytes: 256
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import qualified Data.ByteString.Char8 as BS
import           Data.Maybe            (fromJust, listToMaybe)

main :: IO ()
main = do
  [n, y] <- map readInt . BS.words <$> BS.getLine
  putStrLn . maybe "-1 -1 -1" (unwords . map show) $ solve n y

solve :: Int -> Int -> Maybe [Int]
solve n y = listToMaybe [[a, b, c]
                        | a <- [0 .. n]
                        , b <- [0 .. n - a]
                        , let c = n - a - b
                        , 10000 * a + 5000 * b + 1000 * c == y]

readInt :: BS.ByteString -> Int
readInt = fst . fromJust . BS.readInt


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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

pll A[100005];
set<pll> P[100005];

int main()
{
    ll N, M;
    cin >> N >> M;
    set<ll> s;
    REP(i, M)
    {
        cin >> A[i].first >> A[i].second;
        s.insert(A[i].first);
        P[A[i].first].insert(pll(A[i].second, i));
    }
    for (auto &x : s)
    {
        int index = 1;
        for (auto &y : P[x])
        {
            A[y.second].second = index++;
        }
    }

    REP(i, M)
    {
        cout << std::setfill('0') << std::right << std::setw(6) << A[i].first;
        cout << std::setfill('0') << std::right << std::setw(6) << A[i].second;
        cout << endl;
    }
    return 0;
}

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

int main() {
	string s;
	cin >> s;


	int ans = 0;
	int  cnt = 0;
	for (int i = 0; i < s.size(); i++) {
		if (i % 2 == 0) {
			if (s[i] != '0') cnt++;
		}
		else {
			if (s[i] != '1') cnt++;
		}
	}
	ans = cnt;

	cnt = 0;
	for (int i = 0; i < s.size(); i++) {
		if (i % 2 == 0) {
			if (s[i] != '1') cnt++;
		}
		else {
			if (s[i] != '0') cnt++;
		}
	}
	ans = min(ans, cnt);
	cout << ans;

}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ld long double
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define endl '\n'
const int mod=1e9+7,u=3e3+5;

ld dp[u][u];
signed main(){
    ios::sync_with_stdio(0);cin.tie(0);

    int n;
    cin>>n;
    ld p[n+1];
    for(int i=1;i<=n;i++){
        cin>>p[i];
    }

    dp[0][0]=1;
    for(int i=1;i<=n;i++){
        dp[i][0]=dp[i-1][0]*(1-p[i]);
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            dp[i][j]=(dp[i-1][j-1]*p[i]+dp[i-1][j]*(1-p[i]));
        }
    }

    ld ans=0;
    for(int i=n/2+1;i<=n;i++){
        ans+=dp[n][i];
    }
    cout<<fixed<<setprecision(10)<<ans;

    return 0;
}


Measured memory_bytes: 141184
// OURL: https://atcoder.jp/contests/abc091/tasks/arc092_a
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define RREP(i,a,n) for(int i=(a),i##_len=(n);i<i##_len;++i)
#define MAT1D(V,T,a) vector<T> V (a)
#define MAT2D(V,T,a,b) vector<vector<T>> V (a, vector<T>(b))
#define MAT3D(V,T,a,b,c) vector<vector<vector<T>>> V (a, vector<vector<T>>(b, vector<T>(c)))

// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){ return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}
template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){ for(auto &e:t) fill_v(e,v); }

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool>::reference b) { return to_string(bool(b)); }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A>
string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; }
template <typename A>
string to_string(vector<vector<A>> v) { string res; for(const auto &x : v) {res+="\n ";res += to_string(x);} return res;}

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); }

#ifdef LOCAL
#define debug(...) cerr << "[L" << to_string(__LINE__) << ":" <<#__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif


int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  auto red = make_v<pair<ll,ll>>(n);
  auto blue = make_v<pair<ll,ll>>(n);
  REP(i,n) {
    ll x,y;
    cin >> x >> y;
    red[i] = make_pair(x,y);
  }
  REP(i,n) {
    ll x,y;
    cin >> x >> y;
    blue[i] = make_pair(x,y);
  }
  sort(blue.begin(), blue.end(), [](const auto &x, const auto &y){
        return x.first < y.first;
      });
  auto used = make_v<bool>(n);
  int ans = 0;
  for(auto& b: blue) {
    pair<int,int> p = make_pair(INT_MIN, INT_MIN);
    int pidx = -1;
    REP(i,n) {
      auto &r = red[i];
      if (r.first < b.first && r.second < b.second && !used[i]) {
        if (r.second > p.second) {
          p = r;
          pidx = i;
        }
      }
    }
    if (pidx >= 0) {
      used[pidx] = true;
      ans++;
    }
  }

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


Measured memory_bytes: 256
import static java.util.Arrays.deepToString;

import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;
import java.util.concurrent.ArrayBlockingQueue;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	void tr(Object... os) {
		System.err.println(deepToString(os));
	}

	Scanner sc = new Scanner(System.in);
	public void run() {
		for (;sc.hasNext();) {
			solve();
		}
	}
	
	
	int[] dr = {0, 1, 0, -1, 0, 1};
	int[] dc = {1, 0, -1, 0, 1, 0};
	int[][] t;
	int R, C;
	boolean can(int r, int c) {
		return 0 <= r && r < R && 0 <= c && c < C && t[r][c] == 0;
	}
	int[][][][] memo = new int[50][50][50][50];
	void solve() {
		C = sc.nextInt();
		R = sc.nextInt();
		if (R == 0 && C == 0) return;
		int c1 = sc.nextInt()-1;
		int r1 = sc.nextInt()-1;
		int c2 = sc.nextInt()-1;
		int r2 = sc.nextInt()-1;
		t = new int[R][C];
		for (int i = 0; i < R; i++) for (int j = 0; j < C; j++) t[i][j] = sc.nextInt();
		for (int i = 0; i < R; i++) for (int j = 0; j < C; j++)
			for (int ii = 0; ii < R; ii++) for (int jj = 0; jj < C; jj++)
				memo[i][j][ii][jj] = 99999999;
		Queue<Integer> q = new ArrayDeque<Integer>();
		q.add(e(r1, c1, r2, c2));
		memo[r1][c1][r2][c2] = 0;
		int ans = -1;
		while (!q.isEmpty()) {
			int k = q.poll();
			c2 = k % 50; k /= 50;
			r2 = k % 50; k /= 50;
			c1 = k % 50; k /= 50;
			r1 = k % 50; k /= 50;
			int d = memo[r1][c1][r2][c2];
			if (d > 100) break;
			if (r1 == r2 && c1 == c2) {
				ans = d;
				break;
			}
			for (int i = 0; i < 4; i++) {
				int nr1 = r1 + dr[i];
				int nc1 = c1 + dc[i];
				int nr2 = r2 + dr[i+2];
				int nc2 = c2 + dc[i+2];
				if (!can(nr1, nc1)) { nr1 = r1; nc1 = c1; }
				if (!can(nr2, nc2)) { nr2 = r2; nc2 = c2; }
				if (memo[nr1][nc1][nr2][nc2] > d + 1) {
					memo[nr1][nc1][nr2][nc2] = d + 1;
					q.add(e(nr1, nc1, nr2, nc2));
				}
			}
		}
		if (ans == -1) System.out.println("NA"); 
		else System.out.println(ans);
		
	}
	int e(int a, int b, int c, int d) {
		int k = 0;
		k = k * 50 + a;
		k = k * 50 + b;
		k = k * 50 + c;
		k = k * 50 + d;
		return k;
	}
}

Measured memory_bytes: 96776
import scala.io.StdIn.readLine

object Main extends App {
  val Array(a, b) = readLine().split(' ').map(_.toInt)
  
  val result = (a to b).filter { n =>
    val s = n % 10
    val t = n / 10000 % 10
    val u = n / 10 % 10
    val v = n / 1000 % 10
    s == t && u == v
  }.length
  
  println(result)
}

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

using namespace std;
const int N = 110;
int _w;

int n, a[N], c[N], v1[N], v2[N];

int main() {
	cin >> n;
	for( int i = 1; i <= n; ++i ) {
		cin >> a[i];
		++c[a[i]];
	}
	int diam;
	for( int i = n; i >= 1; --i )
		if( c[i] ) {
			diam = i;
			break;
		}
	if( c[diam] == 1 ) return puts("Impossible"), 0;
	c[diam] -= 2;
	for( int i = 1, j = diam-1; j; ++i, --j ) {
		int x = max(i, j);
		++v1[x], v2[x+1] = 1;
	}
	for( int i = 1; i <= n; ++i )
		while( c[i] ) {
			if( v1[i] ) --v1[i];
			else if( v2[i] );
			else return puts("Impossible"), 0;
			--c[i];
		}
	for( int i = 1; i <= n; ++i )
		if( v1[i] ) return puts("Impossible"), 0;
	return puts("Possible"), 0;
}


Measured memory_bytes: 764
N = int(input())
A = [int(x) for x in input().split()]

def BubbleSort(A):
    N = len(A)
    count = 0
    flag = 1
    i = 0
    while flag:
        flag = 0
        for j in reversed(range(i+1,N)):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                count += 1
                flag = 1
        i += 1
    for k in range(N-1):
        print(A[k], end=" ")
    print(A[N-1])
    print(count)

BubbleSort(A)



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

using namespace std;

int main()
{
	string s;
	cin >> s;
	int n = s.size();
	bool flag=true;
	for (int i = 0; i < (n-1)/2; i++) {
		if (s[i] != s[n - 1 - i]) {
			flag = false;
		}
	}

	for (int i = 0; i < (n - 1) / 4; i++) {
		if (s[i] != s[(n - 1) / 2 - 1 - i]) {
			flag = false;
		}
	}
	for (int i = 0; i < (n - 1) / 4; i++) {
		if (s[(n - 1) / 2 + 1 + i] != s[n - 1 - i]) {
			flag = false;
		}
	}
	if (flag == true) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
H,W = map(int,input().split())
t = []
for i in range(H):
    x = list(input())
    if "#" in x:
        t.append(x)
for i in range(W):
    if all((t[j][i] == "." for j in range(len(t)))):
        for k in range(len(t)):
            t[k][i] = ""
for i in range(len(t)):
    print("".join(t[i]))

Measured memory_bytes: 3064