akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <queue>
#include <vector>
#include <utility>
#include <climits>

using namespace std;

int c, n, m, s, d;

struct N {
  int cost, ticket, stop;
  bool operator < (const N &t)const {
    return cost > t.cost;
  }
  N(int cost, int ticket, int stop) :
    cost(cost), ticket(ticket), stop(stop){}
  void print() {
    printf("cost = %d, ticket = %d, stop = %d\n", cost, ticket, stop);
  }
};

typedef vector<pair<int , int> > edge;

edge G[100];
int visited[100][11];

const int MAX = INT_MAX;

int solve()
{
  for (int i = 0; i < 100; i++) {
    fill(visited[i], &visited[i][11], MAX);
  }
  priority_queue<N> Q;
  Q.push(N(0, c, s));
      
  //printf("ok\n");  
      
  while (true) {    
    N cur = Q.top();
    Q.pop();

    //cur.print();
    int cc = cur.cost, ct = cur.ticket, cs = cur.stop;
    if (cs == d) {
      return cc;
    }

    for (int i = 0; i < G[cs].size(); i++) {
      int t = G[cs][i].first, ec = G[cs][i].second;
      if (cc + ec < visited[t][ct]) {
        visited[t][ct] = cc + ec;
        Q.push(N(visited[t][ct], ct, t));
      }
      if (ct > 0 && cc + ec / 2 < visited[t][ct - 1]) {
        visited[t][ct - 1] = cc + ec / 2;
        Q.push(N(visited[t][ct - 1], ct - 1, t));
      }
    }
  }                
}

int main()
{
  while (scanf("%d %d %d %d %d ", &c, &n, &m, &s, &d) == 5) {
    if (c == 0 && n == 0 && m == 0 && s == 0 && d == 0) {
      break;
    }
    s--, d--;
    for (int i = 0; i < n; i++) {
      G[i].clear();
    }
    for (int i = 0; i < m; i++) {
      int a, b, cost;
      scanf("%d %d %d ", &a, &b, &cost);
      //printf("%d %d %d\n", a, b, cost);
      a--, b--;
      G[a].push_back(make_pair(b, cost));
      G[b].push_back(make_pair(a, cost));
    }
    /*for (int i = 0; i < n; i++) {
      for (int j = 0; j < G[i].size(); j++) {
        printf("%d %d: %d\n", i, G[i][j].first, G[i][j].second);
      }
      }*/
    printf("%d\n", solve());
  }
  return 0;
}

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


string lcs(string s, string t) {
        int m=s.size();
        int n=t.size();
        if(m==0||n==0) return 0;
        vector<vector<int>>dp(m+1,vector<int>(n+1,0));
        for(int i=1;i<=m;i++){
            for(int j=1;j<=n;j++){
                if(s[i-1]==t[j-1]) dp[i][j]=1+dp[i-1][j-1];
                else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
             // cout<<dp[i][j]<<" ";
            }
            // cout<<endl;
        }
        string ans="";
        int i=m;
        int j=n;
         while(1){
        if(i<1||j<1) break;
        
             
        if(s[i-1]==t[j-1]&&(dp[i][j]==dp[i-1][j-1]+1)){ans=s[i-1]+ans;i--;j--; }
             else {
                 if(dp[i][j]==dp[i-1][j]) {
                     i--;
                 }
                 else j--;
                 
             }
        
        
    }
        
        return ans;
    }

int main(){
  
  string s,t;
  cin>>s>>t;
  cout<<lcs(s,t);
  
  
}

Measured memory_bytes: 35584
from itertools import accumulate
from bisect import bisect_left

def main():
    N = int(input())
    A = [0] + list(map(int, input().split()))

    B = list(accumulate(A))
    ans = float('inf')
    for i in range(1,N):
        C = B[i] - B[0]
        D = B[N] - B[i]
        tmp = abs(C - D)
        ans = min(ans, tmp)

    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 101452
