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

using namespace std;
using ll = long long;

signed main() {
    int n, k;
    cin >> n >> k;
    vector<int> h(n), dp(n, INT_MAX);
    // dp[i] обозначает минимальную стоимость достижения с помощью камня
    // 0 < i < n - 1 - это камни
    // Нас просят найти стоимость достижения последнего камня, т.е. dp[n - 1]
    for (int i = 0; i < n; i++) 
        cin >> h[i];
    // Чтобы добраться до первого камня, нет никаких затрат. Так что dp[0] = 0
    dp[0] = 0;
    // Чтобы добраться до второго камня лягушка может перепрыгнуть с 0-го камня на dp [1] = abs(h[1] - h[0])
    dp[1] = abs(h[1] - h[0]);
    // Для всех остальных камней 2 <= i < n лягушка может прыгать из (i - 1), (i - 2)...(i - k)й камни
    for (int i = 2; i < n; i++) {
        for (int j = i - 1, jump = 0; j >= 0 && jump < k; j--, jump++) {
            dp[i] = min(dp[i], dp[j] + abs(h[j] - h[i]));        
        }
    }
    cout << dp[n - 1];
    return false;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>
int main() {
	char s[105];
	long long int i,j=-1,k;
	scanf("%s%lld", s,&k);
	for (i = 0; s[i] == '1'; i++) {
		j = i;
	}
	if (k >= j + 2)printf("%c", s[j + 1]);
		if (k < j + 2)printf("1");
}

Measured memory_bytes: 128
'''

sekai_no_owari
 愛

''' 

n = int(input())
li = list(map(int, input().split()))
a = 1
c = 0
for i in range(n):
    if li[i] != a:
        c += 1
    else:
        a += 1
print(c) if c != n else print(-1)


Measured memory_bytes: 26140
import java.io.*;
import java.util.*;
import java.math.*;
class Main{
    public static void main(String[] args){
    BufferedReader sc=new BufferedReader(new InputStreamReader(System.in));
    try {
	while(true){
	String st = sc.readLine();
	if(st.equals("0000"))
		break;
	if(st.charAt(0)==st.charAt(1) && st.charAt(1)==st.charAt(2) && st.charAt(2)==st.charAt(3))
		System.out.println("NA");
	else{
	int num = 0;
	while(!st.equals("6174")){
	char[] ini = new char[4];
	for(int i=0; i<st.length(); i++)
		ini[i]=st.charAt(i);
	for(int i=st.length(); i<4; i++)
		ini[i]=Character.forDigit(0,10);
	Arrays.sort(ini);
	String s = new StringBuilder().append(ini[0]).append(ini[1]).append(ini[2]).append(ini[3]).toString();
	String l = new StringBuilder().append(ini[3]).append(ini[2]).append(ini[1]).append(ini[0]).toString();
	int now = Integer.valueOf(l)-Integer.valueOf(s);
	st = Integer.toString(now);
	num++;
	}
	System.out.println(num);
	}
	}
    }catch(Exception e){
        System.out.println("Error");
    }
    }
}

Measured memory_bytes: 41268
N,L=map(int,input().split())

out=0

if L>=0:
    out=(N-1)*L+(N-1)*N/2
elif -L>=N:
    out=N*(2*L+N-1)/2-L-N+1
else:
    out=N*(2*L+N-1)/2

print(int(out))


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
// const int MOD = 1e9 + 7;

int main() {
    string S;
    cin >> S;
    vector<int> d(4);
    for (int i = 0; i < (int)S.size(); i++) {
        if (S[i] == 'N') {
            d[0]++;
        } else if (S[i] == 'S') {
            d[1]++;
        } else if (S[i] == 'E') {
            d[2]++;
        } else if (S[i] == 'W') {
            d[3]++;
        }
    }
    if ((d[0] > 0 && d[1] > 0) || (d[0] == 0 && d[1] == 0)) {
        if ((d[2] > 0 && d[3] > 0) || (d[2] == 0 && d[3] == 0)) {
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template<u32 M = 1000000007>
struct modint{
    u32 val;
    modint(): val(0){}
    template<typename T>
    modint(T t){t %= (T)M; if(t < 0) t += (T)M; val = t;}

    modint pow(ll k) const {
        modint res(1), x(val);
        while(k){
            if(k&1) res *= x;
            x *= x;
            k >>= 1;
        }
        return res;
    }
    template<typename T>
    modint& operator=(T t){t %= (T)M; if(t < 0) t += (T)M; val = t; return *this;}
    modint inv() const {return pow(M-2);}
    modint& operator+=(modint a){val += a.val; if(val >= M) val -= M; return *this;}
    modint& operator-=(modint a){if(val < a.val) val += M-a.val; else val -= a.val; return *this;}
    modint& operator*=(modint a){val = (u64)val*a.val%M; return *this;}
    modint& operator/=(modint a){return (*this) *= a.inv();}
    modint operator+(modint a) const {return modint(val) +=a;}
    modint operator-(modint a) const {return modint(val) -=a;}
    modint operator*(modint a) const {return modint(val) *=a;}
    modint operator/(modint a) const {return modint(val) /=a;}
    modint operator-(){return modint(M-val);}
    bool operator==(const modint a) const {return val == a.val;}
    bool operator!=(const modint a) const {return val != a.val;}
    bool operator<(const modint a) const {return val < a.val;}
};
using mint = modint<MOD>;

int main() {
    int n, k;
    cin >> n >> k;
    vector<mint> v(k+1);
    for (int i = k; i >= 1; --i) {
        v[i] = mint(k/i).pow(n);
        for (int j = i+i; j <= k; j += i) {
            v[i] -= v[j];
        }
    }
    mint ans = 0;
    for (int i = 1; i <= k; ++i) {
        ans += mint(i)*v[i];
    }
    cout << ans.val << "\n";
    return 0;
}

Measured memory_bytes: 3788
gets
buildings = Array.new(4){Array.new(3){Array.new(10,0)}}
while gets
	b, f, r, v = $_.split.map(&:to_i)
	buildings[b-1][f-1][r-1] += v
end
puts buildings.map{|building|
	building.map{|floor|
		" "+floor*" "
	}*"\n"
}*"\n#{?#*20}\n"

Measured memory_bytes: 8716
import java.util.Scanner;

public class Main {
	static long solve(long N){
		if(N % 2 == 1){
			return 0;
		}
		long m = 5;
		long S = 0;
		while(m < N){
			S += N / (m * 2);
			m = m * 5;
		}
		return S;
	}
	public static void main(String[] args) {
//		for(int N = 1 ; N <= 100 ; ++N){
//			System.out.println(N+" "+solve(N));
//		}
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		System.out.println(solve(N));
	}
}


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



		Map<String, Boolean> wMap = new HashMap<>();
		boolean isRuled = true;
		String previousLastWord = "";
		for(int i=0;i<n;i++){
				String w = sc.next();
				// System.out.println(w);
				if(wMap.containsKey(w)){
					// System.out.println("containsKey");
					isRuled=false;
					break;
				}
				// System.out.println(w.substring(0,1));
				// System.out.println(previousLastWord);
				// System.out.println(w.substring(0,1).equals(previousLastWord));

				if(i>0 && !w.substring(0,1).equals(previousLastWord)){

					// System.out.println("equals");
					isRuled=false;
					break;
				}

				wMap.put(w,true);

				previousLastWord = w.substring(w.length()-1,w.length());
		}

		if(isRuled){
		System.out.println("Yes");
		}else{
		System.out.println("No");
		}

	}
}

Measured memory_bytes: 21844
b = input().split()
s = [int(n) for n in b]
W = s[0]
H = s[1]
x = s[2]
y = s[3]
r = s[4]

if x + r <= W and y + r <= H and x - r >= 0 and y - r >= 0:
    print("Yes")
else:
    print("No")



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

using namespace std;

int main(){
	int n,a[3],count;
	count =0;
	
	cin >> n;
	
	for (int i=0; i<3; i++){
		 a[i] = n%10;
		 n /= 10;
		}
		
		for (int j; j<3; j++){
			if (a[j]==7){
				count += 1;
			}
		}
		
		if (count > 0){
			cout << "Yes";
		}
		
		else {
			cout << "No";
		}
		
}

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

#define fir first
#define sec second
using namespace std;
typedef long long LL;
typedef unsigned long long u64;

template <typename T> inline bool cmin(T & a, const T & b) { return a > b ? a = b, 1 : 0;}
template <typename T> inline bool cmax(T & a, const T & b) { return a < b ? a = b, 1 : 0;}
int inp() {
	int x = 0, f = 1;char ch;
	for(ch = getchar(); !isdigit(ch); ch = getchar())
		if(ch == '-') f = -1;
	for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
	return x * f;
}

int q, h, s, d, n;
int main() {
	int i;
	cin >> q >> h >> s >> d >> n;
	LL ans = 0;
	int c = min(q * 8, h * 4);
	c = min(c, min(s * 2, d));
	ans += (LL) c * (n/2);
	if(n & 1) {
		ans += min(min(q * 4, h * 2), s);
	}
	cout << ans;
	return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int n, m;
    cin >> n >> m;
    vector<int> v(n);

    REP(i,m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        v[a]++;
        v[b]++;
    }

    bool ans = true;
    REP(i,n) {
        if (v[i] % 2 != 0) {
            ans = false;
            break;
        }
    }

    CFYN(ans)

    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#define M 100000

int A[M],n;

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

int main(){
  int i,q;

  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);

  q = ptt(0,n-1);
  
  for(i=0;i<n;i++){
    if(i) printf(" ");
    if(i == q) printf("[");
    printf("%d",A[i]);
    if(i == q)printf("]");
  }
  printf("\n");

  return 0;
}



Measured memory_bytes: 2092
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef string String;
typedef int i32;
typedef vector<int> VecTi32;
typedef string String;
int main(){
  i32 N, Q;
  cin >> N >> Q;
  String S;
  cin >> S;
  VecTi32 t(N+1);
  /*if(N % 2 == 0){
    S = S + "d";
    }*/
  String T = "AC";
  for(int i = 0; i < N; i++){
    //cout << S[i] << " " << S[i+1] << endl;
    if(S[i] == T[0] && S[i+1] == T[1]){
      //cout << S[i] << S[i+1]  << endl;
      t[i+1] = t[i] + 1;
    } else {
      t[i+1] = t[i] + 0;
    }
    //cout << t[i+1] << endl;
  }
  i32 l, r;
  for(int i = 0; i < Q; i++){
    cin >> l >> r;
    cout << t[r-1] - t[l-1] << endl;
  }
  return 0;
}


Measured memory_bytes: 1408
//g++ -std=gnu++14 a.cpp

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>
//#include <ostream>

using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

int main(){
  int N,R;
  cin >> N >> R;
  if(N>=10)cout << R << endl;
  else cout << R+100*(10-N) << endl;

}


Measured memory_bytes: 256
#include <cstdio>
#include <string.h>
#define INF 99999999
using namespace std;

typedef struct {
    int num;
    int time;
}node;
int n,l;
int dis[105][105],w[1005][1005];
int linker[1005],vis[1005];
node no[1005];

void floyd() {
    for(int k = 0;k < n;k++)
        for(int i = 0;i < n;i++)
            for(int j = 0;j < n;j++)
                if(dis[i][k] < INF &&
                   dis[k][j] < INF &&
                   dis[i][j] > dis[i][k] + dis[k][j])
                   dis[i][j] = dis[i][k] + dis[k][j];
}

bool dfs(int u) {
    for(int v = 1;v <= l;v++)
        if(w[u][v] && !vis[v]) {
            vis[v] = 1;
            if(linker[v] == -1 || dfs(linker[v])) {
                linker[v] = u;
                return true;
            }
        }
    return false;
}

int hungary() {
    int res = 0;
    memset(linker,-1,sizeof(linker));
    for(int u = 1;u <= l;u++) {
        memset(vis,0,sizeof(vis));
        if(dfs(u)) res++;
    }
    return res;
}

int main() {
    int m;
    //freopen("test.in","r",stdin);
    while(~scanf("%d%d%d",&n,&m,&l) && (n + m + l)) {
        memset(w,0,sizeof(w));
        for(int i = 0;i < n;i++)
            for(int j = 0;j < n;j++) {
                dis[i][j] = INF;
                if(i == j) dis[i][j] = 0;
            }


        while(m--) {
            int a,b,val;
            scanf("%d%d%d",&a,&b,&val);
            dis[a][b] = val;
            dis[b][a] = val;
        }

        floyd();

        for(int i = 1;i <= l;i++)
            scanf("%d%d",&no[i].num,&no[i].time);

        for(int i = 1;i <= l;i++)
            for(int j = 1;j <= l;j++) {
            if(i == j) continue;
            int f = no[i].num,t = no[j].num;
            int ft = no[i].time,tt = no[j].time;
            if(ft + dis[f][t] <= tt) w[i][j] = 1;
        }

        printf("%d\n",l - hungary());
    }
    return 0;
}

Measured memory_bytes: 5056
#include <bits/stdc++.h>
#include <iomanip>
#define ll long long int
#define lld double
#define vi vector<int>
#define pii pair<int,int>
#define piii pair<pii, ll>
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define ppb pop_back
#define d0(x) cout<<x<<" "
#define d1(x) cout<<x<<"\n"
#define d2(x,y) cout<<x<<" "<<y<<"\n"
#define d3(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl
#define d4(x,y,z,w) cout<<x<<" "<<y<<" "<<z<<" "<<w<<"\n"
#define d5(x,y,z,w,s) cout<<x<<" "<<y<<" "<<z<<" "<<w<<" "<<s<<endl
using namespace std;
const ll mod = 1e9+7;
 

void init();
void solve(int T);
int main(int argc, char* argv[])
{
    ios_base::sync_with_stdio ( false );cin.tie(0);cout.tie(0);
    int t1=1;
    init();
    //cin>>t1;
    for(int T=1;T<=t1;T++)
    {
        solve(T);
    }
}



void init()
{

}

ll po(ll a,ll m)
{
    if(m==0)return 1;
    ll x = po(a,m/2);
    x = (x*x)%mod;
    return m&1?(x*a)%mod:x;
}


ll N,a,b;

ll C(ll n, ll r)
{
    ll ret = 1;
    for(ll i=0;i<r;i++)
        ret = (ret*(n-i))%mod;
    return ret;
}


ll inv[200001];
void solve(int T)
{
    cin>>N>>a>>b;

    inv[0]=1;

    for(ll i=1;i<=b;i++)
    {
        inv[i] = (inv[i-1]*po(i,mod-2))%mod;
    }

    ll ans = po(2,N) - C(N,a)*inv[a] - C(N,b)*inv[b] - 1;
    ans%=mod;
    if(ans<0)ans+=mod;

    d1(ans);
}



Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main()
{
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int d1, d2;
  d1 = -(y2 - y1);
  d2 = x2 - x1;
  int x3, y3, x4, y4;
  x3 = x2 + d1;
  y3 = y2 + d2;
  d1 = -(x2 - x1);
  d2 = -(y2 - y1);
  x4 = x3 + d1;
  y4 = y3 + d2;
  cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <set>
#include <numeric>


#include <map>
#include <math.h>
#include <iomanip>
#include <stack>
#include <queue>

#define INF 100100100

using namespace std;


int main() {
	long long int n;
	cin >> n;
	long long int res;
	long long int count = 0;
	long long int n0 = n;
	while (n >= 10) {
		n /= 10;
		count++;
	}
	res = count * 9;
	long long int p=1;
	for (int i = 0; i < count; i++) {
		p *= 10;
	}
	if ((n0 + 1) % p == 0)res += n;
	else res += n - 1;
	cout << res;
	return 0;
}

Measured memory_bytes: 256
// Standard I/O
#include <iostream>
#include <sstream>
#include <cstdio>
// Standard Library
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
// Template Class
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
// Container Control
#include <algorithm>

using namespace std;

#define rep( i, n ) for( int i = 0; i < n; ++i )
#define irep( i, n ) for( int i = n-1; i >= 0; --i )
#define reep( i, s, n ) for ( int i = s; i < n; ++i )
#define ireep( i, n, s ) for ( int i = n-1; i >= s; --i )
#define foreach(itr, x) for( typeof(x.begin()) itr = x.begin(); itr != x.end(); ++itr)

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all( v ) v.begin(), v.end()
#define fs first
#define sc second
#define vc vector

// for visualizer.html
double SCALE = 1.0;
double OFFSET_X = 0.0;
double OFFSET_Y = 0.0;
#define LINE(x,y,a,b) cerr << "line(" << SCALE*(x) + OFFSET_X << ","	\
	<< SCALE*(y) + OFFSET_Y << ","										\
	<< SCALE*(a) + OFFSET_X << ","										\
	<< SCALE*(b) + OFFSET_Y << ")" << endl;
#define CIRCLE(x,y,r) cerr << "circle(" << SCALE*(x) + OFFSET_X << ","	\
	<< SCALE*(y) + OFFSET_Y << ","										\
	<< SCALE*(r) << ")" << endl;

typedef long long ll;
typedef complex<double> Point;

typedef pair<int, int> pii;
typedef pair<int, pii> ipii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector< vector<int> > vii;
typedef vector< vector<double> > vdd;

typedef vector<int>::iterator vi_itr;

const int IINF = 1 << 28;
const int MOD = 1e9+7;
const double INF = 1e30;
const double EPS = 1e-10;
const double PI = acos(-1.0);

// Direction : L U R D
const int dx[] = { -1, 0, 1, 0};
const int dy[] = { 0, -1, 0, 1 };

int N, C;
int c[500][500];
int d[30][30];
int cnt[3][30];
int ans;

int calc ( int color[3] ) {
    int ret = 0;

    rep(i, 3) {
        rep(j, C) ret += cnt[i][j]*d[j][color[i]];
    }

    return ret;
}

void search ( int color[3], int depth ) {
    if ( depth == 3 ) {
        ans = min(ans, calc(color));
        return;
    }

    rep(i, C) {
        bool flag = true;
        rep(j, depth) if ( color[j] == i ) {
            flag = false;
            break;
        }

        if ( !flag ) continue;

        color[depth] = i;
        search(color, depth+1);
    }
}

int main()
{
    cin >> N >> C;
    rep(i, C) rep(j, C) cin >> d[i][j];
    rep(i, N) rep(j, N) cin >> c[i][j];

    rep(x, 3) {
        rep(i, N) rep(j, N) {
            if( (i+1 + j+1)%3 == x ) {
                ++cnt[x][c[i][j]-1];
            }
        }
    }
    ans = IINF;
    
    int color[3];
    search(color, 0);

    cout << ans << endl;
}


Measured memory_bytes: 1280
#python3
from math import sqrt
from itertools import permutations
def dist(ti, tj):
    return sqrt((ti[0]-tj[0])**2 + (ti[1]-tj[1])**2)

def main():
    n = int(input())
    towns = []
    for _ in range(n):
        x,y = map(int, input().split())
        towns.append((x, y))    
    p = [i for i in range(n)]
    len = 0
    cnt = 0
    for index in permutations(p):
        for i in range(n-1):
            len += dist(towns[index[i]], towns[index[i+1]])
        cnt += 1
    print(len/cnt) 
main()


Measured memory_bytes: 3064
/* author   : mpily :-()
title : Competing.cpp
time :Sat Oct 19 15:27:56 2019

*/
#include<bits/stdc++.h>
using namespace std;
int main(){
	int N;
	cin>>N;
	int count = 0;
	char prev = '0';
	for(int i = 0; i < N; i++){
		char temp;
		cin>>temp;
		if(temp == prev)continue;
		else{
			count+=1;
			prev = temp;
		}
	}
	cout<<count<<"\n";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define ll long long
using Graph = vector<vector<int> >;
int main(){
    string s,t; cin >> s;
    cin >> t;
    int ans = 0;
    rep(i,s.size()){
        if(s[i]!=t[i]) ans++;
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 3916
#define _USE_MATH_DEFINES
#define FAST ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#include <bits/stdc++.h>
#define Loop(x, l, r) for(int x = l; x < r; ++x)
#define LoopR(x, l, r) for(int x = r-1; x >= l; --x)
#define all(x) x.begin(), x.end()
#define Kill(x) return cout << x << '\n', 0
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second
using namespace std;

const int N = 200'010;
int a[N];
int n, k;

int fen[N] = {};

void add(int r, int v)
{
    r++;
    while(r > 0)
    {
        fen[r] += v;
        r -= r & (-r);
    }
}
int get(int i)
{
    i++;
    int ans = 0;
    while(i <= n)
    {
        ans += fen[i];
        i += i & (-i);
    }
    return ans;
}

int main()
{
    FAST;
    cin >> n >> k; k = min(k, 43);
    Loop(i,0,n)
        cin >> a[i];
    Loop(_,0,k)
    {
        memset(fen,0,4*N);
        Loop(i,0,n)
        {
            int r = min(i+a[i], n-1);
            int l = max(i-a[i], 0);
            add(r, 1);
            add(l-1, -1);
        }
        Loop(i,0,n)
            a[i] = get(i);
    }
    Loop(i,0,n)
        cout << a[i] << ' ';
}


Measured memory_bytes: 5212
#include <bits/stdc++.h>
using namespace std;
const double eps=1e-2;
const int MAXN = 15;
int a[MAXN];
int main()
{
    int n; cin>>n;
    for(int i=0; i<n; i++) cin>>a[i];
    sort(a, a+n);
    int sum = a[n-1]/2;
    for(int i=0; i<n-1; i++) sum+=a[i];
    cout<<sum<<endl;
    return 0;
}


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

using namespace std;
const int INF = 40000;

int main(){
	int n, ma, mb, ans = INF;
	cin >> n >> ma >> mb;
	vector<vector<int>> dp(401, vector<int>(401, INF));
	for(int i = 0; i < n; i++){
		int a, b, c;
		cin >> a >> b >> c;
		dp[0][0] = 0;
		for(int j = 400; j >= a; j--){
			for(int k = 400; k >= b; k--){
				if(dp[j - a][k - b] == INF) continue;
				dp[j][k] = min(dp[j][k], dp[j - a][k - b] + c);
			}
		}
	}
	for(int i = ma, j = mb; i <= 400 && j <= 400; i += ma, j += mb){
		ans = min(ans, dp[i][j]);
	}
	cout << ((ans == INF)? -1 : ans )<< endl;
	return 0;
}

Measured memory_bytes: 1404
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

const int64_t MOD = std::pow(10, 9) + 7;

void OutputError(std::string s) {
  cerr << "\033[93m" << s << "\033[m" << endl;
  return;
}

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  int n;
  cin>>n;
  std::vector<int> a(n, 0);
  std::vector<int> count(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    count[a[i]]++;
  }
  if (n % 2 == 0) {
    int64_t result = 1;
    for (int i = 1; i < n; i += 2) {
      if (count[i] != 2) {
        cout << 0 << endl;
        return 0;
      }
      result *= 2;
      result %= MOD;
    }
    cout << result << endl;
    return 0;
  } else {
    int64_t result = 1;
    if (count[0] != 1) {
      cout << 0 << endl;
      return 0;
    } else {
      for (int i = 2; i < n; i += 2) {
        if (count[i] != 2) {
          cout << 0 << endl;
          return 0;
        }
        result *= 2;
        result %= MOD;
      }
      cout << result << endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

const int MOD = 1e9 + 7; // change if needed

struct Modint {
  ll val;
  
  Modint (ll _val = 0)
    : val(_val % MOD) {}

  Modint operator+ (Modint other) const {
    return Modint(val + other.val);
  }

  void operator+= (Modint other) {
    val += other.val;
    val %= MOD;
  }

  Modint operator- () const {
    return Modint(MOD - val);
  }

  Modint operator- (Modint other) const {
    return Modint(val + MOD - other.val);
  }

  void operator-= (Modint other) {
    val += MOD - other.val;
    val %= MOD;
  }

  Modint operator* (Modint other) const {
    return Modint(val * other.val);
  }

  void operator*= (Modint other) {
    val *= other.val;
    val %= MOD;
  }

  bool operator== (Modint other) const {
    return val == other.val;
  }

  bool operator!= (Modint other) const {
    return val != other.val;
  }
};

Modint exp (Modint a, int k) {
  if (k == 0) {
    return Modint(1);
  } else if (k % 2 == 0) {
    Modint half = exp(a, k / 2);
    return half * half;
  } else {
    return a * exp(a, k - 1);
  }
}

Modint inv (Modint a) {
  return exp(a, MOD - 2);
}

ostream& operator<< (ostream& out, Modint p) {
  out << p.val;
  return out;
}

const int MAX_N = 1e5 + 5;
const ll MAX_F = 1e10;

struct Fenwick {
  map<ll, Modint> tree;
  
public:
  void add (ll idx, Modint val) {
    for (ll i = idx; i < MAX_F; i += i & -i) {
      if (tree.count(i) == 0) {
        tree[i] = val;
      } else {
        tree[i] += val;
      }
    }
  }

  Modint get (ll idx) {
    Modint ans = 0;
    for (ll i = idx; i > 0; i -= i & -i) {
      auto fn = tree.find(i);
      if (fn != tree.end()) {
        ans += fn->second;
      }
    }
    return ans;
  }
};

#define l first
#define r second

bool comp (pair<ll, ll> p, pair<ll, ll> q) {
  if (p.r != q.r) {
    return p.r > q.r;
  }
  return p.l > q.l;
}

int bots [MAX_N];
int holes [MAX_N];

int main () {
  ios::sync_with_stdio(false);

  int n, m;
  cin >> n >> m;

  for (int i = 0; i < n; i++) {
    cin >> bots[i];
  }

  holes[0] = -1e9 - 5;
  for (int i = 1; i <= m; i++) {
    cin >> holes[i];
  }
  holes[m + 1] = 2e9 + 5;

  vector<pair<ll, ll>> pts;
  int ptr = 0;
  for (int i = 0; i < n; i++) {
    while (holes[ptr + 1] < bots[i]) {
      ptr++;
    }

    int ld = holes[ptr] - bots[i];
    int rd = holes[ptr + 1] - bots[i];

    if (ptr != 0 && ptr != m) 
      pts.push_back(make_pair(ld + 3e9, rd));
  }

  sort(pts.begin(), pts.end(), comp);

  Fenwick fen;

  Modint ans (0);
  pair<ll, ll> last = {-1, -1};
  for (pair<ll, ll> pt : pts) {
    if (pt != last) {
      Modint add = Modint(1) + fen.get(pt.l - 1);
      fen.add(pt.l, add);
      ans += add;
      last = pt;
    }
  }

  cout << ans + 1 << endl;
}


Measured memory_bytes: 41072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#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 rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

vector<pair<long long, long long> > res;

vector<pair<long long, long long> > prime_factorize(long long N) {

    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}

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

    ll N;
    cin >> N;
    vl a(100,0);
    rep(i,100){
        a[i]=(1+i)*i/2;
    }
    ll ans = 0;
    const auto &res = prime_factorize(N);
    for(auto it : res){
        //cout << it.fs << " " << it.sc << endl;
        ll tmp = 0;
        bool ok =false;
        while(!ok){
            rep1(i,100){
                //cout << "test" << endl;
                if(it.sc<a[i]){
                    //cout << i <<endl;
                    ans+=tmp;ok = true;break;
                }
                tmp++;
            }
        }
    }
    cout << ans << endl;
    

    return 0;
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
//#define int ll
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector< vvi > vvvi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<vvld> vvvld;
typedef vector<string> vst;
typedef vector<vst> vvst;
typedef pair<ld, ld> pld;
typedef complex<double> base;

#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define mp(a,b) make_pair(a,b)
#define modsum(a, b) ((a) + (b) >= M ? (a) + (b) - M : (a) + (b))
#define modsubtract(a, b) ((a) - (b) < 0 ? (a) - (b) + M : (a) - (b))
#define modmultiply(a, b) (((a) * (b)) % M)
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define sqr(x) ((x) * (x))
#define fori(i, n) for(int i = 0; i < int(n); ++i)
#define cint const int &
#define SZ(a) ((int)((a).size()))
#define watch(x) cout << (#x) << " = " << (x) << endl;

const double PI = 2 * acos(0.0);

const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";


template<class T>
inline ostream & operator << (ostream &out, vector<T> &a) {
    out << "{";
    fori (i, SZ(a))
        out << a[i] << vector<string>{", ", "}"}[i + 1 == SZ(a)];
    return out;
}

void smain();

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


#ifdef MAX_HOME
    freopen("input.txt", "r", stdin);
    clock_t start = clock();
#define cerr cout
#else
#define cerr if (0) cerr
#endif
    cout << setprecision(12) << fixed;
    smain();
#ifdef MAX_HOME
    cout << "\n\n\n\n";
    cout << "TOTAL EXECUTION TIME: " << float( clock () - start ) /  CLOCKS_PER_SEC << endl;
#endif
}

//12:18

const int N = 2e5 + 9;

ll h[N];
ll dp[N];
const ll oo = 1e18;
int n;
ll C;

struct Line {
    ll a, b;
    ld x;

    Line() {}

    Line(ll a, ll b) : a(a), b(b) {
        x = -oo;
    }
};

Line st[N];
int sz = 0;

ld intersect(Line a, Line b) {

    return (ld)(a.b - b.b) / (b.a - a.a);
}

inline void add_line(int ind) {
    Line line(2LL * h[ind], -dp[ind] - h[ind] * h[ind] - C);
//    st[sz++] = line;
    while (sz > 1) {
        ld x = intersect(st[sz - 2], line);
        if (x < st[sz - 1].x) {
            sz--;
        } else break;
    }
    if (sz == 0) {
        line.x = -oo;
        st[sz++] = line;
    } else {
        line.x = intersect(st[sz - 1], line);
        st[sz++] = line;
    }
}

Line get_line(ll x) {
    int l = -1, r = sz;
    while (r - l > 1) {
        int mid = l + r >> 1;
        (st[mid].x <= x ? l : r) = mid;
    }
    return st[l];
}

void smain() {

    cin >> n >> C;
    fori (i, n) cin >> h[i];
    dp[0] = 0;
    add_line(0);
    for (int i = 1; i < n; ++i) {
        Line line = get_line(h[i]);
        dp[i] = -(line.a * h[i] + line.b) + h[i] * h[i];
        add_line(i);
    }
    cout << dp[n - 1];
}

Measured memory_bytes: 9600
n = int(input())
xyh = [list(map(int,input().split())) for i in range(n)]


for x in range(101):
    for y in range(101):
        h = -1
        for k in xyh:
            if k[2] != 0:
                if h == -1:    
                    h = abs(k[2] + abs(k[0]-x) + abs(k[1]-y))
                elif h != abs(k[2] + abs(k[0]-x) + abs(k[1]-y)):
                    h = -2
                    break
        for k in xyh:
            if k[2] == 0:   
                tmp = abs(k[0]-x) + abs(k[1]-y)
                if h > tmp:
                    h = -2
                    break
        if h > 0:
            print(x,y,h)

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

using namespace std;

signed main()
{
	int n, l;
	cin >> n >> l;
	vector<string> vec(n);
	for (int i = 0; i < n; i++)
		cin >> vec[i];

	sort(vec.begin(), vec.end());
	for (int i = 0; i < n; i++)
		cout << vec[i];
	cout << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

// increment
#define rep_n(_1, _2, _3, NAME, ...) NAME
#define rep_2(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define rep_3(i, initial, n) for (int(i) = (int)(initial); (i) < (int)(n); ++(i))
#define rep(...) rep_n(__VA_ARGS__, rep_3, rep_2, rep_1)(__VA_ARGS__)
// decrement
#define rep_r_n(_1, _2, _3, NAME, ...) NAME
#define rep_r_2(i, n) for (int(i) = (int)(n); (i) > 0; (i)--)
#define rep_r_3(i, initial, n) for (int(i) = (int)(initial); (i) > (int)(n); (i)--)
#define rep_r(...) rep_r_n(__VA_ARGS__, rep_r_3, rep_r_2)(__VA_ARGS__)
// define type definition
using namespace std;
typedef long long ll;
using mpint = boost::multiprecision::cpp_int; // 多倍長整数（任意精度）
typedef pair<int, int> P;

// define construct variable
const double EPS = numeric_limits<double>::epsilon();
// 10^9 + 7
const ll MOD = ll(1e9)+7;
const ll INF = ll(1e10);
const string ALPHABET = "abcdefghijklmnopqrstuvwxyz";

// define methods
// 最大公約数
ll gcd(const ll a, const ll b) { return b ? gcd(b, a % b) : a; }
// 最小公倍数
ll lcm(const ll a, const ll b) { return a / gcd(a, b) * b; }
// char -> int
int ctoi(char c) { return (int)(c - '0'); }
// 素因数分解
vector< pair<ll, ll> > prime_factorize(ll n) {
  vector< pair<ll, ll> > p;
  for (ll i = 2; i * i <= n; i++) {
    if ((n % i) != 0) continue;
    p.push_back(make_pair(i, 0));
    while ((n % i) == 0) {
      n /= i;
      p[i].second += 1;
    }
    p.push_back(make_pair(n, 0));
  }

  if (n != 1) p.push_back(make_pair(n, 1));
  return p;
}
// 組み合わせの整合性を保つ（後ほど解析する）
ll modinv(ll a) {
	ll b = MOD, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b;
		swap(a, b);
		u -= t * v;
		swap(u, v);
	}
	u %= MOD;
	if (u < 0) { u += MOD; }
	return u;
}
// 順列
ll permutation(const ll n, const ll m) {
	ll result = 1;
	for (ll i = n; i > n - m; i--) { result = (result * i) % MOD; }
	return result;
}

// 繰り返し n 乗法
ll repeat_square(const ll n, const ll x) {
	if (x == 0) return 1;
	ll res = repeat_square(n, x/2);
	res = res * res % MOD;
	if ((x % 2) == 1) res = res * n % MOD;
  return res;
}
// 組み合わせ
ll combination(const ll n, const ll a) {
	ll x = 1, y = 1;
  for(ll i = 0; i < a; i++){
    x = x * (n-i) % MOD;
    y = y * (i+1) % MOD;
  }
  return x * repeat_square(y, MOD-2) % MOD;
}

int main() {
	int N;
	cin >> N;
	vector<int> A(N, 0);
	rep(i, N) {
		cin >> A[i];
	}

	int start = 1;
	rep(i, N) {
		if (A[i] == start) {
			start += 1;
			continue;
		}
		A[i] = -1;
	}

	int result = 0;
	rep (i, N) {
		if (start != 1 && A[i] == -1) result += 1;
	}

	if (start == 1 && result == 0) {
		cout << "-1" << endl;
	} else {
		cout << result << endl;
	}

  return 0;
}


Measured memory_bytes: 1152
import Control.Applicative
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import qualified Data.List as L
import Data.Map ((!))
import qualified Data.Map as M
import Data.Maybe
import qualified Data.Set as S
import qualified Data.Tuple as T

addToSet :: (Num a, Ord a) => S.Set (a, Int) -> [(Int, a)] -> S.Set (a, Int)
addToSet set xs = L.foldl' (\ acc x -> S.insert (T.swap x) acc) set xs


addToMap :: Ord k => M.Map k a -> [(k, a)] -> M.Map k a
addToMap m xs = L.foldl' (\ acc (x, d) -> M.insert x d acc) m xs


dijkstra :: (Num a, Ord a) => M.Map Int [(Int, a)] -> Int -> M.Map Int a
dijkstra graph source = dijkstra' graph (S.singleton (0, source))
                        (M.singleton source 0)


dijkstra' :: (Ord t, Num t) => M.Map Int [(Int, t)]     -- ^ graph structure
          -> S.Set (t, Int)                             -- ^ priority queue
          -> M.Map Int t -> M.Map Int t                 -- ^ result
dijkstra' graph pq res
    | S.null pq = res
    | otherwise = dijkstra' graph (addToSet pq' info) (addToMap res info)
    where
      fwd = M.findWithDefault
      ((dis, node), pq') = S.deleteFindMin pq
      nodes = fwd [] node graph
      update = filter (\ (x, e) -> M.notMember x res ||
                                   dis + e < res!x) nodes
      info = map (\ (x, e) -> (x, dis + e)) update


buildGraph :: Ord t => [(t, t1, t2)] -> M.Map t [(t1, t2)]
buildGraph edges =
    let g = L.groupBy (\ (x, _, _) (y, _, _) -> x == y) edges
    in M.fromList (map (\ x -> (f1 $ head x, map (\ (_, y, z) -> (y, z)) x)) g)

readInt' :: BS.ByteString -> Int
readInt' = fst . fromJust . BS.readInt

f1 :: (t, t1, t2) -> t
f1 (x, _, _) = x

f3 :: (t, t1, t2) -> t2
f3 (_, _, x) = x

main :: IO ()
main = do
  contents <- BS.lines <$> BS.getContents
  let edges = map (\ [x, y, z] -> (x, y, z))
              (map (\ x -> map readInt' (BS.words x)) contents)
      res = dijkstra (buildGraph $ L.sort $ tail edges) (f3 $ head edges)
      n = f1 $ head edges
  forM_ [0..(n - 1)] $ \i -> do
         if M.member i res
         then print (M.findWithDefault (-1) i res)
         else putStrLn "INF"

Measured memory_bytes: 255948
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
#define fs first
#define sc second
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
// 多倍長
#include <boost/rational.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using boost::rational;
using boost::multiprecision::cpp_int;

const double PI = acos(-1);
const int INF = 1e9;
const ll LLINF = 1e16;
const ll MOD = 1e9+7;
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

 

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}


// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
  return (a + b - 1) / b;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 回文判定
bool kai (string s) {
    string t{s};
    reverse(begin(t), end(t));
    return s == t;
}

using pint = pair<int, int>;
using pll = pair<ll, ll>;


vector<string> split(const string &s, char delim) {
    vector<string> elems;
    string item;
    for (char ch: s) {
        if (ch == delim) {
            if (!item.empty())
                elems.push_back(item);
            item.clear();
        }
        else {
            item += ch;
        }
    }
    if (!item.empty())
        elems.push_back(item);
    return elems;
}



int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int n,x,t;
    cin >> n >> x >> t;
    int ans = rp(n, x);
    print(ans * t);


}



Measured memory_bytes: 3640
#                               #
    # author : samars_diary #
    # 18-09-2020 │ 15:02:48 #
#                               #

import sys, os.path

#if(os.path.exists('input.txt')):
    #sys.stdin = open('input.txt',"r")
    #sys.stdout = open('output.txt',"w")

sys.setrecursionlimit(10 ** 5)

def mod(): return 10**9+7
def i(): return sys.stdin.readline().strip()
def ii(): return int(sys.stdin.readline())
def li(): return list(sys.stdin.readline().strip())
def mii(): return map(int, sys.stdin.readline().split())
def lii(): return list(map(int, sys.stdin.readline().strip().split()))

#print=sys.stdout.write

def solve():
    n,k=mii();b=0;a=sorted(lii())
    for i in range(k):
        b+=a[i]
    print(b)

for _ in range(1):
    solve()

Measured memory_bytes: 9256
/// kAAzuki Hoshino
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
//#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

 
int n;
int a[202020],c[202020];

signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
        

	cin >> n;
	int cur = 0, cnt = 0, sum = 0;
	for(int i=1;i<=n;i++){
		cin >> a[i] >> c[i];
		cnt+= c[i];
		sum+= a[i]*c[i];
	}
	cnt+= (sum-1)/9;
	cout << cnt-1 << endl;

return 0;
}
///....


Measured memory_bytes: 3456
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int[] antena = new int[5];
      for(int i=0;i<5;i++){
	antena[i]=sc.nextInt();
      }
		int k=sc.nextInt();
		for(int i=0;i<4;i++) {
			for(int j=i+1;j<5;j++) {
             
				if(antena[j]-antena[i]>k) {System.out.println(":("); return;}
			}
		}
System.out.println("Yay!");
	}
}


Measured memory_bytes: 21844
from collections import deque


def main():

    N = int(input())
    g = {}
    for i in range(N):
        g[i] = set()

    for i in range(N - 1):
        a, b = map(int, input().split())
        g[a - 1].add(b - 1)
        g[b - 1].add(a - 1)

    # BFS
    dist = [-1] * N     # [-1:initial, 0:even, 1:odd]
    dist[0] = 0
    n_even = 0
    que = deque([0])
    while len(que):
        v = que[0]
        if dist[v] % 2 == 0:
            n_even += 1
        que.popleft()
        for n in g[v]:
            if dist[n] == -1:
                dist[n] = (dist[v] + 1) % 2
                que.append(n)

    ans = [-1] * N
    if n_even <= int(N / 3):
        n3, n3q, n3r = 1, 0, 1
        for i in range(N):
            if dist[i] == 0:
                ans[i] = n3 * 3
                n3 += 1
            else:
                if n3q * 3 + n3r <= N:
                    ans[i] = n3q * 3 + n3r
                    if n3r == 1:
                        n3r = 2
                    else:
                        n3q += 1
                        n3r = 1
                else:
                    ans[i] = n3 * 3
                    n3 += 1
    elif n_even > int(N * 2 / 3):
        n3, n3q, n3r = 1, 0, 1
        for i in range(N):
            if dist[i] == 1:
                ans[i] = n3 * 3
                n3 += 1
            else:
                if n3q * 3 + n3r <= N:
                    ans[i] = n3q * 3 + n3r
                    if n3r == 1:
                        n3r = 2
                    else:
                        n3q += 1
                        n3r = 1
                else:
                    ans[i] = n3 * 3
                    n3 += 1
    else:
        n3, n31, n32 = 1, 0, 0
        for i in range(N):
            if dist[i] == 0:
                if n31 * 3 + 1 <= N:
                    ans[i] = n31 * 3 + 1
                    n31 += 1
                else:
                    ans[i] = n3 * 3
                    n3 += 1
            else:
                if n32 * 3 + 2 <= N:
                    ans[i] = n32 * 3 + 2
                    n32 += 1
                else:
                    ans[i] = n3 * 3
                    n3 += 1

    print(' '.join(map(str, ans)))


if __name__ == '__main__':
    main()




Measured memory_bytes: 109572
#include <iostream>

using namespace std;

typedef long long int ll;

int main()
{
  ll A, B;
  cin >> A >> B;
  
  if(B%A==0)
  {
    cout << A+B << endl;
  }
  
  else
  {
    cout << B-A << endl;
  }
  
  return 0;
}

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

int main(){
	int n;
	cin >> n;
	int a[n];
	int primax = 0;
	int secmax = 0;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		if(a[i] > primax){
			primax = a[i];
		}else if(a[i] > secmax && a[i] <= primax){
			secmax = a[i];
		}
	}
	for(int i = 0; i < n; i++){
		if(a[i] == primax){
			cout << secmax << endl;
		}else{
			cout << primax << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 2432
#include <iostream>

using namespace std;

int main()
{
    int A ,B ,C;

  cin >> A >> B >> C;

  if ( (A == 5 && B == 5 && C == 7) || (B == 5 && C == 5 && A == 7) || (A ==5 && C == 5 && B == 7)  )

    cout << "YES";

    else
    cout << "NO";


    return 0;
}

Measured memory_bytes: 256
//This code uses a C++ Template written by Marcus Handley
//Adapated from Compeitive Programming 3 - A new lower bound
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

#define INF 1000000000
#define MOD 1000000007
#define LOG_LEVEL 0
#define PB push_back
#define P push
#define F first
#define S second
#define ILLP if(LOG_LEVEL)printf
#define SZ(x) ((int)((x).size()))
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))
#define ALL(x) x.begin(),x.end()
#define SMAX(x, y) ((x) = max((x), (y)))
#define SMIN(x, y) ((x) = min((x), (y)))
#define LOOP(x,n) for(int x = 0; x < n; ++x)
#define PI acos(-1.0)


typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;

typedef char byte;

int A[300][300];
int main(){
  int N; scanf("%d",&N);
  LOOP(i, N) LOOP(j, N) scanf("%d",&A[i][j]);
  ll ans = 0;
  LOOP(i, N) for (int j = i+1; j<N; j++){
    int dist = A[i][j];
    ILLP("i = %d j = %d A[%d][%d] = %d\n",i,j,i,j,dist);
    bool equals = false;
    LOOP(w, N){
      if (w==j || w == i) continue;
      ILLP(" w = %d\n",w);
      if (A[i][w]+A[j][w  ]<dist){
        printf("-1\n");
        return 0;
      }
      if (A[i][w]+A[j][w]==dist){
        equals = true;
        break;
      }
    }
    if (!equals) ans+=dist;
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 512
#create date: 2020-08-10 07:31

import sys
stdin = sys.stdin
import math

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    a, b = ns().split(" ")
    n = int(a+b)
    if math.sqrt(n).is_integer():
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()

Measured memory_bytes: 9064