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

using namespace std;

const int N = 1e5+7;

struct Euler
{
    int tot = 0;
    int prime[N];
    bool check[N];
    bool& operator [] (const int i) { return check[i]; }
    void init(int sz) {
        tot = 0;
        for (int i = 1; i <= sz; ++i) check[i] = true;
        check[1] = false;
        for (register int i = 2, j; i <= sz; ++i) {
            if (check[i]) prime[++tot] = i;
            for (j = 1; j <= tot && i*prime[j] <= sz; ++j) {
                check[i*prime[j]] = false;
                if (i%prime[j] == 0) break;
            }
        }
    }
} E;

int x;

int main()
{
    cin >> x;
    E.init(1e5+3);
    for (int i = 1; i <= E.tot; ++i) {
        if (E.prime[i] >= x) {
            cout << E.prime[i] << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 384
#include<cstdio>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#define rep(X,Y) for(int (X)=0;(X)<(Y);++(X))
#define reps(i,j,k) for(int i=j;i<=k;i++)
#define pb push_back

typedef long long ll;
using namespace std;

#define MAX 300000
int prime[MAX];
vector<int> primes;

int main(){
	prime[0] = prime[1] = 1;
  for(int i=2;i<MAX;++i){
    if(prime[i])continue;
    primes.pb(i);
    for(int j=i*2;j<MAX;j+=i)
      prime[j]=1;
  }
  int n,p;
  while(cin >> n >> p){
	if(n<0)break;
	vector<int> v,w;
	for(int i=n+1;i<MAX&&v.size()<p;i++){
		if(!prime[i]) v.pb(i);
	}
	rep(i,v.size())reps(j,i,v.size()-1){
		w.pb(v[i]+v[j]);
	}
	sort(w.begin(),w.end());
	cout << w[p-1] << endl;
	//rep(i,w.size())cout << w[i] << endl;
  }
  //rep(i,10)cout<<primes[i]<<",";cout<<endl;
}

Measured memory_bytes: 2592
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define df 0


int main(){
  int a,b;
  scanf("%d%d",&a,&b);
  if((a+b)&1)printf("IMPOSSIBLE\n");
  else  printf("%d",(a+b)/2);
  return 0;
}


/// confirm df==0 ///

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


def get_input() -> str:
    """
    標準入力を取得する.

    Returns:
        str: 英大文字 ("A" - "Z") または英小文字 ("a" - "z")
    """
    alpha = str(input())

    return alpha


def main(alpha: str) -> None:
    """
    求解処理を行う.

    Args:
        alpha (str): 英大文字 ("A" - "Z") または英小文字 ("a" - "z")
    """
    # 求解処理
    ans = str()
    if alpha.isupper():
        ans = "A"
    elif alpha.islower():
        ans = "a"

    # 結果出力
    print(ans)


if __name__ == "__main__":
    alpha = get_input()
    main(alpha)


Measured memory_bytes: 9004
import java.util.Scanner;

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

		int k = scan.nextInt();
		int sum = 0;

		for(int a = 1;a <= k;a++) {
			for(int b = 1;b <= k;b++) {
				for(int c = 1;c <= k;c++) {
					sum += gcd(gcd(c , b) , a);
				}
			}
		}

		System.out.println(sum);
	}

	public static int gcd(int a , int b) {
		if(b == 0) {
			return a;
		}

		return gcd(b , a % b);
	}
}


Measured memory_bytes: 35596
from itertools import accumulate

n, k = list(map(int, input().split()))
vvv = list(map(int, input().split()))

dpl, dpr = [-10 ** 9] * (k + 1), [-10 ** 9] * (k + 1)
dpl[0] = dpr[0] = 0

for i in range(min(n, k)):
    i += 1
    vv = vvv[:i]
    vv.sort(reverse=True)
    sm = sum(vv)
    dpl[i] = max(dpl[i], sm)
    # print(i, vv, dpl)
    while i < k and vv:
        sm -= vv.pop()
        i += 1
        dpl[i] = max(dpl[i], sm)
    # print(i, vv, dpl)

vvv.reverse()

for i in range(min(n, k)):
    i += 1
    vv = vvv[:i]
    vv.sort(reverse=True)
    sm = sum(vv)
    dpr[i] = max(dpr[i], sm)
    # print(i, vv, dpr)
    while i < k and vv:
        sm -= vv.pop()
        i += 1
        dpr[i] = max(dpr[i], sm)
    # print(i, vv, dpr)

# print(dpl)
# print(dpr)
acl = list(accumulate(dpl, func=max))
acr = list(accumulate(dpr, func=max))
# print(acl)
# print(acr)
ans = 0
for i in range(k + 1):
    ans = max(ans, acl[i] + acr[k - i])
max_ans = sum(v for v in vvv if v > 0)
ans = min(ans, max_ans)
print(ans)


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout<< (x) << " "

int main(){
    int a,b,c;cin>>a>>b>>c;
    for(int i=1;i<=b;i++){
        if(i*a%b==c){co("YES");return 0;}
    }
    co("NO");
}

Measured memory_bytes: 256
abcd = input()

def train_ticket(flg,sum,op):
    if flg == 0:
        if train_ticket(flg + 1, sum, op + "+"):
            return True
        elif train_ticket(flg + 1, sum, op + "-"):
            return True
    if flg >= len(abcd):
        if operation(sum, op[-1], flg) == 7:
            print("".join([abcd[i] + op[i+1] for i in range(len(op) - 1)]) + abcd[-1] + "=7")
            return True
        else:
            return False
    if train_ticket(flg + 1, operation(sum, op[-1], flg), op+"+"):
        return True
    elif train_ticket(flg + 1, operation(sum, op[-1], flg), op+"-"):
        return True

def operation(sum, op, flg):
    if op == "+":
        return sum + int(abcd[flg - 1])
    else:
        return sum - int(abcd[flg - 1])

train_ticket(0, 0, "")

Measured memory_bytes: 3064
n = gets.to_i
cnt = -1
max_n = 1
(1..n).each do |i|
  next unless i.even?
  c = 0
  _i = i
  while _i.even? do
    _i /= 2
    c += 1
  end
  if c > cnt
    cnt = c
    max_n = i
  end
end

puts max_n

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

int main()
{
	int k;
	string s;
	cin>>k>>s;
	if(s.size()<=k)
		cout<<s;
	else
	{
		for(int i=0;i<k;i++)
			cout<<s[i];
		cout<<"...";
	}

	return 0;
}

Measured memory_bytes: 3628
#include<cstdio>
int main(){
  int n;
  scanf("%d", &n);
  for(int i = 0; i < n; i++){
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if(0 == -a*a+b*b+c*c ||
       0 == a*a-b*b+c*c ||
       0 == a*a+b*b-c*c)
      printf("YES\n");
    else
      printf("NO\n");
  }
}

Measured memory_bytes: 992
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

ll cnt[2020];

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

    int n=s.size();
    ll ans=0;

    cnt[0]=1;
    int tot=0;
    int p=1;
    for(int i=n-1;i>=0;i--){
        tot=(tot+(s[i]-'0')*p)%2019;

        ans+=cnt[tot];
        p=(p*10)%2019;
        cnt[tot]++;
    }

    cout<<ans<<endl;
}
    




