akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define times(n, i)      uptil(0, n, i)
#define rtimes(n, i)     downto((n) - 1, 0, i)
#define upto(f, t, i)    for(auto i##0_to = (t), i = decltype(t)(f); i <= i##0_to; i++)
#define uptil(f, t, i)   for(auto i##0_to = (t), i = decltype(t)(f); i <  i##0_to; i++)
#define downto(f, t, i)  for(auto i##0_to = decltype(f)(t), i = (f); i >= i##0_to; i--)
#define downtil(f, t, i) for(auto i##0_to = decltype(f)(t), i = (f); i >  i##0_to; i--)
using LD = long double;
#define double LD
#define long long long
#define LL long
#define int long
template<class T> using vec = vector<T>;
using VB = vec<bool>;   using WB = vec<VB>;
using VC = vec<char>;   using WC = vec<VC>;
using VI = vec<int>;    using WI = vec<VI>;
using VD = vec<double>; using WD = vec<VD>;
using VS = vec<string>; using WS = vec<VS>;
using PI = pair<int, int>;  using VPI = vec<PI>; using WPI = vec<VPI>;
using MI = map<int, int>;   using VMI = vec<MI>;

#if defined(EBUG) && !defined(ONLINE_JUDGE)
    #define debug true
    #define _GLIBCXX_DEBUG
    #define _LIBCPP_DEBUG 2
    #define _LIBCPP_DEBUG2 2
    #define ln << endl
    #define dd(x) cerr << #x << " = " << (x) << ", "
    #define ddd(x) cerr << #x << " = " << (x) ln
#else
    #define debug false
    #define ln << '\n'
    #define dd(x) cerr
    #define ddd(x) cerr
#endif
#define tb << '\t'
#define sp << ' '
#define db dd
#define dbg ddd

template<class T>          inline istream& operator>>(istream& s, vec<T>& v) { for(auto&& p : v) s >> p; return s; }
template<class T, class S> inline ostream& operator<<(ostream&, const pair<T, S>&);
template<class T>          inline ostream& operator<<(ostream&, const vec<T>&);
template<class T, class S> inline ostream& operator<<(ostream&, const map<T, S>&);
#define DEFINE_ITER_OUTPUT(s, x, sep) { int i = 0; for(const auto& x##0_elem : x) { if(i++) s << sep; s << x##0_elem; } return s; }
template<class T, class S> inline ostream& operator<<(ostream& s, const pair<T, S>& p) { return s << "(" << p.first << "," << p.second << ")"; }
template<class T>          inline ostream& operator<<(ostream& s, const vec<T>& v) DEFINE_ITER_OUTPUT(s, v, ' ')
template<class T, class S> inline ostream& operator<<(ostream& s, const map<T, S>& m) DEFINE_ITER_OUTPUT(s, m, ' ')
template<class T>          inline ostream& operator<<(ostream& s, const vec<vec<T>>& w) DEFINE_ITER_OUTPUT(s, w, '\n')
template<class T, class S> inline ostream& operator<<(ostream& s, const vec<map<T, S>>& vm) DEFINE_ITER_OUTPUT(s, vm, '\n')


void solve();

signed main() {
    if(!debug) {
        cin.tie(0);
        ios::sync_with_stdio(0);
    }
    cout << fixed << setprecision(20);
    cerr << fixed << setprecision(20);

    solve();

    return 0;
}

void solve() {
// N N(A)
/* <foxy.memo-area> */
int N;cin>>N;VI A(N);times(N,Ri_0){cin>>A[Ri_0];}
/* </foxy.memo-area> */

    VI c(N);
    times(N, i) c[i] = A[i] - i;
    sort(c.begin(), c.end());
    int b = c[N/2];

    int ans = 0;
    times(N, i) ans += abs(c[i] - b);
    cout << ans ln;
}


Measured memory_bytes: 3328
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main(void)
{
     int a,b,i,j,k,n,m;
     scanf("%d%d",&n,&m);
     a=n*m;
     if(a%2)
          printf("Odd\n");
     else
          printf("Even\n");

     return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use std::process::exit;
use std::cmp::*;
use itertools::Itertools;

fn main() {
    input! {
    a:String,
    }
    let mut a=a.chars().collect_vec();
    a[3]='8';
    let a:String= a.into_iter().collect();
    println!("{}",a)
}

Measured memory_bytes: 2188
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define MOD (ll)(1e9+7)
#define INF 1e17
#define int ll
#define EPS (1e-6)
using namespace std;
using ll=long long;
using pii=pair<int,int>;

int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }
int lcm(int a,int b) { return a/gcd(a,b)*b; }

int fpow(int b,int p)
{
	if(p==0) return 1;
	int h=fpow(b,p/2);
	if(p%2) return h*b%MOD*h%MOD;
	return h*h%MOD;
}

#define MAXN 410

int dp[MAXN][MAXN]; //dp[i][j] = A*ig + B*jg min cost

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n; cin>>n;
	int x,y; cin>>x>>y;
	int a,b,c;
	For(i,0,MAXN-1) For(j,0,MAXN-1) dp[i][j]=INF;
	dp[0][0]=0;
	For(k,0,n-1){
		cin>>a>>b>>c;
		for(int i=MAXN-1;i>=0;i--) for(int j=MAXN-1;j>=0;j--){
			if(i>=a && j>=b) dp[i][j]=min(dp[i][j],dp[i-a][j-b]+c);
		}
	}
	int ans=INF;
	for(int i=x,j=y;i<MAXN-1 && j<MAXN;i+=x,j+=y) ans=min(ans,dp[i][j]);
	if(ans==INF) cout<<"-1\n";
	else cout<<ans<<"\n";
	//For(i,0,MAXN-1) For(j,0,MAXN-1) cout<<(dp[i][j]==INF?-1:dp[i][j])<<" \n"[j==MAXN-1];
	return 0;
}





























Measured memory_bytes: 1536
#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 INF 1e9
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << x << endl;

using namespace std;
typedef long long ll;

