akhauriyash/Code-Regression huggingface dataset:
Month = [0,31,29,31,30,31,30,31,31,30,31,30,31]
Week = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
while (mon, day = gets.split(" ").map(&:to_i)) != [0,0]
  puts Week[(day + Month[0..(mon - 1)].inject{|sum,i|sum + i} + 2) % 7]
end


=begin

inject(reduce) : ブロックを使って繰り返し計算する。

numbers = [2, 6, 5, 3, 7, 8, 1, 9, 4]
puts numbers.reduce {|sum, n| sum + n }   (配列の数値の合計を計算します)
puts numbers.reduce(100) {|diff, n| diff - n }  (100から配列の数値を引いていった結果を計算します)
puts numbers.reduce(:+)  (配列の数値の合計を計算します)
puts numbers.reduce(100, :-)  (100から配列の数値を引いていった結果を計算します)
45
55
45
55

=end





=begin

require 'date'
 
wd = %w(Sunday Monday Tuesday Wednesday Thursday Friday Saturday)


while line = gets
 m, d = line.chomp.split.map(&:to_i)
 break if m == 0 || d == 0
 puts wd[Date.new(2004, m, d).wday]
end

=end


=begin

wd = %w(Sunday Monday Tuesday Wednesday Thursday Friday Saturday)と
wd = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" ]は同じ

%() : ダブルクォート文字列 
%r() : 正規表現 
%w() : 要素が文字列の配列(空白区切り) 

str = %(Programming language "Ruby")
puts str
# => Programming language "Ruby"

array = %w(one two three four)
p array
# => ["one", "two", "three", "four"]

=end





Measured memory_bytes: 6840
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
int main(int argc, char* argv[]) {
    int n;
    cin >> n;
    vint p(n);
    rep(i,n) cin >> p[i];
    sort(ALL(p));
    p[p.size()-1]/=2;
    cout << accumulate(ALL(p),0) << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String args[]){


try (Scanner sc = new Scanner(System.in)) {
  while(true){
  int n = sc.nextInt();
  int r = sc.nextInt();
  int count = 0;
  if(n==0 && r==0){
    break;
  }
  int[] data = new int[n];
  int[] tmp = new int[n];
  for(int i = 0;i<n;i++){//スタートの並び
    data[i] = n - i;
  }

  while(count != r){
    int z = 0;
    int a = sc.nextInt();
    int b = sc.nextInt();
    while(z<b){
      tmp[z] = data[a-1+z];
      z++;
    }
    int y = 0;
    
    while(y<a-1){
      tmp[z] = data[y];
      y++;
      z++;
    }

    
    
    while(z<n){
      tmp[z] = data[z];
      z++;
    }
  
    
    for(int i = 0;i<n;i++){
      data[i] = tmp[i];
    }
    count++;
  }
  System.out.println(data[0]);
}

}
  }
}


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

int main()
{
	int N, M;
	cin >> N;
	vector<string> s(N);
	for (int i = 0; i < N; i++)
	{
		cin >> s.at(i);
	}

	cin >> M;
	vector<string> t(M);
	for (int i = 0; i < M; i++)
	{
		cin >> t.at(i);
	}

	int benefit = 0;
	for (int i = 0; i < N; i++)
	{
		int sum = 0;
		string test = s.at(i);
		for (int j = 0; j < N; j++)
		{
			if (test == s.at(j))
				sum++;
		}
		for (int j = 0; j < M; j++)
		{
			if (test == t.at(j))
				sum--;
		}
		benefit = max(benefit, sum);
	}
	cout << benefit << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 1e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int co[MAXM];
int sz[MAXM];
int A[MAXM];
int dp[MAXM][(1<<12)+10];

vector<int> vv[(1<<12)+10];

int main()
{
    int n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;
    int tc;

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

    cin>>n>>m;

    for(int i=1;i<=m;i++)
    {
        cin>>co[i]>>sz[i];
        for(int j=0;j<sz[i];j++){
            cin>>x;
            x--;
            A[i]|=(1<<x);
        }
    }

    for(int i=0;i<=m;i++)
        for(int j=0;j<(1<<n);j++)
            dp[i][j] = INF;

    dp[0][0] = 0;

    for(int i=0;i<(1<<n);i++){
        for(int j=0;j<n;j++){
            if(!((1<<j)&i)){
                vv[i].push_back((1<<j)|i);
            }
        }
    }

    for(int i=1;i<=m;i++){
        for(int j=0;j<(1<<n);j++){
            cur = j^(j&A[i]);
            dp[i][j] = min(dp[i-1][cur]+co[i],dp[i-1][j]);
        }
        for(int j=(1<<n)-1;j>=0;j--){
            for(int t=0;t<vv[j].size();t++){
                dp[i][j] = min(dp[i][j],dp[i][vv[j][t]]);
            }
        }
    }

    if(dp[m][(1<<n)-1]!=INF)cout<<dp[m][(1<<n)-1]<<"\n";
    else cout<<"-1\n";

    return 0;
}


Measured memory_bytes: 16640
#include <iostream>
#include <string>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  string S, T, U;
  int A, B;
  cin >> S >> T;
  cin >> A >> B;
  cin >> U;
  if (U == S) A--;
  if (U == T) B--;
  cout << A << ' ' << B << endl;
}

Measured memory_bytes: 256
(r, c) = map(int, input().split())
a = [[v for v in list(map(int, input().split()))] for r in range(r)]
for i in range(r):
    a[i].append(sum(a[i]))
add_r = [sum([a[i][j] for i in range(r)]) for j in range(c + 1)]
a.append(add_r)
for i in range(r + 1):
    print(' '.join(map(str, a[i])))

