akhauriyash/Code-Regression huggingface dataset:
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<bitset>
#include<utility>
#include<string>

using namespace std;

main(){
  int d;
  int s;
  while(cin >> d){
    s=0;
    for(int i=1;i<600/d;i++) s+=d*i*d*i*d;
    cout << s << endl;
  }
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include <string>
#include <math.h>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;

// 4近傍（右, 下, 左, 上）
int dy[4] = { 0, -1, 0, 1 };
int dx[4] = { 1, 0, -1, 0 };

bool inside(int y, int x, int H, int W) {
    return 0 <= y && y < H && 0 <= x && x < W;
}
int w,h;
char field[55][55];
int used[2][55][55];
void dfs(int y,int x,int a){
  if(inside(y,x,h,w)==false||field[y][x]!='.'||used[a][y][x]>0)return;
  used[a][y][x]++;
  for(int i=0;i<4;i++){
    dfs(y+dy[i],x+dx[i],a);
  }
}
int main(){
  while(1){
    cin >>w>>h;
    if(w==0&&h==0)break;
    for(int i=0;i<h;i++){
      string s; cin >>s;
      for(int j=0;j<w;j++){
        field[i][j]=s[j];
      }
    }
    int cntb=0; int cntw=0;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        used[0][i][j]=0;
        used[1][i][j]=0;
      }
    }
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        if(field[i][j]=='B'){
          for(int k=0;k<4;k++){
            dfs(i+dy[k],j+dx[k],0);
          }
        }
        else if(field[i][j]=='W'){
          for(int k=0;k<4;k++){
            dfs(i+dy[k],j+dx[k],1);
          }
        }
      }
    }
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        if(used[0][i][j]>0&&used[1][i][j]==0)cntb++;
        else if(used[0][i][j]==0&&used[1][i][j]>0) cntw++;
      }
    }
    cout << cntb << " " << cntw << endl;
  }
  return 0;
}


Measured memory_bytes: 3296
import heapq
x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a=sorted([-i for i in a])
b=sorted([-i for i in b])
c=sorted([-i for i in c]) # avoid reverse=True 
a_dif=[a[i+1]-a[i] for i in range(x-1)]
b_dif=[b[i+1]-b[i] for i in range(y-1)]
c_dif=[c[i+1]-c[i] for i in range(z-1)]#差分をとる

que=[(a[0]+b[0]+c[0],(0,0,0))]
heapq.heapify(que)
s=set([(0,0,0)])
while k>0:
    ans,(ia,ib,ic)=heapq.heappop(que)
    print(-ans) #because sort with - 
    k-=1
    
    if ia < x-1 and (ia+1,ib,ic) not in s:
        heapq.heappush(que,(ans+a_dif[ia],(ia+1,ib,ic)))
        s.add((ia+1,ib,ic))
    if ib < y-1 and (ia, ib+1, ic) not in s:
        heapq.heappush(que, (ans+b_dif[ib], (ia, ib+1, ic)))
        s.add((ia, ib+1, ic))
    if ic < z-1 and (ia, ib, ic+1) not in s:
        heapq.heappush(que, (ans+c_dif[ic], (ia, ib, ic+1)))
        s.add((ia, ib, ic+1))
    

Measured memory_bytes: 5232
def addbit(i):
    i += 1
    while i <= N:
        BIT[i] += 1
        i += i & (-i)
def getsum(i):
    ret = 0
    i += 1
    while i != 0:
        ret += BIT[i]
        i -= i&(-i)
    return ret
def bit(L):
    global BIT
    BIT=[0] * (N+1)
    re = 0
    for l in L:
        re += getsum(l)
        addbit(l)
    return N*(N-1)//2 - re
def get_rank(L):
    D = {x:i for i,x in enumerate(sorted(L))}
    return [D[x] for x in L]
def calc(Z):
    Z.sort()
    l, r, lc, rc = -1<<28, 1<<28, N*(N-1)//4+1, N*(N-1)//4+1
    while (r - l) / max(abs(l), 1) > 0.000000001:
        m = (l * rc + r * lc) / (lc + rc)
        A = get_rank([s*m+t for s, t in Z])
        c = bit(A)
        if c > N*(N-1)//4:
            l = m
            lc = ((c - N*(N-1)//4) * 2) ** 0.4
        else:
            r = m
            rc = ((N*(N-1)//4 - c) * 2 + 1) ** 0.4
    return l

N = int(input())
X, Y = [], []
for _ in range(N):
    a, b, c = map(int, input().split())
    X.append((-a/b, c/b))
    Y.append((-b/a, c/a))
print(calc(X), calc(Y))

Measured memory_bytes: 130552
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Howmanyways solver = new Howmanyways();
        solver.solve(1, in, out);
        out.close();
    }

    static class Howmanyways {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            while (true) {
                int n = in.nextInt();
                int x = in.nextInt();
                if (n == 0 && x == 0) return;
                // 1~n
                int res = 0;
                for (int i = 1; i < n; i++) {
                    for (int j = i + 1; j < n; j++) {
                        if (x - i - j > j && x - i - j <= n) res++;
                    }
                }
                out.println(res);
            }
        }

    }
}




Measured memory_bytes: 26324
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::cmp;
fn main() {
    input!(n:i32, x:i64, a:[i64;n]);
    
    let mut a:Vec<i64> = a.clone();
    a.sort();

    let mut x = x;
    let mut ans = 0_i64;
    let mut sum  = 0_i64;
    for i in 0..n as usize{
        x -= a[i];
        ans += 1;
        if x <= 0 {
            break;
        }
        
    }
    
    println!("{}", if x > 0 || x < 0 {ans-1} else {ans});
}


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

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))

