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

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

typedef long long ll;

int main() {
  int n, m;
  cin >> n >> m;

  vector<int> a(n);
  for(int i=0; i<n; i++) cin >> a[i];

  vector<pair<int, int>> bc(m);

  for(int i=0; i<m; i++){
    int b, c;
    cin >> b >> c;
    bc[i] = make_pair(-c, b);
  }

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

  vector<int> c(n);
  int cnt = 0;
  for(int i=0; i<m; i++){
    for(int j=0; j<bc[i].second; j++){
      c[cnt] = abs(bc[i].first);
      cnt++;
      if(cnt == n) break;
    }
    if(cnt == n) break;
  }
  
  ll ret = 0;
  sort(a.begin(), a.end());
  for(int i=0; i<n; i++){
    if(c[i] > a[i]) ret += c[i];
    else ret += a[i];
  }

  cout << ret << endl;

  return 0;
}

Measured memory_bytes: 1792
s = int(input())
a = s
lis = list()

while True:
    if (s % 2) == 0:
        s = s / 2
        if s in lis:
            break
        lis.append(int(s))
    else:
        s = 3*s + 1
        if s in lis:
            break
        lis.append(int(s))
if (a ==1) or (a == 2) or (a == 4):
    print(4)
else:
    print(len(lis)+2)

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

int main() {
    int A, B; cin >> A >> B;
    int ans = 0;
    if( B == 1 ) {cout << 0 << endl; return 0;} 
    while(++ans){
        if( 1 + (A-1) * ans >= B ){
            cout << ans << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for(LL i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(LL i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(LL i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(LL i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC static_cast
#define SI(v) SC<int>(v.size())
#define SL(v) SC<LL >(v.size())
#define RF(e, v) for(auto & e: v)
#define ef else if
#define UR assert(false)

// ---- ----

LL n, m, l, q, INF = 700;

template<typename T> class RPQ : public priority_queue<T, vector<T>, greater<T>> { };
template<typename C> void dijkstra(int s, vector<pair<int, C>> g[], pair<C, C> d[]) {
	typedef pair<C, C> Z;
	RPQ<pair<Z, int>> q;
	d[s] = { 0, 0 };
	q.emplace(d[s], s);
	while(! q.empty()) {
		Z   c = q.top().FI;
		int v = q.top().SE;
		q.pop();
		if(d[v] != c) { continue; }
		for(auto & e : g[v]) {
			int ev = e.FI;
			C   ec = e.SE;
			auto x = d[v];
			
			if(x.SE + ec <  l) { x.SE += ec; }
			ef(x.SE + ec == l) { x.FI++; x.SE = 0; }
			else               { x.FI++; x.SE = ec; }
			
			if(setmin(d[ev], x)) { q.emplace(d[ev], ev); }
		}
	}
}

vector<pair<int, LL>> g[300];
pair<LL, LL> d[300][300];

int main() {
	cin >> n >> m >> l;
	inc(i, m) {
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		if(c <= l) {
			g[a].EB(b, c);
			g[b].EB(a, c);
		}
	}
	
	inc(i, n) {
	inc(j, n) {
		d[i][j] = { INF, INF };
	}
	}
	
	inc(i, n) { dijkstra(i, g, d[i]); }
	
	inc(i, n) {
	inc(j, n) {
		if(d[i][j].FI >= INF) { d[i][j] = { -1, -1 }; }
		if(d[i][j].SE == 0) { d[i][j].FI--; }
	}
	}
	
	cin >> q;
	inc(qq, q) {
		int s, t;
		cin >> s >> t;
		s--; t--;
		
		cout << d[s][t].FI << "\n";
	}
	
	return 0;
}


Measured memory_bytes: 5652
import java.util.*;

class Main {
    static Node[] ns;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Q = sc.nextInt();
        ns = new Node[N];
        for (int i = 0; i < N; i++)
            ns[i] = new Node(i);
        for (int i = 0; i < N - 1; i++) {
            int s = sc.nextInt() - 1;
            int t = sc.nextInt() - 1;
            ns[s].add(ns[t]);
            ns[t].add(ns[s]);
        }
        dfs(ns[0], null);
        for (int i = 0; i < Q; i++) {
            int p = sc.nextInt();
            int x = sc.nextInt();
            ns[p - 1].cnt += x;
        }
        sum(ns[0]);
        StringJoiner res = new StringJoiner(" ");
        for (Node node : ns)
            res.add(String.valueOf(node.cnt));
        System.out.println(res.toString());
        sc.close();
    }

    private static void sum(Node node) {
        if (node.parent != null)
            node.cnt += node.parent.cnt;
        for (Node c : node) {
            if (c != node.parent) {
                sum(c);
            }
        }
    }

    private static void dfs(Node c, Node p) {
        c.parent = p;
        for (Node cc : c)
            if (cc != p)
                dfs(cc, c);
    }

    static class Node extends ArrayList<Node> {
        Node parent;
        int id;
        int cnt = 0;

        Node(int _id) {
            id = _id;
        }
    }
}

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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define all(v) v.begin(), v.end()

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;

const ll INF = (1LL<<60);

int main(){

    ll n, m; cin >> n >> m;
    ll l, r; cin >> l >> r;
    ll inl, inr;
    rep2(i, 1, m){
        cin >> inl >> inr;
        l = max(l, inl);
        r = min(r, inr);
    }

    cout << max(r-l+1, (ll)0) << endl;

    return 0;
}

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

#define ll long long
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)

ll a[55], b[55], c[55], d[55];
ll N, M, Q;
ll nums[11];
ll ans = 0;

void solve(ll dep, ll now) {
    if (dep < N) {
        REP(i, now, M + 1) {
            nums[dep] = i;
            solve(dep + 1, i);
        }
    } else {
        ll tmp = 0;
        REP(i, 0, Q) {
            if (nums[b[i]] - nums[a[i]] == c[i]) {
                tmp += d[i];
            }
        }
        ans = max(ans, tmp);
    }
}
 
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> M >> Q;
    REP(i, 0, Q) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--;
        b[i]--;
    }
    solve(0, 1);
    cout << ans << endl;
}

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

int main( void )
{
	const int INF = ( 1 << 21 );

	int m, n;
	while ( cin >> m >> n && m > 0 && n > 0 )
	{
		vector <int> S(n+1,0);
		for ( int i = 1; i <= n; i++ )
			cin >> S[i];

		vector <int> P(n+1,0);
		for ( int i = 1; i <= n; i++ )
			P[i] = P[i-1] + S[i];

		vector < vector <int> > M( n+1, vector <int>( m+1, 0 ) );

		for ( int i = 1; i <= n; i++ )
			M[i][1] = P[i];

		for ( int i = 1; i <= m; i++ )
			M[1][i] = S[1];

		for ( int i = 2; i <= n; i++ )
		{
			for ( int j = 2; j <= m; j++ )
			{
				M[i][j] = INF;
				for ( int x = 1; x <= i - 1; x++ )
				{
					int maxv = max( M[x][j-1], P[i]-P[x] );
					if ( M[i][j] > maxv )
						M[i][j] = maxv;
				}
			}
		}

		cout << M[n][m] << endl;

	}

	return 0;
}

Measured memory_bytes: 0
N, K = map(int, input().split())
A = list(map(int, input().split()))

ans = sum([a for a in A if a > 0])
B = [a if a <= 0 else 0 for a in A]

s = sum(B[:K])
s_max = s
for i in range(N-K):
  s += B[i+K] - B[i]
  s_max = max(s_max, s)

B = [a if a > 0 else 0 for a in A]
s = sum(B[:K])
s_min = s
for i in range(N-K):
  s += B[i+K] - B[i]
  s_min = min(s_min, s)

print(max(ans+s_max, ans-s_min))

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

#define ALL(a) (a).begin(), (a).end()
#define ll long long

using namespace std;

signed main(){
    int n,k; cin >> n >> k;
    vector<int> a(n);
    int midx,nmin = (int)1e7;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(a[i] < nmin){
            midx = i;
            nmin = a[i];
        }
    }
    int ans = 0;
    for(int i = 1; i < n; i += k-1){
        ans++;
    }
    cout << ans << endl;



    return 0;
}



Measured memory_bytes: 640
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n;
		while ((n = in.nextInt()) > 0) {
			Map<String, Set<String>> map = new HashMap<String, Set<String>>();
			int m = in.nextInt();
			map.put("1", new HashSet<String>());
			for (int i = 0; i < m; i++) {
				String a = in.next();
				String b = in.next();
				Set<String> af;
				if (map.containsKey(a)) {
					af = map.get(a);
				} else {
					af = new HashSet<String>();
					map.put(a, af);
				}
				af.add(b);
				Set<String> bf;
				if (map.containsKey(b)) {
					bf = map.get(b);
				} else {
					bf = new HashSet<String>();
					map.put(b, bf);
				}
				bf.add(a);
			}
			Set<String> xmas = map.remove("1");
			for (Iterator<Set<String>> it = map.values().iterator(); it
					.hasNext();) {
				Set<String> ff = it.next();
				if (ff.contains("1")) {
					xmas.addAll(ff);
				}
			}
			xmas.remove("1");
			System.out.println(xmas.size());
		}
	}
}