Measured memory_bytes: 7708
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long[] s = new long[N];
		long a1 = sc.nextLong();
		long total = a1;
		s[0] = a1;
		for(int i = 1; i < N; i++) {
			long a = sc.nextLong();
			s[i] = s[i-1] + a;
			total += a;
		}
		long ans = Long.MAX_VALUE;
		for(int i = 0; i < N-1; i++)
			ans = Math.min(ans, Math.abs(total-2*s[i]));
		System.out.println(ans);
	}

}

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

using namespace std;

const int N=1e6+3;

const double eps=0.000000001;

#define pb push_back
#define all(x) (x).begin(),(x).end()
typedef long long ll;

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

const int inf=1e9,mod=1e9+7;

int n,m,a[N],b[N],k,q,u,v,x,y,tc,c,l,r,ans;

char s[N];

void IO(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	#ifndef ONLINE_JUDGE
		freopen("test.txt","r",stdin);
	#endif
}

int main(){
	//IO();
	int a,b;
	string s,t,u;
	cin >> s >> t;
	cin >> a >> b;
	cin >> u;
	if (u==s)
		a--;
	else
		b--;
	cout << a << " " << b;
}


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

int main(){
  string s; cin >>s;
  string key = "keyence";
  if(s==key){
    cout << "YES" << endl;
    return 0;
  }
  int n = s.size();
  rep(i,n){
   for(int j = i; j<n; j++){
     string S = "";
     rep(k,n){
       if(i<=k && k<=j){
         continue;
       }
       else S.push_back(s[k]);
     }
     if(S==key){
       cout << "YES" << endl;
       return 0;
     }
   }
  }
  cout << "NO" << endl;
  return 0; 
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

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

    int H[N];
    REP(i, N){
        cin >> H[i];
    }

    bool flag = true;
    REPD(i, N-1){
        if (H[i+1] >= H[i]) continue;
        else H[i]--;

        if (H[i+1] < H[i]) {
            flag = false;
            break;
        }
    }

    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3896
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
  int n;
  cin>>n;
  rep(a,n){
    int dt[10][10];
    int checkline[10][10];
    int checkrow[10][10];
    rep(i,10){
      rep(j,10){
	checkline[i][j]=0;
	checkrow[i][j]=0;
      }
    }
    loop(i,1,10){
      loop(j,1,10){
	cin>>dt[i][j];
	checkline[i][dt[i][j]]++;//横ライン見てる
	checkrow[j][dt[i][j]]++;//縦ライン見てる
      }
    }
    bool error[10][10];
    rep(i,10)rep(j,10)error[i][j]=false;
    rep(i,10){
      rep(j,10){
	if(checkline[i][j]>1){
	  rep(k,10){
	    if(dt[i][k]==j)error[i][k]=true;
	  }
	}
      }
    }
    rep(j,10){
      rep(i,10){
	if(checkrow[j][i]>1){
	  rep(k,10){
	    if(dt[k][j]==i)error[k][j]=true;
	  }
	}
      }
    }
    int circle[4][4][10];
    rep(i,4)rep(j,4)rep(k,10)circle[i][j][k]=0;
    loop(i,1,4){
      loop(j,1,4){
	for(int k=(i-1)*3+1;k<(i-1)*3+4;k++){
	  for(int l=(j-1)*3+1;l<(j-1)*3+4;l++){
	    circle[i][j][dt[k][l]]++;
	  }
	}
	for(int k=1;k<10;k++){
	  if(circle[i][j][k]>1){
	    for(int l=(i-1)*3+1;l<(i-1)*3+4;l++){
	      for(int m=(j-1)*3+1;m<(j-1)*3+4;m++){
		if(dt[l][m]==k)error[l][m]=true;
	      }
	    }
	  }
	}
      }
    }
    loop(i,1,10){
      loop(j,1,10){
	if(error[i][j])cout<<"*"<<dt[i][j];
	else cout<<" "<<dt[i][j];
      }
      cout<<endl;
    }
    if(a!=n-1)cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
#endif

#ifdef _DEBUG
void init_global_C() {}
#else

#endif

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

    int N, M; cin >> N >> M;
    vi a(M), b(M);
    REP(i, M) {
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
    }

    vvb eg(N, vb(N, false));

    REP(i, M) {
        eg[a[i]][b[i]] = true;
        eg[b[i]][a[i]] = true;;
    }

    int ans = 0;

    REP(i, M) {
        eg[a[i]][b[i]] = false;
        eg[b[i]][a[i]] = false;

        // BFS
        queue<int> que;
        vb visited(N, false);
        que.push(0);

        while(!que.empty()) {
            int x = que.front(); que.pop();
            visited[x] = true;
            for (int nx = 0; nx < N; nx++) {
                if (eg[x][nx] && !visited[nx]) que.push(nx);
            }
        }

        bool bridge = false;
        REP(x, N){
            if (!visited[x]) {
                bridge = true;
                break;
            }
        }
        if (bridge) ans++;

        eg[a[i]][b[i]] = true;
        eg[b[i]][a[i]] = true;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

public class Main {
	
	
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		final int n = sc.nextInt();
		
		HashMap<String, Integer> map = new HashMap<String, Integer>();
		
		for(int i = 0; i < n; i++){
			String in = sc.next();
			int count = sc.nextInt();
			if(map.get(in) == null){
				map.put(in, count);
			}else{
				map.put(in, map.get(in) + count);
			}
		}
		
		TreeSet<String> set = new TreeSet<String>(new Comparator<String>() {
			@Override
			public int compare(String o1, String o2) {
				if(o1.length() != o2.length()){
					return o1.length() - o2.length();
				}
				
				for(int i = 0; i < o1.length(); i++){
					if(o1.charAt(i) != o2.charAt(i)){
						return o1.charAt(i) - o2.charAt(i);
					}
				}
				
				return 0;
			}
		});
		
		set.addAll(map.keySet());
		
		for(String str : set){
			System.out.println(str + " " + map.get(str));
		}
		
	}

}

Measured memory_bytes: 38096
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ll> pll;
const int INF=1e9;
const ll MOD=1e9+7;

ll gcd(ll x,ll y){
    if(y==0) return 0;
    return gcd(y,x%y);
}

int dis2(int x1,int y1,int x2,int y2){
    return (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
}

int main(){
    string s;cin>>s;
    int ans=0;
    for(int i=0;i<4;i++){
        if(s[i]=='2') ans++;
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
  int A[3][3];
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> A[i][j];
    }
  }

  int N;
  cin >> N;

  int tmp;
  for (int i = 0; i < N; i++) {
    cin >> tmp;
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 3; k++) {
        if (tmp == A[j][k]) A[j][k] = 0; // 数字が存在する場合は0にする
      }
    }
  }

  string msg = "No";

  // 横の列チェック
  for (int i = 0; i < 3; i++) {
    if (A[i][0] == 0 && A[i][1] == 0 && A[i][2] == 0) msg = "Yes";
  }

  // 縦の列チェック
  for (int i = 0; i < 3; i++) {
    if (A[0][i] == 0 && A[1][i] == 0 && A[2][i] == 0) msg = "Yes";
  }

  // 斜めの列チェック
  if (A[0][0] == 0 && A[1][1] == 0 && A[2][2] == 0) msg = "Yes";
  if (A[0][2] == 0 && A[1][1] == 0 && A[2][0] == 0) msg = "Yes";

  cout << msg << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split().Select(double.Parse).ToArray();
            var N = input[0];
            var D = input[1];

            Console.WriteLine(Math.Ceiling(N / (2 * D + 1)));

        }
    }
}