#define DEBUG(x) cout<<#x<<": "<<(x)<<endl

int n,m,k;
int p[125252];
int c[125252];
int j[125252];

vl dijkstra(vector<vector<pll>> &g, int s){
	int n = g.size();
	vl dist(n,1ll<<60);
	priority_queue<pll> Q;
	dist[s] = 0;
	Q.push(pll(-0,s));
	while(Q.size()){
		pll P = Q.top(); Q.pop();
		int p = P.second;
		if(dist[p] != -P.first)continue;
		for(pll PP : g[p]){
			int to = PP.first;
			ll cost = PP.second;
			ll nd = dist[p] + cost;
			if(nd < dist[to]){
				dist[to] = nd;
				Q.push(pll(-nd,to));
			}
		}
	}
	return dist;
}

int main(){
	scanf("%d%d%d",&n,&m,&k);
	REP(i,n)scanf("%d",p+i);
	REP(i,n)scanf("%d",c+i),c[i]--;
	REP(i,n)scanf("%d",j+i);
	// 0 - i
	vector<vector<pll>> g(n);
	REP(i,m){
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		--x;--y;
		g[x].push_back(pll(y,z));
		g[y].push_back(pll(x,z));
	}
	vl dist = dijkstra(g,0);
	// 0 - pan - i
	vector<vector<pll>> g2(n+n);
	REP(i,n)for(pll P : g[i]){
		g2[i].push_back(P);
	}
	REP(i,n){
		g2[i].push_back(pll(i+n,-p[i]));
	}
	vl dist2 = dijkstra(g2,0);
	// (0-pan-) i - jam (-0)
	vector<vector<pll>> g3(1+n+k);
	REP(i,n)for(pll P : g[i]){
		g3[i].push_back(P);
	}
	REP(i,n){
		g3[n+k].push_back(pll(i,dist2[i+n]));
		g3[i].push_back(pll(n+c[i],-j[i]+dist[i]));
	}
	vl dist3 = dijkstra(g3,n+k);
	// output
	REP(i,k){
		printf("%lld\n",-dist3[n+i]);
	}
	return 0;
}


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

int main() {
    int N, M, C, Aij;
    int A[20][20];
    int B[20];
    int sum = 0;
    int c = 0;
    cin >> N >> M >> C;
    for (int i = 0; i < M; i++) cin >> B[i];
    for (int i = 0; i < N; i++) {
        sum = C;
        for (int j = 0; j < M; j++) {
            cin >> Aij;
            sum += Aij * B[j];
        }
        if (sum > 0) c++;
    }

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

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;

int main() {
	int H, W, K;
    string C[8];
	cin >> H >> W >> K;
    for (int i = 0; i < H; ++i){
        cin >> C[i];
    }

    int ans  = 0;
    for (int maskH = 0; maskH < 1 << H; ++maskH){
        for (int maskW = 0; maskW < 1 << W; ++maskW){
            int sum = 0;
            for (int i = 0; i < H; ++i){
                for (int j = 0; j < W; ++j){
                    if ( maskH & 1<<i && maskW & 1<<j && C[i][j] == '#') sum++;
                }
            }
            if (sum == K) ans++;
        }
    }

    cout << ans << endl;

	return 0;
}

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


class Main {
    static int p=0;
    static int[]ops;
    static long[]a;
    static int n;
    static void add(int x,int y){
        a[y]+=a[x];
        ops[p++]=x*n+y;
    }
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        n=sc.nextInt();
        a=new long[n];
        ops=new int[2*n];
        for(int i=0;i<n;++i)a[i]=sc.nextLong();
        long max=Math.abs(a[0]);
        int maxind=0;
        for(int i=1;i<n;++i){
            if(max<Math.abs(a[i])){
                max=Math.abs(a[i]);
                maxind=i;
            }
        }
        if(max!=0){
            for(int i=0;i<n;++i)
                if(i!=maxind)
                    add(maxind,i);
            if(a[maxind]<0)
                for(int i=n-2;i>=0;--i)
                    add(i+1,i);
            else
                for(int i=0;i<n-1;++i)
                    add(i,i+1);
        }
        out.println(p);
        for(int i=0;i<p;++i){
            int x=ops[i]/n+1;
            int y=ops[i]%n+1;
            out.println(x+" "+y);
        }
        out.close();
    }
    // http://codeforces.com/blog/entry/7018
    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;
    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;
        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 23380
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a), i##_max = (b); i < i##_max; ++i)
#define RFOR(i, a, b) for (int i = (b)-1, i##_min = (a); i >= i##_min; --i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()

using namespace std;
using vi = vector<int>;
using vd = vector<double>;
using i64 = int64_t;

constexpr int INF = 1 << 30;
constexpr int MOD = 1000000007;

template <typename T>
void print(vector<T> &v) {
  REP(i, v.size()) {
    if (i) cout << " ";
    cout << v[i];
  }
  cout << endl;
}

void dfs(vector<vi> &M, vi &d, int s) {
  queue<int> q;
  q.push(s);
  d[s] = 0;
  while (!q.empty()) {
    auto u = q.front();
    q.pop();
    REP(v, d.size()) {
      if (M[u][v] == 0) continue;
      if (d[v] != INF) continue;
      d[v] = d[u] + 1;
      q.push(v);
    }
  }
  REP(i, d.size()) cout << i + 1 << " " << ((d[i] == INF) ? -1 : d[i]) << endl;
}