#include <bits/stdc++.h>    
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//using namespace __gnu_pbds; 
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cout<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl "\n"
#define int long long 
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
const ll MOD     = 1000*1000*1000+7;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll MOD2    = 998244353;
const ll N       = 1000 * 100 + 10;
const ll N2      = 70;
const ld PI  = 3.141592653589793;
//template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);} 
ll power(ll x,ll y,ll p = LLONG_MAX ){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
ll lcm(ll a , ll b){return (a*b)/gcd(a,b);}

signed main()
{
    fastio();
    //cout<<fixed<<setprecision(20);
    //CHECK for LONG LONG and LONG DOUBLE
    //*comment for all except cc/cf    
    #ifndef ONLINE_JUDGE    
           freopen("input.txt","r",stdin);
           freopen("output.txt","w",stdout);
    #endif//*/
    int a,b;
    cin>>a>>b;
    cout<<(a*b);

    printclock;
    return 0;
}


Measured memory_bytes: 3804
N, M = map(int, input().split())
lis = [0]*N
SC = []
ERROR = False
for _ in range(M):
  sc = list(map(int, input().split()))
  SC.append(sc)
for i in range(len(SC)-1):
  for j in range(i+1,len(SC)):
    if SC[i][0] == SC[j][0] and SC[i][1] != SC[j][1]:
      ERROR = True
for i in range(len(SC)):
  if N > 1 and SC[i][0] == 1 and SC[i][1] == 0:
    ERROR = True
if ERROR:
  print(-1)
else:
  output = ''
  for i in range(M):
    lis[SC[i][0]-1] = SC[i][1]
  if N > 1 and lis[0] == 0:
    lis[0] = 1
  for i in range(N):
    output += str(lis[i])
  print(int(output))

Measured memory_bytes: 3064
package main

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

type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextLong() int64 {
	i, err := strconv.ParseInt(io.Next(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextDouble() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) PrintLn(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntLn(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func (io *Io) PrintStringLn(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

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

func main() {
	io := NewIo()
	defer io.Flush()
	N := io.NextInt()
	S := io.Next()
	T := make([]int, N)
	for i := 0; i < N; i++ {
		if S[i] == 'o' {
			T[i] = 0
		} else {
			T[i] = 1
		}
	}
	bs := [][]int{{0, 0}, {0, 1}, {1, 0}, {1, 1}}
	ok := false
	for k := 0; k < 4; k++ {
		a := make([]int, N)
		a[0] = bs[k][0]
		a[1] = bs[k][1]
		for i := 2; i < N; i++ {
			a[i] = a[i - 1] ^ a[i - 2] ^ T[i - 1]
		}
		if (a[N - 2] ^ a[N - 1] ^ a[0] ^ T[N - 1]) == 0 && (a[N - 1] ^ a[0] ^ a[1] ^ T[0]) == 0 {
			for i := 0; i < N; i++ {
				if a[i] == 0 {
					io.Printf("S")
				} else {
					io.Printf("W")
				}
			}
			io.PrintLn()
			ok = true
			break
		}
	}
	if !ok {
		io.PrintLn(-1)
	}
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(n, 0);
    rep(i, m){
        int x, y;
        cin >> x >> y;
        a[x-1] ++;
        a[y-1] ++;
    }

    rep(i, n){
        cout << a.at(i) << endl;
    }
}

Measured memory_bytes: 256
s = input()

if s =="SUN":
	print("7")
elif s =="MON":
	print("6")
elif s =="TUE":
	print("5")
elif s =="WED":
	print("4")
elif s =="THU":
	print("3")
elif s =="FRI":
	print("2")
elif s =="SAT":
	print("1")

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

int main(){
    int n;
    string s;
    string fhalf,shalf;
    cin>>n>>s;
    if (n%2!=0) cout<<"No";
    else {
        for (int i=0;i<n/2;i++){
            fhalf+=s[i];
        }
        for (int i=n/2;i<n;i++){
            shalf+=s[i];
        }
        if (fhalf == shalf) cout<<"Yes";
        else cout<<"No";
    }
}

Measured memory_bytes: 256
# n = int(input())
a, b = map(int, input().split())
# c = list(map(int, input().split()))
# d = [list(map(int, input().split())) for _ in range(n)]
# s = input()


if a <= 8 and b <= 8:
    ans ="Yay!"
else:
    ans = ":("

print(ans)

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

ll dp[MAX][5],in[MAX][5],n;

int solve(int day,int pre)
{
    if(day>n)
        return 0;
    if(dp[day][pre]!=-1)
        return dp[day][pre];
    ll res=0;
    for(ll i=1; i<=3; i++)
    {
        if(pre==i)
            continue;
        res=max(res,in[day][i]+solve(day+1,i));
    }
    dp[day][pre]=res;
    return res;
}

int main()
{
    ll i,ans;
    cin >> n;
    for(i=1; i<=n; i++)
    {
        cin >> in[i][1] >> in[i][2] >> in[i][3];
    }
    memset(dp,-1,sizeof(dp));
    ans=solve(1,0);
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 15872
def search(a,b):
    na=len(a)
    nb=len(b)
    array = [[0]*(nb+1) for _ in range(na+1)]
    for i in range(na+1):
        array[i][0]=i
    for j in range(nb+1):
        array[0][j]=j
    for i,x in enumerate(a,1):
        prerow=array[i-1]
        row=array[i]
        for j,y in enumerate(b,1):
            if x == y:
                row[j]=prerow[j-1]
            else:
                row[j]=min(prerow[j], prerow[j-1], row[j-1])+1
    return array[-1][-1]
a=input()
b=input()
print(search(a,b))



Measured memory_bytes: 41888
import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args)throws IOException {
		
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		
		int x = a.length();
		
		for(int i = 1; i < x; i++){
			
			if(a.charAt(i) == a.charAt(i-1)){
				System.out.println(i + " " + (i + 1));
				System.exit(0);
			}
		}
		for(int i = 2; i < x; i++){
			
			if(a.charAt(i) == a.charAt(i-2)){
				System.out.println((i - 1) + " " +(i + 1));
				System.exit(0);
			}
		}
		
		System.out.println(-1 + " " + -1);
	}
}


Measured memory_bytes: 13236
import math

def main() -> None:
    a, b, h, m = map(int, input().split())

    theta = abs(30*h - 5.5*m)
    cos_theta = math.cos(math.radians(theta))
    print((a**2+b**2-2*a*b*cos_theta) ** 0.5)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9492
v[2]['~~'],l,n,m,a,c,*i,*s;D(x){c=0;for(i=v+a;c<x;i+=2)c+=i[1];memmove(i+2,i,(v[a]+l-i)*4);l+=2;*i=i[-2]+(i[-1]-=i[1]=c-x);return i;}C(d,s,e){c=memcpy(d,s,e-s)+e-s;}main(p,q,r,x,y){for(;scanf("%d%d%d%d%d",&n,&m,&p,&q,&r)*n;printf("%d\n",c)){v[a=**v=0][1]=n;for(l=2;m--;a^=1)scanf("%d%d",&x,&y),C(C(C(v[a^1],y,v[a]+l),x,y=D(y)),v[a],x=D(x));s=D(p-1);i=D(q);for(c=0;s-i;s+=2)c+=*s+s[1]>r?*s<r?r-*s:0:s[1];}}

Measured memory_bytes: 572
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef map<int, int> mi;
typedef set<int> si;
#define VV(T) vector<vector< T > >
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define pb push_back
#define pu push
#define mp make_pair
#define fi first
#define sc second

#define COUT(x) cout << (x) << endl
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl

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; }


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

    int n, mx1, mx2, x1, x2; cin >> n;
    int cnt1[100003] = {0}, cnt2[100003] = {0};
    rep (i, n / 2) {
        int a, b; cin >> a >> b; 
        cnt1[a]++;
        if (mx1 < cnt1[a]) {
            mx1 = cnt1[a];
            x1 = a;
        }
        cnt2[b]++;
        if (mx2 < cnt2[b]) {
            mx2  = cnt2[b];
            x2 = b;
        }
    }
    sort(cnt1, cnt1 + 100003);
    sort(cnt2, cnt2 + 100003);

    int ans = INF;
    if (x1 != x2) {
        ans = n - mx1 - mx2;
    } else {
        ans = n - max(mx1 + cnt2[100001], mx2 + cnt1[100001]);
    }

    COUT(ans); 
}

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

using namespace std;

#ifdef LOCAL 
  #include "..\debug.hpp"
#else
  #define debug(...) 630;
#endif

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef long double ld;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define np return puts("-1"), 0;

template<class T>bool mins(T &a, T b) {return a>b?(a=b,true):false;}
template<class T>bool maxs(T &a, T b) {return a<b?(a=b,true):false;}
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<ll> a(n);
  for (auto& x : a) cin >> x;
  const ll inf = 1e18;
  vector<vector<ll>> dp(n , vector<ll> (n , inf));
  vector<vector<ll>> p(n , vector<ll> (n , 0));
  for (int i = 0; i < n; i++) {    
    p[i][i] = a[i];
    dp[i][i] = 0;
  }
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      for (int k = i; k <= j; k++) {
        p[i][j] += a[k];
      }
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    for (int j = i + 1; j < n; j++) {
      for (int k = i + 1; k <= j; k++) { 
        mins(dp[i][j], dp[i][k-1] + dp[k][j] + p[i][j]);      
      }
    }
  } 
  cout << dp[0][n-1] << '\n';
  return 0;
}

Measured memory_bytes: 2816
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <climits>
#include<string>
#include<set>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

#define INF INT_MAX/3
#define REP(i,n) for(int i=0;i<n;i++)

int main(){
	
	string str;
	cin>>str;
	
	set<char> syu;

	for(auto& s: str)syu.insert(s);

	if(syu.size() == 26){
		cout<<"None"<<endl;
	}
	else{
		char check = 'a';
		for(auto s : syu){
			if(check != s){
				cout<<check<<endl;
				return 0;
			}
			check++;
		}
		if(check == 'z')cout<<'z'<<endl;
	}

	
	// sort(str.begin(),str.end());
	//
	// char check = 'a';
	// int i = 0;
	// while(i < str.size()){
	// 	
	// 	if(check != str[i++]){
	// 		cout<<check<<endl;
	// 		return 0;
	// 	}
    //
	// 	while(i < str.size() ){
	// 		if(str[i] != check)break;
	// 		i++;
	// 	}
	// 	check++;
	// 	if(i < str.size() ){
	// 		if(str[i] == 'z'){
	// 			cout<<"None"<<endl;
	// 			return 0;
	// 		}
	// 	}
    //
	// }
    //
    //
	// cout<<check<<endl;

	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  int a = (n+999) / 1000;
  int x = a * 1000;
  int ans = x - n;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner input = new Scanner(System.in);
		
		char[][] a = new char[101][101];
		int N = input.nextInt();
		int M = input.nextInt();
		
		input.nextLine();
		
		for (int i=1;i<=N;i++)
		{
			String str = input.nextLine();
			
			char[] ch = str.toCharArray();
			for (int j=1;j<=M;j++){
				a[i][j] = ch[j-1];
			}
		}
		int[] R = new int[101];
		int[] C = new int[101];
		
		for (int i=1;i<=N;i++)
			R[i] = 0;
		for (int j=1;j<=M;j++)
			C[j] = 0;
		
		for (int i=1;i<=N;i++)
		{
			for (int j=1;j<=M;j++){
				if (a[i][j] == '#')
				{
					R[i] = 1;
					break;
				}
			}
		}
		
		for (int j=1;j<=M;j++)
		{
			for (int i=1;i<=N;i++){
				if (a[i][j] == '#')
				{
					C[j] = 1;
					break;
				}
			}
		}
		
		
		for (int i=1;i<=N;i++)
		{
			if (R[i]==0)
				continue;
			else 
			{
				for (int j=1;j<=M;j++){
					if (C[j]==0)
						continue;
					else 
						System.out.print(a[i][j]);
				}	
				System.out.println();
			}
			
		}
		
	}

}