Measured memory_bytes: 3760
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll a;
  cin >> a;
  ll ans,k=0;
  ll n=a;
  while(a>9){
    a/=10;
    k++;
  }
  ans=9*k+a-1;
  if((n+1)%(ll)pow(10,k)==0)ans++;
  cout << ans;
}


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

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

const ll MOD = 1e9+7;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

ll N;
vector<ll> A, B;
int main(int argc, char **argv)
{
	cin >> N;
	A.resize(N);
	B.resize(N);
	REP(i, N) cin >> A[i] >> B[i];

	if (N&1)
	{
		sort(ALL(A));
		sort(ALL(B));
		ll t = N/2;
		ll l = A[t];
		ll r = B[N-1-t];
		
		if (r >= l)
			std::cout << r-l+1 << std::endl;
		else
			std::cout << 0 << std::endl;
	}
	else
	{
		sort(ALL(A));
		sort(ALL(B));

		ll l = A[N/2-1]+A[N/2];
		ll r = B[N/2-1]+B[N/2];

		std::cout << r - l + 1 << std::endl;
	}
}



Measured memory_bytes: 6364
#include <bits/stdc++.h>
 
using namespace std;
 
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ss substr
typedef long long ll ;
typedef long double ld ;
typedef pair<ll, ll> pairs ;
typedef map<ll,ll> mapi ;
typedef map<string,string> maps ;


int main()
{
  //freopen("lifeguards.out", "w", stdout) ;
  //freopen("lifeguards.in", "r", stdin) ;
  ios_base::sync_with_stdio(0) ;
  cin.tie(NULL) ;
  cout.tie(NULL) ;
 
 //int t ; cin >> t ; while(t--){} 
 
 int a , b ; cin >> a >> b ;
 if ( a <= 9 && b <= 9 ) cout << a*b ;
 else cout << -1 ; 
   
 }
 
 



 


Measured memory_bytes: 256
import bisect as bi
n = int(input())
a = sorted(list(map(int,input().split())))
b = sorted(list(map(int,input().split())))
c = sorted(list(map(int,input().split())))
ans = 0
for i in range(len(b)):
        ans += bi.bisect_left(a,b[i]) *  (len(c) - bi.bisect_right(c,b[i]))
print(ans)

Measured memory_bytes: 23092
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>

using namespace std;

vector<int> search(int start, const vector<string>& S){
    const int N = S.size();
    vector<int> dist(N, N);
    queue<int> qu; qu.push(start);
    dist[start] = 0;
    while(!qu.empty()){
        int p = qu.front(); qu.pop();
        for(int t=0;t<N;t++){
            if(S[p][t] == '0') continue;
            if(dist[t] > dist[p] + 1){
                dist[t] = dist[p] + 1;
                qu.push(t);
            }
        }
    }
    return dist;
}

int solve(const vector<string>& S){
    const int N = S.size();
    vector<int> c(N, -1);
    c[0] = 0;
    queue<int> qu; qu.push(0);
    while(!qu.empty()){
        int p = qu.front(); qu.pop();
        for(int t=0;t<N;t++){
            if(S[p][t] == '0') continue;
            if(c[t] != -1){
                if(c[t] == c[p]) return -1;
                continue;
            }
            c[t] = 1 - c[p];
            qu.push(t);
        }
    }
    int res = 0;
    for(int i=0;i<N;i++){
        auto d = search(i, S);
        res = max(res, *max_element(d.begin(), d.end()));
    }
    return res + 1;
}

int main(){
    int N; cin >> N;
    vector<string> S(N);
    for(auto& s : S) cin >> s;
    cout << solve(S) << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args) throws Exception {
         
        Scanner sc = new Scanner(System.in);
        String card;
        int m = 0;
        int h = 0;
        int sum = 0;
        String ans1 = "";
        String ans2 = "";
        
        while( true ){
            
            card = sc.next();
            
             if(card.equals("-")) break;
            
            m = sc.nextInt();
                
            for(int i=0;i<m;i++){
                
                h = sc.nextInt();
                
                sum += h;
                
            }
            
          while( true ){
              if(sum>=card.length()){
                  sum-=card.length();
              }else{
                  break;
              }
              
          }
            ans2 = card.substring(sum);
               ans1 = card.substring(0,sum);
               System.out.println(ans2 + ans1);
            
            sum = 0;
            
         }
        sc.close();
    }
}