int main() {
  int n, u, k, v;
  cin >> n;
  vector<vi> M(n, vi(n, 0));
  vi d(n, INF);
  REP(i, n) {
    cin >> u >> k;
    REP(j, k) {
      cin >> v;
      M[u - 1][v - 1] = 1;
    }
  }
  dfs(M, d, 0);
}


Measured memory_bytes: 3140
using System;
using System.Collections.Generic;
using System.Linq;
class Program
    {
        static long mod = 1000000007;
        static long pow(long a, long n)
        {
            a %= mod;
            long ret = 1;
            long buf = a;
            while (true)
            {
                if((n & 1) == 1) ret = ret * buf % mod;
                else if (n == 0) break;
                buf = buf * buf % mod;
                n >>= 1;
            }
            return ret;
        }
        static long inv(long a)
        {
            return pow(a, mod - 2);
        }
        static void Main(string[] args)
        {   
            string[] s = Console.ReadLine().Split(' ');
            int n = int.Parse(s[0]), k = int.Parse(s[1]);

            long blue = 1, red = n - k + 1;
            Console.WriteLine(blue * red % mod);
            long[] inverse = new long[n];
            for (int i=0; i<n; i++)
            {
                inverse[i] = inv(i);
            }

            for (int i=2; i<=k; i++)
            {
                if (n - k < i - 1) Console.WriteLine(0);
                else
                {
                    blue = blue * (long)(k-i+1) % mod * inverse[i-1] % mod;
                    red = red * (long)(n-k-i+2) % mod * inverse[i] % mod; 
                    Console.WriteLine(blue * red % mod);
                }
            }
            
        }
    }
    //mcs Main.cs
    //mono Main.exe

Measured memory_bytes: 13116
#include <iostream>
#include <vector>
#include <string>
#include <map>

using namespace std;

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

    int ss [m+1]{0};

    for (int i=0;i<n;i++){
        for (int j=0; j<m; j++){
            cin >> e;
            ss[j] += e;
            ss[m] += e;
            cout << e << ' ';
        }
        cout << ss[m] << endl;
        ss[m] = 0;
    }

    for (int j=0; j<m; j++){
        ss[m] += ss[j];
        cout << ss[j] << ' ';
    }
    cout << ss[m] << endl;
}



Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define int long long
#define pq priority_queue

using namespace std;

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    map<string, int> anag;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        if (anag.find(s) != anag.end()) {
            anag[s]++;
        } else {
            anag[s] = 1;
        }
    }
    int no_pairs = 0;
    for (map<string, int>::iterator it = anag.begin(); it != anag.end(); it++) {
        no_pairs += (it -> second) * ((it -> second) - 1) / 2;
    }
    cout << no_pairs;
}

Measured memory_bytes: 11460
#include<stdio.h>

