akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define pb push_back
#define int long long
#define mp make_pair
#define inf 1000000007
#define ll long long
using namespace std;
ll sma[101][32000],lar[101][32000];
signed main(){
	int n,k;
	cin>>n>>k;
	int s=0;
	for(int i=1;i<=32000;i++){
		if( i*i <= n)s=i;
	}
	sma[0][1] = 1;
	for(int i=2;i<=s;i++){
		sma[0][i] = sma[0][i-1];
	}
	for(int i=1;i<=k;i++){
		for(int j=1;j<=s;j++){
			sma[i][j] = sma[i-1][s] + lar[i-1][j];
			sma[i][j] %= inf;
		}
		for(int j=s;j>=1;j--){
			lar[i][j] = sma[i-1][j]*(min(n/j-n/(j+1), n/j-s));
			lar[i][j] %= inf;
		}
		for(int j=1;j<=s;j++){
			sma[i][j] += sma[i][j-1];
			sma[i][j] %= inf;
		}
		for(int j=s;j>=1;j--){
			lar[i][j] += lar[i][j+1];
			lar[i][j] %= inf;
		}
	}
	cout<<(sma[k][s]+lar[k][1])%inf<<endl;
	return 0;
}

Measured memory_bytes: 50432
#include <iostream>
#include <algorithm>
#include <cstdlib>
using namespace std;

#define MAX 100000
typedef pair<char, int> paCard;
paCard A[MAX], B[MAX];


int Partition(int nLeft, int nRight)
{
	int x = A[nRight].second;
	int nIndex = nLeft - 1;
	for (int i = nLeft; i < nRight; i++) // here it is nRight 
	{
		if (A[i].second <= x)
		{
			++nIndex;
			swap(A[i], A[nIndex]);
		}
	}
	nIndex++;
	swap(A[nIndex], A[nRight]);
	return nIndex;
}


void quick_sort(int nLeft, int nRight)
{
	int nMid = 0;
	if (nLeft < nRight)
	{
		nMid = Partition(nLeft, nRight);
		quick_sort(nLeft, nMid - 1);
		quick_sort(nMid + 1, nRight);
	}
}


int main()
{
	int nIn;
	cin >> nIn;
	for (int i = 0; i < nIn; ++i)
	{
		cin >> A[i].first >> A[i].second;
		B[i] = A[i];
	}
	stable_sort(B, B + nIn, [](const paCard& A, const paCard& B) { return A.second < B.second; });
	quick_sort(0, nIn - 1);
	bool bFlag = true;
	for (int i = 0; i < nIn; ++i)
	{
		if (A[i] != B[i])
		{
			bFlag = false;
			break;
		}
	}
	cout << (bFlag ? "Stable" : "Not stable") << endl;
	for_each(A, A + nIn, [](const paCard& A) { cout << A.first << " " << A.second << endl; });
	return 0;

}


Measured memory_bytes: 5108
/*
    Solution by Abil
*/

#include <bits/stdc++.h>

#define fr first
#define sc second
#define pb push_back
#define mk make_pair
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define int long long

using namespace std;

const long long N = (1e6 + 12);
const long long mod = (1e9 + 7);
const long long inf = (1e9 + 123);

int dp[N], arr[N], pr[N];
main(){
    int n;
    cin >> n;
    for(int i = 1;i <= n; i++){
        cin >> arr[i];
    }

    dp[1] = 0;
    dp[2] = abs(arr[2] - arr[1]);
    pr[2] = 1;
    for(int i = 3;i <= n; i++){
       dp[i] = min((abs(arr[i - 1] - arr[i]) + dp[i - 1]),(abs(arr[i - 2] - arr[i]) + dp[i - 2]));
    }
    cout << dp[n];
}


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

using namespace std;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i=0;i<n;i++) cin >> a[i];
    vector<ll> sum(n,0);
    sum[0]=a[0];
    for(int i=1;i<n;i++) sum[i]=sum[i-1]+a[i];
    auto s=[&](int l,int r)->ll
    {
        ll res=sum[r];
        if(l>0) res-=sum[l-1];
        return res;
    };
    vector<vector<ll>> dp(n,vector<ll>(n,(1ll<<60)));
    for(int i=0;i<n;i++) dp[i][i]=0;
    for(int i=2;i<=n;i++)
    {
        for(int l=0;l+i-1<n;l++)
        {
            int r=l+i-1;
            for(int j=l;j<r;j++) dp[l][r]=min(dp[l][r],dp[l][j]+s(l,r)+dp[j+1][r]);
        }
    }
    cout << dp[0][n-1] << "\n";
    return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int l[100100];
    int N;
    cin >> N;
    int i = 1;
    while(N --)
    {
        cin >> l[i];
        i ++;
    }
    int m;
    cin >> m;
    while(m --)
    {
        int p, x;
        cin >> p >> x;
        int c;
        c = l[p];
        l[p] = x;
        int sum = 0;
        for(int j = 1; j < i; j ++)
        {
            sum += l[j];
        }
        cout << sum <<endl;
        l[p] = c;
    }
    return 0;
}

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

const int maxn = 100010;

int n;
int a[maxn];
long long s[maxn];

int main() {
	scanf("%d", &n);
	for(int i = 0; i < n; ++i) scanf("%d", &a[i]);
	sort(a, a + n);
	long long sum = 0;
	int k = 0;
	for(int i = 0; i < n; ++i) {
		sum += a[i]; k = i;
		s[i] = sum;
		if(sum * 2 >= a[n-1]) break;
	}
	while(k > 0 && s[k-1] * 2 >= a[k]) k--;
	printf("%d\n", n - k);
	return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL mod=1000000007;


int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,A;
    cin >> N >> A;

    int mod = N % 500;

    if ( mod <= A ) cout << "Yes" << endl;

    if ( mod > A) cout << "No" << endl;


    return 0;

}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
using namespace std;