Measured memory_bytes: 26308
import collections, math, bisect

local = False
if local:
    file = open("input.txt", "r")
    import time

def inp():
    if local:
        return file.readline().rstrip()
    else:
        return input().rstrip()

def ints():
    return [int(_) for _ in inp().split()]


if local:
    start=time.time()

N = int(inp())

connection = [dict() for i in range(N)]

for i in range(1, N):
    u,v,w = ints()

    connection[u-1][v-1] = w
    connection[v-1][u-1] = w

colors = ["0"]*N
visited = set()

stck = [(0,0)]
visited.add(0)

while len(stck)>0:
    vertex, cur_dist = stck.pop(-1)

    if cur_dist%2==0:
        colors[vertex] = "0"
    else:
        colors[vertex] = "1"

    for nextVertex in connection[vertex]:
        if nextVertex not in visited:
            visited.add(nextVertex)
            stck.append((nextVertex, cur_dist+connection[vertex][nextVertex]))

for c in colors:
    print(c)


if local:
    fin = (time.time()-start)*1000
    print("{:.2f}".format(fin) + "ms")


Measured memory_bytes: 92960
#include<stdio.h>
int gcd(int, int);

int main(){
  int x, y, a;

  scanf("%d %d", &x, &y);

  if(x < y){
    a = x;
    x = y;
    y = a;
  }

  printf("%d\n", gcd(x, y));

  return 0;
}

int gcd(int x, int y){
  int r;
  while(y > 0){
    r = x % y;
    x = y;
    y = r;
  }

  return x;
};



Measured memory_bytes: 2084
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 1e-12
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

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

double dp[305][305][305];
int n;

double f(int i, int j, int k){
    if(i < 0 || j < 0 || k < 0)return 0;
    if(dp[i][j][k] != -1)return dp[i][j][k];
    if(i == 0 && j == 0 && k == 0) return dp[i][j][k] = 0;
    double ret = 1;
    ret += f(i-1,j,k)*i/n;
    ret += f(i+1,j-1,k)*j/n;
    ret += f(i,j+1,k-1)*k/n;
    ret *= 1.0*n/(i+j+k);
    dp[i][j][k] = ret;
    //cout << shosu(10) << i << " " << j << " " << k << " " << ret << endl;
    return ret;
}

signed main(void) {
    cin >> n;
    vi v(4);
    rep(i,n){
        int a;
        cin >> a;
        v[a]++;
    }
    rep(i,305)rep(j,305)rep(k,305)dp[i][j][k] = -1;
    cout << shosu(12) << f(v[1],v[2],v[3]) << endl;
}


Measured memory_bytes: 222080
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define EPS (1e-10)
#define EQ(a,b) (abs(a-b) < EPS)

int main(){


	int l[10];
	int station[11];
	char cm;
	while(cin>>l[0]>>cm>>l[1]>>cm>>l[2]>>cm>>l[3]>>cm>>l[4]>>cm>>l[5]>>cm>>l[6]>>cm>>l[7]>>cm>>l[8]>>cm>>l[9]){
		int sumlength=0;
		for(int i = 0; i < 10; i++)
			sumlength+=l[i];
		station[0]=0;
		for(int i = 1; i < 11; i++){
			station[i]=station[i-1]+l[i-1];
		}
		int v1,v2;
		cin>>cm;
		cin>>v1>>cm>>v2;
		double t = (double)(sumlength)/(v1+v2);
		double place=t*v1;
		for(int i = 0; i < 11; i++){
			if(EQ(station[i],(place))){
				cout<<i<<endl;
				break;
			}
			else if(station[i]<(place) && station[i+1] >(place)){
				cout<<i+1<<endl;
				break;
			}
		}
	}

	return 0;
}

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