int main(void){
    int N,h[100];
    int i,j,num,l,r;
    scanf("%d",&N);
    for(i=0;i<N;i++){
        scanf("%d",&h[i]);
    }
    l=0;    num=0;  h[i]=-1;    j=0;
    while(1){
        if(h[l]==0){
            l++;
            r=l;
        }else if(h[r]>0){
            r++;
            continue;
        }else if(h[r]<=0){
            for(i=l;i<r;i++){
                h[i]--;
            }
            l=0;    r=0;
            num++;
            continue;
        }
        if(h[l]==-1)  break;

    }
    printf("%d\n",num);
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>
#include<bitset>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll a[3][3] = {}, n, b;
bool flag = false;

int main() {
	rep(i, 3) {
		rep(j, 3)cin >> a[i][j];
	}
	cin >> n;
	rep(i, n) {
		cin >> b;
		rep(j, 3) {
			rep(k, 3) {
				if (a[j][k] == b)a[j][k] = 0;
			}
		}
	}
	rep(i, 3) {
		bool flag1 = false, flag2 = false;
		rep(j, 3) {
			if (a[i][j])flag1 = true;
			if (a[j][i])flag2 = true;
		}
		if (!flag1 || !flag2)flag = true;
	}
	if (flag || (a[0][0] == 0 && a[1][1] == 0 && a[2][2] == 0) || (a[0][2] == 0 && a[1][1] == 0 && a[2][0] == 0)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;cin>>n;
    vector<int>h(n,0);
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    vector<int>dp(n+1,1e9+5);
    dp[1]=0;
    for(int i=1;i<n+1;i++){
        for(auto j:{i+1,i+2}){
            if(j<=n){
                dp[j]=min(dp[j],dp[i]+abs(h[j-1]-h[i-1]));
            }
        }
    }
    cout<<dp[n];
    return 0;
}


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

int main() {
	// your code goes here
	int n;
	cin >> n;
	if(n < 1000)
	cout << 1000 - n <<endl;
	else
	cout << int(ceil((n*1.0)/1000)*1000) - n << endl;
	return 0;
}

Measured memory_bytes: 3760
#include<cstdio>
#include<cstring>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
map<int,int> mp;
set<int> st;
int main()
{
	int n,b;	
	cin>>n;
	int sum=0;
	while(n--)
	{
		cin>>b;
		mp[b]++;
		st.insert(b);
	}
	set<int>::iterator it=st.begin();
	for(;it!=st.end();it++)
	{
		if(mp[*it]%2==1)
			sum++;
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define ALL(x) std::begin(x), std::end(x)
using namespace std;

/**
 * @note O((E + V) log V)
 */
vector<int64_t> dijkstra(vector<vector<pair<int, int64_t> > > const & g, int root) {
    vector<int64_t> dist(g.size(), INT64_MAX);
    priority_queue<pair<int64_t, int> > que;
    dist[root] = 0;
    que.emplace(- dist[root], root);
    while (not que.empty()) {
        int64_t dist_i; int i; tie(dist_i, i) = que.top(); que.pop();
        if (dist[i] < - dist_i) continue;
        for (auto it : g[i]) {
            int j; int64_t cost; tie(j, cost) = it;
            if (- dist_i + cost < dist[j]) {
                dist[j] = - dist_i + cost;
                que.emplace(dist_i - cost, j);
            }
        }
    }
    return dist;
}

int main() {
    int n, m; cin >> n >> m;
    vector<vector<pair<int, int64_t> > > g(n);
    REP (i, n - 1) {
        g[i + 1].emplace_back(i, 0);
    }
    REP (i, m) {
        int l, r; int64_t c; cin >> l >> r >> c;
        -- l;
        -- r;
        g[l].emplace_back(r, c);
    }
    int64_t dist = dijkstra(g, 0)[n - 1];
    cout << (dist == INT64_MAX ? -1 : dist) << endl;
    return 0;
}


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

int main (){
	int n,k;
	cin >> n>>k;
    string s;
    cin>>s;
    int score =0;
    for(int i=0;i<n-1;i++){
        if(s[i]==s[i+1]){
            score++;
        }
    }
    int ans = min(score+2*k,n-1);
    cout<<ans<<endl;
}


Measured memory_bytes: 512
class Main{

	public static void main (String[] args) {

		Main main = new Main();

		java.util.Scanner sc = new java.util.Scanner(System.in);

		int N = sc.nextInt();
		char[] list = new char [N];
		String color = sc.next();

		for (int index=0; index<N; index++) {
			list[index] = color.charAt(index);
		}

		int r = 0;

		for (int index=0; index<N; index++) {
			if (list[index]=='R') {
				r++;
			}
		}
		int count = 0;
		for (int index=0; index<r; index++) {
			if (list[index]=='W') {
				count++;
			}
		}
		System.out.println(count);
		sc.close();
	}
}


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

class Main
{
    static class Len
    {	
	int a[]; //= new int[2000010];
	int b[]; //= new int[2000010];
	
	Len(int n)
	{
	    a = new int[n+1];
	    b = new int[n+1];
	}
	

    }

    public static void main(String args[])
    {
	int n;
	int i, j, k;

	String line = new String();
	BufferedReader bin = new BufferedReader(new InputStreamReader(System.in));

	//Read ----------------
	//Read n
	try{
	    line=line=bin.readLine();
	}	
	catch(IOException e){
	    System.out.println("Error");
	}

	n=Integer.parseInt(line);
	Len len = new Len(n);
	j=0;
	//Read A[]
	try{
	    line=bin.readLine();
	    //System.out.println(line);
	    StringTokenizer str = new StringTokenizer(line);   
	    for(i=0; i<n; i++)
		{
		    len.a[i]=Integer.parseInt(str.nextToken());
		    if(j<len.a[i])j=len.a[i];
		}
	}
	catch(IOException e){
	    System.out.println("Error");
	}

	//bin=null;

	//Read end------------


	//sort
	countingSort(len, j, n);

	//print
	StringBuffer s = new StringBuffer(100);
	for(i=1; i<=n; i++)
	    {
		s.append(len.b[i]);
		if(i!=n)s.append(" ");
	    }
	System.out.println(s);

    }

    static void countingSort(Len len, int max, int n)
    {
	int i, j, k;
	int[] c = new int[max+1];

	for(i=0; i<n; i++)c[len.a[i]]++;

	for(i=0; i<=max; i++)
	    {
		if(i!=0)c[i]+=c[i-1];
	    }

	for(i=n-1; i>=0; i--)
	    {
		len.b[c[len.a[i]]]=len.a[i];
		c[len.a[i]]--;
	    }
    }
}

Measured memory_bytes: 102000
n,y=map(int,input().split())

x=y//10000
ans="-1 -1 -1"
for i in range(x+1):
    for j in range(n-i+1):
        if 10000*i+5000*j+1000*(n-i-j)==y:
            ans=(str(i)+" "+str(j)+" "+str(n-i-j))
            

print(ans)

Measured memory_bytes: 3060
time=[0]*1001
a,b=list(map(int,input().split()))
n=int(input())
for i in range(n):
    s,f=list(map(int,input().split()))
    time[s:f]=[1]*(f-s)
if sum(time[a:b])==0:print("0")
else:print("1")


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

int main() {
  int N,i;
  double x, Ans;
  string u;
  cin >> N;
  for(i=0;i<N;i++){
    cin >> x;
    cin >> u;
    if(u=="JPY"){
      Ans +=x;
    }
    else if(u=="BTC"){
      Ans +=x*380000.0;
    }
  }
  cout << Ans <<endl;
}


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

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

    int N; cin >> N;
    int ans = 0, m = 0;
    for (int i = 0; i < N; i++) {
        int p; cin >> p;
        ans += p;
        m = max(m, p);
    }
    cout << ans - m / 2 << "\n";
}

Measured memory_bytes: 256
n, m, q = map(int, input().split())
abcd = [tuple(map(int, input().split())) for _ in range(q)]

ans = 0
import itertools
for i in itertools.combinations_with_replacement(range(1, m+1), n):
    sumd = 0
    for j in abcd:
        if i[j[1]-1] - i[j[0]-1] == j[2]:
            sumd += j[3]
    ans = max(ans, sumd)
print(ans)

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

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()

int main(){
    cout << setprecision(20);

    ll N;
    cin >> N;
    ll total = 0;
    REP(i, 1, N+1){
        if(i%3>0 && i%5>0) total += i;
    }
    cout << total << endl;
}


Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

template <typename TYPE>
void print_vec(const vector<TYPE>& v){
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   " << endl;
		for(int j=0; j<v[i].size(); j++){
			cout << v[i][j] << "   ";
		}
		cout << endl;
	}
}




int main(){
	//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_A&lang=ja
	//Coin Changing Problem

	int n, m;
	cin >> n >> m;
	vector<int> coin(m);
	for(int i=0; i<m; i++){
		cin >> coin[i];
	}

	const int INF = 50000 + 1;
	//dp[yen][c]: コイン0~c-1枚目まで考慮して，ちょうどyen円を作るのに必要な最小枚数
	vector<vector<int>> dp(n+2, vector<int>(m+1, INF));
	dp[0][0] = 0;//コイン1種類も使わずとも0円は0枚で作れる
	for(int i=0; i<(int)dp[0].size(); i++) dp[0][i] = 0;
	
	for(int yen=0; yen<=n; yen++){
		for(int c=0; c<m; c++){
			//使わない
			dp[yen][c+1] = min(dp[yen][c+1], dp[yen][c]+0);

			
			int pay = yen+coin[c];
			if(pay >= (int)dp.size()) continue;
			//cout <<"  yen: " << yen  << " c: " << c << " coin[c+1]: " << coin[c+1] <<   "  pay: " << pay << endl;
			//使う(1回目)
			dp[pay][c+1] = min(dp[pay][c+1], dp[yen][c]+1);

			//使う(2回目以降)
			dp[pay][c+1] = min(dp[pay][c+1], dp[yen][c+1]+1);
		}
	}
	
	// print_vec2(dp);
	// cout << " coin: " ; print_vec(coin);
	// int a = 1;
	// cout << " dp[24+a][m]: " << dp[24+a][m] <<" dp[61+a][m]: " << dp[61+a][m]
	//  << " dp[74+a][m]: " << dp[74+a][m] << " dp[98+a][m]: " << dp[98+a][m]
	// << endl;
	cout << dp[n][m] << endl;
}



Measured memory_bytes: 8608
#include<bits/stdc++.h>
#define N 300005
#define SIZE 2000005
#define int long long
#define pb push_back
#define x first
#define y second
#define all(v) v.begin(),v.end()
using namespace std;

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int x; cin>>x;
    int ans = 0; int cur = 100;
    while(cur<x){
        ans++ ;
        cur += (cur)/(100ll);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3652
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   ff   first
#define   ss   second
#define   pii  pair<int,int>
using namespace std;

inline void solve(){
    int n,r; cin>>n>>r;
    int a[n][r],ans=0;
    for (int i=0;i<n;i++){
        for (int &j: a[i]) cin>>j;
    }
    for (int i=0;i<n;i++){
        for (int j=i+1;j<n;j++) {
            int d=0;
            for (int k=0;k<r;k++){
                d += (a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
            }
            // do some calculation....
            int sq=sqrt(d);
            if (sq*sq==d) ans++;
        }
    }
    cout << ans << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 3624
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    public static void Main()
    {
        var line = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        int A = line[0];
        int B = line[1];
        int C = line[2];
        int ans = C - (A - B);
        if(C - (A - B) <= 0)
        {
            ans = 0;
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13268
if __name__ == '__main__':

    n,k = map(int,input().split())

    A = [0] * n

    for _ in range(k):
        m = int(input())
        B = list(map(int,input().split()))
        for b in B:
            A[b-1] += 1
    print(A.count(0))


Measured memory_bytes: 9028
n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = 10**9 + 7
ans = 1

if k == n:
    for i in range(n):
        ans *= a[i]
        ans %= mod
    print(ans)
    exit()
if max(a) < 0 and k%2 == 1:
    a.sort(reverse=True)
    for i in range(k):
        ans *= a[i]
        ans %= mod
    print(ans)
    exit()

plus, minus = [], []
for i in range(n):
    if a[i] >= 0: plus.append(a[i])
    else: minus.append(a[i])

plus.sort()
minus.sort(reverse=True)
while k > 0:
    if len(plus) >= 2 and len(minus) >= 2:
        nump = plus[-1] * plus[-2]
        numm = minus[-1] * minus[-2]
        if nump > numm or k == 1:
            ans *= plus.pop()
            ans %= mod
            k -= 1
        else:
            ans *= minus.pop()
            ans *= minus.pop()
            ans %= mod
            k -= 2
    elif len(minus) < 2:
        ans *= plus.pop()
        ans %= mod
        k -= 1
    elif len(plus) < 2:
        if k%2 == 0:
            ans *= minus.pop()
            ans *= minus.pop()
            ans %= mod
            k -= 2
        else:
            ans *= plus.pop()
            ans %= mod
            k -= 1
print(ans)

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

using namespace std;


int main()
{
    int a, b, ans = 1;
    cin >> a >> b;

    if(b == 1){
        cout << 0;

        return 0;
    }

    if(a >= b){
        cout << 1;

        return 0;
    }
    int aa = a - 1;
    while((ans - 1) * aa + a < b){
        ans++;
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
 int n,m;
  cin>>n>>m;
  long long a[n+1];
  a[0]=0;
  for(int i=1;i<n+1;i++){
    int k;
    cin>>k;
    a[i]=a[i-1]+k;
  }
  long long ans=0;
  for(int i=0;i<n-m+1;i++){
    ans=max(ans,a[i+m]-a[i]);
  }
  if((ans+m)%2==0)cout<<(ans+m)/2<<endl;
  else cout<<(ans+m)/2<<".5"<<endl;
}


Measured memory_bytes: 1792
import qualified Data.Map as Map

m1=1000000007
t="AGC"
f::String->Bool
f (a:b:c:[])=((a:b:c:[])/=t && (b:a:c:[])/=t && (a:c:b:[]/=t))

f2::String->Bool
f2 (a:b:c:d:[])=((a:b:d:[])/=t && ((c:b:d:[])/=t) && (b:c:d:[])/=t && (b:d:c:[])/=t&&(a:c:d:[])/=t)

f3::Int->Int->Int
f3 a b=mod (a+b) m1

g::Int->Map.Map String Int->Int
g 0 ms=mod (sum $ Map.elems ms) m1
g k ms=g (k-1) (Map.fromListWith (f3) [(b:c:d:[],c1)|(a:b:c:[],c1)<-(Map.toList ms),d<-"AGCT",f2 (a:b:c:d:[])])

main = do
       t<-getLine
       let n=read t::Int
           s="AGCT"
           ms=Map.fromList [(e1:e2:e3:[],1)|e1<-s,e2<-s,e3<-s,f (e1:e2:e3:[])]
       print $ g (n-3) ms

Measured memory_bytes: 3324
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n,a[100],cnt=0,j;
  cin>>n;
  for(int i=0;i<n;i++)cin>>a[i];
  for(int i=0;i<n;i++){
    int minj=i;
    for(j=i;j<n;j++)if(a[j]<a[minj])minj=j;
    if(minj!=i){swap(a[minj],a[i]);cnt++;}
  }
  for(int i=0;i<n;i++){
    cout<<a[i];
    i==n-1?cout<<endl:cout<<" ";
  }
  cout<<cnt<<endl;
  return 0;
}

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

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int h = sc.nextInt();
		int w = sc.nextInt();
		char[][] s = new char[h][w];
		for(int i = 0; i < h; i++){
			s[i] = sc.next().toCharArray();
		}
		int[][] dp = new int[h][w];
		for(int i = 0; i < h; i++){
			Arrays.fill(dp[i], Integer.MAX_VALUE);
		}
		if(s[0][0] == '#') dp[0][0] = 1;
		else dp[0][0] = 0;
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++) {
				if(i == 0 && j == 0) continue;
				if(i > 0) {
					if(s[i][j] == '#' && s[i-1][j] == '.') {
						dp[i][j] = Math.min(dp[i][j], dp[i-1][j]+1);
					}
					else {
						dp[i][j] = Math.min(dp[i][j], dp[i-1][j]);
					}
				}
				if(j > 0) {
					if(s[i][j] == '#' && s[i][j-1] == '.') {
						dp[i][j] = Math.min(dp[i][j], dp[i][j-1]+1);
					}
					else {
						dp[i][j] = Math.min(dp[i][j], dp[i][j-1]);
					}
				}
			}
		}
		System.out.println(dp[h-1][w-1]);
	}
	static class FastScanner {
		public BufferedReader reader;
		public StringTokenizer tokenizer;
		public FastScanner() {
			reader = new BufferedReader(new InputStreamReader(System.in), 32768);
			tokenizer = null;
		}
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch(IOException e) {
				throw new RuntimeException(e);
			}
		}
	}

}


Measured memory_bytes: 23376
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int MAX = 210012;
vector<vector<int>> graph(MAX);
LL dp[MAX];

// グラフの経路を探索する.
// https://ja.wikipedia.org/wiki/深さ優先探索
// @param c: 探索地点となる頂点.
// @param b: 探索地点から見て, 前回探索済の頂点.
// @return : 特に無し.
void dfs(int c, int b){
    dp[c] += dp[b];
    for(int e : graph[c]){
        if(e == b) continue;
        dfs(e, c);
    }
}

int main(){
    
    // 1. 入力情報取得.
    int N, Q;
    scanf("%d %d", &N, &Q);
    for(int i = 0; i < N - 1; i++){
        int a, b;
        scanf("%d %d", &a, &b);
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    for(int i = 0; i < Q; i++){
        int p;
        LL x;
        scanf("%d %lld", &p, &x);
        dp[p] += x;
    }
    
    // 2. dp更新.
    dfs(1, 0);
    
    // 3. 出力 ～ 後処理.
    for(int i = 1; i <= N; i++) printf("%lld ", dp[i]);
    return 0;
    
}

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

int main(void){
    int n,m;
    cin >> n >> m;
    for(int i = 0;i < m;i++){
        int a;
        cin >> a;
        n -= a;
    }
    cout << max(n,-1) << endl;
}

Measured memory_bytes: 3636
N, A, B = [int(i) for i in input().split()]
S = input()

a, b = 0, 0
for s in S:
    if s == "a" and a + b < A + B:
        print("Yes")
        a += 1
    elif s == "b" and a + b < A + B and b < B:
        print("Yes")
        b += 1
    else:
        print("No")

Measured memory_bytes: 4016
#include <iostream>
using namespace std;
int prim();
static const int maxs=100;
static const int infty=(1<<21);
static const int white=0;
static const int gray=1;
static const int black=2;

int n,m[maxs][maxs];

int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      int e; cin>>e;
      m[i][j]=(e==-1)?infty:e;
    }
  }
  cout<<prim()<<endl;
  return 0;
}