Measured memory_bytes: 25088
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int d = scanner.nextInt();
        int x[] = new int[n + 1];
        int y[] = new int[n + 1];
        int cnt = 0;
        for (int i = 1; i <= n; i++) {
            x[i] = scanner.nextInt();
            y[i] = scanner.nextInt();

            double dist = Math.sqrt((double) x[i] * x[i] + (double) y[i] * y[i]);
            if (dist <= (double) d) {
                cnt++;
            }
        }
        System.out.println(cnt);
        scanner.close();
    }
}


Measured memory_bytes: 51436
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define all(x) x.begin(),x.end()
#define YES {cout << "YES\n"; return;}
#define NO {cout << "NO\n"; return;}

const int INF=INT_MAX;
const ld PI=acos(-1);//3.1415926535897932384626433
const ld E=2.71828183;
const int MOD=1e9+7;

vi bfs(vector<vi>adj,int src){
    //adjacency list, not-weighted, possibly directed ,src is 1-indexed, adj[0].size()=0!!!
    //for n vertices, adj.size()=n+1. (constructed via push_back() ).

    queue<int>q;
    q.push(src);
    vi dst(adj.size(),INF);
    dst[src]=0;
    while(!q.empty()){
        int c=q.front();
        q.pop();
        for(int nbr:adj[c]){
            if(dst[nbr]==INF){
                dst[nbr]=dst[c]+1;
                q.push(nbr);
            }
        }
    }
    return dst;
}
vi bfsParents(vector<vi>adj,int src){
    vi parents=vi(adj.size(),INF);
    parents[src]=-1;
    queue<int>q;
    q.push(src);
    vi dst(adj.size(),INF);
    dst[src]=0;
    while(!q.empty()){
        int c=q.front();
        q.pop();
        for(int nbr:adj[c]){
            if(dst[nbr]==INF){
                parents[nbr]=c;
                dst[nbr]=dst[c]+1;
                q.push(nbr);
            }
        }
    }
    return parents;
}
vi shortestPath(vector<vi>adj,int src,int dst){
    vi bfsParetns=bfsParents(adj,src);
    vi ans;
    while(src!=dst){
        if(bfsParetns[src]==INF)
            return {};
        ans.push_back(src);
        src=bfsParetns[src];
    }
    return ans;
}
int powMod(int base,int exp,int mod){
    //(base^exp) %mod
    int ans=1;
    for(int i=0; i<exp; i++)
        ans=((ans%mod)*(base%mod))%mod;
    return ans;
}
vi divisorsOf(int n){
    //vector of divisors of n (inc. 1 , excl.n)
    vi ans;
    for(int i=1; i*i<=n; i++){
        if(n%i==0)
            ans.push_back(i);
        if(i*i!=n && i!=1)
            ans.push_back(n/i);
    }
    return ans;
}