int main(){
  ll N,x,cnt=0;
  cin >> N >> x;
  vector<ll> a(N);
  rep(i,N){
    cin >> a.at(i);
  }
  sort(a.begin(),a.end());
  rep(i,N){
    if(i==N-1&&x-a.at(i)!=0){
      break;
    }else if(x-a.at(i)>=0){
      ++cnt;
      x -= a.at(i);
    }else{
      break;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
n = int(input())
lis = [list(map(int,input().split())) for _ in range(n)]
# print(lis)
# [[10, 40, 70], [20, 50, 80], [30, 60, 90]]
#dp = [lis[0]+[0,0,0]*(n-1)]
#dp[0]=lis[0]
#dp = [lis[0][0]+[0]*(n-2),lis[0][1]+[0]*(n-2),lis[0][2+[0]*(n-2)]
dp = [[lis[0][0]]+[0]*(n-1),[lis[0][1]]+[0]*(n-1),[lis[0][2]]+[0]*(n-1)]
#print(dp)

for j in range(n):
    if j == 0:
        continue
    for i in range(3):
        if i == 0:
            dp[i][j] = max(dp[1][j-1],dp[2][j-1])+lis[j][i]
        if i == 1:
            dp[i][j] = max(dp[0][j-1],dp[2][j-1])+lis[j][i]
        if i == 2:
            dp[i][j] = max(dp[0][j-1],dp[1][j-1])+lis[j][i]

#print(dp)

print(max(dp[0][n-1],dp[1][n-1],dp[2][n-1]))

Measured memory_bytes: 43236
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <algorithm>
#include <typeinfo>
#define _USE_MATH_DEFINES
#include <cmath>
#include <stack>
#include <queue>

using namespace std;


int main(){

    int n;
    cin >> n;

    deque<int> deq;
    string str;
    int m;

    for(int i=0; i<n; i++){
        cin >> str;
        if(str=="insert"){
            cin >> m;
            deq.push_front(m);
        }else if(str=="deleteFirst"){
            deq.pop_front();
        }else if(str=="deleteLast"){
            deq.pop_back();
        }else if(str=="delete"){
            // 一番めんどくさい処理なので、最後に書いた
            cin >> m;
            deque<int>::iterator itr = deq.begin();
            while(itr != deq.end()){
                if(*itr==m){
                    deq.erase(itr);
                    break;
                }
                itr++;
            }

        }
    }
    //
    // while(!deq.empty()){
    //     cout << *deq.begin() << " ";
    //     deq.pop_front();
    // }

    int d_s = deq.size();
    for(int i=0; i<d_s; i++){
        if(i==d_s-1){
            cout << *deq.begin() << endl;
            break;
        }
        cout << *deq.begin() << " ";
        deq.pop_front();
    }


    return 0;
}



Measured memory_bytes: 6980
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;

int main() {
  ll n, k;
  cin >> n >> k;
  int res = k * pow(k - 1, n - 1);
  int digits = 0, d = res;
  while(d > 0) {
    d /= 10;
    digits++;
  }
  cout << fixed << setprecision(digits) << res << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()){
			int n=sc.nextInt();
			int count=0;
			boolean flag=true;
			String str[]=new String[n];
			int c[]=new int[n];
			for(int i=0; i<n; i++){
				str[i]=sc.next();
				c[i]=sc.nextInt();
			}
			
			for(int i=0; i<n; i++){
				
				if(str[i].equals("(")){
					count+=c[i];
				}
				else if(str[i].equals(")")){
					if(count==0){
						flag=false;
						break;
					}
					count-=c[i];
					if(count < 0){
						flag=false;
						break;
					}
				}
			}
			if(flag && count==0){
				System.out.println("YES");
			}
			else{
				System.out.println("NO");
			}
		}

	}

}

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

int main() {
  int n;
  long int p;
  long int min_p;
  long int c = 0;

  cin >> n;
  min_p = 200001 ;

  for ( int i=0 ; i < n ; ++i ) {
    cin >> p ;
    if (min_p > p){
      min_p = p;
      c++;
    } 
  }
  cout << c << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
#include<functional>
#include<stack>
#include<tuple>
#include<cassert>
using namespace std;

#define rep(i, n) for (long long i = 0; i < (long long)(n); ++i)
using P = pair<long long, long long>;

int main() {
  long long N, K;
  cin >> N >> K;
  long long s = N % K;
  long long t = K - s;
  long long ans = min(s, t);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3508
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
const int INF = 2000000000;

int a, b;

int main(){
  cin >> a >> b;
  int digit = 0;
  int tmp = b;
  while(tmp > 0){
    digit++;
    tmp /= 10;
  }
  int k = a*pow(10, digit) + b;
  rep(i, 1000){
    if(k == i * i){
      cout << "Yes" <<endl;
      return 0;
    }
  }
  cout << "No" <<endl;
}

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

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
  	cin.tie(0);
	
	int r, d, x;
	cin >> r >> d >> x;
	for (int i = 0; i < 10; i++) {
		x = r * x - d;
		cout << x << endl;
	}
    return 0;
}


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

int main(){
	int n;
	scanf("%d", &n);
	multiset<int> rem;
	for(int i = 0; i < (1 << n); ++i){
		int x;
		scanf("%d", &x);
		rem.insert(-x);
	}

	multiset<int> cur;
	cur.insert(*rem.begin());
	rem.erase(rem.begin());
	for(int i = 0; i < n; ++i){
		multiset<int> nxt = cur;
		for(auto x : cur){
			auto it = rem.upper_bound(x);
			if(it == rem.end()){
				puts("No");
				return 0;
			}
			nxt.insert(*it);
			rem.erase(it);
		}
		nxt.swap(cur);
	}
	puts("Yes");
}


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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
   void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

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

int main() {
   int N;
   cin >> N;
   vec<int> p(N);
   vec<int> d(N);
   rep (i, N) {
      cin >> p[i];
      p[i]--;
   }

   int cnt = 0;
   repp (i, 0, N-1) {
      if (p[i] == i) {
         swap(p[i], p[i+1]);
         cnt++;
      }
   }
   if (p[N-1] == N-1) {
      cnt++;
   }
   cout << cnt << endl;

   return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<iostream>
#include<ctype.h>
#include<string>
using namespace std;
int main(){
	int N, total = 0;
	cin >> N;
	int V[N], C[N];
	for(int i = 0; i < N; i++){
		cin >> V[i];
	}
	for(int i = 0; i < N; i++){
		cin >> C[i];
	}
	for(int i = 0; i < N; i++){
		if(V[i] - C[i] > 0){
			total += V[i] - C[i];
		}
	}
	cout << total << endl;
	return 0;
}

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

int main(){
  int n;cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++) cin>>a[i];
  int M=*max_element(a.begin(),a.end());
  int m=-1;
  int tmp;
  for(int i=0;i<n;i++){
    if(a[i]==M) continue;
    if(m==-1||tmp>abs(2*a[i]-M)){
      tmp=abs(2*a[i]-M);
      m=a[i];
    }
  }
  cout<<M<<' '<<m<<endl;
  return 0;
}

Measured memory_bytes: 640
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

//std::cout << std::fixed << std::setprecision(10)
constexpr long long MOD = 1000000007;

int main()
{
  int N, M;
  std::cin >> N >> M;
  std::vector<std::vector<int>> edges(N * 3);
  while (M--)
  {
    int u, v;
    std::cin >> u >> v;
    --u;
    --v;
    edges[u].push_back(v + N);
    edges[u + N].push_back(v + 2 * N);
    edges[u + 2 * N].push_back(v);
  }
  int S, T;
  std::cin >> S >> T;
  --S;
  --T;
  std::vector<bool> memo(N * 3, false);
  std::queue<std::pair<int, int>> q;
  q.push({S, 0});
  memo[S] = true;
  while (!q.empty())
  {
    auto pair = q.front();
    q.pop();
    auto u = pair.first;
    auto w = pair.second;
    if (u == T)
    {
      std::cout << w / 3 << std::endl;
      return 0;
    }
    for (auto v: edges[u])
    {
      if (!memo[v])
      {
        memo[v] = true;
        q.push({v, w + 1});
      }
    }
  }
  std::cout << -1 << std::endl;
  return 0;
}



Measured memory_bytes: 16640
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner s=new Scanner(System.in);
		int n=s.nextInt(),Q=s.nextInt();
		char[] c=s.next().toCharArray();

		char[] q=new char[Q];
		boolean[] f=new boolean[Q];
		for(int i=0;i<Q;++i){
			q[i]=s.next().charAt(0);
			f[i]=s.next().charAt(0)=='L';
		}

		int l=0,r=n;
		for(int i=Q-1;i>=0;--i){
			if(f[i]){
				if(l<n&&c[l]==q[i]) ++l;
				if(r<n&&c[r]==q[i]) ++r;
			}else{
				if(l>0&&c[l-1]==q[i]) --l;
				if(r>0&&c[r-1]==q[i]) --r;
			}
		}
		System.out.println(r-l);
	}
}


