akhauriyash/Code-Regression huggingface dataset:
n,k = map(int,input().split())
x = list(map(int,input().split()))

if len(x) == 1 and x[0] == 0:
    print(0)
    exit()

m = []
p = []
for i in range(n):
    if x[i] < 0:
        m.append(x[i])
    elif x[i] > 0:
        p.append(x[i])

ans = float('inf')
if len(m) >= k:
    ans = min(ans,abs(m[-k]))
    m = m[-k+1:]
if len(p) >= k:
    ans = min(ans,p[k-1])
    p = p[:k-1]

x = m+p
i = 0
for i in range(len(x)-k+1):
    ans = min(ans, min(abs(x[i])*2+abs(x[i+k-1]), abs(x[i])+abs(x[i+k-1])*2))

print(ans)

Measured memory_bytes: 14252
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 300000;
const int mod = 998244353;
const int K = 60;
const int M = 16;
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n;
    cin >> n;
    for (int i = 0; i < 3; i++){
        if (n % 10 == 7){
            cout << "Yes";
            return 0;
        }
        n /= 10;
    }
    cout << "No";
}


Measured memory_bytes: 3616
#include<iostream>
using namespace std;
struct Card {char suit, value;};

void BubbleSort(struct Card C[36], int N){
	for(int i = 1; i < N; i ++){
		for(int j = N - 1; j >= i; j --){
			if(C[j].value < C[j - 1].value){
				Card temp;
				temp = C[j];
				C[j] = C[j- 1];
				C[j - 1] = temp;
			}
		}
	}
}

void SelectionSort(struct Card C[36], int N){
	for(int i = 0; i < N; i ++){
		int min = i;
		for(int j = i; j < N; j ++){
			if(C[j].value < C[min].value){
				min = j;
			}
		}
		Card temp;
		temp = C[i];
		C[i] = C[min];
		C[min] = temp;
	}
}