ll gcd(ll a,ll b){if(a%b==0) return b; else return gcd(b,a%b);}
ld log (ld a,ld b){return log(b)/log(a);}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
ll power(ll base, ll exp){ll res=1;while(exp){exp--;res*=base;}return res;}

void solve();
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin >> t;
    while(t--)
        solve();
    return 0;
}
void solve (){
    ull n;
    cin >> n;
    ull best=1e13;
    for(ull i=1; i*i<=n; i++){
        if(n%i==0)
            best=min(best,i+n/i);
    }
    cout << best -2<< "\n";

}

Measured memory_bytes: 3656
#include<stdio.h>

#define max(a,b) ((a)>(b)?(a):(b))

int main(){
	int n,i,j;
	long long a[100000];
	scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%lld",&a[i]);
	long long dp[100000][2]={0};//0:kaeta,1:kaenakatta
	dp[0][0]=-a[0];
	dp[0][1]=a[0];
	for(i=1;i<n-1;i++){
		dp[i][0]=max(dp[i-1][0]+a[i],dp[i-1][1]-a[i]);
		dp[i][1]=max(dp[i-1][0]-a[i],dp[i-1][1]+a[i]);
	}
	dp[n-1][0]=dp[n-2][0]-a[i];
	dp[n-1][1]=dp[n-2][1]+a[i];
	printf("%lld\n",max(dp[n-1][0],dp[n-1][1]));
	return 0;
}

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

int main(){
	int n;
	cin >> n;
	vector<vector<int>> a(n, vector<int>(3));
	rep(i, n){
		int ai, bi;
		cin >> ai >> bi;
		a[i][0] = ai + bi;
		a[i][1] = ai;
		a[i][2] = bi;
	}
	sort(a.begin(), a.end());
	reverse(a.begin(), a.end());
	ll ta = 0;
	ll ao = 0;
	rep(i, n){
		if(i%2 == 0){
			ta += a[i][1];
		}else{
			ao += a[i][2];
		}
	}
	cout << ta - ao << endl;
	return 0;
}

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

int main()
{
	list<int> a;
	list<int>::iterator c = a.end();
	int q;

	cin >> q;

	for (int i = 0; i < q; i++) {
		int t;
		cin >> t;

		if (t == 0) {
			int x;
			cin >> x;

			c = a.insert(c, x);
		}
		else if (t == 1) {
			int d;
			cin >> d;

			if (d > 0) {
				for (int j = 0; j < d; j++)
					c++;
			}
			else {
				for (int j = 0; j < -d; j++)
					c--;
			}			
		}
		else if (t == 2) {
			c = a.erase(c);
		}
	}

	for (list<int>::iterator itr = a.begin(); itr != a.end(); itr++)
		cout << *itr << endl;

	return 0;
}


Measured memory_bytes: 18620
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int N, C, K;
priority_queue<int, vector<int>, greater<int> > que;