int prim(){
  int u,minv;
  int d[maxs],p[maxs],color[maxs];
  for(int i=0;i<n;i++){
    d[i]=infty;
    p[i]=-1;
    color[i]=white;
  }
  d[0]=0;
  while(1){
    minv=infty;
    u=-1;
    for(int i=0;i<n;i++){
      if(minv>d[i]&&color[i]!=black){
	u=i;
	minv=d[i];
      }
    }
    if(u==-1)break;
    color[u]=black;
    for(int v=0;v<n;v++){
      if(color[v]!=black&&m[u][v]!=infty){
	if(d[v]>m[u][v]){
	  d[v]=m[u][v];
	  p[v]=u;
	  color[v]=gray;
	}
      }
    }
  }
  int sum=0;
  for(int i=0;i<n;i++){
    if(p[i]!=-1)sum+=m[i][p[i]];
  }
  // cout<<p[0]<<" "<<p[1]<<" "<<p[2]<<" "<<p[3]<<" "<<p[4]<<" "<<endl;/////////
  return sum;
}

Measured memory_bytes: 3092
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <functional>

using namespace std;

typedef pair<double, string> P;
typedef pair<string, double> Q;

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		string plant;
		int p, a, b, c, d, e, f, s, m;
		int time;
		double kou;
		priority_queue<P> pq;
		for (int i = 0; i < n; i++) {
			cin >> plant >> p >> a >> b >> c >> d >> e >> f >> s >> m;
			time = a+b+c+(d+e)*m;
			kou = (double)(s*f*m-p) / (double)time;
			P pp;
			pp.first = kou;
			pp.second = plant;
			pq.push(pp);
		}
		while (!pq.empty()) {
			P ppp = pq.top();
			pq.pop();
			priority_queue< Q, vector<Q>, greater<Q> > pqq;
			Q q;
			q.first = ppp.second;
			q.second = ppp.first;
			pqq.push(q);
			while (!pq.empty()) {
				if ((pq.top()).first == ppp.first) {
					q.first = (pq.top()).second;
					pqq.push(q);
					pq.pop();
				} else {
					break;
				}
			}
			while (!pqq.empty()) {
				cout << (pqq.top()).first << endl;
				pqq.pop();
			}
		}
		cout << '#' << endl;
	}
	return 0;
}

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