int  main(void){
	Card C[36], C2[36];
	int n;
	
	cin >> n;
	
	for(int i = 0; i < n; i ++) cin >> C[i].suit >> C[i].value;
	for(int i = 0; i < n; i ++) C2[i] = C[i];
	
	BubbleSort(C, n);
	for(int i = 0; i < n; i ++){
		cout << C[i].suit << C[i].value;
		if(i != n - 1)cout << " ";
	}
	cout << endl << "Stable" << endl;
	
	SelectionSort(C2, n);
	for(int i = 0; i < n; i ++){
		cout << C2[i].suit << C2[i].value;
		if(i != n - 1)cout << " ";
	}
	for(int i = 0; i < n; i ++){
		if(C[i].suit != C2[i].suit){
			cout << endl << "Not stable" << endl;
			return 0;
		}
	}
	cout << endl << "Stable" << endl;
	return 0;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = (a), i##_end_ = (b); i <= i##_end_; ++i)
#define drep(i, a, b) for(int i = (a), i##_end_ = (b); i >= i##_end_; --i)
#define clar(a, b) memset((a), (b), sizeof(a))
#define debug(...) fprintf(stderr, __VA_ARGS__)
typedef long long LL;
typedef long double LD;
int read() {
    char ch = getchar();
    int x = 0, flag = 1;
    for (;!isdigit(ch); ch = getchar()) if (ch == '-') flag *= -1;
    for (;isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
    return x * flag;
}
void write(int x) {
    if (x < 0) putchar('-'), x = -x;
    if (x >= 10) write(x / 10);
    putchar(x % 10 + 48);
}

const int Maxn = 309;
int n, a[Maxn], sum1, sum2, sum3, vis[Maxn][Maxn][Maxn];
double dp[Maxn][Maxn][Maxn];

void init() {
	n = read();
	rep (i, 1, n) a[i] = read();
	rep (i, 1, n) {
		if (a[i] == 1) ++sum1;
		if (a[i] == 2) ++sum2;
		if (a[i] == 3) ++sum3;
	}
}

double dfs(int a, int b, int c) {
	if (a < 0 || b < 0 || c < 0) return 0;
	if (vis[a][b][c]) return dp[a][b][c];
	vis[a][b][c] = 1;
	double res = 1;
	res += a * 1. / n * dfs(a - 1, b, c) + b * 1. / n * dfs(a + 1, b - 1, c) + c * 1. / n * dfs(a, b + 1, c - 1) + 1;
	res /= (a + b + c) * 1. / n;
	return dp[a][b][c] = res;
}

void solve() {
	dp[0][0][0] = 0, vis[0][0][0] = 1;
	printf("%.10lf\n", dfs(sum1, sum2, sum3) / 2);
}

int main() {
	//freopen("j.in", "r", stdin);
	//freopen("j.out", "w", stdout);

	init();
	solve();

#ifdef Qrsikno
    debug("\nRunning time: %.3lf(s)\n", clock() * 1.0 / CLOCKS_PER_SEC);
#endif
    return 0;
}



Measured memory_bytes: 340224
from collections import deque
n , k = map(int,input().split())
a = list(map(int,input().split()))
mod = 10**9 + 7
ans = 1
plus = []
minus = []

if n == k:
    for i in range(n):
        ans *= a[i]
        ans %= mod
    print(ans)
    exit()
    
for i in range(n):
    if a[i] >= 0:
        plus.append(a[i])
    elif a[i] < 0:
        minus.append(a[i])

if not plus and k % 2 == 1:
    minus.sort(reverse=True)
    for i in range(k):
        ans *= minus[i]
        ans %= mod
    print(ans)
    exit()

plus.sort(reverse=True)
minus.sort()
plus = deque(plus)
minus = deque(minus)

cou = []
while True:
    if len(cou) == k:
        break
    elif len(cou) == k-1:
        cou.append(plus.popleft())
        break
    else:
        if len(plus)>=2 and len(minus)>=2:
            p1 = plus.popleft()
            p2 = plus.popleft()
            m1 = minus.popleft()
            m2 = minus.popleft()
            if p1*p2 > m1*m2:
                cou.append(p1)
                plus.appendleft(p2)
                minus.appendleft(m2)
                minus.appendleft(m1)
            else:
                cou.append(m1)
                cou.append(m2)
                plus.appendleft(p2)
                plus.appendleft(p1)
        elif len(plus) < 2:
            m1 = minus.popleft()
            m2 = minus.popleft()
            cou.append(m1)
            cou.append(m2)
        elif len(minus) < 2:
            p1 = plus.popleft()
            cou.append(p1)

        
for i in cou:
    ans *= i
    ans %= mod
print(ans)


Measured memory_bytes: 32452
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int gcd(int a, int b) {  
  return b != 0 ? gcd(b, a % b) : a;
}//MAX
int lcm(int a, int b) { 
   return a * b / gcd(a, b);
   }
//MIN

 main() {
   string s;
   cin >> s;
   if(s=="SAT")cout<<1<<endl;
   if(s=="SUN")cout<<7<<endl;
   if(s=="MON")cout<<6<<endl;
   if(s=="TUE")cout<<5<<endl;
   if(s=="WED")cout<<4<<endl;
   if(s=="THU")cout<<3<<endl;
   if(s=="FRI")cout<<2<<endl;
 }


Measured memory_bytes: 256
import sys
if sys.argv[-1] == 'ONLINE_JUDGE':
    import os, zlib, base64
    open('solve.pyx', 'wb').write(zlib.decompress(base64.b85decode("c${5PL2kn!5WHLRAEt*Sc1xnT$EfZ{QXc?Aiev-A^w7S(i%nyvdjV!=XLlAI+=#&ld75G{_6BK2??S|=#!1Dp(1{?w<EOJH&jTL@HQY%)aC=jklvR4;?)gb_s~ORZjk+vkuQcd-eLbh>;LBp^Q+bAC!>}aqjLG~crz;}Y^;(EQ@m_@lgV(U`W`;{yfWm0_EAQ}z^94c0uVBHK)Qq=(wdqwaiA+n#riW!1890MrFbt7Fmc{I(I_&yge_+@XXFrmPb^(T}@+K-OoQG<gI?wg5kYx8Fx996n97i-67Aq_^Fd5`{Y9X@l*7Q3aqT3`=MAG4pQ0gciq0}v|&@A`T&U#x^bc@>E@Z#6j>-vxWYSJk30!ifgSr*IRrv-diT7V=sza4$2?E")))
    os.system('cythonize -i -3 -b -j 36 solve.pyx')
import solve

Measured memory_bytes: 9832
#include <bits/stdc++.h> 
 
using namespace std; 
 
 
int main() 
{ 
    int N,T;

    cin >> T >> N;

    int i=0;
    int T_dash;
    vector<int> result;

    while(T!=0){
        result.push_back(T%N);
        T=T/N;
        i++;
    }

    cout << result.size();

    return 0;
}

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

using namespace std;


int a,b,c;

typedef vector<int> vint;
typedef vector<long long> vll;
typedef vector<double> vdb;
typedef vector<bool> vbol;
typedef vector<string> vstr;

#define vvll(a,b,c) vector<vector<long long>> c(a,vector<long long>(b,0))
#define vvit(a,b,c) vector<vector<int>> c(a,vector<int>(b,0))
#define vvstr(a,b,c) vector<vector<string>> c(a,vector<string>(b,0))
#define vvbol(a,b,c) vector<vector<bool>> c(a,vector<bool>(b,0))
#define vvdb(a,b,c) vector<vector<double>> c(a,vector<double>(b,0))
#define fi(a,b) for(int i=a;i<b;i++)
#define fj(a,b) for(int j=a;j<b;j++)
#define f_i(a,b) for(int i=0;i<=b;i++)
#define f_j(a,b) for(int j=0;j<=b;j++)


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

    int n;
    cin >> n;
    long long count=0;
    set<long long> st;
    fi(0,n)
    {
        int a;
        cin >> a ;
        if(st.find(a)!=st.end())
        {
            continue;
        }
        else
        {
            count++;
            st.insert(a);
        }
    }
    cout << count << endl;

}

Measured memory_bytes: 3540
#include <bits/stdc++.h>
using namespace std;
string alrep(string str,string b,string a){
    int itr=0;
    while(str.find(b,itr)!=string::npos){
        //cout <<itr<< str;
        itr=str.find(b,itr);
        str.replace(itr,b.size(),a);
        //cout <<itr<< str<<endl;
        itr+=a.size();
    }
    return str;
}

int level;
int siz;
int minm=0;
void rp(vector<string> sb,vector<string> sa,string st,string en,int level){
    if(st.size()>siz)return;
    if(level>minm)return;
    for(int i=0;i<sb.size();i++){
        string str;
        str=alrep(st,sb[i],sa[i]);
        //cout << str <<" "<< sb[i] <<" "<<sa[i] <<" " <<st << endl;
        if(en==str){
            minm=level;
        }
        if(st!=str){
            rp(sb,sa,str,en,level+1);
        }
    }
}


int main(void){
    int n;
    while(cin >> n,n){
        minm=11;
        string st,en;
        vector<string> sb;
        vector<string> sa;
        for(int i=0;i<n;i++){
            getchar();
            string s;
            cin >> s;
            sb.push_back(s);
            cin >> s;
            sa.push_back(s);
        }
        cin >> st;
        cin >> en;
        //cout << st <<" "<< en <<" "<<sb[0] <<" " <<sa[0]  << endl;
        
        siz=en.size();
        rp(sb,sa,st,en,1);
        cout << ((minm==11)?-1:minm) << endl;

        
    }
}

Measured memory_bytes: 3124
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
#include <time.h>
#include <chrono>
#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,a,b) for(ll i=a;i>b;i--)
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
#define ct(a) cout<<a<<endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define repl(i,l,r) for(int i=(1);i<(r);i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
const ll INF = (1LL << 31) - 1;
const ll mod = 1e9 + 7;


string s, t;
ll ans;
bool canflag = false;
vector<ll> V[26];


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

	cin >> s >> t;


	FOR(i, 0, s.length()) {
		V[int(s[i] - 'a')].push_back(i);
	}

	int now = s.length()-1;
	FOR(i, 0, t.length()) {
		int cur = int(t[i] - 'a');

		if (V[cur].empty()) {
			canflag = true;
			break;
		}
		auto ite = upper_bound(V[cur].begin(),V[cur].end(), now);
		if (ite == V[cur].end()) {
			ans =(ans + (s.length() - now)+V[cur][0]);
			now = V[cur][0];
		}
		else {
			ans =(ans+ *ite - now);
			now = *ite;
		}


		//cout << ans << endl;
	}

	if (canflag) {
		cout << -1 << endl;
	}
	else {
		cout << ans << endl;
	}


}