Measured memory_bytes: 36544
# coding: ascii

# s = 0
# 15.times do |i|
#   s = s^i 
#   p [i,s]
# end


def f(n)
  ((n / 4 * 4)..n).reduce(0){|s,t|s^t}
end

a, b = gets.to_s.split.map{|i|i.to_i}

p f(b)^f(a-1)

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define reg register
#define ll long long
#define int long long
#define maxn 200001
#define mod 1312344234139
using namespace std;
inline ll read(){
    reg ll s = 0, t = 0; reg char ch = getchar();
    while(ch > '9' || ch < '0') t |= ch == '-', ch = getchar();
    while(ch >= '0' && ch <= '9') s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
    return t ? -s : s;
}

ll prime[maxn], is_prime[maxn], a[maxn], b[maxn], c[maxn], f[maxn], ans, maxx = 10000, cnt, n;
map<ll, ll> mp, d;
signed main(){
    n = read();
    for(int i = 1; i <= n; i++) a[i] = read();
    for(int i = 2; i <= maxx; i++){
        if(!is_prime[i]) prime[++cnt] = i;
        for(int j = 1; j <= cnt && prime[j] * i <= n; j++){
            is_prime[i * prime[j]]  = 1;
            if(i % prime[j] == 0) break;
        } 
    }
    for(int i = 1; i <= n; i++) c[i] = 1, b[i] = 1;
    for(int i = 1; i <= cnt; i++){
        ll t = prime[i] * prime[i] * prime[i];
        for(int j = 1; j <= n; j++) {
        while(a[j] % t == 0) a[j] = a[j] / t;
        }
    }
    for(int i = 1; i <= n; i++) mp[a[i]]++, f[i] = a[i];
    for(int i = 1; i <= cnt; i++){
        ll t = prime[i] * prime[i]; 
        for(int j = 1; j <= n; j++){
            if(a[j] % t == 0)  a[j] = a[j] / t, b[j] = b[j] * t;
            else if(a[j] % prime[i] == 0) a[j] = a[j] / prime[i], c[j] = c[j] * prime[i];
        }
    }
    for(int i = 1; i <= n; i++) {
        if((ll)sqrt(a[i]) * (ll)sqrt(a[i]) == a[i]) b[i] = b[i] * a[i];
        else c[i] = c[i] * a[i]; 
    }
    for(int i = 1; i <= n; i++){
        a[i] = c[i] * c[i] % mod * (ll)sqrt(b[i]) % mod;
        if(d[a[i]] == 0 && d[f[i]] == 0){
          if(a[i] != 1)   ans += max(mp[f[i]], mp[a[i]]);
          else ans++;
        }
        d[a[i]] = 1;
    }   
    cout << ans << endl;
}

