akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define vc vector<int>
#define um unordered_map<int,int>
#define ll long long 
#define rep(i,a,b) for(__typeof(a) i=a; i<b; i++)
#define si(a) a.size()
#define all(a) a.begin(),a.end()
#define ss(a) a.second
#define ff(a) a.first
#define M 1000000
#define pb push_back
#define repit(i,a) for(auto i=a.begin(); i!=a.end(); i++)
#define take(arr,n) for(int i=0;i<n;i++)cin>>arr[i]
#define out(arr,n) for(int i=0;i<n;i++)cout<<arr[i]<<' '
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define reprev(i,b,a) for(__typeof(b) i=b; i>=a; i--)
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define doublearray vector<vector<int>>
#define mod 1000000007
using namespace std;
ll max(ll a, ll b){ return a>b?a:b; }
ll min(ll a, ll b){ return a<b?a:b; }
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a, ll b){
    return (a*b)/gcd(a,b);
}
int main(){
    fastio;
    string s; cin>>s; bool t = false;
  	int c=0; rep(i,0,3){ if(s[i]=='R'){ c++; if(i<2&&s[i]==s[i+1]) t=true;}}
  	if(c==3) cout<<3<<endl;
  	else if(c==2){ if(t) cout<<2<<endl; else cout<<1<<endl; }
     else if(c==1) cout<<1<<endl;
  else cout<<0<<endl;
    return 0;
}





Measured memory_bytes: 3488
import sys
sys.setrecursionlimit(4100000)

k,n = map(int,input().split())
a = list(map(int,input().split()))
b = []
for v in range(n-1):
    b.append(a[v+1]-a[v])

b.append(k-a[n-1]+a[0])
anss = max(b)
ans = k - anss
print(str(ans))

Measured memory_bytes: 26420
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <sstream>
using namespace std;

#define NUM 4

//string -> int
inline int toInt(string s){
  int v;
  istringstream iss(s);
  iss >> v;
  return v;
}

// ~~~ -> string
template<class T>
inline string toString(T x){
  ostringstream oss;
  oss << x;
  return oss.str();
}


int main(){
  int n;
  int t[10010] = {};
  
  cin >> n;
  int a;
  for(int i = 0 ; i < n ; i++){
    scanf("%d", &a);
    t[a]++;
  }
  
  vector<int> v;
  for(int i = 1 ; i <= 10000 ; i++){
    if(t[i] > 0){
      v.push_back(i);
      t[i]--;
      if(v.size() == NUM) break;
    }
    if(v.size() == NUM) break;
  }
  
  vector<int> vv;
  for(int i = 0 ; i < v.size() ; i++){
    for(int j = 0 ; j < v.size() ; j++){
      if(i == j) continue;
      string s, s1, s2;
      s1 = toString(v[i]);
      s2 = toString(v[j]);
      s = s1+s2;
      int p = toInt(s);
      vv.push_back(p);
    }
  }
  
  sort(vv.begin(), vv.end());
  
  cout << vv[2] << endl;
  return 0;
}



  
    

Measured memory_bytes: 1340
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define ull unsigned long long
#define F first
#define S second
#define eps 1e-6
#define mp make_pair
const long long INF=1e18+2;
const int MX=100004;
int N, M, k;
int arr[MX];
string s;;
pair<int,int> solve(char c)
{
    int cur=0;
    for(int i=0;i<s.size();i++)
    {
        if(s[i] == c) cur--;
        else ++cur;
        if(cur < 0 && i) return mp(0, i);
    }
    map<int,int> m;
    cur=0;
    for(int i=0;i<s.size();i++)
    {
        if(s[i] == c) cur--;
        else ++cur;
        map<int,int>::iterator it=m.lower_bound(cur+1);
        int c=5;
        while(it != m.end() && c--)
        {
            if(i-it->S > 1) return mp(it->S+1, i);
            it++;
        }
        if(m.find(cur) != m.end()) continue;
        m[cur]=i;
    }
    return mp(-1, -1);
}
int main()
{
    cin>>s;
    pair<int,int> an=mp(-1, -1);
    for(char c='a';c<='z';c++)
    {
        pair<int,int> cur=solve(c);
        if(cur.F != -1) {
            an=cur;
            break;
        }
    }
    if(an.F == -1) cout<<"-1 -1\n";
    else {
        cout<<++an.F<<" "<<++an.S<<"\n";
    }
    return 0 ;
}



Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> N >> M;
    vi c(M);
    vi a(M);
    int n = 1 << N;
    REP(i, M) {
        cin >> a[i] >> B;
        vi b(B);
        cin >> b;
        int tmp = 0;
        REP(i, B) {
            tmp |= (1 << (b[i] - 1));
        }
        c[i] = tmp;
    }
    dump(c);
    vvi dp(M + 1, vi(n, INF));
    dp[0][0] = 0;
    REP(i, M) {
        REP(j, n) {
            if (dp[i][j] == INF)
                continue;
            int nxtj = j | c[i];
            dp[i + 1][nxtj] = min(dp[i + 1][nxtj], dp[i][j] + a[i]);
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
        }
    }
    dump(dp[M]);
    if (dp[M][n - 1] == INF)
        cout << -1 << endl;
    else
        cout << dp[M][n - 1] << endl;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N; cin >> N;
    map<ll, vector<pair<string, ll>>> x;
    x[1].push_back(make_pair("a", 1));
    rep(i, N - 1){
        for (auto a: x[i + 1]){
            rep(j, a.second){
                x[i + 2].push_back(make_pair(a.first + (char)('a' + j), a.second));
            }
            x[i + 2].push_back(make_pair(a.first + (char)('a' + a.second), a.second + 1));
        }
    }
    for (auto a: x[N]){cout << a.first << endl;}
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 9460
#include<cstdio>
#include<algorithm>