Measured memory_bytes: 13396
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#ifndef M_PI
#define M_PI 3.1415926535897932384626433832795
#endif
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define F first
#define S second

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


bool vis[20][20][1<<10];

typedef struct{
  int x,y;
  int vis;
  int cost;
}state;

char in[22][22];
int durty[22][22];

main(){
  int w,h;
  while(scanf("%d%d",&w,&h),w|h){
    int sx,sy;
    int num=0;
    
    rep(i,h){
      scanf("%s",in[i]);
      rep(j,w){
	if(in[i][j]=='o'){
	  sx=i;
	  sy=j;
	  in[i][j]='.';
	}else if(in[i][j]=='*'){
	  durty[i][j]=num++;
	}
      }
    }

    memset(vis,0,sizeof(vis));

    queue<state> Q;
    state st={sx,sy,0,0};
    Q.push(st);
    int ans=-1;

    while(!Q.empty()){
      int cx=Q.front().x,cy=Q.front().y,cvis=Q.front().vis,cc=Q.front().cost;
      Q.pop();

      if(vis[cx][cy][cvis])continue;
      vis[cx][cy][cvis]=true;

      if(cvis==(1<<num)-1){
	ans=cc;
	break;
      }

      rep(i,4){
	int nx=cx+dx[i],ny=cy+dy[i];
	if(nx<0 || h<=nx || ny<0 || w<=ny || in[nx][ny]=='x')continue;
	int nvis=cvis;
	if(in[nx][ny]=='*')nvis|=1<<durty[nx][ny];
	if(vis[nx][ny][nvis])continue;
	st.x=nx;
	st.y=ny;
	st.vis=nvis;
	st.cost=cc+1;
	Q.push(st);
      }
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 1472
a = int(input())
b = [int(x) for x in input().split()]
summ = 1
for i in range(a):
    if(b[i]==0):
        summ = 0
for i in range(a):
    summ*=b[i]
    if(summ>1000000000000000000):
        summ=-1
        break
print(summ)

Measured memory_bytes: 21640
#include <iostream>
#include<iomanip>
#include <vector>
#define rep(i,n) for(int i = 0; i < (n); i++)

using namespace std;



int main() {
    double n,k;
    cin>>n>>k;
    double ans=0;
    vector<double>p(n,1/n);

    rep(i,n){
        if(i<k-1)p[i]*=0.5;
        double b=2;
        while(b<(double)(k/(i+1))){
            b *=2;
            p[i] *= 0.5;
        }
        ans+=p[i];
        
    }
    cout<<fixed<<setprecision(16);
    cout<<(double)ans<<endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <atcoder/dsu>
using namespace std;
using namespace atcoder;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < int(n);i++)


int main(){
  int n,m;
  cin >> n >> m;
  dsu d(n);
  rep(i,m){
    int x,y;
    cin >> x >> y;
    x--;y--;
    d.merge(x,y);
  }
  cout << d.groups().size()-1 << endl;
  

  
  return 0;
}

Measured memory_bytes: 8976
//This is getting accepted!
#include<bits/stdc++.h>
#define ll long long
#define oo 1000000009

using namespace std;

const int MOD = 1000000007;
const double EPS = 1e-8;
const double PI = 2 * acos(0);
const int MAXN = 1e6 + 6;

string s;

bool input() {
	
	cin >> s;
	return !cin.fail();
}

void process() {
	int n = s.size();
	ll res = 0;
	
	int cntA = 0;
	for (int i = 0; i < n-1; ++i) {
		if (s[i] == 'A')
			cntA++;
		else if (s[i] == 'B' && s[i+1] == 'C') {
			res += cntA;
			i+= 1;
		}
		else 
			cntA = 0;
	}
	
	cout << res << endl;
}

int main(){
    #ifndef ONLINE_JUDGE
//    freopen("../out.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    	
	while(input()) {
		process();
	}
	
    return 0;

}


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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())
#define all(a) (a).begin(), (a).end()

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//print
#define pv(val) cerr << #val << '=' << (val) << endl

const int INF = 1e9;

int main(void){

	ll A; cin >> A;
	string S; cin >> S;
	
	ll B = 0;
	REP(i,S.length()){
		if(S[i] == '.') continue;
		B *= 10;
		B += S[i] - '0';

	}


	ll ans = A*B/100;
	cout << ans << endl;
	


	return 0;

}


Measured memory_bytes: 3608
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**6)

n=int(input().rstrip())
a=[int(i) for i in input().split()]
if 0 in a:
    print(0)
else:
    ans=1
    for i in a:
        ans*=i
        if ans>10**18:
            print(-1)
            exit()
    print(ans)

Measured memory_bytes: 21620
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define inf 500000000
#define IOS ios_base::sync_with_stdio(0)
#define meM(y,a) memset(y,a,sizeof y)
#define sC(a) scanf("%d",&a)
#define alL(a) a.begin(),a.end()
#define prinT(a,sz)  cout<<a[0];for(int i=1;i<sz;i++)cout<<" "<<a[i];cout<<endl
#define ranD srand(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<int,int>pi;
typedef pair<ll,ll>pll;
//int fx[]={0,0,1,-1};
//int fy[]={1,-1,0,0};
//int gx[]={0,0,1,1,1,-1,-1,-1};
//int gy[]={1,-1,0,1,-1,0,1,-1};
bool check(int n,int p){return (1<<p)&n;}
const int N=100010;
int ans[N];
int main()
{
    IOS;
    string s;cin>>s;
    int cnt=0;
    for(int i=0;i<s.length()-1;i++)
    {
        if(s[i]=='R'&&s[i+1]=='L'){
            ans[i]=1+cnt/2;
            ans[i+1]=(cnt+1)/2;
            cnt=0;
        }
        else if(s[i]=='R')cnt++;
    }
    cnt=0;
    for(int i=s.length()-1;i>0;i--)
    {
        if(s[i]=='L'&&s[i-1]=='R')
        {
            ans[i]+=1+cnt/2;
            ans[i-1]+=(cnt+1)/2;
            cnt=0;
        }
        else if(s[i]=='L')cnt++;
    }
    prinT(ans,s.length());
}








Measured memory_bytes: 1104
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int M, D, c = 0;

  std::cin >> M >> D;

  for (int m = 1; m <= M; m ++)
    for (int d = 1; d <= D; d ++) {
      int d1 = d % 10, d2 = d / 10;
      
      if (d1 >= 2 && d2 >= 2 && d1 * d2 == m)
        c ++;
    }

  std::cout << c << std::endl;
  
  return 0;
}


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