Measured memory_bytes: 64892
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<iomanip>
#include<map>
#include<cstring>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vi vector<int>
#define vivi vector<vi>
const int INF = int(1e9);
typedef long long int ll;

int main(){
    int H, W, K; cin >> H >> W >> K;
    string S[H];
    int ans = INF;
    rep(i, H)cin >> S[i];
    for(int bit = 0;bit < (1 << (H - 1));++bit){//横のどこを割るか決定
        int div[H];
        div[0] = 0;
        int count = 0;
        for(int i = 0;i < H - 1;++i){
            if((1 << i) & bit){
                div[i + 1] = div[i] + 1;
                ++count;
            }
            else{
                div[i + 1] = div[i];
            }
        }
        vi sum(H);
        bool notflg;
        for(int w = 0;w < W;++w){
            vi tmpsum(H);
            bool flg = false;
            notflg = false;
            for(int h = 0;h < H;++h){
                if(S[h][w] == '1'){
                    tmpsum[div[h]] += 1;
                    sum[div[h]] += 1;
                }
                if(sum[div[h]] > K)flg = true;
                if(tmpsum[div[h]] > K)notflg = true;
            }
            if(notflg)break;
            if(flg){
                ++count;
                sum = tmpsum;
            }

        }
        if(!notflg)ans = min(ans, count);
    }
    cout << ans << endl;
}


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

#define rep(i,n) for(int i=0;i<(int)n;i++)
typedef long long lint;
#define SZ(x) ((int)(x).size())
int main()
{
	int A, B;
	cin >> A >> B;
	int  ans =max(A+B,A-B);
	ans = max(ans, A*B);
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 256
#!/usr/bin/env python3
# DPL_1_E: Combinatorial - Edit Distance (Levenshtein Distance)
# D[i][j] = if s1[i] == s2[j]: D[i-1][j-1]
#           else: min(D[i-1][j-1], D[i-1][j], D[i][j-1]) + 1


def levenshtein_distance(str1, str2):
    l1, l2 = len(str1), len(str2)

    dp = [i for i in range(l2+2)]
    dp[l2+1] = l1 * l2
    dq = dp[:]

    for i, c1 in enumerate(str1):
        dq[0] = i+1
        for j, c2 in enumerate(str2):
            if c1 == c2:
                dq[j+1] = dp[j]
            else:
                dq[j+1] = min(dp[j], dp[j+1], dq[j]) + 1
        dp, dq = dq, dp

    return dp[l2]


def run():
    s1 = input()
    s2 = input()

    print(levenshtein_distance(s1, s2))


if __name__ == '__main__':
    run()



Measured memory_bytes: 5584
#include <bits/stdc++.h>
#define reg register
#define ll long long
#define vi vector<int>
#define pb push_back
#define SZ(x) (int) x.size()
using namespace std;
int a, b;
void work() {
  scanf("%d%d", &a, &b);
  if(a - 2 * b <= 0) puts("0");
  else printf("%d\n", a - 2 * b);
}
int main() {
  int _ = 1;
  // scanf("%d", &_);
  while(_--) work();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int n;
    cin >> n;
    vector<ll> a(n), b(n);
    ll suma = 0;
    ll sumb = 0;
    rep(i, n) {
        cin >> a[i];
        suma += a[i];
    }
    rep(i, n) {
        cin >> b[i];
        sumb += b[i];
    }
    if (suma < sumb) {
        cout << -1 << endl;
        return 0;
    }
    vector<ll> dif(n);
    rep(i, n) {
        dif[i] = a[i] - b[i];
    }
    sort(dif.begin(), dif.end());
    ll now_sum = 0;
    int ans = 0;
    rep(i, n) {
        if (dif[i] < 0) {
            now_sum += abs(dif[i]);
            ++ans;
        }
    }
    //cout << now_sum << endl;
    reverse(dif.begin(), dif.end());
    rep(i, n) {
        if (dif[i] < 0 || now_sum <= 0) break;
        now_sum = max(now_sum-dif[i], 0LL);
        ++ans;
    }
    cout << ans << endl;
    return 0;
}


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

#define INF (int)1e9+7
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define vll vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define N 100005
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795



ll binPowM(ll a,ll b, ll m)
{ 
  ll ans=1;
  while(b>0)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }
return ans%m;
}
ll f(ll x,ll y,ll a)
{
  return (a&x)*(a&y);
}