int main() {
  INCANT;
  cin >> N >> C >> K;
  int a;
  rep(i, N) {
    cin >> a;
    que.push(a);
  }
  int early = que.top();
  int nowSize = 0;
  int idx=0;
  while(!que.empty()) {
    int tmp = que.top();
    que.pop();
    if (nowSize==C) {
      idx++;
      nowSize= 1;
      early = tmp;
    } else if (early+K < tmp) {
      idx++;
      nowSize= 1;
      early = tmp;
    } else {
      nowSize++;
    }
  }
  if (nowSize>0) idx++;
  cout << idx << "\n";
  return 0;
}


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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;

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; }

ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
ll LCM(ll a, ll b) { return a / GCD(a, b)* b; }

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

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  int n; cin>>n;
  vi a(n);
  rep(i,n) cin>>a[i];
  sort(a.begin(),a.end());
  ll res=0;
  ll r=a[0];
  int c = a[n-1]/2;
  int d=INF;
  rep(i,n-1){
    ll tmp=abs(c-a[i]);
    if(d>=tmp){
      d=tmp;
      r=a[i];
    }
  }
  cout<<a[n-1]<<" "<<r<<endl;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <ctype.h>

int main()
{
    char ch; 
    
    while ((ch = getchar()) != '\n') {
        if (islower(ch)) {
            ch = toupper(ch);
        }
        printf("%c", ch);
    }
    printf("\n");
    
    return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long           ll;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << '\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " = " << arg1 << " | "; __f(comma + 1, args...);
}
ll max(ll a, ll b) {return (a > b ? a : b);}
ll min(ll a, ll b) {return (a < b ? a : b);}
#define all(x) (x).begin(), (x).end()
ll h, w;
ll start_x, start_y, end_x, end_y;
ll dx[4] = {1, 0, -1, 0};
ll dy[4] = {0, 1, 0, -1};
bool check(ll x, ll y) {
  if (x >= 0 and x<h and y >= 0 and y < w)
    return 1;
  return 0;
}
ll cnt = 0;
vector<string> s;
vector<vector<ll>> vis, value, graph;
void dfs(ll x, ll y) {
  if (check(x, y) == 0)
    return;
  vis[x][y] = 1;
  if (s[x][y] == '#')
    return;
  value[x][y] = cnt;
  for (int i = 0; i < 4; i++) {
    ll u = x + dx[i], v = y + dy[i];
    if (check(u, v) == 0)
      continue;
    if (vis[u][v] == 0)
      dfs(u, v);
  }

}
void solve() {
  ll ans = 0;
  cin >> h >> w;
  cin >> start_x >> start_y;
  cin >> end_x >> end_y;
  s = vector<string>(h);
  start_x--, start_y--;
  end_x--, end_y--;

  vis = vector<vector<ll>>(h, vector<ll>(w, 0));
  value = vector<vector<ll>>(h, vector<ll>(w, -1));
  for (int i = 0; i < h; i++)
    cin >> s[i];
  cnt = 0;
// trace(cnt);
  for (int i = 0; i < h; i++) {

    for (int j = 0; j < w; j++) {
      if (vis[i][j] == 0 and s[i][j] == '.')
      {
        dfs(i, j);
        cnt++;
      }
    }

  }
  if (cnt == 1) {
    cout << 0 << "\n";
    return;
  }
  if (value[start_x][start_y] == value[end_x][end_y])
  {
    cout << 0 << "\n";
    return;
  }
  graph = vector<vector<ll>>(cnt);
// trace(cnt);
  ll u, v, x, y;
  for (int i = 0; i < h; i++)

    for (int j = 0; j < w; j++) {

      for (int k = -2; k <= 2; k++) {

        for (int l = -2; l <= 2; l++) {
          u = i + k, v = j + l;
          if (check(u, v) == 0 )
            continue;
          if (s[u][v] == '#') continue;
          if (s[i][j] == '#') continue;
          //trace(i, j, u, v, x, y);
          if (i == u  and j == v) continue;
          x = value[u][v], y = value[i][j];
          if (x != y) {
            graph[x].push_back(y);
            graph[y].push_back(x);
          }
        }

      }

    }

  queue<ll> q;
  u = value[start_x][start_y];
// trace(u);
  ll dest = value[end_x][end_y];
  q.push(u);
  vector<ll> depth(cnt, 0), visited(cnt, 0);
  visited[u] = 1;
  ans = -1;
  while (!q.empty()) {
    v = q.front();
    q.pop();
    if (v == dest)
    {
      ans = depth[v];
      break;
    }
    for (ll i : graph[v]) {
      if (visited[i] == 0) {
        visited[i] = 1;
        q.push(i);
        depth[i] = depth[v] + 1;
      }
    }
  }

  cout << ans << "\n";
}
int main()
{
  cin.sync_with_stdio(0);
  cin.tie(0);
  ll t;
// cin >> t;
  solve();
  return 0;
}


Measured memory_bytes: 65428
#include <bits/stdc++.h>
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define int long long
#define all(c) (c).begin(),(c).end()
#define endl '\n'
using namespace std;

//                                          mdsaqib
signed main(){
    fast;
    int t;
    cin >> t;
    int a=0,b=0,c=0,d=0;
    while(t--){
        string s;
        cin >> s;
        // AC x 3
        // WA x 1
        // TLE x 2
        // RE x 0
        if(s=="AC")a++;
        if(s=="WA")b++;
        if(s=="TLE")c++;
        if(s=="RE")d++;
    }
    cout << "AC x " << a << endl;
    cout << "WA x " << b << endl;
    cout << "TLE x " << c << endl;
    cout << "RE x " << d << endl;
}