Measured memory_bytes: 4580
n=int(input())
m=[[[0 for i in range(10)] for j in range(3)] for k in range(4)]
for i in range(n):
    b,f,r,v=map(int,input().split())
    m[b-1][f-1][r-1]+=v
for i in range(4):
    for j in range(3):
        for k in range(10):
            print(" "+str(m[i][j][k]),end="")
        print()
    if(i!=3):
        print("####################")


Measured memory_bytes: 5624
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  string s;
  cin >> s;
  ll K;
  cin >> K;
  int cnt = 0;
  rep(i,sz(s)) {
    if(s[i] == '1') {
      cnt++;
    } else {
      break;
    }
  }
  if(cnt >= K) {
    cout << 1 << endl;
  } else {
    cout << s[cnt] << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 100000

int partition(int *,int,int);
int main(){
  int A[N+1],n,i,q;
  scanf("%d",&n);
  for(i=1;i<=n;i++)
    scanf("%d",&A[i]);
  q=partition(A,1,n);
  for(i=1;i<q;i++)
    printf("%d ",A[i]);
  printf("[%d] ",A[q]);
  for(i=q+1;i<n;i++)
    printf("%d ",A[i]);
  printf("%d\n",A[n]);
  return 0;
}

int partition(int *A,int p,int r){
  int x,a,i,j;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i++;
      a=A[i];
      A[i]=A[j];
      A[j]=a;
    }
  }
  a=A[i+1];
  A[i+1]=A[r];
  A[r]=a;
  return i+1;
}



Measured memory_bytes: 2144
import sys
# import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
# from itertools import permutations, combinations, product, accumulate, groupby
# from bisect import bisect_left, bisect_right, insort_left, insort_right
# from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
# inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; ansli = []; tmpli = []; candili = []; mod = 10 ** 9 + 7
# dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]; ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]; ddn9 = ddn + [(0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]#WideIntPoint
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]#HeightString
def mi(n): return [wi() for _ in range(n)]#MatrixInt
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]

n, m = wi()
ab = mi(m)

point = [0 for i in range(n + 1)]

for i in range(m):
    point[ab[i][0]] += 1
    point[ab[i][1]] += 1

print("YES" if all(i % 2 == 0 for i in point) else "NO")

Measured memory_bytes: 28608
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int a,b;
    cin>>a>>b;
    vector<char> c(a);
    for(int i=0;i<a;i++){
        cin>>c.at(i);
    }
  string d;
    c.at(b-1)=c.at(b-1)+32;
    for(int i=0;i<a;i++){
      d=d+c.at(i);
    }
  cout<<d<<endl;
      
      
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef vector<double> vec;

int N,K;
vec x(100),y(100),c(100);
bool b(double t){
    int rev=0;
    for(int i=0;i<N;i++){
        int include=0;
        for(int j=0;j<N;j++){
            if(j==i){
                include++;
                continue;
            }
            double d=sqrt((x[j]-x[i])*(x[j]-x[i])+(y[j]-y[i])*(y[j]-y[i]));
            if(t/c[j]-t/c[i]>d) include++;
        }
        rev=max(rev,include);
    }
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            double d=sqrt((x[j]-x[i])*(x[j]-x[i])+(y[j]-y[i])*(y[j]-y[i]));
            double ri=t/c[i],rj=t/c[j];
            if(ri+rj<d) continue;
            vec v={(x[j]-x[i])/d,(y[j]-y[i])/d};
            vec w={(y[j]-y[i])/d,-(x[j]-x[i])/d};
            double X=(d+(ri*ri-rj*rj)/d)/2.0;
            double h=sqrt(ri*ri-X*X);
            int count=0;
            vec L={x[i]+X*v[0]+h*w[0],y[i]+X*v[1]+h*w[1]};
            for(int k=0;k<N;k++){
                if(k==i || k==j)count++;
                else if(sqrt((x[k]-L[0])*(x[k]-L[0])+(y[k]-L[1])*(y[k]-L[1]))<t/c[k])count++;
            }
            rev=max(rev,count);
            count=0;
            L={x[i]+X*v[0]-h*w[0],y[i]+X*v[1]-h*w[1]};
            for(int k=0;k<N;k++){
                if(k==i || k==j)count++;
                else if(sqrt((x[k]-L[0])*(x[k]-L[0])+(y[k]-L[1])*(y[k]-L[1]))<t/c[k])count++;
            }   
            rev=max(rev,count);         
        }
    }
    return rev>=K;
}
double BS(double l,double r){
    if(r-l<1.0e-10)return r;
    double m=(l+r)/2.0;
    if(b(m)) return BS(l,m);
    else     return BS(m,r);
}