int main()
{  
  
ll n,w;cin>>n>>w;

vector<pair<ll,ll>>v;

map<ll,vector<ll>>m;

ll a,b;

for(int i=1;i<=n;i++)
{
  cin>>a>>b;
  m[a].pb(b);
}
vector<ll>store[4];
ll y=0;
while(y!=4)
{
    store[y].pb(0);
    y++;
}
y=0;
vector<ll>wt(4);
for(auto x:m)
{
  wt[y]=x.first;
  sort(x.second.begin(),x.second.end(),greater<>());
  ll temp=0,val=0;
 // store[y].pb(val);
  for(int i=0;i<x.second.size();i++)
  {
      temp+=x.first;
      if(temp>w)break;
      else 
        {
          val+=x.second[i];
          store[y].pb(val);
        }
  }
y++;
}

/*
for(int i=0;i<4;i++)
{
    for(int j=0;j<store[i].size();j++)cout<<store[i][j]<<" ";
    cout<<endl;
}
cout<<wt[0]<<wt[1]<<wt[2]<<wt[3]<<"\n";*/
ll ans=0;

for(int i=0;i<store[0].size();i++)
{
  for(int j=0;j<store[1].size();j++)
  {
    for(int k=0;k<store[2].size();k++)
    {
      for(int l=0;l<store[3].size();l++)
        {
          if(i*wt[0]+j*wt[1]+k*wt[2]+l*wt[3]<=w)
          {
            ans=max(ans,store[0][i]+store[1][j]+store[2][k]+store[3][l]);
          }
        }
    }
  }
}

cout<<ans<<"\n";


  return 0;

}





Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }
        HashMap<Integer, ArrayList<Integer>> map = new HashMap<>();
        for (int i = 0; i < m; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            map.computeIfAbsent(a, k -> new ArrayList<>()).add(b);
            map.computeIfAbsent(b, k -> new ArrayList<>()).add(a);
        }
        int ans = 0;
        parent: for (int i = 1; i <= n; i++) {
            ArrayList<Integer> list = map.get(i);
            if (list == null) {
                ans++;
                continue;
            }
            for (Integer v: list
                 ) {
                if (h[v - 1] >= h[i - 1]) {
                    continue parent;
                }
            }
            ans++;
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 75108
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

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

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)

	N, M := getInt(), getInt()
	a := make([]int, N)
	sum := 0
	for i := 0; i < N; i++ {
		a[i] = getInt()
		sum += a[i]
	}
	th := 4 * M
	th = (sum + th - 1) / th
	// out(th)
	cnt := 0
	for i := 0; i < N; i++ {
		if a[i] >= th {
			cnt++
		}
	}

	if cnt >= M {
		out("Yes")
	} else {
		out("No")
	}

}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define SORTD(s) sort((s).rbegin(),(s).rend())
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
#define PI 3.14159265358979323846264338327950L
const int mod=1000000007,MAX=200005,INF=1<<30;

const int MAX_N = 110;
const int MAX_V = 100100;

	int n;
  	ll w,weight[110],value[110];
  
  	ll dp[110][110110]={0};


int main() {
  cin>>n>>w;
  rep(i,n){
  	cin>>weight[i]>>value[i];
  }
  for(int i=0;i<n;i++)cin>>weight[i]>>value[i];
  
  for(int i=0;i<MAX_N;i++){
  	for(int j=0;j<MAX_V;j++){
    	dp[i][j]=INF;
    }
  }
  
  dp[0][0]=0;
  
  for(int i=0;i<n;i++){
  	for(int sum_v=0;sum_v<=MAX_V;sum_v++){
    	if(sum_v-value[i]>=0){
        	chmin(dp[i+1][sum_v],dp[i][sum_v-value[i]]+weight[i]);
        }
      
      chmin(dp[i+1][sum_v],dp[i][sum_v]);
    }
  }
	ll res=0;
  	for(int sum_v=0;sum_v<MAX_V;sum_v++){
    	if(dp[n][sum_v]<=w)res=sum_v;
    }

	cout<<res<<endl;
}

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

using namespace std;

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

  double suml = 0;
  double numl = 0;
  vector<double> Xn;
  vector<double> Yn;
  for(int i=0;i<N;i++){
    double x;
    double y;
    cin >> x >> y;

    for(int j=0;j<i;j++){
      suml += sqrt(pow(Xn[j]-x,2)+pow(Yn[j]-y,2));
      numl += 1;
    }

    Xn.push_back(x);
    Yn.push_back(y);
  }

  double result = (N-1)*(suml/numl);

  cout<<setprecision(15)<<result<<endl;

  return 0;
}

Measured memory_bytes: 256
N, x = map(int, input().split())
a = list(map(int, input().split()))

cnt = 0

if a[0] > x:
    cnt += a[0] - x
    a[0] = x

for i in range(0, N - 1):
    total = a[i] + a[i + 1]
    if total > x:
        diff = total - x
        a[i + 1] -= diff
        cnt += diff
print(cnt)