#define REP(i,n) for(int i=0;i<(n);++i)
#define ll long long
const long long INF = 1LL<<60;
const long long mod = 1e9 + 7;

int main(){
    int N, i;
    cin >> N >> i;
    cout << N-i+1 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll N,T,A,t,a;
	cin>>N;
	t=a=1;
	for(ll n=0;n<N;n++){
		cin>>T>>A;
		ll k=max((t+T-1)/T,(a+A-1)/A);
		t=k*T;
		a=k*A;
	}
	cout<<t+a<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,igo[100005],a,white,black;

int main(){

    while(1){
            white=0;

    cin >> n;
    if(n==0)break;

    cin >> igo[1];

    for(int i=2;i<=n;i++){
        cin >> a;
        if(i%2==0){
        if(a!=igo[i-1]){
            for(int j=i-1;j>0;j--){
                if(igo[j]==a)break;
                else igo[j]=a;
                }
                igo[i]=a;
            }else igo[i]=a;
        }else igo[i]=a;
    }

    for(int i=1;i<=n;i++){
        if(igo[i]==0)white++;
    }

    cout << white << endl;
    //for(int i=1;i<=n;i++)cout << igo[i];
    //cout << endl;


    }

return 0;
}

Measured memory_bytes: 1548
N, M, C = map(int, input().split())
B = [int(x) for x in input().split()]
A = [[int(x) for x in input().split()] for y in range(N)]
ans = 0
for n in range(N):
    z = C
    for i in range(M):
        z += B[i]*A[n][i]
    if z>0: ans+=1
print(ans)


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


Measured memory_bytes: 3848
#include <stdio.h>

int main(){
int N,M;
int a[55];
int b[55];
int ans[55]={0};
scanf("%d%d\n",&N,&M );
for (int i = 0; i < M; i++) {
  scanf("%d%d\n",&a[i],&b[i] );
  a[i]--;
  b[i]--;
}
for (int i = 0; i < N; i++) {

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

    if(a[j]==i||b[j]==i){
      ans[i]++;
    }else{}
  }
printf("%d\n",ans[i] );

}

return 0;


}