int main(){
    scanf("%d %d",&N,&K);
    for(int i=0;i<N;i++){
        scanf("%lf %lf %lf",&x[i],&y[i],&c[i]);
    }
    printf("%.10lf\n",BS(0.0,1.0e10));
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef pair<ll, int> P;

int main()
{
    int N;
    cin >> N;
    vector<P> A(N), B(N);
    for(int i=0;i<N;++i){
        cin >> A[i].first;
        A[i].second = i;
    }

    for(int i=0;i<N;++i){
        cin >> B[i].first;
        B[i].second = i;
    }

    sort(B.begin(), B.end());
    sort(A.begin(), A.end());

    bool ans = true;
    for(int i=0;i<N;++i){
        if(A[i].first > B[i].first){
            ans = false;
            break;
        }
    }

    vector< int > p(N);
    if(ans){
        for(int i=0;i<N;++i){
            p[A[i].second] = B[i].second;
        }
        int count = 0, root = 0, node = 0;
        while(1){
            node = p[node];
            ++count;
            if(root == node) break;
        }
        if(count == N) {
            ans = false;
            for(int i=0;i<N-1;++i){
                if(A[i+1].first <= B[i].first){
                    ans = true;
                    break;
                }
            }
        }
    }

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


Measured memory_bytes: 3712
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long int llint;
int main() {
	int n;
	cin >> n;
	int a;
	int table[100001] = {};
	for (int i = 0;i < n;i++) {
		cin >> a;
		table[a]++;
	}
	int max = 0;
	for (int i = 1;i < 100000;i++) {
		if (max < table[i - 1] + table[i] + table[i + 1]) {
			max = table[i - 1] + table[i] + table[i + 1];
		}
	}
	cout << max << endl;
	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
int main()
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	int n=1000;
	int f=0;
	int sum=0;
	while(n--)
	{
		if(a%2!=0||b%2!=0||c%2!=0)
		{f=1;
		break;
		}
		else
		{   int x,y,z;
		    x=a;
		    y=b;
		    z=c;
			a=(y/2)+(z/2);
			b=(x/2)+(z/2);
			c=(x/2)+(y/2);
			sum++;
		}
	}
	if(f==1)
	printf("%d\n",sum);
	else
	printf("-1\n");
	
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>

using namespace std;

int n, k, num;
int backet[200005];

int main() {
	cin >> n >> k;
	int maxNum = -1;
	for (int i = 1, temp; i <= n; ++i)
	{
		cin >> temp;
		backet[temp] ++;
		maxNum = maxNum < temp ? temp : maxNum;
	}
	sort(backet + 1, backet + maxNum + 1);
	int p = 0;
	for (int i = 1; i <= maxNum; i ++) {
        if (backet[i] != 0)
           p ++;
   }
	int clip = p - k;
	int t = 1;
	int i = 1;
	while (t <= clip)
	{
		if (backet[i] != 0) 
		{
			num += backet[i];
			++ t;
		}
		++ i;
	}
	cout << num << endl;

	return 0;
}


Measured memory_bytes: 1024
d=int(input())
c=list(map(int,input().split()))
s=[list(map(int,input().split()))for _ in range(d)]
t=[int(input())for _ in range(d)]
m=int(input())
dq=[list(map(int,input().split()))for _ in range(m)]
x=[[0]for _ in range(26)]
ans=0
for i in range(d):
  x[t[i]-1].append(i+1)
  ans+=s[i][t[i]-1]
  for j in range(26):ans-=((i+1)-x[j][-1])*c[j]
for i in range(26):
  x[i].append(d+1)
for dd,q in dq:
  p=t[dd-1]
  t[dd-1]=q
  ans-=s[dd-1][p-1]
  ans+=s[dd-1][q-1]
  pi=qi=0
  while x[p-1][pi]!=dd:pi+=1
  while x[q-1][qi]<dd:qi+=1
  pl=dd-x[p-1][pi-1]
  pr=x[p-1][pi+1]-dd
  ql=dd-x[q-1][qi-1]
  qr=x[q-1][qi]-dd
  del x[p-1][pi]
  x[q-1].insert(qi,dd)
  ans-=c[p-1]*pl*pr
  ans+=c[q-1]*ql*qr
  print(ans)

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

signed main(void)
{
	string s;
	deque<char> deq; 
	bool rev;
	long long q, t, f;
	char p;

	cin >> s >> q;
	rev = false;
	for(auto ch: s)
		deq.push_back(ch);
	rep(i, q)
	{
		cin >> t;
		if (t == 1)
			rev = !rev;
		else if (t == 2)
		{
			cin >> f >> p;
			if (rev ^ (f == 2))
				deq.push_back(p);
			else 
				deq.push_front(p);
		}
	}
	if (rev) reverse(deq.begin(), deq.end());
	for (auto ch : deq)
	{
		cout << ch;
	}
	cout << endl;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
typedef complex<double> P;

P calc(P a,P b,P c,P d){
  a-=d;b-=d;c-=d;
  double A=imag(a/c),B=imag((a-b)/c);
  return d+a+(b-a)*A/B;
}

int main(){
  int n;
  double ax,ay,bx,by,cx,cy,dx,dy;
  scanf("%d",&n);
  while(n--){
    scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&ax,&ay,&bx,&by,&cx,&cy,&dx,&dy);
    P ans=calc(P(ax,ay),P(bx,by),P(cx,cy),P(dx,dy));
    printf("%.8f %.8f\n",ans.real(),ans.imag());
  }
  return 0;
}

Measured memory_bytes: 1256
#include<bits/stdc++.h>
using namespace std;
typedef vector<int>V;
int main(void){
	int n;
	V v;
	int x;
	int i;
	cin>>n;
	for(i=0;i<n;i++)	cin>>x,v.push_back(x);
	if(prev_permutation(v.begin(),v.end())){
		for(i=0;i<(int)v.size();i++){
			if(i)	cout<<" ";
			cout<<v[i];
		}
		cout<<endl;
	}
	next_permutation(v.begin(),v.end());
	for(i=0;i<(int)v.size();i++){
		if(i)	cout<<" ";
		cout<<v[i];
	}
	cout<<endl;
	if(next_permutation(v.begin(),v.end())){
		for(i=0;i<(int)v.size();i++){
			if(i)	cout<<" ";
			cout<<v[i];
		}
		cout<<endl;
	}
	return 0;
}


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

int		main(void)
{
	string	a;
	cin >> a;
	string	b;
	cin >> b;
	string	c;
	cin >> c;
	cout << a.at(0) << b.at(1) << c.at(2) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <limits>
#include <cmath>
#include <cassert>

using namespace std;
using ll = long long;

const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    string ans = "";
    for(int i = 0; i < s.size(); i++)
    {
        char ch = s[i] - 3;
        if(s[i] == 'A') ch = 'X';
        if(s[i] == 'B') ch = 'Y';
        if(s[i] == 'C') ch = 'Z';
        ans += ch;
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 3248
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int, int>;
typedef vector<int> vit;

//最大公約数
lol gcd(lol x, lol y){
  if(x < y) swap(x, y);
  lol r = x % y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}

//最小公倍数
lol lcm(lol x, lol y){
  lol a = x * y;
  return (a / gcd(x, y));
}

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

  int n, m;
  cin >> n >> m;
  vit ans[n + 5];
  int a, b;
  rep(i, m){
    cin >> a >> b;
    ans[a].pu(b);
    ans[b].pu(a);
  }
  reps(i, n){
    cout << ans[i].size() << '\n';
  }
  return 0;
}


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

int main()
{
	int N;
	cin >> N;
	vector<int> C( N );
	vector<int> S( N );
	vector<int> F( N );
	for( int i = 0; i < N - 1; i++ ) {
		cin >> C[i] >> S[i] >> F[i];
	}

	for( int i = 0; i < N; i++ ) {
		long long ans = 0;
		if( i == N - 1 ) cout << ans << endl;
		else {
			for( int j = i; j < N; j++ ) {
				if( j == N - 1 ) {
					cout << ans << endl;
					break;
				}
				else {
					if( ans <= S[j] ) ans += S[j] - ans;
					else {
						int m = ans % F[j];
						if( m ) ans += F[j] - m;
					}
					ans += C[j];
				}
			}
		}
	}
}


Measured memory_bytes: 3588
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>

#define rep(i, n) for(int i=0; i<(n); ++i)
#define max  200001

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
 
    int a[3];
    int ans;
    
    rep(i, 3){
        scanf("%d", &a[i]);
    }
    
    qsort(a, 3, sizeof(int), up_comp);
    
    printf("%d", 10*a[2]+a[0]+a[1]);
    
    return 0;
}

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

int main(){
    string s, t;
    cin >> s >> t;
    map<char, set<char>> ss, tt;
    for(int i = 0; i < s.size(); i++){
        tt[t[i]].insert(s[i]);
        ss[s[i]].insert(t[i]);
    }
    bool flag = true;
    for(auto c : s){
        if(ss[c].size() != 1){
            flag = false;
            break;
        }
        char opponent = *ss[c].begin();
        if(tt[opponent].size() != 1){
            flag = false;
            break;
        }
        if(*tt[opponent].begin() != c){
            flag = false;
            break;
        }
    }
    cout << (flag ? "Yes\n" : "No\n");
    return 0;
}

Measured memory_bytes: 776
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF  = 0x3f3f3f3f;
const ll  mod  = 1e9 + 7;
const ll  maxn = 1e6 + 5;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int s,w;
	cin>>s>>w;
	if(w>=s) cout<<"unsafe\n";
	else cout<<"safe\n";
	return 0;
}

Measured memory_bytes: 3652
const fi='c1.inp';
        fo='c1.out';
var n,i,mi,ma:longint;
        a:array[1..100] of longint;
begin


        readln(n);
        for i:=1 to n do read(a[i]);
        mi:=a[1];ma:=a[1];
        for i:=1 to n do
                if mi>a[i] then mi:=a[i];
        for i:=1 to n do
                if ma<a[i] then ma:=a[i];
        writeln(ma-mi);
end.


Measured memory_bytes: 128
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace ConsoleApp
{
    class Program
    {

        static void Main(string[] args)
        {
            var n = int.Parse(ReadLine());

            WriteLine(Math.Ceiling(n/2.0));


        }
        
       

    }

}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
 
using namespace std;
 
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileio freopen("in.in", "r", stdin),freopen("out.out", "w", stdout);
#define ll long long int
#define FF first
#define SS second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long int,long long 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 pss printf
#define MOD 1000000007
#define INF 1e18
#define eps 0.00001
#define endl '\n'
#define debug(n1) cout<<n1<<endl
ll n,y;
set<ll>s;
int main() {
slld(n);
ll x;
for(int i=1;i<=n;i++)
slld(x),s.insert(x);
ll an=s.size();
plld(an);
	return 0;
           } 

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

const string YES = "Yes";

const string NO = "No";

void solve(int D, int T, int S)
{
    if (S * T >= D)
        cout << YES << endl;
    else
        cout << NO << endl;
}

int main()
{
    int D;
    cin >> D;
    int T;
    cin >> T;
    int S;
    cin >> S;
    solve(D, T, S);
    return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
//cout << setprecision(20) << 

int D = 365;
vector<int> c(27);
vector<vector<int>> s(D + 1);

ll calc_score(vector<int> &t) {
    ll satisfy = 0;
    vector<int> last(27, 0);
    for (int i = 1; i <= D; ++i) {
        int con = t[i];
        // add satisfy
        satisfy += s[i][con];
        // update last
        last[con] = i;
        // sub satisfy
        for (int j = 1; j <= 26; ++j) {
            satisfy -= c[j] * (i - last[j]);
        }
    }
    return satisfy;
}

int main() {
    clock_t start = clock();

    cin >> D;
    for (int i = 1; i <= 26; ++i) cin >> c[i];
    for (int i = 1; i <= D; ++i) {
        vector<int> v(27);
        for (int j = 1; j <= 26; ++j) cin >> v[j];
        s[i] = v;
    }

    // output
    vector<int> ans(D + 1);
    vector<int> last(27, 0);
    ll satisfy = 0;
    for (int i = 1; i <= D; ++i) {
        ll max_pen = 0;
        ll choose_con = 0;
        for (int j = 1; j <= 26; ++j) {
            ll penalty = c[j] * (i - last[j]);
            if (penalty > max_pen) {
                choose_con = j;
                max_pen = penalty;
            }
        }
        // actual update
        int con = choose_con;
        last[con] = i;
        ans[i] = con;
    }

    // random
    // cout << "random" << endl;
    clock_t end = clock();
    double time = static_cast<double>(end-start) / CLOCKS_PER_SEC * 1000.0;
    ll best_score = calc_score(ans);
    random_device rd{};
    while (time < (double)1800) {
        // random
        ll mod;
        if (time < 800)
            mod = 200;
        else if (time < 1300)
            mod = 100;
        else 
            mod = 10;
        
        ll times = rd() % mod;
        vector<int> c_ans = ans;
        for (int j = 0; j < times; ++j) {
            ll day = rd() % 360 + 1;
            ll con = rd() % 25 + 1;
            c_ans[day] = con;
        }
        ll score = calc_score(c_ans);
        if (score > best_score) ans = c_ans;
        end = clock();
        time = static_cast<double>(end-start) / CLOCKS_PER_SEC * 1000.0;
    }

    // output
    for (int i = 1; i <= D; ++i) {
        cout << ans[i] << endl;
    }
}

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

#pragma GCC optimize("O3")
#define MOD 1000000007
#define pb push_back
#define fi first
#define se second
#define fr front()
#define ba back()
#define tp top()
#define mem(x,n) memset(x,n,sizeof(x));
#define sz(x) (int)((x).size())
#define all(x) (x).begin(),(x).end()
#define foreach(it,l) for(auto it=l.begin();it!=l.end();it++)
#define pnl printf("\n")
#define len(x) x.length()

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> pii;
typedef pair<pii,int> piii;
const int inf=(1<<30);
const LL llinf=(1ll<<60);
const double eps=(1e-10);
//const double pi=2*acos(0.0);
//const double GOLD=((1+sqrt(5))/2);
const int xx[8]={1,0,-1,0,1,-1,1,-1};
const int yy[8]={0,1,0,-1,-1,1,1,-1};

/* \( ·w·)~ Clapie ~(·w· )/ */

int n,k;
LL val[100005][3];
LL memo[100005][3];

LL dp(int idx,int sblm){
	if(idx==n) return 0;
	if(memo[idx][sblm]!=-1) return memo[idx][sblm];
	LL ret=0;
	for(int i=0;i<=2;i++){
		if(i!=sblm) ret=max(dp(idx+1,i)+val[idx][i],ret);
	}
	return memo[idx][sblm]=ret;
}

int main(){
	mem(memo,-1);
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%lld%lld%lld",&val[i][0],&val[i][1],&val[i][2]);
	}
	LL ans=dp(0,3);
	printf("%lld\n",ans);
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
#define int long long
using namespace std;
static const int MAX_N = 1ll<<17;
typedef pair<int,int> PII;
int dat[2*MAX_N-1];

class Segment{
    public :
        int n;
        void inti(int n_){
            n=1;
            while(n<n_)n*=2;
            for(int i=0;i<2*n-1;++i)dat[i]=-INT_MAX;
        }

        void update(int k,int a){
            k+=n-1;
            dat[k]=a;
            while(k>0){
                k=(k-1)/2;
                dat[k]=max(dat[k*2+1],dat[k*2+2]);
            }
        }

        int query(int a,int b,int k,int l,int r){
            if(a<=l&&r<=b)return dat[k];
            if(r<=a||b<=l)return -INT_MAX;
            else {
                int vl=query(a,b,k*2+1,l,(l+r)/2);
                int vr=query(a,b,k*2+2,(l+r)/2,r);
                return max(vl,vr);
            }
        }
};

int N;
vector<PII> A;

signed main(){
    cin>>N;
    Segment seg;
    seg.inti(N);
    for(int i=0;i<N;++i){
        int a;
        cin>>a;
        A.push_back(PII(a,-i));
    }
    sort(A.begin(),A.end());
    for(int i=0;i<N;++i){
        int j=-A[i].second;
        seg.update(j,1);
        seg.update(j,max(dat[j+seg.n-1],seg.query(0,j,0,0,seg.n)+1));
    }
    cout<<dat[0]<<endl;
    return 0;
}

Measured memory_bytes: 5144
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: u32 = read();

    let sum = n.to_string().chars().map(|c| ((c as u8) - b'0') as u32 ).sum::<u32>();

    println!("{}", if n % sum == 0 {"Yes"} else {"No"});
}


Measured memory_bytes: 4352
#include<stdio.h>
int main()
{
	int n,m,s[52][3],i,j,t[52],sum[52] = {0};
	scanf("%d %d",&n,&m);
	for(i = 0;i < m;i++)
		scanf("%d %d",&s[i][0],&s[i][1]);
	for(i = 0;i < n;i++)
		t[i] = i + 1;
	for(i = 0;i < m;i++)
	{
		for(j = 0;j < n;j++)
		{
			if(s[i][0] == t[j])
				sum[t[j] - 1]++;
		}
	}
	for(i = 0;i < m;i++)
	{
		for(j = 0;j < n;j++)
		{
			if(s[i][1] == t[j])
				sum[t[j] - 1]++;
		}
	}
	for(i = 0;i < n;i++)
		printf("%d\n",sum[i]);
	return 0;
}


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

int main(){
  int A, B, C;
  cin >> A >> B >> C;
  int ispoor = 0;
  if (A==B && A!=C) ispoor = 1;
  if (B==C && B!=A) ispoor = 1;
  if (C==A && C!=B) ispoor = 1;
  if (ispoor) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#abc095 c
a,b,c,x,y=map(int,input().split())
price=0
d=min(x,y)
if a+b>c*2:
    price+=2*c*d
else:
    price+=(a+b)*d

if x>y:
    price+=min(a*(x-y),2*c*(x-y))
else:
    price+=min(b*(y-x),2*c*(y-x))
print(price)
    

Measured memory_bytes: 3060
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<map>
#include<cmath>
#include<cstdlib>
#define mem(a) (memset(a,0,sizeof(a)))
using namespace std;
 const int N=10005;
const int mod=1e9+7;
int a[10];
int p(int n)
 {
    int b,flag=1;
    while(n){
         b=n%10;
         if(a[b]){
            flag=0;
             break;
         }
         n/=10;
     }
    if(flag) return 1;
     return 0;
 }
int main()
 {
    int n,k,s,t;
     cin>>n>>k;
     mem(a);
     for(int i=0;i<k;i++){
         cin>>t;
         a[t]=1;
     }
     for(int i=n; ;i++){
         if(p(i)){
             cout<<i<<endl;
             break;
        }
    }
    return 0;
 }


Measured memory_bytes: 256
N = int(input())
S = []
for i in range(N):
    S.append(input())

dic = {}
ans = 0

for i in S:
    tmp = "".join(sorted(i))
    if tmp in dic:
        dic[tmp] += 1
    else:
        dic[tmp] = 1
    
for i in dic.values():
    ##sum 1 to i-1 = (i^2-i)/2
    ans += (i*(i-1))//2

print(ans)


Measured memory_bytes: 24976
/*
    ASEEN AAN 
            PINDAN AALE JATT!!!
                                */
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
//#include <boost/functional/hash.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int lli;
lli M=1000000007;   
lli INF=1e17;
#define sqr(x) (x) * (x)
#define bip(n) __builtin_popcount(n)//no of ones bit in binary!!
#define bictz(n) __builtin_ctz(n)//no of trailing zeroes in binary!!
#define biclz(n) __builtin_clz(n)//no of leading zeroes in binary!!
#define bffs(n) __builtin_ffs(n)//index of first one bit!!
typedef pair<lli,lli> ll;
#define mem1(a,x) fill(&a[0], &a[0] + sizeof(a) / sizeof(a[0]), x)
#define mem2(a,x) fill(&a[0][0], &a[0][0] +sizeof(a)/sizeof(a[0][0]),x)
#define mem3(a,x) fill(&a[0][0][0], &a[0][0][0] +sizeof(a)/sizeof(a[0][0][0]),x)
#define fi1 ifstream fin("input.txt")
#define of1 ofstream fout("output.txt")
typedef tree<lli,null_type,less<lli>,rb_tree_tag,tree_order_statistics_node_update> ost;
lli n,q,z,y,k,m;
const double pi1=3.14159265358979323846;
//unordered_map<pair<ll,lli>,lli> mp;
lli me(lli a,lli b,lli M)
{
    if(b==0)
    return 1;
    else if(b%2==0)
    return me((a*a)%M,b/2,M);
    else
    return (a%M*me((a*a)%M,(b-1)/2,M)%M)%M;
}
lli mI(lli a,lli m)
{
    return me(a,m-2,m);
}
//lli tot=0;
vector<lli> pf(string s) {
    int n = (int)s.length();
    vector<lli> pi(n);
    for (int i = 1; i < n; i++) {
        int j = pi[i-1];
        while (j > 0 && s[i] != s[j])
            j = pi[j-1];
        if (s[i] == s[j])
            j++;
        pi[i] = j;
    }
    return pi;
}
//map<ll,lli> dp;
//set<lli> s[100005];
lli dp[3005][3005];
ll pre[3005][3005];
lli vis[3005][3005];
//string sdp[3005][3005];
lli x[3][105];
int main()
{
    ios_base::sync_with_stdio(0);
    lli w;
    string s1,s2;
    cin>>s1>>s2;
    n=s1.length();
    w=s2.length();
    string dd="\0";
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<w;j++)
        {
            if(s1[i]==s2[j])
            {
                dp[i+1][j+1]=dp[i][j]+1;
                vis[i+1][j+1]=1;
                pre[i+1][j+1]={i,j};
            }
            else
            {
                dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1]);
                if(dp[i+1][j+1]==dp[i+1][j])
                pre[i+1][j+1]={i+1,j};
                else
                pre[i+1][j+1]={i,j+1};
                vis[i+1][j+1]=2;
            }
        }
    }
    lli ii=n;
    lli jj=w;
    while(1)
    {
        if(ii==0||jj==0)
        break;
        if(vis[ii][jj]==1)
        dd+=s1[ii-1];
        ll p=pre[ii][jj];
        ii=p.first;
        jj=p.second;
    }
    reverse(dd.begin(),dd.end());
    cout<<dd;
}