Measured memory_bytes: 14548
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left!=NIL){
    x=x->left;
  }
  return x;
}

Node treeMaximum(Node x){
  while(x->right!=NIL){
    x=x->right;
  }
  return x;

}

Node treeSearch(Node u, int k){
  if((u==NIL)||(k==u->key)){
    return u;
  }
  if(k<u->key){
    return treeSearch(u->left,k);
  }else{
    return treeSearch(u->right,k);
  }
  
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right!=NIL){
    return treeMinimum(x->right);
  }
  y=x->parent;
  while((y!=NIL)&&(x==y->right)){
    x=y;
    y=y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if((z->left==NIL)||(z->right==NIL)){
    y=z;
  }else{
    y=treeSuccessor(z);
  }
  if(y->left!=NIL){
    x=y->left;
  }else{
    x=y->right;
  }

  if(x!=NIL){
    x->parent=y->parent;
  }

  if(y->parent==NIL){
    root=x;
  }else if(y==y->parent->left){
    y->parent->left=x; 
  }else{
    y->parent->right=x;
  }

  if(y!=z){
    z->key=y->key;
  }

}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if((z->key)<(x->key)){
      x = x->left;
    }else{
      x = x->right;
    }
  }

  z->parent=y;

  if(y==NIL){
    root=z;
  }else if((z->key) < (y->key)){
    y->left=z;
  }else{
    y->right=z;
  }
}

void inorder(Node u){
  if(u==NIL){
    return;
  }
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
  
}
void preorder(Node u){
  if(u==NIL){
    return;
  }
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 20496
import math
import sys


sys.setrecursionlimit(2000)

def power(x, y):
    if   y == 0     : return 1
    elif y == 1     : return x % mod
    elif y % 2 == 0 : return power(x, y/2)**2 % mod
    else            : return power(x, y/2)**2 * x % mod

mod = 998244353
n, m, k = [int(_) for _ in input().split()]


g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, n + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

# print(g1)
# print(g2)
# print(inverse)

ans = 0
for i in range(k+1):
    ans += g1[n-1] * g2[n-1-i] * m * pow(m-1, n-1-i, mod) * g2[i]
    ans %= mod


print(ans)

# print(pow(2, mod-2, mod))
# print(power(2, mod-2))


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


typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;

#define pb push_back
#define popb pop_back
#define si size()
#define be begin()
#define en end()
#define le length()
// #define mp make_pair
#define mt make_tuple
#define fi first
#define se second

#define forz(i,n) for( int i=0;i<n;i++)
#define forl(i, n) for(int i = 1; i<= n; i++)
#define deci(n)  fixed<<setprecision(n)
#define high(n) __builtin_popcount(n)
#define parity(n) __builtin_parity(n)
#define ctz(n)  __builtin_ctz(n)
#define mod 1000000007
#define mod2 998244353
#define kira ios::sync_with_stdio(0), cin.tie(0),cout.tie(0)

using namespace std;

void cpc()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w" , stdout);
#endif
}

int main()
{
	
	lli n;
	cin >> n;
	ldb area = 3.14159;
	area = area * 2 * n;
	cout << area << endl;

	return 0;
}

Measured memory_bytes: 3756
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;

int main(){
    int N,K;
    cin >> N >> K;
    LL ans=0;
    for(int i=K+1;i<=N;i++){
        ans+=N/i*(i-K);
        ans+=max(N%i-K+1,0);
    }
    if(K==0) ans-=N;
    cout << ans << endl;
    return 0;
}

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

int main(void)
{
    long long D;
    cin >> D;
    vector<long long> c(26);
    vector<vector<long long>> used(26);
    for (long long i = 0; i < 26; i++)
    {
        cin >> c[i];
        used[i].push_back(-1);
    }
    vector<vector<long long>> s(D,vector<long long>(26));
    for (long long i = 0; i < D; i++)
    {
        for (long long j = 0; j < 26; j++)
        {
            cin >> s.at(i).at(j);
        }
    }

    long long lastnum = 0;
    vector<long long> ans(D);
    for (long long i = 0; i < D; i++)
    {
        long long pena = 0;
        for (long long j = 0; j < 26; j++)
        {
            pena += c[j] * (i - used.at(j).at(used[j].size() - 1));
        }
        ans[i] = -1;
        long long cnt = -100000000;
        for (long long j = 0; j < 26; j++)
        {
            pena -= c[j] * (i - used.at(j).at(used[j].size() - 1));
            if (s.at(i).at(j) - pena > cnt)
            {
                ans[i] = j;
                cnt = s.at(i).at(j) - pena;
            }
            pena += c[j] * (i - used.at(j).at(used[j].size() - 1));
        }
        used[ans[i]].push_back(i);
        lastnum += cnt;
    }

    while(clock() <  1.9 * CLOCKS_PER_SEC)
    {
        long long cnt = 100000000;
        long long ranD = rand() % D;
        long long ranq = rand() % 26;
        for (long long i = 0; i < 26; i++)
        {
            if (i != ans[ranD])
            {
                if (abs(s.at(ranD).at(ans[ranD]) - s.at(ranD).at(i)) < cnt)
                {
                    ranq = i;
                    cnt = abs(s.at(ranD).at(ans[ranD]) - s.at(ranD).at(i));
                }
            }
        }

        used[ans[ranD]].erase(remove(used[ans[ranD]].begin(), used[ans[ranD]].end(), ranD), used[ans[ranD]].end());
        used[ranq].push_back(ranD);
        sort(used[ranq].begin(), used[ranq].end());
        long long oldans = ans[ranD];
        ans[ranD] = ranq;

        long long newnum = 0;
        for (long long i = 0; i< D; i++)
        {   
            newnum += s.at(i).at(ans[i]);
        }
        for (long long j = 0; j < 26; j++)
        {
            long long pena = 0;
            for (long long i = 0; i < used[j].size(); i++)
            {
                if ( i == used[j].size() - 1)
                {
                    pena += c[j] * (D - used[j][i] - 1) * (D - used[j][i]) / 2;
                }
                else
                {
                    pena += c[j] * (used[j][i+1] - used[j][i]) * (used[j][i+1] - used[j][i] - 1) / 2;
                }
            }
            newnum -= pena;
        }
        
        if(newnum <= lastnum)
        {
            ans[ranD] = oldans;
            used[ranq].erase(remove(used[ranq].begin(), used[ranq].end(), ranD), used[ranq].end());
            used[ans[ranD]].push_back(ranD);
            sort(used[ans[ranD]].begin(), used[ans[ranD]].end());
        }
        else
        {
            lastnum = newnum;
        }
    }

    for (long long i = 0; i < D; i++)
    {
        cout << ans[i]+1 << endl;
    }
}