using namespace std;

int main(){
	int n; scanf("%d", &n);
	int a[100];
	for(int i = 0; i < n; i++) scanf("%d", &a[i]);
	sort(a, a + n);
	int res = 0;
	for(int i = 0; i < n - 1; i++) res += a[i + 1] - a[i];
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		int x = in.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = in.nextInt();
		System.out.println(solve(n, x, a));
		in.close();
	}

	private static int solve(int n, int x, int[] a) {
		Arrays.sort(a);
		for (int i = 0; i < n; i++)
			if (x < a[i])
				return i;
			else
				x -= a[i];
		if (x > 0)
			return n - 1;
		else
			return n;
	}
}

Measured memory_bytes: 21844
#include <stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card {
  char suit;
  int value;
};

struct Card L[MAX/2+2], R[MAX/2+2];

void merge(struct Card A[], int n, int left, int mid, int right) {
  int i, j, k;
  int n1 = mid - left;
  int n2 = right - mid;
  for(i=0;i<n1;i++) L[i] = A[left + i];
  for(i=0;i<n2;i++) R[i] = A[mid  + i];
  L[n1].value = R[n2].value = SENTINEL;
  i = j = 0;
  for(k=left; k<right; k++) {
    if(L[i].value <= R[j].value) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}

void mergeSort(struct Card A[], int n, int left, int right) {
  if(left+1 < right) {
    int mid = (left+right) / 2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid, right);
    merge(A,n,left,mid,right);
  }
}

int partition(struct Card A[], int n, int p, int r) {
  int i, j;
  struct Card t, x;
  x = A[r];
  i = p-1;
  for(j=p; j<r; j++) {
    if(A[j].value <= x.value) {
      i++;
      t=A[i]; A[i]=A[j]; A[j]=t;
    }
  }
  t=A[i+1]; A[i+1]=A[r]; A[r]=t;
  return i+1;
}

void quickSort(struct Card A[], int n, int p, int r) {
  int q;
  if(p<r) {
    q = partition(A,n,p,r);
    quickSort(A,n,p,q-1);
    quickSort(A,n,q+1,r);
  }
}

int main() {
  int n, i, v;
  struct Card A[MAX], B[MAX];
  char S[10];
  int stable = 1;

  scanf("%d", &n);

  for(i=0;i<n;i++) {
    scanf("%s %d",S,&v);
    A[i].suit =  B[i].suit  = S[0];
    A[i].value = B[i].value = v;
  }

  mergeSort(A,n,0,n);
  quickSort(B,n,0,n-1);

  for(i=0;i<n;i++) {
   
    if(A[i].suit != B[i].suit) stable = 0;
  }

  if(stable==1) printf("Stable\n");
  else printf("Not stable\n");
  for(i=0;i<n;i++) {
    printf("%c %d\n",B[i].suit,B[i].value);
  }

  return 0;
}



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

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> A[300];
    for(int i=0; i<N; i++){
        for(int j=0; j<M; j++){
            int a;
            cin >> a;
            A[i].push_back(a-1);
        }
        reverse(A[i].begin(), A[i].end());
    }
    int ans = 1e9;
    bitset<300> removed;
    int rem = 0;
    while(rem < M){
        vector<int> num(M);
        for(int i=0; i<N; i++){
            while(removed[A[i].back()]) A[i].pop_back();
            num[A[i].back()]++;
        }
        int mx = max_element(num.begin(), num.end()) - num.begin();
        ans = min(ans, num[mx]);
        removed[mx] = 1;
        rem++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 896
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

int main(int argc, char const *argv[]) {
  double x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2 ;
  printf("%lf\n",sqrt(pow(x1-x2, 2) + pow(y1-y2, 2)));

  return 0;
}

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

using namespace std;

int main(){
  int N;cin >> N;
  double p[N];
  double dp[N + 1][N];
  for(int i = 0;i < N;i++){
    cin >> p[i];
    
  }
  for(int i = 0;i <= N;i++)
    for(int j = 0;j < N;j++) 
      dp[i][j] = 0;
  dp[0][0] = 1 - p[0];
  dp[1][0] = p[0];
  for(int i = 1;i < N;i++){
    dp[0][i] = (1 - p[i])*dp[0][i - 1];
    for(int j = 1;j <= i + 1;j++){
      dp[j][i] = p[i]*dp[j - 1][i - 1] + (1 - p[i])*dp[j][i - 1];
    }
  }

  double answer = 0;
  for(int i = N/2 + 1;i <= N;i++){
    answer += dp[i][N - 1];
  }
  cout << setprecision(10);
  cout << answer;
}

Measured memory_bytes: 70528
package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	tmp, _ := reader.ReadString('\n')
	tmp = strings.Trim(tmp, "\n")

	if tmp[2] != tmp[3] {
		fmt.Println("No")
		return
	}

	if tmp[4] != tmp[5] {
		fmt.Println("No")
		return
	}

	fmt.Println("Yes")

	return
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
#ifndef err
#define err(...)(void)0
#endif
using namespace std;
using ll = long long;
using ull = decltype(1ull);
template<class T>int size(T&&a) { return a.size(); }
#define REP(t,a)for(typename make_signed<decltype(a.second)>::type t=a.first,_l##t=a.second;t<_l##t;t++)
#define RREP(t,a)for(typename make_signed<decltype(a.second)>::type t=a.second-1,_l##t=a.first;t>=_l##t;t--)
template<class B>pair<int, B>make_pair(B b) { return{ 0,b }; }
#define rep(t,...)REP(t,make_pair(__VA_ARGS__))
#define rrep(t,...)RREP(t,make_pair(__VA_ARGS__))
#define all(a)begin(a),end(a)
#define rall(a)a.rbegin(),a.rend()
#define var(t, ...) t __VA_ARGS__;in,__VA_ARGS__;

void Calc();
int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);
  cin.exceptions(istream::failbit | istream::badbit);
  cout << fixed << setprecision(15); Calc(); cout.flush(); return 0;
}
template<class A>void amax(A&a, A b) { a = max(a, b); }
template<class A>void amin(A&a, A b) { a = min(a, b); }
template<class A>int comp(A a, A b) { return a < b ? 1 : b < a ? -1 : 0; }
struct Scanner {
  template<class A = string>A Next() { A a; cin >> a; return a; }
  template<class A = int>vector<A>Array(int n) { vector<A>a(n); for (A&i : a) cin >> i; return a; }
  string Line() const { string s; getline(cin, s); return s; }
  template<class A>Scanner&operator,(A&a) { a = Next<A>(); return *this; }
  template<class A>operator A() { return Next<A>(); }
}in;