int main(void){
	int N,K;
	int sum=0;
	int a[55]={0};
	scanf("%d %d",&N,&K);
	for(int i=0;i<N;i++){
		scanf("%d",&a[i]);
	}
	sort(a,a+N);
	for(int i=N-1;i>N-1-K;i--){
		sum += a[i];
	}
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<math.h>
//#include<vector>
//#include <iostream>
//#include <algorithm>
#include <limits>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
vector<vector<int>> G;
int max(int a,int b){
	if(a>b){
		return a;

	}else{
		return b;
	}
}
/*void printdp(int N,ll Vmax){
	rep(i,N+1){
		for(ll j=0;j<Vmax+1;j++){
			if(dp[i][j]==llMAX)continue;
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}
	cout << endl;
	return;
}*/
int rec(int v,int *dp){
	if(dp[v] != -1){
		return dp[v];
	}
	int res = 0;
	for(auto to :G[v]){
		//cout << dp << endl;
		res = max(res,rec(to,dp)+1);
	}
	dp[v] = res;
	return res;
}
int main(void){
	int N;
	int m=0;
	int M;
	int i,k;
	int j;
	int x,y;
	cin >> N>>M;
	int dp[N];
	G=vector<vector<int>>(N,vector<int>());
	rep(i,N)dp[i]=-1;
	rep(i,M){
		cin >> x >> y;
		x--;
		y--;
		G[x].push_back(y);
	}
	int ans = 0;
	for(i=0;i<N;i++){
		ans=max(ans,rec(i,dp));
	}
	cout << ans;
	return 0;
}

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

#define ll long long
#define ar array

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	int arr[n];
	int ans=0;
	for(int i=0;i<n;i++)
        cin>>arr[i];
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            for(int k=j+1;k<n;k++)
            {
                if(arr[i]!=arr[j] && arr[j]!=arr[k] && arr[k]!=arr[i])
                {
                    int a=arr[i],b=arr[j],c=arr[k];
                    int p[3];p[0]=a;p[1]=b;p[2]=c;sort(p,p+3);
                    if(p[0]+p[1]>p[2])
                        ans++;
                }
            }
        }
    }
    cout<<ans;
}


Measured memory_bytes: 3652
from bisect import bisect_left

N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort()
B.sort()
C.sort()

B2 = [0 for i in range(N)]
for i,b in enumerate(B):
	idx = bisect_left(C,b+1)
	B2[i] = N - idx

B2sum = [0 for i in range(N+1)]
for i in range(N)[::-1]:
	B2sum[i] = B2sum[i+1] + B2[i]


ans = 0
for a in A:
	idx = bisect_left(B,a+1)
	ans += B2sum[idx]

print(ans)


Measured memory_bytes: 24780
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mp make_pair
#define fi first
#define se second
const int N=100005;
set<pair<int ,int> >s;
int n,e,t,x[N],f[N],dp[N],d[N];
signed main(){
	scanf("%lld%lld%lld",&n,&e,&t);
	for (int i=1;i<=n;i++)scanf("%lld",&x[i]);
	e-=x[n];x[n+1]=e;
	for (int i=n;i;i--)x[i]-=x[i-1];
	for (int i=1;i<=n;i++)f[i]=f[i-1]+x[i];
	int l=0,r=-1,k=0;
	s.insert(mp(0,0));
	for (int i=1;i<=n;i++){
		while (k<i&&(f[i]-f[k+1])*2>t){
			s.erase(mp(x[k+1]-f[k+1]+dp[k],k));
			while (l<=r&&-3*f[k+1]+x[k+1]+dp[k]<=-3*f[d[r]+1]+x[d[r]+1]+dp[d[r]])r--;
			d[++r]=k;
			k++;
		}
		pair<int ,int > now=*s.begin();
		dp[i]=t+now.fi+f[i];
		if (l<=r)dp[i]=min(dp[i],f[i]*3-3*f[d[l]+1]+x[d[l]+1]+dp[d[l]]);
		s.insert(mp(x[i+1]-f[i+1]+dp[i],i));
	}
	printf("%lld\n",dp[n]+e);
}

Measured memory_bytes: 5248
import sys
input = sys.stdin.buffer.readline
from heapq import heappush, heappop

N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]

AB.sort()

h = []
index = 0
answer = 0
for i in range(1, M + 1):
  while index < N:
    a, b = AB[index]
    if a == i:
      heappush(h, -b)
      index += 1
    else:
      break
  if h:
    answer += - heappop(h)
    
print(answer)

Measured memory_bytes: 31656
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

void maxAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) max(dst, src);
}

void main()
{
    char[] s = sread().to!(char[]);
    s[5] = s[13] = ' ';
    s.writeln();
}


Measured memory_bytes: 256
until (n = $<.gets.to_i).zero?
  square = Array.new(n) {[0] * n}
  
  set = ->(i, x, y) {
    return if i > n * n
    if x < 0
      set.(i, n - 1, y)
    elsif x >= n
      set.(i, 0, y)
    elsif y >= n
      set.(i, x, 0)
    elsif square[y][x].nonzero?
      set.(i, x - 1, y + 1)
    else
      square[y][x] = i
      set.(i + 1, x + 1, y + 1)
    end
  }
  set.(1, n / 2, n / 2 + 1)
  
  square.each do |l|
    puts l.map {|x| sprintf("%4d", x)}.join
  end