const double PI=acos(-1.0);

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

    int x[100];

    rep(i, 100) {
        int mod = a*i % b;
        x[mod] = 1;
    }

    if(x[c] == 1) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

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

#ifdef _DEBUG
#define debug(x) cout<<#x<<": "<<x<<endl
#else
#define debug(x)
#endif

using namespace std;

#define mp make_pair

int64_t pow10(int e) {
    if (e <= 0) return 1;
    int64_t n = 1;
    for (int i = 0; i < e; ++i) {
        n *= 10;
    }
    return n;
}

int main() {
    int N;
    cin >> N;
    // A == B
    int64_t cnt = 0;
    for (int i = 1; i <= N; ++i) {
        string str_i = to_string(i);
        if (str_i.front() == str_i.back())
            cnt++;
        if (i >= 10) {
            for (int j = 1; j <= 9; j++) {
                if (str_i.front() - '0' == j && str_i.back() - '0' == j) {
                    cnt += 2;
                }
            }
        }
    }
    debug(cnt);
    // A > B
    int cnt_ab = 0;
    for (int a = 10; a <= N; ++a) {
        string str_a = to_string(a);
        int a0 = str_a.front() - '0', a1 = str_a.back() - '0';
        if (a1 == 0) { continue; }
        int M = str_a.size();
        if (a1 < a0) {
            cnt_ab += pow10(M - 2);
        }
        if (a0 == a1 && M > 2) { 
            cnt_ab += stoi(string(str_a.begin() + 1, str_a.end() - 1)); 
        }
        for (int i = 0; i < M - 2; ++i) {
            cnt_ab += pow10(i);
        }
    }
    cout << 2 * cnt_ab + cnt << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
#include <numeric>
#include <bitset>
#include <cassert>
#include <functional>

using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<ll, ll> P;
inline ll min(ll x, ll y) { return x < y ? x : y; }
inline ll max(ll x, ll y) { return x > y ? x : y; }

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)

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

	if (N % 2 == 0) {
		num_kisuu = N / 2;
	}
	else {
		num_kisuu = N / 2 + 1;
	}

	cout << num_kisuu / double(N) << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int a = sc.nextInt();
        int b = sc.nextInt();


        int total = a+b;
        if(total>=24){
            total=total-24;
        }
        // 出力
        System.out.println(total);
    }
}

Measured memory_bytes: 22100
#include <stdio.h>

int w, h, x, y, r;

int main() {
  scanf("%d%d%d%d%d", &w, &h, &x, &y, &r);
  if ( x - r < 0 || x + r > w || y - r < 0 || y + r > h ) printf("No\n");
  else printf("Yes\n");
  return 0;
}