/*---------------------------------------------------------------------*/


void Calc() {

  int n = in;
  auto  d = in.Array(n);
  int m = in;
  auto t = in.Array(m);

  map<int, int> a, b;
  for (auto& i : d) {
    a[i]++;
  }
  for (auto& i : t) {
    b[i]++;
  }
  for (auto& i : b) {
    if (a[i.first] < i.second) {
      cout << ("NO") << endl;
      return;
    }
  }
  cout << ("YES") << endl;
}


Measured memory_bytes: 20608
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    int x, t;
    cin >> x >> t;
    if(t < x) {
        cout << x-t;
    }
    else {
        cout << 0;
    }
    
    cout << endl;
    return 0;
}

Measured memory_bytes: 892
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

typedef long long ll;

int n;

int main() {
	cin >> n;
	if (n % 10 == 9 || n / 10 == 9) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1000000007LL;
void  find_centroids(int v, int p, vector<vector<int>> &G, vector<int> &subtree_size, vector<int> &centroids) {
	int N = G.size();
	bool isCentroid = 1;
	for (int to : G[v]) {
		if (to == p) continue;
		find_centroids(to, v, G, subtree_size, centroids);
		if (subtree_size[to] > N / 2) isCentroid = 0;
	}
	if (N - subtree_size[v] > N / 2) isCentroid = 0;
	if (isCentroid) centroids.push_back(v);
}
void calc_subtree_size(int v, int p, vector<vector<int>> &G, vector<int> &subtree_size) {
	subtree_size[v] = 1;
	for (int to : G[v]) {
		if (to == p) continue;
		calc_subtree_size(to, v, G, subtree_size);
		subtree_size[v] += subtree_size[to];
	}
}
ll fact[5001];
ll inv_fact[5001];
ll mod_pow(ll a, ll b) {
	if (b == 0) return 1;
	if (b % 2 == 0) {
		ll x = mod_pow(a, b / 2);
		return (x*x) % MOD;
	}
	return (a*mod_pow(a, b - 1)) % MOD;
}
ll comb(ll n, ll k) {
	if (n < k) return 0;
	ll ret = fact[n];
	(ret *= inv_fact[k]) %= MOD;
	(ret *= inv_fact[n - k]) %= MOD;
	return ret;
}
ll dp[5001][5001];
int main() {
	int N;
	cin >> N;
	fact[0] = inv_fact[0] = 1;
	for (int i = 1; i <= N; i++) {
		fact[i] = (fact[i - 1] * i) % MOD;
		inv_fact[i] = (inv_fact[i - 1] * mod_pow(i, MOD - 2)) % MOD;
	}
	vector<vector<int>> G(N, vector<int>());
	vector<int> centroids;
	vector<int> subtree_size(N);
	for (int i = 0; i < N - 1; i++) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		G[x].push_back(y);
		G[y].push_back(x);
	}
	calc_subtree_size(0, -1, G, subtree_size);
	find_centroids(0, -1, G, subtree_size, centroids);
	if (centroids.size() == 2) {
		cout << (fact[N / 2] * fact[N / 2]) % MOD << endl;
		return 0;
	}
	int c = centroids[0];
	calc_subtree_size(c, -1, G, subtree_size);
	vector<int> T;
	for (int to : G[c]) T.push_back(subtree_size[to]);
	dp[0][0] = 1;
	for (int i = 1; i <= T.size(); i++) {
		for (int j = 0; j <= N; j++) {
			for (int k = 0; k <= T[i - 1]; k++) {
				if (j + k > N) break;
				ll add = dp[i - 1][j];
				ll t = comb(T[i - 1], k);
				t = (t*t) % MOD;
				(add *= t) %= MOD;
				(add *= fact[k]) %= MOD;
				(dp[i][j + k] += add) %= MOD;
			}
		}
	}
	ll ans = 0;
	ll k = 1;
	for (int i = 0; i <= N - 1; i++) {
		ll add = fact[N - i];
		(add *= dp[T.size()][i]) %= MOD;
		(add *= k) %= MOD;
		(ans += add) %= MOD;
		(k *= MOD - 1) %= MOD;
	}
	cout << ans << endl;
}


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

using namespace std;

typedef struct node {
	int v;
	bool root;
}node;

node set[100001];
int candidate[100001];

int find(int x) {
	if (set[x].root) return x;
	else {
		set[x].v = find(set[x].v);
		return set[x].v;
	}
}