end


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

using namespace std;

#define MAX 501
typedef pair<int,int> pii;

int N,T,L,B;
int arr[MAX];

double solve(){
  double dp[MAX][MAX]; //dp[ターン数][どのマスにいるか]
  memset(dp,0,sizeof(dp));
  dp[0][0] = 1;
  for(int i = 1 ; i <= T ; i++){
    for(int j = 0 ; j < N ; j++){
      for(int k = 0 ; k < 6 ; k++){
        if(dp[i-1][j] == 0) continue;
        int next = j+(k+1);
        if(next > N){
          next = next - 2*(next-N);
        }
        switch(arr[next]){
        case 0:
          dp[i][next] += dp[i-1][j]/6;
          break;
        case 1:
          dp[i+1][next] += dp[i-1][j]/6;
          break;
        case 2:
          dp[i][0] += dp[i-1][j]/6;
          break;
        }
      }
    }
  }
  double res = 0;
  for(int i = 1 ; i <= T ; i++){
    res += dp[i][N];
  }
  return res;
}

int main(){
  int in;
  while(cin >> N >> T >> L >> B, N){
    memset(arr,0,sizeof(arr));
    for(int i = 0 ; i < L ; i++){
      cin >> in;
      arr[in] = 1;
    }
    for(int i = 0 ; i < B ; i++){
      cin >> in;
      arr[in] = 2;
    }
    printf("%.8f\n",solve());
  }
  return 0;
}

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

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

//constexpr ll mod = 998244353;
constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, m; cin >> n >> m;
  int s = 1<<n;

  vector<int> sw[11];
  vector<bool> rem(m);

  rep(i, m) {
    int k; cin >> k;
    rep(j, k) {
      int s; cin >> s;
      sw[s-1].push_back(i);
    }
  }

  rep(i, m) {
    int p; cin >> p;
    if (p) rem[i] = true;
  }

  int ans = 0;
  rep(i, s) {
    vector<bool> light(m);
    for(int k=0; k<n; k++) {
      if (i&(1<<k)) {
        for(auto e: sw[k]) {
          light[e] = !light[e];
        }
      }
    }
    if (rem == light) {
      ans++;
    }
  }
  cout << ans << endl;
}

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