Measured memory_bytes: 1012
/******************************************
* AUTHOR : SHASHANK *
* NICK : lance_lot *
* INSTITUTION : BIT MESRA *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define N 100005
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl "\n"
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <ll, ll> pll;
const ll M=1e9+7;
ll inf=1e18;
ll len[N];
vector<ll> adj[N];
ll rec(ll s,ll n) {
  if(s > n)
    return 0;
  if(len[s] != -1)
    return len[s];
  if(adj[s].size() == 0)
    return 1;
  for(ll i = 0;i < adj[s].size();i++)
    len[s] = max(len[s],1+rec(adj[s][i],n));
  return len[s];
}

int main() {
fast;
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ll n,m;
    cin>>n>>m;
    ll temp = m;
    for(ll i = 0;i <= N;i++)
      len[i] = -1;
    while(temp--) {
      ll u,v;
      cin>>u>>v;
      adj[u].pb(v);
    }
    ll maxx = 0;
    for(ll i = 1;i <= n;i++) {
      if(len[i] == -1)
        maxx = max(maxx,rec(i,n));
    }
    maxx--;
    cout<<maxx;
}

Measured memory_bytes: 8576
import sys
from collections import deque
import copy


def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]
    W_set = set([])
    pre_last_char = ""
    for i in range(N):
        input_raw = read_func().strip().split()
        W = input_raw[0]
        if W not in W_set and (pre_last_char == "" or pre_last_char == W[0]):
            W_set.add(W)
            pre_last_char = W[len(W) - 1]
        else:
            print "No"
            exit()
    print "Yes"

if __name__ == '__main__':
    main()

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

int main(){
	int A,B,sum=0;
	cin>>A>>B;
	
	for(int i=0;i<2;i++){
		if(A>B){
			sum+=A;
			A=A-1;
		}
		else{
			sum+=B;
			B=B-1;
		}
		}
	cout<<sum<<endl;
		
	return 0;
}

Measured memory_bytes: 764
/*

    author : s@if

*/

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define 		NIL 			-1
#define		 	fi	 		    first
#define 		sec 			second
#define 		MAX 			INT_MAX
#define			INF 			99999999
#define 		ll 			    long long
#define 		PI 			    acos(-1.0)
#define			MOD 			1000000007
#define 		PLL 			pair<ll,ll>
#define 		PII			    pair<int,int>
#define 		ull 			unsigned long long
#define 		For(i,a,b) 		for(int i=a;i<=(int)b;i++)
typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update> new_data_set;

//*find_by_order(k)  gives the kth element;
//order_of_key(item)   gives the index(number of element strictly less than item) of item;


inline int in() {int x; scanf("%d", &x); return x; }
bool Check(int N , int pos)	{	return (bool) (N & (1<<pos));}
int Set(int N, int pos) {	return N = N | (1<<pos);}

int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};
int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};
int hr[]={-2,-2,-1,+1,+2,+2,-1,+1};
int hc[]={+1,-1,+2,+2,-1,+1,-2,-2};
int dx[]={+1,-1,+0,+0};
int dy[]={+0,+0,+1,-1};

const int MAXN = (int)1e5+9;

int main()
{
/*	freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);  */

    ll i,j,k,l,m,n,p,q,x,y,u,v,r,tc,t;

    scanf("%lld", &n); vector<PLL>vv;

    for(i=1; i<=n; i++)
    {
        scanf("%lld %lld", &u, &v);
        vv.push_back(PLL(u,v));
    }

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

    ll ara[n+9], rev[n+9], L[n+9], R[n+9];
   // memset(ara, 0, sizeof(ara));
  //  memset(rev, 0, sizeof(rev));

    l = vv[0].fi, r = vv[0].sec;
    ara[0] = r-l+1;

    for(i=1; i<n; i++){
        p = vv[i].fi, q = vv[i].sec;
        l = max(l, p); r = min(r, q);
        ara[i] = max(0LL, r-l+1);
    }

    l = vv[n-1].fi, r = vv[n-1].sec;
    rev[n-1] = r-l+1;

    for(i=n-2; i>=0; i--)
    {
        p = vv[i].fi, q = vv[i].sec;
        l = max(l, p); r = min(r, q);
        rev[i] = max(0LL, r-l+1);
    }

    l = vv[n-1].fi; r = vv[n-1].sec;
    L[n-1] = l, R[n-1] = r;

    for(i=n-2; i>=0; i--){
        p = vv[i].fi, q = vv[i].sec;
        l = max(l, p); r = min(r, q);
        L[i] = l, R[i] = r;
    }

    ll ans = 0;

    for(i=0; i+1<n; i++)
    {
        ans = max(ans, ara[i]+rev[i+1]);
    }

    l = vv[0].fi, r = vv[0].sec;
    ans = max(ans, r-l+1);

    for(i=1; i+1<n; i++)
    {
        v = vv[i].sec-vv[i].fi+1;
        l = max(l, L[i+1]); r = min(r, R[i+1]);
        ans = max(ans, v+max(0LL, r-l+1));
    }

    printf("%lld\n", ans);

  //  main();

    return 0;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)


Measured memory_bytes: 5104
using System;
class arrayfun{
  public static void Main(){
    int pcdr = int.Parse(Console.ReadLine());
    int[] num = new int[pcdr+400000];
    int pf=399999,pl=400000;
    for(int i=0; i<pcdr; i++){
      String[] str = Console.ReadLine().Split(' ');
      switch (int.Parse(str[0])){
        case 0:
          if(str[1].Equals("1")){
            num[pl] = int.Parse(str[2]);
            pl++;
          }
          else{
            /*if(pf==-1){
              for(int j=pl; j>0; j--){
                num[j] = num[j-1];
              }
              num[0] = int.Parse(str[2]);
              pl++;
            }
            else{*/
              num[pf] = int.Parse(str[2]);
              pf--;
            //}
          }
          break;
        case 1:
          Console.WriteLine(num[pf+1+int.Parse(str[1])]);
          break;
        case 2:
          if(str[1].Equals("1"))
            pl--;
          else
            pf++;
          break;
        default:
          break;
      }
    }
  }
}



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