Measured memory_bytes: 3656
def calc(n):
    if n <= 1:
        return 1
    else:
        return 2 ** (n - 1)


def normailze(s, n):
    return (n - len(s)) * '0' + s


def solution(s):
    a = calc(len(s))
    cnt = 0
    n = len(s)
    if n ==1:
        return int(s)
    for i in range(a):
        binary = normailze(bin(i)[2:], n - 1)
        b = s[0]
        f = 1
        for j in binary:
            if int(j) == 1:
                cnt += int(b)
                b = s[f]
                f += 1
            else:
                b += s[f]
                f += 1
        cnt += int(b)
    return cnt

print(solution(input()))

Measured memory_bytes: 9224
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define ROOP(i, N) for(int i=0; i<N; i++)
#define RVROOP(i, N) for(int i=N; i>=0; i--)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main() {
  ll N; cin>>N;
  if(N%2==1){
    cout<<"0"<<endl;
  }
  else{
    ll n=N/2;
    ll ans=0;
    ll i=5;
    while(n/i>0){
      ans=ans+n/i;
      i*=5;
    }
    cout<<ans<<endl;
  }
}

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

int A,B;

int main()
{
    cin>>A>>B;

    int cnt=0;
    for (int i = A; i <= B; i++)
    {
        int d5 = (i/10000)%10;

        if(i%10 == (i/10000)%10 && (i/10)%10 == (i/1000)%10) cnt++;
    }
    
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
K = int(input())
D = int(input())
mod = 10**9 + 7

dp = [[[0] * D for _ in range(2)] for _ in range(len(str(K))+1)]
dp[0][0][0] = 1

for i in range(len(str(K))):
    N = int(str(K)[i])
    for j in range(2):
        for k in range(D):
            for n in range((9 if j == 1 else N) + 1):
                dp[i+1][j or n < N][(k+n%D)%D] += dp[i][j][k]%mod

print((dp[-1][0][0]+dp[-1][1][0]-1)%mod)


Measured memory_bytes: 62556
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); }
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

const ll INF = 1LL<<60;