int main() {
    long long int N;
    cin >> N;

    if (N > 11LL) {
        long long int c = (double)N / 11.;
        long long int d = N % 11;
        if (d==0) cout << c * 2 << endl;
        else if (d > 6) cout << c * 2 + 2 << endl;
        else  cout << c * 2 + 1 << endl;
    } else if (N > 6LL) {
        cout << 2 << endl;
    } else if (N > 0LL){
        cout << 1 << endl;
    } else {
        cout << 0 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<set>
#include<cmath>
#include<queue>
#include<unordered_map>
#include<map>
#include<stack>
#include<bits/stdc++.h>
#include<string.h>
#include <ext/pb_ds/assoc_container.hpp>
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
//#define f first
//#define s second
#define respr(fir,sec) for(int i=0;i<=fir;i++){for(int j=0;j<=sec;j++){cout << res[i][j] << " ";}cout << "\n";}
#define pb push_back
//#define INF (1LL<<31)
using namespace std;
using namespace __gnu_pbds;
const int mod = 1e9+7;
const ll MAX = 1000000000000000000;
const ll INF = 1000000000000000000;
typedef pair<int,ll> pii;
typedef pair<ll,int> pi;
typedef tuple<long long,int> tp;
typedef tuple<int,int,long long> tu;
typedef multimap<pii , int> mpp;
typedef priority_queue< tp , vector<tp>, greater<tp>>  minheap;
typedef priority_queue<pii , vector<pii>> maxheap;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>  new_data_set;
const int nax=105;
//const int nax1 = 105;


int main()
{
	FASTIO;
	int n,w;
	cin >> n >> w;
	vector<vector<ll>> dp(n+1,vector<ll>(w+1));
	vector<int> weight(n);
	vector<int> value(n);
	for(int i=0;i<n;i++){
		cin >> weight[i] >> value[i];
	}
	
	int w1,v1;
	for(int item=1;item<=n;item++){
		w1 = weight[item-1];
		v1 = value[item-1];
		
		for(int i=1;i<=w;i++){
			
			if(w1>i){
				dp[item][i] = max(dp[item-1][i], dp[item][i-1]);
			}
			else{
				dp[item][i] = max(v1+dp[item-1][i-w1], max(dp[item-1][i], dp[item][i-1]));
			}
		}
	}

	
	cout << dp[n][w] << "\n";
	return 0;
}


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

int main()
{
    vector <int>alph(26,0);
    string str;
    while(getline(cin,str))
    {
        REP(i,str.size())
        {
        if(str.at(i)>='a'&&str.at(i)<='z')alph.at(str.at(i)-'a')++;
        else if(str.at(i)>='A'&&str.at(i)<='Z')alph.at(str.at(i)-'A')++;
        }
    }
    REP(i,alph.size())
    {
        char a='a'+i;
        cout<<a<<" : "<<alph.at(i)<<endl;
    }
}


Measured memory_bytes: 3144
let prim a n =
  let d = Array.make n max_int in
  d.(0) <- 0;
  let b = Array.make n false in
  let z = Array.make n (-1) in
  let rec doit () =
    let (_, _, u) =
      Array.fold_left (fun (i, m, u) e ->
        let (m, u) = if b.(i) = false && m > e then (e, i) else (m, u) in
        (i + 1, m, u))
        (0, max_int, (-1)) d in
    if u = (-1) then ()
    else begin
      b.(u) <- true;
      for i = 0 to n - 1 do
        if b.(i) = true || a.(u).(i) = max_int || d.(i) <= a.(u).(i) then ()
        else begin
          d.(i) <- a.(u).(i);
          z.(i) <- u;
        end
      done;
      doit ()
    end in
  doit ();
  Array.fold_left (fun (i, sum) e ->
    (i + 1, sum + if e = (-1) then 0 else a.(i).(e)))
    (0, 0) z
  |> snd

let () =
  let n = read_int () in
  let a = Array.make_matrix n n max_int in
  for i = 0 to n - 1 do
    for j = 0 to n - 1 do
      let x = Scanf.scanf " %d" (fun x -> x) in
      if x <> (-1) then a.(i).(j) <- x;
    done
  done;
  prim a n |> Printf.printf "%d\n"

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

using namespace std;

struct group {
    long long int length = 0;
    char sign;
};

int main() {
    long long int N, K;
    string S;

    cin >> N >> K;
    cin >> S;

    vector<group> groups;
    char sign = S[0];
    long long int length = 0;

    if(sign == '0')
        groups.push_back({0, '1'});
    else
        groups.push_back({0, '0'});

    for(auto c : S) {
        if(sign == c) {
            length++;
        } else {
            groups.push_back({length, sign});
            sign = c;
            length = 1;
        }
    }
    groups.push_back({length, sign});

    if(sign == '0')
        groups.push_back({0, '1'});
    else
        groups.push_back({0, '0'});

    long long int max_length = 0;
    for(auto& g : groups) {
        if(g.sign == '0')
            continue;
        max_length = max(max_length, g.length);
    }

    for(long long int i=0; i<max((unsigned long long int)0, groups.size()-2*K); i++) {
        if(groups[i].sign == '0')
            continue;

        long long int total_length = 0;
        for(long long int j=i; j<min((long long int)groups.size(), 2*K+1+i); j++)
            total_length += groups[j].length;

        if(max_length == S.length())
            break;

        max_length = max(max_length, total_length);
    }

    cout << max_length << endl;

    return 0;
}

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

using namespace std;

int main() {
	long long a, b, c;
	cin >> a >> b >> c;
	if(c - a - b < 0ll) {
		puts("No");
		return 0;
	}
	if(4ll * a * b < (c - a - b) * (c - a - b)) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;                                                                     
class Main {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int a = in.nextInt();

        int max = a;
        int min = a;
        long sum = a;
        for(int i = 1; i < n; i++){
            a = in.nextInt();
            if(a < min){
                min = a;
            }
            if(a > max){
                max = a;
            }
            sum += a;

        }
        System.out.println(min + " " + max + " " + sum);
    }
}

Measured memory_bytes: 41656
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<iomanip>
#include<math.h>
#include<bitset>
#include<cassert>
#include<random>
#include<time.h>
#include<functional>
using namespace std;
using ll=long long;
using ld=long double;
using pint=pair<int,int>;
using pll=pair<ll,ll>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

int n, m;
vector<int> c;
vector<int> ans;

void solve(int parity) {
	vector<int> cnt1(m, 0);
	vector<int> cnt2(n + 1, 0);
	int maxi = -1;
	vector<vector<ll>> p(m);
	REP(i, n) {
		cnt1[c[i]]++;
		p[c[i]].pb(c[i]);
	}
	REP(i, m) {
		cnt2[cnt1[i]]++;
		maxi = max(maxi, cnt1[i]);
	}
	for(int i = parity; i < n - 1; i += 2) {
		if(c[i] == c[i + 1]) continue;
		p[c[i]].pb(c[i + 1]);
		p[c[i + 1]].pb(c[i]);
	}
	REP(i, m) {
		int tmp1 = n - cnt1[i];
		REP(j, p[i].size()) {
			cnt2[cnt1[p[i][j]]]--;
			cnt2[cnt1[p[i][j]] - 1]++;
			cnt1[p[i][j]]--;
		}
		int tmp2 = maxi;
		while(cnt2[tmp2] == 0) tmp2--;
		ans[i] = min(ans[i], tmp1 - tmp2);
		REP(j, p[i].size()) {
			cnt2[cnt1[p[i][j]]]--;
			cnt2[cnt1[p[i][j]] + 1]++;
			cnt1[p[i][j]]++;
		}
	}
	return;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> m;
	c.resize(n); ans.assign(m, INF);
	REP(i, n) cin >> c[i]; REP(i, n) c[i]--;
	solve(0); solve(1);
	REP(i, m) cout << ans[i] << endl;
	return 0;
}

/* --------------------------------------- */



Measured memory_bytes: 73096
brank = '.'
while 1:
	H, W = map(int, raw_input().split())
	if H == 0 and W == 0:
		break
	for h in xrange(H):
		if (h == 0) or (h == H - 1):
			print '#' * W
		else:
			print ('#' + brank * (W - 2) + '#')
	print

Measured memory_bytes: 4204
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll N=1e5+5;
ll n,ans,a[N],prfx[N];
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cin>>n;
    for(ll i=1;i<=n;i++)cin>>a[i];
    sort(a+1,a+n+1);
    for(ll i=1;i<=n;i++)prfx[i]=prfx[i-1]+a[i];
    for(ll i=n;i>=1;i--){
        if(prfx[i]*2 < a[i+1])break;
        ans++;
    }
    cout<<ans;

}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919810364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int n, a[10010];
int cnt[1000010];
int ans;

signed main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		int k = a[i];
		for (int j = 2; j <= sqrt(a[i]); j++) {
			int cnt2 = 0;
			while (k % j == 0) {
				k /= j;
				cnt2++;
			}
			cnt[j] = max(cnt[j], cnt2);
		}
		if (k > 1)cnt[k] = max(cnt[k], (int)1);
	}
	int k = 1;
	for (int i = 2; i <= 1000010; i++)if (cnt[i])k = (k * mod_pow(i, cnt[i], mod)) % mod;
	for (int i = 0; i < n; i++) {
		ans = (ans + k * mod_pow(a[i], mod - 2, mod) % mod) % mod;
	}
	cout << ans << endl;
}