using namespace std;

int N,K;
int H[123456];

int main(){
  cin >> N >> K;
  int d = 0;
  for(int i = 1; i <= N; ++i){
    int x;
    cin >> x;
    if(x >= K) ++d;
  }
  cout << d;
  return 0;
}

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

int main() {
	int N;
	cin>>N;
	vector<double>A(N);
	for(int i=0;i<N;i++) cin>>A.at(i);
	
	double sum=0;
	for(int i=0;i<N;i++){
		sum+=1/A.at(i);
	}
	
	cout<<setprecision(8)<<1/sum<<endl;
	return 0;
}

Measured memory_bytes: 256
// IO
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm
#include <algorithm>
#include <cmath>
#include <numeric>

// container
#include <vector>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>

// others
#include <random>
#include <limits>
#include <functional>
#include <ctime>
#include <cassert>

// type alias
using lint = long long;
using ldouble = long double;
template <class T>
using greater_priority_queue = std::priority_queue<T, std::vector<T>, std::greater<T>>;


/* ----- class ----- */

template <class Cost = int>
struct Edge {
    int src, dst;
    Cost cost;
    Edge(int src = -1, int dst = -1, Cost cost = 1)
        : src(src), dst(dst), cost(cost){};

    bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; }
};

template <class Cost = int>
using Edges = std::vector<Edge<Cost>>;

template <class Cost = int>
using Graph = std::vector<std::vector<Edge<Cost>>>;


/* ----- debug ----- */

#if __has_include("../setting/source/debug.hpp")
#include "../setting/source/debug.hpp"
#endif


/* ----- short functions ----- */

template <class T>
inline T sq(T a) { return a * a; }

template <class T>
inline T iceil(T n, T d) { return (n + d - 1) / d; }

template <class T>
T gcd(T a, T b) {
    while (b > 0) {
        a %= b;
        std::swap(a, b);
    }
    return a;
}

template <class T, class U>
T ipow(T b, U n) {
    T ret = 1;
    while (n > 0) {
        if (n & 1) ret *= b;
        n >>= 1;
        b *= b;
    }
    return ret;
}

// 0-indexed
template <class T, class U>
inline T kthbit(T a, U k) { return (a >> k) & 1; }

template <class T, class U>
inline T mask(T a, U k) { return a & ((1 << k) - 1); }

template <class T>
std::map<T, int> compress(std::vector<T>& v) {
    std::sort(v.begin(), v.end());
    v.erase(std::unique(v.begin(), v.end()), v.end());

    std::map<T, int> rev;
    for (int i = 0; i < v.size(); ++i) rev[v[i]] = i;
    return rev;
}

template <class T>
T Vec(T v) { return v; }

template <class T, class... Ts>
auto Vec(size_t l, Ts... ts) {
    return std::vector<decltype(Vec<T>(ts...))>(l, Vec<T>(ts...));
}


/* ----- constants ----- */

// const int INF = std::numeric_limits<int>::max() / 3;
// const lint INF = std::numeric_limits<lint>::max() / 3;
// const ldouble PI = acos(-1);
// const ldouble EPS = 1e-10;
// std::mt19937 mt(int(std::time(nullptr)));


using namespace std;