Measured memory_bytes: 32768
#include <stdio.h>
#include <algorithm>

int N, ans = -2147483648;
int F[100][10];
int P[100][11];

int main()
{
	scanf("%d", &N);
	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < 10; j++) scanf("%d", &F[i][j]);
	}
	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < 11; j++) scanf("%d", &P[i][j]);
	}
	for (int i = 1; i <= 1023; i++)
	{
		int sum = 0;
		for (int j = 0; j < N; j++)
		{
			int cnt = 0;
			for (int k = 0; k < 10; k++)
			{
				if (F[j][k] == 1 && (i&(1 << k)) > 0) cnt++;
			}
			sum += P[j][cnt];
		}
		ans = std::max(ans, sum);
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<cstring>
#include<queue>
#include<stack>
#include<string>
#include<cstdio>
using namespace std;
//typedef long long LL;
#define For(a,b,c) for(int a=b;a<=c;a++)
#define For_(a,b,c) for(int a=b;a>=c;a--)
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define pb push_back
#define debug(x) cout<<#x<<" "<<x<<" "
int read(){
    int r=0,f=1;
    char c=getchar();
    while(!isdigit(c)){
        if(c=='-')
          f=-1;
        c=getchar();
    }
    while(isdigit(c)){
        r=(r<<1)+(r<<3)+c-'0';
        c=getchar();
    }
    return r*f;
}
#define MAXN 100005
int cnt[MAXN],n,q;
long long ans;
int main(){
    n = read();
    For(i,1,n){
        int x =read();
        ans += x;
        cnt[x]++;
    }
    q = read();
    For(i,1,q){
        int b = read(),c = read();
        ans -= 1ll * cnt[b] *b;
        ans += 1ll * cnt[b] *c;
        printf("%lld\n",ans);
        cnt[c] += cnt[b];
        cnt[b] = 0;
    }
    return 0;
}


Measured memory_bytes: 4024
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    private static int N;
    private static int M;
    private static ArrayList<Integer> Li = new ArrayList<>();
    private static ArrayList<Integer> Ri = new ArrayList<>();

    private static void init() {
        Scanner scanner = new Scanner(System.in);

        String header = scanner.nextLine();
        String[] headerItems = header.split(" ");
        N = Integer.parseInt(headerItems[0]);
        M = Integer.parseInt(headerItems[1]);

        for (int gateIndex = 0; gateIndex < M; gateIndex++) {
            String card = scanner.nextLine();
            String[] cardItems = card.split(" ");
            int L = Integer.parseInt(cardItems[0]);
            int R = Integer.parseInt(cardItems[1]);

            Li.add(L);
            Ri.add(R);
        }

        scanner.close();
    }

    public static void main(String[] args) {
        init();
        // logic
        logic();
    }

    private static void logic() {
        int maxL = Integer.MIN_VALUE;
        int minR = Integer.MAX_VALUE;

        for (int gateIndex = 0; gateIndex < M; gateIndex++) {
            int L = Li.get(gateIndex);
            int R = Ri.get(gateIndex);
            maxL = Math.max(maxL, L);
            minR = Math.min(minR, R);
        }

        System.out.println((minR >= maxL) ? minR - maxL + 1 : 0);
    }
}


Measured memory_bytes: 117844
#define _GLIBCXX_DEBUG
#include<iostream>
#include<cstdio>
#include<bits/stdc++.h>//"geometry.cpp"
#include<iomanip>//"cout<<fixed<<setprecision(n)<<sth<<endl;"
#include<queue>
#include<string>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<algorithm>
#include<functional>//"greater<T>" Ex. sort(a,a+n,greater<int>());
#include<cmath>//"abs", "sqrt"
using namespace std;
#define pb push_back
#define fi first
#define sc second
#define mp make_pair
#define is insert	//tentative
typedef map<int,int> mii;

void solve(int n,int g,int w,int q){
	int a[100000],ans=0;
	for(int i=0;i<n;++i){
		a[i]=(g/7)%10;
		if(g%2==0){
			g=(g/2);
		}else{
			g=(g/2)^w;
		}
	}
	if(q!=2&&q!=5){
		int b[100001],x[100000],s=0;
		mii m;
		g=1;
		for(int i=n-1;i>=0;--i){
			b[i]=a[i];
			b[i]*=g;
			b[i]%=q;
			g*=10;
			g%=q;
		}
		m.is(mp(0,-1));
		fill(x,x+n,-1);
		for(int i=0;i<n;++i){
			s+=b[i];
			s%=q;
			mii::iterator it=m.find(s);
			if(it!=m.end()){
				x[m[s]+1]=i+1;
				m.erase(it);
			}
			m.is(mp(s,i));
		}
		b[n]=0;
		for(int i=n-1;i>=0;--i){
			if(x[i]<0){
				b[i]=0;
			}else{
				b[i]=b[x[i]]+1;
			}
			if(a[i]!=0){
				ans+=b[i];
			}
		}
	}else{
		vector<int> v;
		for(int i=0;i<n;++i){
			if(a[i]%q==0){
				v.pb(i);
			}
		}
		for(int i=0;i<n;++i){
			if(a[i]!=0){
				ans+=v.end()-lower_bound(v.begin(),v.end(),i);
			}
		}
	}
	cout<<ans<<endl;
}