Measured memory_bytes: 3744
#include <iostream>
#include <algorithm>
#define llint long long

using namespace std;

llint n, k;
llint h[200005];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> k;
	for(int i = 1; i <= n; i++) cin >> h[i];
	sort(h+1, h+n+1);
	
	llint ans = 0;
	for(int i = 1; i <= n-k; i++) ans += h[i];
	cout << ans << endl;
	
	return 0;
}

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

struct Card {
    char suit;
    int value;
};

void printCards(Card A[], int N) {
    for (int i = 0; i < N; i++) {
        if (i != 0) cout << " ";
        cout << A[i].suit << A[i].value;
    }
    cout << endl;
}

void bubbleSort(Card A[], int N) {
    for (int i = 0; i <= N - 1; i++) {
        for (int j = N - 1; j >= i + 1; j--) {
            if (A[j].value < A[j - 1].value) {
                swap(A[j], A[j - 1]);
            }
        }
    }
    printCards(A, N);
}

void selectionSort(Card A[], int N) {
    for (int i = 0; i <= N - 1; i++) {
        int min_j = i;
        for (int j = i; j <= N - 1; j++) {
            if (A[j].value < A[min_j].value) min_j = j;
        }
        swap(A[i], A[min_j]);
    }
    printCards(A, N);
}

bool isStable(Card in[], Card out[], int N) {
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            for (int k = 0; k < N; k++) {
                for (int l = k + 1; l < N; l++) {
                    if (
                        in[i].value == in[j].value
                        && in[i].suit == out[l].suit && in[i].value == out[l].value
                        && in[j].suit == out[k].suit && in[j].value == out[k].value
                    )
                        return false;
                }
            }
        }
    }
    return true;
}

void printStability(Card in[], Card out[], int N) {
    if (isStable(in, out, N)) {
        cout << "Stable" << endl;
    } else {
        cout << "Not stable" << endl;
    }
}

int main() {
    int N;
    cin >> N;
    Card A[N], A1[N], A2[N];
    for (int i = 0; i < N; i++) {
        cin >> A[i].suit >> A[i].value;
        A1[i] = A2[i] = A[i];
    }

    bubbleSort(A1, N);
    printStability(A, A1, N);

    selectionSort(A2, N);
    printStability(A, A2, N);

    return 0;
}



Measured memory_bytes: 3124
import java.util.Arrays;
import java.util.Scanner;
import java.util.TreeSet;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] t = new int[n];
        for (int i = 0; i < n; i++) {
            t[i] = sc.nextInt();
        }
        int maxValue = Arrays.stream(t).max().getAsInt();
        TreeSet<Integer> set = new TreeSet<>();
        for (int i = 1; i <= maxValue; i++) {
            if(maxValue % i == 0) set.add(i);
        }
        long ans = 0;
        for (int num: t) {
            ans += set.ceiling(num) - num;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 72644
#include <iostream>
#include <cstdint>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <random>

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define loop(i, a, b) for (int i = a; i < (int)(b); i++)

const int offset = 1000000;

int main()
{
    double a, b;
    cin >> a >> b;
    int ans = ceil((b - 1) / (a - 1));
    cout << ans << "\n";
    return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <cassert>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'
#define FIR first
#define SEC second
#define PB push_back
#define SZ(x) ((int)x.size())

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

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

template<class T>
ostream& operator <<(ostream& out, vector<T> vec) {
    for (T& e : vec)
        out << e << " ";
    return out << endl;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

void solveSingleCase(int caseNo)
{
    int A, B, K;
    cin >> A >> B >> K;

    int last = A;
    FOR(a, A, min(A + K, B + 1)) {
        cout << a << endl;
        last = a;
    }

    FOR(a, max(last + 1, B - K + 1), B + 1)
        cout << a << endl;
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int T = 1;
    // cin >> T;
    FOR(tcase, 1, T + 1) {
        solveSingleCase(tcase);
    }
    return 0;
};


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

int main() {
    int n, l;

    cin >> n >> l;
    
    int taste[n];
    taste[0] = l;
    int ori_sum = taste[0];
    for (int i = 1;i < n;i++) {
        taste[i] = l+i;
        ori_sum += taste[i];
    }

    int mini_abs = INT_MAX;
    for (int i = 0;i < n;i++) {
        int val = abs(taste[i]);
        if (val < mini_abs) mini_abs = val;
    }

    if (ori_sum < 0) cout << ori_sum + mini_abs << endl;
    else cout << ori_sum - mini_abs << endl;
}


Measured memory_bytes: 256