void combine(int x, int y) {
	x = find(x);
	y = find(y);
	if (x != y) {
		set[x].v += set[y].v;
		set[y].v = x;
		set[y].root = false;
	}
}

int main() {
	int n, m, k;
	cin >> n >> m >> k;
	for (int i = 1; i <= n; i++) {
		set[i].v = 1;
		set[i].root = true;
	}
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		candidate[a]--;
		candidate[b]--;
		combine(a, b);
	}
	for (int i = 1; i <= n; i++) {
		candidate[i] += set[find(i)].v -1;
	}
	for (int i = 0; i < k; i++) {
		int a, b;
		cin >> a >> b;
		if (find(a) == find(b)) {
			candidate[a]--;
			candidate[b]--;
		}
	}
	for (int i = 1; i <= n; i++) {
		cout << candidate[i] << ' ';
	}
	
}


Measured memory_bytes: 2560
K = int(input())
import math
def gcd(a,b,c):
    return math.gcd(a,math.gcd(b,c))
s = 0
for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(b+1,K+1):
            s = s + gcd(a,b,c)
t = 0
for a in range(1,K+1):
    for b in range(1,K+1):
        t = t + math.gcd(a,b)
print(s*2+t)



Measured memory_bytes: 9224
#include<stdio.h>
#include<stdlib.h>
#define LARGE 10000
#define INF 100000000
#define MIN(a,b) ((a) < (b) ? (a):(b))

int V,E;

typedef struct node{
	int id;
	int cost;
}node;

typedef struct list{
	int id;
	int cost;
	struct list *next;
}list;

void swap(node h[],int x,int y){
	node temp=h[x];
	h[x]=h[y];
	h[y]=temp;
	return;
}


void heapsort(node heap[],int num){

	for(int i=num-1;i>0;i--){
		if(i%2==0){
			if(heap[i].cost < heap[i/2-1].cost)swap(heap,i,i/2-1);
		}else {
			if(heap[i].cost < heap[i/2].cost)swap(heap,i,i/2);
		}
	}
	
	return;

}

int update_heap(node heap[],int num,list *L[]){
	int u=heap[0].id;
	list *p=L[u];
	
	swap(heap,0,num-1);
	num--;
	
	
	while(p!=NULL){
		for(int i=0;i<num;i++){
			if(heap[i].id==p->id){
				heap[i].cost=MIN(heap[i].cost,p->cost);
			}
		}
		p=p->next;
	}
	
	
	return num;
}

list * makelist(int x,int d){
	list *new=malloc(sizeof(list));
	new->id=x;
	new->cost=d;
	new->next=NULL;
	return new;
}

void list_insert(list* L[],int x,list *new){
	list **p=&L[x];
	
	while((*p)!=NULL){
		p=&((*p)->next);
	}
	(*p)=new;
	
	return;
}


int main(){
	int i,j;
	int s,t,d;
	int num;
	int ans=0;
	node heap[LARGE];
	list *L[LARGE];
	list *new;
	
	scanf("%d %d",&V,&E);
	num=V;
	
	for(i=0;i<V;i++){
		L[i]=NULL;
		heap[i].cost=INF;
		heap[i].id=i;
	}
	
	for(i=0;i<E;i++){
		scanf("%d %d %d",&s,&t,&d);
		if(s==0)heap[t].cost=d;
		if(t==0)heap[s].cost=d;
		new=makelist(t,d);
		list_insert(L,s,new);
		new=makelist(s,d);
		list_insert(L,t,new);
	}

	heap[0].cost=0;

	heapsort(heap,num);
	
	while(num!=0){
		ans+=heap[0].cost;
		num=update_heap(heap,num,L);
		heapsort(heap,num);
	}
	
	printf("%d\n",ans);
	
	return 0;
	
}


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

using namespace std;

typedef long long ll;

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, a, b;
    cin >> n >> a >> b;
    vector<int> p(n);
    if (a + b - 1 > n) {
        cout << -1;
        return  0;
    }
    deque<int> q;
    for (int i = 1; i <= a; ++i) {
        q.push_back(i);
    }
    if (b > 1) {
        int z = (n - a) / (b - 1);
        if (z == 0) {
            cout << -1;
            return 0;
        }
        vector<int> kek(b - 1, z);
        for (int i = 0; i < (n - a) % (b - 1); ++i) {
            ++kek[i];
            if (kek[i] > a) {
                cout << -1;
                return 0;
            }
        }
        int cur = a + 1;
        for (int i : kek) {
            for (int j = cur + i - 1; j >= cur; --j) {
                q.push_front(j);
            }
            cur += i;
        }
    } else {
        if (a == n) {
            for (int i : q) {
                cout << i << ' ';
            }
        } else {
            cout << -1;
        }
        return 0;
    }
    for (int i : q) {
        cout << i << ' ';
    }
    return 0;
}

Measured memory_bytes: 4660
#include <stdio.h>

int main(void) {
	int x, y, dummy, i;
	
	i = 0;
	while(i < 3000) {
	    scanf("%d%d", &x, &y);
	    //yのほうが小さければ交換する
	    if(x > y) {
	        dummy = x;
	        x = y;
	        y = dummy;
	    }
	    //どちらも0だったら終了する
	    if((x == 0) && (y == 0)) {
	        break;
	    }
	    printf("%d %d\n", x, y);
	}
	
	return 0;
}


Measured memory_bytes: 2048
import java.util.Scanner;
 
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int X =sc.nextInt();
        int A =sc.nextInt();
        int B =sc.nextInt();
        
        int nokori = X - A;
        System.out.println(nokori % B);
    }
}