int main() {
    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 <iostream>
#include <algorithm>
using namespace std;

int main() {
	long long A, B, K;
	cin >> A >> B >> K;
	if (A >= K) cout << A - K << " " << B << endl;
	else cout << 0 << " " << (A + B >= K ? A + B - K : 0) << endl;
}


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

int main(){

  int a,b,z = 1,s[1000],n;
  vector < pair < int , int > > p;

  while(1){
    scanf("%d,%d",&a,&b);
    if(!a && !b) break;

    pair < int , int > k(b,a);
    p.push_back(k);

  }

  sort(p.begin(),p.end());
  reverse(p.begin(),p.end());
  s[0] = 1;

  for(int i=1;i<p.size();i++){
    if(p[i-1].first > p[i].first) z++;
    s[i] = z;
  }


  while(cin >> n){

    for(int i=0;i<p.size();i++){
      if(p[i].second == n){
	cout << s[i] << endl;
	break;
      }
    }
  }

}

Measured memory_bytes: 1248
#![allow(unused_imports)]
#![allow(dead_code)]
use proconio::input;
use proconio::fastout;
#[macro_use] extern crate text_io;
use proconio::marker::*;
use std::mem::*;
use std::collections::*;
use std::cmp::*;
extern crate num;
use num::Integer;

struct UF{
    par:Vec<usize>,
    rank:Vec<usize>,
}
impl UF{
    fn new(n:usize)->UF{
        let mut v=vec![0;n];
        for i in 0..n{
            v[i]=i;
        }
        UF{
            par:v,
            rank:vec![1;n],
        }
    }
    fn root(&mut self,x:usize)->usize{
        if x==self.par[x]{
            x
        }else{
            let par=self.par[x];
            let res=self.root(par);
            self.par[x]=res;
            res
        }
    }
    fn same(&mut self,a:usize,b:usize)->bool{
        self.root(a)==self.root(b)
    }
    fn unite(&mut self,a:usize,b:usize)->bool{
        let ap=self.root(a);
        let bp=self.root(b);
        if ap==bp{
            return false;
        }
        if self.rank[ap]<self.rank[bp]{
            self.par[bp]=ap;
            self.rank[ap]+=self.rank[bp];
        }else{
            self.par[ap]=bp;
            self.rank[bp]+=self.rank[ap];
        }
        return true;
    }
    fn size(&mut self,a:usize)->usize{
        let ap=self.root(a);
        self.rank[ap]
    }
}

#[fastout]
fn main() {
    input!{
        n:usize,
        mut a:[usize;n],
    }
    let mut v:[usize;1000001]=[0;1000001];
    for i in a.clone(){
        v[i]+=1;
    }
    let mut b=true;
    for i in 2..1000001{
        let mut cnt=0;
        for j in (i..1000001).step_by(i){
            cnt+=v[j];
        }
        if cnt>=2{
            b=false;
        }
    }
    if b{
        println!("pairwise coprime");
        return;
    }
    let mut cnt=0;
    for i in a.clone(){
        cnt=cnt.gcd(&i);
    }
    if cnt==1{
        println!("setwise coprime");
    }else{
        println!("not coprime");
    }
}

Measured memory_bytes: 33300
N, X = map(int, input().split())
items = []
for i in range(N):
    b, l, u = map(int, input().split())
    items.append((b, l, u, u * (X - b), - b * l))

items = sorted(items, key=lambda x: -(x[3] - x[4]))


def f(num):
    cnt = num // X
    mod = num % X
    point = 0
    for i in range(cnt):
        point += items[i][3]
    for i in range(cnt, N):
        point += items[i][4]

    if mod == 0:
        if point >= 0:
            return True
        else:
            return False
    else:
        tmp = -float("inf")
        for i, tmp2 in enumerate(items):
            b, l, u, d1, d2 = tmp2
            if mod >= b:
                mul = u * (mod - b)
            else:
                mul = l * (mod - b)

            if i < cnt:
                tmp = max(tmp, point - d1 + mul + items[cnt][3] - items[cnt][4])
            else:
                tmp = max(tmp, point - d2 + mul)
        if tmp >= 0:
            return True
        else:
            return False

ok = N * X + 1
ng = - 1
while (ok - ng) > 1:
    mid = (ok + ng) // 2
    if f(mid):
        ok = mid
    else:
        ng = mid
print(ok)


Measured memory_bytes: 77528
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<string>
#include<map>
#include<set>
#include<functional>
#include<list>
#include<bitset>
#include<numeric>
using namespace std;
typedef long long ll;
typedef pair<int, int> p;

int main() {
	int k, t;
	cin >> k >> t;
	vector<int> a(t);
	for (int i = 0; i < t; i++) {
		cin >> a[i];
	}
	int MAX = *max_element(a.begin(), a.end());
	int ans;
	cout<<max(0, 2*MAX - 1 - k);
	return 0;
}


Measured memory_bytes: 256
fn get_input() -> String {
    let mut word = String::new();
    std::io::stdin().read_line(&mut word).unwrap();
    word.trim().to_owned()
}

fn main() {
    let (a,b,c) = {
        let line = get_input();
        let mut split = line.split_whitespace();
        let a:i64 = split.next().unwrap().parse().unwrap();
        let b:i64 = split.next().unwrap().parse().unwrap();
        let c:i64 = split.next().unwrap().parse().unwrap();
        (a,b,c)
    };

    let ans = if a - b > c { 0 } else { i64::abs(a - b - c) };
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <string>
#include <map>


using namespace std;

int main(void){
    int n;
    vector<pair<string, int>> sp;
    map<pair<string, int>, int> p;

    cin >> n;

    for(int i = 0; i < n; i++){
        int b;
        string a;
        cin >> a >> b;
        sp.push_back(make_pair(a, -b));
        p[make_pair(a, -b)] = i+1;
    }

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

    for(int i = 0; i < n; i++){
        cout << p[sp[i]] << endl;
    }


    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    int ac=0,wa=0,tle=0,re=0;
    cin >> n;
    string s;
    for(int i=0;i<n;i++){
        cin >> s;
        if(s == "AC")ac++;
        else if(s == "WA")wa++;
        else if(s == "TLE")tle++;
        else if(s == "RE")re++;
    }
    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
    return 0;
}

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

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  sort(h.begin(), h.end());
  ll ans = 0;
  for (int i = 0; i+k < n; i++) {
    ans += h[i];
  }
  cout << ans << endl;
}


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

void CountTriangles(vector <int> A){  
  
    int n=A.size(); 
  
    sort(A.begin(), A.end());  
  
    int count = 0; 
      
    for( int i = n-1; i >= 1; i--){ 
        int l = 0, r = i-1; 
        while( l < r){ 
            if( A[l] + A[r] > A[i]){ 
  
                count += r - l ;  
  
                r--;   
            } 
            else 

                l++;   
        } 
    } 
    cout<<count<<endl;
}
int32_t main()
{
     int n;
     cin>>n;
     vector<int> a;
     int c;
     for(int i=0;i<n;i++)
        {
            cin>>c;
            a.push_back(c);
        }
     
        CountTriangles(a); 

}

Measured memory_bytes: 256
import bisect

n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
a.sort()
c.sort()

ans = 0
C = len(c)

# Bを中心に考える
for i in b:
    ans += (bisect.bisect_right(a,i-1))*(C-bisect.bisect_left(c,i+1))

print(ans)

Measured memory_bytes: 29384
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        int[] B = new int[N];
        for (int i=0;i<N;i++) {
            A[i] = sc.nextInt();
            B[i] = A[i];
        }
        Arrays.sort(B);
        int cnt = 0;
        for (int i=0;i<N;i++) {
            cnt+=Math.abs(Arrays.binarySearch(B, A[i])-i)%2;
        }
        System.out.println(cnt/2);
    }
}


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

