akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
 
int main(void)
{
  char cards[1024];
  while (fgets(cards, sizeof(cards), stdin), *cards != '0') {
    int ones = 0;
    int score = 0;
    char *card = strtok(cards, " ");
    for (; card != NULL; card = strtok(NULL, " ")) {
      int num = atoi(card);
      if (num == 1) ones++;
      score += fmin(num, 10);
    }
    while (ones--) {
      if (score + 10 <= 21) score += 10;
    }
    if (score > 21) score = 0;
    printf("%d\n", score);
  } 
  return (0);
}

Measured memory_bytes: 532
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

int main() {
	long long A, B; double C;
	cin >> A >> C; B = (int)(100.0 * C + 0.5);
	cout << A * B / 100LL << endl;
	return 0;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
#define MAXN 330
#define pii pair<int, int>
#define pll pair<long long, pair<long long, long long>>
#define ff first
#define ss second
#define ll long long
#define in_range(x, y, n) (x >= 0 and x < n and y >= 0 and y < n)
using namespace std;
const int mod = 1e9 + 7;
const ll oo = 1e17 + 7;


int main()
{
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    cout << (n < 1200? "ABC" : "ARC") << endl; 
    return 0;
}

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

int main(){
    
    int n;
    cin >> n;
    vector<int>a(n);
    int total_sum = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        total_sum += a[i];
    }
    int res = total_sum;
    bool done = false;
    if(total_sum%10 == 0){
        sort(a.begin() , a.end());
        for(int i = 0; i < n; i++){
            if(a[i]%10 != 0){
                res -= a[i];
                done = true;
                break;
            }
        }
    }else{
        cout << res << endl;
        return 0;
    }
    if(done)
        cout << res << endl;
    else 
        cout << 0 << endl;
    
}


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

int main(){
    int N;
    cin >> N;
    int b1=0,b2;
    string yn = "Yes";
    rep(i,N){
        b1 = max(b1,b2);
        cin >> b2;
        if( b2 - b1 < -1 ) yn = "No";
    }
    cout << yn << endl;
    return 0;
}


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