Measured memory_bytes: 6656
let S = stdin.ReadLine()
let T = stdin.ReadLine()

let mutable result = 0

for i in [ 0..S.Length - T.Length ] do
    let mutable count = 0
    for j in [ 0..T.Length - 1 ] do
        if S.[i + j] = T.[j] then count <- count + 1
    if count > result then result <- count

T.Length - result |> stdout.WriteLine


Measured memory_bytes: 35880
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
using namespace std;
using vint = vector<int>;
using ll = long long;
using vll = vector<ll>;
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

int main() {
    int N, Y; cin >> N >> Y;
    const int Yd = Y / 1000;
    int x, y = 0, z = -1;
    for(x = 0; x <= 2000; x++) {
        int y4 = Yd - N - (9 * x);
        if(y4 < 0) continue;
        if(y4 % 4 != 0) continue;
        y = y4 / 4;
        z = N - x - y;
        if(z >= 0) break;
    }
    if(z < 0) {
        cout << "-1 -1 -1" << endl;
    } else {
        cout << x << " " << y << " " << z << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws Exception{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(br.readLine());
    String[] data = br.readLine().split(" ");
    long[] a = new long[n];
    for(int i = 0; i < n; i++){
      a[i] = Long.parseLong(data[i]);
    }
    long answer = 0;
    long max = a[0];
    for(int i = 1; i < n; i++){
      max = Math.max(max, a[i]);
      answer += Math.abs(max - a[i]);
    }
    System.out.println(answer);
  }
}

Measured memory_bytes: 62344
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>>vvi;

int main(){
  string s;
  cin>>s;
  bool ans=false;
  if(s=="hi")ans=true;
  if(s=="hihi")ans=true;
  if(s=="hihihi")ans=true;
  if(s=="hihihihi")ans=true;
  if(s=="hihihihihi")ans=true;
  if(ans)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
using ll = long long;

typedef long long ll;
#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++)
#define INF 999999999


int main(){
  string s;
  cin >> s;
  if(s=="Sunny")cout << "Cloudy";
  else if(s=="Cloudy")cout <<"Rainy";
  else if(s=="Rainy")cout << "Sunny";
}


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


#include "boost/multiprecision/cpp_int.hpp"
#include "boost/multiprecision/cpp_dec_float.hpp"
namespace mp = boost::multiprecision;
typedef mp::cpp_int LL;
typedef mp::number<mp::cpp_dec_float<1024>> DD;// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)

 
typedef long double dd;
//#define i_7 (ll)(1E9+7)
#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define rrep(i,r,l) for(ll i=r;i>=l;i--)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"  //インタラクティブで消す！！！！！！！！！！！！！！！！！！！！！
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
template<class T,class S>
inline bool chmax(T &a, S b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T,class S>
inline bool chmin(T &a, S b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

void mod_print(ll k){
    ll P=1000;
    rep(y,1,P){
        ll x=mod(y*k);
        if(x+P>=i_7){
            x-=i_7;
        }
        if(abs(x)<=P){
            //cout<<x<<"/"<<y;
            cout<<setprecision(5)<<(dd)x/(dd)y;
            return;
        }
    }
    cout<<"nun"<<endl;
}
#define all(c) c.begin(),c.end()
//////////////////////////


int main(){fastio
    ll n,k;cin>>n>>k;
    vector<ll>v(n);
    rep(i,0,n-1)cin>>v[i];
    SORT(v);
    ll ans=0;
    rep(i,0,k-1)ans+=v[i];
    cout<<ans;
    
    return 0;
}






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

using namespace std;

int main()
{

    long long int x;
    cin >> x;
    long long int ans = 0;
    // cout << S << endl;

    ans += (x / 500) * 1000;
    x %= 500;
    ans += (x / 5) * 5;

    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.math.*;
public class Main{

	public static void main(String args[]){
		FastReader sc = new FastReader();
		int n;
		n=sc.nextInt();
		out.println(n*n*n);
		out.flush();
	}

	static PrintWriter out;
	static class FastReader{
		BufferedReader br;
		StringTokenizer st;
		public FastReader(){
			br=new BufferedReader(new InputStreamReader(System.in));
			out=new PrintWriter(System.out);
		}
		String next(){
			while(st==null || !st.hasMoreElements()){
				try{
					st= new StringTokenizer(br.readLine());
				}
				catch (IOException e){
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}
		int nextInt(){
			return Integer.parseInt(next());
		}
		long nextLong(){
			return Long.parseLong(next());
		}
		double nextDouble(){
			return Double.parseDouble(next());
		}
		String nextLine(){
			String str = "";
			try{
				str=br.readLine();
			}
			catch(IOException e){
				e.printStackTrace();
			}
			return str;
		}
	}

	static class pair{
		int first,second;
		pair(int f,int s){
			first=f;
			second=s;
		}
	}

	public static long fastexpo(long x, long y, long p){
		long res=1;
		while(y > 0){
			if((y & 1)==1)
				res= ((res%p)*(x%p))%p;
			y= y >> 1;			
			x = ((x%p)*(x%p))%p;
		}
		return res;
	}

	public static boolean[] sieve (int n) {
		boolean primes[]=new boolean[n+1];
		Arrays.fill(primes,true);
		primes[0]=primes[1]=false;
		for(int i=2;i*i<=n;i++){
			if(primes[i]){
				for(int j=i*i;j<=n;j+=i)
					primes[j]=false;
			}
		}
		return primes;
	}

	public static long gcd(long a,long b){
        return (BigInteger.valueOf(a).gcd(BigInteger.valueOf(b))).longValue();
    }

    public static void merge(int a[],int l,int m,int r){
        int n1,n2,i,j,k;
        n1=m-l+1;
        n2=r-m;

        int L[]=new int[n1];
        int R[]=new int[n2];

        for(i=0;i<n1;i++)
            L[i]=a[l+i];
        for(j=0;j<n2;j++)
            R[j]=a[m+1+j];

        i=0;j=0;

        k=l;
        while(i<n1&&j<n2){
            if(L[i]<=R[j]){
                a[k]=L[i];
                i++;
            }
            else{
                a[k]=R[j];
                j++;
            }
            k++;
        }

        while(i<n1){
            a[k]=L[i];
            i++;
            k++;
        }
        while(j<n2){
            a[k]=R[j];
            j++;
            k++;
        }
    }
    public static void sort(int a[],int l,int r){
        int m;
        if(l<r){
            m=(l+r)/2;
            sort(a,l,m);
            sort(a,m+1,r);
            merge(a,l,m,r);
        }
    }
}



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

struct rooted_tree{
    vector<int> parent;
    vector<vector<int> > children;
    vector<int> depth;
    vector<vector<int> > dbl;
    int root;
    int n, logn;
    
    rooted_tree(int n, int r = 0):n(n){
        parent.resize(n);
        children.resize(n);
        depth = vector<int>(n, 0);
        dbl = vector<vector<int> >(n, vector<int>(log2(n)+2, -1));
        root = r;
        logn = log2(n)+2;
    }
    
    void makeDepthTable(int v = 0){
        for(auto i : children[v]){
            depth[i] = depth[v] +1;
            makeDepthTable(i);
        }
    }
    
    void makeDoublingTable(){
        for(int i=0; i<n; i++){
            dbl[i][0] = parent[i];
        }
        for(int i=0; i+1<logn; i++){
            for(int j=0; j<n; j++){
                if(dbl[j][i] != -1){
                    dbl[j][i+1] = dbl[dbl[j][i]][i];
                }
            }
        }
    }
    
    int lca(int a, int b){
        if(depth[a] < depth[b]) swap(a,b);
        while(depth[a] != depth[b]){
            for(int i=0, sqi=2; i<logn; i++, sqi*=2){
                if(depth[a] -sqi < depth[b]){
                    a = dbl[a][i];
                    break;
                }
            }
        }
        if(a==b) return a;
        for(int i=logn-1; i>=0; i--){
            if(dbl[a][i] != dbl[b][i]){
                return lca(dbl[a][i], dbl[b][i]);
            }
        }
        return lca(dbl[a][0], dbl[b][0]);;
    }
};

int main(){
    int n;
    cin >> n;
    rooted_tree t(n);
    for(int i=1; i<n; i++){
        int p;
        cin >> p;
        p--;
        t.parent[i] = p;
        t.children[p].push_back(i);
    }
    t.makeDepthTable();
    t.makeDoublingTable();

    queue<int> wait;
    wait.push(0);
    int prev = 0;
    long long int ans = 0;
    while(!wait.empty()){
        int curr = wait.front();
        wait.pop();
        ans += t.depth[prev] +t.depth[curr] -2*t.depth[t.lca(prev, curr)];
        for(int i=0; i<(int)t.children[curr].size(); i++){
            wait.push(t.children[curr][i]);
        }
        prev = curr;
    }
    cout << ans << endl;
    return 0;
}



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

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b, a % b);
}

ll lcm(ll a, ll b){
  return a/gcd(a,b) * b;
}
ll func2(ll n){
  ll res = 0;
  while(n%2 == 0){
    n /= 2;
    res++;
  }
  return res;
}

ll zyou(ll a,ll b){//a＾b
  ll res = 1;
  for(int i = 1;i<=b;i++){
    res *= a;
  }
  return res;
}
using Graph = vector<vector<char>>;

ll calc(ll a, ll b, ll p){//aのb乗をpで割った余り
  if(b == 0) return 1;

  else if(b%2 == 0){
    ll d = calc(a,b/2,p);
    return (d*d)%p;
  }
  else if(b%2 == 1){
    return (a * calc(a,b-1,p))%p;
  }
}

typedef pair<int,int> P;

bool is_prime(int n){//nが素数であるかどうか判定 iで割り切れると素数でない
    if(n == 1) return false;//1は例外
    for(int i = 2;i*i <= n;i++){
        if(n%i == 0) return false;
    }
    
    return true;
}
int factorial(int a){
  int res = 1;
  while(a){
    res *= a;
    a--;
  }
  return res;
}

int main(){
  ll N,M;
  cin >> N >> M;
  vector<ll> a(N);
  rep(i,N){
    cin >> a[i];
  }
  rep(i,N){
    a[i] /= 2;
  }
  
  ll t = func2(a[0]);//a[0]が2で何回割り切れるか
  rep(i,N){
    if(func2(a[i]) != t){
      cout << 0 << endl;
      return 0;
    }
    else a[i] /= zyou(2,t);
  }
  M /= zyou(2,t);
  //a[i]''のlcmを求める
  ll l = 1;
  rep(i,N){
    l = lcm(l,a[i]);
    if(l > M){
      cout << 0 << endl;
      return 0;
    }
  }
  M /= l;
  cout << (M+1)/2 << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string  n;
    cin>>n;
    int len = n.size();    
    if(n[0]!='A')
    {
        cout<<"WA"<<endl;
        return 0;
    }
    if((n[1]>='A'&&n[1]<='Z')||(n[len - 1]>='A'&&n[len - 1]<='Z'))
    {
        cout<<"WA"<<endl;
        return 0;
    }
    int num = 0;
    for(int i=2;i<len-1;i++)
    {
        if(n[i]=='C')
            num++;
        else if(n[i]>='A'&&n[i]<='Z')
        {
            cout<<"WA"<<endl;
            return 0;
        }
    }
    if(num==1)
     cout<<"AC"<<endl;
    else 
     cout<<"WA"<<endl;
    return 0;
}
//AccccCcc


Measured memory_bytes: 256
#include <bits/stdc++.h>
#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++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main()
{
    int n, t;
    cin >> n >> t;
    pair<int, int> c[n];
    for (int i = 0; i < n; i++)
        cin >> c[i].first >> c[i].second;
    int co = 1001;
    for (int i = 0; i < n; i++)
    {
        if (t >= c[i].second)
        {
            if (co > c[i].first)
            {
                co = c[i].first;
            }
        }
    }
    if (co == 1001)
        cout << "TLE" << endl;
    else
        cout << co << endl;
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

const pid_t pid = getpid();
// Problem Specific Parameter:

const int limit = 200010;
ll L, a[limit];
ll dp[limit][5];

int main(void){
	cin >> L;
	rep(i,L) cin >> a[i];
	const ll inf = 1LL << 60;
	rep(i,L+1)rep(j,5) dp[i][j] = inf;
	dp[0][0] = 0LL;

	rep(i,L)rep(j,5){
		if(j - 1 >= 0) chmin(dp[i][j], dp[i][j-1]);
		const int val = abs(j - 2);
		if(val == 2){
			chmin(dp[i+1][j],dp[i][j] + a[i]);
		}

		if(val == 1){
			ll cost = a[i] % 2;
			if(a[i] == 0) cost = 2LL;
			chmin(dp[i+1][j],dp[i][j] + cost);
		}

		if(val == 0){
			ll cost = 1 - (a[i] % 2);
			chmin(dp[i+1][j],dp[i][j] + cost);
		}
	}

	ll ans = inf;
	rep(j,5) chmin(ans,dp[L][j]);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 9600
#include <algorithm>
#include <iostream>
#include <string>

bool kaibun(std::string S) {
  int size = S.size();
  for (int i = 0; i < size / 2; ++i)
    if (S[i] != S[size - i - 1])
      return false;
  return true;
}

bool strongKaibun(std::string S) {
  return kaibun(S) and kaibun(S.substr(0, S.size() / 2)) and
         kaibun(S.substr((S.size() + 2) / 2));
}

int main(int argc, char *argv[]) {
  std::string S;
  std::cin >> S;
  std::cout << (strongKaibun(S) ? "Yes" : "No") << std::endl;
}


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

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

typedef long long ll;
using namespace std;

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

  ll X;
  cin >> X;

  ll ans = 0ll;
  if (X / 500 > 0) {
    ans += (X / 500 * 1000);
    X %= 500;
  }

  if (X / 5 > 0) {
    ans += (X / 5 * 5);
  }

  cout << ans << endl;

  return 0;
}


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

const int N = 10;
std::string str;

long long recur(int index, bool plus[N]) {
    if (index >= str.length() - 1) {
        long long sum = 0;
        long long curNum = 0;
        for (int i = 0; i < str.length() - 1; ++i) {
            curNum += str[i] - '0';
            if (plus[i]) {
                sum += curNum;
                curNum = 0;
            } else {
                curNum *= 10;
            }
        }
        return sum + curNum + str[str.length() - 1] - '0';
    }
    plus[index] = true;
    long long res = recur(index + 1, plus);
    plus[index] = false;
    return res + recur(index + 1, plus);
}

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);

#if DEBUG_ON
    freopen("input", "r", stdin);
#endif

    std::cin >> str;
    bool plus[N] = { false };
    std::cout << recur(0, plus) << '\n';
    return 0;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007


int main(){

  cout << fixed << setprecision(15);
  int a,b,c,d,e,f;
  cin >> a >> b >> c >> d >> e >> f;
  vector<bool> is(3010,0);
  for(int i = 0;i*c < 3010;i++)is[i*c] = true;
  for(int i = d;i < 3010;i++)if(is[i-d])is[i] = true;
  Pl res = make_pair(100*a,0);
  long double maxi = 0;
  for(int i = 0;i*a*100 <= f;i++){
    for(int j = 0;(i*a+j*b)*100 <= f;j++){
      ll water = (i*a+j*b)*100;
      if(water == 0)continue;
      ll rest = min(f-water,e*water/100);
      ll su = 0;
      for(int gg = rest;gg >= 0;gg--){
        if(is[gg]){
          su = gg;
          break;
        }
      }
      if(maxi <= (long double)(100.0*su/(water+su)))res = make_pair(su+water,su),maxi = (long double)(100.0*su/(water+su));
    }
  }
  cout << res.first << " " << res.second << endl;
  
  




  return 0;
}

Measured memory_bytes: 256
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
# import math
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)


n=l()[0]
A=l()
d={}
for i in range(n):
    if(A[i] not in d):
        d[A[i]]=0
    d[A[i]]+=1
s=list(d.keys())
s.sort(reverse=True)
x=-1
y=-1
for ks in s:
    if(x==-1 and d[ks]>=2):
        x=ks
        if(d[ks]>=4):
            y=ks
            break
    elif(x!=-1 and y==-1 and d[ks]>=2):
        y=ks
        break
y=max(0,y)
print(max(x*y,0))

Measured memory_bytes: 20392
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Stream;
 
public class Main {    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        int[] p = new int[n];
        for(int i=0;i<n;i++){
            p[i] = Integer.parseInt(sc.next());
        }
        Arrays.sort(p);
        int ans = 0;
        for(int i=0;i<k;i++){
            ans = ans + p[i];
        }
        System.out.println(ans);
        
    }
}

Measured memory_bytes: 38088
def bubbleSort(lst, n):
    flag = 1
    i = 0
    while flag:
        flag = 0
        for j in range(n-1, 0, -1):
            if lst[j] < lst[j-1]:
                tmp = lst[j]
                lst[j] = lst[j-1]
                lst[j-1] = tmp
                flag = 1
                i = i + 1
    print(" ".join([str(n) for n in lst]))
    print(i)


if __name__ == "__main__":
    n = int(input())
    lst = [int(n) for n in input().split()]
    bubbleSort(lst, n)

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

using namespace std;

int n,i,dp[100005];
vector <int> edge[100005];

int solve(int id, int p){
	vector <int> u;
	for(int k = 0; k < edge[id].size(); k++){
		int to = edge[id][k];
		if(to == p) continue;
		u.push_back(solve(to, id));
	}
	
	sort(u.begin(), u.end());
	reverse(u.begin(), u.end());
	
	for(int k = 0; k < u.size(); k++)
	dp[id] = max(dp[id], u[k] + k + 1);
	
	return dp[id];
}

int main(){
	scanf("%d", &n);
	for(i = 2; i <= n; i++){
		int x;
		scanf("%d", &x);
		edge[x].push_back(i);
	}
	
	printf("%d\n", solve(1, -1));
}


Measured memory_bytes: 17024
#include<bits/stdc++.h>
using namespace std;
#define sz(x) (int)x.size()
#define pb push_back
#define mp make_pair
#define ll long long 
#define mod 1000000007 
void fast(){
  ios_base::sync_with_stdio(false);cin.tie(NULL);
}

int main() {
   fast();
  long long a,b,x;
  cin>>a>>b>>x;
  if(b%x==0 && a%x==0){
    cout<<b/x-a/x+1<<"\n";
  }else if(a%x==0 && b%x!=0){
    cout<<b/x-a/x+1<<"\n";
  }else if(a%x!=0 && b%x==0){
    cout<<b/x-a/x<<"\n";
  }else{
    cout<<b/x-a/x<<"\n";
  }

   
}


Measured memory_bytes: 3632
#!/usr/bin/env python3
import sys
from decimal import *


def solve(A: int, B):
    # B *= 1000
    # C = int(B)
    # print(A * C // 1000)
    print(int(A * B))

    # Bbig = int(B)
    # # print(Bbig)
    # Bsmall = int((B - Bbig) * 10)
    # # print(Bsmall)
    # Bsmall2 = int((B - Bbig) * 100) - Bsmall * 10
    # # print(Bsmall2)
    # Abig = A * Bbig * 100
    # # print(Abig)
    # Asmall = (A * Bsmall) * 10
    # # print(Asmall)
    # Asmall2 = (A * Bsmall2)
    # # print(Asmall2)
    # print((Abig + Asmall + Asmall2) // 100)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    # B = float(next(tokens))  # type: float
    B = Decimal(next(tokens))
    solve(A, B)

if __name__ == '__main__':
    main()

Measured memory_bytes: 77496
{
  const Main = (input: string) => {
    const inputArray: string[] = input.split(/ |\n/);
    if (!inputArray) return;
    const heightArrayStr: string[] = inputArray.filter((n, i) => i !== 0)
    const heightArray: number[] = heightArrayStr.map(n => parseInt(n)); 
    
    let work: boolean = true;
    let base: number = 0;
    const time: number = parseInt(inputArray[0]);
    for (let i = 0; i < time; i++) {
      if (heightArray[i] > base) {
        base = heightArray[i];
      } else if (base - 1 > heightArray[i]) {
        work = false;
        i = time;
      }
    }

    console.log(work ? 'Yes' : 'No');
  }
  Main(require("fs").readFileSync("/dev/stdin", "utf8"));
}


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

int main() {
  long long N, M;
  cin >> N >> M;
  
  long long ans = 0;
  if (N > 1) {
    ans += N * (N - 1) / 2;
  }
  if (M > 1) {
    ans += M * (M - 1) / 2;
  }
    
  cout << ans << endl;
  
  return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<vector<int>> A(N, vector<int>(N));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      cin >> A[i][j];
    }
  }
  vector<vector<bool>> D(N, vector<bool>(N, true));
  for (int k = 0; k < N; k++) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        if (A[i][j] > A[i][k] + A[k][j]) {
          cout << -1 << '\n';
          return 0;
        }
        if (A[i][j] == A[i][k] + A[k][j] && A[i][k] > 0 && A[k][j] > 0) {
          D[i][j] = false;
        }
      }
    }
  }
  int64_t res = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i; j < N; j++) {
      if (D[i][j]) res += A[i][j];
    }
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

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

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

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

	int n, k;
	cin >> n >> k;
	map<int, int> m;
	for (int i = 1; i <= n; i++) {
		m[i] = 0;
	}
	while (k--) {
		int d;
		cin >> d;
		while (d--) {
			int a;
			cin >> a;
			m[a]++;
		}
	}
	int ans = 0;
	for (auto p : m) {
		if (p.second == 0)
			ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3656