Measured memory_bytes: 282368
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<bitset>
#include<cmath>
#include<queue>
#include<map>
#include<set>

using namespace std;

int read()
{
	int ans=0,f=1;
	char c=getchar();
	while(c>'9'||c<'0'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){ans=ans*10+c-'0';c=getchar();}
	return ans*f;
}

int n;
long long ans;

int main()
{
	n=read();
	for(int i=1;i<=n;++i)
		if(i%3!=0&&i%5!=0)
			ans+=i;
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 3764
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cstdio>
#include<cmath>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<tuple>
#include<utility>
#include<vector>
using namespace std;

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

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define REP(i, n)  for(int i=0; i<(int)(n); i++)
#define REPS(i, n)  for(int i=1; i<=(int)(n); i++)
#define PER(i, n) for(int i=(int)(n)-1; i>= 0; i--)
#define PERS(i, n)  for(int i=(int)(n)-1; i>0; i--)
#define FOR(i, c) for(__typeof((c).begin()) i = (c).begin(); i!=(c).end(); i++)
#define RFOR(i, c)  for(__typeof((c).rbegin()) i=(c).rbegin(); i!=(c).end(); i++)
#define ALL(container)  (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) (container).size()
#define FILL0(n)  setfill('0') << right << setw(n)
#define mp(a, b)  make_pair(a, b)
#define toLower(c)  c+0x20
#define toUpper(c)  c-0x20
#define pb  push_back
#define eb  emplace_back

const int INF = 1e9;
const long long LLINF = 1e18;
const int MOD = 1000000007;

int main(){
  int n, l;  cin >> n >> l;
  vector<int> vec(n);
  REP(i, n) {
    vec[i] = l + i;
  }
  int ans, m = INF, sum = 0;
  REP(i, n){
    sum += vec[i];
  }
  REP(i, n){
    if(m > abs(vec[i])){
      m = abs(vec[i]);
      ans = sum - vec[i];
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
package main
import(
  "fmt"
  "math"
)
func main() {
  var(
    a [6]int
    bottleneck int
  )
  bottleneck=math.MaxInt64
  for i:=0;i<=5;i++{
    fmt.Scan(&a[i])
    if bottleneck>a[i]{
      bottleneck=a[i] 
    }
  }
  if a[0]%bottleneck==0{
    fmt.Println(a[0]/bottleneck+4) 
  }else{
    fmt.Println(a[0]/bottleneck+5)
  }
}

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

int main() {
  int n; cin >> n;
  int l[n];
  for (auto &a : l) cin >> a;
  if (*max_element(l, l+n)*2 < accumulate(l, l+n, 0)) {
    cout << "Yes\n";
  } else cout << "No\n";
}


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;

int main(){
  string s;cin >> s;
  if(s == "SUN")cout << 7 << endl;
  else if(s == "MON")cout << 6 << endl;
  else if(s == "TUE")cout << 5 << endl;
  else if(s == "WED")cout << 4 << endl;
  else if(s == "THU")cout << 3 << endl;
  else if(s == "FRI")cout << 2 << endl;
  else if(s == "SAT")cout << 1 << endl;
  return 0;
}

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

using namespace std;
using ll = long long;
struct SegmentTree
{
    vector<int> _data;
    int N;
    bool minimum;
    SegmentTree(bool minimum):minimum(minimum){}
    void init(int _N){
        N=1;
        while (N < _N)N*=2;
        if(minimum)
            _data = vector<int>(N*2-1, INT_MAX);
        else
            _data = vector<int>(N*2-1, INT_MIN);
    }
    void update(int i, int value){
        i += N-1;
        _data[i] = value;
        while (i)
        {
            i = (i-1)/2;
            if (minimum) _data[i] = min(_data[i*2+1], _data[i*2+2]);
            else _data[i] = max(_data[i*2+1], _data[i*2+2]);
        }
    }
    void initVector(vector<int> v){
        for (int i = 0; i < v.size(); i++)
            update(i, v[i]);
    }
    int getMin(int left, int right, int l = 0, int r = -1, int k = 0){
        if(r == -1)r=N;
        if(r<=left||right<=l)return INT_MAX;
        if(left<=l&&right>=r)return _data[k];
        int v1=getMin(left,right,l,(l+r)/2,k*2+1);
        int v2=getMin(left,right,(l+r)/2,r,k*2+2);
        return min(v1,v2);
    }
    int getMax(int left, int right, int l = 0, int r = -1, int k = 0){
        if(r == -1)r=N;
        if(r<=left||right<=l)return INT_MIN;
        if(left<=l&&right>=r)return _data[k];
        int v1=getMax(left,right,k*2+1,l,(l+r)/2);
        int v2=getMax(left,right,k*2+2,(l+r)/2,r);
        return max(v1,v2);
    }
};




int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    int n, q; cin >> n >> q;
    SegmentTree st = SegmentTree(true);
    st.init(n);
    for (int i = 0; i < q; i++)
    {
        bool com;int x, y; cin >> com >> x >> y;
        if (com)
            cout << st.getMin(x, y+1) << endl;
        else 
            st.update(x, y);
    }
    
}


Measured memory_bytes: 3880
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>

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

int main() {
	int N;
	cin >> N;
	vector<int> p(N);
	rep(i, N) {
		cin >> p[i];
	}
	
	int dif = 0;
	int dif_old = 0;
	int cnt = 0;
	rep(i, N-1) {
		if(p[i]<p[i+1]) dif = 1;
		else dif = -1;

		if(dif==dif_old) cnt++;

		dif_old = dif;
	}

	cout << cnt << 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 n = Integer.parseInt(sc.next());
    int m = Integer.parseInt(sc.next());
    int brokenStair;
    int[] stair = new int[n];
    if(n == 1) {
      System.out.println(1);
    } else {
      Arrays.fill(stair, -1);
      stair[n-1] = 1;
      stair[n-2] = 1;
      for(int i = 0; i < m; i++) {
        brokenStair = Integer.parseInt(sc.next());
        stair[brokenStair-1] = 0;
      }
      for(int i = n-3; i >= 0; i--) {
        if(stair[i] == 0) continue;
        stair[i] = (stair[i+1] + stair[i+2]) % 1000000007;
      }
      int answer = (stair[0] + stair[1]) % 1000000007;
      System.out.println(answer);
    }
  }
}


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

int main() {
	double a, b, C;
	cin >> a >> b >> C;

	double pi = 3.141592653589793;

	double h = b * sin( C * pi / 180 );
	double S = a * h / 2.0;

	double x = a - b * cos( C * pi / 180 );
	double L = a + b + sqrt( x*x + h*h );

	cout << fixed << setprecision( 10 );
	cout << S << '\n' << L << '\n' << h << endl;
}



Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s, t;
  cin >> s >> t;
  int ln = s.length();
  vector<vector<int>> sal(26);
  for(int i = 0; i < ln * 2; i++) sal[s[i % ln] - 'a'].push_back(i);
  ll o = 0;
  for(int i = 0; i < t.length(); i++) {
    auto it = upper_bound(sal[t[i] - 'a'].begin(), sal[t[i] - 'a'].end(),
                          (i ? o % ln : -1));
    if(it == sal[t[i] - 'a'].end()) {
      cout << "-1\n";
      return 0;
    }
    o += *it - o % ln;
  }
  cout << o + 1 << '\n';
}

Measured memory_bytes: 1736