int main(){
    int n;
    cin >> n;
    map<string,ll> m;
    rep(i,n){
        string s;
        cin >> s;
        sort(s.begin(),s.end());
        m[s]++;
    }
    ll ans = 0;
    for(auto p : m){
        if(p.second == 0) continue;
        ans += p.second*(p.second - 1) / 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 11396
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;

bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}


int main(){
  
  int a,b;
  cin>>a>>b;
  if(a<=0 && 0<=b){
    cout<<"Zero"<<endl;
    return 0;
  }
  if(a > 0){
    cout<<"Positive"<<endl;
  }else{
    int cnt = b - a + 1;
    if(cnt%2 == 0){
      cout<<"Positive"<<endl;
    }else{
      cout<<"Negative"<<endl;
    }
  }
  return 0; 
}


Measured memory_bytes: 256
n = int(input())
lst = list(map(int, input().split()))
lst.sort()
count = []

i = 0
while i<n-1:
    if lst[i]==lst[i+1]:
        count.append(lst[i])
        i+=2
    else:
        i+=1

count.sort(reverse=True)
count.append(0)
count.append(0)

print(count[0]*count[1])


Measured memory_bytes: 14252
#include<stdio.h>
int main()
{
    int a[4],i,count=0,count1=0;
    for(i=0; i<3; i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=0; i<3; i++)
    {
        if(a[i]==5)
            count++;
    }
    for(i=0; i<3; i++)
    {
        if(a[i]==7)
            count1++;
    }
    if(count==2 && count1==1)
    {
        printf("YES\n");
    }
    else{
        printf("NO\n");
    }
    return 0;
}


Measured memory_bytes: 128
#差がC以下はダメ（Cもダメ）
N,K,C=map(int,input().split())
S=input()
X=[]
for i in range(N):
    if S[i]=="o":
        X.append(i+1)
M=len(X)
#例外処理（M=1のとき）
if M==1:
    #このときK==1
    print(X[0])
    exit()

#X[i]日に働くとき、その直前or直後で働ける最も近い日のindex
L=[-1 for i in range(M)]
R=[-1 for i in range(M)]
j=1
for i in range(M-1):
    while(j<M):
        if X[j]-X[i]>=C+1:
            R[i]=j
            break
        else:
            j+=1
j=M-2
for i in range(M-1,0,-1):
    while(j>=0):
        if X[i]-X[j]>=C+1:
            L[i]=j
            break
        else:
            j-=1
LD=[-1 for i in range(M)]
RD=[-1 for i in range(M)]
def Ldfs(i):
    if LD[i]!=-1:
        return LD[i]
    if L[i]==-1:
        LD[i]=1
        return 1
    else:
        LD[i]=Ldfs(L[i])+1
        return Ldfs(L[i])+1
def Rdfs(i):
    if RD[i]!=-1:
        return RD[i]
    if R[i]==-1:
        RD[i]=1
        return 1
    else:
        RD[i]=Rdfs(R[i])+1
        return Rdfs(R[i])+1
for i in range(M):
    Ldfs(i)
    Rdfs(M-1-i)
Y=[0 for i in range(M)]
Y[0]=RD[1]
Y[-1]=LD[-2]
for i in range(1,M-1):
    Y[i]=LD[i-1]+RD[i+1]
for i in range(M):
    if Y[i]<K:
        print(X[i])


Measured memory_bytes: 67320
/* 
    Author : Jeff Ahn
    Sun 14 Jun 2020 01:37:23 PM PDT 
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,r) for(int i = 0; i < (r); i++)
#define pb push_back
#define ALL(a) a.begin(), a.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long
#define uint unsigned long long
#define endl '\n'
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const map<T,T> &vec){ os<< "{"; for (auto p : vec) os << "(" << p.first << "," << p.second << "), "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_map<T,T>&vec){ os<< "{"; for (auto p : vec) os << "(" << p.first << "," << p.second << "), "; os << "}"; return os; }

int p[110];
signed main() {
  fastio;
  int x, n;
  cin >> x >> n;
  if (n == 0) { cout << x << endl; return 0; }
  rep(i, n) cin >> p[i];
  set<int> st;
  rep(j, n) {
      st.insert(p[j]);
  }
  set<int> stc;
  for (int i = 0; i <= 101; i++) {
    if (st.count(i)) continue;
    else stc.insert(i);
  }
  int res = 101, mini = 101;
  for (auto c : stc) {
    // cout << c << endl;
    if (abs(x - c) < mini) {
      mini = abs(x - c);
      res = c;
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 3660
#pypyは内包表記使わない
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007

    A, B, K = map(int, input().split())
    if (B-A+1)//2 >= K:
        for i in range(A, A+K):
            print(i)
        for i in range(B-K+1, B+1):
            print(i)
    else:
        for i in range(A, B+1):
            print(i)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
// #include <bits/stdc++.h>
#include <map>
#include <set>
#include <ctime>
#include <cstring>
#include <queue>
#include <iostream>
#include <algorithm>
using namespace std;
 
#define mod 1000000007
#define INF 1000000000
#define ll long long
#define dbl double
#define ull unsigned ll
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define vvvll vector<vector<vector<ll>>>
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define all(x) begin(x), end(x)
#define contains(a, x) (a.find(x) != end(a))
#define F(i,a,b) for(int i = (int)(a); i < (int)(b); ++i)
#define RF(i,a,b)for(int i = (int)(a); i >= (int)(b); --i)
#define fast() {ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
#define log(x) cout << (x) << endl;
 
 
 
int main() {
	fast();
 
	int n;
	cin >> n;
	vi a(n);
	map<int,int> freq;
	REP (i,n) cin>>a[i], freq[a[i]]++;

	ll r = 1;

	if (freq[0] > 1)
		r = 0;
	else
		for (int i=0,k=n-1; i<(n>>1); ++i, k-=2) {
			r = ((r%mod) * (freq[k]%mod))%mod;
		}

	cout << r << endl;
 
	return 0;
}



Measured memory_bytes: 4480
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>
#include<stack>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<string> vstring;
typedef vector<pint> vpint;
typedef stringstream SS;

template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }

#define rep(i,n) for(int i=0;i<(n);++i)
#define repn(i,m,n) for(int i=(m);i<(n);++i)
#define repd(i,n) for(int i=(n)-1;i>=0;--i)
#define repnd(i,m,n) for(int i=(n)-1;i>=(m);--i)
#define rep0(i,n) for(i=0;i<(n);++i)
#define repn0(i,m,n) for(i=(m);i<(n);++i)
#define repd0(i,n) for(i=(n)-1;i>=0;--i)
#define repnd0(i,m,n) for(i=(n)-1;i>=(m);--i)
#define repc(i,n) for(int i=0;i<=(n);++i)
#define repcn(i,m,n) for(int i=(m);i<=(n);++i)
#define repcd(i,n) for(int i=(n);i>=0;--i)
#define repcnd(i,m,n) for(int i=(n);i>=(m);--i)
#define repc0(i,n) for(i=0;i<=(n);++i)
#define repcn0(i,m,n) for(i=(m);i<=(n);++i)
#define repcd0(i,n) for(i=(n);i>=0;--i)
#define repcnd0(i,m,n) for(i=(n);i>=(m);--i)
#define all(n) n.begin(),n.end()
#define sz(n) ((int)(n).size())
#define IL for(;;)
#define MP make_pair
#define PB push_back
#define X second
#define Y first
#define p_queue(n) priority_queue<n,vector<n>,greater<n> >
#define PUTLINE cout<<"LINE:"<<__LINE__<<endl;

const int INF = 2147483647/3;
const double EPS = 1e-10;
const double PI = acos(-1.0);

const int dx[]={1,-1,0,0,1,1,-1,-1,0};
const int dy[]={0,0,1,-1,1,-1,1,-1,0};

int dp[111][111];
int tree[111][111];

int main() {
	int n, w, h, s, t, x, y;
	IL {
		cin >> n;
		if (n == 0) break;
		memset(dp, 0, sizeof(dp));
		memset(tree, 0, sizeof(tree));
		cin >> w >> h;
		rep (i, n) {
			cin >> x >> y;
			tree[y][x] = 1;
		}
		cin >> s >> t;
		repcn (i, 1, h) repcn (j, 1, w) {
			dp[i][j] = dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1] + tree[i][j];
		}
		int res = 0;
		rep (i, h - t + 1) rep (j, w - s + 1) {
			chmax(res, dp[i + t][j + s] - dp[i][j + s] - dp[i + t][j] + dp[i][j]);
		}
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int sum = 0;
		for (int i = 1; i <= K; i++) {
			for (int j = 1; j <= K; j++) {
				for (int k = 1; k <= K; k++) {
					int tmp;
					int i1 = i;
					int j1 = j;
					int k1 = k;
					while ((tmp = k1 % j1) != 0) {
						k1 = j1;
						j1 = tmp;
					}
					while ((tmp = j1 % i1) != 0) {
						j1 = i1;
						i1 = tmp;
					}
					sum += i1;
 
				}
			}
		}
		System.out.println(sum);
 
	}
 
}

Measured memory_bytes: 35588
#include<stdio.h>
int main(void){
	int dice1[5],dice2[5],dice3[5],dice4[5],dice5[5],dice6[5];
	int i,num,co=0,work,one,two,k,j;
	
	scanf("%d %d %d %d %d %d",&dice1[0],&dice2[0],&dice3[0],&dice4[0],&dice5[0],&dice6[0]);
	dice1[1]=dice5[0];
	dice1[2]=dice4[0];
	dice1[3]=dice2[0];
	dice1[4]=dice3[0];
	dice2[1]=dice1[0];
	dice2[2]=dice4[0];
	dice2[3]=dice6[0];
	dice2[4]=dice3[0];
	dice3[1]=dice1[0];
	dice3[2]=dice2[0];
	dice3[3]=dice6[0];
	dice3[4]=dice5[0];
	dice4[1]=dice1[0];
	dice4[2]=dice5[0];
	dice4[3]=dice6[0];
	dice4[4]=dice2[0];
	dice5[1]=dice1[0];
	dice5[2]=dice3[0];
	dice5[3]=dice6[0];
	dice5[4]=dice4[0];
	dice6[1]=dice2[0];
	dice6[2]=dice4[0];
	dice6[3]=dice5[0];
	dice6[4]=dice3[0];
	
	scanf("%d",&num);
	int ans[num];
	for(i=0;i<num;i++){
		scanf("%d %d",&one,&two);
		if(one==dice1[0]){
			for(j=0;j<4;j++){
				if(dice1[j+1]==two){
					ans[i]=dice1[(j+1)%4+1];
					break;
				}
			}
		}
		else if(one==dice2[0]){
			for(j=0;j<4;j++){
				if(dice2[j+1]==two){
					ans[i]=dice2[(j+1)%4+1];
					break;
				}
			}
		}
		else if(one==dice3[0]){
			for(j=0;j<4;j++){
				if(dice3[j+1]==two){
					ans[i]=dice3[(j+1)%4+1];
					break;
				}
			}
		}
		else if(one==dice4[0]){
			for(j=0;j<4;j++){
				if(dice4[j+1]==two){
					ans[i]=dice4[(j+1)%4+1];
					break;
				}
			}
		}
		else if(one==dice5[0]){
			for(j=0;j<4;j++){
				if(dice5[j+1]==two){
					ans[i]=dice5[(j+1)%4+1];
					break;
				}
			}
		}
		else if(one==dice6[0]){
			for(j=0;j<4;j++){
				if(dice6[j+1]==two){
					ans[i]=dice6[(j+1)%4+1];
					break;
				}
			}
		}
	}
	for(i=0;i<num;i++){
		printf("%d\n",ans[i]);
	}
	
	return 0;
}


Measured memory_bytes: 2032
import java.util.*;
public class Main
{
	public static void main(String[] args) 
	{
	    Scanner sc = new Scanner(System.in);
	    
	    long n = sc.nextLong();
	    long x = sc.nextLong();
	    if( (n*500) >= x)
		System.out.println("Yes");
		else
		System.out.println("No");
	}
}


Measured memory_bytes: 21844
n = int(input())
left = 1
right = n
ans_l = 1
while left <= right:
    left += 1
    right = n/left
    if n/left %1==0:
        right = int(n/left)
        ans_l = left
ans_r = n // ans_l
print(ans_l+ans_r-2)
    

Measured memory_bytes: 3064
f :: String -> String -> Bool
f s (x:y:[z]) = let
    a = dropCut (/=x) s
    b = dropCut (/=y) a
    c = dropWhile (/=z) b
    in c /= []
    where
        dropCut cond xs = let
            remains = dropWhile cond xs
            in if remains == [] then [] else tail remains

main = do
    let candidates = (\a b c -> [a, b, c]) <$> ['0'..'9'] <*> ['0'..'9'] <*> ['0'..'9']
    _ <- getLine
    s <- getLine

    print $ length $ filter (f s) candidates


Measured memory_bytes: 2428
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if ((A + B) == (C + D)) {
    cout << "Balanced" << endl;
  }
  else if ((A + B) < (C + D)) {
    cout << "Right" << endl;
  }
  else if ((A + B) > (C + D)) {
    cout << "Left" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <tuple>
 
using namespace std;
 
template<typename E>
using Matrix = std::vector<std::vector<E> >;
 
typedef long long LL;
typedef long double LD;
typedef std::pair<LL ,LL> LP;
 
#define INF		1e9
#define EPS		1e-9
#define gcd 	__gcd
#define make_matrix(rows, col, type, default) 			\
					std::vector< std::vector<type> >( 	\
						rows, 						  	\
						std::vector<type>(col, default) \
					);
 
#define repeat(n)	for(LL __x = 0; __x < n; __x++)
#define watch(x)	cout << (#x) << " is " << (x) << "\n";
#define DEG_TO_RAD(x) (x * PI / 180.0)
#define RAD_TO_DEG(x) (x * 180.0 / PI)
#define FILL_1(collection) for(LL __i = 0; std::cin>>collection[__i]; __i++);
#define FILL_2(collection, n) for(LL __i = 0; std::cin>>collection[__i/n][__i%n]; __i++);

template<typename T>
auto max_self(T &a, T b) -> void {
    a = max(a, b);
}

template<typename T>
auto min_self(T &a, T b) -> void {
    a = min(a, b);
}

auto main() -> int {
    LL n, max_w, max_sum = 0;

    std::cin >> n >> max_w;
    vector<LP> items;
    
    for(LL i = 0, a, b; i < n && std::cin>>a>>b; i++) {
        max_sum += b;
        items.push_back({a, b});
    }

    vector<LL> dp(max_sum + 1, INF);
    dp[0] = 0;
    
    for(LL itm = 0; itm < n; itm++) { //  item
        for(LL v = max_sum - items[itm].second; v >= 0; v--) { // value
            min_self(dp[v+items[itm].second], dp[v] + items[itm].first);
        }
    }
    
    LL ans = 0;
    for(; max_sum >= 0; max_sum--)
        if(dp[max_sum] <= max_w) max_self(ans, (LL)max_sum);
    std::cout << ans;
    
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(ll x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class T>bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

// 隣接リスト
vvll g(200010, vll());
vi visited(200010, 0);

vll cnt(200010, 0);
vll ans(200010, 0);

// グラフに対する深さ優先探索
void dfs(ll node, ll score){
    visited[node] = 1;
    ans[node] = score;
    rep(i, SZ(g[node])){
        if(!visited[g[node][i]]){
            dfs(g[node][i], score+cnt[g[node][i]]);
        }
    }
}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n, q;
    cin >> n >> q;
    vll a(n-1), b(n-1);
    rep(i, n-1){
        cin >> a[i] >> b[i];
        g[a[i]].emplace_back(b[i]);
        g[b[i]].emplace_back(a[i]);
    }
    vll p(q), x(q);
    rep(i, q){
        cin >> p[i] >> x[i];
        cnt[p[i]] += x[i];
    }
    dfs(1, cnt[1]);
    repr(i, 1, n+1){
        cout << ans[i] << (i==n ? "\n" : " ");
    }
    return 0;
}

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

using namespace std;

typedef long long ll;

const ll mod = 1e9 + 7;

ll n;
vector<int> g[200005];
ll ans;

ll p(ll a, ll x)
{
    ll res = 1;

    while (x > 0)
    {

        if (x & 1)
        {
            res = a * res % mod;
        }

        a = a * a % mod;
        x >>= 1;
    }
    return res;
}

ll dfs(int v, int prev = -1)
{
    //cout << "iji" << endl;
    ll s = 1;
    vector<ll> t;

    for (int i = 0; i < g[v].size(); i++)
    {
        int u = g[v][i];
        if (u == prev)
        {
            continue;
        }

        ll tmp = dfs(u, v);
        t.push_back(tmp);
        s += tmp;
    }

    t.push_back(n - s);

    if (t.size() == 1)
        return s;

    ll res = (p(2, n - 1) - 1) % mod;

    for (int i = 0; i < t.size(); i++)
    {
        res = (res - p(2, t[i]) + 1 + mod) % mod;
    }
    ans = (ans + res) % mod;
    //cout << "v = " << v << "  ans = " << ans << endl;
    return s;
}

int main()
{
    cin >> n;

    for (int i = 0; i < n - 1; i++)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    dfs(0);

    cout << ans * p(p(2, n), mod - 2) % mod << endl;
}


Measured memory_bytes: 27008
#include<iostream>
#include<cstdio>
using namespace std;
int N,K;
int A[100],B[100];
int dp[110][4][4][4];
int mod=10000;
int main()
{
	scanf("%d%d",&N,&K);
	for(int i=0;i<K;i++){
		scanf("%d%d",&A[i],&B[i]);A[i]--;B[i]--;
	}
	
	for(int i=0;i<K;i++){
		for(int j=i+1;j<K;j++){
			if(A[i]>A[j]){
				swap(A[i],A[j]);swap(B[i],B[j]);
			}
		}
	}
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
			for(int k=0;k<3;k++){
				//dp[3][i][j][k]
				if(A[0]==0&&i!=B[0])continue;
				if(A[0]==1&&j!=B[0])continue;
				if(A[1]==1&&j!=B[1])continue;
				if(A[0]==2&&k!=B[0])continue;
				if(A[1]==2&&k!=B[1])continue;
				if(A[2]==2&&k!=B[2])continue;
				if(i==j&&i==k)continue;
				//printf("%d %d %d\n",i,j,k);
				dp[2][i][j][k]++;
			}
		}
	}
	for(int i=3;i<N;i++){
		int X=-1;
		for(int j=0;j<K;j++){
			if(A[j]==i)X=B[j];
		}
		for(int j=0;j<3;j++){
			for(int k=0;k<3;k++){
				for(int l=0;l<3;l++){
					if(j==k&&j==l)continue;
					if(X!=-1&&l!=X)continue;
					dp[i][j][k][l]+=dp[i-1][0][j][k];
					dp[i][j][k][l]+=dp[i-1][1][j][k];
					dp[i][j][k][l]+=dp[i-1][2][j][k];
					dp[i][j][k][l]%=mod;
				}
			}
		}
	}
	int ans=0;
	for(int i=0;i<27;i++)ans+=dp[N-1][i/9][(i/3)%3][i%3];
	printf("%d\n",ans%mod);
	return 0;
}

Measured memory_bytes: 1216
#heapq p,qの最小値側にrの最大値入れていく。
import heapq 

#初期入力
X,Y,A,B,C = (int(x) for x in input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))


# ソート⇒無色と比較
p.sort()
q.sort()
r.sort(reverse=True)

ans_sum =sum(p[-X:]) + sum(q[-Y:])
p_hq = p[-X:]
q_hq = q[-Y:]
heapq.heapify(p_hq)
heapq.heapify(q_hq)
p_change =heapq.heappop(p_hq)
q_change =heapq.heappop(q_hq)
count_p =0
count_q =0
for i in r: #rは大きい順
    if p_change <= q_change and p_change < i:
        if  count_p < X:
            heapq.heappush(p_hq,i)
            count_p +=1
            ans_sum = ans_sum -p_change +i
            p_change =heapq.heappop(p_hq)
    elif p_change > q_change and q_change < i:
        if  count_q < Y:
            heapq.heappush(q_hq,i)
            count_q +=1
            ans_sum = ans_sum -q_change +i
            q_change =heapq.heappop(q_hq)
print(ans_sum)

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

int64_t factmod(int64_t n, int64_t m){
	int64_t r = 1;
	for(int64_t i = 1; i <= n; i++) (r *= i) %= m;
	return r;
}

int main(){
	int64_t n, m;
	cin >> n >> m;
	if(2 <= abs(n - m)){
		cout << 0 << endl;
		return 0;
	}
	cout << factmod(n, 1e9 + 7) * factmod(m, 1e9 + 7) * (n == m ? 2 : 1) % int64_t(1e9 + 7) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define Fr(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=0;i++<n;)

int main(){
  int h,w,c;
  cin>>h>>w;
  char s[55][55];
  Fr(i,h+2) Fr(j,w+2) s[i][j]='.';
  fr(i,h) fr(j,w) cin>>s[i][j];
  fr(i,h){
    fr(j,w){
      if(s[i][j]=='#') cout<<'#';
      else{
        c=0;
        Fr(x,3) Fr(y,3) if(s[i+x-1][j+y-1]=='#') c++;
        cout<<c;
      }
    }
    cout<<endl;
  }
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($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)*}
    };
}

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, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

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

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

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

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (let _ = write!(out,$($format)*););
    }
    input! {
        n: usize,
        a: [i64; n],
    }
    let mut a = a;
    a.sort();
    a.reverse();
    let x = a[0];
    let mut mi = (1i64 << 50, 0);
    for i in 1..n {
        mi = min(mi, ((x - a[i] * 2).abs(), a[i]));
    }
    puts!("{} {}\n", x, mi.1);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


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

int main() {
    int n,ans=0;
    string s;
    cin>>n>>s;

    rep(i,n-1) {
        if (s[i] != s[i+1]) ans++;
    }
    ans++;
    cout<<ans<<endl;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>

using namespace std;

bool table[5001][5001];

struct Point{
	int x,y;
};

bool rangeCheck(int x,int y){
	if(x >= 0 && x <= 5000 && y >= 0 && y <= 5000)return true;
	else{
		return false;
	}
}

void func(int N){
	Point point[N];

	for(int i = 0; i < N; i++){
		scanf("%d %d",&point[i].x,&point[i].y);
		table[point[i].x][point[i].y] = true;
	}

	int dx,dy;

	double max_r = 0,tmp;

	for(int i = 0; i < N-1; i++){
		for(int k = i+1; k < N; k++){
			dx = point[i].x - point[k].x;
			dy = point[i].y - point[k].y;

			//i-k???????????¨?????????
			if(rangeCheck(point[k].x-dy,point[k].y + dx) == true && table[point[k].x-dy][point[k].y + dx] == true &&
				rangeCheck(point[i].x-dy,point[i].y + dx) == true &&  table[point[i].x-dy][point[i].y + dx] == true){
				tmp = (double)sqrt(dx*dx+dy*dy);
				max_r = max(max_r,tmp);
			}

			//i-k???????????¨?????????
			if(rangeCheck(point[k].x+dy,point[k].y - dx) == true && table[point[k].x+dy][point[k].y - dx] == true &&
				rangeCheck(point[i].x+dy,point[i].y - dx) == true &&  table[point[i].x+dy][point[i].y - dx] == true){
				tmp = (double)sqrt(dx*dx+dy*dy);
				max_r = max(max_r,tmp);
			}
		}
	}

	printf("%.0lf\n",max_r*max_r);

}


int main(){

	int N;

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		for(int i = 0; i <= 5000; i++){
			for(int k = 0; k <= 5000; k++)table[i][k] = false;
		}

		func(N);

	}

	return 0;
}

Measured memory_bytes: 27052
from collections import deque

n, q = map(int, input().split( ))
Edg=[[] for i in range(n+1)]
Done = [0 for _ in range(n+1)]

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


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


for i in range(q):
    p, x = map(int, input().split( ))
    Pls[p]+=x

root=1

Task=deque()

Task.append(root)

while len(Task)>0:
    p_=Task.popleft()
    tmp = Pls[p_]
    Ans[p_]+=tmp
    Done[p_] = 1
    for child in Edg[p_]:
        if not Done[child]:
            Task.append(child)
            Pls[child]+=tmp


print(*Ans[1:])



Measured memory_bytes: 109132
N, *P = map(int, open(0).read().split())
c = 0
for i in range(N-2):
    p1 = P[i]
    p2 = P[i+1]
    p3 = P[i+2]
    if p1 < p2 < p3 or p3 < p2 < p1:
        c += 1

print(c)

Measured memory_bytes: 2940
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<ull> ulvec;
typedef vector<double> dvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<tuple<ll,ll,ll>> tvec;
typedef vector<string> svec;

int main(){
    string s;
    cin>>s;
    int n=s.size();
    int k=0;
    bool ok=true;
    while(k<n){
        if(k>n-5){
            ok=false;
            break;
        }
        if(s[k]=='d'){
            if(s[k+1]=='r'&&s[k+2]=='e'&&s[k+3]=='a'&&s[k+4]=='m'){
                if(k==n-5) break;
                if(k<=n-7&&s[k+5]=='e'&&s[k+6]=='r'){
                    if(k<=n-8&&s[k+7]=='a'){
                        k+=5;
                    }else{
                        k+=7;
                    }
                }else{
                    k+=5;
                }
            }else{
                ok=false;
                break;
            }
        }else if(s[k]=='e'){
            if(s[k+1]=='r'&&s[k+2]=='a'&&s[k+3]=='s'&&s[k+4]=='e'){
                if(k==n-5) break;
                if(k<=n-6&&s[k+5]=='r'){
                    if(k<=n-7&&s[k+6]=='a'){
                        k+=4;
                    }else{
                        k+=6;
                    }
                }else{
                    k+=5;
                }
            }else{
                ok=false;
                break;
            }
        }else{
            ok=false;
            break;
        }
    }
    if(ok) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
using P = pair<int,int>;
const int MOD = 1000000007;

int main() {
    vector<int> a(3);
    rep(i,3) cin>>a[i];
    sort(a.begin(),a.end());
    if (a[0]+a[1]==a[2]) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
//Himanshu Shukla
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
//#define file_input
//#define multitest
//#define measure_time
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define graph vector<v32>
#define p32 pair<int, int>
#define p64 pair<ll, ll>
#define sz(v) (ll)(v).size()
#define fi first
#define se second
#define ln '\n'
#define debug(x) cerr << (#x) << ": " << (x) << ln
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }
const double EPS = 1e-6;
const ll MOD = 1e9 + 7;
template <typename T, typename U>
ostream &operator<<(ostream &out, const pair<T, U> &p)
{
	out << '[' << p.fi << ", " << p.se << ']';
	return out;
}
template <template <typename, typename...> class ContainerType, typename ValueType, typename... Args>
void print_container(const ContainerType<ValueType, Args...> &c)
{
	cout << "{ ";
	for (const auto &v : c)
		cout << v << ' ';
	cout << '}' << ln;
}

void solve()
{
	ll h, a;
	cin >> h >> a;
	ll ans = ceil(h * 1.0 / a);
	cout << ans << ln;
	return;
}

int main()
{
	FASTIO;
#ifdef file_input
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	clock_t start, stop;
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
#ifdef measure_time
	start = clock();
#endif
	for (int tc = 1; tc < t + 1; tc++)
		solve();
#ifdef measure_time
	stop = clock();
	cerr << "Time :" << fixed << setprecision(5) << double(stop - start) / double(CLOCKS_PER_SEC) << "s" << ln;
#endif
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
constexpr int MOD = 1000000007;
constexpr int INF = 1e18;

using namespace std;

int N, M;
vector<vector<pair<int, int>>> graph;
vector<bool> visited;
vector<int> dist;
string ans = "Yes";

void dfs(int v, int d){
  visited[v] = true;
  dist[v] = d;
  for(pair<int, int>p : graph[v]){
    if(!visited[p.first]) dfs(p.first, d+p.second);
    else if(dist[p.first] != d+p.second) ans = "No";
  }
}

signed main() {
  cin >> N >> M;
  graph = vector<vector<pair<int, int>>>(N);
  visited = vector<bool>(N, false);
  dist = vector<int>(N);

  int l, r, d;
  REP(i, M){
    cin >> l >> r >> d;
    l--; r--;
    graph[l].push_back(make_pair(r, d));
    graph[r].push_back(make_pair(l, -d));
  }

  REP(i, N) if(!visited[i] && graph[i].size())  dfs(i, 0);
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 16512
import java.util.*;
import java.io.*;
import java.math.*;
public class Main{
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		int[] a = new int[3];
		for(int i = 0 ; i < 3 ; i++) a[i] = Integer.parseInt(sc.next());
		sc.close();
		Arrays.sort(a);
		if(a[0] == 5 && a[1] == 5 && a[2] == 7) ou.println("YES");
		else ou.println("NO");
		ou.flush();
	}
}

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

int main() {
	int N,r;
	double s=0, m=1e9;
	cin >> N;
	vector<double> a(N);

	rep(i,N) {
		cin >> a.at(i);
		s += a.at(i);
	}
	s /= N;

	rep(i,N)
		if(abs(a.at(i)-s) < m) {
			m = abs(a.at(i)-s);
			r = i;
		}
	cout << r << endl;
}

Measured memory_bytes: 3728
import sys
n = int(input())
l = [input() for i in range(n)]
count=1

l_f = [x for x in set(l) if l.count(x) > 1]
if len(l_f) != 0:
    print('No')
    sys.exit()
for i in l:
    
    last = i[-1]
    try:
        first = l[count][0]
        count+=1
        if last == first:
            continue
        else:
            print('No')
            sys.exit()
    except IndexError:
        print('Yes')


Measured memory_bytes: 3060
N, K = map(int, input().split())
h = [0]*N
for i in range(N):
    h[i] = int(input())
h.sort()
min_v = h[K-1] - h[0]
for j in range(0, N-K+1):
    min_v = min(min_v, h[j+K-1] - h[j])
print(min_v)


Measured memory_bytes: 7472
// Created by sz
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int x,y,a,b,c;
    cin >> x >> y >> a >> b >>c;
    vector<int> p(a), q(b), r(c);
    
    for (int i = 0; i < a; i++){
        cin >> p[i];
    }
    
    sort(p.begin(), p.end());
    reverse(p.begin(), p.end());
    
    for (int i = 0; i < b; i++){
        cin >> q[i];
    }
    
    sort(q.begin(), q.end());
    reverse(q.begin(), q.end());
    
    for (int i = 0; i < c; i++){
        cin >> r[i];
    }
    
    sort(r.begin(), r.end());
    reverse(r.begin(), r.end());
    
    int pp = 0, qp = 0, rp = 0, cnt = 0;
    ll sum = 0;
    while (cnt <  x + y) {
        int cp = -1, cq = -1, cr = -1;
        if(pp < min(a, x)){
            cp = p[pp];
        }
        
        if(qp < min(b,y)){
            cq = q[qp];
        }
        
        if(rp < c){
            cr = r[rp];
        }
        
        int mx = max({cp, cq, cr});
        if(mx == cp){
            sum += p[pp++];
        }else if(mx == cq){
            sum += q[qp++];
        }else{
            sum += r[rp++];
        }
        
        cnt++;
    }
    cout << sum << "\n";
    
    return 0;
}


Measured memory_bytes: 1408
flag = 0

N = int(input())

l = list(map(int, input().split()))

for i in range(N-1):
  for j in range(N-1):
    if l[N-1-j] < l[N-2-j]:
      a = l[N-1-j]
      b = l[N-2-j]
      l[N-2-j] = a
      l[N-1-j] = b
      flag += 1

print(" ".join(map(str, l)))
print(flag)


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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define INF LONG_LONG_MAX
#define MOD 1000000007
#define yn(f) cout << (f ? "Yes" : "No") << endl;
#define YN(f) cout << (f ? "YES" : "NO") << endl;

int n,m;

signed main() {
    cin >> n >> m;
    int l=1;
    vector<pair<int,int>> v;
    if (n%2) {
        int l=1, r = n;
        rep(i,m) {
            v.pb(mp(l,r));
            ++l, --r;
        }
    } else {
        int l=1, r = (n+1)/2;
        while(l < r) {
            v.pb(mp(l,r));
            ++l, --r;
        }
        l = (n+1)/2+1;
        r = n-1;
        while((r-l) > 0) {
            v.pb(mp(l,r));
            ++l, --r;
        }
    }
    rep(i,m) cout << v[i].fi << " " << v[i].se << endl;
}




Measured memory_bytes: 5300
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n;
    cin>>n;
    ll dp[n];
    for(int i=0;i<n;i++) cin>>dp[i];
    ll sum=0;
    for(int i=0;i<n-1;i++)
    {
        if(dp[i]<=dp[i+1]) continue;
        sum+=(dp[i]-dp[i+1]);
        dp[i+1]=dp[i];
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 5108
n, k = gets.split.map(&:to_i)
v = gets.split.map(&:to_i)

ans = -Float::INFINITY
(0..k).each do |x|
  (0..x).each do |y|
    (0..(x - y)).each do |z|
      q = v.dup
      sum = 0
      garbages = []
      
      y.times do
        jewelry = q.shift
        break if jewelry.nil?
        sum += jewelry
        garbages << jewelry if jewelry < 0
      end

      z.times do
        jewelry = q.pop
        break if jewelry.nil?
        sum += jewelry
        garbages << jewelry if jewelry < 0
      end

      garbages.sort!
      (x - y - z).times do 
        garbage = garbages.shift
        break if garbage.nil?
        sum -= garbage
      end

      ans = [ans, sum].max
    end
  end
end

puts ans

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

using namespace std;

void f() {
    cout << "No\n";
    exit(EXIT_SUCCESS);
}
int main() {
    int a, b;
    string str;
    cin >> a >> b;
    cin >> str;
    for (int i=0; i < a; i++) {
        char ch = str[i];
        if (ch >= '0' and ch <= '9') {
            
        } else {
            f();
        }
    }
    if (str[a] != '-') f();
    for (int i=a+1; i < a+b+1; i++) {
        char ch = str[i];
        if (ch >= '0' and ch <= '9') {
            
        } else {
            f();
        }
    }
    cout << "Yes\n";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int y, m, d;
	while (cin >> y >> m >> d) {
		int g = -1;
		if (y >= 1869 && y <= 1911)
			g = 0;
		else if (y >= 1913 && y <= 1925)
			g = 1;
		else if (y >= 1927 && y <= 1988)
			g = 2;
		else if (y >= 1990)
			g = 3;
		else if (y == 1912) {
			if (m >= 8)
				g = 1;
			else if (m <= 6)
				g = 0;
			else {
				if (d <= 29)
					g = 0;
				else
					g = 1;
			}
		}
		else if (y == 1926) {
			if (m <= 11)
				g = 1;
			else {
				if (d <= 24)
					g = 1;
				else
					g = 2;
			}
		}
		else if (y == 1989) {
			if (m >= 2)
				g = 3;
			else {
				if (d <= 7)
				g = 2;
				else
					g = 3;
			}
		}
		else if (y == 1868) {
			if (m >= 10)
				g = 0;
			else if(m==9){
				if (d >= 8)
					g = 0;
			}
		}
		if (g == 0)
			cout << "meiji " << (y - 1868) + 1 << " " << m << " " << d << endl;
		else if (g == 1)
			cout << "taisho " << ((y - 1912) + 1) << " " << m << " " << d << endl;
		else if (g == 2)
			cout << "showa " << (y - 1926) + 1 << " " << m << " " << d << endl;
		else if (g == 3)
			cout << "heisei " << (y - 1989) + 1 << " " << m << " " << d << endl;
		else if (g == -1)
			cout << "pre-meiji" << endl;
	}
}

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

#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); ++i)
#define rep(i, n) repi(i, 0, n)
#define all(x) (x).begin(), (x).end()

inline void Main() {
  // code
  string s;
  char c;
  int r = 0;
  cin >> s;
  rep(i, 3) {
    cin >> c;
    if(c == s.at(i)) r++;
  }
  cout << r << endl;
}

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


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

using namespace std;

#define inf 1<<30
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define fn fill_n
typedef long long llong;
typedef unsigned long long ullong;
typedef pair<int, int> P;
struct UnionFind{
	vector<int> par, rank;

	UnionFind(){}
	UnionFind(int n){
		par.resize(n), rank.resize(n);
		for(int i = 0; i < n; i++)
			par[i] = i, rank[i] = 0;
	}
	int root(int n){
		if(par[n] == n) return n;
		return par[n] = root(par[n]);
	}
	bool same(int a, int b){
		return root(a) == root(b);
	}
	bool marge(int a, int b){
		a = root(a), b = root(b);
		if(a == b) return false;
		if(rank[a] < rank[b]) swap(a, b);
		if(rank[a] == rank[b]) rank[a]++;
		par[b] = a;
		return true;
	}
};

int main(){
	int n, m;
	P edge[50];
	cin >> n >> m;
	for(int i = 0; i < m; i++)
		cin >> edge[i].first >> edge[i].second;

	int cnt = 0;
	for(int i = 0; i < m; i++){
		UnionFind uf(n+1);
		for(int j = 0; j < m; j++){
			if(i == j) continue;
			uf.marge(edge[j].first, edge[j].second);
		}
		if(!uf.same(edge[i].first, edge[i].second))
			cnt++;
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
import math
a, b, h, m = map(int, input().split())
h += m/60.0
a_x = a*math.sin((h/12.0)*2.0*math.pi)
a_y = a*math.cos((h/12.0)*2.0*math.pi)
b_x = b*math.sin((m/60.0)*2.0*math.pi)
b_y = b*math.cos((m/60.0)*2.0*math.pi)
dist = math.sqrt((a_x - b_x)*(a_x - b_x) + (a_y - b_y)*(a_y - b_y))
print(dist)

Measured memory_bytes: 9520
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		int a = in.nextInt();
		int b = in.nextInt();
		int min = b;
		int max = b;
		long  sum = b;
		for(int i = 0 ;i<a-1 ;i++){
			int c = in.nextInt();
			if(min>c){
				min = c;
			}
			if(max<c){
				max = c;
			}
			sum += c;
		}
		System.out.println(min+" "+max+" "+sum);
	}
}

Measured memory_bytes: 41272
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

    static Map<String, String> map = new HashMap<String, String>(){
        {
            put("Sunny","Cloudy");
            put("Cloudy","Rainy");
            put("Rainy","Sunny");
        }
    };
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String s = sc.nextLine();
        
        System.out.println(map.get(s));
    }

}


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


int main()
{
    int L, R;
    cin >> L >> R;

    int ans = 1 << 30;
    for (int i = L; i < min(R,L+2019); ++i)
    {
        for (int j = i + 1; j <= min(R, L+2019);++j){
            ans = min(ans, (i % 2019) * (j % 2019) % 2019);
        }
    }

    cout << ans << endl;
    return 0;
}

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

#define MAX_N (100)

int main(int argc, char *argv[]) {
  int N, as[MAX_N];
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &as[i]);
  }

  double sum = 0.0;
  for (int i = 0; i < N; i++) {
    sum += 1.0 / as[i];
  }
  printf("%.12lf\n", 1.0 / sum);
  
  return 0;
}


Measured memory_bytes: 128
N = int(input())
S = [int(input()) for n in range(N)]
A = sum(S)

if A%10!=0:
  ans = A
else:
  T = [s for s in S if s%10!=0]
  if len(T)==0:
    ans = 0
  else:
    ans = A-min(T)

print(ans)

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

int main(){

  while(1){
      int x, y;
      cin>>x>>y;
      if(x == 0 && y == 0) break;

      if(x > y) swap(x, y);
      cout<<x<<" "<<y<<endl;
   }

   return 0;
}


Measured memory_bytes: 3068
n,k,*a=map(int,open(0).read().split())
v=[0]+[-1]*n
t=a[0]-1
c=1
while v[t]<0:
  v[t]=c
  t=a[t]-1
  c+=1
l=v[t]
c-=l
print(v.index(min(k,l+(k-l)%c))+1)

Measured memory_bytes: 31788
package main

import "fmt"

func main()  {
	var n int
	fmt.Scan(&n)
	nums := ScanNums(n)
	var ans float64
	for i := 0; i < n; i++ {
		ans += 1 / float64(nums[i])
	}
	fmt.Println(1  / ans)
}

func ScanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return
}


Measured memory_bytes: 512
#include<iostream> //cinなど
#include<string> //文字列
#include<algorithm> //sort など
#include<math.h> //paw(冪乗など)
#include<set> // 集合
#include<map> //写像
#include<stdio.h> //printf
#include<stack>

using namespace std;
int main(){
   int num;
   cin>>num;
   cout<<"ABC"<<num<<endl; 
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;

//ここから

void solve(){
  ll n,m;
  cin>>n>>m;
  vector<ll>x(m);
  rep(i,m)cin>>x[i];
  if(m==1)cout<<0;
  else {
    sort(x.begin(),x.end());
    vector<int>v;
    rep(i,m-1)v.pb(x[i+1]-x[i]);
    sort(v.begin(),v.end());
    int ans=0;
    rep(i,v.size()-(n-1))ans+=v[i];
    cout<<ans;
  }
}

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


Measured memory_bytes: 1660
def get_winner(s):
	for p in ['o','x']:
		for i in xrange(3):
			win_h=True
			win_v=True
			for j in xrange(3):
				if s[i*3+j]!=p:
					win_h=False
				if s[j*3+i]!=p:
					win_v=False
			if win_h or win_v:
				return p
		if p==s[0]==s[4]==s[8] or p==s[2]==s[4]==s[6]:
			return p
	return 'd'

while 1:
	try:
		s=raw_input()
		print get_winner(s)
	except  EOFError:
		break

Measured memory_bytes: 4244