Measured memory_bytes: 21972
#include <stdio.h>

int main(void){
    
    int a,b,i,m;
    
    
    
    while(1){
        scanf("%d %d",&a,&b);
        if(a==0&&b==0){
            break;
        }
        for(i=1;i<=a;i++){
            for(m=1;m<=b;m++){
                if(i>1&&i<a&&m>1&&m<b){
                    printf(".");
                }else printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }
    
    return 0;
}


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

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=s;i<n;i++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
ll a, b;
ll f(ll x){
    return (a*x)/b - a*(x/b);
}
int main()
{
    ll n;
    cin >> a >> b >> n;
    if(n >= b-1)cout << f(b-1) << endl;
    else cout << f(n) << endl;
    return 0;
}

Measured memory_bytes: 3596
s = input()
n = 0
ans = 0
for n in range( 1 << len(s) -1):
    p = 0
    for i in range(len(s) - 1):
        if n & (1 << i):
            ans += int(s[p:i + 1])
            p = i + 1
    if p < len(s):
        ans += int(s[p:])
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep2(i, a, b) for(int i = (a); i < (b); i++)

int main() {
  int n, l;
  cin >> n >> l;
  int ansi = 1;

  rep2(i, 1, n) {
    if (abs(1 - (l + i)) > abs(1 - (l + (i + 1)))) {
      ansi = i + 1;
    }
  }
  cout << (n * n - n) / 2 + n * l - l - ansi + 1 << endl;
}


Measured memory_bytes: 256
#include <iostream>

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

int main()
{
  int x, a, b;
  cin >> x >> a >> b;
  if(a >= b) {
    cout << "delicious" << endl;
  }else if(x >= b - a){
    cout << "safe" << endl;
  }else{
    cout << "dangerous" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
typedef long long LL;
LL SUM,sum[200050],n,a[200050];
map<LL,bool>vis;
map<LL,int>dis;
int main(){
	SUM=0;
	dis.clear();
	vis.clear();
	memset(sum,0,sizeof(sum));
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		sum[i]=sum[i-1]+a[i];
		if(vis[sum[i]]==0){
			vis[sum[i]]=1;
			dis[sum[i]]++;
		}
		else dis[sum[i]]++;
	}
	for(int i=n;i>=1;i--){
		if(sum[i]==0) SUM++;
		if(vis[sum[i]]==1&&dis[sum[i]]>1){
			SUM+=(dis[sum[i]]-1);
			dis[sum[i]]--;
		}
	}
	printf("%lld\n",SUM);
}

Measured memory_bytes: 28416
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll h,w;
  cin >> h >> w;
  mat a(h,vec(w)),b(h,vec(w));
  for(ll i=0;i<h;i++) {
    for(ll j=0;j<w;j++) {
      cin >> a[i][j];
    }
  }
  for(ll i=0;i<h;i++) {
    for(ll j=0;j<w;j++) {
      cin >> b[i][j];
    }
  }
  vector<mat> dp(h+1,mat(w+1,vec(12810)));
  dp[0][1][0]=dp[1][0][0]=1;
  for(ll i=1;i<=h;i++) {
    for(ll j=1;j<=w;j++) {
      for(ll k=0;k<=12800;k++) {
        ll v=abs(a[i-1][j-1]-b[i-1][j-1]);
        if(k+v<=12800) {
          dp[i][j][k+v]=(dp[i][j][k+v]||dp[i-1][j][k]||dp[i][j-1][k]);
        }
        v=abs(k-v);
        dp[i][j][v]=(dp[i][j][v]||dp[i-1][j][k]||dp[i][j-1][k]);
      }
    }
  }
  ll ans=inf;
  for(ll i=0;i<=12800;i++) {
    if(dp[h][w][i]) {
      if(abs(i)<ans) {
        ans=abs(i);
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 668524
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

    public static void main(String[] args) throws IOException {

        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }
        String arr01[] = mylist.get(0).split(" ");

        String s = arr01[0];

        //        System.out.println(s);

        Boolean chkflg = true;

        for (int i = 0; i < s.length(); i++) {
            String stemp = s.substring(i, i + 1);
            //            System.out.println(stemp);
            if (i % 2 != 0) {

                if (stemp.equals("R")) {
                    chkflg = false;
                    break;
                }

            } else {

                if (stemp.equals("L")) {
                    chkflg = false;
                    break;
                }

            }

        }

        System.out.println(chkflg ? "Yes" : "No");

    }

}

Measured memory_bytes: 21332
a, b, c = map(int, input().split())
if a <= b <= c:
    print(a, b, c)
elif a <= c <= b:
    print(a, c, b)
elif b <= a <= c:
    print(b, a, c)
elif b <= c <= a:
    print(b, c, a)
elif c <= a <= b:
    print(c, a, b)
elif c <= b <= a:
    print(c, b, a)


Measured memory_bytes: 5596
N, T = [int(x) for x in input().split()]

list = []
for i in range(0, N):
    c, t = [int(x) for x in input().split()]
    list.append((c, t))

filteredList = [x for x in list if x[1] <= T]

# print(filteredList)

if len(filteredList) >= 1:
    res = min(filteredList, key=lambda x: x[0])
    print(res[0])
else:
    print("TLE")


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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define DBG(...)                \
  exit(0); \
  cerr << #__VA_ARGS__ << ": "; \
  debug(__VA_ARGS__);           \
  cerr << " (L" << __LINE__ << ")" << endl
#else
#define DBG(...)
#endif

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, n) for (auto i : (n))
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)

using namespace std;

int main() {
  string S;
  cin >> S;
  DBG(S);
  cout << ((S.find("A") != string::npos) && (S.find("B") != string::npos) ? "Yes" : "No") << endl;
}


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

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	for (auto& x : a) {
		cin >> x;
	}

	int i = max_element(a.begin(), a.end()) - a.begin();
	int j = 0;

	for (int k = 0; k < n; ++k) {
		if (k == i) {
			continue;
		}
		int vj = min(a[j], a[i] - a[j]);
		int vk = min(a[k], a[i] - a[k]);
		if (vk >= vj) {
			j = k;
		}
	}
	cout << a[i] << " " << a[j] << endl;
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
#include<unordered_map>
#pragma warning(disable:4996)
using namespace std;

const int My_Inf=2147483647;
const long long int My_LInf=9223372036854775807;

vector<string>sts(10);

long long int powint(long long int a, long long int b) {
	assert(b >= 0);
	if (b == 0)return 1;
	if (b == 1)return a;
	long long int ans = 1;
	long long int aa = powint(a, b / 2);
	ans *= aa*aa;
	if (b % 2)ans *= a;
	return ans;
}

int main() {
	while (1) {
		string st; cin >> st;
		if (st == "#")break;
		vector<bool>ns;
		for (int i = 0; i < st.size(); ++i) {
			if (st[i] == 'n') {
				i += 4;
				ns.push_back(false);
			}
			else {
				i += 3;
				ns.push_back(true);
			}
		}
		
		if (ns.size() >= 3) {
			long long int ans = powint(2, ns.size() - 2);
			for (int i = 0; i <ns.size() - 2; ++i) {
				if (ns[i]) {
					ans += powint(2, i);
				}
				else {
					ans -= powint(2, i);
				}
			}
			long long int num = 45 * ans;
			cout << num << "/" << powint(2, ns.size() - 2) << endl;
		}
		else {
			if (st == "north")cout << 0 << endl;
			else if (st == "west")cout << 90 << endl;
			else cout << 45 << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    Int n; cin>>n;
    vector<Int> a(n,0);
    for(Int i=0; i<n; i++) cin>>a[i];
    Int q; cin>>q;
    for(Int i=0; i<q; i++){
        Int k; cin>>k;
        if(binary_search(a.begin(),a.end(),k)){
            cout<<1<<endl;
        }
        else{
            cout<<0<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3588
#include <stdio.h>

int main(void)
{
    int n;
    int a[100];
    int b[100];
    int c[100];
    int tensu=0;
    int i;

    scanf("%d", &n);

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

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

    for(i = 0; i < n-1; i++){
        scanf("%d", &c[i]);
    }

    for(i = 0; i < n; i++){
        tensu += b[a[i]-1];
        if(a[i+1] == a[i]+1){
            tensu += c[a[i]-1];
        }
    }

    printf("%d", tensu);


    return 0;
}

Measured memory_bytes: 128
//良問すぎん?

// グラフに奇数長の閉路を持たない　<=> 二部グラフ

#include<bits/stdc++.h>
using namespace std;

bool dfs(long long node, long long c, long long& cnt_0, long long& cnt_1, vector<long long>& used, vector<vector<long long> >& adj){

    used[node] = c;
    long long next_c = (c + 1) % 2;
    if(c == 0) cnt_0++;
    else cnt_1++;

    for(auto next_node : adj[node]){
        if(used[next_node] == next_c) continue;
        else if(used[next_node] == c) return false;
        else{
            if(!dfs(next_node, next_c, cnt_0, cnt_1, used, adj)) return false;
        }
    }

    return true;
}


int main(){
    
    // 入力受け取り
    long long V, E; cin >> V >> E;
    vector<vector<long long> > adj(V);

    for(long long i = 0; i < E; i++){
        long long a, b; cin >> a >> b;
        a--; b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }



    //二部グラフ判定パート
    vector<long long> used(V, -1);     //-1 := 見訪問  0:= 白  1 := 黒
    map<long long, long long> M;
    long long sum = 0;
    for(long long i = 0; i < V; i++){
        if(used[i] == -1){

            long long cnt_0 = 0;
            long long cnt_1 = 0;
            if(!dfs(i, 0, cnt_0, cnt_1, used, adj)){
                cout << -1 << endl;
                return 0;
            }

            //cout << i + 1 << " " << cnt_0 << " " << cnt_1 << endl;
            sum += (long long)abs(cnt_0 - cnt_1);
            M[(long long)abs(cnt_0 - cnt_1)]++;
        }
    }



    //個数制限付き部分和問題

    long long n = (long long)M.size();

    //dp[i][j] := i番目までのものを使って j を作る最大の a[i]の残る個数 (作れない場合は -1)
    vector<vector<long long> > dp(2, vector<long long> (sum + 1, -1LL));
    dp[0][0] = 0;
    int now_i = 0;
    int next_i = 1;
    for(auto x : M){
        for(long long j = 0; j <= sum; j++){

            if(dp[now_i][j] != -1) dp[next_i][j] = x.second;
            else{
                if(j - x.first >= 0) dp[next_i][j] = max(-1LL, dp[next_i][j - x.first] - 1LL);
            }
            //cout << "dp[" << i << "][" << j << "] = " << dp[i][j] << endl;
        }
        swap(now_i, next_i);
    }

    long long ans = sum;
    for(long long j = 0; j <= sum; j++){

        //cout << "dp[" << i - 1 << "][" << j << "] = " << dp[i - 1][j] << endl;         
        if(dp[now_i][j] != -1) ans = min(ans, (long long)abs(sum - 2 * j));
    }

    cout << (V * V - ans * ans) / 4 - E << endl;
    return 0;
}


Measured memory_bytes: 12632
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    struct Rectangle
    {
        internal int height, pos;
    }

    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            while (true)
            {

                int[] input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

                if (input.All(a => a == 0)) break;

                int H = input[0];
                int W = input[1];

                int[,] dp = new int[H, W + 1];

                for (int i = 0; i < H; i++)
                {
                    string line = Console.ReadLine();

                    for (int j = 0; j < W; j++)
                    {
                        if (line[j] == '*') dp[i, j] = 0;
                        else dp[i, j] = i > 0 ? dp[i - 1, j] + 1 : 1;
                    }
                }

                Stack<Rectangle> stk = new Stack<Rectangle>();
                int maxArea = 0;

                for (int i = 0; i < H; i++)
                {
                    for (int j = 0; j <= W; j++)
                    {
                        Rectangle rect;
                        rect.height = dp[i, j];
                        rect.pos = j;

                        if (stk.Count == 0)
                        {
                            stk.Push(rect);
                        }
                        else
                        {
                            if (stk.Peek().height < rect.height)
                            {
                                stk.Push(rect);
                            }
                            else if (stk.Peek().height > rect.height)
                            {
                                int target = j;

                                while (stk.Count > 0 && stk.Peek().height >= rect.height)
                                {
                                    Rectangle pre = stk.Pop();
                                    int area = pre.height * (j - pre.pos);
                                    maxArea = Math.Max(maxArea, area);
                                    target = pre.pos;
                                }
                                rect.pos = target;
                                stk.Push(rect);
                            }
                        }
                    }
                }
                sb.AppendLine(maxArea.ToString());
            }
            Console.Write(sb);
        }
    }
}

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

int main(){
  int64_t N; vector<int64_t> A(5);
  cin >> N;

  int64_t m =1e16; 
  for(int i=0; i<5; i++){
    cin >> A[i]; m = min(m, A[i]);
  }

  cout << 4 + (N+m-1)/m << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;

ll cnt[150],xcnt[150];
bool F(int x){
  ll kuri=0;
  for(int k=0;k<140;k++){
    ll a=kuri+cnt[k]+xcnt[k]*x;
    if(a%10!=0)return false;
    kuri=a/10;
  }
  return true;
}

int main(){
  string s;
  while(cin>>s){
    for(int k=0;k<150;k++)cnt[k]=0,xcnt[k]=0;
    string a,b,c;char pnt='a';
    for(int i=0;i<s.size();i++){
      if(pnt=='a')a.push_back(s[i]);
      if(pnt=='b')b.push_back(s[i]);
      if(pnt=='c')c.push_back(s[i]);
      if(s[i]=='+')pnt='b';
      if(s[i]=='=')pnt='c';
    }
    a=a.substr(0,a.size()-1);
    b=b.substr(0,b.size()-1);
    for(int i=0;i<a.size();i++){
      if(a[i]=='X')xcnt[a.size()-i-1]++;
      else cnt[a.size()-i-1]+=a[i]-'0';
    }
    for(int i=0;i<b.size();i++){
      if(b[i]=='X')xcnt[b.size()-i-1]++;
      else cnt[b.size()-i-1]+=b[i]-'0';
    }
    for(int i=0;i<c.size();i++){
      if(c[i]=='X')xcnt[c.size()-i-1]--;
      else cnt[c.size()-i-1]-=c[i]-'0';
    }
    bool na=true;
    for(int i=0;i<=9;i++){
      if(i==0){
	if(a.size()>1&&a[0]=='X')continue;
	if(b.size()>1&&b[0]=='X')continue;
	if(c.size()>1&&c[0]=='X')continue;
      }
      if(F(i)==true){
	cout<<i<<endl;
	na=false;
      }
    }
    if(na)cout<<"NA"<<endl;
  }
  return 0;
}

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

int main(){
int n;
long long X=0,x=0,ans=1000000000000000000LL;
cin>>n;
vector<long long> a(n);
for(int i=0;i<n;i++){
cin>>a[i];
X+=a[i];
}
for(int i=0;i<n;i++){
x+=a[i];
if(i+1<n)ans=min(ans,abs(X-2*x));
}
cout<<ans<<endl;
}

Measured memory_bytes: 1792
# -*- coding: utf-8 -*-
"""
Created on Mon Jun 13 15:52:31 2016

"""

def sosu(int_max):
    L = [True]*(int_max+1)
    L[0] = False
    L[1] = False
    for i in range(2, int((int_max)**0.5 + 1)):
        if L[i] == True:
            for j in range(2*i, int_max+1, i):
                L[j] = False
    return L            
                




S = sosu(1000000)
while True:
    cnt = 0
    a, d, n = map(int, input().split())
    if a == 0:
        break
    
    i = 0
    while cnt < n:
        arr = a + d * i
        if S[arr]:
            cnt += 1
        i += 1
        
    print(arr) 

Measured memory_bytes: 15064
A, B, K = map(int, input().split())

cnt = 0
for i in range(K):
    if cnt == 0:
        if A % 2 != 0:
            A -= 1
        give = int(A / 2)
        A -= give
        B += give
        cnt = 1
    elif cnt == 1:
        if B % 2 != 0:
            B -= 1
        give2 = int(B / 2)
        B -= give2
        A += give2
        cnt = 0

print(A, B)

Measured memory_bytes: 3316
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define REP(i, b, n) for (Int i = b; i < Int(n); i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using Int = long long;
Int inf = 1000000000000000001LL;
using vi = vector<Int>;
using vvi = vector<vi>;

Int GCD(Int a, Int b){
    if(b==0) return a;
    if(a < b) return GCD(b, a);
    unsigned r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

int main() {
    int N;
    vector<double> x;
    vector<string> v;
    double total_yen =0;
    double xx;
    string vv;
    cin >> N;
    rep(i,N){
        cin >> xx >> vv;
        x.push_back(xx);
        v.push_back(vv);
    }

    rep(i,N){
        if(v[i]=="BTC"){
            total_yen += 380000*x[i];
        }else{
            total_yen += x[i];
        }
    }

    cout << total_yen;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

int main(void){

    int num_box;
    int limit;
    int *num_C;

    scanf("%d %d",&num_box,&limit);

    num_C=(int *)malloc(sizeof(int)*num_box);

    for(int i=0;i<num_box;i++) scanf("%d",&num_C[i]);

    long long ans=0;

    if(num_C[0]>limit) {
        ans=num_C[0]-limit;
        num_C[0]=limit;
    }

    for(int i=1;i<num_box;i++){
        int sub_sum=num_C[i-1]+num_C[i];
        if(sub_sum>limit){
            ans+=sub_sum-limit;
            num_C[i]-=sub_sum-limit;
        }
    }

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

    return 0;
}


Measured memory_bytes: 2124
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c, d, e, k; cin >> a >> b >> c >> d >> e >> k;
    if(e-a > k) cout << ":(";
    else cout << "Yay!";
    cout << endl;
    return 0;
}




Measured memory_bytes: 256
#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() {
    vector<string> S(3);
    rep(i,3){
        cin >> S[i];
        S[i] += " ";
    }
    int j = 0;
    rep(i,301){
        if(S[j].at(0) == 'a'){
            S[j] = S[j].substr(1);
            j = 0;
        }
        if(S[j].at(0) == 'b'){
            S[j] = S[j].substr(1);
            j = 1;
        }
        if(S[j].at(0) == 'c'){
            S[j] = S[j].substr(1);
            j = 2;
        }
        if(S[j] == " "){
            if(j == 0) cout << 'A' << endl;
            else if(j == 1) cout << 'B' << endl;
            else cout << 'C' << endl;
            return 0;
        }
    }
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=105;
int a[N];
int main(){
	int n,m;
	scanf("%d %d",&n,&m);
	double sum=0;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		sum+=a[i];
	}
	double q=1.0/(4*m);
	sort(a+1,a+n+1);
	int cnt=0;
	for(int i=n;i>=1;i--){
		if(q*sum<=a[i]){
			cnt++;
		}
		else break;
	}
	if(cnt>=m) printf("Yes");
	else printf("No");
	return 0;
}

Measured memory_bytes: 256
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

#ifdef DEBUG
mt19937 mrand(300); 
#else
mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count()); 
#endif

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = (int) 1e5 + 5;
int n;
long long x[maxn];
int m;
long long k;
int a[maxn];

bool read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  for (int i = 0; i < n; i++) {
    scanf("%lld", &x[i]);
  }
  scanf("%d%lld", &m, &k);
  for (int i = 0; i < m; i++) {
    scanf("%d", &a[i]);
    a[i]--;
  }
  return true;
}

int d[maxn];
int p[maxn];
int used[maxn];

void solve() {
  for (int i = 0; i + 1 < n; i++) {
    d[i] = x[i + 1] - x[i];
  }
  n--;
  for (int i = 0; i < n; i++) {
    p[i] = i;
    used[i] = false;
  }
  for (int i = 0; i < m; i++) {
    swap(p[a[i] - 1], p[a[i]]);
  }
  for (int s = 0; s < n; s++) {
    if (used[s]) {
      continue;
    }
    vector<int> c;
    for (int x = s; !used[x]; x = p[x]) {
      c.push_back(x);
      used[x] = true;
    }
    int sh = k % sz(c);
    for (int i = 0; i < sz(c); i++) {
      int x = c[i], y = c[(i + sh) % sz(c)];
      p[x] = y;
    }
  }
  for (int i = 0; i < n; i++) {
    x[i + 1] = x[i] + d[p[i]];
  }
  for (int i = 0; i <= n; i++) {
    printf("%lld\n", x[i]);
  }
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 3696
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
    int n,m,k;cin >> n >> m >> k;
    int a[n],b[m];
    rep(i,n)cin >> a[i];
    rep(i,m)cin >> b[i];
    vector<int> sa(n+1),sb(m+1);
    rep(i,n)sa[i+1] = sa[i] + a[i];
    rep(i,m)sb[i+1] = sb[i] + b[i];
    int bot = 0;
    int top = 1001001001;
    auto ok = [&](int c){
        //cことる
        int res = 1001001001;
        rep(na,c+1){
            int ret = 0;
            int nb = c - na;
            if(nb < 0|| nb > m||na < 0 || na > n)continue;
            ret += sa[na];
            ret += sb[nb];
            //trace(c,na,nb,ret);
            res = min(res,ret);

        }
        //trace(res,c);
        return res <= k;



    };
    while(top - bot > 1){
        int mid = (top + bot)/2;
        if(ok(mid))bot = mid;
        else top = mid;
    }
    cout << bot << endl;
    return 0;
}

Measured memory_bytes: 9592
#include<stdio.h>

int main()
{
	int n ,h ,m ,s;  
	scanf("%d" , &n);
	h = n / 3600;
	m = (n - h * 3600)/60;
	s = n - h * 3600 - m * 60;
	printf("%d:%d:%d\n",h ,m ,s );	
		
	return 0;
 } 


Measured memory_bytes: 2712