signed main() {
  int n, a[3][3], b, cnt = 0;

  REP(i, 3) { REP(j, 3) cin >> a[i][j]; }
  cin >> n;

  REP(i, n) {
    cin >> b;
    REP(j, 3) {
      REP(k, 3) {
        if(a[j][k] == b)
          a[j][k] = 0;
      }
    }
  }

  REP(i, 3) {
    if(a[i][0] + a[i][1] + a[i][2] == 0 || a[0][i] + a[1][i] + a[2][i] == 0) {
      cnt++;
      break;
    }
  }

  if(a[0][0] + a[1][1] + a[2][2] == 0 || a[0][2] + a[1][1] + a[2][0] == 0)
    cnt++;

  if(cnt > 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>

#define rep(i, N) for(int (i) = 0; (i) < (N); (i) ++)
typedef long long ll;

using namespace std;

int main(){
    int N;
    int M;
    cin >> N >> M;
    vector<int> firsts;
    vector<bool> lasts(N, false);
    rep(i, M){
        int a, b;
        cin >> a >> b;
        a --;
        b --;
        if(a == 0){
            firsts.push_back(b);
        }
        if(b == N - 1){
            lasts[a] = true;
        }
    }
    rep(i, firsts.size()){
        int tmp = firsts[i];
        if(lasts[tmp]){
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;

    return 0;
}


Measured memory_bytes: 896
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine()); //標準入力
        int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int count = 0;
        for(int i=0; i<n; i++)
        {
            for(int j=n-1; j>i; j--)
            {
                if(array[j-1] > array[j])
                {
                    int tmp = array[j-1];
                    array[j-1] = array[j];
                    array[j] = tmp;
                    count++;
                }
            }
        }
        Console.WriteLine(string.Join(" ", array.Select(i => i.ToString()).ToArray()));
        Console.WriteLine(count);
    }
}


Measured memory_bytes: 9628
N,K = (int(i) for i in input().split())

A = [0] * N

for k in range(K):
  d = int(input())
  A_tmp = [int(i) for i in input().split()]
  for a in A_tmp:
    A[a-1] += 1

ans = 0

for a in A:
  if a == 0:
    ans += 1

print(ans)


Measured memory_bytes: 9180
#include <bits/stdc++.h>
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define nl '\n'
typedef long long ll;
typedef long double ld;
//////////////////////////////////////////////////////////////////////

int n;
map<int,int> mp;

int main(){
  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  
  cin>>n;
  for(int i=1;i<=n;i++){
    int v;cin>>v;
    mp[v]++;
  }

  int ans = 0;
  for(int v=0;v<=100000;v++)
    ans = max(ans , mp[v-1] + mp[v] + mp[v+1] );

  cout << ans << nl;
  
  return 0;
};


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

using namespace std;

////////////////////////////////////////////////////////////////////////////////////////////////////
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define wt(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define wt(x...)
#endif
/////////////////////////////////////////////////////////////////////////////////////////////////


#define LL long long
const int MAXN = 212345;
const int INF  = 0x3f3f3f3f;




int main () {

	ios_base::sync_with_stdio(false);  cin.tie(NULL); 

	int d, n;
	cin >> d >> n;

	int div = 1;

	// 1 000 000

	if (d == 0) div = 1;
	else if (d == 1) div = 100;
	else div = 10000;

	for (int i = 1; i <= (int)1e7 + 500; ++i) {
		if (i % div == 0)
			--n;

		if (n == 0) {

			if (d == 0 && i == 100)
				cout << i + 1 << '\n';
			else if (d == 1 && i == 10000)
				cout << i + 100 << '\n';
			else if (d == 2 && i == 1000000)
				cout << i + 10000 << '\n';

			else cout << i << '\n';


			return 0;
		}
	}




	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>


int main(void){
  int a,b,c,d,e,i,j;
  int n[9999];
  j=0;  
  while(scanf(" %d %d", &a, &b)!=EOF){
   
    c=a+b;d=1;i=0;e=1;
    while(e>0){
      e=c/d;
      //      printf("%d\n",i);
      d=d*10;
      i++;}
    n[j]=i-1;
    
    //printf("input %d %d \n",a,b);
    j++;
  }
  for(i=0;i<j;i++)
    printf("%d\n",n[i]);
	   return 0;
}

Measured memory_bytes: 0
import scala.util.control.Breaks

object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n, y = sc.nextInt

  val b = new Breaks
  var flg = false
  b.breakable{
    for(i <- n to 0 by -1; j <- (n - i) to 0 by -1) {
      val v = 10000 * i + 5000 * j + 1000 * (n - i - j)
      if(v == y){
        println(i + " " + j + " " + (n - i - j))
        flg = true
        b.break
      }
    }
  }

  if(!flg){
    println("-1 -1 -1")
  }
}

Measured memory_bytes: 27468
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
    int n,k,ans=1;
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    {
        if(ans<k)
            ans*=2;
        else
            ans+=k;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#ifdef xay5421
#define D(...) fprintf(stderr,__VA_ARGS__)
#else
#define D(...) ((void)0)
#define NDEBUG
#endif
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
using namespace std;
typedef long long LL;
template<typename T>void umax(T&x,const T&y){if(x<y)x=y;}
template<typename T>void umin(T&x,const T&y){if(x>y)x=y;}
const int N=1005,M=1000005,INF=0X3F3F3F3F;
const LL INFLL=0X3F3F3F3F3F3F3F3FLL;
int n,m,K,S,T,x[N],y[N],lb[2][N],rb[2][N],pre[N];LL v[N];
LL ans,dis[N];
bool vis[N];
struct data{
	char c;
	int a,b;
}A[N];
int pp,lnk[N],nxt[M],to[M],we[M];LL co[M];
void ae(int k1,int k2,int k3,LL k4){
	D("%d %d %d %lld\n",k1,k2,k3,k4);
	to[++pp]=k2,we[pp]=k3,co[pp]=k4,nxt[pp]=lnk[k1],lnk[k1]=pp;
	to[++pp]=k1,we[pp]=0,co[pp]=-k4,nxt[pp]=lnk[k2],lnk[k2]=pp;
}
queue<int>q;
bool spfa(){
	rep(i,1,T)dis[i]=-INFLL,pre[i]=0;
	dis[S]=0;
	while(!q.empty())q.pop();
	q.push(S),vis[S]=1;
	while(!q.empty()){
		int k1=q.front();
		vis[k1]=0;
		q.pop();
		for(int i=lnk[k1];i;i=nxt[i])if(we[i]&&dis[k1]+co[i]>dis[to[i]]){
			dis[to[i]]=dis[k1]+co[i];
			pre[to[i]]=i;
			if(!vis[to[i]])q.push(to[i]),vis[to[i]]=1;
		}
	}
	return dis[T]>=0;
}
LL mcmf(int K){
	LL mc=0,mf=0;
	while(spfa()){
		int flow=INF;
		for(int i=pre[T];i;i=pre[to[i^1]])flow=min(flow,we[i]);
		for(int i=pre[T];i;i=pre[to[i^1]])we[i]-=flow,we[i^1]+=flow;
		mf+=flow;
		mc+=1LL*dis[T]*flow;
	}
	if(mf==K)return mc;
	return D("bad %d\n",K),0;
}
int main(){
	cin>>n;
	rep(i,1,n)cin>>x[i]>>y[i]>>v[i];
	cin>>m;
	rep(i,1,m)cin>>A[i].c>>A[i].a>>A[i].b;
	S=n*4+1,T=n*4+2;
	for(K=1;K<=n;++K){
		rep(i,1,K)lb[0][i]=lb[1][i]=0,rb[0][i]=rb[1][i]=INF;
		rep(i,1,m){
			if(A[i].c=='L'){
				rep(j,A[i].b+1,K)umax(lb[0][j],A[i].a+1);
			}else if(A[i].c=='R'){
				rep(j,1,K-A[i].b)umin(rb[0][j],A[i].a-1);
			}else if(A[i].c=='U'){
				rep(j,1,K-A[i].b)umin(rb[1][j],A[i].a-1);
			}else{
				rep(j,A[i].b+1,K)umax(lb[1][j],A[i].a+1);
			}
		}
		pp=1;
		rep(i,1,T)lnk[i]=0;
		rep(i,1,K)ae(S,i,1,0);
		rep(i,1,K){
			rep(j,1,n)if(lb[0][i]<=x[j]&&x[j]<=rb[0][i])ae(i,K+j,1,0);
		}
		rep(i,1,n){
			ae(K+i,K+n+i,1,v[i]);
		}
		rep(i,1,K){
			rep(j,1,n)if(lb[1][i]<=y[j]&&y[j]<=rb[1][i])ae(K+n+j,K+n+n+i,1,0);
		}
		rep(i,1,K){
			ae(K+n+n+i,T,1,0);
		}
		ans=max(ans,mcmf(K));
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4016
#include<iostream>
#include<algorithm>
#include<deque>
using namespace std;
int main(){
int n,k; cin >> n >> k;
int h[100000];for(int i = 0; i < n; i++) cin >> h[i];
int dp[100000];
deque<int> q;
dp[0] = 0;
for(int i = 1; i < n; i++){
        for(int j = 0;(j < k && j < i); j++){
               q.push_back(dp[i - j - 1] + abs(h[i] - h[i - j - 1]));
               }
        dp[i] = *min_element(q.begin(), q.end());
        q.clear();
}
cout << dp[n - 1] << "\n";
}

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

using namespace std;

template <typename T>
using V = vector<T>;

typedef long double ld;
typedef long long ll;

#define FO(i, N) for (int (i) = 0; (i) < (N); ++(i))
#define FOll(i, N) for (ll (i) = 0; (i) < (N); ++(i))
#define READALL(c) for (auto &e : c) { cin >> e; }
#define PRINTALL(c) for (const auto &e : c) { cout << e << "\t"; } cout << "\n";
#define MP(x, y) (make_pair((x), (y)))
#define MT(...) make_tuple(__VA_ARGS__)
#define G(i, x) get<i>(x)
#define ALL(x) begin(x), end(x)

int divs(int n) {
	set<int> d;
	for (int i = 1; i*i <= n; ++i) if (n%i == 0) {
		d.insert(i);
		d.insert(n/i);
	}
	return d.size();
}


int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int N;
	cin >> N;
	int cnt = 0;
	for (int i = 1; i <= N; i+=2) if (divs(i) == 8) {
		++cnt;
	}
	cout << cnt << endl;
}

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

long long Calc(long long P) {
	if (P == 0) return 0;
	long long COUNT = 0;
	long long Q = P;
	while (Q > 0) {
		COUNT += Q % 2;
		Q /= 2;
	}
	return Calc(P % COUNT) + 1;
}

long long Pow(long long A, long long B, long long M) {
	if (B == 0) return 1 % M;
	if (B % 2 == 0) {
		long long C = Pow(A, B / 2, M);
		return (C * C) % M;
	}
	return (A * Pow(A, B - 1, M)) % M;
}

int main() {
	long long N;
	string S;
	cin >> N >> S;
	long long X = 0;
	for (int i = 0; i < N; i++) X += (S[i] - '0');
	long long MOD1 = 0, MOD2 = 0, Y = X - 1, Z = X + 1;
	if (Y != 0) {
		for (int i = 0; i < N; i++) {
			MOD1 *= 2;
			MOD1 += S[i] - '0';
			MOD1 %= Y;
		}
	}
	for (int i = 0; i < N; i++) {
		MOD2 *= 2;
		MOD2 += S[i] - '0';
		MOD2 %= Z;
	}
	for (int i = 0; i < N; i++) {
		if (S[i] == '0') {
			long long NEXT = (MOD2 + Pow(2, N - 1 - i, Z)) % Z;
			cout << Calc(NEXT) + 1 << endl;
		}
		else {
			if (Y == 0) cout << 0 << endl;
			else {
				long long NEXT = (MOD1 - Pow(2, N - 1 - i, Y) + Y) % Y;
				cout << Calc(NEXT) + 1 << endl;
			}
		}
	}
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
 
using namespace std;
 
int main(void) 
{
	cin.tie(0);
	ios::sync_with_stdio(false);
 
	int n;
	long long int t,res=0;
	int cnt = 0;
	long long int Min = 1E18;
 	cin >> n;

 	for(int i=0;i<n;i++)
 	{
 		cin >> t;
 		if(t<0)
 		{
 			cnt++;
 		}
 		Min = min(Min,abs(t));
 		res += abs(t);
 	}

 	if(cnt%2==1)
 	{
 		res -= 2*Min;
 	}

 	cout << res << '\n';
 	
	return 0;
}

Measured memory_bytes: 256
from copy import copy
S=input()
S+="A"
lst1=[]
lst2=[]
lst3=[]
lst1.append(int(S[0]))
lst2.append(0)
def confirm(l1,l2):
    s=0
    for i in range(len(l1)):
        if l2[i]==0:
            s+=l1[i]
        else:
            s-=l1[i]
    return s
def draw(l1,l2,l3):
    s=""
    for i in range(len(l1)):
        if l2[i]==0:
            s=s+"+"+str(l1[i])
        else:
            s=s+"-"+str(l1[i])
    s=s+"=7"
    l3.append(s[1:])
    return 0
def func(S,l1,l2,l3):
    if S=="A":
        if confirm(l1,l2)==7:
            draw(l1,l2,l3)
            return 0
        return 0
    x=copy(l1)
    x.append(int(S[0]))
    y1=copy(l2)
    y1.append(0)
    y2=copy(l2)
    y2.append(1)
    return func(S[1:],x,y1,l3),func(S[1:],x,y2,l3)
func(S[1:],lst1,lst2,lst3)
print(lst3[0])

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

int main(){
  int N;
  int max = 0;
  vector<int> V,C;
  cin >> N;
  for(int i=0;i<N;i++){
    int v;
    cin >> v;
    V.push_back(v);
  }
  for(int i=0;i<N;i++){
    int c;
    cin >> c;
    C.push_back(c);
  }

  for(int i=0;i<V.size();i++){
    if(V[i] > C[i]){
      max += V[i] - C[i];
    }
  }

  cout << max << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
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(a > b){ a = b; return 1; } return 0; }
int main()
{
  string s,t; cin >> s >> t;
  int res = 0;
  rep(i,s.size()) {
    if(s[i] != t[i]) res++;
  }
  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 3904
import sys
input = sys.stdin.readline
N,M = map(int, input().split())
A = list(map(int, input().split()))  # -> li = [1,2,3,...n]
C = [[0,0] for _ in range(M)]
for i in range(M):
    b,c = map(int, input().split())
    C[i][0] = c
    C[i][1] = b
A = sorted(A, reverse=True)
C = sorted(C, reverse=True)
cnt = 0
s = 0
ai = 0
ci = 0
while cnt < N:
    aa = A[ai]
    if ci >= M:
        cc = 0
    else:
        cc = C[ci][0]
    if aa > cc:
        s += aa
        ai += 1
    else:
        s += cc
        C[ci][1] -= 1
        if C[ci][1] == 0:
            ci += 1
    cnt += 1
print(s)


Measured memory_bytes: 70296
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int a,b,c;
	cin>>a>>b>>c;
	if((a==b&&a!=c)||(a==c&&a!=b)||(b==c&&b!=a)){
		cout<<"Yes";
	}
	else
		cout<<"No";
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {

        Scanner sc =new Scanner(System.in);
        
        int N = sc.nextInt();
        String S = sc.next();
        int K = sc.nextInt();
        String str = S.substring(K-1,K);

        S = S.replaceAll(str, "_");
        S = S.replaceAll("[a-z]","*");
        S = S.replaceAll("_",str);
        
        System.out.println(S);
    }
}


Measured memory_bytes: 21588
/**
 *    author:  FromDihPout
 *    created: 2020-07-25
**/

#include <bits/stdc++.h>
using namespace std;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    vector<double> p(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    
    vector<vector<double>> dp(n, vector<double> (n + 1));
    dp[0][0] = 1 - p[0];
    dp[0][1] = p[0];
    for (int i = 1; i < n; i++) {
        dp[i][0] = dp[i-1][0] * (1 - p[i]);
        for (int j = 1; j <= i + 1; j++) {
            dp[i][j] = dp[i-1][j] * (1 - p[i])
                + dp[i-1][j-1] * p[i];
        }
    }
    
    double ans = 0;
    for (int i = n / 2 + 1; i <= n; i++) {
        ans += dp[n-1][i];
    }
    printf("%.12f", ans);
    return 0;
}

Measured memory_bytes: 73784
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, n+1)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define rwhole(x) (x).rbegin(), (x).rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define P pair<int, int>
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define eb emplace_back
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, k;
    cin >> n >> k;
    vector<int> d(k);
    rep(i, k) cin >> d[i];
    vector<bool> x(10);
    rep(i, k) {
        x[d[i]] = true;
    }

    int ans = n;
    bool flg = false;
    while (!flg) {
        string s = to_string(ans);
        flg = true;
        for (char c: s) {
            if (x[c-'0']) flg = false;
        }
        if (flg) break;
        ans++;
    }
    
    cout << ans << endl;
    return 0;
}


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

int main(){
    int N,a,n;
    cin >> N;
    if(N%1000==0){
        cout << 0 << endl;
    }else{
        a = N / 1000;
        n = (a + 1) * 1000 - N;
        cout << n << endl;
    }
    return 0;
}

Measured memory_bytes: 3608
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

/* RangeMinimumQuery(0-index) */

struct RMQ{
  typedef pair<int,int> Type;
  int segn2;
  Type inf;
  vector<Type> data;
  
  RMQ(int n){
    inf = {-INF,0}; //init value
    for(segn2=1;segn2<n;segn2*=2);
    data.assign(segn2*2,inf);

    for(int i=0;i<n;i++){
      data[i+segn2-1] = {INF,i};
    }

    for(int i=segn2-2;i>=0;i--){
      data[i] = max(data[i*2+1],data[i*2+2]);
    } 
  }
  
  //get minimum value [a,b]
  Type query(int a,int b,int l=0,int r=-1,int k=0){
    if(r==-1) r+=segn2;
    if(a<=l && r<=b) return data[k];
    if(r<a || b<l) return inf;
    return max(query(a,b,l,(l+r)/2,k*2+1),query(a,b,(l+r)/2+1,r,k*2+2));
  }
  
  //set kth number x
  void set(int k,int x2){
    pair<int,int> x = {x2,k};
    k+=segn2-1;
    data[k]=x;
    while(k>0){
      k=(k-1)/2;
      data[k]=max(data[k*2+1],data[k*2+2]);
    }
    return;
  }
};




int main(){
  int n,m;
  int L[SIZE],R[SIZE];

  vector<pair<int,int> > vec;
  
  scanf("%d%d",&n,&m);

  for(int i=0;i<n;i++){
    scanf("%d%d",L+i,R+i);

    vec.push_back({R[i],L[i]});
  }

  sort(vec.begin(),vec.end());
  
  RMQ rmq(m+1);
  priority_queue<int> pq;
  
  for(int i=n-1;i>=0;i--){
    int r = vec[i].first;
    int l = vec[i].second;

    if(r > m){
      pq.push(-l);
      continue;
    }
    
    auto p = rmq.query(r,m);
    
    if(p.first == INF){
      rmq.set(p.second,l);
    }else{
      if(p.first > l){
        rmq.set(p.second,l);
        pq.push(-p.first);
      }else{
        pq.push(-l);
      }
    }
  }

  int ans = 0;
  
  while(pq.size()){
    
    auto p = rmq.query(1,-pq.top());
    
    if(p.first == INF){
      rmq.set(p.second,1);
    }else{
      ans++;
    }

    pq.pop();
  }

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


Measured memory_bytes: 9328
/*
    AUTHOR:shivam51
    IIESTS
*/
  #include<bits/stdc++.h>
  using namespace std;
  //
  #define MAX 100001
  #define md 1000000007
  #define add accumulate
  #define ll long long int
  #define ff first
  #define ss second
  #define pb push_back
  #define mp make_pair
  #define vll vector<ll>
  #define lb lower_bound
  #define ub upper_bound
  #define pll pair<ll,ll>
  #define vpll vector<pll>
  #define all(v) v.begin(), v.end()
  #define rep(i,k,n) for(int i=k;i<n;i++)
  #define hs ios_base::sync_with_stdio(false);cin.tie(NULL);
  #define repa(a,n) for(int i=a;i<n;i++)
  //
  //
  int main(){
    double a,b,t;
    cin>>a>>b>>t;
    ll ans=b*(ll)((t+0.5)/a);
    cout<<ans;
  }

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

const LL mod = 1000000007;
std::vector<LL>A, pows;
std::vector<std::vector<LL>>memo;

LL dp(LL i, LL j)
{
	if (i == A.size()) return (j == 5 ? 1 : 0);
	if (memo[i][j] != -1) return memo[i][j];
	LL res = 0;
	if (A[i] == -1)
	{
		for (LL k = 0; k <= 9; ++k) (res += dp(i + 1, (j + k * pows[i]) % 13)) %= mod;
	}
	else res = dp(i + 1, (j + A[i] * pows[i]) % 13);
	return memo[i][j] = res;
}

int main()
{
	std::string S;
	in >> S;

	pows.resize(S.length());
	rep(i, S.length())
	{
		if (S[i] == '?') A.push_back(-1);
		else A.push_back(S[i] - '0');
	}
	std::reverse(A.begin(), A.end());
	pows[0] = 1;
	for (LL i = 1; i < S.length(); ++i) pows[i] = pows[i - 1] * 10 % 13;

	memo.resize(S.length(), std::vector<LL>(13, -1));
	out << dp(0, 0) << std::endl;
}


Measured memory_bytes: 23028
import std.stdio, std.algorithm, std.string, std.conv, std.array, std.range, std.math;
int readint() { return readln.chomp.to!int; }
int[] readints() { return readln.split.to!(int[]); }

void main() {
    int n = readint();
    string s = readln.chomp;

    int[] a = new int[300010];
    int[] b = new int[300010];
    foreach (i, c; s) {
        a[i] += (c == 'E');
        b[i] += (c == 'W');
    }
    foreach (i; 0..n - 1) {
        a[i+1] += a[i];
        b[i+1] += b[i];
    }

    int ans = a[n - 1] - a[0];
    foreach (i; 1..n) {
        int x = b[i - 1] + (a[n - 1] - a[i]);
        ans = min(ans, x);
    }
    writeln(ans);

    string _ = readln;
}


Measured memory_bytes: 4456
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

// -----------------------------------------------------------------------------

func calc(a int64) int64 {
	k := a % 4
	switch k {
	case 3:
		return 0
	case 2:
		return a + 1
	case 1:
		return a ^ (a - 1)
	case 0:
		return a
	}
	return 0
}

func main() {
	defer stdout.Flush()
	a := readInt64()
	b := readInt64()
	if a == 0 {
		println(calc(b))
	} else {
		println(calc(b) ^ calc(a-1))
	}
}

// -----------------------------------------------------------------------------

func minInt(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

func maxInt(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

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

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(){
    char d;
	string s1,s2,s3;
	cin>>s1>>s2>>s3;
	d= s1[0]-32;
	cout<<d;
		d= s2[0]-32;
	cout<<d;
	d=s3[0]-32;
	cout<<d;
	return 0;
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define PI 3.1415926535897932384
using namespace std;

const ll int N=1e18;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	ll ar[n],ans=1,zero=0;
	for(int i=0;i<n;i++){
		cin>>ar[i];
		if(ar[i]==0){
			zero++;
		}
	}
	if(zero>0) ans=0;
	else{
	for(int i=0;i<n;i++){
		if(ar[i]<=N/ans)
			ans*=ar[i];
		else{
			ans=-1;
			break;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4432
#include <bits/stdc++.h>
#define ll long long
#define MAX 2000005
using namespace std;
int main()
{
	
		ll a,b,c;
cin>>a>>b>>c;
if((b+c)%2==0)cout<<"Alice\n";
else cout<<"Borys\n";
		
return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
using lint=long long;
using lubl=long double;
void cmx(lint&x,lint y){if(x<y)x=y;}
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint n;std::cin>>n;
    std::vector<lint>a(n);
    for(lint&x:a)std::cin>>x;
    std::sort(ALL(a),std::greater<>{});
    lint ans=0;
    std::vector<lint>b;
    for(lint l=0,r=0;l<n;l=r){
        lint x=a.at(l);
        for(;r<n&&x==a.at(r);r++);
        if(4<=r-l)cmx(ans,x*x);
        if(2<=r-l)b.push_back(x);
    }
    if(2u<=b.size())cmx(ans,b.at(0)*b.at(1));
    std::cout<<ans<<'\n';
}


Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000000000000



int main(){
	
	int N;
	cin>>N;
	
	vector<long long> A(N);
	bool f = false;
	long long S = Inf;
	
	for(int i=0;i<N;i++){
		cin>>A[i];
		if(A[i]==0){
			f=true;
		}
		else{
			S/=A[i];
		}
	}
	
	if(f){
		cout<<0<<endl;
	}
	else if(S==0){
		cout<<-1<<endl;
	}
	else{
		S = 1;
		for(int i=0;i<N;i++)S *= A[i];
		cout<<S<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 4000
#include <stdio.h>
int main(void){
    // Your code here!

    int a,b,c;
    int n=0;
    scanf("%d %d %d",&a,&b,&c);
    for ( int i=a; i<=b; i++){
      if ( (c%i) == 0 )n++;
    }
    printf("%d\n",n);
}



Measured memory_bytes: 1992
#include <bits/stdc++.h>  
using namespace std; 
int n,m;
bool b[1000005];
int tot[1000005];
int ans=0;
int main()  
{  
    int x,y;
    cin>>n>>m;
    for(int i=1;i<=n;i++)tot[i]=1;
    b[1]=true;
    for(int i=1;i<=m;i++)
    {
        cin>>x>>y;
        if(b[x])
            b[y]=true;
            tot[x]--;
            tot[y]++;
        if(tot[x]==0)
            b[x]=false;
    }
    for(int i=1;i<=n;i++)
        if(b[i])
            ans++;
    cout<<ans<<endl;
    return 0;
}

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

int main() {
	
	long long n, d;
	cin >> n >> d;
	int answer = 0;
	for (int i = 0; i < n; i++) {
		long long x, y;
		cin >> x >> y;
		if (x * x + y * y <= d * d) answer++;
	}
	cout << answer << endl;
}


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

#define MAX 1000005
#define INF 200000000
#define MOD 1000000007

typedef long long ll;
typedef unsigned long long llu;

using namespace std;

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

void IO()
{
    freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
}

bool flag;
int n,q,m;
int arr[25];

void Fun(int i, int sum)
{
    if(sum==m){
        flag=true;
        return;
    }
    if(i>=n)return;
    if(sum+arr[i]<=m&&!flag)Fun(i+1,sum+arr[i]);
    if(!flag)Fun(i+1,sum);
}

int main()
{
    //IO();
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%d",&arr[i]);
    scanf("%d",&q);
    for(int i=1;i<=q;i++){
        scanf("%d",&m);
        flag=false;
        Fun(0,0);
        if(flag)printf("yes\n");
        else printf("no\n");
    }
    return 0;
}

Measured memory_bytes: 3140
#include<stdio.h>
#include<iostream>
#include<deque>
using namespace std;
char c;
int m=0,n,i;
int main()
{
	scanf("%d",&n);
	i=n;
	while(i!=0)
	{
		m+=i%10;
		i=i/10;
	}
	if(n%m)printf("No");
	else printf("Yes");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define all(a) (a).begin(),(a).end()
#define lb(s,x) lower_bound(all(s),x)-s.begin()
#define ub(s,x) upper_bound(all(s),x)-s.begin()
#define uniq(a) a.erase(unique(all(a)),a.end())
const int INF = 1e9;

#define debug(x) cerr<<(#x)<<": "<<(x)<<endl
template<class T,class U>
ostream& operator<<(ostream& o, const pair<T,U> &p){
    o<<"("<<p.first<<", "<<p.second<<")";
    return o;
}
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }

class modint {
  public:
    using ll = long long;
    ll num;
    static const ll MOD = 1e9+7;
    static vector<modint> factorial;

    modint(): num(0) {};
    modint(ll _n): num((_n + MOD) % MOD) {}
    modint(const modint &r): num(r.num) {}
    operator ll() const { return (num+MOD)%MOD; }
    friend istream& operator>>(istream& is, modint &r){
        ll num_;
        is >> num_;
        r = num_;
        return is;
    }
    modint operator+(const modint &r) const { return modint(num + r.num); }
    modint operator-(const modint &r) const { return modint(num - r.num); }
    modint operator*(const modint &r) const { return modint(num * r.num); }

    template<typename T>
    modint operator^(const T &r) const {
        if(r == 0) return 1;
        return (((*this)*(*this)) ^ (r/2)) * modint(r&1 ? num : 1);
    }
    modint operator/(const modint &r) const { return num * (r^(MOD-2)); }

    modint operator+=(const modint &r) { return *this = *this + r; }
    modint operator-=(const modint &r) { return *this = *this - r; }
    modint operator*=(const modint &r) { return *this = *this * r; }
    modint operator/=(const modint &r) { return *this = *this / r; }

    template<typename T>
    modint operator^=(const T &r) { return *this = *this ^ r; }

    static modint fact(int n){
        if((int)factorial.size() <= n) factorial.resize(n+1);
        if(factorial[n]) return factorial[n];
        if(n == 0) return 1;
        return factorial[n] = modint(n) * fact(n-1);
    }

    static modint com(ll n,ll r){
        return n >= r ? fact(n)/(fact(n-r)*fact(r)) : modint(0);
    }
};
vector<modint> modint::factorial;

int Y,X,K;
modint dp[110][10];

modint rec(bool pre, int k, int L) {
    if(k == L) return 1;
    if(pre) return rec(false, k+1, L);
    else return rec(true, k+1, L) + rec(false, k+1, L);
}

modint bits[10] = {};

modint f(int x) {
    if (x<=0) return 1;
    else return bits[x];
}

int main(void){
    cin>>Y>>X>>K;
    rep1(k,X){
        bits[k] = rec(false, 0, k);
    }

    dp[0][1] = 1;
    rep(y,Y+1){
        rep1(x,X){
            dp[y+1][x-1] += dp[y][x] * f(x-3) * f(X-1-x);
            dp[y+1][x]   += dp[y][x] * f(x-2) * f(X-1-x);
            dp[y+1][x+1] += dp[y][x] * f(x-2) * f(X-2-x);
        }
    }
    cout << dp[Y][K] << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
    typedef long long lint;
    typedef pair<int,int> pint;
    typedef vector<int> vint;
    #define rep(i, n) for(int i = 0; i < n; i++)
    #define rep2(i, m, n) for(int i = m; i < n; i++)
    #define rep3(elem, vec) for(auto elem: vec)
    #define SORT(V) sort((V).begin(),(V).end())
    #define RSORT(V) sort((V).rbegin(), (V).rend())
    #define COUT(N) cout<<fixed<<setprecision(N)
    lint gcd(int a,int b){return b?gcd(b,a%b):a;}
    lint lcm(int a,int b){return a*b/gcd(a,b);}
    lint comb(int a,int b){return b?comb(a-1,b-1)*a/b:1;}
    int dx[4] ={1,0,-1,0},dy[4] = {0,1,0,-1};
    int MOD = 1e9+7;

int main(){
    int N,M;
    cin >> N >>M;
    vint A(M);
    rep(i,M)cin >> A[i];
    rep(i,M){
        N-=A[i];
    }
    if(N<0)cout <<-1;
    else cout << N;
    return 0;
}


Measured memory_bytes: 3632
import scala.io.StdIn

object Main extends App {

  Iterator.continually(StdIn.readLine)
    .drop(1)
    .takeWhile(_ != null)
    .filter(_.contains('#'))
    .map(_.toCharArray)
    .toArray
    .transpose
    .filter(_.contains('#'))
    .transpose
    .foreach(ch => println(ch.mkString))

}

Measured memory_bytes: 30920
l = [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]

print(l[int(input())-1])

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n;
		int min;

		while (true) {
			n = sc.nextInt();
			if (n == 0) {
				break;
			}
			min = Integer.MAX_VALUE;
			for (int i = 0; i < 100; i++) {
				for (int j = 0; j < 100; j++) {
					for (int k = 0; k < 100; k++) {
						if (n == i * 200 + j * 300 + k * 500) {
							int sum = 0;
							sum += i * 380;
							sum -= (i / 5) * 380 * 5 * 0.20;
							sum += j * 550;
							sum -= (j / 4) * 550 * 4 * 0.15;
							sum += k * 850;
							sum -= (k / 3) * 850 * 3 * 0.12;
							if (sum < min) {
								min = sum;
							}
						}
					}
				}
			}
			System.out.println(min);
		}
	}
}

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

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> aa(n,0);
    for(int i = 0; i < n; i++){
        int ai;
        cin >> ai;
        aa[ai-1] += 1;
    }
    sort(aa.begin(), aa.end());
    int min = 0;
    for(int i = 0; i < n-k; i++ ){
        min += aa[i]; 
    }
    printf("%d\n", min);
}

Measured memory_bytes: 1024
n, m = map(int,input().split())
init_island = set()
last_island = set()
for _ in range(m):
    a,b = map(int,input().split())
    a,b = min(a,b), max(a,b)
    if a == 1:
        init_island.add(b)
    elif b == n:
        last_island.add(a)
    else:
        continue
common = init_island.intersection(last_island)
if len(common) >= 1:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Measured memory_bytes: 23980
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;

vector< pair<int,int> > V;
vector< pair< pair<int,int>,int> > E;
vector<pair<int,int> > G[500005];
int dist[500005];

map<pair<int,int>,int> mp;
int main(){
    int N,M;
    cin>>N>>M;
    for(int i = 0;i < M;i++){
        int p,q,c;
        cin>>p>>q>>c;
        E.push_back(make_pair(make_pair(p,q),c));
        V.push_back(make_pair(p,c));
        V.push_back(make_pair(q,c));
    }
    for(int i = 1;i <= N;i++){V.push_back(make_pair(i,0));}
    for(int i = 0;i<500005;i++)dist[i]=-1;
    sort(V.begin(),V.end());
    V.resize(unique(V.begin(),V.end()) -V.begin());
    int vsize = V.size();
    for(int i = 0;i < vsize;i++){
        mp[V[i]]=i;
    }
    for(int i = 0;i < E.size();i++){
        int p,q,c;
        p=E[i].first.first;
        q=E[i].first.second;
        c=E[i].second;
        G[mp[make_pair(p,c)]].push_back(make_pair(0,mp[make_pair(q,c)]));
        G[mp[make_pair(q,c)]].push_back(make_pair(0,mp[make_pair(p,c)]));
        G[mp[make_pair(p,c)]].push_back(make_pair(0,mp[make_pair(p,0)]));
        G[mp[make_pair(p,0)]].push_back(make_pair(1,mp[make_pair(p,c)]));
        G[mp[make_pair(q,c)]].push_back(make_pair(0,mp[make_pair(q,0)]));
        G[mp[make_pair(q,0)]].push_back(make_pair(1,mp[make_pair(q,c)]));
    }
    priority_queue<pair<int,int> ,vector<pair<int,int> > ,greater<pair<int,int> > > pq;
    pq.push(make_pair(0,mp[make_pair(1,0)]));
    while(!pq.empty()){
        pair<int,int> top = pq.top();
        pq.pop();
        int d = top.first;
        int v = top.second;
        //cout<<"a: "<<d<<" "<<V[v].first<<" "<<V[v].second<<" "<<endl;
        if(dist[v]==-1||dist[v] > d){
            dist[v] = d;
            for(int i = 0; i < G[v].size(); i++){
                pq.push(make_pair(G[v][i].first + d, G[v][i].second));
            }
        }
    }
    cout<<dist[mp[make_pair(N,0)]]<<endl;
}


Measured memory_bytes: 73472
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef vector<lld> vi;
typedef pair<lld,lld> pi;
#define F first
#define S second
#define N 100009
#define PB push_back
#define MP make_pair
#define rep(i,a,b) for (lld i = a; i < b; i++)
lld r,j,l,x,y,m,n,s,q,i,z,p,d,k,t,w,sz;string s1,s2,s3;
int main()
{ 
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);cout.tie(NULL);
  cin>>x>>y;
  if(x+y==15)cout<<"+";
    else if(x*y==15)cout<<"*";
    else cout<<"x";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

template<class T> struct BIT {
  int n, h;
  V<T> t;

  BIT(int n) : n(n), h(__lg(n) + 1) { t.assign(n + 1, (T) 0); }

  void add(int x, T a) {
    for (int i = x + 1; i < n + 1; i += i & -i) t[i] += a;
  }

  int lower_bound(T s) {
    if (s <= 0) return 0;
    int res = 0;
    for (int k = 1 << h - 1; k; k >>= 1) if (res + k < n + 1 and t[res + k] < s) s -= t[res += k];
    return res + 1;
  }

  T sum(int x) {
    T res = 0;
    for (int i = x; i; i -= i & -i) res += t[i];
    return res;
  }

  T sum(int l, int r) {
    return sum(r) - sum(l);
  }
};

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  string s; cin >> s;
  int n = s.size();
  map<char, int> mp;
  for (int i = 0; i < n; i++) mp[s[i]]++;
  int odd = 0;
  for (auto&& e : mp) odd += e.second & 1;
  if (odd > 1) return cout << -1 << '\n', 0;
  V< pair<int, int> > a(n);
  V<> c(26);
  for (int i = 0; i < n; i++) {
    a[i].second = i;
    if (2 * ++c[s[i] - 'a'] - 1 == mp[s[i]]) a[i].first = 0;
    else if (2 * c[s[i] - 'a'] <= mp[s[i]]) a[i].first = -1;
    else a[i].first = 1;
  }
  sort(a.begin(), a.end());
  BIT<int> b(n);
  lint res = 0;
  for (int i = 0; i < n; i++) {
    res += b.sum(a[i].second, n);
    b.add(a[i].second, 1);
  }
  VV<> id(26);
  for (int i = 0; i < n; i++) id[s[a[i].second] - 'a'].push_back(i);
  for (int i = 0; i < n / 2; i++) a[i].second = i;
  for (int i = 0; i < 26; i++) {
    int j = 0, m = id[i].size();
    while (j < m - 1 - j) {
      a[id[i][m - 1 - j]].second = a[id[i][j]].second;
      j++;
    }
  }
  BIT<int> b2(n / 2);
  for (int i = (n + 1) / 2; i < n; i++) {
    res += b2.sum(a[i].second);
    b2.add(a[i].second, 1);
  }
  cout << res << '\n';
}

Measured memory_bytes: 4364
s=input()
n=len(s)
flag=0


for i in range((n-1)//2):
    if s[i]==s[n-1-i]==s[((n-1)//2)-1-i]:
        flag=flag+1

if flag==((n-1)//2):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <string>
#include <iomanip>
#include <deque>
using namespace std;
#define int long long
int n, m;
int mas[110000];
int ansx[110000];
vector <int> op[110000];
vector <int> cl[110000];
int dist(int a, int b) {
	if (a <= b) return b - a;
	else {
		return b + (m - a);
	}
}
int mindist(int a, int b, int x) {
	return min(dist(a, b), dist(x, b) + 1);
}
int mid(int a, int b, int x) {
	if (a <= b) {
		return x > a && x < b;
	}
	else {
		return x > a || x < b;
	}
}
signed main() {
#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	int go = 0;
	cin >> n >> m;
	for (int i = 1; i <= n; ++i) {
		cin >> mas[i];
	}
	for (int i = 2; i <= n; ++i) {
		ansx[1] += mindist(mas[i - 1], mas[i], 1);
		if (dist(mas[i - 1], mas[i]) <= 1) continue;
		if (mid(mas[i - 1], mas[i], 1)) ++go;
		op[mas[i - 1]].push_back(i - 1);
		cl[mas[i]].push_back(i - 1);
	}
	for (int x = 2; x <= m; ++x) {
		ansx[x] = ansx[x - 1];
		for (auto it : cl[x - 1]) {
			ansx[x]--;
			ansx[x] += dist(mas[it], mas[it + 1]);
		}
		ansx[x] -= go;
		go -= cl[x].size();
		go += op[x - 1].size();
	}
	//for (int i = 1; i <= m; ++i) cout << ansx[i] << ' ';
	cout << *min_element(ansx + 1, ansx + m + 1) << endl;	
}

Measured memory_bytes: 11776
n=int(input())
arr=[int (x) for x in input().split()]
q=arr[:]
i,j=0,1
ans=0
while i<n and j<n:
    if arr[i]>arr[j]:
        arr[j]=arr[i]
    i+=1
    j+=1
print(sum(arr)-sum(q))

Measured memory_bytes: 32204
#include <stdio.h>
#define MAX 500004

int heap[MAX], h;

void maxHeapify(int);
void buildMaxHeap();

int main(){
  int a;

  scanf("%d",&h);
  for(a = 1; a <= h; a++) scanf("%d",&heap[a]);

  buildMaxHeap();

  for(a = 1; a <= h; a++) printf(" %d",heap[a]);
  printf("\n");

  return 0;
}

void buildMaxHeap(){
  int a;
  for(a = h/2; a > 0; a--) maxHeapify(a);
}

void maxHeapify(int a){
  int l=2*a, r=2*a+1, largest, temp;

  if(l <= h && heap[l] > heap[a]) largest = l;
  else largest = a;
  if(r <= h && heap[r] > heap[largest]) largest = r;
  if(largest != a){
    temp = heap[a];
    heap[a] = heap[largest];
    heap[largest] = temp;
    maxHeapify(largest);
  }
}



Measured memory_bytes: 3664
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int N;
ll A[100009], ret[100009];
vector<int> V;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>N;
    map<ll,ll> M;
    rep(i,N) cin>>A[i], M[A[i]]++;
    V.push_back(0);
    rep1(i,N-1) if(A[V.back()]<A[i]) V.push_back(i);
    rrep(i,V.size()-2){
        while(M.rbegin()->first>A[V[i]]){
            auto r=*M.rbegin();
            M.erase(r.first);
            ret[V[i+1]]+=(r.first-A[V[i]])*1LL*r.second;
            M[A[V[i]]]+=r.second;
        }
    }
    for(auto& r:M) ret[0]+=r.first*r.second;
    rep(i,N) cout1(ret[i]);
}

Measured memory_bytes: 9468
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll n;
    cin >> n;
    vll vec(n);
    REP(i, n) cin >> vec.at(i);
    ll score_alice = 0;
    sort(ALL(vec));
    reverse(ALL(vec));
    for (int i = 0; i < vec.size(); i += 2) {
        score_alice += vec.at(i);
    }
    ll sum = accumulate(ALL(vec), 0);
    cout << score_alice - (sum - score_alice) << endl;
    return 0;
}

Measured memory_bytes: 256