Measured memory_bytes: 128
#include <stdio.h>
#include <math.h>

int main () {
	int n, b, p, max = 1, tmp;
	scanf ("%d", &n);
	int s = (int)sqrt (n);

	for (b=2; b<=s; b++) 
		for (p=2; n>=(tmp=pow(b,p)); p++)
			if (tmp > max) max = tmp;

	printf ("%d\n", max);
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
using namespace std;
long int H[200000];
int main()
{
    long N, K, ans = 0;
    scanf("%ld %ld", &N, &K);
    for (long i = 0; i < N; i++)
        scanf("%ld", H + i);
    std::sort(H, H + N);
    for (long i = 0; i < N - K; i++)
        ans += H[i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
void tyu(int x,int y,int N[15][15])
{
	int xt,yt;
	xt=x-1;yt=y-1;
	for(int i=yt;i<=yt+2;i++)
		for(int j=xt;j<=xt+2;j++)
			N[i][j]++;
}
void syo(int x,int y,int N[15][15])
{
	N[y][x]++;N[y+1][x]++;N[y-1][x]++;
	N[y][x+1]++;N[y][x-1]++;
}
void dai(int x,int y,int N[15][15])
{
	int xt,yt;
	xt=x-1;yt=y-1;
	for(int i=yt;i<=yt+2;i++)
		for(int j=xt;j<=xt+2;j++)
			N[i][j]++;
	N[y+2][x]++;N[y-2][x]++;
	N[y][x+2]++;N[y][x-2]++;
}

int main()
{
	int x,y,z,PP[15][15]={},xt=0,yt=0;
	while(scanf("%d,%d,%d",&x,&y,&z)!=EOF)
	{
		xt=x+2;yt=y+2;
		if(z==1)syo(xt,yt,PP);
		else if(z==2)tyu(xt,yt,PP);
		else if(z==3)dai(xt,yt,PP);
	}
	int SUM1=0,SUM2=0,max=0;
	for(int i=2;i<12;i++){
		for(int j=2;j<12;j++){
			if(PP[i][j]==0)SUM1++;
			if(PP[i][j]>max){max=PP[i][j];SUM2=1;}
			else if(PP[i][j]==max)SUM2++;
		}
	}
	printf("%d\n%d\n",SUM1,max);

	return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(0), cin.tie(NULL);
#define bge(s) s.begin(), s.end()
#define endl "\n"
#define int long long
using namespace std;

int knapSack(int W, vector<int> wt, vector<int> val, int n)
{
    int i, w;
    int K[n + 1][W + 1];
    for (i = 0; i <= n; i++)
    {
        for (w = 0; w <= W; w++)
        {
            if (i == 0 || w == 0)
                K[i][w] = 0;
            else if (wt[i - 1] <= w)
                K[i][w] = max(
                    val[i - 1] + K[i - 1][w - wt[i - 1]],
                    K[i - 1][w]);
            else
                K[i][w] = K[i - 1][w];
        }
    }

    return K[n][W];
}

int32_t main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
#endif
    IOS int n, w;
    cin >> n >> w;
    vector<int> v1(n);
    vector<int> v2(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v1[i];
        cin >> v2[i];
    }
    cout << knapSack(w, v1, v2, n) << endl;
    return 0;
}

Measured memory_bytes: 82468
#define MOD_TYPE 1

#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
/*
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using multiInt = boost::multiprecision::cpp_int;
using lld = boost::multiprecision::cpp_dec_float_100;
*/
/*
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
*/
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
constexpr int INF = (int)1e9;
constexpr ll LINF = (ll)4e18;
constexpr ld PI = acos(-1.0);
constexpr ld EPS = 1e-11;
constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define REPI(i, m, n) for (int i = m; i < (int)(n); ++i)
#define repi(i, n) REPI(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

inline void init_main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);
}
template <typename T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
inline ll CEIL(ll a, ll b)
{
  return (a + b - 1) / b;
}
template <typename A, size_t N, typename T>
inline void Fill(A (&array)[N], const T &val)
{
  fill((T *)array, (T *)(array + N), val);
}
#pragma endregion

int n, m, q;
int a[50], b[50], c[50], d[50];
int Max = 0;

void dfs(vector<int> &v)
{
  if (v.size() == n)
  {

    int sum = 0;
    rep(i, q)
    {
      if (v[b[i]] - v[a[i]] == c[i])
        sum += d[i];
    }
    chmax(Max, sum);
    return;
  }

  int b = (v.empty() ? 1 : v.back());
  for (int i = b; i <= m; i++)
  {
    v.push_back(i);
    dfs(v);
    v.pop_back();
  }
}

int main()
{
  init_main();
  cin >> n >> m >> q;
  rep(i, q)
  {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
    a[i]--, b[i]--;
  }
  vector<int> v;
  dfs(v);
  cout << Max << endl;
  return 0;
}


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

    vector<int> L(N);
    int sum = 0;

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

    sort(L.begin(), L.end(), greater<int> ());

    for(int i = 0; i < K; i++){
        sum += L[i];
    }
    cout << sum;


}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(a: int, b: int):
    c=[]
    d=[]
    for i in range(int(a)):
        c.append(b)
    for i in range(int(b)):
        d.append(a)
    ans="".join(min(c,d))
    print(ans)

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    a = str(next(tokens))  # type: int
    b = str(next(tokens))  # type: int
    solve(a, b)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(Type, ...)  Type __VA_ARGS__; input(__VA_ARGS__)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
inline i64  sigma(i64 n)            { return (n * (n + 1) >> 1); }
inline i64  updiv(i64 a, i64 b)     { return (a + b - 1) / b; }
inline i64  sqr(i64 n)              { return n * n; }
inline string to_string(char c)     { return string(1, c); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> make_v(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}
template <class T, class... Args>
inline auto make_v(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initValue, args...))>(sz, make_v<T>(initValue, args...));
}

inline void input() {}
template <class Head, class... Tail>
inline void input(Head &head, Tail&... tail) { cin >> head; input(tail...); }

inline void print() { cout << "\n"; }
template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) out << e << delim[&e == &vec.back()];
    return out;
}
// }}} End Header

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

    var(string, s);
    if (s.find("YAKI") == 0) {
        print("Yes");
    } else {
        print("No");
    }

    return 0;
}


Measured memory_bytes: 256