int main() {
  int n, m;
  int64_t k;
  cin >> n >> m >> k;
  vector<int64_t> a(n + 1), b(m + 1);
  a[0] = 0LL; b[0] = 0LL;
  for (int i = 1; i <= n; i++) {
    int64_t ai;
    cin >> ai;
    a[i] = a[i - 1] + ai;
  }
  for (int i = 1; i <= m; i++) {
    int64_t bi;
    cin >> bi;
    b[i] = b[i - 1] + bi;
  }
  int dokuha = 0;
  int j = b.size() - 1;
  for(int i = 0; i < a.size(); i++) {
    if(a[i] > k) break;
    while(a[i] + b[j] > k) {
      j--;
    }
    dokuha = max(dokuha, i + j);
  }
  cout << dokuha;
}

Measured memory_bytes: 6372
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <iomanip>
#include <stdio.h>
#include <string.h>
#include <random>
#include <functional>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using std::map;
using std::set;
using std::bitset;
using std::vector;
using std::string;
using std::multimap;
using std::multiset;
using std::deque;
using std::queue;
using std::stack;
using std::pair;
using std::iterator;

using std::sort;
using std::stable_sort;
using std::reverse;
using std::max_element;
using std::min_element;
using std::unique;
using std::ios_base;
using std::swap;
using std::fill;

using std::setprecision;
using std::fixed;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef string S;

ll min(ll a, ll b) {return a < b ? a : b;}
ll min(int a, ll b) {return a < b ? a : b;}
ll min(ll a, int b) {return a < b ? a : b;}
ll min(int a, int b) {return a < b ? a : b;}

ll max(ll a, ll b) {return a > b ? a : b;}
ll max(int a, ll b) {return a > b ? a : b;}
ll max(ll a, int b) {return a > b ? a : b;}
ll max(int a, int b) {return a > b ? a : b;}

namespace MySpace{

};

#define F(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()
#define int long long

const int N = 5010;
const int MOD = 1e9 + 7;

int n, A, B;
int p[N], pos[N], dp[N];
int ca[N][N], cb[N][N], t[N][N];
int tree[N];

void Add(int pos)
{
    while (pos < N)
    {
        tree[pos]++;
        pos = (pos | (pos - 1)) + 1;
    }
}

int Get(int pos)
{
    int res = 0;
    while (pos > 0)
    {
        res += tree[pos];
        pos = (pos & (pos - 1));
    }
    return res;
}

#define Get(l, r) Get(r) - Get(l - 1)

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> A >> B;
    for (int i = 1; i <= n; i++) cin >> p[i], pos[p[i]] = i;
    n++;
    pos[n] = n, p[n] = n;
    for (int j = 0; j <= n; j++)
    {
        fill(tree, tree + N, 0);
        for (int i = j + 1; i <= n; i++)
        {
            ca[j][i] = Get(0, pos[j]);
            cb[j][i] = Get(pos[i], N);
            t[j][i] = (Get(pos[j], pos[i]) == 0);
            Add(pos[i]);
        }
    }
    for (int i = 1; i <= n; i++)
    {
    	dp[i] = 1e18;
    	for (int j = i - 1; j >= 0; j--)
    	{
    		if (pos[j] < pos[i])
    		{
    		    int CA = ca[j][i], CB = cb[j][i], T = t[j][i];
    			if (T)
    			{
    				dp[i] = min(dp[i], dp[j] + CA * A + CB * B);
    			}
    		}
    	}
    }
    cout << dp[n];
}


Measured memory_bytes: 588288
#define _CRT_SECURE_NO_WARNINGS 1

#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <vector>
#include <cstdio>
#include <string>
#include <iomanip>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

#define LL long long
#define pii pair<int,int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define rep(i,a,b) for(int i = (a) ; i <= (b) ; i++)
#define per(i,a,b) for(int i = (a) ; i >= (b) ; i--)
#define mem(a) memset(a,0,sizeof(a))
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
#define fast_io ios::sync_with_stdio(false)

const int INF = 0x3f3f3f3f;
const LL mod = 1e9 + 7;
const int maxn = 2e5 + 7;

int main() {
    int n;
    sd(n);
    LL ans = 1LL * n * (n + 1) * (n + 2) / 6;
    rep(i,1,n-1) {
        int u, v;
        sd(u), sd(v);
        LL x = min(u,v) , y = max(u,v);
        ans -= x * (n - y + 1);
    }
    plld(ans);
    return 0;
}

Measured memory_bytes: 3832
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ll n;
    cin>>n;
    ll limits=sqrt(n+0.5);
    ll ans1=-1;
    for(ll i=1;i<=limits;i++){
        if(!(n%i)){
            ans1=i;
        }
    }
    ll ans2=n/ans1;
    cout<<(ans1-1)+(ans2-1);
    return 0;
}


Measured memory_bytes: 3680
#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <time.h>
#include <bitset>
#include <assert.h>
#include <complex.h>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define FILL(A,val) memset(A,val,sizeof(A))

#define ALL(V) V.begin(),V.end()
#define SZ(V) (int)V.size()
#define PB push_back
#define MP make_pair

typedef long long Int;
typedef unsigned long long UInt;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double Pi = acos(-1.0);
const int INF = 1000000000;
const Int INF2 = Int(INF) * 5000;
const Int INF3 = Int(INF) * INF;
const int MAX = 307;
const int MAXE = 2007000;
const int MAXV = 5000;
const int BASE = 1000000000;
const int ST = 1000000007;

const int MOD = 1000000007;

Int sum(Int x)
{
    Int s = 0;
    while (x)
    {
        s += x % 10;
        x /= 10;
    }
    return s;
}

Int Less(Int x, Int y)
{
    return x * sum(y) <= y * sum(x);
}


int main()
{
    //freopen("in.txt", "r", stdin);

    
    Int x = 1;
    int k;
    cin >> k;

    Int pw = 1;

    while(k)
    {
        cout << x << endl;
        -- k;
        
        if (!Less(x + pw , x + 10 * pw)) pw *= 10;
        
        x += pw;
    }
    
    
    
}



Measured memory_bytes: 256