vector<ll> dijkstra(int n, int s, vector<vector<P>> G) {
  priority_queue<P, vector<P>, greater<P> > que;
  vector<ll> d(n,INF);
  d[s] = 0;
  que.push(P(0,s));
  while(!que.empty()) {
    P p = que.top(); que.pop();
    int v = p.second;
    if (d[v] < p.first) continue;
    for (int i = 0; i < (int)G[v].size(); ++i) {
      int to = G[v][i].first;
      ll cost = G[v][i].second;
      if (d[to] > d[v] + cost) {
        d[to] = p.first + cost;
        que.push(P(d[to], to));
      }
    }
  }
  return d;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int n;
  cin >> n;
  vector<vector<P>> G(n);
  rep(i,n-1) {
    int a, b;
    ll c;
    cin >> a >> b >> c;
    a--; b--;
    G[a].emplace_back(P(b,c));
    G[b].emplace_back(P(a,c));
  }
  int q, k;
  cin >> q >> k;
  k--;
  vector<ll> dist = dijkstra(n, k, G);
  rep(_,q) {
    int x, y;
    cin >> x >> y;
    x--; y--;
    ll ans = dist[x] + dist[y];
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 18160
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP2(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define INF 2e9
typedef long long ll;
typedef pair<int, int> P;

ll gcd(ll x, ll y)
{
  return y ? gcd(y, x % y) : x;
}
ll lcm(ll x, ll y)
{
  return x * y / gcd(x, y);
}
bool is_prime(int x)
{
  for (int i = 2; i * i <= x; i++)
  {
    if (x % i == 0)
      return 0;
  }
  return true;
}
vector<bool> prime_table(int n)
{
  vector<bool> prime(n + 1, 1);
  prime[0] = 0;
  prime[1] = 0;
  for (int i = 2; i * i <= n; i++)
  {
    if (!prime[i])
      continue;
    for (int j = i * i; j <= n; j++)
      prime[j] = 0;
  }
  return prime;
}
map<int, int> prime_factor(int n)
{
  map<int, int> res;
  for (int i = 2; i * i <= n; i++)
  {
    while (n % i == 0)
    {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1)
    res[n]++;
  return res;
}
ll modpow(ll a, ll n, ll mod)
{
  ll res = 1;
  while (n > 0)
  {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
ll modinv(ll a, ll mod)
{
  return modpow(a, mod - 2, mod);
}

int main()
{
  int a,b,c;
  cin>>a>>b>>c;

  if(a==b && b==c){
    cout<<"No"<<endl;
    return 0;
  }
  if(a==b || b==c || c==a) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
  return 0;
}


Measured memory_bytes: 764
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>
#include <climits>
#include <functional>

#define REP(i,n) for(int i = 0;i < n;i++)

using namespace std;
typedef long long ll;
const int INF = INT_MAX / 4;

const int max_n = 2e5 + 1;

const ll MOD = 1e9 + 7;

ll power[max_n], ipower[max_n];


ll extgcd(ll a, ll b, ll * x, ll * y) {
  ll d = a;
  if (b != 0) {
    d = extgcd(b, a % b, y, x);
    *y -= (a / b) * (*x);
  } else {
    *x = 1;
    *y = 0;
  }
  return d;
}


ll mod_inverse(ll a, ll m) {
  ll x, y;
  extgcd(a, m, &x, &y);
  return (m + x % m) % m;
}


void init_power(int n) {
  power[0] = 1;
  ipower[0] = mod_inverse(1, MOD);
  for(int i = 1;i <= n;i++) {
    power[i] = power[i-1] * i % MOD;
    ipower[i] = mod_inverse(power[i], MOD);
  }
}


ll comb(int n, int r) {
  if (r == 0) return 1;
  if (n < r) return 0;
  ll x;
  x = power[n] * ipower[r] % MOD;
  return x * ipower[n-r] % MOD;
}


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

  int N;
  cin >> N;
  init_power(N + 1);

  int ctr[N + 1];
  REP(i, N + 1) ctr[i] = -1;
  int a, d1, d2;
  REP(i, N + 1) {
    cin >> a;
    if (ctr[a] != -1) {
      d1 = ctr[a];
      d2 = i;
    }
    ctr[a] = i;
  }

  int d_items = d1 + N - d2;

  ll cnt;
  for (int i = 1;i <= N + 1;i++) {
    cnt = comb(N + 1, i) - comb(d_items, i-1);
    // cout << cnt % MOD << "\n";
    cout << (cnt + MOD) % MOD << "\n";
  }



  return 0;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int mod=1000000007;
inline void add(int &a,int b){
    a+=b;
    if(a>=mod)a-=mod;
}
int mpow(int n,int m){
    int ret=1;
    while(m){
        if(m&1)ret=ret*n%mod;
        n=n*n%mod;
        m>>=1;
    }
    return ret;
}
const int FACT_SIZE=1111111;
int fact[FACT_SIZE];
int inv[FACT_SIZE];
struct fact_exec{
    fact_exec(){
        fact[0]=1;
        for(int i=1;i<FACT_SIZE;i++)fact[i]=fact[i-1]*i%mod;
        inv[FACT_SIZE-1]=mpow(fact[FACT_SIZE-1],mod-2);
        for(int i=FACT_SIZE-2;i>=0;i--)inv[i]=inv[i+1]*(i+1)%mod;
    }
}factexec;
int nCk(int n,int k){
    if(n<0|k<0||k>n)return 0;
    return fact[n]*inv[k]%mod*inv[n-k]%mod;
}
int nPk(int n,int k){
    if(n<0||k<0||k>n)return 0;
    return fact[n]*inv[n-k]%mod;
}


int N;

int dp[55][55][55];

signed main(){
    cin>>N;

    dp[N][1][0]=1;
    for(int n=N;n>0;n--){
        for(int i=0;i<=n;i++){
            for(int j=0;i+j<=n;j++){
                if(i==0&&j==0)continue;

                for(int k=0;k<=n;k++){
                    for(int l=0;l<=n&&i+j+k+2*l<=n;l++){
                        if(i>=k){
                            int a=i-k;
                            int b=j+k;
                            int c=k+l;
                            int d=l;
                            add(dp[n-a-b][c][d],dp[n][i][j]*inv[a]%mod*inv[b]%mod);
                        }
                        if(j>=k&&k!=0){
                            int a=i+k;
                            int b=j-k;
                            int c=l;
                            int d=k+l;
                            add(dp[n-a-b][c][d],dp[n][i][j]*inv[a]%mod*inv[b]%mod);
                        }
                    }
                }
            }
        }
    }

    cout<<dp[0][0][0]*fact[N]%mod<<endl;
    return 0;
}


Measured memory_bytes: 18176
#include<iostream>
#include<vector>
#include <string>
#include <numeric>
#include<algorithm>
// #include <iterator>

using namespace std;
int main()
{
  int n, k;
  cin >> n >> k;

  if (n <= k) {
    cout << 0 << endl;
    return 0;
  }

  vector<long long> powers;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    powers.push_back(tmp);
  }

  sort(powers.begin(), powers.end());

  for (int i = 0; i < k; i++) {
    powers.pop_back();
  }
  cout << accumulate(powers.begin(), powers.end(), 0LL) << endl;
  
  return 0;
}


Measured memory_bytes: 3444
#include <cstdio>
#include <queue>
#include <iostream>
#include <bits/stdc++.h>
#include<stdio.h>
#include<string.h>
#include<fstream>

#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
using namespace std;

int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
       
    ll i,j,k,x,y,z,p,q;
    ll n,m,tmp;
    string s[200000];
    string str;
    ll sum=0,ac=0,wa=0;
    ll strr[200005];
    cin>>m>>n;
    if(n==0) {
        cout<<0<<" "<<0<<endl;
        return 0;
    }else{
    vector<int> c(m);
    vector<int> aced(m);
    ll no;
    rep(i,n){
        cin >> no;
        cin>>str;
        if(aced[no]==1) continue;
        if(str[0]=='W'){
            c[no]++;
        }else{
            sum+=c[no];
            aced[no]=1;
            ac++;
        }
    }
    cout<<ac<<" "<<sum<<endl;
    return 0;
    }
}

Measured memory_bytes: 2560
#include <stdio.h>
#include <string.h>

int cap[202][202],flow[202][202],maxflow,visited[202];

int dfs(int cur) {
	if(cur == 201) {
		maxflow++;
		return 1;
	}
	for(int i = 0;i < 202;i++) {
		if(!visited[i] && cap[cur][i] > flow[cur][i]) {
			visited[i] = 1;
			if(dfs(i)) {
				flow[cur][i]++;
				return 1;
			}
		}
		if(!visited[i] && flow[i][cur] > 0) {
			visited[i] = 1;
			if(dfs(i)) {
				flow[i][cur]--;
				return 1;
			}
		}
	}
	return 0;
}

int main() {
	int x,y,e;
	scanf("%d %d %d",&x,&y,&e);
	for(int i = 0;i < e;i++){
		int xx,yy;
		scanf("%d %d",&xx,&yy);
		cap[0][xx+1] = 1;
		cap[xx+1][yy+101] = 1;
		cap[yy+101][201] = 1;
	}
	while(dfs(0) != 0) memset(visited,0,sizeof(visited));
	printf("%d\n",maxflow);
}



Measured memory_bytes: 2156
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
int main(void){
  int N, count;
  for(int i=0; i<=N; i++){
    cin >> N;
    if(N == 0){
        count = i+1;
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3580
n = gets.chomp.to_i
v = gets.split(' ').map(&:to_i)
c = gets.split(' ').map(&:to_i)

diff = [v, c].transpose.map{|arr| arr[0] - arr[1]}

sum = 0
diff.each do |e|
  if e > 0
    sum += e
  end
end

puts sum

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N, K;
    ll R, S, P;
    string T;
    map<char, ll> points;
    vector<vector<char>> wake;
    ll count = 0;
    cin >> N >> K;
    cin >> R >> S >> P;
    cin >> T;
    points['r'] = P;
    points['s'] = R;
    points['p'] = S;
    wake.resize(K);
    rep(i, N) wake[i % K].push_back(T[i]);
    iter(line, wake) {
        bool win = false;
        rep(i, line.size()) {
            if(i != 0) {
                if(line[i - 1] == line[i]) {
                    if(win) {
                        win = false;
                    } else {
                        count += points[line[i]];
                        win = true;
                    }
                } else {
                    count += points[line[i]];
                    win = true;
                }
            } else {
                count += points[line[i]];
                win = true;
            }
        }
    }
    cout << count << endl;
    return 0;
}


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

typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
#define put(ans)    cout << ans << endl;

int main(){
    int x;
    cin >> x;

    int ans(100000);
    for(int i=10001;i>0;i--){
        if(i-x<0)   break;
        if(i%1000==0)
            ans = min(ans,i-x);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
#define lambda(RES_TYPE, ...) (function<RES_TYPE(__VA_ARGS__)>)[&](__VA_ARGS__) -> RES_TYPE
#define method(FUNC_NAME, RES_TYPE, ...) function<RES_TYPE(__VA_ARGS__)> FUNC_NAME = lambda(RES_TYPE, __VA_ARGS__)
using ll = long long;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

namespace templates{
  ll modpow(ll x, ll b){
    ll res = 1;
    while(b){
      if(b&1)res = res * x % MOD;
      x = x * x % MOD;
      b>>=1;
    }
    return res;
  }

  ll modinv(ll x){
    return modpow(x, MOD-2);
  }

  bool was_output = false;
  template<class t>
  void output(t a){
    if(was_output)cout << " ";
    cout << a;
    was_output = true;
  }
  void outendl(){
    was_output = false;
    cout << endl;
  }
  ll in(){
    ll res;
    scanf("%lld", &res);
    return res;
  }

  template<class t>
  istream& operator>>(istream&is, vector<t>&x){
    for(auto &i:x)is >> i;
    return is;
  }

  template<class t, class u>
  istream& operator>>(istream&is, pair<t, u>&x){
    is >> x.first >> x.second;
    return is;
  }

  template<class t>
  void in(t&x){
    cin >> x;
  }

  template<class t>
  t in(){
    t res; cin >> res; return res;
  }

  template<class t>
  void out(t x){
    cout << x;
  }

  template<class t>
  vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){
    sort(line.begin(),line.end(),comp);
    return line;
  }

  template<class t>
  vector<t> reversed(vector<t> line){
    reverse(line.begin(),line.end());
    return line;
  }
}

using namespace templates;

int main(){
  int q = in();
  map<string,int> m;
  rep(_,q){
    int kind = in();
    if(kind==0){
      string key = in<string>();
      int x = in();
      m[key] = x;
    }else if(kind==1){
      string key = in<string>();
      cout << m[key] << endl;
    }else if(kind==2){
      string key = in<string>();
      if(m.count(key))m.erase(key);
    }
  }
}



Measured memory_bytes: 27980
import collections
N = int(input())
A = list(map(int, input().split()))
C = collections.Counter(A)
comb = 0
output = []

for k,v in C.items():
  comb += int(v*(v-1)/2)

for a in A:
  output.append(comb - (C[a]-1))

print(*output, sep="\n")


Measured memory_bytes: 30012
#include <stdio.h>

int main(void){
	int H,W,i,j;

	while(1){
		scanf("%d %d",&H,&W);
		if(H==0 && W==0) break;
		for(i=0;i<H;i++){
			if(i%2==0){
				for(j=0;j<W;j++){
					if(j%2==0){
						printf("#");
					}else{
						printf(".");
					}
				}
				printf("\n");
			}else{
				for(j=0;j<W;j++){
					if(j%2==0){
						printf(".");
					}else{
						printf("#");
					}
				}
				printf("\n");
			}

		}
		printf("\n");
	}

	return 0;

}

Measured memory_bytes: 572