int main(){
	while(true){
		int n,g,w,q;
		cin>>n>>g>>w>>q;
		if(n==0){
			break;
		}
		solve(n,g,w,q);
	}
}

Measured memory_bytes: 8236
#include<iostream>
#include<vector>

using namespace std;

int main(){
    int N, T;
    cin >> N >> T;
    vector<int> t(N);
    for (int i = 0; i < N;i++){
        cin >> t[i];
    }
    int end = 0;
    int res = 0;
    for (int i = 0; i < N; i++){
        res += min(t[i] + T - end, T);
        end = t[i] + T;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
    
int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  sort(a.begin(), a.end());
  cout << a[n-1] - a[0] << endl;
  return 0;
}


Measured memory_bytes: 256
def gcd(m, n):
    while n:
        m, n = n, m % n
    return m
def lcm(m, n):
    return m // gcd(m, n) * n

for line in open(0).readlines():
    a, b = map(int, line.split())
    print(gcd(a, b), lcm(a, b))



Measured memory_bytes: 5600
#include <iostream>
#define MAX 200000

int main() {
    int R[MAX], n, min, profit;
    
    std::cin >> n;
    std::cin >> R[0];
    std::cin >> R[1];
    
    if (R[0] < R[1]) {
        min = R[0];
    } else {
        min = R[1];
    }
    
    profit = R[1] - R[0];
    
    for(int i=2; i<n; i++) {
        std::cin >> R[i];
        if (R[i] - min > profit)
            profit = R[i] - min;
        if (R[i] < min)
            min = R[i];
    }
    
    std::cout << profit << std::endl;
}


Measured memory_bytes: 3892
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;
using ll = long long;
using P = pair<int, int>;

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int divCnt(int num) {
  int cnt = 0;
  while (true) {
    if (num % 2 == 0) {
      cnt++;
      num /= 2;
    } else
      break;
  }
  return cnt;
}

int main() {
  int n;
  cin >> n;
  int result = 0;
  rep(i, n) {
    ll num;
    cin >> num;
    result += divCnt(num);
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 3644
Option Strict On
Public Class Main
    Public Shared Sub Main(ByVal args() As String)
        Dim H, N As Integer
        Dim arr(2) As String
        arr = Split(Console.ReadLine())
        H = Integer.Parse(arr(0)) : N = Integer.Parse(arr(1))
        Dim A() As Integer = Array.ConvertAll(Of String, Integer) _
            (Split(Console.ReadLine()), AddressOf Integer.Parse)
        Array.Sort(A)
        Dim accum As Integer = 0
        Dim flg As Boolean = False
        For i As Integer = N - 1 To 0 Step -1
            accum += A(i)
            If H <= accum Then
                flg = True
                Exit For
            End If
        Next
        Console.WriteLine(If(flg, "Yes", "No"))
    End Sub
End Class


Measured memory_bytes: 24144
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define EPS (1e-10)
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int s[100000],t[100000],d[100000];
int sum[200000];
vector<P>v[30];

signed main(){
	int n,c;scanf("%d%d",&n,&c);
	rep(i,n){
		scanf("%d%d%d",&s[i],&t[i],&d[i]);d[i]--;
		v[d[i]].push_back(P(s[i],t[i]));
	}
	rep(i,c){
		if(v[i].empty())continue;
		sort(v[i].begin(),v[i].end());
		if(v[i].size()==1){
			sum[v[i][0].first-1]++;sum[v[i][0].second]--;
			continue;
		}
		int a=v[i][0].first;
		rep(j,v[i].size()){
			if(j){
				if(v[i][j-1].second==v[i][j].first){
					if(j==v[i].size()-1){
						sum[a-1]++;sum[v[i][j].second]--;
					}
				}
				else{
					sum[a-1]++;sum[v[i][j-1].second]--;
					a=v[i][j].first;
					if(j==v[i].size()-1){
						sum[a-1]++;sum[v[i][j].second]--;
					}
				}
			}
		}
	}
	int Max=sum[0];
	for(int i=1;i<200000;i++){
		sum[i]+=sum[i-1];
		Max=max(Max,sum[i]);
	}
	cout<<Max<<endl;
}

Measured memory_bytes: 3456
import sys
f = sys.stdin
def cylinder(balls):
    cy = []
    for ball in balls:
        if len(cy) == 0:
            pass
        elif len(cy) == 1:
            if cy[0] < ball:
                cy.remove(cy[0])
        elif min(ball, *cy) == ball:
            return False
        elif max(ball, *cy) == ball:
            cy.remove(max(cy))
        else:
            cy.remove(min(cy))
        cy.append(ball)
    return True

n = int(f.readline())
for _ in range(n):
    balls = list(map(int, f.readline().split()))
    print('YES' if cylinder(balls) else 'NO')

Measured memory_bytes: 6720
#include <algorithm>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

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

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

  sort(A.begin(), A.end());
  if (A.back() < K) {
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }

  int gcd = A[0];
  for (int i = 1; i < N; ++i) {
    gcd = __gcd(gcd, A[i]);
  }
  if (K % gcd == 0)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
  return 0;
}


Measured memory_bytes: 640
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//s[i]-'0'でchar文字→int数に;
//string s = to_string(int数);
//int n = stoi(string文字列)
//実行時間制約2秒では２×10^8回くらいまで計算できる


int main() {
  int n;
  string a,b,c;
  cin>>n>>a>>b>>c;
  
  int ans=0;
  rep(i,n){
    if(a[i]!=b[i]&&b[i]!=c[i]&&c[i]!=a[i])ans+=2;
    if((a[i]==b[i]&&b[i]!=c[i])||(b[i]==c[i]&&c[i]!=a[i])||
      (c[i]==a[i]&&a[i]!=b[i]))ans++;
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;
    
#define rep(i,n) for(ll (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrrep(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>
#define pq priority_queue<ll>
#define rpq priority_queue<ll,vector<ll>,greater<ll>>
#define p_b push_back
    
ll n,cnt,ans,a[ohara],b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k,q;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
    
//------ Believe yourself as a genius!!!!!! ------

bool check(ll ind){
    bitset<5000+100> dp;
    dp[0]=true;
    rep(j,n){
        if(ind==j)continue;
        dp|=dp<<a[j];
    }
    int ok=0;
    rrrep(j,k-1,0){
        if(dp[j]){
            if(j+a[ind]>=k)ok=1;
        }
        if(ok)break;
    }
    if(ok)fl=true;
    else fl=false;
    return fl;
}
    
int main(void){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>n>>k;
    rep(i,n)cin>>a[i];
    sort(a,a+n);
    ll le=0,ri=n-1,mid;
    while(ri-le>1){
        mid=(le+ri)/2;
        if(check(mid))ri=mid;
        else le=mid;
    }
    ans=n-1;
    rrep(i,max(0LL,le-5),min(n,ri+5)){
        if(check(i)){
            ans=i-1;
            break;
        }
    }
    Cout(ans+1);
    return 0;
}

Measured memory_bytes: 256
#pragma warning(disable:4996)


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main(void) {
    long  N=1, M;
    double  total = 0;

    //入力
    scanf("%ld", &N);
    scanf("%ld", &M);

    long *A, i, cnt = 0;

    A = (long*)malloc(sizeof(long) * N);

    for (i = 0; i < N; i++)
    {
        scanf("%ld", &A[i]);
        total += A[i];
    }

    total /=((double)M*4);

    for (i = 0; i < N; i++) {
        if (A[i] < total)continue;
        cnt++;
    }
    if (cnt < M)printf("No");
    else printf("Yes");

    free(A);
    return 0;
}



Measured memory_bytes: 128
#pragma comment(linker, "/STACK:102400000,102400000")
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define inf 1000000007
#define mod 1000000007
#define x first
#define y second
#define pi acos(-1.0)
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
//#define dprintf(...) 
#define hash _hash
#define next _next
//#define dprintf(...) fprintf(outFile,__VA_ARGS__)
 
#define FOREACH(it,x) for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define ull unsigned long long
#define ll long long
#define N 200005
 
template <class T,class U>inline void Max(T &a,U b){if(a<b)a=b;}
template <class T,class U>inline void Min(T &a,U b){if(a>b)a=b;}
 
//FILE* outFile;
inline void add(int &a,int b){a+=b;while(a>=mod)a-=mod;}


int pow(int a,int b){
    int ans=1;
    while(b){
        if(b&1)ans=ans*(ll)a%mod;
        a=(ll)a*a%mod;b>>=1;
    }
    return ans;
}

int a[N],b[N];
int cal(int x,int n){
    int m=2*n-1;
    rep(i,0,m)b[i]=a[i]>=x;
    rep(i,0,n-1){
        if(b[n-1+i]==b[n-1+i+1])return b[n-1+i];
        if(b[n-1-i]==b[n-1-i-1])return b[n-1-i];
    }
    return b[0];
}
int main(){
    //freopen("1.txt","w",stdout);
    //cout<<setprecision(3)<<fixed;
    int T,i,j,k,n,m,K=0;
    scanf("%d",&n);
    m=2*n-1;
    rep(i,0,m)scanf("%d",&a[i]);
    int l=1,r=m;
    while(l<=r){
        int x=(l+r)>>1;
        K=cal(x,n);
        //cerr<<x<<" "<<K<<"\n";
        if(K)l=x+1;
        else r=x-1;
    }
    printf("%d\n",l-1);
    return 0;
}

Measured memory_bytes: 1792
package main

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

var H, W int

func main() {
	reader := bufio.NewReaderSize(os.Stdin, 1024)
	fmt.Scan(&H, &W)

	q := make([][]int, 0)
	m := make([][]bool, H)

	for i := 0; i < H; i++ {
		line, _, _ := reader.ReadLine()
		m[i] = make([]bool, W)

		for j, v := range line {
			if string(v) == "#" {
				var t = []int{i, j}
				q = append(q, t)
				m[i][j] = true
			} else {
				m[i][j] = false
			}
		}
	}

	fmt.Println(bfs(q, m))
}

func bfs(q [][]int, m [][]bool) int {
	var ans int

	for len(q) != 0 {
		ans++
		var len int = len(q)

		for i := 0; i < len; i++ {
			var y, x int = q[0][0], q[0][1]
			q = append(q[1:])

			if 0 <= y+1 && y+1 < H && m[y+1][x] == false {
				m[y+1][x] = true
				z := []int{y + 1, x}
				q = append(q, z)
			}
			if 0 <= y-1 && y-1 < H && m[y-1][x] == false {
				m[y-1][x] = true
				z := []int{y - 1, x}
				q = append(q, z)
			}
			if 0 <= x+1 && x+1 < W && m[y][x+1] == false {
				m[y][x+1] = true
				z := []int{y, x + 1}
				q = append(q, z)
			}
			if 0 <= x-1 && x-1 < W && m[y][x-1] == false {
				m[y][x-1] = true
				z := []int{y, x - 1}
				q = append(q, z)
			}
		}
	}
	return ans - 1
}


Measured memory_bytes: 116864
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <set>
#include <map>

using namespace std;

#define reep(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reep(i,0,n)

typedef vector<int> vi;

int main()
{
	int n;
	scanf("%d%*c", &n);
	rep(i, n){
		char str[258];
		fgets(str, 258, stdin);

		set<string> words;
		stringstream stin(str);
		string tmp;
		while(stin >> tmp){
			if(tmp.size() == 4)
				words.insert(tmp);
		}

		int alpha=0, beta=0;
		bool keep = true;
		for(int i=1; keep; ++i){
			if(i%2==0 || i%13==0)
				continue;
			rep(j, 26){
				char samples[][5] = {"that", "this"};
				rep(k, 2){
					rep(l, 4) samples[k][l] = ((samples[k][l]-'a')*i+j)%26+'a';
					if(words.count(string(samples[k]))){
						alpha = i;
						beta = j;
						j=100;
						keep = false;
					}
				}
			}
		}

		map<char, char> conv;
		rep(i, 26)
			conv.insert(make_pair((i*alpha+beta)%26+'a', i+'a'));
		rep(i, strlen(str))
			putchar(isalpha(str[i]) ? conv[str[i]] : str[i]);
	}

	return 0;
}

Measured memory_bytes: 0
class UnionFind:
    def __init__(self, n):
        """ノード数nの配列を作る

        親の番号を格納する
        -> 自分が根だった場合は、-(その集合のサイズ)とする
        作るときはparentの値を全て-1にする
        こうすると全てバラバラになる
        """
        self.parent = [-1 for _ in range(n)]

    def root(self, x):
        """要素xの根の番号を返す
        """
        if self.parent[x] < 0:
            # 自分が根
            return x
        # 要素xの親を要素xの根に変えておく
        # 次の呼び出しが早くなる
        self.parent[x] = self.root(self.parent[x])
        return self.parent[x]

    def size(self, x):
        """要素xの所属するグループの頂点数を調べる

        根のparentにサイズが格納されている
        """
        return -self.parent[self.root(x)]

    def merge(self, x, y):
        """xとyを結合する
        """
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return False

        #大きい方(x)に小さい方(y)をくっつけたい
        if self.size(x) < self.size(y):
            x, y = y, x
        self.parent[x] += self.parent[y]
        self.parent[y] = x
        return True


n,m = map(int,input().split())
a, b = [0]*m, [0]*m
for i in range(m):
    a[i],b[i] = map(int, input().split())
    a[i] -= 1
    b[i] -= 1

ans = [0 for _ in range(m)]
ans[m-1] = n*(n-1)//2

uf = UnionFind(n)
i = 1
for ai, bi in zip(a[::-1], b[::-1]):
    id = m-1-i
    if id < 0:
        break
    if uf.root(ai) == uf.root(bi):
        ans[id] = ans[id+1]
    else:
        sa = uf.size(ai)
        sb = uf.size(bi)
        ans[id] = ans[id+1] - sa*sb
        uf.merge(ai, bi)
    i += 1

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


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

int main(){
  /*  #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    int n;
    cin>>n;
    pair< string, int > s[n];
    pair < string, int > p[n];
    vector< int > v;
    for(int i = 0;i<n;i++){
        cin>>s[i].first;
        cin>>s[i].second;
        //p[i].first = s[i].first;
        //p[i].second = s[i].second;
        v.push_back(s[i].second);
    }
    sort(s,s+n);
    int flag = 0;
    int count = 1;
    int temp = 0;
   //  for(int i = 0;i<n;i++){
     //  cout<<s[i].first<<" "<<s[i].second<<endl;
        //cout<<v[i]<<endl;
   // }
    for(int i = 0;i<n;i++){
        if(s[i].first==s[i+1].first){
            count++;
            flag = 1;
            //cout<<"HI";
        }

       /* else if(i==n-2) {
            if(s[n-2]==s[n-1]){
                count++;
                flag = 1;
            }
            else {
                flag = 0;
            }*/
      //  }
        else {
            flag = 0;
            //cout<<"hI"<<" ";
        }
        if(i==n-1){
            flag = 0;
        }
        if(flag==0){
            //cout<<"HI";
            for(int j = temp+ count-1;j>=temp;j--){
                cout<<find(v.begin(),v.end(),s[j].second)-v.begin()+1<<endl;
                //cout<<count<<" ";
            }
            temp += count;
            count = 1;
            flag = 0;
        }
    }
   


        
    return 0;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  l=[0]+l+[0]

  sm=0
  for i in range(n+1):
    sm+=abs(l[i+1]-l[i])

  ans=[]
  for i in range(1,n+1):
    ans.append(sm-abs(l[i]-l[i-1])-abs(l[i+1]-l[i])+abs(l[i+1]-l[i-1]))

  for x in ans:
    print(x)

main()


Measured memory_bytes: 16588
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = []
for n in b:
	if n % 2 == 0:
		c.append(n)
	else:
		c = c
d = 0
e = len(c)
for m in c:
	if m % 3 ==0 or m % 5 == 0:
		d += 1
	else:
		d =d
if d == e:
	print("APPROVED")
else:
	print("DENIED")

Measured memory_bytes: 3064
#include <unordered_map>
#include <queue>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
#define INF 99999999

typedef int Weight;
typedef vector<Weight> Array;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef unordered_map<int,Edges> Graph;

void shortestPath(Graph &g, int s,
    Array &dist, Array &prev) {
  int n = g.size();
  dist.assign(n, INF); dist[s] = 0;
  prev.assign(n, -1);
  priority_queue<Edge> Q; // "e < f" <=> "e.weight > f.weight"
  for (Q.push(Edge(-2, s, 0)); !Q.empty(); ) {
    Edge e = Q.top(); Q.pop();
    if (prev[e.dst] != -1) continue;
    prev[e.dst] = e.src;
    for(auto &f:g[e.dst]) {
      if (dist[f.dst] > e.weight+f.weight) {
        dist[f.dst] = e.weight+f.weight;
        Q.push(Edge(f.src, f.dst, e.weight+f.weight));
      }
    }
  }
}

int main(){
	int i,V,E,s,t,e;
	//for(scanf("%d",&T);T;putchar(--T?' ':'\n')){
		scanf("%d",&V);
		Graph g(V);
		for(i=0;i<V-1;i++)scanf("%d%d",&s,&t),g[s-1].push_back(Edge(s-1,t-1,1)),g[t-1].push_back(Edge(t-1,s-1,1));
		Array dist1(V),dist2(V),prev(V);
		shortestPath(g,0,dist1,prev);
		shortestPath(g,V-1,dist2,prev);
		int r=0;
		for(i=0;i<V;i++)r+=dist1[i]>dist2[i];
		puts(r<V-r ? "Fennec" : "Snuke");
	//}
}


Measured memory_bytes: 12968
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, s, n) for (int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  vector<ll> num(n);
  rep(i, n - 1) {
    cin >> a[i];
    num[a[i] - 1]++;
  }
  rep(i, n) cout << num[i] << endl;
  return 0;
}

Measured memory_bytes: 6332
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
    auto val = table(args...);
    return vector<decltype(val)>(n, move(val));
}
const ll INF = 1e18;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
ll n;
ll s[401],dp[401][401],cost[401],done[401][401] = {0};
ll slime(ll l,ll r){
    if (done[l][r]) return dp[l][r];
    done[l][r] = 1;
    if (l+1 == r) return dp[l][r] = 0;
    if (l == r) return dp[l][r] = 0;
    ll res = INF;
    rep(i,l+1,r){
        chmin(res,slime(l,i)+slime(i,r)+(cost[r]-cost[i])+(cost[i]-cost[l]));
    }
    return dp[l][r] = res;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    cost[0] = 0;
    rep(i,n){
        cin >> s[i];
        cost[i+1] = cost[i]+s[i];
    }
    PRINT(slime(0,n));
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define REPR(i, m, n) for (int i = (int)(m); i >= (int)(n); i--)
#define all(v) v.begin(), v.end()
typedef long long ll;
#define MAX 2000001
#define VMAX 10000

short A[MAX];
short B[MAX];

int main(){
  int C[VMAX+1];
  int n;
  scanf("%d", &n);

  rep(i, VMAX+1) C[i] = 0;
  rep(i, n){
    scanf("%hu", &A[i]);
    C[A[i]]++;
  }
  REP(i, 1, VMAX) C[i] += C[i-1];

  rep(i, n){
    B[C[A[i]]] = A[i];
    C[A[i]]--;
  }

  REP(i, 1, n){
    if(i != 1) printf(" ");
    printf("%d", B[i]);
  }
  printf("\n");

  return 0;
}






Measured memory_bytes: 10988
#include "stdio.h"
#include "queue"
#include "utility"
using namespace std;
typedef pair<int, int>P;

queue<P>Q;
P now;
P goal[10];
int N;
int W;
int H;
char map[1000][1001] = {};
int x[4] = { 1,0,-1,0 };
int y[4] = { 0,1,0,-1 };
int dis[1000][1001] ;
int ans=0;
int box = 0;

int main() {
	scanf("%d %d %d", &H, &W, &N);
	for (int i = 0; i < H; i++) {
		scanf("%s", map[i]);
	}
	//printf("\n");
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (map[i][j] >= '1'&&map[i][j] <= '9') {
				goal[map[i][j] - '0'].first = i;
				goal[map[i][j] - '0'].second = j;
				map[i][j] = '.';
			}
			else if (map[i][j] == 'S') {
				now.first = i;
				now.second = j;
				map[i][j] = '.';
			}
		}
	}
	for (int i = 1; i <= N; i++) {
		Q.push(now);
		//printf("%d %d????????¢?´¢\n", now.first, now.second);
		box = 0;
		for (int j = 0; j < H; j++) {
			for (int k = 0; k < W; k++) {
				dis[j][k] = 10000000;
			}
		}
		dis[Q.front().first][Q.front().second] = 0;
		while (!Q.empty()) {
			for (int j = 0; j < 4; j++) {
				if (map[Q.front().first + y[j]][Q.front().second + x[j]] == '.') {
					if (dis[Q.front().first + y[j]][Q.front().second + x[j]] > dis[Q.front().first][Q.front().second] + 1) {
						now.first = Q.front().first + y[j];
						now.second = Q.front().second + x[j];
						dis[now.first][now.second] = dis[Q.front().first][Q.front().second] + 1;
					//	printf("%d %d??????%d %d????????£???\n", Q.front().first, Q.front().second, now.first, now.second);
						Q.push(now);
						if (now.first == goal[i].first&&now.second == goal[i].second) {
						//	printf("hijiki\n");
							box = dis[now.first][now.second];
							while (!Q.empty()) {
								Q.pop();
							}
							if (Q.empty())break;
						}
					}
				}
			}
			//printf("hijiki\n");
			if (!Q.empty()) {
				Q.pop();
			}
			//printf("hijiki\n");
		}
		//printf("hijiki\n");
		ans += box;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 5940
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
const int mod=1e9+7;
const int inf = (1<<30);
string toBin(ll a);
void printMat(int arr[], int n);
void printMat(vector<int> arr, int n);
void printMat(vector<vector<int> > arr, int n, int m);
void printMat(vector<int> arr[], int n);
//void printMat(int arr[][], int n, int m);

void solve(){
	int i, j, n, k;
	cin>>n>>k;
	int arr[n];
	for(i=0;i<n;i++){
		cin>>arr[i];
	}
	sort(arr, arr + n);
	ll sum=0;
	for(i=0;i<k;i++){
		sum+=arr[i];
	}
	cout<<sum<<endl;
}

int main()
{
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
	return 0;
}
string toBin(ll a){
	string s="";
	while(a>0){
		if(a&1){
			s="1"+s;
		}else{
			s="0"+s;
		}
		a>>=1;
	}
	return s;
}
void printMat(int arr[], int n){
	for(int i=0;i<n;i++){
		cout<<arr[i]<<" ";
	}cout<<endl;
}
void printMat(vector<int> arr, int n){
	for(int i=0;i<n;i++){
		cout<<arr[i]<<" ";
	}cout<<endl;
}
void printMat(vector<int> arr[], int row, int col){
	for(int i=0;i<row;i++){
		for(int j=0;j<col;j++){
			cout<<arr[i][j]<<" ";
		}cout<<endl;
	}cout<<endl;
}
void printMat(vector<vector<int> > arr, int row, int col){
	for(int i=0;i<row;i++){
		for(int j=0;j<col;j++){
			cout<<arr[i][j]<<" ";
		}cout<<endl;
	}cout<<endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

const int N = 3e5 + 10;
const int MOD = 1e9 + 7;
const int64_t INF = 5e18;
const double PI = 2 * acos(0.0);
//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int tree[4 * N], a[N];

void update(int p, int b, int e, int l, int r, int v) {
//    if (lazy[p]) {
//        propagate(p, b, e, lazy[p]);
//    }
    if (b > r || e < l) {
        return;
    } else if (b >= l && e <= r) {
        tree[p] = v;
    } else {
        int m = b + e >> 1;
        update(p * 2, b, m, l, r, v);
        update(p * 2 + 1, m + 1, e, l, r, v);
        tree[p] = max(tree[p * 2], tree[p * 2 + 1]);
    }
}

int  query(int p, int b, int e, int l, int r) {
//    if (lazy[p]) {
//        propagate(p, b, e, lazy[p]);
//    }
    if (b > r || e < l) {
        return 0;
    } else if (b >= l && e <= r) {
        return tree[p];
    } else {
        int m = b + e >> 1;
        return max(query(p * 2, b, m, l, r), query(p * 2 + 1, m + 1, e, l, r));
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i]++;
    }
    int mxN = 3e5 + 2;
    for (int i = 0; i < n; i++) {
        int bck = max(a[i] - k, 1);
        int fnt = min(a[i] + k, mxN);
        int gotMax = max(query(1, 1, mxN, bck, a[i]), query(1, 1, mxN, a[i], fnt));
        update(1, 1, mxN, a[i], a[i], gotMax + 1);
    }
    cout << query(1, 1, mxN, 1, mxN) << '\n';
    return 0;
}


Measured memory_bytes: 8928
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+10;
typedef long long ll;
ll gcd(ll x,ll y) {return y?gcd(y,x%y):x;}
ll a,b;
int main() {
	cin>>a>>b;
	cout<<a*b/gcd(a,b);
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int a = sc.nextInt();
	if(a%10==9||a/10==9) {
		System.out.println("Yes");
	}
	else {
		System.out.println("No");
	}
	}
	}

Measured memory_bytes: 25172
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const long long MOD = 998244353;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using ll = long long;
using pLL = std::pair<ll, ll>;
#define SORT(v) std::sort(v.begin(), v.end())
#define RSORT(v) std::sort(v.rbegin(), v.rend())
constexpr auto PI = 3.14159265358979323846264338327950L;
int needleX[4] = { -1,0,1,0 };
int needleY[4] = { 0,1,0,-1 };

template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int X, N;
    cin >> X >> N;
    if (N == 0) {
        cout << X << endl;
        return 0;
    }
    vector<bool> p(101);
    for (int i = 0; i < N; ++i) {
        int x;
        cin >> x;
        p[x]=true;
    }
    int ans = 0;
    int cost = abs(X-0);
    for (int i = 1; i <= 100; ++i) {
        if (p[i]==false) {
            int temp = abs(X - i);
            if (chmin(cost,temp)==1)ans = i;
        }
    }
    int temp = abs(X - 101);
    if (chmin(cost, temp) == 1)ans = 101;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    ll ans = 1;
    bool ng = false;
    rep(i, n){
        ll a;
        cin >> a;
        if (a == 0){
            cout << 0 << endl;
            return 0;
        }
        if (ng || a > 1000000000000000000 / ans)
            ng = true;
        else
            ans *= a;
    }
    if (ng)
        cout << -1 << endl;
    else
        cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3612
#include<stdio.h>
#include<stdlib.h>
int main(void){
  int a,b,max;
  scanf("%d %d",&a,&b);
  max = a+b;
  if(max < a-b)max = a-b;
  if(max < a*b)max = a*b;
  printf("%d\n",max);
  return 0;
}

Measured memory_bytes: 128
nums = list(map(int, input().split()))

n = nums[3]
ans = 0
add_num = 1
i = 0
while n > 0:
    if n > nums[i]:
        ans += (add_num * nums[i])
        n -= nums[i]
    else:
        ans += (n * add_num)
        break
    add_num -= 1
    if i == 2:
        break
    i += 1

print(ans)


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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007

using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int iy[]={0, 0, 1, -1};
int ix[]={1, -1, 0, 0};

long long int n, k;
long long int ans;

int main(){
	cin >> n >> k;
	for(int i=1;i<=n;i++){
		if(((2*i)+k)%k==0) ans += ((n+i)/k-i/k)*((n+i)/k-i/k);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256